akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define N 101
#define INF 1e9
using namespace std;
int n,g[N][N],ans;
vector<int> V;

void calc(){
  int sum=0;
  for(int i=0;i<V.size();i++){
    int mn=INF;
    for(int j=0;j<V.size();j++)if(i!=j) mn=min(mn,g[V[i]][V[j]]);
    sum+=mn;
  }
  ans=max(ans, (V.size()>1)*sum);
}


set<int> used;
void solve(int pos){
  if(pos==n){calc();return;}
  solve(pos+1);
if(used.count(pos))V.push_back(pos),solve(pos+1),V.pop_back();
}

vector<int> G[N];
int can[N];
set<set<int> > S;
void dfs(int pos,int cnt){
  int flg=1,len=G[pos].size();
  used.insert(pos);
  if(S.count(used)){used.erase(pos);return;}
  S.insert(used);
  for(int i=0;i<len;i++) can[G[pos][i]]++;
  
  for(int i=0;i<len;i++){
    int nx=G[pos][i];
    if(!used.count(nx)&&can[nx]==cnt)flg=0,dfs(nx,cnt+1);
  }
  if(flg)solve(0);
  used.erase(pos);
  for(int i=0;i<len;i++) can[G[pos][i]]--;
}


int main(){
  int m;
  cin>>n>>m;
  for(int i=0,a,b,c;i<m;i++){
    cin>>a>>b>>c;
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
    g[a][b]=g[b][a]=c;
  }
  
  for(int i=0;i<n;i++)dfs(i,1);
  cout <<ans<<endl;
  return 0;
}

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

int main(){
	int N, M, sum(0), x;
    cin >> N >> M;
  	for (int i=0; i<M; i++){
      	cin >> x;
      	sum += x;
    }
  	if (N - sum < 0) cout << "-1\n";
  	else cout << N-sum << endl;
  	return 0;
}


Measured memory_bytes: 3628
N,Y=map(int,input().split())
flag=0
for x in range(N+1):
    for y in range(N+1):
        z=N-x-y
        if Y-10000*x-5000*y-1000*z==0 and z>=0:
            flag=1
            print(x,y,z)
            break
    else:
        continue
    break
if flag==0:
    print("-1 -1 -1")

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

