akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define dro first
#define adg second.first
#define mog second.second
#define ll long long
using namespace std;

const int N = 500001;

int n,r,pos,l,x,U,D,S;
 
long long ans;

int fix[100],fix1[100],A[100],B[100];

vector<int>gr[100];

int edge[100][100];

int dest;
bool ok;

void dfs(int x){
    //cout<<x<<endl;
    if(x == dest){
        ok = true;
        return;
    }
    
    fix1[x] = 1;
    
    for(int to=0;to<=50;to++){
        
        if(!edge[x][to])continue;
        
        if(!fix1[to])
        dfs(to);
    }
    
    //fix1[x] = 0;
}


bool check(){
    
    for(int i=1;i<=n;i++){
        
        dest = B[i];
        ok = false;
        
        //cout<<A[i]<<endl;
        
        dfs(A[i]);
        
        for(int j=0;j<=50;j++)
        fix1[j] = 0;
        
        if(!ok)return false;
        
    }
    return true;
}

int main(){
    
    cin>>n;
    
    for(int i=1;i<=n;i++)
    cin>>A[i];
    
    for(int j=1;j<=n;j++){
        cin>>B[j];
        if(B[j]>A[j]){
            cout<<-1<<endl;
            return 0;
        }
    }
    
    for(int j=1;j<=50;j++)
    fix[j] = 1;
    
    for(int i=50;i>=1;i--){
        
        fix[i] = 0;
        for(int j=1;j<=50;j++)
        if(fix[j] == 1){
            for(int v = 1; v <= 50; v++)
            edge[v][v%j] = 1;
        }
        
        if(!check()){
            if(i==50){
                cout<<-1<<endl;
                return 0;
            }
            fix[i] = 1;//cout<<i<<endl;
            ans += (1LL<<i);
        }
        
        for(int j=1;j<=50;j++)
        for(int t=0;t<=50;t++)
        edge[j][t] = 0;
    }
    
    //if(ans == 524285) ans = -1;
    
    cout<<ans<<endl;
}





Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int i,j;
  int h,w,u=0;
  cin>>h>>w;
  vector<vector<char>> c(h,vector<char>(w));
  vector<vector<int>> s(h,vector<int>(w));
  for(i=0;i<h;++i)
    for(j=0;j<w;++j){
      cin>>c.at(i).at(j);
      if(c.at(i).at(j)=='.')s.at(i).at(j)=0;
      else if(c.at(i).at(j)=='#')s.at(i).at(j)=-9;
    }
  for(i=0;i<h;++i){
    for(j=0;j<w;++j){
      if(s.at(i).at(j)<0){
        if(i!=0){
          if(j!=0)s.at(i-1).at(j-1)+=1;
          s.at(i-1).at(j)+=1;
          if(j!=w-1)s.at(i-1).at(j+1)+=1;
        }if(i!=h-1){
          if(j!=0)s.at(i+1).at(j-1)+=1;
          s.at(i+1).at(j)+=1;
          if(j!=w-1)s.at(i+1).at(j+1)+=1;
        }if(j!=0)s.at(i).at(j-1)+=1;
        if(j!=w-1)s.at(i).at(j+1)+=1;
      }
    }
  }
  for(i=0;i<h;++i){
    for(j=0;j<w;++j){
      if(s.at(i).at(j)>=0)cout<<s.at(i).at(j);
      else if(s.at(i).at(j)<0)cout<<'#';
    }
    if(i<h-1)cout<<endl;
  }
}

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

#define V_MAX 1000
#define E_MAX 2000
#define INF 1000000000

typedef struct Edge{
    int v1;
    int v2;
    int w;
}Edge;

Edge Es[E_MAX];
int A[V_MAX];

void init(void){
    for(int i = 0; i < V_MAX; i++){
        A[i] = INF;
    }
}


int main(void){
    init();

    int V, E, r;
    scanf("%d %d %d", &V, &E, &r);

    for(int i = 0; i < E; i++){
        scanf("%d %d %d", &Es[i].v1, &Es[i].v2, &Es[i].w);
    }

    A[r] = 0;

    bool is_updated;
    for(int i = 0; i < V; i++){
        is_updated = false;
        for(int j = 0; j < E; j++){
            if(A[Es[j].v2] > A[Es[j].v1] + Es[j].w && A[Es[j].v1] != INF){
                A[Es[j].v2] = A[Es[j].v1] + Es[j].w;
                is_updated = true;
            }
        }
    }

    if(is_updated){
        printf("NEGATIVE CYCLE\n");
        return 0;
    }

    for(int i = 0; i < V; i++){
        if(A[i] == INF){
            printf("INF\n");
        }else{
            printf("%d\n", A[i]);
        }
    }

}



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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

vector<vector<pair<int, ll>>> g;
vector<ll> dist;

void dfs(int node, ll d){
  dist[node] = d;
  REP(i, g[node].size()){
    int nx;
    ll nxd;
    tie(nx, nxd) = g[node][i];
    if(dist[nx] != -1) continue;
    dfs(nx, d+ nxd);
  }
}

