akhauriyash/Code-Regression huggingface dataset:
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#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(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<int> d(n);
		REP(i,n) cin >> d[i];
		int m;
		cin >> m;
		vector<int> t(m);
		REP(i,m) cin >> t[i];
		multiset<int> s(ALL(d));
		bool f = true;
		REP(i,m){
			auto ite = s.find(t[i]);
			if(ite == s.end()) {
				f = false;
				break;
			} else {
				s.erase(ite);
			}
		}
		if(f){
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 11264
N = $stdin.gets.chomp.to_i
A = $stdin.gets.chomp.split(" ").map{ |a| a.to_i }

s = 0
x = 0
$ps = [] # ps[i] = A_0 + ... + A_i
$px = [] # px[i] = A_0 ^ ... ^ A_i
A.each{ |a| 
  s += a
  x ^= a
  $ps << s
  $px << x
}

#p $ps
#p $px

def X(l,r)
  $px[r] ^ (l > 0 ? $px[l-1] : 0)
end

def S(l,r)
  $ps[r] - (l > 0 ? $ps[l-1] : 0)
end

#p S(1,N-1)
#p X(1,N-1)

ct = 0
r = 0
(0...N).each { |l|
  while true
    break if r == N-1
    break if X(l,r+1) != S(l, r+1)
    r += 1
  end
  ct += r-l+1
}
puts ct


Measured memory_bytes: 19992
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys


n = int(input())
red = [[0 for j in range(2)] for i in range(n)]
blue = [[0 for j in range(2)] for i in range(n)]
for i in range(n):
  red[i] = list(map(int, input().split()))
for i in range(n):
  blue[i] = list(map(int, input().split()))
blue = sorted(blue)
red = sorted(red,key=lambda x:x[1])
ans = 0
for a,b in blue:
  i = 0
  idx = -1
  while i < len(red):
    if a > red[i][0] and b > red[i][1]:
      idx = max(idx,i)
    i += 1
  if idx >= 0:
    ans += 1
    red.pop(idx)

print(ans)

Measured memory_bytes: 39152
#include<stdio.h>
#define M 100
#define WHITE 0
#define BLACK 1
#define GRAY 2

int n;
int G[M][M];
int color[M];
int d[M];
int f[M];
int count = 0;
void visit(int);

int main(){
  void dfs(); 
  int u;
  int v;
  int k;
  int i;
  int j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j] = 0;
    }
  }

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

void visit(int r){
  int v;

  color[r] = GRAY;
  d[r] = ++count;
  for(v=0;v<n;v++){
    if(G[r][v] == 0) continue;
    if(color[v] == WHITE) visit(v);
  }
  color[r] = BLACK;
  f[r] = ++count;
}

