akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

struct Node {
  int key;
  Node *parent, *left, *right;
};

Node *NIL, *root = NIL;


void insert(int k) {
    Node *z,*y = NIL,*r = root;

    z = (Node*)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    if ( r == NIL ) {
        root = z;
        return;
    }

    while ( r != NIL ) {
        y = r;
        if ( k < r->key) r = r->left;
        else r = r->right;
    }

    z->parent = y;
    if ( k < y->key ) y->left = z;
    else y->right = z;
}

void inorder(Node*u) {
    if ( u == NIL ) return;
    inorder(u->left);
    cout << ' ' << u->key;
    inorder(u->right);
}

void preorder(Node *u) {
    if ( u == NIL ) return;
    cout << ' ' << u->key;
    preorder(u->left);
    preorder(u->right);
}


int main() {
    int n,i,temp;
    char a[20];
   cin >> n;
    for ( i = 0; i < n; i++ ) {
        cin >> a;
        if ( strcmp(a,"insert") == 0 ) {
             scanf("%d",&temp);
            insert(temp);
        }
        else {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }

}



Measured memory_bytes: 26572
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << endl;
}

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

main()
{
    int res=0, cnt=0;
    string s;
    cin>>s;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T') cnt++;
        else cnt=0;
        res=max(res, cnt);
    }
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;
 
#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f              first                 
#define  s              second
#define  endl           "\n"
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;            
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;
 
const ll   N     =  3e5+5;
const ll   mod   =  1e9+7;
const ll   INF   =  1e18;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, n;
multiset <pair<ll,pll>, greater<>> s;
vector <pair<ll,pll>> val[N];

void solve(){
	s.clear();
	cin>>n;
	for(int i = 1; i <= n; i++){
		ll l,r,k;
		cin>>k>>l>>r;
		val[k].pb({l-r,{l,k}});
	}
	ll ans = 0, ct = 0;
	for(int i = n; i > 0; i--){
		for(auto it : val[i]) s.insert(it);
		if(s.size() == 0) continue;
		if((*s.begin()).f < 0) continue;
		ans += (*s.begin()).s.f;
		s.erase(s.begin());
		ct++;
	}
	for(int i = 1; i <= n; i++) val[i].clear();
	for(auto it : s){
		val[it.s.s+1].pb({-it.f,{it.s.f-it.f,it.s.s}});
	}
	s.clear();
	for(int i = 1; i <= n; i++){
		for(auto it : val[i]) s.insert(it);
		if(i <= ct) continue;
		if(s.size() == 0) continue;
		ans += (*s.begin()).s.f;
		s.erase(s.begin());
	}
	for(auto it : val[n+1]) s.insert(it);
	for(auto it : s) ans += it.s.f-it.f;
	deb1(ans)
	for(int i = 1; i <= n+1; i++) val[i].clear();
}

int main(){
	fastio;
	cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
}

Measured memory_bytes: 25520
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int H, W, D, Q;
int A[310][310], L[101010], R[101010];

map<int, pair<ll, ll> > m;
ll dp[90010];  //dp[i][j]: 数値 i から i + D*j へのコスト
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>H>>W>>D;
    REP(i,0,H){
        REP(j,0,W){
            cin>>A[i][j];
            m[A[i][j]] = make_pair((ll)i, (ll)j);
        }
    }
    cin>>Q;
    REP(i,0,Q){
        cin>>L[i]>>R[i];
    }

    for(int i = 1; i < H*W+1 - D; i++){
        dp[i+D] = abs(m[i].F - m[i+D].F) + abs(m[i].S - m[i+D].S);
    }
    for(int i = D+1; i < H*W+1; i++) {
        dp[i] += dp[i - D];
    }



    REP(i,0,Q){
        cout<<dp[R[i]] - dp[L[i]]<<endl;
    }

    return 0;
}


Measured memory_bytes: 8576
import java.util.Scanner;
import java.util.ArrayList;
class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
 
int N = scan.nextInt();
int M = scan.nextInt();
int H[] = new int[N];
int I[] = new int[N];
int peaks[] = new int[2];
int i;
int count = 0;

  for(i=0; i<N; i++){
    H[i]=scan.nextInt();
  }
  for(i=0; i<M; i++){
    peaks[0]=scan.nextInt();
    peaks[1]=scan.nextInt();
    if (H[peaks[0]-1] > H[peaks[1]-1]){
      I[peaks[1]-1]=1;
    }
    else if(H[peaks[0]-1] < H[peaks[1]-1]){
      I[peaks[0]-1]=1;
    }
    else{
      I[peaks[1]-1]=1;
      I[peaks[0]-1]=1;
    }
  }
  
  for(i=0; i<N; i++){
    if (I[i]==0){
      count += 1;
    }
    else{
    }
  }
  
  System.out.println(count);
 }
}

Measured memory_bytes: 60244
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int d[1001];

void hoge(int n) {
    int i = 2;
    while (n != 1) {
        while (n % i == 0) {
            n /= i;
            d[i]++;
        }
        i++;
    }
}

