akhauriyash/Code-Regression huggingface dataset:
def bingo(A, B):
  for i in range(3):
    if A[i][0] == "o" and A[i][1] == "o" and A[i][2] == "o":
      return True
    elif A[0][i] == "o" and A[1][i] == "o" and A[2][i] == "o":
      return True
    
  if A[0][0] == "o" and A[1][1] == "o" and A[2][2] == "o":
    return True
  elif A[0][2] == "o" and A[1][1] == "o" and A[2][0] == "o":
    return True
    
  return False

A = []
for i in range(3):
  A.append(list(map(int, input().split())))
           
N = int(input())
B = []
for i in range(N):
  B.append(int(input()))

for b in B:
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        A[i][j] = "o"

if bingo(A, B):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
main(){for(;;){int i,n,m,h=0,t,e[1000],b[1000];cin>>n>>m;if(n==0){break;}for(i=0;i<n;i++){cin>>b[i];}for(i=0;i<m;i++){cin>>e[i];}for(i=0;i<m;i++){h+=e[i];if(h>=n){i++;break;}t=h;h+=b[t];if(h>=n){i++;break;}}cout<<i<<endl;}}

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

int main(){
	LL N;
	cin >> N;
	string s, ans="";
	s = "abcdefghijklmnopqrstuvwxyz";
	while(N){
		if(N%26==0){
			--N;
			ans += s[N%26];
		}
		else{
			ans += s[(N%26)-1];
		}
		N /= 26;
		
	}
	reverse(begin(ans),end(ans));
	cout << ans << endl;
}














Measured memory_bytes: 3620
import java.awt.*;
import java.awt.geom.*;
import java.io.*;
import java.util.*;

public class Main{
  public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    String str;
    int num[] = new int[26];
    while(in.hasNextLine()){
      str = in.nextLine();
      char [] cin = str.toCharArray();
      for(int i=0;i<cin.length;++i){
        cin[i]=Character.toLowerCase(cin[i]);
        for(int j = 0; j < 27; j++){
          if(cin[i] == j+97){
            num[j]++;
          }
        }
      }
    }
    for(int k = 0; k < 26; k++){
      char c = (char)(k + 97);
      System.out.println(c + " " + ":" + " " +num[k]);
    }
  }
}



Measured memory_bytes: 26152
#include<stdio.h>
int main()
{
    int a,b,c,d,p1,p2;
    scanf("%d%d%d%d",&a,&b,&c,&d);

    if(a<c) p1=c;
    else p1=a;
    if(b<d) p2=b;
    else p2=d;
    if(b<c || a>d)
        printf("0\n");
    else
        printf("%d\n",p2-p1);
    return 0;


}


Measured memory_bytes: 128
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

const int MAXP = 100 * 500;
pair<int, int> dp[3][MAXP];
int solve_testcase() {
    int N; scanf("%d", &N);
    if(N == 0) return 1;

    vector<int> P(N);
    for(int i=0; i<N; i++) scanf("%d", &P[i]);

    auto update = [](pair<int, int> &A, pair<int, int> &B) {
        if(A.first < B.first) A = B;
        else if(A.first == B.first and A.second > B.second) A = B;
    };

    const pair<int, int> NIL(-1, INF);
    fill(dp[0], dp[2], NIL);
    dp[0][0] = make_pair(0, 0);
    for(int i=0; i<N; i++) {
        int p = P[i] % 1000;
        int cur = i % 2, nxt = 1 ^ cur;
        for(int j=0; j<MAXP; j++) {
            if(dp[cur][j] == NIL) continue;
            
            // 買わない
            update(dp[nxt][j], dp[cur][j]);

            {
                // 買う (小銭を調整しない)
                {
                    int x = -p, g = 0;
                    if(x < 0) x += 1000;
                    g += (x >= 500);
                    x %= 500;
                    pair<int, int> ndp(dp[cur][j].first + g,
                                       dp[cur][j].second + P[i]);
                    update(dp[nxt][j+x], ndp);
                }
                
                // 買う (小銭から 500 円使う)
                if(j >= 500) {
                    int x = 500 - p, g = 0;
                    if(x < 0) x += 1000;
                    g += (x >= 500);
                    x %= 500;
                    
                    pair<int, int> ndp(dp[cur][j].first + g,
                                       dp[cur][j].second + P[i]);
                    update(dp[nxt][j-500+x], ndp);
                }

                if(j < 500) {
                    int x = j - p, g = 0;
                    if(x < 0) x += 1000;
                    g += (x >= 500);
                    x %= 500;

                    pair<int, int> ndp(dp[cur][j].first + g,
                                       dp[cur][j].second + P[i]);
                    update(dp[nxt][x], ndp);
                }
            }

            dp[cur][j] = NIL;
        }
    }

    pair<int, int> ans = NIL;
    for(int i=0; i<MAXP; i++) {
        update(ans, dp[N%2][i]);
    }
    printf("%d %d\n", ans.first, ans.second);
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}



