akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;  
typedef unsigned long long ull;         
typedef vector < pii > vpii;                                   	
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;
 
 
const int inf = 1e9, maxn = 1e6 + 48, mod = 1e9 + 7, N = 2e5 + 24;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;


int n, m, aa, bb, a[N], b[N], c[N], cnta, cntb, p[N], add;
map < pair < pii, int >, int > cnt;
map < pair < pii, int >, bool > was;
vpii v;

main () {
	p[0] = 1;
	for (int i = 1; i < N; ++i)
		p[i] = p[i - 1] * 2 % mod;

	cin >> m;
	while (m--) {
		cin >> aa >> bb;
		if (!aa && !bb) {
		    ++add;
			continue; 
		}
		if (!aa) {
			++cnta;
			continue;
		}

		if (!bb) {
			++cntb;
			continue;
		} 

		++n;
		if (aa < 0) {
			aa = -aa;
			c[n] ^= 1;
		}

		if (bb < 0) {
			bb = -bb;
			c[n] ^= 1;
		}
		int G = __gcd(aa, bb);
		aa /= G;
		bb /= G;

		a[n] = aa;
		b[n] = bb;

		++cnt[{{a[n], b[n]}, c[n]}];
	}

	int ans = (p[cnta] + p[cntb] - 1);
	
	for (int i = 1; i <= n; ++i) {		
	    pair < pii, int > v1 = {{a[i], b[i]}, c[i]};
	    pair < pii, int > v2 = {{b[i], a[i]}, c[i] ^ 1};	    
		if (was.count(v1))
			continue;

		was[v1] = 1;
		was[v2] = 1;
		ans = ans * (p[cnt[v1]] + p[cnt[v2]] - 1) % mod;
	}
	
	cout << (ans + 2*mod - 1 + add) % mod << endl;
}	

Measured memory_bytes: 72332
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int [] List = new int[N];
        for(int num=0;num<N;num++){
            int k =0;
            if(a.charAt(num)==b.charAt(num)) k++;
            if(a.charAt(num)==c.charAt(num))k++;
            if(b.charAt(num)==c.charAt(num))k++;
            if(k==0)List[num]=2;
            else if(k==1) List[num]=1;
        }
        int sum=0;
        for(int d=0;d<N;d++) sum+=List[d];
        System.out.println(sum);
    }
}


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

int main()
{
    int N, Y;
    cin >> N >> Y;
    int a = -1, b = -1, c = -1;
    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; i + j <= N; j++)
        {
            if (i * 10000 + j * 5000 + (N - i - j) * 1000 == Y)
            {
                a = i;
                b = j;
                c = (N - i - j);
            }
        }
    }
    cout << a << " " << b << " " << c << endl;
}


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

int main() {
	int N , M;
  	cin >> N >> M;
    int a , b;
  	vector<int> toshi(N);
  	for(int i = 0; i < M;  i++){
    	cin >> a >> b;
      	toshi.at(a - 1)++;
        toshi.at(b - 1)++;
    }
  	for(int i = 0; i < N; i++){
    	cout << toshi.at(i) << endl;
    }
}

Measured memory_bytes: 3496
# include <bits/stdc++.h>
#define flash ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define ll long long int
#include <tr1/unordered_map>
#define ld long double
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define f(i,a,b)  for(long long i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#include <map>

using namespace std;
ll dp[2005];
ll solve(ll n)
{
    if(n==1||n==2)
    {
        return dp[n]=0;
    }
    else if(n>=3&&n<=5)
    {
        return dp[n]=1;
    }
    else if(dp[n]!=-1)
    {
        return dp[n];
    }
    else
    {
        ll total=0;
        for(ll i=3;i<=n;i++)
        {
            total = (total%MOD + solve(n-i)%MOD)%MOD;
        }
        return dp[n]=total%MOD;

    }
}
int main()
{


     flash;
     ///////////////////////////////////////////////////////////////////////////////////////

memset(dp,-1,sizeof(dp));
dp[0]=1;
ll n;
cin>>n;
cout<<solve(n)%MOD;




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

     return 0;

}


Measured memory_bytes: 3612
#!/usr/bin python3
# -*- coding: utf-8 -*-

H, W = map(int,input().split())
sth, stw = 0, 0
glh, glw = H-1, W-1

INF = 0
Gmap = [list(input()) for _ in range(H)]
Dist = [[INF]*W for _ in range(H)]
direc = {(1,0), (0,1)}
mod = 10**9+7

from collections import deque

def bfs(init):
    next_q = deque([])
    for hi, hw in init:
        next_q.append([hi,hw])
        Dist[hi][hw] = 1

    while len(next_q)!=0:
        #キュー取り出し(先頭)
        h,w = next_q.popleft()
        for d in direc:
            hs, ws = h + d[0], w + d[1]
            if not (0<=hs<H and 0<=ws<W):
                continue
            if Gmap[hs][ws]=='.':
                if Dist[hs][ws]==INF:
                    next_q.append([hs,ws])
                Dist[hs][ws] += Dist[h][w]
                Dist[hs][ws] %= mod
    return Dist

def main():
    ret = bfs([[sth, stw]])
    print(ret[glh][glw])

if __name__ == '__main__':
    main()

Measured memory_bytes: 51848
#include <bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
#define int long long
using namespace std;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int l) { uniform_int_distribution<int> uid(0, l - 1); return uid(rang); }

