akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>

using namespace std;

int main(){
    string s;
    cin >> s;
    int n;
    (int)(s.length());
    n = s.length();
    for(int i=0;s[i];i++){
        s[i] = 'x';
    }
    cout << s <<endl;
    return 0;
}

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

int main(){
    int n,ans=0;
    cin>>n;
    string s,t;
    cin>>s;
    for(int i=0;i<n-1;i++){
    	if(s[i]!=s[i+1]){
    		ans++;
    	}
    }
    cout<<ans+1<<endl;
   return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>

using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

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

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

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

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(map[i][j] == '#'){
                for(int x = -1; x <= 1; x++){
                    for(int y = -1; y <= 1; y++){
                        if( 0 <= x + i && x + i < H && 0 <= y + j && y + j < W){
                            ans[x + i][y + j] ++;
                        }
                    }
                }
            }
        }
    }    

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(map[i][j] == '#') cout  << "#" ;
            else cout << ans[i][j];
        }
        cout << endl;
    }    



}

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

typedef pair<int, int> P;

const int INF = 1000000;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
int H, W;
bool a[1000][1000];
int d[1000][1000];

int bfs(int sx, int sy, int gx, int gy) {
	for (int y = 0; y < H; y++)
		fill_n(d[y], W, INF);
	d[sy][sx] = 0;
	queue<P> que;
	que.push(P(sx, sy));
	while (!que.empty()) {
		P p = que.front();
		que.pop();
		int x = p.first, y = p.second;
		if (x == gx && y == gy)
			return d[y][x];
		for (int i = 0; i < 4; i++) {
			int _x = x + dx[i], _y = y + dy[i];
			if (_x >= 0 && _x < W && _y >= 0 && _y < H && !a[_y][_x] && d[_y][_x] == INF) {
				d[_y][_x] = d[y][x] + 1;
				que.push(P(_x, _y));
			}
		}
	}
}


