akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;

/*
struct point
{
long long dist; long long name;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
*/


ll const MAX = 800010; //4倍に取っておく
ll segtree[MAX];

//演算
ll op(ll x, ll y) {
	return max(x, y);
}
//init valueの変更を忘れない
ll const INIT_VALUE = 0;
ll n_ = 1;

void init(ll n) {
	while (n_ <= n) {
		n_ *= 2;
	}
	REP(i, 1, n_ * 2) {
		segtree[i] = INIT_VALUE;
	}
}

//k番目をxでupdate
void update(ll k, ll x) {
	k += n_;
	segtree[k] = x;
	while (k >= 1) {
		k /= 2;
		segtree[k] = op(segtree[k * 2], segtree[k * 2 + 1]);
	}
}

ll val_o(ll a, ll b, ll k, ll l, ll r) {
	if (a <= l && r <= b) {
		return segtree[k];
	}
	else if (r <= a || b <= l) {
		//ここの値注意
		return -1e18;
	}
	else {
		ll x1 = val_o(a, b, k * 2, l, (l + r) / 2);
		ll x2 = val_o(a, b, k * 2 + 1, (l + r) / 2, r);
		return op(x1, x2);
	}

}

//[a,b)のvalueを求める
ll val(ll a, ll b) {
	return val_o(a, b, 1, 0, n_);
}
ll const MAX_A = 2e5 + 5;
ll a[MAX_A];
ll h[MAX_A];
int main() {
	ll n;
	cin >> n;
	init(n);
	REP(i, 1, n) {
		cin >> h[i];
	}
	REP(i, 1, n) {
		cin >> a[i];
	}
	ll ans = 0;
	REP(i, 1, n) {
		ll x = a[i] + val(0, h[i]);
		update(h[i], x);
		ans = max(ans, x);
	}
	cout << ans << endl;
}

Measured memory_bytes: 8448
n = int(input())
s = input()

type_num = 0
for i in range(1,n):
    left_s = list(set(s[0:i]))
    right_s = list(set(s[i:n]))
    
    tmp = 0
    for j in left_s:
        if j in right_s:
            tmp += right_s.count(j)
            type_num = max(type_num, tmp)
print(type_num)

Measured memory_bytes: 3064
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;

#define mid (l+r>>1)
#define ls o<<1
#define rs o<<1|1
int t[N<<2],laz[N<<2],f[N],gan[N];
const int mod=998244353;
void up(int o,int l,int r){
  int ri=r-mid;
  t[o]=(1ll*t[ls]*f[ri]+t[rs])%mod;
}
void gao(int o,int l,int r,int z){
  t[o]=1ll*z*gan[r-l+1]%mod;
}
void pd(int o,int l,int r){
  if(laz[o]){
    laz[ls]=laz[o];
    gao(ls,l,mid,laz[o]);
    laz[rs]=laz[o];
    gao(rs,mid+1,r,laz[o]);
    laz[o]=0;
  }
}
void up(int o,int l,int r,int x,int y,int z){
  if(l>=x&&r<=y){
    gao(o,l,r,z);
    laz[o]=z;
    return;
  }
  pd(o,l,r);
  if(x<=mid)up(ls,l,mid,x,y,z);
  if(y>mid)up(rs,mid+1,r,x,y,z);
  up(o,l,r);
}
void build(int o,int l,int r){
  if(l==r){
    t[o]=1;
    return ;
  }
  build(ls,l,mid);
  build(rs,mid+1,r);
  up(o,l,r);
}
int n,q;
int main() {
  ios::sync_with_stdio(false);
  cin>>n>>q;
  f[0]=1;
  for(int i=1;i<=n;i++){
    f[i]=1ll*f[i-1]*10%mod;
    gan[i]=(1ll*gan[i-1]*10+1)%mod;
  }
  build(1,1,n);
  for(int i=1;i<=q;i++){
    int l,r,d;
    cin>>l>>r>>d;
    up(1,1,n,l,r,d);
    cout<<t[1]<<'\n';
  }
  return 0;
}

