akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

template<i64 M>
struct modint {
  i64 a;
  constexpr modint(const i64 x = 0) noexcept: a((x % M + M) % M) {}
  constexpr i64 value() const noexcept { return a; }
  constexpr modint pow(i64 r) const noexcept {
    modint ans(1);
    modint aa = *this;
    while(r) {
      if(r & 1) {
        ans *= aa;
      }
      aa *= aa;
      r >>= 1;
    }
    return ans;
  }
  constexpr modint& operator+=(const modint r) noexcept {
    a += r.a;
    if(a >= M) a -= M;
    return *this;
  }
  constexpr modint& operator=(const i64 r) {
    a = (r % M + M) % M;
    return *this;
  }
  constexpr modint& operator-=(const modint r) noexcept {
    a -= r.a;
    if(a < 0) a += M;
    return *this;
  }
  constexpr modint& operator*=(const modint r) noexcept {
    a = a * r.a % M;
    return *this;
  }
  constexpr modint& operator/=(modint r) noexcept {
    i64 ex = M - 2;
    while(ex) {
      if(ex & 1) {
        *this *= r;
      }
      r *= r;
      ex >>= 1;
    }
    return *this;
  }

  constexpr modint operator+(const modint r) const {
    return modint(*this) += r;
  }
  constexpr modint operator-(const modint r) const {
    return modint(*this) -= r;
  }
  constexpr modint operator*(const modint r) const {
    return modint(*this) *= r;
  }
  constexpr modint operator/(const modint r) const {
    return modint(*this) /= r;
  }
};

using fp = modint<(i64)(1e9 + 7)>;

int main() {
  string L;
  cin >> L;
  i64 N = L.size();
  vector<vector<fp>> dp(N + 1, vector<fp>(2));
  dp[0][0] = fp(1);

  rep(i,0,N) {
    i64 num = L[i] - '0';
    rep(lower, 0, 2) {
      i64 MAX = lower ? 1 : num;
      rep(next, 0, MAX + 1) {
        dp[i + 1][lower || next < num] += dp[i][lower] * (1 << next);
      }
    }
  }
  cout << (dp[N][0] + dp[N][1]).value() << endl;
}


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

int main(){
  string a;
  cin >> a;
  int l=a.size();
  int head,end;
  for(int i=0;i<l;i++){
    if(a.at(i) == 'A') {head = i;
    break;}
  }
  for(int i=l-1;i>=0;i--){
    if(a.at(i) == 'Z'){ end = i;
    break;}
  }
  cout << end-head+1 << endl;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 2e6 + 5;
const ll mod = 1e9 + 7;

ll fac[maxn], ifac[maxn];

ll modpow(ll, ll);
ll inv(ll);
ll nck(ll, ll);
void build();
void testlib();




int r1,r2,c1,c2;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  build();
  testlib();

  cin>>r1>>c1>>r2>>c2;


  ll ans = 0;
  
  for (int i=r1; i<=r2; i++) {
    ans += nck(i+c2+1,i+1);
    ans %= mod; ans += mod; ans %= mod;
    ans -= nck(i+c1,i+1);
    ans %= mod; ans += mod; ans %= mod;
  }

  cout<<ans<<endl;  

  return 0;
}

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


ll modpow(ll x, ll y) {
  x %= mod;
  ll res = 1;
  while (y > 0) {
    if (y%2 == 1) {
      res *= x;
      res %= mod;
    }
    x = x * x;
    x %= mod;
    y = y / 2;
  }
  return res;
}

ll inv(ll x) {
  assert(x != 0);
  return modpow(x, mod-2);
}

void build() {
  fac[0] = ifac[0] = 1;
  for (int i=1; i<maxn; i++) {
    fac[i] = fac[i-1] * i;
    fac[i] %= mod;
    ifac[i] = inv(fac[i]);
    ifac[i] %= mod;
  }
}

ll nck(ll n, ll k) {
  assert(n>=0 && k>=0);
  if (k > n) return 0;
  return (((fac[n] * ifac[k]) % mod) * ifac[n-k]) % mod;
}

void testlib() {
  assert(modpow(1,1) == 1);
  assert(modpow(4,2) == 16);
  assert(modpow(2,5) == 32);
  assert(fac[3] == 6);
  assert(nck(4,2) == 6);
  assert(nck(10,2) == 45);
}


Measured memory_bytes: 31488
#include<cstdio>
long long gcd(long long x, long long y) {
	return x % y == 0 ? y : gcd(y, x%y);
}
void solve() {
	long long A, B, C, D;
	scanf("%lld%lld%lld%lld", &A, &B, &C, &D);
	if( A < B || D < B ) {
		puts("No");
		return ;
	}
	if( C >= B-1 ) {
		puts("Yes");
		return ;
	}
	long long E = (A-C+B-1) / B;
	if( A - E * B < 0 ) {
		puts("No");
		return ;
	}
	long long d = gcd(B, D);
	if( (B - 1) - (C + 1) + 1 >= d ) {
		puts("No");
		return ;
	}
	if( (B - 1) - (C + 1) + 1 != (B - 1)%d - (C + 1)%d + 1 ) {
		puts("No");
		return ;
	}
	puts("Yes");
}
int main() {
	int T;
	scanf("%d", &T);
	for(int i=1;i<=T;i++)
		solve();
}

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

class Program {
    static void Main (string[] args) {
        var input = Console.ReadLine().Split(' ');

        long A = TOL(input[0]);
        double B = TOD(input[1]);
        decimal res = (decimal)A *(decimal)B;

        Console.WriteLine(Math.Floor(res));
    }

