akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }


signed main()
{
	int N;
	cin >> N;
	int cur = N;
	while (true)
	{
		if (cur % 2 == 0)
		{
			cout << cur << endl;
			return 0;
		}
		cur += N;
	}
}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <boost/foreach.hpp>

using namespace std;

void dump(vector<int>& v) {
  BOOST_FOREACH(int x, v) {
  	cout << x << " ";
  }
  cout << endl;
}

int main() {
  int limit = 1000000007;
  int n,k;
  cin >> n;
  cin >> k;
  
  vector<int> keys;
  keys.push_back(0);
  
  int sn = sqrt(n);
  
  for(int i = 1; i <= sn; i++) {
    keys.push_back(i);
    int j = n/i;
    if (i != j) {
      keys.push_back(j);
    }
  }
  sort(keys.begin(), keys.end());
  // dump(keys); //TODO: debug
  int key_size = keys.size();
  
  int dp[2][key_size];
  for(int i = 0; i < 2; i++) {
    for(int j = 0; j < key_size; j++) {
      dp[i][j] = 0;
    }
  }
  dp[0][1] = 1; // k=0の値
  
  long long sum;
  long long key_range;
  
  for(int kk = 1; kk <= k + 1; kk++) { //最終結果sum(dp[k])=dp[k+1][1]のため、k+1まで回しておく
    sum = 0;
    
    for(int v = 1; v < key_size; v++) {
      sum += dp[(kk-1)%2][v];
      key_range = keys[key_size - v] - keys[key_size - v -1];
      dp[kk%2][key_size - v] = (sum * key_range) % limit;
    }
  }
  
  /* TODO:debug
  for(int i = 0; i < 2; i++) {
    for(int j = 0; j < key_size; j++) {
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  
  cout << n << endl;
  cout << sn << endl;
  cout << k << endl;
  */
  cout << dp[(k+1)%2][1] << endl;
  return 0;
}

Measured memory_bytes: 1148
n = int(input())
if n%10 == 2 or n%10 == 4 or n%10 == 5 or n%10 == 7 or n%10 == 9:
  print('hon')
elif n%10 == 0 or n%10 == 1 or n%10 == 6 or n%10 ==  8:
  print('pon')
else:
  print('bon')

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
using namespace std;

int main()
{
    ll n, w;
    cin>>n>>w;
    ll weights[100001];
    ll values[100001];
    for(ll i=0; i<n; i++)
    {
        cin>>weights[i]>>values[i];
    }
    ll dp[101][100001];
    memset(dp, 0, sizeof dp);
    
    for(ll i=0; i<=n; i++)
    {
        for(ll j=0; j<=w; j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(weights[i-1] > j)
            {
                dp[i][j]=dp[i-1][j];
                //continue;
            } else {
                dp[i][j]=max(values[i-1]+dp[i-1][j-weights[i-1]], dp[i-1][j]);

            }
        }
    }
    cout<<dp[n][w]<<endl;
    return 0;
}

Measured memory_bytes: 80640
#include <bits/stdc++.h>
using namespace std;
 
#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl "\n"
#define ll long long
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pii pair<int,int> 
 
