akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef pair<int,int> P;
struct edge{
	int to,cap,cost,rev;
	edge(int to,int cap,int cost,int rev) :to(to),cap(cap),cost(cost),rev(rev){}
};
const int MAX_V=202,INF=1e9;
int V;
vector<edge> G[MAX_V];
int h[MAX_V],dist[MAX_V],prevv[MAX_V],preve[MAX_V];
void add_edge(int from,int to,int cap,int cost){
	edge e1=edge(to,cap,cost,G[to].size()),e2=edge(from,0,-cost,G[from].size());
	G[from].pb(e1),G[to].pb(e2);
}
int min_cost_flow(int s,int t,int f){
	int res=0;
	fill(h,h+V,0);
	while(f>0){
		priority_queue<P,vector<P>,greater<P> > que;
		fill(dist,dist+V,INF);
		dist[s]=0;
		que.push(P(0,s));
		while(!que.empty()){
			P p=que.top();
			que.pop();
			int v=p.sc;
			if(dist[v]<p.fs) continue;
			rep(i,G[v].size()){
				edge &e=G[v][i];
				if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
					dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
					prevv[e.to]=v;
					preve[e.to]=i;
					que.push(P(dist[e.to],e.to));
				}
			}
		}
		if(dist[t]==INF) return -1;
		rep(v,V) h[v]+=dist[v];
		int d=f;
		for(int v=t;v!=s;v=prevv[v]){
			chmin(d,G[prevv[v]][preve[v]].cap);
		}
		f-=d;
		res+=d*h[t];
		for(int v=t;v!=s;v=prevv[v]){
			edge &e=G[prevv[v]][preve[v]];
			e.cap-=d;
			G[v][e.rev].cap+=d;
		}
	}
	return res;
}
int main(){
	int N;
	int w[100][100],e[100][100];
	string s[100];
	cin>>N;
	rep(i,N) rep(j,N) cin>>w[i][j];
	rep(i,N) rep(j,N) cin>>e[i][j];
	rep(i,N) cin>>s[i];
	int S=2*N,T=2*N+1;
	V=2*N+2;
	rep(i,N) add_edge(S,i,1,0);
	rep(i,N) add_edge(N+i,T,1,0);
	rep(i,N) rep(j,N){
		int c=0;
		rep(k,N){
			if(k==j){
				if(s[i][k]=='.') c+=w[i][k];
			}else{
				if(s[i][k]=='o') c+=e[i][k];
			}
		}
		add_edge(i,N+j,1,c);
	}
	int f=min_cost_flow(S,T,N);
	cout<<f<<endl;
	bool is[100][100]={};
	rep(v,N){
		for(edge e:G[v]){
			int u=e.to;
			if(u<2*N){
				is[v][u-N]=(e.cap==0);
			}
		}
	}
	int c=0;
	rep(i,N) rep(j,N) if((s[i][j]=='o')^is[i][j]) c++;
	cout<<c<<endl;
	rep(i,N) rep(j,N){
		if((s[i][j]=='o')&&!is[i][j]) printf("%d %d erase\n",i+1,j+1);
		if((s[i][j]=='.')&&is[i][j]) printf("%d %d write\n",i+1,j+1);
	}
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment
 
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
 
namespace std {
  bool operator < (const P& a, const P& b){
    return fabs(real(a)-real(b)) < EPS ? imag(a) < imag(b) : real(a) < real(b);
  }
}
double dot(P a, P b){ return real(conj(a)*b); }

double cross(P a, P b){ return imag(conj(a)*b); }

P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}

P symmetricPoint(L l,P p){
  P v = l.first - l.second;
  v = v * P(0,-1);
  P c = crossPoint( l, L(p, p + v) );
  v = p - c;
  return c - v;
}

char buf[1111];
int cnt;
int N;

struct state{
  bool kind;
  P a;
  L b;
  state(){kind = true;}
  state(bool kind):kind(kind) {}
};

state xros(state a,state b){
  state ret;
  if( a.kind == true && b.kind == true ){
    ret.kind = false;
    ret.b = L(a.a,b.a);    
  } else if( a.kind == false && b.kind == false ){
    ret.a = crossPoint(a.b,b.b);
  } else {
    if( a.kind == false )
      ret.a = symmetricPoint(a.b,b.a);
    else 
      ret.a = symmetricPoint(b.b,a.a);
  }
  return ret;
}

int number(int &co){
    int k = 1;
    if( buf[co] == '-' ){
      k = -1;
      co++;
    }
    int v1 = 0;
    while( isdigit(buf[co]) ){
      v1 *= 10;
      v1 += (buf[co++]-'0');
    }
    return v1*k;
}