Measured memory_bytes: 3912
/*
[abc124] D - Handstand
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int N, K;
string S;

ll solve() {
    vector<pii> seq;
    int prev = 0;
    if (S[0] == '0') {
        seq.push_back({0, 0});
    }
    for (int i = 1; i < N; i++) {
        if (S[i - 1] == '0' && S[i] == '1') {
            prev = i;
        } else if (S[i - 1] == '1' && S[i] == '0') {
            seq.push_back({prev, i});
        }
    }
    if (S[N - 1] == '0') {
        seq.push_back({N, N});
    } else {
        seq.push_back({prev, N});
    }

    if ((int)seq.size() < K + 1) {
        return N;
    }

    int ans = 0;
    for (int i = 0; i + K < (int)seq.size(); i++) {
        ans = max(ans, seq[i + K].second - seq[i].first);
    }
    return ans;
}

int main() {
    cin >> N >> K;
    cin >> S;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int main(){
    int n;
    cin >> n;
    cout << n + n*n + n* n* n << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;


int main(void) {
	int n, i, j, a, b, c[10003], ans[10003], p, t, m;
	vector<int> g[10003];
	queue<int> q;
	bool u[10003] = { false };

	cin >> n;
	for (i = 0; i < n - 1; i++) {
		cin >> a >> b;
		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
	}

	for (i = 0; i < n; i++) {
		cin >> c[i];
	}

	sort(c, c + n, greater<int>());

	q.push(0);
	t = 0;
	m = 0;
	while (!q.empty()) {
		p = q.front();
		q.pop();
		u[p] = true;
		ans[p] = c[t++];
		for (i = 0; i < g[p].size(); i++) {
			if (!u[g[p][i]]) {
				q.push(g[p][i]);
			}
		}
		m += c[t];
	}

	cout << m << endl;
	for (i = 0; i < n; i++) {
		cout << ans[i] << ' ';
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf 1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
struct edge{int to,cost;};
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
signed main(){
    int  a,b,c,x,y;cin>>a>>b>>c>>x>>y;
    int cost=min(a+b,c*2);
    int mai=min(x,y);
    x-=mai,y-=mai;
    if(x){
        int last=min(a,c*2);
        cout<<cost*mai+last*x<<endl;
        return 0;
    }else if(y){
        int last=min(b,c*2);
        cout<<cost*mai+last*y<<endl;
        return 0;
    }
    cout<<cost*mai<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int solve(string s)
{
    int ret = 0;
    int S = s.size();

    vector<int> l(S+1),r(S+1);
    vector<int> rpos;
    rep(i,S)
    {
        if(s[i]=='>') rpos.pb(i);

        l[i+1] = l[i]+(s[i]=='<');
        r[i+1] = r[i]+(s[i]=='>');
    }

    rep(i,S)if(s[i]=='>')
    {
        int L=i, R=S+1;
        while(R-L>1)
        {
            int m = (L+R)/2;

            if(l[m] - l[i] <= r[i]) L=m;
            else R=m;
        }
        if(L<S) ret = max(ret,L+1);
        else
        {
            int idx = lower_bound(all(rpos),i)-rpos.begin();
            idx -= l[L]-l[i];
            ret = max(ret, S-rpos[idx]);
        }
    }

    return ret;
}

int main()
{
    int S;
    string s;
    cin >>S >>s;

    int ans = 0;
    ans = max(ans,solve(s));

    reverse(all(s));
    rep(i,S)
    {
        if(s[i]=='>') s[i]='<';
        else s[i]='>';
    }

    ans = max(ans,solve(s));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4360
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int main(void){
    int N;
    string S;
    cin >> N>>S;
    vector<int> ans(N+1);
    for (int i = 0; i < N; i++) {
        if(S.at(i)=='I') ans.at(i+1)=ans.at(i)+1;
        else ans.at(i+1)=ans.at(i)-1;
    }
    sort(ans.begin(),ans.end());
    cout << ans.at(N) << endl;
    return 0;
}

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

int main() {
    long long n;
    cin >> n;

    long long ans = LLONG_MAX;
    for(long long i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            long long a = n / i;
            long long b = i;
            if((a-1) + (b-1) < ans) {
                ans = a-1 + b-1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int N,K;
    
    scanf("%d%d",&N,&K);
    int a[N];
    for(int i=0;i<N;i++){
        scanf("%d",&a[i]);
        //cout<<a[3]<<endl;
    }
    int ans=0;
    for(int i=0;i<N;i++){
        ans+=min(a[i]*2,(K-a[i])*2);
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
   char s[4];

   scanf("%s",s);
   if (s[0]=='R' && s[1]=='R' && s[2]=='R') puts("3");
   else if ((s[0]=='R' && s[1]=='R') || (s[1]=='R' && s[2]=='R')) puts("2");
   else if (s[0]=='R' || s[1]=='R' || s[2]=='R') puts("1");
   else puts("0");
   return 0;
}


Measured memory_bytes: 1660
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> order_set;
const int MAXN = 3456;
const int MOD = 998244353;
int A[MAXN];
int dp[MAXN];
int ndp[MAXN];

int add(int a, int b) {
    int res = a + b;
    if (res >= MOD) res -= MOD;
    return res;
}

LL mul(LL a, LL b) {
    return (a * b) % MOD;
}

int main() {
    int N, S;
    scanf("%d %d", &N, &S);
    for (int i = 0; i < N; i++)
        scanf("%d", &A[i]);
    LL ans = 0;
    for (int i = 0; i < N; i++) {
        memset(ndp, 0, sizeof(ndp));
        for (int j = 0; j <= S; j++) {
            ndp[j] = dp[j];
            if (j >= A[i])
                ndp[j] = add(ndp[j], dp[j - A[i]]);
        }
        ndp[A[i]] = add(ndp[A[i]], i + 1);
        for (int j = 0; j <= S; j++)
            dp[j] = ndp[j];
        ans = add(ans, dp[S]);
    }
    printf("%lld\n", ans);
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
by Benq;
*/


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

