akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
#include<map>
using namespace std;

typedef pair<int,int> P;

int m,n,pn,tmp;
int ans,upper;
map<int,int> dp[24];
//int dp[24][1<<18];
P pos[24];

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

int rec(int vis,int id){
  if(dp[id].count(vis))return dp[id][vis];
  //if(__builtin_popcount(vis)>6 && dp[id][vis])return dp[id][vis];

  if(!vis && !id)return 1;

  int res = 0;
  int y = pos[id].first, x = pos[id].second;
  for(int k=0;k<4;k++){
    int ty = y+dy[k], tx = x+dx[k];
    for(;;){
      if(ty<0 || tx<0 || n<=ty || m<=tx)break;
      if(!vis && !g[ty][tx]){
		res += 1;
		break;
	  }
      if(0<g[ty][tx]){
	    int tmp = g[ty][tx] - 1;
	    if( (vis>>tmp)&1 ){
	      res += rec(vis-(1<<tmp),g[ty][tx]);
	      break;
        }
      }
      ty += dy[k]; tx += dx[k];
    }
  }
  if(__builtin_popcount(vis)>8)dp[id][vis] = res;
  return res;
}

int main(){
  while(scanf("%d%d",&m,&n), m||n){
    pn = 1;
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	scanf("%d",&tmp);
	if(tmp==1){
	  g[i][j] = pn;
	  pos[pn] = P(i,j);
	  pn++;
	}else if(tmp==2){
	  g[i][j] = 0;
	  pos[0] = P(i,j);
	}else g[i][j] = -1;
      }
    }

    for(int i=0;i<pn;i++)dp[i].clear();
	//for(int i=0;i<pn;i++)
   	  //for(int j=0;j<(1<<18);j++)dp[i][j] = 0;
    upper = (1<<(pn-1));
    printf("%d\n",rec(upper-1,0));
  }
}

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

  using namespace std;
  using namespace std::chrono; 

  typedef long long int ll;

  #define MOD (ll)(1e9+7)
  #define endl "\n"
  #define pb push_back
  #define TEST_CASES  ll t;cin>>t;while(t--)
  #define forn(i,a,n) for (int i = a; i < n; ++i)
  #define f first
  #define s second
  #define all(x) x.begin(), x.end()
  
  ll powD(ll x,ll y){
    ll res = 1;
    while(y > 0){
      if(y & 1)
        res = (res*x)%MOD;
      x = (x*x)%MOD;
      y = y>>1;
    }
    return res;
  }


  int main()
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<ll> a(n);
    forn(i,0,n){
      cin>>a[i];
    }
    forn(i,k,n){
      if(a[i] > a[i-k])
        cout<<"Yes"<<endl;
      else
        cout<<"No"<<endl;
    }
  }
   
  

Measured memory_bytes: 4760
from collections import*
n, m, *t = map(int, open(0).read().split())       
*w, s, t = [a-1for a in t]         
e = [[]for _ in range(n)]        
for u, v in zip(w[::2], w[1::2]):      
    e[u].append(v)

INF = 10**10
f = [[INF]*3for _ in range(n)]        
f[s][0] = 0        
q = deque([(s, 0)])           
while q:
    vi, j = q.popleft()         
    if vi == t and j == 0:
        print(f[vi][0]//3)
        break
    for ui in e[vi]:           
        if f[ui][(j+1)%3] < INF: continue           
        f[ui][(j+1)%3] = f[vi][j] + 1
        q.append((ui, (j+1)%3))
else:
    print(-1)

Measured memory_bytes: 42820
from collections import defaultdict
from itertools import accumulate


def solve(string):
    n, m, *a = map(int, string.split())
    a = list(accumulate(a))

    d = defaultdict(int)
    for i in range(n):
        d[a[i] % m] += 1
    ans = d[0]
    for v in d.values():
        ans += v * (v - 1) // 2
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 69272
#include<bits/stdc++.h>
#define         sz          1000000
#define         inf         1000003

using namespace std;

int grid[20][20];

int main(){

    int n,d;
    cin>>n>>d;

    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>grid[i][j];
        }
    }

    int sum = 0;
    int cnt = 0;

    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            sum = 0;
            for(int k=0;k<d;k++){
                sum = sum +((abs(grid[i][k]-grid[j][k]))*(abs(grid[i][k]-grid[j][k])));
            }

            if(sqrt(sum) == floor(sqrt(sum))){
                cnt++;
            }
        }
    }

    cout<<cnt<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define FILE_NAME "a"


ll cost[4];
ll n;

bool read() {
	forn(i, 4) {
		if  (scanf("%lld", &cost[i]) < 1) {
			return 0;
		}
	}
	scanf("%lld", &n);
	n *= 4;
	return 1;
}



