akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
  ll n,ans=1;cin>>n;
  string s,t;cin>>s>>t;

  for(int i=0;i < n;i++)
  {
    if(i==0){
      if(s[i]==t[i])ans*=3;
      else {ans*=6;i++;}
    }else{

      if(s[i]==t[i]){
        if(s[i-1]==t[i-1])ans*=2;
      }else {
        if(s[i-1]==t[i-1]){
          ans*=2;
        }else{
          ans*=3;
        }
        i++;
      }

    }
    ans%=mod;
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;

void solve(){
    int n , m ;
    cin >> n >> m ;
    int mul = (1 << m);
    long long k = 1LL * mul * (m * 1900 + (n - m) * 100);
    cout << k ; 
}

int main()
{
    ios::sync_with_stdio(NULL);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}


Measured memory_bytes: 3604
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <set>
#include <sstream>
#include <string>
#include <queue>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;

//MOD//
const ll MOD = 1000000007;
struct big;
big ex(big a, ll tms);
typedef struct big{
  ll val;
  big():val(0){}
  big(ll val):val((val%MOD+MOD)%MOD){}
  big& operator += (const big& obj){ (val+=obj.val)%=MOD; return *this;}
  big& operator -= (const big& obj){ (val+=MOD-obj.val)%=MOD; return *this;}
  big& operator *= (const big& obj){ (val*=obj.val)%=MOD; return *this;}
  big& operator /= (const big& obj){ (val*=ex(obj,MOD-2).val)%=MOD; return *this;}
  big operator + (const big& obj)const{ return big(*this) += obj;}
  big operator - (const big& obj)const{ return big(*this) -= obj;}
  big operator * (const big& obj)const{ return big(*this) *= obj;}
  big operator / (const big& obj)const{ return big(*this) /= obj;}
  bool operator < (const big& obj)const{ return val < obj.val;}
  bool operator == (const big& obj)const{ return val == obj.val;}
} big;
istream& operator >> (istream& i, big& obj){ i>>obj.val; return i;}
ostream& operator << (ostream& o, const big& obj){ o<<obj.val; return o;}
big ex(big obj, ll tms){
  if(!tms) return 1;
  big ret = ex(obj, tms/2);
  ret *= ret;
  return (tms&1) ? ret*obj : ret;
}
//MOD//

ll pow(ll n, int m){
  if(!m) return 1;
  ll ret = pow(n, m/2);
  ret *= ret;
  return (m&1) ? ret*n : ret;
}

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


int main(){
  int N;
  scanf("%d",&N);
  ll n1 = 1, n2 = 1;
  int t_b = 1, a_b = 1;
  int t, a;
  rep(i,N){
    scanf("%d%d",&t,&a);
    ll h;
    if(t_b * a > a_b * t){
      h = (n1-1) / t + 1;
    }else{
      h = (n2-1) / a + 1;
    }
    n1 = h * t;
    n2 = h * a;
    t_b = t;
    a_b = a;
  }
  ll ans = n1 + n2;
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

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

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

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i]) {
                    if (l[i] < l[j] + l[k] && l[j] < l[k] + l[i] && l[k] < l[i] + l[j]) ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int cnt = 0;
  while(n > 0){
    n /= k;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <set>

using namespace std;
void input(set<int> &);
void output(set<int> &);

int main()
{
    set<int> A, B;
    input(A);
    input(B);

    // set<int>::iterator it = B.begin();
    // while (it != B.end())
    // {
    //     if (A.find(*it) == A.end())
    //     {
    //         B.erase(*it);
    //     }
    //     it++;
    // }

    // output(B);


    // //法2
    set<int> C;
    set_intersection(A.begin(), A.end(), B.begin(), B.end(), inserter(C, C.begin()));
    output(C);
 
}


void input(set<int> & A)
{
    int n;
    cin >> n;

    int a;
    while (n--)
    {
        cin >> a;
        A.insert(a);
    }
}

void output(set<int> & A)
{
    set<int>::iterator it = A.begin();
    while (it != A.end())
    {
        cout << *it << endl;
        it++;
    }
}


Measured memory_bytes: 23616
#include <stdio.h>

int main(){
  int i,j,n,m,t,v[200][200];

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      v[i][j]=0;
    }
  }

  for(i=1;i<=n;i++){
    scanf("%d%d",&t,&m);
    for(j=0;j<m;j++){
      scanf("%d",&t);
      v[i][t]=1;
    }
  }

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j!=1){
	printf(" ");
      }
      printf("%d",v[i][j]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2056
def solve(ans, shortage, excess):
    if sum(excess) < shortage:
        return -1
    if ans == 0:
        return 0
    excess.sort(reverse=True)
    tmp = 0
    for i, e in enumerate(excess):
        tmp += e
        if tmp >= shortage:
            return ans + i + 1


n = int(input())
shortage = 0
excess = []
ans = 0
for a, b in zip(map(int, input().split()), map(int, input().split())):
    if a == b:
        continue
    if a > b:
        excess.append(a - b)
    else:
        shortage += b - a
        ans += 1
print(solve(ans, shortage, excess))


Measured memory_bytes: 20600
#include<bits/stdc++.h>
#include <sys/stat.h>
using namespace std;
using ll = int64_t;

vector<int> G[1000000];
vector<pair<int, int> > bridge;
vector<int> articulation;
int ord[1000000], low[1000000];
bool vis[1000000];

void dfs(int v, int p, int &k)
{
	vis[v] = true;

	ord[v] = k++;
	low[v] = ord[v];

	bool isArticulation = false;
	int ct = 0;

	for (int i = 0; i < G[v].size(); i++){
		if (!vis[G[v][i]]){
			ct++;
			dfs(G[v][i], v, k);
			low[v] = min(low[v], low[G[v][i]]);
			if (~p && ord[v] <= low[G[v][i]]) isArticulation = true;
			if (ord[v] < low[G[v][i]]) bridge.push_back(make_pair(min(v, G[v][i]), max(v, G[v][i])));
		}
		else if (G[v][i] != p){
			low[v] = min(low[v], ord[G[v][i]]);
		}
	}

	if (p == -1 && ct > 1) isArticulation = true;
	if (isArticulation) articulation.push_back(v);
}



int main(int , char **)
{
#ifdef LOCAL_DEBUG
	struct stat sb;
	ifstream in("/dev/shm/input.txt");
	if (stat("/dev/shm/input.txt",&sb)==0){ cin.rdbuf(in.rdbuf()); }
#endif

	int n, m;

		scanf("%d %d", &n, &m);

		for (int i = 0; i < m; i++){
			int x, y;
			scanf("%d %d", &x, &y);
			G[--x].push_back(--y);
			G[y].push_back(x);
		}

		int k = 0;
		for (int i = 0; i < n; i++){
			if (!vis[i]) dfs(i, -1, k);
		}

		sort(bridge.begin(), bridge.end());
		sort(articulation.begin(), articulation.end());

		printf("%d\n", bridge.size());

	return 0;
}


Measured memory_bytes: 26368
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] T = new int[N];
        for(int i = 0; i < N; i++) T[i] = sc.nextInt();
        
        int M = sc.nextInt();
        int[] P = new int[M];
        int[] X = new int[M];
        for(int i = 0; i < M; i++){
            P[i] = sc.nextInt();
            X[i] = sc.nextInt();
        }
        
        int sumTime = 0;
        for(int i = 0; i < N; i++){
            sumTime += T[i];
        }

        for(int i = 0; i < M; i++){
            int ans = sumTime - (T[P[i]-1] - X[i]);
            System.out.println(ans);
        }
    }
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x;
    cin >> n >>x;
     int l[n];
     for(int i=0;i<n;i++)
     cin >>l[i];
     int d=0,b=0;
     while(d<=x)
     {
        d  = d + l[b];
        b++;
     }   
    cout<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