    static int TOI (string str) {
        return int.Parse(str);
    }

    static long TOL (string str) {
        return long.Parse(str);
    }

    static float TOF (string str) {
        return float.Parse(str);
    }

    static double TOD (string str) {
        return double.Parse(str);
    }
}

Measured memory_bytes: 27620
<?php
list($n) = ints();
$a[] = ints();
$a[] = ints();
$cusum[0][0] = $cusum[1][0] = 0;
for ($i = 0; $i < $n; $i++) {
    $cusum[0][$i + 1] = $cusum[0][$i] + $a[0][$i];
    $cusum[1][$i + 1] = $cusum[1][$i] + $a[1][$i];
}
$ans = -1;
for ($i = 0; $i < $n; $i++) {
    $ans = max($ans, $cusum[0][$i + 1] + $cusum[1][$n] - $cusum[1][$i]);
}
echo $ans;

function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 4604
from sys import stdin, setrecursionlimit
from math import ceil


def main():
    input = stdin.buffer.readline
    a, b = map(int, input().split())

    set_a = set(range(ceil(a / 0.08), ceil((a + 1) / 0.08)))
    set_b = set(range(ceil(b / 0.1), ceil((b + 1) / 0.1)))

    ans = sorted(list(set_a & set_b))

    if len(ans) == 0:
        print(-1)
    else:
        print(ans[0])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 39892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> ii;


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

  int q=N/2, r=N%2;

  if(N==3){
    cout << 2 << endl;
    cout << 1 << ' ' << 3 << endl;
    cout << 2 << ' ' << 3 << endl;
    return 0;
  }

  if(N==4){
    cout << 4 << endl;
    cout << 1 << ' ' << 2 << endl;
    cout << 1 << ' ' << 3 << endl;
    cout << 4 << ' ' << 2 << endl;
    cout << 4 << ' ' << 3 << endl;
    return 0;
  }

  if(r==1){
    cout << 4*q << endl;
    for (int i=0;i<q-1;++i){
      cout << i+1 << ' ' << i+2 << endl;
      cout << 2*q-i << ' ' << 2*q-i-1 << endl;
      cout << i+1 << ' ' << 2*q-i-1 << endl;
      cout << 2*q-i << ' ' << i+2 << endl;
    }

    cout << 2*q+1 << ' ' << 2*q << endl;
    cout << 2*q+1 << ' ' << 1 << endl;
    cout << 2*q+1 << ' ' << q << endl;
    cout << 2*q+1 << ' ' << q+1 << endl;
    return 0;
  }

  if(r==0){
    cout << 4*q << endl;
    for (int i=0;i<q-1;++i){
      cout << i+1 << ' ' << i+2 << endl;
      cout << 2*q-i << ' ' << 2*q-i-1 << endl;
      cout << i+1 << ' ' << 2*q-i-1 << endl;
      cout << 2*q-i << ' ' << i+2 << endl;
    }

    cout << q << ' ' << 1 << endl;
    cout << q << ' ' << 2*q << endl;
    cout << q+1 << ' ' << 1 << endl;
    cout << q+1 << ' ' << 2*q << endl;
    return 0;
  }
}

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

using namespace std;

template<int mod> class modint {
public:
  int x;
  modint(): x(0) {}
  modint(int a) { x = a % mod; if (x < 0) x += mod; }
  modint &operator+=(modint that) { x = (x + that.x) % mod; return *this; }
  modint &operator-=(modint that) { x = (x + mod - that.x) % mod; return *this; }
  modint &operator*=(modint that) { x = (long long) x * that.x % mod; return *this; }
  modint &operator/=(modint that) { return *this *= that.inverse(); }
  modint operator-() { return modint(-this->x); }
  friend ostream& operator<<(ostream &out, modint m) { return out << m.x; }
  modint inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return modint(u);
  }
#define op(o, p) modint operator o(modint that) { return modint(*this) p that; }
  op(+, +=) op(-, -=) op(*, *=) op(/, /=)
#undef op
#define op(o) bool operator o(modint that) { return x o that.x; }
  op(==) op(!=) op(<) op(<=) op(>) op(>=)
#undef op
};

typedef modint<1000000007> mint;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  vector<mint> f(h + w + 1, 1);
  for (int i = 1; i <= h + w; i++) {
    f[i] = f[i - 1] * i;
  }
  mint ans = 0;
  for (int d = 0; d < w - b; d++) {
    int y1 = h - a - 1;
    int x1 = b + d;
    int y2 = a - 1;
    int x2 = w - (b + d) - 1;
    ans += (f[x1 + y1] / (f[x1] * f[y1])) * (f[x2 + y2] / (f[x2] * f[y2]));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

static class Program
{
    static long Solve(long N)
    {
        if (N % 2 == 0)
        {
            N /= 2;
            long sum = 0;
            while (N > 0)
            {
                N /= 5;
                sum += N;
            }
            return sum;
        }
        else
        {
            return 0;
        }
    }

    static void Main(string[] args)
    {
        long N = long.Parse(Console.ReadLine());
        Console.WriteLine(Solve(N));
    }
}


Measured memory_bytes: 13140
/**
 * @author derrick20
 */
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = sc.nextInt();
        int W = sc.nextInt();
        long[] weight = new long[N];
        int[] value = new int[N];
        int totalVal = 0;
        for (int i = 0; i < N; i++) {
            weight[i] = sc.nextInt();
            value[i] = sc.nextInt();
            totalVal += value[i];
        }

        long[] dp = new long[totalVal + 1];
        Arrays.fill(dp, (long) 1e18);
        dp[0] = 0;
        // What's the best value achievable with weight W?
        // AH, dimension flip. Now we want minimum weight for some value
        for (int item = 0; item < N; item++) {
            int val = value[item];
            long wt = weight[item];
            for (int oldVal = totalVal - val; oldVal >= 0; oldVal--) {
                dp[oldVal + val] = Math.min(dp[oldVal + val], dp[oldVal] + wt);
            }
        }
        long best = 0;
        for (int val = totalVal; val >= 0; val--) {
            if (dp[val] <= W) {
                best = val;
                break;
            }
        }
        out.println(best);
        out.close();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        FastScanner(FileReader s) {
            br = new BufferedReader(s);
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        String nextLine() throws IOException { return br.readLine(); }

        double nextDouble() throws IOException { return Double.parseDouble(next()); }

        int nextInt() throws IOException { return Integer.parseInt(next()); }

        long nextLong() throws IOException { return Long.parseLong(next()); }
    }
}