int main() {
    ll n, m;
    cin >> n >> m;
    vector<P> v;
    rep(i,n) {
        ll a;
        cin >> a;
        v.push_back({a,1});
    }
    rep(i,m) {
        ll b, c;
        cin >> b >> c;
        v.push_back({c,b});
    }
    sort(v.begin(),v.end(),greater<>());
    ll ans = 0, cnt = 0;
    rep(i,n) {
        ans += v[cnt].first;
        v[cnt].second--;
        if (v[cnt].second == 0) cnt++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7452
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int main() {
	long long n;cin>>n;
	if(n%2==1) {cout<<0<<endl;return 0;}
	long long ans=0,n2=n;
	while(n2>0) {
		n2/=10;
		ans+=n2;
	}
	n2=n;
	while(n2>0) {
		n2/=10;
		long long div=5;
		while(n2+div>=div*2&&div>0) {
			ans+=(n2+div)/(div*2);
			div*=5;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;




main(){

  char ab[13][102];
  
  int i=0,j=0;
  int sumA[13],sumB[13], game=0;
  
  for(i=0;i<13;i++){
    sumA[i]=0;
    sumB[i]=0;
    
  }
  i=0;
  j=0;

  while(1){
    
    scanf("%c",&ab[i][j]);
    
    if( ab[i][j]== '0'){
      break;
    }
    
    //Ã£ÂÂÃ£ÂÂÃ£ÂÂÃ£ÂÂ¯Ã§ÂÂ¨
    // cout << ab[i][j] <<" "<< i <<" " <<j<< " "<< sumA[i]<< " " << sumB[i]<< endl;
     //cout << game <<  " " << i<< endl;
    
    if(ab[i][j]=='A' && j!=0)sumA[i]++;
    if(ab[i][j]=='B' && j!=0)sumB[i]++;
    
    j++;
    
    
    
    if(ab[i][j-1]== '\n' || ab[i][j-1]=='\0'){
      i++;
      j=0;
      game++;
      //cout << "OK";
    }
    
    
    /*
    if(ab[i][j-1] != 'A' && ab[i][j-1]!= 'B'){
      i++;
      j=0;
      game++;
    }
    */
  }
  
  
  for(i=0;i<game;i++){

    //AÃ£ÂÂBÃ£ÂÂÃ£ÂÂÃ£ÂÂ§Ã£ÂÂÃ£ÂÂÃ¦ÂÂ
    if(sumA[i]>sumB[i]){
      if(sumB[i]>=10){
	sumA[i] = sumB[i]+2;
      }
      if(sumB[i]<10){
	sumA[i] += 11 - sumA[i];
      }
    }
    
    //BÃ¯Â¼ÂAÃ£ÂÂ®Ã¦ÂÂ
    if(sumB[i]>sumA[i]){
      if(sumA[i]>=10){
	sumB[i] = sumA[i]+2;
      }
      if(sumA[i]<10){
	sumB[i] += 11 - sumB[i];
      }
    }
    
  }
  
  for(i=0;i<game;i++){
    
    cout << sumA[i]<< " " << sumB[i]<< endl;

  }
  


  return 0;

}

Measured memory_bytes: 0
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int x, y;
	cin >> x >> y;

	if (x > 0) {
		if (y > 0) {
			if (y - x >= 0) {
				cout << y - x << endl;
			} else {
				cout << x - y + 2 << endl;
			}
		} else if (y < 0) {
			if (x >= -y) {
				cout << y + x + 1 << endl;
			} else {
				cout << -y - x + 1 << endl;
			}
		} else {
			cout << x + 1 << endl;
		}
	} else if (x < 0) {
		if (y > 0) {
			if (-x >= y) {
				cout << -x - y + 1 << endl;
			} else {
				cout << y + x + 1 << endl;
			}
		} else if (y < 0) {
			if (y - x >= 0) {
				cout << y - x << endl;
			} else {
				cout << -y + x + 2 << endl;
			}
		} else {
			cout << -x << endl;
		}
	} else {
		if (y >= 0) {
			cout << y - x << endl;
		} else {
			cout << -y + 1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX/2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }



void solve(void)
{
  int N;
  cin>>N;
  map<int,int> mp;
  for (int i = 0; i < N; i++)
  {
    int A;
    cin>>A;
    auto itr = mp.find(A);
    if(itr != mp.end())
    {
      itr->second++;
    }
    else
    {
      mp[A] = 1;
    }
  }

  int SUM = 0;
  auto itr = mp.begin();
  
  for (int i = 0; i < mp.size(); i++)
  {
    SUM += itr->second;
    itr++;
  }

  int dup = SUM - mp.size();

  cout<<mp.size() - dup%2<<endl;

  
  
  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 6528
#include<stdio.h>
int main(){
  int N;
  scanf("%d",&N);
  int A[N];
  for(int i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
int max_1=0;
int max_2=0;
  for(int i=0;i<N;i++){
    if(A[i]>max_1){
      max_2=max_1;
      max_1=A[i];
    }
    if(max_2<A[i]&&A[i]<max_1)
      max_2=A[i];
  }
  int x;
  x=0;
  for(int i=0;i<N;i++){
    if(A[i]==max_1)
      x++;
  }
  if(x==1){
    for(int i=0;i<N;i++){
      if(A[i]==max_1)
        printf("%d\n",max_2);
      else
        printf("%d\n",max_1);
    }
  }
  if(x>=2){
    for(int i=0;i<N;i++){
      printf("%d\n",max_1);
    }
  }
  return 0;
}



Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector <int> ve[N];
priority_queue <int> qe;
int main()
{
	int n, m;
	cin >> n >> m;
	int a, b;
	for(int i = 0; i < n;i ++)
	{
		cin >> a >> b;
		if(m - a + 1 < 1) continue;
		ve[m - a + 1].push_back(b);
	}
	int anx = 0;
	for(int i = m;i >= 1; i --)
	{
		for(int j = 0; j < ve[i].size(); j ++)
		{
			qe.push(ve[i][j]);
		}
		if(!qe.empty())
		{
			anx += qe.top();
			qe.pop();
		}
	}
	cout << anx << "\n";
}

Measured memory_bytes: 8900
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())
nsl = lambda: list(nsm())

n = ni()
w = nl()
ans = 1000000000
s1 = 0
s2 = 0
for i in range(n):
    s1 = 0
    s2 = 0
    for j in range(n):
        if j <= i:
            s1 += w[j]
        else:
            s2 += w[j]
    ans = min(ans, abs(s1 - s2))
print(ans)

Measured memory_bytes: 3316
package main

import (
    "fmt"
)

func calcMin(w, h, d int) int {
    w1 := w / 2
    w2 := w - w/2
    if w1 == w2 {
        return 0
    } else {
        return 1 * h * d
    }
}

func solve(w, h, d int) int {
    min := calcMin(w, h, d)
    if v := calcMin(h, w, d); v < min {
        min = v
    }
    if v := calcMin(d, w, h); v < min {
        min = v
    }
    return min
}

func main() {

    var w, h, d int
    fmt.Scanf("%d %d %d", &w, &h, &d)
    ans := solve(w, h, d)
    fmt.Printf("%v\n", ans)
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long[] a = new long[M];
		
		long c = 1000000007;
		
		long[] fib = new long[N + 2];
		fib[0] = 1;
		fib[1] = 1;
		fib[2] = 2;
		
		for(int i = 3; i <= N + 1; i++) {
			fib[i] = fib[i - 1] + fib[i - 2];
			fib[i] = fib[i] % c;
		}
		 
		if(M == 0) {
			System.out.println(fib[N]);
			return;
		}
		
		for(int i = 0; i < M; i++) {
			a[i] = sc.nextInt();
			if(i > 0 && a[i] - 1 == a[i - 1]) {
				System.out.println(0);
				return;
			}
		}
		
		int now = 0;
		int x = 0;
		long sum = 1;
		int temp = 0;
		
		while(temp < N) {
			now++;
			temp++;
			if(x < M) {
				if(temp == a[x]) {
					sum = sum % c * fib[now - 1] % c;
					x++;
					now = -1;
				}
			}
		}
		sum = sum % c * fib[now] % c;
		System.out.println(sum);
	}
}


Measured memory_bytes: 44232
import java.util.*;

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

      Scanner sc = new Scanner(System.in);
      
      String word  = sc.next();
      
      // 先頭文字を抜き出す
      String top = word.substring(0,1);
      
      // 末尾文字を抜き出す
      String end = word.substring(word.length() -1);
      
      // 先頭と末尾の間の文字数を抜き出す
      int s = word.length() -2;
      
      System.out.println(top + s + end);
    }
}

Measured memory_bytes: 22868
//ITNOA
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
const long long INF=1e9+10,MAX=2e5+1e4,MOD=1e9+7;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
void OUT(long double o,int x){
	 cout<<fixed<<setprecision(x)<<o;
	 return;
}
ll a[MAX];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll k;
	cin>>k;
	cout<<"50\n";
	ll r=k%50;
	ll x1=(48*(r/3))+49+(k/50),x2=(48*(r/3))+49+(k/50),x3=(48*(r/3))+49+(k/50);
	if(r%3==1)
		x1+=50,x2--,x3--;
	if(r%3==2)
		x1+=100,x2-=2,x3-=2;
	cout<<x1<<" "<<x2<<" "<<x3<<" ";
	//cout<<(50*r)+49+(k/50)<<" ";
	for(ll i=4;i<=50;i++)
		cout<<(k/50)+49-r<<" ";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define pii pair<ll int, ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define repi(i, n) for(ll i=0; i<n; i++)
#define rep(i, a, b) for(ll i=a; i<=b; i++)
#define M 1000000007
#define INF 1e10

using namespace std;

int main() {
    ios
    ll n, d;
    cin>>n>>d;
    ll ans = 0;
    repi(i, n){
        ll x, y;
        cin>>x>>y;
        if(x*x+y*y<=d*d) ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    for(int i=0; s[i]; i++){
        if(i%2 == 0){
            if(s[i] == 'L'){
                cout << "No\n";
                return 0;
            }
        }
        else{
            if(s[i] == 'R'){
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
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; }

int main(){

	string s,t;
	cin>>s>>t;

	lli cnt=0;
	REP(i,0,3){
		if(s[i]==t[i])cnt++;
	}
	cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 256
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    N = int(input())
    S = [input() for _ in range(N)]

    cnt = 0
    cnt_xa = 0
    cnt_bx = 0
    cnt_ba = 0
    for s in S:
        for i in range(0, len(s) - 1):
            if s[i] == 'A' and s[i + 1] == 'B':
                cnt += 1
        if 'B' != s[0] and 'A' == s[-1]:
            cnt_xa += 1
        if 'B' == s[0] and 'A' != s[-1]:
            cnt_bx += 1
        if 'B' == s[0] and 'A' == s[-1]:
            cnt_ba += 1

    if cnt_ba > 1:
        cnt += cnt_ba - 1
        cnt_ba = 1
    if (cnt_xa > 0 or cnt_bx > 0) and cnt_ba == 1:
        cnt += 1
    cnt += min(cnt_xa, cnt_bx)

    print(cnt)


Measured memory_bytes: 46932
#include<bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std; 
typedef pair<long long int,long long int> pa;
#define resize(A) A.resize(unique(A.begin(), A.end()) - A.begin())
#define pb push_back
#define  MAX 200000
long long int MOD=998244353;
long long int INF=1e18;
                                                 /*:-]*/
 
int main()
{
         ios_base::sync_with_stdio(false); 
         cin.tie(NULL);
         cout.tie(NULL);
         long long int i,j,k=0,l=0,r=0,m=0,n,c,p=0,cnt=0,cnt1=0,x,y,z=0,a,b,low,mid,high,ans=0,maxi=0,mini=INF,t,x1,y1;
       cin>>n;
    long double k1;
    if(n%2==0)
        k1=0.5;
    else
    {
        p=n/2+1;
        k1=(p*1.00000000)/n;
        
    }
    cout<<k1<<endl;
    
}
    

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var x int
	fmt.Scan(&x)

	ans := "No"
	for i:=1; i<10; i++{
		for j:=1; j<10; j++{
			if i * j == x{
				ans = "Yes"
				break
			}
		}
	}

	fmt.Println(ans)
}

Measured memory_bytes: 1768
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
typedef long long ll;
typedef long double ld;


#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll S[1000] = { 0 };
ll N,M,Q;


int main() {
	cin >> N;
	vector<ll>A(N);
	rep(i, N)cin >> A[i];
	cin >> Q;
	rep(i, Q) {
		ll k;
		cin >> k;
		vector<ll>::iterator a=lower_bound(A.begin(), A.end(), k);
		cout << distance(A.begin(),a)  << " ";
		vector<ll>::iterator b = upper_bound(A.begin(), A.end(), k);
		cout << distance(A.begin(), b) << endl;
	}
	return 0;
}





Measured memory_bytes: 3628
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

typedef long long LL;
const int M=60;
const int MO=1e9+7;

int cnt[M+5];

int main()
{
	int n; scanf("%d",&n);
	LL a;
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&a);
		for(int j=0;j<M;j++)
			if(a&(1LL<<j)) cnt[j]++;
	}
	LL ans=0;
	LL er=1;
	for(int i=0;i<M;i++,er=er*2%MO)
	{
		ans=(ans+er*cnt[i]%MO*(n-cnt[i])%MO)%MO;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int M = scanner.nextInt();

        if( N<=M ){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto& a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<typename Num>
        constexpr Num mypow(Num a, long long b) {
            if(b==0)return 1;
            if (a==0)return 0;
            Num x = 1;
              while (b > 0) {
                if(b & 1)x*=a;
                a*=a;
                b >>= 1;
              }
              return x;
        }

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

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin>>n;
        umap<ll,ll> m;
        rep(i,n){
            ll a;
            cin>>a;
            m[a]++;
        }
        ll res=0;
        rbf(p,m){
            if(p.Se>=p.Fi)res+=p.Se-p.Fi;
            else res+=p.Se;
        }
        cout<<res<<endl;
    }

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

int main(void){
	unsigned int a,b,sum;
	while(cin >> a >> b){
		sum = a + b;
		unsigned int ans = 0;
		while(sum > 0){
			sum = sum / 10;
			ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
long long t[1005],a[1005],n,c,d;
int main(){
	cin>>n;
	cin>>t[1]>>a[1];
	for(int i=2;i<=n;i++)
	{
		cin>>t[i]>>a[i];
		 
		if((t[i]<t[i-1])&&(a[i]<a[i-1]))
		  c=(t[i-1]+t[i]-1)/t[i],
		 d=(a[i-1]+a[i]-1)/a[i], 
		 a[i]=max(c,d)*a[i], 
		 t[i]=max(c,d)*t[i];
		  
		   if(t[i]<t[i-1])
		      c=(t[i-1]+t[i]-1)/t[i],t[i]=c*t[i], a[i]=c*a[i];
		    
		    if(a[i]<a[i-1])
		       d=(a[i-1]+a[i]-1)/a[i], a[i]=d*a[i],t[i]=d*t[i]; 
	
		    
		 
	}
	cout<<a[n]+t[n];
}

Measured memory_bytes: 256
N,K = map(int, input().split())
p = list(map(int, input().split()))
X = N-K+1
Y = [0]*X
for i in range(K):
    Y[0] += (p[i]+1)/2

for j in range(X-1):
    Y[j+1] = Y[j]-(p[j]+1)/2+(p[j+K]+1)/2

print(max(Y))

Measured memory_bytes: 24548
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Washoum
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CColoringColorfully solver = new CColoringColorfully();
        solver.solve(1, in, out);
        out.close();
    }

    static class CColoringColorfully {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            String s = sc.nextLine();
            int nb0 = 0;
            int nb1 = 0;
            int tawa1 = 0;
            int tawa2 = 1;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) - '0' != tawa1) {
                    nb0++;
                }
                if (s.charAt(i) - '0' != tawa2) {
                    nb1++;
                }
                tawa1 = (tawa1 + 1) % 2;
                tawa2 = (tawa2 + 1) % 2;
            }
            out.println(Math.min(nb0, nb1));
        }

    }

    static class inputClass {
        BufferedReader br;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}



Measured memory_bytes: 24148
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

int find(Node r,int b){
  if(r == NIL){
    return 0;
  }

  if(r->key == b){
    return 1;
  }else if(r->key < b){
    return find(r->right,b);
  }else{
    return find(r->left,b);
  }
}

void insert(int a){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = a;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if(y==NIL){
    root=z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}

void inorder(Node u){
  if(u==NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u==NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int h, i, a, b;
  char com[20];

  scanf("%d", &h);
  for ( i = 0; i < h; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d",&a);
      insert(a);
    }else if(com[0]=='f'){
      scanf("%d" ,&b);
      if(find(root,b)==1){
	printf("yes\n");
      }else{
	printf("no\n");
      }
    }else{
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  
  return 0;
}



Measured memory_bytes: 20440
#include <algorithm>
#include <cstdio>
#define calc(l, r, t) std::min(l, std::max(r, t))
int seq[100005]; 
int main()
{
	// freopen("ARC082-F.in", "r", stdin);
	int x, n; 
	scanf("%d%d", &x, &n); 
	for (int i = 0; i < n; i++)
		scanf("%d", seq + i); 
	int q, idx = 0, coef = -1, l = x, r = 0, c = 0; 
	scanf("%d", &q); 
	while (q--)
	{
		int t, a; 
		scanf("%d%d", &t, &a); 
		while (idx < n && t >= seq[idx])
		{
			int dt = coef * (seq[idx] - (idx ? seq[idx - 1] : 0)); 
			l = calc(x, 0, l + dt); 
			r = calc(x, 0, r + dt); 
			c += dt; 
			idx++; 
			coef *= -1; 
		}
		int dt = coef * (t - (idx ? seq[idx - 1] : 0)); 
		printf("%d\n", calc(x, 0, calc(l, r, a + c) + dt));
	}
	return 0; 
}


Measured memory_bytes: 1536
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

int main() {
	cout << fixed << setprecision(12);	
	int k;
	cin >> k;
	int cur = 0;
	for (int i = 1; i <= 3 * k; i++) {
		cur *= 10;
		cur += 7;
		cur %= k;
		if (cur == 0) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>

using namespace std;
const int N=2e5+10,inf=1e9;
int dp[N][2];
char s[N];

int main(){
    int len,O=0;
    string S,ans;
    cin >> S;
    len = S.length();
    for(int i=0;i<len;i++){
        if(S[i]=='o'){
            O++;
        }
    }

    if((15-len+O)>=8){
        ans = "YES";
    }else{
        ans = "NO";
    }
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;

const char nc[20] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
string ans;
int main()
{
	int m, n, k, t, s;
	
	while(cin >> m /*>> n*/)
	{
		if(m == 0)
		{
			cout << "0" <<endl;
			continue;
		}
		
		n = -2;
		ans = "";
		s = m;
		while(m != 0)
		{
			k = m % n;
			t = m / n;
			if(k < 0)
			{
				k -= n;
				t++;
			}	
			m = t;
			ans.push_back(nc[k]);
		}
		//cout << s << "=";
		for(int i = ans.length() - 1; i >= 0; i--)
			cout << ans[i];
		cout << endl;
		//cout << "(base" << n << ")" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 4;

int n, p[N];
vector<int> g[N];
int dp[N];

int f(int u) {
    int& res = dp[u];
    if (res != -1) {
        return res;
    }
    res = 0;
    if (size(g[u]) == 0) {
        return res;
    }

    vector<int> dpto;
    for (int to : g[u]) {
        dpto.em_back(f(to));
    }
    sort(all(dpto));

    for (int i = 0; i < size(dpto); ++i) {
        res = max(res, i + 1 + dpto[size(dpto) - 1 - i]);
    }
    return res;
}

void solve() {
    cin >> n;
    for (int i = 2; i <= n; ++i) {
        cin >> p[i];
        g[p[i]].em_back(i);
    }

    memset(dp, -1, sizeof dp);
    cout << f(1) << "\n";
}

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

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 20688
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	int N,sum,cnt;
	while(~scanf("%d",&N))
	{
		sum = 0;
		cnt = 0;
		for(int i=1;i<=N;i++)
		{
			sum += i;
			cnt = i;
			if(sum >= N)
			break;
		}
		if(sum == N)
		{
			for(int i=1;i<=cnt;i++)
			printf("%d\n",i);
		}
		else 
		{
			int tmp = sum-N;
			for(int i=1;i<=cnt;i++)
			{
				if(tmp != i)
				printf("%d\n",i);
			}
		}
		
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    string s=to_string(n);
    bool f=0;
    for(int i=0;i<1;i++)
        for(int j=i;j<i+3;j++)
        {
            if(s[j]==s[j+1]&&s[j]==s[j+2])
            {
                f=1;
                break;
            }
        }
        if(!f)
            cout<<"No\n";
        else
            cout<<"Yes\n";
    
    return 0;   
}




 
 


Measured memory_bytes: 256
//#define anjn
//      Anjan Agarwala - anjn98

//#define opti
#ifdef opti
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, 
                  tree_order_statistics_node_update> ordered_set;

ll power(ll x,ll y,ll p){ll r=1; x=x%p; while(y){ if(y&1) r= r*x%p; y=y>>1; x=x*x%p; } return r; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int csrand(int l=0, int r=1e9){
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

#define PR(x) cout<<#x<<": "<<x<<"\n";
#define PR1(x,y) cout<<#x<<": "<<x<<"  |  "<<#y<<": "<<y<<"\n";
#define PR2(x,y,z) cout<<#x<<": "<<x<<"  |  "<<#y<<": "<<y<<"  |  "<<#z<<": "<<z<<"\n";
#define ED cout<<'\n';

#define IO              ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FILEIO          freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define all(v)          v.begin(),v.end()
#define endl            '\n'
#define fr1(j,n)        for(int j=0;j<n;j++)
#define fr(n)           for(int i=0;i<n;i++)
#define trav(x,s)       for(auto x:s)
#define PB              push_back
#define pii             pair<int,int>
#define pll             pair<long long int,long long int>
#define F               first
#define S               second 
#define binf            2000000000000000001
#define mod             1000000007


const int N=1e6+99;



int32_t main() 
{





    int a,p;
    cin>>a>>p;

    a=a*3+p;
    a=a/2;

    cout<<a<<endl;  
        





     
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int n;
  cin >> n;
  vector<ll> sum(n+1,0);
  REP(i,n){
    ll a;
    cin >> a;
    sum[i+1]=a+sum[i];
  }

  ll ans = LINF;
  FOR(i,1,n){
    ll r = sum[n]-sum[i];
    ll l = sum[i];
    chmin(ans, abs(l-r));
  }
  cout << ans << endl;

}



Measured memory_bytes: 4824
import java.util.Scanner
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    sc.nextLine()
    val intSeq = sc.nextLine().split(" ").map(_.toInt).toIndexedSeq
    sc.nextLine()
    val sIntSeq = sc.nextLine().split(" ").map(_.toInt).toIndexedSeq

    println(sIntSeq.count(intSeq.contains(_)))
  }
}



Measured memory_bytes: 50232
#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 vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, x, y;
    cin >> n >> x >> y;
    vi ans(n);
    REP1(i, n - 1) FOR(j, i + 1, n + 1) {
        int mn = min({j - i, abs(x - i) + 1 + abs(j - y)});
        ans[mn]++;
    }
    REP1(i, n - 1) cout << ans[i] << endl;
}


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

int main() {
  int n, k, ans = 0;
  cin >> n >> k;
  rep(i, n) {
    int h;
    cin >> h;
    if(h >= k) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3584
import sys
def input(): return sys.stdin.readline().rstrip()
def ctoi(c):
    return ord(c)-97
class BIT:
    def __init__(self, n):
        self.unit_sum=0 # to be set
        self.n=n
        self.dat=[0]*(n+1)#[1,n]
    def add(self,a,x): #a(1-)
        i=a
        while i<=self.n:
            self.dat[i]+=x
            i+=i&-i
    def sum(self,a,b=None): 
        if b!=None:
            return self.sum(b-1)-self.sum(a-1) #[a,b) a(1-),b(1-)
        res=self.unit_sum
        i=a
        while i>0:
            res+=self.dat[i]
            i-=i&-i
        return res  #Σ[1,a] a(1-)   
    def __str__(self):
        self.ans=[]
        for i in range(1,self.n):
            self.ans.append(self.sum(i,i+1))
        return ' '.join(map(str,self.ans))

def main():
    n=int(input())
    S=list(input())
    q=int(input())
    BIT_tree=[]
    for i in range(26):
        obj=BIT(n+1)
        BIT_tree.append(obj)
    for i in range(n):
        BIT_tree[ctoi(S[i])].add(i+1,1)
    for _ in range(q):
        query=input().split()
        if query[0]=="1":
            index,x=int(query[1])-1,query[2]
            BIT_tree[ctoi(S[index])].add(index+1,-1)
            BIT_tree[ctoi(x)].add(index+1,1)
            S[index]=x
        else:
            l,r=int(query[1])-1,int(query[2])-1
            ans=0
            for c in range(26):
                if BIT_tree[c].sum(l+1,r+2):
                    ans+=1
            print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 165288
#include <stdio.h>
#include <string.h>

int
main(void)
{
	char line[100];
	char res[100];

	auto chksep = [](char c) -> bool {
			return (c == ' ' || c == '.' || c == '\n');
		};

	while (fgets(line, sizeof line, stdin)) {
		int len = strlen(line);
		int state = 0;
		
		for (int s = 0; s < 26; s++) {

			for (int i = 0; i < len; i++) {
				if (chksep(line[i])) {
					res[i] = line[i];
				} else {
					int c = line[i] + s;
;					if (c > 'z') {
						res[i] = c - 'z' + 'a' - 1;
					} else {
						res[i] = c;
					}
				}

				switch (state) {
				case 0:
					if (res[i] == 't') {
						state = 1;
					}
					break;

				case 1:
					if (res[i] == 'h') {
						state = 2;
					} else {
						state = 0;
					}
					break;

				case 2:
					if (res[i] == 'e') {
						state = 5;
					} else if (res[i] == 'i') {
						state = 3;
					} else if (res[i] == 'a') {
						state = 4;
					} else {
						state = 0;
					}
					break;

				case 3:
					if (res[i] == 's') {
						state = 5;
					} else {
						state = 0;
					}
					break;

				case 4:
					if (res[i] == 't') {
						state = 5;
					} else {
						state = 0;
					}
					break;

				case 5:
					if (chksep(res[i])) {
						state = 99;
					} else {
						state = 0;
					}
					break;
				}
			}

			if (state == 99) {
				res[len] = 0;
				printf("%s", res);
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 932
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;


int main(){
    int n;
    scanf("%d",&n);
    int odd=0,even=0;
    int i,q;
    for(i=0;i<=n-1;i++){
        scanf("%d",&q);
        if(q%2==0)even++;
        else odd++;
    }
    int ans=1;
    for(i=1;i<=n;i++)ans=ans*3;
    int minus=1;
    for(i=1;i<=even;i++)minus=minus*2;
    ans=ans-minus;
    printf("%d",ans);
    
    
    
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int h = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		System.out.println((int)Math.ceil((double)h/a));
		sc.close();
	}
}

Measured memory_bytes: 23764
//created by pyoxiao on 2020/04/04
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;}
LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);}
int n, m, a[105];
void solve() {
    scanf("%d %d", &n, &m);
    int sum = 0;
    for(int i = 1; i <= n; i ++) {
        scanf("%d", a + i);
        sum += a[i];
    }
    sum = sum / (4 * m) + (sum % (4 * m) == 0 ? 0 : 1);
    int cnt = 0;
    for(int i = 1; i <= n; i ++) {
        if(a[i] >= sum) cnt ++;
    }
    if(cnt >= m) puts("Yes");
    else puts("No");
}
int main() {
    int T = 1;
    // scanf("%d", &T);
    while(T --) 
        solve();
    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToArray();
        var plusCore = a.First();
        var minusCore = a.Last();
        var aWithOutCore = a.Skip(1).Take(n - 2);
        var plus = aWithOutCore.TakeWhile(x => 0 < x).ToArray();
        var minus = aWithOutCore.SkipWhile(x => 0 < x).ToArray();

        List<string> op = new List<string>();
        //マイナスを作る
        foreach (var item in minus)
        {
            op.Add($"{plusCore} {item}");
            plusCore -= item;
        }
        //プラスを作る
        foreach (var item in plus)
        {
            op.Add($"{minusCore} {item}");
            minusCore -= item;
        }
        op.Add($"{plusCore} {minusCore}");
        Console.WriteLine(plusCore - minusCore);
        Console.WriteLine(string.Join("\n", op));
    }
}

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

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 3e5 + 10;
const int M = (int) 1e6 + 10;
const int K = (int) 500 + 10;
const int mod = (int) 998244353;

int n;
int l[N], r[N];
bool used[N];

ll get(int dir) {
	set<pii> st_l, st_r;
	for (int i = 1; i <= n; i++) {
		st_l.insert(mp(l[i], i));
		st_r.insert(mp(r[i], i));
	}
	int cur_pos = 0;
	ll cur = 0;
	for (int iter = 1; iter <= n; iter++) {
		int nxt = -1;
		if (dir) {
			// taking maximum l, saving index to nxt
			nxt = (--st_l.end()) -> s;
		} else {
			nxt = (*st_r.begin()).s;
			// taking minimum r, saving index to nxt
		}
		if (cur_pos > r[nxt]) {
			cur += cur_pos - r[nxt];
			cur_pos = r[nxt];
		} else if (cur_pos < l[nxt]) {
			cur += l[nxt] - cur_pos;
			cur_pos = l[nxt];
		} 
		st_l.erase(mp(l[nxt], nxt));
		st_r.erase(mp(r[nxt], nxt));
		dir ^= 1;
	}
	cur += abs(cur_pos);
	return cur;
}

int main() {
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output1.txt", "w", stdout);
	#endif
	srand(time(0));
	cin >> n; 
	for (int i = 1; i <= n; i++) {
		cin >> l[i] >> r[i];
	}
	cout << max(get(0), get(1));
	return 0;
}

Measured memory_bytes: 10752
#include<bits/stdc++.h>
using namespace std;
vector<long long> v;
long long arr[103][103];
int main(){
    long long h, w, n;
    memset(arr, -1, sizeof(arr));
    cin >> h >> w;
    cin >> n;
    for(int i = 0; i < n; ++i){
        long long x;
        cin >> x;
        v.push_back(x);
    }
    long long nowx, nowy;
    nowx = nowy = 0;
    for(int i = 0; i < n; ++i){
        long long x = v[i];
        while(x--){
            arr[nowy][nowx] = i;
            if(nowx+1 < w && arr[nowy][nowx+1]==-1){
                nowx++;
            }
            else if(nowy+1 < h && arr[nowy+1][nowx]==-1){
                nowy++;
            }
            else if(nowx-1 >= 0 && arr[nowy][nowx-1]==-1){
                nowx--;
            }
            else if(nowy-1 >= 0 && arr[nowy-1][nowx]==-1){
                nowy--;
            }
        }
    }
   
    for(int i = 0; i < h; ++i){
        cout << arr[i][0]+1;
        for(int j = 1; j < w; ++j){
            cout << ' ' << arr[i][j]+1;
        }
        cout << endl;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pll = pair < ll, ll >;
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e6 + 10;

const int m = 2019;

int main(){ 
	string s; cin >> s;
	int n = s.size();
	int dp[n+1];
	fill(dp, dp + n + 1, 0);
	int mul = 1, ans = 0;
	int cnt[2019];
	fill(cnt, cnt + 2019, 0);
	cnt[0] = 1;
	for(int i = n - 1; i >= 0; i--) {
		dp[i] = (dp[i+1] + ((s[i] - '0') * mul % m)) % m;
		mul *= 10;
		mul %= m;
		ans += cnt[dp[i]];
		cnt[dp[i]]++;
		// cout << mul << endl;
	}
	cout << ans << endl;
}


Measured memory_bytes: 4520
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def bit(n, k):
    return (n >> k) & 1


def main():
    N, M, X = map(int, input().split())
    C = [0]*N
    A = [None]*N
    for i in range(N):
        C[i], *A[i] = map(int, input().split())

    min_money = INF
    # 全探索
    for i in range(1 << N):
        tot = [0]*M
        money = 0
        for n in range(N):
            if bit(i, n):
                money += C[n]
                for j in range(M):
                    tot[j] += A[n][j]

        if all(tot[j] >= X for j in range(M)):
            min_money = min(money, min_money)
    if min_money == INF:
        print(-1)
    else:
        print(min_money)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 74756
X, N = map(int, input().split())
L = list(map(int, input().split()))

if len(L) == 0:
    print(X)
    exit()

list = [0 for _ in range(len(L))]
for i in range(len(L)):
    list[i] = abs(X - L[i])
list = sorted(list)

if min(list) != 0:
    print(X)
    exit()
else:
    num = 1
    cnt = 0
    for i in range(1, len(list)):
        if list[i] != num:
            break
        cnt += 1
        if cnt == 2:
            cnt = 0
            num += 1
if cnt == 0:
    print(X - num)
else:
    if X + num in L:
        print(X - num)
    else:
        print(X + num)


Measured memory_bytes: 62064