akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <map>
#include <functional>
#include <cmath>
using namespace std;
#pragma warning(disable: 4996)
string S; vector<int>x[26]; long long ret, bit[200009]; vector<tuple<int, int, int>>V;
void add(int p, int x) { p++; while (p <= 200008) { bit[p] += x; p += (p&-p); } }
int sum(int p) { p++; int s = 0; while (p >= 1) { s += bit[p]; p -= (p&-p); }return s; }
int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		x[S[i] - 'a'].push_back(i);
	}
	int sums = 0;
	for (int i = 0; i < 26; i++) {
		if (x[i].size() % 2 == 1) { sums++; }
	}
	if (sums >= 2) { cout << "-1" << endl; return 0; }
	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < x[i].size() / 2; j++) {
			V.push_back(make_tuple(x[i][j], 1, -1));
			V.push_back(make_tuple(x[i][x[i].size() - 1 - j], 2, x[i][j]));
			ret += abs(x[i][x[i].size() - 1 - j] - x[i][j]);
		}
	}
	sort(V.begin(), V.end()); long long E = 0;
	for (int i = 0; i < V.size(); i++) {
		if (get<1>(V[i]) == 1) { add(get<0>(V[i]), 1); }
		if (get<1>(V[i]) == 2) { add(get<2>(V[i]), -1); ret -= (sum(get<0>(V[i])) - sum(get<2>(V[i]) - 1)); }
	}
	long long maxn = 0;
	for (int i = S.size() - 1; i >= 0; i -= 2)maxn += i;
	cout << maxn - ret << endl;
	return 0;
}

Measured memory_bytes: 7284
//http://www.cplusplus.com/reference/algorithm/next_permutation/
//https://ravesli.com/urok-61-struktury/#toc-0
#include<bits/stdc++.h>
#define FILE
#define ll long long
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define r_0 return 0
#define ld long double
#define TIME ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
    const ll N = 2e5 + 7;
    const ll mod = 1e9 + 7;

int main(){
    TIME
    #ifdef FILEs
        freopen("army.in", "r", stdin);
        freopen("army.out", "w", stdout);
    #endif
    int n , x;
    cin >> n;
    set < int > st;
    for(int i = 1; i <= n ; i ++)
        cin >> x , st.insert(x);
    cout << (st.size() == n ? "YES" : "NO");
}

///...


Measured memory_bytes: 9600
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        System.out.println(
            new BufferedReader(new InputStreamReader(System.in))
                .lines()  // Stream<String> : ???n
                .mapToInt(Integer::parseInt)  // IntStream : ???n
                .mapToObj(n -> Stream.of(IntStream.iterate(n - 1, i -> i - 1), IntStream.iterate(n + 1, i -> i + 1))) // Stream<Stream<IntStream>> : ???n???[[n-1, n-2, ...], [n+1, n+2, ...]]
                .map(ss -> ss.flatMap(s -> s.filter(x -> IntStream.rangeClosed(2, (int)Math.sqrt(x))
                                                                  .allMatch(y -> x % y != 0))  // ?´???°????????£??????????????°
                                            .limit(1)  // ?????????1???
                                            .mapToObj(String::valueOf))  // Stream<Stream<String>> : ???n?????????????´???°2???
                             .collect(Collectors.joining(" ")))  // Stream<String> : ???n?????????
                .collect(Collectors.joining("\n")));  // String : ??¨n?????????
    }
}

Measured memory_bytes: 31120
#include <bits/stdc++.h>
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++)
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
	float x;
	cin >> x;
	if(floor(ceil(x / 1.08) * 1.08)  == x){
		cout << ceil(x / 1.08) << endl;
	} else {
		cout << ":(" << endl;
	}	
 }


Measured memory_bytes: 3748
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define f first
#define s second
#define lint long long
#define mp make_pair
#define pii pair<int, int>
#define pll pair<lint, lint>
#define ld long double
#define inlld(x) scanf("%lld", &x)
#define ind(x) scanf("%d", &x)
#define vi vector<int>

const int N=4e3+5;
const int MOD=998244353;
const lint INF=1e18;

typedef long long ll;

lint _add(lint x, lint y)
{
    lint ret=x+y;
    while(ret<0LL)
        ret+=MOD;
    return ret;
}

lint _mult(lint x, lint y)
{
    x%=MOD;
    y%=MOD;
    lint ret=x*y;
    ret%=MOD;
    while(ret<0LL)
        ret+=MOD;
    return ret;
}

using namespace std;
using namespace __gnu_pbds;

template <typename T> 
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll n, k, choose[N][N], pow_2[N];