Measured memory_bytes: 23764
#include<iostream>
using namespace std;
int h,w,field[20][20];
int search(int x,int y,int cnt){
  if(cnt>10) return -1;
  int tx=x,ty=y,ans[4],min_a=100000;
  ans[0]=ans[1]=ans[2]=ans[3]=-1;
  while(tx>=0&&field[tx][y]==0){
    tx--;
  }
  if(tx>=0&&field[tx][y]==3) return cnt;
  if(tx>=0&&field[tx][y]==1&&x!=0&&field[x-1][y]!=1){
    field[tx][y]=0;
    ans[0]=search(tx+1,y,cnt+1);
    field[tx][y]=1;
  }
  tx=x;
  while(tx<h&&field[tx][y]==0){
    tx++;
  }
  if(tx<h&&field[tx][y]==3) return cnt;
  if(tx<h&&field[tx][y]==1&&x!=h-1&&field[x+1][y]!=1){
    field[tx][y]=0;
    ans[1]=search(tx-1,y,cnt+1);
    field[tx][y]=1;
  }

  while(ty>=0&&field[x][ty]==0){
    ty--;
  }
  if(ty>=0&&field[x][ty]==3) return cnt;
  if(ty>=0&&field[x][ty]==1&&y!=0&&field[x][y-1]!=1){
    field[x][ty]=0;
    ans[2]=search(x,ty+1,cnt+1);
    field[x][ty]=1;
  }

  ty=y;
  while(ty<w&&field[x][ty]==0){
    ty++;
  }
  if(ty<w&&field[x][ty]==3) return cnt;
  if(ty<w&&field[x][ty]==1&&y!=w-1&&field[x][y+1]!=1){
    field[x][ty]=0;
    ans[3]=search(x,ty-1,cnt+1);
    field[x][ty]=1;
  }
  if(ans[0]==-1&&ans[1]==-1&&ans[2]==-1&&ans[3]==-1) return -1;
  for(int i=0;i<4;i++){
    if(ans[i]!=-1) min_a=(min_a<ans[i])?min_a:ans[i];
  }
  return min_a;
}
int main(){
  int x,y,ans;
  cin >> h >> w;
  while(w!=0){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> field[i][j];
        if(field[i][j]==2){
          x=i,y=j;
          field[i][j]=0;
        }
      }
    }
    ans = search(x,y,1);
    cout << ans << endl;
    cin >> w >> h;
  }
}



Measured memory_bytes: 3096
"""
author : halo2halo
date : 16, Jan, 2020
"""

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

YMD = readline().decode('utf8').rstrip().split('/')
# print(YMD)
MD=int(''.join(YMD[1:]))
print('Heisei' if MD <=430 else 'TBD')


Measured memory_bytes: 12228
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
typedef struct pp
{   char x[50];
    int t,R;
}S;
S s[105];
bool cmp(int a,int b)
{   return a>b;
}
int main()
{   long long int i,j,T,n,m,k,s=0,q;
    priority_queue<long long int>x;
    scanf("%lld%lld",&n,&m);
    for(i=0;i<n;i++)
    {   scanf("%lld",&k);
        x.push(k);
    }
    for(i=0;i<m;i++)
    {   T=x.top();
        x.pop();
        x.push(T/2);
    }
    for(i=0;i<n;i++)
    {   s+=x.top();
        x.pop();
    }
    printf("%lld",s);
    return 0;
}



Measured memory_bytes: 1400
def main():
    n = int(input())
    a=[int(i) for i in input().split()]
    a.sort(reverse = True)

    #隙間には2個入る
    res = a[0]
    tmp = a[1]
    k = 1
    cnt = 0
    for i in range(2,n):
        res += tmp
        cnt+=1
        if(cnt == 2):
            k+=1
            tmp = a[k]
            cnt = 0
    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 94180
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define pb         push_back

typedef long long ll;
class state{
public:
  int time,num;
  int cap;
  string name;
  bool operator<(const state&  a)const{
    if (time != a.time)return time >a.time;
    return num < a.num;
  }
};