state exp(int l,int r){
  
  int bc = l;
  state p[2];
  int xc=0;
  if( buf[bc] != '(' ){
    int v1 = number(bc);
    assert(buf[bc] == ',' );
    bc++;
    int v2 = number(bc);
    state s;
    s.a = P(v1,v2);
    
    //  cout << "point ( " << l << " , " << r << " ) " << " = " << s.a << endl;
    return s;
  }
  while( buf[bc] == '(' && bc < r ) {
    int cc = 0;
    int st = bc;
    for(int i=bc;i<r;i++){      
      if( buf[i] == '(' ) cc++;
      else if( buf[i] == ')' ) cc--;
      if( cc == 0 ){
	st = i;
	break;
      }
    }
    p[xc&1] = exp(bc+1,st);
    if( xc > 0 ){
      p[xc&1] = xros(p[0],p[1]);
    }
    xc++;
    bc = st+1;
    if( buf[bc] == '@' ) bc++;
  } 
  /* cout << "ques ( " << l << " , " << r << " ) " << " = " ;
   if( p[(xc-1)&1].kind ) cout << p[(xc-1)&1].a << endl;
  else cout << p[(xc-1)&1].b.first << " - " << p[(xc-1)&1].b.second << endl;
  */
  return p[(xc-1)&1];
}

int main(){
  while( cin >> buf ){
    if( buf[0] == '#' ) break;
    cnt = 0;
    N = strlen(buf);
    state res = exp(0,N);
    printf("%.10lf %.10lf\n",res.a.real(),res.a.imag());
  }
}

Measured memory_bytes: 1196
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    A = [input().strip("\n") for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#": count += 1
    print("Possible" if count == H + W - 1 else "Impossible")

    return 0

if __name__ == "__main__":
    solve()

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

using namespace std;

#define llong long long int
#define rep(i, n) for (int i = 0; i < n; ++i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static llong MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

    int n, k;
    cin >> n >> k;
    if (k == 1) cout << 0 << endl;
    else cout << n - (k - 1) - 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vb   = vector<bool>;
using vvb  = vector<vb>;
using pii  = pair<int,int>;
using vpii = vector<pii>;
 
int main() {
    long long N; cin >> N;
    vi A(N); for(int i = 0; i < N; i++) cin >> A.at(i);

    long long ans = 0;    
    for (int i = 1; i < N; i++) {
        int tmp = A.at(i-1)-A.at(i);
        if (tmp <= 0) continue;
        A.at(i)+= tmp;
        ans+= tmp;
    }
    cout << ans << endl;
}

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

int main() {
  int n,ac = 0, tle = 0,wa = 0, re = 0;
  cin >> n;
  while(n--) {
    char s[10];
    cin >> s;
 	if(strcmp(s,"AC")==0) ac++;
    else if(strcmp(s,"WA")==0) wa++;
    else if(strcmp(s,"TLE")==0) tle++;
    else re++;
  }
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",ac,wa,tle,re);
  return 0;
}


Measured memory_bytes: 3704
def main():
    import heapq
    n,m = map(int,input().split())
    jobs = {}
    for i in range(n):
        a,b = map(int,input().split())
        if a not in jobs.keys():
            jobs[a] = [b]
        else:
            jobs[a] += [b]
    ob = []
    ans = 0
    for i in range(1,m+1):
        if i in jobs.keys():
            for j in range(len(jobs[i])):
                heapq.heappush(ob,-1*jobs[i][j])
        if len(ob)>0:
            ans += heapq.heappop(ob)*-1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 26072
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    while(true){
      int x = sc.nextInt();
      int y = sc.nextInt();
      if(x == 0 && y == 0){
        break;
      }else if(x <= y){
        System.out.println(x+" "+y);
      }else{
        System.out.println(y+" "+x);
      }
    }
  }
}



Measured memory_bytes: 35852
#include <iostream>

using namespace std;

void swap(int& x, int& y)
{
	int t = x;
	x = y;
	y = t;
}
void sort(int& a, int& b, int& c)
{
	if (a > b) swap(a, b);
	if (b > c) swap(b, c);
	if (a > b) swap(a, b);
}
int main() {
	int a,b,c;
	cin >> a >> b >> c;

	sort(a, b, c);

	cout << a << " " << b << " " << c<<"\n";

}


Measured memory_bytes: 3132
# yahoo-procon2019-qualB - Path
def main():
    *A, = map(int, open(0).read().split())
    cnt = [0] * 5
    for i in A:
        cnt[i] += 1
    flg = all(i < 3 for i in cnt[1:])
    print("YES" if flg else "NO")


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include<iostream>