int main()
{
    for(lint a=0; a<N; a++)
        for(lint b=0; b<=a; b++)
        {
            if(b==0 || a<=1)
                choose[a][b]=1;
            else
                choose[a][b]=(choose[a-1][b-1]+choose[a-1][b])%MOD;
        }
    pow_2[0]=1;
    for(lint a=1; a<N; a++)
        pow_2[a]=(pow_2[a-1]*2)%MOD;
    inlld(k);
    inlld(n);
    for(ll i=2; i<=2*k; i++)
    {
        if(i%2)
        {
            ll p=0, q=0;
            for(ll a=1; a<=k; a++)
            {
                ll here=i-a;
                if(here>0 && here<=k)
                    p++;
                else
                    q++;
            }
            p/=2;
            ll ans_here=0;
            for(ll j=0; j<=p; j++)
            {
                ll toadd=choose[p][j]*pow_2[j];
                toadd%=MOD;
                toadd*=choose[n+q-1][q+j-1];
                toadd%=MOD;
                ans_here+=toadd;
                ans_here%=MOD;
            }
            printf("%lld\n", ans_here);
        }
        else
        {
            ll p=0, q=0;
            for(ll a=1; a<=k; a++)
            {
                ll here=i-a;
                if(here>0 && here<=k)
                    p++;
                else
                    q++;
            }
            p/=2;
            // p--;
            ll ans_here=0;
            for(ll j=0; j<=p; j++)
            {
                ll toadd=choose[p][j]*pow_2[j];
                toadd%=MOD;
                toadd*=choose[n+q-1][q+j-1];
                toadd%=MOD;
                ans_here+=toadd;
                ans_here%=MOD;
            }
            for(ll j=0; j<=p; j++)
            {
                ll toadd=choose[p][j]*pow_2[j];
                toadd%=MOD;
                toadd*=choose[n+q-1-1][q+j-1];
                toadd%=MOD;
                ans_here+=toadd;
                ans_here%=MOD;
            }
            printf("%lld\n", ans_here);
        }
    }
    return 0;
}


Measured memory_bytes: 123904
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=1e5+100;
int x,k,q,r[N],t,a,ans[N];
vector<pair<pii,int>> query,flip[N];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>x>>k;
	rep(i,0,k) cin>>r[i];
	r[k]=1e9+100;
	cin>>q;
	rep(i,0,q) {
		cin>>t>>a;
		query.pb(mp(mp(t,a),i));
	}
	sort(all(query));
	int cur=0;
	for(auto b:query) {
		while(cur<k&&r[cur]<b.fi.fi) cur++;
		flip[cur].pb(b);
	}
	int lbound=0,rbound=x,lheight=0,rheight=x,inc=0;
	cur=0;
	rep(i,0,k+1) {
		flip[i].pb(mp(mp(r[i],0),-1));
		for(auto b:flip[i]) {
			int dist=b.fi.fi-cur;
			//cout<<b.fi.fi<<' '<<b.fi.se<<' '<<dist<<' '<<inc<<endl;
			if(inc) {
				if(rheight+dist>x) {
					int shift=rheight+dist-x;
					rbound=max(0,rbound-shift);
					rheight=x;
					lheight+=dist;
					lbound=min(lbound,rbound);
					lheight=min(lheight,rheight);
				} else {
					rheight+=dist;
					lheight+=dist;
				}
			} else {
				if(lheight-dist<0) {
					int shift=(lheight-dist)*-1;
					lbound=min(x,lbound+shift);
					lheight=0;
					rheight-=dist;
					rbound=max(rbound,lbound);
					rheight=max(lheight,rheight);
				} else {
					lheight-=dist;
					rheight-=dist;
				}
			}
			cur=b.fi.fi;	
			if(b.se==-1) continue;
			if(b.fi.se>=rbound) {
				ans[b.se]=rheight;
			} else if(b.fi.se<=lbound) {
				ans[b.se]=lheight;
			} else {
				ans[b.se]=lheight+(b.fi.se-lbound);
			}
			//ans b.se
		}
		inc^=1;
	}
	rep(i,0,q) cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 11832
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int a[505][505];
int main() {
  int h,w;
  cin >> h >> w;
  rep(i,h)rep(j,w) cin >> a[i][j];

  vector<tuple<int,int,int,int>> ans;
  rep(i,h)rep(j,w-1){
    if(a[i][j]%2==1) {
      a[i][j]--; a[i][j+1]++;
      ans.emplace_back(i,j,i,j+1);
    }
  }
  int j = w-1;
  rep(i,h-1){
    if(a[i][j]%2==1) {
      a[i][j]--; a[i+1][j]++;
      ans.emplace_back(i,j,i+1,j);
    }
  }
  cout << ans.size() << endl;
  rep(i,ans.size()){
    int a,b,c,d;
    tie(a,b,c,d) = ans[i];
    ++a;++b;++c;++d;
    printf("%d %d %d %d\n",a,b,c,d);
  }
}

Measured memory_bytes: 5232
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func main() {
	sc.Split(bufio.ScanWords)

	N := nextInt()

	fmt.Println(N / 3)
}

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

int main(){
    int n,sum;

    scanf("%d",&n);
    int tmp=n;

    while(tmp>0){
        sum += tmp%10;
        tmp /= 10;
    }
    if(n % sum==0)
        puts("Yes");
    else puts("No");
}


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

