akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;

public class Main {

    static class edge{
        int from, to;
        long cost;
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
//        String[] str = br.readLine().split(" ");

        ArrayList<edge>[] es  = new ArrayList[n];
        for(int i=0; i<n; i++) es[i] = (new ArrayList<>());

        for (int i=0; i<n-1; i++) {
            String[] str = br.readLine().split(" ");
            edge ed_f = new edge();
            int a = Integer.parseInt(str[0]) - 1;
            int b = Integer.parseInt(str[1]) - 1;
            long c = Long.parseLong(str[2]);
            ed_f.from = a;
            ed_f.to = b;
            ed_f.cost = c;
            es[a].add(ed_f);

            edge ed_b = new edge();
            ed_b.from = b;
            ed_b.to = a;
            ed_b.cost = c;
            es[b].add(ed_b);

        }
        String[] str = br.readLine().split(" ");
        int q = Integer.parseInt(str[0]);
        int k = Integer.parseInt(str[1]);

        PriorityQueue<long[]> dist = new PriorityQueue<>((long[] le, long[] ri) -> (int)(le[0] - ri[0]));
        long[] vertex = new long[2];
        vertex[0] = 0;
        vertex[1] = k-1;
        dist.add(vertex);

        long[] len = new long[n];
        Arrays.fill(len, Long.MAX_VALUE);
        len[k-1] = 0;

        while(!dist.isEmpty()){
            vertex = dist.poll();

            long u = vertex[1];
            for (Object ed: es[(int)u]){
                if(len[((edge) ed).from] + ((edge) ed).cost < len[((edge) ed).to]) {
                    len[((edge) ed).to] = len[((edge) ed).from] + ((edge) ed).cost;
                    long[] p = new long[2];
                    p[0] = len[((edge) ed).to];
                    p[1] = ((edge) ed).to;
                    dist.add(p);
                }
            }
        }

        for(int i=0; i<q;i ++){
            long length = 0;
            str = br.readLine().split(" ");
            int st = Integer.parseInt(str[0]);
            int ed = Integer.parseInt(str[1]);
            length += len[st-1] + len[ed-1];
            System.out.println(length);
        }
    }
}

Measured memory_bytes: 80764
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
using ll = long long;
//#define int ll
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
signed main(){
    string s;
    int n;
    int b;cin>>n>>b;
    n*=b;
    if(n%2)cout<<"Odd"<<endl;
    else cout<<"Even"<<endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

typedef complex<double> C;
typedef pair<C,C> pp;
typedef vector<C> VP;
typedef vector<pp> VPP;
#define eq(a,b) (fabs(a-b)<eps)
#define veq(a,b) (eq(a.real(),b.real())&&eq(a.imag(),b.imag()))
const C O{0,0};

void In(C& p){
	double x,y;
	cin>>x>>y;
	p=C(x,y);
}

void Out(C p){
	cout<<(int)p.real()<<' '<<(int)p.imag()<<endl;
}

double Dot(C p,C q){
	return p.real()*q.real()+p.imag()*q.imag();
}

double Det(C p,C q){
	return p.real()*q.imag()-q.real()*p.imag();
}

double Triangle(C A,C B,C C){
	return fabs(Det(B-A,C-A))/2;
}

double Area(VP p){
	double sum=0;
	int N=p.size();
	for(int i=0;i<N;i++){
		C A=p[i],B=p[(i+1)%N];
		sum+=Triangle(O,A,B)*(Det(A,B)>0?1:-1);
	}
	return sum;
}

int n;
VP a;

int main(){
	cin>>n;
	a=VP(n);
	for(auto &i:a) In(i);
	cout<<syosu(1)<<Area(a)<<endl;
}


Measured memory_bytes: 3272
#include <stdio.h>
int main(void){
    int n,l,tmp,i,flag;
    int ng[11],check[11]={0};
    scanf("%d %d",&n,&l);
    for(i=0;i<l;i++){
        scanf("%d",&ng[i]);
        check[ng[i]]=1;
    }
    for(i=n;;i++){
        tmp = i;
        flag = 1;
        for(;;){
            if(tmp==0) break;
            if(check[tmp%10]==1){
                flag=0;
                break;
            }
            tmp/=10;
        }
        if(flag==1){
            printf("%d\n",i);
            break;
        }
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define ll long long
#define INF 1000000007
using P = pair<int, int>;
int main(){
    int n,m;
    cin>>n>>m;
    vector<bool> f(n);
    vector<bool> b(n);
    for(int i=0;i<m;i++){
        int a,c;
        cin>>a>>c;
        if(a==1)f[c-1]=true;
        if(c==n)b[a-1]=true;
    }
    bool ans=false;
    for(int i=0;i<n;i++)if(f[i]==true&&b[i]==true){
        ans=true;
        break;
    }
    if(ans==true)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int q = sc.nextInt();
			TreeSet<Integer> s = new TreeSet<>();
			for(int i = 0; i < q; i++) {
				int query = sc.nextInt();
				switch(query) {
				case 0:
					s.add(sc.nextInt());
					System.out.println(s.size());
					break;
				case 1:
					System.out.println(s.contains(sc.nextInt())?"1":"0");
					break;
				case 2:
					s.remove(sc.nextInt());
					break;
				case 3:
					Set<Integer> sub = s.subSet(sc.nextInt(), true, sc.nextInt(), true);
					for (Integer e : sub) System.out.println(e);
				}
			}
		}
	}
}


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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    cout << S.substr(0, S.length() - 8) << endl;

    return 0;
}


