akhauriyash/Code-Regression huggingface dataset:
//21
#include<cstdio>
#include<algorithm>
using namespace std;

const int maxn = 3001;
const int lbt = 1e9 + 7;

struct req {
	int s, x, y, d;
	req() {}
	req(int s, int x, int y, int d) : s(s), x(x), y(y), d(d) {}
};

int n, q;
int a[maxn];
int x[maxn], y[maxn];
int dp[2][maxn][maxn];
req op[14 * maxn];

void add(int &x, int y);

int main() {
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 1; i <= q; i++) {
		scanf("%d%d", &x[i], &y[i]);
	}
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (a[i] < a[j]) dp[0][i][j]++;
			if (a[i] > a[j]) dp[1][i][j]++;
		}
	}
	int rev2 = (lbt + 1) / 2;
	for (int _ = 1; _ <= q; _++) {
		int x = ::x[_];
		int y = ::y[_];
		if (x == y) continue;
		int cnt = 0;
		if (x > y) swap(x, y);
		for (int j = y + 1; j <= n; j++) {
			op[++cnt] = req(0, x, j, dp[0][y][j]);
			op[++cnt] = req(1, x, j, dp[1][y][j]);
			op[++cnt] = req(0, y, j, dp[0][x][j]);
			op[++cnt] = req(1, y, j, dp[1][x][j]);
		}
		for (int i = x + 1; i < y; i++) {
			op[++cnt] = req(1, x, i, dp[0][i][y]);
			op[++cnt] = req(0, x, i, dp[1][i][y]);
		}
		op[++cnt] = req(0, x, y, dp[1][x][y]);
		op[++cnt] = req(1, x, y, dp[0][x][y]);
		for (int j = x + 1; j < y; j++) {
			op[++cnt] = req(1, j, y, dp[0][x][j]);
			op[++cnt] = req(0, j, y, dp[1][x][j]);
		}
		for (int i = 1; i < x; i++) {
			op[++cnt] = req(0, i, x, dp[0][i][y]);
			op[++cnt] = req(1, i, x, dp[1][i][y]);
			op[++cnt] = req(0, i, y, dp[0][i][x]);
			op[++cnt] = req(1, i, y, dp[1][i][x]);
		}
		for (int i = 1; i <= cnt; i++) {
			add(dp[op[i].s][op[i].x][op[i].y], op[i].d);
		}
		for (int i = 1; i < y; i++) {
			dp[0][i][y] = (long long)dp[0][i][y] * rev2 % lbt;
			dp[1][i][y] = (long long)dp[1][i][y] * rev2 % lbt;
		}
		for (int j = x + 1; j <= n; j++) {
			dp[0][x][j] = (long long)dp[0][x][j] * rev2 % lbt;
			dp[1][x][j] = (long long)dp[1][x][j] * rev2 % lbt;
		}
		for (int i = 1; i < x; i++) {
			dp[0][i][x] = (long long)dp[0][i][x] * rev2 % lbt;
			dp[1][i][x] = (long long)dp[1][i][x] * rev2 % lbt;
		}
		for (int j = y + 1; j <= n; j++) {
			dp[0][y][j] = (long long)dp[0][y][j] * rev2 % lbt;
			dp[1][y][j] = (long long)dp[1][y][j] * rev2 % lbt;
		}
		dp[0][x][y] = 2 * dp[0][x][y] % lbt;
		dp[1][x][y] = 2 * dp[1][x][y] % lbt;
	}
	int pow2 = 1;
	for (int i = 1; i <= q; i++) pow2 = 2 * pow2 % lbt;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			dp[0][i][j] = (long long)pow2 * dp[0][i][j] % lbt;
			dp[1][i][j] = (long long)pow2 * dp[1][i][j] % lbt;
			add(ans, dp[1][i][j]);
		}
	}
	printf("%d", ans);
	return 0;
}

void add(int &x, int y) {
	x = x + y >= lbt ? x + y - lbt : x + y;
}

Measured memory_bytes: 69888
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long int ll;

int h,w;
char fi[55][55];
int dist[55][55];
bool ok=false;
int dx[]={0,1,-1,0};
int dy[]={1,0,0,-1};

int main(){
    cin >> h >> w;
    int cnt=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> fi[i][j];
            dist[i][j]=1e9;
            if(fi[i][j]=='.')cnt++;
        }
    }
    queue<pair<int,int> > q;
    q.push(make_pair(0,0));
    dist[0][0]=0;
    while(q.empty()==false){
        int x=q.front().first,y=q.front().second;
        q.pop();
        for(int i=0;i<4;i++){
            int nx=x+dx[i],ny=y+dy[i];
            if(nx<0||nx>=h||ny<0||ny>=w)continue;
            if(fi[nx][ny]=='#'||dist[nx][ny]<1e9)continue;
            dist[nx][ny]=dist[x][y]+1;
            q.push(make_pair(nx,ny));
        }
    }
    if(dist[h-1][w-1]==1e9){
        cout << -1 << endl;
    }
    else{
        cout << cnt-dist[h-1][w-1]-1 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define mod 1000000007
typedef long long ll;
using namespace std;

const int M = (int)(2e6 + 239);


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

    string a;
    ll b;
    set<string>s;
    cin>>b;
    while(b--)
    {
        cin>>a;
        s.insert(a);
    }
    cout<<s.size()<<endl;
}