void dfs(){
  int u;

  for(u=0;u<n;u++){
    color[u] = WHITE;
  }
  count = 0;
  for(u=0;u<n;u++){
    if(color[u] == WHITE) visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}



Measured memory_bytes: 2088
/*
h3110_fr13nd,
 
AUTHOR : @sam_jn
*/
 
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<pair<int, int>, null_type, less_equal<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define in(a, n) for(int i = 0; i < n; i++) cin >> a[i];
#define ot1(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define ot2(a, n) for(int i = 0; i < n; i++) cout << a[i] << "\n";
ll pwr(ll a, ll b);
ll pwr(ll a, ll b, ll m);
int baap[200002];
int find(int i);  
bool Union(int x, int y);
ll inv(ll x) {return pwr(x, MOD - 2, MOD);}

//----------------------------------SOLUTION-BELOW-------------------------------------------// 

void solve(){   
    int n, m;
    cin >> n >> m;
    int a[m];
    in(a, m);
    ll sum = 0;
    for(int i= 0; i < m; i++){
        sum += a[i];
    }
    if(n - sum >= 0) cout << n - sum;
    else cout << -1;

}
int main(){


                                                            // #ifndef ONLINE_JUDGE    
                                                            // freopen("../../input", "r", stdin);
                                                            // freopen("../../output", "w", stdout);
                                                            // #else
                                                            // // online submission
                                                            // #endif


    boost
    int _ = 1;
    // cout << 0 << endl;
    // cin >> _;
    while(_--){
        solve();
        cout << endl;
    }
}
 
 
//--------------------------------------DEFININTIONS---------------------------------------
ll pwr(ll a, ll b){
    if(b == 0)
        return 1 ;
    ll c = pwr(a, b/2) ;
    c = c * c;
    if(b % 2)
        return c*a;
    return c ;
}
ll pwr(ll a, ll b, ll m){
    if(b == 0)
        return 1;
    ll c = pwr(a, b/2, m) % m ;
    c = (c * c) % m;    
    if(b % 2)
        return (c * a%m) % m;
    return c ;
}
int find(int i)  
{  
    if (baap[i] != i)  
        baap[i] = find(baap[i]);  
  
    return baap[i];  
}
 
bool Union(int x, int y)
{
    x = find(x);
    y = find(y);
    if(x == y) return false;
    baap[x] = y;
    return true;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,m;
int a[125252];
bool b[125252];
ll dp[125252];

int main(){
    scanf("%d%d",&n,&m);
    REP(i,m)scanf("%d",a+i);
    REP(i,m)b[a[i]]=true;
    dp[0] = 1;
    REP(i,n){
        if(i+1<=n && !b[i+1]){
            (dp[i+1] += dp[i]) %= MOD;
        }
        if(i+2<=n && !b[i+2]){
            (dp[i+2] += dp[i]) %= MOD;
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 1280
N = gets.to_i
a = gets.split.map(&:to_i)

c4 = 0
c2 = 0
a.each do |d|
  if d % 4 == 0
    c4 += 1
  elsif d % 2 == 0
    c2 += 1
  end
end

s = c4
s += 1 if c2 == 0

puts c2 + c4 + s >= N ? 'Yes' : 'No'

Measured memory_bytes: 8452
import sys
def call(n):
    i = 1
    flg = 1
    while True:
        x = i
        if x % 3 == 0:
            sys.stdout.write(" "+str(i))
            flg = 0
        while flg == 1:
            if x % 10 == 3:
                sys.stdout.write(" "+str(i))
                flg = 0
            x /= 10
            if not x:
                flg = 0
        if i < n :
            i = i+1
            flg = 1
        else:
            sys.stdout.write("\n")
            break
n = input()
call(n)

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

int main() {

  int N, M;
  cin >> N >> M;

  vector<int> A(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }

  int count = 0;
  int limit = ceil((double) sum / (4 * M));
  
  for (int i = 0; i < N; i++) {
    if (limit <= A[i]) {
      count++;
    }
  }

  if (M <= count) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;

}

Measured memory_bytes: 256
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
T = np.array(lr()).astype('int64')
A = np.array(lr()).astype('int64')
MOD = 10 ** 9 + 7

T_low = T.copy()
T_low[1:][T[1:] <= T[:-1]] = 1
A_low = A.copy()
A_low[:-1][A[:-1] <= A[1:]] = 1

lower = np.maximum(T_low, A_low)
upper = np.minimum(T, A)
domain = np.maximum(0, upper - lower + 1) #変域が0の時は記録が間違い
L = len(domain); LSQ = int(L**.5 + 1)
domain = np.resize(domain, LSQ**2) #行列の形に無理やりする下準備（1次元）
domain[L:] = 1 #後半は全部1
domain = domain.reshape((LSQ, LSQ))
for n in range(1, LSQ):
    domain[:, n] *= domain[:, n-1]; domain[:, n] %= MOD
for n in range(1, LSQ):
    domain[n] *= domain[n-1, -1]; domain[n] %= MOD
answer = domain[-1, -1]
print(answer)


Measured memory_bytes: 25076
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    if s.is_empty() {
        None
    } else {
        s.parse::<T>().ok()
    }
}

fn main(){
    while let Some(n) = read() {
        let mut v: Vec<u64> = (0..n).map(|_| read().unwrap()).collect();
        v.sort();
        v.reverse();
        let mut i = 0;
        while i + 1 < n {
            if v[i] == v[i + 1] {
                break;
            }
            i += 1;
        }
        let mut j = i + 2;
        while j + 1 < n {
            if v[j] == v[j + 1] {
                break;
            }
            j += 1;
        }
        println!("{}", if i < n && j < n { v[i] * v[j] } else { 0 });
    }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    ll res = 0;
    for(int i=1;i<=N;i++){
    	ll val = i;
    	ll keta = 0;
    	while(val>0){
    		keta++;
    		val /= 10;
    	}
    	if(keta%2 == 1) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 892
#include"bits/stdc++.h"

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>A(N);

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		A[i] -= i;
	}

	sort(A.begin(), A.end());
	long ans = 0;

	for (int i = 0; i < N; i++) {
		ans += abs(A[i] - A[N / 2]);
	}

	cout << ans << endl;
	return 0;

}

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

bool check(ll s){
  if(s<4)return false;
  s=s*2+1;
  for(ll i=3;i*i<=s;i++){
    if(s%i==0)return true;
  }
  return false;
}

int main(){
  ll n,s,ans=0;
  scanf("%lld",&n);
  while(n--){    
    scanf("%lld",&s);
    if(!check(s))ans++;
  }
  printf("%lld\n",ans);
  return 0;
}

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

int main(void) {
    char a,b;
    bool flag=true;
    cin>>a>>b;
    if(a=='H'){
        flag=true;
        if(b=='H') flag=true;
        else flag=false;
    }
    else if(a=='D') {
        flag=false;
        if(b=='H') flag=false;
        else flag=true;
    }
    if(flag) cout<<'H'<<endl;
    else cout<<'D'<<endl;
    return 0;
}

Measured memory_bytes: 256
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      static long MOD = 1000000007L;
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int K = Integer.parseInt(st.nextToken());
         //solve
         long[] fac = new long[200005];
         fac[0] = 1L;
         for(int i=1; i <= 200002; i++)
            fac[i] = (fac[i-1]*i)%MOD;
         long min = 0L;
         long max = 0L;
         for(int i=0; i < K; i++)
         {
            min += i;
            max += N-i;
         }
         long res = 0L;
         for(long k=K; k <= N+1; k++)
         {
            long mult = (max-min+1)%MOD;
            res += (mult)%MOD;
            res %= MOD;
            min += k;
            max += N-k;
         }
         System.out.println(res);
      }
      public static long nCr(long[] fac, int a, int b)
      {
         long temp = fac[b];
         temp = (temp*power(fac[a], MOD-2, MOD))%MOD;
         temp = (temp*power(fac[b-a], MOD-2, MOD))%MOD;
         return temp;
      }
      public static long power(long x, long y, long p) 
      { 
          long res = 1L;      
          x = x % p;  
          while (y > 0) 
          { 
              if((y & 1)==1) 
                  res = (res * x) % p; 
              y = y >> 1;  
              x = (x * x) % p;  
          } 
          return res; 
      } 
   }

Measured memory_bytes: 34236
#include <stdio.h>
int main(void){
    long long int n , m , l , sum = 0 ;
    int i , j , k ;
    scanf("%d %d %d" , &n , &m , &l) ;
    long long int a[n][m] , b[m][l] , c[n][l] ;
    
    
    //set a[][]
    for(i = 0 ; i < n ; i++){
        for(j = 0 ; j < m ; j++){
            scanf("%lld" , &a[i][j]);
        }
    }
    
    //set b[][]
    for(i = 0 ; i < m ; i++){
        for(j = 0 ; j < l ; j++){
            scanf("%lld" , &b[i][j]);
        }
    }
    
    for(i = 0 ; i < n ; i++){
        for(j = 0 ; j < l ; j++){
            for(k = 0 ; k < m ; k++){
                sum = sum + (a[i][k] * b[k][j]);
            }
            c[i][j] = sum;
            sum = 0;
        }
    }
    for(i = 0 ; i < n ; i++){
        for(j = 0 ; j < l - 1 ; j++){
            printf("%lld " , c[i][j]);
        }
        printf("%lld\n" , c[i][j]);
    }
    
    return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define db double
#define ll long long
const ll MX=100000;
const ll mod=1e9+7;
const ll inf=1e18;
ll dp[MX+5][105][2];
string s;
ll sz;
ll d;
ll ok(ll p, ll r, ll f)
{
  if(p==sz)
  {
    if(!r)return 1;
    return 0;
  }
  if(~dp[p][r][f]) return dp[p][r][f];
  ll ret=0;
  if(!f)
  {
    for(ll i=0;i<=9;i++)
    {
      ret=(ret+ok(p+1,(r+i)%d,f))%mod;
    }
  }
  else
  {
    for(ll i=0;i<(s[p]-'0');i++)
    {
      ret=(ret+ok(p+1,(r+i)%d,1^f))%mod;
    }
    ret=(ret+ok(p+1,(r+s[p]-'0')%d,f))%mod;
  }
  return dp[p][r][f]=ret;
}
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin>>s>>d;
  sz=s.size();
  memset(dp,-1,sizeof(dp));
  ll r=ok(0,0,1);
  cout<<(r-1+mod)%mod<<endl;
  return 0;
}


Measured memory_bytes: 165120
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int z = sc.nextInt();
        int[] ary = new int[z];
        for(int i = 0 ; i < ary.length; i++){
            ary[i] = sc.nextInt();
        }
        int count = 0;
        for(int i = 0; i < ary.length; i++){
            int min = i;
            for(int j = i; j < ary.length; j++){
                if(i != 0){
                    if(ary[min] == ary[i-1]){break;}
                }
                min = ary[min] > ary[j] ? j : min;
            }
            if(ary[i] != ary[min]){
                int temp = ary[i];
                ary[i] = ary[min];
                ary[min] = temp;
                count++;
            }
        }
        for(int i = 0; i < ary.length; i++){
            build.append(ary[i]);
            build.append(i==ary.length-1 ? "\n" : " ");
        }
        build.append(count);
        System.out.println(build.toString());
    }
}