Measured memory_bytes: 256
//Md. Shajibul Islam..
//East West University, CSE Department'19

#include<bits/stdc++.h>
using namespace std;
#define FAST             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define loop(i,n)        for(int i=0;i<n;i++)
#define CASE_PRINT       cout<<"Case "<<C<<": "
#define CASE_PRINT2      cout<<"Case "<<C<<":"<<endl
#define ll               long long
#define ld               long double
#define Pi               2*acos(0.0) // acos(-1.0)

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

    if(s[s.size()-1]=='s')cout<<s<<'e'<<'s'<<endl;
    else cout<<s<<'s'<<endl;
}





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

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

    ll A, B;
    char op;

    cin >> A >> op >> B;

    if(op == '+') cout << A + B << endl;
    else cout << A - B << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n, 0);
    rep(i, m){
        int b, c;
        cin >> b >> c;
        --b;
        --c;
        ++a[b];
        ++a[c];
    }
    repi(i, a){
        cout << *i << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
using namespace std;
typedef pair<int, int> P;

const int INF=9999999;
char map[1005][1005];
int d[1005][1005];
int n, m, xx;
int res;
int sx, sy;
int gx, gy;
int x[10];
int y[10];
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
queue<P> s;
int bfs()
{
    while(!s.empty()){
        s.pop();
    }
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
          d[i][j]=INF;
    s.push(P(sx, sy));
    d[sx][sy]=0;
    while(!s.empty())
    {
        P tmp= s.front();
        s.pop();
        if(tmp.first==gx && tmp.second==gy)
        {
            break;
        }
        for(int i=0; i<4; i++)
        {
            int nx = tmp.first+dx[i];
            int ny = tmp.second+dy[i];
            if(nx>=0 && nx<n && ny>=0 && ny<m && map[nx][ny]!='X' &&d[nx][ny]==INF)
            {
                s.push(P(nx, ny));
                d[nx][ny]=d[tmp.first][tmp.second]+1;
            }
        }
    }
    return d[gx][gy];
}

int main()
{
    while(scanf("%d%d%d", &n, &m, &xx)!=EOF)
    {
        for(int i=0; i<n; i++)
            scanf("%s", map[i]);
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
            {
              if(map[i][j]=='S')
              {
                  sx=i; sy=j;
              }
              if(map[i][j]=='1')
              {
                  x[1]=i;
                  y[1]=j;
              }
              if(map[i][j]=='2')
              {
                  x[2]=i;
                  y[2]=j;
              }
              if(map[i][j]=='3')
              {
                  x[3]=i;
                  y[3]=j;
              }
              if(map[i][j]=='4')
              {
                  x[4]=i;
                  y[4]=j;
              }
              if(map[i][j]=='5')
              {
                  x[5]=i;
                  y[5]=j;
              }
              if(map[i][j]=='6')
              {
                  x[6]=i;
                  y[6]=j;
              }
              if(map[i][j]=='7')
              {
                  x[7]=i;
                  y[7]=j;
              }
              if(map[i][j]=='8')
              {
                  x[8]=i;
                  y[8]=j;
              }
              if(map[i][j]=='9')
              {
                  x[9]=i;
                  y[9]=j;
              }

            }
            res=0;
            gx=x[1]; gy=y[1];
            res+=bfs();
            for(int i=2; i<=xx; i++)
            {
                sx=gx; sy=gy;
                gx=x[i]; gy=y[i];
                res+=bfs();
            }
        printf("%d\n", res);

    }
    return 0;
}

Measured memory_bytes: 5980
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int a, b;
	cin >> a >> b;
	if (a <= b) cout << "unsafe";
	else cout << "safe";
}