Measured memory_bytes: 19272
alp = {chr(x): 0 for x in range(97, 123)}

while True:
    try:
        s = input().lower()
        for c in s:
            if c.isalpha():
                alp[c] += 1
    except EOFError:
        break

for k in alp:
    print(f'{k} : {alp[k]}')
    


Measured memory_bytes: 5580
from collections import deque
H,W = list(map(int,input().split()))
start = list(map(lambda x:int(x)-1,input().split()))
goal = list(map(lambda x:int(x)-1,input().split()))
A = [input() for _ in range(H)]
visited = [[0]*W for _ in range(H)]
B = deque([[start[0],start[1],0]])
warp = []
for i in range(-2,3):
    for j in range(-2,3):
            warp.append([i,j])

num = -1

while B:
    y,x,n = B.popleft()
    if visited[y][x] == 1:continue
    if [y,x] == goal:
        num = n
        break
    visited[y][x] = 1
    for dy,dx in [[1,0],[0,1],[-1,0],[0,-1]]:
        if (y+dy<0)|(x+dx<0)|(y+dy>=H)|(x+dx>=W):continue
        if (A[y+dy][x+dx]==".")&(visited[y+dy][x+dx]==0):
            B.appendleft([y+dy,x+dx,n])
    for dy,dx in warp:
        if (y+dy<0)|(x+dx<0)|(y+dy>=H)|(x+dx>=W):continue
        if (A[y+dy][x+dx]==".")&(visited[y+dy][x+dx]==0):
            B.append([y+dy,x+dx,n+1])

print(num)

Measured memory_bytes: 228280
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cctype>
#include <algorithm>
#include <functional>
#include <utility>
const int ha = 1000000007;
inline void add(int &p, const int &val) {
  p += val; if(p >= ha) p -= ha;
}

const int maxn = 3005;
int R[maxn], f[maxn][maxn];
char S[maxn]; int sum[maxn];
int main() {
  int n, m; scanf("%d%d", &n, &m);
  scanf("%s", S + 1);
  for(int i = 1; i <= n; i ++) {
    sum[i] = sum[i - 1] + S[i] - '0';
    R[i] = i;
  }
  while(m --) {
    int l, r; scanf("%d%d", &l, &r);
    R[l] = std::max(R[l], r);
  }
  for(int i = 2; i <= n; i ++) R[i] = std::max(R[i], R[i - 1]);
  R[n + 1] = n;
  f[1][sum[R[1]]] = 1;
  for(int i = 1; i <= n; i ++) {
    for(int j = 0; j <= n; j ++) {
      int th = f[i][j];
      if(!th) continue;
#ifdef LOCAL
      printf("f[%d][%d] : %d\n", i, j, f[i][j]);
#endif
      int delta = sum[R[i + 1]] - sum[R[i]];
      if(j) add(f[i + 1][j + delta - 1], th);
      if(R[i] - i >= j) add(f[i + 1][j + delta], th);
    }
  }
  printf("%d\n", f[n + 1][0]);
  return 0;
}

