akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 17
#define MAX_M 1000005

ll dp[MAX_M];
ll a[MAX_N][MAX_N];
ll sum[MAX_M];
int n, m;

void dfs(int x){
    if(dp[x] != -1) return;
    dp[x] = sum[x];
    if(__builtin_popcount(x) <= 1) return;

    for(int i = x; i > 0; --i &= x){
        int y = i;
        int z = i ^ x;
        if(y == 0 || z == 0) continue;
        dfs(y);
        dfs(z);
        dp[x] = max(dp[x], dp[y]+dp[z]);
    }

    return;
}

int main() {
    cin >> n;
    rep(i,n)rep(j,n)cin >> a[i][j];

    m = 1 << n;

    rep(i,m){
        vector<int> f;
        int ii = i;
        rep(j,n){
            if(ii % 2 == 1) f.push_back(j);
            ii /= 2;
        }
        rep(j,f.size()){
            srep(k,j+1,f.size()){
                sum[i] += a[f[j]][f[k]];
            }
        }
    }

    rep(i,m)dp[i] = -1;

    dfs(m-1);

    ll ans = dp[m-1];

    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 4864
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


#define MOD 1000000007

long long pow_mod(long long x, long long y) {
	int res = 1;
	while (y) {
		if (y & 1)res = (res * x) % MOD;
		y >>= 1;
		x = (x * x) % MOD;
	}
	return res;
}


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

	string s;
	cin >> s;

	int ones = count(all(s), '1');
	int ans = pow_mod(2, ones);

	long long p2 = 1;
	rep(i, s.size()) {
		if (s[i] == '1') {
			ans += p2 * pow_mod(3, s.size() - i - 1) % MOD;
			ans %= MOD;

			p2 *= 2;
			p2 %= MOD;
		}
	}

	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define mp make_pair
#define pb push_back
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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

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

template<class T> inline auto __lcm(T& a, T& b) 
{ return a * b / __gcd(a, b); }

int main() {
    int N;  cin >> N;
    vector<string> S(N); rep(i, N) cin >> S[i];

    string march = "MARCH";
    vector<ll> cnt(5, 0);
    rep(i, N) {
        rep(j, 5) {
            if (march[j] == S[i][0]) {
                ++cnt[j];
            }
        }
    }

    ll ans = 0;
    rep(i, 5) {
        REP(j, i+1, 5) {
            REP(k, j+1, 5) {
                ans += cnt[i] * cnt[j] * cnt[k];
            }
        }
    }

    print(ans);
    return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
const long long INF = 1LL << 60;
// map<int,int> mp;

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

ll h[100010];
ll dp[100010];

ll rec(int i) {
  // read memo

  if (dp[i] < INF) return dp[i];
  // ini N-1 to 0

  if (i == 0) return 0;

  // path N-1 N-2

  ll res = INF;

  chmin(res, rec(i - 1) + abs(h[i] - h[i - 1]));
  if (i > 1) chmin(res, rec(i - 2) + abs(h[i] - h[i - 2]));

  // write memo

  return dp[i] = res;
}

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

  REP(i, N) cin >> h[i];

  REP(i, 100010) dp[i]=INF;

  cout << rec(N - 1) << endl;
}

Measured memory_bytes: 6528
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
A = np.array([0] + [int(x) for x in input().split()] + [0])
A_diff = np.diff(A)
total = abs(A_diff).sum()
for i in range(1,N+1):
    ans = total
    ans -= abs(A_diff[i]) + abs(A_diff[i-1]) 
    ans += abs(A[i+1] - A[i-1])
    print(ans)

Measured memory_bytes: 32232
#include <bits/stdc++.h>
using namespace std;
#define INF 100000000
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll ans ,n;

void solve(ll x,bool a,bool b,bool c){
    if(x>n)return;
    if(a && b && c) ans++;
    solve(x*10+3,1,b,c);
    solve(x*10+5,a,1,c);
    solve(x*10+7,a,b,1);
}

int main() {
    cin >> n;
    solve(0,0,0,0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  int dx1 = x - r;
  int dx2 = W - r - x;
  int dy1 = y - r;
  int dy2 = H - r - y;
  if (dx1 >= 0 && dx2 >= 0 && dy1 >= 0 && dy2 >= 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main(){
  long long a,b,c,ss,A;
  cin >> a >> b >> c;
  if((a%2)*(b%2)*(c%2)){
    ss=a*b;
    A=ss;
    ss=b*c;
    if(ss<A) A=ss;
    ss=a*c;
    if(ss<A) A=ss;
    cout << A;
  }else{
    cout << 0;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long long int n,sum=1,i;
    while(scanf("%lld",&n)!=EOF){
     for(i=1;i<=n;i++){
        sum=sum*i;
     }
     printf("%lld\n",sum);
     sum=1;
    }
    return 0;
}

Measured memory_bytes: 1860
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n, k;
	string s;
	cin >> n >> s >> k;
	REP(i, (int)s.size()){
		if (s[i] != s[k-1]) s[i] = '*';
	}

	cout << s << endl;

}


Measured memory_bytes: 256
import sys

n = int(input())
a = [int(x) for x in input().strip().split()]

total = sum(a)
nn = n * (n + 1) / 2
if total % nn != 0 :
  print('NO')
else:
  m = total / nn
  l = 0
  flg = True
  for i in range(n):
    j = i - 1
    if i == 0:
      j = n - 1
    if a[j] + m - a[i] < 0 or (a[j] + m - a[i]) % n != 0:
      flg = False
      break
    l += (a[j] + m - a[i]) / n

  if flg == True:
    print('YES')
  else:
    print('NO')

Measured memory_bytes: 14480
#include <iostream>

using namespace std;

int main()
{
    long long n, w;
    cin>>n>>w;
    long long items[n][2];
    for(int i=0;i<n;i++)
    {
        cin>>items[i][0]>>items[i][1];
    }
    long long dp[n+1][w+1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
        {
            dp[i][j]=-1;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=w;j++)
        {
            if(dp[i][j]!=-1)
            {
                if(j+items[i][0]<=w)
                {
                    dp[i+1][j+items[i][0]]=max(dp[i+1][j+items[i][0]],dp[i][j]+items[i][1]);
                }
                dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            }
        }
    }
    long long ans=0;
    for(int i=0;i<=w;i++)
    {
        ans=max(ans,dp[n][i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 79104
#include<iostream>
#include<vector>
#include<string>
using namespace std;

int W,H;
int gx,gy;
int ans=11;

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

bool is_in(const int x,const int y){
	if(x<0 || y<0 || x>=W || y>=H) return false;
	return true;
}

bool move(vector<vector<int> >&field,int &x,int &y,const int r){
	int temp_x=x+dx[r],temp_y=y+dy[r];
	if(!is_in(temp_x,temp_y) || field[temp_y][temp_x]==1) return false;
	while(true){
		if(!is_in(x,y)){//はみ出してしまった 戻してberak
			return false;
		}
		else if(field[y][x]==1){//障害物にぶつかる 消して戻してbreak
			field[y][x]=0;
			x-=dx[r];
			y-=dy[r];
			break;
		}
		else if(field[y][x]==3){
			break;
		}
		x+=dx[r];
		y+=dy[r];
	}
	return true;
}

void dfs(vector<vector<int> > field,int x,int y,int depth){
	if(depth>10) return;
	if(depth>=ans) return;

	for(int r=0;r<4;r++){
		vector<vector<int> > copy=field;
		int cx=x,cy=y;
		bool is_ok=move(copy,cx,cy,r);
		if(!is_ok) continue;
		if(cx==gx && cy==gy){
			ans=min(ans,depth);
			return;
		}
		dfs(copy,cx,cy,depth+1);
	}
}

int main()
{
	while(cin>>W>>H){
		if(W==0 && H==0) return 0;
		ans=11;
		int sx,sy;
		vector<vector<int> >map(H,vector<int>(W));
		for(int y=0;y<H;y++){
			for(int x=0;x<W;x++){
				cin>>map[y][x];
				if(map[y][x]==2){
					sx=x;
					sy=y;
				}else if(map[y][x]==3){
					gx=x;
					gy=y;
				}
			}
		}
		dfs(map,sx,sy,0);
		if(ans+1>10) cout<<-1<<endl;
		else cout<<ans+1<<endl;
	}
}

Measured memory_bytes: 1344
/****************************************************************
# @Author:      iLovePKU_zbtxdy
# @DateTime:    2020-01-28 15:06:55
# @Description: You build it. You run it
# @More: Once lots of AC, try Brute-force,dynamic programming
****************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define close std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long 
#define eps 1e-8
typedef long long ll;
const int maxn = 1e6+10;
const int INF = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
ll mod = 1e9+7;
int d , n , a ,c[maxn];
struct node{
    int x, h;
}mon[maxn];
int cmp(node a , node b){
    return a.x < b.x;
}
int32_t main()
{
    close;
    cin >> n >> d >> a;   
    for(int i = 0; i < n; i++){
        cin >> mon[i].x >> mon[i].h;
    }
    sort(mon , mon + n , cmp);
    int ans = 0;
    for(int i = 0, j = 0; i < n; i++){
        while(j < n && mon[j].x <= mon[i].x + 2*d)++j;
        int tmp = max((mon[i].h - c[i]*a + a - 1)/a, 0ll);
        ans += tmp;
        c[i] += tmp;
        c[j] -= tmp;
        c[i+1] += c[i];
    }cout << ans << endl;
    //system("pause");
}
/***************************************************************************
*stuff you should look for
*int overflow, array bounds
*special cases (n=1?), set tle
*do smth instead of nothing and stay organized
***************************************************************************/

Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int h;
    while(1){

        
        cin >> h;
        if(h == 0){
            break;
        }

        
        vector<vector<int>> stone;
        stone.resize(5);
        for(int i = 0; i < 5; i++){
            stone[i].resize(h);
        }
        for(int i = h-1; i >= 0; i--){
            for(int j = 0; j < 5; j++){
                cin >> stone[j][i];
            }
        }
        
        int old_score = 0;
        int score = 0;
        while(1){
            old_score = score;
            for(int i = 0; i < h; i++){
                for(int j = 0; j < 3; j++){
                    if(stone[j][i] == stone[j+1][i] && stone[j][i] == stone[j+2][i] && stone[j][i] != 0){
                        int old_stone_num = stone[j][i];
                        for(int k = 0; j + k < 5 && stone[j+k][i] == old_stone_num; k++){
                            score += stone[j+k][i];
                            stone[j+k][i] = 0;
                        }
                        break;
                    }
                }
            }
            
            if(old_score == score){
                break;
            }
        
            
            for(int i = 0; i < 5; i++){
                stone[i].erase(remove(stone[i].begin(), stone[i].end(), 0), stone[i].end());
                for(int j = stone[i].size(); j < h; j++){
                    stone[i][j] = 0;
                }
            }


        }
        cout << score << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let n: usize = parse_line().unwrap();
    let (d, x): (usize, usize) = parse_line().unwrap();

    let mut ret = x;
    for _ in 0..n {
        let a: usize = parse_line().unwrap();
        ret += (d - 1) / a + 1;
    }
    println!("{}", ret);
}


Measured memory_bytes: 2188
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
using namespace std;
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define N 1000005
int main()
{
	lld n,p,o=0,e=0,x;
	cin>>n>>p;
	rep(i,1,n+1) {
		cin>>x;
		if(x%2 == 1) o++;
		else e++;
	}
	if(p==1) {
		if(o==0) cout<<0<<endl; 
		else cout<<(1LL<<(o+e-1))<<endl;
	}
	else {
		if(o==1 and e==0) cout<<0<<endl; 
		else if(o==0) cout<<(1LL<<(e))<<endl; 
		else cout<<(1LL<<(o+e-1))<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
# 2019-11-15 13:51:51(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, a, b = [int(x) for x in sys.stdin.readline().split()]
    if n * a >= b:
        ans = b
    else:
        ans = n * a
    
    print(ans)


if __name__ == "__main__":
    main()


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

using Lint=long long;

int main()
{
    int N,K; cin>>N>>K;
    vector<int> a(N);
    for(int i=0;i<N;i++) cin>>a[i];

    vector<Lint> sum(N+1);
    for(int i=0;i<N;i++) sum[i+1]=sum[i]+a[i];

    vector<int> state(N+1);
    for(int i=0;i<=N;i++) state[i]=(sum[i]%K-i%K+K)%K;

    map<int,int> cnt;
    cnt[state[0]]++;
    Lint ans=0;
    for(int i=1;i<=N;i++){
        if(i-K>=0) cnt[state[i-K]]--;
        ans+=cnt[state[i]];
        cnt[state[i]]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a); i<(int)(b); i++)

using ll = long long;

int main(){
  long long int a,b,c;
  cin >> a >> b >> c;
  
  long long int L,R;
  L = 2*(a*b + b*c + c*a);
  R = a*a + b*b + c*c;

  string ans = (L<R ? "Yes" : "No");
  ans = (c < a+b ? "No" : ans);
  
  cout << ans << endl;
}

/*
以下ルートはr(n)として
  ra+rb < rc
  a+b+2rab < c になるはず
移項して
  2rab < c-(a+b)
  4ab < c2 - 2c(a+b) + a2+b2+2ab
  2ab+2bc+2ca < a2+b2+c2 が整数上での条件
各々1e9なのでO(1e18)

1問(005)WAでた…。数学的考察だからわりと合ってるくさいけど
問題があるとしたら2乗で負数のパターン
1回目はabc>=1よりありえない,2回目のc-(a+b)が負数のパターンはあり得る
c-(a+b)が負数のときは
  c < a+b
  rc < r(a+b)
  

*/

Measured memory_bytes: 256
import re

s = input()
table = str.maketrans({'A': 'a', 'T': 't', 'G': 'g', 'C': 'c'})
result = s.translate(table)
# print(result)
#s.replace("A", "a").replace("T", "t").replace("G", "g").replace("C", "c")
result = re.sub(r'[A-Z]', " ", result)
s_list = result.split()
m = 0
for ss in s_list:
    m = max(m, len(ss))
    # print(ss)

print(m)


Measured memory_bytes: 3188
#include<iostream> 
#include<cmath>
#include<algorithm>
#include<string>

using namespace std;

int main(){
    string s;
    int N;
    int c_max = 0;
    cin >> N >> s;
    for(int i = 1; i < N; i++){
        int cnt = 0;
        string a = s.substr(0, i);
        string b = s.substr(i, N - i);
        for(int j = 0; j < 26; j++){
            bool left = false, right = false;
            for(int c = 0; c < a.size();c++){
                if(a[c] == 'a'+j) left = true;
            }
            for(int c = 0; c < b.size();c++){
                if(b[c] == 'a'+j) right = true;
            }
            if(left && right) cnt++;
        }
        c_max = max(c_max, cnt);
    }
    cout << c_max << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Beginner065
{
    public class ABC065B_Trained
    {
        public static void Main(string[] args)
        {
            // 整数の入力
            int n = int.Parse(Console.ReadLine());

            // 改行区切りの整数の入力
            int[] a = new int[n + 1];
            for(int i = 1; i <= n; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
            }


            int pos = 1;
            int distance = 0;
            while(pos != 2 && distance <= n)
            {
                pos = a[pos];
                distance++;
            }

            // 結果出力
            if(distance > n)
            {
                Console.WriteLine("-1");
                return;
            }

            Console.WriteLine(distance);

        }

    }
}

Measured memory_bytes: 15300
#include <iostream>
#include <vector>
#include <string>
using namespace std;

#define FOR(i,s,e) for(int i = (s);i <= (e);i++)

int N;
int M;

string flag[1000];
string emblem[2];

bool issame[1000][1000];


int none_cou = 0;
int main()
{

	cin >> M >> N;

	FOR(i,0,M - 1)
	{
		cin >> flag[i];
	}
	FOR(i,0,1)
	{
		cin >> emblem[i];
	}
	FOR(i,0,M - 2)
	{
		FOR(j,0,N - 2)
		{
			bool same = true;
			FOR(k,0,1)
			{
				FOR(l,0,1)
				{
					same = same && (flag[i + k][j + l] == emblem[k][l]);
				}
			}

			issame[i][j] = same;
			if(same)
			{
				none_cou++;
			}
		}
	}

	int result = none_cou;

	string JOI = "JOI";
	FOR(mi,0,M - 1)
	{
		FOR(ni,0,N - 1)
		{
			int cou = 0;
			for(char c : JOI)
			{
				int cou = none_cou;
				FOR(m,max(mi - 1,0),min(mi,M - 2))
				{
					FOR(n,max(ni - 1,0),min(ni,N - 2))
					{ 
						bool same = true;
						FOR(k,0,1)
						{
							FOR(l,0,1)
							{
								if(!(0 <= m + k && m + k < M && 0 <= n + l && n + l < N))
								{
									same = false;
									break;
								}

								char tmp = flag[m + k][n + l];
								if(m + k == mi && n + l == ni) tmp = c;
								same = same && (emblem[k][l] == tmp);
							}
						}
						if(same && (issame[m][n] == false))
						{
							cou++;
						}
						if( !same && issame[m][n])
						{
							cou--;
						}

					}
				}
				result = max(result,cou);
				if(result == cou)
				{
				}
			}
		}
	}

	cout  << result << endl;
	return 0;

}



Measured memory_bytes: 5112
#include <bits/stdc++.h> 
using namespace std; 
#define rep(i,a,b)		for(long int i=a;i<=b;i++)
#define MOD 1e9+7

long long int n,arr[200];
int main() 
{ 
	ios::sync_with_stdio(false);
    cin.tie(NULL);  

    cin>>n;
    rep(i,1,n)
    	cin>>arr[i];
    sort(arr+1,arr+n+1);
    cout<<arr[n]-arr[1];
}
	

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

using ll = long long;

const ll dev = (ll)(1e9) + 7;

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

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % dev;
        x = x*x % dev;
        n = n >> 1;
    }
    return ans;
}

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

int main(){
	int n, k;

	cin >> n;
	cin >> k;
	
	ll ret = 0;

	fac[0] = 1;
	ifac[0] = 1;
	for(ll i = 0; i<2001; i++){
  	fac[i+1] = fac[i]*(i+1) % dev; // n!(mod M)
		ifac[i+1] = ifac[i]*mpow(i+1, dev-2) % dev; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
	
	for (size_t i = 1; i <= k; ++i) {
		ll co = comb(n-k+1, i);
		ll rem = comb(k-1, i-1);
		ret = (co * rem) % dev;

		cout << ret << endl;
	}
	
	return 0;
}

Measured memory_bytes: 384
S = input()
T = input()

start = [-1 for _ in range(26)]
goal = [-1 for _ in range(26)]

for i in range(len(S)):
    a = ord(S[i]) - ord("a")
    b = ord(T[i]) - ord("a")

    if start[a] != -1 or goal[b] != -1:
        if start[a] != b or goal[b] != a:
            print("No")
            exit()
    else:
        start[a] = b
        goal[b] = a

print("Yes")

Measured memory_bytes: 3632
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque


def check(num, s, left, right):

    if right - left <= 1:
        print(left)
        sys.exit()

    half = (left + right) // 2

    data_set = set()

    for i in range(num -2 * half  + 1):
        now_str = s[i:i + half]
        data_set.add(now_str)
        if s[i + half : i + 2 * half] in data_set:
            check(num, s, half, right)
    check(num, s, left, half)

def main():
    num = int(input())
    s = input()

    left, right = 0, num // 2 + 1

    check(num, s, left, right)




if __name__ == '__main__':
    main()


Measured memory_bytes: 154500
#include <iostream>

using namespace std;

int main() {
    int m1, m2, d1, d2;
    cin >> m1 >> d1 >> m2 >> d2;

    if (m1 != m2) {
        cout << 1 << endl;
        return 0;
    }
    else {
        cout << 0 << endl;
        return 0;
    }
}

Measured memory_bytes: 256
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a + b - 1) / b)
#define tomax(a, b) (a = max(a, b))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int main(){
    StarBurstStream

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n ;i++) cin >> a[i];

    ll ans = 0;
    for(int i = 1; i < n; i++){
        if(a[i] >= a[i - 1]) continue;
        ans += a[i - 1] - a[i];
        a[i] = a[i - 1];
    }
    cout << ans << "\n";

    return 0;
}

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

typedef pair<int, int> P;

int pow(int n) {
  int p = 1;
  for (int i = 0; i < n; i++) {
    p *= 2;
  }
  return p;
}

int main() {
  while (true) {
    string s;
    cin >> s;
    if (s == "#") return 0;

    int i, count, len, slen;
    P a;

    i = 0;
    len = 0;
    slen = 0;
    while (s[i] != '\0') {
      if (s[i] == 'n') {
	i += 5;
	slen += 5;
      } else {
	i += 4;
	slen += 4;
      }
      len++;
    }

    a.second = pow(len - 1);
    
    slen--;
    i = slen;

    if (s[i] == 'h') {
      a.first = 0;
      i -= 5;
    } else {
      a.first = 90 * pow(len - 1);
      i -= 4;
    }

    count = 1;
    while (i > 0) {
      if (s[i] == 'h') {
	a.first -= 90 * pow(len - 1 - count);
	i -= 5;
      } else {
	a.first += 90 * pow(len - 1 - count);
	i -= 4;
      }
      count++;
    }

    while (a.second > 1 && a.first % 2 == 0) {
      a.first /= 2;
      a.second /= 2;
    }
    
    if (a.second == 1)
      cout << a.first << endl;
    else
      cout << a.first << '/' << a.second << endl;
  }
}

Measured memory_bytes: 3036
#include<iostream>
#include<stdio.h>

using namespace std;

int main()
{
	int a, b;

	cin >> a >> b;

	int d = a / b;
	int r = a % b;
	double f = double (a) / b;

	printf("%d %d %f\n", d, r, f);

	return 0;

}

Measured memory_bytes: 3220
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main()
{
	int n;
	int s[1000];
	int sum1=0;
	double sum2=0.0;
	double m;
	int i;
	
	while(1){
		cin >> n;
		if(n==0)
			break;
			
		for(i=0;i<n;i++){
			cin >> s[i];
			sum1+=s[i];
		}
		m=(double)sum1/(double)n;
		
		for(i=0;i<n;i++){
			sum2+=(s[i]-m)*(s[i]-m);
		}
		
		cout << fixed << setprecision(4) << sqrt(sum2/n) << endl;
		
		sum1=0;
		sum2=0.0;
	}
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;

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

int h,n;
int fie[22][2][2];
int flag[22][2][2];
int blo[6][2][2];
int res,cnt;

bool can_set(int v,int dy,int dx){
	for(int i=v*2;i<=v*2+1;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				if(blo[i][j][k]==1){
					if(k+dx<0 || k+dx>=2)return false;
					if(j+dy<0 || j+dy>=2)return false;
				}
			}
		}
	}
	return true;
}

int len(int v,int y,int x){
	for(int i=14;i>=0;i--){
		if(fie[i][y][x]==1)return v-i-1;
	}
	return v;
}

bool check_bomb(int v){
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			if(fie[v][i][j]==0)return false;
		}
	}
	return true;
}

void bomb(int v){
	for(int i=v;i<16;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				fie[i][j][k]=fie[i+1][j][k];
			}
		}
	}
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			fie[16][i][j]=0;
		}
	}
}

