akhauriyash/Code-Regression huggingface dataset:
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException ‚There is no more input";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var W = one[0];
  var H = one[1];
  var x = one[2];
  var y = one[3];
  var output = new Array(2);
  output[0] = H * W / 2;
  output[1] = (x == W / 2 && y == H / 2) ? 1 : 0;
  myout(myconv(output, 8));
}


Measured memory_bytes: 30940
//Humra Baski naahi...
 
#include<bits/stdc++.h>
#include <math.h> 
using namespace std;

//-----------------------------------------------------------------------------------
typedef long long int ll;
typedef long double ld;
#define endl "\n"
#define int long long
#define float long double
#define u_s unordered_set
#define mm multimap
#define pb push_back
#define ff first
#define ss second
#define go_flash ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
const int mod = 1000000007;
//-----------------------------------------------------------------------------------
void primeFactors(int n){while(!(n%2)){n/=2;}for(int i=3;i<=sqrt(n);i+=2){
while(!(n%i)){n/=i;}}if(n>2){;}}
int cd(int n){return floor(log10(n) + 1);} 
unsigned int cb(int number) {unsigned int l=log2(number)+1;return l;}
bool at_position(int num,int pos){unsigned int go=(1ULL<<pos);bool bit = num & go;return bit;} 
//-----------------------------------------------------------------------------------
template<typename...T>void input(T &...args) {((cin >> args), ...);}
template<typename...T>void print(T &&...args) {((cout << args <<" "),...);}
template<typename...T>void deb(T &&...args) {((cerr<<args<<" "),...);cerr<<endl;}
//#define debug(x) cerr<<#x<<" => "<<x<<" ";
//-----------------------------------------------------------------------------------
void forv(vector<int> &v, int n) {int x;for(int i=0;i<n;i++){cin>>x;v.pb(x);}}
void printv(vector<int> v) {for(auto i: v){cout<<i<<" ";}}
void fora(int a[], int n) {for(int i=0;i<n;i++)cin>>a[i];}
void printa(int a[], int n) {for(int i=0;i<n;i++)cout<<a[i]<<" ";}
void dmap(map<int,int> mp){for(auto i: mp)cout<<i.ff<<" "<<i.ss<<endl;}
void dmmap(mm<int,int> mp){for(auto i: mp)cout<<i.ff<<" "<<i.ss<<endl;}
//-----------------------------------------------------------------------------------

signed main(){
    go_flash;cout<<fixed<<setprecision(17);

        int t=1;
        while(t--){
            //Your Code Blows HERE
            float a,b,h,m;input(a,b,h,m);
            float an=abs((5.5*m)-(30*h)),el=cos((M_PI*an)/180);
            float el2=pow(a,2)+pow(b,2)-(2*a*b*el);
            cout<<pow(el2,0.5);
            cout<<endl;
        }
    return 0;
}


Measured memory_bytes: 4184
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝

*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long  t,r=1,r1=0,r2=0,k=0,a,b,c=0,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    vector<tuple<string,int,
           int>>mp;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>a>>b>>c;

    if((b*c)>=a)
    {
        cout<<"Yes"<<endl;
    }
    else{cout<<"No"<<endl;}
}


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

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	for(int i = 0; i < N; i++){
		cin >> A.at(i);
		B.at(i) = A.at(i);
	}
	
	sort(B.begin(), B.end());
	int maxA = B.at(N - 1);
	int maxA2 = B.at(N - 2);
	
	for(int i = 0; i < N; i++){
		if(A.at(i) == maxA) cout << maxA2 << endl;
		else cout << maxA << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
n,x,m=map(int,input().split())
l=[0 for i in range(m)]
ans=0
y=[]
i=1
flag=0
ys=n
while i<n+1:
    if flag==0:
        ans+=x
    l[x]+=1
    x=x*x%m
    i+=1
    if l[x]==2 and flag==0:
        flag=1
        ys=i
    if flag:
        if l[x]==3:
            break
        y.append(x)
if len(y):
    p,pp=divmod(n-ys,len(y))
    print(ans+p*sum(y)+sum(y[:pp+1]))
    #print(ans,p*sum(y),sum(y[:pp+1]))
else:
    print(ans)

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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
int lcm(int a, int b) { return a / __gcd(a,b) * b;}
/***** MAIN *****/
signed main() {
  int N, M;
  string S, T;
  cin >> N >> M;
  cin >> S >> T;
  int L = lcm(N,M);
  string longer_s, shorter_s;
  int longer_l, shorter_l;
  if(N == M) {
    if(S == T) {
      cout << N << endl;
      return 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if(N > M) {
    longer_s = S, shorter_s = T;
    longer_l = N, shorter_l = M;
  } else {
    longer_s = T, shorter_s = S;
    longer_l = M, shorter_l = N;
  }
  int i = 0;
  bool possible = true;
  int longer_l_div = L / longer_l;
  int shorter_l_div = L / shorter_l;
  while(longer_l_div*i <= L) {
    if((longer_l_div*i) % shorter_l_div == 0) {
      int shorter_i = longer_l_div*i / shorter_l_div;
      if(longer_s[i] != shorter_s[shorter_i]) {
        possible = false;
        break;
      }
    }
    ++i;
  }
  if(possible) {
    cout << L;
  } else {
    cout << -1;
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;

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

vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, 1, 0, -1};


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int h, w; cin >> h >> w;
    vector<vector<char>> s(h, vector<char>(w));

    REP(i, h) {
        string line; cin >> line;
        REP(j, w) {
            s.at(i).at(j) = line.at(j);
        }
    }

    Field dp(h, vector<int>(w, INT32_MAX));


    int sy = 0, sx = 0;
    int gy = h - 1, gx = w - 1;

    pair<int, int> sp = {sy, sx};
    queue<pair<int, int>> que;
    que.push(sp);
    dp.at(sy).at(sx) = 0;

    bool flag = false;

    while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();

        int y = p.first, x = p.second;

        REP(i, 4) {
            int ny = y + dy.at(i), nx = x + dx.at(i);
            if (ny < 0 || h <= ny || nx < 0 || w <= nx || s.at(ny).at(nx) == '#') continue;
            if (dp.at(ny).at(nx) != INT32_MAX) continue;

            dp.at(ny).at(nx) = min(dp.at(ny).at(nx), dp.at(y).at(x) + 1);

            if (ny == gy && nx == gx) {
                flag = true;
                break;
            }
            que.push(make_pair(ny, nx));
        }
        if (flag) break;
    }

    if (flag) {
        int m = 0;
        REP(i, h) REP(j, w) if (s.at(i).at(j) == '#') m++;
        int ans = h * w - m - dp.at(gy).at(gx) - 1;
        cout << ans << endl;
    } else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

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() {
	int n;
	string s;
	cin >> n >> s;
	
	string l = s.substr(0, n / 2);
	string r = s.substr(n / 2);

	if (l != r) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    string s;
    vector<int> S(4,0);
    string name[4] = {"AC","WA","TLE","RE"};
    cin>>N;
  	for(int i=0;i<N;i++){
          cin>>s;
          if(s=="AC"){
              S[0] += 1;
          }else if(s=="WA"){
              S[1] += 1;
          }else if(s=="TLE"){
              S[2] += 1;
          }else{
              S[3] += 1;
          }
    }
    for(int i=0;i<4;i++){
        cout<<name[i]<<" x "<<S[i]<<endl;
    }
}

Measured memory_bytes: 3592
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int max = 0,a, count,ans=1;
		for(int i = 1;i <= n;i++) {
			count = 0;
			if(i % 2 == 1)continue;
			a = i;
			for(;;) {
				if(a / 2 != 0) {
					a = a/2;
					count++;
				}
				else {
					count++;
					break;
				}
			}
			if(max < count) {
				max = count;
				ans = i;
			}
		}
		System.out.println(ans);
	}

}

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

LL n, a, k, g;
bool flag = false;
LL gcd(LL a, LL b){
	return b ? gcd(b, a%b) : a;
}

int main(){
	scanf("%lld%lld%lld", &n, &k, &g);
	if (n == 1){
		if (k != g) puts("IMPOSSIBLE");
		else puts("POSSIBLE");
		return 0;
	}
	if (g >= k) flag = true;
	for (int i=2; i<=n; i++){
		scanf("%lld", &a);
		if (a >= k) flag = true;
		g = gcd(a, g);
	}
	if (k % g == 0 && flag) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define IN_BUF 22
#define OUT_BUF 5

int main(void) {
  char in_str[IN_BUF];
  memset(in_str, '\0', IN_BUF);
  scanf("%s", in_str);
  char out_str[OUT_BUF];
  memset(out_str, '\0', OUT_BUF);
  strncpy(out_str, in_str, 3);
  printf("%s\n", out_str);

  return 0;
}


Measured memory_bytes: 1664
/*
            _           __                _      _____ _____ _____ 
  ___ _   _| |__   ___ / _|_ __ ___  __ _| | __ |___  |___  |___  |
 / __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ /    / /   / /   / / 
| (__| |_| | |_) |  __/  _| | |  __/ (_| |   <    / /   / /   / /  
 \___|\__,_|_.__/ \___|_| |_|  \___|\__,_|_|\_\  /_/   /_/   /_/   

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll ;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<int> vl;
typedef vector<pll> vpll;
typedef unordered_map <ll,ll> umap ; 
//#pragma GCC optimize "trapv"
#define loop(i,a,b) for(ll i=a ;i<b;i++)
#define For(i,n) for(int i=0;i<(ll)n;i++)
#define Rev(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,n) for(int i=1;i<=n;++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(),(v).end()                                                              
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a,b) make_pair(a,b)
#define pf(n) {cout<<n<<"\n" ; return ;}
#define po(n) cout << n <<"\n " 
#define pff(n) cout << n << " " ; 
#define ar array
#define endl "\n" 
#define PI acos(-1) 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
//#ifndef ONLINE_JUDGE
//#ifndef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
//#else
//#define debug(x...)
//#endif
//#define int ll 
long const M=1e9+7;
const long mxN =1e5+2 ;
const ll INF =1e18;
void solve(){ 
  int x,n ;set<int> a ;
  cin >> x >> n;
  For(i,n){
    int p ;
    cin >> p ;
    a.insert(p) ;
  }   
  int ans =1e6 ,r;
  for(int i=101;~i;--i){
    if(abs(i-x)<=ans && !a.count(i) ){
      ans = abs(i-x) ;
      r =i ;
    }
  }
  cout << r << endl ;
  
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //cout << setprecision(20) << fixed ;
  solve() ;
  // ll t ; cin >> t ; while(t--)solve() ;
	return 0;
}


Measured memory_bytes: 3660
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N = int(input())
a = list(map(int, input().split()))

# N = 6
# a =  [0, 0, 0, 1, 0, 1]
# ans: [1,    3, 4,    6]

# N = 6
# a =  [1, 1, 0, 1, 0, 1]
# ans: [1, 2, 3, 4,    6]

b = [0 for _ in range(N)]


for i in range(N - 1, 0 , -1):
    # i は 5 から 1 までイテレートする
    # print('i', i)
    # print('a', a[::i][1:])
    # print('b', b[i::i+1])
    # print("")
    # あれ... a イテレートする必要なくない...??
    if (a[i] + sum(b[i::i+1])) % 2 == 0:
        b[i] = 0
    else:
        b[i] = 1

if a[0] == 0:
    b[0] = (sum(b[1:])) % 2
else:
    # print('kotti', sum(b[1:]))
    b[0] = (sum(b[1:]) + 1) % 2

# print('a', a)
# print('b', b)

s = sum(b)
print(s)
if s != 0:
    # print(*b[:last_index(b, 1) + 1])
    print(*[x + 1 for x in range(N) if 0 < b[x]])


Measured memory_bytes: 13112
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        cin.ignore();
        string s[2005];
        rep(i,n){
            cin >> s[i];
        }

        rep(i,n){
            rep(j,s[i].size() - 1){
                if(s[i][j] == '.' && s[i][j + 1] != '.') s[i][j] = '+';
            }
        }

        rep(i,n){
            rep(j,s[i].size() - 1){
                int last = 0;
                if(s[i][j] == '+'){
                    for(int k = i - 1; s[k][j] == '.'; k--){
                        s[k][j] = '|';
                    }
                }
            }
        }

        rep(i,n){
            rep(j,s[i].size()){
                if(s[i][j] == '.') s[i][j] = ' ';
            }
        }
        rep(i,n) cout << s[i] << endl;
    }
}

Measured memory_bytes: 3736
N = int(input())

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

B = [0] + A + [0]

diff_1 = [abs(B[i+1] - B[i]) for i in range(N+1)]
diff_2 = [abs(B[i+2] - B[i]) for i in range(N)]
ans = sum(diff_1)

for i in range(N):
    tmp = ans + diff_2[i] - (diff_1[i] + diff_1[i+1])
    print(tmp)

Measured memory_bytes: 21236
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <map>
#include <sstream>
#include <utility>
#include <stack>
#include <queue>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
using ll = long long;

//const int MOD = 1e9 + 7;

template <class T>
T GCD(T a, T b)
{
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

template <class T>
T LCM(T a, T b)
{
    return (a * b) / GCD(a, b);
}

template <class T>
T max_(std::vector<T> vec)
{
    std::sort(all(vec));
    return vec.at(vec.size() - 1);
}
template <class T>
T min_(std::vector<T> vec)
{
    std::sort(all(vec));
    return vec.at(0);
}

void ans(bool t_or_f)
{
    if (t_or_f == true)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
}

void Ans(bool t_or_f)
{
    if (t_or_f == true)
        std::cout << "YES" << std::endl;
    else
        std::cout << "NO" << std::endl;
}

using namespace std;

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

int main(){
    int l;
    cin >> l;
    int a = l * l * l;
    double s = a / 27.0;
    cout << fixed << setprecision(15) << s << endl;
}

Measured memory_bytes: 888
#include <stdio.h>

int main(){
    int n,h,m,s;
    scanf("%d",&n);
    h = n / 3600;
    m = (n % 3600) / 60;
    s = (n % 3600) % 60;
    
    printf("%d:%d:%d\n",h,m,s);

    return 0;
}

Measured memory_bytes: 1816
function Main(input) {
    var longest = 0;
    var current = 0;
    for(var i = 0; i < input.length; i++) {
        if(input[i] == "A" || 
        input[i] == "T" || 
        input[i] == "C" || 
        input[i] == "G"){
            current++;
            continue;
        }
        if(current > longest) longest = current;
        current = 0;
    }
    if(current > longest) longest = current;
    console.log(longest);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 7500
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;

typedef pair<int, int> PP;
typedef pair<PP, int> Q;

int main() {
  int M, T, P, R, m[2000], t[2000], p[2000], j[2000];
  while (1) {
    scanf("%d%d%d%d", &M, &T, &P, &R);
    if (M == 0) break;
    int d[500], lasttime[500], ptime[500], wa[500][2000];
    for (int i = 0; i < T; i++) lasttime[i] = ptime[i] = d[i] = 0;
    for (int i = 0; i < T; i++) for (int j = 0; j < R; j++) wa[i][j] = 0;
    for (int i = 0; i < R; i++) {
      scanf("%d%d%d%d", &m[i], &t[i], &p[i], &j[i]);
      t[i]--;
      if (j[i] == 0) {
        lasttime[t[i]] += m[i];
        ptime[t[i]] += wa[t[i]][p[i]];
        d[t[i]]++;
      } else {
        wa[t[i]][p[i]]++;
      }
    }
    Q scores[500];
    for (int i = 0; i < T; i++) scores[i] = Q(PP(d[i], -(lasttime[i] + ptime[i] * 20)), i + 1);
    sort(scores, scores + T, greater<Q>());
    printf("%d", scores[0].second);
    for (int i = 1; i < T; i++) printf("%c%d", scores[i].first.first == scores[i - 1].first.first && scores[i].first.second == scores[i - 1].first.second ? '=' : ',', scores[i].second);
    printf("\n");
  }
}



Measured memory_bytes: 3040
import java.util.*;

public class Main{
  static int[] ans;
  static Map<Integer, Integer> map;
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    
    int N = Integer.parseInt(sc.next());
    int Q = Integer.parseInt(sc.next());
    ans = new int[N];
    
    map = new HashMap<>();
    for(int i = 0; i < N-1; i++){
      int a = Integer.parseInt(sc.next());
      int b = Integer.parseInt(sc.next());
      if(map.get(b) == null){
        map.put(b, a);
      }
    }
    
    for(int i = 0; i < Q; i++){
      int a = Integer.parseInt(sc.next());
      int b = Integer.parseInt(sc.next());
      ans[a-1] += b;
    }

    for(int i = 2; i <= N; i++){
      int p = map.get(i);
      ans[i-1] += ans[p-1];
    }
    for(int i = 0; i < N; i++){
      if(i < N-1){
        System.out.print(ans[i]);
        System.out.print(" ");
      }else{
        System.out.println(ans[i]);
      }
    }
  }
}

Measured memory_bytes: 122908
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

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

ll dp[210000][5];

void add(ll &a, ll b){
    a+=b;
    if(a>=MOD) a-=MOD;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    REP(i,s.size()){
        REP(j,5){
            if(s[i] != '?') add(dp[i+1][j],dp[i][j]);
            else add(dp[i+1][j],dp[i][j]*3%MOD);
        }
        if(s[i]=='A' || s[i]=='?') add(dp[i+1][1],dp[i][0]);
        if(s[i]=='B' || s[i]=='?') add(dp[i+1][2],dp[i][1]);
        if(s[i]=='C' || s[i]=='?') add(dp[i+1][3],dp[i][2]);
    }
    cout<<dp[s.size()][3]<<endl;
}

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

const int N = 3e5 + 9;

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c, k; cin >> a >> b >> c >> k;
	int ans = 0;
	ans += min(a, k); k -= min(a, k);
	k -= min(k, b);
	ans -= min(k, c);
	cout << ans << '\n';
    return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 628;
int n, d1, d2;
vector<pair<int, int> > go1, go2;
vector<pair<int, int> > graph1[N][N], graph2[N][N];
int c1[N][N], c2[N][N];

int ok(int i, int j)
{
    return 0 <= i && i < 2 * n && 0 <= j && j < 2 * n;
}

void dfs1(int i, int j, int c)
{
    c1[i][j] = c;
    for (auto u : graph1[i][j])
    {
        int nx = u.first;
        int ny = u.second;
        if (c1[nx][ny] == 0)
        {
            dfs1(nx, ny, 3 - c);
        }
    }
}

void dfs2(int i, int j, int c)
{
    c2[i][j] = c;
    for (auto u : graph2[i][j])
    {
        int nx = u.first;
        int ny = u.second;
        if (c2[nx][ny] == 0)
        {
            dfs2(nx, ny, 3 - c);
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(20);
    cin >> n >> d1 >> d2;
    for (ll i = -600; i <= 600; i++)
    {
        for (ll j = -600; j <= 600; j++)
        {
            if (i * i + j * j == d1) go1.push_back({i, j});
            if (i * i + j * j == d2) go2.push_back({i, j});
        }
    }
    for (int i = 0; i < 2 * n; i++)
    {
        for (int j = 0; j < 2 * n; j++)
        {
            for (auto u : go1)
            {
                int nx = i + u.first, ny = j + u.second;
                if (ok(nx, ny)) graph1[i][j].push_back({nx, ny});
            }
            for (auto u : go2)
            {
                int nx = i + u.first, ny = j + u.second;
                if (ok(nx, ny)) graph2[i][j].push_back({nx, ny});
            }
        }
    }
    for (int i = 0; i < 2 * n; i++)
    {
        for (int j = 0; j < 2 * n; j++)
        {
            if (c1[i][j] == 0)
            {
                dfs1(i, j, 1);
            }
            if (c2[i][j] == 0)
            {
                dfs2(i, j, 1);
            }
        }
    }
    vector<pair<int, int> > p[2][2];
    for (int i = 0; i < 2 * n; i++)
    {
        for (int j = 0; j < 2 * n; j++)
        {
            p[c1[i][j] - 1][c2[i][j] - 1].push_back({i, j});
        }
    }
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            int c = n * n;
            if (p[i][j].size() >= n * n)
            {
                for (auto e : p[i][j]) if (c > 0) cout << e.first << " " << e.second << "\n", c--;
                return 0;
            }
        }
    }
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 176124
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPD(i,n) for(int i=(n)-1;i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
#define TLE() cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms.\n";
const ll MOD = 998244353;
const ll IINF = 1E18;
const int INF = 1e9;
const double EPS = 1E-9;
const double PI = atan(1.0) * 4.0;
template<class T> T getbit(T s, int i) {return s>>i&1;}
template<class T> void flipbit(T& s, int i) {s^=(1LL<<i);}
constexpr int cntbit(ll x) {return __builtin_popcountll(x);}
constexpr int lg2(ll x) {return __lg(x);} // return int(log2(x))
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
ll fpow(ll a,ll p){ll res=1LL;while(p){if(p&1LL) res=res*a%MOD;a=a*a%MOD;p>>=1LL;} return res;}

const int N=2e5+5;
int n;
int lowft[N],highft[N];
ll tot[N];
vector<int> x,y;
vector<pair<int,int>> p;

void lowUpd(int x,int v){
	for(;x<N;x=x|(x+1))
		lowft[x]+=v;
}

int lowGet(int x){
	int res=0;
	for(;x>=0;x=(x&(x+1))-1)
		res+=lowft[x];
	return res;
}

void highUpd(int x,int v){
	for(;x>=0;x=(x&(x+1))-1)
		highft[x]+=v;
}

int highGet(int x){
	int res=0;
	for(;x<N;x=x|(x+1))
		res+=highft[x];
	return res;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	REP(i,n){
		int u,v;
		cin>>u>>v;
		p.pb(mp(u,v));
		x.pb(u);
		y.pb(v);
	}	
	sort(p.begin(),p.end());
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	REP(i,n){
		int cur_x=p[i].fi;
		int cur_y=p[i].se;
//		cerr<<"At point: "<<cur_x<<' '<<cur_y<<'\n';
		tot[i]=MOD-1;
		(tot[i]+=fpow(2,n))%=MOD;
		(tot[i]+=MOD-fpow(2,lower_bound(x.begin(),x.end(),cur_x)-x.begin()))%=MOD;
		(tot[i]+=MOD-fpow(2,x.end()-upper_bound(x.begin(),x.end(),cur_x)))%=MOD;
//		cerr<<lower_bound(y.begin(),y.end(),cur_y)-y.begin()<<' '<<y.end()-upper_bound(y.begin(),y.end(),cur_y)<<'\n';
		(tot[i]+=MOD-fpow(2,lower_bound(y.begin(),y.end(),cur_y)-y.begin()))%=MOD;
		(tot[i]+=MOD-fpow(2,y.end()-upper_bound(y.begin(),y.end(),cur_y)))%=MOD;
		// points whose x<cur_x && y<cur_y
		int idy=lower_bound(y.begin(),y.end(),cur_y)-y.begin();
		int lowy=lowGet(idy-1);
		(tot[i]+=fpow(2,lowy))%=MOD;
		lowUpd(idy,1);
		// points whose x<cur_x && y>cur_y
		int highy=highGet(idy+1);
		(tot[i]+=fpow(2,highy))%=MOD;
		highUpd(idy,1);
//		cerr<<lowy<<' '<<highy<<'\n';
	}	
	memset(lowft,0,sizeof lowft);
	memset(highft,0,sizeof highft);
	REPD(i,n){
		int cur_x=p[i].fi;
		int cur_y=p[i].se;
		// points whose x>cur_x && y<cur_y
		int idy=lower_bound(y.begin(),y.end(),cur_y)-y.begin();
		int lowy=lowGet(idy-1);
		(tot[i]+=fpow(2,lowy))%=MOD;
		lowUpd(idy,1);
		// points whose x>cur_x && y>cur_y
		int highy=highGet(idy+1);
		(tot[i]+=fpow(2,highy))%=MOD;
		highUpd(idy,1);
	}
	ll res=0;
	REP(i,n) (res+=tot[i])%=MOD;
	cout<<res<<'\n';
}



Measured memory_bytes: 10976
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

const int dx[] = { 0, 1, 0, -1 }, dy[] = { -1, 0, 1, 0 };
//const int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy[] = { 0, -1, 1, -1, 1, 0, -1, 1 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }


int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n;
	while (cin >> n, n)
	{
		int minx = 0, maxx = 0;
		int miny = 0, maxy = 0;
		vi x = { 0 }, y = { 0 };
		REP(i, n - 1)
		{
			int a, b; cin >> a >> b;
			int tx = x[a] + dx[b], ty = y[a] + dy[b];
			x.push_back(tx);
			y.push_back(ty);
			chmax(maxx, tx);
			chmin(minx, tx);
			chmax(maxy, ty);
			chmin(miny, ty);
		}
		cout << maxy - miny + 1 << " " << maxx - minx + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}
fn argsort<T: std::cmp::Ord + std::marker::Copy>(v: &Vec<T>) -> Vec<usize> {
    let mut sort_v = Vec::new();
    for i in 0..v.len() {
        sort_v.push((v[i], i));
    }
    sort_v.sort();
    sort_v.iter().map(|x| x.1).collect::<Vec<usize>>()
}

fn main() {
    let n = read::<usize>();
    let v = read_vec::<usize>();
    let ans = argsort(&v).iter().map(|x| x + 1).collect::<Vec<_>>();
    print_array(&ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn print_array<T: std::string::ToString>(array: &Vec<T>) {
    println!(
        "{}",
        array
            .iter()
            .map(|ref x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}


Measured memory_bytes: 10356
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    if S[2] == S[3] and S[4] == S[5]:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

signed main () {
    int n;
    cin >> n;
    vector < int > b(n);
    for (int i = 0; i < n; ++i)
        cin >> b[i];
    deque < int > ans;
    while (!b.empty()) {
        int sz = int(b.size());
        for (int i = sz - 1; i >= 0; --i) {
            if (b[i] == i + 1) {
                ans.push_front(b[i]);
                b.erase(b.begin() + i);
                break;
            }
        }
        if (sz == int(b.size())) {
            cout << "-1\n";
            return 0;
        }
    }
    for (int i = 0; i < n; ++i) 
        cout << ans[i] << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int twofive[20][20];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<double>a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
        a[i]=a[i]*1e9;
        //printf("%.10lf ", a[i]);
    }
    vector<int>b;
    for (int i = 0; i < n; i++)
    {
        
            b.push_back(floor(a[i] + 0.1));
            //printf("%.10lf ", a[i]);
        
    }
    //cerr<<4.2%2<<endl;
    //show(b);
    int N=b.size();
    vector<pair<int,int>>c(N);
    int ans=0;
    for (int i = 0; i < N; i++)
    {
        int two=0;
        int five=0;
        int x=b[i];
        //cerr<<x<<" ";
        while(x%2==0){
            x/=2;
            two++;
        }
        while(x%5==0){
            x/=5;
            five++;
        }
        c[i]={min(two,18LL),min(five,18LL)};
        
        int t=c[i].first;
        int f=c[i].second;
        for (int i = 0; i < 19; i++)
        {
            for (int j = 0; j < 19; j++)
            {
                if(t+i>=18 && f+j>=18){
                    ans+=twofive[i][j];
                }
                
            }
            
        }
        twofive[c[i].first][c[i].second]++;
        //cerr<<" "<<two<<" "<<five<<endl;
        
    }
    /*for (int i = 0; i < 9; i++)
    {
        for (int j = 0; j < 9; j++)
        {
            cerr<<twofive[i][j]<<" ";
        }
        cerr<<endl;
    }*/
    
    /*int cnt=0;
    for (int i = 0; i < N; i++)
    {
        int t=c[i].first;
        int f=c[i].second;
        
    }*/
    cout<<ans<<endl;
    
    
    return 0;
}

Measured memory_bytes: 9624
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);	
	string s;
	cin>>s;
	if(s[s.length()-1] == '2' || s[s.length()-1] == '4' || s[s.length()-1] == '5' || s[s.length()-1] == '7' || s[s.length()-1] == '9')
		cout<<"hon";
	if(s[s.length()-1] == '0' || s[s.length()-1] == '1' || s[s.length()-1] == '6' || s[s.length()-1] == '8')
		cout<<"pon";
	if(s[s.length()-1] == '3')
		cout<<"bon";
	
	
	
	
	return 0;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