int main() {
	int N;
	scanf("%d%d%d", &H, &W, &N);
	int xi[10], yi[10];
	for (int y = 0; y < H; y++) {
		char s[1001];
		scanf("%s", s);
		for (int x = 0; x < W; x++) {
			a[y][x] = (s[x] == 'X');
			if (s[x] == 'S') {
				xi[0] = x;
				yi[0] = y;
			}
			if (s[x] >= '1' && s[x] <= '9') {
				int i = s[x] - '0';
				xi[i] = x;
				yi[i] = y;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < N; i++)
		ans += bfs(xi[i], yi[i], xi[i + 1], yi[i + 1]);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 5932
import scala.io.StdIn

object Main extends App {
  var a = StdIn.readLine().split(' ').map(_.toLong).sorted

  val n = a(0)
  val m = a(1)
  
  println(if (n == 1 && m == 1) 1 else if (n == 1 && m != 1) m - 2 else (n - 2) * (m - 2))

}

Measured memory_bytes: 25416
using System;

namespace A___Five_Antennas
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int d = int.Parse(Console.ReadLine());
            int e = int.Parse(Console.ReadLine());
            int k = int.Parse(Console.ReadLine());
            bool flag = false;
            if ((b - a) <= k && (c - a) <= k && (d - a) <= k && (e - a) <= k)
            {
                if ((c - b) <= k && (d - b) <= k && (e - b) <= k)
                {
                    if ((d - c) <= k && (e - c) <= k)
                    {
                        if ((e - d) <= k)
                        {
                            flag = true;
                        }
                    }
                }
            }
            if(flag)
            {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(a,b) for(int a=0; a<b; ++a)
#define ran(a,b) for(auto &a:b)
using namespace std;

template<typename T>
using vec = vector<T>;

using ll = long long;
using pi = pair<int,int>;
using tup = tuple<string,int,int>;

ll MOD=1000000007;

int main(){
	int N,M; cin>>N>>M;
	vec<int> a(M);
	rep(i,M) cin>>a[i];
	
	vec<ll> dp(N+1,0);
	dp[0]=1;
	ran(e,a) dp[e]=-1;
	rep(i,N){
		if(dp[i]==-1) continue;
		if(dp[i+1]!=-1) dp[i+1]=(dp[i]+dp[i+1])%MOD;
		if(i+2<=N){
			if(dp[i+2]!=-1) dp[i+2]=(dp[i]+dp[i+2])%MOD;
		}
	}
	//ran(e,dp) cout<<e<<" ";
	cout<<dp[N]<<endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    string N;
    cin >> N;
    int size = N.size();
    int max = 9*(size-1);
    int n = int (N[0] - '0');
    bool frg = false;
    for(int i=1;i<size;i++){
        if(N[i]!='9'){
            frg = true;
            break;
        }
    }
    int ans;
    if(frg){
        ans = max + (n-1);
    }
    else{
        ans = max + n;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(long long i=0; i<x;i++)
#define mod 1000000007
#define INF 10000000000
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main(){
  ios::sync_with_stdio(false);
  
  ll N;
  cin>>N;
  ll A[N];
  rep(i,N-1) cin>>A[i];
  
  ll maxS =2*100000;
  
  ll DP[maxS+2];
  
  rep(i,maxS+1) DP[i]=0;
  rep(i,N-1){
    DP[A[i]]++;
  }
	
  for(ll i=1;i<N;i++){
  	cout<<DP[i]<<endl;
  }
  cout<<0;
  
}

Measured memory_bytes: 6736
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

int cases;
const int MAX_LIMIT = 100005;
int isPrime[MAX_LIMIT];
vector <int> prime;
void sieve()
{
	int limit = MAX_LIMIT, i, j;
	memset(isPrime, 0, sizeof(isPrime));
	for(i = 2; i < limit + 1; i++)
	{
		isPrime[i] = 1;
 	}
	int inLimit = sqrt(limit);
	inLimit++;
 
	for(i = 2; i < inLimit; i++)
	{
		if(isPrime[i] == 1)
		{
			for(j = i * i; j < limit; j += i)
			{
				isPrime[j] = 0;
			}
		}
	}
	for(i = 2; i < MAX_LIMIT; i++)
	{	
		if(isPrime[i])
		{
			prime.push_back(i);
 		}
	}
	return;

 } 

int main()
{
	sieve();
	int tempAns[MAX_LIMIT];
	int finalAns[MAX_LIMIT];

	for(int i = 0; i < MAX_LIMIT; i++)
	{
		if(isPrime[i] && isPrime[(i + 1)/ 2])
		{
			tempAns[i] = 1;
		}
	}

	for(int i = 1; i < MAX_LIMIT; i++)
	{
		finalAns[i] = finalAns[i - 1] + tempAns[i];
	}
	scanf("%d", &cases);

	while(cases--)
	{
		int l, r;
		scanf("%d %d", &l, &r);
		int caseAns = finalAns[r] - finalAns[l - 1];
		printf("%d\n", caseAns);
	}
	
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 1920
MOD = 998244353
MAX = int(3e5 + 1)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def main():
    N, A, B, K = map(int, input().split())
    ans = 0
    # solve Ax + By = K
    for x in range(N+1):
        By = K - x * A
        if By >= 0 and By % B == 0 and By <= B * N:
            y = By // B
            tmp1 = FACT[N] * INV[x] * INV[N-x] % MOD
            tmp2 = FACT[N] * INV[y] * INV[N-y] % MOD
            ans = (ans + tmp1 * tmp2) % MOD
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 26740
#include<stdio.h>
#define N 200000

int main(){

  int n,r[N],i,min,max;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&r[i]);
  }

  min=r[0];
  max=r[1]-min;
  for(i=1;i<n;i++){
    if(max<r[i]-min)max=r[i]-min;
    if(min>r[i])min=r[i];
  }

  printf("%d\n",max);
  return 0;

}



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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P,ll>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr double EPS = 1e-9;

int table[10][10];

int f(int a, int b){
    return table[a][b];
}

int check(string s){
    int res = 0;
    for(int i=0;i<int(s.size());i++){
        int d = s[i]-'0';
        res = f(res, d);
    }
    return res;
}

int main(){
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin >> table[i][j];
        }
    }
    int ans = 0;
    for(int i=0;i<10000;i++){
        string s = to_string(i);
        while(s.size()<4) s.insert(s.begin(),'0');
        s.push_back('0'+check(s));
        bool ok = true;
        for(int i=0;i<5;i++){
            for(int d=0;d<=9;d++){
                if(s[i] == '0'+d) continue;
                string t = s;
                t[i] = '0'+d;
                ok &= check(t) != 0;
            }
        }
        for(int i=0;i<4;i++){
            string t = s;
            swap(t[i],t[i+1]);
            if(s == t) continue;
            ok &= check(t) != 0;
        }
        if(!ok) ans++;
    }
    cout << ans << endl;
    return 0;
}



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

int main(){
  string S;
  cin >> S;
  
  int test = 0;
  int length = 0;

  length = S.size();
  for(int i = 0; i < S.size() / 2; i++){
    if(S.at(i) != S.at(S.size() - 1 - i))
      test++;
  }

  int N;
  N = (length - 1) / 2;
  for(int i = 0; i < S.size() / 4; i++){
    if(S.at(i) != S.at((S.size() / 2) - 1 - i))
      test++;
  }


  if(test)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	vector<int>s(4);
	for(int i=0;i<4;i++){
		cin>>s.at(i);
	}
	if(s.at(1)<=s.at(2)||s.at(3)<=s.at(0)){
		cout<<'0'<<endl;
		return 0;
	}
	sort(s.begin(),s.end());
	cout<<s.at(2)-s.at(1)<<endl;

}

Measured memory_bytes: 256
var x = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = x.split(/\s/);
r = parseFloat(arr[0]);
area = (Math.PI*Math.pow(r,2)).toFixed(6);
circumference = (2*Math.PI*r).toFixed(6);
console.log(area +" "+ circumference);



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

typedef long long ll;

int main(void) {
	ll H;
	cin >> H;

	ll ans = (ll)0;
	ll cnt = (ll)1;
	while (true) {
		if (H == 1) {
			ans += cnt;
			break;
		}
		ans += cnt;
		cnt *= 2;
		H /= 2;
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String... args) {

        /*
        ここは、フィールド
         */

        //Scanner インスタンス生成
        Scanner sc = new Scanner(System.in);
        //標準入力の値を代入する
        //枚数
        int numberMochi = sc.nextInt();
        //各自の直径を格納する配列
        int[] diameterArray = new int[numberMochi];
        //枚数分繰り返す。
        for(int i = 0; i < numberMochi; i++){
            diameterArray[i] = sc.nextInt();
        }
        //重複確認変数
        List<Integer> duplicationArray = new ArrayList<>();
        int duplicationNumber = 0;
        /*
        ここからは、アルゴリズム
         */
        //重複分はノーカウント
        //重複しているものが何個あるのか？
        for(int i = 0; i < diameterArray.length; i++){
            if(!duplicationArray.contains(diameterArray[i])){
                //重複を確認する
                for(int j = i+1; j < diameterArray.length; j++){
                    if(diameterArray[i] == diameterArray[j]){
                        duplicationArray.add(diameterArray[j]);
                        duplicationNumber ++;
                    }
                }
            }
        }
        //標準出力をする
        System.out.print(diameterArray.length-duplicationNumber);
    }
}

Measured memory_bytes: 21844
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;

    public static void main(String[] args) {
        long M = 2019;
        long L = nlong();
        long R = nlong();
        
        long ans = Long.MAX_VALUE;
        for (long i = L; i < R && i < L+M; i++) {
            for (long j = i+1; j <= R && j <= L+M; j++) {
                ans = Math.min(ans, (i%M) * (j%M) % M);
            }
        }
        so.println(ans);
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }

    private static String[] nstrs(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = nstr();
        return a;
    }

    private static char[][] nsToChars2D(int h, int w) {
        return nsToChars2D(h, w, 0);
    }

    private static char[][] nsToChars2D(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nsToChars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef tuple<int,int,int> tp;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M;
    cin >> N >> M;
    vector<tp> V(M);
    int dist[N][N];
    rep(i,0,N)rep(j,0,N)dist[i][j] = INF;
    rep(i,0,N)dist[i][i] = 0;
    rep(i,0,M){
        int a,b,c;
        cin >> a >> b >> c;
        a--,b--;
        V[i] = make_tuple(a,b,c);
        dist[a][b] = dist[b][a] = c;
    }
    rep(i,0,N)rep(j,0,N)rep(k,0,N)dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
    int cnt = 0;
    rep(i,0,M){
        int a = get<0>(V[i]), b = get<1>(V[i]), c = get<2>(V[i]);
        if(dist[a][b] != c)cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

void pakuri_sort(int N, ll A[]) {
	const int b = 12;
	ll tmp[200001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	ll S[200000];
	int N = 0;
	char c;
	while ((c = getchar_unlocked()) >= '0') N = N * 10 + c - '0';

	rep(i, N) {
		ll s = 1;
		while ((c = getchar_unlocked()) >= 'a') s = s * 26 + c - 'a';
		S[i] = s;
	}

	pakuri_sort(N, S);

	int kotae = 0;
	ll mae = -1;
	rep(i, N) {
		if (mae != S[i]) {
			kotae++;
			mae = S[i];
		}
	}

	printf("%d\n", kotae);


	Would you please return 0;
}

Measured memory_bytes: 4752
/*** keep hungry and calm CoolGuang!***/
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<" :"<<x<<" "<<endl;
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
const ll INF=1000000000000007;
const ll maxn=1e6+5;
const int mod=1e9+7;
ll n,m;
ll num[maxn];
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
        scanf("%lld",&num[i]);
    int f=0,flag=0;
    for(int i=1;i<=n;i++){
        if(num[i]%2==0){
           // printf("%lld\n",num[i]);
            f=1;
            if(num[i]%3!=0&&num[i]%5!=0)
                flag=1;
        }
    }
    if(f==0) printf("APPROVED\n");
    else{
        if(flag) printf("DENIED\n");
        else printf("APPROVED\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a[7], b[7];  //aは最高気温、bは最低気温
    
    for(int i = 0; i < 7; i++){
        cin >> a[i] >> b[i];
    }

    for(int i = 0; i < 7; i++){
        int td = a[i] - b[i];
        //td = temperature difference(気温差)
        cout << td << endl;
    }
}


Measured memory_bytes: 3120
N = int(input())
H = list(map(int,input().split()))

r = 0
l = 0
ans = 0
cnt = 0

while l < N and r < N:
    if r == l:
        r += 1
    else:
        if H[r-1] >= H[r]:
            cnt += 1
            r += 1
            ans = max(ans,cnt)
        else:
            cnt = 0
            l = r
          
print(ans)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,k;

int main(){
  cin>>n>>k;
  // S = a+b+c
  // S-a | K
  // S-b | K
  // S-c | K
  // 1) a%k == b%k == c%k == 0
  // 2) a%k == b%k == c%k == k/2
  ll c1 = 0, c2 = 0;
  FOR(i,1,n+1){
    if(i%k == 0){
      c1++;
    }else if(2*(i%k)==k){
      c2++;
    }
  }
  ll ans = c1*c1*c1 + c2*c2*c2;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	vector<long long>vecA, vecB, vec;
	int n;
	long long a;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		vecA.push_back(a);
	}
	for (int i = 0; i < n; i++) {
		cin >> a;
		vecB.push_back(a);
	}
	a = 0;
	for (int i = 0; i < n; i++) {
		vec.push_back(vecA[i] - vecB[i]);
	}

	sort(vec.begin(), vec.end());
	a = vec[0];
	if (a >= 0) {
		cout << 0;
		return 0;
	}
	int i = 0;
	int j = 0;

	while (i < n - 1 - j) {
		while (a > 0) {
			if (vec[i+1] >= 0) {
				cout << i + j+1;
				return 0;
			}
			a += vec[i+1];
			i++;
		}
		while (a < 0) {
			if (vec[n - 1 - j] <= 0) {
				cout << -1;
				return 0;
			}
			a += vec[n - 1 - j];
			j++;
		}
	}

	
}


Measured memory_bytes: 3316
#include<stdio.h>

int main(){

	int n,a[10000],min,max,i;
	long int sum;

	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);

	min=a[0];
	max=a[0];
	sum=a[0];

	for(i=1;i<n;i++){
		if(min>a[i])
			min=a[i];
		else if(max<a[i])
			max=a[i];
		sum=sum+a[i];
	}

	printf("%d %d %ld\n",min,max,sum);

	return 0;

}

Measured memory_bytes: 636
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

const ll mod = 1e9 + 7;

int main() {
  while (true) {
    ll w, h;
    cin >> w >> h;
    if (w == 0 && h == 0) break;

    vector<vvP> eds(h, vvP(w));

    rep(i, 2 * h - 1) {
      ll b;
      if (i % 2 == 0) {
        rep(j, w - 1) {
          cin >> b;
          if (b == 0) {
            eds[i / 2][j].emplace_back(i / 2, j + 1);
            eds[i / 2][j + 1].emplace_back(i / 2, j);
          }
        }  // j
      } else {
        rep(j, w) {
          cin >> b;
          if (b == 0) {
            eds[i / 2][j].emplace_back(i / 2 + 1, j);
            eds[i / 2 + 1][j].emplace_back(i / 2, j);
          }
        }  // j
      }
    }  // i

    vvll dist(h, vll(w, -1));
    queue<P> que;
    dist[0][0] = 0;
    que.emplace(0, 0);
    while (!que.empty()) {
      ll y, x;
      tie(y, x) = que.front();
      que.pop();
      for (P p : eds[y][x]) {
        ll ny, nx;
        tie(ny, nx) = p;
        if (dist[ny][nx] == -1) {
          dist[ny][nx] = dist[y][x] + 1;
          que.emplace(ny, nx);
        }
      }  // p
    }    // while

    if (dist[h - 1][w - 1] == -1)
      puts("0");
    else
      cout << dist[h - 1][w - 1] + 1 << endl;
  }  // while
  return 0;
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    string S; ll K; cin >> S >> K; bool can = false;
    rep(i,100){
        if(i==K-1) {cout << S[i] << endl; break;}
        else if(S[i]!='1'){
            cout << S[i] << endl;
            break;
        }
    
    }
    

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(H, W, C, D, S):

    C = (C[0]-1, C[1]-1)
    D = (D[0]-1, D[1]-1)
    q = deque()
    q.append((0, C))
    memo = {}
    T = 10**6
    while q:
        c, (x, y) = q.popleft()
        if (x*T + y) in memo:
            continue
        memo[x*T + y] = c

        for nx in range(x-2, x+3):
            for ny in range(y-2, y+3):
                if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.':
                    if abs(nx-x) + abs(ny-y) == 1:
                        q.appendleft((c, (nx, ny)))
                    else:
                        q.append((c+1, (nx, ny)))

    return -1 if (D[0]*T + D[1]) not in memo else memo[D[0]*T + D[1]]


def main():
    H, W = read_int_n()
    C = read_int_n()
    D = read_int_n()
    S = [read_str() for _ in range(H)]
    print(slv(H, W, C, D, S))


if __name__ == '__main__':
    main()


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

int n, x, m, ans = -1;
int ansls[6] = {0};
int cnt[7] = {0};
struct obser {
  int l;
  int r;
  int s;
};
vector<obser> ls;

void solve(int now);

int main() {
  cin >> n >> x >> m;
  for(int i = 0; i < m; ++i) {
    obser now;
    cin >> now.l >> now.r >> now.s;
    ls.push_back(now);
  }
  solve(0);
  if(ans == -1)
    cout << ans << endl;
  else {
    for(int i = 0; i < n; ++i) {
      cout << ansls[i];
      if(i != n - 1) cout << " ";
    }
    cout << endl;
  }
  return 0;
}

void solve(int now) {
  if(now == n) {
    bool ch = 1;
    for(int i = 0; i < m; ++i)
      if(ch) {
        int cntnum = 0;
        for(int j = ls[i].l - 1; j < ls[i].r; ++j)
          cntnum += cnt[j];
        if(cntnum != ls[i].s) ch = 0;
      }
    if(ch && ans < cnt[6]) {
      for(int i = 0; i < n; ++i) ansls[i] = cnt[i];
      ans = cnt[6];
    }
  }
  else {
    for(int i = 0; i <= x; ++i) {
      cnt[now] = i;
      cnt[6] += i;
      solve(now + 1);
      cnt[6] -= i;
    }
  }
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
int H,W,d[22][22],D,r,i,j,k,l,t[22][22];
char c;
void move(int i,int j,int n){
	if(t[i][j]&&(d[i][j]>n||d[i][j]==-1)){
		d[i][j]=n;
		move(i+1,j,n+1);
		move(i-1,j,n+1);
		move(i,j+1,n+1);
		move(i,j-1,n+1);
	}
}
main(){
	cin>>H>>W;
	for(i=1;i<=H;i++)for(j=1;j<=W;j++){
		cin>>c;
		t[i][j]=(c=='.');
	}
	for(i=1;i<=H;i++)for(j=1;j<=W;j++){
		memset(d,-1,sizeof(d));
		move(i,j,0);
		D=0;
		for(k=1;k<=H;k++)for(l=1;l<=W;l++)D=max(D,d[k][l]);
		r=max(D,r);
	}
	cout<<r;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    
    int a[n][m],b[m];
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }

    for(int k=0;k<m;k++){
        cin>>b[k];
    }
    
    int ans[n];
    
   for(int f=0;f<n;f++){
       ans[f]=0;
       for(int g=0;g<m;g++){
           ans[f]+=a[f][g]*b[g];
        }
    }
    
    for(int l=0;l<n;l++) cout<<ans[l]<<endl;
    
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int me[10],rigidity[10],n;
char str[10][21];
void serch(int num,int now,int sum,int point,int co)
{
    if(num==0)return;
    else if(n==now){
        rigidity[point]=-10000;
        cout<<str[point]<<endl;;
        serch(num-1,0,sum-me[point],0,0);
    }
    else if(sum-me[now]<=rigidity[now]&&co==0)serch(num,now+1,sum,now,1);
    else if(sum-me[now]<=rigidity[now]&&me[point]<me[now])serch(num,now+1,sum,now,1);
    else serch(num,now+1,sum,point,co);
}
int main()
{
    while(cin>>n,n){
        int sum=0;
        for(int i=0;i<n;i++){
            cin>>str[i]>>me[i]>>rigidity[i];
            sum+=me[i];
        }
        serch(n,0,sum,0,0);
    }

}

Measured memory_bytes: 1160
cards_num = int(input())

cards = []

missing_cards = []

for i in range(cards_num):
    cards.append(input())

for i in range(1, 14):
    if "S {0}".format(i) not in cards:
        missing_cards.append("S {0}".format(i))
for i in range(1, 14):
    if "H {0}".format(i) not in cards:
        missing_cards.append("H {0}".format(i))
for i in range(1, 14):
    if "C {0}".format(i) not in cards:
        missing_cards.append("C {0}".format(i))
for i in range(1, 14):
    if "D {0}".format(i) not in cards:
        missing_cards.append("D {0}".format(i))

for i in missing_cards:
    print(i)

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

using ll = long long;

int main() {
    int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    rep(i, b) cout << a;
    cout << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
   int H1, M1, H2, M2, K;
   cin >> H1 >> M1 >> H2 >> M2 >> K;
   cout << (H2 * 60 + M2) - (H1 * 60 + M1) - K<<endl;
}


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

int main() {
  int h, n;
  cin >> h >> n;
  vector<int>  a(n);
  rep(i,n) cin >> a.at(i);
  int sum = 0;
  rep(i,n) sum += a.at(i);
  if (sum >= h) cout << "Yes" << endl;
  else cout << "No" << endl;
    
return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split();
        int N = int.Parse(input[0]);
        int K = int.Parse(input[1]);
        int Q = int.Parse(input[2]);
        int[] Point = new int[N];
        for (int i = 0; i < N; i++)
        {
            Point[i] = K-Q;
        }
        for (int i = 0; i < Q; i++)
        {
            Point[int.Parse(Console.ReadLine())-1]++;
        }
        for (int i = 0; i < N; i++)
        {
            if (Point[i] > 0) { Console.WriteLine("Yes"); }
            else { Console.WriteLine("No"); }
        }
    }
}


Measured memory_bytes: 17600
#include<iostream>
#include<fstream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define int long long
#define mod 1000000009
#define inf 4444444444444444444
#define mn 150005

int n;
int A[1005][1005];

void color(vector <int> V, int col)
{
	if (V.size()==1) return;
	vector <int> V1={};
	vector <int> V2={};
	for (int i=0; i<V.size()/2; i++) V1.push_back(V[i]);
	for (int i=V.size()/2; i<V.size(); i++) V2.push_back(V[i]);
	for (int i:V1) for (int j:V2) A[i][j]=col;
	color(V1, col+1);
	color(V2, col+1);
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	vector <int> vv={};
	for (int i=1; i<=n; i++) vv.push_back(i);
	color(vv, 1);
	for (int i=1; i<=n; i++)
	{
		for (int j=i+1; j<=n; j++) cout<<A[i][j]<<" ";
		cout<<"\n";
	}
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
//#define ll long long
#define mod 1000000007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;
ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int n; cin >> n; vector<ll> vec(n, 0); for(int i = 0; i < n; i++) cin >> vec[i];
    sort(vec.begin(), vec.end());
    cout << vec[n / 2] - vec[n / 2 - 1] << endl;
    
    
    return 0;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli cnt = 0;
    lli n;
    cin >> n;
    for (lli i = 1; 2*i-1 <= n;i++)
    {
        lli tmp = 0;
        for (lli j = 1; j <= 2*i-1;j++)
        {
            if((2*i-1)%j==0)
            {
                tmp++;
            }
        }
        if(tmp==8)
        {
            cnt++;
        }
    }
    out(cnt);
}

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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)
        {
            var nmk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = nmk[0];
            var m = nmk[1];
            var x = nmk[2];
            var ans = 0L;
            var mincost = 1200007L;
            var texts = new long[n][];

            for(int i = 0; i < n; i++)
            {
                var text = Console.ReadLine().Split().Select(long.Parse).ToArray();
                texts[i] = text;
            }

            for(int bit = 0; bit < (1 << n); bit++)
            {
                var pickup = new bool[n];
                var skill = new long[m+1];
                var judge = true;
                for(int j = 1; j <= n; j++)
                {
                    if (((bit >> j - 1) & 1) == 1) pickup[j-1] = true;
                }

                for(int l = 0; l < n; l++)
                {
                    if(pickup[l])
                    {
                        for(int k = 0; k < texts[l].Length; k++)
                        {
                            skill[k] += texts[l][k];
                        }
                    }
                }
                //Console.WriteLine(string.Join(" ", skill));

                for (int ii = 1; ii < skill.Length; ii++)
                {
                    if (skill[ii] < x) judge = false;
                }
                //Console.WriteLine(mincost);
                if (judge) mincost = Math.Min(mincost, skill[0]);
                //Console.WriteLine(mincost);
                ans = mincost;

            }
            if (ans == 1200007L) ans = -1;

            Console.WriteLine(ans);



        }

        






    





        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }
        
        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }

        public static long Gcd(long a, long b)
        {
            long x = Math.Max(a, b);
            long y = Math.Min(a, b);
            if (x % y == 0) return y;
            else return Gcd(y, x % y);
        }
    }
}


Measured memory_bytes: 28780
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<numeric>
#include<vector>
#include<tuple>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
typedef long long ll;
const int MOD = 1e9 + 7;

ll a,b,c;
int ans = 0;
int main(void)
{
	cin >> a >> b >> c;
	if (a == b && b == c&&a%2==0)cout << -1 << endl;
	else {
		while (a % 2 != 1 && b % 2 != 1 && c % 2 != 1) {
			int ha=a/2, hb=b/2, hc=c/2;
			a = hb + hc; b = ha + hc; c = ha + hb;
			ans++;
		}
		ct(ans);
	}

	return 0;
}

Measured memory_bytes: 256
hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]

