akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0)
        cout << 0 << endl;
    else
        cout << min(min(a * b, b * c), a * c) << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n;
     cin>>n;
   ll h[n][3];
    for(int i=0;i<n;i++)
      for(int j=0;j<3;j++)
        cin>>h[i][j];
   ll ans[n][3];
   for(int i=0;i<n;i++)
      ans[i][0]=0,ans[i][1]=0,ans[i][2]=0;
   ans[0][0]=h[0][0];
  ans[0][1]=h[0][1];
  ans[0][2]=h[0][2];
  for(int i=1;i<n;i++)
  {
      ans[i][0]=max(ans[i-1][1]+h[i][0],ans[i-1][2]+h[i][0]);
      ans[i][1]=max(ans[i-1][0]+h[i][1],ans[i-1][2]+h[i][1]);
      ans[i][2]=max(ans[i-1][1]+h[i][2],ans[i-1][0]+h[i][2]);
  }
  ll an=0;
  an=max(ans[n-1][0],ans[n-1][1]);
  an=max(an,ans[n-1][2]);
  cout<<an;
    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int a, b;
      
      
    scanf("%d %d", &a, &b);
   

    printf("%d\n", ( a + b + ( a + b ) % 2 ) / 2 );


    return 0;
                                                          
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;

int main(){
    int A, B;
    cin >> A >> B;
    if(A <= 9 and B<=9){
        cout << A*B << endl;
    }
    else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) ;
#define MOD 1000000007
#define int long long 
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define ff first
#define ss second
#define INF (1LL<<61)

using namespace std;



int32_t main(){   

fastio
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt","w", stdout);
// #endif

int n , wt;
cin>>n>>wt;
int w[n+1] , v[n+1];
for(int i =1; i<=n ; i++){
    cin>>w[i]>>v[i];
}


int dp[n+10][wt+10] ;
memset(dp , 0 , sizeof(dp));



for(int i=1 ; i<=n ; i++){
    for(int j =1 ; j<=wt ; j++){
        if(w[i]<=j)
            dp[i][j] = max(dp[i-1][j-w[i]] + v[i] , dp[i-1][j]);
        else
            dp[i][j] = dp[i-1][j];
    }
}

cout<<dp[n][wt]<<'\n';


return 0;
}


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

#define int 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) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#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.1415926535897932384626433832795028L;
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 T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &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;
struct union_find_tree {
    std::vector<int> par, size;
    union_find_tree(int n) : par(n), size(n) {
        for (int i = 0; i < n; i++) {
            par[i] = i;
            size[i] = 1;
        }
    }
    int get_root(int i) {
        if (par[i] == i) { return i; }
        else { return par[i] = get_root(par[i]); }
    }
    void unite(int i, int j) {
        if ((i = get_root(i)) == (j = get_root(j))) { return; }
        if (size[i] < size[j]) { std::swap(i, j); }
        par[j] = i;
        size[i] += size[j];
    }
    bool are_same(int i, int j) { return get_root(i) == get_root(j); }
    int get_size(int i) { return size[get_root(i)]; }
};

int N, M, K;
int A[110000], B[110000], C[110000], D[110000];
int ans[110000];
signed main() {
    cin >> N >> M >> K;
    union_find_tree uf(N);
    rep(i, M) {
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
        uf.unite(A[i], B[i]);
    }
    rep(i, N) {
        ans[i] = uf.size[uf.get_root(i)] - 1;
    }
    rep(i, M) {
        ans[A[i]]--, ans[B[i]]--;
    }
    rep(i, K) {
        cin >> C[i] >> D[i];
        C[i]--, D[i]--;
        if (uf.are_same(C[i], D[i])) { ans[C[i]]--, ans[D[i]]--; }
    }
    rep(i, N) { cout << ans[i] << endl; }
}

Measured memory_bytes: 6528
list_a = []
list_b = []

for x in range(4) :
    list_a.append(int(input()))
list_a.sort(reverse = True)

for x in range(2) :
    list_b.append(int(input()))
list_b.sort(reverse = True)

print(sum(list_a[0:3]) + list_b[0])


