akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << "\n\n"
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

/* mint、表示は変数名.x */
struct mint {
  ll x;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {
  }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  /* 変数名.pow(n) */
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // 以降はMODが素数のみ
  mint inv() const {
    return pow(MOD - 2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

signed main() {
  int N;
  cin >> N;
  vector<int> C(N);
  rep(i, N) {
    cin >> C[i];
  }
  C.pb(-1);

  vector<int> D;
  rep(i, N) {
    if (C[i] != C[i + 1])
      D.pb(C[i]);
  }
  int M = len(D);

  vector<mint> dp(M + 1);
  dp[0] = 1;
  vector<mint> sum(2e+5 + 10, 0);
  rep(i, M) {
    int d = D[i];
      dp[i + 1] = dp[i] + sum[d];
    sum[d] += dp[i];
  }

  ll ans = dp[M].x;
  cout << ans << "\n";
}

Measured memory_bytes: 6000
#include<bits/stdc++.h>    
using namespace std;
int main() {
   // freopen("input.in","r",stdin); 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  
    long long c;
    cin>>c;
    if(c<=999)
        cout<<"ABC";
    else{
       cout<<"ABD";  
     }
   return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lec5Ds
{
    class Program
    {
        public const int INF = 2000000000;
        public const int MAX = 2000000;
        public static int n;
        public static int[] arr_l = new int[MAX];
        public static int[] arr_r = new int[MAX];

        static void Main(string[] args)
        {
            n = int.Parse(Console.ReadLine());
            int[] arr = new int[n];
            string[] inp = Console.ReadLine().Split(' ');
            for (int i = 0; i< n; i++)
            {
                arr[i] = int.Parse(inp[i]);
            }

            Console.WriteLine(MergeSort(arr,0,n));
            Console.ReadLine();

        }

        static ulong MergeSort(int[] arr, int l, int r)
        {
            if (l + 1 < r)
            {
                int mid = (l + r) / 2;
                ulong re = MergeSort(arr, l, mid) +  MergeSort(arr, mid, r) + Sort(arr, l, mid, r);
                return re;
            }
            return 0;
        }

        static ulong Sort(int[] arr, int l, int mid, int r)
        {
            int i, j = 0, k = 0, a = mid - l, b = r - mid;
            ulong c = 0;

            for (i = 0; i < a; i++)
            {
                arr_l[i] = arr[l + i];
            }
            for (i = 0; i < b; i++)
            {
                arr_r[i] = arr[mid + i];
            }
            arr_l[a] = INF; arr_r[b] = INF;

            for (int m = l; m < r; m++)
            {
                if (arr_l[j] <= arr_r[k])
                {
                    arr[m] = arr_l[j];
                    j++;
                }
                else
                {
                    arr[m] = arr_r[k];
                    k++;
                    c += (ulong)(mid + k - m -1);
                }
            }
            return c;
        }
    }
}



Measured memory_bytes: 36788
import math
from decimal import Decimal

n = int(input())
cura,curb = 1,1

for i in range(n):
    t,a = map(int,input().split())
    
    xa,xb = Decimal(cura)/Decimal(t),Decimal(curb)/Decimal(a)
    x = math.ceil(max(xa,xb))
    
    cura,curb = t*x,a*x
    
print(cura+curb)

Measured memory_bytes: 82544
tbl = [[0,4,2,5,3,0],[3,0,6,1,0,4],[5,1,0,0,6,2],\
       [2,6,0,0,1,5],[4,0,1,6,0,3],[0,3,5,2,4,0]]
num = (input().split())
ite = int(input())
for i in range(ite):
    T,F = map(int,input().split())
    Tin = num.index(str(T))
    Fin = num.index(str(F))
    print(num[tbl[Fin][Tin]-1])


Measured memory_bytes: 5596
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<map>
#include<unordered_map>
#define MAXN 500010
#define ll long long

using namespace std;

int N, Q;
string S;
int type;
int iq, lq, rq;
char cq;

int cnt[4*MAXN][26];

void push(int i, int s, int e, int pos, int k, int val)
{
	if(pos < s || pos > e)
		return;
	cnt[i][k] += val;
	if(s == e)
		return;
	int mid = (s + e) >> 1;
	push(2*i+1, s, mid, pos, k, val);
	push(2*i+2, mid+1, e, pos, k, val);
	return;
}

vector<int> query(int i, int s, int e, int l, int r)
{
	if(r < s || l > e)
		return vector<int> (26, 0);
	vector<int> ret = vector<int> (26, 0);
	if(l <= s && r >= e)
	{
		for(int j = 0; j < 26; ++j)
			ret[j] = cnt[i][j];
		return ret;
	}
	int mid = (s + e)>>1;
	vector<int> lret = query(2*i+1, s, mid, l, r);
	vector<int> rret = query(2*i+2, mid+1, e, l, r);
	for(int j = 0; j < 26; ++j)
		ret[j] = lret[j] + rret[j];
	return ret;
}

int main()
{
	cin>>N;
	cin>>S;
	cin>>Q;
	memset(cnt, 0, sizeof(cnt));
	for(int i = 0; i < S.size(); ++i)
	{
		push(0, 1, N, i+1, S[i]-'a', 1);
	}
	while(cin>>type)
	{
		if(type == 1)
		{
			cin>>iq>>cq;
			push(0, 1, N,iq,S[iq-1]-'a', -1);
			S[iq-1] = cq;
			push(0, 1, N,iq,S[iq-1]-'a', 1);
		} 
		else if(type == 2)
		{
			cin>>lq>>rq;
			vector<int> cnts = query(0, 1, N, lq, rq);
			int ans = 0;
			for(int c: cnts)
			{
				if(c > 0)
					++ans;
			}
			cout<<ans<<endl;
		} 
	}
} 

Measured memory_bytes: 204036
#include<stdio.h>

#define N 45

int f[N];

void fib(int n){
  int i;

  for(i = 0; i <= n; i++)f[i] = 0;
  f[0] = f[1] = 1;
  for(i = 2; i <= n; i++)f[i] = f[i-2] + f[i-1];
}


int main(){
  int n;

  scanf("%d",&n);
  fib(n);
  printf("%d\n",f[n]);
  
  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    vector<int> sum(2, 0);
    rep(i, (int)s.size()) sum[s[i] - '0']++;

    cout << 2 * min(sum[0], sum[1]) << endl;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1<<(i))))
#define setbit1(n,i) ((n)|(1<<(i)))
#define togglebit(n,i) ((n)^(1<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
ll dp[200][200005];
ll weight[200005];
ll val[200005];   
int main()
{

    ll n,i,j,k,l,W;
    scanf("%lld%lld",&n,&W);
    for(i=1;i<=n;i++){
    	scanf("%lld%lld",&weight[i],&val[i]);
	}
	for(i=0;i<=n;i++){
		for(j=0;j<=100000;j++){
			if(j==0)
			dp[i][j]=0;
			else
			dp[i][j]=-1;
		}
	}
	ll sum=0;
	for(i=1;i<=n;i++){
		sum+=val[i];
		for(j=1;j<=sum;j++){
			if(j-val[i]>=0&&dp[i-1][j-val[i]]!=-1){
				if(dp[i-1][j]!=-1){
					dp[i][j]=min(dp[i-1][j],dp[i-1][j-val[i]]+weight[i]);
				}
				else{
					dp[i][j]=dp[i-1][j-val[i]]+weight[i];
				}
			}
			else{
			   	if(dp[i-1][j]!=-1){
					dp[i][j]=dp[i-1][j];
				}	
			}
		}
	}
	ll maxi=-1;
	for(i=1;i<=n;i++){
		for(j=1;j<=sum;j++){
			if(dp[i][j]<=W&&dp[i][j]!=-1)
			maxi=j;
		}
	}
	printf("%lld",maxi);
    return 0;
}

Measured memory_bytes: 160000
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll N;

int main(){


    cin >> N;

    if(N % 10 == 7) cout << "Yes" << endl;
    else if(N/10 % 10 == 7) cout << "Yes" << endl;    
    else if(N/100 == 7) cout << "Yes" << endl;    
    else cout << "No" << endl;

}

Measured memory_bytes: 3648
#include <stdio.h>
 
int main(void){
  int a,b,c;
  int tmp;
  
  scanf("%d %d %d",&a,&b,&c);
  
  tmp = a;
  a = b;
  b = tmp;
  
  tmp = a;
  a = c;
  c = tmp;
  
  printf("%d %d %d",a,b,c);
  
  return 0;
}

Measured memory_bytes: 1732
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    vector<vector<ll>> da(2, vector<ll>(2));
    rip(i,2,0) rip(j,2,0) cin >> da[i][j];
    ll ans = LLONG_MIN/2;
    rip(i,2,0) rip(j,2,0) chmax(ans, da[0][i]*da[1][j]);
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main(){
  int n,m;
  while(cin>>n>>m,n){
    int t,s[20000],d[20000];
    P g[20000];
    for(int i=0;i<m;i++)
      cin>>t>>s[i]>>d[i],g[i]=P(t,i);
    sort(g,g+m);
    int ans=0,b[20001]={};
    b[1]=1;
    for(int i=0;i<m;i++){
      int p=g[i].second;
      if(b[s[p]])b[d[p]]=1;
    }
    for(int i=1;i<=n;i++)ans+=b[i];
    cout<<ans<<endl;
  }
  return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    int man[N];
    rep(i,N) man[i] = 0;
    rep(i,K){
        int d;
        cin >> d;
        rep(j,d){
            int res;
            cin >> res;
            man[res - 1]++;
        }
    }
    int res2 = 0;
    rep(i,N){
        if(man[i] == 0) res2++;
    }
    cout << res2 << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<cmath>
#include<string>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
// look for  all edge cases
//search for a pattern


int n , bulbs;
map<int,set<int>> m;
vector<int> decision;

int calc(int idx ,vector<int> state){
	if(idx == n){
		int cnt = 0;
		for(int i =0 ; i < (int)state.size(); i++){
			if(state[i]%2 == decision[i]){
				cnt += 1;
			}
		}
		
		if(cnt == bulbs){
			return 1;
		}
		else{
			return 0;
		}
		
	}
	
	int ans = 0;
	vector<int> new_state = state;
	for(auto it : m[idx]){
		new_state[it] += 1;
	}
	
	ans += calc(idx+1, state);
	ans += calc(idx+1 , new_state);
	
	return ans;
	
	
}

signed main() {	
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	
	
	cin >> n >> bulbs;
	
	for(int i =0 ; i < bulbs; i++){
		int k;
		cin >> k;
		for(int j =0 ; j< k ; j++){
			int temp;
			cin >> temp;
			m[temp-1].insert(i);
		}
		
	}
	
	for(int i = 0; i <bulbs ;i++){
		decision.pb(-1);
		cin>>decision[i];
	}
	
	vector<int> state(bulbs ,0);
	
	
	int ans = calc(0 ,state);
	
	cout<<ans;
	
	
	return 0;
}


Measured memory_bytes: 3676
// problem 3 : count it
#include <bits/stdc++.h>
using namespace std;

long long int moves(vector<int> &arr, int h, int sMoves){
    if(sMoves >= h)
        return 0;

    long long int sum = 0;
    for(int i = 0; i < h - sMoves; i++){
        sum += arr[i];
    }

    return sum;
}

// Driver function
int main(){
    long long int h, sMoves;
    cin >> h >> sMoves;

    vector<int> monsters;
    long long int temp = 0;
    for(int i = 0; i < h; i++){
        cin >> temp;
        monsters.push_back(temp);
    }

    sort(monsters.begin(), monsters.end());

    cout << moves(monsters, h, sMoves);

    return 0;
}


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

#define SIZE 100
#define INF 100000000

struct edge{int to,cap,rev;};
vector<edge> G[SIZE*2+2];
bool visited[SIZE*2+2];

void add_edge(int from,int to,int cap){
    G[from].push_back({to,cap,(int)G[to].size()});
    G[to].push_back({from,0,(int)G[from].size()-1});
}

int dfs(int v,int t,int f){
    if(v==t) return f;
    visited[v] = true;

    for(int i = 0;i < G[v].size();i ++){
        edge &e = G[v][i];

        if(!visited[e.to] && e.cap>0){
            int d = dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

// sからtの最大流を求める
int max_flow(int s,int t){
    int flow = 0;
    while(1){
        memset(visited,0,sizeof(visited));
        int f = dfs(s,t,INF);
        if(f==0) return flow;
        flow += f;
    }
}

int main(){
    int H,W,si,sj,ti,tj;
    cin >> H >> W;
    for(int i = 0;i < H;i ++){
        for(int j = 0;j < W;j ++){
            char a;
            cin >> a;
            if(a=='o' || a=='S' || a=='T'){
                add_edge(i,H+j,1);
                add_edge(H+j,i,1);
                if(a=='S'){
                    add_edge(2*SIZE+1,i,INF);
                    add_edge(2*SIZE+1,H+j,INF);
                    si = i,sj = j;
                }
                if(a=='T'){
                    add_edge(i,2*SIZE+2,INF);
                    add_edge(H+j,2*SIZE+2,INF);
                    ti = i,tj = j;
                }
            }
        }
    }
    if(si==ti || sj==tj) cout << -1 << endl;
    else cout << max_flow(2*SIZE+1,2*SIZE+2) << endl;
    return 0;
}

Measured memory_bytes: 896
_ = gets.split(' ')
ws = gets.split(' ')

ws = ws.map {|w| w.to_i}

min = 99999999
length = ws.length

(0..length - 2).each do |idx|
  arr1 = ws[0..idx]
  arr2 = ws[(idx + 1)..(length - 1)]
  min = (arr1.inject(:+) - arr2.inject(:+)).abs if min > (arr1.inject(:+) - arr2.inject(:+)).abs
end

p min

Measured memory_bytes: 1788
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) std::cout << (j ? s1 : s2) << endl;
# define YES(j) std::cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

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

    char a[101][101];

    for(int i = 0 ; i < h ; i ++){
        for(int j = 0 ; j < w ; j ++){
            cin >> a[i][j];
        }
    }

    for(int i = -1 ; i <= h ; i ++){
        for(int j = -1 ; j <= w ; j ++){
            if(i==-1 || i==h || j==-1 || j==w) cout << '#';
            else cout << a[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
int n,m,i,j,k,count1=0,count2=0;
using namespace std;
void ABC120(void);
void ABC121(void);
void ABC122(void);
void ABC123(void);
void ABC124(void);
void ABC125(void);
void ABC126(void);
void ABC127(void);
void ABC128(void);
void ABC129(void);

int main(void){
    ABC127();
}

void ABC127(){
    int r,D,x,x_next;
    cin>>r>>D>>x;
    for(i=0;i<10;i++){
        x_next=r*x-D;
        cout<<x_next<<endl;
        x=x_next;
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

# refered to
# rank : http://at274.hatenablog.com/entry/2018/02/02/173000
# size : abc120 kaisetsu
class UnionFind:
    def __init__(self, n):
        # par = Parent Number or NoV
        self.par = [-1] * (n+1)
        # rank = Tree Height
        self.rank = [0] * (n+1)
    
    # 自分が所属する集合の数を返す
    def size(self, x):
        return -1*self.par[self.find(x)]
    
    def size_list(self):
        return [x*(-1) for x in self.par[1:] if x < 0]

    # 根なら番号を返す
    def find(self, x):
        
        if(self.par[x] < 1):
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    # 親が同じか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)

        # もう繋がれている
        if(x == y):
            return False

        # つなぎ替える
        if(self.size(x) < self.size(y)):
            x,y = y,x
        
        # xのサイズを更新
        self.par[x] += self.par[y]
        # yのサイズ(おやばんごう)をxに
        self.par[y] = x

        return True 


def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    ans = 0
    for i in range(M):
        uf = UnionFind(N)
        for j in range(M):
            if(j == i):
                continue
            else:
                uf.union(a[j], b[j])

        if(not uf.same_check(a[i], b[i])):
            ans += 1
        
    print(ans)

    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]" 
    b = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
letter = ("a".."z").to_a
while true do
  n = gets.to_i
  break if n == 0
  message = gets.chomp
  operation = Array.new
  n.times do
    operation.push(gets.split.map(&:to_i))
  end
  n.times do
    a, b = operation.pop
    difference = b - a
    message[a - 1], message[b - 1] = message[b - 1], message[a - 1]
    message[a - 1] = letter[(letter.index(message[a - 1]) + difference)%letter.size]
    message[b - 1] = letter[(letter.index(message[b - 1]) + difference)%letter.size]
  end
  puts message
end

Measured memory_bytes: 6128
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using namespace std;

//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main() {
   ll n,ans=0;
   cin>>n;
  
   ll a[n],b[n],c[n];
   rep(i,n)cin>>a[i];
   
   
   rep(i,n)cin>>b[i];
   
   
   rep(i,n)cin>>c[i];
   
   sort(a,a+n);
   sort(c,c+n);
   
   rep(i,n){
       ll ans1,ans2;
       ans1 = lower_bound(a,a+n,b[i])-a;
       ans2 = upper_bound(c,c+n,b[i])-c; 
       //cout<<ans1<<" "<<ans2<<endl;
       if(ans1>n)ans1--;
       if(ans2>n)ans2--;
       ans+=(ans1)*(n-ans2);
       
   }
   cout<<ans<<endl;
   
   
   
   
}



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

int kthbit(int A, int K) { return (A >> K) & 1; }

struct card{ int val; int initial; };

void sortCards(vector<card>& v){
    sort(v.begin(), v.end(), [](const card &a, const card &b){
        if(a.val != b.val) return a.val < b.val;
        else return a.initial < b.initial;
    });
}

int main(){
    int N;  cin >> N;
    vector<pair<int, int>> P(N);
    for(int i=0; i<N; i++)
        cin >> P[i].first;
    for(int i=0; i<N; i++)
        cin >> P[i].second;
    
    int ans = -1;
    for(int n=0; n<(1<<N); n++){
        vector<card> even, odd;
        for(int i=0; i<N; i++){
            card card;
            card.initial = i;
            bool isTable;
            if(kthbit(n, i) == 1){
                card.val = P[i].second;
                isTable = false;
            }else{
                card.val = P[i].first;
                isTable = true;
            }
            if((i%2==0 && isTable) || (i%2==1 && !isTable)) even.push_back(card);
            if((i%2==1 && isTable) || (i%2==0 && !isTable)) odd.push_back(card);
        }
        sortCards(odd);  sortCards(even);

        vector<card> result(N);
        bool ok = true;
        for(int i=0; i<even.size(); i++){
            if(2*i >= N){
                ok = false;
                break;
            }
            result[2*i] = even[i];
        }
        for(int i=0; i<odd.size(); i++){
            if(2*i + 1 >= N){
                ok = false;
                break;
            }
            result[2*i + 1] = odd[i];
        }
        for(int i=0; i<N-1; i++){
            if(result[i].val > result[i+1].val){
                ok = false;
                break;
            }
        }
        if(!ok) continue;

        vector<int> start(N);
        for(int i=0; i<N; i++){
            start[i] = result[i].initial;
        }

        int cnt = 0;
        for(int i=0; i<N-1; i++) for(int j=N-1; j>i; j--){
            if(start[j-1] > start[j]){
                swap(start[j-1], start[j]);
                cnt++;
            }
        }
        if(ans == -1) ans = cnt;
        else ans = min(ans, cnt);   
    }
    cout << ans << endl;
}


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

int main(){
  int A, B, T, result=0;
  cin >> A >> B;

  for(int i=0;i<2;i++){
    if(A>B){
  	  result += A--;
    } else {
      result += B--;
    }
  }
  cout << result << endl;
}

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



Measured memory_bytes: 2040
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
#include<math.h>
#include<list>
 
using namespace std;
 
int main() {
	int  X, N, M;
	cin >> X >> N >> M;
 
	if (abs(X-N)>abs(X-M))	cout << "B" << endl;
	else cout << "A" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace QiFeng233{
	typedef long long ll;
	ll n,ans;
	void solve(){
		scanf("%lld",&n);
		for(ll i=1;i<=n;++i)if(i%3&&i%5)ans+=i;
		printf("%lld",ans);
	}
}
signed main(){
	QiFeng233::solve();
	return 0;
}

Measured memory_bytes: 3828
#include <stdio.h>
#include <math.h>
int main() {
    int n, k,ans=0;
    scanf("%d%d",&n ,&k);
    int a[105]={0};
    while (k--) {
        int d;
        scanf("%d",&d);
        while(d--) {
            int i;
            scanf("%d",&i);
            a[i-1]++;
        }
    }
    for(int i=0;i<n;i++) {
        if(a[i]==0) ans++;
    }
    printf("%d\n",ans);
    // for(int i=0;i<n;i++) {
    //     printf("a[%d]: %d\n",i,a[i]);
    // }
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-') f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=1e5+50;
int n,cnt,L,T,a[N],b[N],w[N];
int main() {
	n=rd(), L=rd(), T=rd();
	for(int i=1;i<=n;i++) {
		a[i]=rd(), w[i]=(rd()==1 ? 1 : -1);
		b[i]=((a[i]+(LL)T*w[i])%L+L)%L;
		int dis=(w[i]>0 ? L-a[i] : a[i])+1;
		if(T>=dis) {
			cnt+=w[i]; int res=T-dis;
			cnt+=(res/L)*w[i];
			cnt=(cnt%n+n)%n;
		}
	} sort(b+1,b+n+1);
	for(int i=1;i<=n;i++) 
		printf("%d\n",b[(i+cnt-1)%n+1]);
}

Measured memory_bytes: 2688
<?php

$n = (int) fgets(STDIN);
$a = explode(' ', rtrim(fgets(STDIN)));

rsort($a);

$index = 0;

// nが奇数の場合
if ($n & 1) {
    // 0がない場合はエラー
    if ($a[$n - 1] != 0) {
        echo 0;
        return;
    }

    $index++;
}

for ($index; $index < $n; $index++) {
    if ($a[$index] != $n - floor($index / 2) * 2 - 1) {
        echo 0;
        return;
    }
}

$result = 1;
$mod = 10 ** 9 + 7;
for ($index = 0; $index < intdiv($n, 2); $index++) {
    $result *= 2;
    $result %= $mod;
}
echo $result;


Measured memory_bytes: 12792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

ll N;

int main(){
	cin >> N;
	
	vector<pii> v(N);
	
	for ( int i = 0; i < N; i++ ){
		ll a, b;
		cin >> a >> b;
		v[i] = {a,b};
	}
	
	sort(v.begin(), v.end(), [](const pii &l, const pii &r){return l.second < r.second;});
	
	int tsum = 0;
	for ( int i = 0; i < N; i++ ){
		tsum += v[i].first;
		if ( tsum > v[i].second ){
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;
	
	
	return 0;
}



Measured memory_bytes: 1792
import java.util.*;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a[][] = new int[3][3];
		for(int i = 0; i < 3; ++i){
			for(int j = 0; j < 3; ++j){
				a[i][j] = sc.nextInt();
			}
		}
		int n = sc.nextInt();
		boolean tmpa[][] = new boolean[3][3];
		for(int i = 0; i < n; ++i){
			int tmp = sc.nextInt();
			for(int j = 0; j < 3; ++j){
				for(int k = 0; k < 3; ++k){
					if(tmp == a[j][k]){
						tmpa[j][k] = true;
					}
				}
			}
		}
		String ans[] = {"Yes", "No"};
		int an = 1;
		sc.close();
		boolean isbingo = true;
		for(int i = 0; i < 3; ++i){
			isbingo = true;
			for(int j = 0; j < 3; ++j){
				if(!tmpa[j][i])isbingo = false;
			}
			if(isbingo){
				an = 0;
				break;
			}
			isbingo = true;
			for(int j = 0; j < 3; ++j){
				if(!tmpa[i][j])isbingo = false;
			}
			if(isbingo){
				an = 0;
				break;
			}
		}
		isbingo = true;
		for(int i = 0; i < 3; ++i){
			if(!tmpa[i][i])isbingo = false;
		}
		if(isbingo){
			an = 0;
		}
		isbingo = true;
		for(int i = 0; i < 3; ++i){
			if(!tmpa[i][2 - i])isbingo = false;
		}
		if(isbingo){
			an = 0;
		}
		System.out.println(ans[an]);
	}
}


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

int main(){
  int HPt, ATt, HPa, ATa;
  cin >> HPt >> ATt >> HPa >> ATa;
  bool wintakahashi;

  for(;;){
    //takahashi's attack
    HPa -= ATt;
    if(HPa <= 0){
      wintakahashi = true;
      break;
    }
    //aoki's attack
    HPt -= ATa;
    if(HPt <= 0){
      wintakahashi = false;
      break;
    }
  }

  if(wintakahashi){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3636
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
scr = 0
ai_1 = float('Inf')
for ai in a:
    scr += b[ai-1]
    if ai_1 + 1 == ai:
        scr += c[ai_1-1]
    ai_1 = ai
print(scr)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int dx[] = { -1 , -1 , -1 , 0 , 0 , 0 , 1 , 1 , 1 };
const int dy[] = { -1 , 0 , 1 , -1 , 0 , 1 , -1 , 0 , 1 };
#define NN 8010000
#define TC int t;cin>>t;for(int T=1;T<=t;T++)
#define mod 1000000007
#define PI acos(-1) // 3.141592654
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define mem(a,n) memset(a,n,sizeof(a))
void AIA() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
//cout<<fixed<<setprecision(20);
// freopen("stand.in","r",stdin);
// freopen("stand.out","w",stdout);
bool isprime(ll n) {
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0)return 0;
	}
	return (n!=1);
}
ll gcd(ll x, ll y)
{
	return (y == 0 ? x : gcd(y, x % y));
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll rem(int x, int N){
	return (x % N + N) % N;
}

int main()
{
	//cout<<fixed<<setprecision(9);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int k;
	cin>>k;
	for(int i=0;i<k;i++)cout<<"ACL";
	cout << endl;
	return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;

    ll N,K;
    ll A[1000];
    ll ans=1;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>K;
    REP(i,N){cin>>A[i];K-=A[i];}
    sort(A,A+N);
    cout<<N+K/A[0];
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    H, W, K = map(int, input().split())
    fib = [1, 1]
    for i in range(W-2):
        fib.append(fib[-2] + fib[-1])
    
    nex = [[0] * W for i in range(W)]
    for i in range(W):
        nex[i][i] = fib[i] * fib[W-1-i]
        if i > 0:
            nex[i][i-1] = fib[i-1] * fib[W-i-1]
        if i < W-1:
            nex[i][i+1] = fib[i] * fib[W-i-2]
    MOD = int(1e9) + 7
    dp = [[0] * W for i in range(H+1)]
    dp[0][0] = 1
    for i in range(H):
        for j in range(W):
            dp[i+1][j] += dp[i][j] * nex[j][j]
            dp[i+1][j] %= MOD
            if j > 0:
                dp[i+1][j-1] += dp[i][j] * nex[j][j-1]
                dp[i+1][j-1] %= MOD
            if j < W-1:
                dp[i+1][j+1] += dp[i][j] * nex[j][j+1]
                dp[i+1][j+1] %= MOD
    print(dp[H][K-1])


if __name__ == "__main__":
    main()

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

using namespace std;
int main(){
	int i,N,ans,x,y;
		cin >> N;
	vector <long long> a(N+1);
	for(i=0;i<N;i++){
		cin >> a[i];
	}
	a[N] = 1000000010;
	sort(a.begin(),a.end());
	x = 0;
	ans = 0;
	y = 0;
	for(i=0;i<N;i++){
		if(a[i]!=a[i+1]){
			y = i+1;
			if((y-x)<a[i]){
				ans += y-x;
			}else{
				ans += y-x-a[i];
			}
		x = i+1;
		}
	}
	cout << ans << endl;
}
			

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void map_add(map<int,int> & mp, int X)
{
  auto itr = mp.find(X);
  if(itr != mp.end())
  {
    itr->second++;
  }
  else
  {
    mp[X] = 1;
  }
  return;
}
void solve(void)
{
  int N;
  cin>>N;
  map<int,int> mp;
  for (int i = 1; i <= N; i++)
  {
    int A = i;
    for (int j = 2; j*j <= A ; j++)
    {
      while(A%j == 0)
      {
        A /=j;
        map_add(mp,j);
      }
    }
    if(A != 1)
    {
      map_add(mp,A);
    }
  }

  int ANS = 1;
  auto itr = mp.begin();
  for (int i = 0; i < mp.size(); i++)
  {
    ANS *= (itr->second +1 );
    itr++;
    ANS %= MOD;
  }
  cout<<ANS<<endl;
  
  

  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector<int> A(N+1,-1),B;
	for(int i=0;i<N;++i){
		cin >> A[i+1];
	}
	B = A;
	int ans = 0;
	for(int i=1;i<N;++i){
		if( A[i] != i ) continue;
		{
			swap(A[i],A[i+1]);
			++ans;
			++i;
		}
	}
	if( A[N] == N ){
		++ans;
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 1024
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//vector<pair<ll,ll>> pc;
//int ABS(int a){return max(a,-a);}
int main(){
    int n;
    cin>>n;
    int l[n];
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    sort(l,l+n);
    int num=0;
    for(int i=0;i<n-1;i++){
        num+=l[i];
    }
    if(num>l[n-1]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

const int mod = 998244353;

ll binpow(ll a, int p) {
	ll res = 1;
	while (p) {
		if (p & 1) {
			(res *= a) %= mod;
		}
		p >>= 1;
		(a *= a) %= mod;
	}
	return res;
}

const int N = 3001;

ll dp[N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, s;
	cin >> n >> s;
	vector<int> a(n);
	for (int& i : a) cin >> i;
	dp[0] = binpow(2, n);
	ll q = binpow(2, mod - 2);
	for (int i = 0; i < n; i++) {
		for (int w = s; w >= a[i]; w--) {
			dp[w] += dp[w - a[i]] * q % mod;
			dp[w] %= mod; 
		}
	}
	cout << dp[s] << endl;
	return 0;
}


Measured memory_bytes: 3672
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

struct node_t {
	int x;
	struct node_t* prev;
	struct node_t* next;
};

struct node_t* create_node(int x) {
	struct node_t* node = malloc(sizeof(struct node_t));
	if (node == NULL) exit(1);
	node->x = x;
	node->prev = node->next = NULL;
	return node;
}

int main(void) {
	struct node_t* cursor = create_node(INT_MAX);
	int q, i;
	if (scanf("%d", &q) != 1) return 1;
	for (i = 0; i < q; i++) {
		int query, param;
		if (scanf("%d", &query) != 1) return 1;
		if (query != 2 && scanf("%d", &param) != 1) return 1;
		switch (query) {
			case 0:
				{
					struct node_t* pe = cursor->prev;
					struct node_t* new_node = create_node(param);
					new_node->prev = pe;
					new_node->next = cursor;
					if (pe != NULL) pe->next = new_node;
					cursor->prev = new_node;
					cursor = new_node;
				}
				break;
			case 1:
				if (param > 0) {
					int j;
					for (j = 0; j < param; j++) cursor = cursor->next;
				} else if (param < 0) {
					int j;
					for (j = 0; j > param; j--) cursor = cursor->prev;
				}
				break;
			case 2:
				{
					struct node_t* pe = cursor->prev;
					struct node_t* ne = cursor->next;
					if (pe != NULL) pe->next = ne;
					if (ne != NULL) ne->prev = pe;
					free(cursor);
					cursor = ne;
				}
				break;
		}
	}
	while (cursor->prev != NULL) cursor = cursor->prev;
	while (cursor != NULL && cursor->x != INT_MAX) {
		struct node_t* next = cursor->next;
		printf("%d\n", cursor->x);
		free(cursor);
		cursor = next;
	}
	free(cursor);
	return 0;
}



Measured memory_bytes: 17284
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
using namespace std;
typedef long long int llint;
int main() {
	int a, b, x;
	cin >> x >> a >> b;
	if (abs(a - x) < abs(b - x)) {
		cout << "A" << endl;
	}
	else {
		cout << "B" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
int main() {
	long long n, m;
	cin >> n >> m;
	if(n > m) swap(n, m);
	if(n == 1 and m > 2) cout << m - 2 << endl;
	else cout << n * m - 2 * m - 2 * n + 4 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int a[3];

int main(){
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	cout<<(a[0]==a[1]&&a[1]!=a[2]||a[0]!=a[1]&&a[1]==a[2]?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
   int N,K;
   cin>>N>>K;
   int count[150]={0};
   int d[150];
   int A[150];
   int result=0;
   for(int i=0;i<K;i++) {
       cin>>d[i];
       for(int j=0;j<d[i];j++){
           cin>>A[j];
           count[A[j]-1]++;
       }
   }
    for(int k=0;k<N;k++){
        if(count[k]==0){
            result++;
        }
    }
    cout<<result<<endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define bint vector<int>
#define minus qwertyuiopasdfghjklzxcvbnm
struct hugenum{
	int digits;
	int cnt[10];
	hugenum(){
		digits=0;
		memset(cnt,0,sizeof(cnt)); 
	}
}dp[10010];
int cost[10]={0,2,5,5,4,5,6,3,7,6};
bool vis[10010];
bool big(hugenum a,hugenum b){
	if(a.digits!=b.digits)
		return a.digits>b.digits;
	for(int i=9;i>=1;i--)
		if(a.cnt[i]!=b.cnt[i])
			return a.cnt[i]>b.cnt[i];
	return 0;
}
int n,m;
bool yes[10];
int x;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>x;
		yes[x]=true;
	}
	vis[0]=true;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=9;j++)if(yes[j]&&cost[j]<=i&&vis[i-cost[j]]){
			hugenum x=dp[i-cost[j]];
			x.cnt[j]++;
			x.digits++;
			if(big(x,dp[i])){
				dp[i]=x;
			}
			vis[i]=true;
		}
	}
	for(int i=9;i>=1;i--){
		for(int j=1;j<=dp[n].cnt[i];j++)
			cout<<i;
	}
	return 0;
}


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

def main():
    """Function."""
    n = int(input())
    a = str(input())
    b = str(input())
    c = str(input())

    counter = 0
    for i in range(n):
        temp = len(set((a[i], b[i], c[i])))

        if temp == 1:
            pass
        elif temp == 2:
            counter += 1
        elif temp == 3:
            counter += 2

    print(counter)


if __name__ == "__main__":
    main()


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

int main() {
	char x[4], y[4];

	cin >> x >> y;

	if (x[0] == y[2] && x[1] == y[1] && x[2] == y[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a; cin >> a ;
  if(a<1200) cout << "ABC" << endl;
  else if(1200<=a&a<2800) cout << "ARC" << endl;
  else if (a>=2800) cout << "AGC" << endl;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] line = br.readLine().split(" ");
		String s = line[0];
		String t = line[1];
		line = br.readLine().split(" ");
		int a = Integer.parseInt(line[0]);
		int b = Integer.parseInt(line[1]);
		String u = br.readLine();
		br.close();
		if(u.equals(s)) {
			a--;
		}else if(u.equals(t)) {
			b--;
		}
		System.out.println(a + " " + b);
	}

}


Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
typedef long long ll;

int main() {
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;

    int ans = 0;

    for (int start = 0; start < K; start++) {
       vector<tuple<int,int,int>> dp = {make_tuple(0,0,0)}; 
       int step = 0;
       while (start + step*K < N) {
           char c = T[start + step*K];
           auto prev = dp.back();
           int prevr, prevs, prevp, nextr, nexts, nextp;
           tie(prevr, prevs, prevp) = prev;
           nextr = max(prevs, prevp);
           nexts = max(prevr, prevp);
           nextp = max(prevr, prevs);
           if (c == 's') nextr += R;
           if (c == 'p') nexts += S;
           if (c == 'r') nextp += P;
           dp.push_back(make_tuple(nextr, nexts, nextp));
           step++;
       }
       int bestr, bests, bestp;
       tie(bestr, bests, bestp) = dp.back();
       ans += max(max(bestr, bests), bestp);
    }

    cout << ans << endl;
}


Measured memory_bytes: 2104
#include <stdio.h>

int main(void){
  int n;
char s[2];
  
  int i;
  int x = 0;
  
  scanf("%d", &n);
  for (i = 0; i < n; i++) {scanf("%s", s);if (s[0]=='Y')x++;
  }
  puts(x ? "Four": "Three");
  return 0;

}


Measured memory_bytes: 128