ll solve() {
	forn(i, 3) {
		cost[i + 1] = min(cost[i + 1], cost[i] * 2);
	}

	ll ans = (n % 2) * cost[0];
	n /= 2;
	ans += (n % 2) * cost[1];
	n /= 2;
	ans += (n % 2) * cost[2];
	n /= 2;
	ans += n * cost[3];
	return ans;
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		printf("%lld\n", solve());
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;

signed main(){
	int A,B,C;
	scanf("%lld %lld.%lld",&A,&B,&C);
	out(A * (B * 100 + C) / 100);
}

Measured memory_bytes: 3752
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		int s=0;
		for(int i=0; i<4; i++){
			s+=sc.nextInt();
		}
		println(s/60+"");
		println(s%60+"");
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	string s;
	cin>>s;
	cout<<s[0]<<s[1]<<s[2];
	
	return 0;	
}

Measured memory_bytes: 3640
n,m=map(int,input().split())
d={}#{中継地:(1 or n)}
flag=False

for i in range(m):
    a,b=map(int,input().split())
    if a==1:
        try:
            flag=(d[b]==n)
        except:
            d[b]=1
    elif b==n:
        try:
            flag=(d[a]==1)
        except:
            d[a]=n
    if flag:
        print('POSSIBLE')
        break

if not flag:
    print('IMPOSSIBLE')


Measured memory_bytes: 27068
#include <stdio.h>
typedef long long ll;
ll dp[110][100010];
ll max(ll x, ll y) {
	return x > y ? x : y;
}
int main() {
	int n, w, weight[100], value[100];
	scanf("%d%d", &n, &w);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &weight[i], &value[i]);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= w; j++) {
			if (j >= weight[i]) {
				dp[i + 1][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i]);
			}
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
		}
	}
	printf("%lld\n", dp[n][w]);
	return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

ll powa(ll a, ll b, ll c)
{
    a%=c;
    if(a<0)
	a+=c;
    ll res = 1;
    while(b>0)
    {
        if(b&1)
            res*=a, res%=c;
        a*=a, a%=c;
        b>>=1;
    }
    return res;
}

int main()
{
  FAST/**/
   
   ll n;
   cin>>n;
   
   ll ans = powa(10,n,mod);
   ans = (ans-2*powa(9,n,mod) + powa(8,n,mod));
   ans = ((ans%mod)+mod)%mod;
   cout<<ans;
   
   
   return 0;        
}  

  
          
   

