akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll x2 = 0;
  rep(i,n) {
    if (i%2) x2 -= a[i];
    else x2 += a[i];
  }
  vector<int> ans(n);
  ans[0] = x2/2;
  rep(i,n-1) {
    ans[i+1] = a[i]-ans[i];
  }
  rep(i,n) ans[i] *= 2;
  rep(i,n) printf("%d%c", ans[i], i==n-1?'\n':' ');
  return 0;
}

Measured memory_bytes: 2048
#include<stdio.h>
int main(void)
{
    long int d,s,t;
    scanf("%ld %ld %ld",&d,&t,&s);
    if(d <= s * t)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1604
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(int, k, a, b);
	bool ans = false;
	incII(i, a, b) { if(i % k == 0) { ans = true; } }
	OUT(-ans ? "OK" : "NG");
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define sz size()
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

#define ll long long

int main() {

     ios::sync_with_stdio(false);
     cin.tie(nullptr);

    int n,k;
    int i,j;
    cin>>n>>k;
    
    std::vector<int> a(n);

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

    for (j=k;j<n;j++)
    if (a[j]>a[j-k]) cout<<"Yes\n";
        else cout<<"No\n";


    return 0;
}

Measured memory_bytes: 3984
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author yoshizaki
 *151
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        Deque<String> deque = new ArrayDeque<String>();
        int qcount = scanner.nextInt();
        int submitCount = scanner.nextInt();
        for (int i = 1 ; i <= submitCount ; i++) {
            scanner.nextLine();
            deque.push(scanner.next());
            deque.push(scanner.next());
        }
        
        int ac = 0;
        int wa = 0;
        int waMemo = 0;
        String qnum = "";
        String  result = "";
        Map<String,String> submitted = new HashMap<String,String>();
        
        while (deque.peek() != null) {
            qnum = deque.pollLast();
            result = deque.pollLast();
            // 正解済みなら何もしない。
            if (submitted.containsKey(qnum) && submitted.get(qnum).equals("AC")) {
                continue;
            }
            // 正解してなくてWAなら誤答数のメモを1増やす。
            if (result.equals("WA")) {
                if (submitted.containsKey(qnum)) {
                    waMemo = Integer.valueOf(submitted.get(qnum));
                } else {
                    waMemo = 0;
                }
                waMemo++;
                submitted.put(qnum, String.valueOf(waMemo));
                continue;
            }
            // 正解した時に正答数を１増やす、正解した問題を記録する。
            if (result.equals("AC")) {
                ac++;
                if (submitted.containsKey(qnum)) {
                    wa = wa + Integer.valueOf(submitted.get(qnum));
                }
                submitted.put(qnum, result);
                waMemo = 0;
                continue;
            }
            
        }
        StringBuilder sb = new StringBuilder();
        sb.append(ac).append(" ").append(wa);
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 155860
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char B[1 << 15], *S = B, *T = B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 200010
int Fa[maxn], Fa2[maxn];
int Find(R int x) {return Fa[x] == x ? x : Fa[x] = Find(Fa[x]);}
int Find2(R int x) {return Fa2[x] == x ? x : Fa2[x] = Find2(Fa2[x]);}
std::map<std::pair<int, int>, int> cnt;
int main()
{
//	setfile();
	R int n = F(), k = F(), l = F();
	for (R int i = 1; i <= n; ++i) Fa[i] = Fa2[i] = i;
	for (R int i = 1; i <= k; ++i)
	{
		R int a = F(), b = F();
		if (Find(a) != Find(b))
		{
			Fa[Find(a)] = Find(b);
		}
	}
	for (R int i = 1; i <= l; ++i)
	{
		R int a = F(), b = F();
		R int f1 = Find2(a), f2 = Find2(b);
		if (f1 != f2)
		{
			Fa2[f1] = f2;
		}
	}
	for (R int i = 1; i <= n; ++i) ++cnt[std::make_pair(Find(i), Find2(i))];
	for (R int i = 1; i <= n; ++i) printf("%d ", cnt[std::make_pair(Find(i), Find2(i))] );
	return 0;
}


Measured memory_bytes: 13568
import numpy as np
import math
import heapq

N, M = map(int, input().split())
A = list(map(lambda x: [-int(x),int(x)], input().split()))
heapq.heapify(A)

for i in range(M):
    x = heapq.heappop(A)
    x[1] //= 2
    x[0] = -x[1]
    heapq.heappush(A, x)

ans = 0
for i in range(N):
    ans += A[i][1]
print(ans)


Measured memory_bytes: 36332
/*  /$$                                     /$$
      | $$                                    | $$
  /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$
 /$$__  $$ /$$__  $$ /$$_____/ /$$__  $$ /$$__  $$ /$$__  $$ /$$__  $$
| $$  | $$| $$$$$$$$| $$      | $$  \ $$| $$  | $$| $$$$$$$$| $$  \__/
| $$  | $$| $$_____/| $$      | $$  | $$| $$  | $$| $$_____/| $$
|  $$$$$$$|  $$$$$$$|  $$$$$$$|  $$$$$$/|  $$$$$$$|  $$$$$$$| $$
 \_______/ \_______/ \_______/ \______/  \_______/ \_______/|__//$$$$$$ /$$$$$$
                                                               |______/|______/

*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#define fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ln            cout << endl;
#define vi            vector<int>
#define vll           vector<long long>
#define sortl(vec)    sort(vec.begin(), vec.end());
#define sortr(vec)    sort(vec.rbegin(), vec.rend());
#define forn(i, x, n) for(long long i = x; i < n; i++)
#define revn(i, n, x) for(long long i = n; i >= x; i--)
#define in(vec)       for(auto &it : vec) cin >> it;
#define loop(vec)     for(auto &it : vec)
#define	out(vec)      for(auto &it : vec) cout << it << " "; ln
#define ll            long long
#define mod           1000000007
#define pb            emplace_back
#define mp            make_pair
#define um            unordered_map
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define f             first
#define s             second
#define pi            3.14159265359
#define o(x)		  cout << x << endl;
#define CLOCK         cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
using namespace std;

ll bS(ll l, ll r, ll x, vll arr) {
	while (l <= r) {
		ll m = l + (r - l) / 2;

		if (arr[m] == x)
			return m;

		if (arr[m] < x)
			l = m + 1;

		else
			r = m - 1;
	}

	return -1;
}

void primeFactors(ll n) {
	while (n % 2 == 0) {
		//cout << 2 << " ";
		n = n / 2;
	}

	for (ll i = 3; i <= sqrt(n); i += 2) {
		while (n % i == 0) {
			//cout << i << " ";
			n = n / i;
		}
	}

	if (n > 2)
		cout << n << " ";
}

ll power(ll x, ll y, ll p) {
	ll res = 1;
	x = x % p;

	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;

		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

ll modulo(ll a, ll b) {
	ll c = a % b;
	return (c < 0) ? c + b : c;
}

int main() {
// in(vec) works for size-defined type vectors

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input1.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output1.txt", "w", stdout);
#endif

	fastio
	ll t = 1;
	//cin >> t;
	while (t--) {
		ll n;
		cin >> n;
		o(n + n * n + n * n * n)


	}
	CLOCK
	return 0;
}



Measured memory_bytes: 3760
// inputに入力データ全体が入る
function Main(input) {
	ans = 'No'
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.trim().split("\n");
	// s = input[0].split(' ').map((n) => (parseInt(n)))
	if (input[0].indexOf('A') >= 0 && input[0].indexOf('B') >= 0) {
		ans = 'Yes'
	}




	//出力
	console.log(ans)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require('fs').readFileSync('./input.txt', 'utf-8'));

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

vector<int> adj[100005];
int depth[100005];
int value[100005];
int sz[100005];
int pa[100005];

int backLow, backHigh;

void dfs(int u, int p){
	for(int v : adj[u]){
		if(v == p) continue;
		
		if(depth[v] != 0){
			backLow = u;
			backHigh = v;
			continue;
		}
		
		depth[v] = depth[u] + 1;
		pa[v] = u;
		dfs(v, u);
	}
}

void dp(int u){
	sz[u] = value[u];
	for(int v : adj[u]){
		if(depth[v] == depth[u] + 1){
			dp(v);
			sz[u] += sz[v];
		}
	}
}

int main(){
    //freopen("i.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m; cin >> n >> m;
    for(int i = 0;i < m;i++){
		int a, b; cin >> a >> b;
		a--; b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	depth[0] = 1;
	dfs(0,-1);
	if(depth[backLow] < depth[backHigh]) swap(backHigh, backLow);
	
	if(m == n - 1){
		for(int i = 0;i < n;i++){
			if(depth[i] & 1) value[i] = 1;
			else value[i] = -1;
		}
		
		dp(0);
		
		long long ans = 0;
		long long balance = 0;
		for(int i = 0;i < n;i++){
			ans += abs(sz[i]);
			balance += value[i];
		}
		
		if(balance != 0) ans = -1;
		cout << ans;
	}
	
	else if((depth[backLow] - depth[backHigh]) % 2 == 0){ ///odd cycle
		for(int i = 0;i < n;i++){
			if(depth[i] & 1) value[i] = 1;
			else value[i] = -1;
		}
		
		long long balance = 0;
		for(int i = 0;i < n;i++){
			balance += value[i];
		}
		
		if(balance & 1){
			cout << -1;
			return 0;
		}
		
		value[backHigh] -= balance / 2;
		value[backLow] -= balance / 2;
		
		dp(0);
		
		long long ans = 0;
		for(int i = 0;i < n;i++){
			ans += abs(sz[i]);
		}
		
		
		ans += abs(balance) / 2;
		
		cout << ans;
	}
	
	else{ ///even cycle
		for(int i = 0;i < n;i++){
			if(depth[i] & 1) value[i] = 1;
			else value[i] = -1;
		}
		
		dp(0);
		
		long long ans = 0;
		long long balance = 0;
		for(int i = 0;i < n;i++){
			ans += abs(sz[i]);
			balance += value[i];
		}
		
		if(balance != 0){
			cout << -1;
			return 0;
		}
		
		vector<long long> values;
		values.push_back(0);
		while(backLow != backHigh){
			values.push_back(sz[backLow]);
			ans -= abs(sz[backLow]);
			backLow = pa[backLow];
		}
		
		sort(values.begin(),values.end());
		
		int median = values[values.size() / 2];
		for(long long x : values){
			ans += abs(median - x);
		}
		

		cout << ans;
	}
}




Measured memory_bytes: 13176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
int a,b,sum=1;
cin >> a >> b;
while(a>sum*8/100||b>sum*10/100){
    sum++;
    
    if(a<sum*8/100||b<sum*10/100){
        sum=-1;
        break;
    }
}
cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int i = 1;
    while(true){
      int x = Integer.parseInt(sc.next());
      if(x == 0){
        break;
      }
      else{
        System.out.printf("Case %d: %d\n", i, x);
        i++;
      }
    }
  }
}


Measured memory_bytes: 63532
#include <bits/stdc++.h>
#define maxn 1200
using namespace std;

char grid[maxn][maxn];
long long dp[maxn][maxn];
int h, w;

int main()
{
    ios::sync_with_stdio(false);
    cin >> h >> w;
    //dp[1][1] = 1;
    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            cin >> grid[i][j];
            if (grid[i][j] == '#')
                dp[i][j] = 0;
            else if (i == 1 && j == 1)
                dp[i][j] = 1;
            else
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % (1000000007);
        }
    }
    cout << dp[h][w];
    return 0;
}

Measured memory_bytes: 12672
#include <stdio.h>


int main(void)
{
	int x, y, w, cnt;

	while (1) {
		scanf("%d%d", &x, &y);
		if (x == 0 && y == 0)
			break;
		cnt = 0;
		if (x < y){
			w = x; x = y; y = w;
		}	
		while (1) {
			cnt++;
			if (x % y == 0)
				break;
			else {
					w = x % y; x = y; y = w;
			}
		}
	printf("%d %d\n", y, cnt);
	}
	

	return 0;
}
	
				


			

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

typedef long long ll;
#define nl "\n"
#define ff first
#define ss second
#define mod 1e9+7
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define pp pop_back
#define bs binary_search
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define sll stack<ll>
#define qll queue<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define vc vector <char>
#define vvll vector<vector<ll>>
#define mod 1e9+7
#define mxn 9e18
#define all(x) x.begin(),x.end()
#define loop(i,s,n) for(ll i=s;i<n;i++)
#define test ll t ; cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve()
{
   ll n,ans=0;
   cin>>n;
   ll a[n];
   loop(i,0,n)  cin>>a[i];
   map<ll,ll>   M;
   loop(i,0,n)  M[i+a[i]]++;
   loop(i,0,n)  ans+=M[i-a[i]];
   cout<<ans<<nl;
}

int main() {
	fast_io;
	
	solve();
	return 0;
}


Measured memory_bytes: 27800
#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define all(a)  (a).begin(),(a).end()


signed main(){
  int n,k;
  cin>>n>>k;
  V<P<int,int>> a(n);
  fo(i,n){
    cin>>a[i].fi>>a[i].se;
  }
  Sort(a);
  int b=0;
  fo(i,n){
    b+=a[i].se;
    if(b>=k){
      cout<<a[i].fi<<endl;
      break;
    }
  }
}


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


def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    a.sort(reverse=True)
    b = sorted([i for i in b if i > a[0]], key=lambda x:x, reverse=True)

    ans = 0
    s = 0
    while(s < H):
        if(len(b) == 0):
            from math import ceil
            print(ans + ceil((H-s)/a[0]))
            exit()
        
        s += b.pop(0)
        ans += 1

    print(ans)

    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 14376
#include <iostream>
#include <string>
#include <map>
#define MAX(a,b) (((a)>(b))?(a):(b))
using namespace std;

bool ch(char a){
	switch(a){
		case 'a':
		case 'i':
		case 'u':
		case 'e':
		case 'o':
			return true;
		default:
			return false;
	}
}

int main(void){
	int n;

	while (cin>>n,n) {
		int mlen=0;
		string s[50];
		string code[50];
		string jn[50];
		for(int i=0;i<n;i++)jn[i]="";
		for(int i=0;i<n;i++){
			cin>>s[i];
		}
		for(int i=0;i<n;i++)code[i]=s[i][0];
		for(int i=0;i<n;i++){
			for(int j=1;j<s[i].length();j++){
				if(ch(s[i][j-1]))code[i]+=s[i][j];
			}
		}
		for(int i=0;i<n;i++)mlen=MAX(mlen,code[i].length());
		int k,i;
		for(k=1;k<=mlen;k++){
			std::map<string,bool> b;
			for(i=0;i<n;i++){
				if(k-1<code[i].length())jn[i]+=code[i][k-1];
			}
			for(i=0;i<n;i++){
				if(b[jn[i]])break;
				else b[jn[i]]=true;
			}
			if(i==n)break;
		}
		if(k!=mlen+1)cout<<k<<endl;
		else cout<<-1<<endl;
	}

	return 0;
}

Measured memory_bytes: 3196
#include<stdio.h>
#include <stdlib.h>

int sort( const void * a , const void * b ) {
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}
 
int main(void)
{
  int N = 0;
  scanf("%d", &N);
  
  int d[100000]; //10^5
  for(int i = 0; i < N; i++)
  {
    scanf("%d", &d[i]);
  }
  
  qsort(( void * )d , N , sizeof( d[0] ) , sort );
  printf("%d", d[N/2] - d[N/2 - 1] );
  
  return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b; cin >> a >> b;
    if(b % a == 0) cout << a + b << endl;
    else cout << b - a << endl;
    return 0;
}



Measured memory_bytes: 256
// L - Deque  https://atcoder.jp/contests/dp/tasks/dp_l
/* 入力例
4
10 80 90 30
// →出力 10
*/
#include <bits/stdc++.h>
using namespace std;

int N;
int a[3000];
long long int mem[3000][3000];
int memflag[3000][3000];

long long int dp(int l, int r) {
    if(memflag[l][r] == 1) {
        return mem[l][r];
    } else if(l == r) {
        mem[l][r] = a[l];
        memflag[l][r] = 1;
        return mem[l][r];
    } else {
        mem[l][r] = max(dp(l + 1, r) * (-1) + a[l], dp(l, r - 1) * (-1) + a[r]);
        memflag[l][r] = 1;
        return mem[l][r];
    }
}

int main(void) {
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        for(int j = 0; j < N; j++) {
            memflag[i][j] = 0;
        }
    }

    cout << dp(0, N - 1);
    cout << "";
    return 0;
}


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

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