int main() {
    long n;
    cin >> n;
    for (int i = n; i >= 2; i--) hoge(i);
    long ans = 1;
    REPI(i,2,n+1) {
        if (d[i]) {
            ans *= d[i] + 1;
            ans %= MOD;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
import sys
input=sys.stdin.readline

fact = [1]
for i in range(1,8+1):
  fact.append(fact[i-1]*i)


def seq_to_index(seq):
  #print?g()
  seq_len=len(seq)
  unused_val=[i+1 for i in range(seq_len)]
  index=0
  for i in range(seq_len):
  #for i in reversed(range(0,seq_len)):
    ##print?g(i)
    #先頭の数字*それまでに通過してきた組み合わせ
    coeff = seq[i]
    coeff_index_in_unused = unused_val.index(coeff)
    index+=coeff_index_in_unused*fact[seq_len-1-i]
    #使用済みの数は削除
    #print?g(coeff,
    #unused_val,
    #coeff_index_in_unused,
    #index,
    #fact[seq_len - 1 - i])

    unused_val.remove(coeff)

  #print?g()
  return index
    
n=input()

P = list(map(int, input().split()))
Q = list(map(int, input().split()))

pindex=seq_to_index(P)
qindex=seq_to_index(Q)

#print?g(pindex)
#print?g(qindex)

print(qindex-pindex if qindex>pindex else pindex-qindex)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	static boolean memo[];
	static int ans, min;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long n = sc.nextLong();
		long a = Long.MAX_VALUE;
		for (int i = 0; i < 5; i++) {
			a = Math.min(a, sc.nextLong());
		}
		if (n % a == 0) {
			System.out.println(5 + n / a - 1);
		} else {
			System.out.println(5 + n / a);
		}
	}
}


Measured memory_bytes: 21844
#include<iostream>

int main () {
  int A, B;
  std::cin >> A >> B;
  if (A < B) {
    std::swap(A,B);  
  }
  if (A<=8 && B<=8) {
    std::cout << "Yay!" << std::endl;  
  }
  else {
    std::cout << ":(" << std::endl;
  }
}

Measured memory_bytes: 256
arr = [
  "* = ****","* =* ***","* =** **","* =*** *","* =**** ",
  " *= ****"," *=* ***"," *=** **"," *=*** *"," *=**** "
]

10000000.times do |i|
  s = gets
  break unless s
  puts "" if i!=0
  puts sprintf("%5d",s.to_i).split('').map{|i|arr[i.to_i].split ''}.transpose.map{|s|s.join}
end

Measured memory_bytes: 6168
#include<iostream>
#include<cstdio>
using namespace std;
bool yes[1001];
int main()
{
	int n,a,b,c,q,i;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a>>b>>c;
		if(b>a){q=a;a=b;b=q;}
		if(c>a){q=a;a=c;c=q;}
		if((a*a)==(b*b)+(c*c))yes[i]=true;
		else yes[i]=false;
	}
	for(i=1;i<=n;i++)
	{
		if(yes[i]==true)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;


int main(){
    int r,d,x;
    cin >> r >> d >> x;
    rep(i,10){
        cout << r*x-d << endl;
        x=r*x-d;
    }
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);


struct node{
    int index,life,cost;
    node(int index,int life,int cost):index(index),life(life),cost(cost){}
    bool operator<(const node& other)const{
        return cost>other.cost;
    }
};
const int MAX=INT_MAX/10;
const int NONE=-1;

int main(){
    int n,m,l,k,a,h;
    while(cin>>n>>m>>l>>k>>a>>h,n){
        vvi dist(n,vi(n,NONE));
		vi reito(n);
		REP(i,l){
			int r;
			cin>>r;
			reito[r]=1;
		}
		REP(i,n){
			dist[i][i]=0;
		}
        REP(i,k){
            int src,dst,d;
			cin>>src>>dst>>d;
            dist[src][dst]=d;
            dist[dst][src]=d;
        }
        
        priority_queue<node> q;
        q.push(node(a,m,0));
        vvi cost(n,vi(m+1,MAX));
        cost[a][m]=0;
        while(!q.empty()){
            node cnode=q.top();q.pop();
            if(cost[cnode.index][cnode.life]<cnode.cost){
                continue;
            }
			REP(charge,(reito[cnode.index]?m-cnode.life+1:1)){
				FOR(i,(!charge?0:cnode.index),(!charge?n:cnode.index+1)){
					if((charge>0&&cnode.index==i)||(charge==0&&i!=cnode.index&&dist[cnode.index][i]!=NONE)){
						int newlife=cnode.life+charge-dist[cnode.index][i];
						if(newlife>=0){
							int newcost=cnode.cost+dist[cnode.index][i]+charge;
							if(cost[i][newlife]>newcost){
								cost[i][newlife]=newcost;
								q.push(node(i,newlife,newcost));
							}
						}
					}
				}
            }
        }
		int ans=MAX;
		FOR(i,0,m+1){
			ans=min(ans,cost[h][i]);
		}
		if(ans==MAX){
			cout<<"Help!"<<endl;
		}else{
			cout<<ans<<endl;
		}
    }
}

Measured memory_bytes: 1380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
ll dp[22][1<<22];
ll mod = 1e9+7;
int n;
int a[23][23];
ll rec(int i,int j){
    if(dp[i][j]>=0){
        return dp[i][j];
    }
    if(i==n){
        return 1;
    }
    ll res = 0;
    for(int k = 0;k<n;k++){
        if(j&(1<<k)){
            continue;
        }
        if(a[i][k]){
            res += rec(i+1,j+(1<<k)); 
        }
    }
    return dp[i][j] = res%mod;
}
int main(){
    cin >> n;
    rep(i,n){
        rep(j,n){
            cin >> a[i][j];
        }
    }
    memset(dp,-1,sizeof(dp));
    dp[n][1<<n-1] = 1;
    cout << rec(0,0)<<endl;
    return 0;
}

Measured memory_bytes: 721280
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

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; }



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll K,T; cin>>K>>T;
  vector<ll> a(T); rep(i,T) cin>>a[i];
  
  if(T==1) {cout<<K-1<<'\n'; return 0;}
  ll now=-1;
  while(true){
    ll next;
    ll hoge=0;
    rep(j,T) if(j!=now&&chmax(hoge,a[j])) next=j;
    a[next]--; now=next;
    auto sa=a;
    sort(sa.rbegin(),sa.rend()); if(sa[1]==0) break;
  }
  
  cout<<max(*max_element(a.begin(),a.end())-1,0LL)<<'\n';
    
  return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<map>
#include<math.h>
#include<queue>
#include<algorithm>
using namespace std;
int main() {
	string a, b;
	cin >> a >> b;
	int cnt = 0;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] != b[i])cnt++;
	}
	cout << cnt;
	return 0;
}

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

