akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    char c;
    cin >> c;
    if(c == 'A') cout << 'T';
    else if(c == 'T') cout << 'A';
    else if(c == 'C') cout << 'G';
    else cout << 'C';
    cout << endl;
}

Measured memory_bytes: 256
import math

n = int(input())
arr = sorted([int(_) for _ in input().split()])
MAX = max(arr)
MIN = min(arr)
val = 99999999999999

for i in range(MIN, MAX+1):
  for j in range(len(arr)-n+1):
    if val > sum([math.pow(i-_, 2) for _ in arr[j:j+n]]):
      val = sum([math.pow(i-_, 2) for _ in arr[j:j+n]])
print(int(val))


Measured memory_bytes: 3064
#include<stdio.h>
#define INF 2140000000
#define N 102
#define white 0
#define gray 1
#define black 2

//単一始点最短経路
//０までの最短距離を求めるプログラム

int color[N],p[N],d[N];      //ｐは親、ｄは距離

void dijkstra(int a[][N],int n){
  int i,mincost,u;

  for(i=0;i<n;i++){           //色と距離を初期化
    color[i]=white;
    d[i]=INF;
  }

  d[0]=0;                  //配列の０から考えるので、d[0]の距離は０で親はいないのでp[0]はー１
  p[0]=-1;

  while(1){
    mincost=INF;

    for(i=0;i<n;i++){             //辺の中で一番小さいものを探す
      if(color[i]!=black && d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }

    if(mincost==INF) break;     //すべての探索が終わっている場合、プログラムを終了させる
    
    color[u]=black;          //移動した先の頂点を黒にする

    for(i=0;i<n;i++){
      if(color[i]!=black && a[u][i]!=-1 && d[i]>a[u][i]+d[u]){  //辺があり、一番小さいものを探し出す
	d[i]=a[u][i]+d[u];
	p[i]=u;
	color[i]=gray;
      }
    }
  }
}

void print(int a[][N], int n){
  int i;
  for(i=0;i<n;i++){    //0は距離がないので、１から始まる。
    printf("%d %d\n",i,d[i]);
  }
}

int main(){
  int a[N][N],n,i,j,v,k,u,c;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      a[i][j]=-1;
    }
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      a[u][v]=c;           
    }
  }

  dijkstra(a,n);
  print(a,n);

  return 0;
}



Measured memory_bytes: 2048
#include<iostream>
#include<map>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int x;
    long long int sum = 0;
    map<int,int>mp;
    for(int i = 0;i<n;i++)
    {
        cin>>x;
        mp[x]++;
        sum += x ;
    }

    int m;
    cin>>m;
    for(int i = 0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;

        if(mp.find(a)!=mp.end())
        {
            sum = sum-(mp[a]*1LL*a*1);
            sum = sum+(mp[a]*1LL*b);
            int l = mp[a];
            mp.erase(a);
            if(mp.find(b)!=mp.end())
            {
                mp[b] = mp[b]+l;
            }
            else
            {
                mp[b] = l;
            }

        }


        cout<<sum<<"\n";
    }

}


Measured memory_bytes: 6524
from collections import Counter

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