Measured memory_bytes: 26056
#include<cstdio>
using namespace std;
#define N 17
#define mod 1000000007
int dp[1<<N],fr[1<<N],ifr[1<<N],n,m,v[N],tp[1<<N];
int pw(int a,int b){int as=1;while(b){if(b&1)as=1ll*as*a%mod;a=1ll*a*a%mod;b>>=1;}return as;}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d",&v[i]);
	dp[0]=1;
	fr[0]=ifr[0]=1;
	for(int i=1;i<=1<<n;i++)fr[i]=1ll*fr[i-1]*i%mod,ifr[i]=pw(fr[i],mod-2);
	for(int i=m;i>=1;i--)
	for(int j=(1<<n)-1;j>=0;j--)
	for(int k=1;k<=n;k++)if(!(j&(1<<k-1)))
	if((1<<n)-j-v[i]-(1<<k-1)+1>=0)
	dp[j|(1<<k-1)]=(dp[j|(1<<k-1)]+1ll*dp[j]*fr[(1<<n)-j-v[i]]%mod*ifr[(1<<n)-j-v[i]-(1<<k-1)+1]%mod*(1<<k-1))%mod;
	int as=0;tp[0]=1;
	for(int i=0;i<1<<n;i++)tp[i]=tp[i>>1]*(i&1?-1:1),as=(as+1ll*tp[i]*dp[i]%mod*fr[(1<<n)-i-1]%mod*(1<<n))%mod;
	printf("%d\n",(as+mod)%mod);
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
using namespace std;