//Author: Lixiang
#include<stdio.h>
#include<iostream>
using namespace std;
struct A{
	long long K,A,B;
	void init(){
		cin>>K>>A>>B;
	}
	void work(){
		K-=A;
		if(K<=0)cout<<1<<endl;
		else
			if(A<=B)puts("-1");
			else{
				long long t=A-B;
				if(K%t==0)cout<<(K/t-1ll)*2ll+3ll<<endl;
				else cout<<(K/t)*2ll+3ll<<endl;
			}
	}
}sol;
int main(){
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	sol.init();
	sol.work();
	return 0;
}


Measured memory_bytes: 256
//   //  /////       ///      
//  //   //  //     // //     
// //    //   //   //   //    
////     //   //  //     //   
// //    //   //  /////////    
//  //   //  //   //     //    
//   //  /////    //     //    

#include <bits/stdc++.h>
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define iter(it,a,b) for(a::iterator it=b.begin(); it!=b.end();++it)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (binary me 1 kitne hai) (if longlong popcount ll)
#define ln "\n"
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end() 
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;

#pragma GCC optimize ("-O2")
const ll LIM = 2e5+5;
const ll MOD = 1e9+7;
const ll inf = 1e10;



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

	int n;
	cin >> n;

	ld p[n+1];
	forsn(i,1,n+1) cin >> p[i];

	ld dp[n+1][n+1];

	dp[0][0]=1;
	forsn(i,1,n+1) dp[i][0] = (dp[i-1][0])*(1-p[i]);
	forsn(i,1,n+1) dp[0][i]=0;

	forsn(i,1,n+1) forsn(j,1,n+1) dp[i][j] = ((dp[i-1][j-1])*p[i]) + ((dp[i-1][j])*(1-p[i]));

	ld dpsum=0;

	forsn(i,(n+1)/2,n+1) dpsum += dp[n][i];

	cout << setprecision(11) << dpsum;

}


