akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=1e9+1000;
ll infi=1e18+100;

int N,M,X;
int A[200];
 
int main(){
	cin>>N>>M>>X;
	rep(i,M) cin>>A[i];
	int k;
	rep(i,M){
		if(A[i]>X){
			k = i-1;
			break;
		}
	}
	if(k<M-k){
		cout<<k<<endl;
	}
	else cout<<M-k<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
//#include<cmath>
//#include<array>
#include<algorithm>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
//#include<map>
//#include<list>
//#include<bitset>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

LLI gcd(LLI x, LLI y) {
	LLI  r;
	if (x < y) {
		swap(x, y);
	}
	r = x % y;
	while (r != 0) {
		x = y;
		y = r;
		r = x % y;
	}
	return y;
}
LLI lcm(LLI x, LLI y) {
	return x / gcd(x, y) * y;
}

long nCr(int n,int r) {
	long ans = 1;
	for (int i = n; i > n - r;i--) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1;i++) {
		ans = ans / i;
	}
	return ans;
}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	LLI A, B,C;
	cin >> A >> B;
	C = A - B + 1;
		cout<< C <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N,M;cin>>N>>M;
	int s[N],t[M];
	rep(i,0,N) cin>>s[i];
	rep(i,0,M) cin>>t[i];
	long dp[N+1][M+1] = {};
	rep(i,1,N+1)rep(j,1,M+1){
		if(s[i-1] == t[j-1]) dp[i][j] = (dp[i-1][j] + dp[i][j-1] + 1) % mod;
        else dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + mod) % mod;
	}cout<<(dp[N][M] + 1) % mod<<endl;//pprint(dp,,N+1,M+1);
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define foin for (int i = 0; i < n; i++)
#define fojn for (int j = 0; j < n; j++)
#define vi vector<int>
#define vil vector<ll>
#define omii map<int,int>
#define omlii map<ll,ll>
#define umii unordered_map<int,int>
#define umlii unordered_map<ll,ll>
#define pi pair<int,int>
#define pli pair<ll,ll>
#define MAX (ll)1e18
using namespace std;


void solve() {
	ll a;
	long double b;
	cin >> a >> b;
	ll c;
  	c= a * b;
	cout <<(ll)c;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio;


	solve();


}

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

using namespace std;

const int NMAX = 110;
const double eps = 1e-6, pi = acos(-1), g = 9.8;

int N, V, X, Y;
int X1[NMAX], X2[NMAX], Y1[NMAX], Y2[NMAX];
double v0x, v0y, rAngle, birdTime;

int getSign(double value) {
	if (value < -eps)
		return -1;
	if (value > eps)
		return 1;
	return 0;
}

bool trajectoryIntersect() {
	for (int i = 1; i <= N; ++i) {
		for (int j = X1[i]; j <= X2[i]; ++j) {
			double time = j / v0x;
			if (getSign(time - birdTime) > 0)
				break;
			double y = v0y * time - 0.5 * g * time * time;
			if (getSign(y - Y1[i]) >= 0 && getSign(y - Y2[i]) <= 0)
				return true;
		}
	}
	return false;
}

bool projectileIntersect(double y) {
	for (int i = 1; i <= N; ++i) {
		if (getSign(X - X1[i]) >= 0 && getSign(X - X2[i]) <= 0 && getSign(y - Y1[i]) >= 0 && getSign(y - Y2[i]) <= 0)
			return true;
	}
	return false;
}

int main() {
//	assert(freopen("debug.in", "r", stdin));
//	assert(freopen("debug.out", "w", stdout));

	int i, j;

	cin >> N >> V >> X >> Y;
	for (i = 1; i <= N; ++i)
		cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];

	rAngle = -pi / 100000;
	while (rAngle + pi / 100000 <= pi / 2) {
		rAngle += pi / 100000;
		v0x = V * cos(rAngle);
		v0y = V * sin(rAngle);
		birdTime = X / v0x;
		double birdY = v0y * birdTime - 0.5 * g * birdTime * birdTime;
		if (getSign(Y - birdY) > 0)
			continue;
		if (trajectoryIntersect())
			continue;
		if (projectileIntersect(birdY))
			continue;
		cout << "Yes\n";
		return 0;
	}

	cout << "No\n";

	return 0;
}



Measured memory_bytes: 3480
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, m = inintm()

city = [0]*(n+1)

for _ in range(m):
    a, b = inintm()
    city[a] += 1
    city[b] += 1

for c in range(1,n+1):
    print(city[c])


Measured memory_bytes: 62124
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int A[20];