typedef long long int ll;


int main()
{
    ll n, m;
    vector<ll> ans;
    while(1){
        cin >> n >> m;
        if(n == 0) break;
        vector<vector<ll> > p(m,vector<ll>(n));
        ll anst = 0;
        for(ll i = 0;i < m;i++){
            ll t = 0;
            for(ll j = 0;j < n;j++){
                cin >> p[i][j];
            }
        }

        for(ll i = 0;i < n;i++){
            ll t = 0;
            for(ll j = 0;j < m;j++){
                t += p[j][i];
            }
            anst = max(anst, t);
        }
        ans.push_back(anst);
    }

    for(ll i = 0;i < ans.size();i++){
        cout << ans[i] << "\n";
    }

    return 0;
}



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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int S = sc.nextInt();
		long MOD = 998244353;
		long dp[] = new long[S + 1];
//		dp[0] = 1;
		long p2 = 1;
		for(int i = 0 ; i < N; ++i){
			int a = sc.nextInt();
			long next[] = new long[S + 1];
			for(int x = 0 ; x < next.length ; ++x){
				long ret = 0;
				if(x == a){
					ret = 1;
				}
				if(x >= a){
					ret += dp[x -a];
				}
				ret += 2 * dp[x];
				ret = ret % MOD;
				next[x] = ret;
			}
			p2 = (p2 * 2) % MOD ;
			next[0] = (p2 + MOD - 1) % MOD;
			dp = next;
//			System.out.println(Arrays.toString(dp));
		}
		System.out.println(dp[S]);
	}
}


Measured memory_bytes: 55484
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;

bool bpm(vector<vector<int>> &bpGraph, int u, bool seen[], int matchR[]) 
{
    int M = bpGraph.size();
    int N = bpGraph[0].size();
    for (int v = 0; v < N; v++) 
    { 
        if (bpGraph[u][v] && !seen[v]) 
        { 
            seen[v] = true;  
            if (matchR[v] < 0 || bpm(bpGraph, matchR[v], seen, matchR)) 
            { 
                matchR[v] = u; 
                return true; 
            } 
        } 
    } 
    return false; 
} 
  
int maxBPM(vector<vector<int>> &bpGraph) 
{
    int M = bpGraph.size();
    int N = bpGraph[0].size();
    int matchR[N]; 
    memset(matchR, -1, sizeof(matchR)); 
    int result = 0;  
    for (int u = 0; u < M; u++) 
    {
        bool seen[N]; 
        memset(seen, 0, sizeof(seen)); 
        if (bpm(bpGraph, u, seen, matchR)) 
            result++; 
    } 
    return result; 
} 