Measured memory_bytes: 140928
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n, i;
  cin >> n >> i;

  int ans = n - i + 1;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		
		ll k;
		cin>>k;
		string s;
		cin>>s;
		if(s.size()<=k) {
			cout<<s<<endl;
		}
		else {
			string subs = s.substr(0,k);
			subs = subs + "...";
			cout<<subs<<endl;
		}
		return 0;
	}


Measured memory_bytes: 3620
#Time limit exceedsになるので二分探索法を使う
from bisect import bisect_left


while True:
    n, q = map(int, input().split())
    if n == 0:
        break

    era = {} # {西暦: ('元号', 年)}
    years = [] 
    
    for _ in range(n):
        gengou, wa_year, we_year = input().split()
        wa_year = int(wa_year)
        we_year = int(we_year)
        era[we_year] = (gengou, wa_year)
        years.append(we_year)
    
    years_final = sorted(years) 

    for _ in range(q):
        year1 = int(input())
        temp = bisect_left(years_final, year1)
        
        if temp >= len(years_final):
            print('Unknown')
            continue
            
        year2 = years_final[temp]
        gengou, span = era[year2]
        result = year1 - year2 + span

        if result <= 0:
            print('Unknown')
        else:
            print(gengou, result)


Measured memory_bytes: 5928
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	k, x := nextInt(), nextInt()

	for i := x - (k - 1); i < (x + (k - 1)); i++ {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println(x + (k - 1))
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**9)
n,q=map(int,input().split())
G=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

subtree_size=[0]*n
cnt=[0]*n

for _ in range(q):
    p,x=map(int,input().split())
    p-=1
    cnt[p]+=x
ans=[0]*n

def dfs(G,v,p):
    ans[v]+=cnt[v]
    for nv in G[v]:
        if nv==p:
            continue
        cnt[nv]+=cnt[v]
        dfs(G,nv,v)
    
    subtree_size[v]=1
    for c in G[v]:
        if c==p:
            continue
        subtree_size[v]+=subtree_size[c]

root=0
dfs(G,root,-1)

for i in range(n):
    print(ans[i],end=' ')





Measured memory_bytes: 244260
from fractions import gcd
n = int(input())
A = list(map(int, input().split()))
#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num

#####segfunc######
def segfunc(x,y):
    return gcd(x, y) 

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k+1:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res
  
init(A)
result = 0
for i in range(n):
  temp = gcd(query(0, i), query(i + 1, n))
  result = max(result, temp)
print(result)

Measured memory_bytes: 16140
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    vector<int>A(3);
    int ans=0;
    rep(i,3){
        cin>>A.at(i);
    }
    sort(A.begin(),A.end());
    ans+=abs(A.at(1)-A.at(0));
    ans+=abs(A.at(2)-A.at(1));
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
n, k, q = map(int, input().split())
inl = [int(input()) for x in range(q)]
chl = [0] * n
for z in inl:
  chl[z-1] += 1
for y in range(n):
  if chl[y] > (q-k):
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 8636
#include <bits/stdc++.h> 
using namespace std;
int main(){
	double w,h,x,y;
	int z=0;
	cin>>w>>h>>x>>y;
	if(w/2==x && h/2==y){
		z=1;
	}
	cout<<w*h/2<<"  "<<z;
	return 0;
}

Measured memory_bytes: 256
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans;
ll n,k,q;
void solve()
{
    cin>>n;
    ll a[n];
    for(int i=1;i<n;i++)
    {
        cin>>a[i];
    }
    ans+=a[1]+a[n-1];
    for(int i=2;i<n;i++)
    {
        ans+=min(a[i],a[i-1]);
    }
    cout<<ans<<endl;
}   

int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
   // int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  if(N<1000) cout<<"ABC"<<endl;
  else cout<<"ABD"<<endl;
}



Measured memory_bytes: 3612
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 2e5 + 10 , LG = 19;
int n , V , x[N] , toR[LG][N] , toL[LG][N] , len;
int fL[1<<LG] , fR[1<<LG];