int main() {
	int N;
	cin >> N;
	vector<vector<pair<int, int>>> v(N);
	for(int i=0; i<N; ++i){
		cin >> A[i];
		for(int j=0; j<A[i]; ++j){
			int x, y;
			cin >> x >> y;
			v[i].push_back(make_pair(x-1, y));
		}
	}
	int ans=0;
	for(int i=0; i<(1<<N); ++i){
		bool flag=1;
		int cnt=0;
		for(int j=0; j<N; ++j){
			if(i&(1<<j)){
				++cnt;
				for(int k=0; k<A[j]; ++k){
					if((i&(1<<(v[j][k].first)))>0 ^ (v[j][k].second>0)){
						flag=0;
						break;
					}
				}
				if(!flag) break;
			}
		}
		if(flag) ans=max(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
  vector<string> dr = {"dream", "erase"};
  string S;
  int start_n = 0;
  bool flag;
  int S_len;

  cin >> S;
  S_len = S.size();
  while (5 <= S_len - start_n)
  {
    if (!S.compare(start_n, 5, dr[0]))
    {
      start_n += 5;
      if (S_len - start_n < 2)
        continue;
      if (!S.compare(start_n, 2, "er"))
      {
        if (5 <= S_len - start_n)
        {
          if (!S.compare(start_n, 5, dr[1]))
            continue;
        }
        start_n += 2;
      }
    }
    else if (!S.compare(start_n, 5, dr[1]))
    {
      start_n += 5;
      if (S_len - start_n < 1)
        continue;
      if (!S.compare(start_n, 1, "r"))
        start_n += 1;
    }
    else
    {
      cout << "NO" <<endl;
      return (0);
    }
  }
  if (S_len == start_n)
    cout << "YES" <<endl;
  else
    cout << "NO" <<endl;
}

Measured memory_bytes: 512
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    g = [f() for i in range(3)]

    for i in range(2):
        if g[i][0] - g[i+1][0] != g[i][1] - g[i+1][1] or g[i][1] - g[i+1][1] != g[i][2] - g[i+1][2]:
            print('No')
            return
    
    for i in range(2):
        if g[0][i] - g[0][i+1] != g[1][i] - g[1][i+1] or g[2][i] - g[2][i+1] != g[1][i] - g[1][i+1]:
            print('No')
            return

    print('Yes')

solve()


Measured memory_bytes: 3064
//package atcoder;

import java.io.*;
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }

        int start = 0;
        int ans = 0;
        while(true) {
            start = 0;
            int count = 0;
            while(count < n && arr[start] == 0) {
                start++;
                count++;
            }

            if(count == n) {
                break;
            }

            int i = start;
            int min = Integer.MAX_VALUE;
            while(i < n && arr[i] != 0) {

                min = Math.min(arr[i], min);
                i++;
            }

            int j = start;
            while(j < i) {
                arr[j] -= min;
                j++;
            }
            ans += min;
        }
        System.out.println(ans);
    }
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, w;
  cin >> n >> w;
  vector<vector<long long>> dp(2, vector<long long>(w + 1));
  for (int wt = 0; wt <= w; wt++) {
    dp[0][wt] = 0;
  }
  int crr = 0;
  int nxt = 1;
  for (int i = 0; i < n; i++) {
    int a;
    long long b;
    cin >> a >> b;
    dp[nxt] = dp[crr];
    for (int wt = a; wt <= w; wt++) {
      dp[nxt][wt] = max(dp[nxt][wt], dp[crr][wt - a] + b);
    }
    swap(crr, nxt);
  }
  long long maxv = 0;
  for (int wt = 0; wt <= w; wt++) {
    maxv = max(maxv, dp[crr][wt]);
  }
  cout << maxv << '\n';
  return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<cstring>
char a[10010];
bool c,f;
int main() {
    scanf("%s", a);
    for(int i=0; i<strlen(a); i++) 
	{
        if(a[i]=='C') c=true;
        if(a[i]=='F'&&c==true) f=true;
    }
    if(f)
	printf("Yes\n");
    else 
	printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  unordered_map<string,int> umap;
  int n;
  cin>>n;
  for(int i=0; i<n; i++) {
    string s;
    cin>>s;
    umap[s]++;
  }
  cout<<umap.size();
}

Measured memory_bytes: 17720
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
using namespace std;

int main(int argc, char* argv[]){
	int A, B;

	cin >> A >> B;
	int s = A*B - A - B + 1;
	printf("%d\n", s);
	return 0;

}

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

using namespace std;

#define PB push_back
#define rep(i,x) for(int i=0;i<(int)(x);++i)

int N, A, B, C;
vector<string> op;
vector<char> ans;

