akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 200005
vi G[MAX_N];
vi G_[MAX_N];
ll a[MAX_N];
int f[MAX_N];

ll dfs(int x){
    if(G[x].size()==0){
        return a[x];
    }else{
        ll ma = 0;
        ll sum = 0;
        rep(i,G[x].size()){
            ll tmp = dfs(G[x][i]);
            if(tmp == -1){
                return -1;
            }
            ma = max(tmp,ma);
            sum += tmp;
        }
        if(a[x] < ma){
            return -1;
        }
        if(a[x]*2 < sum){
            return -1;
        }
        if(sum < a[x]){
            return -1;
        }
        
        a[x] = 2*a[x] - sum;
        return a[x];
    }
}

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

    srep(i,1,n+1)cin >> a[i];

    rep(i,n-1){
        int x,y; cin >> x >> y;
        G_[x].push_back(y);
        G_[y].push_back(x);
    }

    // 親が葉の根付き木にする
    int root = 0;
    rep(i,n+1){
        if(G_[i].size()==1){
            root = i;
            break;
        }
    }

    queue<int> que;
    que.push(root);
    f[root] = 1;
    while(que.size()>0){
        int z = que.front();
        que.pop();
        f[z] = 1;
        rep(i,G_[z].size()){
            if(f[G_[z][i]] == 0){
                G[z].push_back(G_[z][i]);
                que.push(G_[z][i]);
            }
        }
    }

    ll ans = a[root];

    ll flag = dfs(root);

   

    if(flag == ans)yn;

    return 0;
}
 



Measured memory_bytes: 23552
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<stack>
#include<set>
using namespace std ;
using ll = long long ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using pll = pair<ll,ll> ;
ll INF = 1e15 ;
void chmin(ll &a,ll b){if(a>b) a = b ;}
void chmax(ll &a,ll b){if(a<b) a = b ;}
void YorN(bool a){cout << (a?"YES":"NO") << "\n" ;}

int main(){
	ll l ; cin >> l ;
	ll a = 0 ;
	ll sub = 1 ;
	while(sub<=l){
		a++ ;
		sub *= 2 ;
	}
	a-- ;
	ll n = a+1 ;
	ll m = 2*a ;
	for(int i=0;i<a;i++) if(l>>i&1) m++ ;
	vector<vector<pll>> g(n) ;
	for(int i=0;i<n-1;i++){
		g[n-2-i].emplace_back(n-1-i,0) ;
		g[n-2-i].emplace_back(n-1-i,1<<i) ;
	}
	a = 1<<n-1 ;
	for(int i=n-2;i>=0;i--){
		if(l>>i&1){
			g[0].emplace_back(n-1-i,a) ;
			a += 1<<i ;
		}
	}
	cout << n << " " << m << endl ;
	for(int i=0;i<n;i++){
		for(int j=0;j<g[i].size();j++){
			cout<< i+1 << " " << g[i][j].first+1 << " " << g[i][j].second << endl ; 
		}
	}
}

Measured memory_bytes: 3628
#!/usr/bin/env python3
import sys
# input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    S = input()
    answer = len(S)-1

    def is_even(s):
        if len(s)&1:
            return False
        
        half_length = len(s)//2
        if s[:half_length] == s[half_length:]:
            return True
        else:
            return False
    
    while True:
        S = S[:-1]
        if is_even(S):
            print(len(S))
            return
        
        answer -= 1
    return

if __name__ == '__main__':
    main()


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back

const int INF = 1e9;
const int MOD = 1e9+7;

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i++)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

//library----------------------------------------------

int main() {
    CIN(N);
    vector<int> v(N);
    map<int,int> mp;
    rep(i,N){
        cin>>v[i];
        mp[v[i]]++;
    }
    bool ok = true;
    RepA(mp){
        if(item.second>1) ok = false;
    }
    printf(ok?"YES":"NO");
    return 0;
}

Measured memory_bytes: 10368
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		in.close();
		int mod = 1000000007;
		List<Integer> list = new ArrayList<>();
		for(int i=2;i*i<=m;i++) {
			int count = 0;
			while(m%i==0) {
				m /= i;
				count++;
			}
			if(count!=0) {
				list.add(count);
			}
		}
		if(m>1) list.add(1);
		long ans = 1;
		for(int q : list) {
			ans = (ans * comb(n+q-1,q,mod)) % mod;
		}
		System.out.println(ans);
		

	}
	
	//return pCq % r
	public static long comb(int p,int q,int mod) {
		long ans = 1;
		for(int i=0;i<q;i++) {
			ans = (ans * ((p-i)%mod))%mod;
		}
		for(int i=2;i<=q;i++) {
			ans = (ans * powmod(i,mod-2,mod))%mod;
		}
		return ans;
	}
	
	public static int powmod(int base,int exp,int mod) {
		long ans = 1;
		while(exp>0) {
			if((exp&1)==1) {
				ans = (ans * base) % mod;
			}
			exp = exp>>1;
			base = (int) (((long)base * base) % mod);
		}
		return (int) ans;
	}

}


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

