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

const int INF = 1 << 28;

int h, w;
char grid[22][22];
int d[22][22];
int dist[11][11];

void bfs(int sx, int sy)
{
	static const int dx[] = {-1, 0, 1, 0};
	static const int dy[] = {0, -1, 0, 1};
	
	fill_n(*d, 22 * 22, INF);
	d[sx][sy] = 0;
	
	queue<pair<pair<int, int>, int>> q;
	q.push(make_pair(make_pair(sx, sy), 0));
	while (q.size()){
		auto p = q.front(); q.pop();
		int x = p.first.first;
		int y = p.first.second;
		int s = p.second;
		for (int dir = 0; dir < 4; dir++){
			int nx = x + dx[dir];
			int ny = y + dy[dir];
			if (grid[nx][ny] == 'x') continue;
			if (d[nx][ny] > s + 1){
				d[nx][ny] = s + 1;
				q.push(make_pair(make_pair(nx, ny), s + 1));
			}
		}
	}
}

int solve()
{
	vector<pair<int, int>> vp;
	
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			if (grid[i][j] == '*') vp.push_back(make_pair(i, j));
			if (grid[i][j] == 'o'){
				vp.push_back(make_pair(i, j));
				swap(vp.front(), vp.back());
			}
		}
	}
	
	for (int i = 0; i < vp.size(); i++){
		bfs(vp[i].first, vp[i].second);
		for (int j = 0; j < vp.size(); j++){
			dist[i][j] = d[vp[j].first][vp[j].second];
		}
	}
	
	static int dp[1 << 11][11];
	fill_n(*dp, (1 << 11) * 11, INF);
	dp[0][0] = 0;
	for (int i = 0; i < 1 << vp.size(); i++){
		for (int j = 0; j < vp.size(); j++){
			for (int k = 0; k < vp.size(); k++){
				int ni = i | 1 << k;
				dp[ni][k] = min(dp[ni][k], dp[i][j] + dist[j][k]);
			}
		}
	}
	
	int res = INF;
	for (int i = 0; i < vp.size(); i++){
		res = min(res, dp[(1 << vp.size()) - 1][i]);
	}
	
	return res == INF ? -1 : res;
}

int main()
{
	while (scanf("%d %d", &w, &h), w){
		memset(grid, 'x', sizeof(grid));
		
		for (int i = 1; i <= h; i++){
			for (int j = 1; j <= w; j++){
				scanf(" %c", &grid[i][j]);
			}
		}
		
		printf("%d\n", solve());
	}
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n; cin >> n;
  int p[n];
  for(int i=0; i<n; i++) cin >> p[i];
  int c=0;
  for(int i=1; i<n-1; i++){
    if(min({p[i-1], p[i], p[i+1]})!=p[i] && max({p[i-1], p[i], p[i+1]})!=p[i]) c++;
  }
  cout << c;
  return 0;
}

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

int main()
{
    int a,b,c,d,e,f,g;
    cin >> a;
    cin>> b;
    cin >> c;
    d=(a-b);
    e=(d/c);
    f=(e*c);
    g=(d-f);
    cout << g<< endl;
    return 0;
}

Measured memory_bytes: 3612
#include<cstdio>
#include<algorithm>
#include<cmath>
#define ll long long
#define N 100005
#define inf 0x3fffffff
#define rep(i, l, r) for(int i=l; i<=r; ++i)
using namespace std;
int n, k;
char s[N];
int main(){
    scanf("%d%d%s", &n, &k, s);
    int tmp=0;
    rep(i, 0, n-1){
        if(!i || s[i]!=s[i-1]) ++tmp;
    }
    tmp=max(1, tmp-2*k);
    printf("%d", n-tmp);
    return 0;
}

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

#define M 1046257
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}

long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str); 
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) % M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str); 
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str);
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 16036
mountain_heights = []
for i in range(10):
    mountain_heights.append(int(input()))

for i in range(3):
    maximum = 0
    index = i
    for j in range(i, 10):
        if mountain_heights[j] > maximum:
            maximum = mountain_heights[j]
            index = j
    temp = mountain_heights[i]
    mountain_heights[i] = mountain_heights[index]
    mountain_heights[index] = temp
    print(maximum)



Measured memory_bytes: 5596
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
int dx[4] = { 0,  0, 1, -1 };
int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

string solve(string s) {
	sort(DESC(s));
	int ma = atoi(s.c_str());
	sort(ASC(s));
	int mi = atoi(s.c_str());

	ostringstream sout;
	sout << setfill('0') << setw(4) << to_string(ma - mi);
	string ret = sout.str();
	return ret;
}