st = set()
super_coder = 0
for ele in a:
    clr = ele // 400
    if clr <= 7:  # has color
        st.add(clr)
    else:  # greater than red coder!!!
        super_coder += 1

if super_coder:
    ans = [max(len(st), 1), len(st) + super_coder]
else:
    ans = [len(st), len(st)]

print(*ans)


Measured memory_bytes: 3060
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>
#include<math.h>

using namespace std;

void Solution()
{
	int n;
    cin >> n;
    
    vector<int> a;
    a.push_back(0);
    a[0]=1;
    
    a.push_back(1);
    a[1]=1;
    
    for ( int i = 2; i <= n; i++ ) 
    {
        a.push_back(i);
        a[i] = a[i-2] + a[i-1];
    }
    
    cout << a[n] << endl;
}

int main()
{
	Solution();
	return 0;
}

Measured memory_bytes: 1216
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        var nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var x = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var minus = new List<int>();
        var plus = new List<int>();
        for (int i = 0; i < x.Length; i++)
        {
            if (x[i] < 0) minus.Add(x[i]);
            else if (x[i] > 0) plus.Add(x[i]);
        }
        minus = minus.OrderByDescending(i => i).ToList();
        if (x.Contains(0)) nk[1]--;
        var ans = new int[x.Count()];
        for (int i = 0; i < minus.Count(); i++)
        {
            var tempK = nk[1];
            ans[i] += Math.Abs(minus[i]);
            tempK -= i + 1;
            if (tempK > 0 && tempK <= plus.Count()) ans[i] += Math.Abs(plus[tempK - 1]) + Math.Abs(minus[i]);
            if (tempK > plus.Count()) ans[i] = int.MaxValue;
        }
        for (int i = 0; i < plus.Count(); i++)
        {
            var tempK = nk[1];
            ans[minus.Count() + i] = Math.Abs(plus[i]);
            tempK -= i + 1;
            if (tempK > 0 && tempK <= minus.Count()) ans[minus.Count() + i] += Math.Abs(minus[tempK - 1]) + Math.Abs(plus[i]);
            if (tempK > minus.Count()) ans[minus.Count() + i] = int.MaxValue;
        }
        Console.WriteLine(ans.Min());
    }
}