int main(){
  int N;
  cin >> N;
  g.resize(N);
  dist.resize(N,-1);
  REP(i, N-1){
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  
  int Q, K;
  cin >> Q >> K;
  K--;
  dfs(K, 0);
  REP(i, Q){
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << dist[x] + dist[y] << endl;
  }
  return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,p;
    string s,ss,sss;
    vector<string>v;
    cin>>s;
    set<char>st;
    a=s.size();
    char c;
    for(ll i=0;i<a;i++)
    {
        c=s[i];
        st.insert(c);
    }
    b=st.size();
    if(a==b) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll N,l,ans;
	cin >> N;
	vector<ll> v(N);
	cin >> ans;
	for (ll i = 1;i < N;i++){
		cin >> l;
		ans = __gcd(l,ans);
		
	}
	cout << ans << endl;

	// sort(ALL(v));
	// ll ans = 1000000000000000;
	// for (ll i = 0;i < N - 1;i++){
	// 	if (i >= 1){
	// 		ans = min(ans % v[i] ,v[i]);
	// 	}
	// 	if (v[i+1] % v[i]  != 0){
	// 		v[i+1] = v[i+1] % v[i];
	// 	}

	// }
	// ans = min(ans % v[N-1],v[N-1]);
	// cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
# C - Average Length

N = int(input())
arr = []
for i in range(N):
    tmp = list(map(int, input().split()))
    arr.append(tmp)

####

import math
import statistics
import itertools

table = [[0]*N for i in range(N)]
for i in range(N):
    ti = arr[i]
    for j in range(N):
        tj = arr[j]
        dist = math.sqrt((ti[0] - tj[0])**2 + (ti[1] - tj[1])**2)
        table[i][j] = dist

kumi_all = list(itertools.permutations(range(N)))
kumi_all_count = len(kumi_all)

total_dist = 0

for i in range(kumi_all_count):
    this_dist = 0
    this_kumi = kumi_all[i]

    for j in range(N-1):
        this_dist += table[this_kumi[j]][this_kumi[j+1]]

    total_dist += this_dist

avr_dist = total_dist / kumi_all_count

print(avr_dist)


Measured memory_bytes: 10092
x1, y1, x2, y2 = map(int, input().split())

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x3 - (y3 - y2)
y4 = y3 + (x3 - x2)

print(x3, y3, x4, y4)

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


int main()
{
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif


	int n;
	cin >> n;

	string s;
	cin >> s;

	string t;
	cin >> t;

	for(int i = 0; i < n; i++)
		cout << s[i]<< t[i];
	cout << endl;
	return 0;
}

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

using namespace std;

int main()
{
    int N,C,K;
    cin >> N >> C >> K ;
    vector<int> T(N);
    for(int i=0; i<N; i++){
        cin >> T.at(i);
    }

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

    int bus_cnt = 0;
    for(int i=0; i<N;){

        int start = T.at(i);
        int time = start;
        int cnt = 1;
        //cout << "bus:" << bus_cnt << " num:" << i << endl;
        i++;
        while(i<N && T.at(i) <= start+K && cnt<C){
           //     cout << "bus:" << bus_cnt << " num:" << i << endl;
                cnt++;
                i++;
        }
        bus_cnt++;
    }

    cout << bus_cnt << endl;
}

Measured memory_bytes: 3744
#include<cstdio>

const int N_MAX = 2000, M_MAX = 2000, A = 1e9 + 7;
int n, m;
int s[N_MAX], t[M_MAX];
int su[N_MAX][M_MAX];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf("%d", &s[i]);
    }
    for (int i = 0; i < m; i++) {
        scanf("%d", &t[i]);
    }
    
    su[0][0] = static_cast<int>(s[0] == t[0]);
    for (int i = 1; i < n; i++) {
        su[i][0] = su[i - 1][0] + static_cast<int>(s[i] == t[0]);
    }
    for (int i = 1; i < m; i++) {
        su[0][i] = su[0][i - 1] + static_cast<int>(s[0] == t[i]);
    }
    for (int i = 1; i < n; i++) {
        for (int j = 1; j < m; j++) {
            int a = (s[i] == t[j]) ? (su[i - 1][j - 1] + 1) : 0;
            long b = static_cast<long>(su[i - 1][j]) + su[i][j - 1] - su[i - 1][j - 1] + a;
            su[i][j] = (b >= 0) ? b % A : b % A + A;
        }
    }
    
    int ans = (su[n - 1][m - 1] + 1) % A;
    printf("%d\n", ans);
    return 0;
}           


Measured memory_bytes: 15872
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

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


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    int N, K;
    cin >> N >> K;
    set<int> even, odd;
    for (int i = 1; i <= N; ++i)
    {
        if (((i * 2) % K) == 0)
        {
            if (i % K == 0)
            {
                even.insert(i);
            }
            else
            {
                odd.insert(i);
            }
        }
    }
    cout << (LL)even.size() * even.size() * even.size() + (LL)odd.size() * odd.size() * odd.size() << endl;
    return 0;
}