N = input()

last_num = N[-1]
if int(last_num) in hon:
    print('hon')
elif int(last_num) in pon:
    print('pon')
else :
    print('bon')

Measured memory_bytes: 9188
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

typedef int Weight;
struct Edge{
  int src, dest; Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

Edges prim(Graph &g){
  Edges res;
  vector<int> visited(g.size(), 0);
  priority_queue<Edge> q;
  q.push((Edge){-1, 0, 0});
  while (!q.empty()) {
    Edge e = q.top();
    q.pop();
    if (visited[e.dest]) continue;
    if (e.src >= 0) res.push_back(e);
    visited[e.dest] = 1;
    for (Edge i : g[e.dest]) if(visited[i.dest] == 0) q.push(i);
  }
  sort(res.rbegin(), res.rend());
  return res;
}

int main() {
  while(1){
    int s,d;
    cin>>s>>d;
    if(!s)break;
    Graph g(s+d+1);
    REP(i,s){
      REP(j,d){
        int l;
        cin>>l;
        if (l>0) {
          g[i+d].push_back({i+d,j,l});
          g[j].push_back({j,i+d,l});
        }
      }
    }
    REP(i,d-1) {
      REP(j,d-i-1) {
        int l;
        cin>>l;
        if (l>0) {
          g[i].push_back({i,i+j+1,l});
          g[i+j+1].push_back({i+j+1,i,l});
        }
      }
    }
    REP(i,s){
      g[s+d].push_back({s+d,i+d,0});
      g[i+d].push_back({i+d,s+d,0});
    }
    auto res = prim(g);
    int sum = 0;
    for (Edge e : res) sum += e.weight;
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1336
import java.util.Scanner;

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

		int n = sc.nextInt();
		int[] t = new int[n];
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			t[i] = sc.nextInt();
			a[i] = sc.nextInt();
		}

		long[] dpt = new long[n];
		long[] dpa = new long[n];

		dpt[0] = t[0];
		dpa[0] = a[0];

		long c = 0;
		long ca = 0;

		for (int i = 1; i < n; i++) {
			if (t[i] >= dpt[i - 1]) {
				if (a[i] >= dpa[i - 1]) {
					dpt[i] = t[i];
					dpa[i] = a[i];
				} else {
					if (dpa[i - 1] % a[i] == 0)
						c = dpa[i - 1] / a[i];
					else
						c = dpa[i - 1] / a[i] + 1;

					dpt[i] = c * t[i];
					dpa[i] = c * a[i];
				}
			} else {
				if (a[i] >= dpa[i - 1]) {
					if (dpt[i - 1] % t[i] == 0)
						c = dpt[i - 1] / t[i];
					else
						c = dpt[i - 1] / t[i] + 1;

					dpt[i] = c * t[i];
					dpa[i] = c * a[i];
				} else {
					if (dpa[i - 1] % a[i] == 0)
						ca = dpa[i - 1] / a[i];
					else
						ca = dpa[i - 1] / a[i] + 1;

					if (dpt[i - 1] % t[i] == 0)
						c = dpt[i - 1] / t[i];
					else
						c = dpt[i - 1] / t[i] + 1;

					dpt[i] = Math.max(ca, c) * t[i];
					dpa[i] = Math.max(ca, c) * a[i];
				}
			}

		}

		System.out.println(dpt[n - 1] + dpa[n - 1]);

	}

}