Measured memory_bytes: 32476
open Hashtbl

let f a b = (a, b)
let n, m = Scanf.scanf "%d %d\n" f
let h = create n

let rec inith x =
  if x = 0 then ()
  else
    match Scanf.scanf "%d %d\n" f with
    | 1, a ->
        add h 1 a ;
        inith (pred x)
    | a, b when b = n ->
        add h a n ;
        inith (pred x)
    | _ -> inith (pred x)


let rec solve = function
  | [] -> "IMPOSSIBLE"
  | hd :: tl -> if mem h hd then "POSSIBLE" else solve tl


let () =
  inith m ;
  solve (find_all h 1) |> print_endline

Measured memory_bytes: 16640
#include <stdio.h>

main()
{	int k,a,b;
	int count=0;
	
	scanf("%d",&k);
	scanf("%d",&a);
	scanf("%d",&b);
	
	while(a<=b)
	{
		if(a%k!=0)
		{
			++a;
		}
		else
		{
			++a;
			++count;
		}
	}
	
	if(count==0)
	{
		printf("NG");
	}
	else
	{
		printf("OK");
	}
}


Measured memory_bytes: 1728
n=int(input())
act=[]
for _ in range(n):
    act.append(list(map(int,input().split())))
dp=[[0 for x in range(3)] for y in range(n+1)]
for i in range(n):
    for p in range(3):
        dp[i+1][p]=max(dp[i][(p+1)%3]+act[i][p],dp[i][(p+2)%3]+act[i][p])