int a[3001][3001];

int32_t main() {
	// #ifndef ONLINE_JUDGE
	// 	freopen("/tmp/input", "r", stdin);
	// 	freopen("/tmp/output", "w", stdout);
	// #endif
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	string s; cin >> s;
	string t; cin >> t;
	int n = s.size();
	int m = t.size();
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if (s[i] == t[j])
			{
				a[i + 1][j + 1] = a[i][j] + 1;
			} else {
				a[i + 1][j + 1] = max(a[i][j + 1], a[i + 1][j]);
			}
		}
	}
	string s1 = "";
	int i = n, j = m;
	while(i && j) {
		if (s[i - 1] == t[j - 1])
		{
			s1 += string(1, s[i - 1]);
			i--; j--;
		} else {
			if (a[i - 1][j] > a[i][j - 1])
			{
				i--;
			} else {
				j--;
			}
		}
	}
	reverse(s1.begin(), s1.end());
	cout << s1;
}

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

enum {
	A,
	B,
	C,
	D,
	E,
	F,
	G,
	H,
	I,
	J,
	K,
	L,
	M,
	N,
	O,
	P,
	Q,
	R,
	S,
	T,
	U,
	V,
	W,
	X,
	Y,
	Z
};

int main(int argc, char const* argv[])
{
	std::string str;
	int count[26] = {};
	char ch[27] = "abcdefghijklmnopqrstuvwxyz";

	while(std::cin >> str)
		for (size_t i = 0; i < str.size(); i++)
			count[std::toupper(str[i]) - 'A'] += 1;

	for (size_t j = 0; j < 26; j++)
		std::cout << ch[j] << " : " << count[j] << std::endl;

	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

bool is_ok(ll x, ll n, ll m, ll k, vector<ll>& suma, vector<ll>& sumb) {
    for (ll i = 0; i <= min(x, n); i++) {
        ll j = x - i;
        if (j > m) continue;
        if (suma[i] + sumb[j] <= k) return true;
    }
    return false;
}

ll binary_search(ll l, ll r, ll n, ll m, ll k, vector<ll>& suma, vector<ll>& sumb) {
    if (l + 1 == r) return l;
    ll mid = (l + r) / 2;
    if (is_ok(mid, n, m, k, suma, sumb)) return binary_search(mid, r, n, m, k, suma, sumb);
    else return binary_search(l, mid, n, m, k, suma, sumb);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //const ll p = 1e9 + 7;
    //const ll p = 998244353;
    
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n), b(m);
    for (ll i = 0; i < n; i++) cin >> a[i];
    for (ll i = 0; i < m; i++) cin >> b[i];
    
    if (a[0] > k || b[0] > k) {
        cout << 0 << endl;
        return 0;
    }
    
    vector<ll> suma(n + 1, 0), sumb(m + 1, 0);
    for (ll i = 0; i < n; i++) suma[i + 1] = suma[i] + a[i];
    for (ll i = 0; i < m; i++) sumb[i + 1] = sumb[i] + b[i];
    if (suma[n] + sumb[m] <= k) {
        cout << n + m << endl;
        return 0;
    }
    
    cout << binary_search(0, n + m, n, m, k, suma, sumb) << endl;
}

Measured memory_bytes: 9536
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n;
	while(cin>>n){
		string s;
		cin>>s;
		char a=s[0],b=s[1];
		s=s.substr(2);
		int ans=0;
		rep(l,n){
			string t;
			cin>>t;
			bool f=false;
			rep(i,t.size()){
				if(t[i]==a){
					reep(j,i+1,t.size()){
						if(b==t[j]){
							bool ff=true;
							rep(k,s.size()){
								int tt=j+(k+1)*(j-i);
								if(tt>=t.size()||s[k]!=t[tt]){
									ff=false;
									break;
								}
							}
							if(ff){
								f=true;
								goto end;
							}
						}
					}
				}
			}
			end:
			if(f){
				ans++;
				// cout<<t<<endl;
			}
		}
		cout<<ans<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1212
n = int(input())
a = list(map(int,input().split()))
sums = 0
b = 0
count = 1
for i in range(len(a)-1):
  sums += a[i+1] - a[i]
  #print(i,sums,b)
  if sums >= 0 and sums < b or b > 0 and sums < 0:
    count += 1
    sums = 0
  elif sums <= 0 and sums > b or b < 0 and sums > 0:
    count += 1
    sums = 0
  b = sums
  
print(count)

Measured memory_bytes: 14228
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; }
typedef pair<ll,ll> pll;
const ll INF=1e18;
const ll mn=4e5+4;
ld a[mn];
ld p2[mn];
ll n,d1,x;
ld harmonic[mn];
int main() {
	ld now=1.0;
	for (ll i=0;i<mn;i++) {
		p2[i]=now;
		now/=2;
	}
	scanf("%lld %lld %lld",&n,&d1,&x);
	for (ll i=0;i<2*n;i++) {
		a[i]=d1+i*x;
	}
	now=0;
	for (ll i=0;i<=n;i++) {
		harmonic[i]=now;
		now+=1.0/(i+1);
	}
	ld ans=0;
	for (ll i=0;i<2*n;i++) ans+=a[i]/2;
	for (ll k=0;k<2;k++) {
		for (ll y=1;y<n;y++) {
			ld sum=a[y*2]+a[(y*2)+1];
			ld add=0.25*(harmonic[y+1]-1)*sum;
			ans+=add;
		}
		reverse(a,a+2*n);
	}
	printf("%.8f\n",(double)ans);
}