if len(set(v)) == 1:
    print(n//2)
else:
    c1 = Counter(v[0::2])
    c2 = Counter(v[1::2])
    
    c1m = c1.most_common(2)
    c2m = c2.most_common(2)
    
    if c1m[0][0] != c2m[0][0]:
        print(n-c1m[0][1]-c2m[0][1])
    else:
        mn = n
        if len(set(c1)) > 1:
            mn = min(mn, n-c1m[1][1]-c2m[0][1])
        if len(set(c2)) > 1:
            mn = min(mn, n-c1m[0][1]-c2m[1][1])
            
        print(mn)

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

int main(){
  
  string S;
  cin >>S;
  
  int num1 = 0;
  int num0 = 0;
  
  for(int i=0;i<S.size();i++){
    if(S[i]=='1')num1 ++;
    if(S[i]=='0')num0 ++;
  }
  
  cout << 2*min(num1,num0) << endl;
  
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define int ll

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

  int A,B,Q;
  cin>>A>>B>>Q;
  vector<int>s(A),t(B),x(Q);
  for(int i=0;i<A;i++)cin>>s[i];
  for(int i=0;i<B;i++)cin>>t[i];
  for(int i=0;i<Q;i++)cin>>x[i];
  sort(rng(s));
  sort(rng(t));
  for(int i=0;i<Q;i++){
    int ans=INF;

    int sl=-1;
    int sr=A;
    int sm;
    while(sr-sl>1){
      sm=(sr+sl)/2;
      if(s[sm]<x[i])sl=sm;
      else sr=sm;
    }

    int tl=-1;
    int tr=B;
    int tm;
    while(tr-tl>1){
      tm=(tr+tl)/2;
      if(t[tm]<x[i])tl=tm;
      else tr=tm;
    }

    //s -> t <-
    if(0<=sr&&sr<A&&0<=tl&&tl<B)ans=min(ans,2*abs(x[i]-s[sr])+abs(x[i]-t[tl]));
    //s <- t ->
    if(0<=sl&&sl<A&&0<=tr&&tr<B)ans=min(ans,2*abs(x[i]-s[sl])+abs(x[i]-t[tr]));
    //t -> s <-
    if(0<=sl&&sl<A&&0<=tr&&tr<B)ans=min(ans,2*abs(x[i]-t[tr])+abs(x[i]-s[sl]));
    //t <- s ->
    if(0<=sr&&sr<A&&0<=tl&&tl<B)ans=min(ans,2*abs(x[i]-t[tl])+abs(x[i]-s[sr]));
    //st ->
    if(0<=sl&&sl<A&&0<=tl&&tl<B)ans=min(ans,abs(x[i]-min(s[sl],t[tl])));
    //st <-
    if(0<=sr&&sr<A&&0<=tr&&tr<B)ans=min(ans,abs(max(s[sr],t[tr])-x[i]));
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 3712
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

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

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using Graph = vector<vector<int> >;//隣接リスト
 
vector<bool> seen;
bool check = true;
int ans = 0;
void dfs(Graph &G, int v) {
    seen[v] = true;
    rep(i, 1, seen.size()) {
        if (seen[i] == false) {
            check = false;
            break;
        }
    }
    if (check) {
        ++ans;
    }
    check = true;
    for (auto next_v: G[v]) {
        if (seen[next_v]) {
            continue;
        }
        dfs(G, next_v);
    }
    seen[v] = false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M, s, t;
    cin >> N >> M;
    Graph G(N+1);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        //無向グラフ
        G[b].push_back(a);
    }

    seen.assign(N+1, false);
    dfs(G, 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
static const int MAX_N = 100000;

int N;
int a[MAX_N], b[MAX_N], c[MAX_N];
int memo[MAX_N][3];

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d %d %d", &a[i], &b[i], &c[i]);
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 3; j++){
			if(i == 0){
				if(j == 0) memo[i][j] = a[i];
				if(j == 1) memo[i][j] = b[i];
				if(j == 2) memo[i][j] = c[i];
			}else{
				for(int k = 0; k < 3; k++){
					if(k == j) continue;
					if(j == 0) memo[i][j] = max(memo[i][j], memo[i - 1][k] + a[i]);
					if(j == 1) memo[i][j] = max(memo[i][j], memo[i - 1][k] + b[i]);
					if(j == 2) memo[i][j] = max(memo[i][j], memo[i - 1][k] + c[i]);
				}
			}
		}
	}
	int res = 0;
	for(int i = 0; i < 3; i++) res = max(res, memo[N - 1][i]);
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 2560
function Main(input){
  input = input.split(' ').map(num => Number(num));

  input.sort(function(a,b){
    if( a < b ) return -1;
    if( a > b ) return 1;
    return 0;
});

    if(input.toString() === [5,5,7].toString()) {
        console.log('YES');
    } else {
        console.log('NO');
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  vector<int>a(3),b(3);
  vector<int>g[4];
  for(int i=0;i<3;i++){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  
  for(int i=0;i<4;i++){
    if(g[i].size()==3){cout<<"NO"<<endl;return 0;}
  }
  cout<<"YES"<<endl;
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
using namespace std;
using ll = long long;
int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if(c - a - b <= 0) {
    cout << "No" << endl;
    return 0;
  }
  ll lhs = c - a - b;
  lhs *= lhs;
  ll rhs = 4 * a * b;
  cout << (rhs < lhs ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int s[250005][2];
int f[505][505];
bool used[505][505];
int main()
{
	srand((unsigned int)time(NULL));
	while(1)
	{
		int lim;
		scanf("%d",&lim); if(!lim) return 0;
		for(int q=0;q<2;q++)
		{
			memset(used,0,sizeof(used));
			int cnt=1;
			int w,h,x,y; scanf("%d%d%d%d",&w,&h,&x,&y);
			for(int i=1;i<=h;i++)for(int j=1;j<=w;j++) scanf("%d",&f[i][j]);
			priority_queue<P1,vector<P1>,greater<P1> >que;
			que.push(mp(f[y][x],mp(y,x)));
			for(int i=1;i<=lim;i++) s[i][q]=INF;
			while(!que.empty())
			{
				int v=que.top().f;
				int x=que.top().s.f; int y=que.top().s.s;
				que.pop();
				if(used[x][y]) continue;
				used[x][y]=true;
				s[cnt][q]=max(s[cnt-1][q],v); cnt++;
				int dx[4]={0,1,0,-1};
				int dy[4]={1,0,-1,0};
				for(int i=0;i<4;i++)
				{
					int nx=x+dx[i];
					int ny=y+dy[i];
					if(!(1<=nx && nx<=h)) continue;
					if(!(1<=ny && ny<=w)) continue;
					if(used[nx][ny]) continue;
					que.push(mp(f[nx][ny],mp(nx,ny)));
				}
			}
		}
		int ret=INF;
		for(int i=0;i<=lim;i++)
		{
			ret=min(ret,s[i][0]+s[lim-i][1]);
		}
		printf("%d\n",ret);
	}
}

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

int main(){
    int W,a,b;
    cin >> W >> a >> b;
    if ((b <= (a+W) && b >= a) || ((b+W) >= a && (b+W) <= (a+W))){ 
        cout << 0 << endl;
    }
    else if (b > (a+W)){
        cout << b - (a + W) << endl;
    }
    else if ((b+W) < a){
        cout << a - (b + W) << endl;;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#include <numeric>
using namespace std;
 int main(){
 int n,m;
 string s="Yes"; 
 cin>>n>>m;
 int a[n];
 rep(i,n) cin>>a[i];
 sort(a,a+SIZE_OF_ARRAY(a),greater<>());

 rep(i,m) {
  if (a[i]<((1/double((4*m)))*accumulate(a, a+SIZE_OF_ARRAY(a), 0))){
  s="No";}
 			}
cout<<s<<endl;
 }

Measured memory_bytes: 256
n = int(input())
r = []
for i in range(n):
    r.append(int(input()))

maxv = (-10) ** 9
minv = r[0]
for i in range(1, n):
    maxv = max([r[i] - minv, maxv])
    minv = min([r[i], minv])


print(maxv)



Measured memory_bytes: 13596
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << " = " << x << ".\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define print(xx) cout << (xx) << endl
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
const int INF = ((1LL << 30) + (1LL << 29));
const ll MOD = 1000000007;

/* 

*/
//================== INPUT ========================
int N;
vector<int> O;
vector<int> E;
//=================================================
void input()
{
    cin>>N;
    rep(i,N){
        int tmp;
        cin>>tmp;
        if (i%2) O.push_back(tmp);
        else E.push_back(tmp);
    }
}
//=================================================
void solve()
{
    map<int,int> Ocnt;
    map<int,int> Ecnt;
    for (auto x: O)Ocnt[x]++;
    for (auto x: E)Ecnt[x]++;

    vector<pii> Ofreq;
    vector<pii> Efreq;

    for(auto x: Ocnt){
        Ofreq.push_back(pii(x.second,x.first));
    }
    for (auto x: Ecnt) {
        Efreq.push_back(pii(x.second,x.first));
    }
    sort(Ofreq.rbegin(),Ofreq.rend());
    sort(Efreq.rbegin(),Efreq.rend());
    Ofreq.push_back(pii(0,0));
    Efreq.push_back(pii(0,0));
    

    if (Ofreq[0].second != Efreq[0].second){
        cout<<(N-Ofreq[0].first-Efreq[0].first)<<endl;
    }
    else {
        if (Ofreq[1].first > Efreq[1].first){
            cout<<(N-Ofreq[1].first - Efreq[0].first)<<endl;
        }
        else {
            cout<<(N-Ofreq[0].first - Efreq[1].first)<<endl;
        }
        
    }

}

//=================================================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 9584
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<climits>
using namespace std;

int w,h;
int check[40][40][40][40];
int ans;
vector<vector<int> > input;

int loop(int count){

  int flag=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(input[i][j]==count){
	if(i>0){
	  if(check[i][j][i-1][j]==0){
	    input[i-1][j]=min(input[i-1][j],count+1);
	    flag=1;
	  }
	}
	if(j>0){
	  if(check[i][j][i][j-1]==0){
	    input[i][j-1]=min(input[i][j-1],count+1);
	    flag=1;
	  }
	}

	if(i<h-1){
	  if(check[i][j][i+1][j]==0){
	    input[i+1][j]=min(input[i+1][j],count+1);
	    flag=1;
	  }
	}
	if(j<w-1){
	  if(check[i][j][i][j+1]==0){
	    input[i][j+1]=min(input[i][j+1],count+1);
	    flag=1;
	  }
	}
      }
    }
  }

  return flag;
}




int main(){

  while(cin >> w >> h,w||h){
    input.clear();
    input.resize(h);
    memset(check,0,sizeof(check));

    for(int i=0;i<h;i++){
      input[i].resize(w,INT_MAX);
	int tmp;
      for(int j=0;j<w-1;j++){
	cin >> tmp;
	check[i][j][i][j+1]=tmp;
	check[i][j+1][i][j]=tmp;
      }
      if(i!=h-1){
	for(int j=0;j<w;j++){
	  cin >>tmp;
	  check[i][j][i+1][j]=tmp;
	  check[i+1][j][i][j]=tmp;
	}
      }
    }

    /*    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++)
	cout << check[i][j][i+1][j] << " ";
      cout << endl;
      }*/

    //    return 0;
    input[0][0]=0;
    for(int i=0;;i++){
      //      cout << i << endl; 
      int tmp;
      if(loop(i)==0) break;
    }

    if(input[h-1][w-1]==INT_MAX)
      input[h-1][w-1]=(-1);
    cout << input[h-1][w-1]+1 << endl;
  }

  return 0;
} 

Measured memory_bytes: 10000
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  if(S=="Sunny"){
    cout<<"Cloudy"<<endl;
  }
  else if(S=="Cloudy"){
    cout<<"Rainy"<<endl;
  }
  else
  {
      cout<<"Sunny"<<endl;
  }
  
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define PB(a,num) FOR(i,0,num) {ll x; scanf("%lld",&x); a.pb(x); }
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define INF 111111111111111111
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef set<ll> SET;
typedef map<ll, ll> MAP;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[8] = { 1,-1,0,0,1,1,-1,-1 }, ddy[8] = { 0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 111111


ll gcd(ll x, ll y) {
  if (x < y) swap(x, y);
  return y ? gcd(y, x%y) : x;
}

ll lcm(ll w, ll z) {
  return w * (z / gcd(w, z));
}

int main(void) {
  cin >> n;
  ans = 1;
  FOR(i, 0, n) {
	cin >> tmp;
	ans = lcm(ans, tmp);
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    int l,r;
    while (cin >> l >> r)
    {
        ans += r-l+1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] strs = line.Split(' ');
            long N = long.Parse(strs[0]);
            long K = long.Parse(strs[1]);

            long min = N;
            if (N < K)
            {
                if (min > Math.Abs(N - K)) min = Math.Abs(N - K);
                if (min > Math.Abs(K - N)) min = Math.Abs(K - N);
            }
            else
            {
                if (min > N % K) min = N % K;
                if (min > Math.Abs(min - K)) min = Math.Abs(min - K);
            }

            Console.WriteLine(min);
        }
    }
}


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

using namespace std;

int main ()
{
	string input , start , output , ans;
	map<char , string>code;
	code[' '] = "101" ,
	code['\''] = "000000" ,
	code[','] = "000011" ,
	code['-'] = "10010001" ,
	code['.'] = "010001" ,
	code['?'] = "000001" ,
	code['A'] = "100101" ,
	code['B'] = "10011010" ,
	code['C'] = "0101" ,
	code['D'] = "0001" ,
	code['E'] = "110" ,
	code['F'] = "01001" ,
	code['G'] = "10011011" ,
	code['H'] = "010000" ,
	code['I'] = "0111" ,
	code['J'] = "10011000" ,
	code['K'] = "0110" ,
	code['L'] = "00100" ,
	code['M'] = "10011001" ,
	code['N'] = "10011110" ,
	code['O'] = "00101" ,
	code['P'] = "111" ,
	code['Q'] = "10011111" ,
	code['R'] = "1000" ,
	code['S'] = "00110" ,
	code['T'] = "00111" ,
	code['U'] = "10011100" ,
	code['V'] = "10011101" ,
	code['W'] = "000010" ,
	code['X'] = "10010010" ,
	code['Y'] = "10010011" ,
	code['Z'] = "10010000";


	map<string , char>code2;
	code2["00000"] = 'A' ,
	code2["00001"] = 'B' ,
	code2["00010"] = 'C' ,
	code2["00011"] = 'D' ,
	code2["00100"] = 'E' ,
	code2["00101"] = 'F' ,
	code2["00110"] = 'G' ,
	code2["00111"] = 'H' ,
	code2["01000"] = 'I' ,
	code2["01001"] = 'J' ,
	code2["01010"] = 'K' ,
	code2["01011"] = 'L' ,
	code2["01100"] = 'M' ,
	code2["01101"] = 'N' ,
	code2["01110"] = 'O' ,
	code2["01111"] = 'P' ,
	code2["10000"] = 'Q' ,
	code2["10001"] = 'R' ,
	code2["10010"] = 'S' ,
	code2["10011"] = 'T' ,
	code2["10100"] = 'U' ,
	code2["10101"] = 'V' ,
	code2["10110"] = 'W' ,
	code2["10111"] = 'X' ,
	code2["11000"] = 'Y' ,
	code2["11001"] = 'Z' ,
	code2["11010"] = ' ' ,
	code2["11011"] = '.' ,
	code2["11100"] = ',' ,
	code2["11101"] = '-' ,
	code2["11110"] = '\'' ,
	code2["11111"] = '?';


	while( getline ( cin , input ) )
	{
		output = "";
		ans = "";
		for( auto x : input )
		{
			output += code[x];
		}
		while( output.size () % 5 )output += "0";
		for( size_t i = 0; i < output.size (); i += 5 )
		{
			ans += code2[output.substr ( i , 5 )];
		}
		cout << ans << endl;
	}
}

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

int main(){
  int N;
  cin >> N;
  vector<double> X(N);
  vector<string> U(N);
  for(int i=0;i<N;i++){
    cin >> X.at(i) >> U.at(i);
  }
  int sumA = 0;
  double sumB = 0;
  for(int i=0;i<N;i++){
    if(U.at(i) == "BTC"){
      sumB += X.at(i);
    }else{
      sumA += X.at(i);
    }
  }
  cout << sumA + sumB * 380000 << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  vector<int> b;
  for (int i = 1; i < n; i++) {
    if (a.at(i - 1) < a.at(i)) b.emplace_back(0);
    else if (a.at(i - 1) > a.at(i)) b.emplace_back(1);
  }
  
  int count = 0;
  for (int i = 1; i < b.size(); i++) {
    if (b.at(i - 1) != b.at(i)) {
      count++;
      i++;
    }
  }
  
  cout << 1 + count << '\n';
}

Measured memory_bytes: 1276
n, q = gets.split().map(&:to_i)
$graph = Array.new(n).map{Array.new()}
$seen = []
$ans = Array.new(n, 0)

(n-1).times do
  a, b = gets.split().map(&:to_i)
  $graph[a-1] << b-1
  $graph[b-1] << a-1
end

q.times do 
  root, point = gets.split().map(&:to_i)
  $ans[root-1] += point
end

que=[0]
while n=que.shift
  $seen[n] = true
  $graph[n].each do |to|
    next if $seen[to]
    $ans[to] += $ans[n]
    que << to
  end 
end

puts $ans.join(' ')

Measured memory_bytes: 28924
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll a,b,c; cin >> a >> b >> c;
    if(a==b && b==c) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static AtCoderer.Exter;
using static System.Console;
using static System.Math;
using System.Linq;

namespace AtCoderer
{

    public class App
    {
        public static void Main(string[] args)
        {
            double Perc = 0;
            var r = readarr;
            double n = r[0], k = r[1];
            for (int i = 1; i <= n; i++)
            {
                int p = 0;
                for (int j = i; j < k; j *= 2)
                {
                    p++;
                }
                Perc += Pow(0.5,p);
            }
            cout = Perc / n;
            Console.ReadKey();
        }
    }
    public static class Exter
    {
        public static void rep(int loop, Action<int> act)
        {
            for (int i = 0; i < loop; i++)
                act(i);
        }
        public static int ToInt(this string v) => int.Parse(v);
        public static int Max(params int[] p) => p.Max();
        public static long Max(params long[] p) => p.Max();
        public static int Min(params int[] p) => p.Min();
        public static long Min(params long[] p) => p.Min();
        public static int Gcd(int a, int b) => a > b ? GcdRecursive(a, b) : GcdRecursive(b, a);
        private static int GcdRecursive(int a, int b) => b == 0 ? a : GcdRecursive(b, a % b);
        public static object cout
        {
            set
            {
                Console.Write(value.ToString());
                Console.WriteLine();

            }
        }
        public static void ToCout<t>(this IEnumerable<t> v)
        {
            cout = string.Join(",", v);
        }
        public static int[] readarr
        {
            get
            {
                preadarr = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
                return preadarr;
            }
        }
        public static int[] preadarr;
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <set>
#include <iomanip>
#include <unordered_map>
#include <cmath>
#define int long long
#define pii pair<int, int>
typedef long long ll;
using namespace std;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}

int a[4];

signed main() {
	fast();
	for (int i = 0; i < 4; i++) cin >> a[i];
	sort(a, a + 4);
	while (true) {
		if (a[0] * 1000 + a[1] * 100 + a[2] * 10 + a[3] == 1974) {
			cout << "YES";
			return 0;
		}
		if (!next_permutation(a, a + 4)) {
			break;
		}
	}
	cout << "NO";
	return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

struct edge {
    int to, from;
};

const int MAX_N = 100000;

vector<edge> G[MAX_N + 1];

int N, M;

void tracePath(int s, int p, int& ans);

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

    cin >> N >> M;

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        edge et = { a, b };
        G[b].push_back(et);
        edge es = { b, a };
        G[a].push_back(es);
    }

    int ans = 0;

    tracePath(1, 0, ans);

    cout << ans << "\n";

    return 0;
}

void tracePath(int s, int p, int& ans)
{
    if (p == (1 << (N - 1)) - 1) {
        ans++;
        return;
    }
    vector<edge> v = G[s];
    for (int i = 0; i < v.size(); i++) {
        edge e = v[i];
        if (e.to != 1 && !(p & (1 << (e.to - 2)))) {
            int np = p | (1 << (e.to - 2));
            tracePath(e.to, np, ans);
        }
    }
    return;
}

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

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";

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

char ch[] = { 'N','S','E','W' };



template <class T> inline T biton(T n, T pos)
{
	return n | ((T)1 << pos);
}
template <class T> inline T bitoff(T n, T pos)
{
	return n & ~((T)1 << pos);
}
template <class T> inline T ison(T n, T pos)
{
	return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b)
{
	while (b)
	{
		a = a % b;
		swap(a, b);
	}
	return a;
}
template <class T> inline T bigmod(T p, T e, T m)
{
	T ret = 1;
	for (; e > 0; e >>= 1)
	{
		if (e & 1)
			ret = (ret * p) % m;
		p = (p * p) % m;
	}
	return (T)ret;
};


#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " is " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define debug(...)
#endif

void solve()
{
	int a, b, c, k;
	cin >> a >> b >> c >> k;

	long long res = min(k, a);
	k = k - res;

	k = k - b;

	if (k <= 0) {
		cout << res << nl;
	}
	else {
		res = res - k;
		cout << res << nl;
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(10);
	cout.tie(nullptr);
	cin.tie(nullptr);

	int t = 1;

	while (t--)
	{
		solve();
	}

	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main(void) {
    ll N,M; cin >> N >> M;
    ll ans = 1;
    if(abs(N-M)>=2){
        ans = 0;
    }else if(abs(N-M)==1){
        if(M < N) swap(N,M);
        for(ll i = 1; i <= N; i++){
            (ans *= i)%=MOD;
        }
        ans = (ans * ((ans*M)%MOD))%MOD;
    }else{
        for(ll i = 1; i <= N; i++){
            (ans *= i)%=MOD;
        }
        ans = (((ans * ans)%MOD)*2)%MOD;
    }
    cout << ans << endl;
	return 0;
}

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

int main() {
    int n;
    long long int count = 0;
    map<string,long long int> m;
    cin >> n;
    string a[n];
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        sort(a[i].begin(),a[i].end());
        m[a[i]]++;
    }
    for(auto it = m.begin();it != m.end(); it++)
    {
        long long int c = it->second;
        count += (c*(c-1))/2;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 18176
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
const ll MOD = 1e9 + 7;
string s;
ll n;
vector<ll> o, e;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> s;
    o.pb(0);
    FOR(i, 1, 2 * n)
    {
        ll c = sz(o) - sz(e);
        if(c < 0)
        {
            cout << 0;
            return 0;
        }
        // cout << c << " ";
        if(s[i] == 'B')
        {
            if(c%2) e.pb(i);
            else o.pb(i);
        }
        else
        {
            if(c%2) o.pb(i);
            else e.pb(i);
        }
    }
    reverse(o.begin(), o.end());
    reverse(e.begin(), e.end());
    // for(auto i : o) cout << i << " ";
    // cout << "\n";
    // for(auto i : e) cout << i << " ";
    // cout << "\n";
    if(sz(o) != sz(e))
    {
        cout << 0;
        return 0;
    }
    ll res = 1;
    ll i = 0, j = 0, cnt = 0;
    while(i <= n - 1 && j <= n)
    {
        if(j == n || o[i] > e[j])
        {
            
            // cout << i << " " << j - cnt << " " << j <<  "\n";
            res *= j - cnt;
            i++;
            cnt++;
        } 
        else j++;
        res %= MOD;
    }
    ll mult = 1;
    F0R(i, n)
    {
        mult *= (i + 1);
        mult %= MOD;
    }
    mult %= MOD;
    cout << (res * mult)% MOD;
    return 0;
}

Measured memory_bytes: 3340
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<int> Num = {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};
    int K;
    cin >> K;
    cout << Num[K-1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    ll n,d,a;
    cin >> n >> d >> a;
    vector<LP> mon(n);
    rep(i,n) cin >> mon[i].first >> mon[i].second;
    sort(all(mon));
    ll ans = 0;
    ll sum = 0;
    queue<LP> q;
    rep(i,n) {
        while(!q.empty()) {
            auto p = q.front();
            if(p.first < mon[i].first) {
                q.pop();
                sum -= p.second;
            } else break;
        }
        if(sum >= mon[i].second) continue;
        ll x = (mon[i].second-sum+a-1)/a;
        ans += x;
        q.emplace(mon[i].first+d*2,x*a);
        sum += x*a;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992
#import numpy as np
def main():
  n=int(input())+1
  yueg=[0]*(n)
  for i in range(1,n):
    j=0
    while j < n:
      yueg[j]+=1
      j+=i
    yueg[i]*=i
  r=0  
#yueg=np.array(yueg)
#ka=np.arange(n)
#r=np.sum(yueg*ka)
  print(sum(yueg)-yueg[0])
main()

Measured memory_bytes: 145800
n, m = map(int, input().split())
list_score = [ list(map(int,input().split(" "))) for i in range(m)]

left = 1
right = n
for i in range(m):
    k = list_score[i]
    if left < k[0]:
        left = k[0]
    if right > k[1]:
        right = k[1]

if left > right:
    print(0)
else:
    print(right-left+1)


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int mn, mx;
    if (n % 2) {
        mn = a[(n - 1) / 2];
        mx = b[(n - 1) / 2];
    } else {
        mn = a[n / 2 - 1] + a[n / 2];
        mx = b[n / 2 - 1] + b[n / 2];
    }
    cout << mx - mn + 1 << endl;
}


Measured memory_bytes: 4840
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

xs,ys,xt,yt = map(int,readline().split())
n, = map(int,readline().split())

xyr = [tuple(map(int,readline().split())) for _ in range(n)] + [(xs,ys,0),(xt,yt,0)]


from heapq import *
def dijkstra(d,s0):
    n = len(d)
    INF = float("inf") #INF = 1<<61
    dist = [INF]*(n) #startからの最短距離
    #pending = n-1 #未確定の点の個数
    dist[s0] = 0.0
    res = d[s0][:]
    res[s0] = INF
    for _ in range(n-1):
        idx = min(range(n),key = lambda i: res[i])
        r = dist[idx] = res[idx]
        res[idx] = INF
        for j in range(n):
            if res[j] != INF:
                res[j] = min(res[j],r+d[idx][j])
        
        #print(x0,d0)
    return dist

from math import hypot
d = [[max(0.0,hypot((xi-xj),(yi-yj))-ri-rj) for xj,yj,rj in xyr] for xi,yi,ri in xyr]

#print(d)
dist = dijkstra(d,n)
print(dist[-1])
#print(dist)











Measured memory_bytes: 83648
import scala.io.StdIn

object Main extends App {
  val a = StdIn.readLine().split(' ').map(_.toInt)
  val r = a(0) + a(1) - (a(2) + a(3))
  println(if(r > 0) "Left" else if(r < 0) "Right" else "Balanced")
}

Measured memory_bytes: 27188
#include<iostream>
#include<string.h>
#include<algorithm>

using namespace std;
long long a[200005];
long long sum[200005];
const int mod=1e9+7;
int main()
{
    int n;
    cin>>n;
    long long num=0;
    for (int i=1;i<=n;i++)
        cin>>a[i];
    for (int i=n;i>=1;i--)
    {sum[n-i+1]=sum[n-i]+a[i];
    sum[n-i+1]%=mod;
    }
    for (int i=1;i<n;i++)
    {
        num+=a[i]*sum[n-i]%mod;
        num%=mod;
    }
    cout<<num%mod<<endl;
    return 0;
}


Measured memory_bytes: 6700
#include <iostream>
using namespace std;
int main(){
	int k, x; cin >> k >> x;
	if(k == 1) cout << x << endl;
	else{
		cout << x - k + 1;
		for(int i = x - k + 2; i <= x + k - 1; i++) cout << " " << i;
		cout << endl;
	}
}


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

// const long long int MOD = 1000000007;
const int MOD = 1000000007;


int main() {
    int N;
    cin >> N;
    vector<int> x(N), y(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }
    double ans = 0.0;
    for (int i = 0; i < N-1; i++) {
        for (int j = i+1; j < N; j++) {
            double dist_ij = sqrt(pow(x[i]-x[j], 2)+pow(y[i]-y[j], 2));
            ans += dist_ij*2/N;
        }
    }
    // printf("%.6d\n", ans);
    cout << fixed << setprecision(7) << ans << endl;
}


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

#define FastRead  ios_base::sync_with_stdio(0);cin.tie(0);
#define endl      "\n"
#define pi        acos(-1.0)

typedef long long unsigned llu;

int main()
{
    FastRead

    llu h,w,ans=0;

    cin>>h>>w;

    if(h==1 or w==1)
    {
        cout<<1;
        return 0;
    }

    if(h%2)
    {
        if(w%2)
        {
            llu half = h/2;
            ans+= (w/2)*half;

            ans+=((w/2)+1)*(half+1);

            cout<<ans;
        }
        else
        {
            ans+= (w/2)*h;
            cout<<ans;
        }
    }

    else
    {
        if(w%2)
        {
            llu half = h/2;
            ans+=(w/2)*half;

            ans+=((w/2)+1)*half;

            cout<<ans;
        }
        else
        {
            ans+= (w/2)*h;

            cout<<ans;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 310;
const long long INF = 1e13;
long long a[maxn][maxn], b[maxn][maxn];
int n, m, L;

void init(){
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			if(i==j){
				a[i][j] = 0;
				b[i][j] = 0;
			}else{
				a[i][j] = INF;
				b[i][j] = INF;
			}
}

int main(){
	cin >> n >> m >> L;
	int x, y, z;
	init();
	for(int i=1; i<=m; i++){
		cin >> x >> y >> z;
		if(z<=L && z<a[x][y])
			a[y][x] = a[x][y] =  z;
	}
	for(int k=1; k<=n; k++) // 求出各个点之间的最短路径 
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				a[i][j] = min(a[i][j], a[i][k]+a[k][j]);
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			if(i!=j && a[i][j]<=L) //当成是加一次油 
				b[i][j] = 1;
	// 以加油次数为权值（b[i][j]），再求一次floyd，就可以求出最小加油次数
	for(int k=1; k<=n; k++)
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				b[i][j] = min(b[i][j], b[i][k]+b[k][j]);

	int q;
	cin >> q;
	for(int i=1; i<=q; i++){
		cin >> x >> y;
		if(x==y)
			cout << 0 << endl;
		else{
			if(b[x][y]>=INF)
				cout << -1 << endl;
			else
				cout << b[x][y]-1 << endl;  // 不超过L时，默认为1，实际要减去1 
		}
	}
	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  
  if (a * b % 2 == 1) {
    cout << "Odd" << endl;
  }
  
  else {
    cout << "Even" << endl;
  }
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  for (int i = 0; i < k; ++i) {
    if (i % 2 == 0) {
      if (a % 2 != 0) a--;
      b += (a / 2);
      a /= 2;
    } else {
      if (b % 2 != 0) b--;
      a += (b / 2);
      b /= 2;
    }
  }
  cout << a << " " << b << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,t) for(int i = a;i < t;i++)
#define froop2(a,t) for(int i = a;i > t;i--)
int main(){
	long N,M;
  long a,b,count = 0;
  cin >> N >> M;
  vector<long> height(N);
  vector<int> check(N,0);
  froop1(0,N){
    cin >> height.at(i);
  }
  froop1(0,M){
    cin >> a >> b;
    a--;
    b--;
   if(height.at(a) <= height.at(b)){
     if(check.at(a) == 0){
       check.at(a) = 1;
       count++;
     }
   }
    if(height.at(b) <= height.at(a)){
       if(check.at(b) == 0){
         check.at(b) = 1;
         count++;
       }
     }
  }
  cout << N - count << endl;
     return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll n;
  cin >> n;
  vll a(n);
  vin(a);
  
  vll a1 = a, a2 = a;
  ll ans1 = 0, ans2 = 0;
  ll pointer = 0;
  ll sum = 0;
  while(pointer < n){
    sum += a1.at(pointer);
    if(pointer % 2 == 0){
      if(sum > 0) pointer++;
      else{
        ans1 += -1 * sum + 1;
        a1.at(pointer) += -1 * sum + 1;        
        sum += -1 * sum + 1; 
        pointer++;
      }
    }
    else{
      if(sum < 0) pointer++;
      else{
        ans1 +=  sum + 1;
        a1.at(pointer) -=  sum + 1;
        sum -= sum + 1; 
        pointer++;
      }
    }
  }
  
  pointer = 0, sum = 0;
  while(pointer < n){
    sum += a2.at(pointer);
    if(pointer % 2 == 1){
      if(sum > 0) pointer++;
      else{
        ans2 += -1 * sum + 1;
        a2.at(pointer) += -1 * sum + 1;
        sum += -1 * sum + 1; 
        pointer++;
      }
    }
    else{
      if(sum < 0) pointer++;
      else{
        ans2 +=  sum + 1;
        a2.at(pointer) -=  sum + 1;
        sum -= sum + 1; 
        pointer++;
      }
    }
  }
cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 2560
def bubble_sort(a):
    n = len(a)
    for j in range(n):
        m = n-1-j # n-1 to 0
        for i in range(m):
            if a[i][1] > a[i+1][1]:
                a[i],a[i+1] = a[i+1],a[i]
    return a


def selection_sort(a):
    MAXINT = 10
    n = len(a)
    for j in range(n):
        minv = MAXINT
        minp = -1
        for i in range(j,n):
            if int(a[i][1]) < minv:
                minv = int(a[i][1])
                minp = i
        a[minp],a[j]=a[j],a[minp]
    return a

def stable(a,f):
    b = f(a[:])
    print ' '.join(b)
    p = 1
    while p < 10:
        c = []
        d = []
        for i in range(len(a)):
            if a[i][1] == str(p):
                c.append(a[i])
            if b[i][1] == str(p):
                d.append(b[i])
        for i in range(len(c)):
            if c[i] != d[i]:
                print "Not stable"
                return
        p += 1
    print "Stable"

n = int(raw_input())
cards = raw_input().split(' ')

stable(cards[:],bubble_sort)
stable(cards[:],selection_sort)

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

int main(){

  int a,b,c,d;

  cin >> a >> b >> c;

  if ( a > b ){
    d = a;
    a = b;
    b = d;
  }if( c < a  ){
    d = c;
    c = a;
    a = d;
  }if( c < b  ){
    d = b;
    b = c;
    c = d;
  }

  cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3092
#include<iostream>
#include<vector>
#include<set>

using namespace std;

const int MAX=100000;

vector<int>G[MAX];

int N;
bool visited[MAX];//訪問状況

int prenum[MAX],parent[MAX],lowest[MAX],timer;

bool dfs(int current,int prev){
  //ノードcurrentを訪問した直後の処理
  prenum[current]=lowest[current]=timer;
  timer++;

  visited[current]=true;//訪問

  int next;
  //          curerentからのびてる辺の数
  for(int i=0;i<G[current].size();i++){
    next=G[current][i];
    if(!visited[next]){//訪問していない

      //ノードcurrentからノードnextへ訪問する直前の処理
      parent[next]=current;

      dfs(next,current);

      //ノードnextの探索が終了した直前の処理
      lowest[current]=min(lowest[current],lowest[next]);
    }else if(next!=prev){
      //エッジcurrent-->nextがBack-edgeの場合の処理
      lowest[current]=min(lowest[current],prenum[next] );
    }
  }
  //ノードcurrentの探索が終了した直後の処理
}

void art_points(){
  for(int i=0;i<N;i++) visited[i]=false;//falseを入れておく
  timer=1;
  //lowestの計算

  dfs(0,-1);//0==root(根から見ていく)
    
  set<int> ap;
  int np=0;
  for(int i=1;i<N;i++){
    int p=parent[i];
    if(p==0) np++;
    else if(prenum[p]<=lowest[i]) ap.insert(p);
  }
  if(np>1) ap.insert(0);
  for(set<int>::iterator it=ap.begin();it!=ap.end();it++){
    cout<<*it<<endl;
  }
}

int main(){
  int m;
  cin>>N>>m;

  for(int i=0;i<m;i++){
    int s,t;
    cin>>s>>t;
    G[s].push_back(t);//sからt
    G[t].push_back(s);//tからs
  }
  art_points();

  return 0;
}



Measured memory_bytes: 6896
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T>
void __f(const char* s, T t) { cout << s << " : "; __p(t); }
template<typename T>
void __t(const char* s, const T &x) { cout << s << " : { "; for (auto it : x) __p(it); cout << "} ";}
template<typename T, typename ... F>
void __f(const char* s, T t, F ... f) {
	int i = 0; for (;; ++i) if (s[i] == ',') break;
	cout.write(s, i) << " : "; __p(t); cout << " | "; __f(s + i + 1, f...);
}
#define trace(...) { cout<<"LINE: "<<__LINE__<<" || "; __f(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#define debug(...) { cout<<"LINE: "<<__LINE__<<" || "; __t(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define debug(...) 
#define end_time()
#endif
 
 
#define int long long 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

inline bool equals(ld a, ld b) {return fabs(a - b) < 1e-9;}
inline int gcd(int a, int b) { a=abs(a); b=abs(b); while(a>0 && b>0) (a>b?a%=b:b%=a); return (a==0?b:a); } 
inline int power(int x, int n, int m = LLONG_MAX)
    {  int res=1; x = (x%m + m)%m;
       while(n) { if(n&1) res=(res*x)%m;  x=(x*x)%m;  n >>= 1; }  return res;
    }
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007

void solve(){
	int n,w;
	cin>>n>>w;
	vi wt(n), vl(n);
	for(int i = 0; i<n; i++){
		cin>>wt[i]>>vl[i];
	}
	int dp[n][w+1];
	memset(dp,0,sizeof(dp));
	dp[0][wt[0]] = vl[0];
	for(int i = 1; i<n; i++){
		for(int j = 0; j<wt[i]; j++){
			dp[i][j] = dp[i-1][j];
		}
		for(int j = wt[i]; j<=w; j++){
			dp[i][j] = max(dp[i-1][j],dp[i-1][j-wt[i]]+vl[i]);
		}
	}
	int ans = 0;
	for(int i = 0; i<=w; i++){
		ans = max(ans,dp[n-1][i]);
	}
	cout<<ans<<"\n";
}
signed main(){
	speedX;
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;++i) {
		//cout<<"Case #"<<i<<": ";
		solve();
	}
	end_time();
	return 0;
}


Measured memory_bytes: 81672
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] array = new long[n + 1];
		array[0] = 2;
		array[1] = 1;

		for(int i = 2; i < array.length; i++) {
			array[i] = array[i-2] + array[i-1];
		}
		System.out.println(array[n]);
	}
}

Measured memory_bytes: 21972