akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;

  // header
  cout << "#";
  for (int i = 0; i < w; i++)
    cout <<"#";
  cout << "#" << endl;

  // contents
  for (int j = 0; j < h; j++) {
    string s;

    cin >> s;
    cout << "#" << s << "#" << endl;
  }

  // footer
  cout << "#";
  for (int i = 0; i < w; i++)
    cout <<"#";
  cout << "#" << endl;

}


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int a,b,c,d,ans;
    cin >> a >> b >> c >> d;
    if (a * b == c * d){
        ans = a*b;
    } else {
        if (a * b > c * d){
            ans = a * b;
        } else {
            ans = c * d;
        } 
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
int mod = 1e9 + 7;
int INF = 2e18;

signed main() {
    int X, Y;
    cin >> X >> Y;
    int ans = 0;
    vector<int> prize = {300000, 200000, 100000};
    if (X <= 3) ans += prize[X - 1];
    if (Y <= 3) ans += prize[Y - 1];
    if (X == 1 && Y == 1) ans += 400000;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b;

	scanf("%d %d",&a,&b);

	if( a == 1 ) a = 14;
	if( b == 1 ) b = 14;

	if( a > b ){
		printf("Alice\n");
	}else if( a < b ){
		printf("Bob\n");
	}else{
		printf("Draw\n");
	}

	return 0;
}

Measured memory_bytes: 128
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque

def main():
    n = int(input())
    if n%2 == 0:
        ans = []
        m = n//2
        for i in range(1,m):
            ans.append((i,n - i))
            ans.append((i,i + 1))
            ans.append((i + 1,n - i + 1))
            ans.append((n - i,n - i + 1))
        
        if n > 4:
            ans.append((1,m))
            ans.append((1,m + 1))
            ans.append((m,n))
            ans.append((n,m + 1))
        
        print(len(ans))
        for i in range(len(ans)):
            print(*ans[i])
    
    else:
        if n == 3:
            ans = [[1,3],[2,3]]
            print(2)
            for i in range(2):
                print(*ans[i])
        else:
            ans = []
            m = n//2
            for i in range(1,m):
                ans.append((i,n - i - 1))
                ans.append((i,i + 1))
                ans.append((i + 1,n - i))
                ans.append((n - i,n - i - 1))
            
            ans.append((m,n))
            ans.append((m + 1,n))
            ans.append((1,n))
            ans.append((n,n - 1))

            print(len(ans))
            for i in range(len(ans)):
                print(*ans[i])

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
a = [I() for _ in range(N)]

b = sum(a[i] % 2 for i in range(N))
if b == 0:
    print('second')
else:
    print('first')


Measured memory_bytes: 77748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
#define PI 3.1415926535
#define pb  push_back
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
int n;
cin>>n;
int a[n-1],b[200002]={0};
FOR(i,n-1)
{
	cin>>a[i];
	b[a[i]]++;
}
FORA(i,1,n)
{
	cout<<b[i]<<"\n";

}
return  0;
}




Measured memory_bytes: 5216
'use strict';
(function(stdin) {
  var inputs = stdin.toString().split(' ').map(Number);
  var a = inputs[0];
  var b = inputs[1];
  var c = inputs[2];
  var count = 0;
  for (var i = a; i < b + 1;i++){
    if (c % i === 0){
      count++;
    }
  }
  console.log(count);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15648
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.next();
        if(isPalindrome(0,s.length()-1,s) && isPalindrome(0,(s.length() -1)/2-1,s)&&isPalindrome((s.length()+3)/2-1,s.length()-1,s)){
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }

    private static boolean isPalindrome(final int start, final int end, final String s) {
        for (int i = 0; ; i++) {
            if (start + i > end - i) {
                return true;
            }
            if (s.charAt(start + i) != s.charAt(end - i)) {
                return false;
            }
        }
    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int cnt=0;
    while(cnt!=10000&&(a%2==0&&b%2==0&&c%2==0)){
        int x=a,y=b,z=c;
        a=y/2+z/2;
        b=x/2+z/2;
        c=x/2+y/2;
        cnt++;
    }
    if(cnt!=10000)cout<<cnt<<endl;
    else cout<<-1<<endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        do_(inp);
        inp.close();
    }
    public static void do_(Scanner inp) {
        int k = inp.nextInt();
        int a = inp.nextInt();
        int b = inp.nextInt();
        for (int i = a; i <= b; i++) {
            if (i % k == 0) {
                System.out.println("OK");
                return;
            }
        }
        System.out.println("NG");
    }
}


Measured memory_bytes: 35784
#!/usr/bin/env python

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.sizes = [1 for _ in range(n)]

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x]) # 圧縮経路
            return self.par[x]
            # return root(par[x]) # 圧縮しない場合

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return

        # par[rx] = ry # naiveな連結

        # 低い木を高い方にくっつける。
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.sizes[ry] += self.sizes[rx]
        else:
            self.par[ry] = rx
            self.sizes[rx] += self.sizes[ry]

        # rx木とry木の高さが同じならば、rx木を深くする。
        if self.rank[rx] == self.rank[ry]:
            self.rank[rx] += 1
             
    def size(self, x):
        '''
        xが属するグループのサイズを返す
        (連結成分の大きさ)
        '''
        return self.sizes[self.root(x)]

# main
n, q = map(int ,input().split())
uf = UnionFind(n)

for i in range(q):
    t, u, v = map(int, input().split())
    if t == 0:uf.unite(u, v)
    else:print(int(uf.same(u, v)))


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

