akhauriyash/Code-Regression huggingface dataset:
import sys
 
nmlist = list(map(int, input().split()))
N = nmlist[0]
M = nmlist[1]
order_list = [list(map(int, input().split())) for _ in range(M)]
 
Number = [0,0,0]
cnt = 0

for k in range(M):
    if N==1 and order_list[k] == [1,0]:
        cnt += 1
 
if cnt == M and cnt>0:
    print(0)
    sys.exit()
for j in range(M):
    if order_list[j][0] > N:
        print(-1)
        sys.exit()
    if order_list[j][0] == 1 and order_list[j][1] == 0:
        print(-1)
        sys.exit()
 
for i in range(M):
    if Number[order_list[i][0]-N+2] != 0 and Number[order_list[i][0]-N+2] != order_list[i][1]:
        print(-1)
        sys.exit()
    Number[order_list[i][0]-N+2] = order_list[i][1]
 
if N == 1 and Number[0]+Number[1]+Number[2] == 0:
    print(0)
    sys.exit()
 
if Number[3-N] == 0:
    Number[3-N] = 1
 
print(100*Number[0]+10*Number[1]+Number[2])

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

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

    if (N / 100 == 7) {
        cout << "Yes" << endl;
        return 0;
    }

    if (N % 100 / 10 == 7) {
        cout << "Yes" << endl;
        return 0;
    }

    if (N % 10 == 7) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>

int max(int a, int b)
{
	return a > b ? a : b;
}

int main(void)
{
	int P, Q, R;
	scanf("%d%d%d", &P, &Q, &R);
	
	int ans = P + Q + R - max(max(P, Q), R);
	
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
N = int(input())

count = 0
for a in range(1,N+1):
  for b in range(a,N//a + 1):
    c = N - a * b
    if c == 0:
      continue
    else:
      if a != b:
        count += 2
      else:
        count += 1
print(count)

Measured memory_bytes: 67976
//sol->//https://www.geeksforgeeks.org/longest-path-in-a-directed-acyclic-graph-dynamic-programming/

#include <bits/stdc++.h>
using namespace std;
#define N 1000000007
vector<long>adj[100000];
vector<long>dp;
map<long,bool>vis;
vector<long>s;

void dfs(long v){
vis[v]=true;
for(auto x:adj[v]){if(!vis[x])dfs(x);    dp[v]=max(dp[v],dp[x]+1);   }


s.push_back(v);
}

int main() {
    long n,m;
    long x,y;
    cin>>n>>m;
    dp.assign(n,0);   //we need longest path so take wight of each here -1 and default as int_min
    for(long i=0;i<m;i++){cin>>x>>y; adj[x-1].push_back(y-1);}
    for(long i=0;i<n;i++){
        if(!vis[i])dfs(i);
    }
    
    long ans=LONG_MIN;
    for(long i=0;i<n;i++)ans=max(ans,dp[i]);
    cout<<ans<<endl;



	return 0;
}


Measured memory_bytes: 20540
N = int(input())

ans = ""

if N == 0:
    print(0)
    exit()

while N != 0:
    
    if N % -2 == 0:
        ans = "0" + ans
    else:
        ans = "1" + ans
    tmp = abs(N % -2)
    #print(N, tmp)
    N = (N-tmp) // -2

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair

using namespace std;

ll get(ll x,ll fn[], ll n)
{
    //cout<<"at x = "<<x<<"\n";
    if(x == 0)
        return 0;
    if(x == 1)
        return 0;
    if(fn[n-1]+1>x)
        return get(x-1,fn,n-1);
    if(fn[n-1] + 1 == x)
        return (1ll<<(n)) - 1;
    if(fn[n-1] + 2 == 2)
        return (1ll<<(n));
    if(2*fn[n-1]+2 > x)
        return (1ll<<(n)) + get(x-fn[n-1]-2,fn,n-1);
    return 2*((1ll<<n)-1) + 1;
    
    /*if(x <= 1)
        return x;
    ll ind=0;    
    for(ll i=1;i<53;i++)
    {
        if(fn[i] == x)
            return (1ll<<(i+1) - 1);
        if(fn[i]>x)
        {
            ind = i-1;
            break;
        }
    }
    
    //cout<<"at x = "<<x<<" ind = "<<ind<<"\n";
    
    if(x == fn[ind] + 1)
        return (1ll<<(ind+1) - 1);
    if(x == fn[ind] + 2)
        return (1ll<<(ind+1));
    if(x == 2*fn[ind] + 2)    
        return 2*((1ll<<(ind+1) - 1)) + 1;
    return (1ll<<(ind+1)) + get(x-fn[ind]-2,fn);    */
}

int main()
{
   FAST/**/
   
   ll n,x;
   cin>>n>>x;
   
   ll fn[53];
   fn[0] = 1;
   for(ll i=1;i<53;i++)
        fn[i] = 2*fn[i-1] + 3;
   
   ll ans = get(x,fn,n);
   cout<<ans;
   
   
   return 0;
}

Measured memory_bytes: 256
s = int(input())

def f(x):
    if x%2 == 0:
        return int(x/2)
    else:
        return 3*x + 1
i = 1
m_max = 1000000
b_s = s
b = set([s])
while i <= m_max:
    i += 1
    a = f(b_s)
    if a in b:
        break
    b.add(a)
    b_s = a
print(i)

Measured memory_bytes: 9168
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
using namespace std;

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

    int digitSum = 0;
    int tmp = N;
    while(tmp > 0){
        digitSum += tmp % 10;
        tmp /= 10;
    }
    if(N % digitSum == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

int A[10000000];

int main(){
    int n,q,k;
    int sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d", &A[i]);
    }

    cin>>q;
    for(int j=0;j<q;j++){
        cin>>k;
        if( *lower_bound(A, A+n, k)==k) sum++;
    }
    cout<<sum<<endl;

    return 0;

}


Measured memory_bytes: 3512
def single_shuffle(cards, h)
  tmp = cards[0..(h-1)]
  cards.slice!(0..(h-1))
  cards<<tmp
  return cards
end

def shuffle(cards, h_array)
  length = h_array.length
  for i in 0..(length-1)
    single_shuffle(cards, h_array[i])
  end
  return cards
end

answer = []

while true
  cards = gets.chomp
  if cards == "-"
    break
  else
    m = gets.chomp.to_i
    h_array = []
    m.times do
      h = gets.chomp.to_i
      h_array.push(h)
    end
    answer.push(shuffle(cards, h_array))
  end
end

length = answer.length
for i in 0..(length-1)
  puts answer[i]
end

Measured memory_bytes: 8664
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <memory.h>
#include <algorithm>
#include <cassert>
#include <numeric>
#include <functional>
#include <queue>

using namespace std;

#define prev prev_______________________
#define next next_______________________
#define hash hash_______________________
#define y1 y1___________________________

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(c) (c).begin(), (c).end()
#define sz(c) int((c).size())
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define fst first
#define snd second

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

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr);
#else
#define eprintf(args...) ;
#define cerr if (0) cerr
#endif

ll a, b, c;
ll k;

bool read() {
    if  (!(cin >> a)) {
        return 0;
    }
    cin >> b >> c;
    cin >> k;
    return 1;
}

void solve() {
    if  (k % 2 == 1) {
        cout << b - a << endl;
    } else {
        cout << a - b << endl;
    }
}

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

#ifdef LOCAL
    #define FNAME "a"
    freopen(FNAME ".in", "r", stdin);
    freopen(FNAME ".out", "w", stdout);
#endif

    while (read()) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(3);

    vector<double> v;
    double n;
    while (cin >> n)
        v.push_back(n);

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

    cout << v[v.size() - 1] - v[0] << endl;
    return 0;
}