print(max(dp[n]))


Measured memory_bytes: 47320
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[][] ab = new int[n][2];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 2; j++){
                ab[i][j] = scan.nextInt();
            }
        }
        int[][] cd = new int[m][2];
        for(int i = 0; i < m; i++){
            for(int j = 0; j < 2; j++){
                cd[i][j] = scan.nextInt();
            }
        }
        int min = Integer.MAX_VALUE;
        int out = 0;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                if(Math.abs(ab[i][0] - cd[j][0]) + Math.abs(ab[i][1] - cd[j][1]) < min){
                    min = Math.abs(ab[i][0] - cd[j][0]) + Math.abs(ab[i][1] - cd[j][1]);
                    out = j + 1;
                }
            }
            System.out.println(out);
            min = Integer.MAX_VALUE;
            out = 0;
        }
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n;
  double m;
  cin>>n>>m;
  vector<double> a(n);
  double sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  double x=1/(4*m);
  double ans=0;
  rep(i,n){
    if(a[i]>=sum*x){
      ans++;
    }
  }
  if(ans>=m) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3696
//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 200005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define forn(i,a,b) for (ll i = a; i <= b; i ++ )
#define mod(n,k) (((n%k)+k)%k)
using namespace std;
typedef long long ll;

ll K, ans;