template<typename T1,typename T2> inline void cmax(T1 &a,T2 b) {
  if (a < b) a = b;
}

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector V(H + 1, vector(W + 1, 0));
  for (int h, w, v; cin >> h >> w >> v;) V.at(--h).at(--w) = v;
  int64_t z = 0;
  vector DP(H + 1, vector(W + 1, vector(5, z)));
  DP.at(0).at(0).at(1) = V.at(0).at(0);
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      for (int i = 0; i < 4; i++) {
        int64_t now = DP.at(h).at(w).at(i);
        cmax(DP.at(h + 1).at(w).at(0), now);
        cmax(DP.at(h + 1).at(w).at(1), now + V.at(h + 1).at(w));
        cmax(DP.at(h).at(w + 1).at(i), now);
        cmax(DP.at(h).at(w + 1).at(i + 1), now + V.at(h).at(w + 1));
      }
    }
  }
  cout << *max_element(DP.at(H - 1).at(W - 1).begin(), DP.at(H - 1).at(W - 1).begin() + 4) << "\n";
}


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

using namespace std;
const int MAXN=1e5+7;
int n,m,ed=0;
vector<int> G[MAXN];
int td[MAXN],vis[MAXN],from[MAXN];
vector<pair<int,int>> deg;
void dfs(int v)
{
    vis[v]=1;
    bool flg=1;
    for (int i=0;i<G[v].size();i++)
    {
        if (!vis[G[v][i]])
        {
            from[G[v][i]]=v;
            dfs(G[v][i]);
            flg=0;
            break;
        }
    }
    if (flg==1)
    {
        ed=v;
        return ;
    }
}
int main()
{
    int n;
    ios::sync_with_stdio(0);
    cin >> n>>m;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin >> x >>y;
        --x,--y;
        G[x].push_back(y);
        G[y].push_back(x);
        ++td[x];
        ++td[y];
    }
    for (int i=0;i<n;i++)
    {
        if (td[i]!=0)
            deg.push_back(make_pair(td[i],i));
    }
    sort(deg.begin(),deg.end());
    for (int i=0;i<deg.size();i++)
    {
        memset(vis,0,sizeof(vis));
        for (int i=0;i<n;i++)
        {
            from[i]=i;
        }
        ed=deg[i].second;
        dfs(deg[i].second);
        bool ok=1;
        for (int j=0;j<G[deg[i].second].size();j++)
        {
            if (!vis[G[deg[i].second][j]])
            {
                ok=0;
                break;
            }
        }
        if (ok&&ed!=deg[i].second)
        {
            int x=ed;
            vector<int> ans;
            while(from[x]!=x)
            {
                ans.push_back(x);
                x=from[x];
            }
            ans.push_back(x);
            cout <<ans.size()<<endl;
            for (int i=ans.size()-1;i>=0;i--)
            {
                cout << ans[i]+1 << " ";
            }
            cout << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
string s[]={ "","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts" };
int main(){
  int n,m;
  while(cin>>m>>n,m){
    int a[19]={};
    a[0]=1;
    for(int i=0;i<n;i++)
      for(int j=18;j>=0;j--){
        a[j]*=m;
        a[j+1]+=a[j]/10000;
        a[j]=a[j]%10000;
      }
    for(int i=18;i>=0;i--)if(a[i])cout<<a[i]<<s[i];
    cout<<endl;
  }
}

Measured memory_bytes: 3224
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] a = new int [100000];
        int count = 0;
        for (int i = 0 ; i < N ; i++) {
            int a_i = sc.nextInt();
            if (a_i <= 100000) {
                a[a_i - 1]++;
            } else {
                //10000より大きいのは論外なので取り除く対象
                count++;
            }
        }
        //1~Nまでの数字が何個あるかを調べる
        //それぞれについて、少ないときは全部削る。多いときはあまりだけ削る。O(N)
        for (int i = 0 ; i < 100000 ; i++ ) {
            if (a[i] < i + 1) {
                count += a[i];
            } else if (a[i] > i + 1) {
                count += a[i] - (i + 1);
            } else {

            }
        }
        System.out.println(count);

    }

}

Measured memory_bytes: 51372
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<algorithm>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define For(i,x,y) for(int i=((int)x);i<=((int)y);i++)
#define Dep(i,y,x) for(int i=((int)y);i>=((int)x);i--)
#define Rep(i,x) for (int y,i=head[x];i;i=E[i].nxt)
using namespace std;

const int inf=1000000009;

typedef double db;
typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;

int rd() {
	char c=getchar(); int t=0,f=1;
	while (!isdigit(c)) f=(c=='-')?-1:1,c=getchar();
	while (isdigit(c)) t=t*10+c-48,c=getchar(); return t*f;
}
void wt(int x) {
	if (x<0) putchar('-'),wt(-x);
	else { if (x>9) wt(x/10); putchar(x%10+48); }
}

const int N=2e5+35;

int n,K,P[N],Q[N],h,t,L[N],R[N],S[N],cnt,ans,flg;