Measured memory_bytes: 9600
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a<b)   cout << "a < b" << endl;
  if(b<a)   cout << "a > b" << endl;
  if(b==a)   cout << "a == b" << endl;
  return 0;
}


Measured memory_bytes: 3056
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <functional>
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        vector<vector<int>> a(2, vector<int> (n));
        for (int i = 0; i < 2; i ++) {
                for (int j = 0; j < n; j ++) {
                        scanf("%d", &a[i][j]);
                }
        }
        vector<int> l(n), r(n);
        l[0] = a[0][0];
        for (int i = 1; i < n; i ++) {
                l[i] = l[i - 1] + a[0][i];
        }
        r[n - 1] = a[1][n - 1];
        for (int i = n - 2; i >= 0; i --) {
                r[i] = r[i + 1] + a[1][i];
        }
        int ans = 0;
        for (int i = 0; i < n; i ++) {
                ans = max(ans, l[i] + r[i]);
        }
        printf("%d\n", ans);
        return 0;
}



Measured memory_bytes: 256
#define debug 0
#define test 0
#define CPLUS 1
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#if CPLUS
#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
#include <queue>
#include <map>
#include <unordered_map>
#include <functional>
#include <iomanip>
using namespace std;
#endif

typedef struct {
	int i;
	int t;
}PER;

PER p[1005];

int cmp(const void* a, const void *b)
{
	PER *m = (PER*)a;
	PER *n = (PER*)b;
	if (m->t == n->t)
		return m->i > n->i;
	return m->t > n->t;
}