Measured memory_bytes: 5600
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (int i = 0; i < values.length; i++) {
			values[i] = i + 1;
		}
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;
			swap(values,a,b);
		}
		for(int i = 0; i < values.length; i++)
		System.out.println(values[i]);
	}
	public static void swap(int[] values,int a,int b){
		int t=values[a];
		values[a]=values[b];
		values[b]=t;
	}
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> vec(n);
  int soutoku = 0;
  
  for(int i = 0;i < n;i ++){
    cin >> vec.at(i);
    soutoku += vec.at(i);
  }
  
  int count = 0;
  int a = 4 * m;
  for(int i = 0;i < n;i ++){
    if((vec.at(i) * a) >= soutoku)count ++;
  }
  
  if(count >= m)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#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) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

using ll = long long;
using Graph = vector<vector<int>>;

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN2(n,m);
  Vi K(m);
  VVi ss(m, Vi(n));
  REP(i,m){
    IN(K[i]);
    REP(j,K[i]){
      IN(ss[i][j]);
      --ss[i][j];
    }
  }
  Vi p(m);
  VIN(p)
  for(int bit = 0; bit < (1<<n); ++bit){
    // bit全探索でflg=trueで電球がついている
    bool flg = true;
    for(int i = 0; i < m; ++i){
      //kをみる
      x = 0;
      for(int j = 0; j < K[i]; ++j){
        if(bit & (1 << ss[i][j])){
          //ss[i][j]は点灯してる
          x++;
        }
      }
      if(x % 2 != p[i]) flg = false;
    }
    if(flg) z++;
  }
  OUT(z);
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<vc> vcc;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 7;

void solve(){
    vi v(5);
    int k;
    for(int i = 0; i < 5; i++) cin>>v[i];
    cin>>k;
    sort(all(v));
    if(v[4]-v[0]>k) cout<<":(";
    else cout<<"Yay!";
    
    
}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

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

int main()
{
	int N,i,temp;
	bool flag=1;
	vector<int> b,ans;
	cin>>N;
	for(i=0;i<N;i++){
		cin>>temp;
		if(temp>i+1){
			flag=0;
			break;
		}
		b.push_back(temp);
	}
	if(flag){
		while(b.size()!=0){
			for(i=b.size();i>0;i--){
				if(b.at(i-1)==i){
					ans.push_back(i);
					b.erase(b.begin()+i-1);
					break;
				}
			}
		}
		for(i=N;i>0;i--){
			cout<<ans.at(i-1)<<endl;
		}
	}else{
		cout<<-1;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll n,k;
	rl2(n,k);
	VL arr(n);
	fr(i,0,n)
	{
		rl(arr[i]);
	}
	VL psum(n+1,0);
	fr(i,1,n+1)
	{
		psum[i]+=psum[i-1]+arr[i-1];
	}
	map<ll,VL> mp;
	ll ans=0;
	map<ll,ll> mp2;
	ll j=0;
	mp[0].PB(0);
	mp2[0]=0;
	fr(i,1,n+1)
	{
		ll x=(psum[i]-i)%k;
		// if(mp.count(x))
		// 	ans+=SZ(mp[x]);
		
		
		
		if(i-j>=k)
		{
			ll y=mp2[j];
			VL::iterator tp;
			tp=lower_bound(ALL(mp[y]),j);
			mp[y].erase(tp);
			mp2.erase(j);
			j++;
		}
		if(mp.count(x))
			ans+=SZ(mp[x]);
		mp[x].PB(i);
		mp2[i]=x;
	}
	// for(auto i: mp)
	// {
	// 	ans+=SZ(i.S);
	// }
	wl(ans);
	NL;
	return 0;
}


Measured memory_bytes: 37760
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define LL long long
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;	
}
using namespace std;
int n,m,f[10][10];
int main()
{
	re(n),re(m);
	for(int i=0;i<=9;++i)
		for(int j=0;j<=9;++j)
			re(f[i][j]);
	for(int k=0;k<=9;++k)	
		for(int i=0;i<=9;++i)
			for(int j=0;j<=9;++j)
				f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			int x;re(x);
			if(~x)ans+=f[x][1];
		}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
N,D = map(int,input().split())
array = []
for i in range(N):
    l = list(map(int,input().split()))
    array.append(l)

c = 0
for i in range(N):
    for j in range(N):
        if i < j:
            dist2 = 0
            for k in range(D):
                dist2 += (array[i][k] - array[j][k])**2
            dist = (dist2)**(1/2)
            if dist == int(dist):
                c += 1
print(c)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// === debug ===
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// === end ===