using namespace std;

int main(){
  int n;
  cin >>n; 
  long a[n];

  for(int i=0;i<n;i++) cin >> a[i];
  
  int res=0;
  
  while(1){
    bool odd=false;
   for(int i=0;i<n;i++){
    if(a[i]%2!=0) odd=true;
   }
    if(odd) break;
    
    for(int i=0;i<n;i++){
    a[i]/=2;
   }
    res++;
  }
  cout << res << endl;
}

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

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int a, b; cin >> a >> b;
    for(int i=0;;i++){if((a-1)*i+1 >= b){cout << i << endl; break;}}
    return 0;
}

Measured memory_bytes: 3572
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;

int len,a[100005],r[100005],l[100005],ans[100005];
char c[100005];

int work1(int x){
	int left=1,right=r[0],mid,s=len;
	while(left<=right){
		mid=(left+right)/2;
		if(r[mid]<x){
			left=mid+1;
		}
		else{
			s=min(s,mid);
			right=mid-1;
		}
	}
	return r[s];
}

int work2(int x){
	int left=1,right=l[0],mid,s=0;
	while(left<=right){
		mid=(left+right)/2;
		if(l[mid]>x){
			right=mid-1;
		}
		else{
			s=max(s,mid);
			left=mid+1;
		}
	}
	return l[s];
}

int main(void){
	scanf("%s",c);
	len=strlen(c);
	for(int i=0;i<len;i++){
		if(c[i]=='R')a[i+1]=1;
		else a[i+1]=-1;
	}
	for(int i=1;i<=len;i++){
		if(a[i]==1&&a[i+1]==-1)
		r[++r[0]]=i;
		else
		if(a[i]==-1&&a[i-1]==1)
		l[++l[0]]=i;
	}
	for(int i=1;i<=len;i++){
		if(a[i]==1){
			int near;
			near=work1(i);
			int need=near-i;
			if(need%2==0)ans[near]++;
			else ans[near+1]++;
		}
		else
		if(a[i]==-1){
			int near;
			near=work2(i);
			int need=i-near;
			if(need%2==0)ans[near]++;
			else ans[near-1]++;
		}
	}
	for(int i=1;i<=len;i++)
	printf("%d ",ans[i]);
}

Measured memory_bytes: 1664
#%%
from sys import stdin, setrecursionlimit as srl
from threading import stack_size
srl(int(1e9)+7)
stack_size(int(1e8))

def func(x, graph, flag, dp):
    if (flag[x]):
        return dp[x]

    flag[x] = 1
    check = 0
    for i in graph[x]:
        check = max(check, func(i, graph, flag, dp) + 1)

    dp[x] = check

    return dp[x]

N, M = [int(i) for i in input().split()]
flag = [0] * (N + 1)
dp = [0] * (N + 1)
graph = [[] for _ in range(N + 1)]
#%%
for _ in range(M):
    temp_x, temp_y = [int(i) for i in input().split()]
    graph[temp_x].append(temp_y)

#%%
ans = 0
for i in range(1, N + 1):
    ans = max(ans, func(i, graph, flag, dp))

print(ans)


Measured memory_bytes: 64728
#include <stdio.h>

int main () {
	int N; 
	int K;
	char S[50];
	int length;
	scanf("%d%d", &N, &K);
	scanf("%s", S);
	length = K - 1;
	S[length] += 32; 
	printf("%s", S);
	return 0;
}

Measured memory_bytes: 1656
#include<cstdio>
#define tin int
#define itn int
#define tni int
#define nit int
#define nti int
#define pritnf printf
#define scnaf scanf
#define retrun return
#define ll long long
#define infa 0x3f3f3f3f
#define infb 0x7fffffff
#define infc 1061109567
#define infd 0x7f
using namespace std;
#define maxa 30
#define maxb 1000005
#include<cstring>
#include<iostream>

itn m,a,b;

itn main()
{
	cin>>m>>a>>b;
	cout<<(m-a)%b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int  H, W, Q;
long long D;
int x[100000], y[100000];

int Next[20][100000];

int main() {
	while (cin >> H >> W >> D) {
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				int a;
				cin >> a;
				x[a] = i;
				y[a] = j;
			}
		}
		for (int i = 1; i+D <= H*W; ++i) {
			Next[0][i] = abs(x[i + D] - x[i]) + abs(y[i + D] - y[i]);
		}
		for (int i = 0; i < 20; ++i) {
			for (int j = 0; j+D*(1<<i)<= H*W; ++j) {
				Next[i + 1][j] = Next[i][j] + Next[i][j + D * (1 << i)];
			}
		}

		cin >> Q;
		for (int iter = 0; iter < Q; ++iter) {
			long long L, R;
			cin >> L >> R;
			int con = (R - L) / D;
			long long res = 0;
			for (int i = 0; i < 20; ++i) {
				if (con & (1 << i)) {
					res += Next[i][L];
					L += D * (1 << i);
				}
			}
			cout << res << endl;
		}

	}
}











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