int main(){
	int a, b;
	cin >> a >> b;
	int ans = 0, curr = 1;
	while(curr < b){
		curr += (a-1);
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
l=sorted([[*map(int,input().split())] for _ in range(int(input()))],key=lambda k:-k[2])
x,y,h=l[0]
for X in range(101):
  for Y in range(101):
    H=h+abs(x-X)+abs(y-Y)
    if all(h==max(H-abs(x-X)-abs(y-Y),0) for x,y,h in l): print(X,Y,H)

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)

/////////////////////////////////////////////////////////

void Main(){
  ll N; cin >> N;
  vector<ll> A(N), B(N), C(N);
  rep(i, 0, N) cin >> A[i];
  rep(i, 0, N) cin >> B[i];
  rep(i, 0, N) cin >> C[i];
  sort(all(A));
  sort(all(B));
  sort(all(C));
  ll res = 0, a = 0, c = N;
  rep(b, 0, N){
    while(a < N){
      if(A[a] < B[b]) a++;
      else break;
    }
    while(c > 0){
      if(B[b] >= C[N - c]) c--;
      else break;
    }
    res += a * c;
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


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

int main() {
 int N;
  cin >> N;
  vector<int> data(N);
  for(int i=0;i<N;i++){
  cin >> data.at(i);
  }
  int count=0;
  int a=0;
  for(int i=0;i<N;i++){
  if(data.at(a)==2){
  count++;
    break;
  }
  a = data.at(a)-1;
    count++;
  if(i==N-1){
  count = -1;
  }
  }
  cout << count;
}

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



int main(){
	
	string a,b;
	cin>>a>>b;
	int n = stoi(a+b);

	for(int i=1;i<=1000;i++){
		if(i*i==n){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	
	cout<<"No"<<endl;
	
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  long long x = 1000;
  for( int i = 0; i < n-1; i++){
    int w = a.at(i);
      int s = a.at(i +1);
      if(w < s){
        long long t = x/w;
        x %= w;
        x += t*s;
      }
  }
  cout << x << endl;
  
  return 0;
     
}

Measured memory_bytes: 3572
#![allow(non_snake_case)]

use std::io::*;

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

pub fn main() {
    let R = rl().parse::<i32>().unwrap();
    if R < 1200 {
        println!("ABC")
    } else if R < 2800 {
        println!("ARC")
    } else {
        println!("AGC")
    }
}


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

class Dice {
  int U, D, N, E, S, W;

  void goN() {
    int tmp = U;
    U = S;
    S = D;
    D = N;
    N = tmp;
  }

  void goE() {
    int tmp = U;
    U = W;
    W = D;
    D = E;
    E = tmp;
  }

  void goS() {
    int tmp = U;
    U = N;
    N = D;
    D = S;
    S = tmp;
  }

  void goW() {
    int tmp = U;
    U = E;
    E = D;
    D = W;
    W = tmp;
  }

  public:
  Dice(vector<int> label) {
    U = label.at(0);
    S = label.at(1);
    E = label.at(2);
    W = label.at(3);
    N = label.at(4);
    D = label.at(5);
  }

  void go(char way) {
    switch(way) {
      case 'N':
        goN();
        break;
      case 'E':
        goE();
        break;
      case 'S':
        goS();
        break;
      case 'W':
        goW();
        break;
    }
  }

  string getPos(int label, string avoid) {
    string pos = "";
    if (U == label && avoid.find("U") == string::npos) pos += "U";
    if (D == label && avoid.find("D") == string::npos) pos += "D";
    if (N == label && avoid.find("N") == string::npos) pos += "N";
    if (E == label && avoid.find("E") == string::npos) pos += "E";
    if (S == label && avoid.find("S") == string::npos) pos += "S";
    if (W == label && avoid.find("W") == string::npos) pos += "W";
    return pos;
  }

  int getLabel(char pos) {
    if (pos == 'U') return U;
    else if (pos == 'D') return D;
    else if (pos == 'N') return N;
    else if (pos == 'E') return E;
    else if (pos == 'S') return S;
    else if (pos == 'W') return W;
    return -1;
  }
};

bool isSameAllSurf(Dice &d1, Dice &d2) {
  if (d1.getLabel('U') == d2.getLabel('U') &&
    d1.getLabel('D') == d2.getLabel('D') &&
    d1.getLabel('N') == d2.getLabel('N') &&
    d1.getLabel('E') == d2.getLabel('E') &&
    d1.getLabel('S') == d2.getLabel('S') &&
    d1.getLabel('W') == d2.getLabel('W')) return true;
  return false;
}

bool isSame(Dice &d1, Dice &d2) {
  for (int i = 0; i < 4; ++i) {
    d1.go('S');
    for (int j = 0; j < 4; ++j) {
      d1.go('E');
      if (isSameAllSurf(d1, d2)) return true;
    }
  }
  d1.go('E');
  d1.go('S');
  for (int i = 0; i < 4; ++i) {
    d1.go('E');
    if (isSameAllSurf(d1, d2)) return true;
  }
  d1.go('S');
  d1.go('S');
  for (int i = 0; i < 4; ++i) {
    d1.go('E');
    if (isSameAllSurf(d1, d2)) return true;
  }

  return false;
}

int main() {
  vector<int> label(6);
  for (int i = 0; i < 6; ++i) cin >> label.at(i);
  Dice d1(label);
  for (int i = 0; i < 6; ++i) cin >> label.at(i);
  Dice d2(label);
  if (isSame(d1, d2)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

  ll a, b, c;
  cin >> a >> b >> c;
  cout << a * b / 2 << endl;

  return 0;
}

Measured memory_bytes: 256
n=gets.chomp.to_i
x=Array.new
y=Array.new
for i in 0..n-1
  x[i],y[i]=gets.chomp.split(" ").map{|s| s.to_i}
end

ans=0.0
for i in 0..n-1
  for j in 0..n-1
    ans+=(((x[i]-x[j])**2)+((y[i]-y[j])**2))**(0.5)
  end
end
p ans/n

Measured memory_bytes: 1788
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DKi solver = new DKi();
        solver.solve(1, in, out);
        out.close();
    }

    static class DKi {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            ArrayList<Integer>[] ale = new ArrayList[n];
            for (int i = 0; i < n; i++) {
                ale[i] = new ArrayList<>();
            }
            int[] cost = new int[n];
            boolean[] used = new boolean[n];
            Arrays.fill(used, false);
            for (int i = 0; i < n - 1; i++) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                ale[a].add(b);
                ale[b].add(a);
            }

            for (int i = 0; i < q; i++) {
                int p = in.nextInt() - 1;
                int x = in.nextInt();
                cost[p] += x;
            }

            ArrayDeque<Integer> stack = new ArrayDeque<>();
            stack.push(0);
            while (!stack.isEmpty()) {
                int now = stack.pop();
                used[now] = true;
                for (int nxt : ale[now]) {
                    if (!used[nxt]) {
                        cost[nxt] += cost[now];
                        stack.push(nxt);
                    }
                }
            }

            for (int c : cost) out.print(c + " ");
            out.println();

        }

    }
}



Measured memory_bytes: 199620
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};

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


int n,m;

void solve(){
  vector<pair<PI,int> > in(n);
  rep(i,n) cin >> in[i].F.F >> in[i].F.S >> in[i].S;
  sort(ALL(in));
  int inf[m];
  memset(inf,0,sizeof(inf));
  inf[0]=1;
  FOR(it,in) inf[it->S-1] |= inf[it->F.S-1];
  int ans=0;
  rep(i,m) ans += inf[i];
  cout << ans << endl;
}


int main(int argc, char *argv[])
{
  while(cin >> m >> n && n|m) solve();
  return 0;
}

Measured memory_bytes: 1512
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	vector<int> h(n);
	for (int i = 0; i < n; i++)
	{
		cin >> h.at(i);
	}

	vector<int> dp(n, inf);

	dp.at(0) = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = 1; j <= k; j++)
		{
			if (i - j >= 0)
			{
				dp.at(i) = min(dp.at(i), dp.at(i - j) + abs(h.at(i - j) - h.at(i)));
			}
		}
	}

	cout << dp.at(n - 1) << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