using namespace std;

bool cmp(const string& left, const string& right)
{
  if(left.size() != right.size()) return left.size() < right.size();
  for(int i = 0; i < left.size(); i++) {
    if(left[i] != right[i]) return left[i] < right[i];
  }
  return false;
}

string addstr(string s, string t)
{
  for(int i = 0; i < s.size(); i++) {
    if(s.substr(i) == t.substr(0, s.size()-i)) return t.substr(s.size()-i);
  }
  return t;
}

int main()
{
  int N;
  while(cin >> N, N) {
    vector<string> S(N);
    for(int i = 0; i < N; i++) cin >> S[i];
    sort(S.begin(), S.end(), cmp);
    S.erase(unique(S.begin(), S.end()), S.end());

    vector<string> T;
    for(int i = 0; i < S.size(); i++) {
      bool flag = false;
      for(int j = i+1; j < S.size(); j++) {
	if(S[j].find(S[i]) != string::npos) flag = true;
	if(flag) break;
      }
      if(!flag) T.push_back(S[i]);
    }
    
    int M = T.size();
    int add[15][15];
    for(int i = 0; i < M; i++) {
      for(int j = 0; j < M; j++) {
	add[i][j] = addstr(T[i], T[j]).size();
      }
    }
    
    int dp[1<<15][15];
    const int inf = 1<<25;
    fill(dp[0], dp[1<<15], inf);
    for(int i = 0; i < M; i++) dp[1<<i][i] = T[i].size();
    
    int ans = inf;
    for(int i = 0; i < 1<<M; i++) {
      for(int j = 0; j < M; j++) {
	if(dp[i][j] == inf) continue;
	if(i == (1<<M)-1) {
	  ans = min(ans, dp[i][j]);
	}
	for(int k = 0; k < M; k++) {
	  if((i >> k) & 1) continue;
	  dp[i|(1<<k)][k] = min(dp[i|(1<<k)][k], dp[i][j] + add[j][k]);
	}
      }
    }
    
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 4964
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    string s;cin>>s;
    int now=0;
    rep(i,4){
        if(s[i]=='+')now++;
        else now--;
    }
    cout<<now<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c,t,sum;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){t=a;a=b;b=t;}
	if(b>c){t=b;b=c;c=t;}
	if(a>b){t=a;a=b;b=t;}
	if(b>c){t=b;b=c;c=t;}
	sum=b-a+c-b;
	printf("%d",sum);
	
	
	return 0;
	
	
}

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

int main() {
    int n;
    cin >> n;
    vector<pair<ll, ll>> l;
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        l.emplace_back(b, a);
    }
    sort(l.begin(), l.end());
    ll time = 0;
    bool ok = true;
    for(auto k : l){
        time += k.second;
        if(k.first < time){
            ok = false;
            break;
        }
    }
    cout << (ok ? "Yes": "No") << endl;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int N;
    vector<int> a;
    cin >> N;
    rep(i, N) {
        int ai;
        cin >> ai;
        a.pb(ai);
    }

    int result[200000] = {0};
    // 後ろから確定させていく
    for (int j = N - 1; j >= 0; j--) {
        int i = j + 1;

        // i が 2分の1以上だとその数だけ
        if (i > N / 2) {
            result[j] = a[j];
        } else {
            // そうじゃないものはiの倍数を2倍、3倍と足し合わせる
            int sum = 0;
            for (int k = i * 2 ; k <= N; k = k + i) {
                sum += result[k - 1];
            }

            sum %= 2;
            if ((a[j] == 0 && sum == 0) || (a[j] == 1 && sum == 1)) {
                result[j] = 0;
            } else {
                result[j] = 1;
            }
        }
    }

    int M = 0;
    rep(i, N) {
        if (result[i] == 1) M++;
    }

    cout << M << endl;
    rep(i, N) {
        if (result[i] == 1) {
            cout << (i + 1) << endl;
        }
    }
}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long; using ld = long double; using ull = unsigned long long; using uint = unsigned int;
using vi  = vector<int>; using vb  = vector<bool>; using vd  = vector<double>; using vl  = vector<ll>;
using vvi = vector<vi>;  using vvb = vector<vb>;   using vvd = vector<vd>;     using vvl = vector<vl>;
 
#define REP(i,n) for(ll i=0; i<(n); ++i)
#define FOR(i,b,n) for(ll i=(b); i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define TEN(x) ((ll)1e##x)
 
template<typename T> inline string join(const vector<T>& vec, string sep = " ") { stringstream ss; REP(i, vec.size()) ss << vec[i] << ( i+1 == vec.size() ? "" : sep ); return ss.str(); }
 
 
///////////////
 
#define EPS (1e-10)
#define NEXT(x, i) (x[(i + 1) % x.size()])
 
template<class T> using CR = const T &;
using P = complex<ld>;
using G = vector<P>;
 
int sgn(ld a, ld b = 0) {
    if (a > b + EPS) return 1;
    if (a < b - EPS) return -1;
    return 0;
}
 
ld dot(P a, P b) { return real(conj(a)*b); }
ld cross(P a, P b) { return imag(conj(a)*b); }
 
int ccw(P a, P b, P c) {
    b -= a;
    c -= a;
    if (sgn(cross(b, c))) return sgn(cross(b, c)); // clockwise(-1) or counter clockwise(1)
    if (sgn(dot(b, c)) == -1) return 2;            // c--a--b
    if (sgn(norm(b), norm(c)) == -1) return -2;    // a--b--c
    return 0;                                      // a--c--b
}
 