int main()
{
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n),d(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    rep(i,n){
        cin >> c[i] >> d[i];
    }
    vector<vector<int>> g(n,vector<int>(n));
    rep(i,n){
        rep(j,n){
            if(a[i]<c[j] && b[i]<d[j]){
                g[i][j]=1;
            }
        }
    }
    cout << maxBPM(g);
}

Measured memory_bytes: 384
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

ll n,m;
ll tmp[100005] = {};

/*ll f(ll num){
    if(tmp[num] != 0)ret tmp[num];
    if(num == 0)ret tmp[0] = 1;
    ret tmp[num] = mod(num * f(num-1));
}*/
ll f(ll num){
    ll a = 1;
    rep(i,1,num+1)a = mod(a*i);
    ret a;
}
int main(){
    IN n >> m;
    if(abs(n-m) > 1){
        P(0);
        ret 0;
    }
   
    ll ans = mod(f(n) * f(m));

    if((n+m)&1)P(ans);
    else P(mod(ans * 2));
    
	return  0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    vector<vector<P>> g(n);
    for (int i = 0; i < n - 1; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        w %= 2;
        u--;
        v--;
        g[u].push_back(P(v, w));
        g[v].push_back(P(u, w));
    }
    vector<int> d(n, INF);
    queue<int> que;
    que.push(0);
    d[0] = 0;
    while (!que.empty())
    {
        int cur = que.front();
        que.pop();
        for (auto p : g[cur])
        {
            int dst = p.first, w = p.second;
            if (d[dst] != INF)
                continue;
            if (w == 0)
                d[dst] = d[cur];
            else
                d[dst] = 1 - d[cur];
            que.push(dst);
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << d[i] << endl;
    }
}


Measured memory_bytes: 6784
#include <iostream>
#include <cstdlib>

int main(){
  char s[4];
  std::cin >> s;
  const int N = atoi(s);
  int i = 0;
  int num = 1;
  while(num *2 <= N) {
    num *= 2;
    i++;
  }
  std::cout<<num<<std::endl;
  return 0;
    
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin>>N;
reps(n,N+1,1){
    ll r=sqrt(2*n);
    int cnt=0;
    reps(x,r+1,1){
        reps(y,r+1-x,1){
            ll b=x+y;
            ll c= x*x+ y*y + x*y-n;
            ll d=b*b-4*c;
            
            if(d>0&&ceil(sqrt(d)) == floor(sqrt(d))&&(-b+sqrt(d))>=1){
                cnt++;
            }
        }   
    }
    cout<<cnt<<endl;
}
return 0;
}

Measured memory_bytes: 3576
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		long N = stdIn.nextLong();
		long[] A = new long[(int)N];
		long sum = 0;
		for(int i = 0; i < N; i++) {
			A[i] = stdIn.nextLong();
			sum += A[i];
		}
		
		if(sum%2 == 0) {
			long x1 = 0;
			long x2 = 0;
			for(int i = 0; i < N; i++) {
				x1 += A[i];
				if(x1 == sum/2) {
					System.out.println(0);
					System.exit(0);
				}
				else if(x1 < sum/2 && x1+A[i+1] > sum/2) {
					x2 = x1+A[i+1];
					break;
				}
			}
			System.out.println(Math.min(sum-2*x1,2*x2-sum));
		}
		else {
			long x1 = 0;
			long x2 = 0;
			for(int i = 0; i < N; i++) {
				x1 += A[i];
				if(x1 < sum/2 && x1+A[i+1] > sum/2) {
					x2 = x1+A[i+1];
					break;
				}
			}
			System.out.println(Math.min(sum-2*x1,2*x2-sum));
		}

	}

}

Measured memory_bytes: 88032
let () =
  let s = read_line () and
      stack = Stack.create () and
      stack2 = Stack.create ()
  in
  let len = String.length s in
  let rec loop total = function
      i when i = len -> total
    | i ->
       if s.[i] = '\\' then
         begin Stack.push i stack;loop total (i+1) end
       else if s.[i] = '/' && not (Stack.is_empty stack) then
         let j = Stack.pop stack in
         let rec loop2 subtotal =
           if Stack.is_empty stack2 then
             Stack.push (j,subtotal) stack2
           else
             let (id,area) = Stack.top stack2 in
             if id <= j then
               Stack.push (j,subtotal) stack2
             else
               begin
                 let (id,area) = Stack.pop stack2 in
                 loop2 (subtotal+area)
               end
         in
         loop2 (i-j);
         loop (total + i-j) (i+1)
       else
         loop total (i+1)
  in
  Printf.printf "%d\n" (loop 0 0);
  Printf.printf "%d" (Stack.length stack2);
  let st = Stack.create () in
  Stack.iter (fun x -> Stack.push (snd x) st) stack2;
  Stack.iter (fun x -> Printf.printf " %d" x) st;print_newline ()