int main() {
	while (1) {
		string s; cin >> s;
		int tmp = atoi(s.c_str());
		if (!tmp) break;

		if (s[0] == s[1] && s[1] == s[2] && s[2] == s[3]) {
			cout << "NA" << endl;
			continue;
		}

		int cnt = 0;
		while (s != "6174") {
			s = solve(s);
			cnt++;
		}
		cout << cnt << endl;
	}
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll n;
    cin >> n;
    int sn = 0;
    for (ll i = n; i > 0 ; i /= 10) {
        sn += i%10;
    }
    if ((n % sn) == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
const ll Mod = 1000000007;
int main() {
  int A,B;
  cin >> A >> B;
  int ans = (A + B) % 24;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

from itertools import permutations

lis = [i+1 for i in range(N)]
per = permutations(lis,N)

index = 0
for i in per:
    if i == P:
        p_index = index
    if i == Q:
        q_index = index
    index += 1
    
print(abs(p_index-q_index))

Measured memory_bytes: 73252
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> board(H);
    Rep(i, H) {
        cin >> board[i];
    }
    int ans = 0;
    BitRep(a, H) {
        bitset<6> row(a);
        BitRep(b, W) {
            int count = 0;
            bitset<6> col(b);
            Rep(i, H) {
                if (!row[i]) continue;
                Rep(j, W) {
                    if (!col[j]) continue;
                    if (board[i][j] == '#') count++;
                }
            }
            if (count == K) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>
#include<numeric>
#include<stdlib.h>

using namespace std;

int main()
{
  int H, W;
  cin >> H >> W;

  char c[H][W];

  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> c[i][j];
    }
  }

  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cout << c[i][j];
    }
    cout << endl;
    for(int k=0; k<W; k++){
      cout << c[i][k];
    }
    cout << endl;
  }


  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	ll n,y; cin >> n >> y;
	//y/=1000;
	rep(i,n+1) {
		rep(j,n-i+1) {
				ll s=10000*i+5000*j+(n-i-j)*1000;
				if(s==y) {
					printf("%d %d %d\n",i,j,n-i-j);
					return 0;
			}
		}
	}
	printf("-1 -1 -1\n");
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;

class seg_tree{

public:
  int n;
  vector<int> seg;

  seg_tree(int nn) {
    n=1;
    while(n<nn) n*=2;

    seg = vector<int>(2*n-1, INF);
  }

  //k番目の値をaに変更
  //(k-1)/2で上の葉
  //(k*2)+1,2で下の葉
  void update(int k, int a) {
    k += n-1;
    seg[k] = a;
    while(k>0){
      k=(k-1)/2;
      seg[k] = min(seg[k*2+1], seg[k*2+2]);
    }
  }

  //query minimun in [a, b)
  //call this from  as query(a, b, 0, 0, tree.n)
  int query(int a, int b, int k, int l, int r){
    if(a==b) return seg[a+n-1];
    if(r <= a || b <= l) return INF;
    if(a <= l && r <= b) return seg[k];
    int vl = query(a, b, k*2+1, l, (l+r)/2);
    int vr = query(a, b, k*2+2, (l+r)/2, r);


    return min(vl, vr);
  }
};

int main(){
  int n;
  cin>>n;
  int a[n];
  REP(i, n)cin>>a[i];

  if(n==1){
    cout<<a[0]<<endl;
    return 0;
  }

  seg_tree tree(n);
  REP(i, n) {
    tree.update(i, a[i]);
  }

  LL ans=0;
  REP(i, n){
    int litr=i, ritr=i;
    if(i>0){
      int l=0, r=i;
      int x=(l+r)/2;
      while(r-l>1){
        if(tree.query(x, i+1, 0, 0, tree.n)==a[i]) r=x;
        else l=x;
        x=(l+r)/2;
      }
      if(tree.query(l, i+1, 0, 0, tree.n)==a[i]) x=l;
      else x=r;

      litr = x;
    }

    if(i<n-1){
      int l=i, r=n-1;
      int x=(l+r)/2;
      while(r-l>1){
        if(tree.query(i, x+1, 0, 0, tree.n)==a[i]) l=x;
        else r=x;
        x=(l+r)/2;
      }
      if(tree.query(i, r+1, 0, 0, tree.n)==a[i]) x=r;
      else x=l;

      ritr = x;
    }

    ans += (LL)(i-litr+1)*(ritr-i+1)*a[i];
    //cout<<litr<<" "<<ritr<<" "<<ans<<endl;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ff first
#define ss second
#define maxn 1000000007
#define PI 3.14159265358979323846
#define MAX 1000007 
using namespace std; 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    //cout<<fixed<<setprecision(20);
    string s;
    cin>>s;
    set<ll> st;
    for (int i = 0; i < s.length(); ++i)
    {
        st.insert(s[i]);
    }
    if(st.size()==2)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0037
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(2 * Math.PI * double.Parse(Console.ReadLine()));
        }
    }
}


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


int main() {
    int N,Q;
    string S;
    cin>>N>>S>>Q;
    vector<set<int>> atoz(26);
    rep(i,N){
        atoz.at(S.at(i)-'a').insert(i);
    }
    
    rep(i,Q){
        int a;
        cin>>a;
        if(a==1){
            int b;
            char c;
            cin>>b>>c;--b;
            atoz.at(S[b]-'a').erase(b);
            S[b]=c;
            atoz.at(c-'a').insert(b);
        }
        if(a==2){
            int b,c;
            cin>>b>>c;--b;
            int count=0;
            rep(j,26){
                auto p=atoz[j].lower_bound(b);
                if(p!=atoz[j].end() && *p<c){count++;}
            }
            cout<<count<<endl;
        }
    }
}


Measured memory_bytes: 24196
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
//    freopen("../input2.txt", "r", stdin);

    int N, M, a, b;
    int8_t odd[100000];

    memset(odd, 0, 100000);

    scanf("%d%d", &N, &M);

    for (int i = 0; i < M; i++) {
        scanf("%d%d", &a, &b);
        odd[a - 1] = odd[a - 1] ^ 1;
        odd[b - 1] = odd[b - 1] ^ 1;
        if (a < 1 || a > N || b < 1 || b > N || a == b)
            goto BadEnd;
    }

    short result = 1;
    for (int i = 0; i < N; i++) {
        if (odd[i]) {
            result = 0;
            break;
        }
    }

    if (result)
        printf("YES\n");
    else
        BadEnd:
        printf("NO\n");



    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        int s, a, c, m = 256, inp[256];
        double ans[4];
        ans[0] = INF;

        rep(i,n) cin >> inp[i];
        for(s = 0; s <= 15; s++){
            for(a = 0; a <= 15; a++){
                for(c = 0; c <= 15; c++){
                    int r[300];
                    double ental = 0;
                    int cnt[256] = {0};

                    rep(i,300){
                        if(i == 0) r[i] = s;
                        else r[i] = (a * r[i - 1] + c) % m;
                    }
                    rep(i,n){
                        cnt[(inp[i] + r[i + 1]) % m]++;
                    }
                    rep(i,256){
                        double temp = static_cast<double>(cnt[i]);
                        double N = static_cast<double>(n);
                        if(cnt[i] == 0) continue;
                        ental += -1 * log(temp / N) * temp / N;
                    }
                    if(ans[0] > ental + 1e-9){
                        ans[0] = ental;
                        ans[1] = s;
                        ans[2] = a;
                        ans[3] = c;
                    }
                }
            }
        }
        range(i,1,4){
            if(i != 1) cout << ' ';
            cout << ans[i];
        }
        cout << endl;
    }
}