namespace std {
    bool operator < (P a, P b) {
        return sgn(real(a), real(b)) ? real(a) < real(b) : imag(a) < imag(b);
    }
}
G convex_hull(G g, bool strict = false) {
	int n = g.size();
	assert(n >= 3);

	sort(ALL(g));
	G c(n * 2);
	int k = 0;
	REP(i, n) {
		while (
			k >= 2 && ccw(c[k - 2], c[k - 1], g[i]) != 1
			&& (strict || ccw(c[k - 2], c[k - 1], g[i]) == -1)
		) k--; // x : {-1, (2, 0)},  o: {1},  ???: {-2}
		c[k++] = g[i];
	}
	int t = k + 1;
	REP(i, n - 1) {
		while (
			k >= t && ccw(c[k - 2], c[k - 1], g[n - 2 - i]) != 1
			&& (strict || ccw(c[k - 2], c[k - 1], g[n - 2 - i]) == -1)
		) k--;
		c[k++] = g[n - 2 - i];
	}
	c.resize(k - 1);
	return c;
}
 
//////////////
 
int main() {
#ifdef INPUT_FROM_FILE
    ifstream cin("sample.in");
    ofstream cout("sample.out");
#endif
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
    ll n; cin >> n;
 
    G g(n);
    REP(i,n){
        ld x, y;
        cin >> x >> y;
        g[i] = { x, y };
    }
 
    G g2 = convex_hull(move(g));
    ll under = 10001;
    REP(i, g2.size()) under = min<ll>(under, g2[i].imag());
    ll d = -1;
    REP(i, g2.size()) if (g2[i].imag() == under) if (d == -1 || g2[d].real() > g2[i].real()) d = i;
 
    cout << g2.size() << endl;
    REP(i, g2.size()) cout << (int)g2[(i+d)%g2.size()].real() << " " << (int)g2[(i+d)%g2.size()].imag() << endl;
    return 0;
}

Measured memory_bytes: 12312
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<string>
#include<vector>
#include<functional>

using namespace std;

const double EPS=1e-12;
const double INF=1e12;

typedef complex<double>Point;

namespace std{
    bool operator<(const Point &P,const Point &Q){
        return real(P)!=real(Q)?real(P)<real(Q):imag(P)<imag(Q);
    }
}

double dot(const Point &P,const Point &Q){
    return real(P)*real(Q)+imag(P)*imag(Q);
}

double cross(const Point &P,const Point &Q){
    return real(P)*imag(Q)-real(Q)*imag(P);
}

struct Line{
    Point a,b;
    Line(Point P,Point Q){
        a=P;b=Q;
    }
    Line(){}
};

struct Segment{
    Point a,b;
    Segment(Point P,Point Q){
        a=P;b=Q;
    }
    Segment(){}
};

struct Circle{
    Point c;
    double r;
    Circle(Point P,double l){
        c=P;r=l;
    }
};

typedef vector<Point>Polygon;

int ccw(Point A,Point B,Point C){
    B-=A;C-=A;
    if(cross(B,C)>0)return 1; //ccw
    if(cross(B,C)<0)return -1; //cw
    if(dot(B,C)<0)return 2; //c-b-a
    if(norm(B)<norm(C))return -2; //a-b-c
    return 0; //a-c-b
}
inline bool Parallelism(const Line &L,const Line &M){
    return fabs(cross(L.a-L.b,M.a-M.b))<EPS;
}

inline bool Orthogonal(const Line &L,const Line &M){
    return fabs(dot(L.a-L.b,M.a-M.b))<EPS;
}

inline bool intersect(const Line &L,const Line &M){
    return cross(L.a-L.b,M.a-M.b)>EPS ||cross(L.a-L.b,M.a-M.b)<-EPS;
}

inline bool intersect(const Line &L,const Segment &S){
    return cross(L.b-L.a,S.a-L.a)*cross(L.b-L.a,S.b-L.a)<-EPS;
}

inline bool intersect(const Line &L,const Point &P){
    return abs(ccw(L.a,L.b,P))!=1;
}

inline bool intersect(const Segment &S, const Segment &T){
    return ccw(S.a,S.b,T.a)*ccw(S.a,S.b,T.b)<=0&&
        ccw(T.a,T.b,S.a)*ccw(T.a,T.b,S.b) <= 0;
}

inline bool intersect(const Segment &S,const Point &P){
    return ccw(S.a,S.b,P)==0;
}

inline bool intersect(const Circle &C,const Point &P){
    return abs(C.c-P)<=C.r+EPS;
}

inline bool intersect(const Circle &C,const Circle &D){
    return abs(C.c-D.c)<=C.r+D.r&&abs(C.c-D.c)>=fabs(C.r-D.r);
}

inline Point crossPoint(const Line &L,const Line &M){

}
double areaTriangle(Point A,Point B,Point C){
    B-=A;C-=A;
    return fabs(cross(B,C))*0.5;
}

double areaPolygon(Polygon &g){
    const int Sz=g.size();
    if(Sz<3)return 0;
    if(Sz==3)return areaTriangle(g[0],g[1],g[2]);

    double res=cross(g[Sz-1],g[0]);
    for(int i=1;i<Sz;i++)res+=cross(g[i-1],g[i]);

    return fabs(res)*0.5;
}