void fall(int v,int dy,int dx){
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				if(blo[v*2+i][j][k]==1){
					fie[17+i][j+dy][k+dx]=1;
				}
			}
		}
	}
	int down=20;
	for(int i=17;i<=18;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				if(fie[i][j][k]==1){
					down=min(down,len(i,j,k));
				}
			}
		}
	}
	for(int i=17;i<=18;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				if(fie[i][j][k]>0)fie[i-down][j][k]=fie[i][j][k];
				fie[i][j][k]=0;
			}
		}
	}
	for(int i=16;i>=0;i--){
		if(check_bomb(i)){
			bomb(i);
			cnt++;
		}
	}
}

void dfs(int v){
	if(v==n){
		res=max(res,cnt);
		return;
	}
	for(int i=-1;i<=1;i++){
		for(int j=-1;j<=1;j++){
			if(can_set(v,i,j)){
				int tmp[22][2][2];
				int tmpc=cnt;
				memcpy(tmp,fie,sizeof(tmp));
				fall(v,i,j);
				dfs(v+1);
				cnt=tmpc;
				memcpy(fie,tmp,sizeof(tmp));
			}
		}
	}
}

int main(void){
	while(1){
		scanf("%d%d",&h,&n);
		if(h==0 && n==0)break;
		memset(fie,0,sizeof(fie));
		for(int i=0;i<h;i++){
			for(int j=0;j<2;j++){
				string str;
				cin >> str;
				for(int k=0;k<2;k++){
					if(str[k]=='#')fie[i][j][k]=1;
				}
			}
		}
		memset(blo,0,sizeof(blo));
		for(int i=0;i<n*2;i++){
			for(int j=0;j<2;j++){
				string str;
				cin >> str;
				for(int k=0;k<2;k++){
					if(str[k]=='#')blo[i][j][k]=1;
				}
			}
		}
		res=0;
		cnt=0;
		dfs(0);
		printf("%d\n",res);
	}
	return 0;
}

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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

