akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n, i;
	cin >> n >> i;
	cout << n-i+1 << endl;
	return 0;
}

Measured memory_bytes: 256
//含有标记的线性搜索可以将算法效率提高常数倍
//for(int i=0;i<n;i++)
//s[n]==key;while(s[i]!=key)i++;if(i!=n)
//区别在于主循环中比较运算的次数 
#include<iostream>
#include<cstdio>
using namespace std;
int s[100005];
int cnt,n;
/*void LinearSearch(int s[],int num)
{
	for(int i=0;i<n;i++)
	{
		if(s[i]==num)
		{
			cnt++;
			break;
		}	
	}
}*/
int BinarySearch(int key)
{
	int left=0;
	int right=n;
	while(left<right)
	{
		int mid=(left+right)/2;
		if(s[mid]==key)
		{
			//cout<<"1"<<endl; 
			return 1;
		}
		else if(key<s[mid])//前半部分 
		{
			right=mid;
		}	
		else //后半部分 
		{
			left=mid+1;
		}
	}
	return 0;	
} 
int main()
{
	scanf("%d",&n);
	for(int k=0;k<n;k++)
	{
		scanf("%d",&s[k]);
		//cin>>s[k];
	}
	int q;
	scanf("%d",&q);
	while(q--)
	{
		int nn;
		//cin>>nn;
		scanf("%d",&nn);
		if(BinarySearch(nn))
		{
			cnt++;
			//cout<<nn<<endl;
	}
		
	} 
	cout<<cnt<<endl;
	return 0;
}


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

using namespace std;
using ll = long long;
int main() {
    int n,m,x;
    cin >> n >> m >> x;
    int arr[n][m];
    int c[n];
    int i,j;
    for(i=0;i<n;i++)
    {
        cin >> c[i];
        for(j=0;j<m;j++)
            cin >> arr[i][j];
    }
    bool ok = 0;
    int ans = 1000000000;
    for(i=0;i<(1<<n);i++)
    {
        int j, cost = 0;
        int sum[m] = {0};
        for(j=0;j<n;j++)
        {
            if(((i>>j)&1))
            {
                for(int k = 0;k<m;k++)
                    sum[k]+=arr[j][k];
                cost+=c[j];
            }
        }
        for(j=0;j<m;j++)
        {
            if(sum[j] < x)
                break;
        }
        if(j == m)
        {
            ok = 1;
            ans = min(ans, cost);
        }
    }
    if(!ok)
        cout << -1;
    else
        cout << ans;
}

Measured memory_bytes: 3632
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
#include <iterator>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
// 大きい順
#define rall(v) v.rbegin(), v.rend()
#define vi vector<int>
#define vl vector<ll>
const  long long INF = 1LL << 60;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}



int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }

    return true;
}

map<ll,ll> mp;

auto findFactors(ll num){
	
    ll i;
    while (num % 2 == 0){ // 偶数の素数は2のみ
        if(mp.count(2)){
			mp[2] = mp[2] + 1;
		}
		else{
			mp[2] = 1;
		}
        num /= 2;
    }
    for (i = 3; i <= num; i++){ // 他の素数で割っていく
        while (num % i == 0){
			if(mp.count(i)){
			mp[i] = mp[i] + 1;
		}
		else{
			mp[i] = 1;
		}
            num /= i;
        }
    }
    return 0;
}
ll kaizyou(ll n){
    if(n == 1){
        return 1;
    }
    else{
        return (n * kaizyou(n-1)) % 1000000007;
    }
}