Measured memory_bytes: 3096
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={0,31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
ll a[10010],v[10010];
ll n,k,res=-1000000007;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>v[i];
	for(int i=1;i<=n;i++){
		int x=i,l=0;
		ll s=0,num=0;
		do{
			l++;
			x=a[x];
			s+=v[x];
			num+=v[x];
			if(l<=k){
				res=max(res,num);
			}
		}while(x!=i);
		num=0;
		if(k>=l&&s>0){
			for(int j=1;j<l+1;j++){
				x=a[x];
				num+=v[x];
				res=max(res,num+s*((k-j)/l));
			}
		}
	}
	cout<<res;
	return 0;
}




Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if(c >= a && c <= b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
V = list(map(int,input().split()))
Ve = V[::2]
Vo = V[1::2]
from collections import Counter


Ve = list(Counter(Ve).items())
Ve.sort(key = lambda x:x[1], reverse = 1)
Vo = list(Counter(Vo).items())
Vo.sort(key = lambda x:x[1], reverse = 1)

if Ve[0][0] == Vo[0][0]:
  if len(Ve) == len(Vo) == 1:
    print(n//2)
  else:
    print(n - max(Ve[0][1]+Vo[1][1], Ve[1][1]+Vo[0][1]))
else:
  print(n-Ve[0][1]-Vo[0][1])

Measured memory_bytes: 63724
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


N, x = map(int, input().split())
a = list(map(int, input().split()))


a.sort()


i = 0
s = 0
while (i<N) and (s <= x):
    s += a[i]
    i += 1


if i == N:
    if sum(a) == x:
        print(N)
    else:
        print(N-1)
else:
    print(i-1)


Measured memory_bytes: 38384
n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
mask = n2 - 1

dp = [[a, 0] for a in aaa]


def update(dp, i, k):
    dpi, dpk = dp[i], dp[k]
    if dpk[0] < dpi[0]:
        dpk[1] = max(dpk[0], dpi[1])
        dpk[0] = dpi[0]
    elif dpk[1] < dpi[0]:
        dpk[1] = dpi[0]


for j in range(n):
    b = 1 << j
    c = i = mask ^ b
    while i:
        update(dp, i, i | b)
        i = (i - 1) & c
    update(dp, 0, b)

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a[0] + a[1])
    ans.append(tmp)
print(*ans)


Measured memory_bytes: 58652
#include <iostream>

using namespace std;

int main(){
  int r, g,b;
  cin >> r >> g>> b;
  if((100*r + 10*g + b)%4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
	int n;
	vector<int> train;
	while (cin>>n) {
		if (n != 0) {
			train.emplace_back(n);
		}
		else {
			cout << train.back() << endl;
			train.pop_back();
		}
	}
	return 0;
}

Measured memory_bytes: 3148
n,m,X=map(int,input().split())
c=[list(map(int,input().split())) for i in range(n)]
ans=float('inf')
from itertools import combinations as com
for l in range(1,n+1):
    for i in com(list(range(n)),r=l):
        cnt=[0]*m
        p=0
        for j in i:
            p+=c[j][0]
            for x in range(m):
                cnt[x]+=c[j][x+1]
        if min(cnt)>=X:ans=min(ans,p)
print(ans if ans!=float('inf')else -1)

Measured memory_bytes: 9116
using System;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            double A, B, H, M;
            double xH, yH, xM, yM;
            double dH, dM;
            string[] str = Console.ReadLine().Split(' ');
            A = double.Parse(str[0]);
            B = double.Parse(str[1]);
            H = double.Parse(str[2]);
            M = double.Parse(str[3]);
            dH = (double)((H * 30 + M / 2) * (Math.PI / 180));
            dM = (double)(M * (Math.PI / 30));
            xH = A * Math.Cos(dH);
            yH = A * Math.Sin(dH);
            xM = B * Math.Cos(dM);
            yM = B * Math.Sin(dM);
            //Console.WriteLine(dH);
            double distance = Math.Sqrt((xM - xH) * (xM - xH) + (yM - yH) * (yM - yH));
            Console.WriteLine(distance);
        }
        
    }
}