string s;

void read() {
  cin >> s;
}

int abs(int x) {
  if (x > 0)
    return x;
  return -x;
}

void solve() {
  int sol = 1e9;
  int cnr = (s[0] - '0') * 100 + (s[1] - '0') * 10 + s[2] - '0';
  for(int i = 1; s[i + 1]; ++i) {
    sol = min(sol, abs(753 - cnr));
    cnr -= (s[i - 1] - '0') * 100;
    cnr *= 10;
    cnr += s[i + 2] - '0';
  }
  cout << sol;
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
//  cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


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

int main()
{
  int64_t n, m, a = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++)
  {
    int tmp;
    cin >> tmp;
    a += tmp;
  }
  if (n < a)
  {
    cout << -1 << endl;
  }
  else
  {
    cout << n - a << endl;
  }
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,R;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>R;
	cout<<R+100*max(0,10-N)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
import math
def main():
  a,b,n=map(int,input().split())
  if(b>n):
    print(math.floor(a*n/b)-a*math.floor(n/b))
    return
  if(n>=b):
    print(math.floor(a*(b-1)/b)-a*math.floor((b-1)/b))
    return
    
main()

Measured memory_bytes: 9112
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#define BIG 100000
int main(void) {
	int N;
//	int head = 1;
//	int a[BIG];
	int A = 0;
	int ans=0;
	int tmp = 0;
	scanf("%d", &N);
	scanf("%d", &A);
	ans = N*N - A;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
	val n = (readLine() ?: return).toInt()
	val s = (readLine() ?: return)
	val s1 = s.substring(0, n / 2)
	val s2 = s.substring(n / 2)
	if (s1 == s2) println("Yes")
	else println("No")
}

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

int main() {
	string s;
	map<char, int>mp = {
		{ 'I',1 },
		{ 'V',5 },
		{ 'X',10 },
		{ 'L',50 },
		{ 'C',100 },
		{ 'D',500 },
		{ 'M',1000 }
	};
	while (cin >> s) {
		int cnt = 0;
		rep(i, s.size()) {
			if (i == s.size() - 1 || mp[s[i]] >= mp[s[i + 1]])cnt += mp[s[i]];
			else {
				cnt += mp[s[i + 1]] - mp[s[i]];
				i++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
    int input_sec;
    cin >> input_sec;
    int h = input_sec / 3600;
    int m = (input_sec % 3600) / 60;
    int s = input_sec % 60;
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3136
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(){
  string s;
  cin >> s;
  for(int i = 1;i < s.size();i++){
    if(s.at(i-1) == s.at(i)){
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
}


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

int main() {
    string s;
    cin >> s; 
    int x = 0;
    for (char c : s){
      x += (c - '0');
}
    x %= 9;
    if(x == 0) cout << "Yes" << endl;
    else cout << "No" << endl;    
return 0;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


int main(){
    fast_io

    int c[3][3];
    rep(i,3){
        rep(j, 3){
            cin>>c[i][j];
        }
    }
    for(int i=0;i<3;i++){
        for(int j=i+1;j<3;j++){
            if(c[i][j]+c[j][i] == c[i][i]+c[j][j]){

            }
            else{
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque

def ni():
    return int(sys.stdin.readline())


def nia():
    data = sys.stdin.readline().split(' ')
    return [int(g) for g in data]

n = ni()
graph = []
for i in range(0, n):
    graph.append([])

for i in range(1, n):
    a, b = nia()
    a = a - 1
    b = b - 1

    graph[a].append(b)
    graph[b].append(a)


q = deque()
q.append(0)
visited = set()
visited.add(0)
last = 0
while q:
    n = q.popleft()
    last = n
    for nb in graph[n]:
        if nb not in visited:
            visited.add(nb)
            q.append(nb)

diam = 0
visited = set()
next = [(last, 0)]
while next:
    ind, x = next.pop()
    diam = max(diam, x)
    for nb in graph[ind]:
        if nb not in visited:
            visited.add(nb)
            next.append((nb, x + 1))

if (diam + 1) % 3 == 2:
    print 'Second'
else:
    print 'First'



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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio
    lli n ;
    cin >> n ;
    lli d[n] , s[n] , b[n - 1] , sum =  0 , cnt = 0;
    loopcin(n ,d) ;
    loopcin(n ,s) ;
    loopcin(n - 1 , b) ;

    for (lli i = 0 ; i < n ; i ++)
    {
       if (i > 0 )
        {
            if (d[i] - d[i - 1] == 1){
                sum += s[d[i] - 1] + b[d[i - 1] - 1] ;
                //cout << sum << " 1 " ;
                }

            else {
                sum += s[d[i] - 1] ;
                //cout << sum <<" 2 " ;
                }
        }
        else if (i == 0){
        sum += s[d[i] - 1 ] ;
        //cout << sum << " 22 " ;
        }
    }
    cout << sum ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



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

int main() {
  int n; cin >> n;
  vector<int> x(n), y(n);
  int sum = 0;
  rep(i,n) {
    int a;
    cin >> a;
    sum += a;
    x[i] = sum;
  }
  sum = 0;
  rep(i,n) {
    int a;
    cin >> a;
    sum += a;
    y[i] = sum;
  }

  int ans = x[0] + y[n-1];
  for (int i = 1; i < n; i++) {
    int tmp = x[i] + y[n-1] - y[i-1];
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cfloat>
#include <climits>
#include <cassert>
#include <random>
#include <bitset>
#include <memory>

constexpr long long int MOD = 1000000007;
long long int power(long long int base, long long int exp) {
	switch (exp) {
	case 0: return 1;
	case 1: return base % MOD;
	default: return power(base, exp & 1) * power(base * base % MOD, exp >> 1) % MOD;
	}
}
long long int factorial(int n) {
	long long int result = 1;
	for (auto i = 2; i <= n; ++i) {
		result *= i;
		result %= MOD;
	}
	return result;
}
long long int combination(int n, int r) {
	long long int result = 1;
	for (int i = n; i > n - r; --i) {
		result *= i;
		result %= MOD;
	}
	result *= power(factorial(r), MOD - 2);
	return result % MOD;
}
int main() {
	int n, a, b; std::cin >> n >> a >> b;
	long long int result = power(2, n) - 1;
	result += (2 * MOD - combination(n, a) - combination(n, b));
	std::cout << result % MOD << '\n';
}


Measured memory_bytes: 256
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin >> h >> w;
    char arr[h][w];
    for (int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> arr[i][j];
        }
    }
    int M = 1e9 + 7;
    vector<vector<int>> dp(h,vector<int>(w,0));
    for (int i=h-1;i>=0;i--){
        for (int j=w-1;j>=0;j--){
            if (i==h-1 && j==w-1)
                dp[i][j] = 1;
            else if (arr[i][j] == '#')
                continue;
            else if (i==h-1)
                dp[i][j] = dp[i][j+1];
            else if (j==w-1)
                dp[i][j] = dp[i+1][j];
            else{
                ll val1 = dp[i+1][j];
                val1 = (val1 + dp[i][j+1])%M;
                dp[i][j] = (int)val1;
            }
        }
    }
    cout << dp[0][0] << "\n";
}


Measured memory_bytes: 8192
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;

ll W,H;
int N;
ll X[100005],Y[100005];
ll x[100005],y[100005];

int main(){
  scanf("%lld%lld%d",&W,&H,&N);
  for(int i=0;i<N;i++) scanf("%lld%lld",&X[i],&Y[i]);
  for(int i=0;i<N;i++) x[i] = X[i], y[i] = Y[i];
  sort(X, X+N);
  sort(Y, Y+N);
  
  ll res = 1LL<<60;
  ll resX, resY;
  for(int i=max(0,N/2-1);i<min(N, N/2+1);i++){
    for(int j=max(0,N/2-1);j<min(N,N/2+1);j++){
      ll dis = 0;
      ll maxd = 0;
      for(int k=0;k<N;k++){
	dis += (abs(X[i]-x[k])+abs(Y[j]-y[k]));
	maxd = max(maxd, abs(X[i]-x[k])+abs(Y[j]-y[k]));
      }
      dis *= 2;
      dis -= maxd;
      if(dis < res){
	res = dis;
	resX = X[i];
	resY = Y[j];
      }
    }
  }
  printf("%lld\n%lld %lld\n", res, resX, resY);
  return 0;
}

Measured memory_bytes: 4168
n,k=map(int,input().split())
d=[]
a=[]
for i in range(k):
  d+=[int(input())]
  a+=list(map(int,input().split()))

a=set(a)
cnt=0
for i in range(1,n+1):
  if i not in a:
    cnt+=1
print(cnt)

Measured memory_bytes: 9228
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::input;
//use proconio::marker::*;
//use std::collections::*;
//use std::cmp::*;
// use std::num;
fn main() {
    input! {N:usize, A:[i64;N]}
    let mut ans = -1_000_000_000_000_000_000;
    let mut sodd = vec![0i64; N + 1];
    let mut seven = vec![0i64; N + 1];
    sodd[0] = 0;
    for i in 0..N {
        if i & 1 == 1 {
            sodd[i + 1] = sodd[i] + A[i];
            seven[i + 1] = seven[i];
        } else {
            sodd[i + 1] = sodd[i];
            seven[i + 1] = seven[i] + A[i];
        }
    }
    // 連続する箇所をi,jと置く。
    let mut t = 0;
    if N & 1 == 0 {
        //偶数個の場合
        for i in (0..=N).step_by(2) {
            t = seven[i] + sodd[N] - sodd[i];
            ans = std::cmp::max(ans, t);
        }
    } else {
        //奇数個の場合
        let inf = -1_000_000_000_000_000_000;
        let mut max_over = vec![inf; N + 1];
        // 素直にやるとTLEするので、先に一部を求めておく。
        // max_over ...j >= i+1の時の、seven[N] + sodd[j] -seven[j] の最大値
        max_over[N] = sodd[N] - seven[N];
        let mut i = N - 2;
        loop {
            max_over[i] = std::cmp::max(max_over[i + 2], sodd[i] - seven[i]);
            if i >= 2 {
                i -= 2;
            } else {
                break;
            }
        }
        for i in (0..=N).step_by(2) {
            // for j in (i+1..=N).step_by(2) {
            //   t = seven[i]+ sodd[j] - sodd[i] + seven[N] - seven[j];
            t = seven[i] - sodd[i] + seven[N] + max_over[i + 1];
            ans = std::cmp::max(ans, t);
        }
    }
    println!("{}", ans);
}


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

/*
<url:https://cf16-exhibition-final-open.contest.atcoder.jp/tasks/cf16_exhibition_final_c>
問題文============================================================
 チーターと不正者がニムをすることになりました。 このゲームでは、N 個の石の山を使います。
 最初に i 番目の山には ai 個の石があります。 チーターが先手で、交互にターンを取ります。
 それぞれのターンでは、プレイヤーは一つの山を選び、その山から一個以上の石を取り除きます。
 ターンが回ってきたときに操作ができなくなったプレイヤーの負けです。
 
 しかし、ゲームが始まる前に、
 不正者はチーターがどのような動きをしても必ず勝つことができるように少し不正をすることにしました。
 それぞれの山から、不正者は 0 個または 1 個の石を取り除き、ゲームが始まる前に食べます。
 不正者が必ず勝てるようにする方法が複数通りある場合は、食べる石の個数を最小にするようにしたいです。
 
 不正者が食べる石の個数を求めてください。 不正をしても不正者が必ず勝つようにできない場合は、-1 を出力してください。
=================================================================

解説=============================================================

 ゲーム理論より 全ての山の xor を 0 にしたい
 ここで、初期状態のxor を x とし　ある値 a[i] を a[i]-1 にすると
 
 x = x^(a[i]^(a[i]-1))
 
 となる
 さて、　a[i]^(a[i]-1) は　必ず　2^k-1 の形になることに注目する
 
  サンプル1では
   2^3^4 = (101)_2
     3^2 = (1)_2
     2^1 = (11)_2
     4^3 = (111)_2
 
 である
 
 この(101)_2を 0 にするには　、　まず
 
 3桁目の最上位１に注目して
 4=>3にして
 (101)^(111) = (10)
 次に2桁目の最上位１に注目して
 (10)^(11) = (1)
 同様に
 (1)^(1) = (0) = 0
 
 このように最上位から順番に見て行くことによって確実かつ最適に値を0に近づけることができる
 
 よって、先に a[i] によって作れる 2^k-1 の値を確認しておき
 x に関して最上位から順番に見て行き 変化させていけば良い
 
================================================================
*/

ll solve(){
    ll N; cin >> N;
    vector<ll> a(N);
    for(auto &in:a) cin >> in;
    ll x = 0;
    for(int i = 0; i < N;i++) x ^= a[i];

    // a[i] -> a[i] - 1 := x^(a[i]^(a[i]-1)) = x^(2^k - 1)
    bool f[31] = {false};
    for(int i = 0; i < N;i++){
        ll t = a[i]^(a[i]-1);
        ll cnt = 0, n = 1;
        while(n <= t){cnt++; n<<=1;}
        f[cnt] = true;
    }
    ll ret = 0;
    for(int i = 30; i >= 0; i--){
        if((x>>i)&1){
            if(f[i+1] == false) return ret = -1;
            x^=((1<<(i+1)) - 1); ret++;
        }
    }
    return ret;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


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

	if (n < 1200) {
		cout << "ABC" << endl;
		return 0;
	}
	cout << "ARC" << endl;

}


Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N,p,q;
  cin>>N;
  vector<pair<int,int>> A;
  REP(i,N){
    int a;
    cin>>a;
    A.push_back(make_pair(a,i));
  }
  SORT(A);
  bool CAN=false;
  if(A[N-1].first==A[N-2].first) CAN=true;
  else{
    p=A[N-1].second;
    q=A[N-2].first;
  }
  
  if(CAN){
    REP(i,N) cout<<A[N-1].first<<endl;
  }
  else{
    REP(i,N){
      if(i==p) cout<<q<<endl;
      else cout<<A[N-1].first<<endl;
    }
  }
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
#define repb(i, n) for (int i = (n - 1); i >= 0; i--)
#define repb2(i, a, n) for (int i = (n - 1); i >= (a); i--)
#define all(x) x.begin(), x.end()
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
inline void fastio() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
const int INF = 2e9 + 7;

struct arr {
    int x, y, h;
};

void co_elem(vector<int> &A, int N) {
    rep(i, N) {
        if (i < N - 1) {
            cosp(A[i]);
        } else {
            co(A[i]);
        }
    }
}

void insertionSort(vector<int> &A, int N) {
    rep2(i, 0, N) {
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        co_elem(A, N);
    }
}

int greatestCommonDivisor(int x, int y) {
    if (x < y)
        swap(x, y);
    while (y > 0) {
        int rem = x % y;
        x = y;
        y = rem;
    }
    return x;
    // int n = ((x <= y) ? x : y);
    // int ans = 1;
    // rep2(i, 2, n + 1) {
    //     if (x % i == 0 && y % i == 0 && i > ans) {
    //         ans = i;
    //     }
    // }
    // return ans;
}

int main() {
    int x, y;
    cin >> x >> y;
    co(greatestCommonDivisor(x, y));
    return 0;
}


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

int main()
{
	int L;
	while( cin >> L && L ){
		int M, N;
		int deposit = 0;
		int month = 0;
		for( int i = 0; i < 12; ++i ){
			cin >> M >> N;
			deposit += M - N;
			if( !month && L <= deposit ){
				month = i + 1;
			}
		}
		if( !month ){
			cout << "NA" << endl;
		}else{
			cout << month << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
trs=[]
for _ in range(m):
  a,b=map(int,input().split())
  c=list(map(int,input().split()))
  cnt=0
  for i in range(b):
    cnt+=2**(c[i]-1)
  trs.append((a,cnt))
dp=[10**9]*2**n
dp[0]=0
for i in range(2**n):
  for a,cnt in trs:
    dp[i|cnt]=min(dp[i]+a,dp[i|cnt])
if dp[2**n-1]!=10**9:
  print(dp[2**n-1])
else:
  print(-1)

Measured memory_bytes: 42988