int main(){
    int N;
    Line L,M;
    while(true){
        cin>>L.a.real()>>L.a.imag()>>L.b.real()>>L.b.imag();
        if(cin.eof())break;
        cin>>M.a.real()>>M.a.imag()>>M.b.real()>>M.b.imag();
        if(Orthogonal(L,M))cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1216
import java.util.*;

class Main{
	static public void main(String[] args){
		Scanner sc=new Scanner(System.in);
		
		long n=sc.nextLong();
		long sum=0;
		for(long i=1;i<=n;i++){
			if(i%3==0||i%5==0){
				continue;
			}
			else{
				sum+=i;
			}
		}
		
		System.out.println(sum);
	}
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

bool isPalindrome(string s) {
    string ss = s;
    reverse(all(s));
    if (ss == s) return true;
    else return false;
}

int main(){
    string s;
    cin >> s;
    bool ans = true;
    if (!isPalindrome(s)) ans = false;
    if (!isPalindrome(s.substr(0, s.size()/2))) ans = false;
    if (!isPalindrome(s.substr(s.size()/2+1, s.size()/2))) ans = false;
    cout << (ans?YES:NO) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main (){

	int n=0;
	int an[200];
	int e=1;
	int cnt=0; 
		scanf("%d",&n);

		for(int i=0;i<n;i++){//anの入力
		scanf("%d",&an[i]);
		}
		
		while(e){
				
			for (int j=0;j<n;j++){//偶数か判定する
				
				if(an[j]%2==1){
					e=0;
					break;
                }
			}	
			
			if(e==1){
				cnt++;
				for(int l=0;l<n;l++){//割った数を配列に入れる
				an[l]=an[l]/2;
				}
			}
		
		}
		printf("%d",cnt);

	return 0;
}

Measured memory_bytes: 128
N = int(input())
K = int(input())
x = [int(i) for i in input().split()]

totalDist = 0
for i in range(N):
    choiceA = abs(0 - x[i]) * 2
    choiceB = abs(K - x[i]) * 2
    totalDist += min(choiceA,choiceB)
print(totalDist)

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

int calcDigitSum(int n) {
  int digitSum = 0;
  string s = to_string(n);
  for (char c: s) {
    digitSum += c - '0';
  }
  return digitSum;
}

int main() {
  int N;
  cin >> N;
  
  int a, b, tmp, upper = N / 2 + 1;
  int min = 108;
  for (a = 1; a <= upper; a++) {
    b = N - a;
    tmp = calcDigitSum(a) + calcDigitSum(b);
    if (tmp < min) {
      min = tmp;
    }
  }
  
  cout << min << endl;
}


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

int main(void) {
    ll N;cin>>N;
    vector<ll> vc(100001, 0);
    ll total = 0;
    for (ll i = 0; i < N; i++) {
        ll A;cin>>A;
        vc.at(A) += 1;
        total += A;
    }
    int Q;cin>>Q;
    for (int i = 1; i <= Q; i++) {
        ll B,C;cin>>B>>C;
        ll tmp_b = vc.at(B);
        total -= tmp_b * B;
        vc.at(B) = 0;
        total += C * tmp_b;
        vc.at(C) += tmp_b;
        cout << total << endl;
    }
    return 0;
}

Measured memory_bytes: 3612
from collections import Counter
n = int(input())
s = []
for _ in range(n):
    s.append(input())

sc = Counter(s).most_common()

ans = [sc[0]]

if len(sc) == 1:
    pass
else:
    for i in range(1, n):
        if sc[i][1] == sc[0][1]:
            ans.append(sc[i])
        else:
            break

ans.sort()
for x in ans:
    print(x[0])


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 X, K, D;
  cin >> X >> K >> D;
  X = abs(X);
  int64 t = X/D;
  X -= min(t, K) * D;
  K -= min(t, K);
  if (K%2 == 0) {
    cout << X << endl;
  } else {
    cout << abs(X-D) << endl;
  }
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
#define mREP(a,b) for (int i = a; i == (b); --i)
#define mod 1e9 + 7
typedef long long ll;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	　　　　　 　 _... ..._
	　　　　　 , ´⌒ ⌒ヽ
	　　　 　 ﾉｨ（ノﾉ）ﾉ）ﾉ）
	　　　 　 （（q|.ﾟ ヮﾟﾉ|ﾊ
	　　　　　　△ﾑ,8ﾑﾌつ
	　　　　　/(ﾝ_/＿ヽ＼
	　　　　 ～～i_ﾌ_ﾌ～´
	*/
int n,m;
  cin>>n>>m;
  cout<<(n - 1) * (m - 1)<<endl;
	return 0;
}


Measured memory_bytes: 256
import heapq

n, k = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]
sushi.sort(key=lambda x: x[1])
t = {}
x = []
z = 0
for i in range(n - 1, n - k - 1, -1):
    ti, di = sushi[i]
    if ti in t.keys():
        heapq.heappush(x, di)
        t[ti] += 1
    else:
        t[ti] = 1
    z += di

p = len(t.keys())
ans = z + p ** 2
for i in range(n - k - 1, -1, -1):
    if len(x) == 0:
        break
    ti, di = sushi[i]
    if ti not in t.keys():
        t[ti] = 1
        z += di - heapq.heappop(x)
        p += 1
        ans = max(ans, z + p ** 2)

print(ans)


Measured memory_bytes: 32228
x1,y1,x2,y2 = (map(int,input().split()))
ans = ("R" * (x2 - x1)) + ("U" * (y2 - y1)) + ("L" * (x2 - x1)) + ("D" * (y2 - y1))  \
      + "D" + ("R" * (x2 - x1 + 1)) + ("U" * (y2 - y1 + 1)) + "L" + "U" \
      + ("L" * (x2 - x1 + 1)) + ("D" * (y2 - y1 + 1)) + "R"
print(ans)
       


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include<assert.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
struct combination{
    vector<vector<ll>> c;
    combination() : c(60,vector<ll>(60)){
        rep(i,0,60){
            rep(j,0,i+1){
                if(j==0 || j==i){
                    c[i][j] = 1ll;
                }
                else{
                    c[i][j] = (c[i-1][j-1]+c[i-1][j]);
                }
            }
        }
    }
 
    ll operator ()(ll n, ll k){
        return c[n][k];
    }
} comb;

signed main() {
    int n, a, b;
    cin >> n >> a >> b;
    double v[n];
    map<double, int, greater<double>> mp;
    rep (i, 0, n) {
        cin >> v[i];
        mp[v[i]]++;
    }

    int cnt = 0;
    double sum = 0;
    ll ans = 1;
    double ave = 0;
    for (auto p : mp) {
        if (cnt + p.second < a) {
            sum += p.second * p.first;
            cnt += p.second;
        } else if (a <= cnt + p.second) {
            if (cnt == 0) {
                ans=0;
                rep(k,a,min(b,p.second)+1) ans+=comb(p.second,k);
                ave = p.first;
            } else {
                int cnt2 = a - cnt;
                ans=comb(p.second,cnt2);
                ave = (sum + cnt2 * p.first) / a;
            }
            break;
        }
    }
    cout << fixed << setprecision (15) << ave << "\n" << ans << "\n";
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

signed main(){
    int n;
    int cd[6] = {5, 7, 5, 7, 7, 10000};
    while(cin >> n, n){
        string s;
        vector<int> d(n);
        rep(i, 0, n){
            cin >> s;
            d[i] = (int)(s.size());
        }
        int ans = 0;
        rep(i, 0, n){
            int cnt = 0, ind = 0;
            rep(j, i, n){
                cnt += d[j];
                if(cnt == cd[ind]){
                    cnt = 0;
                    ind++;
                }
                if(cnt > cd[ind]) break;
            }
            if(ind == 5){
                ans = i + 1;
                break;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1204
<?php

for ($i = 0; $i < 20; $i++) {
    $score[] = trim(fgets(STDIN));
}

$w_scores = array_slice($score, 0, 10);
$k_scores = array_slice($score, 10);

rsort($w_scores);
rsort($k_scores);

$w_sum_top3 = $w_scores[0] + $w_scores[1] + $w_scores[2];
$k_sum_top3 = $k_scores[0] + $k_scores[1] + $k_scores[2];

echo $w_sum_top3. ' '. $k_sum_top3. PHP_EOL;


Measured memory_bytes: 9248
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int h = scanner.nextInt();
        int a = scanner.nextInt();
        if (h % a == 0) {
            System.out.println(h / a);
        } else {
            System.out.println(h / a + 1);
        }
    }
}


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

using ll = long long;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x) for (auto&& v : (x))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))

int main() {
  ll d, t, s;
  cin >> d >> t >> s;
  cout << (d <= t * s ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>

using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int n,m; cin >> n >> m;
    int ans = n;
    for (int i = 0; i < m; i++) {
        int a;cin >> a;
        ans -= a;
    }
    if (ans < 0) ans = -1;
    cout << ans << "\n";
}

Measured memory_bytes: 3636
import sys
input=sys.stdin.readline
n=int(input())
cnt=[]
for i in range(n):
	s=input().rstrip()
	l=s.count("(")
	r=s.count(")")
	minus=0
	now=0
	for j in range(len(s)):
		if s[j]=="(":
			now+=1
		else:
			now-=1
			minus=min(minus,now)
	cnt.append((l,r,s,minus))
cnt.sort(key=lambda x:x[1]-x[0])
plus=[]
minus=[]
#x[3]は最小値　x[0]-x[1]が合計値
for x in cnt:
	if x[0]-x[1]>0:
		plus.append(x)
	else:
		minus.append(x)
plus.sort(key=lambda x:-x[3])#最小値の少ない(0に近い方から)
minus.sort(key=lambda x:-(x[0]-x[1]-x[3]))
lr=0#l-r
for x in plus+minus:
	if lr+x[3]<0:
		print("No")
		exit()
	lr+=x[0]-x[1]
if lr==0:
	print("Yes")
else:
	print("No")


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

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

    string s;
    cin >> s;
    
    string ans = "Yes";
    rep(i,s.size()){
        if((i+1) % 2 == 1 && s[i] == 'L'){
            ans = "No";
        }
        
        if((i+1) % 2 == 0 && s[i] == 'R'){
            ans = "No";
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;

using ll = long long;
const int N = 1e5+5;

int main()
{
    ios_base::sync_with_stdio(0);

    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 0; i < n; ++i) {
        ++ans;
        int j = i;
        while(s[j+1] == s[i]) {
            ++j;
        }
        i = j;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
// #define int long long
using namespace std;


const int siz=2e5+5;
vector<vector<pair<int,pair<int,int> > > >adj;
int parent[siz];
int sz[siz];
int vis_ind[siz];
int vis[siz];
int mm[siz];
int find_parent(int ver)
{
    if(ver==parent[ver])
        return ver;
    return parent[ver]=find_parent(parent[ver]);
}

bool merge(int a,int b)
{
    a=find_parent(a);
    b=find_parent(b);
    if(a!=b)
    {
        if(sz[a]<sz[b])
            swap(a,b);
        sz[a]+=sz[b];
        parent[b]=a;
        mm[a]=min(mm[a],mm[b]);
        return true;
    }
    return false;
}

vector<pair<int,pair<int,int> > >temp;
void dfs(int ver)
{
    vis_ind[ver]=1;
    for(auto i:adj[ver])
    {
        if(!vis[i.second.second])
        {
            vis[i.second.second]=1;
            temp.push_back({i.second.first,{i.first,ver}});
            if(vis_ind[i.first]==0)
            dfs(i.first);
        }
    }
}

signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int n,h,w;
    cin>>n>>h>>w;
    int x,y,z;
    adj.resize(2e5+5);
    int lim=1e5;
    
    for(int i=0;i<n;i++)
    {
        cin>>x>>y>>z;
        adj[x].push_back({y+lim,{z,i}});
        adj[y+lim].push_back({x,{z,i}});
    }    

    for(int i=1;i<=2*lim;i++)
    {
        mm[i]=1;
        parent[i]=i;
        sz[i]=1;
    }
    long long ans=0;
    for(int i=1;i<=2*lim;i++)
    {
        if(!vis_ind[i])
        {
            temp.clear();
            dfs(i);
            sort(temp.begin(),temp.end(),greater<>());
            int mx=0;
            for(auto j:temp)
            {
                if(mm[find_parent(j.second.first)]+mm[find_parent(j.second.second)]==0)
                    continue;
                int z=merge(j.second.first,j.second.second);
                if(z==0)
                {
                    mm[find_parent(j.second.first)]=0;
                }
                ans+=j.first;
            }

            ans+=mx;
            
        }
    }

    cout<<ans;

}


Measured memory_bytes: 25652
n, m = map(int, input().split())
drink = []
for tsumugi in range(n):
    drink.append(list(map(int, input().split())))
    #栄養ドリンクの単価と販売本数をリストの形で保存

drink.sort()
bought = 0
shop = 0
ans = 0
while 1:
    dif = m - bought
    if drink[shop][1] >= dif:
        ans += drink[shop][0] * dif
        break
    else:
        ans += drink[shop][0] * drink[shop][1]
        bought += drink[shop][1]
    shop += 1

print(ans)

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

using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	int a[n];
	int sum=0;
	for(int i = 0; i < m ; i++){
		scanf("%d",&a[i]);	
		sum += a[i];
	}	
	int res = n- sum ;
	if(0 > res){
		cout << -1 <<endl;
	}else{
		cout << res << endl;
	}

}

Measured memory_bytes: 3792
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	int C = 200000;
	vector<int> X(200000, 0);
	for (int i = 0; i < N; i++) {
		cin >> A[i]; A[i]--;
	}
	vector<int> B;
	for (int i = 0; i < N; i++) {
		if ((int)B.size() == 0 || B.back() != A[i]) {
			B.push_back(A[i]);
		}
	}
	N = B.size();
	//cerr << N << endl;
	res = 1;
	for (int i = 0; i < N; i++) {
		X[B[i]] = (X[B[i]] + res) % MOD;
		res = X[B[i]];
	}


	cout << res << endl;
}

Measured memory_bytes: 5620
(defun count-bits (bits)
  (if (= bits 0)
      0
      (+ (logand bits 1)
         (count-bits (ash bits -1)))))

(defun solve (n infos)
  (loop for bits from 0 below (expt 2 n)
        if (loop for i from (1- n) downto 0
                 for info in infos
                 if (and (logbitp i bits)
                         (some (lambda (info)
                                 (destructuring-bind (x . y) info
                                   (not (= y (if (logbitp (- n x) bits)
                                                 1
                                                 0)))))
                               info))
                 do (return nil)
                 finally (return t))
        maximize (count-bits bits)))

#-swank
(let* ((n (read))
       (infos (loop repeat n
                    collect (let ((m (read)))
                              (loop repeat m
                                    collect (cons (read) (read)))))))
  (format t "~A~%" (solve n infos)))


Measured memory_bytes: 57956
#include<iostream>
#include<vector>
#include<string>
#include<queue>

int main() {
	int h, w;
	std::cin >> h >> w;
	std::vector<std::vector<int>>score(h, std::vector<int>(w, -1));
	std::queue<std::pair<int, int>>q;
	for (int i = 0; i < h; i++) {
		std::string s;
		std::cin >> s;
		for (int j = 0; j < w; j++) {
			if (s[j] == '#') {
				score[i][j] = 0;
				q.push(std::make_pair(j, i));
			}
		}
	}

	int dx[4] = { 0,0,1,-1 };
	int dy[4] = { 1,-1,0,0 };
	while (!q.empty()) {
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (nx == -1 || ny == -1 || nx == w || ny == h)continue;
			if (score[ny][nx] >= 0)continue;
			q.push(std::make_pair(nx, ny));
			score[ny][nx] = score[y][x] + 1;
		}
	}

	int max = 0;
	for (int i = 0; i < h*w; i++) {
		if (score[i / w][i%w] > max)max = score[i / w][i%w];
	}
	printf("%d\n", max);
}

Measured memory_bytes: 12432
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 998244353;
typedef long long ll;
int main(){
	int n,s;
	cin >> n >> s;
	vector<int> a(n);
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}

	vector<vector<ll>> dp(n+1,vector<ll>(s+1,0));
	dp[0][0] = 1;

	//(T,U)のそれぞれに含めるか含めないかを全通り数え上げれば,答えを求めたことになる.
	for(int i = 0;i < n;i++){
		for(int j = 0;j <= s;j++){
			dp[i+1][j] += 2 * dp[i][j];//取らない場合は(T,U)について2通りに分岐する.
			dp[i+1][j] %= MOD;
			if(j + a[i] <= s){
				dp[i+1][j+a[i]] += dp[i][j];
				dp[i+1][j+a[i]] %= MOD;
			}
		}
	}

	cout << dp[n][s] << endl;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int MAX_N = 1000000;
int n;
int prime[MAX_N];
bool isPrime[MAX_N+1];
int ptr;
int sum[MAX_N];

int main()
{
  prime[ptr++] = 2;  sum[0] = 2;
  for(int i=2; i<=MAX_N; i+=2) isPrime[i] = true;
  for(int i=3; i<=MAX_N; i+=2){
    if(!isPrime[i]){
      sum[ptr] = sum[ptr-1] + i;
      prime[ptr++] = i;
      for(int j=2*i; j<=MAX_N; j+=i){
        isPrime[j] = true;
      }
    }
  }

  while((cin >> n) && n) cout << sum[n-1] << endl;

  return 0;
}

Measured memory_bytes: 5564
# abc136_a.py
# https://atcoder.jp/contests/abc136/tasks/abc136_a

# A - Transfer /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 水を入れる容器が 2つあります。
# 容器 1には水を A ミリリットルまで入れることができ、水が Bミリリットル入っています。
# 容器 2には水が Cミリリットル入っています。
# 容器 2から容器 1に入るだけ水を移します。
# 容器 2の中には何ミリリットルの水が残るでしょうか。

# 制約
#     入力は全て整数である。
#     1≤B≤A≤20
#     1≤C≤20

# 入力
# 入力は以下の形式で標準入力から与えられる。
# A B C

# 出力
# ミリリットル単位で容器 2の中に残る水の量を整数で出力せよ。

# 入力例 1
# 6 4 3

# 出力例 1
# 1

# 容器 2から容器 1 に 2 ミリリットルの水を移すことになるので、容器 2 には 1ミリリットルの水が残ります。

# 入力例 2
# 8 3 9

# 出力例 2
# 4

# 入力例 3
# 12 3 7

# 出力例 3
# 0


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    A, B, C = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(6):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(M):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = max(C - (A-B), 0)

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['6 4 3']
        lines_export = [1]
    if pattern == 2:
        lines_input = ['8 3 9']
        lines_export = [4]
    if pattern == 3:
        lines_input = ['12 3 7']
        lines_export = [0]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9280
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		// cin.ignore(); must be there when using getline(cin, s)
		ll n,w;
		cin>>n>>w;
		ll wt[n];
		ll v[n];
		ll mv=0;
		for(ll i=0;i<n;i++)
		{
			cin>>wt[i]>>v[i];
			mv+=v[i];
		}
		ll dp[mv+1];
		memset(dp,inf,(mv+1)*sizeof(dp[0]));
		dp[0]=0;
		for(ll i=0;i<n;i++)
		{
			for(ll j=mv;j>=v[i];j--)
			{
				dp[j]=min(dp[j],dp[j-v[i]]+wt[i]);
			}
		}
		for(ll j=mv;j>=0;j--)
			if(dp[j]<=w)
			{
				cout<<j;
				break;
			}
		return 0;
	}


Measured memory_bytes: 1024
struct UnionFind {
    dp: Vec<usize>
}

impl UnionFind {
    fn new(length: usize) -> UnionFind {
        return UnionFind { dp: (0..length).collect::<Vec<usize>>() };
    }

    fn find(&mut self, x: usize) -> usize {
        if x == self.dp[x] { return x; }
        self.dp[x] = self.find(self.dp[x]);
        return self.dp[x];
    }

    fn connect(&mut self, a: usize, b: usize) {
        let ra = self.find(a);
        self.dp[ra] = self.find(b);
    }
}

fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        ab: [(usize, usize); m]
    }

    let mut uf = UnionFind::new(n);

    for (a, b) in &ab {
        uf.connect(*a - 1, *b - 1);
    }

    let res = (0..n)
        .fold(std::collections::HashMap::new(), |mut map, index| {
            *map.entry(uf.find(index)).or_insert(0) += 1;
            return map;
        })
        .iter()
        .map(|(_, &count)| count)
        .max()
        .unwrap();

    println!("{}", res);
}

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