Measured memory_bytes: 15872
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    L = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
    for i in range(N):
        S = input().rstrip()
        if S[0] in L:
            L[S[0]] += 1
    CNT = 0
    i = 0
    S = [0]*5
    for k, v in L.items():
        S[i] = v
        i += 1
    ans = 0
    for p in range(3):
        for q in range(p+1,4):
            for r in range(q+1,5):
                ans += S[p]*S[q]*S[r]
    print(ans)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<size_t I,class H,class...T>struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template<class H,class...T>struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class...T>istream&operator>>(istream&i,tuple<T...>&t){t=TupleReaderWriter<sizeof...(T),T...>::r(i);return i;}
template<class...T>ostream&operator<<(ostream&o,tuple<T...>&t){string delim=" ";TupleReaderWriter<sizeof...(T)-1,T...>::w(o,t,delim);return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector2d<int> ans(H, vector<int>(W, 0));
    int flag = 0;
    bool exist = false;
    int x = -1, x_;
    int k = 0;
    for(int i = 0; i < H; i++) {
        string s;
        cin >> s;
        for(int j = 0; j < W; j++) {
            if(s[j] == '#') {
                flag++;
                exist = true;
                k++;
                x_ = i;
                ans[i][j] = k;
                int m = j;
                while(m > 0 && ans[i][--m] == 0) {
                    ans[i][m] = k;
                }
            } else {
                if(exist) ans[i][j] = k;
            }
        }
        if(i > 0 && ans[i - 1][0] == 0) {
            if(flag > 0) {
                for(int j = 0; j < W; j++) {
                    for(int l = i - 1; l >= 0; l--) {
                        ans[l][j] = ans[i][j];
                    }
                }
            } else if (exist) {
                for (int j = 0; j < W; j++) {
                    for (int l = i - 1; l > x; l--) {
                        ans[l][j] = ans[i][j];
                    }
                }
            }
        }
        if(flag > 0) flag = -1e7;
        x = x_;
        exist = false;
    }
    for(int i = 1; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(ans[i][j] == 0) ans[i][j] = ans[i - 1][j];
        }
    }
    for(int i = 0; i < H; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;



int main(){
    string a,b,c;
    cin >> a >> b >> c;
    char A,B,C;
    A=a[0]-32;
    B=b[0]-32;
    C=c[0]-32;
    cout << A << B << C << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef unsigned long long ull;
int main() {
    ull a, b, x;
    cin >> a >> b >> x;
    ull ans = 0;
    if(a % x == 0) ans++;
    ans = ans + (b / x - a / x);
    cout << ans;
    return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if(a == 1){
		a = 14;
	}
	if(b == 1){
		b = 14;
	}
	if(a == b){
		cout << "Draw" << endl;
	}else if(a < b){
		cout << "Bob" << endl;
	}else{
		cout << "Alice" << endl;
	}
	
	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); 
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	for(int i = 0; i <= n; i++) {
		string r = string(s.begin(), s.begin() + i) + t;
			cerr << r << endl;
		if(r.substr(0, n) == s) {
			cout << r.length() << endl;
			return 0;
		}
	}
	return 0;	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    int a[m], cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < m; i++) {
        cin >> a[i];
        if (a[i] > x) {
            cnt2++;
        } else cnt1++;
    }
    cout << min(cnt1, cnt2) << endl;
}

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

using namespace std;
using ll = long long;