int main(void){
 
  char S[101];
  
  scanf("%s\n",S);
 
  for(int i=0;i<strlen(S)-1;i++){
   printf("x"); 
  }
  
  printf("x\n");
  
  return 0;
  
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,const P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 2e5;
int n, d[N];
ll i2=modInv(2, MOD), g[N];
V<int> e[N];
map<int, ll> m[N];
ll f(int a, int p){
  if(m[a][p]) return m[a][p];
  if(d[a]<0){
    d[a] = p;
    g[a] = i2;
    for(int b:e[a]) if(p!=b) g[a] = g[a] * (MOD+1-f(b, a)) % MOD;
    return m[a][p] = (MOD+1-g[a]) % MOD;
  }
  if(d[a]<n){
    g[a] = g[a] * (MOD+1-f(d[a], a)) % MOD;
    d[a] = n;
  }
  return m[a][p] = (MOD+1-g[a]*modInv((MOD+1-f(p, a))%MOD, MOD)%MOD) % MOD;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  scanf("%d", &n);
  fill(d, d+n, -1);
  FOR(_, 0, n-1){
    int a, b;
    scanf("%d %d", &a, &b);
    a--; b--;
    e[a].pb(b);
    e[b].pb(a);
  }
  if(n==2){
    printf("0\n");
    return 0;
  }
  ll ans = 0;
  FOR(a, 0, n) if(sz(e[a])>1){
    ll s = 1, p = 1;
    for(int b:e[a]){
      ll v = f(b, a), r = MOD+1-v;
      s += modInv(r, MOD) * v % MOD;
      p = p*r%MOD;
    }
    ans += (MOD+1-s%MOD*p%MOD) * i2 % MOD;
  }
  printf("%d\n", ans%MOD);
}

Measured memory_bytes: 62336
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        long ret = x/500*1000L + x%500/5*5;
        System.out.println(ret);
    }
}