;;

Measured memory_bytes: 3400
function countRGB(s)
    numR = numG = numB = 0
    for c in s
        if c == 'R'
            numR += 1
        elseif c == 'G'
            numG += 1
        elseif c == 'B'
            numB += 1
        end
    end
    (numR, numG, numB)
end

function numequaldistance(s)
    ret = 0
    for i = 1:length(s)-2
        for d = 1:(length(s)-i)÷2
            j = i+d
            k = j+d
            if s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
                ret += 1
            end
        end
    end
    ret
end

function solve()
    readline()
    s = readline()
    numR, numG, numB = countRGB(s)
    ned = numequaldistance(s)
    numR*numG*numB - ned
end

println(solve())

Measured memory_bytes: 161180
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int t = sc.nextInt();
		
		int res = 0;
		
		for(int i = a; i <= t+0.5; i+=a) {
			res+=b;
		}
		System.out.println(res);
	}

}


Measured memory_bytes: 23764
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int E = sc.nextInt();
		int F = sc.nextInt();
		sc.close();
		ArrayList<Integer> x = new ArrayList<Integer>();
		for(int i=0; i*A*100<=F; i++) {
			for(int j=0; j*B*100<=F; j++) {
				x.add(100*A*i+100*B*j);
			}
		}
		ArrayList<Integer> y = new ArrayList<Integer>();
		for(int i=0; i*C<=F; i++) {
			for(int j=0; j*D<=F; j++) {
				y.add(C*i+D*j);
			}
		}
		int maxtotal = 100*A;
		int maxs = 0;
		double maxper = 0;
		for(int i=0; i<x.size(); i++) {
			for(int j=0; j<y.size(); j++) {
				int amounts = y.get(j);
				int amountw = x.get(i);
				if(amounts == 0 && amountw == 0) continue;
				if(amounts+amountw<=F && 100*amounts <= E*amountw) {
					if((double)amounts/(double)(amounts+amountw) > maxper) {
						maxtotal = amounts + amountw;
						maxs = amounts;
						maxper = (double)(amounts)/(amounts+amountw);
					}
				}
			}
		}
//		OUTER: for(int a=0; a<=N; a++) {
//			OUTERb: for(int b=0; b<=N; b++) {
//				if(A*a+B*b > F/100) break OUTERb;
//				INNER: for(int c=0; c<=N; c++) {
//					int d = N - a - b - c;
//					if(d < 0) break INNER;
//					if(C*c + D*d>F*E/(100+E)) break INNER;
//					if(((A*a+B*b)*E >= C*c+D*d) && (100*A*a+100*B*b+C*c+D*d <= F)) {
//						int temptotal = 100*A*a + 100*B*b+C*c+D*d;
//						int temps = C*c + D*d;
//						double tempper = (double)(100*temps)/temptotal;
//						if(maxper < tempper) {
//							maxtotal = temptotal;
//							maxs = temps;
//							maxper = tempper;
//						}
//					}
//				}
//			}
//		}
		System.out.println(maxtotal + " " + maxs);
	}

}

Measured memory_bytes: 35028
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;

const int mod = 1000000007;
struct mint
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

struct combination
{
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1)
    {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i)
            fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i)
            ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k)
    {
        if (k < 0 || k > n)
            return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
} c(200010);

int main()
{
    int N;
    cin >> N;
    long long X;
    cin >> X;
    long long res = 0;
    for (int i = 0; i < N; ++i)
    {
        long long x;
        cin >> x;
        res = __gcd(res, abs(x - X));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3328
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    REP(x,4){
        vint a(n);
        a[0] = (x&1);
        a[1] = ((x>>1)&1);
        for(ll i=1;i<n-1;++i){
            if(a[i]==0){
                if(s[i]=='o'){
                    a[i+1] = a[i-1];
                }else{
                    a[i+1] = 1-a[i-1];
                }
            }else{
                if(s[i]=='o'){
                    a[i+1] = 1-a[i-1];
                }else{
                    a[i+1] = a[i-1];
                }
            }
        }
        if((a[0]==0&&s[0]=='o')||(a[0]==1&&s[0]=='x')){
            if(a[1]!=a[n-1]) continue;
        }
        if((a[0]==0&&s[0]=='x')||(a[0]==1&&s[0]=='o')){
            if(a[1]==a[n-1]) continue;
        }
        if((a[n-1]==0&&s[n-1]=='o')||(a[n-1]==1&&s[n-1]=='x')){
            if(a[0]!=a[n-2]) continue;
        }
        if((a[n-1]==0&&s[n-1]=='x')||(a[n-1]==1&&s[n-1]=='o')){
            if(a[0]==a[n-2]) continue;
        }
        string sw = "SW";
        REP(i,n){
            cout << sw[a[i]];
        }
        cout << endl;
        return 0;
    }
    cout << -1 << endl;
    return 0;
}

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

#define FOR(i, a, b) for(int(i)=(a);(i)<(b);(i)++)
#define REP(i, n) FOR((i), 0, (n))

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair 

using namespace std;

const int INF=INT_MAX/4;
const long MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
	if(debug_flag){
		cout<<str<<endl;
	}
}