int main()
{
    optimiza_io
    cin >> K;
    forn(a,1,K)
        forn(b,1,K)
            forn(c,1,K) 
                ans += __gcd( a , __gcd( b , c ) ) ;
    
    cout << ans << "\n";
    return 0;
}

// CHECAR LIMITES 

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

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


//SOLVE
void solve(void)
{
  int N,W;
  cin>>N>>W;
  vector<int> Weight (N,0);
  vector<int> Value (N,0);
  for (int i = 0; i < N; i++)
  {
    cin>>Weight[i]>>Value[i];
  }
  int MV = 1000001;
  vector<vector<int> > DP (N+1,vector<int>(MV+1,INF));
  DP[0][0] = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < MV; j++)
    {
      if(j < Value[i])
      {
        DP[i+1][j] = DP[i][j];
      }
      else
      DP[i+1][j] = min(DP[i][j],DP[i][j-Value[i]] + Weight[i]);
    }
  }
  int ANS = 0;
  for (int i = 0; i < MV; i++)
  {
    if(W >= DP[N][i])
    {
      ANS = max(ANS,i);
    }
  }
  
  cout<<ANS<<endl;
  
  
  return;
}


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

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

  return 0;
}


Measured memory_bytes: 797568
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;
//using Graph = vector<vector<int>>;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> P;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n)  for(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}
LL sum(LL a, LL b){
    LL cnt=0;
    cnt=(b-a+1)*(a+b)/2;
    return cnt;
}
/*LL yaku(int x){
    vector<pair<LL, LL> a=[];
    LL xh;
    if(x==1){
        pair<LL, LL> tmp;
        tmp=MP(1,1);
        return tmp;
    }
    else{
        FOR(i, 1, x/2+1){
            if(x%i==0){
                a.append(MP(i,x/i));
            }
        }
    }
    return a;

}*/
LL cul(int a, int b){
    LL f = pow(a,4)+pow(a,3)*b+pow(a,2)*pow(b,2)+a*pow(b,3)+pow(b,4);
    return f;
} 
int main(){
    while(true){
        int a, b;
        cin >> a >>b;
        if(a==b&&a==0) break;
        int mi = min(a,b);
        int ma = max(a,b);
        cout << mi << ' ' << ma << endl;


    }
}
    





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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int T[N];
    int sum = 0;
    rep(i, N) {
        cin >> T[i];
        sum += T[i];
    }
    int M;
    cin >> M;
    rep(i, M) {
        int p, x;
        cin >> x >> p;
        x--;
        cout << sum + p - T[x] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a5, a7;
    vector<int> A(3);
    for(int i = 0; i < 3; i++){
        cin >> A.at(i);
    }
    a5 = count(A.begin(), A.end(), 5);
    a7 = count(A.begin(), A.end(), 7);
    if(a5 == 2 && a7 == 1){
        cout << "YES";
    }else{
        cout << "NO";
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        int x=0 , y=0 , min=999999;
        for(int i=1; i<=N; i++){
            x = x+(L+i-1);
            y=L+i-1;
            if(Math.abs(min)>Math.abs(y)){
                min = y;
            }
        }
        x = x-min;
        System.out.println(x);
    }
}

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