int main(){
int W,a,b; cin >> W >> a >> b;
int ans = 0;
if(b >= a){
    chmax(ans,b-a-W);
}
else{
    chmax(ans,a-b-W);
}
cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

#define MAX_N 10000
struct edge {int to, cap, rev;};
vector<edge> G[MAX_N+1];
bool used[MAX_N+1];

void add_edge(int from, int to, int cap) {
  G[from].push_back((edge){to, cap, (int)G[to].size()});
  G[to].push_back((edge){from, 0, (int)G[from].size()-1});
}

int dfs(int v, int t, int f) {
  if(v == t) return f;
  used[v] = true;
  REP(i, G[v].size()) {
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if(d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t) {
  int flow = 0;
  while(true) {
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0) return flow;
    flow += f;
  }
}

signed main(void)
{
  int v, e;
  cin >> v >> e;
  REP(i, e) {
    int p, q, c;
    cin >> p >> q >> c;
    add_edge(p, q, c);
  }

  cout << max_flow(0, v-1) << endl;

  return 0;
}

Measured memory_bytes: 3404
sa = str(input())
sb = str(input())
sc = str(input())
turn = 1
while True:
    if turn == 1 and len(sa) == 0:
        print("A")
        break
    elif turn == 2 and len(sb) == 0:
        print("B")
        break
    elif turn == 3 and len(sc) == 0:
        print("C")
        break
    if turn == 1:
        if sa[0] == "a":
            turn = 1
        elif sa[0] == "b":
            turn = 2
        else:
            turn = 3
        sa = sa[1:]
    elif turn == 2:
        if sb[0] == "a":
            turn = 1
        elif sb[0] == "b":
            turn = 2
        else:
            turn = 3
        sb = sb[1:]
    else:
        if sc[0] == "a":
            turn = 1
        elif sc[0] == "b":
            turn = 2
        else:
            turn = 3
        sc = sc[1:]

Measured memory_bytes: 9080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main
{

	public static void main(String[] args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str;
		while((str=br.readLine())!=null)
		{
			int n=Integer.parseInt(str);
			int ans=0;
			if(n>36){}
			else
			{
				for(int i=0;i<=9;i++)
				{
					for(int j=0;j<=9;j++)
					{
						for(int k=0;k<=9;k++)
						{
							for(int l=0;l<=9;l++)
							{
								if(i+j+k+l==n){ans++;}
							}
						}
					}
				}
			}
			System.out.println(ans);

		}
	}

}

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

int main() {
	ios_base::sync_with_stdio( false );

	string S;
	int64_t K;
	cin >> S >> K;

	int i = 0;
	char ch = '?';
	for( ; i < S.size(); ++i ) {
		if( S[i] != '1' ) {
			ch = S[i];
			break;
		}
	}

	cout << (K <= i ? '1' : ch) << endl;

	return 0;
}


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

int main()
{
    int t;
    //cin>>t;

   // while(t--){
    int n;
    cin>>n;


    int x = n%1000;


    if(n%1000==0) cout<<0<<endl;
    else       cout<<abs(1000-x)<<endl;


  //  }
    return 0;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1000000007;
vl a1(55);
vl sousuu,pat;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
ll solve(ll a,ll x) {
  if(x==0) return 0;
  if(a < 2) return a1[x];
  if(x <= sousuu[a-2]) return solve(a-1,x-1);
  else if(x == sousuu[a-2]+1) return pat[a-2] + 1;
  //else if(x >= sousuu[a-1]-1) return pat[a-1];
  else return solve(a-1,x-sousuu[a-2]-2) + pat[a-2] + 1;
}
int main(){
  ll n,x;
  cin >> n >> x;
  sousuu.assign(n,0),pat.assign(n,0);
  sousuu[0] = 5;
  pat[0] = 3;
  a1[0] = 0;
  a1[1] = 1;
  a1[2] = 2;
  a1[3] = 3;
  a1[4] = 3;
  for(int i = 5;i<55;i++) {
      a1[i] = 3;
  }
  REP(i,n-1) {
    sousuu[i+1] = 2 * sousuu[i] + 3;
    pat[i+1] = 2 * pat[i] + 1;
  }
  cout << solve(n,x-1) << endl;
  
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

template<typename T>
struct is_vector : false_type{};

template<typename T>
struct is_vector<vector<T>> : true_type{};

template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) {
    return ostr;
  }
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    if (is_vector<T>()) ostr << "\n" << *itr;
    else ostr << ' ' << *itr;
  }
  return ostr;
}

template<typename T>
bool CompareBySecond(pair<T, T> a, pair<T, T> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

template<typename T>
T GCD(T a, T b) {
  T c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

void solve() {
  int n; cin >> n;
  vi arr(n);
  rep(i,n) cin >> arr[i];

  vi Ldp(n), Rdp(n);

  Ldp[0] = arr[0];
  rep(i,n-1) {
    Ldp[i+1] = GCD<int>(arr[i+1], Ldp[i]);
  }

  Rdp[n-1] = arr[n-1];
  rrep(i,n-1) {
    Rdp[i] = GCD<int>(arr[i], Rdp[i+1]);
  }

  int ans = max(Ldp[n-2], Rdp[1]);
  rep(i,n-2) {
    ans = max(ans, GCD<int>(Ldp[i], Rdp[i+2]));
  }
  cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>

int main()
{
    int w,h,x,y;int c=0;

    scanf("%d %d %d %d",&w,&h,&x,&y);

    if(x+x == w && y+y == h)
        c = 1;

printf("%lf %d\n",(double)w*(double)h/2,c);
    return 0;
}

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

void dfs(vector<int> &output, int n) {
	if (n == N) {
		for (int i = 0; i < N; i++) {
			cout << char(output[i] + 'a');
		}
		cout << endl;
		return;
	}

	if (n == 0) {
		output[0] = 0;
		dfs(output, 1);
		return;
	}

	int max = 0;
	for (int i = 0; i < n; i++) {
		if (max < output[i]) {
			max = output[i];
		}
	}
	for (int i = 0; i <= max + 1; i++) {
		output[n] = i;
		dfs(output, n + 1);
	}
}

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

	//calculation
	vector<int> output(N);
	dfs(output, 0);

	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > g[100005];
int ans[100005];
void dfs(int x,int col)
{
	ans[x]=col;
	for(int i=0;i<g[x].size();i++)
		if(g[x][i].second%2==0&&ans[g[x][i].first]==-1)
			dfs(g[x][i].first,col);
		else if(g[x][i].second%2==1&&ans[g[x][i].first]==-1)
			dfs(g[x][i].first,abs(col-1));
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n-1;i++)
	{
		int u,v,w;
		cin>>u>>v>>w;
		g[u].push_back(make_pair(v,w));
		g[v].push_back(make_pair(u,w));
		ans[i]=-1;
	}
	ans[n]=-1;
	dfs(1,0);
	for(int i=1;i<=n;i++)
		cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 9088
# -*- coding: utf-8 -*-
import numpy as np
n = int(input())
nums = input().split()
nums = [int(nums[i]) for i in range(0, len(nums))]

odd = 0
even = 0
for i in range(0, len(nums)):
    if nums[i] % 2 == 0:
        even += 1
    else:
        odd += 1
if odd % 2 == 0:
    print("YES")
else:
    print("NO")

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

int main() {
    int N, K;
    int kb = 0;

    cin >> N >> K;
    for (int i = 0; i < K; i++) {
        int k;
        cin >> k;
        kb |= (1<<k);
    }

    int ans = N;
    while (1) {
        int a = ans;
        bool flag = true;
        while (a) {
            if (kb & (1<<(a%10))) {
                ans++;
                flag = false;
                break;
            }
            a /= 10;
        }
        if (flag) {
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
ll N;

int main() {
  INCANT;
  cin >> N;
  for (ll h=1; h<=3500; h++) {
    for (ll n=h; n<=3500; n++) {
      ll Nhn = N*h*n;
      ll bunbo = 4*h*n-N*n-N*h;
      if (bunbo==0) continue;
      if (Nhn%bunbo==0) {
        ll w = Nhn/bunbo;
        if (w>=0) {
          cout << h << ' ';
          cout << n << ' ';
          cout << w << endl;
          return 0;
        }
      }
    } 
  } 
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define l first
#define r second

using namespace std;

const int maxn = 3002, mod = 998244353;

int dp[maxn][2 * maxn], sf[maxn];
pair<int, int> v[maxn];
int n, t;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> t; --t;
    for (int i = 0; i < n; i++)
        cin >> v[i].l >> v[i].r;
    sort(v, v + n);
    for (int i = 0; i < n; i++) {
        for (int x = 0; x <= t + maxn; x++)
            dp[i + 1][x] = dp[i][x];
        for (int x = 0; x <= t; x++) {
            dp[i + 1][x + v[i].l] = max(dp[i + 1][x + v[i].l],
                                      dp[i][x] + v[i].r);
        }
    }
    int ans = 0;
    for (int x = 0; x <= t + maxn; x++)
        ans = max(ans, dp[n][x]);
    cout << ans;
    return 0;
}


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

ll Get(ll A,ll index){
  if(index>=A)return index+1;
  else return index;
}

bool check(ll A,ll B,ll mid){
  /*
    if( mid < 1000 ){
    for(ll i=1;i<=mid;i++){
      ll ap=Get(A,i);
      ll bp=Get(B,mid+1-i);
      if(ap*bp>=A*B)return false;
    }
  */
  for( ll i= mid/2 - 10000 ; i <= mid/2 + 10000 ; i ++){
    if(i<1 || i>mid)continue;
    ll ap=Get(A,i);
      ll bp=Get(B,mid+1-i);
      if(ap*bp>=A*B)return false;
  }

    
  return true;
}

ll solve(ll A,ll B){
  ll left=0;
  ll right=A+B;
  while(right-left>1){
    ll mid=(left+right)/2;
    if( check(A,B,mid) )left=mid;
    else right=mid;
  }
  return left;
}

int main(){
  int Q;
  cin>>Q;
  while(Q--){
    ll A,B;
    cin>>A>>B;
    cout<<solve(A,B)<<endl;
  }
  return 0;
}


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

int main(){
  vector<int> vec(3);
  cin>>vec[0]>>vec[1]>>vec[2];
  sort(vec.begin(), vec.end());
  cout<<abs(vec[0]-vec[1])+abs(vec[1]-vec[2])<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(void) {
  string s;
  int c[26]={0};
  cin>>s;
  for(int i=0; s[i]!='\0'; i++) {
    if(c[s[i]-'a']==0) c[s[i]-'a']=1;
  }
  for(int i=0; i<26; i++) {
    if(c[i]==0) {
      char ch = 'a'+i;
      cout<<ch<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
  return 0;
}


Measured memory_bytes: 512
<?php
$inputs = explode(' ', trim(fgets(STDIN)));
$sx = $inputs[0];
$sy = $inputs[1];
$tx = $inputs[2];
$ty = $inputs[3];
$ans = '';
$root_x = $tx - $sx;
$root_y = $ty - $sy;

for($i = 0; $i < $root_y; $i++) $ans .= 'U';
for($i = 0; $i < $root_x; $i++) $ans .= 'R';
for($i = 0; $i < $root_y; $i++) $ans .= 'D';
for($i = 0; $i < $root_x; $i++) $ans .= 'L';
$ans .= 'L';
for($i = 0; $i < $root_y + 1; $i++) $ans .= 'U';
for($i = 0; $i < $root_x + 1; $i++) $ans .= 'R';
$ans .= 'DR';
for($i = 0; $i < $root_y + 1; $i++) $ans .= 'D';
for($i = 0; $i < $root_x + 1; $i++) $ans .= 'L';
$ans .= 'U';
echo $ans;
?>

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  char ss[n], tt[n];
  for(int i=0; i<n; i++) {
    cout << s.at(i) << t.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string.h>
using namespace std;
int main() 
{
	long long int k;
	int tok,rec;
	char str[100],st;
	while(cin>>str>>k)
	{
		rec=0;
		if(strlen(str)==1&&str[0]=='1'&&k==1)
		{
			cout<<1<<endl;
			continue;
		}
		for(int i=0;i<strlen(str);i++)
		{
			if(str[i]=='1')
			{
				rec++;
			}
		} 
		if(rec==strlen(str))
		{
			cout<<1<<endl;
			continue;
		}
		for(int i=0;i<strlen(str);i++)
		{
			if(str[i]-'0'!=1)
			{
				tok=i+1;
				st=str[i];
				break;
			}
		} 
		if(k<tok)
		{
			cout<<1<<endl;
		}
		else cout<<st<<endl;
	}
	return 0;
}

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

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

    vector<long long int> data(N);
    int flag = 0;

    for(long long int i = 0; i < N; i++){
        long long int tmp; cin >> tmp;
        data[i] = tmp;
        if(tmp == 0) flag = 1;
    }
    
    long long int ans = data[0];
    for(long long int i = 1; i < N; i++){
        if(flag == 1){
            ans = 0;
            break;
        }
        if(ans <= 1000000000000000000 / data[i]) ans = ans * data[i];
        else{
            ans = -1;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4044
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int H,W; cin >> H >> W;
    char a[H][W]; REP(i,H)REP(j,W) cin >> a[i][j];
    REP(i,W+2) cout << '#';
    cout << endl;
    REP(i,H){
        cout << '#';
        REP(j,W) cout << a[i][j];
        cout << '#' << endl;
    }
    REP(i,W+2) cout << '#';
    cout << endl;
    return 0;
}

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

using namespace std;

int main(){

	int A, B, C;
	cin >> A >> B >> C;

	if(A==B){
		cout << C <<endl;
	}

	if(B==C){
		cout << A <<endl;
	}

	if(A==C){
		cout << B <<endl;
	}
}

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

using namespace std;
#define ll long long
#define repX(i,j,n)for (ll i = j; i < n; i++)
#define rep(i, n) repX(i,0,n)


int main()
{
    ll n,k;
    string s;
    
    cin >>n>>k>>s;
    
    char &target = s[k-1];
    
    switch(target)
    {
        case 'A':
            target = 'a';
            break;
        case 'B':
            target = 'b';
            break;
        case 'C':
            target = 'c';
            break;
    }
    
    cout << s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

#include<unistd.h>
struct Buffer{
    enum { chunk = 1 << 16 };
    int idx;
    char buf[chunk];
    Buffer(){ init(); }
    void init(){ idx = 0; read(0, buf, chunk); }
    void check(){ if(idx == chunk){ init(); } }
    int next(){
        static char notDigits[256] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1, 0,0,0,0,0,0,0,0,0,0,};
        int ret = 0, sign = 1;
        while(check(), notDigits[(int)buf[idx]]){ idx++; }
        if(check(), buf[idx] == '-'){ sign = -1; idx++; }
        while(check(), !notDigits[(int)buf[idx]]){ ret = ret * 10 + buf[idx++] - '0'; }
        return sign * ret;
    }
};
struct FastInput {
    Buffer buf;
    template <class T>
    FastInput& operator >> (T& num) { num = buf.next(); return *this; }
    void tie(int){ }
    template <class S, class T>
    friend FastInput& operator >> (FastInput& in, pair<S, T>& p){ return in >> p.first >> p.second; }
    template <class T>
    friend FastInput& operator >> (FastInput& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
};
FastInput fin;
#define cin fin

int accs[501][501];
int main(){
    int n, m, q;
    cin >> n >> m >> q;
    // vector<vector<int>> accs(n, vector<int>(n));
    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        l--; r--;
        accs[0][r]++;
        accs[l + 1][r]--;
        // for(int i = 0; i <= l; i++){
        //     accs[i][r]++;
        // }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i + 1 < n){ accs[i + 1][j] += accs[i][j]; }
            if(j){ accs[i][j] += accs[i][j - 1]; }
        }
    }
    // for(int j = 0; j < n; j++){
    //     for(int i = 1; i < n; i++){
    //         accs[i][j] += accs[i - 1][j];
    //     }
    // }
    // for(int i = 0; i < n; i++){
    //     for(int j = 1; j < n; j++){
    //         accs[i][j] += accs[i][j - 1];
    //     }
    // }
    for(int i = 0; i < q; i++){
        int p, q;
        cin >> p >> q;
        p--; q--;
        cout << accs[p][q] << '\n';
    }
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  int a, b, s = 0;
  cin >> a >> b;
  
  for (int i = 0; i < a; i ++)
    s = s + i;

  for (int i = 0; i < b; i ++)
    s = s + i;

  
  cout << s << endl;
}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main(){
  ll L;cin>>L;
  double ans = (double)L/3;
  printf("%.12lf\n", ans*ans*ans);
}
  


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const ll inf = 2e11 + 7;

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

int main_wa(int n, int w, ll ww[], ll v[]) {
    const int mmax = 100 * 1000;
    ll val[mmax + 1]; rep(i, mmax + 1) val[i] = inf;
    val[0] = 0;
    rep(i, n) {
        
        for (int j = mmax; j >= 0; --j) {
            if (val[j] != inf) {
                val[j + v[i]] = min(val[j + v[i]], val[j] + ww[i]);
            }
        }
    }
    for (int i = mmax; i >= 0; --i) {
        if (val[i] != inf && val[i] <= (ll)w) {return i;}
    }
    return -1;
}

/*

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

const int MAX_N = 110;
const int MAX_V = 100100;



// DPテーブル
long long dp[MAX_N][MAX_V];

ll main_ac(int N, int W, ll weight[], ll value[]) {
    
    // 初期化
    for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF;
    
    // 初期条件
    dp[0][0] = 0;
    
    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
            
            // i 番目の品物を選ぶ場合
            if (sum_v - value[i] >= 0) chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
            
            // i 番目の品物を選ばない場合
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }
    
    // 最適値の出力
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    return res;
}

random_device rnd;
mt19937 mt(rnd());
uniform_int_distribution<> rand100(1, 100);
uniform_int_distribution<> rand200(1, 1e9);
uniform_int_distribution<> rand300(1, 1000);

 */

int main() {
    /*
    int n = rand100(mt), w = rand200(mt);
    ll ww[n], v[n];
    rep(i, n) ww[i] = rand200(mt), v[i] = rand300(mt);
     
    cout << main_wa(n, w, ww, v) << endl;
    cout << main_ac(n, w, ww, v) << endl;
    if (main_wa(n, w, ww, v) != main_ac(n, w, ww, v) ) {
        
        cout << n << " " << w << endl;
        rep(i, n) cout << ww[i] << " " << v[i] << endl;
    }
    cout << -1 << endl;
     */
    
    int n, w; cin >> n >> w;
    ll ww[n], v[n];
    rep(i, n) cin >> ww[i] >> v[i];
    cout << main_wa(n, w, ww, v) << endl;
}


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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef long long int ll;

using namespace std;
using Data = pair<long long, tuple<ll, ll, ll>>;

ll A[1001], B[1001], C[1001];
int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  REP(i, X) cin >> A[i];
  REP(i, Y) cin >> B[i];
  REP(i, Z) cin >> C[i];

  sort(A, A + X, greater<ll>());
  sort(B, B + Y, greater<ll>());
  sort(C, C + Z, greater<ll>());

  priority_queue<Data> que;
  set<tuple<int, int, int>> se;

  que.push(Data(A[0] + B[0] + C[0], make_tuple(0, 0, 0)));
  REP(i, K) {
    auto e = que.top();
    que.pop();
    cout << e.first << endl;
    ll idxA = std::get<0>(e.second);
    ll idxB = std::get<1>(e.second);
    ll idxC = std::get<2>(e.second);
    if (idxA + 1 < X) {
      ll sum = e.first - A[idxA] + A[idxA + 1];
      tuple<int, int, int> t = make_tuple(idxA + 1, idxB, idxC);
      Data d = Data(sum, t);
      if (!se.count(t)) {
        se.insert(t);
        que.push(d);
      }
    }
    if (idxB + 1 < Y) {
      ll sum = e.first - B[idxB] + B[idxB + 1];
      tuple<int, int, int> t = make_tuple(idxA, idxB + 1, idxC);
      Data d = Data(sum, t);
      if (!se.count(t)) {
        se.insert(t);
        que.push(d);
      }
    }
    if (idxC + 1 < Z) {
      ll sum = e.first - C[idxC] + C[idxC + 1];
      tuple<int, int, int> t = make_tuple(idxA, idxB, idxC + 1);
      Data d = Data(sum, t);
      if (!se.count(t)) {
        se.insert(t);
        que.push(d);
      }
    }
  }
}

Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
int h,w,n,a[10010],b[111][111];
int main(){
	scanf("%d%d%d",&h,&w,&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	int pen=0,now=1;
	for(int i=1;i<=h;++i){
		if(i%2==1){
			for(int j=1;j<=w;++j){
				++pen;
				b[i][j]=now;
				if(pen==a[now]){
					++now;
					pen=0;
				}
			}
		}
		else{
			for(int j=w;j>=1;--j){
				++pen;
				b[i][j]=now;
				if(pen==a[now]){
					++now;
					pen=0;
				}
			}
		}
	}
	for(int i=1;i<=h;++i){
		for(int j=1;j<w;++j){
			printf("%d ",b[i][j]);
		}
		printf("%d\n",b[i][w]);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  long double n,m,d;
  cin >> n >> m >> d;
  long double ans;
  if (d == 0) {
    ans = (m-1)/n;
  }
  else {
    ans = 2*(n-d)*(m-1)/(n*n);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
int main()
{
    int a,b,i;
    //string str1="",str2="";
    cin >> a >> b;
    if(a<b)
    {
        for(i=0;i<b;i++)
        {
            cout << a;
        }
    }
    else
    {
        for(i=0;i<a;i++)
        {
            cout << b;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
const ll INF=1e15;
#define int long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false)
const double pi = acos(-1.0);
int gcd (int a, int b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
int lcm (int a, int b) {
    return a / gcd(a, b) * b;
}

long long binpows(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)  //impar
            res = res * a;
        a = a * a;
        b >>= 1;  // /2
    }
    return res;
}
const int mod=1e9+7;
int binpow(int a, int b, int m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
//CHECAR SE PRECISA DE LONG LONG
vector<pair<int,int> > v;
int dp[123][123456];
int wq,n;
int resolve(int pos, int w){
	if(pos==n)
		return 0;
	int &x=dp[pos][w];
	if(x!=-1){
		return x;
	}
	x=0;
	x=max(x,resolve(pos+1,w));
	if(w-v[pos].first>=0){
		x=max(x,resolve(pos+1,w-v[pos].first)+v[pos].second);
	}
	return x;
}
void solve(){
	memset(dp,-1,sizeof(dp));
	cin>>n>>wq;
	v.resize(n);
	for(auto &i: v)cin>>i.first>>i.second;

	cout<<resolve(0,wq)<<endl;
}
//revise as variaveis e a ordem nas funções
signed main(){
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

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

using namespace std;

int main()
{
    long long int A, B, C, K;

    scanf("%lld %lld %lld %lld", &A, &B, &C, &K);

    printf("%lld\n", (K % 2 == 0) ? (A - B) : (B - A));

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll int
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{ 
    ll n,t;
    cin>>n>>t;

    vector<pair<ll,ll>> v(n);
    for(ll i=0;i<n;i++)
    	cin>>v[i].ff>>v[i].ss;

    sort(v.begin(),v.end());
    vector<ll> dp(t+3000,0);

    for(auto d:v)
    	for(ll i=t-1;i>-1;i--)
    		dp[i+d.ff]=max(dp[i+d.ff],dp[i]+d.ss);

    	cout<<*max_element(dp.begin(),dp.end())<<endl;
}


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

#define REP(i, n, N) for(int i=(n); i<(N); i++)
#define RREP(i, n, N) for(int i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

int N, M;
int A[100010];
int ans;
int main() {
	cin >> N;
	REP(i, 0, N){
		cin>>A[i];
		ans = __gcd(A[i], ans);
	}
	p(ans);

	return 0;
}


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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  while(true){
    c -= b;
    if(c <= 0){
      break;
    }
    a -= d;
    if(a <= 0){
      break;
    }
  }
  if(a <= 0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
}}


Measured memory_bytes: 3620
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
int main(){
	int a,b,x;
	scanf("%d%d%d",&x,&a,&b);
	x-=a;
	int ans;
	ans=x%b;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL N;
LL A,B,C,D;
int main(){
    cin>>N>>A>>B>>C>>D;
    N-=1;
    LL now=B-A;
    bool check=false;
    REP(i,N+1){
        LL a=(i*C)-((N-i)*C);
        if((now-a>=0)&&(i!=0)&&((now-a)<=(D-C)*i)){
           //cout<<i<<endl;
           //cout<<now<<" "<<a<<" "<<D-C<<endl;
           check=true;
           break;
        }
        if((a-now>=0)&&(N-i!=0)&&((a-now)<=(D-C)*(N-i))){
           //cout<<i<<endl;
           //cout<<N-2*i<<" "<<now<<" "<<a<<" "<<D-C<<endl;
           check=true;
           break;
        }
    }
    /*
    if(N==1){
       if(abs(B-A)=>C&&abs(B-A)<=D){
          cout<<"Yes"<<endl;
       }else{
          cout<<"No"<<endl;
       }
       return 0;
    }*/
    if(check){
       cout<<"YES"<<endl;
    }else{
       cout<<"NO"<<endl;
    }
    
    return(0);
}

Measured memory_bytes: 256
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
P = [*map(int, input().split())]
ans = x
d = 1000000000
for c in range(101+1): # candidate:[0,101]
    ok = True
    for p in P:
        if p == c:
            ok = False
            break
    if ok:
        if d > abs(x - c):
            d = abs(x - c)
            ans = c
print(ans)


Measured memory_bytes: 9180
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int N; cin >> N;
    int res = 0;
    rep(i, 0, N) {
      int l, r; cin >> l >> r;
      res += (r-l+1);
    }
  
    cout << res << endl;
}


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

typedef struct{
	int first;
	int second;
}point;

int main(){
	while(1){
		int w, h;
		int field[50][50];
		int dx[8]={1,1,0,-1,-1,-1,0,1}, dy[8]={0,1,1,1,0,-1,-1,-1};
		
		scanf(" %d %d", &w, &h);
		if(w==0) break;
		
		for(int i=0; i<h; ++i)
		for(int j=0; j<w; ++j)	
		scanf(" %d", &field[i][j]);
		
		int ans=0;
		for(int i=0; i<h; ++i){
			for(int j=0; j<w; ++j){
			
				if(field[i][j]==1){
					//printf("%d %d\n", i, j);
					queue<point> que;
					point p;
					p.first=i; p.second=j;
					field[i][j]=2; //訪問済み
					que.push(p);
					++ans;
					
					//bfs
					while(!que.empty()){
						p=que.front();
						que.pop();
						for(int k=0; k<8; ++k){
							int nf=p.first+dy[k], ns=p.second+dx[k];
							if(nf>=0 && nf<h && ns>=0 && ns<w && field[nf][ns]==1){
								field[nf][ns]=2;
								point q;
								q.first=nf;
								q.second=ns;
								que.push(q);
							}	
						}
					
					}
		
				}
			}
			
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1216
<?php

function input(string $func = null) {
    if ($func === null) {
        return trim(fgets(STDIN));
    } else {
        return $func(trim(fgets(STDIN)));
    }
}

function input_array(string $func = null) {
    if ($func === null) {
        return explode(' ', trim(fgets(STDIN)));
    } else {
        return array_map(function($v) use ($func) {
            return $func($v);
        }, explode(' ', trim(fgets(STDIN))));
    }
}

$s = str_split(input('strval'));
$count = count($s);

$flag = false;
for ($offset = 0; $offset <= $count; $offset++) {
    for ($length = 0; $length <= $count - $offset; $length++) {
        $copied = $s;
        array_splice($copied, $offset, $length);
        if (implode('', $copied) === 'keyence') {
            $flag = true;
            break 2;
        }
    }
}

if ($flag) {
    echo "YES\n";
} else {
    echo "NO\n";
}

Measured memory_bytes: 4728
n,u,v = map(int, input().split( ))
u-=1
v-=1
Tr = [[] for _ in range(n)]
for i in range(n-1):
    ai,bi = map(int, input().split( ))
    ai -=1
    bi-=1
    Tr[ai].append(bi)
    Tr[bi].append(ai)

Dep_u = [-1] *n 
Dep_v = [-1] *n

Dep_u[u] = 0
Dep_v[v] = 0

from collections import deque
##bfs2回が簡明
def bfs(L,x):
    Q = deque()
    Q.append(x)
    while Q:
        y = Q.popleft()
        for z in Tr[y]:
            if L[z] == -1:
                L[z] = L[y] + 1
                Q.append(z)
                
bfs(Dep_u,u)
bfs(Dep_v,v)

ans = 0###0から

for i in range(n):
    if Dep_v[i]>Dep_u[i]:
        ans = max(ans,Dep_v[i]-1)###v
print(ans)





Measured memory_bytes: 63136
#include<bits/stdc++.h>
using namespace std;
string a[3];
int n,mod=1e9+7;
int dp[100][3][20];

int change(char ch){
  return ch-'0';
}

void add(int &a,int b){
  a=(a+b)%mod;
}

void init(){
  for(int i=0;i<100;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<20;k++){
        dp[i][j][k]=-1;
      }
    }
  }
}

int rec(int x,int y,int z){
  if(x==-1){
    if(z==0)return 1;
    else return 0;
  }

  if(dp[x][y][z]!=-1)return dp[x][y][z];

  if(y==2){
    if(a[2][x]=='?'){
      return rec(x-1,0,z/10);
    }else{
      if(change(a[2][x])!=z%10)return 0;
      else return rec(x-1,0,z/10);
    }
  }
  
  int res=0;
  if(a[y][x]!='?'){
    return rec(x,y+1,z+change(a[y][x]));
  }else{
    for(int i=0;i<10;i++){
      if(i==0&&x==0)continue;
      add(res,rec(x,y+1,z+i));
    }
  }
  return dp[x][y][z]=res;
}

int main(){
  while(1){
    cin>>a[0];
    if(a[0]=="0")break;
    cin>>a[1]>>a[2];
    n=a[0].size();
    init();
    cout<<rec(n-1,0,0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
#define dd double
#define ll long long

using namespace std;

int main()
{
    ll n, m, l;
    cin >> n >> m >> l;
    ll ar[n][m],br[m][l];
    for(int i = 0; i<n ; i++)
    {
        for(int j =0; j <m; j++)
        {
            cin >> ar[i][j];
        }
    }
    for(int i = 0; i<m ; i++)
    {
        for(int j =0; j <l; j++)
        {
            cin >> br[i][j];
        }
    }
    ll cr[n][l];
    for(int i = 0; i<n ; i++)
    {
        for(int j =0; j <l; j++)
        {
            cr[i][j] = 0;
        }
    }
    for(int i = 0; i<n ; i++)
    {
        for(int j =0; j <l; j++)
        {
            for(int k=0; k<m; k++)
                cr[i][j] += (ar[i][k] * br[k][j] );
        }
    }
    int i,j;
    for( i = 0; i<n ; i++)
    {
        for( j =0; j <l-1; j++)
        {
            cout << cr[i][j] << " ";
        }
        cout << cr[i][j] << endl;
    }
    return 0;
}





Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int X = Integer.parseInt(st.nextToken());
        int N = Integer.parseInt(st.nextToken());

        if(N == 0) {
            pw.println(X);
            br.close();
            pw.close();
            return;
        }

        String[] input_array = br.readLine().split(" ");

        Set<Integer> checkSet = new HashSet<>();

        for(String str : input_array) {
            checkSet.add(Integer.parseInt(str));
        }

        int up = X;
        int down = X;
        int increment = 1;

        if(!checkSet.contains(X)) {
            pw.println(X);
            br.close();
            pw.close();
            return;
        }

        while(up != 100 || down != 0) {
            up += increment;
            down -= increment;

            if(!checkSet.contains(down)) {
                pw.println(down);
                break;
            } else if(!checkSet.contains(up)) {
                pw.println(up);
                break;
            }
        } 

        br.close();
        pw.close();
    }
}

Measured memory_bytes: 32496
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;


struct UnionFind {
	VI par;
	UnionFind(int N) :par(N) {
		REP(i, N)par[i] = i;
	}
	int root(int x) {
		if (par[x] == x)return x;
		return par[x] = root(par[x]);
	}
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;
		par[rx] = ry;
	}
	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

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

	int N; cin >> N;
	vector<VI> G(N);
	REP(i, N) {
		int a; cin >> a;
		G[i].push_back(--a);
	}
	int to = 0;
	int cnt = 0;
	while (cnt<1000000) {
		to = G[to][0];
		if (to == 1) {
			cout << cnt+1 << endl;
			return 0;
		}
		cnt++;
		//cout << cnt << endl;
	}

	cout << -1 << endl;
	return 0;
}



Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt(),b=sc.nextInt();
		String s=sc.next();
		int cnt=0;
		for(int i=0;i<(a+b+1);i++) {
			if(i==a) {
				if(s.charAt(i)=='-') {
					cnt++;
				}
			}else {
				if(s.substring(i,i+1).matches("[0-9]")) {
					cnt++;
				}
			}
		}
		System.out.println(cnt==s.length()?"Yes":"No");
	}
}

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

int main(){
    ll q,h,s,d,n;cin>>q>>h>>s>>d>>n;
    vector<ll>v;
    v.push_back(4*q*n);
    v.push_back(2*h*n);
    v.push_back(s*n);
    v.push_back(n/2*d+n%2*s);
    v.push_back(n/2*d+n%2*q*4);
    v.push_back(n/2*d+n%2*h*2);
    sort(v.begin(),v.end());
    co(v[0]);
}

Measured memory_bytes: 256