Measured memory_bytes: 9332
//Zory-2019
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
// #include<unordered_map>
using namespace std;
int bin[40],lg[1<<21];
namespace mine
{
	typedef long long ll;
	#define double long double
	const int INF=0x3f3f3f3f;
	const ll LLINF=0x3f3f3f3f3f3f3f3fll;
	ll qread()
	{
		ll ans=0;char c=getchar();int f=1;
		while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) {num=-num;putchar('-');}
		if(num>9) write(num/10);
		putchar('0'+num%10);
	}
	void writeln(int num){write(num);puts("");}
	#define FR first
	#define SE second
	#define MP make_pair
	#define pr pair<int,int>
	#define PB push_back
	#define vc vector
	void chmax(int &x,const int y) {x=x>y?x:y;}
	void chmin(int &x,const int y) {x=x<y?x:y;}
	const int MAX_N=1e5+10;
	const int MOD=1e9+7;
	void add(int &x,int y) {x+=y;if(x>=MOD) x-=MOD;if(x<0) x+=MOD;}

	int a[MAX_N];
	void main()
	{
		int n=qread();for(int i=1;i<=n;i++) a[i]=qread();
		sort(a+1,a+n+1);reverse(a+1,a+n+1);
		for(int x=1;x<=n;x++)
			if(x+1>a[x+1])
			{
				int up=(a[x]-x),right=0;
				while(x+right+1<=n and x<=a[x+right+1]) right++;
				int now;
				if(up==0 and right==0) now=0;
				else if(up==0) now=right&1;
				else if(right==0) now=up&1;
				else now=(((up-1)&1)==0 or ((right-1)&1)==0);
				puts(now?"First":"Second");
				break;
			}
	}
};
int main()
{
	srand(time(0));
	bin[0]=1;for(int i=1;i<=30;i++) bin[i]=bin[i-1]<<1;
	lg[1]=0;for(int i=2;i<(1<<21);i++) lg[i]=lg[i>>1]+1;
	mine::main();
}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int n, c;
int im[33][101010] = {0};