int main(){
	int  n;
	cin >> n;
	vector<ll> a(n+2);
	a[0] = 0;
	a[n+1] = 0;
	REP(i,n){
		cin >> a[i];
	}
	ll dist = 0;
	rep(i,n+1){
		dist += abs(a[i+1] - a[i]);
	}
	//a[i+1]をスキップする。
	ll temp = dist;
	rep(i,n){
		if(a[i] <= a[i+1] && a[i+1] <= a[i+2]){
			dist = dist;
		} else if (a[i+2] <= a[i+1] && a[i+1] <= a[i]) {
			dist = dist;
		} else if (a[i] <= a[i+2] && a[i+2] <= a[i+1]){
			dist -= 2*(a[i+1] - a[i+2]);
		} else if (a[i+1] <= a[i] && a[i] <= a[i+2]){
			dist -= 2*(a[i] - a[i+1]);
		} else if (a[i+1] <= a[i+2] && a[i+2] <= a[i]){
			dist -= 2*(a[i+2] - a[i+1]);
		} else if (a[i+2] <= a[i] && a[i] <= a[i+1]){
			dist -= 2*(a[i+1] - a[i]);
		}
		cout << dist << endl;
		dist = temp;
	}
	
    return 0;
}



Measured memory_bytes: 2048
n=int(input())
d,x=map(int,input().split())
a=[]
for i in range(n):
    a.append(int(input()))
ctr=0
for i in range(n):
    for k in range(101):
        if k*a[i]+1<=d:
            ctr+=1
        else:
            break
print(ctr+x)


Measured memory_bytes: 3060
N,K,Q = [int(i) for i in input().split()]
ppl = [0]*(N + 1)
for _ in range(Q):
    A = int(input())
    if A == 1:
        ppl[1] += 1
        if N != 2:
            ppl[-1] -= 1
    elif A == N:
        ppl[0] += 1
        if N != 2:
            ppl[-2] -= 1
    else:
        ppl[0] += 1
        ppl[A-1] -= 1
        ppl[A] += 1
        ppl[-1] -= 1
ans = ["Yes"] * N
ans[0] = "Yes" if ppl[0] < K else "No"
for i in range(1,N):
    ppl[i] += ppl[i-1]
    if ppl[i] >= K:
        ans[i] = "No"
