akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

int main() {
    ll n, a, ans0 = 0, ans1 = 0, sum0 = 0, sum1 = 0;
    cin >> n;
    rep(i, n) {
        cin >> a;
        sum0 += a;
        sum1 += a;
        if (i % 2 == 0) {
            if (sum0 <= 0) {
                ans0 += 1 - sum0;
                sum0 = 1;
            }
            if (sum1 >= 0) {
                ans1 += sum1 + 1;
                sum1 = -1;
            }
        } else {
            if (sum1 <= 0) {
                ans1 += 1 - sum1;
                sum1 = 1;
            }
            if (sum0 >= 0) {
                ans0 += sum0 + 1;
                sum0 = -1;
            }
        }
    }
    cout << min(ans0, ans1) << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;
vector<ll> num;
ll x[100];
int main(){
    ll ans=0,tmp=0;
    string s;
    cin>>s;
    rep(i,0,s.length())x[i]=s[i]-'0';
    for(int mask = 0; mask < (1 << s.length()-1); mask++){
        tmp=x[0];
        rep(i,0,s.length()-1){
            if(mask&(1<<i)){ans+=tmp;tmp=x[i+1];}
            else tmp=tmp*10+x[i+1];
        }
        ans+=tmp;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
    ll k;
    cin>>k;
    ll sum=0;
    for(ll i=1; i<=k; i++)
    {
        for(ll j=1; j<=k; j++)
        {
            for(ll m=1; m<=k; m++)
            {
                sum+=__gcd(i, __gcd(j, m));
            }
        }
    }
    cout<<sum;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 3628
package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)

	stdin.Scan()
	a, _ := strconv.Atoi(stdin.Text())
	stdin.Scan()
	b, _ := strconv.Atoi(stdin.Text())
	stdin.Scan()
	c, _ := strconv.Atoi(stdin.Text())
	stdin.Scan()
	sum, _ := strconv.Atoi(stdin.Text())

	ans := 0

	for x := 0; x <= a; x++ {
		for y := 0; y <= b; y++ {
			for z := 0; z <= c; z++ {
				if x*500+y*100+z*50 == sum {
					ans++
				}
			}
		}
	}

	fmt.Printf("%v\n", ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	int t;
	cin >> t;
	vector<int> a(n);
	vector<int> b(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i];
    }
	vector<pair<int, int>> x;
	for (int i = 0; i < n; ++i) x.pb(mp(a[i], -b[i]));
	sort(all(x));
	for (int i = 0; i < n; ++i) {
	    a[i] = x[i].first;
		b[i] = -x[i].second;
	}
  
	int ans = 0;
	int m = 6010;
	vector<vector<int>> dp(n, vector<int> (m, 0));
	dp[0][a[0]] = b[0];
	ans = b[0];
	for (int i = 1; i < n; ++i) {
	    for (int j = 0; j < m; ++j) {
			dp[i][j] = dp[i - 1][j];
			if (j > 0) dp[i][j] = max(dp[i][j], dp[i][j - 1]);
			ans = max(ans, dp[i][j]);
			if (j - a[i] >= t) continue;
			if (j - a[i] < 0) continue;
		    dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i]] + b[i]);
			ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 70912
import sys
a,b,c=map(int,input().split())
if a == 5:
    if b == 5:
        if c == 7:
            print('YES')
            sys.exit()
    elif b==7:
        if c == 5:
            print('YES')
            sys.exit()
if a == 7:
    if b==c==5:
        print('YES')
        sys.exit()
print('NO')

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=1<<30;

map <int,int> ma;

int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(ma[x]==0) ma[x]=1;
		else{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	
	return 0;
}

Measured memory_bytes: 9600
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int unsigned long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int base=1e4+7;
struct hash_{
	int power[400005],hashed[400005],mod;
	void in(V<int> v){
		power[0]=1;
		rep(i,0,v.size()){
			power[i+1]=power[i]*base%mod;
			hashed[i+1]=(hashed[i]*base+v[i])%mod;
		}
	}
	int get(int l,int r){
		RE (hashed[r]+mod-hashed[l]*power[r-l]%mod)%mod;
	}
};
struct hashing{
	hash_ hash1,hash2;
	void put(V<int> v){
		hash1.mod=1e9+7;
		hash2.mod=998244353;
		hash1.in(v);hash2.in(v);
	}
	P<int,int> get(int l,int r){
		RE MP(hash1.get(l,r),hash2.get(l,r));
	}
};
V<int> c,d;int n,a[200005],b[200005];
hashing ha,hb;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	rep(i,0,n)cin>>a[i];
	rep(i,0,n)cin>>b[i];
	c.resize(n*2);d.resize(n*2);
	rep(i,0,n){
		c[i]=a[i]^a[(i+1)%n];c[i+n]=c[i];
		d[i]=b[i]^b[(i+1)%n];d[i+n]=d[i];
	}
	ha.put(c);hb.put(d);
	rep(i,0,n){
		if(ha.get(i,i+n)==hb.get(0,n)){
			cout<<i<<' '<<(a[i]^b[0])<<'\n';
		}
	}
	RE 0;
}