const int MAX=100000;

bool marked[MAX];
int parent[MAX];

int find(int s)
{
	int i=s;
	while(!marked[i])i=parent[i];
	return i;
}

int main()
{
	int n,q;
	while(cin>>n>>q,n)
	{
		int a;char c;
		for(int i=1;i<n;i++)
		{
			cin>>a;a--;
			parent[i]=a;
			marked[i]=false;
		}
		parent[0]=0;
		marked[0]=true;
		long long int sum=0;
		for(int i=0;i<q;i++)
		{
			cin>>c>>a;a--;
			if(c=='Q')
			{
				sum+=(long long int)find(a)+1;
			}
			else
			{
				marked[a]=true;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 3520
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def factorize(n):
    res = set()
    i = 2
    while i*i <= n:
        if n % i != 0:
            i += 1
            continue
        while n % i == 0:
            n //= i
            res.add(i)
        i += 1
    if n != 1:
        res.add(n)
    return res

def main():
    A, B = map(int,input().split())

    g = gcd(A, B)
    f = factorize(g)
    ans = len(f) + 1
    print(ans)

if __name__ == '__main__':
    main()

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

    using Graph = vector<vector<int>>;
 
int main() {

    string s;
    cin>>s;


    int cnt_n=0,cnt_w=0,cnt_s=0,cnt_e=0;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='N')
            cnt_n++;
        else if(s.at(i)=='W')
            cnt_w++;
        else if(s.at(i)=='S')
            cnt_s++;
        else //E
            cnt_e++;
    }

    bool cond1 = (cnt_n>=1 && cnt_s>=1) && (cnt_w>=1 && cnt_e>=1);
    bool cond2 = (cnt_n==0 && cnt_s==0) && (cnt_w>=1 && cnt_e>=1);
    bool cond3 = (cnt_n>=1 && cnt_s>=1) && (cnt_w==0 && cnt_e==0);

    if(cond1 || cond2 || cond3)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

 	return 0;
}

Measured memory_bytes: 3600
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main() {
    int n, k;
    cin >> n >> k;
    auto a = vector<int>(n);
    for (auto& a_i : a)
        cin >> a_i;

    auto lit = vector<int>(n + 1, 0);
    for (auto rep = 0; rep < k; ++rep) {
        for (auto i = 0; i < n; ++i) {
            auto l = max(0, i - a[i]);
            auto r = min(n - 1, i + a[i]);
            lit[l]++;
            lit[r + 1]--;
        }
        for (auto i = 0; i < n; ++i) {
            lit[i + 1] += lit[i];
        }

        lit.resize(n);
        if (lit == a)
            break;
        swap(a, lit);
        lit.assign(n + 1, 0);
    }

    for (auto i = 0; i < n; ++i)
        cout << a[i] << (i + 1 == n ? "\n" : " ");
    return 0;
}


Measured memory_bytes: 5608
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mxn=1000010,md=1000000007;
int power(int x,int p,int num=1){
	for (;p;p>>=1,x=1ll*x*x%md)
		if (p&1) num=1ll*num*x%md;
	return num;
}
int ans,c[mxn],stk[mxn],tp,son[mxn],vis[mxn],cnt[mxn];
int solve_tr(){
	int lst=0;
	for (int i=1;i<=tp;++i) cnt[i]=0;
	for (int i=1;i<=tp;++i)
		for (int x=son[stk[i]];x;++cnt[i],vis[x]=1,x=son[x]);
	for (int i=1;i<=tp;++i)
		if (cnt[i]) {lst=i;break;}
	if (!lst) return ++c[tp],1;
	int ret=1;
	for (int i=tp;i;++lst,--i)
		if (cnt[i]){
			if (lst>cnt[i]) ret=ret*2%md;
			if (lst<cnt[i]) return 0;
			lst=0;
		}
	return ret;
}
int f[mxn],pw[mxn],fct[mxn],ifc[mxn];
int cal(int x){
	return (x-1ll)*x/2%md;
}
int solve_lp(int n,int k){
	f[0]=1;
	bool flg=((k&1)&&k>1);
	int ret=pw[flg*n];
	for (int i=1;i<<1<=n;++i){
		f[i]=1ll*f[i-1]*cal(n-(i<<1)+2)%md*k%md;
		ret=(ret+1ll*f[i]*ifc[i]%md*pw[flg*(n-(i<<1))])%md;
	}
	return ret;
}
void init(int n){
	pw[0]=1;
	for (int i=1;i<=n;++i) pw[i]=pw[i-1]*2%md;
	fct[0]=ifc[0]=1;
	for (int i=1;i<=n;++i) fct[i]=1ll*fct[i-1]*i%md;
	ifc[n]=power(fct[n],md-2);
	for (int i=n-1;i;--i) ifc[i]=(i+1ll)*ifc[i+1]%md;
}
int n,fa[mxn],stkk[mxn],tpp,tag[mxn],exist[mxn];
bool init2(){
	for (int i=1;i<=n;++i)
		if (!vis[i]){
			tpp=0;
			for (int x=i;x;x=fa[x])
				if (vis[x]){
					if (!exist[x]) break;
					for (;stkk[tpp+1]!=x;tag[stkk[tpp]]=1,exist[stkk[tpp--]]=0);
					break;
				}
				else vis[x]=exist[x]=1,stkk[++tpp]=x;
			for (;tpp;exist[stkk[tpp--]]=0);
		}
	memset(vis,0,sizeof(vis));
	for (int i=1;i<=n;++i)
		if (!tag[i]){
			if (son[fa[i]]) return 0;
			son[fa[i]]=i;
		}
	return 1;
}
int main()
{
	scanf("%d",&n);
	init(n);
	for (int i=1;i<=n;++i) scanf("%d",&fa[i]);
	if (!init2()) return puts("0"),0;
	int ans=1;
	for (int i=1;i<=n;++i)
		if (tag[i]&&!vis[i]){
			tp=tpp=0;
			for (int x=i;x;x=fa[x])
				if (vis[x]){
					for (;stkk[tpp+1]!=x;stk[++tp]=stkk[tpp--]);
					break;
				}
				else vis[x]=1,stkk[++tpp]=x;
			ans=1ll*ans*solve_tr()%md;
		}
	for (int i=1;i<=n;++i)
		ans=1ll*ans*solve_lp(c[i],i)%md;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 33280