int main() {
	
	
	n=rd(),K=rd();
	if (K==1) {
		printf("%d\n",1);
		return 0;
	} 
	For (i,1,n) P[i]=rd();
	
	h=1,t=0;
	For (i,1,K-1) {
		while (h<=t && P[i]<P[Q[t]]) t--;
		Q[++t]=i;
	}
	For (i,K,n) {
		while (Q[h]<i-K+1) h++;
		while (h<=t && P[i]<P[Q[t]]) t--;
		Q[++t]=i,L[i-K+1]=Q[h];
	}
	
	h=1,t=0;
	memset(Q,0,sizeof Q);
	Dep (i,n,n-K+2) {
		while (h<=t && P[i]>P[Q[t]]) t--;
		Q[++t]=i;
	}
	Dep (i,n-K+1,1) {
		while (Q[h]>i+K-1) h++;
		while (h<=t && P[i]>P[Q[t]]) t--;
		Q[++t]=i,R[i]=Q[h];
	}
	
	ans=1,cnt=0;
	For (i,1,K-1) if (P[i]<P[i+1]) cnt++; else cnt=0;
	if (cnt==K-1) flg=1;
	
	For (i,1,n-K) {
		if (P[i+K-1]>P[i+K]) cnt=0; else cnt++;
		if (!(L[i]==i && R[i+1]==i+K)) {
			if (!flg || cnt<K-1) ans++;
			if (cnt>=K-1) flg=1;
		}
	}
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3328
n=int(input())
s=input()
d=[[30005,-1] for i in range(10)]
ans=set([])
for i in range(n):
    p=int(s[i])
    if d[p][0]==30005:
        d[p][0]=i
        d[p][1]=i
    else:
        d[p][1]=i

for i in range(1,n-1):
    for j in range(10):
        if d[j][0]<i:
            for k in range(10):
                if d[k][1]>i:
                    ans.add(str(j)+str(s[i])+str(k))

print(len(ans))

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


int main(void)
{
  int m, n;
  cin >> n >> m;
  int am = 0;
  int an = 0;
  if (m > 1)
  {
    am = m*(m - 1)/2;
  }
  if (n > 1)
  {
    an = n*(n - 1)/2;
  }
  cout << an + am << endl;
  
}

Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n = ii()
P = iil()
ans = 0
flag = False
for i in range(n-1):
    if flag:
        flag = False
        continue
    if P[i] == i+1:
        ans += 1
        flag = True
if P[-1] == n and flag == False:
    ans += 1
print(ans)


Measured memory_bytes: 14008
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
long long n;
double d,x,nn,dd,xx,ans;
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
   	n=read();d=read();x=read();
   	nn=2.0*n;
   	while(n--){
		ans=ans+d+(nn-1.0)/2.0*x;
		dd=d+(2.0*d+5.0*x)/nn;
        x=x+4.0*x/nn;
        d=dd;
        nn-=2.0;
	}
	printf("%.10lf\n",ans);
    return 0;
}

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