int main(){
    string S,T;
    cin >> S >> T;
    bool answer = true;

    for(int i = 0; i < S.size(); ++i){
        if(S.at(i) != T.at(i)) answer = false;
    }

    if(S.size() + 1 != T.size() ) answer = false;

    if(answer) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int di[8] = {599, 799, 999, 1199, 1399, 1599, 1799, 1999};

int main(){
  int X; cin >> X;
  for (int i = 0; i < 8; i++){
    if (X <= di[i]){
      cout << 8 - i << endl;
      return 0;
    }
  }


  return 0;
}


Measured memory_bytes: 3592
from collections import deque
from collections import defaultdict
N, M = map(int, input().split())
d = [0]*N
G = defaultdict(list)
for i in range(N-1+M):
    s, t = map(int, input().split())
    d[t-1] += 1
    G[s-1].append(t-1)
q = deque([])
for i in range(N):
    if d[i] == 0:
        q.append(i)
rank = [0]*N
ans = [0]*N
while q:
    s = q.popleft()
    for t in G[s]:
        d[t] -= 1
        if d[t] == 0:
            rank[t] = rank[s]+1
            q.append(t)
for i in range(N):
    for x in G[i]:
        if rank[x] - rank[i] == 1:
            ans[x] = i+1
for x in ans:
    print(x)

Measured memory_bytes: 78676
#include <iostream>
using namespace std;
int main(void){
    int a, b;
    cin >> a >> b;
    for(int c : {1, 2, 3}){
        if((a*b*c) % 2 == 1){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}


Measured memory_bytes: 768
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	char lc1Buf[1024];

	// A, B - 取得
	long long llA;
	double ldB;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%lld%lf", &llA, &ldB);

	// 計算
	long long llVal = (llA * (long long)(ldB * 100.0 + 0.5)) / 100;

	// 出力
	sprintf(lc1Buf, "%lld\n", llVal);
	fOutLine(lc1Buf);

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 1768
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    int N;
    cin >> N;
    vector<int> p(N);
    REP(i, N) cin >> p[i];
    vector<int> q(N);
    REP(i, N) q[p[i]-1] = i;
    int ans = 0, tmp = 1;
    REP(i, N-1){
        if(q[i] < q[i+1]) tmp++;
        else{
            chmax(ans, tmp);
            tmp = 1;
        }
    }
    chmax(ans, tmp);
    ans = N - ans;
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int a, b;
	cin >> a >> b;
	cout << a / b << " " << a % b << " ";
	printf("%.05f\n", (double)a / b);
}


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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> row(H);
  rep(i, H) {
    cin >> row.at(i);
  }
  rep(i, W+2) {
    cout << "#";
  }
  cout<<endl;
  rep(i, H) {
    cout <<"#"<<row.at(i)<<"#"<< endl;
  }
  rep(i, W+2) {
    cout << "#";
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int a[100001];
int b[100001],c[100001];
int main()
{
	int n;
	scanf("%d",&n);
	c[0]=b[0]=a[0]=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
	}
	int flag=1;
	for(int i=1;i<=n;i++)
	{
		int s=a[i]-a[i-1];
		int x=(b[i]-b[i-1])+(c[i]-c[i-1]);
		if(s-x==0||(s-x)%2==0&&s-x>0)
		{
			continue;
		}
		else
		{
			flag=0;
			break;
		}
	}	
	if(flag)
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}

Measured memory_bytes: 1280
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7

m = max(A).bit_length()
cnt = 0
k = 1
for i in range(m):
    s = sum((v >> i) & 1 for v in A)
    cnt += s*(N-s)*k
    cnt %= MOD

    k *= 2
    k %= MOD

print(cnt)

Measured memory_bytes: 122808
N,M = list(map(int,input().split()))

if M//N < 10**7:
    for i in range(M//N,0,-1):
        if M % i ==0:
            break
    print(i)
else:
    for i in range(N,int(M**0.5)):
        if M % i == 0:
            break
    else:
        i = M
    print(M//i)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for(int i = 0; i < N; i++) cin >> h[i];

  int ans = 0;
  for (int i = 0; i < h.size(); i++) {
    if (h[i] >= K) ans++;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
a = input()
b = list(map(int,input().split()))

total = 0
for i in range(len(b) - 2):
  templist = [b[i], b[i+1], b[i+2]]
  if b[i+1] != max(templist) and b[i+1] != min(templist):
    total += 1

print(total)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
int n,b[4][2]={{0,0},{0,1},{1,0},{1,1}};
bool a[maxn];
string s;
bool check() {
    char c;
    if(a[0]){
        if(a[n-1]==a[1])   c = 'x';
        else c = 'o';
        if(s[0]!=c)  return false;
    }
    else{
        if(a[n-1]==a[1])  c = 'o';
        else   c = 'x';
        if(s[0]!=c) return false;
    }
    for(int i=1; i<n-1; i++){
        if(a[i]){
            if(a[i-1]==a[i+1])  c = 'x';
            else  c = 'o';
            if(s[i]!=c)  return false;
        }else{
            if(a[i-1]==a[i+1]) c = 'o';
            else c = 'x';
            if(s[i]!=c) return false;
        }
    }
    if(a[n-1]){
        if(a[n-2]==a[0])  c = 'x';
        else     c = 'o';
        if(s[n-1]!=c)   return false;
    }else{
        if(a[n-2]==a[0])   c = 'o';
        else      c = 'x';
        if(s[n-1]!=c)   return false;
    }
    return true;
}

void f(){
    for (int i=2;i<n;i++){
        if(a[i-1]==0 && s[i-1]=='o') a[i]=a[i-2];
        else if(a[i-1]==0 && s[i-1]=='x') a[i]=!a[i-2];
        else if(a[i-1]==1 && s[i-1]=='o') a[i]=!a[i-2];
        else a[i]=a[i-2];
    }
}
int main(){
    scanf("%d",&n);
    cin>>s;
    for (int i=0;i<4;i++){
        for (int j=0;j<2;j++){
            a[j]=b[i][j];
        }
        f();
        if(check()){
            for (int i=0;i<n;i++){
                if(!a[i]) printf("S");
                else printf("W");
            }
            printf("\n");
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}


Measured memory_bytes: 640
s=input()
n=len(s)
dp=[13*[0]for _ in range(n)]
if s[0]=="?":dp[0]=10*[1]+[0]*3
else:dp[0][int(s[0])]+=1
for i in range(1,n):
  if s[i]!="?":
    for j in range(13):
      dp[i][(j*10+int(s[i]))%13]=dp[i-1][j]
  else:
    for j in range(13):
      for k in range(10):
        dp[i][(j*10+k)%13]+=dp[i-1][j]
  for j in range(13):dp[i][j]%=10**9+7
print(dp[-1][5])

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  if (n % 2 != 0) {
    cout << "No" << endl;
  } else {
    string sub = s.substr(n/2,n/2);

    rep(i,n/2) {
      if (s[i] != sub[i]) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }
  return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1005;
const int inf=0x3f3f3f3f;
int h,w;
int ch,dh,cw,dw;
bool vis[maxn][maxn];
char mp[maxn][maxn];
int dis[maxn][maxn];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
bool border(int x,int y)
{
	if(x>=0&&x<h&&y>=0&&y<w)
		return true;
	return false;
}
struct node{
	int x,y,len;
	node(){}
	node(int a,int b,int c):x(a),y(b),len(c){}
	bool operator<(const node&o)const{
		return len>o.len;
	}
};
priority_queue<node> q;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    cin>>h>>w>>ch>>cw>>dh>>dw;
    for(int i=0;i<h;i++)
    	for(int j=0;j<w;j++)
    		cin>>mp[i][j];
    ch--;cw--;dh--;dw--;
    memset(vis,0,sizeof(vis));
    memset(dis,inf,sizeof(dis));
    dis[ch][cw]=0;
    q.push(node(ch,cw,dis[ch][cw]));
  //  cout<<q.top().x<<" "<<q.top().y<<endl;
    while(!q.empty())
    {
    	node nw=q.top();
    	q.pop();
    	vis[nw.x][nw.y]=true;
    	for(int i=0;i<4;i++)
    	{
    		int fx=nw.x+dx[i];
    		int fy=nw.y+dy[i];
//    		cout<<"nw.x:"<<nw.x<<" nw.y:"<<nw.y<<endl;
//    		cout<<"fx:"<<fx<<" fy:"<<fy<<endl;
    		if(border(fx,fy)&&mp[fx][fy]=='.'&&vis[fx][fy]==false)
    		{
    			if(dis[fx][fy]>nw.len)
    			{
    				q.push(node(fx,fy,nw.len));
//    				cout<<"nw.x:"<<nw.x<<" nw.y:"<<nw.y<<endl;
//    				cout<<"fx:"<<fx<<" fy:"<<fy<<endl;
    				dis[fx][fy]=nw.len;
  //  				cout<<dis[fx][fy]<<endl;
    			}
			}
		}
		for(int i=nw.x-2;i<=nw.x+2;i++)
		{
			for(int j=nw.y-2;j<=nw.y+2;j++)
			{
				if(border(i,j)&&mp[i][j]=='.'&&vis[i][j]==false)
				{
					if(dis[i][j]>nw.len+1)
					{
						q.push(node(i,j,nw.len+1));
//						cout<<"i:"<<i<<" j:"<<j<<endl;
						dis[i][j]=nw.len+1;
//						cout<<dis[i][j]<<endl;
					}
				}
			}
		}
	}
//	for(int i=0;i<h;i++)
//	{
//		for(int j=0;j<w;j++)
//			cout<<dis[i][j]<<" ";
//		cout<<endl;
//	}
	if(vis[dh][dw]==false)
		cout<<"-1"<<endl;
	else
		cout<<dis[dh][dw]<<endl;
	return 0;
}


Measured memory_bytes: 9636
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
ll cnt1=0,cnt2[200050]={0},cnt3=0;
ll n,m;
ll vis[200050]={0};
ll p;
char s[10];
int main()
{
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%lld%s",&p,s);
        if(!vis[p])
        {
            if(strcmp(s,"AC")==0)
            {
                cnt1++;
                cnt3+=cnt2[p];
                vis[p]=1;
            }
            else
            {
                cnt2[p]++;
            }
        }
    }
    printf("%lld %lld\n",cnt1,cnt3);
}


Measured memory_bytes: 1664
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  VI ns(4);
  FOR(n,ns) {
    cin >> n;
  }
  sort(ns.begin(), ns.end());
  cout << (ns[0] == 1 && ns[1] == 4 && ns[2] == 7 && ns[3] == 9 ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 256
/*
 ╔═══╦═══╦═══╗
 ║╔═╗║╔══╩╗╔╗║
 ║║░║║╚══╗║║║║
 ║║░║║╔══╝║║║║
 ║╚═╝║╚══╦╝╚╝║
 ╚══╗╠═══╩═══╝
 ░░░╚╝░░░░░░░░
 */

#include <bits/stdc++.h>
#define ll					long long
#define MOD					1000000007
#define MAX					1e9
#define MIN                 -1e9
#define PI					acos(-1.0)
#define vi					vector<int>
#define vii					vector<vi>
#define vll					vector<ll>
#define mid(s,e)			(s+(e-s)/2)

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
template<typename T>
void printVec(const T &v, char sep=' ') {for (auto &i: v) cout << i << sep;}
template<typename T>
void printVecPair(const T &v, char sep=' ') {for (auto &i: v) cout << i.first <<" " << i.second<< sep;}


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else

#define debug(x...)
#endif



int main() {
	ios::sync_with_stdio(false);
 	cin.tie(0);
	int N,W;
	cin>>N>>W;
	vector<vector<ll>>dp(N+1,vector<ll>(W+1,0));
	int w[110], v[110];
	for(int i=0;i<N;i++) {
			cin>>w[i]>>v[i];
	}
	ll ans = 0;
	for(int i=1;i<=N;i++) {
			unsigned ll itemW = w[i-1];
			ll value = v[i-1];
			for(int j=0;j<=W;j++) {
					if(itemW > j) dp[i][j] = dp[i-1][j];
					else  {
							dp[i][j] = max(dp[i-1][j], value + dp[i-1][j-itemW]);
							ans = dp[i][j];
					}


			}
	}
	//debug(dp);
	cout<<dp[N][W];

	return 0;
}







Measured memory_bytes: 80256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
	}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int n,l;
    string c;
    vs s;
    cin >> n >> l;
    rep(i,n){
        cin >> c;
        s.pb(c);
    }
    sort(s.begin(),s.end());
    rep(i,n){
        cout << s[i];
    }
    cout << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n,x,y,ans;
bool s[100002];
inline void in(int &s){
	s=0;
	int f=1;
	char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0' && c<='9'){
		s=(s<<1)+(s<<3)+c-'0';
		c=getchar();
	}
	s*=f;
}
int main(){
	in(n);
	while(n--){
		in(x);in(y);
		for(int i=x;i<=y;++i) s[i]=1;
	}
	for(int i=1;i<=100000;++i) if(s[i]) ++ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
import sys
n = int(input())
A = [int(e)for e in sys.stdin]
cnt = 0
G = [int((2.15**i-1)/1.15)for i in range(18,0,-1)]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')


Measured memory_bytes: 53324
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)

main::IO()
main=do
  getLine
  as1 <- reverse . sort . map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
  let _:asp = scanr1 (+) as1 ++[0]
  print $ whileloop 1 as1 asp


whileloop::Int->[Int]->[Int]->Int
whileloop n [] []=n
whileloop n _ []=n
whileloop n [] _=n
whileloop n (x:xs) (y:ys)=if x>y*2
  then n
  else whileloop (n+1) xs ys
  
  

Measured memory_bytes: 25084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

int main()
{
    int n; cin >> n;
    ll z,w; cin >> z >> w;
    ll a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    if(n == 1){
        cout << abs(w-a[0]);
    }else{
        ll ans = 0;
        if(abs(a[n-2] - a[n-1]) > abs(a[n-1] - w)) {
            ans = abs(a[n-2] - a[n-1]);
        }else{
            ans = abs(a[n-1] - w);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	int h, w, size;
	int[][] map;
	boolean[][] bomb;
	P[] ps;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			h = sc.nextInt(); w = sc.nextInt();
			if((h|w) == 0) break;
			
			map = new int[h][w];
			bomb = new boolean[h][w];
			ArrayList<P> ps = new ArrayList<P>();
			for(int i=0;i<h;i++) {
				String l = sc.next();
				for(int j=0;j<w;j++) {
					switch ( l.charAt(j) ) {
						case '.': map[i][j] = -1; break;
						case '*': map[i][j] = 0;  break;
						default:  map[i][j] = l.charAt(j) - '0';
								  ps.add(new P(j, i));
					}
				}
			}
			
			this.ps = ps.toArray(new P[]{});
			size = ps.size();
			memo = new HashMap<Long, Integer>();
			pow10 = new long[size];
			pow10[0] = 100L; 
			long S = pow10[0] * map[this.ps[0].y][this.ps[0].x];
			for(int i=1;i<size;i++) {
				pow10[i] = pow10[i-1] * 10L;
				S += pow10[i] * map[this.ps[i].y][this.ps[i].x];
			}
//			debug(pow10);
			System.out.println(solve(S, 0));
		}
	}
	
	int[] dx = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
	int[] dy = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
	long[] pow10;
	HashMap<Long, Integer> memo;
	int solve(long S, int cnt) {
		int p = (int)(S % 100);
//		debug(S, cnt, p);
		if(memo.containsKey(S)) return memo.get(S);
		if(S % 100 == size) {
			if(S / 100 == 0) return 0;
			return INF;
		}
		
		if(cnt == 9) {
			if(S / pow10[p] % 10 == 0) {
				int ret = solve(S+1, 0);
				memo.put(S, ret);
				return ret;
			}
			else return INF;
		}
		
		int min = solve(S, cnt+1);
		int x = ps[p].x + dx[cnt], y = ps[p].y + dy[cnt];
		
		if(out(x, y) || bomb[y][x] || map[y][x] < 0) return min;
		long next = S;
		bomb[y][x] = true;
		
		boolean ng = false;
		for(int i=0;i<size;i++) for(int j=0;j<9;j++){
			int tx = x + dx[j], ty = y + dy[j];
			if(out(tx, ty)) continue;
			P tar = new P(tx, ty);
			if(!ps[i].isEquals(tar)) continue;
			if(next / pow10[i] % 10 > 0) next -= pow10[i];
			else ng = true;
		}

		if(!ng) min = min(min, solve(next, cnt+1) + 1);
		
		bomb[y][x] = false;
//		debug("", x, y, next, min);
		return min;
	}
	
	boolean out(int x, int y) {
		return x < 0 || y < 0 || x >= w || y >= h;
	}
	
	class P {
		int x, y;
		P(int x, int y) {
			this.x = x;
			this.y = y;
		}
		
		boolean isEquals(P p) {
			return x == p.x && y == p.y;
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 36160
n,m=map(int,input().split())
ll=0
rr=10**6
for i in range(m):
    l,r=map(int,input().split())
    if ll<l:
        ll=l
    if rr>r:
        rr=r
if rr-ll>=0:
    print(rr-ll+1)
else:
    print(0)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a+b==3)
        cout << 3;
    if(a+b==4)
        cout << 2;
    if(a+b==5)
        cout << 1;
    return 0;
}


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

using namespace std;

int main(void)
{
	string longest;
	string in;
	pair<string, int> times;
	map<string, int> mp;
	
	while(std::cin >> in){
		if(longest.size() < in.size()) longest = in;
		mp[in]++;
	}
	
	std::map<string, int>::iterator mp_first = mp.begin();
	for(;mp_first != mp.end(); ++mp_first){
		if(times.second < (mp_first -> second))
		times = *mp_first;
	}
	
	cout << times.first << ' ' << longest << endl;
	return 0;
}

Measured memory_bytes: 1192
def inpl(): return [int(i) for i in input().split()]
class UnionFind():
    def __init__(self, num):
        self.par = [-1 for _ in range(num)]
    
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            x = self.par[x]
            return self.find(x)
    
    def union(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        if rx != ry:
            if self.par[rx] < self.par[ry]:
                self.par[ry] = rx
            if self.par[rx] > self.par[ry]:
                self.par[rx] = ry
            else:
                self.par[rx] -= 1
                self.par[ry] = rx
        return

N = int(input())
V = [0 for _ in range(N)]
Edge = []
for i in range(N):
    x, y = inpl()
    V[i] = (x, y, i)
V = sorted(V, key = lambda x: x[0])
for i in range(N-1):
    Edge.append((V[i+1][0]-V[i][0],V[i+1][2],V[i][2]))
V = sorted(V, key = lambda x: x[1])
for i in range(N-1):
    Edge.append((V[i+1][1]-V[i][1],V[i+1][2],V[i][2]))

Edge = sorted(Edge, key = lambda x: -x[0])
U = UnionFind(N)
ctr = 0
ans = 0
while ctr != N-1:
    c,i,j = Edge.pop()
    if U.find(i) != U.find(j):
        U.union(i,j)
        ans += c
        ctr += 1
print(ans)

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

using namespace std;

using ll = long long;

using vi = vector<int>;
using vll = vector<ll>;

using pi = pair<int, int>;
using pll = pair<ll, ll>;

constexpr auto MOD = 1e9 + 7;
constexpr auto INF = 0x3f3f3f3f;

#define rep(i, a, b) for (auto i = a; i < b; ++i)

template <class T> inline T square(T x) { return x * x; };

template <class T> void print(const T &val) { cout << val << '\n'; }

template <class Iterator> void print(Iterator begin, Iterator end) {
  for (auto it = begin; it != end; ++it) {
    cout << *it << ' ';
  }

  cout << '\n';
}

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

  int n;
  cin >> n;
  int q;
  cin >> q;

  string s;
  cin >> s;

  vector<int> dp(n + 1, 0);

  for (auto i = 1; i < n; ++i) {
    dp[i] = dp[i - 1];
    if (s[i - 1] == 'A' && s[i] == 'C') {
      dp[i]++;
    }
  }

  for (auto i = 0; i < q; ++i) {
    int x, y;
    cin >> x >> y;

    print(dp[y - 1] - dp[x - 1]);
  }
}



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



int main(){
   int a,b;
   string op;
   cin >> a >> op >> b;
   if(op=="+"){
      cout << a+b <<endl;
   }
   else{
      cout <<a-b <<endl;
   }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import bisect
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, M: int):
    ds = []
    for i in range(1, int(ceil(sqrt(M))) + 1):
        if M % i == 0:
            ds.append(i)
            ds.append(M // i)
    ds.sort()
  
    th = M // N
    return ds[bisect.bisect(ds, th)-1]


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    result = solve(N, M)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5252
let () =
  Scanf.scanf "%d %d %d" @@ fun n m x ->
  let c = Array.init m (fun _ ->
    Scanf.scanf " %d" (fun v -> if v < x then 1 else 0))
    |> Array.fold_left (+) 0
  in Printf.printf "%d\n" (min c (m-c))

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


// ??\??? ????????¨???

typedef bool B;
typedef long double D;
typedef complex<D> P;
typedef vector<P> VP;
typedef struct {P s,t;} L;
typedef vector<L> VL;
typedef struct {P c;D r;} C;
typedef vector <C> VC;

const D eps=1.0e-10;
const D pi=acos(-1.0);
template<class T> bool operator==(T a, T b){return abs(a-b)< eps;}
template<class T> bool operator< (T a, T b){return a < b-eps;}
template<class T> bool operator<=(T a, T b){return a < b+eps;}
template<class T> int sig(T r) {return (r==0||r==-0) ? 0 : r > 0 ? 1 : -1;}
#define X real()
#define Y imag()

D ip(P a, P b) {return a.X * b.X + a.Y * b.Y;}
D ep(P a, P b) {return a.X * b.Y - a.Y * b.X;}
D sq(D a) {return sqrt(max(a, (D)0));}
P vec(L l){return l.t-l.s;}

// verify AOJ 2514
P proj(P b,P p){ return b*ip(b,p)/norm(b);}
P proj(L l,P p){ return l.s+proj(vec(l),p-l.s);}
P refl(L l,P p){ return proj(l,p)*D(2.0)-p; }

// ccw
enum CCW{
	FRONT = 1,
	RIGHT = 2,
	BACK = 4,
	LEFT = 8,
	MID = 16,
	ON=FRONT|BACK|MID
};

inline int ccw(P base, P a, P b) {              //???a??¨???b???????????????????????????
	a -= base; b -= base;
	if (ep(a, b) > 0)
		return LEFT;    // counter clockwise
	if (ep(a, b) < 0)
		return RIGHT;   // clockwise
	if (ip(a, b) < 0)
		return BACK;    // b--base--a on line
	if (norm(a) < norm(b))
		return FRONT;   // base--a--b on line
	// otherwise
	return MID;      // base--b--a on line  a??¨b????????????????????????
}

int main(void){
	L line;
	{
		D x[2],y[2];
		rep(i,2)cin >> x[i] >> y[i];
		line={{x[0],y[0]},{x[1],y[1]}};
	}
	int q;
	cin >> q;
	cout.precision(10);
	rep(loop,q){
		D x,y;
		cin >> x >> y;
		P point={x,y};
		P ans=proj(line,point);
		cout << fixed << ans.X << " " << ans.Y << endl;
	}
	return 0;
}

Measured memory_bytes: 1312
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h, w;
  cin >> h >> w;
  vector <string> a(h);
  for(int i; i<h; i++){
    cin >> a.at(i);
  }
  
  for(int i=0; i<h+2; i++){
    for(int j=0; j<w+2; j++){
      if(i==0||i==h+1||j==0||j==w+1){
        cout << "#";
      }
      else if(j==1){
        cout << a.at(i-1);
      }
    }
   cout << endl;}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define SIZE 4005

int max(int aa, int bb);

int main(void) {
    int a_len,b_len,itr,itrA,itrB,dp[4055][4055],tmp,piv_x,piv_y,piv_ans=0,ans_len;
    char a_str[4055],b_str[4055], ans[4055];
    memset(ans, '\0', sizeof(ans));
    scanf("%s %s",a_str,b_str);
    //配列の長さを取得
    a_len = strlen(a_str);
    b_len = strlen(b_str);
    //初期化
    for(itr = 0;itr <= a_len; itr++){
        dp[itr][0] = 0;
    }
    for(itr = 0;itr <= b_len; itr++){
        dp[0][itr] = 0;
    }
    /*
    dpの計算
    三通りあるので、それらの最大値を取る
    */
    for(itrA = 1;itrA <= a_len; itrA++){
        for(itrB = 1;itrB <= b_len; itrB++){
            dp[itrA][itrB] = max(dp[itrA][itrB-1],dp[itrA-1][itrB]);
            if(a_str[itrA-1]==b_str[itrB-1]){
                tmp = dp[itrA-1][itrB-1] + 1;
                dp[itrA][itrB] = max(dp[itrA][itrB],tmp);
            }
        }
    }
    //右下から探索を始める
    piv_x = a_len;
    piv_y = b_len;
    
    while(piv_x != 0 && piv_y != 0){
        if(dp[piv_x][piv_y] == dp[piv_x-1][piv_y]){
            piv_x--;
        }
        else if(dp[piv_x][piv_y] == dp[piv_x][piv_y-1]){
            piv_y--;
        }
        else{
            //左上なのでansに追加
            ans[piv_ans] = a_str[piv_x-1];
            piv_ans++;
            piv_y--;
        }
    }
    ans_len = strlen(ans);
    //反転しながら出力
    for(itr = ans_len-1;itr >= 0; itr--){
        printf("%c",ans[itr]);
    }
    printf("\n");
    
    return 0;
}
//maxを計算する関数
int max(int aa, int bb) {
    if (aa > bb)
        return aa;
    else
        return bb;
}


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

const int maxn = 110000;
const int mod = 998244353;

int d[maxn];
int cnt[maxn];

inline int modExp(int a, int n) {
	int b = 1;
	for(; n; n >>= 1) {
		if(n & 1) b = 1LL * b * a % mod;
		a = 1LL * a * a % mod;
	}
	return b;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for(int i = 1; i <= n; ++ i) {
		cin >> d[i];
		++ cnt[d[i]];
	}
	long long ans = 0;
	if(d[1] == 0 && cnt[0] == 1) {
		int last = 1, tot = 1;
		ans = 1;
		for(int i = 1; i <= n - 1; ++ i) {
			if(cnt[i] == 0) {
				ans = 0;
				break;
			}
			ans = (ans * modExp(last, cnt[i])) % mod;
			tot += cnt[i];
			last = cnt[i];
			if(tot == n) break;
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	float t,t1;
	while(scanf("%f %f",&t,&t1)!=EOF){
	if(t<35.50 && t1<71.00){
		printf("AAA\n");
	}
	else if(t<37.50 && t1<77.00){
		printf("AA\n");
	}
	else if(t<40.00 && t1<83.00){
		printf("A\n");
	}
	else if(t<43.00 && t1<89.00){
		printf("B\n");
	}
	else if(t<50.00 && t1<105.00){
		printf("C\n");
	}
	else if(t<55.00 && t1<116.00){
		printf("D\n");
	}
	else if(t<70.00 && t1<148.00){
		printf("E\n");
	}
	else{
		printf("NA\n");
	}
}
	return 0;
}

Measured memory_bytes: 1032
import queue
def main():
    n,m = map(int,input().split())
    ab = [[] for i in range(n)]
    for _ in range(m):
        a,b = map(int,input().split())
        ab[a-1].append(b-1)
        ab[b-1].append(a-1)
    q =queue.Queue()
    q.put(0)
    ans = [-1] * n
    ans[0] = 0
    while q:
        now = q.get()
        for i, next in enumerate(ab[now]):
            if ans[next] == -1:
                ans[next] = now+1
                q.put(next)
        if q.empty():
            break
    print('Yes')
    for i in range(1,n):
        print(ans[i])



if __name__=='__main__':
    main()


Measured memory_bytes: 37204
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
#define MOD (int)(1e9+7)
int x[100000];
int n;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)cin >> x[i];

	vector<int>index;
	int j = 0;
	for (int i = 1; i < n; i++) {
		if (x[i-1] >= 2 * j + 1)x[i-1] = 2 * j + 1;

		if(x[i]-x[i-1]==1){
			index.push_back(i+1);
			i++;
		}
		j++;
	}
	
	ll ans = 1;
	int cnt = 0;
	for (int i = 0; i < index.size(); i++) {
		ans *= ll(index[i]-cnt);
		ans %= MOD;
		cnt++;
	}
	for (ll i = n - cnt; i >= 1; i--) {
		ans *= i;
		ans %= MOD;
	}
	cout << ans%MOD << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); ++i)
#define rep1(i,n) for (int i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;
int main(){
  ll a; cin >> a;
  cout << (a<1000?"ABC":"ABD");
  return 0;
}


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

int main(){
    int N; cin>>N;
    vector<ll> A(N+1,0);
    rep(i,N) cin>>A[i];

    ll money=1000;
    ll kabu=0;
    ll m_max=1000;
    for(int i=0; i<N; i++){
        // 株が上がるなら買っておく
        if(A[i]<A[i+1]){
            kabu += money/A[i];
            money = money % A[i];
        }

        // 株が下がるなら売っておく
        if(A[i]>A[i+1]){
            money += kabu * A[i];
            kabu = 0;
            m_max = max(m_max, money);
        }
    }

    cout << m_max << endl;
}


Measured memory_bytes: 3628