akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll n,k;
    cin>>n>>k;
    ll mod=1e9+7;
    ll ans=0;
    vll sum(n+2,0);
    rep(i,0,n+1){
        sum[i+1]=sum[i]+i;
    }
    rep(num,k,n+2){
        ll l,r;
        l=sum[num]-sum[0];
        r=sum[n+1]-sum[n+1-num];
        ans+=r-l+1;
        ans%=mod;
        if(ans<0)ans+=mod;
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 4756
def base10toN(num, base):
    converted_string, modstring = "", ""
    currentnum = num
    if not num:
        return '0'
    while currentnum:
        mod = currentnum % base
        currentnum = currentnum // base
        converted_string = chr(48 + mod + 7*(mod > 10)) + converted_string
    return converted_string
h,w,k=map(int,input().split())
c=[]
for i in range(h):
  a=input()
  c.append(a)
ans=0
for i in range(2**h):
  iconvert=base10toN(i,2)
  ic=[]
  for _ in range(h-len(iconvert)):
    ic.append('0')
  for _ in range(len(iconvert)):
    ic.append(iconvert[_])
  for j in range(2**w):
    jconvert=base10toN(j,2)
    jc=[]
    for _ in range(w-len(jconvert)):
      jc.append('0')
    for _ in range(len(jconvert)):
      jc.append(jconvert[_])
    count=0
    for a in range(h):
      for b in range(w):
        if ic[a]=='0' and jc[b]=='0' and c[a][b]=='#':
          count+=1
    if count==k:
      ans+=1
print(ans)

Measured memory_bytes: 68856
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

typedef long long ll;

int dx[] = {0, -1, 1, 0, -1, 1, -1, 1, 0};
int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

#define _rep3(i,p,n) for(int i=(p),i##_counter=(n); i<i##_counter;++i)
#define _rep2(i,n,_) _rep3(i,0,n)
#define _rep_call(a, b, c, name, ...) name(a, b, c)
#define rep(...) _rep_call(__VA_ARGS__, _rep3, _rep2)

#define dump(x)  cerr << #x << " = " << (x) << '\n'
#define debug(x) cerr << #x << " = " << (x) << " (at line " << __LINE__ << ")" << " " << __FILE__ << '\n'

void Main() {
    int A, B, C; cin >> A >> B >> C;
    if (A == 7) {
        if (B == 5 && C == 5) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    } else if (A != 5) {
        cout << "NO\n";
    } else {
        if ((B == 7 && C == 5) || (B == 5 && C == 7)) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
    int key;
    struct node *next;
    struct node *prev;
};
typedef struct node * nodePtr;

void init(void);
void insert(int key);
void delete(int target);
void deleteFirst(void);
void deleteLast(void);
void printList(void);

int main(void)
{
    init();

    int num_op;
    scanf("%d", &num_op);

    char op[12];
    int key;

    while (num_op--) {
        scanf("%s", op);
        if (strcmp(op, "insert") == 0) {
            scanf("%d", &key);
            insert(key);
        } else if (strcmp(op, "delete") == 0) {
            scanf("%d", &key);
            delete(key);
        } else if (strcmp(op, "deleteFirst") == 0) {
            deleteFirst();
        } else {
            deleteLast();
        }
    }

    printList();
    return 0;
}

    /*
       ------- root <------
      |                    |
       --> 3 --> 2 --> 1 --
    */

nodePtr root;
void init(void)
{
    root = malloc(sizeof(struct node));
    root->next = root;
    root->prev = root;
}

void insert(int key)
{
    nodePtr inserted;
    inserted = malloc(sizeof(struct node));
    inserted->next = root->next;
    inserted->prev = root;
    inserted->key = key;

    root->next->prev = inserted;
    root->next = inserted;
}

void deleteNode(nodePtr node);

void delete(int target)
{
    nodePtr current = root->next;
    while (current != root) {
        if (current->key == target) {
            deleteNode(current);
            return ;
        }
        current = current->next;
    }
}

void deleteNode(nodePtr node)
{
    if (node == root) {
        return ;
    }
    node->next->prev = node->prev;
    node->prev->next = node->next;
    free(node);
}

void deleteFirst(void)
{
    deleteNode(root->next);
}

void deleteLast(void)
{
    deleteNode(root->prev);
}

void printList(void)
{
    nodePtr current = root->next;
    int isFirst = 1;
    while (current != root) {
        if (isFirst == 0) {
            printf(" ");
        }
        printf("%d", current->key);
        current = current->next;
        isFirst = 0;
    }
    printf("\n");
}

Measured memory_bytes: 31784
#include <iostream>
#include <vector>
// #include <algorithm>
// #include <map>
// #include <cmath>
// #include <string>

using namespace std;
// typedef unsigned long long ull;

// void p() {
//     cout << "\n";
// }
// template<class Head, class... Body>
// void p(Head head, Body... body) {
//     cout << head << ",";
//     p(body...);
// }

// template<typename T>
// ostream& operator<<(ostream& os, const vector<T>& v) {
//     os << "[";
//     for (const auto i : v) {
//         os << i << " ";
//     }
//     os << "]";
//     return os;
// }


int main(int argc, char const *argv[]) {
    int N;
    cin >> N;

    vector<int> T(N);
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> T[i];
        sum += T[i];
    }

    int M;
    cin >> M;
    vector<int> P(M), X(M);
    for (int i = 0; i < M; i++) {
        cin >> P[i] >> X[i];
        P[i] -= 1;
    }

    for (int i = 0; i < M; i++) {
        cout << sum - T[P[i]] + X[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define INF 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
    ll int jhogeo = 1;
    rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
    return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}

int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){    
  int N; cin>>N;
  vector<int> A(N);
  rep(i,0,N) cin>>A[i];
  vector<vector<int>> num(3,vector<int> (N));

  rep(i,0,3){
    rep(j,0,N){
      num[i][j]=0;
    }
  }
  int check=0;
  rep(i,0,N-1){
    check=0;
    rep(j,0,3){
      if(!check&&num[j][i]==A[i]){
        num[j][i+1]=num[j][i]+1;
        check++;
      }else{
        num[j][i+1]=num[j][i];
      }
    }
      
  }
    ll int ans=1;
    int tmp=0;
    rep(i,0,N){
      rep(j,0,3){
        tmp+=(num[j][i]==A[i]);
      }
      ans=ans*tmp%MOD;
      tmp=0;
    }
    cout<<ans;
  
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示

//  vector<pair<int,int>> data(N);  //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int n,j,ans = 0;
  string s;
  string tmp;
  cin >> n >> s;
  
  rep(i,n) {
    if(s[i] == 'A'){
      tmp = "A";
    } else if(tmp == "A" && s[i] == 'B') {
      tmp = "AB" ;
    } else if(tmp == "AB" && s[i] == 'C') {
      ans++;
      tmp = "";
    } else {
      tmp = "";
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T & a, const T & b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

int dx2[2] = { 1,0 };
int dy2[2] = { 0,1 };

/******************************************************************************************/

int w, h;
char mp[75][75];
auto memo = make_v<string>(75, 75);

string strMaxi(string a, string b) {
	if (a.size() > b.size()) return a;
	if (a.size() < b.size()) return b;
	return max(a, b);
}

string dfs(int y, int x) {

	if (memo[y][x] != "")return memo[y][x];

	string res = "";
	for (int i = 0; i < 2; i++)
	{
		int ny = y + dy2[i];
		int nx = x + dx2[i];
		if (0 <= ny && ny < h && 0 <= nx && nx < w && '0' <= mp[ny][nx] && mp[ny][nx] <= '9') {
			res = strMaxi(res, mp[y][x] + dfs(ny, nx));
		}
	}

	
	if (res == "") {
		res = mp[y][x];
	}
	return memo[y][x] = res;
}



int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	

		
	while (cin >> w >> h, w | h) {

		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				cin >> mp[i][j];
			}
		}
		string ans = "";


		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				memo[i][j] = "";
			}
		}

		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if ('1' <= mp[i][j] && mp[i][j] <= '9') {
					
					ans = strMaxi(ans, dfs(i, j));
				}
			}
		}

		cout << ans << endl;
	}


	
	

	return 0;
}