Measured memory_bytes: 3548
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return input()
def n():
    return int(input())
def d():
    return float(input())

def ls():
    return input().split()
def ln():
    return map(int, input().split())
def ld():
    return map(float, input().split())

def fs():
    return [input() for i in range(input())]
def fn():
    return [int(input()) for i in range(input())]
def fd():
    return [float(input()) for i in range(input())]

N = n()


li=[]
for i in range(26):
    for j in range(16):
        li.append(i*4+j*7)

if N in li:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 5456
program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,k,m,n,ans,ss
    integer(8)::a,b,c,d
    integer(8),allocatable::y(:)
  
    read(*,*) a,b
    c=min(a,b)
    d=max(a,b)
    a=c
    b=d
    
    do i=1,1000
        c=mod(b,a)
        b=a
        a=c
        if(a==0)then
            exit
        end if
    end do
    a=b
    if(a==1)then
        write(*,*)1
        stop
    end if
    
    c=0
    ans=1
    ss=0
    d=int(sqrt(real(b)))
    do i=2,d+1
        c=0
        do j=1,100
            if(mod(a,i)==0)then
                a=a/i
                if(c==0)then
                    c=1
                    ss=1
                    ans=ans+1
                end if
            else
                exit
            end if
        end do
        if(a==1)then
            exit
        end if
    end do
    if(a>1)then
        ans=ans+1
    end if

    write(*,*)ans


   
    stop