Measured memory_bytes: 32640
#include<bits/stdc++.h>
using namespace std;
long long prime(long long a)
{
	long long y,i;
	y=sqrt(a);
	for(i=2;i<=y;i++)
	{
		if(a%i==0)
		{
			return -1;
		}
	}
	if(i>y)
	return 1;
}
int main()
{
	long long a,c,d;
	cin>>a;
	c=prime(a);
	if(c==1)
	{
		cout<<a-1;
	}
	else
	{
		d=sqrt(a);
		while(a%d!=0)
		{
			d--;
		}
		cout<<(d-1)+(a/d-1);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int gcd(int a, int b)
{
	if(a == 0)
		return b;

	return gcd(b % a, a);
}

int main(int argc, char const *argv[])
{
	//ifstream cin("input.txt");
	ll n,k;
	cin>>n>>k;
	
	n = n%k;
	cout<<min(n, abs(n-k));
}

Measured memory_bytes: 3632
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M = map(int, readline().split())

    ans = (N + M) * (N + M - 1) // 2 - N * M

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9108
#include<stdio.h>
int main()
{
  int N;
  int X[101]={};
  scanf("%d", &N);
  int i;
  int min=100, max=1;
  
  for(i=0;i<N;i++)
  {
	scanf("%d", &X[i]);
    if(X[i]>max)
      max=X[i];
    if(X[i]<min)
      min=X[i];
  }
  
  int p;
  int sum;
  int ans = 100 * 100 * 100;
  
  for(p=min;p<=max;p++)
  {
    sum = 0;
    for(i=0;i<N;i++)
    	sum += (X[i] - p)*(X[i] - p);
    if(sum<ans)
      ans = sum;
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 128
N, M = map(int,input().split())
A = list(map(int,input().split()))

S = sum(A)

f = S / (4 * M)

A.sort(reverse=True)

flag = 0

for i in range(M):
  if A[i] >= f:
    pass
  else:
    flag = 1
    break

if flag == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
import os, sys, re, math

lines = sys.stdin.readlines()

S = lines[0].strip()

accepted = False
if S[0] == 'A':
    if len(S[2:-1].replace('C', '')) == len(S[2:-1]) - 1:
        if len(re.sub(r'[A-Z]', '', S)) == (len(S) - 2):
            accepted = True
            exit

print ('AC' if accepted else 'WA')


Measured memory_bytes: 3316
import java.util.Scanner;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		new AOJ0092().doIt();
	}
	
	class AOJ0092{
		boolean[][] t;
		int[][] w;
		void doIt(){
			while(true){
				int n = in.nextInt();
				if(n==0)return;
				t = new boolean[n][n];
				w = new int[n][n];
				int result = 0;
				for(int i=0;i<n;i++){
					char[] a = in.next().toCharArray();
					for(int s=0;s<n;s++){
						t[i][s] = a[s]=='*';
						if(t[i][s]==false)result = 1;
					}
				}
				for(int i=0;i<n;i++)for(int s=0;s<n;s++)if(!t[i][s])w[i][s] = 1;
				for(int i=1;i<n;i++)for(int s=1;s<n;s++)if(w[i][s]>0){
					int plus = Math.min(w[i][s-1], Math.min(w[i-1][s], w[i-1][s-1]));
					w[i][s] += plus;
					result = Math.max(result, w[i][s]);
				}
				System.out.println(result);
			}
		}
	}
	
}

Measured memory_bytes: 62144
#include <iostream>
#include <algorithm>
using namespace std;
#define N 100001
int main(){
	int n,d[N]={};
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> d[i];
	}
	sort(d,d+n);
	int ct=0;
	ct=d[n/2]-d[n/2-1];
	cout << ct << endl;
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// a,b,cの入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if((a - c)*(b - c)<0) {
			// 出力
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll A, B;
	cin >> A >> B;
	cout << A*B - A - B + 1 << endl;
    return 0;
}

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

template<typename T> class Dijkstra {
public:
  struct edge {
    int to; T cost;
  };
  int V;
  vector<vector<edge>> G;
  vector<T> dist;
  vector<int> pre;
  using pti = pair<T,int>;
  Dijkstra(int n) : V(n), G(V), dist(V, numeric_limits<T>::max()), pre(V) {}
  void add(int u, int v, T cost) {
    G.at(u).push_back((edge) {v, cost});
  }
  void solve(int s) {
    priority_queue<pti, vector<pti>, greater<pti>> Q;
    dist.at(s) = 0;
    Q.push(pti(0, s));
    while (!Q.empty()) {
      pti p = Q.top();
      Q.pop();
      int v = p.second;
      if (dist.at(v) < p.first) continue;
      for (auto &w : G.at(v)) {
        if (dist.at(w.to) > dist.at(v) + w.cost) {
          dist.at(w.to) = dist.at(v) + w.cost;
          pre.at(w.to) = v;
          Q.push(pti(dist.at(w.to), w.to));
        }
      }
    }
  }
  vector<int> route(int from, int to) {
    vector<int> res;
    while (true) {
      res.push_back(to);
      if (to == from) break;
      to = pre.at(to);
    }
    reverse(res.begin(), res.end());
    return res;
  }
};

int N;
vector<vector<int>> G;
int cnt;
void dfs(int pre, int v, int ng) {
  cnt++;
  for (auto next : G.at(v)) {
    if (next == pre) continue;
    if (next == ng) continue;
    dfs(v, next, ng);
  }
}

int main() {
  cin >> N;
  G.resize(N);
  Dijkstra<int> D(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    D.add(--a, --b, 1);
    D.add(b, a, 1);
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  D.solve(0);
  auto res = D.route(0, N - 1);
  int tmp = res.size();
  int f = res.at(tmp - tmp / 2 - 1);
  int s = res.at(tmp - tmp / 2);
  dfs(-1, 0, s);
  int F = cnt;
  cnt = 0;
  dfs(-1, N - 1, f);
  int S = cnt;
  cout << ((F > S) ? "Fennec" : "Snuke") << "\n";
}

Measured memory_bytes: 17896
#include <cctype>
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    int count = 0;
    string w;
    cin >> w;
    while (true) {
        string t;
        cin >> t;
        if (t == "END_OF_TEXT") {
            break;
        }
        transform(t.begin(), t.end(), t.begin(), ::tolower);
        if (t == w) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}




Measured memory_bytes: 3200
#include <stdio.h>

int main(){
    int a,b,c;
    int p1,p2,p3,min;
    
    scanf("%d%d%d",&a,&b,&c);
    
    p1 = a+b;
    p2 = b+c;
    p3 = a+c;

    if(p1<=p2 && p1<=p3){
         min = p1;
    }
    else if(p2<=p1 && p2<=p3){
        min = p2;
    }
    else if(p3<=p1 && p3<=p2){
        min = p3;
    }
   

    printf("%d\n",min);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

typedef long long ll;
typedef pair<int, int> pii;

#define MAX 51

class node {
public:
	int id;
	int solve_cnt;
	int penalty;

	node(int id):id(id), solve_cnt(0), penalty(0) {
		memset(wrong_cnt, 0, sizeof(wrong_cnt));
	}

	int wrong_cnt[MAX];

	void inc_wrong(int i) { wrong_cnt[i]++; }
	void solve(int i, int time)
	{
		penalty += time + wrong_cnt[i] * 1200;
		solve_cnt++;
	}

	bool operator<(const node& r) const {
		if (solve_cnt == r.solve_cnt &&
			penalty == r.penalty)
			return id < r.id;
		else if (solve_cnt == r.solve_cnt)
			return penalty < r.penalty;
		else
			return solve_cnt > r.solve_cnt;
	}
};

int main(void)
{
	int t, p, r;
	while (cin >> t >> p >> r, t|p|r) {
		vector<node> nodes;
		rep(i, t)
			nodes.push_back(node(i));
	
		rep(i, r) {
			int tid, pid, time;
			string message;
			cin >> tid >> pid >> time >> message;
			tid--; pid--;
			if (message == "WRONG")
				nodes[tid].inc_wrong(pid);
			else
				nodes[tid].solve(pid, time);
		}
		sort(ALL(nodes));
		rep(i, nodes.size())
			printf("%d %d %d\n", nodes[i].id+1, nodes[i].solve_cnt, nodes[i].penalty);
	}
	return 0;
}

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

int main() {
  int a,b;
  cin >> a ;

  b = a%10 ;
  a = a/10 ;

  b = b + a%10;
  a = a/10;

  b = b + a%10;
  a = a/10;

  cout << b <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
int a[100];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int ji=0;
        //int maxx=-1;
        rep(i,1,n+1)
        {
            scanf("%d",&a[i]);
            if(abs(a[i])>=abs(a[ji]))
            {
                ji=i;
            }
        }
        printf("%d\n",2*n-1);
        rep(i,1,n+1)
        {
            printf("%d %d\n",ji,i);
        }
        if(a[ji]>=0)
        {
            rep(i,1,n)
            {
                printf("%d %d\n",i,i+1);
            }
        }
        else
        {
            for(int i=n;i>1;i--)
            {
                printf("%d %d\n",i,i-1);
            }
        }
    }
    return 0;
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

int main() 
{
	int ans = 0;
	string s;
	cin >> s;

	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '+')
		{
			ans++;
		}
		else
		{
			ans--;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;

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

	int n;
	cin >> n;
	int a, b;
	int ans = 0;
	rep(i, n) {
		cin >> a >> b;
		ans += b - a + 1;
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>

using namespace std;
typedef long long ll;

ll N, A[100001] = {}, sum[100002] = {};

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		if (i == 1) {
			sum[1] = abs(A[1]);
		}
		else {
			sum[i] = sum[i - 1] + abs(A[i] - A[i - 1]);
		}
	}
	sum[N + 1] = sum[N] + abs(A[N]);
	cout << sum[N + 1] - abs(A[1]) - abs(A[2] - A[1]) + abs(A[2]) << endl;
	for (int i = 2; i < N; i++)cout << sum[N + 1] - abs(A[i + 1] - A[i]) - abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i - 1]) << endl;
	cout << sum[N + 1] - abs(A[N]) - abs(A[N] - A[N - 1]) + abs(A[N - 1]) << endl;
	return 0;
}

Measured memory_bytes: 2816
import math
n=int(input())
t=0

for i in range(n):
    if (i+1)%2==0:
        continue
    else :
        s=0
        for j in range(i+1):
            if (i+1)%(j+1)==0:
                s+=1
        if s==8:
            t+=1
print(t)

Measured memory_bytes: 9120
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    vector<int> stand;
    vector<int> reverse;

    int count = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
            count++;
        } else {
            if (count) {
                stand.push_back(count);
                count = 0;
            }
        }
    }
    if (count) {
        stand.push_back(count);
    }

    count = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '1') {
            count++;
        } else {
            if (count) {
                reverse.push_back(count);
                count = 0;
            }
        }
    }
    if (count) {
        reverse.push_back(count);
    }

    vector<int> stand_cum(stand.size()+1);
    stand_cum[0] = 0;
    for (int i = 0; i < stand.size(); i++) {
        stand_cum[i+1] =  stand_cum[i] + stand[i];
    }
    vector<int> reverse_cum(reverse.size()+1);
    reverse_cum[0] = 0;
    for (int i = 0; i < reverse.size(); i++) {
        reverse_cum[i+1] = reverse_cum[i] + reverse[i];
    }

    int ans = 0;
    if (stand.size() <= k) {
        ans = n;
    } else {
        reverse_cum.push_back(reverse_cum[reverse_cum.size()-1]);
        for (int i = 0; i < stand.size()-k+1; i++) {
            if (s[0] == '1') {
                ans = max(ans, stand_cum[i+k] - stand_cum[i] + reverse_cum[i+k+1] - reverse_cum[i]);
            } else {
                if (i == 0) {
                    ans = max(ans, stand_cum[i+k] - stand_cum[i] + reverse_cum[i+k] - reverse_cum[i]);
                } else {
                    ans = max(ans, stand_cum[i+k] - stand_cum[i] + reverse_cum[i+k] - reverse_cum[i-1]);
                }
            }
        }
    }

    cout << ans << endl;


}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