int main() {
  string s;
  getline(cin, s);
  for(int i = 0; i < s.size(); ++i) {
    cout << (char)toupper(s[i]);
  } 
  cout << endl;
  return 0;
}

Measured memory_bytes: 1168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		String[] abc = sc.nextLine().split(" ");

		int a = Integer.parseInt(abc[0]);
		int b = Integer.parseInt(abc[1]);
		int c = Integer.parseInt(abc[2]);

		if (a < b && b < c)
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}

Measured memory_bytes: 26316
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	long double n, m, d;
	cin >> n >> m >> d;
	if (d) cout << fixed << setprecision(15) << (m-1)*(n-d)*2/(n*n);
	else cout << fixed << setprecision(15) << (m-1)*(n-d)/(n*n);
}

















Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
char s[111111];
int dfs(int a, int b, int c)
{
	if(s[a] == 'a' && a < c && b > 0)
	{
		dfs(a + 1, b, c);
	}
	else if(a == c && b > 0)
	{
		b = b % 26;
		if(s[a] + b <= 'z')
		{
			s[a] = s[a] + b;
		}
		else
		{
			b = b - ('z' - s[a]) - 1;
			s[a] = 'a';
			s[a] = s[a] + b;
			}
		b = 0;
	}
	else if(a < c && b > 0)
	{
		if('z' - s[a] + 1 <= b)
		{
			b = b - ('z' - s[a] + 1);
			s[a] = 'a';
			dfs(a, b, c);
		}
		else
		{
			dfs(a + 1, b, c);
		}
	}
}
int main()
{
	int k;
	scanf("%s", &s);
	scanf("%d", &k);
	dfs(0, k, strlen(s) - 1);
	printf("%s\n", s);
}

Measured memory_bytes: 384
n,l = map(int, input().split())
listA = []
for i in range(n):
    listA.append(l+i)
b = 201
c = -1
for j in range(n):
    if abs(listA[j])<b:
        b=abs(listA[j])
        c=j
listA.pop(c)
print(sum(listA)) 

Measured memory_bytes: 3064
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		long N = input.nextLong();
		long A = input.nextLong();
		long B = input.nextLong();
		long numCycles = N/(A+B);
		long ans = A*numCycles;
		N%=(A+B);
		ans+=Math.min(N, A);
		System.out.println(ans);
	}
}