Measured memory_bytes: 40848
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
xy=[list(map(int,input().split())) for i in range(n)]

dic={}
for i in range(n):
    x,y=xy[i]
    if (0,x) in dic:
        dic[(0,x)].append(y)
    else:
        dic[(0,x)]=[y]
    x,y=y,x
    if (1,x) in dic:
        dic[(1,x)].append(y)
    else:
        dic[(1,x)]=[y]
# print(dic)

lst=[[0]*(10**5+1) for i in range(2)]

ans=0
for x,y in xy:
    if lst[0][x]==1:
        continue
    lst[0][x]=1
    d=deque([(0,x)])
    xcnt,ycnt=0,0
    cnt=0
    while d:
        # print(d)
        now=d.popleft()
        if now[0]==0:
            xcnt+=1
        else:
            ycnt+=1
        for j in dic[now]:
            cnt+=1
            if lst[1-now[0]][j]==0:
                lst[1-now[0]][j]=1
                d.append((1-now[0],j))
    # print(xcnt,ycnt,cnt)
    ans+=xcnt*ycnt-cnt//2
print(ans)

Measured memory_bytes: 115764
from math import ceil
res = 0
N, K = map(int, input().split())
for n in range(1, N + 1):
    if n >= K:
        res += 1 / N
        continue
    val = ceil(K / n - 1)
    res += 1 / (2 ** (len(bin(val)) - 2) * N)
print(res)

Measured memory_bytes: 3060
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

    public static final int MOD = (int) (Math.pow(10, 9) + 7);

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        Deque<Long> q = new ArrayDeque<>();
        for (int i = 1; i < n + 1; i++) {
            long a = Long.parseLong(sc.next());
            if (i % 2 != 0) {
                q.addLast(a);
            } else {
                q.addFirst(a);
            }
        }
        StringBuilder sb = new StringBuilder();
        if (n % 2 == 0) {
            for (long a : q) {
                sb.append(a);
                sb.append(" ");
            }
        } else {
            for (int i = 0; i < n; i++) {
                sb.append(q.pollLast());
                sb.append(" ");
            }
        }
        sb.setLength(sb.length() - 1);
        sb.append("\n");
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 72068
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 1000000007;
int main() {
    int N; cin >> N;
    vector<int> X(N); for (auto &x : X) cin >> x;
    Int ans = 1, cnt = 0, i = 0;
    for (int t = 0; t < N; t++) {
        while (i < N && X[i] >= cnt * 2 + 1) i++, cnt++;
        if (i < N && X[i] == cnt * 2) i++, cnt++;
        ans = ans * cnt % MOD;
        cnt--;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String s1, s2;
		s1 = s2 = "";
		for(int i = 0; i < 2; i++) {
			s1 += s.charAt(i);
			s2 += s.charAt(i + 2);
		}

		int a = Integer.valueOf(s1);
		int b = Integer.valueOf(s2);

		if(a < 13 && b < 13 && a > 0 && b > 0) System.out.println("AMBIGUOUS");
		else if(a < 13 && a > 0) System.out.println("MMYY");
		else if(b < 13 && b > 0) System.out.println("YYMM");
		else System.out.println("NA");

		sc.close();
	}
}


Measured memory_bytes: 22484
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;