print("\n".join(ans))

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

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

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

    int l;
    cin >> l;

    double a = (double)l / 3.0;

    cout << a * a * a << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int H[3000], W[3000], i, l, k, n;
  for(i=0;;i++){
    scanf("%d %d", &H[i], &W[i]);
    if(H[i]==0 && W[i]==0){
      break;
    }
  }
  n = i-1;
  for(i=0;i<=n;i++){
    for(l=0;l<H[i];l++){
      for(k=0;k<W[i];k++){
        if(l%2==1 && k%2==1){
          printf("#");
        }else if(l%2==1 && k%2==0){
          printf(".");
        }else if(l%2==0 && k%2==1){
          printf(".");
        }else if(l%2==0 && k%2==0){
          printf("#");
        }
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1808
#define _GLIBCXX_DEBUG
#include"bits/stdc++.h"

using namespace std;

//loops
#define REP(i,n) for(int i=0;i<(ll)(n);i++)
#define REPD(i,n) for(int i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(int i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(int i=0;i<(ll)(n+1);i++)
#define AToB(i,a,b) for(int i=a;i<(ll)(b+1);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back


#define remove_unique(v) v.erase(unique(ALL(v)), v.end())

//pair
#define fir first
#define sec second

//types
#define ll long long
#define vec vector
//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)

//output
void print(int a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T = int>
void print(vec<T> v){ cout << "["; for (T item: v) { cout << item << ", "; } cout << "]" << endl; }

template <class T = int>
void print2dVec(vec<vec<T>> v2d){for(vec<T> v: v2d) {print(v);}}

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"YES":"NO"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__
#define next next__
#define prev prev__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 10000007;

void Main() {
    //code here
    int x = gi;
    int res = floor(x/500.0)*1000;
    res +=  floor((x%500)/5)*5;
    print(res);
}

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define N 2

using namespace std;
void output_array_int(int*,int,char);
void input_array_int(int*,int);

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

int main(){
  int a[N];

  while(1){
    input_array_int(a,N);
    if(a[0]==0&&a[1]==0){
      break;
    }
    sort(a,a+N);
    output_array_int(a,N,' '); 
  }

  return 0;
}

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

void output_array_int(int * a,int n,char ch){
  int i;

  for(i=0;i<n;i++){
    cout<<*(a+i);
    if(i<(n-1)){
      cout<<ch;
    }
  }

  cout<<endl;

  return;
}

void input_array_int(int *a,int n){
  int i;

  for(i=0;i<n;i++){
    cin>>*(a+i);
  }
}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
int a[1000000];
signed main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int tmp=0;
    for(int i=0;i<n;i++)
        tmp=gcd(tmp,a[i]);
    if(tmp!=1){
        cout<<"not coprime"<<endl;
        return 0;
    }
    bool isp[1001]={};
    for(int i=2;i<=1000;i++)
        isp[i]=1;
    for(int i=2;i*i<=1000;i++)
        if(isp[i])
            for(int j=i*i;j<=1000;j+=i)
                isp[j]=0;
    int ps[168],cnt=0;
    for(int i=0;i<=1000;i++){
        if(isp[i]){
            ps[cnt]=i;
            cnt++;
        }
    }
    bool minps[168]={};
    set<int>maxps;
    for(int i=0;i<n;i++){
        int aa=a[i];
        for(int j=0;j<168;j++){
            if(ps[j]>aa)
                break;
            if(aa%ps[j]==0){
                if(minps[j]==1){
                    cout<<"setwise coprime"<<endl;
                    return 0;
                }
                minps[j]=1;
                while(aa%ps[j]==0)
                    aa/=ps[j];
            }
        }
        if(aa!=1){
            if(maxps.find(aa)!=maxps.end()){
                cout<<"setwise coprime"<<endl;
                return 0;
            }
            maxps.insert(aa);
        }
    }
    cout<<"pairwise coprime"<<endl;
}


Measured memory_bytes: 11312
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;

long long int gcd(long long int l, long long int r) {
	if (l > r)return gcd(r, l);
	else {
		if (r%l) {
			return gcd(l, r%l);

		}
		else {
			return l;
		}
	}
}
int dx[8] = { -1,-1,-1, 0, 1, 1, 1, 0 };
int dy[8] = { -1, 0, 1, 1, 1, 0,-1,-1 };

class Compare {
public:
	//keiroが昇順に並ぶ
	bool operator()(const string&l, const string&r) {
		return l.size() == r.size() ? l<r : l.size() < r.size();

	}
};


int main() {
	while (1) {
		int H, W; cin >> H >> W;
		if (!H)break;
		vector<string>field;
		for (int i = 0; i < H; ++i) {
			string st; cin >> st;
			field.push_back(st);
		}
		int ytime = H;
		int xtime = W;
		int yxtime = H*W/ gcd(H,W);
		map<string, int>mp;
		for (int y = 0; y < H; ++y) {
			for (int x = 0; x < W; ++x) {
				for (int i = 0; i < 8; ++i) {
					int ny(y);
					int nx(x);
					int atime;
					if (i % 2==0) {
						atime = yxtime;
					}
					else if (i == 1 || i == 5) {
						atime = xtime;
					}
					else {
						atime = ytime;
					}
					string nst;
					for (int k = 0; k < atime; ++k) {
						nst += field[ny][nx];
						if (k) {
							mp[nst]++;
						}
						ny = (ny + H + dy[i]) % H;
						nx = (nx + W + dx[i]) % W;
					}
				}
			}
		}
		string ans = "0";
		int num = 0;
		for (auto it = mp.begin(); it != mp.end(); ++it) {
			if (it->second >= 2) {
				if (num < it->first.size()) {
					ans = it->first;
					num = it->first.size();
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 38008
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


q = int(input())
ans = []
def sub(a,b):
    if a==b:
        ans = 2*a-2
    elif abs(a-b)==1:
        ans = min(a,b)*2-2
    else:
        l = 0
        r = a*b
        while l<r-1:
            m = (l+r)//2
            if m**2<a*b:
                l = m
            else:
                r = m
        a,b = max(a,b), min(a,b)
        ans = 2*l-2
        if l*(l+1)<a*b:
            ans += 1
    return ans
    
for i in range(q):
    a,b = map(int, input().split())
    ans.append(sub(a,b))
write("\n".join(map(str, ans)))

Measured memory_bytes: 39280
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int S, K, ans = 0;
	cin >> K >> S;
	for (int i = 0; i <= K; i++)
	{
		for (int j = 0; j <= K; j++)
		{
			if (i + j <= S&&S-i-j<=K)ans++;
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
N = int(input())
S = input()
S_list = list(S)
AR = [chr(ord("A") + i) for i in range(26)]

for i in range(len(S_list)):
    for j in range(26):
        if str(S_list[i]) == str(AR[j]):
            if j + N >= 26:
                S_list[i] = AR[j + N - 26]
                break
            else:
                S_list[i] = AR[j + N]
                break
S = "".join(S_list)
print(S)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <deque>
#include <sstream>
using namespace std;

#define namefile ""
#define inifile freopen(namefile".inp","r",stdin); freopen(namefile".out","w",stdout)
#define fastio ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef unsigned int uint;
typedef unsigned long ulong;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef vector<int> VI;
typedef vector<long> VL;
typedef vector<string> VS;
typedef vector< VI > VVI;
typedef vector< VL > VVL;
typedef vector< PII > VPII;
typedef vector< PLL > VPLL;
typedef set<int> SETI;
typedef set<long> SETL;
typedef map<int,int> MII;
typedef map<long,long> MLL;

const long long MOD = 1e9+7;
const long long INFMAX = 1e9;
const long long INFMIN = -1e9;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const double epsilon = 1e-9;
const double PI = acos(-1.00);

string s;

bool res(true);

int main()
{
    cin >> s;
    for (int i=0; i<s.size(); i++)
    {
        if ((i+1)%2)
        {
            if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') res = false;
        }
        else
        {
            if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') res = false;
        }
    }
    if (res) cout << "Yes"; else cout << "No";
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
from collections import deque
def main():
    #入力
    readline=stdin.readline
    n,q=map(int,readline().split())
    G=[[] for _ in range(n+1)]
    for i in range(n-1):
        a,b=map(int,readline().split())
        G[a].append(b)
        G[b].append(a)
    px=[0]*(n+1)
    for i in range(q):
        p,x=map(int,readline().split())
        px[p]+=x

    cnt=[0]*(n+1)
    flags=[False]*(n+1)
    d=deque([[1,px[1]]])
    while len(d)>0:
        now=d.pop()
        flags[now[0]]=True
        cnt[now[0]]=now[1]
        for nex in G[now[0]]:
            if flags[nex]==False:
                d.append([nex,now[1]+px[nex]])

    print(*cnt[1:])

if __name__=="__main__":
    main()

Measured memory_bytes: 73732
#include<iostream>
using namespace std;
int main(){
	int ans=0,n;
	cin >> n;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		for(;;){
			if(a%2==0){
				ans++;
				a/=2;
			}
			else break;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...) \
    { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 1000009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 1e9 + 7;
class {
   public:
    vector<int> pr;
    i64 eu[maxn];
    void init() {
        eu[1] = 1;
        for (int i = 2; i < 10000; ++i) {
            if (!eu[i])
                eu[i] = i - 1, pr.push_back(i);
            for (int j : pr) {
                if (1ll * j * i >= 10000)
                    break;
                if (i % j == 0) {
                    eu[i * j] = j * eu[i];
                    break;
                } else {
                    eu[i * j] = eu[i] * eu[j];
                }
            }
        }
    }
    i64 Max[maxn], A[maxn];
    void solve() {
        init();
        int n;
        cin >> n;
        for (int i = 0; i < n; ++i) {
            int a;
            cin >> a;
            A[i] = a;
            for (int j = 0; j < pr.size() && 1ll * pr[j] * pr[j] <= a; ++j) {
                if (a % pr[j] == 0) {
                    i64 cc = 0;
                    while (a % pr[j] == 0) a /= pr[j], cc++;
                    Max[pr[j]] = max(Max[pr[j]], cc);
                }
            }
            if (a != 1)
                Max[a] = max(Max[a], 1ll);
            ;
        }
        i64 Lcm = 1;
        for (int i = 0; i < maxn; ++i) {
            if (Max[i]) {
                while (Max[i]--) {
                    (Lcm *= i) %= MOD;
                }
            }
        }
        i64 ans = 0;
        for (int i = 0; i < n; ++i) {
            (ans += Lcm * pw(A[i], MOD - 2) % MOD) %= MOD;
        }
        cout << ans << '\n';
    }
    i64 pw(i64 a, i64 b) {
        i64 c = 1;
        while (b) {
            if (b & 1ll)
                c = c * a % MOD;
            a = a * a % MOD;
            b >>= 1;
        }
        return c;
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 10624
#include<iostream>
main(){int n,m,i,a,c[1000001];for(std::string s;std::cin>>n>>m>>s,n;printf("%d\n",a))for(a=0,i=m;--i;a+=c[i]>=n)c[i]=s.substr(i,3)=="IOI"?c[i+2]+1:0;}

Measured memory_bytes: 5840
from collections import defaultdict
N = int(input())

res = 0
freq = defaultdict(int)

for i in range(1, N+1):
    si = str(i)
    freq['{}{}'.format(si[0], si[-1])] += 1
    
for i in range(1, N+1):
    si = str(i)
    res += freq['{}{}'.format(si[-1], si[0])]
        
print(res)

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

vector<long long> B;
vector<pair<long long,long>> A;
int main(void){
	long N,M;
	cin >> N >> M;
	B = vector<long long>(N);
	A = vector<pair<long long,long>>(N);
	
	for(long i=0;i<N;i++){
		cin >> A[i].first >> B[i];
		A[i].second = i;
	}
	
	sort(A.begin(),A.end());
	long count = 0;
	long long ans = 0;
	while(M != 0){
		if((M-B[A[count].second]) >= 0){
			M -= B[A[count].second];
			ans += A[count].first * B[A[count].second];
		}else{
			ans += A[count].first * M;
			M = 0;
		}
		count++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>

int	main(){
	int	N,	i,	k,	cnt	=	0,	m,	a,	data[201][3]	=	{0},	point[201]	=	{0};
	scanf("%d",	&N);
	for(i	=	1;	i	<=	N;	i++){
		for(k	=	1;	k	<=	3;	k++){
			scanf("%d",	&data[i][k]);
		}
	}
	for(i	=	1;	i	<=	N;	i++){
		for(k	=	1;	k	<=	3;	k++){
			a	=	data[i][k];
			for(m	=	1;	m	<=	N;	m++){
				if(i	==	m)continue;
				if(a	==	data[m][k])a	=	0;
			}
			point[i]	+=	a;
		}
	}

	for(i	=	1;	i	<=	N;	i++){
		printf("%d\n",	point[i]);
	}
	return	0;
}

Measured memory_bytes: 1028
#include<stdio.h>
int main(void){
	int i=0,x[10000];
	do{
		scanf("%d",&x[i]);
		i++;
	}while(x[i-1]!=0);
	for(i=0;x[i]!=0;i++){
		printf("Case %d: %d\n",i+1,x[i]);
	}
	return 0;
}


Measured memory_bytes: 2032
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int s =(S%60);
        int M =(S/60);
        int m =(M%60);
        int h =(M/60);
        System.out.printf("%d:%d:%d\n",h,m,s);
    }
}


Measured memory_bytes: 26304
#include "bits/stdc++.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 3e5 + 5;

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int h, w, m;
    cin >> h >> w >> m;
    
    set<pii> S;
    vector<int> row(N), col(N);
    for (int i = 1; i <= m; i++) {
        pii p;
        cin >> p.fi >> p.se;
        row[p.fi]++;
        col[p.se]++;
        S.insert(p);
    }
    
    int maxRowId = max_element(all(row)) - row.begin();
    int maxRow = row[maxRowId];
    
    int maxColId = max_element(all(col)) - col.begin();
    int maxCol = col[maxColId];
    
    //cout << "maxRow = " << maxRow << "\n";
    //cout << "maxRowId = " << maxRowId << "\n";
    //cout << "maxCol = " << maxCol << "\n";
    //cout << "maxColId = " << maxColId << "\n";

    vector<int> v(N, count(all(row), maxRow));

    for (auto [x, y]: S) {
        if (row[x] == maxRow) {
            v[y]--;
        }
    }

    int ans = 0;
    for (int c = 1; c <= w; c++) {
        int cnt = maxRow + col[c] - (v[c] == 0 ? 1 : 0);
        ans = max(ans, cnt);
    }
    
    cout << ans;
}


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

int main() {
    long N;
    cin>>N;
    long x[N], y[N];
    for(long i=0;i<N;++i){
        cin>>x[i]>>y[i];
    }
    map<pair<long, long>, long>pqmap;
    vector<pair<long, long> >pqarr;
    pair<long, long>pq;
    long p, q;
    for(long i=0;i<N;++i){
        for(long j=i+1;j<N;++j){
            p = x[i] - x[j];
            q = y[i] - y[j];
            if(p<0){
                p *= -1;
                q *= -1;
            }
            if(p==0 & q<0) q *= -1;
            pq = make_pair(p, q);
            if(pqmap[pq]==0){
                pqarr.push_back(pq);
            }
            pqmap[pq]++;
        }
    }
    /**
    for(long i=0;i<pqarr.size();++i){
        cout<<pqarr[i].first<<" "<<pqarr[i].second<<endl;
        cout<<pqmap[pqarr[i]]<<endl;
    }
    **/
    long maxpq = 0;
    for(long i=0;i<pqarr.size();++i){
        if(maxpq < pqmap[pqarr[i]]){
            maxpq = pqmap[pqarr[i]];
            pq = pqarr[i];
        }
    }
    cout<<N-maxpq<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
using namespace std;
 
int main() { 
    int N;
	vector<int> vec(20);

    cin >> N;
    for (int i = 0; i < N; i++) {
    	cin >> vec.at(i);
    }

    int count = 0;
	for (int i = 1; i < N - 1; i++) {
    	if ((vec.at(i)<vec.at(i+1) && vec.at(i)>vec.at(i-1)) ||
            (vec.at(i)>vec.at(i+1) && vec.at(i)<vec.at(i-1))) {
				count++;
            }
    }
	cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

const int INF = 100000000;

struct Data{
    int xa, xi, ya, yi;
};

int h, w;

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

void dfs(char m[55][55], bool used[55][55], Data &d, int y, int x, char a){
    d.xa = max(d.xa, x);
    d.xi = min(d.xi, x);
    d.ya = max(d.ya, y);
    d.yi = min(d.yi, y);
    used[y][x] = true;

    rep(i,4){
        int ny = y + dy[i];
        int nx = x + dx[i];
        if(y >= h || y < 0 || x >= w || x < 0) continue;
        if(m[ny][nx] != a) continue;
        if(used[ny][nx] == true) continue;
        dfs(m,used,d,ny,nx,a);
    }
}

bool isRect(char m[55][55], Data d, char a){
    range(i,d.yi,d.ya + 1){
        range(j,d.xi,d.xa + 1){
            if(m[i][j] != a && m[i][j] != '@') return false;
        }
    }
    return true;
}

bool check(char m[55][55]){
    rep(i,h){
        rep(j,w){
            if(m[i][j] >= 'A' && m[i][j] <= 'Z') return false;
        }
    }
    return true;
}

bool replace(char m[55][55], Data d){
    //cout << d.yi << ' ' << d.ya << endl;
    range(i,d.yi,d.ya + 1){
        range(j,d.xi,d.xa + 1){
            m[i][j] = '@';
        }
    }
   //cout << endl; rep(i,h){ rep(j,w){ cout << m[i][j]; } cout << endl; }
    return true;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        cin >> h >> w;

        char m[55][55];
        rep(i,h) cin >> m[i];

        while(true){
            bool f = false;
            bool used[55][55] = {0};
            rep(i,h){
                rep(j,w){
                    if(m[i][j] != '.' && m[i][j] != '@' && used[i][j] == false){
                        Data d = {-INF,INF,-INF,INF};
                        //dfs(m,used,d,i,j,m[i][j]);
                        rep(I,h){
                            rep(J,w){
                                if(m[I][J] == m[i][j]){
                                    d.xa = max(d.xa, J);
                                    d.xi = min(d.xi, J);
                                    d.ya = max(d.ya, I);
                                    d.yi = min(d.yi, I);
                                }
                            }
                        }
                        //cout << i << ' ' << j << endl;
                        //cout << d.yi << ' ' << d.ya << endl;
                        //cout << d.xi << ' ' << d.xa << endl;
                        if(isRect(m,d,m[i][j])) f = replace(m,d);
                    }
                }
            }
            if(not f){
                break;
            }
        }
        cout << (check(m) ? "SAFE" : "SUSPICIOUS") << endl;
    }
}

Measured memory_bytes: 3088
if __name__ == "__main__":
    l = str(input())
    l = [int(x) for x in list(str(l))]
    length = len(l)
    temp1 = []
    temp2 = []
    for i in range(length):
        temp1.append(i % 2)
        temp2.append((i + 1) % 2)
    t1 = 0
    t2 = 0
    for n in range(length):
        if temp1[n] != l[n]:
            t1 += 1
        if temp2[n] != l[n]:
            t2 += 1
    print(min(t1, t2))


Measured memory_bytes: 6756
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;
using namespace std;

int main(){
	int s,w; cin >> s >> w;
    if(w>=s) cout <<"unsafe"<<endl;
    else cout << "safe" << endl;
    
  	return 0;
}

Measured memory_bytes: 3620
sx, sy, tx, ty = [int(i) for i in input().split()]
ans = ''
# (sx,sy)→(tx,ty)
ans += 'U' * abs(ty - sy)
ans += 'R' * abs(tx - sx)
# (tx,ty)→(sx,sy)
ans += 'D' * abs(ty - sy)
ans += 'L' * abs(tx - sx)
# (sx,sy)→(tx,ty)
ans += 'L'
ans += 'U' * (abs(ty - sy) + 1)
ans += 'R' * (abs(tx - sx) + 1)
ans += 'D'
# (tx,ty)→(sx,sy)
ans += 'R'
ans += 'D' * (abs(ty - sy) + 1)
ans += 'L' * (abs(tx - sx) + 1)
ans += 'U'
print(ans)

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

lst = []

for i in range(N):
    lst.append("".join(sorted(list(input()))))


d={}
count = 0

for i in lst:
  if not i in d:
    d[i] = 1
    continue
  else:
    d[i] = d[i] + 1
    count = count + d[i]-1


print(count)


Measured memory_bytes: 19504
loop {
    h, w = gets.split(" ").map(&:to_i)
    if h == 0 && w ==0
        break
    end
    w.times{print "#"}
    puts "\n"
    for i in 1..h-2
        print "#"
        for n in 1..w-2
            print "."
        end
       print "#"
       puts "\n"
    end
    w.times{print "#"}
    puts "\n"
    puts "\n"
}

Measured memory_bytes: 8692
#include<iostream>
#include<string>

using namespace std;

/*
 exp    ::= term    | exp  + term   | exp  - term
 term   ::= factor  | term * factor | term / factor
 factor ::= literal | (exp) | -factor
*/

int perseExp( string str );
int perseTerm( string str );
int perseFactor( string str );

int perseExp( string str ){
  //cout << "perseExp" << str << endl;
  int  nest = 0;
  char op   = 0;
  int pos;
  for(int i=str.size()-1; i>0; i--){
    char c = str[i];
    if(nest == 0 && (c == '+' || c == '-')){
      op = c;
      pos = i;
      break;
    }
    if(c == '('){
      nest--;
    }else if(c == ')'){
      nest++;
    }
    if(nest < 0)
      throw "Error: perseExp";
  }
  if(op == 0){
    return perseTerm(str);
  }else{
    int op1 = perseExp( str.substr(0, pos) );
    int op2 = perseTerm( str.substr(pos+1) );
    if(op == '+'){
      return op1 + op2;
    }else{
      return op1 - op2;
    }
  }
}

int perseTerm( string str ){
  //cout << "perseTerm" << str << endl;
  int nest = 0;
  char op = 0;
  int pos;
  for(int i=str.size()-1; i>0; i--){
    char c = str[i];
    if(nest == 0 && (c == '*' || c == '/')){
      op = c;
      pos = i;
      break;
    }
    if(c == '('){
      nest--;
    }else if(c == ')'){
      nest++;
    }
    if(nest < 0)
      throw "Error: perseTerm";
  }
  if(op == 0){
    return perseFactor(str);
  }else{
    int op1 = perseTerm( str.substr(0, pos) );
    int op2 = perseFactor( str.substr(pos+1) );
    if(op == '*'){
      return op1 * op2;
    }else{
      return op1 / op2;
    }
  }
}

int perseFactor( string str ){
  //cout << "perseFactor" << str << endl;
  if(str.size() == 0)
    throw "Parse Error: perseFactor";

  char firstStr = str[0];
  if(firstStr == '('){
    return perseExp( str.substr(1, str.size()-2) );
  }else if(firstStr == '-'){
    return -1 * perseFactor( str.substr(1) );
  }else{
    bool f = true;
    for(int i=0; i<str.size(); i++){
      if(!isdigit(str[i])) f = false;
    }
    if(f){
      int num; sscanf(str.c_str(), "%d", &num);
      return num;
    }else{
      return perseExp(str);
    }
  }
}

string trim(string str){
  while(str.find(' ') != -1) str.erase(str.find(' '), 1);
  while(str.find('=') != -1) str.erase(str.find('='), 1);
  return str;
}

int main(){
  int n;
  string str;
  getline(cin,str);
  sscanf(str.c_str(),"%d",&n);
  while(n-->0){
    getline(cin,str);
    str = trim(str);
    int ret = perseExp(str);
    cout << ret << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
  int k,a,b;
  bool flag = 0;

  cin >> k >> a >> b;

  for(int i = a; i <= b; i++){
    if(i % k == 0) flag = 1;
  }

  if(flag) cout << "OK" << endl;
  else cout << "NG" << endl;

  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <utility>
#include <queue>
#include <tuple>
#include <map>
#include <cctype>
#include <math.h>
using namespace std;
using ll = long long;
using VI = vector<int>;


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

    if (ans >= 0) {
        cout << 0 << endl;
    }
    else {
        cout << abs(ans) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; cin >> N;
  int min = 100000000;
  for (int i = 0; i < N; i++) {
  	int A; cin >> A;
    int currentMin = 0;
    while (A % 2 == 0) {
      A = A / 2;
      currentMin++;
    }
    if (currentMin < min) {
      min = currentMin;
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    int N;
    cin >> N;
    vll A(3*N);
    cin >> A;
    sort(A.begin(),A.end(),greater<ll>());
    ll ans = 0;
    ll cnt = 0;
    for(int i=1; i<3*N; i+=2){
        cnt++;
        ans += A[i];
        if(cnt >= N)break;
    }
    cout << ans << endl;
}

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

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define in insert
#define mp(a, b) make_pair(a, b)
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define INF INT_MAX
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
	ll a, b, n;
	cin>>a>>b>>n;
	ll elem = min(n, b-1);
	cout<<(a*elem)/b<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	// cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 3644
#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 K,N;
int l[55];

int main() {
    cin>>N>>K;
    REP(i,0,N) cin>>l[i];
    sort(l,l+N);
    int sum = 0;
    REP(i,N-K,N) sum += l[i];
    cout<<sum<<endl;
    return 0;
}


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

const int INF = 2e9;

int main(){
    string s;
    cin >> s;
    int q;
    cin >> q;
    bool ok = false;
    rep(x,q){
        int a;
        cin >> a;
        if(a == 1){
            if(ok) ok = false;
            else ok = true;
        }
        else{
            int b;
            char c;
            cin >> b >> c;
            if(b == 1){
                if(ok) s += c;
                else s = c + s;
            }
            else{
                if(ok) s = c + s;
                else s += c;
            }
        }
    }
    if(ok) reverse(s.begin(),s.end());
    cout << s << endl;
}

Measured memory_bytes: 4640
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>

using namespace std;
int a[13][2];
int d, g;

int main() {
	int ans = 100000009;
	long long inf = 10000000008;
	cin >> d;
	cin >> g;
	for (int i = 0; i < d; i++) {
		cin >> a[i][0];
		cin >> a[i][1];
	}
	for (int i = 0; i < 1 << d; i++) {
		int sum = 0;
		int ssum=0;
		for (int j = 0; j < d; j++) {
			if (i & 1 << j) {
				sum += 100 * a[j][0] * (j + 1) + a[j][1];
				ssum += a[j][0];
			}
		}
		int cnt = 0;
		for (int j = d - 1; j > -1; j--) {
			if (!(i & 1 << j)) {
				while (sum < g) {
					sum += (j + 1) * 100;
					cnt++;
					if (cnt == a[j][0]) {
						cnt = inf;
						break;
					}
				}
				break;
			}
		}
		ans = min(ans, ssum + cnt);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++);
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>;// intの2次元の型に vvi という別名をつける

int main(){
  vvi A(3, vi(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>A.at(i).at(j);
    }
  }
  
  int N;
  cin>>N;
  
  vi B(N);
  for(int i=0;i<N;i++){
    cin>>B.at(i);
  }
  
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<N;k++){
        if(A.at(i).at(j)==B.at(k)){
          A.at(i).at(j)=0;
          break;
        }
      }
    }
  }
  
  bool BINGO = false;
  
  for(int i=0;i<3;i++){
    int sum;
    sum = 0;
    for(int j=0;j<3;j++){
      sum += A.at(i).at(j);
    }
    if(sum==0)
      BINGO = true;
  }
  
  for(int i=0;i<3;i++){
    int sum;
    sum = 0;
    for(int j=0;j<3;j++){
      sum += A.at(j).at(i);
    }
    if(sum==0)
      BINGO = true;
  }
  
  if(A.at(0).at(0)+A.at(1).at(1)+A.at(2).at(2)==0)
    BINGO = true;
  if(A.at(0).at(2)+A.at(1).at(1)+A.at(2).at(0)==0)
    BINGO = true;
  
  if(BINGO)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}
      

Measured memory_bytes: 256
import Data.Array.Unboxed
import Data.Bool
import qualified Data.ByteString.Char8  as C
import Data.List
import Data.Maybe

main = sol <$> getn <*> gets >>= put

getn = fst . fromJust . C.readInt <$> C.getLine

gets = C.filter ((||) <$> ('o' ==) <*> ('x' ==)) <$> C.getLine

put = putStrLn . (flip bool "-1" <*> null)

sol n s = maybe "-1" (fmap snd . init) $ find ((==) <$> head <*> last) [ss,sw,ws,ww]
  where
  a = listArray (0,n) $ (=='o') <$> C.last s:C.unpack s :: UArray Int Bool
  ss = ('S','S'):unfoldr step ('S','S',1)
  sw = ('S','W'):unfoldr step ('S','W',1)
  ws = ('W','S'):unfoldr step ('W','S',1)
  ww = ('W','W'):unfoldr step ('W','W',1)
  step ('S','S',i) = if i<=n
    then Just (('S',nxt), ('S',nxt,i+1))
    else Nothing
    where
    nxt = bool 'W' 'S' (a!i)
  step ('S','W',i) = if i<=n 
    then Just (('W',nxt), ('W',nxt,i+1))
    else Nothing
    where
    nxt = bool 'S' 'W' (a!i)
  step ('W','S',i) = if i<=n 
    then Just (('S',nxt), ('S',nxt,i+1))
    else Nothing
    where
    nxt = bool 'S' 'W' (a!i)
  step ('W','W',i) = if i<=n
    then Just (('W',nxt), ('W',nxt,i+1))
    else Nothing
    where
    nxt = bool 'W' 'S' (a!i)

Measured memory_bytes: 15740
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        int res = 0;
        for (int i = s.length()-1; i > 0; i--) {
            if (i == s.length()-1) continue;
            String tmpString = s.substring(0, i+1);

            if (tmpString.length() % 2 != 0) continue;// 偶文字列は文字数が偶数になるため奇数はスキップ

            String frontString = tmpString.substring(0, tmpString.length()/2);
            String rearString = tmpString.substring(tmpString.length()/2);

            if (frontString.equals(rearString)) {
                res = tmpString.length();
                break;
            }
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stack>
using namespace std;
int n, m;
int x, y;
string s;
int main() {
    cin >> n;
    vector<int> v;
    for(int i=0; i<n; ++i){
        int a; cin >> a;
        v.push_back(a);
    }
    int minj = 0;
    int cnt=0;
    for(int i=0; i<n; ++i){
        bool flag = false;
        minj=i;
        for(int j=i; j<n; ++j){
            if(v[j] < v[minj]){
                minj = j;
                flag = true;
            }            
        }
        if(flag)cnt++;
        int temp=v[minj];
            v[minj] = v[i];
            v[i] = temp;
       
    }
     for(int i=0; i<n; ++i){
        if(i==n-1) {
            cout << v[i] << endl; break;
        }
        cout << v[i] << " ";
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3204
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

/*-----<Defines>-----*/
#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)size(x))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)-1)/(x)+1)
#define     flush           fflush(stdout)

using ull=unsigned long long;
using ll=long long;
using ld=long double;
/*-----</Defines>-----*/

/*-----<Debugging Stuff>-----*/
string to_string(char s)
{   string res="'''";res[1]=s;return res; }

string to_string(string s)
{   return '"'+s+'"'; }

string to_string(const char* s)
{   return to_string((string)s); }

string to_string(bool b)
{   return (b?"true":"false"); }

template<typename A, typename B>
string to_string(pair<A, B> p)
{   return "("+to_string(p.F)+", "+to_string(p.S)+")"; }

template<typename A>
string to_string(A v)
{
    bool first=1; string res="{";
    for(const auto &x:v)
    {
        if(!first)  res+=", ";
        first=0;
        res+=to_string(x);
    }
    res+="}";
    return res;
}

void debug() { cout<<"\n"; }
template<typename Head, typename... Tail>
void debug(Head H, Tail... T)
{
    cout<<" "<<to_string(H);
    debug(T...);
}

#define show(...) cout << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
/*-----</Debugging Stuff>-----*/

/*-----<Mod Operations>-----*/
const int M=1e9+7;
inline int add(int a,int b,int p=M){ a=a+b; if(a>=p) a-=p; return a; }
inline int sub(int a,int b,int p=M){ a=a-b; if(a<0) a+=p; return a; }
inline int mul(int a,int b,int p=M){ a=(a*1ll*b)%p; return a; }
/*-----</Mod Operations>-----*/

/*-----<Constants>-----*/
const ld pi=acos(-1),eps=1e-9;
const ll inf=1e18;
const int N=1;
/*-----</Constants>-----*/

void solve()
{
    int n;
    cin>>n;

    int ans=0;
    for(int i=1;i<=n;++i)
    {
        int x;
        cin>>x;

        if(i%2 && x%2)
            ++ans;
    }

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




Measured memory_bytes: 3648
def solve():
    t = [0] * (N+1)
    for i in range(N):
        if S[i:i+2] == "AC":
            t[i+1] = t[i] + 1
        else:
            t[i+1] = t[i]
    for j in range(Q):
        print(t[lr[j][1]-1]-t[lr[j][0]-1])

if __name__ == "__main__":
    N,Q = list(map(int, input().split()))  
    S = input()
    lr = [list(map(int, input().split())) for _ in range(Q)]
    solve()


Measured memory_bytes: 29708