void debugs(string str){
	if(debug_flag){
		cout<<str;
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.precision(10);

	int n, m;
	cin>>n>>m;

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

	vector<long> y(m);
	for(int i=0; i<m; i++){
		cin>>y[i];
	}

	long X=0;
	for(int i=0; i<n; i++){
		X+=(i-n+i+1)*x[i];
		X%=MOD;
	}

	long Y=0;
	for(int i=0; i<m; i++){
		Y+=(i-m+i+1)*y[i];
		Y%=MOD;
	}

	cout<<(X*Y)%MOD<<endl;

	return 0;
}


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#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()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int n, m;
vector< vector<int> > g;
vector<bool> done;

void dfs(int v){
    done[v] = true;
    for(auto x : g[v]){
        if(!done[x]){
            dfs(x);
        }
    }
    return;
}

int main(){
    cin >> n >> m;
    g.resize(n + m);
    done.resize(n + m);
    rep(i, n){
        int k;
        cin >> k;
        rep(j, k){
            int l;
            cin >> l;
            --l;
            g[i].push_back(n + l);
            g[n + l].push_back(i);
        }
    }
    dfs(0);
    bool flag = true;
    rep(i, n){
        flag &= done[i];
    }
    if(flag){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

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

int main()
{

        int o, t, p, i;
        cin >> o >> t;
        while((o!=0) || (t!=0)){
                if(t<o){
                        p=0;
                        p=o;
                        o=t;
                        t=p;
                        cout << o << " " << t << endl;
                }
                else
                cout << o << " " << t << endl;
                cin >> o >> t;
        }
}



Measured memory_bytes: 3108
#include<stdio.h>

#define MAX 100000

int partition(int *,int ,int );

int main(){
  int i,j,n,p,A[MAX];

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);

  p = partition(A,0,n-1);

  for(i=0;i<n;i++){
    if(i == p)printf("[%d]",A[i]);
    else printf("%d",A[i]);
    if(i<n-1)printf(" ");
  }
  printf("\n");
  return 0;
}

int partition(int *A,int  p,int  r){
  int i,j,x,tmp;

  x = A[r];

  i = p-1;

  for (j = p; j<= r-1;j++){
    if (A[j] <= x){
      i = i+1;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }

  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;

  return i+1;
}

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

long long MOD = 1e9+7;
int MAX_INT = 1e9;

long long gcd(long long a, long long b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int N;
  cin >> N;
  vector<char> c(N), d(N);
  for(int i = 0; i < N; i++) {
    cin >> c[i];
  }
  int red = 0, white = 0;
  for(int i = 0; i < N; i++) {
    red += (c[i] == 'R');
  }
  for(int i = 0; i < red; i++) {
    white += (c[i] == 'W');
  }
  cout << white << endl;
  return 0;
}


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

#define ll long long
#define llu unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define fill(x,v) fill(all(x), v)
#define sumv(v) accumulate(all(v), 0LL)
#define bitcount(x) __builtin_popcount(x)
#define present(v,x) ((v).find(x) != (v).end())
#define cpresent(v,x) (find(all(v),x) != (v).end())
#define v2(type, v, n, m) vector<vector<type>> v(n, vector<type>(m))
#define v3(type, v, x, y, z) vector<vector<vector<type>>> v(x, vector<vector<type>>(y, vector<type>(z)))
#define unique(v) {sort(all(v)); v.resize(unique(all(v))-v.begin());}

// const int MOD = 1000000007;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-6;

#define cerr cout
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
string to_string(_Bit_reference b) { return (b ? "true" : "false");}
void debug_out() { cerr << ""; }
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(v, n) {for(int j=0; j<n; j++){debug_out(v[j]); if(j<n-1) cerr<<",";}}
#define dbg(...) {cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); { cerr << endl; }}
#define dbg1d(v, n) {cerr << "[" << #v << "]: {"; pr(v, n); {cerr << " }" << endl;}}
#define dbg2d(v, n, m) {cerr<<"["<<#v<<"]:"<<endl;{for(int i=0; i<n; i++){cerr<<right<<setw(10)<<"["+to_string(i)+"] {";pr(v[i],m);{cerr<<" }"<<endl;}}}}
#define shout()  {cerr << "I'm Here...!!!" << endl;}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
random_device rd; mt19937 mt(rd()); uniform_int_distribution<long long> mtrng(1,LONG_LONG_MAX);
inline long long myRand() {return mtrng(mt);}

inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = (n%p) * (n%p) % p;} return r;}
inline int inv(ll a, int p = MOD) {return fpow(a, p - 2, p);}
inline int addmod(int a, int val, int p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline int submod(int a, int val, int p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n, k;
	cin >> n >> k;

	n %= k;
	cout << min(n, k-n) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

int n,H,W;
int memo[65536];
int visi[65536];
int Q[65537];
int head = 0 , size = 0;
vector< pair<int,int> > mask;

vector< vector<char> > goal(4,vector<char>(4));

int w[20],h[20];

inline void gen(int s,int x,int y){
	rep(k,3){
		int a=0,b=0;
		rep(i,h[s]){
			rep(j,w[s]){
				int tx = x + j;
				int ty = y + i;
				if(tx >= 0 && tx < 4 && ty < 4 && ty >= 0){
						a |= 1<<(ty*4+tx);
						b |= (goal[ty][tx] == k)<<(ty*4+tx);
				}
			}
		}
		mask.push_back(make_pair(a,b));
	}
}
int f(int init){
	Q[size++] = init;
	memo[init] = 0;
	int good = (1<<16)-1;
	while(head < size){
		int q = Q[head++];
		int cost = memo[q];
		if(good == q) return cost;
		
		rep(i,mask.size()){
			int bit = (q & ~mask[i].first) | mask[i].second;
			if(!visi[bit]){
				visi[bit] = 1;
				memo[bit] = cost + 1;
				Q[size++] = bit;
			}
		}
	}
	

}

int main(){
	cin >> n;
	rep(i,n) cin >> h[i] >> w[i];
	rep(i,4)rep(j,4){
		char c;cin >> c;
		if(c=='R')c = 0;
		if(c=='G')c = 1;
		if(c=='B')c = 2;
		goal[i][j] = c;
	}
	rep(k,n){
		rep(i,7)rep(j,7){
			gen(k,i-3,j-3);
		}
	}
	sort(mask.begin(),mask.end());
	mask.erase(unique(mask.begin(),mask.end()),mask.end());
	
	cout << f(0) << endl;
	
	
}

Measured memory_bytes: 1696
from collections import deque

N,M =map(int,input().split())
graph=[[] for _ in range(N)]

for _ in range(M):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    graph[a].append(b)
    graph[b].append(a)

dist=[-1]*N
pre=[-1]*N
dist[0]=0

q=deque()
q.append(0)

while q:
    v=q.popleft()
    for i in graph[v]:
        if dist[i] != -1:
            continue
        else:
            dist[i]=dist[v]+1
            pre[i]=v
            q.append(i)

print("Yes")
for i in range(1,N):
    print(pre[i]+1)

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

int main(){
  ll n,N,f,ans=1,p[168]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997};
  cin>>N;
  fr(i,168){
    n=N;f=1;
    while(n){
      n/=p[i];
      f+=n;
    }
    ans*=f;
    ans%=1000000007;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main() {
  char a,b;
  cin >> a >> b;
  int ret = a - b;
  if(ret > 0) {
    cout << ">" << endl;
  } else if(ret < 0) {
    cout << "<" << endl;
  } else {
    cout << "=" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

int x[4],y[4];
bool board[4][4];

int solve(int cnt){
    int i, j, k, res = 0;

    if( cnt == 8 ) return 1;

    bool f = false;
    rep(i,4){
        rep(j,4){
            if( !board[i][j] ){
                f = true; break;
            }
        }
        if( f ) break;
    }

    rep(k,4){
        int tx = j + x[k];
        int ty = i + y[k];
        if( tx < 0 || tx >= 4 || ty >= 4 || ty < 0 || board[ty][tx] ) continue;
        board[i][j] = board[ty][tx] = true;
        res += solve(cnt+1);
        board[i][j] = board[ty][tx] = false;
    }
    return res;
}

int main(){

    while( scanf("%d %d %d %d %d %d %d %d",x,y,x+1,y+1,x+2,y+2,x+3,y+3) != 1 ){
        memset(board, false, sizeof(board));
        cout << solve(0) << endl;
    }
    return 0;
}

Measured memory_bytes: 0
func readIntArray() -> [Int] {
    readLine()!.split(separator: " ").map({Int($0)!})
}

func readIntPair() -> (Int, Int) {
    let line = readLine()!.split(separator: " ").map({Int($0)!})
    return (line[0], line[1])
}

let N = Int(readLine()!)!
let A = readIntArray()
let Q = Int(readLine()!)!

var count = Array(repeating: 0, count: 100001)
var sum = 0
A.forEach({
    count[$0] += 1
    sum += $0
})
var ans: [Int] = []
(1...Q).forEach({ _ in
    let (B, C) = readIntPair()
    sum += (C - B) * count[B]
    count[C] += count[B]
    count[B] = 0
    ans.append(sum)
})

ans.forEach({
    print($0)
})


Measured memory_bytes: 12596
from heapq import heapify, heappush, heappop

N = int(input())
As, Bs = [], []
for _ in range(N):
    A, B = map(int, input().split())
    As.append(A)
    Bs.append(B)

PQ = [(-A-B, i) for i, (A, B) in enumerate(zip(As, Bs))]
heapify(PQ)

t = 1
hT = hA = 0
while PQ:
    H, i = heappop(PQ)
    if t % 2:
        hT += As[i]
    else:
        hA += Bs[i]
    t += 1

print(hT - hA)


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

ll N,P,A[2];
int main(){
    cin.tie(0),ios_base::sync_with_stdio(0);
    cin>>N>>P;
    for(int i{};i<N;++i){
        int a;cin>>a;
        ++A[a%2];
    }
    if(A[1])
        cout<<(1ll<<(N-1))<<endl;
    else
        cout<<(P?0:(1ll<<N))<<endl;
}


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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

struct mint {
    long long x;
    mint(long long x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
    	return *this;
    }
    mint& operator*=(const mint a) {
    	(x *= a.x) %= MOD;
        if(x < 0) x += MOD;
    	return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
    	if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
    	return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

void Main(){
    int N,X; cin >> N >> X;
    VI S(N); REP(i,N) cin >> S[i]; SORT(S);

    vector<mint> inv(N+1,0); REP(i,N) inv[i+1] = mint(i+1).pow(MOD-2);
    vector<vector<mint>> dp(N,vector<mint>(X+1)); REP(i,X+1) dp[0][i] = i%S[0];
    REP(i,N-1)REP(j,X+1){
        dp[i+1][j] = dp[i][j%S[i+1]]*inv[i+2] + dp[i][j]*(i+1)*inv[i+2];
    }

    vector<mint> fact(N+1); fact[0] = 1; REP(i,N) fact[i+1] = fact[i]*(i+1);
    mint ans = dp[N-1][X] * fact[N];
    cout << ans.x << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 160820
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>

using namespace std;

struct status{
	int correct, penalty, teamid;
	status():correct(0), penalty(0), teamid(0){}
};

bool cmpr(const status& a, const status& b){
	if(a.correct != b.correct)
		return a.correct > b.correct;
	else if(a.penalty != b.penalty)
		return a.penalty < b.penalty;
	else
		return a.teamid < b.teamid;
}

int main(){
	
	int t, p, r;
	int tried[64][16];
	
	while(cin>>t>>p>>r, (t||p||r)){
		
		vector<status> teams(t);
		memset(tried, 0, sizeof(tried));
		
		for(int i=0; i<t; ++i){
			teams[i].teamid=i+1;
		}
		
		for(int i=0; i<r; ++i){
			
			int tid, pid, time;
			string mes;
			
			cin>>tid>>pid>>time>>mes;
			tid--;
			
			if(mes == "CORRECT"){
				teams[tid].correct++;
				teams[tid].penalty+=tried[tid][pid]*1200+time;
			}
			else if(mes == "WRONG"){
				tried[tid][pid]++;
			}
		}
		
		sort(teams.begin(), teams.end(), cmpr);
		
		for(int i=0; i<t; ++i){
			cout << teams[i].teamid << " " << teams[i].correct
					<< " " << teams[i].penalty << endl;
		}
	}

	return 0;
}

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

int main(){
  int N;
  string S;
  
  cin >> N >> S;
  
  int count = 0;
  for(int i = 2; i < N; i++){
    if(S.at(i-2) == 'A'&& S.at(i-1) == 'B' && S.at(i) == 'C'){
      count+=1;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256