int main(void)
{
#if debug
	freopen("in.txt", "r", stdin);
#endif
	int n;
	scanf("%d", &n);
	map<int, int> ma;
	int ans = 0;
	int t;
	for (int i = 0; i < n; i++) {
		scanf("%d", &t);
		if (ma.count(t) == 0) ma[t] = 1;
		else ma[t]++;
	}
	for (auto i = ma.begin(); i != ma.end(); i++) {
		if (i->second % 2 == 1)
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>

using namespace std;
int main() {
	int N,a,min = 0,max = 0;
	vector<int> color(9,0);
	cin >> N;
	
	for (int i = 0; i < N;i++) {
		cin >> a;
		if (a < 400) {
			color[0]++;
		}
		else if(a < 800){
			color[1]++;
		}
		else if (a < 1200) {
			color[2]++;
		}
		else if(a < 1600){
			color[3]++;
		}
		else if (a < 2000) {
			color[4]++;
		}
		else if (a < 2400) {
			color[5]++;
		}
		else if (a < 2800) {
			color[6]++;
		}
		else if (a < 3200) {
			color[7]++;
		}
		else {
			color[8]++;
		}
	}
	for (int i = 0; i < 8;i++) {
		if (color[i] > 0) {
			min++;
		}
	}
	max = min + color[8];
	if (min == 0) {
		min++;
	}
	cout << min << " " << max << endl;
	return 0;
}



Measured memory_bytes: 256
use List::Util 'min';

($n ,$a, $b) = split(/ /, <STDIN>);

if($a == 0){
	print "0\n";
	exit;
}
if($n <= $a){
	print "$n\n";
	exit;
}

printf ($a * int($n / ($a + $b)) + min($n % ($a + $b), $a)) . "\n";


Measured memory_bytes: 640
#include <stdio.h>
int main(){
	int N;
	scanf("%d",&N);
	int A[N];
	int K=0,i;
	int B[N-1];
	for(i=0;i<N-1;i++){
		scanf("%d",&B[i]);
	}
	for(i=0;i<N;i++){
		if(i==0){
			A[0]=B[0];
		}else if(i==(N-1)){
			A[N-1]=B[N-2];
		}else{
			if(B[i]<B[i-1]){
				A[i]=B[i];
			}else{
				A[i]=B[i-1];
			}
		}
	}
	for(i=0;i<N;i++){
		K=K+A[i];
	}
		printf("%d ",K);
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    int k;
    int[] as;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        as = new int[3];
        as[0] = sc.nextInt();
        as[1] = sc.nextInt();
        as[2] = sc.nextInt();
        k = sc.nextInt();
        solve();
    }

    void solve() {
        Arrays.sort(as);
        while (k > 0) {
            as[2] *= 2;
            k--;
        }
        System.out.println(as[0] + as[1] + as[2]);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21204
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    static int find(int curr, String s){
        int cans = 0;
        for(int i = 0; i < s.length(); i++){
            int to = s.charAt(i) - '0';
            if(to != curr) cans++;
            curr ^= 1;
        }
        return cans;
    }

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = Math.min(find(0, s), find(1, s));
        System.out.print(ans);
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}

int main(){
	int N,M,C; cin>>N>>M>>C;
  printf("%d",min(M/N,C));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const double pi=acos(-1);


int main(){
  int A,B,Q;
  cin >> A >> B >> Q;
  vector<ll>s(A+2);
  vector<ll>t(B+2);
  rep(i,A) cin >> s[i+1];
  rep(i,B) cin >> t[i+1];
  s[0]=-1e18;
  t[0]=-1e18;
  s[A+1]=1e18;
  t[B+1]=1e18;
  rep(i,Q){
    ll x;
    cin >> x;
    ll b = lower_bound(s.begin(),s.end(),x)-s.begin();
    ll d = lower_bound(t.begin(),t.end(),x)-t.begin();
    ll a = b-1;
    ll c = d-1;
    
    ll ans=1e18;
    
    ll saki;
    ll ato;
    rep(i,2){
      if(i==0) saki = s[a];
      else saki = s[b];
      rep(j,2){
        if(j==0) ato = t[c];
        else ato = t[d];
        if(ans>abs(x-saki)+abs(saki-ato))ans=abs(x-saki)+abs(saki-ato);
      }
    }
    rep(i,2){
      if(i==0) saki = t[c];
      else saki = t[d];
      rep(j,2){
        if(j==0) ato = s[a];
        else ato = s[b];
        if(ans>abs(x-saki)+abs(saki-ato))ans=abs(x-saki)+abs(saki-ato);
      }
    }
    
    cout << ans << endl;
  }
  return 0;

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

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

	ll n, k, pos = 0;
	cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0 ; i < n ; i++) {
		cin >> a[i];
		a[i]--;
	}

	map<ll, ll> voyage;
	while (voyage[pos] < 1 && k > 0) {
		voyage[pos] = k;
		pos = a[pos];
		k--;
	}
	if (voyage[pos] > 0)
		k %= voyage[pos] - k;
	while (k > 0) {
		pos = a[pos];
		k--;
	}
	cout << pos + 1 << "\n";

	return 0;
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Graph;
const int M = 1e9 + 7;
const ll INF = 1e9;
const int MAX_V = 100000 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<P> query(q);
    rep(i, q) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        query[i] = make_pair(a, b);
    }
    vector<int> cusum(n, 0);
    repeat(i, 1, n) {
        if (s[i - 1] == 'A' && s[i] == 'C') {
            cusum[i] = cusum[i - 1] + 1;
        } else {
            cusum[i] = cusum[i - 1];
        }
    }
    rep(i, q) {
        int ans = cusum[query[i].second] - cusum[query[i].first];
        cout << ans << endl;
    }
}


Measured memory_bytes: 2176
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<llint>&ar,llint in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<llint>&ar,llint in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n;cin>>n;
	llint sai=big,ans=0;
	while(n--){
		llint a,b;cin>>a>>b;
		ans+=a;
		if(a>b){mineq(sai,b);}
	}
	cout<<max(0LL,ans-sai)<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

signed main(void)
{
	int k, s;
	cin >> k >> s;
	int ans = 0;
	REP(i, k+1) {
		REP(j, k+1) {
			int t = s-i-j;
			//cout << t << " ";
			if(0 <= t && t <= k) ans++;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long n;
    cin>>n;
    long ctr=0;
    long grv=0;
    for(int i=0;i<n;i++)
    {
        long x;
        cin>>x;
        if(x%2==0)
        {
        if(x%3==0||x%5==0)
        {
            ctr++;
        }
        grv++;
        }
    }
    if(ctr==grv)
    {
        cout<<"APPROVED"<<endl;
    }
    else
    {
        cout<<"DENIED"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  ll ans = 0;
  map<int, vector<int>> mp;
  for(int i = 0; i < N; i++){
    int a, b; cin >> a >> b;
    mp[a].push_back(b);
  }

  priority_queue<int> pq;
  for(int i = 1; i <= M; i++){
    if(mp[i].size() != 0){
      for(int j : mp[i]) pq.push(j);
    }
    if(!pq.empty()){
      ans += pq.top();
      pq.pop();
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 10880
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=1e5;
string s;
int x;
int main(){
	cin>>s>>x;
	int n=s.length();
	for (int i=0;i<n;i+=x)
	cout<<s[i]; 
	return 0;
} 

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

namespace dp
{
    class Program
    {
        static long[] ReadNumList()
        {
            var line = Console.ReadLine().Split(' ');
            var numList = new long[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = long.Parse(line[i]);
            }
            return numList;
        }
        static void Main(string[] args)
        {
            var nw = Console.ReadLine().Split(' ');
            var n = int.Parse(nw[0]);
            var w = int.Parse(nw[1]);
            var iTable = new long[n][];
            var rTable = new long[n + 1][];
            for (var i = 0; i < n; ++i)
            {
                iTable[i] = ReadNumList();
                rTable[i] = new long[w + 1];
            }
            rTable[n] = new long[w + 1];

            for (var wi = 0; wi <= w; ++wi)
            {
                for (var i = 1; i <= n; ++i)
                {
                    var iWeight = iTable[i - 1][0];
                    var iValue = iTable[i - 1][1];
                    rTable[i][wi] = rTable[i - 1][wi];
                    if (iWeight <= wi)
                    {
                        rTable[i][wi] = Math.Max(rTable[i - 1][wi], rTable[i - 1][wi - iWeight] + iValue);
                    }
                }
            }
            Console.WriteLine(rTable[n][w]);
        }
    }
}


Measured memory_bytes: 106152
#include<bits/stdc++.h>
#define ll long long 
#define pa pair<ll,ll>
using namespace std;
const ll mod = 1e9+7;
int n;
ll c[1000004];
ll rev[1000004];
map<ll , ll>mert[10004];
ll fp(ll x , ll y){
	if(y == 0) return 1;
	if(y & 1) return (x * fp(x , y-1)) % mod;
	ll temp = fp(x , y>>1);
	return (temp * temp) %mod;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		ll x;scanf("%lld",&x);
		mert[i].clear();
		for(ll j=2;j<=sqrt(x);j++){
			while(x % j == 0){
				mert[i][j] ++;
				x /= j;
			}
		}
		if(x > 1) mert[i][x] ++;
		//cout << i << endl;
		for(auto j : mert[i]){
			pa u = j;
			//cout << u.first <<" "<< u.second<<endl; 
			c[u.first] = max(c[u.first] , u.second);
		}
	}
	ll bac = 1;
	for(int i=1;i<=(int)1e6;i++){
		bac *= fp( i , c[i]);
		bac %= mod;
		if(c[i] != 0){
			rev[i] = fp(i , mod-2);
		//	cout<<"-- | " << i <<" "<< c[i] <<endl;
		}
 	}
 	//cout << bac<<endl;
 	ll ans=0;
	for(int i=1;i<=n;i++){
		ll now = bac;
		for(auto j : mert[i]){
			pa u = j;
			ll a = u.first , b = u.second;
			now *= fp(rev[a] , b);
			now %= mod;
		}
		ans += now;
		ans %= mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    cin >> A;
    sort(A.rbegin(), A.rend());
    ll ans = 0;
    priority_queue<ll> temp;
    temp.push(A[1]);
    temp.push(A[1]);
    ans += A[0];
    for (int i = 2; i < N; i++) {
        ans += temp.top();
        temp.pop();
        temp.push(A[i]);
        temp.push(A[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6928
# coding=utf-8

###
### for atcorder program
###

import sys
import math
import array

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def main():
    N, L = [int(x) for x in input().split()]
    
    azi = [(L+i) for i in range(N)]
    risou = sum(azi)

    sabun = 1145141919
    ans = 0

    for i in range(N):
        pi = sum(azi) - azi[i]
        
        a = (risou - pi)**2 

        if a < sabun:
            sabun = a
            ans = pi

    print(ans)


if __name__ == '__main__':
    main()

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

using namespace std;

void rwFile() {
    freopen("INP.inp", "r", stdin);
    freopen("OUT.out", "w", stdout);
}

void solveA_MezoPlayingZoma() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int l = 0, r = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'L') l++;
        else r++;
    }
    cout << l + r + 1;
}

void solveB_JustEatIt() {
    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        long long arr[n];
        long long pre[n], suf[n];
        pre[0] = 0;
        suf[0] = 0;
        for (int i = 0; i < n; i++) cin >> arr[i];
        for (int i = 0; i < n - 1; i++) {
            pre[i + 1] = pre[i] + arr[i];
            suf[i + 1] = suf[i] + arr[n - 1 - i];
        }
        int able = 1;
        for (int i = 1; i < n; i++) {
            if (pre[i] <= 0) {
                able = 0;
                break;
            }
            if (suf[i] <= 0) {
                able = 0;
                break;
            }
        }
        if (able) cout << "YES\n";
        else cout << "NO\n";
    }
}

void solveC_FadiAndLCM() {
    long long x;
    cin >> x;
    vector<long long> div;
    for (int i = 2; i < 1e6; i++) {
        if (x % i == 0) {
            long long tmp = 1;
            while (x % i == 0) {
                tmp *= i;
                x /= i;
            }
            div.push_back(tmp);
        }
    }
    if (x != 1) div.push_back(x);
    long long maxx = 1e18, minn = 0;
    long long k = pow(2, div.size());
    //cout << k;
    for (int i = 0; i < k; i++) {
        int tmp = i;
        long long A = 1, B = 1;
        for (int j = 0; j < (int)div.size(); j++) {
            if (tmp % 2 == 1) A *= div[j];
            else B *= div[j];
            tmp /= 2;
        }
        if (max(A, B) < maxx) {
            maxx = max(A, B);
            minn = min(A, B);
        }
    }
    cout << maxx << " " << minn;
}

void ALDS1_1_D() { /// Aizu
    int n; cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    int maxx[n];
    maxx[n - 1] = 0;
    for (int i = n - 2; i >= 0; i--) {
        maxx[i] = max(maxx[i + 1], arr[i + 1]);
    }
    int res = -1e9;
    for (int i = 0; i < n - 1; i++) res = max(res, maxx[i] - arr[i]);
    cout << res << '\n';
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    //rwFile();
    ///solveC_FadiAndLCM();
    ALDS1_1_D();
}



Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;
typedef long long ll;

const int MAXN = 210;
const ll INF = 1e9;
const ll LINF = 1e16;

int n, m, R;

ll dist[MAXN][MAXN];
int a[MAXN * MAXN], b[MAXN * MAXN], c[MAXN * MAXN];
int r[MAXN];

void warshalFloyd() {
  for (int k=0;k<n;k++) {
    for (int i=0;i<n;i++) {
      for (int j=0;j<n;j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
}

ll calc(vector<int> v) {
  ll d = 0;
  for (int i=0;i<v.size()-1;i++) {
    d += dist[v[i]][v[i+1]];
  }
  return d;
}

void solve() {
  for (int i=0;i<n;i++) {
    for (int j=0;j<n;j++) {
      dist[i][j] = INF;
    }
  }
  for (int i=0;i<n;i++) {
    dist[i][i] = 0;
  }
  for (int i=0;i<m;i++) {
    dist[a[i]-1][b[i]-1] = c[i];
    dist[b[i]-1][a[i]-1] = c[i];
  }
  warshalFloyd();
  vector<int> v;
  for (int i=0;i<R;i++) {
    v.push_back(r[i]-1);
  }
  sort(v.begin(), v.end());
  ll minDist = INF;
  do {
    minDist = min(minDist, calc(v));
  } while (next_permutation(v.begin(), v.end()));
  cout << minDist << endl;
}

int main() {
  cin >> n >> m >> R;
  for (int i=0;i<R;i++) {
    cin >> r[i];
  }
  for (int i=0;i<m;i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  solve();
}


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

#define endl "\n"
#define int long long
#define vec(x) vector<x>
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define matrix(x) vector<vector<x>>
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a, b, sizeof a)
#define setBits(n) __builtin_popcountll(n)
#define prec(n) fixed<<setprecision(n)
#define ff first
#define ss second
#define print(x) for(auto it:x) cout<<it<<" ";
#define dbg(x) cerr<<#x<<" :: "<<x<<endl;
#define dbg2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
const int INF = 1e9;
const int MOD = 1e9 + 7; 
const double pi = acos(-1);
int power(int a,int b,int m=MOD)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}
int dir[]={-1, 0, 1, 0, -1};
int dx[]={1,1,0,-1,-1,-1, 0, 1};
int dy[]={0,1,1, 1, 0,-1,-1,-1};

const int N = 1e5+1;

void solve()
{
	int a,b;
	cin>>a>>b;
    cout<<a*b<<endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t;
	t=1;
	//cin>>t;
	while(t--)
		solve();
}

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

int main(){
    string s;
    cin >> s;
    int counter = 0;
    if (s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
    else if (s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 888
// ABC049C.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;
#define modP 1000000007

ll myPower2(int num){
	if( num == 0) return 1;
	return (myPower2(num-1)*2)%modP;
}


int main()
{
	int n;
	cin>>n;
	int *A = new int[n];
	int *B = new int[2*n];
	rep(i,2*n) B[i] = 0;
	rep(i,n){
		cin>>A[i];
		B[A[i]]++;
	}
	bool ans = true;
	if( n % 2 == 1){
		if( B[0] != 1){
			ans = false;
		}else{
			for(int i = 2; i <= (n-1); i = i * 2){
				if( B[i] != 2){
					ans = false;
					break;
				}
			}
		}
	}else{
		for(int i = 1; i <= (n-1); i = i + 2){
			if(B[i] != 2){
				ans = false;
				break;
			}
		}
	}
	if( ans == false){
		cout<<0<<endl;
	}else{
		int num;
		if( n % 2 == 0){
			num = n / 2;
		}else{
			num = (n-1)/2;
		}
		cout<<myPower2(num)<<endl;
	}

	return 0;
}



Measured memory_bytes: 2176
def m(L,R):
 T=[]
 for l in L[::-1]:
  while R and R[-1]>l:T+=[R.pop()]
  T+=[l]
 return R+T[::-1]
def d(A):
 l=len(A);global c;c+=l
 s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A
c=-int(input())
print(*d(list(map(int,input().split()))))
print(c)


Measured memory_bytes: 63428
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    replace(s.begin(), s.end(), ',', ' ');
    cout << s << endl;

    return 0;
}

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

int main() {
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if(u==s){
    cout << a-1 << " " << b << endl;
  }
  else{
    cout << a << " " << b-1 << endl;
  }
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <tuple>
#include <cassert>
using namespace std;
using int64 = long long int;

struct UnionFind {
    vector<int> node, anc, color;
    UnionFind(int n) : node(n, -1), anc(n), color(n) {}
    int find(int k) { return node[k] < 0 ? k : find(node[k]); }
    int size(int k) { return -node[find(k)]; }
    bool unite(int u, int v) {
        u = find(u), v = find(v);
        if(u == v) return false;
        if(size(u) < size(v)) swap(u, v);
        node[u] += node[v];
        node[v] = u;
        return true;
    }
};

int main() {
    int N, Q; scanf("%d%d", &N, &Q);
    vector< vector< tuple<int, int, int> > > G(N);
    for(int i=0; i<N-1; i++) {
        int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
        a--; b--; c--;
        G[a].emplace_back(b, c, d);
        G[b].emplace_back(a, c, d);
    }

    vector<int64> ans(Q), neg(Q);
    vector< vector< tuple<int, int, int, int> > > info(N), tmp(N);
    for(int i=0; i<Q; i++) {
        int x, y, u, v; scanf("%d%d%d%d", &x, &y, &u, &v);
        x--; u--; v--;
        info[u].emplace_back(x, y, i, v);
        info[v].emplace_back(x, y, i, u);
    }

    UnionFind uf(N);
    function<void(int, int)> find_lca = [&](int cur, int par) {
        uf.anc[cur] = cur;
        for(auto e : G[cur]) {
            int to = get<0>(e);
            if(to == par) continue;
            find_lca(to, cur);
            uf.unite(to, cur);
            uf.anc[uf.find(cur)] = cur;
        }
        uf.color[cur] = 1;
        for(auto e : info[cur]) {
            int col, d, idx, to; tie(col, d, idx, to) = e;
            if(to < 0) continue;
            if(uf.color[to] == 1 and neg[idx]++ == 0) {
                int lca = uf.anc[uf.find(to)];
                tmp[lca].emplace_back(col, d, idx, -1);
            }
        }
    };

    vector<int64> sum(N), cnt(N);
    int64 cost = 0;
    function<void(int, int)> go = [&](int cur, int par) {
        for(auto e : info[cur]) {
            int col, d, idx, p; tie(col, d, idx, p) = e;
            int64 diff = cost + cnt[col] * d - sum[col];
            if(p < 0) {
                ans[idx] -= 2 * diff;
            }
            else { 
                ans[idx] += diff;
            }
        }

        for(auto e : G[cur]) {
            int to, col, dist; tie(to, col, dist) = e;
            if(to == par) continue;
            sum[col] += dist;
            cnt[col]++;
            cost += dist;
            go(to, cur);
            sum[col] -= dist;
            cnt[col]--;
            cost -= dist;
        }
    };

    find_lca(0, -1);
    for(int i=0; i<N; i++) for(auto e : tmp[i]) info[i].push_back(e);
    go(0, -1);
    for(auto a : ans) printf("%lld\n", a);
    return 0;
}


Measured memory_bytes: 32756
#include <bits/stdc++.h>
using namespace std;
#define endl "\n";
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define double long double
#define M_PI 3.14159265358979323846 
const int mod = 1e9 + 7;

int32_t main()
{
    fastio;

    int a; double b; cin >> a >> b;
    int ans = a*b;
    cout << ans << endl;
    return 0;
}

/*

*/

Measured memory_bytes: 3744
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

int main() {
    string S, T;
    cin >> S >> T;
    int l = S.length();
    int ans = 0;
    rep(i,0,l) {
        if (S[i] != T[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3860
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;

const ll MAX = 1e9 + 5;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	bool canWin2 = true;
	for (int i = 0; i < n; i++) {
		canWin2 = canWin2 && (a[i] % 2 == 0);
	}

	if (!canWin2) {
		cout << "first" << endl;
	}
	else {
		cout << "second" << endl;
	}
}

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

int main(){
 int a,b;	cin >> a >> b;
  
  if(a >= 13){
    cout << b << endl;
  }else if(a < 13 && a >= 6){
    cout << b/2 << endl;
  }else{
    cout << '0' << endl;
  }
  
  return 0;
    
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int X = scan.nextInt();
        if(-40 <= X && X <= 40){
            //処理
            if(X >= 30) {
                System.out.println("Yes");
            }else {
                System.out.println("No");
            }
            
        }else{
            System.out.println("Invalid value");
        }
    }
}


Measured memory_bytes: 35688
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#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()
const int INF = 1<<29;

int main() {
  int v[4] = {};
  REP(i,2) {
    REP(j,4) {
      int a;
      cin >> a;
      v[i] += a;
    }
  }
  cout << max(v[0],v[1]) << endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

long int f(int L, long int X);

using namespace std;
long int a[50];
long int p[50];

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

    a[0] = 1;
    for(int i = 1; i < 50 ; i++){
        a[i] = 2*a[i-1] + 3;
    }
    p[0] = 1;
    for(int i = 1; i < 50; i++){
        p[i] = 2*p[i-1] + 1;
    }

    cout << f(N,X) << endl;

    return 0;
    
}

long int f(int L, long int X){
    long int ans = 0;
    if(L == 0){
        return 1;
    }else{
        if(X == 1) ans = 0;
        if(1 < X && X <= 1 + a[L-1]) ans = f(L -1 , X-1);
        if(X == 2 + a[L-1]) ans = p[L-1] + 1;
        if(2 + a[L-1] < X && X <= 2 + 2*a[L-1] ) ans = 1 + p[L-1] + f(L-1 , X - 2 - a[L-1] );
        if(X == 3 + 2*a[L-1]) ans = 2*p[L-1] + 1 ;

        return ans; 
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=(j),i##_end=(k);i<=i##_end;++i)
const int MXN = 5e5 + 5;
const int INF = 0x7fffffff;
int n,a[MXN],k,p[MXN],mn[MXN<<2],deg[MXN],A[MXN],cnt;
vector<int> G[MXN];

inline void pushup(int k) {
	mn[k]=min(mn[k<<1],mn[k<<1|1]);
}
inline void update(int k,int l,int r,int p,int x) {
	if(l==r) {
		mn[k]=x;	return;
	}
//	cerr<<"k = "<<k<<endl;
	int mid=l+r>>1;
	if(p<=mid) update(k<<1,l,mid,p,x);
	else update(k<<1|1,mid+1,r,p,x);
	pushup(k);
}
inline int query(int k,int l,int r,int L,int R) {
	if(L>R) return INF;
	if(l>=L&&r<=R) {
		return mn[k];
	}
//	fprintf(stderr,"k = %d , l = %d , r = %d L = %d R = %d\n",k,l,r,L,R);
	if(!k) exit(0);
	int mid=l+r>>1;
	if(L>mid) return query(k<<1|1,mid+1,r,L,R);
	else if(R<=mid) return query(k<<1,l,mid,L,R);
	else return min(query(k<<1,l,mid,L,mid),query(k<<1|1,mid+1,r,mid+1,R));
}

int main() {
	ios::sync_with_stdio(false);
	cin>>n>>k;
	rep(i,1,n) cin>>a[i];
	rep(i,1,n) p[a[i]]=i;
	rep(i,0,MXN*4-1) mn[i]=INF;
	for(int i=n;i;--i) {
		int ret=query(1,1,n,p[i]+1,min(p[i]+k-1,n));
		if(ret!=INF) G[p[i]].push_back(p[ret]),deg[p[ret]]++;
		ret = INF; ret = query(1,1,n,max(1,p[i]-k+1),p[i]-1);
		if(ret!=INF) G[p[i]].push_back(p[ret]),deg[p[ret]]++;
		update(1,1,n,p[i],i);
	}
	priority_queue<int,vector<int>,greater<int> > Q;
	rep(i,1,n) if(!deg[i]) Q.push(i);
	while(!Q.empty()) {
		int now = Q.top(); Q.pop();
		A[now]=++cnt;
		for(auto w:G[now]) {
			if(!--deg[w]) Q.push(w);
		}
	}
	rep(i,1,n) cout<<A[i]<<endl;
}

Measured memory_bytes: 46592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  int B;
  cin >> A >> B;
  if ((((A%2) ==0) &&((B%2) ==0)) || (((A%2) ==1) &&((B%2) ==1))) {
    cout << (A+B)/2 << endl;
  }
  else {
    cout << "IMPOSSIBLE " << endl;
  }
  
   
  
    
  
  
 }

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

string s;
string t;

string dup_s;
vector<map<char, ll>> acc;

bool check(int next, int pos, char target) {
  return (acc[next][target] - acc[pos][target]) >= 1;
}

ll search(int pos, char target) {
  int ok = dup_s.size();
  int ng = pos;

  while (abs(ok - ng) > 1) {
    int next = (ok + ng) / 2;

    if (check(next, pos, target)) {
      ok = next;
    } else {
      ng = next;
    }
  }

  // printf("%d, %d, %c\n", pos, ok, dup_s[ok]);

  return ok - pos;
}

ll ans;

int main(void) {
  // Here your code !
  cin >> s;
  cin >> t;

  set<char> set_s;
  for (auto &e : s) {
    set_s.insert(e);
  }

  for (auto &e : t) {
    if (set_s.find(e) == set_s.end()) {
      printf("-1\n");
      return 0;
    }
  }

  dup_s = s + s;

  map<char, ll> cnt;

  for (int i = 0; i < dup_s.size(); ++i) {
    cnt[dup_s[i]] += 1;
    acc.push_back(cnt);
  }

  int pos;

  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == t[0]) {
      pos = i;
      break;
    }
  }

      // printf("%d: %c\n", pos, s[pos]);

  ans = pos;

  for (int i = 0; i < t.size() - 1; ++i) {
    // printf("%d: %c\n", pos, dup_s[pos]);
    pos %= s.size();
    // printf("%d: %c\n", pos, s[pos]);

        // printf("next: %c\n", t[i + 1]);

    int commit = search(pos, t[i + 1]);

    // printf("commit: %lld\n", commit);

    pos += commit;

    ans += commit;
  }

  ans += 1LL;

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

  // for (int i = 0; i < dup_s.size(); ++i) {
  //   for (auto &e: acc[i]) {
  //     printf("%c: %lld\n", e.first, e.second);
  //   }
  //   printf("\n");
  // }

  return 0;
}


Measured memory_bytes: 336680
#include <bits/stdc++.h>
     
    using namespace std;
     
    int main()
    {
        int n,m;
        cin >> n >> m;
     
        vector <pair<int,int> > v;
     
        for(int i=0;i<m;i++)
        {
            int x,y;
            cin >> x >> y;
     
            v.push_back(make_pair(y,x));
        }
     
        sort(v.begin(),v.end());
     
        int count = 0;
        int ed = 1;
     
        for(int i=0;i<m;i++)
        {
            if(v[i].second >= ed)
            {
                count++;
                ed = v[i].first;
            }
        }
     
        cout << count << endl;
    }

Measured memory_bytes: 1400