const ll MAX_V = 100000;

// 行き先toとコストcost
struct edge
{
    ll to;
    ll cost;
};
typedef pair<ll, ll> P; // firstは最短距離、secondは頂点の番号

// int V;
// vector<edge> graph[MAX_V]; // グラフ(隣接リスト)
// int d[MAX_V];              //最短距離

void dijkstra(ll s, vector<vector<edge>> &graph, vector<ll> &d, ll V)
{
    priority_queue<P, vector<P>, greater<P>> pq;
    fill(d.begin(), d.begin() + V, LLINF);
    d[s] = 0;
    pq.push(P(0, s));

    while (!pq.empty())
    {
        P p = pq.top(); // 未確定の中から確定させた頂点
        pq.pop();
        ll v = p.second; // 取り出した頂点の番号
        // もう探索する必要のない経路がpqに残っていた場合は枝刈り
        if (d[v] < p.first)
        {
            continue;
        }

        for (ll i = 0; i < (ll)graph[v].size(); i++)
        {
            edge e = graph[v][i];
            if (d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                pq.push(P(d[e.to], e.to));
            }
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<vector<edge>> graph(n);
    for (ll i = 0; i < n - 1; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        graph[a].push_back(edge{b, c});
        graph[b].push_back(edge{a, c});
    }
    ll q, k;
    vector<ll> d(n);
    cin >> q >> k;
    k--;
    dijkstra(k, graph, d, n);
    for (ll i = 0; i < q; i++)
    {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << d[x] + d[y] << endl;
    }
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
#define N 100010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll unsigned long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)	for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define form(l, r, i)	for(int i = l; i <= r; ++i)
#define forv(r, l, i)	for(int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
 
const ll inf = 1e9 + 7;
const lld EPS = 0.00000001;
const ll modw = 1e9 + 7;
 
using namespace std;

ll dp[110][N];
ll w[N], v[N];

int main()
{
	barnarnar
	ll n, mx;
	cin >> n >> mx;
	forn1(i, n)	cin >> w[i] >> v[i];
	forn(i, N)	dp[0][i] = inf;
	dp[0][0] = 0;
	forn1(i, n)
	{
		forn(j, N)	dp[i][j] = inf;
		//cout << "BRUH " << i << endl;
		forn(j, N)
		{
			dp[i][j] = dp[i - 1][j];
			//if(j <= 100)
			//	cout << dp[i][j] << endl;
			if(j >= v[i])
			{
				dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
				//if(j <= 100)
				//	cout << "CHANGE: " << j << ' ' << v[i] << ' ' << w[i] << ' ' << dp[i][j] << endl;
			}
		}
	}
	ll ans = 0;
	forn(i, N)	if(dp[n][i] <= mx)	ans = i;
	cout << ans;
	return 0;
}
/*
5
11000
11100
01100
00000
00000
*/

Measured memory_bytes: 80640
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
a_sum = Array.new(n, 0)
a_sum[0] = a[0]
1.step(n - 1) do |i|
  a_sum[i] = a_sum[i - 1] + a[i]
end
s = a_sum.pop
puts a_sum.map {|x| (x - (s - x)).abs }.min

Measured memory_bytes: 19716
#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max
#include <string>	//string
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt
#include <sstream>	//stringstream,getline

using namespace std;

int main() {

	int a, b;
	cin >> a >> b;

	cout << a * b << " " << 2 * a + 2 * b << endl;

	return 0;

}


Measured memory_bytes: 3072
s = input()
t = input()

len_s = len(s)
len_t = len(t)

dp = [[0] * 3010 for _ in range(3010)]

for i in range(len_s):
    for j in range(len_t):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])

i = len_s
j = len_t
res = ""
while i > 0 and j > 0:
    if dp[i][j] == dp[i][j-1]:
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else:
        res += s[i-1]
        i -= 1
        j -= 1

print(res[::-1])


Measured memory_bytes: 115164
import java.util.*;
import java.math.*;

public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    // static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    static long[] fact = new long[100];

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int h = sc.nextInt();
        int m = sc.nextInt();
        h *= 30;
        m*=6;
        //System.out.println(h+" "+m);
        //何度
        double rad = h-m;
        rad+=(double)m/12;
        if(rad>180)rad -=360;
        if(rad<0)rad*=-1;
        //System.out.println(rad);
        //System.out.println(Math.acos(rad));
        rad = rad*Math.PI/180;
        
        //rad =Math.PI*80/180;
        //System.out.println(rad);
        //System.out.println(Math.cos(rad));
        double ans = a*a +b*b - 2*a*b*Math.cos(rad);
        //System.out.println(ans);
        System.out.println(Math.sqrt(ans));
    }
}