Measured memory_bytes: 3168
a, b, c, x, y = map(int, input().split())

min_price = 2 * 5000 * 100000
for nab in range(0, 2 * max(x, y) + 1, 2):
    na = max(0, x - nab // 2)
    nb = max(0, y - nab // 2)
    min_price = min(min_price, nab * c + na * a + nb * b)

print(min_price)

Measured memory_bytes: 3060
# https://atcoder.jp/contests/abc150/submissions/9395610

def main():
    from functools import reduce

    def count_two(x):
        ret = 0
        while x % 2 == 0:
            x //= 2
            ret += 1
        return ret

    def lcm(a, b):
        def _gcd(a, b):
            return a if b == 0 else _gcd(b, a % b)

        return a * b // _gcd(a, b)

    n, m = map(int, input().split())
    *a, = map(int, input().split())

    a = [x >> 1 for x in a]

    e = len(set(map(count_two, a)))
    if e != 1:
        print(0)
        return

    # x=(ai/2)*(2p+1)と変形する
    # 2p+1は奇数だから、
    # すべてのiについて,xと(ai/2)は,2で割れる回数が等しい必要がある

    x = reduce(lcm, a)
    ret = (m // x) - (m // (x + x))
    print(ret)
    # xは(ai/2)の最小公倍数の奇数倍
    # (ai/2)の最小公倍数の倍数全体から
    # (ai/2)の最小公倍数の偶数倍を引いた残り


if __name__ == '__main__':
    main()


Measured memory_bytes: 14748
#include <stdio.h>
#include <string.h>
const int N = 1300;
int main(){
	char str[N];
	while(fgets(str, 1300, stdin))
	{
		for(int i = 0; i < strlen(str); i++)
		{
			if(str[i] >= 'A' && str[i] <= 'Z')
			{
				printf("%c", str[i] + 32);
			}
			else if(str[i] >= 'a' && str[i] <= 'z')
			{
			    printf("%c", str[i] - 32);	
			}
			else
			{
				printf("%c", str[i]);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2628
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String alpha = sc.next();
        
        if (alpha.toUpperCase().equals(alpha)) {
             System.out.println("A");
        } else {
            System.out.println("a");
        }
       
    }
}


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

int main() {
  int n,x,b;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a.at(i);
  x=b=0;
  
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0;i<n;i++){
    if(i%2==0)x+=a.at(i);
    else b+=a.at(i);
  }
  cout<<x-b<<endl;
}


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

//{{{
#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
 vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x;
 while (getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
 template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}
//

int T;

const int mod = 1e9 + 7;
const int N = 2e5 + 10;
int x;
int n, k;
int a[N];

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif

    while (cin >> n >> k)
    {
        for (int i = 1; i <= n; i++) cin >> a[i];
        int st = 1, ed = k + 1;

        for (int i = 0; i < n - k; i++)
        {
            // debug(st, ed, n);
            if (a[ed] > a[st])

                cout << "Yes" << endl;
            else
                cout << "No" << endl;

            st++;
            ed++;
        }
    }

    return 0;
}

Measured memory_bytes: 4412
def d_replacing():
    from collections import Counter
    N = int(input())
    A = [int(i) for i in input().split()]
    Q = int(input())
    Queries = [[int(i) for i in input().split()] for j in range(Q)]

    total = sum(A)
    sequence = Counter(A)

    ans = []
    for b, c in Queries:
        sub = b * sequence[b]
        add = c * sequence[b]
        total += add - sub
        ans.append(total)
        sequence[c] += sequence[b]
        sequence[b] = 0
    return '\n'.join(map(str, ans))

print(d_replacing())

Measured memory_bytes: 49056
n, m = map(int,input().split())
h = list(map(int,input().split()))

ab = [list(map(int,input().split())) for _ in range(m)]


point = [0]*n
app = [0]*n
cnt = []

for i in ab:
    app[i[0]-1] += 1
    app[i[1]-1] += 1
    if h[i[0]-1] > h[i[1]-1]:
        point[i[0]-1] += 1
    elif h[i[0]-1] < h[i[1]-1]:
        point[i[1]-1] += 1
for i in range(n):
    if app[i] == point[i]:
        cnt.append(i+1)
print(len(cnt))


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

int main() {
  long a,b;
  string s,ans="Yes";
  cin >> a >> b >> s;
  for(int i=0;i<a+b+1;i++) {
    if(i!=a&&s[i]=='-') ans="No";
    if(i==a&&s[i]!='-') ans="No";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  N--;
  int data[] = {1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << data[N] << endl;
  return 0;
}

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

int len(char* str){
  int i=0;
 while(str[i]){
     i++;
 }
 return i;
}
int main()
{
    char a[2000];
    cin>>a;
    for (int i=0;i<len(a);i++)
    cout <<"x";
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n,t;
    cin>>n>>t;
    unsigned long min = -1;
    for(int i = 0; i < n; i++){
        int c,tt;
        cin>>c>>tt;
        if(tt<=t){
            if(c<min)
                min = c;
        }
    }
    if(min == -1){
        cout<<"TLE";
    }
    else
        cout<<min;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

const int inf = 1<<30;
int N, Ma, Mb;
vector<int> a, b, c;

void input(){
    cin >> N >> Ma >> Mb;
    a.resize(N); b.resize(N); c.resize(N);
    rep(i, N) cin >> a[i] >> b[i] >> c[i];
}

void solve(){
    
    vector<vector<vector<int>>> dp(N+1, vector<vector<int>>(440, vector<int>(440, inf)));
    dp[0][0][0] = 0;
    rep(i, N) rep(j, 401) rep(k, 401) {
        // not use
        chmin(dp[i+1][j][k], dp[i][j][k]);
        // use
        if(j-a[i]>=0 && k-b[i]>=0) chmin(dp[i+1][j][k], dp[i][j-a[i]][k-b[i]]+c[i]);
    }

    int ans = inf;
    repr(j, 1, 401) repr(k, 1, 401){
        if(j*Mb == k*Ma) chmin(ans, dp[N][j][k]);
    }
    cout << (ans==inf? -1:ans) << endl;
}

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

    input();
    solve();

    return 0;
}

Measured memory_bytes: 32768
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	map<string, int> mp;
	REP(i,n){
		string s;
		cin >> s;
		mp[s]++;
	}
	int maxc = 0;
	for(auto t: mp){
		maxc = max(maxc, t.second);
	}
	for(auto t: mp){
		if(t.second == maxc){
			cout << t.first << '\n';
		}
	}

	return 0;
}



Measured memory_bytes: 23808
// 043.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <map>
#include <climits>
#include <algorithm>

using namespace  std;

typedef long long ll;

int join(int a[], int size)
{
	
	for (int i = 0; i < size-2; ++i)
	{
		const auto diff = abs(a[i] - a[i + 2]);
		if (a[i] == a[i + 2]) a[i] = 0;		
		else if (diff == 1) { a[i] = 1; }
		else
		{
			if (a[i + 1] == 2) a[i] = 0;
			else a[i] = 2;
		}
	}

	if (size == 2) return abs(a[0]- a[1]);
	return join(a, size - 2);
}

int main()
{
	//A
   /* int a, b, c;
	cin >> a >> b >> c;

	bool is_equal =
		a == b && a != c ||
		a == c && a != b ||
		b == c && b != a;
	cout << (is_equal ? "Yes" : "No");*/

	//B
	/*int n;
	cin >> n;
	vector<int> a(n);
	int ai;
	for (int i = 0; i < n; ++i)
	{
		cin >> ai;
		a[i] = ai;
	}

	bool is_approved = true;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] % 2 == 0)
		{
			if (a[i] % 3 != 0 && a[i] % 5 != 0)
			{
				is_approved = false;
				break;
			}
		}
	}

	cout << (is_approved ? "APPROVED" : "DENIED");*/


	//C
	/*int n;
	cin >> n;

	map<string, int> votes;

	int max = -1;

	string s;
	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		votes[s]++;
		if (votes[s] > max) max = votes[s];
	}


	for (const auto& item :votes)
	{
		if (item.second == max)
		{
			cout << item.first << "\n";
		}
	}*/


	//D
	

	//E
	string n;
	cin >> n;

	//pd[i][j] - оптимальное число монет для числа 0..i (с конца), j - ждем ли сдачу
	int dp0, dp1;

	int res = 0;
	int prev = 0;
	for (ll i = n.length() - 1; i >= 0; --i)
	{
		int a = n[i] - '0';
		if (i == n.length() - 1)
		{
			dp0 = a;
			dp1 = 10 - a;
		}
		else
		{
			int new_dp0 = a + min(dp0, dp1 + 1);
			int new_dp1 = min(10 - a + dp0, 10 - (a +1) + dp1);

			dp0 = new_dp0;
			dp1 = new_dp1;
		}
		
		/*a += prev;
		const auto back_pay = (10 - a) % 10;
		if (a <= back_pay)
		{
			res += a;
			prev = 0;
		}
		else
		{
			res += back_pay;
			prev = 1;
		}*/
	}
	dp1++;
	//res += prev;

	cout << min(dp0, dp1);
}



Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep2(i, a, b) for(int i = (a); i < (b); i++)
typedef long long ll;

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

   if (n % 2 == 0) {
       cout << n << endl;
   } else {
       cout << n * 2 << endl;
   }
}

Measured memory_bytes: 256
import numpy as np

from numba import njit
@njit(cache=True)
def solve(N,K,A):
    for _ in range(K):
        B = np.zeros(N,dtype=np.int64)
        for i in range(N):
            l = max(0,i-A[i])
            r = min(N-1,i+A[i])
            B[l] += 1
            if N > r+1:
                B[r+1] -= 1
        
        A = np.cumsum(B)
        if np.all(A==N):
            break

    return A

def main():
    N,K = map(int,input().split())
    A = np.array(list(map(int,input().split())))

    A = solve(N,K,A)
    print(*A)

main()


Measured memory_bytes: 126172
import java.io.*;
import java.math.BigDecimal;
import java.util.*;

public class Main {
	static int INF = 2 << 27;
	static int[] vx = {1,0,-1,0};
	static int[] vy = {0,1,0,-1};
	public static void main(String[] args) {	
		//FastScanner sc = new FastScanner();
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int m = sc.nextInt();
		int[] c = new int[m];
		int[] d = new int[m];
		boolean[] triple = new boolean[N+1];
		for(int i = 0; i < m; i++) {
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
			for(int j = c[i]; j < d[i]; j++) {
				triple[j] = true;
			}
		}
		int sum = 0;
		for(int i = 0; i <= N; i++) {
			if(triple[i]) sum += 3;
			else sum += 1;
		}
		System.out.println(sum);
		
		
		
		
		
	}
}

Measured memory_bytes: 30256
'use strict'

const Main = (input) => {
  const N = input.trim()

  const F = N.split('')[N.length - 1]

  let result = 'hon'

  if (F === '0' || F === '1' || F === '6' || F === '8') {
    result = 'pon'
  } else if (F === '3') {
    result = 'bon'
  }

  console.log(result)
  return result
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

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

char H[M][L];

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

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

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

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

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

int main(){
  int i,n,h;
  char str[L],com[9];
  for(i=0;i<M;i++)H[i][0]='\0';
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",com,str);

    if(com[0]=='i'){
      insert(str);
    }else{
      if(find(str)){
        printf("yes\n");
      }else{
        printf("no\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 14916
// template version 1.7

// varibable settings {{{
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define int long long
#define INF 1e18
// #define INF 2147483647
#define MOD 1e9+7
#define infile "../test/sample-1.in"
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
// }}}

int solve(){
  int n;cin>>n;
  int a[n]; rep(i, n) {cin>>a[i];}

  int h = 0;
  int res = 0;
  rep(i, n){
    if (h<=a[i]){
      res++;
      h = a[i];
    }
  }
  cout << res << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

vector<ll> a, p;

ll f(int n, ll x){

    // レベル0のバーガーの場合
    if (n == 0){
        // xがあれば1
        if (x > 0) return 1;
        else return 0;
    }
    // バーガーが半分より下
    else if (x <= 1 + a[n-1]){
        return f(n-1, x-1);
    }
    // バーガーのちょうど半分
    else if (x == 2 + a[n-1]){
        return p[n-1] + 1;
    }
    // バーガーが半分より上
    else{
        return p[n-1] + 1 + f(n-1, x-(a[n-1]+2));  
    }
}


int main(){
    int N;
    ll X;
    cin >> N >> X;
    a.resize(N+1);
    p.resize(N+1);
    a[0] = p[0] = 1;
    rep(i,N){
        // バーガーの層
        a[i+1] = 2*a[i]+3;
        // パティの数
        p[i+1] = 2*p[i]+1;        
    }

    cout << f(N,X) << endl;

}

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

int main() {
	int a[3];
  	rep(i,3) cin>>a[i];
  	sort(a,a+3);
  	
  	if(a[0]==5 && a[1]==5 && a[2]==7) cout<<"YES"<<endl;
   	else cout<<"NO"<<endl;
  	
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    cin>>N;
    vec l(N), r(N), ord(N);
    rep(i,N){
        cin>>A>>B;
        l[i] = A - B;
        r[i] = A + B;
        ord[i] = i;
    }
    ll last = -1e+11, ans = 0;
    sort(ALL(ord), [&](int x, int y){
        return r[x] < r[y];
    });
    for(int id : ord){
        if(l[id] >= last){
            ++ans;
            last = r[id];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

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

        Scanner scanner = new Scanner(System.in);

        while(true) {
            Integer a = scanner.nextInt();
            Integer b = scanner.nextInt();

            if (a == 0 && b == 0) {
                break;
            }
            AtomicInteger count = new AtomicInteger(0);
            List<String> used = new ArrayList<>();
            IntStream.range(1, a + 1)
                     .forEach(x -> {
                         IntStream.range(1, a + 1)
                                  .filter(y -> y != x)
                                  .forEach(y -> {
                                      IntStream.range(1, a + 1)
                                               .filter(z -> z != x && z != y)
                                               .filter(z -> x + y + z == b)
                                               .forEach(z -> {
                                                   String sorted = Arrays.asList(x, y, z)
                                                                         .stream()
                                                                         .sorted()
                                                                         .collect(Collectors.toList())
                                                                         .toString();
                                                   if (used.contains(sorted)) {
                                                       return;
                                                   }
                                                   used.add(sorted);
                                                   count.getAndAdd(1);
                                               });
                                  });
                     });
            System.out.println(count.get());
        }
    }
}



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

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

    int cnt = 1;

    for(int i = 0; i < N; ++i) {
        if(cnt + K > cnt * 2) {
            cnt = cnt * 2;
        } else {
            cnt = cnt + K;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
import math

N = int(input())
lst = [int(x) for x in input().split()]
a = sum(lst) / N
b = math.ceil(a)
c = math.floor(a)
ret1 = sum([(b - x) ** 2 for x in lst])
ret2 = sum([(c - x) ** 2 for x in lst])

print(min(ret1, ret2))



Measured memory_bytes: 3060
n = int(input())
ls = sorted(list(map(int, input().split())))
cnt = 0
for i in range(len(ls) - 2):
    a = ls[i]
    for j in range(i+1, len(ls) - 1):
        b = ls[j]
        for k in range(j+1, len(ls)):
            c = ls[k]
            if a==b or a==c or b==c:
                continue
            if a+b > c and b+c > a and c+a > b:
                cnt += 1
print(cnt)

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

int main(){
    int h,w;
    
    while(1){
        cin>>h>>w;
        if(h==0 && w==0)break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cout<<"#";
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3068
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	char rem[500];
	char ram[500];
	int ar[n];
	for (int i=0;i<n;i++)
		ar[i]=0;
	int x=0;
	int l=0,r=n,mid;
	int prev=0;
	int q=19;
	printf ("%d\n",x);
	fflush(stdout);
	ar[0]=1;
	scanf("%s",ram);
	{
		while (q--)
		{
			mid=(l+r)/2;
			x=mid;
			printf ("%d\n",x);
			fflush(stdout);
			scanf("%s",rem);
			if (!strcmp(rem,"Vacant"))break;
			else if (!strcmp(rem,ram))
			{
				ar[x]=1;
				if (((x-prev+n)%n)%2==0)
				{
					l=mid;
				}
				else r=mid;
			}
			else
			{
				ar[x]=1;
				if (((x-prev+n)%n)%2==0)
				{
					r=mid;
				}
				else l=mid;
			}
			prev=x;
			strcpy(ram,rem);
		}
	}
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a*b==15){
        cout << "*" << endl;
    }else if(a+b==15){
        cout << "+" << endl;
    }else{
        cout << "x" << endl;
    }
}







Measured memory_bytes: 384
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << 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 solve() {
	int n; cin >> n;
    vector<int> p(n);
    vector<int> pos(n);
    rep(i, n) {
        cin >> p[i];
        -- p[i];
        pos[p[i]] = i;
    }
    vector<int> a(n, -1), b(n, -1);
    rep(i, n) {
        a[i] = (i + 1) * n;
    }
    b[p[0]] = n * n;
    for(int i = 1; i < n; ++i) {
        int j = p[i];
        int k = p[i - 1];
        b[j] = a[k] + b[k] + 1 - a[j];
    }
    rep(i, n) {
        cout << a[i] << " ";
    }
    cout << endl;
    rep(i, n) {
        cout << b[i] << " ";
    }
    cout << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 1024
import java.io.*;
 
class Main {
    public static void main(String[] args) {
        BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        try {
            String str = kb.readLine();
            String[] tmpArr = str.split( " " );
            int n = Integer.parseInt( tmpArr[0] );
            int m = Integer.parseInt( tmpArr[1] );
                         
            int[][] a = new int[n][m];
            int[] b = new int[m];
            int c;
 
 
            for( int i=0; i<n; i++ ) {
                str = kb.readLine();
                tmpArr = str.split( " " );
                for( int j=0; j<m; j++ ) {
                    a[i][j]=Integer.parseInt( tmpArr[j] );
                }
            }
            for( int j=0; j<m; j++ ) {
                str = kb.readLine();
                b[j]=Integer.parseInt( str );
            }
             
            for( int i=0; i<n; i++ ) {
                c=0;
                for( int j=0; j<m; j++ ) {
                    c+=a[i][j]*b[j];
                }
                System.out.print( c+"\n" ); 
            }
        } catch( IOException e ) {
            System.err.println( e );
        }
    }
}

Measured memory_bytes: 22548
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,sa[3010],sb[3010],ta=0,tb=0,pos[6010];
char s[6010];
string f[3010];
int main()
{
	scanf("%d\n%s",&n,s+1);
	for(int i=1;i<=2*n;i++)
	{
		if(s[i]=='a') sa[++ta]=i,pos[i]=ta;
		else sb[++tb]=i,pos[i]=tb;
	}
	string ans;
	for(int i=n;i>=1;i--)
	{
		if(sa[i]<sb[i])
		{
			int k=i;
			for(int j=sa[i]+1;j<sb[i];j++) k=max(k,pos[j]);
			f[i]="ab"+f[k+1];
		}
		else
		{
			int k=i;
			while(k<n&&sb[k+1]<sa[k]) k++;
			for(int j=sb[i];j<=2*n;j++) if(i<=pos[j]&&pos[j]<=k) f[i]+=s[j];
			f[i]+=f[k+1];
		}
		f[i]=max(f[i],f[i+1]);
		ans=max(ans,f[i]);
	}
	printf("%s",ans.c_str());
}

Measured memory_bytes: 14720
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  Int g=0;
  for(Int i=0;i<n;i++) g^=a[i];

  Int ans=0;
  set<Int> s;
  for(Int i=0;i<n;i++) s.emplace(-__builtin_ctzll(a[i]));
  for(Int x:s){
    Int y=-x;
    if((g>>y)&1){
      g^=(1<<(y+1))-1;
      ans++;
    }
  }
  
  if(g) ans=-1;
  cout<<ans<<endl;
  return 0;
}


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

inline int read()
{
 char c=getchar();
 int x=0,f=1;
 while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
 while (c>='0'&&c<='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
 return x*f;
}

int main()
{
 int n;
 scanf("%d",&n);
 cout<<"Christmas";
 while (n<25) {n++;cout<<" Eve";}
 cout<<endl;
 return 0;
}

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

int main(){
	// sengen
	int a[3][3];
	int count[3][3];
	int n;
	// nyuryoku
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin >> a[i][j];
			count[i][j] = -1;
		}
	}
	cin >> n;
	int b[n];
	for(int i=0;i<n;i++){
		cin >> b[i];
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(a[j][k] == b[i]){
					count[j][k] = 1;
				}
			}
		}
	}
	// keisan
	int judge = 0;
	for(int i=0;i<3;i++){
		if(count[i][0]==1&&count[i][1]==1&&count[i][2]==1){
			judge = 1;
		}
	}
	for(int i=0;i<3;i++){
		if(count[0][i]==1&&count[1][i]==1&&count[2][i]==1){
			judge = 1;
		}
	}
	if(count[0][0]==1&&count[1][1]==1&&count[2][2]==1) judge=1;
	if(count[0][2]==1&&count[1][1]==1&&count[2][0]==1) judge=1;
	// syutsuryoku
	if(judge){
		cout << "Yes";
	}else{
		cout << "No";
	}
}

Measured memory_bytes: 256
import fractions
from functools import reduce

n = int(input())
a = list(map(int,input().split()))

#累積GCD
left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
    left[i + 1] = (fractions.gcd(left[i],a[i]))
    right[n - i - 1] = (fractions.gcd(right[n - i],a[n - 1 - i]))

ans = 0
for i in range(n):
    ans = max(ans,fractions.gcd(left[i],right[i + 1]))
print(ans)


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

#define pout(n)  printf ("%d\n", n)
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main (){
  int a,b,c;
  int count = 0;
  string s;

  cin >> a >> b >> s;

  rep(i,0,s.length()){
    if(s[i] == '-'){
      c = i;
      count++;
    }
    if(count == 2){
      puts("No");
      return 0;
    }

  }

  if(a != c && b != s.length()-(c+1)){
    puts("No");
  }
  else if(s.length() != a+b+1) puts("No");
  else puts("Yes");

  return 0;
}

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

struct point
{
	int i,id,ans;
}a[100005],b[100005];

bool cmp(point x,point y)
{
	return x.i>y.i;
}

int main()
{
	int n;
	cin>>n;
	int x;
	for(int i=1;i<=n;i++){
		cin>>x;
		if(i%2){
			a[x].i++;
			a[x].id=x;
		}
		else{
			b[x].i++;
			b[x].id=x;
		}
	}
	sort(a,a+100002,cmp);
	sort(b,b+100002,cmp);
	a[0].ans=(n+1)/2-a[0].i;
	b[0].ans=(n-(n+1)/2)-b[0].i;
	a[1].ans=(n+1)/2-a[1].i;
	b[1].ans=(n-(n+1)/2)-b[1].i;
	if(a[0].id==b[0].id){
		if(a[1].i==0){
			cout<<b[0].ans+a[1].ans<<endl;
		}
		else if(b[1].i==0){
			cout<<a[0].ans+b[1].ans<<endl;
		}
		else{
			cout<<min(a[0].ans+b[1].ans,a[1].ans+b[0].ans)<<endl;
		}
	}
	else{
		cout<<a[0].ans+b[0].ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 2688
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

// =========ここまでテンプレ============

int main()
{
    ll n;
    cin >> n;
    multiset<ll> a;
    rep(i, n)
    {
        ll tempA;
        cin >> tempA;
        a.insert(tempA);
    }
    vector<ll> numbers(1000001, true);
    set<ll> primes;
    ll last;
    for (auto itr = a.begin(); itr != a.end(); ++itr)
    {
        if (last == *itr)
        {
            primes.erase(*itr);
        }
        else if (numbers[*itr])
        {
            primes.insert(*itr);
            last = *itr;
            for (ll j = 2; j * (*itr) <= 1000001; ++j)
            {
                numbers[j * (*itr)] = false;
            }
        }
    }
    cout << primes.size() << endl;
}

Measured memory_bytes: 29384
n=int(input())
d={}
for i in range(1, n+1):
  x=int(input())
  d[i] = x
if d[1] == 2:
  print(1)
  exit()
tmp = d[1]
ans=1
for _ in range(n):
  ans+=1
  tmp = d[tmp]
  #print(tmp)
  if tmp == 2:
    print(ans)
    exit()
print(-1)

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

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    rep(i, n - 1) if (h[i] < h[i + 1]) h[i + 1]--;
    bool ok = true;
    rep(i, n - 1) if (h[i] > h[i + 1]) ok = false;
    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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




#define INF INT_MAX/2
int X, Y;
//-----------------------------------------------------------------
int main() {
	cin >> X >> Y;

	int ans = INF * 2;
	rep(i, 0, 2) rep(j, 0, 2) {
		int a = X * (1 - i * 2);
		int b = Y * (1 - j * 2);
		if (a <= b) ans = min(ans, b - a + (i + j));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x);

P dequeue(void);


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head=1;
  tail=n+1;

  while(head!=tail){
    u=dequeue();

    if(u.t<=q){
      elaps += u.t;
      printf("%s %d\n",u.name,elaps);
    }
    else if(u.t>q){
      elaps += q;
      u.t=u.t-q;
      enqueue(u);
    }

  }


  return 0;
}

void enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P dequeue(void){
  P y;
  y=Q[head];
  head=(head+1)%LEN;
  return y;

}



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

using namespace std;

const int INF = numeric_limits<int>::max() / 2;

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

	int H,W,h,w;cin>>H>>W>>h>>w;
	if(H%h==0 && W%w==0){
		cout<<"No"<<endl;
		return 0;
	}
	vector<vector<int>> res(H,vector<int>(W,1));
	if(W%w!=0){
		vector<int> sum(W+1,0);
		for(int i=w;i<=W;i+=w){
			sum[i]=sum[i-w]-1;
		}
		for(int i=W;i>0;i--){
			if(sum[i]!=0) continue;
			sum[i]=1;
			for(int j=i-w;j>0;j-=w){
				sum[j]=sum[j+w]+1;
			}
		}
		for(int i=0;i<W;i++){
			res[0][i]=sum[i+1]-sum[i];
		}
		for(int i=1;i<H;i++){
			for(int j=0;j<W;j++){
				res[i][j]=res[0][j];
			}
		}
	}
	else{
		vector<int> sum(H+1,0);
		for(int i=h;i<=H;i+=h){
			sum[i]=sum[i-h]-1;
		}
		for(int i=H;i>0;i--){
			if(sum[i]!=0) continue;
			sum[i]=1;
			for(int j=i-h;j>0;j-=h){
				sum[j]=sum[j+h]+1;
			}
		}
		for(int i=0;i<H;i++){
			res[i][0]=sum[i+1]-sum[i];
		}
		for(int i=0;i<H;i++){
			for(int j=1;j<W;j++){
				res[i][j]=res[i][0];
			}
		}
	}
  cout<<"Yes"<<endl;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(j==0) cout<<res[i][j];
			else cout<<" "<<res[i][j];
		}
		cout<<endl;
	}
}


Measured memory_bytes: 2304
A, B = [int(ab) for ab in input().split()]
ans = 0
for AB in range(A, B+1):
  AB_str = str(AB)
  for i in range(len(AB_str)//2):
    if AB_str[i] != AB_str[-i-1]:
      break
  else:
    ans += 1
print(ans)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int k = Integer.parseInt(str[1]);
    int[] l = new int[n];
    int sum = 0;
    str = in.readLine().split(" ");
    for(int i=0; i<n; i++) {
      l[i] = Integer.parseInt(str[i]);
    }
    Arrays.sort(l);
    for(int i=n-1; i>n-1-k; i = i-1) {
      sum += l[i];
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 32752
#include <bits/stdc++.h>
using namespace std;
int k; string s; int n;

int main(){
    cin >> k >> s; n = s.length();
    if(n>k){
        for(int i=0; i<k; i++) cout << s[i];
        cout << "..." << endl;
    }
    else{
        cout << s << endl;
    }
}


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

int main() {
    string s; cin >> s;
    if(s[0] == 'R') {
        if(s[1] == 'R') {
            if(s[2] == 'R') cout << 3 << endl;
            else cout << 2 << endl;
        }
        else cout << 1 << endl;
    }
    else if(s[1] == 'R') {
        if(s[2] == 'R') cout << 2 << endl;
        else cout << 1 << endl;
    }
    else if(s[2] == 'R') cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 3560
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

p = []
m = []
zero = 0
for i in range(N) :
  if A[i] > 0 :
    p.append(A[i])
  elif A[i] < 0 :
    m.append(-A[i])
  else :
    zero += 1

p.sort()
m.sort()

ng, ok = -(10 ** 18)-1, 10 ** 18+1
while ok - ng > 1 :
  mid = (ok + ng) // 2
  s = 0 
  if mid < 0 :
    j = 0
    for i in range(len(m) - 1, -1, -1) :
      while j < len(p) and m[i] * p[j] < -mid :
        j += 1
      s += len(p) - j
      
  else :
    j = len(p) - 1
    for i in range(len(p)) :
      while j >= 0 and p[i] * p[j] > mid :
        j -= 1
      s += max(0, j - i)
      
    j = len(m) - 1
    for i in range(len(m)) :
      while j >= 0 and m[i] * m[j] > mid :
        j -= 1
      s += max(0, j - i)
      
    s += (len(p) + len(m)) * zero + len(p) * len(m) + zero * (zero - 1) // 2

  if s < K :
    ng = mid
  else :
    ok = mid
    
print(ok)


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

int main(void){

  int *flag;
  int *dest;

  int num;

  scanf("%d",&num);

  flag = (int*)calloc(num,sizeof(int));
  dest = (int*)calloc(num,sizeof(int));

  int i;

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

  
  int cnt = 0;
  int current = 1;

  while(1){
    if(flag[current] == 1){
      printf("-1\n");
      break;
    }else{
      flag[current] = 1;
    }

    if(current == 2){
      printf("%d\n",cnt);
      break;
    }
    current = dest[current - 1];
    cnt++;
  }


  free(flag);
  free(dest);
  return 0;
}


Measured memory_bytes: 896
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

int main(){
  string str; cin >> str;
  int n = str.size();
  ll ans = 0;
  for(int i=0;i<(1 << (n-1)); i++){
    int bits = i;
    ll sum = 0;
    ll t = str[0]-'0';
    int cnt = 1;
    while(cnt <= n-1){
      if(bits %2 == 0){
        bits = bits/2;
        t = 10*t + (str[cnt]-'0');
      }else{
        bits = bits/2;
        sum = sum + t;
        t = str[cnt]-'0';
      }
      cnt++;
    }
    sum = sum + t;
    ans = ans + sum;
    //cout << i << " " << sum << endl;
  }
  cout << ans << endl;
}

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

using namespace std;

const int C = 17;
const int N = 300;

int dp[C+1][N+1];

void solve(){
  dp[0][0] = 1;
  for(int j = 1; j <= C; j++) dp[0][j] = 0;
  
  for(int i = 1; i <= C; i++){
    for(int j = 0; j <= N; j++){
      if(j >= i * i) dp[i][j] = dp[i - 1][j] + dp[i][j - i * i];
      else dp[i][j] = dp[i - 1][j];
    }
  }
}

int main(){
  int n;
  solve();
  while(cin >> n && n){
    cout << dp[C][n] << endl;
  }
}

Measured memory_bytes: 0