signed main()
{
    cin >> N >> A >> B >> C;
    rep(i, N) {
        string s; cin >> s;
        op.emplace_back(s);
    }

    bool f = false;

    if (op[0] == "AB" and (A > 0 or B > 0)) f = true;
    if (op[0] == "AC" and (A > 0 or C > 0)) f = true;
    if (op[0] == "BC" and (B > 0 or C > 0)) f = true;

    if (!f) {
        puts("No");
        return 0;
    }

    rep(i, N) {
        if (op[i] == "AB") {
            if (A == 0 and B == 0) {
                puts("No");
                return 0;
            }

            if (A * B == 1) {
                if (i + 1 < N) {
                    if (op[i + 1] == "BC") {
                        B++, ans.PB('B');
                        A--;
                    } else {
                        A++, ans.PB('A');
                        B--;
                    }
                }

                continue;
            }

            if (A >= B) {
                B++, ans.PB('B');
                A--;
            } else {
                A++, ans.PB('A');
                B--;
            }
        }
        if (op[i] == "AC") {
            if (A == 0 and C == 0) {
                puts("No");
                return 0;
            }

            if (A * C == 1) {
                if (i + 1 < N) {
                    if (op[i + 1] == "BC") {
                        C++, ans.PB('C');
                        A--;
                    } else {
                        A++, ans.PB('A');
                        C--;
                    }

                    continue;
                }
            }

            if (A >= C) {
                C++, ans.PB('C');
                A--;
            } else {
                A++, ans.PB('A');
                C--;
            }
        }
        if (op[i] == "BC") {
            if (B == 0 and C == 0) {
                puts("No");
                return 0;
            }

            if (B * C == 1) {
                if (i + 1 < N) {
                    if (op[i + 1] == "AB") {
                        B++, ans.PB('B');
                        C--;
                    } else {
                        C++, ans.PB('C');
                        B--;
                    }
                }

                continue;
            }

            if (B >= C) {
                C++, ans.PB('C');
                B--;
            } else {
                B++, ans.PB('B');
                C--;
            }
        }
    }

    puts("Yes");
    rep(i, N) printf("%c\n", ans[i]);
}


Measured memory_bytes: 7452
#include <iostream>                                             
#include <vector>                                               
using namespace std;                                            
                                                                
int main (void) {                                               
  int N;                                                        
  cin >> N;                                                     
  int x;                                                        
  vector<int> A;                                                
  for (int i=0; i<N; i++) {                                     
    cin >> x;                                                   
    A.push_back(x);                                             
  }                                                             
  int flag=1, tmp;                                              
  int ans=0;                                                    
  while (flag) {                                                
    flag=0;                                                     
    for (int j=A.size()-1; j>=1; j--) {                         
      if (A[j] < A[j-1]) {                                      
        tmp = A[j-1];                                           
        A[j-1] = A[j];                                          
        A[j] = tmp;                                             
        ans++;                                                  
        flag=1;                                                 
      }                                                         
    }                                                           
  }                                                             
  for (int i=0; i<A.size(); i++) {                              
    cout << (i==0?"":" ") << A[i] << flush;                     
  }                                                             
  cout << endl << ans << endl;                                  
}                                                               
                                                                
                                        

Measured memory_bytes: 3140
#include<stdio.h>

double x[9],y[9];

int main(){
	while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x[1],&y[1],&x[2],&y[2],&x[3],&y[3],&x[4],&y[4])!=EOF){
		if(x[1]>x[4])printf("NO\n");
		else if(x[3]>x[2])printf("NO\n");
		else if(y[1]>y[4])printf("NO\n");
		else if(y[3]>y[2])printf("NO\n");
		else printf("YES\n");
	}
	return 0;
}

Measured memory_bytes: 0
# Code for B - Bounding
# Use input() to fetch data from STDIN
[n, x] = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]

count = 1
d = 0
for k in l:
    if d + k <= x:
        count += 1
        d += k
    else:
        break


print(count)


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main(){
    int n,x;
    cin>>n>>x;
    int d[n]={0};
    int l[n]={0};
    int count=0;
    bool f=true;
    for(int i=1;i<=n;i++){
        cin>>l[i];
        d[i]=d[i-1]+l[i];
        count++;
        if(d[i]>x){
            f=false;
            cout<<count<<endl;
            break;
        }
    }
    if(f){
        if(d[n]<=x)cout<<n+1<<endl;
        else cout<<1<<endl;
    }
    return 0;
}

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

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