Measured memory_bytes: 24276
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,ans=0;

bool chk(int x){
  int cur = n;
  while(cur%x==0){
    cur/=x;
  }
  return cur%x==1;
}

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> n;
  int cur = n-1;
  vi v;
  for(int i=2;i*i<=cur;i++){
    if(cur%i==0){
      v.pb(i);
      if(i*i!=cur){
        v.pb(cur/i);
      }
    }
  }
  if(cur>1)
  v.pb(cur);
  ans+=v.size();v.clear();
  // cout << v.size() << endl;
  cur = n;
  for(int i=2;i*i<=cur;i++){
    if(cur%i==0){
      v.pb(i);
      if(i*i!=cur){
        v.pb(cur/i);
      }
    }
  }
  v.pb(cur);
  for(auto t:v){
    if(chk(t))ans++;
  }
  cout << ans << endl;

return 0;
}
///....


Measured memory_bytes: 384
// 容斥+dp 
#include<bits/stdc++.h>
#define ll long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define swap(x,y) (x^=y^=x^=y)
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
#define MN 5005
#define mod 1000000007
ll dp[MN][MN],g[MN],t[MN],siz[MN];
int hr[MN],en;
struct edge{int to,nex;}e[MN<<1];
inline void ins(int f,int t)
{
	e[++en]=(edge){t,hr[f]};hr[f]=en;
	e[++en]=(edge){f,hr[t]};hr[t]=en;
}
void dfs(int x,int fa){
    siz[x]=1;dp[x][1]=1;register int i,j,k;
    for(i=hr[x];i;i=e[i].nex)if(e[i].to^fa)
	{
    	dfs(e[i].to,x);
    	for(j=0;j<=siz[x];++j)
    		t[j]=dp[x][j],dp[x][j]=0;
    	for(j=0;j<=siz[x];++j)
    		for(k=0;k<=siz[e[i].to];++k)
    			(dp[x][j+k]+=t[j]*dp[e[i].to][k]%mod)%=mod; 
    	siz[x]+=siz[e[i].to];
	}
	for(i=0;i<=siz[x];i+=2)
		dp[x][0]=(dp[x][0]-dp[x][i]*g[i]%mod+mod)%mod;

}
int main(){
    register int i,n,x;
    n=read();
    for(i=1;i<n;++i) x=read(),ins(x,read());
    g[0]=1;for(i=2;i<=n;g[i]=g[i-2]*(i-1)%mod,i+=2);
    dfs(1,0);
    printf("%lld\n",mod-dp[1][0]);
    return 0;
}

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

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int count=0;
    for(int i=0;i<n-1;++i){
        if(n==1) break;
        while(s[i] == s[i+1]){
            i++;
        }
        count++;
    }
    if(n!=1 && s[n-2]==s[n-1]) count--;
    cout << count+1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <climits>