int main() {
  string S; cin >> S;
  int count = 0, ans = 0;
  rep(i, 3) {
    if (S[i] == 'S')
      count = 0;
    else
      ans = max(ans, ++count);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3596
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 C = sc.nextInt();
    int ans =0;
    int resA=0;
    int resB=0;
    int resC=0;
    for(int i=0;i<1000000;i++){
      if(A%2==0&&B%2==0&&C%2==0){
        ans++;
        resA=B/2+C/2;
        resB=A/2+C/2;
        resC=A/2+B/2;
        A=resA;
        B=resB;
        C=resC;
      }else{
        break;
      }
    }
    if(ans==1000000){
      System.out.println(-1);
    }else{
      System.out.println(ans);
    }


  }
  

  
}


Measured memory_bytes: 21844
// cpp test file
#include <bits/stdc++.h>

using namespace std;


// function to solve
void solve(long long n, long long k){
  double prob = 0;
  for (long long i = 1; i<=n; i++){
    long long a = i;
    long double p = 1.0/n;

    while (a < k){
      a *= 2;
      p /= 2;
    }

    prob += p;
  }

  printf("%.45f", prob);
}

// Driver program to test above function  
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    // Keep this, testcases
    // int t;
    // cin >> t;

    // Now we can run our algo
    // for (int i = 1; i <= t; ++i){
    //   cout << "Case #" << i << ": ";
    //   solveC();
    // }
    long long n, k;
    cin >> n >> k;
    solve(n, k);
    return 0;
}

Measured memory_bytes: 256
<?php
$inVal = (int)trim(fgets(STDIN));
$h = (int)($inVal/3600);
$inVal = (int)($inVal%3600);
$m = (int)($inVal/60);
$s = (int)($inVal%60);
echo $h.":".$m.":".$s.PHP_EOL;
?>


Measured memory_bytes: 9184
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <cstring>
using namespace std;
typedef long long ll;
int main()
{
    //freopen("input.in", "r", stdin);
    int n;
    while(scanf("%d", &n)!=EOF){

        vector<ll> nums(n, 0);

        for(int i=0;i<n;i++){
            scanf("%lld", &nums[i]);
        }

        ll sum1=0, sum2=0, res1=0, res2=0;
        if(nums[0]>0){
            sum1+=nums[0];
            res1=0;
            sum2=-1;
            res2+=(1+nums[0]);
        }
        else if(nums[0]<0){
            sum1=1;
            res1+=(1-nums[0]);
            sum2+=nums[0];
            res2=0;
        }
        else if(nums[0]==0){
            sum1=1;
            res1=1;
            sum2=-1;
            res2=1;
        }
        //first number is positive
        for(int i=1;i<n;i++){
            if(sum1>0){
                res1+=(sum1+nums[i] < 0? 0 : (sum1+nums[i]+1));
                if(sum1+nums[i] < 0){
                    sum1+=nums[i];
                }
                else {
                    sum1=-1;
                }
            }
            else {
                res1+=(sum1+nums[i] > 0? 0 : (1+abs(sum1+nums[i])));
                if(sum1+nums[i] > 0){
                    sum1+=nums[i];
                }
                else {
                    sum1=1;
                }
            }
        }
        //first number is negative
        for(int i=1;i<n;i++){
            if(sum2>0){
                res2+=(sum2+nums[i] < 0? 0 : (sum2+nums[i]+1));
                if(sum2+nums[i] < 0){
                    sum2+=nums[i];
                }
                else {
                    sum2=-1;
                }
            }
            else{
                res2+=(sum2+nums[i] > 0? 0 : (1+abs(sum2+nums[i])));
                if(sum2+nums[i] > 0){
                    sum2+=nums[i];
                }
                else {
                    sum2=1;
                }
            }
        }
        printf("%lld\n", min(res1, res2));
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<10)
#define LLINF (1<<30)
#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
    string s;
    ll k;
    cin >> s >> k;
    int one = INF;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '1') {
            one = i;
            break;
        }
    }
    if (one == INF)cout << s[0];
    else if (one == 0) {
        int notone;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] != '1') {
                notone = i;
                break;
            }
        }
        if (notone + 1 > k)cout << '1';
        else cout << s[notone];
    }
    else cout << s[0];
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
	const int maxn=500000;
	

	int main(){
		IOS
		int n,a,b;
		cin>>n;
		a=n/100;
		b=n%100;
		if(a>0&&a<=12){
			if(b>0&&b<=12)
				cout<<"AMBIGUOUS\n";
			else
				cout<<"MMYY\n";
		}
		else if(b>0&&b<=12){
			if(a>0&&a<=12)
				cout<<"AMBIGUOUS\n";
			else
				cout<<"YYMM\n";
		}
		else
			cout<<"NA\n";
		
		return 0;
	} 

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int l = in.nextInt();
        List<String> strings = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            strings.add(in.next());
        }
        Collections.sort(strings);
        System.out.println(strings.stream().collect(Collectors.joining()));
    }
}


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