void prepare(int toR[][N] , int *fL , const vi&x) {
  int V = ::V;
  len = 0;
  while(V >= 0) {
    toR[len][n]=toR[len][n+1]=n;
    per(i,1,n) toR[len][i]=abs(x[i]-x[i+1])<=V?toR[len][i+1]:i;
    len++;
    if(V==0) break;
    V >>= 1;
  }
  rep(i,0,1<<len) fL[i]=0;
  rep(i,0,1<<len) {
    rep(j,0,len) if(~i>>j&1)
      fL[i|1<<j]=max(fL[i|1<<j],toR[j][fL[i]+1]);
  }
}

int main(){
  scanf("%d%d",&n,&V);
  rep(i,1,n+1) scanf("%d",x+i);
  vi v(x,x+1+n);
  prepare(toR , fL , v);
  reverse(v.begin()+1,v.begin()+1+n);
  prepare(toL , fR , v);
  vector<pii> seg;
  int full=(1<<len)-1-1;
  rep(i,0,1<<len) if(~i&1) {
    seg.pb(mp(-fR[i],fL[full^i]));
  }
  sort(all(seg));
  int cur=0,leftmost=-1;
  rep(i,1,n+1) {
    int left=n+1-toL[0][n+1-i];
    int right=toR[0][i];
    while(cur<sz(seg)&&-seg[cur].fi+right>=n) {
      leftmost=max(leftmost,seg[cur].se);
      cur++;
    }
    if(leftmost+1>=left) puts("Possible");
    else puts("Impossible");
  }
  return 0;
}


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

void stones() {
	int n, k;
	cin >> n >> k;
	int arr[n];

	for (int i = 0; i < n; i++)
		cin >> arr[i];
	bool dp[k + 1];
	memset(dp, 0, sizeof dp);
	for (int i = 1; i <= k; i++) {
		for (int j = 0; j < n; j++) {
			if (i - arr[j] >= 0  and dp[i - arr[j]] == 0) {
				dp[i] = 1;
				break;
			}
		}
	}
	if (dp[k] == 1)
		cout << "First";
	else cout << "Second";
	return;
}
int main()
{
	stones();
	return 0;
}


Measured memory_bytes: 384
# Problem Line++

# input
N, X, Y = map(int, input().split())

# initialization
kyori_graph = [[N]*N for i in range(N)]
kosu_list = [0]*(N-1)

# dp
for i in range(N):
    for j in range(i+1, N):
        kyori_graph[i][j] = min(abs(j-i), abs((X-1)-i)+1+abs(j-(Y-1)))

# output
for i in range(N):
    for j in range(i+1, N):
        kyori = kyori_graph[i][j]
        kosu_list[kyori-1] += 1
for k in kosu_list:
    print(k)


Measured memory_bytes: 78172
#include<bits/stdc++.h>
#define LL long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define For(i,a,b) for(int i=a;i>=b;i--)
#define debug
#define Maxn 1000

using namespace std;

int read(){
    char c=getchar(); int flag=1, x=0;
    while(!isdigit(c)){ if(c=='-') flag=-1; c=getchar(); }
    while( isdigit(c)){ x=x*10+(c-'0'); c=getchar(); }
    return flag*x;
}

int n;
int d[Maxn+10];

signed main(){

    n=read();
    FOR(i,1,n) d[i]=read();

    unsigned LL Sum=0;
    FOR(i,1,n) FOR(j,i+1,n)
        Sum+=d[i]*d[j];

    cout<<Sum<<endl;
    
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  bool A = false;
  for (char c = 'a'; c <= 'z'; c++) {
    if (A) {
      break;
    }
    for (int i = 0; i < S.length(); i++) {
      if (S[i] == c) {
        break;
      }
      if (i == S.length() - 1) {
        cout << c;
        A = true;
      }
    }
  }
  if (!A) {
    cout << "None";
  }
}

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

#define endl '\n'

bool cmp(char a, char b) {
    return a > b;
}

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

    string a, b;
    cin >> a >> b;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end(), cmp);

    cout << (a < b ? "Yes" : "No");

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  bool flag = true;
  vector<string> st(n);
  rep(i, n) {
    cin >> st[i];
  }
  rep(i,n) rep(j,i) {
    if(i == j) continue;
    if(st[j] == st[i]) flag = false;
  }
  if(flag) {
    for(int i = 0; i < n; i++){
      char s_last;
      if(i == 0) {
        s_last = st[i][st[i].size()-1];
        continue;
      }
      else {
        char s_first = st[i][0];
        if(s_first != s_last) {
          flag = false;
        }
        s_last = st[i][st[i].size()-1];
      }
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

      
  

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

using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;


int32_t main() {
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    
    ini(n);
    int tmp = INF;
    int tmp1 = 0;
    FOR(i,0,n){
        ini(x);
        tmp1+=x;
        ini(x1);
        if(x>x1){
            tmp = min(tmp,x1);
        }
    }
    if(tmp == INF)out(0);
    else out(tmp1-tmp);
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include<stdlib.h>
#include<stdio.h>
#pragma warning(disable:4996)

int main(){
	int n = 0, u = 0, k = 0, x = 0;
	int matrix[100][100] = { 0 };
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d", &u);
		scanf("%d", &k);
		for (int j = 0; j < k; j++){
			scanf("%d", &x);
			matrix[u - 1][x - 1] = 1;
		}
	}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				printf("%d", matrix[i][j]);
				if (j == n - 1){
					continue;
				}
				else
					printf(" ");
				
			}
			printf("\n");
		}//輸出
		
	


	return 0;
}