int N;
ll X[1001],Y[1001],P[1001];
ll M;
ll V[40];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>X[i]>>Y[i];
		P[i]=(abs(X[i])+abs(Y[i]))%2;
		if(P[i]!=P[0]) return _P("-1\n");
	}
	
	M=32;
	FOR(i,32) {
		V[i]=1LL<<(31-i);
	}
	if(P[0]==0) V[M++]=1;
	
	cout<<M<<endl;
	FOR(i,M) {
		cout<<V[i]<<" ";
	}
	cout<<endl;
	
	FOR(i,N) {
		string S;
		FOR(j,M) {
			if(abs(X[i])>=abs(Y[i])) {
				if(X[i]>=0) {
					S+='R';
					X[i]-=V[j];
				}
				else {
					S+='L';
					X[i]+=V[j];
				}
			}
			else {
				if(Y[i]>=0) {
					S+='U';
					Y[i]-=V[j];
				}
				else {
					S+='D';
					Y[i]+=V[j];
				}
			}
		}
		cout<<S<<endl;
	}
	
	
	
}


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


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#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 mem( f, x ) memset( f, x, sizeof( f ) )
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define e 2.71828
using namespace std;
const int N = 505;
const int M = 1e6+5;
const int MAX = 5;
const ll inv = 500000004;
const double g = 9.80;
const double PI = acos( -1.0 );
int a[N][N];

struct node{
    pii x, y;
    node( ){ x = y = make_pair( 0, 0 ); }
    node( pii xx, pii yy ){
        x = xx, y = yy;
    }
    void Pri( ){
        printf( "%d %d %d %d\n", x.fi, x.se, y.fi, y.se );
    }
}p[N*N];

int main(){
    ll n;
    while( scanf("%lld", &n) != EOF ){
           printf("%lld\n", (n/2)*((n+1)/2) );
     }
    return 0;
}


Measured memory_bytes: 4352
# coding:utf-8

import math
import re

def main(params):
    a,b = params[0].split()
    a = int(a)
    b = int(b)
    if a <= 5:
        print 0
    elif a >= 6 and a <= 12:
        print b / 2
    else:
        print b
#    a = params[1].split()
#    b = list(params[2])

if __name__ == "__main__":
    cnt = 1 # TODO: edit here
    params = []
    for i in range(cnt):
        param = raw_input()
        params.append(param)
    main(params)



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

int main(){
    int n,k;
    cin>>n>>k;
    vector <ld> v;

    ld sum = 0;
    for(int i=0; i<n; i++){
        ld a;
        cin>>a;
        v.push_back(a);

        ld ans = (a+1)*1.00/2.00;
        if(i<k) sum+=ans;
    }

    ld fans = sum;
	for (int i=k; i<n; i++) {
		sum -= (v[i-k]+1)*1.00/2.00;
		sum += (v[i]+1)*1.00/2.00;

		fans = max(fans, sum);
	}
    cout<<fixed<<setprecision(10)<<fans<<endl;

    return 0;
}


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

int main(){
	int n, m, q;
	cin >> n >> m >> q;
	int a[n + 1][m + 1]{}, b[n + 1][m + 1]{}, c[n + 1][m + 1]{};
	for(int i = 1; i < n + 1; i++){
		string s;
		cin >> s;
		for(int j = 1; j < m + 1; j++){
			a[i][j] = s[j - 1] - '0';
			b[i][j] = a[i][j] & a[i][j - 1];
			c[i][j] = a[i][j] & a[i - 1][j];
		}
	}
	for(int i = 1; i < n + 1; i++){
		for(int j = 1; j < m + 1; j++){
			a[i][j] += a[i][j - 1];
			b[i][j] += b[i][j - 1];
			c[i][j] += c[i][j - 1];
		}
		for(int j = 1; j <= m; j++){
			a[i][j] += a[i - 1][j];
			b[i][j] += b[i - 1][j];
			c[i][j] += c[i - 1][j];
		}
	}
	while(q--){
		int x, y, xx, yy;
		cin >> x >> y >> xx >> yy;
		int t = a[xx][yy] - a[x - 1][yy] - a[xx][y - 1] + a[x - 1][y - 1], u = b[xx][yy] + b[x - 1][y] - b[x - 1][yy] - b[xx][y], v = c[xx][yy] + c[x][y - 1] - c[xx][y - 1] - c[x][yy];
		cout << t - u - v << endl;
	}
}

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

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

typedef long long ll;
 
using namespace std;

template <typename T> T gcd(T a, T b) {
    if (b == 0)
        return a;

    return gcd(b, a % b);
}

template <typename T> T lcm(T a, T b) {
    return (a * b) / gcd(a, b);
}

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

    int a[n];
    rep(0, n) cin >> a[i];

    int diff, max_diff = 0;
    rep(1, n) {
        diff = abs(a[i]-a[i-1]);
        max_diff = max(max_diff, diff);
    }
    diff = abs(k - a[n-1] + a[0]);
    max_diff = max(max_diff, diff);

    cout << (k - max_diff) << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 1024
n,m=map(int,input().split())
s=[]
dp=[]
mod=10**9+7
for _ in range(n):
    s.append(input())
    dp.append([0]*m)