Measured memory_bytes: 27936
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n, t; cin >> n >> t;
    int a[100010]; rep(i,0,n) cin >> a[i];
    reverse(a, a+n);
    set<int> s;

    int ma = a[0], val = 0, ans = 0;
    rep(i,0,n) {
        if(val < ma - a[i]) {
            ans = 1;
            val = ma - a[i];
        }
        else if(s.count(a[i] + val)) ans++;
        s.insert(a[i]);
        ma = max(ma, a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, ans = 0;
char A[105], B[105], C[105];

int main(){
	getint(N), scanf("%s%s%s", A + 1, B + 1, C + 1);
	for(register int i = 1; i <= N; i++){
		if(A[i] == B[i] && B[i] == C[i]) continue;
		else if(A[i] == B[i] || B[i] == C[i] || C[i] == A[i]) ans++;
		else ans += 2;
	}
	return printf("%d\n", ans), 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q,K,R,W,H;
string S,T;
ll ans;
ll x[1000000];
ll y[1000000];
ll a[1000000];
ll b[1000000];
ll c[1000000];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;
int main() {
	char c;
	cin>>W>>H>>c;
	rep(i,0,H){
		rep(j,0,W){
			if((i==0||i==H-1)&&(j==0||j==W-1))
				cout<<'+';
			else if(j== 0 || j== W-1)
				cout<<'|';
			else if(i== 0 || i == H-1)
				cout<<'-';
			else if(i==H/2 && j ==W/2)
				cout<<c;
			else
				cout<<'.';
		}
		cout<<endl;
	}
	return 0;
}



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

int hex2digit(const char x) {
    int res = 0;
    if ('0' <= x && x <= '9') {
        res += x - '0';
    } else if ('a' <= x && x <= 'f') {
        res += x - 'a' + 10;
    }
    return res;
}

int main() {
    const int red[] = {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, };
    const int green[] = {0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, };
    const int blue[] = {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, };
    const char* color[] = {
        "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white",
    };
    while (true) {
        char input[8];
        cin >> input;
        if (input[0] == '0') {
            break;
        }
        int k = 0,
            r = hex2digit(input[1]) * 16 + hex2digit(input[2]),
            g = hex2digit(input[3]) * 16 + hex2digit(input[4]),
            b = hex2digit(input[5]) * 16 + hex2digit(input[6]);
        double minD = 1000000;
        for (int i = 0; i < (int) sizeof red / (int) sizeof *red; i++) {
            double d = sqrt(pow(r - red[i], 2) + pow(g - green[i], 2) + pow(b - blue[i], 2));
            if (d < minD) {
                minD = d;
                k = i;
            }
        }
        cout << color[k] << endl;
    }
}

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

int H, W, d1[2009][2009], d2[2009][2009], d3[2009][2009], d4[2009][2099];
char c[2009][2009];

int main() {
	cin >> H >> W;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) cin >> c[i][j];
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (c[i][j] == '#') d1[i][j] = 0;
			else d1[i][j] = d1[i][j - 1] + 1;
		}
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (c[i][j] == '#') d2[i][j] = 0;
			else d2[i][j] = d2[i - 1][j] + 1;
		}
	}
	for (int i = H; i >= 1; i--) {
		for (int j = W; j >= 1; j--) {
			if (c[i][j] == '#') d3[i][j] = 0;
			else d3[i][j] = d3[i][j + 1] + 1;
		}
	}
	for (int i = H; i >= 1; i--) {
		for (int j = W; j >= 1; j--) {
			if (c[i][j] == '#') d4[i][j] = 0;
			else d4[i][j] = d4[i + 1][j] + 1;
		}
	}

	int maxn = 0;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) maxn = max(maxn, d1[i][j] + d2[i][j] + d3[i][j] + d4[i][j] - 3);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 67840
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

ll dp[100001][13];

signed main(){
    string s;
    cin >> s;
    dp[0][0] = 1;
    REP(i,s.size()){
        if(s[i] == '?'){
            REP(j,10){
                REP(k,13){
                    dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
                    dp[i + 1][(k * 10 + j) % 13] %= MOD;
                }
            }
        }else{
            int c = s[i] - '0';
            REP(j,13){
                dp[i + 1][(j * 10 + c) % 13] = dp[i][j];
            }
        }
    }
    cout << dp[s.size()][5] << endl;
}