map<ll, ll> mmap;
int N, M;
ll A, B, C;
 
int main() 
{
	cin>>N>>M;
	for (int i = 0; i < N; i++) {
		cin>>A;
		mmap[-A]++;
	}
	for (int i = 0; i < M; i++) {
		cin>>B>>C;
		mmap[-C] += B;
	}
	ll sol = 0;
	ll cnt = N;
	for (auto it = mmap.begin(); it != mmap.end(); it++) {
		ll cost = min(cnt, it->second);
		if (cost == 0) 
		    break;
		sol -= it->first*cost;
		cnt -= cost;
	}
	cout<<sol<<endl;
}

Measured memory_bytes: 12800
N, A, B, C, D = map(int, input().split())
A -= 1
B -= 1
C -= 1
D -= 1
S = input()

c = [1 if S[0] == '#' else -1]
for i in range(1, N):
    if c[-1] > 0:
        if S[i] == '#':
            c.append(c[-1] + 1)
        else:
            c.append(-1)
    else:
        if S[i] == '#':
            c.append(1)
        else:
            c.append(c[-1] - 1)

if A < B < C < D:
    ans = max(c[A:D + 1]) <= 1
elif A < B < D < C:
    ans = max(c[A:C + 1]) <= 1 and min(c[B + 1:D + 2]) <= -3
elif A < C < B < D:
    ans = max(c[A:C + 1]) <= 1 and max(c[B:D + 1]) <= 1
print('Yes' if ans else 'No')


Measured memory_bytes: 6420
#include<iostream>
using namespace std;
int main(){
	int n,m,ans=9999999;
	while(true){
	ans=9999999;
	cin>>n>>m;
	if(n==0&&m==0)break;
	bool t[200][200];
	int cnts[300]={0};
	for(int i=0;i<200;i++)for(int j=0;j<200;j++)t[i][j]=0;
	for(int i=0;i<n;i++){
		int tmp;
		cin>>tmp;
		for(int j=0;j<tmp;j++){
			int x;
			cin>>x;
			t[i][x]=1;
		}
	}
	for(int i=0;i<200;i++){
		int cnt=0;
		for(int j=0;j<n;j++){
		if(t[j][i])cnt++;
		}
		cnts[i]=cnt;
	}
	int now=0;
	for(int i=0;i<300;i++){
	if(now<cnts[i]&&cnts[i]>=m){
	ans=i;now=cnts[i];
	}
	//else if(now==cnts[i]&&cnts[i]>=m)ans=i;
	}
	if(ans==9999999)ans=0;
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>
int main()
{
    int x, y, ans, swap;

    scanf("%d %d",&x,&y);
    
    if(x < y){
        swap = y;
        y = x;
        x = swap;
    }
    
    while((x%y)!=0){
        swap = x%y;
        x = y;
        y = swap;
    }
    printf("%d\n",y);
    return 0;
}



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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; ++i)
    {
        reverse(divide[i].begin(), divide[i].end());
    }
    bool can = true;
    for (int i = 0; i < S.size();)
    {
        bool can2 = false;
        for (int j = 0; j < 4; ++j)
        {
            string d = divide[j];
            if (S.substr(i, d.size()) == d)
            {
                can2 = true;
                i += d.size();
            }
        }
        if (!can2)
        {
            can = false;
            break;
        }
    }
    cout << (can ? "YES" : "NO");
}


Measured memory_bytes: 512
NT = list(map(int, input().split()))
N = NT[0]
T = NT[1]
del NT

t = list(map(int, input().split()))

ans = 0
for i in range(N-1):
    l = t[i+1] - t[i]
    if l <= T:
        ans += l
    else:
        ans += T