Measured memory_bytes: 23124
def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod = 10**9+7

    A_bin_cnt = [0] * 60
    for i in range(N):
        a = A[i]
        for j in range(60):
            if a >> j & 1:
                A_bin_cnt[j] += 1

    ans = 0
    for i in range(60):
        ans = (ans + (pow(2, i, mod) * (A_bin_cnt[i] * (N - A_bin_cnt[i])))%mod) % mod
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
  int sum = 0;
  vector<int> vec(3);
  for(int i = 0; i < 3; i++){
    cin >> vec.at(i);
  }
  
  // ソート
  sort(vec.begin(), vec.end());
  
  // 選択本数分計算
  for(int i = 0; i < 2; i++){
    sum += vec.at(i);
  }
  
  cout << sum;
}


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

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

    bool flag = false;

    for(int i=0; i<=N; i++){
        for(int j=0; j<=M; j++){
            if(i*(M-j) + j*(N-i) == K) flag = true;
        }
    }

    cout<<(flag ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 3632
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  ll dp[n+1];
  fill(dp,dp+(n+1),0);
  rep(i,n){
    dp[v[i]]=dp[v[i]-1]+1;
  }
  ll ans=0;
  rep(i,n+1){
    chmax(ans,dp[i]);
  }
  cout<<n-ans<<endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
using namespace std;
int board[101][101];
int h,w;
int xs,ys,xg,yg;
int n;

int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
bool search(int c,int y,int x){
	if(y<1||h<y||x<1||w<x||c!=board[y][x])return false;
	if(y==yg&&x==xg)return true;
	board[y][x]=0;
	for(int i=0;i<4;i++)
		if(search(c,y+dy[i],x+dx[i]))return true;
	return false;
}
int main(){
	while(cin>>w>>h,w|h){
		int c,d,x,y;
		cin>>xs>>ys>>xg>>yg>>n;
		fill_n((int*)board,sizeof(board)/sizeof(int),0);
		for(int i=0;i<n;i++){
			cin>>c>>d>>x>>y;
			int dx=2,dy=2;
			if(d==0)dx=4;
			else dy=4;
			for(int i=0;i<dy;i++)
				for(int j=0;j<dx;j++)
					board[y+i][x+j]=c;
		}
		if(board[ys][xs]!=0 && board[yg][xg]!=0 && search(board[ys][xs],ys,xs))cout<<"OK\n";
		else cout<<"NG\n";
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<ctime>
#include<random>
#include<algorithm>
#define ll long long
using namespace std;
int n;
char s[3][1000];
int main()
{
    cin>>n;
    int ans=0;
    for (int k=0; k<3; ++k)
        for (int i=0; i<n; ++i)
            cin>>s[k][i];
    for (int i=0; i<n; ++i)
    {
        if (s[0][i]==s[1][i] && s[1][i]==s[2][i])
        {
            ans+=0;
            continue;
        }
        if (s[0][i]==s[1][i] || s[1][i]==s[2][i] || s[2][i]==s[0][i])
        {
            ans+=1;
            continue;
        }
        ans+=2;
    } 
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
//const ll mod=1e9+7;
const ll mod=998244353;
const ll inf=5e15;

struct query{
  ll type;//0=empty, 1=add-sum ,2=set-max
  ll value;
  query(ll a=0,ll b=0):type(a),value(b) {}
};

ll INF=(1LL<<60);

struct segtree{
  ll SIZE;
  vector<query> s;
  vector<ll> t;// sum-add
  vector<ll> u;// max-set

  segtree(ll n=1){
    SIZE=1;
    while(SIZE<n)SIZE*=2;
    s.clear();
    t.clear();
    u.clear();
    s.resize(SIZE*2, query());
    t.resize(SIZE*2, 0);
    u.resize(SIZE*2, 0);
  }
  
  void func(ll k,ll l,ll r,query q){
    if(q.type==1){
      if(s[k].type==0)s[k]=q;
      else s[k].value+=q.value;
      t[k]+=q.value*(r-l);
      u[k]+=q.value;
    }
    if(q.type==2){
      s[k]=q;
      t[k]=q.value*(r-l);
      u[k]=q.value;
    }
  }

  void compute(ll k,ll l,ll r){
    query q=s[k];
    s[k]=query();
    if(q.type==0||r-l==1)return;
    ll m=(l+r)/2;
    func(k*2+1,l,m,q);
    func(k*2+2,m,r,q);
  }

  void Update(ll a,ll b,query x,ll k,ll l,ll r){
    if(b<=l || r<=a)return;
    compute(k,l,r);
    if(a<=l && r<=b){
      func(k,l,r,x);
    }else{
      ll m=(l+r)/2;
      Update(a,b,x,k*2+1,l,m);
      Update(a,b,x,k*2+2,m,r);
      t[k]=t[k*2+1]+t[k*2+2];
      u[k]=max(u[k*2+1],u[k*2+2]);
    }
  }

  ll Dfs(ll type,ll a,ll b,ll k,ll l,ll r){
    if(b<=l || r<=a){
      if(type==1)return 0; //add
      if(type==2)return -INF; // max
    }
    compute(k,l,r);
    if(a<=l && r<=b){
      if(type==1)return t[k];
      if(type==2)return u[k];
    }else{
      ll m=(l+r)/2;
      ll lv=Dfs(type,a,b,k*2+1,l,m);
      ll rv=Dfs(type,a,b,k*2+2,m,r);
      if(type==1)return lv+rv; // add
      if(type==2)return max(lv,rv); // max
    }
  }

  void Add(ll a,ll b,ll x){
    Update(a,b,query(1,x), 0,0,SIZE);
  }
  void Set(ll a,ll b,ll x){
    Update(a,b,query(2,x), 0,0,SIZE);
  }
  ll Getsum(ll a,ll b){
    return Dfs(1,a,b, 0,0,SIZE);
  }

  ll Getmax(ll a,ll b){
    return Dfs(2,a,b, 0,0,SIZE);
  }
  
};

int main() {
  ll n;
  cin >> n;
  vector<pll> a(n);
  vector<pll> b(n);
  for(ll i=0;i<n;i++) {
    ll x,d;
    cin >> x >> d;
    a[i]={x,x+d};
  }
  sort(a.begin(),a.end());
  segtree d(n+10);
  d.Set(0,n+1,-INF);
  vec dp(n+1);
  dp[0]=1;
  for(ll i=0;i<n;i++) {
    ll x=a[n-i-1].second;
    ll it=upper_bound(a.begin(),a.end(),pll(x,-INF))-a.begin();
    d.Set(n-i-1,n-i,it);
    d.Set(n-i-1,n-i,d.Getmax(n-i-1,it));
    ll id=n-d.Getmax(n-i-1,n-i);
    (dp[i+1]=dp[i]+dp[id])%=mod;
  }
  cout << dp[n] << endl;
}

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


Measured memory_bytes: 2140
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	vector<int> A(N);
	REP(i,N){
		A[i] = in();
	}
	sort(ALL(A));
	cout << A[N-1]-A[0] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int N;
int A[2<<17],B[2<<17];
int cA[2<<17],cB[2<<17];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		A[i]--;
		cA[A[i]]++;
	}
	for(int i=0;i<N;i++)
	{
		cin>>B[i];
		B[i]--;
		cB[B[i]]++;
	}
	vector<int>id(N);
	for(int i=0;i<N;i++)id[i]=i;
	sort(id.begin(),id.end(),[](int i,int j){return cA[i]+cB[i]>cA[j]+cB[j];});
	if(cA[id[0]]+cB[id[0]]>N)
	{
		cout<<"No"<<endl;
		return 0;
	}
	queue<int>Arest,Brest;
	for(int i=0;i<cA[id[0]];i++)Arest.push(id[0]);
	for(int i=0;i<cB[id[0]];i++)Brest.push(id[0]);
	vector<pair<int,int> >edge;
	for(int i=1;i<N;i++)
	{
		bool witch;
		if(Arest.size()<cB[id[i]])witch=false;
		else if(Brest.size()<cA[id[i]])witch=true;
		else witch=cA[id[i]]>=cB[id[i]];
		if(witch)
		{
			if(Arest.size()<cB[id[i]])return 1;
			for(int j=0;j<cB[id[i]];j++)
			{
				edge.push_back(make_pair(Arest.front(),id[i]));
				Arest.pop();
			}
			for(int j=0;j<cA[id[i]];j++)
			{
				Arest.push(id[i]);
			}
		}
		else
		{
			if(Brest.size()<cA[id[i]])return 1;
			for(int j=0;j<cA[id[i]];j++)
			{
				edge.push_back(make_pair(id[i],Brest.front()));
				Brest.pop();
			}
			for(int j=0;j<cB[id[i]];j++)
			{
				Brest.push(id[i]);
			}
		}
	}
	while(!Arest.empty())
	{
		edge.push_back(make_pair(Arest.front(),-1));
		Arest.pop();
	}
	int i=N;
	while(!Brest.empty()){
		edge[--i].second=Brest.front();
		Brest.pop();
	}
	cout<<"Yes"<<endl;
	sort(edge.begin(),edge.end());
	for(int i=0;i<N;i++)cout<<edge[i].second+1<<(i+1==N?'\n':' ');
}


Measured memory_bytes: 9832
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define bg begin()
#define end end()
#define sz size()
#define vi vector<int>
#define vl vector<long long int>
int main(){
	fast;
	ll n,s=1,cnt=0,next=0,prev=0;
	cin>>n;
	int arr[n+1],fr[n+1]={0};
	for(int i=1;i<n+1;i++)
		cin>>arr[i];
	while(1){
		fr[s]++;
		if(fr[s]>1)
			break;
		s=arr[s];
		cnt++;
		if(s==2)
		{
			cout<<cnt;
			return 0;
		}
		
	}
	cout<<-1;
	return 0;
}



Measured memory_bytes: 4400
#include<stdio.h>
#include<string.h>
#include<ctype.h>
 
int main(){
    char s[21];
    char w[21];
    int count=0;
    scanf("%s",s);
    while(1){
       scanf("%s",w);
       if(strcmp(w, "END_OF_TEXT")==0)
           break;
       for(int i=0;w[i]!='\0';i++){
           w[i]=tolower(w[i]);
       }
       if(strcmp(w,s)==0){
           count+=1;
       }
   }
   printf("%d\n", count);
 
   return 0;
}


Measured memory_bytes: 2832