Measured memory_bytes: 10624
//  IT'S NEVER TOO LATE...

		    #include <bits/stdc++.h>
			#include <complex>
		    #define ll long long

			#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
			#define forn(i, n) fore(i, 0, n)
			#define fori(i, l, r) fore(i, l, (r) + 1)
			#define sz(v) int((v).size())
			#define all(v) (v).begin(), (v).end()
			#define pb push_back
			#define mp make_pair
		    #define ff first
		    #define ss second
			#define inf 1e9
		    
			#define C complex<int>
			#define X real()
			#define Y imag()

		    using namespace std; 

		    const double PI = atan(1)*4;

		    const int mod=1e9+7;


		    bool isprime(int n)
		    {
		        for(int i=2;i*i<=n;i++)
		            if(n%i==0)
		                return false;
		        return true;
		    }
		     
		    bool comp(pair<double,int> a, pair<double,int> b)
		    {
		    	if( b.ff == a.ff )
		    		return a.ss < b.ss ;
		    	return b.ff < a.ff ;
		    }

		    int modpow(int b,int p,int m)
		    {
		    	if(p==0) return 1%m;
		    	if(p%2) return (b*modpow(b,p-1,m))%m;
		    	int u=modpow(b,p/2,m);
		    	return (u*u)%m;
		    }

		    vector<int> ar[100005];
		    int vis[100005],from[100005];
		    double dis[100005];
		    
		     
		/*    void dikstra(int s,int n)
		    {
		    	forn(i,n+3)
		    	{
		    		dis[i]=inf;
		    		vis[i]=0;
		    		from[i]=-1;
		    	}

		    	dis[s]=0;
		    	priority_queue<pair<int,int>> q;
		    	q.push({0,s});
		    	from[s]=s;

		    	while(!q.empty())
		    	{
		    		pair<int,int> a;
		    		a=q.top();
		    		q.pop();
		    		//cout<<a.ss<<" ";

		    		if(vis[a.ss]) continue;
		    		vis[a.ss]=1;

		    		for(pair<int,int> b:ar[a.ss])
		    		{
		    			if(dis[b.ff]>dis[a.ss] + b.ss)
		    			{
		    				dis[b.ff]=dis[a.ss] + b.ss;
		    				from[b.ff]=a.ss;
		    				q.push({-dis[b.ff],b.ff});
		    			}
		    		}
		    	}
		    }*/


		    int main()
		    {
		    	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		     
		    	#ifndef ONLINE_JUDGE
		        freopen("input.txt","r", stdin);
		        freopen("output.txt", "w", stdout);
		        #endif
		     
		    	int tt=1;
		    	//cin>>tt;
		    	
		    	while(tt--)
		    	{
		    		int n;
		    		cin>>n;

		    		cout<<(1000-(n%1000))%1000;
		    	}

		    	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";

		    	return 0;
		    }
		    				//              NOW IT'S TIME TO WAKE UP...

Measured memory_bytes: 6152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxN = 55;
const int maxV = 90010;
//const int INF = 1e9+9;
const ll INF = (1ll)<<60;
const int MOD = 998244353;

int n;
int a[maxN];
int b[maxN];


int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++)
	{
		scanf("%d",&b[i]);
	}
	int m = 1<<n;
	int ans = 0;
	for(int i=0;i<m;i++)
	{
		int val = 0,cost = 0;
		for(int j=0;j<n;j++)
		{
			if(i>>j & 1)
			{
				val += a[j];
				cost += b[j];
			}
		}
		ans = max(ans,val - cost);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int64_t T;
    cin >> T;

    const vector<int64_t> v = { 2, 3, 5 };
    for (int64_t _ = 0; _ < T; _++) {
        int64_t N, D;
        vector<int64_t> costs(3);
        cin >> N >> costs[0] >> costs[1] >> costs[2] >> D;

        map<int64_t, int64_t> memo;
        function<int64_t(int64_t)> f = [&](int64_t x){
            if (x == 0) {
                return (int64_t)0;
            } else if (x == 1) {
                return D;
            } else if (memo.count(x)) {
                return memo[x];
            }

            int64_t ans = LLONG_MAX;

            //Dをx回
            //ここオーバーフローしかねないのでチェックをいれる
            if ((double)D * x <= 1e18) {
                ans = min(ans, D * x);
            }

            for (uint64_t i = 0; i < v.size(); i++) {
                int64_t target = v[i];
                int64_t cost = costs[i];

                //x以上でtargetで割り切れる一番小さい数
                int64_t up = (x + target - 1) / target * target;
                ans = min(ans, f(up / target) + cost + D * abs(up - x));

                //x以下でtargetで割り切れる一番大きい数
                int64_t down = x / target * target;
                ans = min(ans, f(down / target) + cost + D * abs(down - x));
            }

            return memo[x] = ans;
        };

        cout << f(N) << endl;
    }
}