int main()
{
    ll N,K;
    cin >> N >> K;
    ll A[N];

    for(ll i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    ll ans = 0;
    if((N - 1) % (K - 1) == 0)ans = (N - 1) / (K - 1);
    else ans = (N - 1) / (K - 1) + 1;

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  if(A>=13){
    cout << B << endl;
  }else if(A>=6 || 12<=A){
    cout << B/2 << endl;
  }
  else{
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
int i, j;
int main() {
	int N = 0, tmp = 0, another_length = 0, ans = 0;
	int L[10] = {};
	std::cin >> N;
	for (i = 0; i < N; i++)std::cin >> L[i];
	for (j = 0; j < N - 1; j++)for (i = 0; i < N - 1; i++)if (L[i] < L[i + 1]) {
		tmp = L[i];
		L[i] = L[i + 1];
		L[i + 1] = tmp;
	}
	for (i = 1; i < N; i++)ans += L[i];
	if (L[0] < ans)std::cout << "Yes";
	else std::cout << "No";
	return 0;
}

Measured memory_bytes: 256
/**
 *   created: 01 June 2019  22:10:21
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int n;
		cin>>n;
		vi v(n);
		rep(i,0,n)
			cin>>v[i];
		int gd=v[0];
		rep(i,1,n)
			gd = __gcd(gd,v[i]);
		cout<<gd;
	
	}
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>

typedef long long int ll;

using namespace std;

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

    vector<int> c(h);
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < w; j++) {
            if (s[j] == '#') c[i] |= (1 << (w - j - 1));
        }
    }

    int cnt = 0;
    vector<int> c_, c__;

    for (int i = 0; i < (1 << h); i++) {
        c_ = c;
        for (int x = 0; x < h; x++) {
            if (i & (1 << x)) c_[x] = 0;
        }
        for (int j = 0; j < (1 << w); j++) {
            c__ = c_;
            for (int y = 0; y < w; y++) {
                if (j & (1 << y)) {
                    for (int z = 0; z < h; z++) c__[z] &= ~j;
                }
            }

            int b = 0;
            for (int i_ = 0; i_ < h; i_++) {
                for (int j_ = 0; j_ < w; j_++) {
                    if (c__[i_] & (1<<j_)) b++;
                }
            }
            if (b == k) cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    string s;
  	cin>>s;
  	if(count(s.begin(),s.end(),'A')==0 or count(s.begin(),s.end(),'A')==3)
      cout<<"No"<<endl;
  	else
      cout<<"Yes"<<endl;
    
}


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

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

flag = [0 for _ in range(n)]
wa_num_list = [0 for _ in range(n)]

for i in range(m):
    p, s = list(map(str, input().split()))
    p = int(p)
    if flag[p-1] == 0:
        if s == "WA":
            wa_num_list[p-1] += 1
        else:
            flag[p-1] = 1

pen = 0
for i in range(n):
    if flag[i] == 1:
        pen += wa_num_list[i]

print(sum(flag), pen)


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

int main(){
  string s;
  int N;
  char bot[10][20]={"0",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; 

  int count=0,flag=0;
  while(cin>>N){
    for(int i=0;i<N;i++){
      count=0;
      s.clear();
      cin>>s;
      for(int j=0;j<(int)s.size();j++){
	if(s[j]!='0'&&flag==0){
	  flag=s[j]-'0';
	}else if(flag!=0&&s[j]!='0'){
	  count++;
	}else if(s[j]=='0'&&flag!=0){
	  if(count<0&&count<=strlen(bot[flag]))cout<<bot[flag][count];
	  else{
	    while(count>strlen(bot[flag])-1){
	      count=count-strlen(bot[flag]);
	    }

	    cout<<bot[flag][count];
	  }
	  count=0;
	  flag=0;
	}
      }
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#include <ctype.h>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int digit_sums(int n){
    int sum=0;
    while (n>0){
        sum += n%10;
        n /= 10;
    }
    return sum;
}
int main(){ 
    int N; cin >> N;
    cout << ((N%digit_sums(N)==0)? "Yes":"No") << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
int main()
{
    const ll  INF = 1e9;
    int n,k;
    cin >> n >> k;
    ll h[n];
    for(int i  = 0;i < n;i++)
    {
        cin >> h[i];
    }
    ll dp[n];
    for(int i = 0;i < n;i++)
    {
        dp[i] = INF;
    }
    dp[0] = 0;
    for(int i = 1;i < n;i++)
    {
        for(int j = 1;j <= k;j++)
        {
            if(i - j < 0)
            {
                break;
            }
            dp[i] = min(dp[i],dp[i - j] + (ll)fabs(h[i] - h[i - j]));
        }
    }
    cout << dp[n - 1] << "\n";
    
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int par[200005],sz[200005];
int n,m;
int find(int x) {
	return x==par[x]?x:par[x]=find(par[x]);
}
void merge(int x,int y) {
	x=find(x);y=find(y);
	if (x==y) return;
	if (sz[x]>sz[y]) {
		sz[x]+=sz[y];
		par[y]=x;
	} else {
		sz[y]+=sz[x];
		par[x]=y;
	}
}
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n+n;i++) par[i]=i,sz[i]=1;
	for(int i=1;i<=m;i++) {
		int a,b;
		scanf("%d%d",&a,&b);
		if (find(a)==find(a+n)||find(b)==find(b+n)) {
			printf("%lld\n",1ll*n*(n-1)/2-m);
			return 0;
		}
		merge(a,b+n);
		merge(a+n,b);
	}
	int a=0,b=0;
	for(int i=1;i<=n;i++) {
		if (find(i)==find(1)) a++;
		else b++;
	}
	cerr<<a<<" "<<b<<endl;
	printf("%lld\n",1ll*a*b-m);
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {

	public static void main(String[] args) {
		int i,j;
		String input;
		int count=0;
		Scanner s = new Scanner(System.in);

		int n = s.nextInt();
		for(i=0;i<n;i++){
			input=s.next();
			int k=0;
			for(j=0;j<input.length();j++){
				int ch = input.charAt(j)-'0';


				if(ch==0){
					switch(k){
					case 1:
						if(count%5==1) System.out.print(".");
						else if(count%5==2) System.out.print(",");
						else if(count%5==3) System.out.print("!");
						else if(count%5==4) System.out.print("?");
						else System.out.print(" ");
						break;
					case 2:
						if(count%3==1) System.out.print("a");
						else if(count%3==2) System.out.print("b");
						else System.out.print("c");
						break;
					case 3:
						if(count%3==1) System.out.print("d");
						else if(count%3==2) System.out.print("e");
						else System.out.print("f");
						break;
					case 4:
						if(count%3==1) System.out.print("g");
						else if(count%3==2) System.out.print("h");
						else System.out.print("i");
						break;
					case 5:
						if(count%3==1) System.out.print("j");
						else if(count%3==2) System.out.print("k");
						else System.out.print("l");
						break;
					case 6:
						if(count%3==1) System.out.print("m");
						else if(count%3==2) System.out.print("n");
						else System.out.print("o");
						break;
					case 7:
						if(count%4==1) System.out.print("p");
						else if(count%4==2) System.out.print("q");
						else if(count%4==3) System.out.print("r");
						else System.out.print("s");
						break;
					case 8:
						if(count%3==1) System.out.print("t");
						else if(count%3==2) System.out.print("u");
						else System.out.print("v");
						break;
					case 9:
						if(count%4==1) System.out.print("w");
						else if(count%4==2) System.out.print("x");
						else if(count%4==3) System.out.print("y");
						else System.out.print("z");
						break;
					case 0:
						break;
					}
					count=0;
					k=0;

				}else{
				k=ch;
				count++;
				}
			}
			System.out.println();


		}

	}

}

Measured memory_bytes: 21900
#include <iostream>
#include <queue>
#include <set>
#include <list>
#include <deque>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <iterator>
#define ll long long
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define powr(x,n,p) for(int axy=0 ; axy<p ; axy++){x=x*n;}
#define YES printf("YES\n")
#define Yes printf("Yes\n")
#define yes printf("yes\n")
#define NO printf("NO\n")
#define No printf("No\n")
#define no printf("no\n")
#define nl printf("\n")
#define fr0(n,q) for(q=0 ; q<n ; q++)
#define fr1(n,q) for(q=1 ; q<=n ; q++)
#define mp make_pair
#define scl(x) scanf("%lld",&x)
#define sci(x) scanf("%d",&x)
#define lst(x) x[x.size()-1]
#define llst(x) x[x.size()-2]
#define md 1000000007
#define check(x,y) (x&(1<<y))
#define set(x,y) x=x|(1<<y)
using namespace std;
int n;
int arr[100005][3],dp[100005][3];
int solve(int i, int j){
    if(i>n) return 0;
    if(dp[i][j]!=-1) return dp[i][j];
    int ret;
    if(j==0) ret=max(arr[i][j]+solve(i+1,1),arr[i][j]+solve(i+1,2));
    else if(j==1) ret=max(arr[i][j]+solve(i+1,0),arr[i][j]+solve(i+1,2));
    else ret=max(arr[i][j]+solve(i+1,0),arr[i][j]+solve(i+1,1));
    return dp[i][j]=ret;
}
int main()
{
        sci(n);
        int i,j;
        fr0(100005,i){
            fr0(3,j) dp[i][j]=-1;
        }
        for(i=1 ; i<=n ; i++){
            for(j=0 ; j<3 ; j++) sci(arr[i][j]);
        }
        int ans=max(solve(1,0),solve(1,1));
        ans=max(ans,solve(1,2));
        printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 12252
N=int(input())
M=[[0 for i in range(2**10)] for j in range(N)]
K=[0]*(2**10)
F=[list(map(int,input().split())) for _ in range(N)]
P=[list(map(int,input().split())) for _ in range(N)]

for i in range(2**10):
  for j in range(10):
    for k in range(N):
      if (i>>9-j)&1 and F[k][j]:
        #print(i,j)
        M[k][i]+=1

for i in range(2**10):
  for k in range(N):
    K[i]+=P[k][M[k][i]]
print(max(K[1:]))

Measured memory_bytes: 3956
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int r;
    cin>>r;
    cout<<3*r*r<<endl;
}

Measured memory_bytes: 256
// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{int res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(int* a, int* b){shuffle(a,b,grndm);}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	int a; cin >> a;
	cout << a + a * a + a * a * a << endl;
	return 0;
}

Measured memory_bytes: 3616
#
# AIZU ONLINE JUDGE: Digit Number
# cf. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002&lang=jp
#


import sys
import re


#file = open(sys.argv[1], "r")

for line in sys.stdin:
    ab = map(int, re.split(" +", line))
    answer = reduce((lambda x, y: x + y), ab, 0)
    digits = len(str(answer))
    print digits

Measured memory_bytes: 4312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;


int main(){
    int n;  cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++)  cin >> a.at(i);
    
    vector<ll> sum(n+1, 0);
    map<ll, ll> obj;
    for(int i=0; i<n; i++) sum[i+1] = sum[i]+a[i];
    for(int i=0; i<=n; i++) obj[sum[i]] += 1;
    ll ans=0;
    for(auto x: obj){
        ans += x.second*(x.second-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
#include <stdio.h>
#include <math.h>

int is_prime1(int);
int is_prime2(int);

int prime[168];

int main()
{
	int input, input_cnt, prime_cnt, cnt;
	int output[30];
	
	/*Make prime table*/
	prime[0] = 2;
	prime_cnt = 1;
	for(cnt = 3; cnt < 1000; cnt += 2)
		if(is_prime1(cnt)){
			prime[prime_cnt++] = cnt;
		}
	
	/*Get, calculate input then save in output[]*/
	input_cnt = 0;
	while(scanf("%d", &input) != EOF){
		prime_cnt = 0;
		if(input >= 2)
			prime_cnt++;
		for(cnt = 3; cnt <= input; cnt += 2)
			if(is_prime2(cnt))
				prime_cnt++;
		output[input_cnt] = prime_cnt;
		input_cnt++;
	}
	
	/*print output[]*/
	for(cnt = 0; cnt < input_cnt; cnt++)
		printf("%d\n", output[cnt]);
	
    return 0;
}

/*Test prime directly*/
int is_prime1(int prime1_input)
{
	int prime1_cnt;
	
	if(prime1_input == 1){
		return 0;
	}
	else if(prime1_input == 2 || prime1_input == 3 || prime1_input == 5 || prime1_input == 7){
		return 1;
	}
	else if((prime1_input % 2) == 0){
		return 0;
	}
	
	for(prime1_cnt = 3 ; prime1_cnt <= (sqrt(prime1_input)); prime1_cnt += 2)
		if(prime1_input % prime1_cnt == 0)
			return 0;
	
	return 1;
}

/*Test prime with prime table*/
int is_prime2(int prime2_input)
{
	int prime2_cnt = 0;
	for( ;prime2_cnt <168; prime2_cnt++){
		if(prime[prime2_cnt] > sqrt(prime2_input))
			break;
		if(prime2_input % prime[prime2_cnt] == 0)
			return 0;
	}
	return 1;
}

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

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    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;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  int n;
  cin >> n;
  map<P, P> mp;
  int zero = 0;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) {
      zero++;
      continue;
    }
    ll g = gcd(x, y);
    x /= g;
    y /= g;
    if (y < 0) x = -x, y = -y;
    if (y == 0 && x < 0) x = -x, y = -y;
    bool rot90 = x <= 0;
    if (rot90) {
      swap(x, y);
      y = -y;
    }
    if (rot90)
      mp[P(x, y)].first++;
    else
      mp[P(x, y)].second++;
  }

  mint ans = 1;
  for (auto p : mp) {
    int s = p.second.first;
    int t = p.second.second;
    mint now = 1;
    now += mint(2).pow(s) - 1;
    now += mint(2).pow(t) - 1;
    ans *= now;
  }
  ans -= 1;
  ans += zero;
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 19264
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define endl "\n"
#define mod 1000000007
#define INF 1e18
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define w(x) int x; cin >> x; while (x--)

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void rwf()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int xpowery(int x, int y)
{
	int ans = 1;
	while (y)
	{
		if (y & 1)
			ans = (ans * x) % mod;
		x = (x * x) % mod;
		y = y / 2;
	}
	return ans;
}