Measured memory_bytes: 35832
def main():
    N, M, X = map(int, input().split())
    A = list(map(int, input().split()))

    lower_cnt = 0
    upper_cnt = 0

    for a in A:
        if a < X:
            lower_cnt += 1
        elif a > X:
            upper_cnt += 1

    print(min(upper_cnt, lower_cnt))

main()

Measured memory_bytes: 2940
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    bool yymm = true;
    bool mmyy = true;
    string s;
    int l, r;
    cin >> s;
    l = stoi(s.substr(0,2));
    r = stoi(s.substr(2,2));
    if(l < 1 || l > 12) {
        mmyy = false;
    }
    if(r < 1 || r > 12) {
        yymm = false;
    }
    if(yymm) {
        if(mmyy){
            cout << "AMBIGUOUS" << endl;
        }
        else {
            cout << "YYMM" << endl;
        }
    }
    else {
        if(mmyy) {
            cout << "MMYY" << endl;
        }
        else {
            cout << "NA" << endl;
        }
    }
	return 0;
}


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


int main()
{
    int n,c(0),x;
    cin>>n;
    for (int i=1;i<=n;i++) {
        cin>>x;
        if (i%2==1 && x%2==1) c++;
    }
    cout<<c;
}

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

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    string s; cin>>s;
    int n=s.size();
    int ans=1e9;
    for(char cha='a'; cha<='z'; cha++){
        string t=cha+s+cha;
        int maxgap=0, pid=0;
        for(int i=1; i<n+2; i++){
            if(t[i]==cha){
                maxgap=max(maxgap, i-pid-1);
                pid=i;
            }
        }
        ans=min(ans, maxgap);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#ifdef Rahul
# include "RAHUL.h"
#else
# include <bits/stdc++.h>
  using namespace std;
# define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

template<typename T, int K>
struct Basis {
  array<T, K> bas;
  int n, rank;
  Basis() : bas(), n(), rank() {}
  bool add(T x) {
    ++n;
    for (int i = K - 1; i >= 0; --i) {
      if (x >> i & 1) {
        if (bas[i]) {
          x ^= bas[i];
        } else {
          bas[i] = x, ++rank;
          return true;
        }
      }
    }
    return false;
  }
  Basis operator + (Basis o) const {
    for (int i = 0; i < K; ++i) if (bas[i]) o.add(bas[i]);
    return o;
  }
  bool operator == (const Basis &o) const {
    for (int i = 0; i < K; ++i) if (bas[i] != o.bas[i]) return false;
    return true;
  }
};

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int tt; cin >> tt;
  while (tt--) {
    int n; cin >> n;
    Basis<i64, 63> zer;
    vector<i64> a(n);
    for (i64 &x : a) cin >> x;
    string s; cin >> s;
    int ok = 0;
    for (int i = n - 1; !ok && i >= 0; --i) {
      if (s[i] == '1') {
        if (zer.add(a[i])) ok = 1;
      } else {
        zer.add(a[i]);
      }
    }
    cout << ok << '\n';
  }
}


Measured memory_bytes: 3624