akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int h_dire[8]={-1,0,1,-1,1,-1,0,1};
int w_dire[8]={1,1,1,0,0,-1,-1,-1};
int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> field(h,vector<char>(w));
    rep(i,0,h){
        rep(j,0,w){
            cin >> field[i][j];
        }
    }
    rep(i,0,h){
        rep(j,0,w){
            if(field[i][j]=='.'){
                int bomb = 0;
                rep(k,0,8){
                    int nh = i+h_dire[k];
                    int nw = j+w_dire[k];
                    if(nh>=0&&nh<h&&nw>=0&&nw<w){
                        if(field[nh][nw]=='#'){
                            bomb++;
                        }
                    }
                }
                field[i][j]='0'+bomb;
                //cout<<field[i][j]<<endl;

            }
        }
    }
    rep(i,0,h){
        rep(j,0,w){
            cout<<field[i][j];
        }
        cout<<endl;
    }
  return 0;
}

Measured memory_bytes: 3632
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

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

	cin >> N;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	sort(v.begin(), v.end());
	long long int ans = 1;
	for (int i = 0; i < N; i++) {
		ans *= gcd(i, v[i]);
		ans %= MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3704
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int [] d = new int[n + 1];
        d[0] = 0;
        for (int i = 1; i <= n; ++i) {
            d[i] = scanner.nextInt();
        }
        Arrays.sort(d);
        for (int i = 0; i <= n; ++i) {
            if (i % 2 == 0) {
                d[i] = 24 - d[i];
            }
        }
        int min = 24;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                int diff = Math.abs(d[i] - d[j]);
                int current = Math.min(24 - diff, diff);
                min = Math.min(min, current);
            }
        }

        System.out.println(min);
    }
}


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