ans += T
print(ans)

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

static const int MAX_S = 100;
static const int INFTY = ( 1 << 20 );

pair< int, int > Adj[MAX_S][MAX_S]; // first : cost, second : time

int main()
{

	int n, m, a, b, cost, time, qn, r;

	while( cin >> n >> m, n || m ) {

		for( int i = 0; i < m; i++ ) {
			for( int j = 0; j < m; j++ ) Adj[i][j].first = Adj[i][j].second = INFTY;
		}

		for( int i = 0; i < n; i++ ) {

			cin >> a >> b >> cost >> time;
			Adj[--a][--b].first  = Adj[b][a].first  = cost;
			Adj[a][b].second	 = Adj[b][a].second = time;

		}

		for( int k = 0; k < m; k++ ) {
			for( int i = 0; i < m; i++ ) {
				if( Adj[i][k].first == INFTY ) continue;
				for( int j = 0; j < m; j++ ) {

					Adj[i][j].first  = min( Adj[i][j].first , Adj[i][k].first  + Adj[k][j].first );
					Adj[i][j].second = min( Adj[i][j].second, Adj[i][k].second + Adj[k][j].second );
				
				}
			}
		}

		cin >> qn;
		for( int i = 0; i < qn; i++ ) {

			bool query;

			cin >> a >> b >> query;
			a--; b--;

			cout << ( !query ? Adj[a][b].first : Adj[a][b].second ) << endl;

		}

	}

	return 0;

}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define int long long
#define dd second
#define mp make_pair
#define pb push_back
#define ff first
#define dd second
#define pp pair<int,int>
using namespace std;

int n;

struct Turbo
{
    int n, m;
    vector<int> lm, rm;
    vector<bool> visited;
    vector<vector<int>> graph;

    Turbo(int n, int m)
    {
        this->n = n;
        this->m = m;
        lm.resize(n,-1); rm.resize(m,-1);
        visited.resize(n,false);
        graph.resize(n);
    }

    void addEdge(int a, int b)
    {
        graph[a].pb(b);
    }

    int bestMatching()
    {
        int res = 0;
        while(1)
        {
            bool change = false;
            for(int i = 0; i < n; ++i) visited[i] = false;
            for(int i = 0; i < n; ++i)
            {
                if(lm[i] == -1 and findPath(i))
                {
                    res++;
                    change = true;
                }
            }
            if(!change) break;
        }
        return res;
    }

    bool findPath(int x)
    {
        if(visited[x]) return false;
        visited[x] = true;
        for(auto &i:graph[x])
        {
            if(rm[i] == -1 or findPath(rm[i]))
            {
                lm[x] = i;
                rm[i] = x;
                return true;
            }
        }
        return false;
    }

};

bool prime(int x)
{
    if(x < 3) return false;
    for(int i = 2; i*i <= x; ++i) if(x % i == 0) return false;
    return true;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    vector<int> ev, od;
    for(int i = 0; i < n; ++i)
    {
        int temp; cin >> temp;
        if(temp & 1)
        {
            if(od.size() > 0 and od.back() == temp) od.pop_back(); else od.pb(temp);
            ev.pb(temp+1);
        }
        else
        {
            if(ev.size() > 0 and ev.back() == temp) ev.pop_back(); else ev.pb(temp);
            od.pb(temp+1);
        }
    }

    Turbo turbo(ev.size(), od.size());
    for(int a = 0; a < ev.size(); ++a)
        for(int b = 0; b < od.size(); ++b)
        {
            if(prime(abs(od[b]-ev[a]))) turbo.addEdge(a,b);
        }
    int k = turbo.bestMatching();
    int ans = k + ((ev.size()-k)/2+(od.size()-k)/2) * 2 + ((ev.size()-k) % 2) * 3;
    cout << ans << endl;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());
      String line = in.readLine();
      int nHalf = n >> 1;

      Integer num;
      Map<Integer,Integer> mapA = new HashMap<>();
      Map<Integer,Integer> mapB = new HashMap<>();;
      int offset=0,next=0;
      char regx = ' ';

      for(int i=0; i<n; i++) {
        if((next = line.indexOf(regx,offset)) == -1)
          next = line.length();
        num = new Integer(line.substring(offset, next));
        offset = ++next;

        if((i&1) == 0)
          mapA.merge(num, 1, (a,b) -> a+b);
        else
          mapB.merge(num, 1, (a,b) -> a+b);

        // if((i & 1) == 0) {
        //   if(mapA.containsKey(num))
        //     mapA.replace(num, mapA.get(num) + 1);
        //   else
        //     mapA.put(num, 1);
        // }
        // else {
        //   if(mapB.containsKey(num))
        //     mapB.replace(num, mapB.get(num) + 1);
        //   else
        //     mapB.put(num, 1);
        // }
      }

      int[] vm1 = {0,0};
      int[] vm2 = {0,0};
      int[] x   = {0,0};

      for (Map.Entry<Integer,Integer> m : mapA.entrySet()) {
        int val = m.getValue();
        if(vm1[0] <val) {
          vm2[0] = vm1[0];
          vm1[0] = val;
          x[0]  = m.getKey();
        } else if(vm2[0] < val) {
          vm2[0] = val;
        }
      }
      for (Map.Entry<Integer,Integer> m : mapB.entrySet()) {
        int val = m.getValue();
        if(vm1[1] <val) {
          vm2[1] = vm1[1];
          vm1[1] = val;
          x[1]  = m.getKey();
        } else if(vm2[1] < val) {
          vm2[1] = val;
        }
      }

      int ans = 0;
      int cca1 = nHalf - vm1[0];
      int ccb1 = nHalf - vm1[1];
      int cca2 = nHalf - vm2[0];
      int ccb2 = nHalf - vm2[1];

      if(x[0] == x[1])
        ans = cca2 > ccb2 ? cca1 + ccb2 : cca2 + ccb1;
      else
        ans = cca1 + ccb1;

      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int n,r;
    cin >> n >> r;
    if(n < 10)r+=100*(10-n);
    cout << r;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.nextLine(); // 改行
        String[] strz = new String[N];
        for (int n = 0; n < N; n++){
            strz[n] = sc.nextLine();
        }

        for (int n = 0; n < N; n++){
            char[] charn = strz[n].toCharArray();
            Arrays.sort(charn);
            strz[n] = new String(charn);
        }
        Arrays.sort(strz);
  			long ret = 0;
  			long one = 1;
  			Map<String,Long> m = new HashMap<String,Long>();

  			for(int i=0;i<N;i++) {
  				m.merge(strz[i], one, Long::sum);
  			}

  			for(Map.Entry<String, Long> e:m.entrySet()) {
  				ret+=e.getValue()*(e.getValue()-1)/2;
  			}

  			System.out.println(ret);
    }

    public static long f (long n){
        if (n<=1){return 1;}
        return f(n-1)*n;
    }
    public static long conbi(long n,long r){
        return (f(n)/(f(n-r)*f(r)));
    }
}