int main() {
    int Sum = 0, diagSum = 0;
    for (int i = 0; i < 9; ++i) {
        int x;
        cin >> x;
        Sum += x;
        if (i == 0 || i == 4 || i == 8)
            diagSum += x;
    }
    if (Sum % 3 == 0 && Sum / 3 == diagSum)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

using namespace std;

int main()
{
	int a, b, c, k;
	int i = 0;
	int sum = 0;
	cin >> a >> b >> c >> k;

	for (; i < k && a != 0; i++)
	{
		sum++;
		a--;
	}
	if (k == i)
	{
		cout << sum;
		return 0;
	}
	for (; i < k && b != 0; i++)
	{
		b--;
	}
	if (i == k)
	{
		cout << sum;
		return 0;
	}
	for (; i < k && c != 0; i++)
	{
		sum--;
		c--;
	}
	cout << sum;

	return 0;
}

Measured memory_bytes: 3552
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;
 
 int main(void){
     int N,A,B,st=0,ty=0,en=0,a;
     cin >> N >> A >> B;
     int P[N+10];
     for(int i=0; i<N; i++){
         cin >> P[i];
         if(P[i]<=A){
             st+=1;
         }else if(P[i]>A && P[i]<=B){
             ty+=1;
         }else if(P[i]>B){
             en+=1;
         }
     }
     a=min(st,ty);
     a=min(a,en);
    cout << a << endl;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

int main(){
    int a,b;
    cin>>a>>b;
    if(b%a==0)cout<<a+b<<endl;
    else cout<<b-a<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc128/tasks/abc128_f>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<ll> s(N); for(auto& in:s) cin >> in;

    for(int C = 1; C < N;C++){
        map<ll,int> mp;
        ll dp = 0;
        for(int k = 1; k < N; k++){
            if((k+1)*C >= N-1) break;
            ll p1 = N-1-k*C;
            ll p2 = k*C;
            if(mp[p1]) break;
            mp[p1]++;
            if(mp[p2]) break;
            mp[p2]++;
            
            dp += s[N-1-k*C] + s[k*C];
            res = max(res,dp);
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <regex>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;

const int MOD = 1e9+7;

int main(void){
  ll cnt = 0;
  string str;
  cin >> str;
  str[5] = ' ';
  str[13] = ' ';
  cout << str << endl;
  return 0;
}

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

int main()
{
	int k, s;
	cin>>k>>s;
	int ans = 0;
	for(int i=0;i<=k;i++)
	{
		for(int j=0;j<=k;j++)
		{
			int p = s - i - j;
			if(p <= k && p >= 0) ++ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(int argc, char const *argv[])
{
  int A,B,M;
  scanf("%d%d%d",&A,&B,&M);
  int a[A],b[B],x,y,c;
  int mina=100000,minb=100000;
  int min,los;
  for(int i=0;i<A;i++){
    scanf("%d",&a[i]);
    if(a[i]<mina) mina=a[i];
  }
  for(int i=0;i<B;i++){
    scanf("%d",&b[i]);
    if(b[i]<minb) minb=b[i];
  }
  min=mina+minb;
  for(int i=0;i<M;i++){
    scanf("%d%d%d",&x,&y,&c);
    los=a[x-1]+b[y-1]-c;
    if(los<min) min=los;
  }
  printf("%d",min);
  return 0;
}


Measured memory_bytes: 896
n = int(input())
cards = [[ s+' '+str(n) for n in range(1,14)] for s in ['S','H','C','D']]
for _ in range(n):
    suit,num = input().split()
    if   suit=='S': cards[0][int(num)-1] = 0
    elif suit=='H': cards[1][int(num)-1] = 0
    elif suit=='C': cards[2][int(num)-1] = 0
    elif suit=='D': cards[3][int(num)-1] = 0
for s in cards:
    for n in s:
        if n!=0: print(n)

Measured memory_bytes: 7708
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int now = 0;
    lint ans = 1;
    REP(i, N*2) {
        if(S[i] == 'B') {
            if(now%2 == 0) {
                now++;
            } else {
                ans = (ans * now) % MOD;
                now--;
            }
        } else {
            if(now == 0) {
                cout << 0 << endl;
                return 0;
            } else if(now%2 == 0) {
                ans = (ans * now) % MOD;
                now--;
            } else {
                now++;
            }
        }
    }
    if(now != 0) {
        cout << 0 << endl;
        return 0;
    }
    FOR(i, 1, N+1) {
        ans = (ans * i) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	int N;
	cin >> N;
	vector<int>a(N);
	int ma = -1;
	int mi = 1e7;
	for (int i = 0; i < N; i++) { cin >> a[i]; ma = max(ma, a[i]), mi = min(mi, a[i]); }
	
	if (ma - mi >= 2) { puts("No");}
	else if (ma - mi == 1) {
		int macnt = 0;
		int micnt = 0;
		for (int i = 0; i < N; i++) {
			if (a[i] == ma)macnt++;
			else micnt++;
		}
      	if(macnt == 1)puts("No");
		else if (micnt + 1 <= ma && ma <= micnt + (macnt / 2))puts("Yes");
		else puts("No");
	}
	else {
		if (1 <= ma && ma <= N / 2)puts("Yes");
		else if (ma == N - 1)puts("Yes"); 
		else puts("No");
	}
 
	return 0;
}

Measured memory_bytes: 640
#include <float.h>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int A1;
  int A2;
  int A3;
  cin >> A1 >> A2 >> A3;
  int sum;
  sum = A1 + A2 + A3;
  if (sum >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

typedef struct UnionFindTree{
  vector<int> par;
  vector<int> treerank;
  
  UnionFindTree(int n){
    par.resize(n); treerank.resize(n);
    rep(i, n) par[i] = i, treerank[i] = 0;
  }
  
  int find(int x){
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  
  void unite(int x, int y){
    x = find(x); y = find(y);
    if(x == y) return;
    if(treerank[x] < treerank[y]) swap(x, y);
    if(treerank[x] == treerank[y]) treerank[x]++;
    par[y] = x;
    return;
  }
  
  bool same(int x, int y){
    return find(x) == find(y);
  }
}UF;
 
template<class T> struct edge{
    int from, to; T cost;
    edge(int f, int t, T c){
        from = f; to = t; cost = c;
    }
};
 
template<class T> struct Graph{
    vector<vector<edge<T>>> G;
    int n;
    
    Graph(int n_){
        n = n_;
        G.resize(n);
    }
    
    void add_edge(int f, int t, T c){
        G[f].emplace_back(f, t, c);
    }
    
    vector<T> dijkstra(int s){
        using P = pair<T, int>;
        priority_queue<P, vector<P>, greater<P>> que;
        vector<T> d(n, numeric_limits<T>::max());
        d[s] = 0;
        que.push(P((T)0, s));
        while(!que.empty()){
            P p = que.top(); que.pop();
            int v = p.second;
            if(d[v] < p.first) continue;
            for(edge<T> &e : G[v]){
                if(d[e.to] > d[v] + e.cost){
                    d[e.to] = d[v] + e.cost;
                    que.push(P(d[e.to], e.to));
                }
            }
        }
        return d;
    }
    
    T kruskal(){
        vector<edge<T>> E;
        rep(i, n)for(edge<T> &e: G[i]) E.push_back(e);
        sort(E.begin(), E.end(), [](const edge<T> &e1, const edge<T> &e2){return e1.cost < e2.cost;});
        UF uf(n);
        T res = 0;
        for(edge<T> &e: E){
            if(!uf.same(e.from, e.to)){
                uf.unite(e.from, e.to);
                res += e.cost;
            }
        }
        return res;
    }
    
    void toposo(){
        vector<int> ret(n, -1), in(n, 0);
        rep(i, n)for(edge<T> &e: G[i]) ++in[e.to];
        stack<int> st;
        rep(i, n)if(!in[i]) st.push(i);
        while(!st.empty()){
            int v = st.top(); st.pop();
            for(edge<T> &e: G[v]){
                --in[e.to];
                if(!in[e.to]){
                    st.push(e.to);
                    ret[e.to] = v;
                }
            }
        }
        rep(i, n) printf("%d\n", ret[i]+1);
    }
};

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    Graph<int> g(n);
    rep(i, n-1+m){
        int a, b;
        scanf("%d%d", &a, &b);
        g.add_edge(a-1, b-1, 0);
    }
    g.toposo();
}

Measured memory_bytes: 7040
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;


int main(void) {
	int A, B;
	cin >> A >> B;
	int c = A + B;
	int d = A - B;
	int e = A * B;
	if (c < d) {
		if (d < e) cout << e << endl;
		else cout << d << endl;

	}
	else {
		if (c < e) cout << e << endl;
		else cout << c << endl;
	}
	
}

Measured memory_bytes: 256
main = do
        waste <- getLine 
        get <- getLine
        let ls = map read (words get) :: [Integer]
        let ans = sum $ map factorize ls
        putStrLn (show ans)

factorize :: Integer -> Integer
factorize i = if i `mod` 2 == 0 then (1 + factorize (i `div` 2)) else 0

Measured memory_bytes: 7548
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
using namespace std;
 
#define ll long long int
const int MOD = 1000000007;//10^9+7
 
int max(int a, int b) {
 
	if (a > b)return a;
	else return b;
 
}
//aとbの大きい方
 
int min(int a, int b) {
 
	if (a < b)return a;
	else return b;
 
}
//aとbの小さい方
 
int avd_i(int a, int b) {
 
	if (a > b)return a - b;
	else return b - a;
 
}
double avd_d(double a, double b) {
 
	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;
 
}
//aとbの差の絶対値
 
ll calc(ll a, ll b, ll p) {
 
	if (b == 0) {
 
		return 1;
 
	}
	else if (b % 2 == 0) {
 
		ll d = calc(a, b / 2, p);
		return ((d%p)*(d%p)) % p;
 
	}
	else {
 
		return ((a%p)*calc(a, b - 1, p) % p) % p;
 
	}
 
}
//pは素数,aのb乗をpで割った余り
 
ll CMOD(ll n, ll r, ll p) {
 
	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {
 
		a *= i;
		a = a%p;
 
	}
	for (int i = 1; i <= r; i++) {
 
		b *= i;
		b = b%p;
 
	}
	for (int i = 1; i <= n - r; i++) {
 
		c *= i;
		c = c%p;
 
	}
	b = calc(b, p - 2, p);
	c = calc(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;
 
	return re;
 
}
//pは素数,(nCr)%p
 
int main() {
 
	int X, T;
 
	cin >> X >> T;
	if (X > T)cout << X - T << endl;
	else cout << 0 << endl;
 
	return 0;
}

Measured memory_bytes: 256
/*input
1
11 11
*/

#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 k, a, b;
  cin >> k >> a >> b;
  int c = b/k*k;
  if (a <= c) cout << "OK" << endl;
  else cout << "NG" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int uni[N],dis[N],sz[N][3],n,m,tag[N],num[N],deg[N];
long long ans;
int getfa(int pos) {
  if (uni[pos] == pos) return pos;
  int ret = getfa(uni[pos]);
  (dis[pos] += dis[uni[pos]]) %= 3;
  return uni[pos] = ret;
}
int main() {
  int x,y,a,b;
  scanf("%d%d",&n,&m);
  for (int i = 1 ; i <= n ; ++ i)
    uni[i] = i, dis[i] = 0;
  for (int i = 1 ; i <= m ; ++ i) {
    scanf("%d%d",&x,&y);
    a = getfa(x), b = getfa(y);
    ++ deg[x];
    ++ deg[y];
    if (a != b) {
      uni[b] = a;
      dis[b] = (dis[x] + 4 - dis[y]) % 3;
    } else {
      if ((dis[y] - dis[x] + 3) % 3 == 1);
      else tag[a] = 1;
    }
  }
  for (int i = 1 ; i <= n ; ++ i) {
    num[getfa(i)] += deg[i];
    tag[getfa(i)] |= tag[i];
    sz[getfa(i)][(dis[i] + 3) % 3] ++;
  }
  for (int i = 1 ; i <= n ; ++ i) {
    if (getfa(i) != i) continue;
    if (tag[i]) ans += 1ll * (sz[i][0] + sz[i][1] + sz[i][2]) * (sz[i][0] + sz[i][1] + sz[i][2]);
    else {
      if ((!sz[i][0]) || (!sz[i][1]) || (!sz[i][2]))
	ans += num[i] / 2;
      else
	ans += 1ll * sz[i][0] * sz[i][1] + 1ll * sz[i][1] * sz[i][2] + 1ll * sz[i][2] * sz[i][0];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<cmath>


using namespace std;

int main(){
  int N,A,B;
  
  cin>>N>>A>>B;
  
  
  if(abs(N-A)<abs(N-B)){
    cout<<"A";
  }else{
    cout<<"B";
  }
  
  cout<<endl;
}


Measured memory_bytes: 256
import sys
import heapq

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())

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

    q, k = map(int, input().split())
    Query = [list(map(int, input().split())) for _ in range(q)]

    def dijkstra_heap(s):
        # 始点sから各頂点への最短距離
        d = [float("inf")] * n
        used = [True] * n  # True:未確定
        d[s] = 0
        used[s] = False
        edgelist = []
        for e in edge[s]:
            heapq.heappush(edgelist, e)
        while len(edgelist):
            minedge = heapq.heappop(edgelist)
            # まだ使われてない頂点の中から最小の距離のものを探す
            if not used[minedge[1]]:
                continue
            v = minedge[1]
            d[v] = minedge[0]
            used[v] = False
            for e in edge[v]:
                if used[e[1]]:
                    heapq.heappush(edgelist, [e[0] + d[v], e[1]])
        return d

    dist = dijkstra_heap(k - 1)

    for x, y in Query:
        res = dist[x - 1] + dist[y - 1]
        print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 77308
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
  ll a,b,x,min=0;
  cin>>a>>b>>x;

  if (a!=0)
  {
    cout << b/x-(a-1)/x << endl;
  }
  else
  {
    cout << b/x+1 << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int m=1e9+7;
int dp[100009];
int n;
ll cant[100009];
ll call(ll val)
{
    if(val==n)return 1;
    if(val>n)return 0;
    if(cant[val]==1)return 0;
    if(dp[val]!=-1)return dp[val];
    ll f1=0,f2=0;
    ll ans=(call(val+1)%m+call(val+2)%m)%m;
    dp[val]=ans;
    return ans;
}

int main()
{
    cin>>n;
    int m;cin>>m;
    for(int i=0;i<m;i++){
        int a;cin>>a;
        cant[a]=1;
    }
    memset(dp,-1,sizeof dp);
    cout<<call(0)<<endl;
}


Measured memory_bytes: 4480
def rotate(src)
  src[-1] + src[0..-2]
end

def main
  s = ARGF.gets.chomp
  t = ARGF.gets.chomp

  if s == t
    puts 'Yes'
    return
  end

  (s.length - 1).times do
    # 回転
    r = rotate(s)
    if r == t
      puts 'Yes'
      return
    end

    s = r
  end

  puts 'No'
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 1788
using System;

public class Test
{
	public static void Main()
	{
		var dice = Console.ReadLine().Split();
        var rotate = new Action<int, int, int, int>((d1, d2, d3, d4) => {
            var tmp = dice[d1]; dice[d1] = dice[d2]; dice[d2] = dice[d3]; dice[d3] = dice[d4]; dice[d4] = tmp;
        });
        foreach (var c in Console.ReadLine()) {
            switch (c) {
                case 'N':
                    rotate(0, 1, 5, 4);
                    break;
                case 'E':
                    rotate(0, 3, 5, 2);
                    break;
                case 'W':
                    rotate(0, 2, 5, 3);
                    break;
                case 'S':
                    rotate(0, 4, 5, 1);
                    break;
            }
        }
        Console.WriteLine(dice[0]);
	}
}

Measured memory_bytes: 9232
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n;

	cin >> n;
	vector<int> l(2 * n, 0);
	for (int i = 0; i < l.size(); i++) {
		cin >> l[i];
	}
	sort(l.begin(), l.end());

	int ans = 0;
	for (int i = 0; i < l.size(); i += 2) {
		ans += l[i];
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
h.append(0)
cnt = 0
while True:
    flag = True
    for i in h:
        if i != 0:
            flag = False

    if flag:
        break

    l = 0
    while h[l] == 0:
        l += 1

    r = l
    while h[r+1] != 0 and r < n:
        r += 1

    for i in range(l, r+1, 1):
        h[i] -= 1
    cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 20000000000000000
#define mod 998244353
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
//knight and king//
int dr[]= {2,2,-2,-2,1,-1,1,-1};
int dc[]= {1,-1,1,-1,2,2,-2,-2};
int dr1[]= {0,0,1,1,1,-1,-1,-1};
int dc1[]= {1,-1,1,0,-1,0,1,-1};
int dr2[]= {0,0,1,-1};
int dc2[]= {1,-1,0,0};
////////////////////////////
using namespace std;
#define ma 200000
ll b[ma],a[ma];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll i,j,x,y,n,m,k,q;
    while(cin>>n)
    {
       set<ll>s[26];
       for(i=0;i<26;i++)s[i].insert(n+2);
       string t;
       cin>>t;
       for(i=0;i<t.sz;i++)s[t[i]-'a'].insert(i+1);
       cin>>q;
       while(q--)
       {
           cin>>m;
           if(m==2)
           {
               cin>>x>>y;
               ll ans=0;
               for(i=0;i<26;i++)
               {
                   ll r=*s[i].lower_bound(x);
                   if(r<=y)ans++;
               }
               cout<<ans<<endl;
           }
           else
           {
               char ch;
               cin>>x>>ch;
               ll r=t[x-1]-'a';
               s[r].erase(s[r].find(x));
               ll y=ch-'a';
               s[y].insert(x);
               t[x-1]=ch;

           }
       }

    }

    return 0;
}


Measured memory_bytes: 27212
s = list(str(input()))
S = []
for i in range(len(s)):
  S.append(int(s[i]))
ans1 = 100000
ans2 = 100000
ans = 0
t = 0
s = 0

if S[0]==0:
  for i in range(1,len(S),2):
    if S[i] != 1:
      t += 1
  for i in range(0,len(S),2):
    if S[i] != 0:
      s += 1
  ans1 = min(t+s,len(S)-t-s)
else:
  for i in range(1,len(S),2):
    if S[i] != 0:
      t += 1
  for i in range(0,len(S),2):
    if S[i] != 1:
      s += 1
  ans2 = min(t+s,len(S)-t-s) 
ans=min(ans1,ans2)
print(ans)


Measured memory_bytes: 4776
#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>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

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

int main() {
	int N, S;
	cin >> N >> S;
	vector<int> A(N);
	for (int n = 0; n < N; ++n) {
		cin >> A[n];
	}
	vector<vector<mint> > dp(N + 1, vector<mint>(S + 1,0));

	(dp[0])[0] = 1;


	for (int n = 0 ; n < N; ++n) {
		for (int m = 0; m < S + 1; ++m) {
			dp[n +1][m] += (mint)2 * dp[n][m];
			if (m+A[n] <= S) {
				dp[n+1][m+A[n]] += dp[n][m];
			}
		}
	}
	cout << dp[N][S]<<endl;
	
	return 0;
}

Measured memory_bytes: 73700
a, b, k = input().split()
a = int(a)
b = int(b)
k = int(k)
a_list = []
b_list = []
for j in range(a):
    i = j + 1
    if a % i == 0:
        a_list.append(i)
for j in range(b):
    i = j + 1
    if b % i == 0:
        b_list.append(i)

#a_list.extend(b_list)
#co_divisor = list(set(a_list))
a_list = set(a_list)
b_list = set(b_list)
co_divisor = list(a_list & b_list)
co_divisor.sort(reverse=True)
print(co_divisor[k-1])

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

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextLong();
        }
        Arrays.sort(A);
        long sum = 0;
        for (int i = 0; i < N - 1; i++) {
            sum += A[N - 1 - (i + 1) / 2];
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 61484
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		vector<vector<int> >in(n+1,vector<int>(n+1));
		rep(i,n)rep(j,n)cin>>in[i][j];
		rep(i,n){
			int sum=0;
			rep(j,n)sum+=in[i][j];
			in[i][n]=sum;
		}
		rep(i,n+1){
			int sum=0;
			rep(j,n)sum+=in[j][i];
			in[n][i]=sum;
		}
		rep(i,n+1){
			rep(j,n+1)printf("%5d",in[i][j]);
			cout<<endl;
		}
	}
}

Measured memory_bytes: 1248
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

const ll M = pow(10,9)+7;

vector<ll> fac(1000001); //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)


ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCb(mod M)
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}


int main(){
  int S;
  cin >> S;
  fac[0] = 1;
  ifac[0] = 1;
  for(ll i = 0; i<2001; i++){
        fac[i+1] = fac[i]*(i+1) % M; 
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; 
  }
  ll ans = 1;
  int k = 6;
  int n = 2;
  while (S>=k){
    ans = ans + (comb(S-3*n+n-1,n-1))%M;
    n++;
    k = k+3;
  }
  if(S<3) ans = 0;
  if(ans%M<0) cout << ans%M+M << endl;
  else cout << ans%M << endl;
}


Measured memory_bytes: 18216
C = []
for _ in range(3):
    C.append(list(map(int, input().split())))

ans = False
for a1 in range(0, 101):
    for a2 in range(0, 101):
        for a3 in range(0, 101):
            b1, b2, b3 = C[0][0] - a1, C[0][1] - a1, C[0][2] - a1
            flag1 = (b1 == C[1][0] - a2) and (b1 == C[2][0] - a3)
            flag2 = (b2 == C[1][1] - a2) and (b2 == C[2][1] - a3)
            flag3 = (b3 == C[1][2] - a2) and (b3 == C[2][2] - a3)
            if flag1 and flag2 and flag3:
                ans = True

if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 45676
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline()).split())

n,m=nii()

list=[[] for i in range(n+1)]

for i in range(m):
  p,y=nii()
  list[p].append([y,i])

ans=[]
for i in range(1,n+1):
  tl=list[i]
  s_tl=sorted(tl,key=lambda x:x[0])
  for j in range(len(tl)):
    town=s_tl[j][1]
    s1=str(i).zfill(6)
    s2=str(j+1).zfill(6)
    s=s1+s2
    ans.append([town,s])

ans.sort(key=lambda x:x[0])
for i,j in ans:
  print(j)

Measured memory_bytes: 49984
class UnionFind:
    def __init__(self,N):
        self.table = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N
    
    def find(self,x):
        if self.table[x] == x:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
    
    def unite(self,x,y):
        x,y = self.find(x),self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.table[x] = y
            self.size[y] += self.size[x]
        else:
            self.table[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    
    def same(self,x,y):
        return self.find(x) == self.find(y)
    
    def count(self,x):
        return self.size(x)

N,M = map(int,input().split())
P = list(map(int,input().split()))
uf = UnionFind(N)
for _ in range(M):
    x,y = map(int,input().split())
    uf.unite(x-1,y-1)

count = 0
for i in range(N):
    if uf.same(P[i]-1,i):
        count += 1

print(count)

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

using namespace std;

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

    using ll = long long;
    map<ll, ll> mp;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        mp[x]++;
    }

    vector<ll> v;
    for (auto m : mp) {
        if (m.second >= 2) {
            for (int i = 0; i < m.second / 2; i++) {
                v.emplace_back(m.first);
            }
        }
    }

    sort(v.rbegin(), v.rend());
    if (v.size() < 2) {
        cout << 0 << endl;
    } else {
        cout << v[0] * v[1] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 6528
import java.util.Scanner;
class Main { public static void main(String args[]) { 
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt(); 
int x=n*m;
int y=2*(n+m);
System.out.print(x);
System.out.print(" ");
System.out.println(y); } }


Measured memory_bytes: 26200
#include <bits/stdc++.h>
#define rep(i, e, n) for (int i = e; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const ll inf=1000000000007;

int main() {
  char b;
  cin >> b;
  if(b=='A') cout << 'T' << endl;
  if(b=='T') cout << 'A' << endl;
  if(b=='G') cout << 'C' << endl;
  if(b=='C') cout << 'G' << endl;

  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <algorithm>

int main()
{
    long long int a[5], k;
    std::cin >> a[0] >> a[1] >> a[2] >> k;

    std::sort(a, a + 3);

    while (k--)
    {
        a[2] *= 2;
    }

    std::cout << a[2] + a[1] + a[0];
}


Measured memory_bytes: 256