Measured memory_bytes: 2148
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000



int main(){

  while(true){
    int n;
    cin >> n;

    if(n==0) break;

    int sum=0, a=INF, b=-1; //a:min, b:max

    rep(i,n){
      int s;
      scanf("%d",&s);
      sum += s;
      a=min(a,s);
      b=max(b,s);
    }
    sum=(sum-a-b)/(n-2);

    cout << sum << endl;

  }

}

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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}
const int N = 2*1e5 + 5;
lli fac[N];

lli pow1(lli x, lli y) {
  lli ans = 1;
  while(y>0) {
    if(y&1LL) ans = (ans * x) % MOD;
    x = (x * 1LL * x) % MOD;
    y = y>>1;
  }
  return ans;
}
lli inv(lli x) {
  return pow1(x, MOD-2);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  int n; cin>>n;
  int a, b; cin>>a>>b;
  lli s1 = 1, s2 = 1;
  rep(i,n-a+1,n+1) s1 = (s1 * i) % MOD;
  rep(i,1,a+1) s1 = (s1 * inv(i)) %MOD;
  rep(i,n-b+1,n+1) s2 = (s2 * i) % MOD;
  rep(i,1,b+1) s2 = (s2 * inv(i)) %MOD;
  lli ans = pow1(2,n) - 1 - ((s1+s2)%MOD);
  ans %= MOD;
  if(ans<0) ans += MOD;
  ans %= MOD;
  cout<<ans<<endl;
}