typedef long long ll;

char c[26];

int main()	
{
	for(int i=0;i<26;i++) c[i] = 'a'+i;
	ll n,cnt = 26,sz=1;
	cin>>n;
	while(n>cnt){
		n-=cnt;
		cnt *= 26;
		sz++;
	}
	string ans(sz,'#');
	n--;
	for(int i=sz-1;i>=0;i--){
		ans[i] = c[n%26];
		n/=26; 
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3568
class Stack:
    def __init__(self, stack = None):
        if type(stack) is type([]):
            self.stack = stack
            self.top = len(stack)
        else:
            self.stack = []
            self.top = 0
            
    def isEmpty(self):
        return self.top == 0
    
    def isFull(self):
        return self.top >= MAX - 1
            
    def push(self, e):
        if len(self.stack) != (self.top):
            self.stack[self.top] = e
        else:
            self.stack.append(e)
        self.top += 1
           
    def pop(self):
        self.top -= 1
        return self.stack[self.top]

S = input().split(" ")

operators = ["+", "-", "*"]


stack = Stack()
for s in S:
    if s in operators:
        a = stack.pop()
        b = stack.pop()
#         print("%d %s %d"%(a, s, b))
        result = eval("%d %s %d"%(b, s, a))
        stack.push(result)
    else:
        stack.push(int(s))
print (stack.pop())

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

int main(){
    int a,b,n,m;
    map <int,int> road;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        road[a]++;
        road[b]++;
    }
    for(int i=1;i<=n;i++){
        cout<<road[i]<<endl;
    }
    return 0;
}


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

int dp[128][1010];

int getDp(int n, int t) {
    if(t == 1) {
        return n;
    }
    if(dp[n][t] != -1) {
        return dp[n][t];
    }
    int &ret = dp[n][t];
    for(int i = 1; i < 128; ++ i) {
        ret = std::max(ret, std::max(i + getDp(n ^ i, t - 1), (n ^ i) + getDp(i, t - 1)));
    }
    return ret;
}

void MAIN() {
    int t, n;
    scanf("%d%d", &t, &n);
    printf("%d\n", getDp(n, t));
}

int main() {
    memset(dp, -1, sizeof dp);
    int n;
    scanf("%d", &n);
    while(n --) {
        MAIN();
    }
    return 0;
}


Measured memory_bytes: 768
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int a,b,c;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>a>>b>>c;
    cout<<(min(c,a+b+1)) +b<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  double R;
  scanf("%lf", &R);
  printf("%.9lf\n", 2 * R * M_PI);

  return 0;
}


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

#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define exp2(x)  (1LL<<(x))

using ll=long long;
using namespace std;