Measured memory_bytes: 101960
s = input()
ans = 0
if s.count('R') > 0:
    ans = 1
if s[0] == 'R' and s[1] == 'R':
    ans = 2
if s[2] == 'R' and s[1] == 'R':
    ans = 2
if s[0] == 'R' and s[1] == 'R' and s[2] == 'R':
    ans = 3
print(ans)


Measured memory_bytes: 9132
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	long double ave;
	long double sum = 0;
	int n;
	long double ans;
	long double data[1000];
	while(1){
		cin >> n;
		sum = 0;
		if(n==0) break;
		REP(i,n){
			cin >> data[i];
			sum += data[i];
		}
		ave = sum / (long double) n;
		ans = 0;
		REP(i,n){
			ans += (data[i] - ave) * (data[i] - ave) / (long double) n;
		}
		cout << setprecision(20) << fixed << sqrt(ans) << endl;
	}
}

Measured memory_bytes: 1304
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m,ans=0;cin>>n>>m;
  lvector A(n,0),S(n,0);
  rep(i,n) cin>>A[i];
  sort(ALL(A),greater<ll>());
  S[0]=A[0];rep(i,n-1) S[i+1]=S[i]+A[i+1];
  ll xmin=0,xmax=2e5,x,shakes,k;
  while(xmax-xmin>1) {
    shakes=0;k=n-1;x=(xmax+xmin)/2;
    for(ll i=0;i<n;++i) {
      for(ll j=k;j>-1;--j) {
        if(A[j]>x-A[i]) break;
        k--;
      }
      shakes+=k+1;
    }
    if(shakes>m) xmin=x;
    else xmax=x;
  }
  shakes=0;k=n-1;
  rep(i,n) {
    for(ll j=k;j>-1;--j) {
      if(A[j]>x-A[i]) break;
      k--;
    }
    if(k!=-1) ans+=S[k]+(k+1)*A[i];
    shakes+=k+1;
  }
  ans+=(m-shakes)*xmax;
  print(ans);
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
int mod=1e9+7;
int32_t main()
{
	int t=1;
	while(t--)
	{
		int n,k;
		cin >> n >> k;
		int pref[n+1]={0};
		int suf[n+1]={0};
		int a[n+1];
		for(int i=0;i<=n;i++)
		{
			a[i]=i;
			pref[i]=i;
			suf[n-i]=i;
		}
		
		for(int i=1;i<=n;i++)
		pref[i]+=pref[i-1];
		
		for(int i=n-1;i>=0;i--)
		{
			suf[n-i]+=suf[n-i-1];
		}
		
		int cnt=0;
		for(int i=k-1;i<=n;i++)
		{
			cnt+=(abs(suf[i]-pref[i])+1);
			cnt=cnt%mod;
		}
	
		cout << cnt;
	}
}