Measured memory_bytes: 256
function main(input) {
    var args = input.split(' ');
    var a = parseInt(args[0], 10);
    var b = parseInt(args[1], 10);
    var c = parseInt(args[2], 10);
    var cnt = 0;
    for(var i = a; i < c+0.5; i+=a){
         cnt+=b;
    }
    console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main()
{
    int a,b; cin >> a >> b;
    puts(a*b%2==0?"Even":"Odd");
    return 0;
}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
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 dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  string s1,s2,s3;

  cin >> s1 >> s2 >> s3;
  cout << char(s1[0]-32) << char(s2[0]-32) << char(s3[0]-32) << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){



		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		
		int w = sc.nextInt();
		
		boolean[][] cells = new boolean[h+2][w+2];
		for(int i=0;i<w+2;i++) {
			cells[0][i]=false;
			cells[h+1][i]= false;
		}
		for(int i =0;i<h+2;i++) {
			cells[i][0]= false;
			cells[i][w+1] = false;
		}
		for(int i=1;i<h+1;i++) {
			String s = sc.next();
			String[] ss = s.split("");
			for(int j=1;j<w+1;j++) {
				if(ss[j-1].equals(".")) {
					cells[i][j]=true;
				}else {
					cells[i][j]=false;
				}
			}
		}
		
		int highest = 0;
		
		for(int i=1;i<h+1;i++) {
			for(int j=1;j<w+1;j++) {
				if(cells[i][j]) {
					int[][] costs = new int[h+2][w+2];
					for(int l=0;l<h+2;l++) {
						for(int m=0;m<w+2;m++) {
							costs[l][m]=10000;
						}
					}
					costs[i][j]=0;
					boolean checker = true;
					while(checker) {
						checker=false;
						for(int l=1;l<h+1;l++) {
							for(int m=1;m<w+1;m++) {
								if(cells[l][m]) {
									if(cells[l+1][m]) {
										if(costs[l+1][m]>costs[l][m]+1) {
											checker=true;
											costs[l+1][m]=costs[l][m]+1;
										}
									}
									if(cells[l-1][m]) {
										if(costs[l-1][m]>costs[l][m]+1) {
											checker=true;
											costs[l-1][m]=costs[l][m]+1;
										}
									}
									if(cells[l][m+1]) {
										if(costs[l][m+1]>costs[l][m]+1) {
											checker=true;
											costs[l][m+1]=costs[l][m]+1;
										}
									}
									if(cells[l][m-1]) {
										if(costs[l][m-1]>costs[l][m]+1) {
											checker=true;
											costs[l][m-1]=costs[l][m]+1;
										}
									}
								}
							}
						}
					}
					int subhigh = 0;
					for(int l=1;l<h+1;l++) {
						for(int m=0;m<w+1;m++) {
							if(subhigh < costs[l][m]&& costs[l][m]<10000)subhigh=costs[l][m];
						}
					}
					if(subhigh>highest)highest=subhigh;
				}
				
			}
		}
		System.out.println(highest);
	}
	
}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 24620
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int M,T,P,R;
  while(cin >> M >> T >> P >> R){
    if(M == 0 && T == 0 && P == 0 && R == 0)break;

    int m,t,p,r;

    map<pair<int,int>,int>mm;
    pair<pair<int,int>,int>time[51];

    for(int i=0; i<T; i++){
      time[i].second = i;
      time[i].first.first = time[i].first.second = 0;
    }


    for(int i=0; i<R; i++){
      cin >> m >> t >> p >> r;
      t--;
      if(r != 0) mm[make_pair(t,p)]++;
      else {
	time[t].first.second -= (m + 20 * mm[make_pair(t,p)]);
	time[t].first.first++;
      }
    }

    sort(time,time+T);
    reverse(time,time+T);


    map<pair<int,int>,vector<int> >ans;

    for(int i=0; i<T; i++){
      ans[time[i].first].push_back(time[i].second);
    }

    bool flag[51];
    fill(flag,flag+T,false);

    for(int i=0; i<T; i++){
      if(flag[time[i].second])continue;
      vector<int> v = ans[time[i].first];
      for(int j=0; j<v.size(); j++){
	if(flag[v[j]])continue;
	flag[v[j]] = true;
	if(v.size() == 1){
	  if(i == 0) cout << v[j]+1;
	  else cout << ',' << v[j]+1;
	} else {
	  if(i == 0){
	    if(j == 0) cout << v[j]+1;
	    else cout << '=' << v[j]+1;
	  } else {
	    if(j == 0) cout << ',' << v[j]+1;
	    else cout << '=' << v[j]+1;
	  }
	}
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1256
import java.util.Scanner

fun main(args:Array<String>){

    val cin = Scanner(System.`in`)
    var result = Array<Int>(26,{0})

    while(cin.hasNext()){
        var str = cin.nextLine()
	    str = str.toLowerCase()

	    for(i in 0..str.length-1){
	        if(str[i] >= 'a' && str[i] <= 'z'){
	            val x = str[i].toInt() - 'a'.toInt() 
	            result[x] = result[x] + 1
	        }
	    }
    }

    for(i in 'a'..'z'){	
	println("$i : ${result[i.toInt() - 'a'.toInt()]}")
    } 
	
}


Measured memory_bytes: 25556
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

ll mod = 1e9+7;

vector<ll> inv,fact,invfact;
void mod_build(int n){
	fact.resize(n+1);
	inv.resize(n+1);
	invfact.resize(n+1);
	fact[0]=inv[0]=invfact[0] = 1;
	inv[1] = 1;
	for(int i=0;i<n;i++){
		fact[i+1] = fact[i]*(i+1)%mod;
		if(i > 0) inv[i+1] = mod - inv[mod%(i+1)]*(mod/(i+1))%mod;
	}
}

int main(){
	int a,b,t;
	cin >> a >> b>> t;
	int ans = 0;
	int an =a;
	while(an<=t){
		ans += b;
		an+=a;
	}
	cout << ans <<endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n;
    int money;
    int i;
    long long total;
    
    total = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &money);
        total += money;
    }
    
    printf("%d\n", (total / n) % 10000000);

    return (0);
}

Measured memory_bytes: 0
from collections import Counter
S = input()[::-1]
MOD = 2019
X = [0]
for i,s in enumerate(S):
    X.append((X[-1]+int(s)*pow(10,i,MOD))%MOD)
C = Counter(X)
print(sum([v*(v-1)//2 for v in C.values()]))

Measured memory_bytes: 16608
import java.util.Scanner;
import java.math.BigInteger;
import java.lang.Math;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0; i<n; i++){
            a[i] = sc.nextLong();
        }

        for(int k = 0; k<n; k++){
            if(a[k] == 0){
                System.out.println(0);
                return;
            }   
        }

        BigInteger mul = BigInteger.ONE;
        for(int j = 0; j<n; j++){
            mul = mul.multiply(BigInteger.valueOf(a[j]));
            if(mul.compareTo(BigInteger.valueOf(1000000000000000000L)) == 1){
                mul = BigInteger.valueOf(-1);
                j=n;
            }
        }
        System.out.println(mul);
    }
}

Measured memory_bytes: 62176
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,cnt=0,i;
	ll ans=1ll,r=0ll;
	string s;
	cin >> n;
	cin >> s;
	for(i=0; i<n*2; ++i){
		if((s[i]=='W')^(r%2)){
			mul_mod(ans,r);
			--r;
		}else{
			++r;
			++cnt;
		}
		if(cnt>n || r<0 || r>n){
			ans = 0ll;
			break;
		}
	}
	if(r){
		ans = 0ll;
	}
	for(i=1; i<=n; ++i){
		mul_mod(ans,i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int q = std.nextInt();
        String s = std.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for (int i = 0; i < q; i++) {
            l[i] = std.nextInt() - 1;
            r[i] = std.nextInt() - 1;
        }

        String ac = "AC";
        int[] sum = new int[n];
        for (int i = 1; i < s.length(); i++) {
            char current = s.charAt(i);
            char before = s.charAt(i - 1);
            if (before == 'A' && current == 'C') {
                sum[i] = sum[i - 1] + 1;
            } else {
                sum[i] = sum[i - 1];
            }
        }

        for (int i = 0; i < q; i++) {
            int count = sum[r[i]] - sum[l[i]];
            System.out.println(count);
        }
    }
}


Measured memory_bytes: 79600
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

const int N=100005;
const int mod=1000000007;

int n,m;
int fac[N];

int main(){
	int i;
	scanf("%d%d",&n,&m);
	if (n>m) swap(n,m);
	if (m>n+1){
		printf("0\n");
		return 0;
	}
	fac[0]=1; for (i=1;i<=m;i++) fac[i]=1ll*fac[i-1]*i%mod;
	if (n==m){
		printf("%d\n",2ll*fac[n]*fac[n]%mod);
		return 0;
	}
	printf("%d\n",1ll*fac[n]*fac[m]%mod);
	return 0;
} 

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
ll inf = 1000000000 + 7;


vector<pint> ener;

int main() {
	ll N, M;
	ll p, n;
	cin >> N >> M;

	rep(i, N) {
		cin >> p >> n;
		ener.push_back({ p, n });
	}


	sort(ener.begin(), ener.end());
	
	ll ans = (ll)0, pans = (ll)0;
	rep(i, N) {

		if (M - ans - ener[i].second > (ll)0){
			cerr << (M - ans - ener[i].second) << endl;
			ans += ener[i].second;
			pans += ener[i].first * ener[i].second;
		}
		else {
			pans += ener[i].first * (M - ans);
			break;
		}



	}


	cout << pans << endl;
	
	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int L;
  int max = 0;
  int sum = 0;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> L;
    if(max < L)
      max = L;
    sum += L;
  }
  sum -= max;
  if(sum > max)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    x = int(input())

    money = 100
    year = 0
    while money < x:
        money += (money // 100)
        year += 1

    return year


if __name__ == "__main__":
    print(main())


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

int main(void) {
	int n, i, sum = 0; cin >> n;
	int t[n]; for (i = 0; i < n; i++) { cin >> t[i]; }
	int m; cin >> m;
	int p[m], x[m];
	for (i = 0; i < m; i++) { cin >> p[i]; cin >> x[i]; }

	for (i = 0; i < m; i++) {
		int y = t[p[i] - 1];
		t[p[i]-1] = x[i];
		for (int j = 0; j < n; j++) {
			sum += t[j];
		}
		cout << sum << endl;
		t[p[i] - 1] = y;
		sum = 0;
	}
	return 0;
}

Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
class COM{
    vi fact, inv;
    ll N, mod;
public:
    COM(ll n,ll m=MOD):N(n),mod(m){
        fact.resize(N+1);inv.resize(N+1);
    }
    ll power(ll a, ll b){
        ll res=1;
        while(b>0){
            if(b&1) res=res*a%mod;
            a=a*a%mod;
            b>>=1;
        }
        return res;
    }
    void __init__(){
        fact[0]=1;
        REPS(i,N){fact[i]=fact[i-1]*i%mod;}
        inv[N]=power(fact[N],mod-2);
        RREPS(i,N){inv[i-1]=inv[i]*i%mod;}
    }
    ll nCr(ll n,ll r){
        return fact[n]*inv[n-r]%mod*inv[r]%mod;
    }
};
//-----------------------------------------
int main(void){
    ll X,Y;cin>>X>>Y;
    ll d=abs(X-Y);
    ll M,m;
    ll a,b;
    M=max(X,Y);
    m=min(X,Y);
    if((X+Y)%3!=0){
        cout<<0<<"\n";
        return 0;
    }
    if(d<=m){//ok
        M-=d*2;
        m-=d;
        a=d;
        ll add=m/3;
        a+=add;
        b=add;
    }else{//ng
        cout<<0<<"\n";
        return 0;
    }
    COM com(2200000);
    com.__init__();
    cout<<com.nCr(a+b,b)<<"\n";
}

Measured memory_bytes: 37576
#include<bits/stdc++.h>
using namespace std;
#define int long long
int mod;
void add(int &x,int y){
	x=(x+y+mod)%mod;
}
int mul(int x,int y){
	return x*y%mod;
}
int sadd(int x,int y){
	return (x+y)%mod;
}
pair<int,int> a[505];
int f[505][505];
signed main(){
	int n,l,r,cnt=0;
	cin>>n>>mod;
	l=2*n-1; r=2*n-1;
	for(int i=0;i<=2*n-1;++i){
		while(i*i + l*l >= n*n && l>=0) --l;
		while(i*i + r*r > 4*n*n && r>=0) --r;
		if(l==-1) a[++cnt]=make_pair(r+1,0);
		else a[++cnt]=make_pair(l+1,r+1);
	}
	sort(a+1,a+cnt+1);
	int ans=0;
	for(int k=0;k<=n;++k){
		memset(f,0,sizeof(f));f[0][0]=1;
		for(int i=1,F=0,g=0;i<=cnt;F+=(a[i].second!=0),g+=(a[i].second==0),++i)
			for(int j=0;j<=k;++j){
				int now=f[i-1][j];
				if(a[i].second==0) add(f[i][j],mul(now,a[i].first-g-j));
				//g表示前面参与前缀计数的,j表示容斥时参与前缀计数的
				else{
					if(j!=k) add(f[i][j+1],mul(now,a[i].first-g-j));
					add(f[i][j],mul(now,a[i].second-(F-j)-k-n));
				} 
			}
		if(k&1) add(ans,mod-f[cnt][k]);
		else add(ans,f[cnt][k]);
	}
	cout<<ans; 
	return 0;
} 

Measured memory_bytes: 5576
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

long long int LCM(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return (a / dummy1) * (b / dummy1) * dummy1;
}

long long int GCD(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return dummy1;
}

int main(){
	
	int N;
	cin >> N;
	long long int ans = 1;
	for(int i = 0; i < N; i++){
		long long int num;
		cin >> num;
		ans = LCM(ans, num);
	}
	
	cout << ans << endl;
	
	return 0;
}



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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  string S; cin >> S;
  for(auto c : S){
    if(c - '0' == 7){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3596
//author: dxm
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
inline void Fail(){
	printf("Yes");
	exit(0);
}

string s;
int main(){
	cin>>s;
	rep(i,s.size()-1){
		if(s[i]=='A'&&s[i+1]=='C')Fail();
	}
	printf("No");
	return 0;
}

/*
Input:
-----------------
Output:
*/

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

int main(){
  while(1){
    int N;
    cin >> N ;
    if(N==0){
      break;
    }
    int str[11][6]={0};
    for(int i=N-1;i>=0;i--){
      for(int j=0;j<5;j++){
        cin >> str[i][j];
      }
    }
    int score=0;
    for(int i=0;i<10;i++){
//    for(int q=0;q<N;q++){
//     for(int w=0;w<5;w++){
//       cout << str[q][w];
//     }
//     cout << endl;
//    }
//    cout << endl;
      for(int j=0;j<N;j++){
        int a=str[j][0];
        int ch=0;
        for(int k=0;k<=5;k++){
          if(a==str[j][k]&&a!=0){
            ch++;
          }else{
            if(ch>=3){
              for(int l=k-1;l>=k-ch;l--){
                score+=str[j][l];
                str[j][l]=0;
              }
              break;
            }else{
              a=str[j][k];
              ch=1;
            }
          }
        }
      }
      for(int j=0;j<N;j++){
        for(int k=0;k<N;k++){
          for(int l=0;l<5;l++){
            if(str[k][l]==0){
              str[k][l]=str[k+1][l];
              str[k+1][l]=0;
            }
          }
        }
      }
    }
//    for(int q=0;q<N;q++){
//     for(int w=0;w<5;w++){
//       cout << str[q][w];
//     }
//     cout << endl;
//    }
    cout << score << endl;
  }
}


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

int main(){
    int n;
    int now = 1;
    int count = 0;
    int check[100001] = {0};
    int a[100001];
    
    cin >> n;
    
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    
    for (int j = 1; j <= n;j++){
        check[now]++;
        now = a[now];
        count++;
        
        if (now == 2){
            cout << count << endl;
            break;
        }
        if (check[now] == 2){
            cout << -1 << endl;
            break;
        }
            
    }
}
        
        
    
    

Measured memory_bytes: 1024