int dx[] = { 1, 4, -1, -4 };

signed main(){
    map<string, int> ans;
    ans["01234567"] = 1;

    queue<string> que;
    que.push( "01234567" );
    while( !que.empty() ){
        string s = que.front(); que.pop();
        int p0;
        REP( i, 8 ) if( s[i] == '0' ) p0 = i;
        REP( i, 4 ){
            if( 0 <= p0 + dx[i] && p0 + dx[i] < 8 &&
                !( p0 == 3 & i == 0 ) && !( p0 == 4 && i == 2 ) ){
                    string t = s;
                    swap( t[p0], t[p0 + dx[i]] );

                    if( ans[t] == 0 ){
                        ans[t] = ans[s] + 1;
                        que.push( t );
                    }
                }
        }
    }

    while( 1 ){
        string s;
        REP( i, 8 ){
            char c;
            if( !( cin >> c ) ) return 0;
            s += c;
        }

        cout << ans[s] - 1 << endl;
    }
}


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

int main(){
    string a,b;
    cin>>a;
    if(a=="A")b="T";
    if(a=="C")b="G";
    if(a=="G")b="C";
    if(a=="T")b="A";
    cout<<b<<endl;
}

Measured memory_bytes: 256
N, M = [int(_) for _ in input().split()]
S = input()
T = input()

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a