int32_t main()
{
	IOS;
	//rwf();

	int n, k;
	cin >> n >> k;

	int h[n], dp[n];

	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
		dp[i] = 1e18;
	}

	dp[0] = 0;

	for (int i = 1; i < n; i++)
	{
		for (int j = i - 1; j >= max(0LL, i - k); j--)
		{
			dp[i] = min(dp[i], abs(h[i] - h[j]) + dp[j]);
		}
	}

	cout << dp[n - 1];

	return 0;
}

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int n, m;
    int a[100000], b[100000], c[100000];
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < m; i++)
        cin >> b[i] >> c[i];

    map<ll, ll> mp;
    for (int i = 0; i < m; i++)
        mp[c[i]] += b[i];

    sort(a, a + n);

    int idx = 0;
    for (auto itr = mp.rbegin(); itr != mp.rend(); itr++)
    // for (auto itr = mp.begin(); itr != mp.end(); itr++)
    {
        // cout << itr->first << endl;
        while (itr->second > 0)
        {
            if (a[idx] < itr->first)
            {
                a[idx] = itr->first;
                idx++;
                itr->second--;
            }
            else
            {
                goto L;
            }
        }
    }

L:
{
}
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += a[i];
    }
    // cout << endl;

    cout << sum << endl;
}