Measured memory_bytes: 8248
#include<bits/stdc++.h>
using namespace std;
const int maxn=60;
int cnt[maxn];
int main()
{
    int n,m;
    memset(cnt,0,sizeof(cnt));
    scanf("%d%d",&n,&m);
    while(m--)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        cnt[u]++;
        cnt[v]++;
    }
    for(int i=1;i<=n;i++)
        printf("%d\n",cnt[i]);
}


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

class Progaram
{
    static void Main(String[] args)
    {
        var l = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
        var n = l[0]; var m = l[1];
        var sum = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).Sum();
        Console.WriteLine((sum > n) ? -1 : n - sum);
    }
}

Measured memory_bytes: 29336
main :: IO ()
main = do
  [k,s] <- map read . words <$> getLine :: IO [Int]
  let z_xpy = zip [0..k] [xpy | z <- [0..k], let xpy = s-z]
  let yz = [(y, z) | y <- [0..k], (z, xpy) <- z_xpy, xpy - y >= 0]
  let x = [a |(y, z) <- yz, let a = s-z-y, a >=0 && a<= k]
  print $ length x



Measured memory_bytes: 1148
alpha = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
L = []
for _ in range(N):
    L.append(input())
for char in alpha:
    minimum = 10 ** 10
    for string in L:
        cnt = 0
        for s in string:
            if s == char:
                cnt += 1
        minimum = min(cnt,minimum)
    print(char*minimum,end = '')
print()


Measured memory_bytes: 39408
#include<iostream>
#include<sstream>

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