Measured memory_bytes: 3364
#include <bits/stdc++.h>
#include <set>
#define rep(i,n) for (int i =0; i < (n); ++i)
using namespace std;


int main() {
  int n,h,w;
  int ans = 0;
  cin >> n >> h >> w;
  for (int i = 0;i < n; i++){
    int a[1100],b[1100];
    cin >> a[i] >> b[i];

    if (a[i] >= h && b[i] >= w) ans++;
  }
 
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

#define ll unsigned long long
#define INF 1234567890
#define N (int)(2e5 + 5)

void solve()
{
    string s;
    cin >> s;
    bool ok = true;
    int n = s.length();
    for(int i = 0; i < n; i += 2)
        if(s[i] == 'h' && s[i + 1] == 'i') continue;else
    {
        ok = false;
        break;
    }
    if(ok) cout << "Yes";else cout << "No";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    int h1, h2, m1, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int c1 = h1 * 60 + m1;
    int c2 = h2 * 60 + m2;
    cout << (c2 - c1) - k << endl;
    return 0;
}

Measured memory_bytes: 3612
import java.util.*;

public class Main{
//public class abc166_a{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		
		if(s.equals("ABC")){
			System.out.println("ARC");
		}else{
			System.out.println("ABC");
		}
	}

}

Measured memory_bytes: 26996
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N+1),B(N);
  for(int i=0;i<N+1;i++){
    cin >> A.at(i);
  }
  for(int j=0;j<N;j++){
    cin >> B.at(j);
  }
  
  long long int ans=0;
  
  for(int k=0;k<N;k++){
    ans+=min(A.at(k),B.at(k));
    if(A.at(k)<B.at(k)){
      ans+=min((B.at(k)-A.at(k)),A.at(k+1));
      if(A.at(k+1)>(B.at(k)-A.at(k))){
        A.at(k+1)-=B.at(k)-A.at(k);
      }else{
        A.at(k+1)=0;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int64, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
	}
	dp := make([][5][2]int64, n+1)
	for i := 0; i < n+1; i++ {
		for j := 0; j < 5; j++ {
			for k := 0; k < 2; k++ {
				dp[i][j][k] = -math.MaxInt64
			}
		}
	}
	dp[0][2][0] = 0
	for i := 0; i < n; i++ {
		for j := 0; j < 4; j++ {
			if dp[i][j][0] == -math.MaxInt64 {
				continue
			}
			dp[i+1][j+1][1] = max(dp[i+1][j+1][1], dp[i][j][0]+aa[i])
		}

		for j := 1; j < 5; j++ {
			dp[i+1][j-1][0] = max(dp[i+1][j-1][0], dp[i][j][1])
			dp[i+1][j-1][0] = max(dp[i+1][j-1][0], dp[i][j][0])
		}
	}
	if n%2 == 0 {
		fmt.Fprintln(writer, max(dp[n][2][0], dp[n][2][1]))
		return
	}
	fmt.Fprintln(writer, max(dp[n][1][0], dp[n][1][1]))
}

func max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 22528
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <queue>
#include <unordered_map>
#include <list>
using namespace std;

using ll = long long;

#define rep_init(i, init, n) for(int i = (init); i < (n); ++i)
#define rep(i, n) rep_init(i, 0, n)

int main()
{
	int X, N;
	std::vector<bool> P(102, true);
    cin >> X >> N;
	for(int i=0;i<N;i++){
		int p;
		cin >> p;
		P[p] = false;
	}

	int d = 0;
	int ans;
	while (true)
	{
		if (P[X-d]){
			ans = X-d;
			break;
		}else if(P[X+d]){
			ans = X+d;
			break;
		}
		++d;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3640
X, K, D = map(int, input().split())

k = abs(X // D)
r = X % D
k = K-k
if k < 0:
    if X < 0:
        print(abs(X+K*D))
    else:
        print(abs(X-K*D))
else:
    if k % 2 == 0:
        print(abs(r))
    else:
        print(abs(r-D))

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)

int main()
{
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (s == u)
    {
        cout << a - 1 << ' ' << b << "\n";
    }
    else
    {
        cout << a << ' ' << b - 1 << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll solve(string s, int n, int k) {
    ll d = 0, m = 0, dm = 0, dmc = 0;
    for (int i = 0; i < k - 1; i++) {
        switch (s[i]) {
        case 'D':
            d++;
            break;
        case 'M':
            m++;
            dm += d;
            break;
        case 'C':
            dmc += dm;
            break;
        }
    }
    for (int i = k - 1; i < n; i++) {
        switch (s[i]) {
        case 'D':
            d++;
            break;
        case 'M':
            m++;
            dm += d;
            break;
        case 'C':
            dmc += dm;
            break;
        }
        switch (s[i - k + 1]) {
        case 'D':
            d--;
            dm -= m;
            break;
        case 'M':
            m--;
            break;
        }
    }
    return dmc;
}

int main() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    int ks[q];
    for (int i = 0; i < q; i++) {
        cin >> ks[i];
    }

    for (int k: ks) {
        cout << solve(s, n, k) << endl;
    }
    return 0;
}


Measured memory_bytes: 2308
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	private int[] a;

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run(){
		Scanner scan = new Scanner(System.in);
		
		while (true) {
			int n = scan.nextInt();
			int k = scan.nextInt();
			if ((n | k) == 0) break;
			
			boolean flag = false;
			boolean zeroUsed = false;
			//boolean insortZero = false;
			
			a = new int[k];
			int p;
			for (int i = 0; i < k; i++) {
				p = scan.nextInt();
				if (p != 0) {
					a[i] = p;
				}else {
					k--;
					i--;
					flag = true;
				}
			}
			
			Arrays.sort(a, 0, k);
			
			int count = 1, max = 0, zeroPos = 0;
			if (!flag) {
				for (int i = 1; i < k; i++) {
					if (a[i] - a[i - 1] == 1) {
						count++;
					}else {
						max = Math.max(count, max);
						count = 1;
					}
				}
			}else {
				for (int i = 0; i < k; i++) {
					if (i == 0) {
						if (a[i] == 2) {
							count++;
							zeroUsed = true;
							zeroPos = i;
						}
					}else if (a[i] - a[i - 1] == 1) {
						count++;
					}else if (a[i] - a[i - 1] == 2 && !zeroUsed) {
						count += 2;
						zeroUsed = true;
						zeroPos = i;
					}else {
						max = Math.max(count, max);
						count = 1;
						if (zeroUsed) i = zeroPos;
						zeroUsed = false;
					}
				}
				max = Math.max(count, max);
			}
			//System.out.println(Arrays.toString(a));
			System.out.println(max);
		}
	}

}

Measured memory_bytes: 62876
/*

    author : s@if

*/

#include<bits/stdc++.h>
using namespace std;
#define NIL -1
#define fi first
#define sec second
#define MAX INT_MAX
#define INF 99999999
#define ll long long
#define PI acos(-1.0)
#define MOD 1000000007
#define PLL pair<ll,ll>
#define PII pair<int,int>
#define ull unsigned long long
#define triplell pair<pair<ll,ll> , ll>
#define triple pair<pair<int,int> , int>
#define For(i,n) for(int i=0;i<(int)n;i++)
#define Forn(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define forba(i,a,b) for(int i=(int)b;i>=(int)a;i--)

int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};

const int MAXN = (int)1e5+9;

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */
    
    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;
    
    cin>>n;
    int ara[n+9];
    
    for(i=1;i<=n;i++)
    {
    	cin>>ara[i];
	}
	
	int ans = 1;
	int mx = ara[1];
	
	for(i=2;i<=n;i++)
	{
		if(ara[i]>=mx)
		{
			ans++;
			mx = ara[i];
		}
	}
	
	cout<<ans<<endl;
	
//	main();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    string s,t,u;
    int a,b;
    cin >> s >> t >> a >> b >> u;

    if(t == u){
        cout << a << " " << b-1 << endl;
    }else{
        cout << a-1 << " " << b << endl;
    }

    
    return 0;
}

Measured memory_bytes: 256
import math
N=int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
L=list()
for i in range(N-1):
  for j in range(i,N):
    L.append(((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**(1/2))
    
print(2*math.factorial(N-1)*sum(L)/math.factorial(N))

Measured memory_bytes: 9380
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int a,b;
    cin >> a >> b;
    int add = a + b;
    int pull = a - b;
    int call = a * b;
    int an = max(add,pull);
    int ans = max(call, an);
    cout << ans << endl;
   
}
  

Measured memory_bytes: 256
from collections import deque
n = int(input())
a = deque()
for i in range(n):
    c = input()
    if c == "deleteFirst":
        a.popleft()
    elif c == "deleteLast":
        a.pop()
    else:
        c, v = c.split()
        if c == "insert":
            a.appendleft(v)
        else:
            try:
                a.remove(v)
            except:
                pass
print(" ".join(a))


Measured memory_bytes: 69740
#include <bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define MAXX 1005

#define PI 3.14159265358979323846264338327950
#define ll  long long int
int n , x;
int p[MAXX];
bool used[MAXX];

int main()
{
    FAST;
    cin >> x >> n;
    for(int i = 0; i < n; i++){
        cin >> p[i];
        used[p[i] + 100] = true;
    }
    int ans = x;
    ans ++;
    ans --;
    ans ++;
    ans --;
    
    for(int i = 0; i < 101; i++){
        if(!used[x - i + 100]){
            ans = x - i;
            break;
        }
        if(!used[x + i + 100]){
            ans = x + i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
// test.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#include <iostream>
#include <algorithm>
#include <vector>




using namespace std;


int main()
{
	// 整数の入力
	int N;
	cin >> N;
	vector<int> A(N), B(N), C(N);
	for (int i = 0; i < N; i++) cin >> A.at(i);
	for (int j = 0; j < N; j++) cin >> B.at(j);
	for (int k = 0; k < N-1; k++) cin >> C.at(k);
	
	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += B.at(A.at(i)-1);
		if (i > 0 && A.at(i) == A.at(i-1) + 1) {
			sum += C.at(A.at(i-1)-1);
			//cout << "C発見！"<< C.at(A.at(i-1) - 1) << "~i:" << i << endl;
		}
		//cout << sum << endl;
	}
	
	//全部

	//cout <<C.at(A.at(N - 1)) << endl;
	cout << sum << endl;
	
	
	
	

	return 0;
}





// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int a[100], b[100];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int k = a[0], m;
	for (int i = 0; i < n; i++)
		cin >> b[i], k += b[i];
	m = k;
	for (int i = 1; i < n; i++)
		k += a[i] - b[i - 1], m = max(m, k);
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

void QuickSort(long begin, long end, long *array) {
  if (begin == end) return;
  long pivot;
  long i, j, temp;
  i = begin;
  j = end;
  pivot = array[end];
  while (1) {
    while (pivot >= array[i]) {
      i++;
      if (i == end) break;
    }
    while (pivot < array[j]) {
      j--;
    }
    if (j <= i) {
      if (i == j) j = end - 1;
      break;
    } else {
      temp = array[i];
      array[i] = array[j];
      array[j] = temp;
    }
    i++;
    j--;
  }
  QuickSort(begin, j, array);
  QuickSort(i, end, array);
  return;
}

int main(int argc, char const *argv[]) {
  long data[8][1000];
  long ans = 0;
  int N, M;
  long tempx, tempy, tempz;
  long temp;
  scanf("%d%d", &N, &M);

  for (int i = 0; i < N; i++) {
    scanf("%ld%ld%ld", &tempx, &tempy, &tempz);
    data[0][i] = tempx + tempy + tempz;
    data[1][i] = tempx + tempy - tempz;
    data[2][i] = tempx - tempy + tempz;
    data[3][i] = tempx - tempy - tempz;
    data[4][i] = -tempx + tempy + tempz;
    data[5][i] = -tempx + tempy - tempz;
    data[6][i] = -tempx - tempy + tempz;
    data[7][i] = -tempx - tempy - tempz;
  }

  for (int loopcount = 0; loopcount < 8; loopcount++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; i + j < N - 1; j++) {
        if (data[loopcount][j] > data[loopcount][j + 1]) {
          temp = data[loopcount][j + 1];
          data[loopcount][j + 1] = data[loopcount][j];
          data[loopcount][j] = temp;
        }
      }
    }
    temp = 0;
    for (int i = 0; i < M; i++) {
      temp += data[loopcount][N - i - 1];
    }
    // for (int debug = 0; debug < N; debug++) {
    //   printf("%d ", data[loopcount][debug]);
    // }
    // printf("\n");
    if (ans < temp) ans = temp;
  }
  printf("%ld", ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;

int main(void) {
  int X, A, B;
  cin >> X >> A >> B;
  if (B <= A)
    cout << "delicious" << endl;
  else if ((B - A) <= X)
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
  int n;
  cin >> n;
  long long sum=0;

  long long m=0,a=0,r=0,c=0,h=0;

  string temp;
  for(int i=0;i<n;++i){
        cin >> temp;
        if(temp[0] == 'M') m++;
        if(temp[0] == 'A') a++;
        if(temp[0] == 'R') r++;
        if(temp[0] == 'C') c++;
        if(temp[0] == 'H') h++;
  }

  sum += m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h;
  sum += a*r*c + a*r*h + a*c*h;
  sum += r*c*h;

  cout << sum << endl;
}


Measured memory_bytes: 256
import math

class Vector:
    def __init__(self,x,y):
        self.x = x
        self.y = y
        
    def __add__(self,other):
        return Vector(self.x+other.x,self.y+other.y)
    
    def __sub__(self,other):
        return Vector(self.x-other.x,self.y-other.y)
    
    def __mul__(self,scalar):
        return Vector(self.x*scalar,self.y*scalar)
    def __rmul__(self, scalar):
        return Vector(self.x*scalar,self.y*scalar)
   
    def __repr__(self):
        return str([self.x,self.y])
        
    def norm_2(self):
        return dot(self,self)
    
    def norm(self):
        return math.sqrt(self.norm_2())
    
def v_sum(v1,v2):
    return Vector(v1.x+v2.x,v1.y+v2.y) 
def scalar_multi(k,v):
    return Vector(k*v.x,k*v.y)
def v_diff(v1,v2):
    return v_sum(v1,scalar_multi(-1,v2))
    
def dot(vector1,vector2):
    return vector1.x*vector2.x+vector1.y*vector2.y

def cross(vector1,vector2):
    return vector1.x*vector2.y-vector1.y*vector2.x


x1,y1,x2,y2 = map(float,input().split())
p1 = Vector(x1,y1)
p2 = Vector(x2,y2)

q = int(input())

for i in range(q):
    x,y = map(float,input().split())
    p3 = Vector(x,y)
    
    a = p2-p1
    v = p3-p1
    if cross(a,v) > 0:
        print('COUNTER_CLOCKWISE')
    elif cross(a,v) < 0:
        print('CLOCKWISE')
    else:
        if dot(a,v)<0:
            print('ONLINE_BACK')
        elif dot(a,v)>a.norm_2():
            print('ONLINE_FRONT')
        else:
            print('ON_SEGMENT')


Measured memory_bytes: 5704
n=int(input())
def gcd(x,y):
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)

def lcm(a,b):
    return a*b//gcd(a,b)
ans=1
for i in range(n):
    t=int(input())
    ans=lcm(ans,t)
print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
int b[200010]={1};

    int main(){
      int n,k;
      cin >> n >>k;
      int a[n+1];
      rep(i,n)cin >> a[i];
      sort(a,a+n);
      a[n]=a[n-1];
      int count=0;
      b[0]=1;
      int pos=0;
      rep(pos,n-1){
       if(a[pos]==a[pos+1]){
        b[count]++; 
       }else{
        count++;
         b[count]++;
       }
      }
      sort(b,b+count+1);
      int ans=0;
      rep(i,count-k+1)ans+=b[i];
      cout << ans << endl;
      return 0;}


Measured memory_bytes: 1792
#include <bits/stdc++.h>

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<tuple<string, int, int>> shop(N);
    string S;
    int P;
    for (int i = 0; i < N; i++) {
        cin >> S >> P;
        shop[i] = make_tuple(S, -P, i+1);
    }
    sort(shop.begin(), shop.end());
    for (int i = 0; i < N; i++) {
        cout << get<2>(shop[i]) << endl;
    }
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3636
def ichiro(n)
  (n-1)%5
end

def count(n)
  n < 0 ? 0 : n
end

while n = gets.to_i
  break if n.zero?

  jiro = gets.split.map(&:to_i)
  ohajiki = 32
  i = 0
  
  while 0 < ohajiki
    ohajiki -= ichiro(ohajiki)
    puts count(ohajiki)

    ohajiki -= jiro[i]
    puts count(ohajiki)

    if i == jiro.size-1
      i = 0
    else
      i += 1
    end
  end
end

Measured memory_bytes: 6108
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    int h, w;
    cin >> h >> w;
    vector<string> strs;
    string s;
    for(int i = 0; i < h; i++) {
        cin >> s;
        strs.push_back(s);
    }
    unordered_map<int, int> mm_id;
    int nodes = 0;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if (strs[i][j] == '.') {
                mm_id[i*w+j] = nodes++;
            }
        }
    }
    vector<vector<int>> mat(nodes, vector<int>(nodes, 100000));
    for(int i =0; i < nodes; i++)
        mat[i][i] = 0;
    vector<int> dir = {-1, 0, 1, 0, -1};
    for(int i = 0; i < h; i++) {

        for(int j = 0; j < w; j++) {
            if (strs[i][j] == '.') {
                for(int d = 0; d < 4; d++) {
                    int ii = i + dir[d];
                    int jj = j + dir[d+1];
                    if (ii < 0 || ii >= h || jj < 0 || jj >= w)
                        continue;
                    if (strs[ii][jj] == '.') {
                        mat[mm_id[i*w+j]][mm_id[ii*w+jj]] = 1;
                    }
                }
            }
        }
    }
    for(int k = 0; k < nodes; k++) {
        for(int i = 0; i < nodes; i++) {
            for(int j = 0; j < nodes; j++) {
                if (mat[i][k]+mat[k][j] < mat[i][j])
                    mat[i][j] = mat[i][k]+mat[k][j];
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < nodes; i++) {
        for(int j = 0; j < nodes ; j++) {
            // cout << mat[i][j] << " ";
            if (mat[i][j] != 100000)
                ans = max(ans, mat[i][j]);
        }
        // cout << endl;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 896
#include <iostream>
using namespace std;
 
int main(){
  int A,B,C,a,b,c;
  cin>>a;
  cin>>b;
  cin>>c;
  A=c;B=a;C=b;
 cout <<A<<endl;
  cout <<B<<endl;
   cout <<C<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define F first
#define S second
int main()
{
  ll n,W;
  cin>>n>>W;
  vector<pair<ll,ll>> w(n);

  for(int i=0;i<n;i++)
    cin>>w[i].F>>w[i].S;

  sort(w.begin(),w.end());
  vector<vector<ll>> dp(n+1,vector<ll>(W+1,0));

  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=W;j++)
    {
      if(w[i-1].F>j)
        dp[i][j]=dp[i-1][j];
      else
        dp[i][j]=max(dp[i-1][j],w[i-1].S+dp[i-1][j-w[i-1].F]);

      //  cout<<dp[i][j]<<" ";
    }
    //cout<<endl;
  }
  cout<<dp[n][W]<<endl;
}


Measured memory_bytes: 83088
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,T,A;
  cin >> N >> T >> A;
  int h;
  int near = 1<<30;
  int ans = 0;
  for (int i=1; i <N+1; i++) {
    cin >> h;
    int d = (1000*T-h*6)-1000*A;
    if (d<0) d=-d;
    if (d < near) {
      near = d;
      ans = i;
    }
  }
  cout << ans  << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

//nもrも10^5くらいのときにはこれ使うと良き
//二項係数の計算
const int MAX = 510000;
ll fac[MAX],finv[MAX],inv[MAX];

//テーブルの初期化
void COMinit(){
	fac[0] = fac[1] = 1;//階乗
	finv[0] = finv[1] = 1;//階乗の逆元
	inv[1] = 1;//逆元(1の逆元は1)
	for(int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;//累積積的な感じ
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;//inv[i] = iの逆元(mod mod)
		finv[i] = finv[i - 1] * inv[i] % mod;//階乗の逆元の計算
	}
}



ll COM(int n,int k){//二項係数の計算
	if(n < k){
		return 0;
	}
	if (n < 0 || k < 0){
		return 0;
	} 
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

//繰り返し二乗法
ll mod_pow(ll x,ll n){
	ll res = 1;
	while(n > 0){
		if(n & 1){
			res = res * x % mod;
		}
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}
//階乗の計算
ll mod_fact(ll n){
	if (n != 1LL){
		return (mod_fact(n - 1LL) * n) % mod;
	}
	else{
		return 1LL;
	}
}

ll mod_comb(ll n,ll r){//nが大きくて(10^9)でrが小さい時(10^5)にO(r)で計算できるやつ
	ll a = 1LL;
	for(ll i = 1LL; i <= r; i++) {
		a *= (n - i + 1LL);
		a %= mod;
	}
	ll b = mod_pow(mod_fact(r),mod - 2);//r!の逆元（フェルマーの小定理）
	return (a * b) % mod;
}

int main(){
	ll n,k;cin>>n>>k;
	COMinit();
	ll x = min(n,k);
	ll ans = 0;
	for(ll i = 0LL; i <= x; i++) {
		ans += COM(n,i) * COM(n - 1,i) % mod; 
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    int a,b,c;
    cin >> a;
    b = 24 - a + 24;

    cout << b <<endl;

    return 0;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[100005];

int main() {
    ll H, N;
    cin >> H >> N;
    ll s = 0;
    REP(i, N) {
        cin >> A[i];
        s += A[i];
    }

    if (s >= H)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 100000000000000000ll
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
ll n,m;
vector<ll> adj[100001];
bool vis[100001];
ll v1[100001];

int main() {
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    cin>>n>>m;
    for (int i = 0; i < m; ++i)
    {
        ll a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    for (int i = 1; i<=n; ++i)
    {
        v1[i]=-1;
        vis[i]=false;
    }

    queue<ll> q1;
    q1.push(1);
    vis[1]=true;

    while(!q1.empty()){
        ll u = q1.front();
        q1.pop();
        for (auto i = adj[u].begin(); i != adj[u].end(); ++i)
        {
            if(!vis[*i]){
                vis[*i]=true;
                v1[*i]=u;
                q1.push(*i);
            }
        }
    }

    for (int i = 2; i <=n; ++i)
    {
        if(v1[i]==-1){
            cout<<"No";
            return 0;
        }
    }

    cout<<"Yes"<<endl;
    for (int i = 2; i <=n; ++i)
    {
        cout<<v1[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 13188
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, a[112345], b[112345];
    P p[212345];

    cin >> n;

    ll res = LLONG_MAX;

    ll sumA = 0;
    ll sumB = 0;

    REP(i, n)
    {
        cin >> a[i] >> b[i];
        p[i * 2] = make_pair(a[i], i);
        p[i * 2 + 1] = make_pair(b[i], i);

        sumA += a[i];
        sumB += b[i];
    }

    res = min(sumA, sumB);

    sort(p, p + n * 2);

    ll sumN = 0;

    M mp;

    bool check = false;

    REP(i, n)
    {
        sumN += p[i].first;

        if (mp[p[i].second])
            check = true;

        mp[p[i].second]++;
    }

    if (check)
        res = min(res, sumN);

    REP(i, n)
    {
        int tmp;
        if (p[i].second == p[n].second)
            tmp = p[n + 1].first;
        else
            tmp = p[n].first;

        res = min(res, sumN - p[i].first + tmp);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 7552
#include <vector>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <limits>
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ll, ll> pll;
const int N =1e5 + 10;
int k;
int dis[N];
int INT_MAX = 1e9 + 10;
int solve() {
    for (int i = 0; i < k; i++) dis[i] = INT_MAX;
    queue<pair<int, int>> pq;
    for (int i = 1; i < 10; i++) {
        pq.push({-i, i % k});
        dis[i % k] = min(dis[i % k], i);
    }
    int res = INT_MAX;
    while (pq.size()) {
        auto cur = pq.front();
        pq.pop();
        if (cur.second == 0) {
            res = min(res, -cur.first);
            continue;
        }
        if (dis[cur.second] == -cur.first) {
            for (int i = 0; i < 10; i++) {
                int next = (cur.second * 10 + i) % k;
                int value = -cur.first + i;
                if (dis[next] > value) {
                    pq.push({-value, next});
                    dis[next] = value;
                }
            }
        }
    }
    return res;
}
int main() {
    while (cin >> k) {
        cout << solve() << endl;
    }
    return 0;
}


Measured memory_bytes: 1960
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std; 

int main()
{
  int N ;
  cin>>N ;
  vector<int>A(N) ;
  for(int i=0;i<N;i++) cin>>A.at(i) ;
  
  sort(A.begin(),A.end()) ;
  int start=0 ;
  int min=0 ;
  while(start!=N-1){
    min=A.at(start) ;
    for(int i=start+1;i<N;i++){
      A.at(i)=A.at(i)%min ;
      if(A.at(i)==0) start++ ;
    }
    sort(A.begin(),A.end()) ;
  }
  cout<<A.at(N-1)<<endl ;
  
  return 0 ;
}

Measured memory_bytes: 640
import sys
import heapq


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def reward(n, d):
    s = []
    for i in range(n):
        for item in d.get(i, []):
            heapq.heappush(s, item)
        for _ in range(len(s), i+1, -1):
            _ = heapq.heappop(s)
    return sum(s)


def test():
    n = _i()
    ll, rr = {}, {}
    mn = ln = rn = 0
    for i in range(n):
        k, l, r = _ia()
        mn += min(l, r)
        if l >= r:
            ll[k-1] = ll.get(k-1, []) + [l-r]
            ln += 1
        else:
            rr[n-k-1] = rr.get(n-k-1, []) + [r-l]
            rn += 1

    return mn + reward(n, ll) + reward(n, rr)


def main():
    t = _i()
    ret = [test() for _ in range(t)]
    return "\n".join(map(str, ret))


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 114776
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const ll INF = 1e18;
const int mod = 1e9+7;
const int MAX = 1e6;

// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visit[MAX]; // 訪問の有無

ll power(int m, int n) { // m^n（繰り返し自乗法）
    if (n == 0) return 1;
    if (n % 2 == 1) return power(m, n-1) * m % mod;
    ll r = power(m, n/2);
    return r * r % mod;
}

ll inv(ll a, ll b) { // 逆元を利用してa/bのmodを返す
    return a * power(b, mod-2) % mod;
}

int n; // 変数
ll a[MAX];
ll sum = 0;
ll ans = 0;

int main() {
// input
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
// solve
    rep(i, n) {
        ans += (sum - a[i]) % mod * a[i] % mod;
        sum -= a[i];
        ans %= mod;
    }
    // ans = inv(ans, 2);
// output
    cout << ans << "\n";
}

Measured memory_bytes: 5116
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
  int N; cin >> N;
  string S; cin >> S;
  int cnt = 1;
  rep(i, N-1) {
    if (S[i] != S[i + 1]) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
 
int main() {

    int n;
    cin >> n;
    int ans = false;
    int count = 0;
    rep(i,n) {
        int a,b;
        cin >> a >> b;
        if(a == b) {
            count ++;
        }
        else    count = 0;
        if(count>=3) {
            ans = true;
            break;
        }
    }

    if(ans) cout<<"Yes"<<endl;
    else    cout<<"No"<<endl;

 return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int x = 1;
  
  for (int i = 0; i < N; i++){
    if (x < K) {
      x *= 2;
    }
    else {
      x += K;
    }
  }
  
  cout << x << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = []

for i in range(n):
    a.append(list(map(int, input().split())))

b = []
for i in range(m):
    b.append(int(input()))

for i in range(n):
    c = 0
    for j in range(m):
        c += a[i][j] * b[j]
    print(c)



Measured memory_bytes: 6008
N=int(input())

cnts=[0 for i in range(N+1)]

for x in range(1,100):
    x2=x*x
    for y in range(x,100):
        y2=y*y
        xy=x*y
        if x2+y*y+x*y+x+y > N:
            break

        for z in range(y,100):
            z2 = z*z
            M = x2+y2+z2+xy+y*z+z*x
            if M > N:
                break
            if x!=y:
                if y!=z:
                    cnts[M]+=6
                else:
                    cnts[M]+=3
            else:
                if y!=z:
                    cnts[M]+=3
                else:
                    cnts[M]+=1

for a in cnts[1:N+1]:
    print(a)
                         
                    


Measured memory_bytes: 9264