int main(){
    string moji;
    cin >> moji;
    if(moji.substr(2,1) == moji.substr(3,1) && moji.substr(4,1) == moji.substr(5,1)){
        cout <<"Yes";
    }else{
        cout <<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b,c,d,tmp[ohara],tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
unordered_map<ll,ll> mp;

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n){
        mp[a[i]]++;
        
    }
    ll cntt=0;
    cnt=2;
    rep(i,100){
        tmp[cntt++]=cnt;
        cnt*=2;
        if(cnt>=1000000000*2+100)break;
    }
    reverse(tmp,tmp+cntt);
    rep(i,cntt){
        rep(j,n){
            if(tmp[i]<a[j])continue;
            if(mp[a[j]]==0||mp[tmp[i]-a[j]]==0)continue;
            if(mp[tmp[i]-a[j]]>=1){
                if(a[j]==tmp[i]-a[j]){
                    if(mp[a[j]]>=2){
                        mp[a[j]]-=2;
                        ans++;
                    }
                }
                else{
                ans++;
                mp[a[j]]--;
                mp[tmp[i]-a[j]]--;
                //Cout(a[j]);
                }
            }
        }
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 32884
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

ll ufar[100010], ufs[100010];

priority_queue<ll, vector<ll>, greater<ll>> treeV[100010], alq;

void treemerge(int from, int to) {
	while (!treeV[from].empty()) {
		treeV[to].push(treeV[from].top());
		treeV[from].pop();
	}
}

void init(int n) {
	for (int i = 0;i < n;i++)ufar[i] = i, ufs[i] = 1;
	return;
}

int root(int n) {
	if (ufar[n] == n)return n;
	return ufar[n] = root(ufar[n]);
}

void unite(int x, int y) {
	x = root(x);
	y = root(y);
	if (x == y)return;
	if (ufs[x] < ufs[y]) {
		ufar[x] = y;
		ufs[y] += ufs[x];
		ufs[x] = 0;
		treemerge(x, y);
	}
	else {
		ufar[y] = x;
		ufs[x] += ufs[y];
		ufs[y] = 0;
		treemerge(y, x);
	}
}

int main() {
	ll N, M, A, x, y;
	cin >> N >> M;
	init(N);
	for (int i = 0;i < N;i++) {
		cin >> A;
		treeV[i].push(A);
	}
	for (int i = 0;i < M;i++) {
		cin >> x >> y;
		unite(x, y);
	}

	A = 0;
	ll comp = 0;
	for (int i = 0;i < N;i++) {
		if (treeV[i].empty())continue;
		comp++;
		A += treeV[i].top();
		treeV[i].pop();
		alq.push(0);
		while (!treeV[i].empty()) {
			alq.push(treeV[i].top());
			treeV[i].pop();
		}
	}
	//(comp-1)*2必要
	if (comp == 1) {
		cout << 0 << endl;
		return 0;
	}
	if (N < (comp - 1) * 2) {
		cout << "Impossible" << endl;
		return 0;
	}
	for (int i = 0;i < (comp - 1) * 2;i++) {
		A += alq.top();
		alq.pop();
	}
	cout << A << endl;
}

Measured memory_bytes: 11636
package main

import(
	"fmt"
  	"bufio"
  	"os"
  	"strconv"
)

func nestLine() string {
  sc.Scan()
  return sc.Text()
}
var sc = bufio.NewScanner(os.Stdin)
func main(){
  n,k,x,y := nestLine(),nestLine(),nestLine(),nestLine()
  N, _ := strconv.Atoi(n)//連泊回数2
  K, _ := strconv.Atoi(k)//k宿泊まで3
  X, _ := strconv.Atoi(x)//kまでの料金
  Y, _ := strconv.Atoi(y)//k+1以降の料金
  
  total_ageX := 0
  total_ageY := 0
  sti := N - K//K宿泊以降の日数
  if N < K {
  	K = N
  }
  for i := 1; i <= K; i++{//Kまでの料金
  	total_ageX += X
  }  
  
  if N > K {
    for p:=0; p < sti; p++{
       total_ageY += Y
    }
  }
  fmt.Println(total_ageX+total_ageY)

}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>


using namespace std;


int main(){

    int H, W;
    cin >> H >> W;

    char A[H][W];
    int cnt = 0;
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            cin >> A[i][j];
            if (A[i][j] == '#'){
                cnt++;
            }
        }
    }

    int ans = 1;
    
    bool f = true;
    int i = 0, j = 0;
    while(f == true){
        if (A[i + 1][j] == '#'){
            ans ++;
            i ++;
        }else if(A[i][j + 1] == '#'){
            ans ++;
            j ++;
        }else{
            f = false;
        }
    }
    
    if (ans == cnt){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll INF = 1000000007LL;
ll H, W;

ll calc(ll len1, ll len2){
  ll res = INF;
  ll a = len1/2;
  ll b = len1 - a;
  if (b>a){
    rep(i,len2){
      ll c1 = len1*i;
      ll c2 = (len2-i)*b;
      ll c3 = (len2-i)*a;
      // c2 > c3ではある
      ll d = c1>c2?c1-c3:max(c2-c3, c2-c1);
      res = min(res, d);
    }
  } else {
    rep (i, len2){
      res = min(abs(i*len1 - a*(len2-i)), res);
    }
  }
  return res;
}

ll calc2(ll len1, ll len2){
  ll res = INF;
  for (ll i=1; i*2<len1; i++){
    res = min(res, abs(i-(len1-2*i))*len2);
  }
  return res;
}


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

  cin >> H >> W;
  if (H%3==0 || W%3==0){
    cout << 0 << "\n";
    return 0;
  }

  ll ans = INF;
  
  ans = min(ans, calc(H, W));
  ans = min(ans, calc(W, H));
  ans = min(ans, calc2(H, W));
  ans = min(ans, calc2(W, H));
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
N, M = list(map(int, input().split()))
p = []
s = []
for _ in range(M):
    p_i, s_i = list(input().split())
    p += [int(p_i)]
    s += [s_i]

passed_problem = set()
penalty_problem = defaultdict(int)
for i, p_i in enumerate(p):
    if s[i] == 'WA':
        if not p[i] in passed_problem:
            penalty_problem[p[i]] += 1
    elif s[i] == 'AC':
        passed_problem.add(p[i])

# print(f"penalties:{penalty_problem}", file=sys.stderr)
penalty = 0
for n in passed_problem:
    penalty += penalty_problem[n]    

print("{} {}".format(len(passed_problem), penalty))

Measured memory_bytes: 30012
N = int(input())
eda = {}
for i in range(1, N+1):
    eda[i] = set()
for _ in range(N-1):
    a, b = map(int, input().split())
    eda[a].add(b)
    eda[b].add(a)
fennec = 0
snuke = 0
fenneccheck = set([1])
snukecheck = set([N])
checked = set([1, N])
while len(checked) < N:
    nextfennec = set()
    for i in fenneccheck:
        for j in eda[i]:
            if j in checked:
                continue
            checked.add(j)
            nextfennec.add(j)
            fennec += 1
    fenneccheck = nextfennec
    nextsnuke = set()
    for i in snukecheck:
        for j in eda[i]:
            if j in checked:
                continue
            checked.add(j)
            nextsnuke.add(j)
            snuke += 1
    snukecheck = nextsnuke
if fennec > snuke:
    print("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 50656
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define mp make_pair

/// easy access -------------
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<int,int> pii;
///-------------------------
/*
const int MAXN = 1e3+5;
vector<int> p;

void sieve()
{
    vector<bool> a(MAXN,false);
    for(int i=2; i<=MAXN; ++i)
    if (!a[i])
    {
        p.pb(i);
        for(int j=i; j<=MAXN/i; ++j)
            a[j*i]=true;
    }
    for(int x:p) cout << x << '\n';
}
*/
int main()
{
    Phuong_;
    ll n,k;
    cin >> n >> k;
    n%=k;
    cout << min(n,k-n);
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
    static int mod=1000000007;
    public static void main(String args[]) {
       Scanner sc=new Scanner(System.in);
       int h=sc.nextInt();
       int w=sc.nextInt();
       char grid[][]=new char[h+1][w+1];
       for(int i=1;i<=h;i++)
       {
           char ch[]=sc.next().toCharArray();
           for(int j=1;j<=w;j++)
           {
           grid[i][j]=ch[j-1];
          // System.out.print(grid[i][j]+ " ");
           }
          // System.out.println();
       }
      long dp[][]=new long[h+1][w+1];
     
      for(int i=1;i<=h;i++)
      {
          for(int j=1;j<=w;j++)
          {
              if(grid[i][j]=='#')
              dp[i][j]=0;
              else if(i==1 && j==1)
              dp[i][j]=grid[i][j]=='#'?0:1;
              else
              dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
          }
      }
      System.out.println(dp[h][w]%mod);
    }
}

Measured memory_bytes: 49664
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<pair<int, int>> v(n);
	vector<vector<int>> s(19, vector<int>(19));
	rep(i, n)
	{
		long double b; cin >> b;
		b *= 1000000000;
		ll a = (ll)floor(b + 0.5L);
		int x = 0, y = 0;
		while (a % 2 == 0 && x < 18)
		{
			a /= 2;
			++x;
		}
		while (a % 5 == 0 && y < 18)
		{
			a /= 5;
			++y;
		}
		v[i] = { x,y };
		++s[x][y];
	}
	ll res = 0;
	rep(i, n)
	{
		int x, y; tie(x, y) = v[i];
		--s[x][y];
		rep(j, 19)rep(k, 19)
		{
			if (j >= 18 - x && k >= 18 - y)res += s[j][k];
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 4688
#include<iostream>
using namespace std;
    
int main (){

    //input
    int A,B;
    cin >> A >> B;

    //process
    int result=0;
    if(A<6){
        result = 0;
    }else if(A>12){
        result = B;
    }else{
        result = B/2;
    }

    //output
    cout << result << endl;
    return 0;

}


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

typedef struct _team{
    int tid;
    int ac;
    int time;
    _team(){tid=ac=time=0;}
} Team;

bool cmp(Team& a, Team& b){
    if(a.ac == b.ac){
        if(a.time == b.time){
            return a.tid > b.tid;
        }else{
            return a.time < b.time;
        }
    }else{
        return a.ac > b.ac;
    }
}

int main(){
    while(1){
        int m,t,p,r;
        cin >> m >> t >> p >> r;
        if(m==0) break;

        int mi, ti, pi, ji;
        vector<vector<int> > pena(t, vector<int>(p, 0));
        vector<Team> info(t);
        for(int i=0; i<t; i++){
            info[i].tid = i+1;
        }
        
        for(int i=0; i<r; i++){
            cin >> mi >> ti >> pi >> ji;
            ti--;
            pi--;
            if(ji==0){
                info[ti].time += mi;
                info[ti].ac++;
                pena[ti][pi] = -pena[ti][pi];
            }else{
                pena[ti][pi] -= 20;
            }
        }
        for(int i=0; i<t; i++){
            for(int j=0; j<p; j++){
                if(pena[i][j]>0){
                    info[i].time += pena[i][j];
                }
            }
        }

        sort(info.begin(), info.end(), cmp);
        cout << info[0].tid;
        for(int i=1; i<t; i++){
            if(info[i].ac==info[i-1].ac && info[i].time==info[i-1].time){
                cout << "=";
            }else{
                cout << ",";
            }
            cout << info[i].tid;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b){return !b ? a : gcd(b, a % b);}
ll modP(ll a, ll b) {return (!b ? 1 : (modP(a, b / 2) * modP(a, b / 2) * (b % 2 ? a : 1)) % MOD);}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int a, b;
	cin >> a >> b;
	cout << max(2 * max(a, b) - 1, a + b) << endl;
	return 0;
}



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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

int main(){
#define int ll
  string s,t; cin >> s >> t;
  rep(i,sz(s)){
    bool f = true;
    rep(j,sz(s)){
      if(s[(i+j)%sz(s)] != t[j]){
	f = false;
	break;
      }
    }
    if(f){
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
    
}

Measured memory_bytes: 256
#include <iostream>
//#include "bits/stdc++.h"
#include <vector>
#include <stdlib.h>
#include <string>
#include <sstream>

using namespace std;

int main() {
	vector<string> x;

	while (true) {
		string xin;
		cin >> xin;
		if (xin == "0") break;
		x.push_back(xin);
	}

	int ans = 0;
	int stoi = 0;
	for (int i = 0; i < x.size();++i) {
		string str = x[i];
		for(int j = 0; j < str.size(); ++j){
			stoi = str[j]-'0';
			ans += stoi;
		}
		cout << ans << endl;
		ans = 0;
	}
	return 0;
}


Measured memory_bytes: 3172
import java.io.IOException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		while(true) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			if(x==0 && y==0) {
				break;
			}
			if(x>=y) {
				System.out.println(y + " " + x);
			}else {
				System.out.println(x + " " + y);
			}
		}

		sc.close();
	}
}


Measured memory_bytes: 34552
while True:
    
    H, W = map(int, input().split())
    
    if H == W == 0:
        break
        
    for i in range(H):
        for j in range(W):
            if i % 2 != 0:
                if j % 2 == 0:
                    print(".", end = "")
                else:
                    print("#", end = "")
                    
            else:
                if j % 2 != 0:
                    print(".", end = "")
                else:
                    print("#", end = "")
                    
        print("")
        
    print("")


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

using namespace std;

int main(){
	int H,W;
	cin >> H >> W;
	int ns[100];
	fill_n(ns,100,0);
	for(int i = 0;i < H;i++){
		for(int i = 0;i < W;i++){
			char c;
			cin>>c;
			ns[c-'a']++;
		}
	}
	// for(int i = 0;i < 4;i++){
	// 	cout << ns[i]<<" ";
	// }
	// cout << endl;
	bool ans = true;
	if(H%2==0 && W%2==0){///g*g
		for(int i = 0;i < 100;i++){
			if(ns[i]%4!=0)ans = false;
		}
	}else if(H%2==1 && W%2==1){///k*k
		int v = 0;
		for(int i = 0;i<100;i++){
			if(ns[i]%2==1){v++;ns[i]--;}
		}
		if(v != 1)ans = false;
		int me = ((W/2)+1)*((H/2)+1);
		int four = me-(W/2)-(H/2)-1;
		for(int i = 0;i < 100;i++){
			if(four==0)break;
			if(ns[i]!=0&&ns[i]>=4){
				four--;
				ns[i]-=4;
				i--;
			}
		}
		if(four!=0)ans = false;
		int two = (W/2)+(H/2);
		for(int i = 0;i < 100;i++){
			if(two==0)break;
			if(ns[i]!=0&&ns[i]%2==0){
				two--;
				ns[i]-=2;
				i--;
			}
		}
		if(two!=0)ans = false;
	}else if(H%2==0 && W%2==1){///g*k
		int me = ((W/2)+1)*(H/2);
		int four = me-(H/2);
		for(int i = 0;i < 100;i++){
			if(four==0)break;
			if(ns[i]!=0&&ns[i]>=4){
				four--;
				ns[i]-=4;
				i--;
			}
		}
		if(four!=0)ans = false;
		int two = (H/2);
		for(int i = 0;i < 100;i++){
			if(two==0)break;
			if(ns[i]!=0&&ns[i]%2==0){
				two--;
				ns[i]-=2;
				i--;
			}
		}
		if(two!=0)ans = false;
	}else if(H%2==1 && W%2==0){///k*g
		int me = (W/2)*((H/2)+1);
		int four = me-(W/2);
		for(int i = 0;i < 100;i++){
			if(four==0)break;
			if(ns[i]!=0&&ns[i]>=4){
				four--;
				ns[i]-=4;
				i--;
			}
		}
		if(four!=0)ans = false;
		int two = (W/2);
		for(int i = 0;i < 100;i++){
			if(two==0)break;
			if(ns[i]!=0&&ns[i]%2==0){
				two--;
				ns[i]-=2;
				i--;
			}
		}
		if(two!=0)ans = false;
	}
	cout << (ans?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
sc = [tuple(map(int,input().split())) for _ in range(M)]
sc = set(sc)
 
ans = -1
begin = 10**(N-1) - (1 if N == 1 else 0)
end = 10**N
for i in range(begin,end):
    num = str(i)
    for s,c in sc:
        if int(num[s-1]) != c:
            break
    else: ans = i
    if ans != -1:
        break
 
print(ans)

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

#include <boost/algorithm/string/classification.hpp>  // is_any_of
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/math/tools/minima.hpp>
#include <boost/multi_array.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>

const int MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)

namespace adaptor = boost::adaptors;
using namespace std;
using boost::irange;
using boost::algorithm::join;
using boost::algorithm::replace_all;
using boost::algorithm::split;
using boost::math::tools::brent_find_minima;
using boost::multiprecision::cpp_int;
using ll = long long;
using P = pair<int, int>;

// TOP
void Main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> V(n - 1);
	for (char c = 'a'; c <= 'z'; c++)
	{
		int start = INT_MAX;
		int end = -1;
		rep(i, n - 1)
		{
			if (s.at(i) == c)
			{
				start = i;
				break;
			}
		}
		for (int i = n - 1; i > 0; i--)
		{
			if (s.at(i) == c)
			{
				end = i - 1;
				break;
			}
		}
		for (int i = start; i <= end; i++)
			V.at(i)++;
	}
	auto it = max_element(V.begin(), V.end());
	cout << *it << endl;
}
// END

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

int main()
{
	string N;
	cin >> N;
	int ans = 0;
	for (char c : N) {
		if (c == '2')
			ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N := sc.nextInt()
	A := sc.nextIntSlice(N)
	count := make(map[int]int)
	for i := 0; i < N; i++ {
		count[A[i]]++
	}
	nums := []int{}
	for _, c := range count {
		if c > 1 {
			nums = append(nums, c-1)
		}
	}
	for i := 1; i < len(nums); i++ {
		nums[i] = abs(nums[i] - nums[i-1])
	}
	ans := len(count)
	if len(nums) > 0 && nums[len(nums)-1]%2 != 0 {
		ans--
	}

	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 7168
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<utility>
using namespace std;
#define MS(m,z) memset(m,z,sizeof(m))
typedef unsigned U;typedef long long ll;typedef pair<int,int > P;
void inp();
const int N = 1e5+100;
struct Node {
	int t,x,y;
}ps[N];
bool operator <(Node &a,Node &b){ return a.t<b.t; }
int main(){
#ifdef XS
	//freopen(".in","r",stdin);
#endif
	//int ttt;scanf("%d",&ttt);for(int i=1;i<=ttt;i++)
	inp();
	return 0;
}
void inp(){
	int n;scanf("%d",&n);
	for(int i =0;i<n;i++){
		scanf("%d%d%d",&ps[i].t,&ps[i].x,&ps[i].y);
	}
	ps[n++] = Node{0,0,0};
	sort(ps,ps+n);
	for(int i = 1;i<n;i++){
		int A = ps[i].t - ps[i-1].t;
		int B = abs(ps[i].x - ps[i-1].x) 
					+ abs(ps[i].y - ps[i-1].y);
		if(A <= 0 || A < B || (A - B)%2){
			puts("No");
			return ;
		}
	}
	puts("Yes");
}
//C.cc by xsthunder at Sun Jan 21 20:03:12 2018


Measured memory_bytes: 1280
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::*,
    std::{cmp::*, collections::*, convert::*, iter::*, marker::*, mem::*, ops::*},
};
fn main() {
    input! {//
        n:usize,
        q:usize,
        query:[(usize,Usize1);q],
    }
    let mut ans = (n - 2).pow(2);
    let mut row = BTreeMap::new();
    let mut col = BTreeMap::new();
    row.insert(n - 1, n - 2);
    col.insert(n - 1, n - 2);
    for &(qq, x) in query.iter() {
        match qq {
            1 => {
                let a = col.range(x..).next().unwrap();
                ans -= a.1;
                let mut k = row.entry(*(a.1)).or_insert(n - 1);
                *k = min(*k, x - 1);
            }
            _ => {
                let a = row.range(x..).next().unwrap();
                ans -= a.1;
                let mut k = col.entry(*(a.1)).or_insert(n - 1);
                *k = min(*k, x - 1);
            }
        };
    }
    println!("{}", ans);
}


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

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

int A[100005];

int main()
{
	int N;
	cin >> N;
	REP(i, N)
	{
		cin >> A[i];
	}

	ll ans = 0;
	REP(i, N)
	{
		if (i != 0 && A[i] != 0)
		{
			A[i] -= A[i - 1];
			ans += A[i - 1];
		}
		ans += A[i] / 2;
		A[i] %= 2;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        int splc = 0;
        var spl = input.ReadLine().Split(' ');
        var a = int.Parse(spl[splc++]);
        var b = int.Parse(spl[splc++]);

        var hb = Total(1, b - a);
        return hb - b;
    }

    static long Total(long n, long m) {
        var c = (n > m) ? n - m : m - n;
        return (n + m) * (c + 1) / 2;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


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

int main(){
  int D;
  cin >> D;
  if(D==25)
    cout << "Christmas" << endl;
  else if(D==24)
    cout << "Christmas Eve" << endl;
  else if(D==23)
    cout << "Christmas Eve Eve" << endl;
  else if(D==22)
    cout << "Christmas Eve Eve Eve" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 301000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
ll INF = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int N,M;
int a[2020],b[2020],c[2020];
struct edge{ int from,to,cost; };

int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--; c[i] *= -1;
    }
    ll dist[1010];
    for(int i = 0; i < N; i++) dist[i] = INF;
    dist[0] = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            int u = a[j];
            int v = b[j];
            if(dist[u] == INF) continue;
            if(dist[v] > dist[u] + c[j]) dist[v] = dist[u] + c[j];
        }
    }
    ll ans = dist[N-1];
    bool negative[1010];
    for(int i = 0; i < N; i++) negative[i] = false;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            int u = a[j];
            int v = b[j];
            if(dist[u] == INF) continue;
            if(dist[v] > dist[u] + c[j]){
                dist[v] = dist[u] + c[j];
                negative[v] = true;
            }
            if(negative[u]) negative[v] = true;
        }
    }
    if(negative[N-1]) cout << "inf" << endl;
    else cout << -ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>
int N, C;
int D[33][33];
int c[504][504];
long long ans;
std::map<int, int >mp[3];

void evaluate(std::vector<int > vec){
  int color[3];
  color[0]=vec[0];
  color[1]=vec[1];
  color[2]=vec[2];
  if (color[0]==color[1] || color[1]==color[2] || color[2]==color[0]){
    return;
  }
  long long sum=0;
  //printf("(%d, %d, %d)\n", color[0], color[1], color[2]);
  for (int i=0; i<3; i++){
    for (auto &entry: mp[i]){
      sum+=(long long)entry.second * D[entry.first][color[i]];
    }
  }
  ans = std::min(ans, sum);
  return;
}

void dfs(std::vector<int > vec){
  //printf("dfs%d called\n", vec.size());
  if (vec.size()==3){
    evaluate(vec);
  } else {
    for (int i=0; i<C; i++){
      //printf("i=%d\n", i);
      vec.push_back(i);
      dfs(vec);
      vec.pop_back();
    }
  }
  return;
}

int main(){
  scanf("%d", &N);
  scanf("%d", &C);
  for (int i=0; i<C; i++){
    for (int j=0; j<C; j++){
      scanf("%d", &D[i][j]);
    }
  }
  for (int i=0; i<N; i++){
    for (int j=0; j<N; j++){
      scanf("%d", &c[i][j]);
      c[i][j]--;
      mp[(i+j)%3][c[i][j]]++;
    }
  }
  
  std::vector<int > empty;
  ans = 1e15;
  dfs(empty);
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
 
signed main(){
    int N,L;cin>>N>>L;
    vector<string>V(N);
    REP(i,N)cin>>V[i];
    sort(V.begin(),V.end());
    string ans="";
    REP(i,N) ans+=V[i];
    cout<<ans<<endl;
}

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

int main(void){
  int h, a;
  cin >> h >> a;
  cout << (h+a-1)/a << endl;
  return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ul unsigned long long int
#define vi vector<int>
#define vl vector<int64_t>
#define all(x) x.begin(),x.end()
#define pb push_back
#define fo(x,a,b) for(int x=a; x<b; x++)
#define rfo(x,a,b) for(int x=a; x>=b; x--)
#define fi first
#define sec second
#define mp make_pair
int sgn(int x) { return x>0 ? 1 : ( x<0 ? -1 : 0); }
typedef pair<int,int> pairs;
double pi = 3.14159265358979323846;
ll mod = 1000000007;

void solve()
{
    ll x,d,k,ans=0;
    cin>>x>>k>>d;
    x=abs(x);
    ll z=x%d;
    ll zz=x/d;
    if(zz>=k)
    {
        ans=x-k*d;
    }
    else
    {
        if((k-zz)%2) ans=abs(d-z);
        else ans=z;
    }
    cout<<ans;
    cout<<"\n";
    return;
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    //cin>>t;
    //while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;
/**
 * @author yamato
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static int C(int a, int b) {
		b = Math.min(a-b,b);
		if (a==0||a==1)return 0;
		if (a==2)return 1;
		if (b==0)return 0;
		int i;
		int up = 1;
		for(i=0;i<b;i++) {
			up *= a-i;
		}
		int down = 1;
		for(i=1;i<=b;i++) {
			down *= i;
		}
		return up/down;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int ans = (C(n,2))+C(m,2);
		
		System.out.println(ans);
		
	}

}

Measured memory_bytes: 23252
#pragma GCC optimize(3)
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define db double
#define inf 200009
#define INF (ll)1e15
#define mod ((ll)1e9+7)
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;
int n,m;
 
struct edge{
    int y,nxt,w;
    edge(){}
    edge(int yy,int nn,int ww){
        y=yy,nxt=nn,w=ww;
    }
}e[inf*2];
int head[inf],ecnt;
 
void addedge(int x,int y,int z){
    ecnt++;
    e[ecnt]=edge(y,head[x],z);
    head[x]=ecnt;
    return;
}
 
ll cnt[3],cntp,cnte;
bool vis[inf];
int val[inf];
 
bool dfs(int u){
    vis[u]=1;
    cntp++;
    cnt[val[u]]++;
    int p=1;
    for (int i=head[u];i;i=e[i].nxt){
        int v=e[i].y;
        cnte+=(e[i].w>0);
        if (!vis[v]){
            val[v]=(val[u]+e[i].w+3)%3;
            if (!dfs(v)){
                p=0;
            }
        }
        else if (val[v]!=(val[u]+e[i].w+3)%3){
            p=0;
        }
    }
    return p;
}
 
int main(){
    rd(n) rd(m)
    int x,y;
    for (int i=1;i<=m;i++){
        rd(x) rd(y)
        addedge(x,y,1);
        addedge(y,x,-1);
    }
    ll ans=0;
    for (int i=1;i<=n;i++){
        if (!vis[i]){
            cnt[0]=cnt[1]=cnt[2]=0;
            cntp=cnte=0;
            int tmp=dfs(i);
            if (!tmp){
                ans+=cntp*cntp;
            }
            else if (cnt[0] && cnt[1] && cnt[2]){
                ans+=cnt[0]*cnt[1]+cnt[1]*cnt[2]+cnt[0]*cnt[2];
            }
            else{
                ans+=cnte;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

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

long long n;

int main() {
	cin >> n;
	long long l = 1, r = 100, lg = 0;
	for (long long i = 0; i <= 50; i++)
		if ((1ll << i) - 1 <= n)
			lg = i;
	n -= (1ll << lg) - 1;
	string s = "";
	for (long long i = 50; i >= 0; i--) {
		if (n >= (1ll << i)) {
			s = '1' + s;
			n -= (1ll << i);
			if (!lg)
				lg = i;
		}
		else
			s = '0' + s;
	}
	vector <int> res;
	for (int i = 1; i <= lg; i++) {
		if (s[i - 1] == '1') {
			res.push_back(r);
			r--;
		}
		res.push_back(i);
	}
	cout << 2 * res.size() << endl;
	for (int i = 1; i <= lg; i++)
		cout << i << " ";
	for (int i = r + 1; i <= 100; i++)
		cout << i << " ";
	for (int i = 0; i < res.size(); i++)
		cout << res[i] << " ";
	return 0;
}


Measured memory_bytes: 256
#coding:UTF-8

def Max(A):
    max=0
    for i in range(len(A)):
        if A[i]>max:
            max=A[i]
    return max

def CS(A,n):
    B=[]
    C=[]
    cn=Max(A)+1
    for i in range(n):
        B.append(0)
    for i in range(cn):
        C.append(0)
    for j in range(n):
        C[A[j]]+=1
    for i in range(1,cn):
        C[i]+=C[i-1]
    for j in reversed(range(n)):
        B[C[A[j]]-1]=A[j]
        C[A[j]]-=1
    for i in range(len(B)):
        B[i]=str(B[i])
    print(" ".join(B))
 
    
if __name__=="__main__":
    n=int(input())
    A=input().split(" ")
    for i in range(n):
        A[i]=int(A[i])
    CS(A,n)

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

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 a, b;
  cin >> a >> b;
  string s = "";
  rep(i,0,b) s += to_string(a);
  string t = "";
  rep(i,0,a) t += to_string(b);
  if(s < t) {
    cout << s << endl;
  }
  else {
    cout << t << endl;
  }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

const ll mod  = 1e9+7;
const db eps  = 1e-9 ;
const ll maxn = 1e5+1;
const ll inf  = LLONG_MAX;
const ll minf = LLONG_MIN;

#define mp make_pair
#define pb push_back
#define endl "\n"
#define deb(x) cerr << #x << " " << x << endl

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll x,ans,p=100;
    double r=1.01;
    cin >> x;

    for(ll i=1 ; i<4000 ; ++i)
    {
        ans = p + p/100;
        p = ans;

        if(ans >= x) 
        {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
} 

Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#define repeat(i,n)     for(int i=0; i<(n); ++i)
#define repeat1(i,n)    for(int i=1; i<=(n); ++i)
#define range(i,l,r)    for(int i=(l); i<(r); ++i)

using namespace std;
typedef long long llint;

int iin();
llint   lin();
double  fin();

int main() {
    char str[105];

    scanf("%s", str);
    int len = strlen(str), j;

    for(j=0; j<len && str[j]!='C'; ++j) ;
    if(j == len) {
        printf("No\n");
        return 0;
    }
    for(; j<len && str[j]!='F'; ++j) ;
    if(j == len) {
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    return 0;
}

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

int iin() {
    int x;
    scanf("%d", &x);
    return  x;
}

llint lin() {
    llint x;
    scanf("%lld", &x);
    return  x;
}

double fin() {
    double  x;
    scanf("%lf", &x);
    return x;
}


Measured memory_bytes: 256
#include <iostream> 
#include <climits>
#define ll long long
const ll M=1e9+7;
 using namespace std;

 ll powmod(ll a,ll b,ll mod) {
    ll res=1;a%=mod;
    //assert(b>=0);
    for(;b;b>>=1){
        if(b&1)res=res*a%mod;a=a*a%mod;
    }
    return res;
}

int main() 
{ 
  int n;
  cin>>n;
  ll ans=powmod(10,n,M);
  ll temp=2*powmod(9,n,M)-powmod(8,n,M);
  ans-=temp;
  ans%=M;
  cout<<(ans+M)%M<<'\n';

}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
class TreeDP{//c++11
	public:
	struct edge{
		int to,cost;
	};
	int n;
	vi dist;
	vector<vector<edge> >G;
	TreeDP(int size){
		n=size;
		dist=vi(n);
		G=vector<vector<edge> >(n);
	}
	void add_edge(int a,int b,int c){
		edge e={b,c},ee={a,c};
		G[a].pb(e);
		G[b].pb(ee);
	}
	void dfs1(int a,int par){
		rep(i,G[a].size()){
			edge e=G[a][i];
			if(e.to==par)continue;
			dfs1(e.to,a);
			dist[a]=max(dist[a],dist[e.to]+e.cost);
		}
	}
	int dfs2(int a,int d_par,int par){
		vp d_child;
		d_child.pb({0,-1});
		rep(i,G[a].size()){
			edge e=G[a][i];
			if(e.to==par)d_child.pb({d_par+e.cost,e.to});
			else d_child.pb({dist[e.to]+e.cost,e.to});
		}
		sort(d_child.rbegin(),d_child.rend());
		int ret=d_child[0].first+d_child[1].first;
		rep(i,G[a].size()){
			edge e=G[a][i];
			if(e.to==par)continue;
			ret=max(ret,dfs2(e.to,d_child[d_child[0].second==e.to].first,a));
		}
		return ret;
	}
	int dp(){
		dfs1(n/2,-1);
		return dfs2(n/2,0,-1);
	}
};
int main(){
	int n;
	cin>>n;
	TreeDP dp(n);
	rep(i,n-1){
		int a,b,c;
		cin>>a>>b>>c;
		dp.add_edge(a,b,c);
	}
	cout<<dp.dp()<<endl;
}

Measured memory_bytes: 15964
n = gets.to_i
town = gets.chomp.split.map(&:to_i)
hero = gets.chomp.split.map(&:to_i)

i = 0
count = 0

while i < n
	if town[i]+town[i+1] < hero[i]
		count += town[i]+town[i+1]
		town[i+1] = 0
	elsif town[i] < hero[i]
		town[i+1] = town[i+1]-(hero[i]-town[i])
		count += hero[i]
	else
		count += hero[i]
	end
	i += 1
end

puts count

Measured memory_bytes: 17564
#include <bits/stdc++.h>
#define fastIO ios::sync_with_stdio(NULL); cin.tie(NULL);

using namespace std;
const int N = 1E6+7;
typedef pair<int,int> ii;

vector<ii> adj[N];
long long f[N];
int n,m;

long long DFS(int u)
{
    long long &ret = f[u];
    if (ret != -1) return ret;
    ret = 0;
    
    for (int i = 0;i < (int)adj[u].size(); ++i)
    {
        int v = adj[u][i].first;
        int w = adj[u][i].second;
        f[u] = max(f[u],DFS(v) + w);
    }
return ret;
}

int main()
{
    fastIO
    cin>>n>>m;
    
    for (int i = 1;i <= m;++i)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(ii(v,1));
    }
    
    memset(f,-1,sizeof(f));
    long long res = 0;
    for (int i = 1;i <= n;++i) res = max(res,DFS(i));
    
    cout<<res;
}

Measured memory_bytes: 40040
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scn = new Scanner(System.in);
		long a = scn.nextLong();
		long b = scn.nextLong();
		long c = scn.nextLong();
		long k = scn.nextLong();
		System.out.println(Ret(a, b, c, k));
	}

	public static long Ret(long a, long b, long c, long k) {
		long ans = 0;
		while (a != 0) {
			ans = ans + 1;
			k = k - 1;
			a = a - 1;
			if (k <= 0) {
				return ans;
			}
		}
		k = k - b;
		while (k > 0) {
			ans = ans - 1;
			k = k - 1;
		}
		return ans;
	}

}

Measured memory_bytes: 35692
import java.io.*;
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int a[][] = new int[n][3];
    for(int i=0;i<n;i++){
      a[i][0] = in.nextInt();
      a[i][1] = in.nextInt();
      a[i][2] = in.nextInt();
    }
    int dp[][] = new int[n][3];
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];

    for(int i=1;i<n;i++){
      dp[i][0] = Math.max(dp[i-1][1], dp[i-1][2]) + a[i][0];
      dp[i][1] = Math.max(dp[i-1][0], dp[i-1][2]) + a[i][1];
      dp[i][2] = Math.max(dp[i-1][0], dp[i-1][1]) + a[i][2];
    }
    System.out.println(Math.max(Math.max(dp[n-1][0], dp[n-1][1]),dp[n-1][2]));
  }
}

Measured memory_bytes: 96920