for i in range(n):
    for j in range(m):
        if i==0 and j==0:
            dp[i][j]=1 
        else:
            if s[i][j]=='#':
                dp[i][j]=0
            else:
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod
print(dp[n-1][m-1])

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

int main() {
  int N;
  int x = 0;
  string S;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> S;
    if (S == "Y") {
    x = 1;
    }
    else {
    }
  }
  if (x == 1) {
      cout << "Four" <<endl;
  }
  else {
    cout << "Three" <<endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  N%=10;
  if(N==3)Out("bon");
  else if(N<2||(N>5&&N%2==0))Out("pon");
  else Out("hon");
} 

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    int a, b;
    cin >> a >> b;
    if (a+b == 15) cout << "+" << endl;
    else if (a*b == 15) cout << "*" << endl;
    else cout << "x" << endl;
    return 0;
}


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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  for (int i = 1; i < 10; i ++) {
    for (int j = 1; j < 10; j ++) {
      if (n == i * j) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
function Main(input){
    input = input.split("\n");
    var n = input[0];
    var a = input[1].split(" ");
    var ans = 0;
    var flag = true;
    while(flag){
        for(var i = 0; i < n; ++i){
            if(a[i]%2 == 0){
                a[i] /= 2;
            }else{
                flag = false;
                break;
            }
        }
        if(!flag) break;
        ans++;
    }
    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main(){
	REP(i, 3) {
		string a;
		cin >> a;
		cout << a[i];
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A + B) < (C + D)){
    cout << "Right" << endl;
  } else if ((A+B) > (C+D)) {
    cout << "Left" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}

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

const double EPS= 1e-12;

struct zahyo{
	double x;
	double y;
};


int main(){
	zahyo a , b , c , d , ab , cd;
	int n;
	std::cin >> n;
	for(int i=0 ; i<n ; ++i){
		std::cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> d.x >> d.y;
		ab.x=b.x-a.x;
		ab.y=b.y-a.y;
		cd.x=d.x-c.x;
		cd.y=d.y-c.y;
		if (abs(ab.x*cd.y-ab.y*cd.x)<EPS){ //gaiseki
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}			
	}
	return 0;
}

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

int main() {
  int N, M;
  while(cin >> N >> M && (N || M)) {
    int bt = M;
    int bl = 1001;
    int a;
    typedef pair<pair<int, int>, int> P;
    vector<P> v;
    for(int i = 0; i < N; ++i) {
      cin >> a;
      int s = bt+(int)(bl > a);
      P p = make_pair(make_pair(min((M / a) * a,(s/a+(int)(s%a!=0))*a), a), i+1);
      v.push_back(p);
      bt = p.first.first; bl = p.first.second;
    }
    sort(v.begin(), v.end());
    if(v[0].first == v[1].first) cout << N << endl;
    else                         cout << v[0].second << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(void){

	long long a[200000];
	int c, d;
	long long k;
	int n, m;
	int s, t;
	long long x, y, z;

	scanf("%d", &n);
	x = 0;
	y = 0;
	k = 2000000001;
	for (int i = 0; i < n; i++){
		scanf("%lld", &a[i]);
		y = y + a[i];
	}
	for (int i = 0; i < n-1; i++){
		x = x + a[i];
		y = y - a[i];
		z = y - x;
		if (z < 0)z = -z;
		if (z < k)k = z;
	}

	printf("%lld\n", k);

	return 0;
}


Measured memory_bytes: 1664
function main(input) {
  const inArray = input.trim().split(' ').map(x => parseInt(x));
  console.log( inArray[0] >= 13 ? inArray[1] : inArray[0] >= 6 ? inArray[1] / 2 : 0);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
<?php
$a=explode(" ",trim(fgets(STDIN)));
$x=$a[0]+$a[1];
$y=$a[0]+$a[2];
$z=$a[1]+$a[2];
if($x<$y){
	if($x<$z){
      echo $x;
    }else{
      echo $z;
    }
} else{
 if($y<$z){
   echo $y;
 }else{
   echo $z;
 }
 }
     

Measured memory_bytes: 4728
N = int(input())
A = [ int(v) for v in input().split(" ") ]

c_max = 0
total = 0

for i in range(N):
  if i == 0:
    c_max = A[0]
  elif A[i] < c_max:
    total += c_max - A[i]
  else:
    c_max = A[i]

print(total)

Measured memory_bytes: 32196
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
ll powMod(ll x, ll k, ll m) {//x^k (mod n)
	if (k == 0)     return 1;
	if (k % 2 == 0) return powMod(x*x % m, k/2, m);
	else            return x*powMod(x, k-1, m) % m;
}
int N;

int main(){
	cin>>N;
	bool ans=true;
	if(N<100)ans=false;
	if(N<2100){
		int x=N/100;
		if(N>x*105)ans=false;

	}
	if(ans)cout<<1<<endl;
	else cout<<0<<endl;
}





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

void display(const std::vector<std::vector<int>>& vec);

int main(void) {
    u_int a, b, n;
    const int NOT_ASSIGNED = -1;

    std::cin >> a >> b;
    for (; a != 0 && b != 0; std::cin >> a >> b) {
        /*
         * 初期化
         */
        std::vector<std::vector<int>> matrix(a);
        for (int x = 0; x < a; ++x) {
            if (x == 0) {
                // x = 0 上はそれぞれ1通り
                matrix[x].resize(b, 1);
            } else {
                matrix[x].resize(b, NOT_ASSIGNED);
            }
            matrix[x][0] = 1;  // y = 0 上はそれぞれ1通り
        }
        // 原点
        matrix[0][0] = 0;

        /*
         * 行き止まりを反映する
         */
        std::cin >> n;
        for (u_int i = 0, x, y; i < n; ++i) {
            std::cin >> x >> y;
            matrix[--x][--y] = 0;  // 行き止まり

            // x = 0 上に行き止まりがあるとき、y 以降は通ることができない
            if (x == 0) {
                auto it = matrix[0].begin();
                for (std::advance(it, y + 1); it != matrix[0].end(); ++it) {
                    *it = 0;
                }
            }
            // y = 0 上に行き止まりがあるとき、x 以降は通ることができない
            if (y == 0) {
                for (int j = x + 1; j < a; ++j) {
                    matrix[j][0] = 0;
                }
            }
        }

        /*
         * 経路の計算
         */
        for (int x = 1; x < a; ++x) {
            for (int y = 1; y < b; ++y) {
                if (matrix[x][y] == NOT_ASSIGNED) {
                    matrix[x][y] = matrix[x][y-1] + matrix[x-1][y];
                }
            }
        }

        std::cout << matrix[a-1][b-1] << std::endl;
    }

    return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;


int main(){
    int N, K; cin >> N >> K;
    vector<ll> x(N);
    for(int i=0; i<N; i++){
        cin >> x[i];
    }
    ll res=LINF;
    for(int i=0; K+i-1<N; i++){
        ll l=x[i], r=x[K+i-1];
        if(r < 0) res=min(res, -l);
        else if(l > 0) res=min(res, r);
        else{
            res=min(res, min(2*r-l, 2*(-l)+r));
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4052
#!/usr/bin/env python3
import sys
from collections import Counter

def main():
    N = int(input())
    S = input()
    L = Counter(S)
    p = 10**9 + 7
    ans = 1
    for l in L.items():
        ans =  ans * (l[1] + 1) % p
    print((ans - 1) % p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
ary = gets.chomp.chars.map(&:to_i)

c = 0
ary.each_with_index do |v, k|
  if k != 0
    if v == ary[k-1]
      ary[k] = v == 0 ? 1 : 0
      c += 1
    end
  end
end
puts c

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

int main()
{
  int total = 0,  n = 0, k = 0, x = 0, y = 0;
  int last = 0;
  
  cin >> n >> k >> x >> y;
  if(n<=k)
  {
  	total=(n*x);
  }
  if(n>k)
  {
    last = n-k;
  	total += (k*x) + y*last;
  }
  cout << total;
}

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

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(ll)(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) reps(i,0,((n)+1))
#define repst(i,s,n) reps(i,s,((n)+1))
#define reprt(i,n,t) for(ll (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// 立方体の上面と底面のパネルと前者の向きを全探索
// この2つが決まれば8頂点全ての色が確定するから残りは数え上げればいい
// c[i]の順列のうち辞書順最小のものをハッシュ値として保存しておけば側面のパネルとして採用できる枚数がわかる

int n, c[400][4], t[4], ans;
map<int,int> m;

int id(int a, int b, int c, int d) {return (a<<30)+(b<<20)+(c<<10)+d;}

void pl(int i, int x) {
	int a = i>>30, b = (i>>20)&1023, c = (i>>10)&1023, d = i&1023;
	m[id(a,b,c,d)] += x;
	m[id(d,a,b,c)] += x;
	m[id(c,d,a,b)] += x;
	m[id(b,c,d,a)] += x;
}

signed main() {
	cin >> n;
	rep(i,n) {
		rep(j,4) cin >> c[i][j];
		pl(id(c[i][0],c[i][1],c[i][2],c[i][3]), 1);
	}
	rep(i,n-5) {
		pl(id(c[i][0],c[i][1],c[i][2],c[i][3]), -1);
		reps(j,i+1,n) rep(d,4) {
			// 一つの立方体を作るときに同じパネルを採用しないように一旦使用済みにしてから元に戻す
			pl(id(c[j][0],c[j][1],c[j][2],c[j][3]), -1);
			t[0] = id(c[i][0],c[j][(0+d)%4],c[j][(3+d)%4],c[i][1]);
			t[1] = id(c[i][1],c[j][(3+d)%4],c[j][(2+d)%4],c[i][2]);
			t[2] = id(c[i][2],c[j][(2+d)%4],c[j][(1+d)%4],c[i][3]);
			t[3] = id(c[i][3],c[j][(1+d)%4],c[j][(0+d)%4],c[i][0]);
			if (m[t[0]]&&m[t[1]]&&m[t[2]]&&m[t[3]]) {
				int tmp = 1;
				// ここも同様
				rep(l,4) tmp *= m[t[l]], pl(t[l],-1);
				ans += tmp;
				rep(l,4) pl(t[l],1);
			}
			pl(id(c[j][0],c[j][1],c[j][2],c[j][3]), 1);
		}
	}
	cout << ans << ln;
}

Measured memory_bytes: 20352
n = int(input())
s = input()
ls = []
for i in range(n):
    ls.append(s[i])
l = 0
r = n - 1
su = 0
while l < r:
    while ls[l] == 'R':
        l += 1
        if l >= n:
            break
    while ls[r] == 'W':
        r -= 1
        if r < 0:
            break
    if l >= r:
        break
    else:
        su += 1
        l += 1
        r -= 1
print(su)

Measured memory_bytes: 87344
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }


typedef long long ll;
using P = pair<ll, ll>;		//P.first, P.second
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

struct UnionFind{
    vector<int> Parent;
    vector<int> sizes;
    UnionFind(int n):Parent(n),sizes(n,1){ rep(i,n)Parent[i]=i; }
    //find the root of x
    int root(int x){
        if(x!=Parent[x]){
        Parent[x] = root(Parent[x]);
        }
        return Parent[x];
    }
    //merge x and y
    void unite(int x,int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(x>y) swap(x, y);
        Parent[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(int x,int y){ return root(x) == root(y); }
    int size(int x){ return sizes[root(x)]; }
};


ll a,b;
int main() {
	ll N,M;
	cin>>N>>M;
	vector<P> ba;
	rep(i,N){
		cin>>a>>b;
		ba.push_back({b,-a});
	}
	sort(all(ba),greater<P>());
	printpair(ba);
	UnionFind uni(M);
	vector<ll> ansv(M);
	rep(i,N){
		a = -ba[i].second;
		b = ba[i].first;
		cerr<<a<<" "<<b<<endl;
		cerr<<M-a<<endl;
		if(M-a<0){
			continue;
		}
		ll umeru = uni.root(M-a);
		if(ansv[umeru]==0){

			ansv[umeru] = b;

			if(umeru-1>=0){
				uni.unite(umeru,umeru-1);
			}

		}
	}

	ll ans = 0;
	print(ansv);
	rep(i,M){
		ans+=ansv[i];
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3440
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int a,b; cin>>a>>b;
    if(a==1) a=14;
    if(b==1) b=14;
    if(a>b) cout<<"Alice"<<endl;
    else if(a==b) cout<<"Draw"<<endl;
    else cout<<"Bob"<<endl;
}

Measured memory_bytes: 256
/* code by AbhiTaker  */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define M 1000000007
#define N 1000016
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define inf 9000000000000000000
pair< pair<ll,ll> , ll> p[N] ;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n,i,j;
    cin>>n;

    for(i=1; i<n; i++)
    {
        cin>>p[i].ff>>p[i].fs>>p[i].s;
    }

    for(i=1; i<n; i++)
    {
            ll t = p[i].ff + p[i].fs ;

        for(j=i+1;j<n;j++)
        {
            ll x = p[j].fs;
            while(x < t)
                x += p[j].s;

            t = x;
            t += p[j].ff;
        }

        cout<<t<<"\n";


    }

    cout<<"0\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))


struct Graph {
  vector<vector<int>> edge;
  Graph(int n = 0) { resize(n); }
  void resize(int n) {
    edge.resize(n, vector<int>());
  }
  void addEdge(int from, int to, bool directed = false) {
    edge[from].push_back(to);
    if (!directed)
      edge[to].push_back(from);
  }
  vector<int>& operator[](int from) { return edge[from]; }
};
Graph G;

int main() {
  int in(N); ll in(K);

  G.resize(N);
  rep(i, N) {
    int in(a);
    --a;
    G.addEdge(i, a, true);
  }

  queue<int> q;
  q.push(0);
  int count = 0;

  vi cost(N, -1);
  vi dist;
  while (!q.empty()) {
    int p = q.front(); q.pop();
    if (count == K) {
      cout << p+1 << endl;
      return 0;
    }
    if (cost[p] != -1) {
      int cycle = count-cost[p];
      int ans = *(dist.end() - cycle + ((K - cost[p]) % cycle));
      cout << ans + 1 << endl;
      break;
    }
    dist.push_back(p);
    cost[p] = count;
    ++count;
    q.push(G[p][0]);
  }

  return 0;
}



Measured memory_bytes: 16044
<?php

fscanf(STDIN, "%s", $s);
$array = [];
for($i=0;$i<4;$i++){
    @$array[$s[$i]]++;
}
foreach($array as $value){
    if($value == 2){
        continue;
    }else{
        echo "No";
        exit;
    }
}

echo "Yes";

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    int ans=0;
    int b=0;
    rep(i,n){
        cin>>a[i];
        if(a[i]%2==0){
            b++;
            if(a[i]%3==0||a[i]%5==0){
                ans++;
            }
        }
    }
    if(b==ans)cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
N = int(input())
A = input().split(" ")

def bubble_sort(A):
  N = len(A)
  for i in range(N):
    for j in range(N - 1, i, -1):
      if int(A[j][1]) < int(A[j - 1][1]):
        A[j - 1], A[j] = A[j], A[j - 1]
  return A

def selection_sort(A):
  N = len(A)
  for i in range(N):
    mini = i
    for j in range(i + 1, N):
      if int(A[j][1]) < int(A[mini][1]):
        mini = j
    if mini != i:
      A[mini], A[i] = A[i], A[mini]
  return A

def is_stable(A, B):
  map_a = {}
  map_b = {}
  for i in range(len(A)):
    s_a = A[i][0]
    s_b = B[i][0]
    v_a = A[i][1]
    v_b = B[i][1]
    if v_a in map_a:
      map_a[v_a].append(s_a)
    else:
      map_a[v_a] = [s_a]
    if v_b in map_b:
      map_b[v_b].append(s_b)
    else:
      map_b[v_b] = [s_b]

  result = True
  for k in map_a:
    if len(map_a[k]) > 1:
      result = result and (map_a[k] == map_b[k])

  return result

A_sorted = bubble_sort(A[:])
print(" ".join(A_sorted))
print("Stable") if is_stable(A, A_sorted) else print("Not stable")

A_sorted = selection_sort(A[:])
print(" ".join(A_sorted))
print("Stable") if is_stable(A, A_sorted) else print("Not stable")

Measured memory_bytes: 7820
#include <stdio.h>
int main()
{
    int n,c,a,b;
    scanf("%d%d%d",&n,&a,&b);
    if(1<=n&&n<=20&&1<=a&&a<=100&&1<=b&&b<=2000)
    {
        c=n*a;
        if(c<b)
            printf("%d",c);
        else
            printf("%d",b);
    }
    return 0;
}


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

int main()
{
	int N, x;
	cin >> N >> x;
	if (x == 1 || x == 2 * N - 1) {
		cout << "No" << endl;
		return 0;
	}
	int l = 0, r = 2 * N - 1, lb = 1, ub = 2 * N;
	vector<int> res(2 * N - 1);
	while (r - l > 1) {
		if (x < (lb + ub) / 2) {
			res[l++] = --ub;
			res[--r] = --ub;
		}
		else if (x > (lb + ub) / 2) {
			res[l++] = lb++;
			res[--r] = lb++;
		}
		else {
			res[l++] = lb++;
			res[--r] = --ub;
		}
	}
	res[l] = lb;
	cout << "Yes" << endl;
	for (int i = 0; i < 2 * N - 1; i++) {
		cout << res[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 2304
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

//struct edge { int to, cap, rev; };

const int MAX_V = 202;

int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
}

bool dfs(int v) {
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        int u = G[v][i], w = match[u];
        if (w < 0 || !used[w] && dfs(w)) {
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int bipartite_matching() {
    int res = 0;
    memset(match, -1, sizeof(match));
    for(int v = 0; v < V; v++) {
        if (match[v] < 0) {
            memset(used, 0, sizeof(used));
            if (dfs(v)) {
                res++;
                // dump(v);
            }
        }
    }
    return res;
}


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> V;
    int n = V;
    V *= 2;
    int x1[n], y1[n];
    int x2[n], y2[n];
    rep(i, n) cin >> x1[i] >> y1[i];
    rep(i, n) cin >> x2[i] >> y2[i];
    // cout << endl;
    rep(i, n) {
        rep(j, n) {
            if(x1[i] < x2[j] && y1[i] < y2[j]) {
                add_edge(i, j + n);
                // cout << i << " " << j + n << endl;
            }
        }
    }
    //cout << endl;
    cout << bipartite_matching() << endl;


    return 0;
}


Measured memory_bytes: 256