int main(void){
int aa[4], bb[4];
int ht, bl, j;

	while(cin >> aa[0]){
		rep2(j,1,4) cin >> aa[j];
		rep(i,4) cin >> bb[i];
		ht = 0; bl = 0;
		rep(i,4) rep(j,4) {
			if(aa[i] == bb[j]){
				if(i==j) ht++;
				else     bl++;
			}
		}	
		cout << ht << " " << bl << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(){
  char m;
  int a,b,c[256],i,j;
  for(i=0;i>-1;i++){
    scanf("%d %c %d",&a,&m,&b);
    if(m=='?'){
      break;
    }
    if(m=='+'){
      c[i]=a+b;
    }
    if(m=='-'){
      c[i]=a-b;
    }
    if(m=='*'){
      c[i]=a*b;
    }
    if(m=='/'){
      c[i]=a/b;
    }
  }
  for(j=0;j<i;j++){
    printf("%d\n",c[j]);
  }
  return(0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int x,y; cin>>x>>y;
    for (int i = 0; i <= x; ++i) {
        int kame = i;
        int tsuru = x-i;
        if (kame*4+tsuru*2 == y) {
            cout << "Yes" << '\n';
            return 0;
        }
    }

    cout << "No" << '\n';
    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int sum = 1;
  for (int i = 0; i < N; i++) {
    if (sum < K) {
      sum += sum;
    }
    else {
      sum += K;
    }
  }
  cout << sum << endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int x,i,zah = 0;
    scanf("%d",&x);
    for (i = 1;;i++) {
        zah += i;
        if (zah >= x) {
            printf("%d\n",i);
            break;
        }
    }
    return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 3;

void solve(){
    ll N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;
    --A, --B, --C, --D;

    // C < D
    // C前にAがBを抜き去れるかどうか
    if(C > D) {
        bool flag = false;
        for(int i = B - 1; i < N; ++i){
            if(S[i] == '.' && S[i + 1] == '.'&& S[i + 2] == '.'){
                B = i + 2;
                A = i + 1;
                swap(C, D);
                if(A <= C && B <= D){
                    flag = true;
                }
                break;
            }
        }
        if(!flag){
            cout << "No\n";
            return;
        }
    }

    // B -> D
    for(int i = B; i < D; ++i){
        if(S[i] == '#' && S[i + 1] == '#'){
            cout << "No\n";
            return;
        }
    }

    // A -> C
    for(int i = A; i < C; ++i){
        if(S[i] == '#' && S[i + 1] == '#'){
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";
    return;
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 640
#include <iostream>

using namespace std;

void print_table(int A[], int n){
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<A[i];
  }
  cout<<endl;
}
 
int main(){

  int n,key,A[100],j;
 
  cin>>n;
  for(int i=0;i<n;i++) cin>>A[i];
  print_table(A, n);
  for(int i=1;i<n;i++){
    key=A[i];
    j=i-1;
    while(j>=0&&A[j]>key){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=key;
    print_table(A, n);
  }
  return 0;
}


Measured memory_bytes: 3080
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
const int MAX_W = 10000;
const int MAX_H = 10000;
const int MAX_N = 1000;

int main(void) {
  int W, H, N, tx[MAX_N], ty[MAX_N], i;
  scanf("%d %d %d", &W, &H, &N);
  for(i = 0; i < N; ++i) scanf("%d %d", &tx[i], &ty[i]);
  int ny = ty[0], nx = tx[0], ans = 0;
  for(i = 1; i < N; ++i){
    int cnt = 0;
    if(ny < ty[i] && nx < tx[i]){
      cnt = (ty[i] - ny < tx[i] - nx ? ty[i] - ny : tx[i] - nx);
      ans += cnt;
      ny += cnt;
      nx += cnt;
    }else if(ny > ty[i] && nx > tx[i]){
      cnt = (ny - ty[i] < nx - tx[i] ? ny - ty[i] : nx - tx[i]);
      ans += cnt;
      ny -= cnt;
      nx -= cnt;
    }
    ans += abs(ny - ty[i]) + abs(nx - tx[i]);
    ny = ty[i];
    nx = tx[i];
  }
  printf("%d\n", ans);
  return 0;
}

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

namespace _1_11_C_2
{
    class Program
    {


        static void Main(string[] args)
        {
            string[] dice1 = Console.ReadLine().Split();
            string[] dice2 = Console.ReadLine().Split();
            string[] order = { "S", "S", "S", "N", "S", "S", "S", "N", "S", "S", "S", "E","S","S","S"
            ,"E","S","S","S","N","S","S","S"};
            string str = "No";

            for (int i = 0; i < order.Length; i++)
            {
                if (Judge(dice1, dice2) == true)
                {
                    str = "Yes";
                    break;
                }
                Order(order, i, dice2);
            }
            if (Judge(dice1, dice2) == true)
            {
                str = "Yes";
            }
            Console.WriteLine(str);
        }

        //文字で転がす方向を決める
        static void Order(string[] order, int i, string[] dice)
        {
            if (order[i] == "S") Roll_South(dice);
            if (order[i] == "N") Roll_Noth(dice);
            if (order[i] == "E") Roll_East(dice);
        }
        //サイコロを東西南北に転がす
        static void Roll_South(string[] dice)
        {
            string str = dice[0];
            dice[0] = dice[2];
            dice[2] = dice[5];
            dice[5] = dice[3];
            dice[3] = str;
        }
        static void Roll_Noth(string[] dice)
        {
            string str = dice[0];
            dice[0] = dice[1];
            dice[1] = dice[5];
            dice[5] = dice[4];
            dice[4] = str;
        }
        static void Roll_East(string[] dice)
        {
            string str = dice[0];
            dice[0] = dice[4];
            dice[4] = dice[5];
            dice[5] = dice[1];
            dice[1] = str;
        }
 

        //同じサイコロか判定する
        static bool Judge(string[] dice1, string[] dice2)
        {

            if (dice1[0] == dice2[0] && dice1[1] == dice2[1] && dice1[2] == dice2[2]
                && dice1[3] == dice2[3] && dice1[4] == dice2[4] && dice1[5] == dice2[5])
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}


Measured memory_bytes: 19900
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main(){
  vector<vector<int>> agent;
  vector<int> a;
  double save1,save2,save3;
  int s,t;
  
  cin>>s>>t;
  int result[s][2];
  for(int i=0;i<s;i++){
    cin>>save1>>save2;
    a.push_back((int)save1);
    a.push_back((int)save2);
    agent.push_back(a);
    a.clear();
  }
  
  for(int i=0;i<t;i++){
    cin>>save1>>save2;
    for(int j=0;j<s;j++){
      save3=abs(agent[j][0]-save1)+abs(agent[j][1]-save2);
      if(i==0){
        result[j][0]=i+1;
        result[j][1]=save3;
      }
      else if(save3<result[j][1] ){
        result[j][0]=i+1;
        result[j][1]=save3;
      }
    }
  }
  for(int i=0;i<s;i++){
    cout<<result[i][0]<<endl;
  }
}

Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())
s = input()

def canJump(check):
    prev = False
    for c in check:
        if c == '#':
            if prev:
                return False
            else:
                prev = True
        else:
            prev = False
    return True

def canJump2(check):
    ren = 0
    for c in check:
        if c == '.':
            ren += 1
        else:
            ren = 0
        if ren == 3:
            return True
    return False


if c < b:
    check1 = s[a:c]
    check2 = s[b:d]
    if canJump(check1) and canJump(check2):
        print('Yes')
    else:
        print('No')

elif c < d:
    check = s[a:d]
    if canJump(check):
        print('Yes')
    else:
        print('No')

else:
    check1 = s[a:c]
    check2 = s[b-2:d+1]
    if canJump(check1) and canJump2(check2):
        print('Yes')
    else:
        print('No')



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

int main() {
  vector<bool> prime(100100,true);
  for(int i=2;i*i<100100;i++){
    if(prime.at(i)){
      int k=2;
      while(i*k<=100001){
        prime.at(i*k)=false;
        k++;
      } 
    }
  }
  vector<int> like(100100,0);
  for(int i=2;i<100001;i++){
    like.at(i)=like.at(i-1);
    if(i%2==1&&prime.at(i)&&prime.at((i+1)/2)) like.at(i)++;
  }
  int Q; cin>>Q;
  rep(i,Q){
    int a,b; cin>>a>>b;
    cout<<like.at(b)-like.at(a-1)<<endl;
  }
}

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

using namespace std;

int main() {
    int N = 0;
    unsigned long long A = 0, ans = 1;
    vector<unsigned long long > vec;
    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> A;
        vec.push_back(A);
    }

    sort(vec.begin(), vec.end());

    unsigned long long z = pow(10, 18);
    for (unsigned long long x:vec) {
        if (x == 0) {
            cout << 0 << endl;
            return 0;
        } else {
            if(x<=z/ans){
                ans*=x;
            }else{
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4324
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int ans=0;
  int N,M;
  cin >> N >> M;
  vector<pair<int,int>> P;
  int a,b;
  rep(i,M){
    cin >> a >> b;
    a--; b--;
    P.pb(make_pair(a,b));
  }
  for(int i=0;i<M;i++){
    vector<vector<int>> G(N);
    rep(j,M){
      if(i==j) continue;
      G[P[j].first].pb(P[j].second);
      G[P[j].second].pb(P[j].first);
    }
    vector<int> d(N,-1);
    d[0] = 0;
    queue<int> q;
    q.push(0);
    while(!q.empty()){
      int now = q.front(); q.pop();
      for(int j=0;j<(int)G[now].size();j++){
        if(d[G[now][j]]>=0) continue;
        q.push(G[now][j]);
        d[G[now][j]] = d[now] + 1;
      }
    }
    rep(j,N){
      if(d[j] == -1) {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

#define INF 0xc0c0c0c0
#define NINF 0x3f3f3f3f

#define FOR(i, a, b) for((i)=a; i<b; ++(i))
#define EFOR(i, a, b) for((i)=a; i>b; --(i))

#define MLC(n, type) (type*)malloc(n*sizeof(type))
#define CLC(n, type) (type*)calloc(n, sizeof(type))

void solver(int a, int b, int c) {
	if (a <= 0 || b <= 0 || c <= 0) {
		printf("No\n");
		return;
	}

	if (a == b && b == c) {
		printf("Yes\n");
		return;
	}

	printf("No\n");
	return;
}

int main() {
	int a = 0, b = 0, c = 0;

	scanf("%d %d %d", &a, &b, &c);
	solver(a, b, c);
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace AIZU {
	class Program {
		#region Reserve
		static int cin() { return cin(-1); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static int[] cins(char spliter) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(spliter);
			int[] Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static int[] cins() { return cins(' '); }
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }
		#endregion
		
		static void Main(string[] args) {
			int N = cin();
			int[] link = new int[N];
			for (int i = 0; i < N; i++) {
				link[i] = cin()-1;
			}
			HashSet<int> Hist = new HashSet<int>();
			int light = 0;
			int count = 0;
			while (true) {
				light = link[light];
				if (Hist.Contains(light)) { count = -1; break; }
				Hist.Add(light);
				count++;
				if (light == 1) break;
			}
			print(count);
			Console.ReadKey();
		}
	}
}

Measured memory_bytes: 18016
from collections import deque
import numpy as np
h, w = map(int, input().split())
mass = [[ord(i) for i in input()] for _ in range(h)]
wall = ord("#")


def bfs(s, t):
    if mass[s][t] == wall:
        return 0
    visited = [[False] * w for _ in range(h)]
    depth = np.zeros((h, w))
    q1 = deque([s])
    q2 = deque([t])
    visited[s][t] = True
    while q1:
        i = q1.popleft()
        j = q2.popleft()
        r = depth[i][j] + 1
        if j != w - 1:
            if mass[i][j + 1] != wall and not visited[i][j + 1]:
                q1.append(i)
                q2.append(j+1)
                visited[i][j + 1] = True
                depth[i][j + 1] += r
        if j != 0:
            if mass[i][j - 1] != wall and not visited[i][j - 1]:
                q1.append(i)
                q2.append(j - 1)
                visited[i][j - 1] = True
                depth[i][j - 1] += r
        if i != 0:
            if mass[i - 1][j] != wall and not visited[i - 1][j]:
                q1.append(i-1)
                q2.append(j)
                visited[i - 1][j] = True
                depth[i - 1][j] += r
        if i != h - 1:
            if mass[i + 1][j] != wall and not visited[i + 1][j]:
                q1.append(i + 1)
                q2.append(j)
                visited[i + 1][j] = True
                depth[i + 1][j] += r
    return np.max(depth)


ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, bfs(i, j))
print(int(ans))


Measured memory_bytes: 12464
#include <iostream>
#include <string>
#include<vector>
#define max 100000
using namespace std;

int find(int arr[], int len, int seek)
{
    for (int i = 0; i < len; ++i)
    {
        if (arr[i] == seek) return i;
    }
    return -1;
}

int main() {
  int n;
  int a[max], b[max];
  int ans = 0;
  int B = 1000000000;
  int A;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i] >> b[i];
  }

  for(int i = 0; i < n; i++){
    B = min(B, b[i]);
  }

  for (int i = 0; i < n; i++) {
    if (b[i] == B){
      A = a[i];
    }
  }

  // A = IndexOf(b[], B);

  ans = A + B;

  cout << ans << endl;
  

  return 0;
}

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

using namespace std;

int main()
{
    int N;
    int X, Y;

    cin >> N >> X >> Y;
    X--, Y--;
    vector<int> dist(N);

    for (int i = 0; i < N; i++)
        for (int j = i + 1; j < N; j++)
            dist.at(min(abs(j - i), abs(X - i) + 1 + abs(Y - j)))++;

    for (int i = 1; i < N; i++)
        cout << dist.at(i) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,m,g=0;
    cin>>n>>m;

      string s[n],t[m];
      for(int i=0;i<n;i++)
      {
        cin>>s[i];

      }
      for(int i=0;i<m;i++)
      {
        cin>>t[i];
      }
      for(int i=0;i<n;i++)
      {
        for(int j=0;j<n;j++)
        {
          if(s[i][j]==t[0][0])
          {
            ll count=0;
            for(int p=0;p<m;p++)
            {
              ll f=0;
              for(int q=0;q<m;q++)
              {
                if(s[i+p][j+q]==t[p][q])
                {
                  count++;
                }
                else
                {
                  f=1;
                  break;
                }

              }
              if(f)
              {
                break;
              }

            }
            if(count==m*m)
              g=1;

          }
        }
      }
      if(g)
        Yes
      else
        No

}
return 0;
}

Measured memory_bytes: 256
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define REP(i, x) for(int i = 0; i < (int)(x); i++)
#define REPS(i,x) for(int i = 1; i <= (int)(x); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define PB(a) push_back(a)
#define debug(x) cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  string s;
  cin >> s;
  string t[4] = {"dream", "dreamer", "erase", "eraser"};

  reverse(ALL(s));
  FOR(i, 0, 4) reverse(ALL(t[i]));

  int i = 0;
  while (true){
    bool found2 = false;
    FOR(j, 0, 4){
      if(s.substr(i, t[j].size()) == t[j]){
        i += t[j].size();
        found2 = true;
        break;
      }
    }
    debug(i);
    debug(s.size());
    debug(found2);
    if (!found2){
      cout << "NO" << endl;
      return 0;
    }
    else if(i==s.size()){
      cout << "YES" << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 512
# shell sort
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/2/ALDS1_2_D

import sys
readline = sys.stdin.buffer.readline
cnt = 0


def insersion_sort(A: list, n: int, g: int):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            cnt += 1
        A[j + g] = v
    return


def shell_sort(A: list, n: int):
    # 数列 G = {1,4,13,40,121,363,...}を生成
    G = []
    h = 1
    while h <= n:
        G.append(h)
        h = h * 3 + 1
    G = G[::-1]
    print(len(G))
    print(" ".join([str(g) for g in G]))
    for g in G:
        insersion_sort(A, n, g)
    return A


n = int(readline())
A = []

for _ in range(n):
    A.append(int(readline()))

shell_sort(A, n)
print(cnt)
for a in A:
    print(a)



Measured memory_bytes: 45500
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline

N, Q = map(int, input().split())
ki = [[[],0] for i in range(N)]
result = [0]*N

def dfs(i, num, parent):
    num_tmp = num+ki[i][1]
    result[i] = num_tmp
    if not ki[i][0]:
        return
    for j in ki[i][0]:
        if j == parent:
            continue
        dfs(j, num_tmp, i)
    return

for i in range(N-1):
    a, b = map(int, input().split())
    ki[a-1][0].append(b-1)
    ki[b-1][0].append(a-1)

for i in range(Q):
    p, x = map(int, input().split())
    ki[p-1][1] += x

dfs(0, 0, -1)
print(*result)

Measured memory_bytes: 254356
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using P = pair <int, int>;
 
int sumdigit(int x){
  if(x/10==0) return x;
  return sumdigit(x/10)+x%10;
  }

int main(){
    
   ll x,y;
   cin >> x>>y;
   int cnt =0;
   while(x<=y){
      x*=2;
      cnt++;
   }
   cout << cnt <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,n)  for(ll i=0;i<n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef pair<int,int> pii;
int main()
{
	IOS;
	//int t; cin>>t;
	int t=1;
	while(t)
	{
		int n; cin>>n;
		int w=n%1000;
		if(w==0) cout<<"0";
		else
		{
		w=1000-w;
		cout<<w;
	}
		t--;
	}
	return 0;
}

Measured memory_bytes: 3640
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		char x = next().charAt(0);
		char y = next().charAt(0);

		out.println(x < y ? "<" : x > y ? ">" : "=");
	}

	private void solveB() {
		int numX = nextInt();
		int numY = nextInt();
		int numZ = nextInt();

		int res = (numX - numZ) / (numY + numZ);

		out.println(res);
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main() {
	long long N; cin >> N;
	ll m = (int)sqrt(N) + 1;
	assert(m * m >= N);
	while (N % m) {
		m--;
	}
	ll ans = m + N / m - 2;
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep2(i,n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
template <class T>
using Grid = vector<vector<T>>;

int main(){
    ll l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r; i++) {
        if (i % d == 0)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    string x;
    ll ans=0;
    cin >> x;
    for (int i=0;i<4;++i){
        if (x[i]=='+'){
            ++ans;
            continue;
        }
        --ans;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int A, B, C;
  int N;
  cin >> A >> B >> C >> N;
  
  int X = max(A, max(B, C));
  
  int a = 0;
  int b = 0;
  int c = 0;
  
  if (X == A) {
    b = B;
    c = C;
  } else if (X == B) {
    a = A;
    c = C;
  } else {
    a = A;
    b = B;
  }
  
  for (int i = 0; i < N; i++) {
     X *= 2;
  }
  
  cout << X + a + b + c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <string>

using namespace std;
using ll = long long;
using P = pair<int, int>;

ll abs(int n, vector<int> X,int subave) {
	ll souwa= 0;
	for (int i = 0; i < n; i++) {
		souwa += (X[i] - subave)*(X[i] - subave);
	}
	return souwa;
}

int main() {
	int n;
	cin >> n;
	vector<int> X(n);
	long long sum = 0;
	int ave;

	for (int i = 0; i < n; i++) {
		cin >> X[i];
		sum += X[i];
	}
	ave = sum / n;

	ll min;
	min = abs(n, X, ave-11);
	for (int i = ave - 10; i < ave + 10; i++) {
		min = std::min(min,abs(n, X, i));
	}

	cout << min;
	return 0;
}

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

int main()
{	
	int n;
	std::cin >> n;
	
	std::string str1, str2 = "";
	std::cin.ignore(32767, '\n');
	std::getline(std::cin, str1);
	
	int l = 0, r = 0, lcount = 0, rcount = 0;
	for (int i = 0; i < str1.length(); ++i)
		if (str1[i] == '(')
		{
			l = std::max(r, l);
			++l;
		}
		else if (str1[i] == ')')
		{
			++r;
			if (l < r)
				++lcount;
		}
	
	l = 0;
	r = 0;
	
	for (int i = str1.length() - 1; i >= 0; --i)
		if (str1[i] == ')')
		{
			r = std::max(l, r);
			++r;
		}
		else if (str1[i] == '(')
		{
			++l;
			if (r < l)
				++rcount;
		}
	
	for (int i = 0; i < lcount; ++i)
		std::cout << '(';
	
	std::cout << str1;
	
	for (int i = 0; i < rcount; ++i)
		std::cout << ')';
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
    vector<vector<int>> tr(n); 
    for(int i=1; i<n; ++i){
        int a, b;
        cin >> a >> b;
        --a; --b;
        tr[a].push_back(b);
        tr[b].push_back(a);
    }
    vector<int> v(n,0);
    for(int i=0; i<q; ++i){
        int p, x;
        cin >> p >> x;
        v[--p] += x;
    }

    stack<int> s; s.push(0);
    vector<int> flg(n,1); flg[0]=0;
    while(!s.empty()){
        int z=s.top();
        s.pop();
        flg[z]=0;
        for(int i : tr[z]){
            if(flg[i]){
                v[i] += v[z];
                s.push(i);
                flg[i]=0;
            }
        }
    }

	for(int i : v) cout << i << " ";
    cout << endl;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll a,b,k;cin >> a >> b >> k;
  if(k < a) cout << a - k << ' ' << b << endl;
  else if(k < a + b) cout << 0 << ' ' << (a + b) - k << endl;
  else cout << 0 << ' ' << 0 << endl;
  return 0;
}


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

using namespace std;

#define F first
#define S second
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)

const int inf = 1 << 25;

typedef pair<char, int> P;

void input(vector<P>& v)
{
  char c; int l;
  while(cin >> c, c != '$') {
    cin >> l;
    v.emplace_back(c, l);
  }
}

int main()
{
  vector<P> A; input(A);
  vector<P> B; input(B);
  vector<P> C; input(C);

  int a = A.size();
  int b = B.size();
  int c = C.size();

  rep(i, A.size()-b+1) {
    if(A[i].F == B[0].F && A[i].S >= B[0].S &&
       A[i+b-1].F == B[b-1].F && A[i+b-1].S >= B[b-1].S) {
      bool flag = true;
      reps(j, 1, b-1) flag &= (A[i+j].F == B[j].F && A[i+j].S == B[j].S);
      if(!flag) continue;
      rep(j, b) A[i+j].S -= B[j].S;
      if(b == 1) A.insert(begin(A)+i, begin(C), end(C));
      else A.insert(begin(A)+i+1, begin(C), end(C));
      break;
    }
  }

  auto it = begin(A);
  while(it != end(A)) {
    if(it->S == 0) {
      auto itr = it+1;
      while(itr != end(A) && itr->S == 0) itr++;
      it = A.erase(it, itr);
    } else {
      it++;
    }
  }
  it = begin(A);
  while(it != end(A)) {
    auto itr = it+1;
    while(itr != end(A) && it->F == itr->F) it->S += itr->S, itr++;
    if(itr != it+1) it = A.erase(it+1, itr);
    else it++;
  }

  rep(i, A.size()) cout << A[i].F << " " << A[i].S << " ";
  //rep(i, A.size()) cout << A[i].F << endl << A[i].S << endl;
  cout << "$" << endl;

  return 0;
}

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

int main(void){
    int n;
    cin >> n;

    int p[n];
    rep(i, n)
        cin >> p[i];

    int count = 0;
    rep(i, n - 2){
        if((p[i+1] < p[i] && p[i+1] > p[i+2]) || (p[i+1] > p[i] && p[i+1] < p[i+2]))
            count++;
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 9223372036854775807
#define mini 9223372036854775807
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};
ll d;
string k;
ll arr[10007];
ll dp[10007][2][105];
ll func(ll i,ll tight,ll sum)
{
	if(dp[i][tight][sum]!=-1)
		return dp[i][tight][sum];
	ll ans=0;
	if(i>=k.size())
	{
		if((sum%d)==0)
			return 1;
		else 
			return 0;
	}
	if(tight==1)
	{
		ll j;
		for(j=0; j<arr[i]; j++)
		{
			ans=((ans%mod)+(func(i+1,0,(sum+j)%d)%mod))%mod;
		}
		ans=((ans%mod)+(func(i+1,1,(sum+arr[i])%d)%mod))%mod;
	}
	else
	{
		ll j;
		for(j=0; j<=9; j++)
		{
			ans=((ans%mod)+(func(i+1,0,(sum+j)%d)%mod))%mod;
		}
	}
	return dp[i][tight][sum]=ans;
}
int main()
{
    boost
    cin>>k>>d;
    ll i,j;
    for(i=0; i<10007; i++)
    {
    	for(j=0; j<105; j++)
    	{
    		dp[i][0][j]=-1;
    		dp[i][1][j]=-1;
    	}
    }
    char zz='0';
    for(i=0; i<k.size(); i++)
    {
    	arr[i]=(ll)(k[i]-zz);
    }
    ll ans=func(0,1,0)%mod;
    ans=(ans-1+mod)%mod;
    cout<<ans<<endl;
    return 0;
}

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

int len = 0;
string n;
void solve();

int main() {
  solve();
  cout << "! " << n << endl;
  return 0;
}

void solve() {
  auto send = [](string s) {
    cout << "? " << s << endl;
    string res;
    cin >> res;
    return res == "Y";
  };
  // search digit
  while (++len < 10)
    if (!send("1" + string(len, '0'))) break;
  // 10^(len) pattern
  if (len == 10) {
    len = 0;
    while (++len)
      if (send(string(len, '9'))) {
        n = "1" + string(len - 1, '0');
        return;
      }
  }
  // binary search
  for (int i = 1; i <= len; ++i) {
    int l = -(i != 1), r = 9;
    while (r - l > 1) {
      int mid = (l + r) / 2;
      if (send(n + (char)('0' + mid) + string(18 - i, '9')))
        r = mid;
      else
        l = mid;
    }
    n += '0' + r;
  }
}

Measured memory_bytes: 3696
import java.util.Scanner;

/**
 * Created by Reopard on 2014/05/06.
 */
public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.next();
        char tmp[] = line.toCharArray();
        char answer[] = new char[20];
        for(int i = 0; i < tmp.length; i++) answer[i] = tmp[tmp.length-(i+1)];
        line = String.valueOf(answer);
        System.out.println(line);
    }
}

Measured memory_bytes: 17116
#include <iostream>
#include <vector>
int main(int argc, const char * argv[]) {
    long n;
    std::cin >> n;
    std::vector<long> h(n);
    std::vector<bool> flag(n, true);
    for(long i=0; i<n; i++)
    {
        std::cin >> h[i];
    }
    long i=1;
    while(i!=n)
    {
        if(i==0)
        {
            i++;
        }
        else if(h[i-1] <= h[i])
        {
            i++;
        }
        else
        {
            if(h[i-1] - h[i] >= 2) break;
            if(flag[i-1])
            {
                h[i-1]--;
                flag[i-1] = false;
                i--;
            }
            else
            {
                break;
            }
        }
    }
    if(i==n)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define ll long long
#define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef set<int> si;
typedef vector<vi> vii;
typedef vector<ii> vpi;
typedef vector<ll> vll;
int oo = (1e9) + 7;
ll oo2 = 1ll*oo*oo;


int main() {
    ll k, a, b;
    cin >> k >> a >> b;

    ll tmp = a-1+1+1;
    ll ans = 0;
    if(a-1+1+1 > k) ans = 1+k;
    else if(a-1+1+1 == k) {
        ans = max(1+k, b);
    } else {
        if(b > a) {
            ll t = k - tmp;
            ll aux = (b-a)*(t/2) + t%2;
            ans = max(1+k, aux+b);
        } else {
            ans = 1+k;
        }
        // ll aux = b + b*(t/(a+1+1)) + (t%(a+1+1));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { 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; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    string S, T;
    cin >> S >> T;

    int ls = S.length();
    int lt = T.length();
    int mi = 1000000000;
    for(int i = 0; i < ls; i++){
        int n = 0;
        for(int j = 0; j < lt; j++){
            if(ls <= i+j) goto failure;
            if(S[i+j] != T[j]){
                n++;
            }
        }
        if(n < mi) mi = n;
failure:
        ;
    }

    cout << mi << endl; 
}


Measured memory_bytes: 3660