end program sample
  



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

using namespace std;

int main()
{
	int N;
	cin >> N;
	for (int i = 1; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			if (i * j == N) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


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

char c;
int a, b;

int main () {
	while (~(c = getchar ())) {
		if (c == 'C') a = 1;
		else if (c == 'F' && a) b = 1;
	}
	puts (a && b ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i <= b; i++)
const int N = 510+10;
using namespace std;

int n,m,vis[N][N];
char s[N][N];

int main(){
    scanf("%d%d",&n,&m);
    rep(i,1,n) scanf("%s",s[i]+1);
    rep(i,1,n)
        rep(j,1,m)
            if(s[i][j] == '#') vis[i][j] = 1;
    rep(j,1,m) vis[1][j] = 2;
    rep(j,1,m) vis[n][j] = 3;
    rep(i,2,n-1)
        rep(j,1,m)
            if(!vis[i][j])
                vis[i][j] = (j%2==0) ? 2 : 3;
    rep(i,1,n){
        rep(j,1,m)
            if(vis[i][j] == 1 || vis[i][j] == 2) printf("#");
            else printf(".");
        printf("\n");
    }
    printf("\n");
    rep(i,1,n){
        rep(j,1,m)
            if(vis[i][j] == 1 || vis[i][j] == 3) printf("#");
            else printf(".");
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 2048
const main = (input) => {
  const num = Number(input);
  var flag = true;
  var moveNumXArray = [];
  var moveNumYArray = [];
  
  for(var i = 2; i <= Math.sqrt(num); i++){
    if(num % i === 0) {
      moveNumXArray.push(i - 1);
      moveNumYArray.push(num / i - 1);
      flag = false;
    }
  }
  
  if(flag){
    minMoveValue = num - 1;
  }else{
    var minMoveValue = num;
    for(var k=0; k < moveNumXArray.length; k++){
      if(minMoveValue > moveNumXArray[k] + moveNumYArray[k])
        minMoveValue = moveNumXArray[k] + moveNumYArray[k];
    }
  }
  console.log(minMoveValue);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));

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

int sums(int n){
    int re=0;
    while(n>9){
        re+=n%10;
        n/=10;
    }
    re+=n;
    return re;
}

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int sum=0;
    for(int i=1;i<=n;i++){
        if(sums(i)>=a && sums(i)<=b){
            sum+=i;
        }
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
cnt = 0
def dfs(i, x):
    global cnt
    if i == N:
        if x == 0:
            cnt += 1
        return
        
    dfs(i+1, ((A[i]+1) % 2) * x)
    dfs(i+1, (A[i] % 2) * x)
    dfs(i+1, ((A[i]-1) % 2) * x)

    return cnt

cnt = dfs(0, 1)

print(cnt)

Measured memory_bytes: 3064
n, m = gets.split.map(&:to_i)
s = []
c = []
for i in 0..m-1
  a, b = gets.split.map(&:to_i)
  s << a
  c << b
end
ans = -1
for k in 0..999
  next if k.to_s.length != n
  flag = true
  s.each_with_index do |si, i|
    if k.to_s[si-1] != c[i].to_s
      flag = false
    end
  end
  if flag
    ans = k
    break
  end
end
puts ans


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,n,m,b,c,sum=0,cnt=0;
	cin>>n>>m;
	priority_queue<pair<ll,ll>>q;
	for(ll i=0;i<n;i++){
		cin>>a;
		q.push({a,1});
	}
	for(ll i=0;i<m;i++){
		cin>>b>>c;
		q.push({c,b});
	}
	for(ll i=0;i<n;i++){
		auto p=q.top();
		p.second-=cnt;
		sum+=p.first;
		if(p.second<=1){
			q.pop();
			cnt=0;
		}else{
			cnt++;
		}
	}
	cout<<sum<<endl;
	return 0;
}


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

namespace AtCoder.Contests.ABC161
{
    /// <summary>
    /// 
    /// </summary>
    static class D
    {
        static void Main(string[] args)
        {
            var k = NextInt();
            int count = 0;

            var q = new Queue<long>();
            for (int i = 1; i < 10; i++)
            {
                q.Enqueue(i);
            }

            long num = 0;
            while (count < k)
            {
                num = q.Dequeue();
                count++;

                if (num % 10 > 0) q.Enqueue(num * 10 + num % 10 - 1);
                q.Enqueue(num * 10 + num % 10);
                if (num % 10 < 9) q.Enqueue(num * 10 + num % 10 + 1);
            }
            Console.WriteLine(num);
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


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

int main() {
  int N , A , B , C , D;
  cin >> N;
  A = N / 1000;
  B = N % 1000 / 100;
  C = N % 1000 % 100 / 10;
  D = N % 1000 % 100 % 10;
  
  if((A == B && B== C) || (B == C && C== D)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
int main()
{
    vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << a[K-1] << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


bool lcmp(const pair<int, int>& l, const pair<int, int>& r) {
  return l.first < r.first;
}

void solve(vector<pair<int, int>>& as) {

  int N = as.size();

  vector<int> bs(4, INT32_MIN);
  F0R(i, N) {
    chmax(bs[0], as[i].first + as[i].second);
    chmax(bs[1], as[i].first - as[i].second);
    chmax(bs[2], - as[i].first + as[i].second);
    chmax(bs[3], - as[i].first - as[i].second);
  }

  int r = 0;

  F0R(i, N) {
    chmax(r, max(max(bs[0]-as[i].first-as[i].second, bs[1]-as[i].first+as[i].second),
      max(bs[2] + as[i].first - as[i].second, bs[3] + as[i].first + as[i].second)));
  }

  cout << r;
}

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
#if 0
  N = 200000;
  vector<pair<int, int>> as(N);
  F0R(i, N) {
    as[i] = { 1,1 };
  }

#else
  cin >> N;
  vector<pair<int, int>> as(N);
  F0R(i, N) {
    cin >> as[i].first >> as[i].second;
  }
#endif
  solve(as);
}
#endif


Measured memory_bytes: 4784
//
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define speed ios::sync_with_stdio(false)
using namespace std;

string gs(char x){
    string s(1,x);
    return s;
}


int main()
{
	speed;
	
	string s;
	cin>>s;

	ll ans=0;
	for(ll i=0;i<s.length();i++)
	{
		if(s[i]=='+')
			ans++;
		else
			ans--;
	}
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


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






int main() {

	string S;
	cin >> S;
	ll N = S.size();

	string ans = "yes";

	rep(i, N) {
		for (ll j = i + 1; j < N; j++) {
			if (S[i] == S[j]) { ans = "no"; }
		}
	}

	cout << ans;
	system("PAUSE");
}


Measured memory_bytes: 504
#https://atcoder.jp/contests/abc153/tasks/abc153_b
S_list = [(input()) for i in range(2)]
H,N = map(int,S_list[0].split())
S_list_1 = list(map(int,S_list[1].split()))
damage = sum(S_list_1)
if damage >= H:
    result = "Yes"
else:
    result = "No"
print(result)

Measured memory_bytes: 21084
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include <numeric>
using namespace std;


int main()
{	long long int N;
	scanf("%lld", &N);
	
	
	long long int kosuu=0;
	long long int joken=1;
	long long int kazu=1;
	while(joken==1)
	{
		long long int Nkari=kazu;
		long long int Nkariss=kazu;
		long long int count=1;
		while(Nkari>=4)
		{
			Nkari=Nkari/4;
			count++;
		}
		long long int keta[count];
		long long int mita0=0;
		long long int mita1=0;
		long long int mita2=0;
		long long int mita3=1;
		for(int i=0;i<count;i++){
			keta[i]=Nkariss%4;
			if(keta[i]==1){mita0=1;}
			if(keta[i]==2){mita1=1;}
			if(keta[i]==3){mita2=1;}
			if((keta[i]==0)){mita3=0;}
			Nkariss=Nkariss/4;
		}
		
		long long int jusin=0;
		for(int i=0;i<count;i++){
			jusin=jusin+(2*keta[i]+1)*pow(10,i);
		}
		kazu++;
		
		if(jusin<=N){
		if((mita0+mita1+mita2)*mita3==3){
			kosuu++;
		}}
		else{joken=0;}
	}
	printf("%lld", kosuu);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

string S;

void solve() {
}

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

    cin >> S;
    set<char> s;
    for (auto& x : S)
        s.insert(x);
    No(s.count('N') + s.count('S') == 1 || s.count('E') + s.count('W') == 1);

    solve();
    return 0;
}


Measured memory_bytes: 3676
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

N = int(input())
P = [float(x) for x in input().split()]

dp = np.zeros(N+1) # 表の回数ごとの確率
dp[0] = 1.0
for p in P:
    prev = dp.copy()
    dp *= (1-p)
    dp[1:] += p * prev[:-1]

answer = dp[(N+1)//2:].sum()
print(answer)

Measured memory_bytes: 12516
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>


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

  std::string s;
  std::cin >> s;

  std::vector<std::string> tokens;
  std::istringstream iss{s};
  for (std::string token; std::getline(iss, token, '/');) {
    tokens.push_back(token);
  }

  std::vector<int> ns(tokens.size());
  std::transform(
    std::cbegin(tokens),
    std::cend(tokens),
    std::begin(ns),
    [](const auto& e) {
      return std::stoi(e);
    });
  std::cout << (ns[0] > 2019 || ns[1] > 4 || ns[2] > 30 ? "TBD" : "Heisei") << std::endl;

  return EXIT_SUCCESS;
}


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

long long F[10000002];



long long f(long long n)
{
    if(n<2)
    {
        return 1;
    }
    else
    {
        if(F[n]!=0)
        {
            return F[n];
        }
        else
        {
            F[n] = n*f(n-2);
            return F[n];

        }
    }

}

long long digit(long long n)
{
    int count = 0;

    while(n!=0)
    {
        int rem = n % 10;
        count++;
        n = n / 10;
    }

   // cout << count << endl;

    return count-1;
}
int main()
{
    unsigned long long n;

    cin >> n;

    if(n%2 || n<10)
    {
        cout << 0 << endl;

    }
    else
    {
       unsigned long long  count = 0;

       unsigned long long a = 2;

        while(1)
        {
            a = a * 5;
            if(a>n)
            {
                break;
            }

            count += (n/a);

        }

        cout << count << endl;

    }






    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int A, B;
	cin >> A >> B;
	rep(i, 3) {
		if (i + 1 != A && i + 1 != B) {
			cout << i + 1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void prt(int x,int y) {
	printf("%d %d\n",x,y);
}
int main() {
	int n,m=1;
	scanf("%d",&n);
	while(m<n) m<<=1;
	if(m==n) printf("No\n");
	else {
		printf("Yes\n");
		prt(1,2),prt(2,3),prt(3,n+1),prt(n+1,n+2),prt(n+2,n+3);
		for(int i=4;i<n;i+=2) {
			prt(1,i),prt(1,i+1);
			prt(i,i+1+n),prt(i+1,i+n);
		}
		if(n%2==0) {
			for(int i=2;i<n;i++) {
				if((n^i^1)<n) {
					prt(i,n);
					prt(n^i^1,2*n);
					break;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>

using namespace std;

int main(void){
  int n, d[100];
  int i, j, k, sum = 0;

  cin >> n;
  
  for(i = 0; i < n; i++){
    cin >> d[i];
  }
  for(i = 0; i < n - 1; i++){
    for(j = i + 1; j < n; j++){
      sum = sum + d[i] * d[j];
    }
  }
  cout << sum;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

int main() {
	int X, Y, Z;
	int cnt = 0;
	cin >> X >> Y >> Z;
	
	X -= Z;
	while (X >= Y + Z) {
		X = X - Y - Z;
		cnt++;
	}

	cout << cnt << endl;
	return 0;
}

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

using namespace std;

int main() {
    string s;
    int min = 1000;
    cin >> s;
    for (int i = 0; i < s.size() - 2; ++i) {
        min = std::min(min, abs(753 - stoi(s.substr(i, 3))));
    }
    cout << min << endl;
}

Measured memory_bytes: 256
n=int(input())
abc='abcdefghijklmnopqrstuvwxyz'
s=[]
t=[51]*len(abc)
#print(t)
for i in range(n):
    u=input()
    for j in range(len(abc)):
        v=u.count(abc[j])
        t[j]=min(t[j],v)
ans=''
for j in range(len(abc)):
    ans+=t[j]*abc[j]
print(ans)

Measured memory_bytes: 9124
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n = 0, l = 0;
    cin >> n >> l;
    if (l > 0) {
        n--;
        l++;
        cout << n*(2*l+n-1)/2 << endl;
    }
    else if (l+n-1 < 0) {
        n--;
        cout << n*(2*l+n-1)/2 << endl;
    }
    else {
        cout << n*(2*l+n-1)/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d;
            double x;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            x = (a + b) / 2.0;
            c = (a + b) / 2;

            if (x - c > 0) c++;

            Console.WriteLine(c);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
s = list(input())
t = list(input())

s_ord = sorted(list(map(ord, s)))
t_ord = sorted(list(map(ord, t)), reverse=True)

for i in range(min([len(s_ord), len(t_ord)])):
    if t_ord[i] > s_ord[i]:
        print("Yes")
        break
else:
    if len(s_ord) < len(t_ord) and s_ord == t_ord[:len(s_ord)]:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 8904
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  double r; cin >> r;
  cout << 3.1415 * r * 2.0 << endl;
}


Measured memory_bytes: 3768
#include <iostream>
using ll = long long;
using namespace std;

/* initialize */
struct card{
    char suit;
    int value;
};
card A[100000];
card L[60000], R[60000];
/* main */

int partition(card A[],int p,int r);


int quicksort(card A[], int p, int r) {
    if (p < r){
        int q = partition(A, p, r);
        quicksort(A, p, q-1);
        quicksort(A, q+1, r);
    }

}

int partition(card A[], int p, int r) {
    card temp{};
    card x = A[r];
    int i = p-1;
    for (int j = p; j < r; j++) {
        if (A[j].value <= x.value){
            i++;
            temp = A[i];
            A[i] = A[j];
            A[j] = temp;
        }
    }
    temp = A[i+1];
    A[i+1] = A[r];
    A[r] = temp;
    return i+1;
}

void merge(card A[],int left, int right){
    int mid = (left + right) / 2;
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; ++i)  L[i] = A[left+i];
    for (int j = 0; j < n2; ++j) R[j] = A[mid+j];
    L[n1].value = R[n2].value = INT32_MAX;
    int i = 0, j = 0;
    for ( int k = left; k < right; k++ ){
        if (L[i].value <= R[j].value) A[k] = L[i++];
        else A[k] = R[j++];
    }
}

void mergeSort(card A[], int n, int left, int right){
    if(left+1 < right){
        mergeSort(A, n, left,(left+right)/2);
        mergeSort(A, n, (left+right)/2, right);
        merge(A, left, right);
    }
}

int main() {
    int v;
    card A[100000], B[100000];
    char S[10];
    int stable = 1, n = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        scanf("%s %d" , S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    quicksort(B, 0, n-1);
    mergeSort(A, n, 0, n);


    for (int i = 0; i < n; ++i) {
        if (A[i].suit != B[i].suit) stable = 0;
    }
    if (stable) printf("Stable\n"); else printf("Not stable\n");
    for (int j = 0; j < n; j++) {
        printf("%c %d\n", B[j].suit, B[j].value);
    }
    return 0;
}


Measured memory_bytes: 5476
// Problem : C - Tsundoku
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mk make_pair
#define fast                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define rep(i, a, b) for (ll i = a; i < b; i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x) (int)x.size()
#define mem(a, val) memset(a, val, sizeof(a))
#define deci(x) cout << fixed << setprecision(x);
#define bitcount(x) __builtin_popcountll(x)

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

const long long int mod = 1e9 + 7;
const long double EPS = 1e-12;
const int N = 1e5 + 20;

void solve() {
  ll ans = 0;
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1, 0), b(m + 1, 0);
  rep(i, 1, n + 1) cin >> a[i];
  rep(i, 1, m + 1) cin >> b[i];

  rep(i, 2, n + 1) a[i] += a[i - 1];
  rep(i, 2, m + 1) b[i] += b[i - 1];

  ll i = 0, j = m;

  while (i <= n && k >= a[i]) {
    ll rem = k - a[i];

    while (j >= 0 && rem < b[j]) {
      j--;
    }
    // cout << i << " " << j << " " << rem << endl;
    ans = max(ans, i + j);
    i++;
  }
  i = 0, j = n;

  while (i <= m && k >= b[i]) {
    ll rem = k - b[i];

    while (j >= 0 && rem < a[j]) {
      j--;
    }
    // cout << i << " " << j << " " << rem << endl;
    ans = max(ans, i + j);
    i++;
  }

  cout << ans << '\n';
}
int main() {
  fast;
  ll t;
  t = 1;

  // cin>>t;

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

  return 0;
}


Measured memory_bytes: 6364
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;
Node NIL;

Node treeSearch(Node u, int k){
	while( u != NIL && k != u-> key ){
    if ( k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}
void insert(int k){
    Node y = NIL;
    Node x = root;
    Node z;
    
    z = malloc(sizeof(struct node));
    z->key = k;
    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 n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ) {
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if( t != NIL )
	printf("yes\n");
      else
	printf("no\n");
    }
    else if( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 20472
n,m = gets.chomp.split(' ').map(&:to_i)
l_max = 0
r_min = n + 1
m.times do
  l,r = gets.chomp.split(' ').map(&:to_i)
  if l > l_max
    l_max = l
  end
  if r < r_min
    r_min = r
  end
end
if  l_max > r_min
  puts 0
else
  puts r_min - l_max + 1
end

Measured memory_bytes: 14264
#include <bits/stdc++.h>
using namespace std;
const int N=200005;
int read(){
	int x=0;
	char ch=getchar();
	while (!isdigit(ch))
		ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x;
}
int n,X,Y;
vector <int> er[N],eb[N];
int depth[N],fa[N][20];
int tag[N];
void dfs1(int x,int pre,int d){
	depth[x]=d,fa[x][0]=pre;
	for (int i=1;i<20;i++)
		fa[x][i]=fa[fa[x][i-1]][i-1];
	for (auto y : eb[x])
		if (y!=pre)
			dfs1(y,x,d+1);
}
int LCA(int x,int y){
	if (depth[x]<depth[y])
		swap(x,y);
	for (int i=19;i>=0;i--)
		if (depth[x]-(1<<i)>=depth[y])
			x=fa[x][i];
	if (x==y)
		return x;
	for (int i=19;i>=0;i--)
		if (fa[x][i]!=fa[y][i])
			x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
int Dis(int x,int y){
	return depth[x]+depth[y]-2*depth[LCA(x,y)];
}
int vis[N],ans=0;
void dfs(int x,int d){
	vis[x]=1;
	int k1=Dis(x,Y);
	if (d>=k1){
		ans=max(ans,d*2-(d>k1));
		return;
	}
	if (tag[x]){
		ans=max(ans,10000000);
		return;
	}
	ans=max(ans,k1*2);
	for (auto y : er[x])
		if (!vis[y])
			dfs(y,d+1);
}
int main(){
	n=read(),X=read(),Y=read();
	for (int i=1;i<=n;i++)
		er[i].clear(),eb[i].clear();
	for (int i=1;i<n;i++){
		int a=read(),b=read();
		er[a].push_back(b);
		er[b].push_back(a);
	}
	for (int i=1;i<n;i++){
		int a=read(),b=read();
		eb[a].push_back(b);
		eb[b].push_back(a);
	}
	dfs1(1,0,0);
	memset(tag,0,sizeof tag);
	memset(vis,0,sizeof vis);
	for (int x=1;x<=n;x++)
		for (auto y : er[x])
			if (Dis(x,y)>2)
				tag[x]=tag[y]=1;
	dfs(X,0);
	printf("%d",ans<2e6?ans:-1);
	return 0;
}

Measured memory_bytes: 49024
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000

int main(){

    int A, B, C; cin >> A >> B >> C;
    int ans = 0;
    set<pair<int, pair<int, int> > > s;
    s.insert(make_pair(A, make_pair(B, C)));
    s.insert(make_pair(B, make_pair(C, A)));
    s.insert(make_pair(C, make_pair(A, B)));
    while(A % 2 == 0 && B % 2 == 0 && C % 2 == 0){
        int a = A/2;
        int b = B/2;
        int c = C/2;
        A = b + c;
        B = a + c;
        C = a + b;
        std::set<pair<int, pair<int, int> > >::iterator it;
        it = s.find(make_pair(A, make_pair(B, C)));
        if(it != s.end()){
            ans = -1;
            break;
        }
        it = s.find(make_pair(B, make_pair(C, A)));
        if(it != s.end()){
            ans = -1;
            break;
        }
        it = s.find(make_pair(C, make_pair(A, B)));
        if(it != s.end()){
            ans = -1;
            break;
        }
        ans++;
        //cout << A << " " << B << " " << C << " " << ans << endl;
    }

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

Measured memory_bytes: 256
n, m = map(int, input().split())
s = []
c = []
number = 100000
for i in range(m):
    x, y = map(int, input().split())
    s = s + [x]
    c = c + [str(y)]
for i in range(1000):
    count = 0
    i_list = list(str(i))
    if len(i_list) == n:
        for j in range(m):
            if i_list[s[j] - 1] != c[j]:
                count += 1
        if count == 0:
            number = i
            break
if number < 10000:
    print(number)
else:
    print('-1')


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

int main()
{
	string a, b, c;
	cin >> a >> b >> c;

	if (a[a.size() -1] == b[0] && b[b.size() -1] == c[0])
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256