int X[100][1000];

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

    int N, D; cin >> N >> D;
    rep(i, 0,N-1)
        rep(j, 0, D-1) cin >> X[i][j];

    int ans = 0;
    rep(i, 0, N-2)
        rep(j, i+1, N-1) {
            int tt = 0;
            rep(k, 0, D-1) {
                int d= X[i][k]-X[j][k];
                tt += d *d;
            }
            int c=0;
            while( c*c < tt) c++;
            if (c*c == tt) ans++;
        }

    END(ans);
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main()
    {
        var x = new int[101];
        x[4] = 1;
        x[7] = 1;
        for (int i = 8; i <= 100; i++)
        {
            if (x[i - 4] == 1 || x[i - 7] == 1) x[i] = 1;
        }
        Console.WriteLine(x[int.Parse(Console.ReadLine())] == 1 ? "Yes" : "No");
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
#define INF 10000000

int time[101][101],cost[101][101],m;

void warshall_floyd_time(void);
void warshall_floyd_cost(void);
int min(int,int);
void init(void);

int main(void){
  int i,j,n,k,a,b,cos,tim,p,q,r;

  while(scanf("%d %d",&n,&m),n,m){

    init();
    
    for(i=0;i<n;i++){
      scanf("%d %d %d %d",&a,&b,&cos,&tim);
      cost[a][b]=cost[b][a]=cos;
      time[a][b]=time[b][a]=tim;
    }

    warshall_floyd_time();
    warshall_floyd_cost();

    scanf("%d",&k);
    for(i=0;i<k;i++){
      scanf("%d %d %d",&p,&q,&r);
      printf("%d\n",r?time[p][q]:cost[p][q]);
    }
  }
  return 0;
}



void warshall_floyd_time(void){
  int i,j,k;
  for(k=0;k<=m;k++)
    for(i=0;i<=m;i++)
      for(j=0;j<=m;j++)
	time[i][j]=time[j][i]=min(time[i][j],time[i][k]+time[k][j]);
}

void warshall_floyd_cost(void){
  int i,j,k;
  for(k=0;k<=m;k++)
    for(i=0;i<=m;i++)
      for(j=0;j<=m;j++)
	cost[i][j]=cost[j][i]=min(cost[i][j],cost[i][k]+cost[k][j]);
}

int min(int x,int y){
return x<y?x:y;
}

void init(void){
  int i,j;
  for(i=0;i<101;i++){
    for(j=0;j<101;j++){
      time[i][j]=cost[i][j]=INF;     
    }
    time[i][i]=cost[i][i]=0;
  }
}

Measured memory_bytes: 492
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    lint a[n+1][n+1];
    for (int i=0; i<=n; ++i){
        for (int j=0; j<=n; ++j){
            a[i][j] = 0;
        }
    }
    for (int i=1; i<=n; ++i){
        for (int j=1; j<=n; ++j){
            cin >> a[i][j];
        }
    }
    for (int i=1; i<=n; ++i){
        for (int j=1; j<=n; ++j){
            a[i][j] = a[i][j-1] + a[i][j];
        }
    }
    for (int j=1; j<=n; ++j){
        for (int i=1; i<=n; ++i){
            a[i][j] = a[i-1][j] + a[i][j];
        }
    }
    lint ans = -INF;
    lint sum;
    for (int i=1; i<=n; ++i){
        for (int j=1; j<=n; ++j){
            for (int ii=i; ii<=n; ++ii){
                for (int jj=j; jj<=n; ++jj){
                    sum = a[ii][jj] - a[ii][j-1] - a[i-1][jj] + a[i-1][j-1];
                    ans = max(ans, sum);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<long long> A(N + 1);
  for (int i = 1, a; i <= N && cin >> a; i++) A.at(i) = A.at(i - 1) + a;
  long long ans = LLONG_MAX;
  for (int i = 1; i < N; i++) ans = min(ans, abs(A.at(N) - A.at(i) * 2));
  cout << ans << "\n";
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
        int n = sc.nextInt();
		int l = sc.nextInt();
        String ans[] = new String[n];
        for(int i = 0;i < n;i++){
          ans[i] = sc.next();
        }
		Arrays.sort(ans);
        
        for(int i = 0;i < n;i++){
          System.out.print(ans[i]);
        }
          System.out.println();
    }
}

Measured memory_bytes: 37440
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 100100;
int n;
vector<int> g[N];
int dp[N];

void dfs(int v)
{
    vector<int> a;
    dp[v] = (int)g[v].size();
    for (int u : g[v])
    {
        dfs(u);
        a.push_back(dp[u]);
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < (int)a.size(); i++)
        dp[v] = max(dp[v], a[i] + (int)a.size() - i);
    return;
}

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

    scanf("%d", &n);
    for (int i = 1; i < n; i++)
    {
        int v;
        scanf("%d", &v);
        v--;
        g[v].push_back(i);
    }
    dfs(0);
    printf("%d\n", dp[0]);

    return 0;
}

Measured memory_bytes: 13952
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
ll mod=1e9+7;
ll inv(ll a){
    ll n=mod-2,ans=1;
    while(n>0){
        if(n%2) ans=ans*a%mod;
        n=n/2;
        a=a*a%mod;
    }
    return ans;
}
int main(){
    int n;
    cin>>n;
    ll t[2][52]={0},count=0;
    char s[2][n];
    rep(i,2)rep(j,n) cin>>s[i][j];
    rep(j,n)rep(i,2){
        if(t[i][j]) continue;
        int x,y,a,b;
        if(i&&s[i-1][j]==s[i][j]) x=i-1,y=j;
        if(!i&&s[i+1][j]==s[i][j]) x=i+1,y=j;
        if(j>0&&s[i][j-1]==s[i][j]) x=i,y=j-1;
        if(j<n-1&&s[i][j+1]==s[i][j]) x=i,y=j+1;
        set<char> A;
        rep(k,2){
            if(k==1) a=x,b=y;
            else a=i,b=j;
            if(a&&t[a-1][b]) A.insert(s[a-1][b]);
            if(!a&&t[a+1][b]) A.insert(s[a+1][b]);
            if(b>0&&t[a][b-1]) A.insert(s[a][b-1]);
            if(b<n-1&&t[a][b+1]) A.insert(s[a][b+1]);
        }
        t[i][j]=3-A.size();
        t[x][y]=4;
        if(i==1&&j+1==y&&j>=2&&s[i][j-2]==s[i][j-1]) count++,t[x][y]=3;
    }
    ll ans=1,MOD=1e9+7;
    rep(i,2)rep(j,n) if(t[i][j]<=3) ans=ans*t[i][j]%MOD;
    rep(i,count) ans=ans*inv(2)%MOD;
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


map<ll,vll> G;
vll t;

ll func(ll pos) {
	ll ret = t[pos];

	if(ret > -1) {
		return ret;
	}

	for (auto x : G[pos]) {
		ret=max(ret,func(x));
	}
	ret++;
	t[pos] = ret;
	return ret;
}


int main() {
	ll N, M;
	cin >> N >> M;
	t.resize(N, -1);
	rep(i, 0, M) {
		ll x, y;
		cin >> x >> y;
		x--; y--;
		G[x].push_back(y);
	}

	ll ans = 0;
	rep(i, 0, N) {
		ans = max(ans, func(i));
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 18104
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
//clang++ -std=c++11 -stdlib=libc++ 

int dp[3005][3005];


int main() {
  int n,t; cin >> n >> t;
  vii p(n);
  rep(i,n) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());
  int ans =0;
  rep(i,n) {
    rep(j, t) {
      chmax(dp[i+1][j], dp[i][j]);
      int nj = j + p[i].first;
      if (nj < t) dp[i+1][nj] = max(dp[i+1][nj], dp[i][j] + p[i].second);
    }
    int now = dp[i][t-1] + p[i].second;
    chmax(ans, now);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 35456
#include <stdio.h>

int main(void) 
{
	int mul,minu,num;
	int i;
	scanf("%d%d%d",&mul,&minu,&num);
	for(i = 1;i <= 10;i++){
		num = num * mul - minu;
		printf("%d\n",num);
	}
}

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

using namespace std;

int main(){
    int n, sum1, sum2;
    sum1 = 0;
    sum2 = 0;
    cin >> n;
    vector<int> var(n);
    for (int x = 0; x < n; x++){
        cin >> var[x];
    }
    sort(var.begin(), var.end(), greater<int>());
    
    for (int x = 0; x < n; x += 2){
        sum1 += var.at(x);
    }
    for (int x = 1; x < n; x += 2){
        sum2 += var.at(x);
    }
    cout << sum1 - sum2 << endl;
}
    

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Map<String, Integer> cnt = new HashMap<>();
        cnt.put("AC", 0);
        cnt.put("WA", 0);
        cnt.put("TLE", 0);
        cnt.put("RE", 0);
        scanner.nextLine();
        for (int i = 0; i < n; i++) {
            String s = scanner.nextLine();
            cnt.put(s, cnt.get(s) + 1);
        }
        System.out.println("AC x "+cnt.get("AC"));
        System.out.println("WA x "+cnt.get("WA"));
        System.out.println("TLE x "+cnt.get("TLE"));
        System.out.println("RE x "+cnt.get("RE"));
    }
}

Measured memory_bytes: 60236
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

typedef pair<int,int> pii;

int w,h;
int xs, ys, xg, yg;
int ba[100][100];

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

bool solve() {
  queue<pii> Q;
  bool visited[w][h];
  memset(visited, 0, sizeof(visited));
  Q.push(pii(xs,ys));
  int col = ba[xs][ys];
  while(Q.size()){
    pii a = Q.front();
    int x = a.first, y = a.second;
    Q.pop();
//    printf("%d %d   %d\n", x,y, visited[x][y]);
    visited[x][y] = 1;
    REP(k,4) {
      int xx = x + dx[k];
      int yy = y + dy[k];
      //    cout << " " <<x << endl;
      if (xx<0 || w<=xx || yy<0 || h<=yy) continue;
      if (visited[xx][yy]) continue;
      if (col != ba[xx][yy]) continue;
      
      if (xx == xg && yy == yg)
        return true;
      //cout << xx << ". " << yy << endl;
      Q.push(pii(xx,yy));
    }
  }
  return false;
}

int main() {
  while(cin>>w>>h,w+h) {
    cin >>xs>>ys>>xg>>yg;
    xs--;ys--;xg--;yg--;
    int n;
    cin >> n;
    REP(i,n) {
      int c,d,x,y;
      cin >> c>>d>>x>>y;
      x--;y--;
      REP(i,8) {
        if (d==0)
          ba[x+i%4][y+i/4] = c;
        else
          ba[x+i/4][y+i%4] = c;
      }
    }
    // REP(y,h) {
    //   REP(x,w)
    //     cout << ba[x][y] << " ";
    //   cout << endl;
    // }
    if (solve())
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
}

Measured memory_bytes: 0
//code by lynmisakura.wish to be accepted
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(void){
	//入力
	int n,k; scanf("%d%d",&n,&k);
	ll x = 0; //食べる寿司の種類
	ll sum = 0; //おいしさの和
	ll ans = 0; //答え(sum + x*x)
	
	//まず寿司をおいしい順にソートする
	vector<pair<int,int>> a(n);
	for(int i = 0;i < n;i++){
		int t,d;scanf("%d%d",&t,&d);
		//種類を0-indexedにして,dをfirstにする
		a[i] = make_pair(d,--t);
	}
	sort(a.begin(),a.end()); reverse(a.begin(),a.end());//降順ソート
	
	vector<priority_queue<int,vector<int>,greater<int>>> S(n); //食べる寿司のリスト
	vector<priority_queue<int>> T(n); //食べない寿司のリスト
	
	for(int i = 0;i < k;i++){
		sum += a[i].first;
		S[a[i].second].push(a[i].first); //種類t[i]の寿司で食べるものを昇順で管理
	}
	for(int i = k;i < n;i++){
		T[a[i].second].push(a[i].first);//種類t[i]の寿司で食べないものを降順で管理
	}
	
	
	//まず、おいしい順にk個選んだ時の種類数をカウントする
	for(int i = 0;i < n;i++) if(S[i].size() >= 1) x++;
	ans = sum + (x*x);
	
	/*
	OUT：食べないことにした寿司のなかで一度も食べられていない種類の、最もおいしい寿司
	IN：食べることにした寿司の中で、同種寿司が2個以上ある種類の2番目以下の寿司
	*/
	priority_queue<int> OUT;
	priority_queue<int,vector<int>,greater<int>> IN;
	
	for(int i = 0;i < n;i++){
		int s = S[i].size();
		int t = T[i].size();
		
		if(s >= 2){
			for(int j = 0;j < s - 1;j++){
				IN.push(S[i].top());S[i].pop();
			}
		}
		if(s == 0 && t >= 1) OUT.push(T[i].top());
	}
	
	while(!IN.empty() && !OUT.empty()){
		int i,o;
		i = IN.top(); IN.pop();
		o = OUT.top(); OUT.pop();
		sum += o - i;
		x++;
		ans = max(ans, sum + (x*x));
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 10752
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {

    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int> d(N, 0);
    REP(i, N) {
        cin >> d[i];
    }

    ll ans = INF;
    REP(i, pow(4, N)){
        vector<vector<ll>> a(4);
        ll tmp = i;
        REP(j, N){
            a[tmp % 4].push_back(d[j]);
            tmp /= 4;
        }
        if (a[0].size() == 0 || a[1].size() == 0 || a[2].size() == 0) continue;

        ll A_sum = accumulate(a[0].begin(), a[0].end(), 0LL);
        ll B_sum = accumulate(a[1].begin(), a[1].end(), 0LL);
        ll C_sum = accumulate(a[2].begin(), a[2].end(), 0LL);

        ll tans = abs(A - A_sum) + 10 * (a[0].size() - 1) + abs(B - B_sum) + 10 * (a[1].size() - 1) + abs(C - C_sum) + 10 * (a[2].size() - 1);
        ans = min(ans, tans);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#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 REP_(i,m,n) for(int i =m; i <n; ++i)

#define INF 2e9

#define ll long long

const ll MOD = 1000000007;
const int MAX = 1000000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    ll x,y;
    cin >> x >> y;
    
    ll n_x ,n_y;
    n_x= (2*y - x)/3;
    n_y =(2*x - y)/3;

    if((2*y - x)%3 != 0){
        cout << 0 << endl;
        return 0;
    }
    if( (2*x - y)%3 != 0){
        cout << 0 << endl;
        return 0;
    }
    if((2*y - x)/3 < 0){
        cout << 0 << endl;
        return 0;
    }
    if( (2*x - y)/3 < 0){
        cout << 0 << endl;
        return 0;
    }
    //cout << n_x << "," << n_y << endl;


    COMinit();
    cout <<  COM(n_x+n_y,n_x) << endl;
    return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int in(){int x; scanf("%d",&x); return x;}
//static const int MAX = 10000;


int main(){
  int N = in(), k;
  vector<int> l(N);
  long long count = 0;
  rep(i, N) l[i] = in();
  sort(l.begin(), l.end());

  rep(i, N){
    for(int j = i+1; j < N; j++){
      k = lower_bound(l.begin(), l.end(), l[i]+l[j]) - l.begin();

      count += max(k-(j+1), 0);
    }
  }
  
  cout << count << endl;
}


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

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)
#define pb push_back
#define mp make_pair

const double pi = 2*acos(0.0);
//__gcd(n1, n2);
//cout << fixed;
//cout << setprecision(6); //fixes # of dp
//tgamma(i+1) is 1!

void solve(){
    int n,m;
    cin >> n >> m;
    ll summ = 0;
    f(i,0,m){
        int x;
        cin >> x;
        summ += x;
    }
    cout << (summ>n?-1:n-summ) << "\n";
}


int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
    solve();
}








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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL N; cin >> N;
	VL a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}

	map<LL, LL>M;
	FOR(i, 0, N) {
		M[a[i]]++;
	}
	bool ok = 1;
	if (N & 1) {
		ok &= M[0] == 1;
		FOR(i, 1, N / 2 + 1) {
			ok &= M[2 * i] == 2;
		}
	}
	else {
		FOR(i, 0, N / 2) {
			ok &= M[2 * i + 1] == 2;
		}
	}

	auto modpow = [](LL n) {
		long long  res = 1;
		LL x = 2;
		while (n > 0) {
			if (n & 1) {
				res = (res*x) % MOD;
			}
			x = (x*x) % MOD;
			n >>= 1;
		}
		return res;
	};
	LL ans = 0;
	if (ok) {
		ans = modpow(N / 2);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
int n,m;
int fa[200005];
int cnt[200005];

void init() {
	for(int i=1;i<=n;i++) {
		fa[i]=i;
		cnt[i]=1;
	}
}

int get(int x) {
	if(fa[x]==x) {
		return x;
	}
	return fa[x]=get(fa[x]);
}

int main() {
	scanf("%d %d",&n,&m);
	init();
	for(int i=1;i<=m;i++) {
		int u,v;
		scanf("%d %d",&u,&v);
		u=get(u);
		v=get(v);
		if(u!=v) {
			fa[v]=u;
			cnt[u]+=cnt[v];
		}
	}
	int res=0;
	for(int i=1;i<=n;i++) {
		if(fa[i]==i) {
			res=max(res,cnt[i]);
		}
	}
	printf("%d",res);
	return 0;
}

Measured memory_bytes: 5372
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

    	int H = 0;
    	int W = 0;

    	Scanner sc= new Scanner(System.in);

    	while( true ) {
    		H = sc.nextInt();
    		W = sc.nextInt();

    		if( ( H == 0 ) && ( W == 0 ) ) {
    			break;
    		}

    		for( int i = 0 ; i < H ; i++ ) {
    			for ( int j = 0 ; j < W ; j++ ) {
        			System.out.print( '#' );
    			}
    			System.out.print( "\n" );
    		}
    		System.out.print( "\n" );
    	}
    	sc.close();
    }
}


Measured memory_bytes: 39736
n=int(input())

s=input()
import heapq
windex=[]
rindex=[]

for i,ss in enumerate(s):
  if ss=="W":
    heapq.heappush(windex,i)
  else:
    heapq.heappush(rindex,i*(-1))
 
cnt=0
while 1:
  if len(windex)==0 or len(rindex)==0:
    print(cnt)
    exit()
  else:
    tmpw=windex[0]
    tmpr=rindex[0]*(-1)
    
    if tmpw>tmpr:
      print(cnt)
      exit()
    else:
      cnt+=1
      heapq.heappop(windex)
      heapq.heappop(rindex)

Measured memory_bytes: 81992