Measured memory_bytes: 4368
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>

using namespace std;
int n;
long long a[100000]; // 10^5

bool check() {
  bool good = true;
  for (int i = 0; (i < n - 1) && good; i++) {
    good = (a[i] * a[i+1]) % 4 == 0;
  }
  return good;
}

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

  cin >> n;
  int twos = 0;
  int fours = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] % 4 == 0) {
      fours++;
    } else if (a[i] % 2 == 0) {
      twos++;
    }
  }

  bool good = true;

  if (twos != n) {
    if (twos > 0) {
      n -= twos - 1;
    }
    good = fours > 0 && fours >= n / 2;
  } else {
    good = twos > 1;
  }

  if (good) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}


Measured memory_bytes: 1024
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let a: usize = sc.read();
    let b: usize = sc.read();
    if a + b > n + 1 || (n + b - 1) / b > a {
        println!("-1");
        return;
    }

    let mut ans = (1..(n + 1)).collect::<Vec<_>>();
    let segments = (n + b - 1) / b;
    let mut remain = n - a;
    for i in 0..segments {
        let from = i * b;
        let to = cmp::min(from + cmp::min(b, remain + 1), n);
        ans[from..to].reverse();
        remain -= to - from - 1;
        if remain == 0 {
            break;
        }
    }

    assert_eq!(remain, 0);
    for i in 0..n {
        if i > 0 {
            print!(" ");
        }
        print!("{}", ans[i]);
    }
    println!();
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 10364
#include<bits/stdc++.h>
using namespace std;
#define N 1000005
#define ll long long
#define debug(a) cout<<#a<<": ";for(auto i:a)cout<<i<<" ";cout<<'\n';
#define trace(a) cout<<#a<<": "<<a<<"\n"
#define int ll
int a[N];
ll ps[N];
int n;
vector< vector<ll> > poss;
signed main() {
	ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
	int i,j,k,l,m,t;
	cin >> n;
	ll sum = 0;
	for(i = 1;i <= n;i++) {
		cin >> a[i];
		ps[i] = ps[i-1] + a[i];
		sum += a[i];
	}
	ll ans = 1e18;
	for(i = 2;i <= n-2;i++) {
		ll sum1 = ps[i];
		int lid[2],rid[2];
		int id = lower_bound(ps,ps+n,(sum1)/2) - ps;
		lid[0] = id;
		lid[1] = id-1;
		id = lower_bound(ps+i,ps+n,(ps[n] - ps[i])/2 + ps[i]) - ps;
		rid[0] = id;
		rid[1] = id-1;
		for(int j = 0;j < 2;j++) {
			for(int k = 0;k < 2;k++) {
				if(lid[j] < i && lid[j] > 0 && rid[k] > i && rid[k] < n) {
					vector<ll> v = {ps[lid[j]],ps[i] - ps[lid[j]], ps[rid[k]] - ps[i],ps[n] - ps[rid[k]]};
					sort(v.begin(),v.end());
					// trace(i);
					// debug(v);
					ans = min(ans,v[3] - v[0]);
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5888
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  int n;
  char s1[501],s2[501];
  scanf("%d",&n);
  int x = 200;
  while(true){
    bool flag = true;
    for(int i=0;i<4;i++){
      char res[3];
      if(i==0){
        s1[x] = '.';
        s2[x] = '.';
      }else if(i==1){
        s1[x] = '#';
        s2[x] = '.';
      }else if(i==2){
        s1[x] = '.';
        s2[x] = '#';
      }else if(i==3){
        s1[x] = '#';
        s2[x] = '#';
      }
      s1[x+1] = '\0';
      s2[x+1] = '\0';
      printf("%s\n%s\n", s1+200, s2+200); fflush(stdout);
      scanf("%s",res);
      if(res[0]=='T'){
        flag = false;
        x++;
        break;
      }
    }
    if(flag){
      s1[x] ='\0';
      s2[x] ='\0';
      break;
    }
  }
  x = 199;
  while(true){
    bool flag = true;
    for(int i=0;i<4;i++){
      char res[3];
      if(i==0){
        s1[x] = '.';
        s2[x] = '.';
      }else if(i==1){
        s1[x] = '#';
        s2[x] = '.';
      }else if(i==2){
        s1[x] = '.';
        s2[x] = '#';
      }else if(i==3){
        s1[x] = '#';
        s2[x] = '#';
      }
      printf("%s\n%s\n", s1+x, s2+x); fflush(stdout);
      scanf("%s",res);
      if(res[0]=='T'){
        flag = false;
        x--;
        break;
      }
    }
    if(flag) break;
  }
  return 0;
}


Measured memory_bytes: 504
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

using Weight = int;
using Flow = int;
struct Edge {
	int s, d; Weight w; Flow c;
	Edge() {};
	Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, int s, int d, Weight w = 1) {
	g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
	addArc(g, a, b, w);
	addArc(g, b, a, w);
}

vector<int> dijkstra(const Graph &g, int s, Array &dist) {
	int n = g.size();
	assert(s < n);
	enum { WHITE, GRAY, BLACK };
	vector<int> color(n, WHITE); color[s] = GRAY;
	vector<int> prev(n, -1);
	dist.assign(n, INF); dist[s] = 0;
	using State = tuple<Weight, int, int>;
	priority_queue<State, vector<State>, greater<State>> pq; pq.emplace(0, s, -1);
	while (pq.size()) {
		Weight d; int v, u; tie(d, v, u) = pq.top(); pq.pop();
		if (dist[v] < d)continue;
		color[v] = BLACK; prev[v] = u;
		for (auto &e : g[v]) {
			if (color[e.d] == BLACK)continue;
			if (dist[e.d] > dist[v] + e.w) {
				dist[e.d] = dist[v] + e.w;
				pq.emplace(dist[e.d], e.d, v);
				color[e.d] = GRAY;
			}
		}
	}
	return prev;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int w, h; cin >> w >> h && w;) {
		vector<vector<int>> v(h, vector<int>(w));
		rep(i, 0, h) rep(j, 0, w) { cin >> v[i][j]; }
		Graph g(w*h * 4);
		auto index = [&](int i, int j, int d) {return i*w + j + d*w*h; };
		auto inrange = [&](int i, int j) { return i >= 0 && i < h && j >= 0 && j < w; };
		vector<int> c(4); rep(i, 0, 4) {
			cin >> c[i];
		}

		static const int di[] = { 0,1,0,-1 };
		static const int dj[] = { 1,0,-1,0 };
		rep(i, 0, h)rep(j, 0, w) {
			rep(a, 0, 4) {
				rep(k, 0, 4) {
					int b = (a + k) % 4;
					int ni = i + di[b], nj = j + dj[b];
					if (!inrange(ni, nj))continue;
					if (k == v[i][j])
						addArc(g, index(i, j, a), index(ni, nj, b), 0);
					else
						addArc(g, index(i, j, a), index(ni, nj, b), c[k]);
				}
			}
		}
		int ans = INF;
		Array dist;
		dijkstra(g, index(0, 0, 0), dist);
		rep(b, 0, 4) {
			chmin(ans, dist[index(h - 1, w - 1, b)]);
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
  int n,x,d=0,ans=1;
  cin >> n >> x;
  vector<int> l(n);
  for(int i=0;i<n;i++) cin >> l.at(i);
  for(int i=0;i<n;i++) {
    d+=l.at(i);
    if(d<=x)ans++;
    else break;
  };
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 100000000001
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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


int main()
{
    set<string> se;
    int n;
    cin >> n;
    REP(i, n){
        string s;
        cin >> s;
        se.insert(s);
    }
    cout << se.size() << endl;
}


Measured memory_bytes: 19116
#include<cstdio>
#include<cmath>

int main(){
    double r;
    scanf("%lf",&r);
    double a,b;
    a = r * r * M_PI;
    b = 2.0 * r * M_PI;
    printf("%lf %lf\n",a,b);
    return 0;
}


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

using namespace std;

int main()
{
    int N;
    while (cin >> N) {
        vector<int> a(N);
        for (int i = 0; i < N; i++) {
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        int res = 0, sum = 0;
        for (int i = 0; i < N; i++) {
            sum += a[i];
            res += sum;
        }
        cout << res << endl;
    }        
    return 0;
}

Measured memory_bytes: 3084
while True:
  n=int(input())
  if n==0:
    break
  a=list(map(int,input().split()))
  x=[]
  for i in range(n):
    for j in range(i+1,n):
      b=a[i]-a[j]
      if b<0:
        b=b*(-1)
      x.append(b)
  print(min(x))


Measured memory_bytes: 27040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int N = 0;
		int M = 0;
		String s;
		Scanner sc = new Scanner(System.in);
		N = Integer.parseInt(sc.next());
		M = Integer.parseInt(sc.next());
		int i;
		int temp;
		int max = 100000, min = 0;
		for (i = 0; i < M; i++) {
			temp = Integer.parseInt(sc.next());
			if (min < temp) {
				min = temp;
			}
			temp = Integer.parseInt(sc.next());
			if (max > temp) {
				max = temp;
			}
		}
		int dif = max - min + 1;
		if (dif <= 0) {
			System.out.println("0");
		} else if (dif <= N) {
			System.out.println(dif);
		} else {
			System.out.println(N);
		}

	}

}

Measured memory_bytes: 47400
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 2e3+10;
LL dp[SIZE][SIZE],a[SIZE],b[SIZE];
int main(){
    int N,M;
    R(N,M);
    FOR(i,1,N)R(a[i]);
    FOR(i,1,M)R(b[i]);
    FOR(i,0,2000)dp[0][i]=dp[i][0]=1;
    FOR(i,1,N)FOR(j,1,M){
        dp[i][j]=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1];
        ADD(dp[i][j],0);
        if(a[i]==b[j])ADD(dp[i][j],dp[i-1][j-1]);
    }
    W(dp[N][M]);
    return 0;
}


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

int main()
{
    char b;
    cin >> b;
    if(b=='A') cout << 'T';
    if(b=='C') cout << 'G';
    if(b=='G') cout << 'C';
    if(b=='T') cout << 'A';
}


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

struct DSU {
	vector<int> par, rnk, sz; int c;
	DSU(int n) : par(n + 1), rnk(n + 1,0), sz(n + 1,1), c(n) {
		for (int i = 1; i <= n; ++i) par[i] = i;
	}
	int find(int i) { return (par[i] == i ? i : (par[i] = find(par[i]))); }
	bool same(int i, int j) { return find(i) == find(j); }
	int get_size(int i) { return sz[find(i)]; }
	int count() { return c; } //connected components
	int merge(int i, int j) {
		if ((i = find(i)) == (j = find(j))) return -1; else --c;
		if (rnk[i] > rnk[j]) swap(i, j);
		par[i] = j; sz[j] += sz[i];
		if (rnk[i] == rnk[j]) rnk[j]++;
		return j;
	}
};
int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	DSU d(n);
	while (m--) {
		int u, v; cin >> u >> v;
		d.merge(u, v);
	}
	cout << d.count() - 1 << '\n';
    return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

int main() {
    cin.sync_with_stdio(false);

    int n, l;
    cin >> n >> l;

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

    int sol = -1;
    for (int i = 0; i < n - 1; i++) {
        if (a[i] + a[i + 1] >= l) {
            sol = i + 1;
            break;
        }
    }

    if (sol == -1) {
        cout << "Impossible";
    } else {
        cout << "Possible\n";
        for (int i = 1; i < sol; i++) {
            cout << i << '\n';
        }
        for (int i = n - 1; i > sol; i--) {
            cout << i << '\n';
        }
        cout << sol;
    }

    return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);

        int n = stdIn.nextInt();
        int[] w = new int[n];
        for(int i=0; i<n; i++){
            w[i] = stdIn.nextInt();
        }

        int s = 0;
        int sSum = w[0];
        int g = n-1;
        int gSum = w[n-1];

        while(s+1 != g){
            if(sSum <= gSum){
                s++;
                sSum += w[s];
            }else{
                g--;
                gSum += w[g];
            }
        }

        System.out.println(Math.abs(sSum-gSum));
    }
}

Measured memory_bytes: 23252
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
void printvec(const vector<int> &v){
  REP(i,v.size()-1) cout << v[i] <<" ";
  cout << v.back() << endl;
}
signed main(){
  deque<int> dq;
  int q;
  cin >> q;
  REP(i,q){
    int d,p;
    cin >> d >> p;
    if(d==0){
      int x;
      cin >> x;
      if(p==0) dq.push_front(x);
      else dq.push_back(x);
    }else if(d==1){
      cout << dq[p] << endl;
    }else{
      if(p==0) dq.pop_front();
      else dq.pop_back();
    }
  }
}



Measured memory_bytes: 4628
my $n = <>;
my @sorted_a = sort { $a <=> $b } glob <>;

my @memo = ();

my %counter = ();
for my $cursor (@sorted_a) {
    ++$counter{$cursor};
    if($memo[$cursor] eq 'No') {
        next;
    }
    my $i = 2*$cursor;
    while($sorted_a[$n-1] >= $i) {
        $memo[$i] = 'No';
        $i += $cursor
    }
}

my $ans = grep { $memo[$_] ne 'No' && $counter{$_} == 1 } keys %counter;
print $ans;

Measured memory_bytes: 208744