Measured memory_bytes: 8832
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        long ans = 0;
        int i = 0;
        while (i <= n) {
            if (i % 3 != 0 && i % 5 != 0) {
                ans += i;
            }
            i++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35716
#include <bits/stdc++.h>
#define fi first
#define se second
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

int dp[MX];

int main() {
  int n,t;
  scanf("%d%d",&n,&t);
  vp p(n);
  cin>>p;
  sort(rng(p));
  int ans = 0;
  rep(i,n) {
    int a = p[i].fi;
    int b = p[i].se;
    drep(j,t) {
      maxs(ans, dp[j]+b);
      maxs(dp[j+a],dp[j]+b);
    }
  }
  cout<<ans<<endl;
  return 0;
}






















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

int main(){
  int N,K;
  cin >> N>>K;
  
  int ans=0;
  for (int i=0;i<N;i++){
    int x;
    cin >>x;
    if (x<=K-x){
      ans += 2*x;
    }
    else{
      ans += 2*(K-x);
    }
  }
  cout << ans << endl;
}

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

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

    long long length = n.size();

    string q;

    for(int i = 0; i < length-1; i++){
        q += '9';
    }

    long long maxv = 9*(length-1);

    long long  N = stoll(n);
    for(int j = 1; j <= 9; j++){
        string p;
        char m = j + '0';
        p = m + q;
        long long x = stoll(p);

        if(x <= N){
            maxv = max(maxv, 9*(length-1)+j);
        }
    }
    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 256
while s = gets
  n, r = s.split.map(&:to_i)
  break if n.zero?
  yama = [*1..n].reverse
  r.times do
    p, c = gets.split.map(&:to_i)
    cut = yama[p - 1, c]
    yama = cut + (yama - cut)
  end
  p yama[0]
end

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


int main(){
  int N;cin>>N;
  vector<int> L(N);for(int i=0;i<N;i++)cin>>L[i];
  sort(L.begin(),L.end());
  int ans=0;
  int c=2;
  for(int a=0;a<N-2;a++){
    for(int b=a+1;b<N-1;b++){
      c=b+1;
      while(c<N && L[c]<L[a]+L[b]){
        //cout<<L[a]<<","<<L[b]<<","<<L[c]<<endl;
        c++;
      }
      ans+=c-b-1;
    }
  }
  cout<<ans;
}

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

int main() {
  vector<vector<int>> bingo(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      int A;
      cin >> A;
      bingo.at(i).at(j) = A;
    }
  }
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int b;
    cin >> b;
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (bingo.at(j).at(k) == b) {
          bingo.at(j).at(k) = 0;
        }
      }
    }
  }
  bool ok = false;
  for (int i = 0; i < 3; i++) {
    if (bingo.at(i).at(0) == 0 && bingo.at(i).at(1) == 0 && bingo.at(i).at(2) == 0) {
      ok = true;
    }
    if (bingo.at(0).at(i) == 0 && bingo.at(1).at(i) == 0 && bingo.at(2).at(i) == 0) {
      ok = true;
    }
  }
  if (bingo.at(0).at(0) == 0 && bingo.at(1).at(1) == 0 && bingo.at(2).at(2) == 0) {
    ok = true;
  }
  if (bingo.at(0).at(2) == 0 && bingo.at(1).at(1) == 0 && bingo.at(2).at(0) == 0) {
    ok = true;
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
n=int(input())
a1=list(input().strip())
a2=list(input().strip())

p1='0'
p2='1'
for i1,i2 in zip(a1,a2):
  if p1=='0':
    if i1 != i2:
      x=6
    else:
      x=3
  elif i1 != p1 and i2 !=p2 and i1 !=i2 and p1 != p2:
    x*=3
  elif i1 != p1 and i2 !=p2 and i1 !=i2 and p1 == p2:
    x*=2
  elif i1 != p1 and i2 != p2 and i1 ==i2 and p1 == p2:
    x*=2
  p1=i1
  p2=i2
  
print(x%(10**9+7))

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    string S, T;
    cin >> S >> T;
    ll N = S.size();
    ll M = T.size();
    vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 0));
    rep(i, N) {
        rep(j, M) {
            if (S[i] == T[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }
    string ans = "";
    ll i = N - 1;
    ll j = M - 1;
    while ((i >= 0 && j >= 0)) {
        if (S[i] == T[j]) {
            ans += S[i];
            i--;
            j--;
        } else {
            if (i > 0 && j > 0) {
                if (dp[i + 1][j] > dp[i][j + 1]) {
                    j--;
                } else {
                    i--;
                }
            } else {
                if (i == 0) {
                    j--;
                } else {
                    i--;
                }
            }
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 73632
#include <bits/stdc++.h>
// #define vec(v) vector<int>(v)
// #define be(v) (v).begin(), (v).end()
// #define pb(q) push_back(q)
// #define mapci(mp) map<char*,int>(mp)
// #define mapcc(mp) map<char*,char*>(mp)
typedef long long ll;
using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    cout<<n-k+1<<endl;
    return 0;
}

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

typedef long long ll;

template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}

#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)

const int N=2e5+5,D=1e9+7;
int mi(ll x,int y=D-2)
{
	ll ans=1;
	while(y)
	{
		if(y&1)ans=ans*x%D;
		x=x*x%D;y>>=1;
	}
	return ans;
}
const int mi_2=mi(2);
ll qa[N],*tot=qa,*dp[N];
int fa[N],deep[N],mx[N];
vector<int>lk[N];
bool mx_da(int x,int y)
{
	return mx[x]>mx[y];
}

int main()
{
	int n;
	cin>>n;
	rep(i,1,n){scanf("%d",fa+i);lk[fa[i]].push_back(i);}
	rep(i,1,n)deep[i]=deep[fa[i]]+1;
	rep(i,0,n)mx[i]=1;
	per(i,n,1)chmax(mx[fa[i]],mx[i]+1);
	rep(x,0,n)sort(lk[x].begin(),lk[x].end(),mx_da);
	rep(x,0,n)
	if(x==0||x!=lk[fa[x]].front())
	{
		for(int y=x;;y=lk[y].front())
		{
			dp[y]=tot++;
			if(lk[y].empty())break;
		}
	}
	per(x,n,0)
	{
		dp[x][0]=mi_2;
		int last=0,i=lk[x].size();
		while(--i>0)
		{
			while(last<mx[lk[x][i]])
			{
				++last;
				ll pre=1-dp[x][last];
				for(int j=i;j;--j)
				{
					ll p=dp[lk[x][j]][last-1];
					dp[x][last]=(dp[x][last]*(1-p)+pre*p)%D;
					pre=(pre*(1-p))%D;
				}
			}
		}
	}
	
	ll ans=0;
	rep(i,0,mx[0]-1)ans+=dp[0][i];
	cout<<(ans%D*mi(2,n+1)%D+D)%D<<endl;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
  if (b == 0){
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int main(){
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  for (int i = 0; i < N; i++){
    cin >> x[i];
    x[i] = abs(x[i] - X);
  }
  int ans = x[0];
  for (int i = 1; i < N; i++){
    ans = gcd(ans, x[i]);
  }
  cout << ans;
}

Measured memory_bytes: 640