Measured memory_bytes: 3648
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int n;
	cin >> n;
	vector<int>p(n);
	rep(i, n)cin >> p[i];
	int cnt = 0;
	rep(i, n - 2)if (max({ p[i],p[i + 1],p[i + 2] }) != p[i + 1] && min({ p[i],p[i + 1],p[i + 2] }) != p[i + 1])cnt++;
	cout << cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    while (true) {
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        int ans = 0;
        REP1(i, n) REP1(j, n) {
            if (i >= j) continue;
            int z = x - (i + j);
            if (z > i && z > j && z > 0 && z <= n) {
                ans++;
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 1001
#define MAX_N2 MAX_N*(MAX_N+1)/2
typedef long long ll;
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define REP(i, n) for(ll i=0; i<n; i++)
#define RER(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin() v.end()
#define pb push_back
using namespace std;
typedef pair<ll, ll> P;
ll n, k, a[MAX_N], c[50];
vector<ll> b;
bool use[MAX_N2];

signed main(){
	cin >> n >> k;
	REP(i, n){
		cin >> a[i];
	}
	// fill(a, a+n, 1);
	for(ll r=0; r<n; r++){
		for(ll l=r; l<n; l++){
			b.pb(0);
			for(ll i=r; i<=l; i++) b[b.size()-1] += a[i];
		}
	}
	ll bn = b.size();

	fill(use, use+bn, true);
	fill(c, c+50, 0);

	// cout << bn << endl;
	ll ret = 0;
	for(ll j=49; j>=0; j--){
		bool tmp_use[MAX_N2]; fill(tmp_use, tmp_use+MAX_N2, true);
		REP(i, bn){
			tmp_use[i] = use[i];
			tmp_use[i] &= ((b[i] >> j) & 1); 
			if(tmp_use[i]){
				c[j]++;
				// cout << b[i] << endl;
			}
		}
		// cout << c[j] << endl;
		if(c[j] >= k){
			REP(l, bn) use[l] &= tmp_use[l];
			ret += 1LL << j;
		}
	}
	cout << ret << endl;
    return 0;
}

Measured memory_bytes: 6384
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		ArrayList<String> str = new ArrayList<String>();
		while(in.hasNext()) {
			String buf = in.nextLine();
			str.add(buf);
		}
		
		int facter[];
		facter = new int[str.size()];

		for (int i = 0; i < str.size(); i++) {
			facter[i] = Integer.parseInt(str.get(i));
		}
		
		int count = 0;
		
		for (int i = 0; i < facter.length; i++) {
			if (isPrime(facter[i])) {
				count++;
			}
		}
		
		System.out.println(count);
	}
	
	public static boolean isPrime (int number) {
		if (number == 2) {
			return true;
		}
		if ((number < 2) || ((number % 2) == 0)) {
			return false;
		}
		
		for (int i = 3; i <= Math.sqrt(number); i = i + 2 ) {
			if ((number % i) == 0) {
				
				return false;
			}
			
		}

		return true;
	}
	
	

}

Measured memory_bytes: 66048
#include<bits/stdc++.h>
#define ll  long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<ll>

#define sz(x) ((int) (x).size())
#define pll pair<long long,long long>
#define mp make_pair
#define F first
#define S second
#define T int tt; cin>>tt; while(tt--)
#define fastio ios_base::sync_with_stdio(false);
 
#define endl '\n'
#define all(a) (a).begin(), (a).end()
#define display(x) for(auto i : x) cout << i << " "; cout << '\n';
#define input(x) for(int i = 0; i < n; i++) cin >> x[i];
#define make(x,y) fill(all(x), y)
#define FO(i,startLoop,n) for (int i = startLoop; i < n; i++)

#define mod 1000000007
#define Y cout<<"YES"<<endl;
#define N cout<<"NO"<<endl;
#define ITFO(myiterator, mymap) for(auto myiterator = mymap.begin(); myiterator!=mymap.end(); ++myiterator)
using namespace std;  
 

int main()
{
    fastio
    cin.tie(NULL); cout.tie(0);
    
     
  
  int n, k; cin>>n>>k; vi a(n, 0), dp(n, INT_MAX); input(a);
  dp[0] = 0;
    

  for(int i = 0; i<min(n, k) ; ++i)  dp[i] = abs(a[i] - a[0]);
  
  for(int i=k; i<n; ++i)
  {
      ll cnt = k, mm = INT_MAX, j = i-1;
      while(cnt-- && j>=0)
      {
          mm = min(mm, abs(a[i] - a[j]) + dp[j]);
          j--;
      }
      dp[i] = mm;
  }
  cout<<dp[n-1];
  cerr << "\nTime elapsed: "<< 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
   return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <bitset>
#include <cmath>

using namespace std;

const int kMax = 2200;
const int kMaxPr = 500;
const double eps = 1e-10;

void Init(vector < int > &prime) {
  
  bitset < kMax > used;
  int index = 0;
  for (int pr = 2; pr < kMax; pr ++) {
    if (used[pr]) {
      continue;
    }
    prime[++ index] = pr;

    for (int j = pr * 2; j < kMax; j += pr) {
      used[j] = true;
    }
  }

  prime[0] = index;
}

void solve(vector < long long > &element, vector < int > &prime, map < long long, long long > &hash, 
  map < long long, long long > &comp, map < long long, int > &frecv, int n) {

  for (int i = 1; i <= n; i ++) {
    cin >> element[i];
    
    long long k = element[i];
    if (hash[k]) {
      frecv[hash[k]] ++;
      continue;
    }

    hash[k] = 1ll;
    comp[k] = 1ll;
    for (int j = 1; j <= prime[0] and k != 1 and prime[j] * prime[j] <= k; j ++) {
      if (k % prime[j] != 0) {
        continue;
      }

      int elExp = 0;
      while (k % prime[j] == 0) {
        elExp ++;
        k /= prime[j];
      }

      elExp %= 3;
      if (elExp == 0) {
        continue;
      }

      if (elExp == 1) {
        hash[element[i]] *= 1ll * prime[j];
        comp[element[i]] *= 1ll * prime[j] * prime[j];
      }
      else {
        hash[element[i]] *= 1ll * prime[j] * prime[j];  
        comp[element[i]] *= 1ll * prime[j];
      }
    }

    hash[element[i]] *= k;
    double sq_root = sqrt(k);
    if (sq_root - floor(sq_root) < eps) {
      comp[element[i]] *= sq_root;
    }
    else {
      double aux = hash[element[i]];
      aux *= (double)k * (double)k;
      if (aux < 1e18) {
        comp[element[i]] *= k * k;
      }
      else {
        comp[element[i]] = 0;
      }
    }
    
    frecv[hash[element[i]]] ++;
    comp[hash[element[i]]] = comp[element[i]];
  }
}

int main(int argc, char const *argv[]) {

  vector < int > prime(kMaxPr);
  Init(prime);

  int n;
  cin >> n;

  vector < long long > element(n + 1);
  map < long long, long long > hash;
  map < long long, long long > comp;
  map < long long, int > frecv;

  solve (element, prime, hash, comp, frecv, n);
  
  map < long long, bool > used;
  used[1] = true;
  int to_remove = frecv[1] > 0 ? frecv[1] - 1 : 0;
  for (auto &x : frecv) {
    if (used[x.first]) {
      continue;
    }

    long long k = x.first;
    int c = frecv[comp[k]];

    to_remove += min(x.second, c);
    used[comp[k]] = true;
  }

  cout << n - to_remove << '\n';
}

Measured memory_bytes: 34048
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>

using namespace std;

int a[100010];
int b[100010];

int n;
long long sumA, sumB;

struct Item
{
	int value;
	int pos;
	int c;
};

Item d[100010];	//差异 

bool compareValue(const Item &a, const Item &b)
{
	return a.value > b.value;
}

bool comparePos(const Item &a, const Item &b)
{
	return a.pos < b.pos;
}


int main()
{
	sumA = 0;
	sumB = 0;
	scanf("%d", &n);
	
	sumA = 0;
	for (int i = 0 ; i < n ; i++)
	{
		scanf("%d", &(a[i]));
		sumA = sumA + a[i];
	}
	
	long long totalDToAdd = 0;
	sumB = 0;
	for (int i = 0 ; i < n ; i++)
	{
		scanf("%d", &(b[i]));
		sumB = sumB + b[i];
		
		d[i].value = b[i] - a[i];
		d[i].pos = i;
		if (d[i].value > 0)
			totalDToAdd = totalDToAdd + d[i].value;
	}
	
	if (sumA < sumB)
	{
		printf("-1\n");
		return 0;
	}
	
	sort(d, d + n, compareValue);
	
	int changeCount = 0;
	totalDToAdd = 0;

	for (int i = 0 ; i < n ; i++)
	{
		if (d[i].value > 0)
		{
			d[i].c = b[d[i].pos];
			totalDToAdd = totalDToAdd + b[d[i].pos] - a[d[i].pos];
			changeCount++;
		}
		else if (d[i].value == 0)
		{
			d[i].c = b[d[i].pos];
		}
		else 
			break;
	}
	
	for (int i = n - 1 ; i >= 0 ; i--)
	{
		if (d[i].value >= 0)
			break;
		if (totalDToAdd > -d[i].value)
		{
			d[i].c = b[d[i].pos];
			totalDToAdd = totalDToAdd - (-d[i].value);	//注意是负值
			changeCount++;
		}
		else if (totalDToAdd > 0)
		{
			d[i].c = b[d[i].pos] - totalDToAdd;
			totalDToAdd = 0;
			changeCount++;
		}
		else
		{
			if (d[i].value < 0)
				d[i].c = a[d[i].pos];
			else
				break;
		}
	}
	
	printf("%d\n", changeCount);
//	sort(d, d + n, comparePos);
//	for (int i = 0 ; i < n ; i++)
//		printf("%d ", d[i].c);
//	printf("\n");
	
	return 0;
}



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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

int main ()
{
    int A , B , C ;
    cin >> A >> B >> C ;
    int sep = (B + C) - A ;

    if (sep >= 0) {

    cout << sep ;
    }
    else
    {
        cout << 0 ;
    }

    return 0 ;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	
	public static double find(double arr[],double dp[][],int tail,int i,int n)
	{
		if(i>=n)
			return 1;
		
		if(dp[tail][i]==-1)
		{
			double op1=(arr[i])*find(arr,dp,tail,i+1,n);
			double op2=0;
			if(tail<n/2)
				op2=(1-arr[i])*find(arr,dp,tail+1,i+1,n);
			
				dp[tail][i]=op2+op1;
				
		}
		
			return dp[tail][i];
	}
    public static void main(String[] args) 
    {
       Scanner s=new Scanner(System.in);
       int n=s.nextInt();
       double arr[]=new double[n];
       for(int i=0;i<n;i++)
    	   arr[i]=s.nextDouble();
       
       double dp[][]=new double[n/2+1][n];
       for(int i=0;i<=n/2;i++)
       {
    	   for(int j=0;j<n;j++)
    		   dp[i][j]=-1;
       }
       System.out.print(find(arr,dp,0,0,n));
    }
}

Measured memory_bytes: 71144
/**
*    created: 30.07.2020 22:24:40
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#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++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dx2[8] = {0, 1, 0, -1, 1, 1,-1, -1};
const int dy2[8] = {1, 0,-1, 0, 1, -1, 1, -1};
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n; cin >> n;
    map<int,int> mp;
    rep(i,n) {int a; cin >> a; mp[a]++;}
    int dcnt = 0;
    for (auto p : mp) if (p.second >= 2) {
        int t = p.second;
        while (t >= 3) t = t % 3 + t / 3;
        if (t >= 2) dcnt++;
    }
    if (dcnt % 2 == 0) cout << mp.size() << endl;
    else cout << mp.size() - 1 << endl;
}

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

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC097_B();
        }

        static void ABC097_B()
        {
            var X = int.Parse(Console.ReadLine());
            var ans = 1D;
            for (var x = 2; x <= X; x++)
            {
                for (var i = 2; Math.Pow(x, i) <= X; i++)
                    ans = Math.Max(ans, Math.Pow(x, i));
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
int main(void){

char ch;

while(1){
    scanf("%c", &ch);
    if('a' <= ch && ch <= 'z')
        {
            printf("%c",ch-32);
        }
    else if('A' <= ch && ch <= 'Z')
        {
            printf("%c",ch+32);
        }
    else {printf("%c",ch);}


    if ( ch == '\n' ){ break; }
}
return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int N;

vector<string> ans;

void dfs(string a, int used_count){
    if (a.size() == N){
        ans.push_back(a);
        return;
    }

    int next_count = used_count;
    rep(i,used_count+1){
        char next_char = 'a'+i;
        if (i == used_count) next_count++;
        
        dfs(a+next_char, next_count);
    }

}

int main(){
    cin >> N;

    dfs("a", 1);

    rep(i,ans.size()){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 7432
import java.io.*;
import java.util.*;
import java.lang.Math;
import java.util.Arrays;

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

        Scanner sc = new Scanner(System.in);

        int m, f, r;
        MainRoop : while(true){
            m = sc.nextInt();
            f = sc.nextInt();
            r = sc.nextInt();

            if(m == -1 && f == -1 && r == -1)break MainRoop;

            String p = "";
            if(m == -1 || f == -1)p = "F";
            else if(m + f >= 80)p = "A";
            else if(m + f >= 65)p = "B";
            else if(m + f >= 50)p = "C";
            else if(m + f >= 30){
                if(r >= 50)p = "C";
                else p = "D";
            }else p = "F";

            System.out.println(p);
        }
    }
  
}


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

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  pb             push_back
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define  deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define  deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   MAXN  =  1e+5+7;

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n,m,a,b,ans;
//<<-----Implement Functions Here---->>//
ll solve(ll i)
{
	if(visit[i]!=-1)return visit[i];
	for(ll j=0;j<adj[i].size();j++)visit[i] = max(visit[i],solve(adj[i][j]));
	visit[i]++;
	return visit[i];
}

//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n>>m;mset(visit,-1);
		for(ll i=0;i<m;i++)cin>>a>>b,adj[a].pb(b);
		for(ll i=1;i<=n;i++)ans = max(ans,solve(i));
		cout<<ans;
}

int main(){
	fastio;randomINIT;

	//cin>>t;
	while(t--){
		MAIN();
	}

    
}

Measured memory_bytes: 8576
use std::cmp::min;
const INF: u64 = 1 << 60;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let l: usize = sc.read();
    let a: Vec<u64> = sc.vec(l);

    let mut dp = [INF; 5];
    dp[0] = 0;
    for i in 0..l {
        let a = a[i];
        let mut next = [INF; 5];
        for state in 0..5 {
            for next_state in state..5 {
                let cost = match next_state {
                    0 => a,
                    1 => {
                        if a == 0 {
                            2
                        } else {
                            a % 2
                        }
                    }
                    2 => (a + 1) % 2,
                    3 => {
                        if a == 0 {
                            2
                        } else {
                            a % 2
                        }
                    }
                    4 => a,
                    _ => unreachable!(),
                };
                next[next_state] = min(next[next_state], dp[state] + cost);
            }
        }
        dp = next;
    }
    println!("{}", dp.iter().min().unwrap());
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 6396
using System;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(double.Parse).ToArray();
            var N = input[0];
            var K = input[1];

            var ans = Math.Max(0, (N - (K - 1)) / N);
            for (int i = 1; i <= Math.Min(K - 1, N); i++)
            {
                var m = Math.Ceiling(Math.Log2(K / i));
                ans += Math.Pow(0.5, m) / N;
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28616
#include <iostream>

int main()
{
    int K, A, B;
    std::cin >> K;
    std::cin >> A >> B;
    bool suc = false;
    for(int i = A; i <= B; ++i) {
        if(!(i % K)) {
            suc = true;
            break;
        }
    }
    std::cout << (suc ? "OK" : "NG") << std::endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<pair<string,int>>p(n);
    rep(i,n){
        string s; int t;
        cin>>s>>t;
        p[i]=make_pair(s,t);
    }
    string ss; cin>>ss;
    int x;
    rep(i,n){
        if(ss==p[i].first)x=i;
    }
    int ans=0;
    for(int i=x+1; i<n; ++i){
        ans+=p[i].second;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

# In[1]:


H,W = map(int, input().split())
c = []
for _ in range(10):
    c.append(list(map(int, input().split())))
A = []
for _ in range(H):
    A.append(list(map(int, input().split())))


# In[3]:


def wf_func(mat):
    dist = mat
    for k in range(10):
        for i in range(10):
            for j in range(10):
                dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
    return dist


# In[5]:


dist = wf_func(c)
ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] != -1:
            ans += dist[A[i][j]][1]
print(ans)


# In[ ]:






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

int main()
{
    long long N;

    cin >> N;

    vector<long long> Lucas(87);

    Lucas.at(0) = 2;
    Lucas.at(1) = 1;

    for (int i = 2; i < 87; i++)
    {
        Lucas.at(i) = Lucas.at(i - 1) + Lucas.at(i - 2);
    }

    cout << Lucas.at(N) << endl;
}


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int max_house_gap(int K, int Num, int *house){
  int *gaps = new int[Num];
  for(int i = 0; i < Num; i++){
    if(i == Num-1){
      gaps[i] = house[0] + K - house[Num-1];
      continue;
    }
    gaps[i] = house[i+1] - house[i];
  }
  int maxgap = 0;
  for(int i = 0; i < Num; i++){
    if(gaps[i] > maxgap){
      maxgap = gaps[i];
    }
  }
  return maxgap;
}
 
int main(){
  int K,N;
  cin >> K;
  cin >> N;
  int *A = new int[N];
  for(int i = 0; i < N ; i++){
    cin >> A[i];
  }
  
  //家の間の最大値を求める。
  int gap = max_house_gap(K,N,A);
  
  cout << K - gap << endl;
  
  return 0;
}

Measured memory_bytes: 1792
type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.Scan2 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
  member this.Scan3 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))
  member this.Scan4 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2], a.[3]))
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f
  member this.ScanVecV n f = [| for i in 1..n -> stream.ReadLine() |> f |]
  member this.ScanMatrix n f  = [| for i in 1..n -> stream.ReadLine().Split() |> Array.map f |]
  member this.ScanCharMatrix n = [| for i in 1..n -> stream.ReadLine().ToCharArray() |]
  member this.Close () = stream.Close()

let util = ABC(stdin)

let analyze xs =
  let r = xs
          |> Array.countBy id
          |> Array.sortByDescending (fun (k,v) -> v)
  let n1, cnt1 = Array.head r
  let n2, cnt2 = Array.tryItem 1 r |> function | Some (a,b) -> (a,b) | None -> ("114514" , 0)
  (n1, cnt1, cnt2)



// 入力
util.Scan1 id |> ignore
let zs = util.ScanVecH id |> Array.chunkBySize 2
let xs = zs |> Array.map (Array.item 0)
let ys = zs |> Array.map (Array.item 1)

let n1, cnt1, cnt2 = analyze xs
let m1, cnt3, cnt4 = analyze ys
match n1 = m1 with
| false -> 2 * xs.Length - cnt1 - cnt3
| true -> 2 * xs.Length - cnt1 - (max cnt2 cnt4)
|> printfn "%d"

util.Close()


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

int main() {

	int W[10];
	int K[10];

	int i = 0;
	while (i<10) {
		cin >> W[i];
		i++;
	}

	while (i<20) {
		cin >> K[i-10];
		i++;
	}

	sort(W,W+10);
	sort(K,K+10);

	cout << W[7] + W[8] + W[9] << " " <<  K[7] + K[8] + K[9] << endl;

	return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define CLR(a) memset(a, 0, sizeof(a))
#define DBG(x) cout<<(#x)<<"="<<x<<endl
#define FOR(i, a, b)  for(int i=(a); i<(b); i++)
#define REP(i, a, b)  for(int i=(a); i<=(b); i++)
#define DOWN(i, a, b) for(int i=(a); i>=(b); i--)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1000000009;
const int N= 2e5 +10;

int n;
int a[N];
int tmp;
ll ans;
int ok=1;

int main() {
	cin>>n;
	REP(i, 1, n) {
		cin>>a[i];
	}
	tmp=0;
	DOWN(i, n, 2) {
		if (a[i]==tmp) {
			tmp--;
			continue;
		}
		if (a[i]<tmp) {
			ok=0;
			break;
		}
		if (a[i]>tmp) {
			ans+=a[i];
			tmp=max(tmp-1, a[i]-1);
		}
	}
	if (a[1]!=0||tmp>0) ok=0;
	if (!ok) cout<<-1<<endl;
	else cout<<ans<<endl;
	//cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<"\n";
	return 0;
}

Measured memory_bytes: 1024
from itertools import product
MOD = 10 ** 9 + 7

N = int(input())
dp = {}
for s in product('ATCG', repeat=3):
  dp[s] = int(s not in [('A','G','C'), ('G','A','C'), ('A','C','G'),])

for _ in range(3, N):
  ndp = {}
  for s in product('ATCG', repeat=3):
    if s[2] in ['A', 'T']:
      ndp[s] = sum([
        v for k,v in dp.items()
        if k[1] == s[0] and k[2] == s[1]
      ]) % MOD
    elif s[2] == 'G':
      ndp[s] = sum([
        v for k,v in dp.items()
        if (
          k[1] == s[0] and k[2] == s[1] and
          (k[1] != 'A' or k[2] != 'C')
        )
      ]) % MOD
    else:
      ndp[s] = sum([
        v for k,v in dp.items()
        if k[1] == s[0] and k[2] == s[1] and not (
          (k[1] == 'A' and k[2] == 'G') or
          (k[0] == 'A' and k[2] == 'G') or
          (k[1] == 'G' and k[2] == 'A') or
          (k[0] == 'A' and k[1] == 'G')
        )
      ]) % MOD
  dp = ndp
print(sum(dp.values()) % MOD)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define long long long
using namespace std;
int n,m;
string s;
char mat[55][55];
void check(int i,int j)
{
  if(mat[i+1][j]=='#')return ;
  if(mat[i-1][j]=='#')return ;
  if(mat[i][j+1]=='#')return ;
  if(mat[i][j-1]=='#')return ;
  cout<<"No"<<endl;
  exit(0);
}
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  for(int i=0;i<=51;i++)
    for(int j=0;j<=51;j++)
      mat[i][j]='.';

  cin>>n>>m;
  for(int i=1;i<=n;i++)
  {
    cin>>s;
    for(int j=1;j<=m;j++)
      mat[i][j]=s[j-1];
  }
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=m;j++)
    {
      if(mat[i][j]=='#')
        check(i,j);
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

const int INF = 1 << 29;

auto solve() {
    string X;
    cin >> X;
    stack<char> st;
    for(auto&&e:X) {
        if(e == 'T' && !st.empty() && st.top() == 'S') {
            st.pop();
        }else
            st.push(e);
    }

    return st.size();
}


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

    cout << solve() << endl;
//    solve();
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    long long A;
    long long a, b;
    priority_queue<long long> que;
    for(int i=0; i<N; i++){
        cin >> A;
        que.push(A);
    }

    bool flaga, flagb;
    flaga=false;
    flagb=false;
    a=que.top();
    que.pop();
    while(!que.empty()){
        A=que.top();
        que.pop();
        if(A==a){
            flaga=true;
            break;
        }else{
            a=A;
        }
    }
    if(flaga){
        b=que.top();
        que.pop();
        while(!que.empty()){
            A=que.top();
            que.pop();
            if(A==b){
                flagb=true;
                break;
            }else{
                b=A;
            }
        }        
    }
    if(flagb){
        cout << a*b << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 1400
#include<stdio.h>
#include<string.h>
int miru(int[][100],int*,int,int);
int ans=0,stack[100];
int main(){
  int i,j,n,a[100][100],mita[100],min;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    mita[i]=0;
    stack[i]=0;
  }
  for(i=0;i<n;i++)
  for(j=0;j<n;j++)
    scanf("%d",&a[i][j]);
  min=2001;
  mita[0]=1;
  stack[0]=0;
  for(i=1;i<n;i++){
    miru(a,mita,n,i);
  }
  printf("%d\n",ans);

}

int miru(int a[][100],int *mita,int n,int round){
  int j,i,min=2001,minnm,test;
  for(i=0;i<round;i++){
    for(j=0;j<n;j++){
      if(mita[j]==1)
	continue;
      if(min>a[stack[i]][j] && a[stack[i]][j] != -1){
	min=a[stack[i]][j];
	minnm=j;
	test = stack[i];
      }
    }
  }
  ans+=min;
  mita[minnm]=1;
  stack[round]=minnm;
  //  printf("%d -> %d  %d long  stack are",test,minnm,min);
  // for(i=0;i<round;i++) printf(" %d",stack[i]);
  // printf("\n");
  return 0;

}



Measured memory_bytes: 2112
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#include<cmath>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<list>
#include<deque>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<chrono>
#include<iomanip>

/*  auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
pr(duration.count());    */


#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define siz         100009
#define mp          make_pair
#define ll          long long int
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define pi          acos(-1.0)
#define all(x)      x.begin(),x.end()
#define ull		    unsigned long long int
#define m(a)	    memset(a,0,sizeof(a))
#define f(i,n)	    for(ll i=0;i<n;i++)
#define sc(a)	    scanf("%lld",&a)
#define pr(a)	    printf("%lld\n",a)
#define vll			vector<ll>
#define sll			set<ll>
const ll inf = 1000000000000000;
ll in = 1000000000000000000;
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

int main()
{
	FastIO;
	ll t, a, i, j, k, c, b, r,n;
	cin >> n;
	vll cost[100005], v[100005];
	f(i, n-1)
	{
		cin >> a >> b >> c;
		v[a - 1].push_back(b - 1);
		v[b - 1].push_back(a - 1);
		cost[a - 1].push_back(c);
		cost[b - 1].push_back(c);
	}
	bool d[100005];
	memset(d, false, sizeof(d));
	ll ans[100005];
	m(ans);
	d[0] = true;
	queue<ll>q;
	q.push(0);
	while (!q.empty())
	{
		ll u = q.front();
		q.pop();
		f(i, v[u].size())
		{
			if (d[v[u][i]] == false)
			{
				d[v[u][i]] = true;
				if (cost[u][i] % 2)
				{
					ans[v[u][i]] = (ans[u] + 1) % 2;
				}
				else
				{
					ans[v[u][i]] = ans[u];
				}
				q.push(v[u][i]);
			}
		}
	}
	f(i, n)
	{
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 16408
#include <stdio.h>

int main(void) {
    int a,b;
    int total = 0;
    scanf("%d",&a);
    scanf("%d",&b);
    for(int i = 0;i<2;i++) {
        if(a>b) {
            total = total + a;
            a -= 1;
        }else{
            total = total + b;
            b -= 1;
        }
    }
    printf("%d\n",total);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>

#define SIZE 3

struct Board {
	int array[SIZE][SIZE];
	int x0;
	int y0;
};

int distance(int a[][SIZE], int b[][SIZE])
{
	int res = 0;
	for (int i=0; i<SIZE*SIZE; i++) {
		int val = a[i/SIZE][i%SIZE];
		for (int j=0; j<SIZE*SIZE; j++) {
			if (b[j/SIZE][j%SIZE] == val) {
				res += abs((i/SIZE) - (j/SIZE)) + abs((i%SIZE) - (j%SIZE));
				break;
			}
		}
	}
	return res/2;
}

void copyBoard(int A[][SIZE], int B[][SIZE])
{
	for (int i=0; i<SIZE; i++) {
		for (int j=0; j<SIZE; j++) A[i][j] = B[i][j];
	}
}

void swap(int& x,int& y)
{
	int tmp = x;
	x = y;
	y = tmp;
}

bool DFS(Board b, Board goal, int step, int max_step, int pre_x0, int pre_y0)
{			
	if (distance(b.array, goal.array) + step > max_step) return false;
	if (distance(b.array, goal.array) == 0) return true;
	
	int x0 = b.x0;
	int y0 = b.y0;
	
	Board next;
	
	if (x0 > 0 && !(pre_x0 == x0 - 1 && pre_y0 == y0) ) {
		copyBoard(next.array, b.array);
		swap(next.array[x0-1][y0], next.array[x0][y0]);
		next.x0 = x0 - 1;
		next.y0 = y0;
		if (DFS(next, goal, step+1, max_step, x0, y0)) return true;
	}
	if (x0 < SIZE-1 && !(pre_x0 == x0 + 1 && pre_y0 == y0)) {
		copyBoard(next.array, b.array);
		swap(next.array[x0][y0], next.array[x0+1][y0]);
		next.x0 = x0 + 1;
		next.y0 = y0;
		if (DFS(next, goal, step+1, max_step, x0, y0)) return true;
	}
	if (y0 > 0 && !(pre_x0 == x0 && pre_y0 == y0 - 1)) {
		copyBoard(next.array, b.array);
		swap(next.array[x0][y0], next.array[x0][y0-1]);
		next.x0 = x0;
		next.y0 = y0 - 1;
		if (DFS(next, goal, step+1, max_step, x0, y0)) return true;
	}
	if (y0 < SIZE-1  && !(pre_x0 == x0 && pre_y0 == y0 + 1)) {
		copyBoard(next.array, b.array);
		swap(next.array[x0][y0], next.array[x0][y0+1]);
		next.x0 = x0;
		next.y0 = y0 + 1;
		if (DFS(next, goal, step+1, max_step, x0, y0)) return true;
	}
	return false;
}

int solve(Board init, Board goal, int lb_max_step)
{
	for (int max_step = lb_max_step; ; max_step++) {
		if ( DFS(init, goal, 0, max_step, init.x0, init.y0) ) return max_step;
	}
}
	
	
int main()
{
	Board init;
	
	for (int i=0; i<SIZE; i++) {
		for (int j=0; j<SIZE; j++) {
			std::cin >> init.array[i][j];
			if (init.array[i][j] == 0) {
				init.x0 = i, init.y0 = j;
			}
		}
	}
	
	Board goal;
	for (int i=0; i<SIZE; i++) {
		for (int j=0; j<SIZE; j++) {
			goal.array[i][j] = (SIZE*i+j+1) % (SIZE*SIZE);
		}
	}
	goal.x0 = SIZE-1;
	goal.y0 = SIZE-1;
	
	int distance_to_goal = distance(init.array, goal.array);
	
	int fewest_steps = solve(init, goal, distance_to_goal);
	
	std::cout << fewest_steps << std::endl;
	
	return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

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

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    int n;
    cin >> n;
    vector<int> cnt(n);
    rep(i, n) {
      int a;
      cin >> a;
      ++cnt[a];
    }
    int p = 0;
    if(n % 2) {
      if(cnt[0] != 1) {
        cout << 0 << endl;
        return 0;
      }
      rep(i, n) {
        if(i % 2 && cnt[i] != 0) {
          cout << 0 << endl;
          return 0;
        }
        else if(i % 2 == 0 && i != 0 && cnt[i] != 2) {
          cout << 0 << endl;
        }
      }
      p = n / 2;
    }
    else if(n % 2 == 0) {
      rep(i, n) {
        if(i % 2 && cnt[i] != 2) {
          cout << 0 << endl;
          return 0;
        }
        else if(i % 2 == 0 && cnt[i] != 0) {
          cout << 0 << endl;
          return 0;
        }
        p = n / 2;
      }
    }
    ll ans = 1;
    rep(i, p) {
      ans *= (ll) 2;
      ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3728
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    long long int a, b, c, d;
    long long int A, B, C, D, AB, CD, ans;
    cin >> a >> b >> c >> d;
    A = a * c;
    B = b * d;
    C = c * b;
    D = d * a;
    AB = max(A, B);
    CD = max(C, D);
    ans = max(AB, CD);
    cout << ans;
}

Measured memory_bytes: 3632