int main()
{
	string in;
	string l="qwertasdfgzxcvb";
	
	while(cin>>in, in!="#"){
		int cnt=0;
		rep(i,in.size()-1){
			if((l.find(in[i])!=l.npos)^(l.find(in[i+1])!=l.npos))cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    cout << (1 + n) * n / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1e+9 + 7;

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

    string s;
    cin >> s;
    int n = s.length();
    deque<char> deq;
    for(int i = 0; i < n; ++i)  deq.push_back(s[i]);
    int q;
    cin >> q;
    int flag = 0;
    for(int i = 0; i < q; ++i){
        int t;
        cin >> t;
        if(t == 1){
            flag ^= 1;
        }
        else{
            int f;
            char c;
            cin >> f >> c;
            if(flag == 0){
                if(f == 1){
                    deq.push_front(c);
                }
                else{
                    deq.push_back(c);
                }
            }
            else{
                if(f == 1){
                    deq.push_back(c);
                }
                else{
                    deq.push_front(c);
                }
            }
        }
    }
    if(flag == 0){
        while(!deq.empty()){
            cout << deq.front();
            deq.pop_front();
        }
        cout << endl;
    }
    else{
        while(!deq.empty()){
            cout << deq.back();
            deq.pop_back();
        }
        cout << endl;
    }
}

Measured memory_bytes: 976
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define fr first
#define sc second
#define pb push_back
const ll mod = 1e9+7;
const int N = 2e5+205;
void solve(){
	int n; 
	cin>>n;
	vector<ll>v; 
	for(int i=0;i<n;i++){
		ll x; 
		cin>>x; 
		v.pb(x);
	}
	ll ans = 0;
	for(int i=0;i<n;i++){
		ll x; 
		cin>>x; 
		if(v[i]>x){
			ans+=v[i]-x;
		}
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3640
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int overlap(int a, int b, int c, int d) {
    int lo = max(a, c);
    int hi = min(b, d);
    return max(0, hi - lo);
}

void main() {
    int a, b, c, d; scan(a, b, c, d);
    writeln(overlap(a, b, c, d));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


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

namespace AOJ {
    class ALDS1_4_B {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            string[] inputS = Console.ReadLine().Split();
            int q = int.Parse(Console.ReadLine());
            string[] inputT = Console.ReadLine().Split();
            int[] S = new int[n + 1];
            int count = 0;
            for (int i = 0; i < n; i++) S[i] = int.Parse(inputS[i]);
            for (int i = 0; i < q; i++) if (BinarySearch(S, n, int.Parse(inputT[i]))) count++;
            Console.WriteLine(count);
        }

        static bool BinarySearch(int[] A, int n, int key) {
            int left = 0;
            int right = n;
            while (left < right) {
                int mid = (left + right) / 2;
                if (A[mid] == key) return true;
                else if (A[mid] > key) right = mid;
                else left = mid+1;
            }
            return false;
        }
    }
}



Measured memory_bytes: 29220
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))


a = int(input())

print(a + a** 2 + a**3)


Measured memory_bytes: 10760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, X, min, max;
  cin >> K >> X;
  min = X - (K-1);
  max = X + (K-1);
  for (int i=min; i <= max; i++)
    cout << i << " ";
  cout << endl;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
using namespace std;
int dp[2][110000]={};
int main(){
  int d,g;
  cin>>d>>g;
  g/=100;
  for(int i=0;i<110000;i++)
    dp[0][i]=dp[1][i]=INF;
  dp[0][0]=0;
  for(int i=0;i<d;i++){
    int p,c;
    cin>>p>>c;c/=100;
    for(int j=0;j<=g;j++){
      if(dp[i%2][j]!=INF){
	for(int k=0;k<=p;k++){
	  if(k==p){
	    if(j+k*(i+1)+c>=g){dp[(i+1)%2][g]=min(dp[(i+1)%2][g],dp[i%2][j]+k);break;}
	    else  dp[(i+1)%2][j+k*(i+1)+c]=min(dp[(i+1)%2][j+k*(i+1)+c],dp[i%2][j]+k);
	  }else{
	    if(j+k*(i+1)>=g){dp[(i+1)%2][g]=min(dp[(i+1)%2][g],dp[i%2][j]+k);break;}
	    else dp[(i+1)%2][j+k*(i+1)]=min(dp[(i+1)%2][j+k*(i+1)],dp[i%2][j]+k);
	  }
	}
      }
      dp[i%2][j]=INF;
    }
    // for(int j=0;j<=g;j++)
    //   cout<<dp[(i+1)%2][j]<<" ";
    // cout<<endl;
  }
  cout<<dp[d%2][g]<<endl;
  return 0;
}


Measured memory_bytes: 1152
(n,m),*d = [list(map(int, s.split())) for s in open(0)]

d.sort()
for i in range(m):
    d[i] = [d[i][0]-1, d[i][1]-1]

l = [0] * n
for x in d:
    l[x[0]] += 1

p = [0] * n
p[0] = 1
for x in d:
    p[x[1]] += p[x[0]]/l[x[0]]

e = [0] * n
index = d[-1][0]
max_in_index = 0
max_reduce_e = 0

for x in d[::-1] + [[-1, -1]]:
    if index != x[0]:
        if l[index] > 1:
            max_reduce_e = max(max_reduce_e, 
                               p[index] * (e[index]/l[index] - (e[index] - max_in_index)/(l[index] - 1)))
        e[index] /= l[index]
        index = x[0]
        max_in_index = 0
        if index == -1:
            break
    max_in_index = max(max_in_index, e[x[1]] + 1)
    e[x[0]] += e[x[1]] + 1

print(e[0] - max_reduce_e)

Measured memory_bytes: 91996
#include <bits/stdc++.h>
using namespace std;
#define int long long int
signed main() {
	int n,w;
	cin>>n>>w;
	int W[n],V[n];
	for(int i=0;i<n;i++)
	{
		cin>>W[i]>>V[i];
	}
	int dp[n+1][w+1];
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=w;j++)
		{
			if(i==0||j==0)dp[i][j]=0;
			else if(W[i-1]>j)dp[i][j]=dp[i-1][j];
			else{
				dp[i][j]=max(dp[i-1][j],V[i-1]+dp[i-1][j-W[i-1]]);
			}
		}
	}
	cout<<dp[n][w];
	return 0;
}

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

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var n = ReadLineIntSpilit();
            var result = 0;

            result = nCm(n[0], 2) + nCm(n[1], 2);

            Console.WriteLine(result);
            ReadLine();
        }

        /// <summary>
        /// コンビネーション
        /// </summary>
        /// <param name="n"></param>
        /// <param name="m"></param>
        /// <returns></returns>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        /// <summary>
        /// stringを一文字ずつintにキャストして配列に変換します。
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int[] StringCharArrayIntArray(string str)
        {
            List<int> b = new List<int>();
            for (int i = 0; i < str.Length; i++) {
                b.Add( int.Parse(str[i].ToString()));
            }
            return b.ToArray();
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static int ReadLineInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static string[] ReadLineStringSplit(char a = ' ')
        {
            return ReadLine().Split(a).ToArray();
        }

        public static int[] ReadLineIntSpilit(char a = ' ')
        {
            return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        }
    }
}

Measured memory_bytes: 13396
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

int N;
vector<int> V[100010];

int lg(int a){
	int b = -1;
	for(; a > 0 ; a /= 2) ++b;
	return b;
}

int dfs(int p , int q){
	int x = 0;
	int y = 0;
	repv(int,it,V[q]){
		if(p == (*it)) continue;
		int z = dfs(q,(*it));
		y |= (x&z);
		x |= z;
	}
	int w = lg(y) + 1;
	x >>= w;
	while(x % 2 == 1){
		x /= 2;
		++w;
	}
	return ((x + 1) << w);
}

int main(){
	scanf("%d" , &N);
	repp(i,1,N){
		int x,y;
		scanf("%d%d" , &x , &y);
		V[x].PB(y);
		V[y].PB(x);
	}
	printf("%d\n" , lg(dfs(-1,1)));
	return 0;
}


Measured memory_bytes: 10240
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int INF=1e9;