Measured memory_bytes: 33792
#include<bits/stdc++.h> 
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int N = 200010;
long long n,d,x,y,k,a[N];
string s;
int main()
{
	cin>>n>>s;
	int x=0,y=n-1;
	k=0;
	while(x<y){
		while(y>0&&s[y]!='R') y--;
		while(x<n&&s[x]!='W') x++;
		if(y>x){
			swap(s[x],s[y]);
			k++;
		}
	}
	cout<<k<<endl;
    return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000



int main(){
	
	int N,Z,W;
	cin>>N>>Z>>W;
	vector<int> a(N);
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	if(N==1){
		cout<<abs(W-a[0])<<endl;
	}
	else{
		cout<<max(abs(W-a[N-1]),abs(a[N-1]-a[N-2]))<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    
    ll ans = 0;
    ll k = n / (a + b);
    ans += a * k;
    ll d = n - ((a + b) * k);
    
    if (d < a)
        ans += d;
    else
        ans += a;
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
from collections import deque
n = int(input())
d = deque()

for _ in range(n):
    t = input().split()
    if t[0] == "0":
        if t[1] == "0":
            d.appendleft(t[2])
        else:
            d.append(t[2])
    elif t[0] == "1":
        print(d[int(t[1])])
    else:
        if t[1] == "0":
            d.popleft()
        else:
            d.pop()




Measured memory_bytes: 34652
n,a,b = map(int,input().split())
if n ==1:
    if a == b:
        
        print(n)
    else:
        print(0)
else:
    if a<=b:
        s = (n-1)*a+b
        f = (n-1)*b+a
        print(f-s+1)
    else:
        print(0)

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


int main() {
    int n; cin >> n;
    vector<vector<double>> p(n,vector<double>(2));
    rep(i,n){
        rep(j,2){
            cin >> p[i][j];
        }
    }
    double ans=0;
    rep(i,n-1){
        for(int j=i+1;j<n;j++){
            ans += sqrt(pow(p[i][0]-p[j][0],2)+pow(p[i][1]-p[j][1],2));
        }
    } 
    ans/=n;
    ans*=2;
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

f("Christmas", 25).
f("Christmas Eve", 24).
f("Christmas Eve Eve", 23).
f("Christmas Eve Eve Eve", 22).

main :-
    get_number(D),
    f(X, D),
    writeln(X).


Measured memory_bytes: 7964
#include <iostream>
#include <map>
#include <vector>
#include <queue>
using namespace std;

int main()
{
    int n;
    cin >> n;
    map<int, vector<pair<int, long long>>> mv;
    long long r[n] = {};
    for(int i=0; i<n-1; i++){
        int a, b, t;
        cin >> a >> b >> t;
        a--;
        b--;
        mv[a].push_back({b,t});
        mv[b].push_back({a,t});
    }
    int m, k;
    cin >> m >> k;
    k--;
    
    queue<int> q;
    q.push(k);
    while(!q.empty()){          // BFS
        int c = q.front();
        q.pop();
        for(auto p: mv[c]){
            if(r[p.first] != 0) continue;
            r[p.first] = r[c] + p.second;
            q.push(p.first);
        }
    }
    
    while(m--){
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << r[x] + r[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 15488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX =1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int 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 COM(int n, int k){
  if(n<k)
    return 0;
  if(n<0 || k<0)
    return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
//10^6*2の盤面はメモリオーバー
//mapでDP？
//下に何回、右に何回動くか、を計算するのかな
//2r+d=X
//r+2d=Y r=Y-2d
//2Y-3d=X
//d=2Y-X)/3
//rrrdd 5C2
int main(){
  COMinit();
  ll X,Y,r,d; cin>>X>>Y;
  d=(2*Y-X)/3;
  r=Y-2*d;
  if(r*2+d==X && r+d*2==Y)
    cout<<COM(r+d,d)%MOD<<endl;
  else
    cout<<0<<endl;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
     
using namespace std;
     
int main() {
    int n;
    cin >> n;
    vector<int> bricks(n);
    for (int i = 0; i < n; i++) {
        cin >> bricks[i];
    }
    int next_no = 1;
    for (int i = 0; i < n; i++) {
        if (bricks[i] == next_no) {
            next_no++;
        }
    }
    if (next_no == 1) {
        cout << -1;
    } else {
        cout << n - next_no + 1;
    }
}

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


def solve(s: str):
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            print(i + 1, i + 2)
            return
    for i in range(len(s) - 2):
        if s[i] == s[i + 2]:
            print(i + 1, i + 3)
            return
    print(-1, -1)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;
 
inline int read(){
	int x = 0, ch = getchar(), f = 1;
	while (!isdigit(ch)){if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}

int n, A, xi[55];
LL cnt[2][55][2505];
int main(){
	n = read(), A = read();
	REP(i, 1, n) xi[i] = read();
	int cur = 0, pre = 1;
	cnt[0][0][0] = 1;
	REP(i, 1, n){
		cur ^= 1, pre ^= 1;
		REP(j, 0, i) REP(k, 0, 2500) cnt[cur][j][k] = 0;
		REP(j, 0, i - 1) REP(k, 0, (i - 1) * 50){
			cnt[cur][j][k] += cnt[pre][j][k];
			cnt[cur][j + 1][k + xi[i]] += cnt[pre][j][k];
		}
	}
	LL ans = 0;
	for (int i = 1; i <= n && i * A <= 2500; ++i)
		ans += cnt[cur][i][i * A];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2176
while(1):
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if(op=='+'):print(a+b)
    if(op=='-'):print(a-b)
    if(op=='*'):print(a*b)
    if(op=='/'):print(a//b)
    if(op=='?'):break


Measured memory_bytes: 5596
H, W = map(int, input().split())

if H == 1 or W == 1:
    ans = 1
else:
    if H % 2 == 1 and W % 2 == 1:
        ans = H * (W // 2) + H // 2 + 1
    else:
        ans = W * H // 2
print(ans)

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

int a[100000], n, m;
ll sum[300000], sum2[300000];

int dist(int a, int b) {
	return (b + m - a) % m;
}
int dist(int a, int b, int c) {
	return min(dist(a, b), dist(c, b) + 1);
}
int main() {
	scanf("%d%d", &n, &m);
	rep(i, n)scanf("%d", &a[i]), a[i]--;
	rep(i, n - 1) {
		sum[a[i] + 1]++;
		if (a[i] < a[i + 1]) {
			sum[a[i + 1] + 1]--;
			sum2[a[i + 1] + 1] -= a[i + 1] - a[i];
		}
		else {
			sum[a[i + 1] + m + 1]--;
			sum2[a[i + 1] + m + 1] -= a[i + 1] + m - a[i];
		}
	}
	for (int i = 1; i < m * 2; i++) {
		sum[i] += sum[i - 1];
		sum2[i] += sum2[i - 1] + sum[i];
		if (i >= m)sum2[i - m] += sum2[i];
	}
	ll ans = 0;
	int id = max_element(sum2, sum2 + m) - sum2;
	rep(i, n - 1) {
		ans += dist(a[i], a[i + 1], id);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
int main() {
float t1,t2,s1,s2;
cin>>t1>>t2>>s1>>s2;
float t,s;
t=s1/t2;
s=t1/s2;

if(t<=s||ceil(t)<=ceil(s))
    cout<<"Yes";
else
    cout<<"No";
}


Measured memory_bytes: 3720
#include<iostream>
using namespace std;
int func(int N){
  int count=0;
  for(int i=1;i<=197;i+=2){
    if(N%i==0){
      count++;
    }
  }
  return count;
}
int main(){
  int N;
  cin>>N;
  int ans=0;
  for(int i=1;i<=N;i=i+2){
    if(func(i)==8){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

void joge(int w) {
  string s = "";
  for(int i = 0; i < w; i++) s.push_back('#');
  printf("%s\n", s.c_str());
  return;
}

void naka(int w) {
  string s = "#";
  for(int i = 0; i < w - 2; i++) s.push_back('.');
  s.push_back('#');
  printf("%s\n", s.c_str());
  return;
}

int main() {
  int h, w;
  while(true) {
    scanf("%d %d", &h, &w);
    if(h == 0 && w == 0) break;
    joge(w);
    for(int i = 0; i < h - 2; i++) naka(w);
    joge(w);
    printf("\n");
  }
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  vsort(a);
  
  ll ans=0;
  rep(i,n){
    irep(j,i+1,n){
      ll sum=a[i]+a[j];
      ll idx=lower_bound(all(a),sum)-a.begin();
      idx-=(1+j);
      ans+=idx;
    }
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int A,B,X;
    cin >> A >> B >> X;
    X -= A;
    bool ok = 1;
    if(X < 0)ok = 0;
    if(X > B)ok = 0;
    cout << (ok ? "YES" : "NO") << "\n";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

struct edge {
  int from;
  int to;
  ld cost;
};
bool operator<(const edge&l, const edge&r) {
  return l.cost < r.cost;
}
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};
int main() {
  
  int N; cin >> N;
  vector<int>nums(1000000);
  vector<int>sums(1000000);
  for (int i = 0; i < N; ++i) {
    int a, b; cin >> a >> b;
    nums[a-1]++;
    nums[b]--;
  }
  int asum = 0;
  for (int i = 1; i < 1000000; ++i) {
    asum += nums[i];
    sums[i] = asum;
  }
  int ans = 0;
  for (int i = 0; i < N + 2; ++i) {
    if (sums[i] >= i)ans = i;
  }
  cout << ans << endl;
  return 0;
}

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

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

  int A = s.at(0) - '0';
  int B = s.at(1) - '0';
  int C = s.at(2) - '0';
  int D = s.at(3) - '0';

  if(A+B+C+D == 7) {
    cout << A << "+" << B << "+" << C << "+" << D;
  } else if(A+B+C-D == 7) {
    cout << A << "+" << B << "+" << C << "-" << D;
  } else if(A+B-C+D == 7) {
    cout << A << "+" << B << "-" << C << "+" << D;
  } else if(A+B-C-D == 7) {
    cout << A << "+" << B << "-" << C << "-" << D;
  } else if(A-B+C+D == 7) {
    cout << A << "-" << B << "+" << C << "+" << D;
  } else if(A-B+C-D == 7) {
    cout << A << "-" << B << "+" << C << "-" << D;
  } else if(A-B-C+D == 7) {
    cout << A << "-" << B << "-" << C << "+" << D;
  } else if(A-B-C-D == 7) {
    cout << A << "-" << B << "-" << C << "-" << D;
  }
  
  cout << "=7" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 1000000000000
#define int long long int
#define hell (int)(1e9+7)

using namespace std;

void solve(){
    int n,k;
    cin>>n>>k;
    vector <int> adj[n+1];
    for(int i=0;i<k;i++){
        int d;
        cin>>d;
        for(int j=0;j<d;j++){
            int x;
            cin>>x;
            adj[x].push_back(i);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(adj[i].empty())
            ans++;
    }
    cout<<ans;
}

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


Measured memory_bytes: 3692
while True:
    size = map(int,raw_input().split())
    if size[0] == 0:
        break
    size = sorted(size)
    rmin2 = size[0]**2 + size[1]**2
    
    n = input()
    for i in range(n):
        R2 = (input()**2)*4
        if rmin2 < R2:
            print 'OK'
        else:
            print 'NA'

Measured memory_bytes: 4204
package main

import "fmt"

const max int = 1000000
const mod int = 1000000007

var f [max]int
var rf [max]int

func main() {
	f[0], rf[0] = 1, 1
	for i := 1; i < max; i++ {
		f[i] = (f[i-1] * i) % mod
		rf[i] = inv(f[i], mod)
	}

	var X, Y int
	fmt.Scan(&X, &Y)
	for a := 0; a < X+1; a++ {
		b := Y - 2*a
		if a+2*b == X {
			fmt.Println(C(a+b, a))
			return
		}
	}
	fmt.Println(0)
}
func inv(x, mod int) int {
	res := 1
	k := mod - 2
	y := x
	for k > 0 {
		if (k & 1) == 1 {
			res = (res * y) % mod
		}
		y = (y * y) % mod
		k = k >> uint(1)
	}
	return res
}
func C(n, k int) int {
	a := f[n]
	b := rf[n-k]
	c := rf[k]

	bc := (b * c) % mod

	return (a * bc) % mod
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;

ll gcd(ll a, ll b)
{
    if (b==0) return a;
    return gcd(b, a%b);
}
ll lcm(ll a, ll b)
{
    return (a/gcd(a, b))*b;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> l(n);
    vector<int> r(n);
    l[0] = a[0];
    r[n-1] = a[n-1];
    rep(i, n) {
        if (i==0) continue;
        l[i] = gcd(a[i], l[i-1]);
    }
    for (int i=n-2; i>=0; i--) {
        r[i] = gcd(r[i+1], a[i]);
    }
    int ans = max(r[1], l[n-2]);
    rep(i, n-1) {
        if (i==0) continue;
        int res = gcd(l[i-1], r[i+1]);
        ans = max(ans, res);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
function Main(input){
    input = input.split("\n");
    for(var i = 0;1;i++){
        input[i] = input[i].split(" ");

        var x = parseInt(input[i][0],10);
        var y = parseInt(input[i][1],10);
        var s = parseInt(input[i][2],10);

        if(x == 0 && y == 0 && s == 0)
            break;
 
        var max = 0;

        for(var l = 1;l < s;l++){
            var a = [];
            a[0] = l;
            a[1] = s - l;

            var sum = 0;var flag = false;
            for(var j = 0;j < 2;j++){
                var b = Math.floor(a[j] / (100 + x) * 100) + 1;
                while(b * (100 + x) / 100 >= a[j] + 1)
                    b--;
                if(b * (100 + x) / 100 < a[j])
                    flag = true;
                var c = Math.floor(b * (100 + y) / 100);
                if(c + 1 == b * (100 + y) / 100)
                    c++;
                sum += c;
            }
            if(flag)
                continue;
            if(max < sum){
                max = sum;
            }
        }
        console.log(max);
    }
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 18044
#include <bits/stdc++.h>
#define MAXN 10010
#define pii  pair<ll, ll>
#define ss second
#define ff first

using ll = long long;
using namespace std;
const int mod = 1e9 + 7;

int main(){
    ll n, d;
    cin >> n >> d;

    ll ans = n/(d*2 + 1);
    if (n%(d*2 + 1) != 0) ans++;

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <limits>
#include <set>
#include <map>
 
int main()
{
    int n{};
    std::set<std::string> items;

    std::cin >> n;
    std::string s;
    for (int i = 0; i < n; i++) {
        std::cin >> s;
        items.insert(s);
    }
    std::cout << items.size() << std::endl;
    return 0;
}

Measured memory_bytes: 19112
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

const lint MOD = pow(10, 9) + 7;

lint gcd(lint a, lint b) {
	//aとbの最大公約数を返す
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(a % b, b);
}

lint lcm(lint a, lint b) {
	//aとbの最小公倍数を返す
	return a / gcd(a, b) * b;
}

lint sgm(lint n) {
	//0からの総和を返す
	return n * (n + 1) / 2;
}

lint fact(lint n) {
	//n!を返す
	if (n == 0) return 1;
	else return n * fact(n - 1);
}

lint power(lint x, lint n, lint m) {
	//(x^n)%mを返す
	lint res = 1;
	x %= m;
	while (n > 0) {
		if (n % 2 == 1) {
			res = res * x % m;
		}
		x = x * x % m;
		n /= 2;
	}
	return res;
}

int isprime(lint x) {
	//xが素数:1,xが素数でない:0
	if (x == 2) {
		return 1;
	}
	else if (x == 1 || x % 2 == 0) {
		return 0;
	}
	else {
		lint i = 3;
		while (i * i <= x) {
			if (x % i == 0) {
				return 0;
			}
			i += 2;
		}
		return 1;
	}
}

int stringTOlint(string s) {
	//string→lint
	lint Z = s.size();
	lint ret = 0;
	reverse(s);
	rep(i, Z) {
		ret += ((s[i] - '0') * pow(10, i));
	}
	return ret;
}

/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/

int main() {
	int ans = 0;
	int N;
	cin >> N;
	string S = to_string(N);
	int Z = S.size();
	vector<char>V(Z);
	rep(i, pow(3,Z)) {
		int I = i;
		rep(j, Z) {
			if (I % 3 == 0) {
				V[j] = '3';
			}
			else if (I % 3 == 1) {
				V[j] = '5';
			}
			else if (I % 3 == 2) {
				V[j] = '7';
			}
			I /= 3;
		}
		int v = 0;
		rep(j, Z) {
			v += (V[j]-'0') * pow(10, j);
		}
		int cnt3 = 0, cnt5 = 0, cnt7 = 0;
		rep(j, Z) {
			if (V[j] == '3') {
				cnt3++;
			}
			else if (V[j] == '5') {
				cnt5++;
			}
			else if (V[j] == '7') {
				cnt7++;
			}
		}
		if (v <= N && (cnt3 && cnt5 && cnt7)) {
			/*rep(j, Z) {
				cout << V[j] << ' ';
			}
			cout <<v<< endl;*/
			ans++;
		}
	}
	rep(i, Z - 1) {
		int I = i+1;
		ans += (pow(3, I) - 3 * pow(2, I) + 3);
	}
	cout << ans << endl;
}


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

int main() {
  
  int N;
  cin >> N;
  
  for (int i = 0; i < N; i++){
    
    string S;
    cin >> S; 
   
   if (i < N -2 && S != "Y"){
     continue;
   }
   
   else if (S == "Y"){
     cout << "Four" << endl;
     break;
   }    
    
   if (i == N-1 && S != "Y"){
     cout << "Three" << endl;
   } 
  }
}

Measured memory_bytes: 256
n = int(input())

l = [[0]*10 for _ in range(10)]

for i in range(1, n+1):
    l[int(str(i)[0])][(i % 10)] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += l[i][j] * l[j][i]

print(ans)

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

int main() {
    int x; cin >> x;
	if(x < 600) { cout << 8 << '\n';}
	else if(x < 800) {cout << 7 << '\n';}
	else if(x < 1000) {cout << 6 << '\n';}
	else if(x < 1200) {cout << 5 << '\n';}
	else if(x < 1400) {cout << 4 << '\n';}
	else if(x < 1600) {cout << 3 << '\n';}
	else if(x < 1800) {cout << 2 << '\n';}
	else if(x < 2000) {cout << 1 << '\n';}
}



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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    string s; cin >> s;
    if (s == "RRR") cout << "3\n";
    else if (s.substr(0, 2) == "RR" || s.substr(1, 2) == "RR") cout << "2\n";
    else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout << "1\n";
    else cout << "0\n";
}

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

int main(){
	int max1=-1,max2=-1,max3=-1;
	for(int i=0;i<10;i++){
		int n;
		cin >> n;
		if (max1<n){
			max3=max2;
			max2=max1;
			max1=n;
		}
		else if (max2<n){
			max3=max2;
			max2=n;
		}
		else if (max3<n){
			max3=n;
	}
	}
	cout << max1 << endl <<max2 <<endl << max3 <<endl; 
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct BIT {
    int N;
    vector<int> bit;

    void init(int _n){
        N = _n;
        bit.resize(_n+1, 0);
    }

    int getSum(int i) {  // i番目までの要素の和を求める(1-index)
        int sum = 0;
        while (i > 0) {
            sum += bit[i];
            i -= i & -i;
        }
        return sum;
    }
    void add(int i, int x) {  // i番目の要素にxを加算
        while (i <= N) {
            bit[i] += x;
            i += i & -i;
        }
    }
};

int main() {
    ll n, k, ans = 0;
    cin >> n >> k;
    vector<ll> a(n+1), pos(n+1);
    vector<P> v(n+1);
    for(int i=0;i<n;i++){
        cin >> a[i+1];
        a[i+1] -= k;
        a[i+1] += a[i];
        v[i+1] = P(a[i+1],i+1);
    }
    sort(v.begin(), v.end());
    for(int i=0;i<=n;i++){
        pos[v[i].second] = i+1;
    }
    BIT bit;
    bit.init(n+2);
    for(int i=0;i<=n;i++){
        int id = pos[i];
        ans += bit.getSum(id);
        bit.add(id, 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == '1') {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
program template_matching
  implicit none
  character(50) :: s
  integer :: n, m, a(50,50) = 0, b(50,50) = 0, i, j
  read(*,*) n, m
  do i = 1, n
    read(*,*) s
    s = trim(adjustl(s))
    do j = 1, n
      if (s(j:j) == "#") a(i,j) = 1
    end do
  end do
  do i = 1, m
    read(*,*) s
    s = trim(adjustl(s))
    do j = 1, m
      if (s(j:j) == "#") b(i,j) = 1
    end do
  end do
  do i = 1, n-m+1
    do j = 1, n-m+1
      if (sum(abs(a(i:i+m-1,j:j+m-1)-b(1:m,1:m))) == 0) then
        write(*,'(a)') "Yes"
        stop
      end if
    end do
  end do
  write(*,'(a)') "No"
  stop
end program template_matching

Measured memory_bytes: 256
import heapq
from collections import defaultdict
n, m =map(int, input().split())
a=list(map(int, input().split()))

for i in range(n):
  a[i] *= -1


pri=list(set(a))
heapq.heapify(pri)
dict=defaultdict(int)
for i in a:
  dict[-i] += 1
for i in range(m):
  b, c = map(int, input().split())
  dict[c] += b
  heapq.heappush(pri,-c)
# print (pri)
# print (dict)

ans = 0
cnt = 0
old = 0
while True:
  x = heapq.heappop(pri)
  x *= -1
  if old == x:
    continue
  if cnt+dict[x] > n:
    ans += (n-cnt)*x
    cnt += n-cnt
  else:
    ans += dict[x]*x
    cnt += dict[x]
  if cnt >= n:
    break
  old = x
print (ans)


Measured memory_bytes: 43164
x, n, = map(int, input().split())
p = list(map(int, input().split()))
#print("p = {}".format(p))

ret = 0
diff = 0
flag = False
while True:
    flag = False
    ret = x - diff
    #print("ret = {}".format(ret))
    for i in p:
        if i == ret:
            flag = True
            break
    if flag == False:
        break

    flag = False    
    ret = x + diff
    #print("ret = {}".format(ret))
    for i in p:
        if i == ret:
            flag = True
            break
    if flag == False:
        break

    diff += 1

print("{}".format(ret))

Measured memory_bytes: 9228
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=998244353;
const int N=8010, M=205, LOG=14, NN=(1<<LOG);

ll n, m, k, u, v, x, y, t, a, b, ans;
ll F[N], I[N], A[NN], B[NN];
int rev[NN];
ll dp[M][N];

ll powmod(ll a, ll b){
	ll res=1;
	for (; b; b>>=1, a=a*a%mod) if (b&1) res=res*a%mod;
	return res;
}
ll nCr(ll n, ll r){
	if (r<0 || r>n) return 0;
	return F[n]*I[r]%mod*I[n-r]%mod;
}
inline void NTT(ll *A, bool inv){
	for (int i=1; i<NN; i++) if (rev[i]<i) swap(A[rev[i]], A[i]);
	for (int ln=1; ln<NN; ln<<=1){
		ll wn=powmod(3, mod/ln/2);
		if (inv) wn=powmod(wn, mod-2);
		for (int i=0; i<NN; i+=2*ln){
			ll w=1;
			for (int j=i; j<i+ln; j++){
				ll a=A[j], b=A[j+ln]*w;
				A[j]=(a+b)%mod;
				A[j+ln]=(a-b)%mod;
				w=w*wn%mod;
			}
		}
	}
	if (inv){
		ll invn=powmod(NN, mod-2);
		for (int i=0; i<NN; i++) A[i]=A[i]*invn%mod;
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	F[0]=1;
	for (int i=1; i<N; i++) F[i]=F[i-1]*i%mod;
	I[N-1]=powmod(F[N-1], mod-2);
	for (int i=N-1; i; i--) I[i-1]=I[i]*i%mod;
	for (int i=1; i<NN; i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(LOG-1));
	
	cin>>n>>m;
//	assert(n<=300);
	dp[0][0]=1;
	for (int i=1; i<=m; i++){
		memset(A, 0, sizeof(A));
		memset(B, 0, sizeof(B));
		for (int j=0; j<=n; j++) A[j]=dp[i-1][j]*I[j]%mod;
		for (int j=0; j<=n; j++) B[j]=I[j+2];
		
		NTT(A, 0);
		NTT(B, 0);
		for (int j=0; j<NN; j++) A[j]=A[j]*B[j]%mod;
		NTT(A, 1);
		for (int j=1; j<=n; j++) dp[i][j]=A[j]*F[j+2]%mod;
		for (int j=1; j<=n; j++) dp[i][j]=(dp[i][j] - dp[i-1][j]*(j+1))%mod;
	}
	for (int i=0; i<=m; i++) for (int j=0; j<=n; j++)
		ans=(ans + nCr(m, i)*nCr(n, j)%mod*dp[i][j])%mod;
	if (ans<0) ans+=mod;
	cout<<ans<<"\n";
	
	return 0;
}


Measured memory_bytes: 16464
#include <cstdio>
#include <algorithm>
#include <cstring>
#define INF 0x3f3f3f3f

using namespace std;
const int maxn = 1024;

char s[maxn], t[maxn];
int lens, lent, ans = INF;

int match(int l) {
    int numdiff = 0;
    for (int i = 0; i < lent; i++) {
        if (s[l + i] != t[i]) numdiff++;
    }
    return numdiff;
}

int main() {
    scanf("%s", s);
    scanf("%s", t);
    lens = strlen(s);
    lent = strlen(t);
    for (int i = 0; i + lent <= lens; i++) {
        ans = min(ans, match(i));
    }
    printf("%d\n", ans);
    return 0;
}

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

int solve(int, int, int*, int*, int);
int main(){
  int n; cin >> n;

  int a1[n], a2[n];
  for(int i=0; i<n; i++) cin >> a1[i];
  for(int i=0; i<n; i++) cin >> a2[i];

  cout << solve(0, 0, a1, a2, n) << endl;

  return 0;
}

int solve(int x, int y, int* a1, int* a2, int n){
  if(x>=n || y>=2) return 0;
  if(x==n-1 && y==1) return a2[x];
  if(y==0) return max(solve(x+1, y, a1, a2, n), solve(x, y+1, a1, a2, n))+a1[x];
  else return max(solve(x+1, y, a1, a2, n), solve(x, y+1, a1, a2, n))+a2[x];

}


Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int a,b,c;
	cin>>a>>b>>c;
	cout<<((a+b==c||a+c==b||b+c==a)?"Yes":"No");
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3640
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    string s;
    string t;
    cin >> s >> t;

    //0-indexedで、
    //dp[i][j] := sの先頭から(i - 1)文字目まで、tの先頭から(j - 1)文字目までのLCSの長さ
    vvll dp(s.size() + 1, vll(t.size() + 1));

    rep(i, s.size())
    {
        rep(j, t.size())
        {
            if (s[i] == t[j]) chmax(dp[i + 1][j + 1], dp[i][j] + 1);

            if(j > 0) chmax(dp[i + 1][j + 1], dp[i + 1][j]);
            if(i > 0) chmax(dp[i + 1][j + 1], dp[i][j + 1]);
        }
    }

    //DPの結果から文字列を逆算
    string ans;
    ll length = dp[s.size()][t.size()];

    int istart = s.size() - 1;
    int jstart = t.size() - 1;

    for(int i = istart; i>=0 ;i--)
    {
        for (int j = jstart; j >= 0; j--)
        {
            if (dp[i][j] == length - 1 && s[i] == t[j])
            {
                ans += t[j];
                length--;
                jstart--;
                break;
            }
        }
    }
    
    reverse(all(ans));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
#define LL long long
#define M(a,b) memset(a,b,sizeof a)
#define pb(x) push_back(x)
using namespace std;
const int maxn=2e3+9;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
int n,t,z,w,a[maxn];
int main()
{
    scanf("%d%d%d",&n,&z,&w);
    for(int i=0; i<n; i++)scanf("%d",&a[i]);
    if(n==1)
    {
        printf("%d\n",abs(a[0]-w));
        return 0;
    }
    if(abs(a[n-1]-w)>abs(a[n-1]-a[n-2]))z=a[n-1];
    else w=a[n-1],z=a[n-2];
    printf("%d\n",abs(z-w));
}


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<long> P(M),Y(M);
  for(int i=0; i<M; i++){
    cin >> P.at(i) >> Y.at(i);
  }
  
  vector<vector<pair<long,int>>> S(N);
  for(int i=0; i<M; i++){
    S.at(P.at(i)-1).push_back(make_pair(Y.at(i),i));
  }
  for(int i=0; i<N; i++){
    sort(S.at(i).begin(),S.at(i).end());
  }
  vector<pair<int,int>> T(M);
  for(int i=0; i<N; i++){
    for(int j=0; j<S.at(i).size(); j++){
      T.at(S.at(i).at(j).second)=make_pair(S.at(i).at(j).second,j+1);
    }
  }
  sort(T.begin(),T.end());
  for(int i=0; i<M; i++){
    if(P.at(i)/10==0){
      cout << "00000";
    }
    else if(P.at(i)/100==0){
      cout << "0000";
    }
    else if(P.at(i)/1000==0){
      cout << "000";
    }
    else if(P.at(i)/10000==0){
      cout << "00";
    }
    else if(P.at(i)/100000==0){
      cout << "0";
    }
    cout << P.at(i)*1000000+T.at(i).second << endl;
  }
}

Measured memory_bytes: 9344
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    K = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=0
    for a in A:
        ans+=2*min(a,K-a)
    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 10164
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
int main()
{
    	char x,y;
    	scanf("%c %c",&x,&y);
    	if(x<y){
    		printf("<\n");
    	}
    	else if(x==y){
    		printf("=\n");
    	}
    	else{
    		printf(">\n");
    	}
    	return 0;

}


Measured memory_bytes: 3680
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<pair<string, int>> SP(N);
    vector<pair<string, int>> SP2(N);
    for (int i = 0; i < N; i++) {
        cin >> SP[i].first >> SP[i].second;
        SP2[i].first = SP[i].first;
        SP2[i].second = SP[i].second;
    }
    sort(SP2.begin(), SP2.end());
    /*for (int i = 0; i < N; i++) {
      	cout << SP2[i].first << " " << SP2[i].second << endl;
    }*/

    int ans = 0;
    string res = SP2[0].first;
    vector<int> cnt = {};
    for (int i = 0; i < N; i++) {
        if (SP2[i].first != res) {
            //for (int i = 0; i < cnt.size(); i++) cout << cnt[i] << endl;
            sort(cnt.begin(), cnt.end());
            reverse(cnt.begin(), cnt.end());
            for (int j = 0; j < cnt.size(); j++) {
				for (int k = 0; k < N; k++) {
                  	if (res == SP[k].first && cnt[j] == SP[k].second) { 
                      	cout << k + 1 << endl;
                      	break;
                    }
                }
            }
            res = SP2[i].first;
            cnt = {};
        }
        cnt.push_back(SP2[i].second);
    }
            sort(cnt.begin(), cnt.end());
            reverse(cnt.begin(), cnt.end());
            for (int j = 0; j < cnt.size(); j++) {
				for (int k = 0; k < N; k++) {
                  	if (res == SP[k].first && cnt[j] == SP[k].second) { 
                      	cout << k + 1 << endl;
                      	break;
                    }
                }
            }
}

Measured memory_bytes: 256
N,H=gets.split.map(&:to_i)
as,bs=N.times.map{gets.split.map(&:to_i)}.transpose
as_max=as.max
bs.delete_if{|e|e<=as_max}
bs.sort!
bs.reverse!
damage=0
attack=0
bs.each do |e|
  attack+=1
  damage+=e
  if H<=damage
    puts attack
    exit
  end
end
attack+=((H-damage)/as_max.to_f).ceil
puts attack


Measured memory_bytes: 13180