vector<ll> solve(vector<state> &dish,
		 vector<int> &come,vector<vector<int> >&ord){
  ll now = 0;
  int p=0;
  vector<ll> ret(come.size(),(1LL)<<50);
  while(p < come.size()){
    if (come[p] > now)now=come[p];

    int cap=-1,num=-1;
    rep(i,dish.size()){
      if(ord[p][i] != 0){
	num=i;
	cap=dish[i].cap;
	break;
      }
    }

    REP(i,p,ord.size() && cap){
      if (now < come[i])break;
      if (cap >= ord[i][num]){
	cap-=ord[i][num];
	ord[i][num]=0;
      }else if (cap < ord[i][num]){
	ord[i][num]-=cap;
	cap=0;
      }
    }

    now=now+dish[num].time;
    rep(i,ord.size()){
      bool isok=true;
      rep(j,ord[i].size())if (ord[i][j]!=0)isok=false;
      if (isok)ret[i]=min(ret[i],now);
      if (p == i && isok)p++;
    }
  }
  return ret;
}

int getindex(string a,map<string,int> &M){
  int index = M.size();
  if (M.count(a)==0)M[a]=index;
  return M[a];
}

main(){
  int n,m;
  int te=0;
  while(cin>>n>>m && n){
    if( te++)cout << endl;
    vector<state> in(n);
    vector<int> come(m);
    vector<vector<int> > ord(m);
    map<string,int> M;
    
    rep(i,n){
      cin>>in[i].name>>in[i].cap>>in[i].time;
      in[i].num=i;
    }


    sort(in.begin(),in.end());
    rep(i,n)getindex(in[i].name,M);

    rep(i,m){
      cin>>come[i];
      rep(j,n)ord[i].pb(0);
      int k;
      cin>>k;
      rep(j,k){
	string tmp;cin>>tmp;ord[i][getindex(tmp,M)]++;
      }
    }

    vector<ll> ans=solve(in,come,ord);
    rep(i,ans.size())cout << ans[i]<<endl;
  }
  return false;
}

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

int main(){
    int a,b,c;
    int p;
    cin >> a >> b >> c;
    if(a>b){//5,2,6
        p = a;
        a = b;
        b = p;
    }
    if(b>c){
        p = b;
        b = c;
        c = p;
    }
    if(a>b){
        p = a;
        a = b;
        b = p;
    }
    
    cout << a << " "<< b << " " << c << endl;
    
    return 0;
}



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

