akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <climits>
#include <utility>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#define REP(i,n) for(int (i)=0;i<(int)(n);++(i))
#define REPIT(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define PB push_back
#define FT first
#define SD second
#define ZERO(x) memset(x,0,sizeof(x))
#define NEG(x) memset(x,-1,sizeof(x))
#define RI(x) scanf("%d",&(x))
#define RII(x,y) scanf("%d%d",&(x),&(y))
#define RIII(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))
#define OIII(x,y,z) printf("%d %d %d\n",(x),(y),(z))
#define OII(x,y) printf("%d %d\n",(x),(y))
#define OI(x) printf("%d\n",(x))
#define OL(x) cout<<(x)<<endl
#define OLL(x,y) cout<<(x)<<" "<<(y)<<endl
#define OLLL(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define RS(s) scanf("%s",(s))
#define MP(x,y) make_pair((x),(y))
#define SZ(x) ((int)(x).size())
#define FIN(f) freopen(f,"r",stdin)
#define FOUT(f) freopen(f,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<int,int> PII;
const int MOD = 1e9+7;
const int maxn = 5555;
int n;
string s;
LL dp[maxn][maxn];
void upd(LL &x ,LL v) {
    x += v;
    x%=MOD;
}
int main(int argc, char const *argv[])
{
    cin>>n>>s;
    dp[0][0] = 1;
    for(int i=0;i<n;++i)
        for(int j=0;j<n;++j) {
            if(dp[i][j] == 0)continue;
            if(j)upd(dp[i+1][j-1], dp[i][j]); //B
            if(j && j<=s.size())upd(dp[i+1][j-1], dp[i][j]);
            if(j==0)upd(dp[i+1][j], dp[i][j]);
            upd(dp[i+1][j+1],dp[i][j]); // 01
            if(j>=s.size())upd(dp[i+1][j+1],dp[i][j]);
        }
    cout<<dp[n][s.size()]<<endl;
    return 0;
}

Measured memory_bytes: 118016
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  string s;
  cin>>s;
  int ans(1e9);
  for (int i(0);i<s.size()-2;i++){
    int num = (s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0');
    ans = min({ans,abs(num-753),abs(753-num)});
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner stdInt = new Scanner(System.in);

		int a = stdInt.nextInt();
		int b = stdInt.nextInt();
		int c = stdInt.nextInt();

		System.out.println(c + " " + a + " " + b);
	}
}