L = N * M // gcd(N, M)

cs = {}

for i in range(N):
    cs[L // N * i + 1] = S[i]

result = L

for i in range(M):
    j = L // M * i + 1
    if j in cs and cs[j] != T[i]:
        result = -1
        break

print(result)


Measured memory_bytes: 15396
// abc156_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<int> X(N);
    REP(i, N) cin >> X[i];

    int ans = 0;
    int mn = INF;

    REP(x, 101){

        int tmp = 0;
        REP(i, N) tmp += (X[i] - x) * (X[i] - x);

        if (tmp < mn){
            ans = x;
            mn = tmp;
        }
    }

    print(mn);


    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class Abc_086_C
    {
        // https://atcoder.jp/contests/abc086/tasks/arc089_a
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            int N = int.Parse(Console.ReadLine());

            int[] t = new int[N + 1];
            int[] x = new int[N + 1];
            int[] y = new int[N + 1];
            y[0] = x[0] = y[0] = 0;

            for (int i = 1; i <= N; ++i)
            {
                int[] inputIntArray = Console.ReadLine().Split(' ').Select(j => int.Parse(j)).ToArray();
                t[i] = inputIntArray[0];
                x[i] = inputIntArray[1];
                y[i] = inputIntArray[2];
            }

            var flag = true;
            for (int i = 0; i < N; ++i)
            {
                var time = t[i + 1] - t[i];
                var dist = Math.Abs(x[i + 1] - x[i]) + Math.Abs(y[i + 1] - y[i]);
                if (time < dist) flag = false;
                if (Math.Abs(time - dist) % 2 != 0) flag = false;
            }

            if (flag) Console.WriteLine("Yes");
            else Console.WriteLine("No");

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 17496
Q,H,S,D = map(int,input().split())
N = int(input())
Q_l = [8*Q,0.25,Q]
H_l = [4*H,0.5,H]
S_l = [2*S,1,S]
D_l = [D,2,D]
L = [Q_l,H_l,S_l,D_l]
L.sort()
cost = 0
for e in L:
    num = int(N // e[1])
    N -= (num) * e[1]
    cost += num * e[2]
print(cost)

Measured memory_bytes: 3064
s=list(input())
n=len(s)
a=(n-1)//2
b=(n+3)//2
ans=0
ss=[]
for i in range(a):
    ss.append(s[i])
if a%2==0:
    aa=a//2
    for i in range(aa):
        if ss[i]!=ss[-(i+1)]:
            ans=1
            break
else:
    aa=(a-1)//2
    for i in range(aa):
        if ss[i]!=ss[-(i+1)]:
            ans=1
            break
if ans==0:
    al=n-(b-1)
    if al%2==0:
        bb=al//2
        for i in range(b-1,n):
            if s[i]!=s[-(i+1)]:
                ans=1
                break
    else:
        bb=(al-1)//2
        for i in range(b-1,n):
            if s[i]!=s[-(i+1)]:
                ans=1
                break
print("Yes" if ans==0 else "No")

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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; i++){
        cin >> d.at(i);
    }
    int sum = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            sum = sum + d.at(i) * d.at(j);
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;

string s;
int c[26];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  ll l = sz(s), ans = l*(l-1)/2 + 1;
  FOR(i, 0, l){
    int a = s[i] - 'a';
    ans -= c[a];
    c[a]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 720
#include <stdio.h>
int main() {
    int S, h, m, s;
    
    scanf("%d", &S);
    
    h = S / 3600;
    m = (S - h * 3600) / 60;
    s = S % 60;
    
    printf("%d:%d:%d\n", h, m, s);
    
    return 0;
}


Measured memory_bytes: 2144
import math
N,K = list(map(int, input().split()))

#1,2,4,8,16...
# max coin num
ans = 0


for i in range(1, N+1):
    coin = math.log2(K/i)
    if coin > 0:
        if coin % 1 == 0:
            coin = int(coin)
        else:
            coin = int(coin) + 1
        ans += (0.5) ** coin
    else:
        ans += 1
    
    

# ans = (1/N) * (1 - (2 ** N))  * (0.5 ** max_coin) * (-1)
# ans = (1/N) * ((math.exp(N*math.log(2))) -1)  * (0.5 ** max_coin)
print(ans/N)

Measured memory_bytes: 3060
# include <iostream>
using namespace std;
bool search(int *a,int n,int tar)
{
	for(int i = 0;i < n;i++) if(a[i] == tar) return true;
	return false;
}
int main(void)
{
	int *a,ans = 0,n,m,k;
	scanf("%d",&n); a = new int [n];
	for(int i = 0;i < n;i++) scanf("%d",&a[i]);
	scanf("%d",&m);
	for(int i = 0;i < m;i++) 
	{
		scanf("%d",&k);
		ans += search(a,n,k);
	}
	printf("%d\n",ans);
	return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<long long int> a(N+1);
    a[0] = 2;
    a[1] = 1;
    for(int i = 2; i < N+1; i++){
        a[i] = a[i-1] + a[i-2];
    }
    cout << a[N] << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
//#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
std::random_device rd;
std::mt19937 mt(rd());
constexpr int MOD = 1e9 + 7; constexpr int MAX = 200020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e16;
typedef array<int, 3>arr3;


bool dp[4005000];
int cum[2020];
void solve() {
	int N; cin >> N;
	vector<int>A(N);
	REP(i, N) {
		cin >> A[i];
		cum[i + 1] = cum[i] + A[i];
	}
	int mid = (cum[N] + 1) / 2;
	dp[0] = true;

	REP(i, N) {
		int mn = min(2000001, cum[i]+1);
		REPR(j, mn) {
			dp[j + A[i]] |= dp[j];
		}
	}
	FOR(i, mid, cum[N] + 1) {
		if (dp[i]) {
			print(i); return;
		}
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
		solve();
}



Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	VL prime(1e6,1),nom;
	fr(i,2,1e6)
	{
		if(prime[i]==1)
		{
			nom.PB(i);
			for(ll j=i;j<=1e6;j+=i)
			{
				prime[j]=0;
			}
		}
	}
	// fr(i,0,SZ(nom))
	// {
	// 	cout<<nom[i]<<" ";
	// }
	// NL;
	ll x;
	rl(x);
	VL::iterator low;
	low=lower_bound(ALL(nom),x);
	ll ans=nom[low-nom.begin()];
	//cout<<low-nom.begin()<<endl;
	wl(ans);
	NL;
	return 0;
}

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

int main(){
    int n;
    cin >> n;

    int a = 0;
    int max = -1;
    int min = 1005;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a > max){
            max = a;
        }
        if(a < min){
            min = a;
        }
    }

    cout << max - min << endl;
}

Measured memory_bytes: 256