int main(){
	vector<int> num;
	int cnt=0;
	string str0,str1,str2;
	cin>>str0;
	for(int i=0; i<str0.size(); i++){
		char ch=str0[i];
		num.push_back(ch-'0');
	}
	while(getline(cin,str1)){
		if(str1=="END_OF_TEXT") break;
		stringstream ss(str1);
		while(getline(ss,str2,' ')){
			int s=num[0]-(str2[0]-'0');
			if((s==0 || s==32) && num.size()==str2.size() ){
				int judge=0;
				for(int i=1; i<num.size(); i++){
					int t=num[i]-(str2[i]-'0');
					if(t!=0 && t!=32 ){
						judge=1;
						break;
					}
				}
				if(judge==0) cnt++;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3172
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

struct Dice{
  int top, front, side;
  int const static SUM = 7;
  void north(){
    int tmp = front;
    front = SUM - top;
    top = tmp;
  }
  void east(){
    int tmp = top;
    top = SUM - side;
    side = tmp;
  }
  void west(){
    int tmp = side;
    side = SUM - top;
    top = tmp;
  }
  void south(){
    int tmp = top;
    top = SUM - front;
    front = tmp;
  }
  void right(){
    int tmp = side;
    side = SUM - front;
    front = tmp;
  }
  void left(){
    int tmp = front;
    front = SUM - side;
    side = tmp;
  }
};

int main(){
  int n;
  while(scanf("%d", &n) && n){
    Dice d;
    d.top = 1; d.front = 2; d.side = 3;
    int res = 1;
    string op;
    //    printf("%d %d %d\n", d.top, d.front, d.side);
    rep(i, n){
      cin >> op;
      switch(op[0]){
      case 'N': d.north(); break;
      case 'E': d.east();  break;
      case 'W': d.west();  break;
      case 'S': d.south(); break;
      case 'R': d.right(); break;
      case 'L': d.left();  break;
      }
      res += d.top;
      //      printf("%d %d %d\n", d.top, d.front, d.side);
    }
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1228
n = int(input())
ans = [0 for _ in range(n+1)]
for x in range(1,int(n**0.5)+1):
    for y in range(1,x+1):
        for z in range(1,y+1):
            if x**2+y**2+z**2+x*y+y*z+z*x<=n:
                if x==y==z:
                    ans[x**2+y**2+z**2+x*y+y*z+z*x] += 1
                if (x==y and y != z) or (y==z and z !=x) or (z==x and x != y):
                    ans[x**2+y**2+z**2+x*y+y*z+z*x] += 3
                if (x!=y) and (y!=z) and (z!=x):
                    ans[x**2+y**2+z**2+x*y+y*z+z*x] += 6
for a in ans[1:]:
    print(a)

Measured memory_bytes: 73972
#include <iostream>
#include <vector>
#include <algorithm>


int main() {
    int N, x;

    std::cin >> N >> x;

    std::vector<int> a(N);
    
    for (int i = 0; i < N; i++) {
        std::cin >> a[i];
    }

    std::sort(a.begin(), a.end());

    int num = 0;
    for (auto val : a) {
        x = x - val;
        if (x < 0) {
            break;
        }
        num++;
    }
    if (x > 0) {
        num -=1;
}
    std::cout << num << std::endl;
}


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


int main(){

int n,v=0;
cin >> n;
string a,b,c;
cin >> a >> b >> c;
for(int i=0;i<n;i++){
  if(a[i]==b[i] && b[i]==c[i]){
    v=v+0;
  }else if(a[i]==b[i] || a[i]==c[i] || b[i]==c[i]){
    v++;
  }else{
    v=v+2;
  }
}
cout << v << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int A, B;
	cin >> A >> B;
	cout << A * B << endl;
	return 0;
}


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

int main() {
	int A, B;
	cin >> A >> B;
	int price;
	price = 10;
	while (price <= 1009)
	{
		if (price * 8 / 100 == A && price / 10 == B)
			break;
		price++;
	}
	if (price == 1010)
		price = -1;
	cout << price << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int ans = Math.max(a + b, a - b);
    ans = Math.max(ans, a * b);
    System.out.println(ans);
  }
}

Measured memory_bytes: 21716
## constant

MAX_LOAD = 150

### main

while true
  n = gets.strip.to_i
  break if n == 0

  events = []

  n.times do
    m, a, b = gets.strip.split(' ').map{|s| s.to_i}
    events << [a, m]
    events << [b, -m]
  end

  events.sort!{|a, b| (cmp0 = a[0] <=> b[0]) != 0 ? cmp0 : a[1] <=> b[1]}
  #p events

  load = 0
  for ev in events
    load += ev[1]
    break if load > MAX_LOAD
  end

  puts (load <= MAX_LOAD ? "OK" : "NG")
end

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

int main() {
    Int x; cin >> x;
    Int k;
    if (x <= 5) {
        cout << 1 << endl;
        return 0;
    }
    if ((x+5) % 11) {
        k = (x+15)/11;
    }
    else {
        k = (x+5) / 11;
    }
    Int g;
    if (x% 11) {
        g = (x+10) / 11;
    }
    else {
        g = x /11;
    }
    if ((Int)k*11-5 <= (Int)g*11) {
        cout << (Int)k*2 - 1 << endl;
    }
    else {
        cout << (Int)g*2;
    }
}


Measured memory_bytes: 3568
import java.util.*

fun main(args: Array<String>) {
    // Your code here!
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    val k = sc.nextInt()
    val l = listOf(a,b,c)
    println((l.sum() - l.max()!! + l.max()!! * Math.pow(2.0,k.toDouble())).toInt())
}

Measured memory_bytes: 33920
#include<bits/stdc++.h>
using namespace std;
int main(){
string answer;getline(cin,answer); char bit = answer[0];
int some_count =0 ;
for(int i=0;i<answer.size();i++)
{
  if(answer[i]!=bit){some_count++;}
 	if(bit=='1'){bit='0';}
  	else{bit='1';}
}
cout<<some_count<<endl;
return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n,k;
  cin>>n>>k;

  vll remind(n+2);
  REP(i,n+1)remind[i+1]=remind[i]+i;

  ll ans=0;
  REP(i,n+2){
    ll r=remind[n+1]-remind[n+1-i];
    ll l=remind[i]-remind[0];
    if(k<=i)
      ans=(ans+r-l+1)%MOD;
  }

  cout<<ans<<endl;

}



Measured memory_bytes: 4760
import java.util.*;

class Main{
  public static void main(String args[]){

    int i= 0;
    int key = 0;
    int n = 0;

    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    int A [] = new int[n];
    //input
    for(int k = 0; k<n; k++){
      A[k] = sc.nextInt();
    }

    //insertion sort
    for(int j = 1; j<A.length;j++){
      key = A[j];
      i = j -1;
      for(int k = 0; k<A.length-1;k++){
        System.out.printf("%d ", A[k]);
      }
      System.out.printf("%d\n",A[A.length-1]);

      while(i>=0 && A[i]>key){
        A[i+1] = A[i];
        i--;
      }
      A[i+1] = key;
    }

    //output
    for(int k = 0; k<A.length-1;k++){
      System.out.printf("%d ", A[k]);
    }
    System.out.printf("%d\n",A[A.length-1]);

  }
}


Measured memory_bytes: 44824
N = int(input())
h = list(map(int,input().split()))

memo = [None for _ in range(N+1)]
memo[N] = 0
memo[N-1] = abs(h[-1]-h[-2])

for i in range(N-2,0,-1):
  memo[i] = min(abs(h[i-1]-h[i])+memo[i+1],abs(h[i-1]-h[i+1])+memo[i+2])
  
print(memo[1])

Measured memory_bytes: 13980
#include<iostream>
#include<vector>
#include<string>
using namespace std;
 
int main() {
  int h, w;
  cin >> h >>w;
  vector<string> a(h);
  for(int i(0);i<h;i++)
    cin >> a[i];
  
  vector<bool> row(h,false);
  vector<bool> col(w,false);
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(a[i][j]=='#'){
        row[i]=true;
        col[j]=true;
      }
  
  for(int i=0;i<h;i++){
    if(row[i])
      for(int j=0;j<w;j++)
        if(col[j])
          cout << a[i][j];
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int main(){
	string s;
	cin >> s;
	int cnt = 0;
	ll ans = 0ll;
	for(int i=0;i<s.size();i++){
		if(s[i]=='W'){
			ans += i-cnt;
			cnt++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll d, t, s;
    cin >> d >> t >> s;
    if(d <= t * s) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main()
{
    string str;
    cin >> str;
    for (int i = 0; i < str.length(); i++) {
        if (str[i] == ',') {
            str[i] = ' ';
        }
    }
    cout << str << endl;
    return 0;
}

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


int main()
{
	int n; cin >> n;
	int d[55];
	for (int i = 0; i < n; ++i)
		cin >> d[i];
	int sum = 0, t = d[0];
	for (int i = 1; i < n; ++i)
	{
		sum += t * d[i]; 
		t += d[i];
	}
	cout << sum << endl;
}



Measured memory_bytes: 3544
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int h[] = new int[N];
		
		for(int i = 0; i < N; i++) {
		    h[i] = sc.nextInt();
		}
		
		Arrays.sort(h);
        
        int minDiff = Integer.MAX_VALUE;
		for(int i = 0; i < (N - K + 1); i++) {
		    int diff = h[i + K - 1] - h[i];
		    if (diff < minDiff) {
		        minDiff = diff;
		    }
		}
		System.out.println(minDiff);
	}
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int n;
string s;
bool ok[100010];

int main() {
	cin >> s;
	n = s.size();
	ok[0] = 1;

	rep(i, n) {
		if (ok[i]) {
			if (i + 5 <= n) {
				if (s.substr(i, 5) == "dream") {
					ok[i+5] = 1;
				}
				if (s.substr(i, 5) == "erase") {
					ok[i+5] = 1;
				}			
			}
			if (i + 6 <= n) {
				if (s.substr(i, 6) == "eraser") {
					ok[i+6] = 1;
				}		
			}			
			if (i + 7 <= n) {
				if (s.substr(i, 7) == "dreamer") {
					ok[i+7] = 1;
				}		
			}
		}
	}
	puts(ok[n] ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>

typedef long long int64;

const int MAXN = 200000 + 10;
const int MOD = 1000000007;

int n, m, a, b;
int fac[MAXN], invfac[MAXN];

inline int qpow(int64 b, int p, int mod= MOD) {
	int res = 1;
	while(p){
		if(p&1)
			res=res*b%mod;
		b=b*b%mod;
		p>>=1;
	}
	return res;
}
void init() {
	int i;
	
	fac[0] = invfac[0] = 1;
	for(i=1; i<MAXN; i++)
		fac[i] = 1ll * fac[i - 1] * i % MOD;
	invfac[MAXN - 1] = qpow(fac[MAXN - 1], MOD - 2);
	for(i=MAXN-2; i; i--)
		invfac[i]=invfac[i+1]*(i+1ll)%MOD;
}
inline int C(int n, int m) { return (0 <= n and n <= m) ? (1ll * fac[m] * invfac[n] % MOD * invfac[m - n] % MOD) : 0;}

int main() {
	int i, res = 0;
	
	init();
	scanf("%d %d %d %d", &n, &m, &a, &b);
	for(i=b; i<m; i++) 
		res = (res + 1ll * C(n - a - 1, i + n - a - 1) * C(a - 1, m - i + a - 2)) % MOD;
	printf("%d\n", res);
	return 0;
}
/*
	0	1	2	3
0	.
1	.
2
3	*	*	*
4	*	*	*

n = 5
m = 4
a = 2
b = 3

C(

*/

Measured memory_bytes: 1664
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int i,j;
  int n,m;
  while(cin>>n>>m,n||m){
    int o;
    cin>>o;
    vector<pair<int,int> > a[10000];
    int b[10000];
    memset(b,0,sizeof(b));
    for(i=0;i<o;i++){
      int p,q,r;
      cin>>p>>q>>q>>r;
      q--;
      if(r){
	if(b[q]){
	  b[q]++;
	}else{
	  a[q].push_back(make_pair(p,0));
	  b[q]++;
	}
      }else{
	b[q]--;
	if(b[q]){
	}else{
	  a[q].back().second=p;
	}
      }
    }
    for(i=0;i<m;i++){
      for(j=1;j<(int)a[i].size();j++){
	if(a[i][j-1].second==a[i][j].first){
	  a[i][j-1].second=a[i][j].second;
	  a[i].erase(a[i].begin()+j);
	  j--;
	}
      }
    }
    cin>>o;
    for(i=0;i<o;i++){
      int p,q,r;
      cin>>p>>q>>r;
      r--;
      if(a[r].size()){
	int sm=0;
	for(j=0;j<(int)a[r].size();j++){
	  if(0){
	  }else if(a[r][j].first>=q){
	  }else if(a[r][j].second<=p){
	  }else if(a[r][j].first<=p&&q<=a[r][j].second){
	    sm+=q-p;
	  }else if(p<=a[r][j].first&&a[r][j].second<=q){
	    sm+=a[r][j].second-a[r][j].first;
	  }else if(a[r][j].first<p){
	    sm+=a[r][j].second-p;
	  }else if(a[r][j].first>p){
	    sm+=q-a[r][j].first;
	  }
	}
	cout<<sm<<endl;
      }else{
	cout<<0<<endl;
      }
    }
  }
  return 0;
}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("10 2 3");
            WillReturn.Add("abccabaabb");
            //Yes
            //Yes
            //No
            //No
            //Yes
            //Yes
            //Yes
            //No
            //No
            //No
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("12 5 2");
            WillReturn.Add("cabbabaacaba");
            //No
            //Yes
            //Yes
            //Yes
            //Yes
            //No
            //Yes
            //Yes
            //No
            //Yes
            //No
            //No
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("5 2 2");
            WillReturn.Add("ccccc");
            //No
            //No
            //No
            //No
            //No
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
        int A = wkArr[1];
        int B = wkArr[2];

        string S = InputList[1];

        int TuukaCnt = 0;
        int KaigaiJyuni = 0;

        for (int I = 0; I <= S.Length - 1; I++) {
            if (S[I] == 'c') Console.WriteLine("No");

            if (S[I] == 'a') {
                if (TuukaCnt < A + B) {
                    TuukaCnt++;
                    Console.WriteLine("Yes");
                }
                else Console.WriteLine("No");
            }
            if (S[I] == 'b') {
                KaigaiJyuni++;
                if (TuukaCnt < A + B && KaigaiJyuni <= B) {
                        TuukaCnt++;
                        Console.WriteLine("Yes");
                }
                else Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 7640
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int INF = 1e9;
const int EPS = 1e-9; 

int main() {
  string N;
  cin >> N;
  if (N.at(N.size()-1) == '2' | N.at(N.size()-1) == '4' | N.at(N.size()-1) == '5' | N.at(N.size()-1) == '7' |N.at(N.size()-1) == '9') cout << "hon" << endl;
  else if (N.at(N.size()-1) == '0' | N.at(N.size()-1) == '1' | N.at(N.size()-1) == '6' | N.at(N.size()-1) == '8') cout << "pon" << endl;
  else cout << "bon" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}

	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	double mul = 1;
	double val = 0;
	for (int i = 0; i < N; i++) {
		if (i != N - 1)	mul *= 2;
		val += (v[i] / mul);
	}

	cout << val;
	return 0;
}



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

int main()
{
   long long int n;
   cin>>n;
   int A[n+1];
     for(int i=1;i<=n;i++)
      {
          A[i]=0;
      }
      int x=0;
  for(int i=1;i<n;i++)
       { 
          cin>>x;
          A[x]++;
       }
       for(int i=1;i<=n;i++)
         {
             cout<<A[i]<<endl;
         }
}


Measured memory_bytes: 4436
#include <stdio.h>
int main(){
	int n,i,j,m,f;
	char a[256],b[256],x;
	while(1){
	scanf("%d ",&n);
	if(n==0){
		break;
        }

	for(i=0;i<n;i++){
		scanf("%c %c ",&a[i],&b[i]);
	}
	
	scanf("%d ",&m);
	for(i=0;i<m;i++){
		scanf("%s",&x);
		f=0;
		for(j=0;j<n;j++){
		 if(x==a[j]){
			printf("%c",b[j]);
			f=1;
			break;
		 }
	    }
	 if(f==0){
	    printf("%c",x);
	 }
	}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1008
fun main(args: Array<String>) {
    val n = readInt()
    val list = (1..n).map { readString() }

    val map = list.groupBy { it }.map { it.key to it.value.size }
    val max = map.maxBy { it.second }!!.second

    val ans = StringBuilder()
    map.filter { it.second == max }.map { it.first }.sorted().
    forEach { ans.appendln(it) }
    println(ans)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 113536
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int N,K;
vector<int> v;
int x[200010] = {0};
int main (){
    cin >> N >> K;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        x[a]++;
    }
    int cnt = 0;
    for(int i=1; i<200001; i++){
        if( x[i] > 0 ) {
            cnt++;
            v.push_back( x[i] );
        }
    }
    sort( v.begin(), v.end());
    if ( K >= cnt ) cout << 0 << endl;
    else {
        int n = cnt - K;
        int ans = 0;
        for(int i=0; i<n; i++){
            ans += v[i];
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2168
#include<stdio.h>
int s1=0,s2=0,sum=0,sss;
int w[200];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&w[i]);
        if(i==1) s1+=w[i];
        else  s2+=w[i];
    }
    if(s1>s2) sum=s1-s2;
    else sum=s2-s1;
    if(sum==0) printf("%d\n",sum);
    else
    {
        for(int i=2;i<=n;i++)
        {
//            printf("*********%d\n",i);
            s1+=w[i];
            s2-=w[i];
            if(s1>s2) sss=s1-s2;
            else sss=s2-s1;
//            printf("&&&&&&&&%d\n",sss);
            if(sss<sum) sum=sss;
//            printf("################%d\n",sum);
            if(sum==0) break;
        }
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 128
// 以下のソースを勉強する.
// zscoder氏.
// https://atcoder.jp/contests/dp/submissions/3938762
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

LL dp[455][455];
LL P[455];

// l ～ r番目 までの 総和
// @param l: 先頭要素の場所.
// @param r: 末尾要素の場所.
// @return : 総和を返却.
LL sum(int l, int r){
    if(l == 0) return P[r];
    else       return P[r] - P[l - 1];
}

// スライムを合体させるための最小コストを計算.
// @param l: 先頭要素の場所.
// @param r: 末尾要素の場所.
// @return : 再帰処理を行う.
LL recursive(int l, int r){
    if(l > r)          return 0;
    if(l == r)         return 0;
    if(dp[l][r] != -1) return dp[l][r];
    LL ans = LL(1e18);
    for(int i = l; i < r; i++) ans = min(ans, recursive(l, i) + recursive(i + 1, r) + sum(l, r));
    return (dp[l][r] = ans);
}

int main(){
    
    // 1. 入力情報取得.
    int N;
    scanf("%d", &N);
    for(int i = 0; i < N; i++) scanf("%lld", &P[i]);
    for(int i = 1; i < N; i++) P[i] += P[i - 1];
    
    // 2. dp更新.
    memset(dp, -1, sizeof(dp));
    LL ans = recursive(0, N - 1);
    // for(int i = 0; i < N; i++){
    //     for(int j = 0; j < N; j++) printf("%lld ", dp[i][j]);
    //     printf("\n");
    // }
    
    // 3. 出力.
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define pll pair<ll,ll> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//g++ code.cpp   ./a.out 

int main() {
   ll n,m;
   cin >> n >> m;
   ll k=0;
   vector<ll> a(n);
   rep(i,n){
      cin >> a[i];
      k+=a[i];
   }
   sort(a.begin(),a.end());
   reverse(a.begin(),a.end());
   if(a[m-1]*4*m>=k) Yes;
   else No;
}

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



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

    int N = S.size();
    int s[200200], t[200200];
    for(int i=0; i<N; i++){
        s[i] = S.at(i) - 'a';
        t[i] = T.at(i) - 'a';
//        cout << s[i] << " " << t[i] << endl;
    }
    int nums[26]; 
    int numt[26];

    const int INF = 20000200;

    for(int i=0; i<26; i++){
        nums[i] = INF;
        numt[i] = INF;
    }

    bool flag = true;
    int cnt=0;

    for(int i=0; i<N; i++){
        if(nums[s[i]]==INF && numt[t[i]] !=INF) {flag =false;break;}
        if(nums[s[i]]!=INF && numt[t[i]] ==INF) {flag = false;break;}
        if(nums[s[i]]==INF && numt[t[i]]==INF){
            nums[s[i]] =cnt;
            numt[t[i]] =cnt;
            cnt++;
        }
        else{
            if(nums[s[i]] != numt[t[i]]) flag = false;
        }
    }
/*
    for(int i=0; i<N; i++){
        cout << nums[s[i]] << " ";
    }
    for(int i=0; i<N; i++){
        cout << numt[t[i]] << " ";
    }
*/
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 2312
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.text.DecimalFormat;

public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        DecimalFormat df = new DecimalFormat("0.00000000");
        String input;
        while (!(input = br.readLine()).equals("0")) {
            int n = Integer.parseInt(input);
            String[] st = br.readLine().split(" ");
            double sum = 0;
            double[] s = new double[n];
            for (int i = 0; i < n; i++) {
                sum += s[i] = Double.parseDouble(st[i]);
            }
            double m = sum / (double) n;
            double result = 0;
            for (int i = 0; i < n; i++) {
                result += Math.pow(s[i] - m, 2);
            }
            bw.append(df.format(Math.sqrt(result / (double) n)) + "\n");
        }
        bw.flush();
    }


}



Measured memory_bytes: 27604
import sys
sys.setrecursionlimit(10000000)

[n, m] = map(int, input().split())

_map = {}
for i in range(n):
    _map[i+1] = []

for i in range(m):
    [x1, y1] = map(int, input().split())

    _map[y1].append(x1)

_memo = {}

def lpath(vertex):
    if vertex in _memo:
        return _memo[vertex]

    if len(_map[vertex]) == 0:
        return 0
    else:
        _max = 0
        for nv in _map[vertex]:
            # print(nv)
            x = lpath(nv)
            if (x > _max):
                _max = x

        _memo[vertex] = _max + 1
        return _max + 1

global_longest_path = 0
for i in range(n):
    longest_path_to_cur_node = lpath(i + 1)
    if global_longest_path < longest_path_to_cur_node:
        global_longest_path = longest_path_to_cur_node

print(global_longest_path)

Measured memory_bytes: 122984
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

int main()
{
	cin >> n;
	vi v(n), vv;
	REP(i, n) cin >> v[i], sum += v[i];
	ans = v[0];
	sum -= v[0];
	vv.push_back(abs(ans - sum));
	FOR(i, 1, n - 1)
	{
		ans += v[i];
		sum -= v[i];
		vv.push_back(abs(ans - sum));
	}
	sort(ALL(vv));
	cout << vv[0] << endl;
}

Measured memory_bytes: 4084
#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++){
                cout << "#";
            }
            cout << "\n";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scan = new Scanner(System.in);
        int inA = scan.nextInt();
        int inB = scan.nextInt();
        int inC = scan.nextInt();
        
        int ans;
        
        if(inA == inB){
            ans = inC;
        }else if(inA == inC){
            ans = inB;
        }else{
            ans = inA;
        }
 
        System.out.println(ans);
        
    }
}

Measured memory_bytes: 22484
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize
    }
    println!("{}", (n + 110) / 111 * 111);
}


Measured memory_bytes: 4352