Measured memory_bytes: 21844
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

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

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

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

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

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

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

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

    int n;
    lint k;
    cin >> n >> k;

    vector<lint> a(n);
    lint s = 0;
    rep(i, n){
        cin >> a[i];
        s += a[i];
    }

    vector<lint> d;
    for(lint i = 1 ; i * i <= s ; ++i){
        if(s % i == 0LL){
            d.emplace_back(i);
            if(i != s / i){
                d.emplace_back(s / i);
            }
        }
    }

    lint ans = 1;
    rep(i, d.size()){
        sort(a.begin(), a.end(), [&](lint l, lint r){ return l % d[i] < r % d[i]; });
        vector<lint> sum(n + 1);
        reps(j, n){
            sum[j] = sum[j - 1] + (a[j - 1] % d[i]);
        }
        lint cnt = LLINF;
        rep(j, n + 1){
            lint neg = sum[j];
            lint pos = d[i] * (lint)(n - j) - (sum[n] - sum[j]);
            if(max(neg, pos) <= k && abs(pos - neg) % d[i] == 0LL){
                chmax(ans, d[i]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cctype>
using namespace std;
char tmp;
int read()
{
    int f(1),x(0);
    for(tmp=getchar();!isdigit(tmp);tmp=getchar()) if(tmp=='-') f=-1;
    for(;isdigit(tmp);tmp=getchar()) x=x*10+tmp-'0';
    return f*x;
}
long long limit,ans;
int n,arr[100010],cnt[1000100],treearr[1000100];
inline int lowbit(const int & k)
{
    return k&(-k);
}
void update(int x)
{
    while(x<=200050)
    {
        treearr[x]++;
        x+=lowbit(x);
    }
}
long long query(int x)
{
    long long r=0;
    while(x)
    {
        r+=treearr[x];
        x-=lowbit(x);
    }
    return r;
}

bool check(const int & mid)
{
    ans=0; memset(treearr,0,sizeof(treearr));
    for(int i=1;i<=n;i++)
        cnt[i]=cnt[i-1]+((arr[i]<mid)?(-1):1);
    for(int i=0;i<=n;i++)
    {
        ans+=query(cnt[i]+100010);
        update(cnt[i]+100010);
    }
    return ans>=(long long) n*(n+1)/4;
}

int main()
{
    int l=0,r=0,mid;
    n=read();
    for(int i=1;i<=n;i++)
    {
        arr[i]=read();
        r=max(r,arr[i]);
    }
    limit=(n+1)*n/4;
    while(l<=r)
    {
        mid=(l+r)>>1;
        if(check(mid))
            l=mid+1;
        else
            r=mid-1;
    }
    printf("%d\n",r);
    return 0;
}


Measured memory_bytes: 8448
fun main(args: Array<String>) {

    val (A, V) = readLine()!!.split(" ").map { it.toLong() }

    val (B, W) = readLine()!!.split(" ").map { it.toLong() }

    val T = readLine()!!.toLong()


    if (W >= V) {
        println("NO")
        return
    }

    var dist = Math.abs(A - B)

    if (T * (V - W) >= dist) {
        print("YES")
    } else {
        print("NO")
    }


}

Measured memory_bytes: 36488
college = Array.new(4).map { [  
                               ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                               ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                               ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
                             ] }

input = []

gets.to_i.times do
  input << gets.split(' ').map(&:to_i)
end

input.each do |e|
  b, f, r, v = e
  college[b - 1][f - 1][r] +=  v
end

college.each_with_index do |ary, i|
  puts ary.map{ |e| e.join(' ') }.join("\n")
  break if college.size - 1 == i
  puts '#' * 20
end

Measured memory_bytes: 8700
n = int(input())
p_lst = input().split()
# int化
for i in range(0, len(p_lst)):
    p_lst[i] = int(p_lst[i])

cnt = 0
for i in range(0, len(p_lst)-2):
    if (p_lst[i+1] > p_lst[i] and p_lst[i+1] < p_lst[i+2]) or (p_lst[i+1] < p_lst[i] and p_lst[i+1] > p_lst[i+2]):
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
L, R = [int(x) for x in input().split()]
if R-L >= 2019:
  print(0)
elif L%2019 > R%2019:
  print(0)
else:
  s = 20190
  for i in range(L%2019,1+(R%2019)):
    for j in range(L%2019,1+(R%2019)):
      if i < j:
        t = (i*j)%2019
        if s > t:
          s = t
  print(s)

Measured memory_bytes: 42092
# -*- coding: utf-8 -*-


import sys
import math

# 1整数
n = int(input())

# 空白区切りリスト
b = list(map(int, input().split()))

def add(list:[],i):
    list.insert()

#1~100まで試す
##後ろがなるべく埋まるように 埋まらなければ前から矛盾が起きないように

ret=[]

for i in range(n):
    bb = b[i]
    #print(bb,len(ret),ret)
    if len(ret)+1 < bb:
        print('-1')
        quit()
    ret.insert(bb-1,bb)

#print(ret)
ss = []
for i in ret:
    print(i)
    #print(i,ss)
#print(ss)




Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll H, A;
  cin >> H >> A;
  ll count = 0;
  while (H > 0) {
    H -= A;
    count++;
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
  int n; cin >>n;
  vector<int> a(n);
  cinf(n,a);
  ll sum=0;
  for(int i=0;i<n;i++){
  	sum+=a[i];
  }
  ll left=0;
  ll ans=1e18;
  for(int i=0;i<n-1;i++){
  	left+=a[i];
  	ans=min(ans,abs(sum-left-left));
  }
  cout << ans <<endl;
} 


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 1e5+7;
vector<vector<int>> dp(lim,vector<int>(3,0));

int main(){
    int n;
    cin>>n;
    vector<vector<int>> a(n+1,vector<int>(3,0));
    for(int i=1;i<=n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    dp[1][0]=a[1][0]; dp[1][1]=a[1][1]; dp[1][2]=a[1][2];
    for(int i=2;i<=n;i++){
        dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i][0];
        dp[i][1] = max(dp[i-1][2],dp[i-1][0]) + a[i][1];
        dp[i][2] = max(dp[i-1][1],dp[i-1][0]) + a[i][2];
    }
    int ans = max(dp[n][0],max(dp[n][1],dp[n][2]));
    cout<<ans;
    return 0;
}


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

using namespace std;

int main(void) {

	int k ;
	int a[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

	cin >> k;

	




	cout<<a[k-1] <<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define INF 1000000000000 //10^12:極めて大きい値,∞
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    vector <int> n;
    int x=1;
    for(int i=0; x!=0;++i){
        cin >> x;
        n.push_back(x);
    }
    for(int i=0; n[i]!=0;i++){
        cout << "Case " << i+1 <<": " << n[i] << endl;
    }

    return 0;
}


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

#define MAX 100002

int n;

vector<int> v[MAX];

int dp[MAX];

int ans;
int ans2;

int leaf[MAX];

int cer;

int wa;


inline void dfs(int b,int pr){
	vector<int> ret;
	for(int go:v[b]){
		if(go==pr)continue;
		dfs(go,b);
		leaf[b]+=leaf[go];
		ret.push_back(dp[go]);
	}
	leaf[b]+=(v[b].size()==1);
	sort(ret.begin(),ret.end(),greater<int>());
	while(ret.size()<=2)ret.push_back(0);
	if(true){
		wa=max(wa,(v[b].size()==2)+ret[0]+ret[1]);
	}
	dp[b]=max(dp[b],(v[b].size()==2)+ret[0]);
	return;
}

int main(){
	cin>>n;
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(0,-1);
	dp[0]=max(dp[0],wa);
	cout<<dp[0]+leaf[0]<<endl;
	return 0;
}


Measured memory_bytes: 6528
#include <stdio.h>
#include <iostream>
#include <vector>
#include <time.h>
#include <queue>
#include <utility>

#define INF (-1)


int solve( ) {

	using namespace std;

	int N, M, L, K, A, H;
	cin >> N >> M >> L >> K >> A >> H;
	if( !(N|M|L|K|A|H) ) return 1;
	vector< vector< int > > root( N, vector< int >( N, INF ) );
	vector< vector< int > > graph( N, vector< int >( M + 1, INF ) );
	vector< vector< int > > in( N, vector< int >( M+1, 0 ) );
	vector< int > fr( N, 0 );

	//冷凍可能な都市
	for( int i = 0; i < L; i++ ) {
		int j;
		cin >> j;
		fr[j] = 1;
	}
	//道の情報
	for( int i = 0; i < K; i++ ) {
		int x, y, t;
		cin >> x >> y >> t;
		root[x][y] = t;
		root[y][x] = t;
	}

	//ダイクストラ？
	//初期化
	for( int i = 0; i <= M; i++ ) {
		graph[A][i] = 0;
	}
	//pair<町、残り時間>
	queue< pair<int,int> > q;
	q.push( pair<int,int>(A,M) );
	in[A][M] = 1;

	while( !q.empty() ) {
		pair< int, int > p = q.front();
		q.pop();
		if( p.first == H ) continue;
		
		in[p.first][p.second] = 0;
		for( int i = 0; i < N; i++ ) {
			if( root[p.first][i] < 0 ) continue;
			int cost = graph[p.first][p.second] + root[p.first][i];
			int rest = p.second - root[p.first][i];
			if( rest < 0 ) continue;
			if( graph[i][rest] == INF || graph[i][rest] > cost ) {
				graph[i][rest] = cost;
				if( in[i][rest] == 0  ) {
					q.push( pair<int,int>( i, rest) );
					in[i][rest] = 1;
				}
			}
			if( fr[i] == 1 ) {
				//j分間冷凍する
				for(int j = 1;rest+j<= M; j++ ){  
					if( graph[i][rest+j] == INF || graph[i][rest+j] > cost+j ) {
						graph[i][rest+j] = cost+j;
						if( in[i][rest+j] == 0 ) {
							q.push( pair<int,int>( i, rest+j) );
							in[i][rest+j] = 1;
						}
					}
				}
			} 
		}
	}

	int mincost = -1;
	for( int i = 0; i <= M; i++ ) {
		if( graph[H][i] != -1 ) {
			if( mincost == -1 || ( mincost >= 0 && mincost > graph[H][i] ) ) {
				mincost = graph[H][i];	
			}
		}
	}
	if( mincost == -1 ) {
		cout << "Help!" << endl;
	} else {
		cout << mincost << endl;
	}

	return 0;
}

int main(void){

	using namespace std;

	while( !cin.eof() ) {
		unsigned int stime = clock();
		if( solve() ) break;
		unsigned int etime = clock();
//		cout << "processing time = " << etime - stime << "[ms]" << endl;
	}
//	while(1){}
	return 0;

}

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

using namespace std;

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    int i, n, m, j;
    string s, t;
    cin >> s >> t;
    int best = INT_MAX;
    n = s.length();
    m = t.length();
    for(i = 0; i < n - m + 1; i++){
        int res = 0;
        for(j = 0; j < m; j++){
            if(s[i + j] != t[j])
                res++;
        }
        best = min(best, res);
    }
    cout << best << endl;
}

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

int main(){
  int n;
  int count = 0;
  bool all_even = true;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; i++){
    cin >> A[i];
    if(A[i] % 2 != 0) all_even = false;
  }

  while(all_even){
    ++count;
    for (int i = 0; i < n; i++){
   		A[i] = A[i] / 2;
    	if(A[i] % 2 != 0){
          all_even = false;
          break;
        }
  	}
  }
  cout << count << endl;
}


Measured memory_bytes: 888
#include <stdio.h>
int main()
{
  int i, j, k, v, n;
  int A[100];

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

  for(k=0; k<n; k++) {
    printf("%d", A[k]);
    if(k==n-1) break;
    printf(" ");
  }
  printf("\n");
  for(i=1; i<n; i++) {
    v = A[i];
    j = i-1;
    while(j>=0 && A[j]>v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    for(k=0; k<n; k++) {
      printf("%d", A[k]);
      if(k==n-1) break;
      printf(" ");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl ("\n")
#define pi (3.141592653589)
#define mod 1e9+7
#define INF 1e9+9
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define so sizeof 
#define pii pair<ll,ll>
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define max3(a, b, c) max(c, max(a, b))
#define max4(a, b, c, d) max(d, max(c, max(a, b)))
#define repe(i,a) for(auto i:a)
#define st string
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define rrep(i,a,b) for(ll i=b;i>=a;i--)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
void solve(){
  st s,t;
  cin>>s>>t;
  ll dp[t.size()+1][s.size()+1];
  rep(i,0,s.size()){
    dp[0][i]=0;
  }
  rep(i,0,t.size()){
    dp[i][0]=0;
  }
  rep(i,1,t.size()){
    rep(j,1,s.size()){
       if(t[i-1]==s[j-1]){
          dp[i][j]=1+dp[i-1][j-1];
       }
       else{
          dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
       }
    }
  }
  // rep(i,0,t.size()){
  //   rep(j,0,s.size()){
  //       cout<<dp[i][j]<<" ";
  //   }
  //   cout<<endl;
  // }
  st res;
  ll i,j;
  i=t.size();
  j=s.size();
  while(i>0 && j>0){
     if(dp[i][j]==dp[i-1][j]){
         i--;
     }
     else if(dp[i][j]==dp[i][j-1]){
         j--;
     }
     else{
         res=s[j-1]+res;
         i--;
         j--;
     }
  }
  cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
#endif
    fast
    solve();
    return 0;
}

Measured memory_bytes: 73960
x, k, d = gets.chomp.split.map(&:to_i)

abs_x = x.abs

a, b = abs_x.divmod(d)

if k < a
  puts abs_x + (-1 * d * k)
else
  if (k - a).odd?
    puts (d - b).abs
  else
    puts b
  end
end


Measured memory_bytes: 14352
#include <bits/stdc++.h>
#define sz(x) (int((x).size()))
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
template<typename T> bool domax(T &a, T b) { return (b > a ? (a = b, true) : false); }
template<typename T> bool domin(T &a, T b) { return (b < a ? (a = b, true) : false); }
typedef long long ll;

typedef std::vector<std::pair<ll, int>> primes;

const ll magic = 2500;

int n, ans;
ll s[100*1000+5];

bool botherwithit;

void end(primes &p, ll x) {
    ll y = std::sqrt(double(x));
    for (ll d = y-1; d <= y+2; d++) {
        if (d*d == x) {
            x = 1;
            p.eb(d, 2);
        }
    }
    if (x > 1) {
        botherwithit = false;
        ans++;
    }
}

primes factor(ll x) {
    primes p;
    for (ll d = 2; d < magic && d*d <= x; ) {
        int k = 0;
        while ((x%d) == 0) {
            x /= d;
            k++;
        }
        if (k) p.eb(d, k);
        if (d == 2) d++;
        else d += 2;
    }
    if (x >= magic*magic) {
        end(p, x);
    } else if (x > 1) {
        p.eb(x, 1);
    }
    return p;
}

std::map<ll,int> count;
std::map<ll,ll> tofind;

int main() {
    //for (int i = 1; i <= 12; i++) {
    //    printf("%d: ", i);
    //    primes x = factor(i);
    //    for (auto p : x) printf("(%lld,%d)", p.first, p.second);
    //    printf("\n");
    //}
    //std::vector<int> aoeu = {2917, 2917*2917,2917*2927};
    //for (int i : aoeu) {
    //    printf("%d: ", i);
    //    botherwithit = true;
    //    primes x = factor(i);
    //    printf("(bother = %d) ", int(botherwithit));
    //    for (auto p : x) printf("(%lld,%d)", p.first, p.second);
    //    printf("\n");
    //}
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", s+i);
        botherwithit = true;
        primes p = factor(s[i]);
        if (botherwithit) {
            ll canon = 1ll, search = 1ll;
            for (auto k : p) {
                ll d = k.first, t = k.second;
                t %= 3;
                if (t == 0) continue;
                assert(t == 1 || t == 2);
                if (t == 1) {
                    canon *= d;
                    search *= d*d;
                } else {
                    canon *= d*d;
                    search *= d;
                }
            }
            //printf("s[i] = %lld, canon = %lld, search = %lld\n", s[i], canon, search);
            count[canon]++;
            tofind[canon] = search;
        }
    }

    for (auto &blah : count) {
        int me = blah.second;
        int other = count[tofind[blah.first]];
        if (blah.first == tofind[blah.first]) ans++;
        else if (me > other || (me == other && blah.first > tofind[blah.first]))
            ans += me;
        //printf("canon = %lld, search = %lld\n", blah.first, tofind[blah.first]);
        //printf("me = %d, other = %d, ans = %d\n", me, other, ans);
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 21632
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


ll fact[100001];
const int mod = 1000000007;

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

	int N, M;
	cin >> N >> M;
	int mx = max(N, M);
	int mn = min(N, M);
	int sum = M + N;
	if (mn < sum / 2) {
		cout << 0 << "\n";
		return 0;
	}
	fact[0] = 1;
	for (int i = 1;i <= mx;i++) fact[i] = (fact[i - 1] * i) % mod;
	int res = (fact[mx] * fact[mn]) % mod;
	if (sum % 2 == 0) res = 2 * res % mod;
	cout << res << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,Q;
long long m;
#define Maxn 100010
int head[Maxn],v[Maxn<<1],nxt[Maxn<<1],tot=0;
int bel[Maxn],col=0;
inline void add_edge(int s,int e){
	tot++;v[tot]=e;nxt[tot]=head[s];head[s]=tot;
	tot++;v[tot]=s;nxt[tot]=head[e];head[e]=tot;
}
void dfs(int u){
	bel[u]=col;
	for(int i=head[u];i;i=nxt[i])
	    if(!bel[v[i]])dfs(v[i]);
}

struct P{
	int a,b;
}seq[Maxn];
int len=0;

int main(){
	scanf("%d%lld%d",&n,&m,&Q);
	int a,b,c;
	for(register int i=1;i<=Q;++i){
		scanf("%d%d%d",&a,&b,&c);
		a++;b++;
		if(!c)add_edge(a,b);
		else seq[++len]=(P){a,b};
	}
	for(register int i=1;i<=n;++i)
	    if(!bel[i]){
			col++;
			dfs(i);
	    }
	for(register int i=1;i<=len;++i)
	    if(bel[seq[i].a]==bel[seq[i].b]){
			puts("No");
			return 0;
	    }
	m-=n-(col);
	if(m<0){
		puts("No");
		return 0;
	}
	if(len){
		if(m>=col&&m<=1ll*col*(col-1)/2)puts("Yes");
		else puts("No");
	}else{
		if(m<=1ll*col*(col-1)/2&&m>=col-1)puts("Yes");
		else puts("No");
	}
	return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	ll n; cin >> n;
	ll ans = 1e18;
	for (ll i = 1; i*i <= n; i++)
	{
		if (n%i != 0)continue;
		ll j = n / i;
		ans = min(ans, i + j - 2);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:640000000")
#include <bits/stdc++.h>

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);

int main() {
	#ifdef LOCAL
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	string s; cin >> s;

	if (sz(s) < 26) {
		cout << s;
		for (char c = 'a'; c <= 'z'; c++) {
			bool ok = true;
			for (int j = 0; j < sz(s); j++) if (s[j] == c) {
				ok = false;
				break;
			}
			if (ok) {
				cout << c << endl;
				return 0;
			}
		}
	}

	string t = s;

	if (next_permutation(all(s))) {
		for (int i = 0; i < sz(s); i++) {
			cout << s[i];
			if (s[i] > t[i]) break;
		}
		cout << endl;
	} else {
		cout << -1 << endl;
	}

	return 0;
}

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

using namespace std;

bool isAllUp(vector<int> vec) {
    bool test = false;
    for (int i = 0; i < vec.size() - 1; ++i) {
        if (vec.at(i) < vec.at(i + 1)) {
            test = true;
        } else {
            test = false;
            break;
        }
    }
    return test;
}

int main() {
    bool test = false;
    int a, n;
    cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n; ++i) {
        cin >> a;
        vec.at(i) = a;
    }
    vector<int> bacKUp = vec;
    for (int j = 0; j < n; ++j) {
        for (int i = j; i < n; ++i) {
            swap(vec.at(j), vec.at(i));
            if (isAllUp(vec)) {
                test = true;
                break;
            } else {
                test = false;
            }
            vec = bacKUp;
        }
    }
    if (test) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


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

int main(){
	int N,K,d;cin >> N >> K;
	int ans =0;
	vector<int> A;
	rep(i,K){
		cin >> d;
		for(int j=0;j<d;j++){
			int m;cin >> m;
			A.push_back(m); 
		}
	}
	sort(A.begin(), A.end());
	A.erase(unique(A.begin(), A.end()), A.end());

	cout << N-A.size() << endl;


}


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

int main() {
	unsigned char b = 0;
	while (b < 81) {
		cout << (b / 9 + 1) << "x" << (b % 9 + 1) << "=" << (b / 9 + 1)*(b % 9 + 1) << endl;
		b++;
	}
	
	return 0;
}

Measured memory_bytes: 1116
x, y = map(int, input().split())

a = [4, 6, 9, 11]

if x == 2 and y == 2:
    print("Yes")
elif x == 2 or y == 2:
    print("No")
elif x in a and y in a:
    print('Yes')
elif x not in a and y not in a:
    print('Yes')
else:
    print('No')

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

int main(){
  string S,ans="";
  cin >> S;
  int N = S.size();
  for (int i=0; i < N; i++){
    if (S.at(i) == '0'){
     ans.push_back('0');
    }
    else if(S.at(i) == '1'){
     ans.push_back('1');
    }
    else if(ans.size()!=0){
    ans.erase(ans.size()-1);
    }
  }
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3560
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  for(int x = 1; x <= 50000; x++) {
    // x * 1.08
    if(x * 108 / 100 == n) {
      cout << x << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}


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

int A[2000000];
int n;

int parent(int i)
{
  return i/2;
} 
int left(int i)
{
   return 2*i;
}

int right(int i)
{
   return 2*i+1;
} 


void maxHeapify(int i)
{
  int l = left(i);
  int r = right(i);
  int largest,temp;
  if( l <= n && A[l] > A[i])
    {
      largest = l;
    }
  else
    {
      largest = i;
    }
  if(r <= n && A[r] > A[largest])
    {
      largest = r;
    }
  if (largest != i)
    {
      temp = A[i];
      A[i] = A[largest];
      A[largest] = temp;
      maxHeapify(largest);
    }
}

void buildMaxHeap()
{
  int i;
  for( i = n/2;i>0;i--)
    {
      maxHeapify(i);
    }
}

void maxHeapInsert(int key)
{
  n = n + 1;
  A[n] = INT_MIN;
  heapIncreaseKey(n,key);
}


void heapIncreaseKey(int i,int key)
{
  int tmp;
  if (key < A[i])
    {
      return;
    }
  A[i] = key;
  while (i > 1 && A[parent(i)] < A[i])
    {
      tmp = A[i];
      A[i] = A[parent(i)];
      A[parent(i)]= tmp;
      i = parent(i);
    }
}

int heapExtractMax()
{
  int max;
  if ( n < 1)
    {
      return;
    }
  max = A[1];
  A[1] = A[n];
  n = n - 1;
  maxHeapify(1);
  return max;
}


int main()
{
  int t;
  char s[10];
  while(1){
    scanf("%s",s);
    if(s[2]=='s')
      {
	scanf("%d",&t);
	maxHeapInsert(t);
      }
    if(s[2]=='t')
      {
	printf("%d\n",heapExtractMax());
      }
    if(s[2]=='d')
      {
	break;
      }
  }
  return 0;
}

Measured memory_bytes: 4692
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n; cin >> n;
	vi a(n); rep(i,n) cin >> a[i];
	vi dp(n,0);
	vi boxidx;
	for(int i=n-1; i>=0; i--){
		int sum = 0;
		for(int j=i+(i+1); j<n; j+=i+1) sum += dp[j];
		sum %= 2;
		dp[i] = a[i]^sum;
		if(dp[i]) boxidx.push_back(i+1);
	}
	REV(boxidx);
	int m = boxidx.size();
	cout << m << endl;
	rep(i,m) cout << boxidx[i] << endl;
}




Measured memory_bytes: 3064
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))

dp = defaultdict(int)
dm = defaultdict(int)
for i, ai in enumerate(a):
    if i + 1 + ai <= n:
        dp[i + ai + 1] += 1
    if 0 < i + 1 - ai <= n:
        dm[i + 1 - ai] += 1
ans = 0
keys = set(dp.keys()) & set(dm.keys())
for k in keys:
    ans += dp[k] * dm[k]
print(ans)


Measured memory_bytes: 48776
N = 10**5 + 10
n = int(input())
a = list(map(int, input().split()))
c = [0] * N
for i in a: c[i] += 1
ans = max(c[i - 1] + c[i] + c[i + 1] for i in range(1, N - 1))
print(ans)
    

Measured memory_bytes: 14008
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007

//ここから編集する
struct BFS01 {
    struct edge {
        ll to,cost;
    };
    typedef pair<ll, ll> P;//firstは最短距離、secondは頂点の番号

    int V;//超点数
    vector<vector<edge> > G;//グラフ,G[i]はiから出る辺の集合,G[i][j]はiから出る辺のj番目の辺
    vector<ll> d; //最短距離

    BFS01(int N) {
        V = N;
        G = vector<vector<edge> >(N);
        d = vector<ll>(N);
    };
    void addEdge(int from,int to,int cost){
        edge e;
        e.to = to;
        e.cost = cost;
        G[from].push_back(e);
    }
    void calc(int s){
//        priority_queue<P,vector<P>,greater<P> > que;
        queue<P> que;
        fill(d.begin(),d.end(),INFl);
        d[s] = 0;
        que.push(P(0,s));

        while(!que.empty()){
            P p = que.front();que.pop();
            ll v = p.second;
            if(d[v] < p.first) continue;
            for(int i = 0; i < G[v].size(); i++){
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost && !(d[e.to] == INFl && d[v] == INFl)) {
                    d[e.to] = d[v] + e.cost;
                    que.push(P(d[e.to],e.to));
                }
            }
        }

    }
};

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

    int K;
    cin >> K;
    BFS01 bfs01(K);
    rep(i,0,K){
        bfs01.addEdge(i,(i+1)%K,1);
        bfs01.addEdge(i,i * 10 % K,0);
    }
    bfs01.calc(1);
    cout << bfs01.d[0] + 1 << endl;



    return 0;
}


Measured memory_bytes: 8576
n = gets.to_i
xs = gets.chomp
x = xs.to_i(2)

def popcount(n)
  return n.to_s(2).count('1')
end

$x_pp = popcount(x)
$x_mod_pp_plus = x % ($x_pp + 1)
$x_mod_pp_minus = x % ($x_pp - 1) if $x_pp > 1

(n-1).downto(0) do |i|
  if x[i].zero?
    t = ($x_mod_pp_plus + 2.pow(i, $x_pp + 1)) % ($x_pp + 1)
  else 
    if ($x_pp - 1).zero?
      puts 0
      next
    end
    t = ($x_mod_pp_minus - 2.pow(i, $x_pp - 1)) % ($x_pp - 1)
  end
  ans = 1
  while  t != 0
    t = t % popcount(t)
    ans += 1
  end
  puts ans
end


Measured memory_bytes: 14952
#include <bits/stdc++.h>
using namespace std;
int n,i,j,a[200005],b[200005];
int main(){
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",a+i);
	memcpy(b,a,sizeof(a));
	sort(a+1,a+n+1);
	for (i=1;i<=n;i++){
		if (b[i]<=a[n/2]) printf("%d\n",a[n/2+1]); else printf("%d\n",a[n/2]);
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int h, w;
    cin >> h >> w;
    vector<string> pic(h);
    for (int i=0; i<h; ++i) cin >> pic.at(i);
    for (int i=0; i<w+2; ++i) cout << '#';
    cout << '\n';
    for (int i=0; i<h; ++i) {
        cout << '#' << pic.at(i) << '#' << '\n';
    }
    for (int i=0; i<w+2; ++i) cout << '#';
    cout << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
i,o,t,j,l,s,z = map(int,input().split())
if i > 0 and j > 0 and l > 0:
  print(max(o + i//2*2 + j//2*2 + l//2*2,o + (i-1)//2*2 + (j-1)//2*2 + (l-1)//2*2 + 3))
else:
  print(o + i//2*2 + j//2*2 + l//2*2)


Measured memory_bytes: 3060
// dp[i] - TRUE if the first player wins if there are i stones remaining
#include<bits/stdc++.h>
using namespace std ;

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> a(n);
    for(int& x : a) {
        scanf("%d", &x);
    }
    vector<bool> dp(k + 1);
    for(int stones = 0; stones <= k; ++stones) {
        for(int x : a) {
            if(stones >= x && !dp[stones-x]) {
                dp[stones] = true;
            }
        }
    }   
    puts(dp[k] ? "First" : "Second");
}

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

int main() {
	int N, M;
	cin >> N >> M;
	mf_graph<int> graph(N * M + 2);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if ((i + j) % 2 == 0) graph.add_edge(0, i * M + j + 1, 1);
			else graph.add_edge(i * M + j + 1, N * M + 1, 1);
		}
	}
	vector<string> Map(N);
	for (int i = 0; i < N; i++) cin >> Map[i];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if ((i + j) % 2 == 0 && Map[i][j] == '.') {
				if (i - 1 >= 0 && Map[i - 1][j] == '.') graph.add_edge(i * M + j + 1, (i - 1) * M + j + 1, 1);
				if (i + 1 < N && Map[i + 1][j] == '.') graph.add_edge(i * M + j + 1, (i + 1) * M + j + 1, 1);
				if (j - 1 >= 0 && Map[i][j - 1] == '.') graph.add_edge(i * M + j + 1, i * M + (j - 1) + 1, 1);
				if (j + 1 < M && Map[i][j + 1] == '.') graph.add_edge(i * M + j + 1, i * M + (j + 1) + 1, 1);
			}
		}
	}
	int ans = graph.flow(0, N * M + 1);
	cout << ans << endl;
	int edge_id = N * M;
	vector<string> NewMap(N);
	for (int i = 0; i < N; i++) NewMap[i] = Map[i];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if ((i + j) % 2 == 0 && Map[i][j] == '.') {
				if (i - 1 >= 0 && Map[i - 1][j] == '.') {
					if (graph.get_edge(edge_id).flow == 1) {
						NewMap[i][j] = '^';
						NewMap[i - 1][j] = 'v';
					}
					edge_id++;
				}
				if (i + 1 < N && Map[i + 1][j] == '.') {
					if (graph.get_edge(edge_id).flow == 1) {
						NewMap[i][j] = 'v';
						NewMap[i + 1][j] = '^';
					}
					edge_id++;
				}
				if (j - 1 >= 0 && Map[i][j - 1] == '.') {
					if (graph.get_edge(edge_id).flow == 1) {
						NewMap[i][j] = '<';
						NewMap[i][j - 1] = '>';
					}
					edge_id++;
				}
				if (j + 1 < M && Map[i][j + 1] == '.') {
					if (graph.get_edge(edge_id).flow == 1) {
						NewMap[i][j] = '>';
						NewMap[i][j + 1] = '<';
					}
					edge_id++;
				}
			}
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) cout << NewMap[i][j];
		cout << endl;
	}
}


Measured memory_bytes: 5116
s = input()
x = sorted(set(s[::2]))
y = sorted(set(s[1::2]))
countx = 0
county = 0
for i in x:
    if i in 'RDU':
        countx += 1
for i in y:
    if i in 'LDU':
        county += 1
print('Yes' if countx==len(x) and county==len(y) else 'No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main(){

    int N, K;
    long S;

    cin >> N >> K >> S;

    vector<long> ans(N); 

    if(S < pow(10, 9)){
        for(int i=0; i<N; i++){
            if(i<K){
                ans[i] = S;
            }else{
                ans[i] = S + 1;
            }
        }
    }else if(S == pow(10, 9)){
        for(int i=0; i<N; i++){
            if(i<K){
                ans[i] = S;
            }else{
                ans[i] = 1;
            }
        }
    }

    for(int i=0; i<N; i++){
        cout << ans[i] << " ";
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 2048
#include<iostream>
using namespace std;
int main(){
	string s;
	int cnt[26]={0};
	cin>>s;
	for(int i=0;i<s.size();i++){
		cnt[s[i]-'a']++;
	}
	bool ok=true;
	for(int i=0;i<26;i++)if(cnt[i]%2==1)ok=false;
	cout<<(ok?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 256
N,Y=map(int,input().split())
answer=-1,-1,-1
for x in range(N+1):
    for y in range(N-x+1):
        z=N-x-y
        if 0<=z<=2000 and 10000*x+5000*y+1000*z==Y:
            answer=x,y,z
            break
    else:
        continue
    break
print(*answer)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,x,max=0,t=0;
    for(int i=0;i<3;i++){
        cin >> x;
        t+=x;
        if(max<x){
            max=x;
        }
    }
    cout << t-max << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

template <typename T, typename U>
vector<U> make_vector(T&& n, U&& val) {
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
decltype(auto) make_vector(T&& n, Args&&... args) {
  return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...));
}

const int INF = 1001001001;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve() {
  int n;
  cin >> n;
  vector<vi32> g(n);
  rep(i, n - 1) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  auto grundy = [&](auto grundy, int u, int p) -> int {
    int ret = 0;
    for (auto v : g[u]) if (v != p) {
      ret ^= grundy(grundy, v, u) + 1;
    }
    return ret;
  };
  int ret = grundy(grundy, 0, -1);
  if (ret != 0) {
    cout << "Alice" << endl;
  } else {
    cout << "Bob" << endl;
  }
}


Measured memory_bytes: 14676
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

ll combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  ll dividend = 1;
  ll divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

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

	int a[100005];
	rep(i,n) cin >> a[i];
	sort(a, a+n);

	int mm = a[n-1];
	double target = mm / 2.0;

	double res = mm;
	int out = 0;

	rep(i,n){
		if(res > abs(target - a[i]) && mm != a[i]){
			res = abs(target - a[i]);
			out = a[i];
		}
	}

	cout << mm << " " << out << endl;
}

int main(){
	solve();
	return 0;
}





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

int main() {
  int a,b,c;
  //string s;
  cin>>a;
  //cin>>s;
/*if(a-b ==0|| b-a==0)
{
  cout<<0<<endl;
}
else if((a+b)%2==0)
{
  cout<<(a+b)/2<<endl;
}

else
{
  cout<<"IMPOSSIBLE"<<endl;
}
  */
  cout<<(a*a*3)<<endl;
}

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

int main(){
	int n, a, b, c, d;
	scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
	ll l = a, r = a;
	n -= 1;
	while (n > 0){
		if (b > r)l += c, r += d;
		else if (b < l)l -= d, r -= c;
		else if (n & 1){
			ll tl = l + c, tr = r + d;
			if (b >= tl && b <= tr) { l = tl, r = tr; break; }
			l -= d, r -= c;
		}
		else break;
		--n;
	}
	printf("%s\n", b >= l && b <= r ? "YES" : "NO");
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
s = input()
cnt = 0
_max = 0
for _s in s[::-1]:
    if _s == ")":
        cnt -= 1
    else:
        cnt += 1
    _max = max(cnt, _max)
s += ")" * _max

cnt = 0
_max = 0
for _s in s:
    if _s == "(":
        cnt -= 1
    else:
        cnt += 1
    _max = max(cnt, _max)
s = "(" * _max + s
ct = Counter(s)

if ct.get("(") is None:
    ct["("] = 0
if ct.get(")") is None:
    ct[")"] = 0
if ct[")"] > ct["("]:
    s = "(" * (ct[")"] - ct["("]) + s
else:
    s = s + ")" * (ct["("] - ct[")"])
print(s)

Measured memory_bytes: 3316
#include<stdio.h>
int main()
{
    int i, j,c,a,b;
    scanf("%d%d", &a, &b);
    for (i=b*10; i <= b*10+9; i++)
    {
        c = i * 0.08;
        if (c==a)
        {
            printf("%d", i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
 int N;
  cin >>N;
  vector<pair<string, int>> vec(N);
  rep(i,N) {
    cin >>vec.at(i).first;
  }
  
  sort(all(vec));
  int count=1;
  rep(i,N-1) {
if(vec.at(i).first==vec.at(i+1).first) {
  count++;
  vec.at(i).second=count-1;
}
if(vec.at(i).first!=vec.at(i+1).first) {
  vec.at(i).second=max(count,1);
  count=1;
}
  }
  if(vec.at(N-2).first==vec.at(N-1).first) {
    vec.at(N-1).second=count;
  }
     if(vec.at(N-2).first!=vec.at(N-1).first) {
       vec.at(N-1).second=1;
     }
  //cout<<"A"<<" "<<vec.at(0).second<<vec.at(1).second<<vec.at(2).second<<vec.at(3).second<<vec.at(4).second<<vec.at(5).second<<vec.at(6).second<<endl;
  vector<pair<int, string>> vect(N);
  rep(i,N) {
vect.at(i).first=vec.at(i).second;
    vect.at(i).second=vec.at(i).first;
  }
  
  sort(all(vect));
  int x=vect.at(N-1).first;
  int counting=0;
  rep(i,N) {
    if(vect.at(i).first==x) {
      counting++;
    }
    
  }

  vector<string> vecto(counting);
  int a=0;
  rep(i,N) {
    if(vect.at(i).first==x) {
      vecto.at(a)=vect.at(i).second;
      a++;
    }
  }
  
  sort(all(vecto));
  rep(i,counting) {
    cout<<vecto.at(i)<<endl;
  }
  
  
}
     
   


Measured memory_bytes: 20480
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
    int n;
    cin >> n;
    ll ans = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
        for(int k=1;k<=n;k++){
            ll che = gcd(i,j);
            che = gcd(k,che);
            ans+=che;
        }
    }
    }
    cout << ans<<endl;
}
    



Measured memory_bytes: 3636
import Foundation

let N = Int(readLine()!)!
let array = Array(readLine()!)
var wArray = Array(repeating: 0, count: N + 1)
var rc = 0
var wc = 0
for i in 0..<N{
  if(array[i] == "W"){
    wc += 1
  }else{
    rc += 1
  }
  wArray[i + 1] = wc
}
print(wArray[rc])

Measured memory_bytes: 17920
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a < 10 && b < 10) {
            System.out.println(a * b);
        } else {
            System.out.println(-1);
        }
    }
}


Measured memory_bytes: 24916
L=input().split( )
A,B,C=int(L[0]),int(L[1]),int(L[2])

w=C//(7*A+B)
m=C%(7*A+B)
d=m//A
if d>=7:
    d=7
else:
    if m%A!=0:
        d+=1
print(7*w+d)



Measured memory_bytes: 5600