int main(){
    int H, W;
    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if(i == 0 || i == H - 1 || j == 0 || j == W - 1) cout << "#";
                else cout << '.';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll ans=0,sum=0;
    vector<ll> dp(n);
    rep(i,n){
        if (i==0||i==1) dp[i]=1;
        else dp[i]=(sum+MOD-dp[i-2])%MOD;
        sum=(sum+dp[i])%MOD;
        if (i<n-2) ans=(ans+dp[i]*(((n-1)*(n-1)%MOD+i+2)%MOD)%MOD)%MOD;
        else if (i==n-2) ans=(ans+dp[i]*(n-1)%MOD*n%MOD)%MOD;
        else ans=(ans+dp[i]*n%MOD)%MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
string s[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main(){
	string a;
	cin>>a;
	REP(i,7){
		if(a==s[i]){
			cout<<7-i<<endl;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int m[10];
  int i,j,tmp;
  for(i=0;i<10;i++)
    scanf("%d", &m[i]);
  for(i=0;i<3;i++){
    for(j=i+1;j<10;j++){
      if(m[i]<m[j]){
        tmp = m[i];
        m[i]= m[j];
        m[j]= tmp;
      }
    }
  }
  for(i=0;i<3;i++)
    printf("%d\n", m[i]);
  return 0;
}

Measured memory_bytes: 600
{
  const run = (input: string) => {
    let splitted = input.trim().split("\n")
    const n = parseInt(splitted[0])

    const first = splitted[1].trim().split(" ").map(v => parseInt(v))
    const second = splitted[2].trim().split(" ").map(v => parseInt(v))

    let firstSum = first.reduce((a: number, x: number) => a + x) + second[n - 1]
    let secondSum = second.reduce((a: number, x: number) => a + x)

    let sum = 0
    let tmpSum = 0
    let tmpFirstSum = 0
    for (let i = 0; i < n; i++) {
      tmpSum = firstSum > secondSum ? tmpFirstSum + firstSum : tmpFirstSum + secondSum;
      if (sum < tmpSum) sum = tmpSum

      tmpFirstSum += first[i]
      firstSum -= first[i]
      if (second[i - 1] != null) secondSum -= second[i - 1]
    }

    return sum
  }

  const Main = (input: string) => {
    console.log(run(input))
  };

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


Measured memory_bytes: 29904
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long lli;
typedef pair<int, int> pii;
const int INF = 1e9;
const int lim = 51;
int n;
vector<int> a, b;

vector< vector<int> > dp, val;

void ReadInput()
{
    cin >> n;
    a.resize(n);
    b.resize(n);
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    for(int i = 0; i < n; ++i)
        cin >> b[i];
}

void Init()
{
    val.resize(n, vector<int>(n));
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            val[i][j] = (i % 2 == j % 2) ? a[j] : b[j];
}

inline int bit(int k, int x)
{
    return (x >> k & 1);
}

inline void minmim(int&tar, int val)
{
    if(tar > val) tar = val;
}

void Solve()
{
    dp.resize((1 << n), vector<int>(lim + 5, INF));
    dp[0][0] = 0;
    for(int mask = 0; mask < (1 << n); ++mask)
    {
        int pos = __builtin_popcount(mask);
        for(int lst = 0; lst < lim; ++lst)
        {
            int cost = 0;
            for(int i = 0; i < n; ++i)
            {
                if(bit(i, mask)) continue;
                if(val[pos][i] >= lst)
                    minmim(dp[mask | (1 << i)][val[pos][i]], dp[mask][lst] + cost);
                ++cost;
            }
        }
    }
    int ans = INF;
    for(int lst = 1; lst < lim; ++lst)
        minmim(ans, dp[(1 << n) - 1][lst]);
    if(ans == INF) ans = -1;
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Init();
    Solve();
}


Measured memory_bytes: 69888
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<memory.h>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
int c[N];
int vis[N], id;
int d[2][N];
vector<vector<int> > v;
void dfs(int u, int cost) {
	d[id][u] = cost;
	vis[u] = id;
	for (int i = 0; i < v[u].size(); ++i) {
		int next = v[u][i];
		if (vis[next] < id)
			dfs(next, cost + 1);
	}
}
int main() {
	memset(vis, -1, sizeof vis);
	int n;
	cin >> n;
	v.resize(n);
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(0, 0); ++id; dfs(n - 1, 0);
	int a = 0;
	int b = 0;
	int path = d[0][n - 1];
	for (int i = 1; i < n - 1; ++i) {
		int cost1 = d[0][i];//from 0   to i
		int cost2 = d[1][i];//from n-1 to i
		if (cost1 < cost2)
			++a;
		else if (cost1 > cost2)
			++b;
		else {
			if (path % 2 == 0)
				++a;
			else
				++b;
		}
	}
	if (a > b)
		cout << "Fennec";
	else
		cout << "Snuke";
	cout << endl;
}

Measured memory_bytes: 9984
import sys, collections
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

class Node():
    key = None
    p = None
    left = None
    right = None

    def __init__(self, key):
        self.key = key

class BinarySearchTree():
    root = None

    def insert(self, z):
        y = None
        x = self.root
        while x is not None:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        
        z.p = y

        if y is None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

    def print_nodes(self):
        inorder = []
        preorder = []

        def dfs(v):
            v_key = v.key
            preorder.append(v_key)
            if v.left is not None:
                dfs(v.left)
            inorder.append(v_key)
            if v.right is not None:
                dfs(v.right)

        dfs(self.root)

        print('', *inorder)
        print('', *preorder)

def resolve():
    n = I()
    T = BinarySearchTree()
    for _ in range(n):
        q = LSS()
        if q[0]=='insert':
            z = Node(int(q[1]))
            T.insert(z)
        else:
            T.print_nodes()

if __name__ == '__main__':
    resolve()



Measured memory_bytes: 184284
$n,A,B,C =gets.split.map(&:to_i)
$ls = $n.times.map{ gets.to_i }
$inf = 10 ** 9

def dfs(cur, a, b, c)
  if cur == $n
    #puts "#{cur}, #{a}, #{b}, #{c}"
    return $inf if [a,b,c].min == 0
    return (a-A).abs + (b-B).abs + (c-C).abs - 30
  end
  ret0 = dfs(cur + 1, a, b, c)
  ret1 = dfs(cur + 1, a + $ls[cur], b, c) + 10
  ret2 = dfs(cur + 1, a, b+$ls[cur], c) + 10
  ret3 = dfs(cur + 1, a, b, c + $ls[cur]) + 10
  #p [ret0, ret1, ret2, ret3]
  [ret0, ret1, ret2, ret3].min
end
puts dfs(0,0,0,0)

Measured memory_bytes: 3836
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| min!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| max!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn lower_bound(xs: &Vec<usize>, x: usize) -> Option<usize> {
    let n = xs.len();
    if n == 0 || xs[n - 1] >= x {
        None
    } else {
        // returns Some(i) s.t. xs[i] > x >= xs[i+1]
        let mut left = 0;
        let mut right = n;
        for _ in 0..2000 {
            let mid = (left + right) / 2;
            if xs[mid] >= x {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        Some(left)
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut bots = vec![];
    for _ in 0..n {
        let x: usize = sc.cin();
        // trace!(&bots, x, lower_bound(&bots, x));
        match lower_bound(&bots, x) {
            None => { bots.push(x); }
            Some(i) => { bots[i] = x; }
        }
    }
    put!(bots.len());
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t H,W,N;

int main()
{
    using std::endl;
    in.sync_with_stdio(false);
    out.sync_with_stdio(false);
    in.tie(nullptr);
    out.tie(nullptr);

    in >> H>>W>>N;
    int32_t max = std::max(H, W);
    out << (N + max - 1) / max << endl;

    return 0;
}
#endif


Measured memory_bytes: 888
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
	int i;
	long long n,m;
	double t;
    while(~scanf("%lld",&n)){
    t=sqrt(n);
	for(i=1;i<=t;i++){
		m=i*i;
		}
		printf("%lld\n",m);
	}
}


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

#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end());
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, M;
int D[220000], T[220000];
map<int, int> plan, problem;
signed main() {
    cin >> N;
    rep(i, N) { cin >> D[i], plan[D[i]]++; }
    cin >> M;
    rep(i, M) { cin >> T[i], problem[T[i]]++; }
    for (auto p:problem) {
        if (plan[p.first] < p.second) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 28416
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
#include <tuple>
#include <map>
 
using namespace std;

typedef long long ll;

long long gcd(long long a, long long b) {

   	if(a < b) {
       swap(a, b);
   	}

	long long r = a % b;
	while(r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

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

    ll A, B;

    cin >> A >> B;

    ll x = gcd(A, B);

    ll c = 1;

    for(ll i = 2; i * i < x; i++) {
        if(x % i == 0) {
            c++;
            x /= i;
            while(x % i == 0) {
                x /= i;
            }
        }
    }

    if(x != 1) c++;

    cout << c << endl;
}


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

static const int MAX = 1000003;
static const int STRLEN = 13;
static const int CMDLEN = 7;
static const int KEYLEN = 14;

char H[MAX][KEYLEN];

int h1(int key) {
    return key % MAX;
}

int h2(int key) {
    return 1 + (key % (MAX - 1));
}

int getChar(char c) {
    if (c == 'A') return 1;
    else if (c == 'C') return 2;
    else if (c == 'G') return 3;
    else if (c == 'T') return 4;
    else return 0;
}

long long getKey(char str[]) {
    long long sum = 0, p = 1;
    for (int i = 0; i < strlen(str); i++) {
        sum += p * (getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int find(char str[]) {
    long long key, i = 0, h;
    key = getKey(str);
    while (1) {
        h = (h1(key) + i * h2(key)) % MAX;
        if (strcmp(H[h], str) == 0) {
            return 1;
        } else if (strlen(H[h]) == 0) {
            return 0;
        }
        i++;
    }
    return 0;
}

int insert(char str[]) {

    long long key, i = 0, h;
    key = getKey(str);
    while (1) {
        h = (h1(key) + i * h2(key)) % MAX;
        if (strcmp(H[h], str) == 0) {
            return 1;
        } else if (strlen(H[h]) == 0) {
            strcpy(H[h], str);
            return 0;
        }
        i++;
    }

    return 0;
}



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

    // initialize
    for (int i = 0; i < MAX; i++) {
        H[i][0] = '\0';
    }

    char str[STRLEN], cmd[CMDLEN];
    for (int i = 0; i < n; i++) {
        cin >> cmd >> str;

        if (cmd[0] == 'i') {
            insert(str);
        } else if (cmd[0] == 'f') {
            if (find(str)) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 16756
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
 
typedef long long ll;
#define INF 1e9


int main(){
  int N;
  cin >> N;
  vector<int> X(N), B(N);
  REP(i, N){
    cin >> X[i];
    B[i] = X[i];
  }
  sort(X.begin(), X.end());
  int media = N / 2 -1;
  int medib = N / 2;
  REP(i, N){
    if(B[i] > X[media]){
      cout << X[media] << endl;
    }
    else{
      cout << X[medib] << endl;
    }
  }


  return 0;
}

Measured memory_bytes: 3712
import sys

for _ in xrange(input()):
    A = map(int, raw_input().split())
    x, y = 0, 0
    for a in A:
        if a > x and a > y:
            if x >= y:
                x = a
            else:
                y = a
        elif a > x:
            x = a
        elif a > y:
            y = a
        else:
            print 'NO'
            break
    else:
        print 'YES'

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

int main(){
    using namespace std;
    string S;
    cin >> S;
    unsigned long ans{0}, prev{0};
    for(unsigned long i{0}; i < 3; ++i){
        if(S[i] == 'S')prev = 0;
        else prev++;
        ans = max(ans, prev);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (a % 2 == 0) {

				if (a % 3 != 0 && a % 5 != 0) {
				System.out.println("DENIED");
				sc.close();
				return;

			}
			}

		}
		System.out.println("APPROVED");
		sc.close();

	}

}


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

// abac
// [a] => 0,2
// [b] => 1
// [c] => 3
vector<vector<int>> D(26);
string s;
string t;

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

  cin >> s >> t;

  int ss = s.size();
  rep(i, ss) {
    D[s[i]-'a'].push_back(i);
  }

  if(D[t[0]-'a'].size() == 0) {
    cout << -1 << endl;
    return 0;
  }

  int times = 1;
  int cp = D[t[0]-'a'][0];

  int ts = t.size() - 1;
  rep1(i, ts) {
    int c = t[i]-'a';
    if(D[c].size() == 0) {
      cout << -1 << endl;
      return 0;
    }

    auto np = upper_bound(D[c].begin(), D[c].end(), cp);
    if(*np <= cp || np == D[c].end()) {
      times++;
      cp = D[c][0];
    } else {
      cp = *np;
    }
  }

  cout << (times - 1) * s.size() + (cp + 1) << endl;
}


Measured memory_bytes: 1228
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 2e5+17;
int main(int argc ,char const *argv[])
{
	#ifdef noob
	freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
	#endif
	int n;
	cin>>n;
	vector<int > a(n),b(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		cin>>b[i];
	}
	vector<int > c,d;
	int ans = 0;
	for (int i = 0; i <= 28; ++i)
	{
		c = a;
		d = b;
		int m = 1;
		for (int k = 0; k < i ; ++k) m*=2;
		for (int j = 0; j < n; ++j)
		{
			c[j]%=(2*m);
			d[j]%=(2*m);
		}
		sort(c.begin(), c.end());
		sort(d.begin(), d.end());
		int l,r,sum=0;
		for (int j = 0; j < n; ++j)
		{
			l = lower_bound(d.begin(), d.end(), m-c[j])-d.begin();
			r = lower_bound(d.begin(), d.end(), 2*m-c[j])-d.begin()-1;
			sum += (r-l+1);
			l = lower_bound(d.begin(), d.end(), 3*m-c[j])-d.begin();
			r = lower_bound(d.begin(), d.end(), 4*m-c[j])-d.begin()-1;
			sum += (r-l+1);
		}
		// debug(sum);
		if(sum&1) ans += m;
	}
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3328
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,n,a[200001],z[200001],x,wk,flg,sa;
	long long k,k2,j;
	scanf("%d %lld",&n,&k);
	for(i=1;i<=n;i++)	scanf("%d",&a[i]);
	for(i=1;i<=n;i++)	z[i]=-1;
	x=1;
	z[1]=0;
	flg=0;
	for(j=1;j<=k;j++)	{
		x=a[x];
		if(z[x]!=-1)	{
			flg=1;
			break;
		}
		else z[x]=j;
	}
	if(flg==1)	{
		sa=j-z[x];
		k2=k-z[x];
//		printf("sa=%d k2=%lld\n",sa,k2);
		k2=k2%sa;
		for(j=1;j<=k2;j++)	{
			x=a[x];
		}
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 3292
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

R = INT()
print(2*pi*R)


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

int N;
int A[2][101];
int main(){
    cin >> N;
    A[0][0] =  A[1][0] = 0;
    for(int i = 0; i < N; ++i){
        cin >> A[0][i+1];
    }
    for(int i = 0; i < N; ++i){
        cin >> A[1][i+1];
    }
    for(int i = 1; i <= N; ++i){
        A[0][i] += A[0][i-1];
        A[1][i] += A[1][i-1];
    }
    int ret = 0;
    for(int i = 0; i < N; ++i){
        int tmp = A[0][i+1] + A[1][N] - A[1][i];
        ret = max(ret, tmp);
    }

    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <random>
#include <numeric>

using namespace std;

#define INT_MAX_VALUE 2147483647
#define LONG_LONG_MAX_VALUE 9223372036854775807
#define ll long long
#define ld long double

struct XX{
    string s;
    int p;
    int i;
};

class xxGreater {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第2条件
        if((riLeft.s) == (riRight.s)){
            return riLeft.p > riRight.p;//<:昇順(小さいものから順番)、>:降順(大きいものから順番)
            //プライオリティキューの場合は > で、top()すると値の小さいものがとれる
        }
        //第1条件
        return (riLeft.s) < (riRight.s);
    }
};


//map<long long,long long> prime_f(long long n){
//    map<long long,long long>res;
//    for(int i=2;i*i<=n;i++){
//        while(n%i==0){
//            ++res[i];
//            n/=i;
//        }
//    }
//    if(n!=1)res[n]=1;
//    return res;
//}

//int n;
////int dat[2*10000000];
////int dat2[2*10000000];
//int dat[10];
//int dat2[10];
//
//void init(int n_){
//    n=1;
//    while(n<n_)n*=2;
//    for(int i=0;i<2*n-1;i++){
//        dat[i]=0;
//        dat2[i]=0;
//    }
//}
//
//void initset(int k,int a){
//    k+=n-1;
//    dat[k]=a;
//    while(k>0){
//        k=(k-1)/2;
//        dat[k]=dat[k*2+1]+dat[k*2+2];
//    }
//}
//
////[a,b)の間を[l,r]区間で比較しアップデート
////引数のindexに注意
////nは固定。initで計算すみ
////update2(L[i],R[i]+1,0,0,n,D[i]);
//void update2(int a,int b,int k,int l,int r,int v){//v更新値、区間は0-index
//    if(r<=a || b<=l)return;
//    if(a<=l && r<=b){
//        dat[k]+=dat2[k];
//        if(r-l>1){
//            dat2[k*2+1]+=dat2[k]/2;
//            dat2[k*2+1]+=dat2[k]/2;
//        }
//        dat2[k]=v*(r-l);
//        return;
//    }else{
//        update2(a,b,k*2+1,l,(l+r)/2,v);
//        update2(a,b,k*2+2,(l+r)/2,r,v);
//        return;
//    }
//}
//
//int query(int a,int b,int k,int l,int r){
//    if(r<=a || b<=l)return 0;
//    if(a<=l && r<=b){
//        dat[k]+=dat2[k];
//        if(r-l>1){
//            dat2[k*2+1]+=dat2[k]/2;
//            dat2[k*2+1]+=dat2[k]/2;
//        }
//        dat2[k]=0;
//        return dat[k];
//    }
//    else{
//        int vl=query(a,b,k*2+1,l,(l+r)/2);
//        int vr=query(a,b,k*2+2,(l+r)/2,r);
//        return vl+vr;
//    }
//}




int main(int argc, const char * argv[])
{
    //scanf("%s",S);
    //scanf("%d",&N);
    //scanf("%lld %lld",&target1,&target2);
    //sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]);
    //getline(cin, target);
    //ifstream ifs("3.txt");//テスト用
    //ifs >> a;
    //ここから
    
    //入力高速化
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N;
    cin>>N;
    XX a[100];
    for(int i=0;i<N;i++){
        cin>> a[i].s>>a[i].p;
        a[i].i=i;
    }
    sort(a,a+N,xxGreater());
    for(int i=0;i<N;i++){
        cout << a[i].i+1<<endl;
    }

    
    //ここまで
    //cout << "ans" << endl;
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
cs = Array.new(100, 0)
(1..N).each{ |x|
  i = x.to_s[0].to_i * 10 + x.to_s[-1].to_i
  cs[i] += 1
}
n = 0
(1..N).each{ |x|
  i = x.to_s[0].to_i + x.to_s[-1].to_i * 10
  n += cs[i]
}
p n


Measured memory_bytes: 1788
import numpy as np
import pprint

#入力を受け付ける
X,Y,Z,K = list(map(int, input().split()))
A_list =[int(i) for i in input().split()]
B_list =[int(i) for i in input().split()]
C_list =[int(i) for i in input().split()]

#並び替え
A_list.sort(reverse=True)
B_list.sort(reverse=True)
C_list.sort(reverse=True)

#処理準備
calclated_flag = np.zeros((X,Y,Z), dtype=np.bool) #計算済みか
#calclated_result = np.zeros((X,Y,Z), dtype=np.int64) #計算結果 　…stockを使うので不要
ans = [] #解答

#木の頭
x=0
y=0
z=0
stock=[[x,y,z,A_list[x] + B_list[y] + C_list[z]]]
calclated_flag[x,y,z]=True

#ここから解答が条件の手前になるまでループ
for i in range(K):
  #stockの中から最大を調べる
  stock.sort(key=lambda x: x[3]) #ソート
  ans.append(stock[len(stock)-1][3]) #最小は一番最後。ansに追加

  temp = stock.pop() #stockから削除。
  x=temp[0]
  y=temp[1]
  z=temp[2]

  #子に分岐 ここで範囲外にならないよう判断が必要
  if x+1 <= X-1:
    if calclated_flag[x+1,y,z]!=True:
      stock.append([x+1,y,z,A_list[x+1] + B_list[y] + C_list[z]])
      calclated_flag[x+1,y,z]=True
      
  if y+1 <= Y-1:
    if calclated_flag[x,y+1,z]!=True: 
      stock.append([x,y+1,z,A_list[x] + B_list[y+1] + C_list[z]])
      calclated_flag[x,y+1,z]=True
      
  if z+1 <= Z-1:
    if calclated_flag[x,y,z+1]!=True:
      stock.append([x,y,z+1,A_list[x] + B_list[y] + C_list[z+1]])
      calclated_flag[x,y,z+1]=True
  
#回答を出力
for i in range(K):
  print(ans[i])

Measured memory_bytes: 988144
#include<bits/stdc++.h>
using namespace std;
#define N 705
#define ll long long
#define debug(a) cout<<#a<<": ";for(auto i:a)cout<<i<<" ";cout<<endl;
#define trace(a) cout<<#a<<": "<<a<< endl;
#define int ll
bool mark[N][N];
vector<int> adj[N];
bool vis[N];
vector<int> v[2];
int col[N];
void dfs(int node,int flag) {
	v[flag].push_back(node);
	vis[node] = true;
	col[node] = flag;
	for(int it : adj[node]) {
		if(!vis[it]) {
			dfs(it,flag^1);
		}
	}
}
vector< pair<int,int> > poss;
ll tot;
ll dp[N][N];
int rec(int id,ll a) {
	if(id == poss.size()) {
		ll b = tot-a;
		return (a*(a-1))/2 + (b*(b-1))/2;
	}
	if(dp[id][a] != -1) return dp[id][a];
	return dp[id][a] = min(rec(id+1,a+poss[id].first),rec(id+1,a+poss[id].second));
}
signed main() {
	ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
	int i,j,k,l,m,n,t;
	cin >> n >> m;
	for(i = 1;i <= m;i++) {
		int u,v;
		cin >> u >> v;
		mark[u][v] = mark[v][u] = true;
	}
	for(i = 1;i <= n;i++) {
		for(j = i+1;j <= n;j++) {
			int u = i,v = j;
			if(!mark[u][v]) {
				adj[u].push_back(v);
				adj[v].push_back(u);
			}
		}
	}

	tot = n;
	for(i = 1;i <= n;i++) {
		if(!vis[i]) {
			// trace(i);
			dfs(i,0);
			poss.push_back({(int)v[0].size(),(int)(v[1].size())});
			for(int node : v[0]) {
				for(int it : adj[node]) {
					if(col[it] == col[node]) {
						cout << "-1" << endl;
						return 0;
					}
				}
			}
			for(int node : v[1]) {
				for(int it : adj[node]) {
					if(col[it] == col[node]) {
						cout << "-1" << endl;
						return 0;
					}
				}
			}
			v[0].clear();
			v[1].clear();
		}
	}
	memset(dp,-1,sizeof(dp));
	cout << rec(0,0) << endl;
}

Measured memory_bytes: 8064
nmc = list(map(int, input().split()))
b = list(map(int, input().split()))
a_st = [input().split() for i in range(nmc[0])]
a = [[int(item) for item in row] for row in a_st]
count = 0

for i in a:
    s = 0
    for index, value in enumerate(i):
        s += value * b[index]
    if s + nmc[2] > 0:
        count += 1
print(count)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
int k,s,count=0;
cin>>k>>s;
if(3*k==s){
  cout<<1<<endl;
}
else{
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
    if(x+y+k>=s&&s-x-y>=0){
     // cout<<x<<" "<<y<<" "<<s-x-y<<endl;
      count++;
    }
  }
}
cout<<count<<endl;
}
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner scanner = new Scanner(System.in);
    int a = scanner.nextInt();
    String s = scanner.next();
    scanner.close();

    if (a >= 3200) {
      System.out.println(s);
    } else {
      System.out.println("red");
    }
  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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; }

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

int main(){
  int n; ll m; cin >> n >> m;
  vl a(n); rep(i,n) cin >> a[i];
  vl s(n+1); rep(i,n) s[i+1] = s[i] + a[i];

  map<ll,int> C;
  rep(i,n+1) {
    s[i] %= m;
    C[s[i]]++;
  }

  ll ans = 0LL;
  for(auto c : C) {
    ll num = c.second;
    ans += num*(num-1LL)/2LL;
  }

  cout << ans << endl;
  
}


Measured memory_bytes: 5760