int main(){
	cin >> n >> c;
	for(int i = 0; i < n; i++){
		int a,b,d;
		cin >> a >> b >> d;
		im[d][a]++;
		im[d][b+1]--;
	}
	int ans = 0;
	for(int j = 1; j <= c; j++){
		for(int i = 1; i < 100011; i++){
			im[j][i] += im[j][i-1];
			im[j][i-1] = !!im[j][i-1];
		}
	}
	for(int i = 0; i < 100010; i++){
		for(int j = 2; j <= c; j++){
			im[1][i] += im[j][i];
		}
		ans = max(im[1][i], ans);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int dp[MAXM][10];


int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>k;

    if(k<=9){
        cout<<k<<"\n";
        return 0;
    }

    k-=9;

    for(int i=0;i<=9;i++){
        dp[1][i] = 1;
    }

    pii ans = pii(-1,-1);

    for(int i=2;;i++){
        dp[i][0] = dp[i-1][0]+dp[i-1][1];
        for(int j=1;j<9;j++){
            dp[i][j] = dp[i-1][j-1]+dp[i-1][j]+dp[i-1][j+1];
        }
        dp[i][9] = dp[i-1][8]+dp[i-1][9];
        for(int j=1;j<=9;j++){
            if(dp[i][j]>=k){
                ans = pii(j,i);
                break;
            }
            else k-=dp[i][j];
        }
        if(ans.f!=-1)break;
    }

    cur = ans.f;

    for(int i=ans.s-1;i>=0;i--){
        cout<<cur;
        if(cur==0){
            if(dp[i][0]>=k)cur = 0;
            else {
                k-=dp[i][0];
                cur = 1;
            }
        }
        else if(cur==9){
            if(dp[i][8]>=k)cur = 8;
            else {
                k-=dp[i][8];
                cur = 9;
            }
        }
        else {
            if(dp[i][cur-1]>=k){cur--;}
            else {
                k-=dp[i][cur-1];
                if(dp[i][cur]<k){
                    k-=dp[i][cur];
                    cur++;
                }
            }
        }
    }
    cout<<"\n";

    return 0;
}


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

using namespace std;

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;



int main(void) {
    int N;
    int A[100000  + 1];

    cin >> N;
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    int cp[100000 + 2];
    int ca[100000 + 2];

    int p = 0;
    int yen = 0;
    for(int i=0; i<N; i++) {
        yen = yen + abs(p - A[i]);
        p = A[i];
        cp[i] = yen;
    }
    yen = yen + abs(p);
    cp[N] = yen;
    for(int i=0; i<N + 1; i++) {
        ca[i] = yen - cp[i];
    }

    cout << 0 + abs(A[1]) + ca[1] << endl;  
    for(int i=1; i<N; i++) {
        cout << cp[i-1] + abs(A[i-1] - A[i+1]) + ca[i+1] << endl;  
    }

    return 0;
}

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

#define REP(i, n) for (int i = 0; i < (int)(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 ALL(v) v.begin(), v.end()

int main() {
  int H,W,A,B;
  int ans;
  cin >> H >> W >> A >> B;
  REP(i,B) {
    REP(j,A) {
      cout << 0;
    }
    FOR(j,A,W) {
      cout << 1;
    }
    cout << endl;
  }
  FOR(i,B,H) {
    REP(j,A) {
      cout << 1;
    }
    FOR(j,A,W) {
      cout << 0;
    }
    cout << endl;
  }
}


Measured memory_bytes: 1280
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
    
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1000*1000*1000;
const ll LINF = (ll)1e18;
int xv[4] = {-1, 1, 0, 0};
int yv[4] = {0, 0, -1, 1};

vector<vector<int>> mp(501, vector<int>(501,0));

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, M;
    cin >> N >> M;
    vector<P> ba(M);
    REP(i, M){
        int a, b;
        cin >> a >> b;
        ba[i].first = b;
        ba[i].second = a;
    }
    sort(ba.begin(), ba.end());
    int cut = -1;
    int cnt = 0;
    REP(i, M){
        int a = ba[i].second;
        int b = ba[i].first;
        if(a >= cut){
            cut = b;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 2048
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M, X = il()
    CA = [il() for _ in range(N)]

    ret = MAX
    for n in range(1 << N):
        k = 0
        A = [0] * M
        for j in range(N):
            c, *alist = CA[j]
            if n >> j & 1:
                k += c
                for i in range(len(alist)):
                    A[i] += alist[i]
            if all([a >= X for a in A]):
                ret = min(ret, k)
                break
        else:
            continue

    print(-1 if ret == MAX else ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9576
a, b, c, x, y = map(int, input().split())

ans = 0

if (a+b)/2 >= c:
    ans = c* 2 * min(x,y)
else:
    ans += (a+b)*min(x,y)
if x >= y:
    ans += min(a*(x-y), 2*c*(x-y))
else:
    ans += min(b*(y-x), 2*c*(y-x))

print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
    string s; cin >> s;
    int n = s.size();
    for (int i=0; i<n; i++){
        if (i%2==0){
            if (s[i] == 'L'){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            if (s[i] == 'R'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N;
ll A[200000],L[200000],R[200000], res;

int main() {
	cin >> N;
	res = llmax;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	L[0] = A[0];
	for (int i = 1; i < N; i++) {
		L[i] = L[i - 1] + A[i];
	}
	R[N - 1] = A[N - 1];
	for (int i = N - 2; i >= 0; i--) {
		R[i] = R[i + 1] + A[i];
	}
	for (int i = 1; i < N; i++) {
		res = min(res, abs(R[i] - L[i - 1]));
	}
	cout << res << endl;
}

Measured memory_bytes: 4992
n,x,y=map(int,input().split())
G=[[i,i+2] for i in range(n)]
G[0],G[-1]=[2],[n-1]
G[x-1].append(y)
G[y-1].append(x)
#print(G)
ans=[0]*(n-1)
#X,Yのショートカットに気を付けて上から見ていく
for i in range(n-1):
    for j in range(i+1,n):
    #i+1<=XかつY<=j+1の時ショートカットするのが最短
        temp1=j-i
        temp2=abs(x-(i+1))+1+abs(y-(j+1))
        dis=min(temp1,temp2)
        ans[dis-1]+=1
print(*ans,sep='\n')

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,o,p,q,i,j,k,k1;
    double a;

    while(scanf("%lld %lld",&n,&m)==2)
    {
            k=0;
            for(i=22;i<=m;i++)
            {
                o=(i%10)*((i/10)%10);
                if(n>=o && i%10>=2 ){k++;}
            }
            printf("%lld\n",k);

    }
    return 0;
}


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

int main() {
	// your code goes here
	long long a;
	long long b;
	cin>>a>>b;
	long long d=abs(a-b);
	if(d%2==0){
      long long q=d/2;
	cout<<abs(q-max(a,b))<<endl;}
	else
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a;
    scanf("%d",&a);
    if(a==22){
        printf("Christmas Eve Eve Eve");
    }else if(a==23){
        printf("Christmas Eve Eve");
    }else if(a==24){
        printf("Christmas Eve");
    }else printf("Christmas");
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}

const int N = 200005;

LL s1[N], s2[N], a[N], L, Ans;
int n;

LL f(int l, int r) { return s1[r] - a[l] * (r - l) - s1[l]; }

void Calc() {
  for (int i = 1; i <= n; ++i)
    s1[i] = s1[i - 1] + a[i], s2[i] = s2[i - 1] + (L - a[n - i + 1]);
  for (int i = 0; i < n; ++i) {
    LL now = a[i] * (n - i) + a[i];
    int cnt = (n - i) / 2;
    if ((n - i) % 2 == 0)
      now += s2[cnt] * 2 + f(i, i + cnt) * 2 - (a[i + cnt] - a[i]);
    else
      now += s2[cnt + 1] * 2 + f(i, i + cnt) * 2 - (L - a[n - cnt]);
    Ans = max(Ans, now);
  }
}
int main() {
  L = read();
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  Calc();
  for (int i = 1; i <= n; ++i) a[i] = L - a[i];
  reverse(a + 1, a + n + 1);
  Calc();
  cout << Ans;
  return 0;
}


Measured memory_bytes: 4992
#include <cstdio>


int arr[200009];
int N,K;

int main(){
    scanf("%d%d",&N,&K);
    for(int i=1;i<=N;i++){
        scanf("%d",arr+i);

        if (i>K){
            if (arr[i]>arr[i-K])
                puts("Yes");
            else 
                puts("No");

        }
    }

    return 0;
}

Measured memory_bytes: 2428
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
using namespace std;

int main() {
	int M;
	cin >> M;
	cout << 48 - M << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
int n,p,a[60],s;
LL f[5005];
int main(){
	scanf("%d%d",&n,&p);
	f[0]=1;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);s+=a[i];
		for(int j=s;j>=a[i];j--)f[j]+=f[j-a[i]];
	}
	LL ans=0;
	for(int j=p;j<=s;j+=2)ans+=f[j];
	printf("%lld",ans);
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)

using namespace std;

int main(){
  array<int, 3> abc;;
  cin>>abc[0]>>abc[1]>>abc[2];

  sort(abc.begin(), abc.end());
  if(abc[0]==5 && abc[1]==5 && abc[2]==7){
    cout<<"YES";
  }else{
    cout<<"NO";
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
// template<class T> T gabs(const T& x) { return max(x, -x); }
// #define abs gabs

int main() {
    int n;
    cin >> n;
    vector<double> x(n), y(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }
    double ans = 0;
    for (int i = 0, j = 0; i < n; ++i) {
        while (hypot(x[j] - x[i], y[j] - y[i]) 
            < hypot(x[(j + 1) % n] - x[i], y[(j + 1) % n] - y[i])) {
            j = (j + 1) % n;
        }
        ans = max(ans, hypot(x[j] - x[i], y[j] - y[i]));
    }
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 4032
import sys
import math
import bisect

def query(n):
    ans = 0
    for c in str(n):
        val = ord(c) - ord('0')
        ans += val
    return ans

def main():
    n = int(input())
    if n % query(n) == 0:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()


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

const int N = 1e3 + 5 , M = 5e3+5;

int n , m , mod =1e9+7;


int dp[N][N];
string a[N];

int solve(int i , int j)
{
    if(i>n || j>m)return 0;
    if(i==n && j == m)return 1;
    if(a[i-1][j-1]=='#')return 0;
    if(dp[i][j]!=-1)return dp[i][j];
    int ret = (solve(i+1 , j)%mod + solve(i , j+1)%mod ) %mod;
    return dp[i][j] = ret;
}


int main()
{
    memset(dp , -1 , sizeof dp);
    cin>>n>>m;
    for(int i = 0;i<n;i++)cin>>a[i];
    cout<<solve(1 , 1);
    return 0;
}


Measured memory_bytes: 5376
using System;
public class ITP1_7_C
{
  public static void Main()
  {
    string[] data = System.Console.ReadLine().Split(' ');
    int r = int.Parse(data[0]);
    int c = int.Parse(data[1]);
    int[,] rc = new int[r + 1, c + 1];
    int sum = 0;
    
    for (int i = 0; i < r; i++)
    {
      string[] row = System.Console.ReadLine().Split(' ');
      for (int j = 0; j < c; j++)
      {
        int n = int.Parse(row[j]);
        rc[i, j] = n;
        rc[r, j] += n;
        rc[i, c] += n;
        sum += n;
      }
    }
    rc[r, c] = sum;
    
    for (int i = 0; i < r + 1; i++)
    {
      for (int j = 0; j < c + 1; j++)
      {
        if(j != c)
        {
          System.Console.Write(rc[i, j] + " ");
        }
        else
        {
          System.Console.Write(rc[i, j]);
        }
      }
    System.Console.WriteLine("");
    }
  }
}

Measured memory_bytes: 9400
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

def main():
    n = int(input())
    a = list(map(int, input().split()))
    r = sum(a)
    l = 0
    ans = r
    for i in a:
        l += i
        r -= i
        ans = min(ans, abs(r - l))
        if l >= r:
            break
    print(ans)

main()

Measured memory_bytes: 26224
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
void fast()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int main()
{
	fast();
	ll a, b, c;
	cin >> a >> b >> c;
	ll z = a / b + int(a % b != 0);
	cout << z*c << endl;
}

Measured memory_bytes: 3568
N, W = map(int, input().split())
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i in range(1,N+1):
    w, v = map(int, input().split())
    for j in range(W+1):
        if j - w >= 0:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w] + v)
        else:
            dp[i][j] = dp[i-1][j]

print(dp[-1][-1])


Measured memory_bytes: 219160
fn main() {
    proconio::input! {
        n: usize,
        city: [(i64, i64, i64); n]
    };
    let mut dist_v = vec![vec![0; n]; 1<<n];
    let mut dist_h = vec![vec![0; n]; 1<<n];
    for i in 0..1<<n {
        for j in 0..n {
            dist_v[i][j] = city[j].0.abs();
            dist_h[i][j] = city[j].1.abs();
            for k in 0..n {
                if i&(1<<k) == 0 { continue }
                dist_v[i][j] = dist_v[i][j].min((city[k].0-city[j].0).abs());
                dist_h[i][j] = dist_h[i][j].min((city[k].1-city[j].1).abs());
            }
            dist_v[i][j] *= city[j].2;
            dist_h[i][j] *= city[j].2;
        }
    }
    let mut res = vec![1000000000000000000; n+1];
    for i in 0..1<<n {
        let idx = (i as u64).count_ones() as usize;
        let mut j = i;
        loop {
            let mut cur = 0;
            for k in 0..n {
                cur += dist_v[j][k].min(dist_h[i^j][k]);
            }
            res[idx] = res[idx].min(cur);
            if j == 0 { break; }
            j = i&(j-1);
        }
    }
    for &v in &res { println!("{}", v) }
}


Measured memory_bytes: 11776
from collections import deque

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
write = sys.stdout.write
N = int(readline())
G = [None]*N
for i in range(N):
    k, *c = map(int, readline().split())
    G[i] = c

H = [0]*N
prv = [None]*N
def dfs(v):
    s = 1; heavy = None; m = 0
    for w in G[v]:
        prv[w] = v
        c = dfs(w)
        if m < c:
            heavy = w
            m = c
        s += c
    H[v] = heavy
    return s
dfs(0)


SS = []
D = []
L = [0]*N
I = [0]*N
que = deque([(0, 0)])
while que:
    v, d = que.popleft()
    S = []
    k = len(SS)
    while v is not None:
        I[v] = len(S)
        S.append(v)
        L[v] = k
        h = H[v]
        for w in G[v]:
            if h == w:
                continue
            que.append((w, d+1))
        v = h
    SS.append(S)
    D.append(d)


C = list(map(len, SS))
DS = [[0]*(c+1) for c in C]
def add(K, data, k, x):
    while k <= K:
        data[k] += x
        k += k & -k
def get(K, data, k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s

def query_add(v, x):
    l = L[v]
    add(C[l], DS[l], I[v]+1, x)
    v = prv[SS[l][0]]

def query_sum(v):
    s = 0
    while v is not None:
        l = L[v]
        s += get(C[l], DS[l], I[v]+1)
        v = prv[SS[l][0]]
    return s


Q = int(readline())
ans = []
for q in range(Q):
    t, *cmd = map(int, readline().split())
    if t:
        ans.append(str(query_sum(cmd[0])))
    else:
        v, w = cmd
        query_add(v, w)
write("\n".join(ans))
write("\n")



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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

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

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

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

signed main(){
	int H=read(),W=read(),h=read(),w=read();
	if(H%h==0&&W%w==0){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	REP(i,H)REP(j,W){
		int x=0;
		if(i%h==0&&j%w==0)x=999999999;
		if(i%h==h-1&&j%w==w-1)x=-1000000000;
		print(x,j==W-1?1:2);
	}
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define forn(i,n)for(ll i=0;i<(n);i++)
#define forn_rev(i,n)for(ll i=(n)-1;i>=0;i--)
#define for1n(i,n) for(ll i=1;i<=(n);i++)
#define ARRAY_SIZE(a) sizeof(a)/sizeof(*a)

using namespace std;


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);
    ll N;
    cin>>N;
    vector<ll> height(N+1);
    forn(i,N) cin>>height[i];
    vector<ll> dp(N+1,0);
    //dp[0]=height[0];
    dp[1]=abs(height[0]-height[1]);
    for(ll i=2;i<N;i++){
        dp[i]=min(dp[i-2]+abs(height[i-2]-height[i]),dp[i-1]+abs(height[i]-height[i-1]));

    }
    cout<<dp[N-1];
    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ld long double
#define mx 200005
#define fr first
#define se second
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
struct hello
{
    int first,second,third;
}coin[100005];
ll dp[100005][3];
ll n,k;
ll func(ll i, ll who)
{
    if(i>n) return 0;
    if(dp[i][who]!=-1) return dp[i][who];
    int ans1=0,ans2=0,ans3=0;
    if(who == 0){
        ans1+=coin[i].first+func(i+1,1);
        ans2+=coin[i].second+func(i+1,2);
        ans3+=coin[i].third+func(i+1,3);
    }
    else if(who == 1){
        ans1+=coin[i].second+func(i+1,2);
        ans2+=coin[i].third+func(i+1,3);
    }
    else if(who == 2){
        ans1+=coin[i].first+func(i+1,1);
        ans3+=coin[i].third+func(i+1,3);
    }
    else if(who == 3){
        ans1+=coin[i].first+func(i+1,1);
        ans2+=coin[i].second+func(i+1,2);
    }
    return dp[i][who] = max({ans1,ans2,ans3});
}

int main()
{
   fast;
   cin >> n;
   memset(dp,-1,sizeof dp);
   for(ll i=1; i<=n; i++) cin >> coin[i].first >> coin[i].second >> coin[i].third;
   cout << func(1,0) << "\n";
   return 0;
}


Measured memory_bytes: 11648
#include<bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN=2e5+5;
int a[MAXN];
ll val[35];
map<int,int> sv,pool;
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int n;
	for(int i=0;i<=31;i++)
		val[i]=(1LL<<i);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sv[a[i]]++;
	}
	sort(a+1,a+1+n);
	int ans=0;
	for(int i=n;i>=1;i--)
	{
		if(pool.find(a[i])!=pool.end()&&pool[a[i]]!=0)
		{
			pool[a[i]]--;
			continue;
		}
		sv[a[i]]--;
		for(int j=31;j>=1;j--)
		{
			int v=val[j]-a[i];
			if(sv.find(v)==sv.end())
				continue;
			if(sv[v]==0) continue;
			sv[v]--;pool[v]++;
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}


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

int main(){
    double fp;   //false prob
    double sp;   //success prob
    double t;    //time
    double Sn;
    int N, M;
    // Sn = (1*t)*(fp^0*sp) + (2*t)*(fp^1*sp) + ...
    // fpSn =                 (1*t)*(fp^1*sp) + ...
    // (1-fp)Sn = t*sp*fp^0 + t*sp*fp^1 + ...
    // Sn = (t*sp/(1-fp))/(1-fp)

    cin >> N >> M;

    sp = pow(0.5, M);
    fp = 1.0 - sp;
    t = 1900*M + 100*(N-M);
    
    Sn = (t*sp/(1-fp))/(1-fp);

    cout << Sn << endl;

}



Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int w;
	scanf("%d",&w);
	int n;
	scanf("%d",&n);
	int i,a[30],b[30],j,now;
	for(j=0;j<n;j++){
		scanf("%d,%d",&a[j],&b[j]);
	}	
	for(i=1;i<=w;i++){
		now=i;
		for(j=n-1;j>=0;j--){
			if(a[j]==now){
				now=b[j];
			}
			else if(b[j]==now){
				now=a[j];
			}
		}
		printf("%d\n",now);
	}
	return 0;
}


Measured memory_bytes: 1976
n,k=list(map(int,input().split()))
s=input()
if s[k-1]=="A":
    i="a"
if s[k-1]=="B":
    i="b"
if s[k-1]=="C":
    i="c"
if k!=n:
    for j in range(n):
        if j==k-1:
            print(i,end="")
        elif j==n-1:
            print(s[j])
        else:
            print(s[j],end="")
if k==n:
    for j in range(n):
        if j==n-1:
            print(i)
        else:
            print(s[j],end="")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 100001
#define mod 1000000007
ll a[MAXN];
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll num1 = 0;
    ll num2 = 0;
    ll num3 = 0;
    ll ret = 1;
    for (int i = 1; i <= n; i++) {
        if ((a[i] == num1) && (a[i] == num2) && (a[i] == num3)) {
            num1++;
            ret = ret * 3 % mod;
        }
        else if ((a[i] == num1) && (a[i] == num2)) {
            num1++;
            ret = ret * 2 % mod;
        }
        else if ((a[i] == num2) && (a[i] == num3)) {
            num3++;
            ret = ret * 2 % mod;
        }
        else if ((a[i] == num3) && (a[i] == num1)) {
            num3++;
            ret = ret * 2 % mod;
        }
        else if (a[i] == num1) {
            num1++;
        }
        else if (a[i] == num2) {
            num2++;
        }
        else if (a[i] == num3) {
            num3++;
        }
        else {
            ret = 0;
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 4388
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

char buf[105];

int main() {
  int n;
  scanf("%d\n%s", &n, buf);
  int ret = 0;
  int curr = 0;
  for(int i = 0; i < n; i++) {
    if(buf[i] == 'I') curr++;
    else curr--;
    ret = max(ret, curr);
  }
  printf("%d\n", ret);
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	sides := map[int]int{}
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		sides[a]+=1
	}	

	var first, second int
	for k, v := range sides {
		if k > first {
			if v >= 2 {
				second = first
				first = k
				v -= 2
			}
		}
		if k > second {
			if v >= 2 {
				second = k
			}
		}
	}

	fmt.Println(first * second)
}

Measured memory_bytes: 8064
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
dp=[[0 for i in range(m+1)] for i in range(n+1)]
for i in range(m+1):
	dp[0][i]=1
for j in range(n+1):
	dp[j][0]=1
for i in range(n):
	for j in range(m):
		if s[i]==t[j]:
			dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j])%1000000007
		else:
			dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j]-dp[i][j])%1000000007
print(dp[n][m])

Measured memory_bytes: 74204
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		if(a>b) {
			System.out.println(a-1);
		}
		else {
			System.out.println(a);
		}
		}
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll x, n;
    cin >> x >> n;
    vector<ll> p(n);
    rep(i, n) cin >> p[i];
    set<ll> s;
    rep(i, n) s.insert(p[i]);
    ll diff = LONG_LONG_MAX, ans = -1;
    rep(i, 102) {
        if (s.count(i) > 0) continue;
        ll tmp = abs(i - x);
        if (diff > tmp) {
            diff = tmp;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3660
<?php
$a = (int)trim(fgets(STDIN));
$b = (int)trim(fgets(STDIN));
$c = (int)trim(fgets(STDIN));
$d = (int)trim(fgets(STDIN));
$e = (int)trim(fgets(STDIN));

$ary = [$a, $b, $c, $d, $e];

$cand = [];
$sum = 0;
foreach ($ary as $k => $v) {
	if ($v % 10 === 0) {
		$sum += $v;
	}else{
		$cand[$k] = $v % 10;
	}
}
asort($cand);
$first = true;
foreach ($cand as $k => $v) {
	if ($first) {
		$first = false;
		$sum += $ary[$k];
	}else{
		$sum += (int)(ceil($ary[$k]/10)*10);
	}
}

echo $sum;

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;


int main(){
    int n;
    cin>>n;
    ll ans=1;
    vector<ll>a(n);

    rep(i,0,n){
        cin>>a.at(i);
    }
    rep(i,0,n){
        if(a.at(i)==0){
            cout<<0<<endl;
            return 0;
        }
    }
    rep(i,0,n){
        if(a.at(i)>1000000000000000000/ans){
            cout<<-1<<endl;
            return 0;
        }
        ans*=a.at(i);
    }
    cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3964
#include <iostream>
#include <string>

using namespace std;

class DLinkList
{
private:
	struct ListNode{
		ListNode *prior, *next;
		int val;
		ListNode(int v) :prior(NULL), next(NULL), val(v){};
	};

private:
	ListNode *head;
	int len;

public:
	DLinkList()
	{
		head = new ListNode(-1);
		head->prior = head;
		head->next = head;

		len = 0;
	}

	ListNode *search(int v)
	{
		ListNode *p = head->next;
		while (p != head && p->val != v)
			p = p->next;
		return p;
	}

	void del_helper(ListNode *p)
	{
		if (p == head) return;
		p->prior->next = p->next;
		p->next->prior = p->prior;
		delete p;
		len--;
	}

	void del_first()
	{
		del_helper(head->next);
	}

	void del_last()
	{
		del_helper(head->prior);
	}

	void del_x(int v)
	{
		del_helper(search(v));
	}

	void insert(int val)
	{
		ListNode *node = new ListNode(val);

		node->next = head->next;
		head->next->prior = node;

		head->next = node;
		node->prior = head;

		len++;
	}

	void print()
	{
		ListNode *p = head->next;
		int count = 0;
		while (count++ < len - 1)
		{
			cout << p->val << " ";
			p = p->next;
		}
		if (len - 1 >= 0) cout << p->val << endl;
	}
};






int main()
{


	DLinkList l;
	string str;
	int val;
	cin >> str;
	while (cin >> str)
	{
		if (str == "insert")
		{
			cin >> val;
			l.insert(val);
		}
		else if (str == "delete")
		{
			cin >> val;
			l.del_x(val);
		}
		else if (str == "deleteFirst")
			l.del_first();
		else if (str == "deleteLast")
			l.del_last();
	}
	l.print();
}

Measured memory_bytes: 34428
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T>> &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vv<int> w(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  int ans = INF;
  int s1 = 0, s2 = accumulate(ALL(w), 0);
  for (int i = 0; i < n; i++) {
    s1 += w[i];
    s2 -= w[i];
    chmin(ans, abs(s1 - s2));
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 256
def ans():
  N, K = map(int,input().split())
  H = sorted([int(input()) for _ in range(N)])
  res = 1e9+7
  for i in range(N-K+1):
    x = H[i+K-1] - H[i]
    if(res > x):
      res = x
  print(res)
ans()

Measured memory_bytes: 8280
#!/usr/bin/python3

from math import floor

while True:
    n = eval(input())
    if n != 0:
        ls = []
        for i in range(n):
            m = eval(input())
            ls.append(m)
        ls.remove(max(ls))
        ls.remove(min(ls))
        print(floor(sum(ls)/len(ls)))
    else:
        break

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<int,int> p;

ll n;
ll a[100100];
map<ll, bool> mp;
int main(){
  cin >> n;
  rep(i,0,n){
    cin >> a[i];
    mp[a[i]] = !mp[a[i]];
  }
  ll ans=0;
  for(auto p :mp){
    ans += p.second;
    // cout << p.first << ' '<<p.second << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 7296
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;

int a,b,x;

int main(){
    cin >> a >> b >> x;
    if(2*x <= a * a * b){ //三角形
        double d = (double)a * b * b / x / 2;
        cout << setprecision(20) << atan(d) * 180 / M_PI << endl;
    }else{ //台形
        double d = 2.0 / (double)a * (b - (double)x / a / a);
        cout << setprecision(20) << atan(d) * 180 / M_PI << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,color = gets.chomp.split.map(&:to_i)
diff = []
color.times do |i|
  diff[i] = gets.chomp.split.map(&:to_i)
end
field = []
n.times do |i|
  field[i] = gets.chomp.split.map(&:to_i)
end

count = [[0]*color,[0]*color,[0]*color]

n.times do |i|
  n.times do |j|
    count[(i+j)%3][field[i][j]-1] += 1
  end
end

min = 500*500*1000
color.times do |i|
  color.times do |j|
    next if i==j
    color.times do |k|
      next if i==k || j==k
      sum = 0
      color.times do |l|
        sum += count[0][l] * diff[l][i]
        sum += count[1][l] * diff[l][j]
        sum += count[2][l] * diff[l][k]
      end
      min = sum if min > sum
    end
  end
end

printf("%d\n",min)

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

int main(){
  int N, cnt = 0;
  cin >> N;
  int a[N];
  for(int i = 1; i <= N; i++) cin >> a[i];

  for(int i = 1; i <= N; i++){
    if(i == a[a[i]])
      cnt++;
  }
  cout << cnt/2 << endl;
  return 0;
}

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

int main(){
    stack<char> S;
    char X[222222];
    cin >> X;
    int i,N,n;
    n = 0;
    N = 0;
    S.push('A');
    while(X[N]) N++;
    for(i=0;i<=N-1;i++){
        if(X[i]=='S') {S.push('S');}
        if(X[i]=='T' && S.top() != 'S') {S.push('T');}
        if(X[i]=='T' && S.top() == 'S') {S.pop();}
    }
    cout << S.size() - 1 << endl;
}


Measured memory_bytes: 640
n = int(input())
d = {}
for i in range(n):
    s, p = input().split()
    if s in d:
        d[s].append((int(p), i + 1))
    else:
        d[s] = [(int(p), i + 1)]
for key in sorted(d.keys()):
    sorted_list = sorted(d[key], reverse =True)
    for item in sorted_list:
        print(item[1])


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

int main() {
    string s;
    cin >> s;
    int count = 0;
    if(s.at(0) == '1'){
        count++;
    }
    if(s.at(1) == '1'){
        count++;
    }
    if(s.at(2) == '1'){
        count++;
    }
    cout << count;
}

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

int main() {
    int n=0,x,t;
    string s;
    cin>>s;
    x=0;
    while(s[x]){
        t = s[x]-'0';
        n += t;
        x++;
    }
    if(n%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3748
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var line string
	fmt.Scan(&n)
	fmt.Scan(&line)
	split := strings.Split(line, "")
	count := 0
	for i := 0; i < 1000; i++ {
		targets := strings.Split(fmt.Sprintf("%03d", i), "")
		index := 0
		for j := 0; j < n; j ++ {
			if split[j] == targets[index] {
				index++
			}
			if index >= 3 {
				break
			}
		}
		if index >= 3 {
			count += 1
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 1408
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

root = None

def insert(key):
    global root
    x, y = root, None
    while x != None: x, y = x.left if key < x.key else x.right, x
    if y == None: root = Node(key)
    elif key < y.key: y.left = Node(key)
    else: y.right = Node(key)

def inorder(node):
    return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
    return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''

input()
for e in sys.stdin:
    if e[0] == 'i': insert(int(e[7:]))
    else:
        print(inorder(root))
        print(preorder(root))


Measured memory_bytes: 63328
def answer():
    n, m = map(int, input().split())
    ans = [-1] * n
    for i in range(m):
        s, c = map(int, input().split())
        if ans[s-1] != -1 and ans[s-1] != c:
            return -1
        ans[s-1] = c
    if n == 1 and (ans[0] == 0 or ans[0] == -1):
        return 0
    if ans[0] == 0:
        return -1
    if ans[0] == -1:
        result = 1
    else:
        result = ans[0]
    for i in range(1, n):
        if ans[i] == -1:
            result = result * 10
        else:
            result = result * 10 + ans[i]
    return result

print(answer())

Measured memory_bytes: 3064
if __name__ == '__main__':
    k = int(input())
    ks = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

    print(ks[k - 1])


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

int H, W;
vector<vector<char>> grid(50, vector<char>(50));
vector<vector<int>> from(50, vector<int>(50, -1));
queue<int> q;
vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};
vector<vector<bool>> use(50, vector<bool>(50, false));

void search() {
  int x = q.front() % W;
  int y = (q.front() - x) / W;
  q.pop();
  
  for (int i = 0; i < 4; ++i) {
    int X = x + dx[i];
    int Y = y + dy[i];
    if (0 <= X && X < W && 0 <= Y && Y < H) {
      if (grid[Y][X] == '.' && from[Y][X] == -1) {
        q.push(Y * W + X);
        from[Y][X] = y * W + x;
      }
    }
  }
  return;
}

void re(int x, int y) {
  if (x == 0 && y == 0) return;
  
  int X = from[y][x] % W;
  int Y = (from[y][x] - X) / W;
  use[Y][X] = true;
  re(X, Y);
  return;
}

int main() {
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> grid[i][j];
    }
  }
  
  q.push(0);
  from[0][0] = 0;
  while (q.size() > 0) search();
  if (from[H - 1][W - 1] == -1) {
    cout << -1 << endl;
    return 0;
  }
  
  use[H - 1][W - 1] = true;
  re(W - 1, H - 1);
  
  int ans = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (!use[i][j] && grid[i][j] == '.') ++ans;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
a = list(range(20000, (n + 1) * 20000, 20000))
b = a[::-1]
for i in range(len(p)):
	a[p[i] - 1] -= n - i - 1
for i in a:
	print(i, end=" ")
print()
for i in b:
	print(i, end=" ")
print()

Measured memory_bytes: 75420