using namespace std;

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

    long long min_A = LONG_MAX, sum = 0, negative_num = 0;
    for (int i = 0; i < N; i++) {
        long long A;
        cin >> A;
        if (A < 0) {
            negative_num++;
            A = -A;
        }
        sum += A;
        min_A = min(min_A, A);
    }

    if (negative_num % 2 == 0) {
        cout << sum << endl;
    } else {
        cout << sum - 2*min_A << endl;
    }

    
    return 0;
}


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

int main() { /* ここに書く */
  
  long long N,D,X,Y,c;
  c = 0;
  cin >> N >> D;
  
  D = D*D;
  
  for(int i = 0; i<N ; i++){
    
    cin >> X >> Y;
    X = X*X;
    Y = Y*Y;
    
    if(D >= X+Y){
      c++;
    }
    
  }
  
  cout << c << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N), F(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> F[i];
  sort(all(A));
  sort(all(F), greater<ll>());
  auto bsearch = [&]() {
    auto test = [&](ll k) {
      ll cur = 0;
      rep(i, N) cur += max(A[i]-k/F[i], 0LL);
      return cur <= K;
    };

    ll ok = longinf, ng = -1;
    while(abs(ok-ng)>1) {
      ll mid = (ok+ng)/2;
      (test(mid) ? ok : ng) = mid;
    }
    return ok;
  };
  cout << bsearch() << "\n";
  return 0;
}


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

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

  int area1 = a * b;
  int area2 = c * d;

  if(area1 > area2) {
    cout << area1 << endl;
  } else {
    cout << area2 << endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    ta = [list(map(int, input().split())) for _ in range(n)]
    ans = sum(ta[0])
    for i in range(1, n):
        si1 = sum(ta[i - 1])
        si = sum(ta[i])
        cand1 = (ans * ta[i - 1][0] // si1) // ta[i][0] if (ans * ta[i - 1][0] // si1) % ta[i][0] == 0 else (ans * ta[i - 1][0] // si1) // ta[i][0] + 1
        cand2 = (ans * ta[i - 1][1] // si1) // ta[i][1] if (ans * ta[i - 1][1] // si1) % ta[i][1] == 0 else (ans * ta[i - 1][1] // si1) // ta[i][1] + 1
        ans = si * max([cand1, cand2])
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

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

#define MAX_N 100

using namespace std;

int main(){
	int N, M, a, L;
	cin >> N >> M;
	bool field[MAX_N + 1] = {};
	for(int i = 0; i < M; i++){
		cin >> a >> L;
		for(int j = a; j < a + L; j++){
			field[j % N] = true;
		}
	}
/*
for(int j = 0; j < M; j++){
	cout << j << ": " << field[j] << endl;
}
*/

	int i = 0;
  int cnt_num[MAX_N + 1] = {};
  if(field[N - 1])
	  for(; field[i] && i < N; i++);
  if(i == N)
    cnt_num[N]++;
  while(i < N)
  {
    int j = i;
    for(; field[j % N]; j++);
    if(j - i)
      cnt_num[j - i]++;
    i = j + 1;
  }

	for(int k = MAX_N; k >= 0; k--){
		if(cnt_num[k] != 0){
			cout << k << " " << cnt_num[k] << endl;
		}
	}
}


Measured memory_bytes: 1164
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import defaultdict

N = int(readline())
C = (0,) + tuple(map(int, readline().split()))
m = map(int, read().split())
AB = zip(m, m)

graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)

root = 1
parent = [0] * (N + 1)
depth = [0] * (N + 1)  # 根を深さ 1 として
order = []
stack = [root]
depth[root] = 1
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)
        depth[y] = depth[x] + 1


def merge(A, B):
    if len(A) < len(B):
        A, B = B, A
    for key, cnt in B.items():
        A[key] += cnt
    return A


dp = [defaultdict(int) for _ in range(N + 1)]  # 部分木内で、消去済の頂点数の分布
size = [0] * (N + 1)  # 部分木の大きさ
answer = [N * (N + 1) // 2] * (N + 1)

for v in order[::-1]:
    size[v] += 1
    p = parent[v]
    dp[v][C[v]] = size[v]
    if not p:
        break
    size[p] += size[v]
    c = C[p]
    x = size[v] - dp[v][c]
    answer[c] -= x * (x + 1) // 2
    dp[p] = merge(dp[p], dp[v])

A = dp[root]
for c in range(1, N + 1):
    x = N - A[c]
    answer[c] -= x * (x + 1) // 2

print(*answer[1:], sep='\n')


Measured memory_bytes: 164128