int main(){
	int H,W,N;
	cin>>H>>W>>N;
	int sr,sc;
	cin>>sr>>sc;
	string S,T;
	cin>>S;
	cin>>T;
	
	int ans=true;
	
	int now=sr;
	rep(i,N){
		if(S[i]=='U')now--;
		if(now<=0){
			ans=false;
			break;
		}
		if(T[i]=='D' && now<H)now++;
	}

	now=sr;
	rep(i,N){
		if(S[i]=='D')now++;
		if(now>H){
			ans=false;
			break;
		}
		if(T[i]=='U' && now>1)now--;
	}

	now=sc;
	rep(i,N){
		if(S[i]=='L')now--;
		if(now<=0){
			ans=false;
			break;
		}
		if(T[i]=='R' && now<W)now++;
	}

	now=sc;
	rep(i,N){
		if(S[i]=='R')now++;
		if(now>W){
			ans=false;
			break;
		}
		if(T[i]=='L' && now>1)now--;
	}
	
	
	if(ans==true){
		cout<<"YES"<<endl;
	}
	else cout<<"NO"<<endl;
}

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

using namespace std;

const int MOD = 1000000007;

int N;
char s[2][55];
int pt[55];
int dp[55];

int main()
{
  while (scanf("%d", &N) != EOF) {
    scanf("%s%s", s[0], s[1]);
    char pre = s[0][0];
    int ppt = 0;
    int cnt = 1;
    for (int i = 1; i <= N; ++i) {
      if (pre != s[0][i]) {
        pt[++ppt] = cnt;
        cnt = 1;
      } else {
        cnt++;
      }
      pre = s[0][i];
    }
    // for (int i = 1; i <= ppt; ++i) printf("a[%d]=%d\n", i, pt[i]);
    if (pt[1] == 1)
      dp[1] = 3;
    else
      dp[1] = 6;
    for (int i = 2; i <= ppt; ++i) {
      if (pt[i] == 1) {
        dp[i] = (pt[i - 1] == 1) ? (dp[i - 1] * 2LL % MOD) : (dp[i - 1]);
      } else {
        dp[i] = (pt[i - 1] == 1) ? (dp[i - 1] * 2LL % MOD) : (dp[i - 1] * 3LL % MOD);
      }
    }
    printf("%d\n", dp[ppt]);
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String [] str = br.readLine().split(" ");
    int H = Integer.parseInt(str[0]);
    int W = Integer.parseInt(str[1]);
    str = br.readLine().split(" ");
    int h = Integer.parseInt(str[0]);
    int w = Integer.parseInt(str[1]);
    
    System.out.println((H * W) - ((H * w + W * h) - h * w));
  }
}

Measured memory_bytes: 23124
#include <stdio.h>

int main()
{
    char op[11];
    int ans[2];

    scanf("%s", op);

    for (int i = 8 ; i <= 9 ; i++){
        ans[i-8] = op[i]-48;
    }

    printf("2018/01/%d%d", ans[0], ans[1]);
    return 0;
}


Measured memory_bytes: 1700
import bisect

    
def main():
    answer=0
    n = int(input())
    
    A = input().split( )
    B = input().split( )
    C = input().split( )
    
    A = [int(a) for a in A]
    B = [int(b) for b in B]
    C = [int(c) for c in C]
    
    A.sort()
    B.sort()
    C.sort()
    #Bの要素数分ループ
    for b in B:
        #Bの要素でAを2分探索し、Bより小さい個数を求める
        num_A=bisect.bisect_left(A,b)
        #Bの要素でCを2分探索し、Bより大きい個数を求める
        num_C=len(C)-bisect.bisect_right(C,b)
        #掛け算
        num=num_A*num_C
        #合計をたしていく
        answer+=num
    print(answer)


main()

Measured memory_bytes: 29708
#include<bits/stdc++.h>
using namespace std;
int n;
int c[100];
  
int greedy(int x){
  int res=0;
  for(int i=n-1;i>=0;i--){
    res+=x/c[i];
    x%=c[i];
  }
  return res;
}
  
int dp[5000];
  
void solve(){
  if(c[0]!=1){
    printf("Cannot pay some amount");
    return;
  }
  
  fill( dp, dp+5000, 1e9);
  dp[0]=0;
    
  for(int i=0;i<n;i++){
    int val=c[i];
    for(int j=0;j<2000;j++){
      if(j-val>=0)dp[j]=min(dp[j],dp[j-val]+1);
    }
  }
    
  for(int num=0;num<2000;num++){
    int cost=greedy(num);
    if(cost!=dp[num]){
      //      cout<<num<<' '<<cost<<' '<<dp[num]<<endl;
      printf("Cannot use greedy algorithm");
      return;
    }
  }
  
  for(int j=2000;j<5000;j++){
  
    for(int i=0;i<n;i++){
      int val=c[i];      
      dp[j]=min(dp[j],dp[j-val]+1);
    }
      
    if( dp[j]!=dp[j- c[n-1] ]+1 ){
      printf("Cannot use greedy algorithm");
      return;
    }
  }
  printf("OK");
}
  
int main(){
  for(int tc=1;;tc++){
    scanf("%d",&n);
    if(n==0)break;
    for(int i=0;i<n;i++)scanf("%d",&c[i]);
    printf("Case #%d: ",tc);
    solve();
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 3132