akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef pair<int, int> P;
vector<int> edge[216000];
map<P, int> memo;
int m[216000];
int p[216000];
int ans[216000];
int n, a, b;

int q(int v, int x){
	if(memo.count(P(v,x)))return memo[P(v,x)];
	memo[P(v,x)] = 0;
	int &res = memo[P(v,x)];
	for(int i = 0;i < edge[v].size();i++){
		int to = edge[v][i];
		if(to == p[v])continue;
		if(to >= x)continue;
		res += 1 + q(to, x);
	}                       
	return res;
}

void dfs(int x, int last = -1){
	p[x] = last;
	if(last != -1)m[x] = max(last, m[last]);
	for(int i = 0;i < edge[x].size();i++){
		int to = edge[x][i];
		if(to == last)continue;
		dfs(to, x);
	}
}

int calc(int x){
	int &res = ans[x];
	if(res != -1)return res;
	if(x == 1)return res = 0;
	if(m[p[x]] < x)return res = q(x, m[x]) + 1 + calc(p[x]);
	if(m[p[x]] > x)return res = calc(p[x]) - q(x, m[p[x]]) + q(x, m[x]);
}

int main(){
	cin >> n;
	fill(ans, ans + n + 1, -1);
	for(int i = 0;i < n-1;i++){
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	m[1] = -1;
	dfs(1);
	for(int i = 2;i <= n;i++){
		if(i > 2)cout << " ";cout << calc(i);
	}                                       cout << endl;
	return 0;
}

Measured memory_bytes: 55936
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 30 15:18:29 2018
ALDS1-4c
@author: maezawa
"""
def can_load(w, k, p):
    n = len(w)
    m = 0
    tk = 0
    i = 0
    while tk < k:
        if m + w[i] <= p:
            m += w[i]
            i += 1
            if i >= n:
                return n+1
        else:
            m = 0
            tk += 1
    return i


n, k = list(map(int, input().split()))
w = []
tr = [0 for _ in range(k)]

for i in range(n):
    w.append(int(input()))

maxw = max(w)
# =============================================================================
# for p in range(maxw, maxw*n):
#     if can_load(w, k, p) == n:
#         print(p)
#         break
# =============================================================================
right = maxw*n
left = maxw
while left<right:
    mid = (right+left)//2
    cl = can_load(w, k, mid)
#    if cl == n:
#        print(mid)
#        break
#    elif cl < n:
    if cl < n:
        left = mid + 1
    else:
        right = mid
print(right)    
    
    
    
    
    


Measured memory_bytes: 9564
import java.util.Scanner;

public class Main {
    static final int MODULUS = 1_000_000_007;

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

        String L = sc.next();

        System.out.println(solve(L));

        sc.close();
    }

    static int solve(String L) {
        int[] threePowers = new int[L.length()];
        threePowers[0] = 1;
        for (int i = 1; i < threePowers.length; ++i) {
            threePowers[i] = multiplyMod(threePowers[i - 1], 3);
        }

        int result = 0;
        int factor = 1;
        for (int i = 0; i < L.length(); ++i) {
            if (L.charAt(i) == '1') {
                result = addMod(result, multiplyMod(factor, threePowers[L.length() - i - 1]));
                factor = multiplyMod(factor, 2);
            }
        }
        result = addMod(result, factor);

        return result;
    }

    static int addMod(int x, int y) {
        return (x + y) % MODULUS;
    }

    static int multiplyMod(int x, int y) {
        return (int) ((long) x * y % MODULUS);
    }
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Low Elements
            int N = int.Parse(Console.ReadLine());
            var P = ReadLine();

            int ans = 0;
            int min = int.MaxValue;

            for(int i = 0; i < N; i++)
            {
                if (P[i] <= min)
                {
                    min = P[i];
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
const double EPS=1e-6;
#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 RALL(a) a.rbegin(),a.rend()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) FLL(a,0)
#define declare(a,it) __typeof(a) it=(a)
#define FOR(it,a) for(declare(a.begin(),it);it!=a.end();++it)
#define FORR(it,a) for(declare(a.rbegin(),it);it!=a.rend();++it)
template<class T,class U> ostream& operator<< (ostream& o, const pair<T,U>& v){return o << "(" << v.F << ", " << v.S << ")";}
template<class T> ostream& operator<< (ostream& o, const vector<T>& v){o << "{";rep(i,SZ(v)) o << (i?", ":"") << v[i];return o << "}";}
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
int s2i(string& a){stringstream ss(a);int r;ss>>r;return r;}
int geti(){int n;scanf("%d", &n);return n;}


int main(int argc, char *argv[])
{
  ll a,b,c;
  while(cin >> a >> b >> c && (a || b || c)){
    assert(a);
    if(c == 0){
      if(a > 1)
        cout << a << " " << b << " 1 0" << endl;
      else
        cout << a << " " << max(b,0LL) << " 1 " << min(b,0LL) << endl;
      continue;
    }
    
    vector<int> dic;
    for(int j = 1; j*j <= abs(c); ++j){
      if(c%j) continue;
      dic.pb(j);
      dic.pb(c/j);
      dic.pb(-j);
      dic.pb(-c/j);
    }

    
    
    for(ll i = 1; i*i <= a; ++i){
      if(a%i) continue;
      ll p = a/i;
      ll r = i;
      for(int j = 0; j < (int)dic.size(); ++j){
        ll q = dic[j];
        ll s = c/q;
        if(p == r && q < s) swap(q, s);
        //cout << p << " " << q << " " << r << " " << s << endl;
        if(p*s + q*r == b){
          assert((p > r) || (p == r && q >= s));
          cout << p << " " << q << " " << r << " " << s << endl;
          goto END;
        }
      }
    }
    
    cout << "Impossible" << endl;
  END:;
  }
}

Measured memory_bytes: 1216
n = int(input())
ab = [input() for _ in range(n)] #数字1*複数列入力

l = len(set(ab))

if n != l:
    print("No")
    exit()
for i in range(1,n):
    if ab[i-1][-1] == ab[i][0]:
        pass
    else:
        print("No")
        exit()
print("Yes")    

Measured memory_bytes: 8956
def run():
  N, M = map(int, input().split())
  s_li = [0]*(N+1)
  e_li = [0]*(N+1)
  for m in range(M):
    p, s = input().split()
    p = int(p)
    if s == 'WA':
      if s_li[p] == 0:
        e_li[p] += 1
    else:
      s_li[p] = 1
  print(sum(s_li), sum([s*e for s, e in zip(s_li, e_li)]))

if __name__ == '__main__':
  run()

Measured memory_bytes: 5528
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  long long N, x;
  cin >> N >> x;
  long long a[100];
  int i;
  for (i = 0; i < N; i++) cin >> a[i];

  sort(a, a + N);
  //for (i = 0; i < N; i++) cout << "sort" << a[i] << endl;;
  int count = 0;
  for (i = 0; i < N - 1; i++) {
    if(x >= a[i]) {
      x -= a[i];
      count++;
    } else {
      break;
    }
  }
  if (x == a[i]) count++;
  cout << count << endl;
  return 0;
}

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

int n;
int a[100010];
int b[100010];
int c[100010];
int dp[100010][5];

int rek(int x, int y) {
	if (x == n) {
		return 0;
	}
	
	int &ret = dp[x][y];
	if (ret != -1) return ret;
	
	if (y != 0) ret = max(ret, rek(x+1, 0) + a[x]);
	if (y != 1) ret = max(ret, rek(x+1, 1) + b[x]);
	if (y != 2) ret = max(ret, rek(x+1, 2) + c[x]);
	
	
	return ret;
}

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

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;

ll SQRT(ll n){ll s=1; while(s*s>n||n>=(s+1)*(s+1)){ s=(n/s+s)/2; } return s;}
int main(){
    int X;cin>>X;
    int k=(SQRT(1+8LL*X)-1)/2;
    while(k*(k+1)/2<X) k++;
    cout<<k<<endl;
}

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();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int sum = 0;
		for(int i=1 ; i<=n ; i++) {
			if(check(i,a,b)) {
				sum += i;
			}
		}
		System.out.println(sum);
	}
	static boolean check(int n,int a,int b) {
		int sum=0;
		while(n != 0) {
			sum += (n%10);
			n /= 10;
		}
		if(sum >= a && sum <= b) {
			return true;
		}else {
			return false;
		}
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

int main() {
    int n;
    cin >> n;
    vi x(n);
    cin >> x;
    int ans = INF;
    for (int i = 0; i <= 100; ++i) {
        int tmp = 0;
        rep(j, n) tmp += (x[j] - i) * (x[j] - i);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
 
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
 
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())
 
#define PB(a) push_back(a)
#define PF(a) pop_front(a)

#define MP(a,b) make_pair(a,b)
 
#define FS first
#define SE second
 
#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
//grobal var
//------------------------------------------
const int MAX = 2*10e5+2;


int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  int N;
  while(cin >> N){
    vector <tuple<str,int,int>> ress;
    REP(i,N){
      int p;
      str s;
      cin >> s >> p;
      ress.PB(make_tuple(s,p,i+1));
    }
    sort(ALL(ress),[](const tuple<str,int,int> &x,const tuple<str,int,int> &y)
    {
     return get<0>(x)==get<0>(y)?get<1>(x)>get<1>(y):get<0>(x)< get<0>(y);
    });
    EACH(i,ress){
      cout << get<2>(*i) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define min(a,b) a<b?a:b
#define G(x,y,z) g[x][y][z]
int main()
{
	int g[100][100][2],m,n,k,i,a,b,c,j;
	for(;~scanf("%d%d",&n,&m),n,m;)
	{
		for(i=0;i<m;i++)
			for(j=0;j<m;j++)
				g[i][j][0]=g[i][j][1]=i==j?0:1000000;
		for(i=0;i<n;i++)
		{
			scanf("%d%d%d%d",&a,&b,&c,&j);
			a--,b--;
			g[a][b][0]=g[b][a][0]=c;
			g[a][b][1]=g[b][a][1]=j;
		}

		for(k=0;k<m;k++)
			for(i=0;i<m;i++)
				for(j=0;j<m;j++)
					for(a=0;a<2;a++)
						g[i][j][a]=min(g[i][j][a],g[i][k][a]+g[k][j][a]);
		scanf("%d",&k);
		for(i=0;i<k;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			printf("%d\n",g[a-1][b-1][c]);
		}
	}
	return 0;
}

Measured memory_bytes: 680
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
#include <cassert>
using namespace std;

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)x)<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define EREP(i,a,b) for(int i=a;i<=b;i++)
#define erep(i,n) EREP(i,0,n)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

int n;
int x[25],y[25],r[25],c[25];
int b[25];

bool intersects(int i,int j){
  int dist1 = pow(x[i]-x[j],2) + pow(y[i]-y[j],2);
  int dist2 = pow(r[i]+r[j],2);

  return dist2 > dist1;
}

char dp[1<<24];

int main(void){
  while(scanf("%d",&n),n){
    rep(i,n){
      scanf("%d%d%d%d",&x[i],&y[i],&r[i],&c[i]);

      b[i] = 0;
      rep(j,i) if(intersects(i,j)) b[i] |= (1<<j);
    }

    int ans = 0;
    int to = (1<<n);
    memset(dp,-1,sizeof(dp));
    dp[0] = 0;

    rep(i,to){
      if(dp[i] == -1) continue;
      ans = max(ans,(int)dp[i]);
      rep(j,n-1){
        if((i & (1<<j)) != 0 || (i & b[j]) != b[j]) continue;
        REP(k,j+1,n){
          if(c[j] != c[k] || (i & (1<<k)) != 0 || (i & b[k]) != b[k]) continue;
          int next = i | (1<<j) | (1<<k);
          dp[next] = max((int)dp[next],dp[i]+2);
        }
      }
    }

    printf("%d\n",ans);
  }
}

Measured memory_bytes: 16000
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

signed main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> v;
  for (int i = 1; i <= min(s.size(), (unsigned long) k); i++) {
    for (int j = 0; j + i <= s.size(); j++) {
      v.insert(s.substr(j, i));
    }
  }
  auto itr = v.begin();
  for (int i = 1; i < k; i++) {
    itr++;
  }
  cout << *itr << endl;
  return 0;
}


Measured memory_bytes: 1664
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
//int[] date=new int[2];
public class  Main {
int i,o,sum,h,s,e,u,ty,yu,ui,n,num,qw;
double m,t,r,j,k,f,d,g,w;
static double l;
String b,c,z,x,v,a,q;
Scanner scan =new Scanner(System.in);
//入力
	public void input() {	
	
	}
	//演算
	public void compute() {
	
		}
//出力
public void output() {
b=scan.next();
String[] names=b.split("");
//for(h=0;h<7;h++) {
//System.out.println(names[h]);
//}
if(names[3].equals(names[4])&&names[5].equals(names[6])) {
	System.out.println("Yes");
}else {
	System.out.println("No");
}
}
	public static void main(String [ ] args) {
		 Main p = new  Main ();
		p.input();
		p.compute();
		p.output();
		}
	}

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

#define all(x) (x).begin(),(x).end()

#define MOD 1000000007

using namespace std;

int main(){
	string s;
	int cnt=0;
	char before='R';
	vector<int> tmp;
	vector<int> ans;
	
	cin >> s;
	
	for(int i=0; i<s.length(); i++){
		if(before==s[i])	cnt++;
		else{
			tmp.push_back(cnt);
			cnt=1;
			before=s[i];
		}
	}
	tmp.push_back(cnt);
	
	for(int i=0; i<tmp.size(); i+=2){
		for(int j=0; j<tmp[i]-1; j++){
			ans.push_back(0);
		}
		ans.push_back(tmp[i]/2+tmp[i]%2+tmp[i+1]/2);
		ans.push_back(tmp[i]/2+tmp[i+1]/2+tmp[i+1]%2);
		for(int j=0; j<tmp[i+1]-1; j++){
			ans.push_back(0);
		}
	}
	
	for(int i=0; i<ans.size(); i++){
		cout << ans[i];
		if(i!=ans.size()-1)	cout << " ";
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 1592
k,s = map(int,input().split())
count = 0
for i in range(k+1):
    for j in range(k+1):
        l = s-(i+j)
        if i+j+l == s and l >= 0 and l <= k and i <= k and j <= k:
            #print("解：",i,j,l)
            count += 1
print(count)

Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
char ch[5]={'a','e','i','o','u'},s;
int main()
{
	s=getchar();
	for(int i=0;i<5;i++)
	{
		if(s==ch[i])
		{
			cout<<"vowel"<<endl;
			return 0;
		}
	}
	cout<<"consonant"<<endl;
	return 0;
}


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


public class Contest
{
	public static void Main()
	{

/*
		int n = a[0];
		int[][] e = new int[n][];
		for(int i=0; i<n; i++) MyIO.ReadArray(out e[i]);

		int[] a;
		MyIO.ReadArray(out a);

        long a,b,c,d,e,f;
        MyIO.ReadMulti(out a, out b, out c, out d, out e, out f);

		MyIO.WriteArray(ans);
*/

        int n,y;
		MyIO.ReadMulti(out n, out y);


		for(int i=0; i<=n;i++){
			for(int j=0; j<=n-i;j++){
				int z = y/1000-10*i-5*j;
				if(z<0) break; 
				if((i+j+z)==n){
					Console.WriteLine(i.ToString() + " " + j.ToString() + " " + z.ToString());
					return;
				}
			}
		}

		Console.WriteLine("-1 -1 -1");
	}


}

public static class MyIO
{
	private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
	private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
	private static T cv<T>(string s) => eq<T, int>()    ? ct<T, int>(int.Parse(s))
	                                  : eq<T, long>()   ? ct<T, long>(long.Parse(s))
	                                  : eq<T, double>() ? ct<T, double>(double.Parse(s))
	                                  : eq<T, char>()   ? ct<T, char>(s[0])
	                                                    : ct<T, string>(s);
	public static string[] ReadArray<T>(out T[] a) {		
		var ar = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries); 												
		a = System.Array.ConvertAll(ar, new Converter<string,T>(cv<T>));
		return ar;
	}										
	public static string[] ReadMulti<T>(out T a) {
		var ar = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries); 
		a = cv<T>(ar[0]);
		return ar;
	}
	public static string[] ReadMulti<T, U>(out T a, out U b) {
		var ar = ReadMulti<T>(out a); 
        b = cv<U>(ar[1]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
		var ar = ReadMulti<T, U>(out a, out b); 
        c = cv<V>(ar[2]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) {
		var ar = ReadMulti<T, U, V>(out a, out b, out c); 
        d = cv<W>(ar[3]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) {
		var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); 
        e = cv<X>(ar[4]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) {
		var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); 
        f = cv<Y>(ar[5]);
		return ar;
	}

	public static void WriteArray<T>(T[] a) {
		Console.WriteLine(string.Join(" ", Array.ConvertAll(a, x => x.ToString())));
	}


}




Measured memory_bytes: 11348
def partition(A, p, r):
  x = A[r]
  i = p - 1
  for j in range(p, r):
    if A[j] <= x:
      i = i + 1
      A[i], A[j] = A[j], A[i]
  A[i+1], A[r] = A[r], A[i+1]
  return i + 1

if __name__ == "__main__":
  import sys
  n = sys.stdin.readline()
  for line in sys.stdin:
    items = line.strip().split()
    items = [ int(item) for item in items ]
    target = partition(items, 0, len(items) - 1)
    items[target] = "[%s]" % (items[target])
    print " ".join([ str(item) for item in items ])

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

const int N = 405;

int sum[N][N];
int pw[N][N];
int A[N], B[N];

const int mod = 1e9 + 7;

int n, C;
int f[N][N], ans[N];

int main() {
	for (int i = 1; i < N; i ++) {
		pw[i][0] = 1;
		for (int j = 1; j < N; j ++) pw[i][j] = 1ll * pw[i][j-1] * i % mod;
	}
	for (int p = 0; p < N; p ++) {
		sum[p][0] = (p == 0);
		for (int i = 1; i < N; i ++) {
			sum[p][i] = pw[i][p] + sum[p][i-1];
			if (sum[p][i] >= mod) sum[p][i] -= mod;
		}
	}
	scanf("%d %d", &n, &C);
	for (int i = 1; i <= n; i ++) scanf("%d", &A[i]);
	for (int i = 1; i <= n; i ++) scanf("%d", &B[i]);
	for (int i = 1; i <= n; i ++) {
		for (int j = 0; j <= C; j ++) {
			f[i][j] = sum[j][B[i]] - sum[j][A[i]-1];
			if (f[i][j] < 0) f[i][j] += mod;
		}
	}
	ans[0] = 1;
	for (int i = 1; i <= n; i ++) {
		for (int j = C; j >= 0; j --) {
			ans[j] = 1ll * ans[j] * f[i][0] % mod;
			for (int jj = j-1; jj >= 0; jj --) {
				ans[j] = (ans[j] + 1ll * ans[jj] * f[i][j-jj]) % mod;
			}
		}
	}
	printf("%d\n", ans[C]);
	return 0;
}


Measured memory_bytes: 5756
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
typedef long double ld;
const int N  = 5e5+10;
const ll mod = 1e9+7;
const ll inf = 1e18;
 
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define iceil(n,x)      ((n)+(x)-1)/(x)
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pll             pair<ll,ll>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;   }
ll lcm(ll a, ll b) { ll r=((a*b)/gcd(a,b)); return r;}
ll isOnBit(ll n, ll b) {return (n >> b) & 1;         }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }
ll choose2(ll n)   { ll ans=(n*(n-1))/2; return ans;  }
ll digsum(ll n)    { ll cnt=0; while(n){cnt+=(n%10); n/=10;} return cnt;}
ll dist2(ll x1,ll y1,ll x2,ll y2){ ll ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return ans;}


int main()
{
    fast
    string s;
    cin>>s;
    
    ll cnt[26]={0};
    forn(i,0,4)
    {
    	cnt[s[i]-'A']++;
    }
    int a=0;
    forn(i,0,26)
    {
    	if(cnt[i]==2)
    		a++;
    }

    if(a==2)
    	cout<<"Yes";
    else
    	cout<<"No";

    return 0;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')

typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
const int p = 1e9 + 7;
ll inv[maxn];
ll fac[maxn];
ll invfac[maxn];
void init()
{
    inv[0] = inv[1] = 1;
    for (int i = 2; i <= maxn; i++)
    {
        inv[i] = (p - p / i) * inv[p % i] % p;
    }
}
ll C(ll n, ll m)
{
    fac[0] = invfac[0] = invfac[1] = 1;
    for (int i = 1; i <= n; i++)
    {
        fac[i] = (ll)fac[i - 1] * i % p;
    }
    for (int i = 2; i <= n; i++)
        invfac[i] = (ll)(p - p / i) * invfac[p % i] % p;
    for (int i = 2; i <= n; i++)
    {
        invfac[i] = (ll)invfac[i - 1] * invfac[i] % p;
    }
    //cout << fac[n] * invfac[m] % p * invfac[n - m] % p << "\n";
    ll res = n < m ? 0 : (ll)fac[n] * invfac[m] % p * invfac[n - m] % p;
    return res;
}
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int X, Y;
    cin >> X >> Y;
    if ((X + Y) % 3 != 0 || (2 * Y - X < 0) || (2 * X - Y < 0))
    {
        cout << 0 << "\n";
    }
    else
    {
        ll m = (2 * X - Y) / 3;
        ll n = (2 * Y - X) / 3;
        cout << C(n + m, n) << "\n";
    }
    return 0;
}

Measured memory_bytes: 14008
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int a;
    while(cin>>a){
        if(a%2==0){
            if(a%3==0||a%5==0){
                
            }else{
                cout<<"DENIED";return 0;
            }
        }
    }
    cout<<"APPROVED";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

int main(){
    int N,X; cin>>N>>X;
    vector<int> City(N);
    rep(n,0,N) cin>>City.at(n);
    City.push_back(X);

    sort(ToEnd(City));
    vector<int> Dis(N);
    rep(n,0,N) Dis.at(n)=City.at(n+1)-City.at(n);
    sort(ToEnd(Dis));

    int ans=Dis.front();
    rep(i,1,Dis.size()) ans=gcd(ans,Dis.at(i));

    cout<<ans<<endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 整数の入力
	int n = sc.nextInt();
	int k = sc.nextInt();

	List<Integer> h = new ArrayList<Integer>();

	for (int i = 1; i <= n; i ++){
	    h.add(sc.nextInt());
	}
	Collections.sort(h);

	int minsub = 1000000000;
	int sub;
	for (int i = 1; i <= n - (k-1); i ++){
	    sub = h.get(i-1 + k-1) - h.get(i-1);
	    if(sub < minsub){
		minsub = sub;
	    }
	}

	// 出力
	System.out.println(minsub);
    }
}


Measured memory_bytes: 60488
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[10010];
    rep(i, n) cin >> a[i];
    int ans = 0;
    rep(i, n) while(a[i] % 2 == 0) {ans++; a[i] /= 2;}
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
while True:
        count = 0
        list = input().split()
        n = int(list[0])
        x = int(list[1])
        if n == 0 and x == 0:
                break
        for i in range(1, n + 1):
                for j in range(i + 1, n + 1):
                        for k in range(j + 1, n + 1):
                                if i + j + k == x:
                                        count += 1
        print(count)


Measured memory_bytes: 5592
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    int ar[n+1],a[n];
    fill(ar, 0);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        int l=max(0ll, i-a[i]);
        int r=min(n, i+a[i]+1);
        ar[l]++;
        ar[r]--;
    }
    int pre[n+1];
    pre[0]=ar[0];
    for(int i=1;i<=n;i++)
    pre[i]=pre[i-1]+ar[i];
    for(int i=0;i<n;i++)
    a[i]=pre[i];
    k--;
    for(int i=0;i<k;i++)
    {
        fill(ar, 0);
        for(int i=0;i<n;i++)
        {
            int l=max(0ll, i-a[i]);
            int r=min(n, i+a[i]+1);
            ar[l]++;
            ar[r]--;
        }
        pre[0]=ar[0];
        int f=0;
        for(int i=1;i<=n;i++)
        pre[i]=pre[i-1]+ar[i];
        for(int i=0;i<n;i++)
        {
            a[i]=pre[i];
            if(a[i]!=n)
            f=1;
        }
        if(f==0)
        break;
    }
    for(int i=0;i<n;i++)
    cout<<a[i]<<" ";
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0;
	int count = 1;
	for (int i = 1; i < n; i++) {
		if (a[i] == a[i - 1])
			count++;
		else {
			if (count >= a[i - 1])
				ans += count - a[i - 1];
			else
				ans += count;
			count = 1;
		}
	}
	if (count >= a[n - 1])
		ans += count - a[n - 1];
	else
		ans += count;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
///////////////////////////////////////

int main() {
	int N, K;
	cin >> N >> K;
	double ans = 0.0;
	for (int i = 1; i <= N; ++i) {
		double tmp = 1.0/ N;
		int k = i;
		while (K > k) {
			k *= 2;
			tmp /= 2;
		}
		ans += tmp;
	}
	cout << setprecision(12) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//(int)'a'は97 (int)'A'は65
//おまじない



int main() {
	
	int x, y;
	cin >> x >> y;

	if (x + y < 10) {
		cout << x + y << endl;
	}
	else {
		cout << "error" << endl;
	}


	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();
      int wa=0;
      int ac=0;
      int tle=0;
      int re=0;
      for(int i=0;i<N+1;i++){
      String ch=sc.nextLine();
       if(ch.equals("AC")){
         ac++;
       }
        if(ch.equals("WA")){
          wa++;
       }
       if(ch.equals("TLE")){
         tle++;
       }
       if(ch.equals("RE")){
         re++;
       }
      }
      System.out.println("AC x "+ac);
      System.out.println("WA x "+wa);
      System.out.println("TLE x "+tle);
      System.out.println("RE x "+re);
}
}

Measured memory_bytes: 59716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int n,m,dis[1005],pa[1005],mn,mnx;vector<int> v[1005],sav[1005];bool vis[1005];
void bfs(int x){
    queue<int> q;
    q.push(x);
    rep(i,1,n) vis[i]=0,pa[i]=dis[i]=0;
    dis[x]=inf;
    while(!q.empty()){
        int t=q.front();q.pop();
        rap(i,0,v[t].size()){
            int to=v[t][i];
            if(vis[to]) continue;
            q.push(to);vis[to]=1;
            int cs=(x==t?0:dis[t]);
            dis[to]=cs+1;pa[to]=t;
            if(to==x){
                int p=t;
                while(p!=x){sav[x].pb(p);p=pa[p];}
                sav[x].pb(x);
            }
        }
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    rep(i,1,m){
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        v[t1].pb(t2);
    }
    mn=inf;
    rep(i,1,n) {
        bfs(i);
        if(mn>dis[i]) mn=dis[i],mnx=i;
        //printf("%d %d\n",i,dis[i]);
    }
    if(mn==inf) printf("-1");
    else {
        printf("%d\n",mn);
        rap(i,0,sav[mnx].size()) printf("%d\n",sav[mnx][i]);
    }
    return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)

using namespace std;
int main() {
    long long N;
    cin >> N;
    long long a[N];
    long long sum = 0;
    long long x = 0;
    REP(i, N) {
        cin >> a[i];
        sum += a[i];
    }
    long long min = 1000000000000000000LL;
    REP(i, N) {
        x += a[i];
        if(i+1 < N) {
            if(min > abs(sum-x*2)) {
                min = abs(sum-x*2);
            }
        }
    }
    cout << min << "\n";
}

Measured memory_bytes: 1792
program main
   implicit none
   integer n,i,counter
   character(100) ::a,b,c
   read(*,*)n
      read(*,*)a
   read(*,*)b
   read(*,*)c
   counter=0
   do i=1,n
      if(a(i:i)==b(i:i).and.c(i:i)==b(i:i))then
         counter=counter
      elseif(a(i:i)/=b(i:i) .and. c(i:i)/=b(i:i) .and. c(i:i)/=a(i:i))then
         counter=counter+2
      else
         counter=counter+1
      endif
   enddo
   write(*,*)counter
end program main


Measured memory_bytes: 256
#include<cctype>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
#define N 2000010
#define mod 998244353
using namespace std;int n,Q,l,r;
LL s[N],x;
inline LL read()
{
	char c;LL d=1,f=0;
	while(c=getchar(),!isdigit(c)) if(c=='-') d=-1;f=(f<<3)+(f<<1)+c-48;
	while(c=getchar(),isdigit(c)) f=(f<<3)+(f<<1)+c-48;
	return d*f;
}
struct xds
{
	#define lson k<<1
	#define rson k<<1|1
	LL sum[N<<2],lzy[N<<2];
	inline void pushup(int k)
	{
		(sum[k]=sum[lson]+sum[rson])%=mod;
		return;
	}
	inline void pushdown(int k,int l,int r)
	{
		if(lzy[k]==0) return;
		int mid=l+r>>1;
		lzy[lson]=lzy[rson]=lzy[k];
		sum[lson]=((s[mid]-s[l-1]+mod)%mod)*lzy[k]%mod;
		sum[rson]=((s[r]-s[mid]+mod)%mod)*lzy[k]%mod;
		lzy[k]=0;
		return;
	}
	inline int Query(int ql,int qr,int k=1,int l=0,int r=n) 
	{
		if(ql<=l&&r<=qr) return sum[k];
		LL res=0;
		int mid=l+r>>1;
		pushdown(k,l,r);
		if(ql<=mid) res+=Query(ql,qr,lson,l,mid);
		if(qr>mid) res+=Query(ql,qr,rson,mid+1,r);
		pushup(k);
		return res;
	}
	inline void Modify(int ql,int qr,LL val,int k=1,int l=0,int r=n)
	{
		if(ql<=l&&r<=qr) {lzy[k]=val;sum[k]=(s[r]-s[l-1]+mod)%mod*val%mod;return;}
		int mid=l+r>>1;
		pushdown(k,l,r);
		if(ql<=mid) Modify(ql,qr,val,lson,l,mid);
		if(qr>mid) Modify(ql,qr,val,rson,mid+1,r);
		pushup(k);
		return;
	}
}T;
signed main()
{
	n=read();Q=read();
	s[1]=1;
	for(register int i=2;i<=n;i++) s[i]=((s[i-1]<<3)+(s[i-1]<<1)+1)%mod;
	T.Modify(1,n,1);
	while(Q--)
	{
		l=read();r=read();x=read();
		l=n-l+1;r=n-r+1;
		r=l^r;l^=r;r=l^r;
		T.Modify(l,r,x);
		printf("%lld\n",T.sum[1]);
	}
}

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

// dp[i][j][k][l]:
// n 番目の物まで見て (w_1, w_1+1, ...) の4種類の物が
// それぞれ (i, j, k, l) 個入っているときの価値の最大値
long long dp[102][102][102][102] = {};

int main()
{
    int N, W;
    cin >> N >> W;
    vector<long long> w(N), v(N);
    for(int i = 0; i < N; ++i) cin >> w[i] >> v[i];

    vector<int> num_w(4);
    for(int i = 0; i < N; ++i) ++num_w[w[i]-w[0]];

    dp[1][0][0][0] = v[0];
    for(int n = 1; n < N; ++n){
        for(int i = num_w[0]; i >= 0; --i){
            for(int j = num_w[1]; j >= 0; --j){
                for(int k = num_w[2]; k >= 0; --k){
                    for(int l = num_w[3]; l >= 0; --l){
                        if(w[n]-w[0] == 0){
                            dp[i+1][j][k][l] = max(dp[i][j][k][l]+v[n], dp[i+1][j][k][l]);
                        }
                        if(w[n]-w[0] == 1){
                            dp[i][j+1][k][l] = max(dp[i][j][k][l]+v[n], dp[i][j+1][k][l]);
                        }
                        if(w[n]-w[0] == 2){
                            dp[i][j][k+1][l] = max(dp[i][j][k][l]+v[n], dp[i][j][k+1][l]);
                        }
                        if(w[n]-w[0] == 3){
                            dp[i][j][k][l+1] = max(dp[i][j][k][l]+v[n], dp[i][j][k][l+1]);
                        }
                        // cout << n << " " << i << " " << j << " " << k << " " << l << " " << dp[i][j][k][l] << endl;
                    }
                }
            }
        }
    }

    long long ans = 0;
    for(int i = 0; i <= num_w[0]; ++i){
        for(int j = 0; j <= num_w[1]; ++j){
            for(int k = 0; k <= num_w[2]; ++k){
                for(int l = 0; l <= num_w[3]; ++l){
                    if(i+j+k+l <= N and w[0]*(i+j+k+l)+j+2*k+3*l <= W){
                        ans = max(ans, dp[i][j][k][l]);
                    }
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 205056
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define watch(x); cout<<#x<<"="<<x<<endl;
#define watch2(x,y); cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define endl "\n"
#define int long long
using namespace std;    


int32_t main(){

    fast
    string s;
    cin>>s;
    if(s=="ABC")cout<<"ARC";
    else cout<<"ABC";


    return 0;
}



Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>

using namespace std;

pair<int,int> divmod(int a, int b) {
    int q = a / b, r = a - b * q;
    if (r < 0) {
        ++q;
        r = a - b * q;
    }
    return make_pair(q, r);
}

int main() {
    int N;
    cin >> N;
    vector<int> a;
    pair<int, int> p;
    do {
         p = divmod(N, -2);
         auto q = p.first;
         auto r = p.second;
         a.push_back(r);
         N = q;
    } while (N != 0);
    for (auto itr = a.rbegin(); itr != a.rend(); ++itr) {
        cout << *itr;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
typedef long long ll;
typedef long double ld;

int sort1(const void* a, const void* b) {
	return *(int*)b - *(int*)a;
}

int main() {
	int n, m, a[200001], b[200001], c[200001] = { 0 }, d[200001] = { 0 };
	scanf("%d %d", &n, &m);
	rep(i, m) {
		scanf("%d %d", &a[i], &b[i]);
		if (a[i] == 1)c[b[i]] = 1;
		if (b[i] == n)d[a[i]] = 1;
	}
	rep(i, n) {
		if (c[i] == d[i] && c[i] == 1) { printf("POSSIBLE"); return 0; }
	}
	printf("IMPOSSIBLE");
}

Measured memory_bytes: 3328
import math
import copy
N, H = map(int, input().split())
a_max = [list(map(int, input().split())) for _ in range(N)]
b_max = copy.deepcopy(a_max)
b_max.sort(key=lambda x:-x[1])
a_max.sort(key=lambda x:-x[0])
damage = 0
cnt_damage = 0
for i in range(N):
    if damage >= H:
        print(cnt_damage)
        exit()
        
    if b_max[i][1] >= a_max[0][0]:
        damage += b_max[i][1]
        cnt_damage += 1
    else:
        break

cnt_damage += math.ceil((H-damage)/a_max[0][0])

print(cnt_damage)

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{

	cin.tie(0); ios_base::sync_with_stdio(false);
	int n,  ans =0;
	string s;
	cin >> s;
	bool ok=true;
	rep(i, sz(s)){
		if(i%2==0 && s[i] =='L') ok=false;
		if(i%2==1 && s[i] =='R') ok=false;
	}
	puts(ok? "Yes":"No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
ll ans = 0LL;
int i_index;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];

int main(){
    int nmax = 50;
    cin >> N >> M;
    int a[nmax], b[nmax];
    int cnt[nmax];
    rep(i, nmax) cnt[i] = 0;
    rep(i, M) cin >> a[i] >> b[i];
    rep(i, M){
        cnt[a[i] - 1]++;
        cnt[b[i] - 1]++;
    }
    rep(i, N) cout << cnt[i] << endl;
    return 0;
}

Measured memory_bytes: 256
# ALDS1_11_C.py
import queue


def printNode():
    for i, node in enumerate(glaph):
        print(i, node)


N = int(input())
glaph = [[] for i in range(N+1)]
for i in range(1, N+1):
    glaph[i] = list(map(int, input().split()))[2:]
# printNode()

step = [-1]*(N+1)
step[1] = 0

q = queue.Queue()
q.put(1)
while not q.empty():
    now = q.get()
    next_node = glaph[now]
#    print("now is ", now, ", next is", next_node)
    for i in next_node:
        if step[i] != -1:
            continue
        q.put(i)
        step[i] = step[now] + 1

for i, v in enumerate(step):
    if i != 0:
        print(i, v)



Measured memory_bytes: 6844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, flg=0, ans=0;
  cin >> n;
  int A[n];

  rep(i, n)
  {
    cin >> A[i];
  }
  while(true)
  {
    rep(i, n)
    {
      if(A[i] % 2 != 0)
      {
        flg = 1;
        break;
      }
      else
      {
        A[i] /= 2;
      }
    }
    if(flg)
      break;
    ans++;
  }
  

  cout << ans << endl;

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)

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

    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    cout << (s < t ? "Yes": "No") << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
# dp[buy][sell]
dp = [0 for j in range(n)]
dp[0] = 1000
for i in range(n):
    ai = a[i]
    m = dp[i]
    s = m // ai

    for j in range(i + 1, n):
        dp[j] = max(dp[j], m + s * (a[j] - ai))

    for j in range(n - 1):
        dp[j + 1] = max(dp[j + 1], dp[j])
print(dp[-1])


Measured memory_bytes: 9216
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>

using namespace std;

int main()
{
    string s;
    int T[300000];
    int q;
    int f;
    int r = 0;
    string fro = "";
    string tai = "";
    string c;
    
    cin >> s;
    cin >> q;
    for (int i = 0;i < q;i++){
        cin >> T[i];
        if (T[i] == 2){
            cin >> f >> c;
            if ((r%2 == 1 && f == 1) || (r%2 == 0 && f == 2)){
                tai = tai + c;
            }
            else {
                fro = c + fro;
            }
        }
        else {
            r = (r+1)%2;
        }
    
    }
    s = fro + s + tai;
    if (r%2 == 1){
        reverse(s.begin(),s.end());
    }
    
    cout << s << endl;
}


Measured memory_bytes: 2236
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;





int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<int>>a(h, vector<int>(w));
    ll p = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
            a[i][j] = (a[i][j] + 1) % 2;
            p = max((int)p, a[i][j]);
          
        }
    }



    for (int i = 1; i < h; i++) {
        for (int j = 1; j < w; j++) {
            if (!a[i][j])a[i][j] = 0;
            else {
                a[i][j] = min(a[i-1][j-1], min(a[i-1][j], a[i][j-1])) + 1;
                p = max(a[i][j], (int)p);
                
            }
        }
    }

    cout << p * p << endl;




    return 0;

}


Measured memory_bytes: 10496