akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	string s;
	cin>>s;
	ll c1=0,c2=0;
	for(int i=0;i<s.size();i++){
		if(i%2){
			if(s[i]=='0')c1++;
			else c2++;
		}else{
			if(s[i]=='1')c1++;
			else c2++;
		}
	}
	cout<<min(c1,c2)<<endl;
	return 0;
}

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
vector<int> init_spf(int n){
    vector<int> spf(n+1);
    for (int i = 0; i < n+1; i++){
        spf[i]=i;
    }
    for (int i = 2; i*i<=n; i++){
        if(spf[i]==i){
            for (int j = i*i; j <= n; j+=i){
                if(spf[j]==j)spf[j]=i;
            }
        }
    }
    return spf;
}
int main(){
    auto spf=init_spf(100003);
    int X;cin>>X;
    for (int i = X; ; i++){
        if(spf[i]==i){
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3720
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

//最大公約数

ll mod = pow(10, 9) + 7;


int main() {
	int N, H,i,a,b,a_max=0,ans=0;
	cin >> N >> H;
	vector<int> B(100000);
	REP(i, N) {
		cin >> a >> b;
		a_max = max(a_max, a);
		B[i] = b;
	}
	sort(B.begin(), B.begin() + N);
	i = N - 1;
	int sum = 0;
	while (i>=0) {
		if (sum >= H) {
			cout << ans << endl;
			return 0;
		}
		if (B[i] > a_max) {
			sum += B[i];
			ans++;
		}
		else
			break;
		i--;
	}
	cout << ans + (H - sum+a_max-1) / a_max << endl;
	return 0;
}


Measured memory_bytes: 768
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

string in;
char search(int s, int& e, int p, int& len){
	if(s==in.size()){
		len=0;
		return 0;
	}
	//cout << s << ", " << p << ", " << in[s] << endl;
	if(in[s]==')'){
		len=0;
		e=s+1;
		return 0;
	}
	if(in[s]=='('){
		return search(s+1,e,p,len);
	}
	else
	{
		int r=s;
		int v=0;
		while('0'<=in[r]&&in[r]<='9'){
			v*=10;
			v+=in[r]-'0';
			r++;
		}
		if(v>0){
			int l=0;
			char c;
			if(in[r]=='(')
			{
				c=search(r,e,p,l);
				if(c){
					return c;
				}
				if(p<l*v){
					return search(r,e,p%l,l);
				}
			}
			else
			{
				if(p<v){
					return in[r];
				}
				l=1;
				e=r+1;
			}
			p-=l*v;
			len=l*v;
		}
		else{
			if(p==0){
				return in[s];
			}
			p--;
			e=s+1;
			len=1;
		}
	}
	int len2;
	char ret=search(e,e,p,len2);
	len+=len2;
	return ret;
}
int main() {
	int pos=0;
	while(cin >> in >> pos){
		if(in[0]=='0'&&pos==0){
			return 0;
		}
		//cout << in << ", " << pos << endl;
		int e,len;
		char c=search(0,e,pos,len);
		if(c==0){
			c='0';
		}
		cout << c << endl;
	}
}

Measured memory_bytes: 1204
import java.util.Scanner;

/**
 * Created by Reopard on 2014/05/22.
 */
public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String args[]) {
        int n, count, number;
        String line;
        char button[];
        char keitaiButton[][] = {
                {'.', ',', '!', '?', ' '},
                {'a', 'b', 'c'},
                {'d', 'e', 'f'},
                {'g', 'h', 'i'},
                {'j', 'k', 'l'},
                {'m', 'n', 'o'},
                {'p', 'q', 'r', 's'},
                {'t', 'u', 'v'},
                {'w', 'x', 'y', 'z'}
        };
        n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            line = sc.next();
            button = line.toCharArray();
            count = 0;
            for (int j = 0; j < button.length; j++) {
                while (button[j] - '0' != 0) {
                    count++;
                    j++;
                }
                if(count > 0) {
                    System.out.print(keitaiButton[(button[j - 1] - '0') - 1][(count - 1) % keitaiButton[(button[j - 1] - '0') - 1].length]);
                    count = 0;
                }
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 24328
#include<stdio.h>
 
int main()
{
	int n,b = 0,w = 0,i;
	scanf("%d",&n);
  
  	char c[n];
	scanf("%s",c);
	
	for(i = 0;i < n;i++){
		if(c[i] == '.') w++;
	}
	
	int min = w;
  
	for(i = 0;i < n;i++){
		if(c[i] == '#') b++;
		else w--;
		if(b + w < min) min = b + w;
	}
	printf("%d",min);
	return 0;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	"strings"
)

func main()  {
	var input string


	_, _ = fmt.Scan(&input)

	if strings.Count(input, "A") == 3 {
		fmt.Println("No")
		return
	}

	if strings.Count(input, "B") == 3 {
		fmt.Println("No")
		return
	}

	fmt.Println("Yes")
	return
}


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

int main() {
	int n;
 	cin>>n;
  	int num=n;
  	
  	bool nana=false;
  	rep(i,5){
      	if(num%10==7){
        	nana=true;
          	break;
        }
      
      else{
    	num/=10;
      }
    }
 	
  	if(nana){
    	cout<<"Yes"<<endl;
    }
  
  	else{
    	cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3568
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        String s = scanner.next();

        String r = s;
        if(s.length() > k){
            r = s.substring(0, k);
            r += "...";
        }

        System.out.println(r);
    }
}

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


int main() {
	int s;
	bool is = false;
	cin >> s;

	int tmp = s % 10;
	s /= 10;
	for (int i = 0; i < 3; i++) {
		if (tmp == s % 10) {
			is = true;
			break;
		}
		tmp = s % 10;
		s /= 10;
	}

	if (is) cout << "Bad";
	else cout << "Good";
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
A=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append([a,b])
A=sorted(A, key=lambda x:(x[0], -x[1]))
from collections import deque
A=deque(A)

# import numpy as np
import bisect as bi
ans=0
now=[]
for nouki in range(1,m+1):
    while A:
        a,b=A.popleft()
        if a>nouki: A.appendleft([a,b]);break
        bi.insort(now,b)
    #print(nouki, now)
    if now==[]:continue
    ans+= now[-1]
    del now[-1]


print(ans)
    


Measured memory_bytes: 99440
void main()
{
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], x = tmp[1];
    int[] a = readln.split.to!(int[]);

    a ~= x;
    a.sort!"a < b";
    int[] diff = new int[n];
    foreach (i; 0 .. n)
    {
        diff[i] = a[i+1] - a[i];
    }

    int d = diff[0];
    foreach (i; 1 .. n)
    {
        d = gcd(d, diff[i]);
    }

    d.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 4276
#include<bits/stdc++.h>
#define N 100010
using namespace std;
int x[14]={531441,279936,59049,46656,7776,6561,1296,729,216,81,36,9,6,1};
int vis[100010];
struct node
{
    int x,s;
    node(int xx,int ss):x(xx),s(ss){}
};
int main()
{
    int n,i,a,b,ans=0;
    cin>>n;
    queue<node>q;
    memset(vis,0,sizeof(vis));
    q.push(node(n,0));
    vis[n]=1;
    while(!q.empty())
    {
        node t=q.front();
        q.pop();
        if(t.x==0)
        {
            ans=t.s;
            break;
        }
        for(i=0;i<14;i++)
        {
            int a=t.x-x[i];
            if(a>=0&&vis[a]==0)
            {
                q.push(node(a,t.s+1));
                vis[a]=1;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

int main() {
    long long a,b,x;
    cin >> a >> b >> x;
    if(a > 0) {
        cout << b/x - (a-1)/x;
    }else {
        cout << b/x + 1;
    }
    return 0;
}

Measured memory_bytes: 256
A ,B ,C ,D = (map(int , input().split()))
from fractions import gcd
def lcm(x,y):
    return (x*y) // gcd(x,y)
koubaisuu = lcm(C,D)
e = B//C
f = B//D
g = B//(koubaisuu)
h = B-((e+f)-g)
AA = A - 1
ee = AA//C
ff = AA//D
gg = AA//(koubaisuu)
hh = AA-((ee+ff)-gg)
print(h-hh)

Measured memory_bytes: 5332
#include <string>
#include <stack>
#include <iostream>
#include <cstdlib>
using namespace std;
int main () {
  string word;
  stack<int> S;
  while (cin >> word) {
    if (word == "+") {
      int n = S.top();
      S.pop();
      n += S.top();
      S.pop();
      S.push(n);
    }
    else if (word == "-") {
      int s = S.top();
      S.pop();
      s = S.top() - s;
      S.pop();
      S.push(s);
    }
    else if (word == "*") {
      int y = S.top();
      S.pop();
      y *= S.top();
      S.pop();
      S.push(y);
    }
    else {
      S.push(atoi(word.c_str() ) );
	}
  }
  cout << S.top() << endl;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}


using namespace std;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(int argc, char *argv[]) {
    ll result = 0;
    ll k, x;
    cin >> k >> x;
    
    if(x < -1000000 + k){
        ll z = -1000000 - x;
        for(ll i = z; i < k; i ++){
            cout << x + i << " ";
        }
    } else if(x > 1000000 - k){
        ll z = 1000000 - x;
        for(ll i = -k+1; i < z+1; i ++){
            cout << x + i << " ";
        }
    } else {
        for(int i = -k+1; i < k; i ++){
            cout << x + i << " ";
        }
    }
    
    return 0;
}



Measured memory_bytes: 256
def nrange(n):
    if n == -1:
        return range(0, 1)
    if n == 0:
        return range(0, 2)

    if n % 2 == 0:
        np = n
        nm = n - 1
    else:
        np = n - 1
        nm = n

    ma = (4**(np // 2 + 1) - 1) // 3
    mi = -2 * (4**((nm + 1) // 2) - 1) // 3

    return range(mi, ma+1)


n = int(input())
k = 0
while n not in nrange(k):
    k += 1

s = ''
while k >= 0:
    if (n in nrange(k)) and (n not in nrange(k-1)):
        n -= (-2)**k
        s += '1'
    else:
        s += '0'

    k -= 1

print(s)

Measured memory_bytes: 3064
#include <cstdio>
#define inf 999999999
using namespace std;
int Mark[100005];
inline void _R(int &x)
{
	char c=getchar();
	while(c<'0'||c>'9')
		c=getchar();
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=x*10+c-'0';
}
int main()
{
	int n,x,Maxn=-inf,Max=-inf;
	_R(n);
	for(int i=1;i<=n;i++)
	{
		_R(x);
		Mark[x]++;
		Mark[x+1]++;
		Mark[x-1]++;
		if(x>Max)
			Max=x;
	}
	for(int i=1;i<=Max+1;i++)
		if(Mark[i]>Maxn && Mark[i]!=0)
			Maxn=Mark[i];
	printf("%d\n",Maxn);
}

Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))
total = 0
for i in range(N-1):
    if(A[i+1]<A[i]):
        add= abs(A[i+1]-A[i])
        A[i+1] = A[i+1]+add
        total+=add
print(total)

Measured memory_bytes: 32132
#include <bits/stdc++.h>
#define pii pair<int,int>
#define mp make_pair
#define xx first
#define yy second
using namespace std;
typedef long long ll;
const int N = 100010;
const ll mod = 998244353;
int a[N],b[N];
vector<int>v[N];
void solve(int p,int n)
{
    for(int i=1;i<=p;i++)
        v[i].clear();
    for(int i=1;i<=p;i++)
    {
        for(int j=i+1;j<=p;j++)
        {
            v[i].push_back(n);
            v[j].push_back(n--);
        }
    }
    printf("%d\n",p);
    for(int i=1;i<=p;i++)
    {
        printf("%d",v[i].size());
        for(int j=0;j<v[i].size();j++)
        {
            printf(" %d",v[i][j]);
        }
        printf("\n");
    }

}
int main()
{
    int n;
    scanf("%d",&n);
    if(n==1)
    {
        printf("Yes\n");
        printf("2\n1 1\n1 1\n");
        return 0;
    }
    for(int i=2;i<=n&&i*(i+1)<=n*2;i++)
    {
        if(i*(i+1)==n*2)
        {
            printf("Yes\n");
            solve(i+1,n);
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 4608
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
// dp[i][j]:i番目にjの手を出した時の点数の最大値
int dp[100010][3];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b; cin >> a >> b;
	int k; cin >> k;
	if (a <= k) {
		k -= a;
		a = 0;
	}
	else {
		a -= k;
		cout << a << " " << b << endl; return 0;
	}
	cout << a << " " << max(b - k, 0LL) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
#include<iterator>
using namespace std;
int main()
{

    int n;
    cin>>n;
unordered_map<string,int> arr;
arr.insert(make_pair("AC",0));
arr.insert(make_pair("WA",0));
arr.insert(make_pair("TLE",0));
arr.insert(make_pair("RE",0));

    string a;
    for(int i=0;i<n;i++){
      cin>>a;
      auto it= arr.find(a);

        it->second++;


    }
    cout<<"AC"<<" x "<<arr["AC"]<<endl;
    cout<<"WA"<<" x "<<arr["WA"]<<endl;
    cout<<"TLE"<<" x "<<arr["TLE"]<<endl;
    cout<<"RE"<<" x "<<arr["RE"]<<endl;

}


Measured memory_bytes: 3596
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class abc155_a {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();

            boolean ret = false;
            if ((A == B) && (A != C)) {
                ret = true;
            } else if ((A == C) && (A != B)) {
                ret = true;
            } else if ((B == C) && (A != C)) {
                ret = true;
            }
            out.println((ret ? "Yes" : "No"));

        }

    }
}



Measured memory_bytes: 21844
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int main(){
  int h, w, H, W;
  cin >> H >> W >> h >> w;
  cout << (H*W)-((h*W)+(w*H)-(h*w)) << endl;

  return 0;
}


Measured memory_bytes: 256
// input: aldsalds1_10_a.in
#include<iostream>
#define MAX_N 45
#define NIL -1
using namespace std;

int dp[MAX_N];

int fib(int n) {
  if(n == 0 || n == 1)
    return 1;

  if(dp[n] != NIL)
    return dp[n];

  int v = fib(n-1) + fib(n-2);
  dp[n] = v;

  return v;
}

int main() {
  for(int i=0; i<MAX_N; i++)
    dp[i] = NIL;

  int x;
  cin >> x;

  cout << fib(x) << endl;
}

Measured memory_bytes: 3092
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


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

	int org = 0;
	rep( i, N )
	{
		org += L + ( i + 1 ) - 1;
	}

	int aji = 10000;
	int result = 10000000;
	rep( i, N )
	{
		if ( abs( L + i ) <= aji )
		{
			result = org - ( L + i );
			aji = abs( L + i );
		}
	}

	cout << result << endl;

	return ( 0 );
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set> 
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector <int> v(n);
    int baap=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
        baap^=v[i];
    }
    for(int i=0;i<n;i++)cout<<(baap^v[i])<<" ";
    return 0;
}

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

  int b[n];

  for(int i=0; i<n; i++){
    int p = a[i];
    int m = 0;
    for(int j=0; m<1; j++){
      if(p%2!=0){
	m = 1;
      }
      p = p / 2;
      b[i] = j;
    }
  }

  int ans=0;
  for(int i=0; i<n; i++){
    ans = ans + b[i];
  }
   
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

int main()
{
    int n, m;
    std::cin >> n >> m;

    std::cout << n * (n - 1) / 2 + m * (m - 1) / 2 << std::endl;
}


Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))
u = [1]*(n+1)
a = 0
b = False
tmp = 0
tt = 0
for i in range(n+1):
  if u[i] < v[i]:
    b = True
    break
  if i < n:
    u[i+1] = (u[i] - v[i])*2
for i in range(n, -1, -1):
  tt += v[i]
  tmp = min(tt, u[i])
  a += tmp
  tt = tmp
if n == 0:
  a = v[0]
if b:
  a = -1
print(a)

Measured memory_bytes: 674528
#include<iostream>
#include<tuple>
#include<vector>
#include<algorithm>

using namespace std;

int distsq(int y1,int x1,int y2,int x2){
  return (y1-y2)*(y1-y2)+(x1-x2)*(x1-x2);
}

bool includes(int y1,int x1,int r1,int y2,int x2,int r2){
  return r1>=r2&&distsq(y1,x1,y2,x2)<(r1-r2)*(r1-r2);
}

int main(){
  for(int n;cin>>n,n;){
    int xs,ys,xt,yt;
    cin>>xs>>ys>>xt>>yt;
    vector<tuple<int,int,int> > v[4];
    v[1].emplace_back(0,ys,xs);
    v[2].emplace_back(0,yt,xt);
    while(n--){
      int x,y,r;
      cin>>x>>y>>r;
      v[includes(y,x,r,ys,xs,0)+2*includes(y,x,r,yt,xt,0)].emplace_back(r,y,x);
    }
    int dp[4][1234]={};
    for(int vi=0;vi<4;vi++){
      auto &e=v[vi];
      sort(begin(e),end(e));
      for(int i=0;i<e.size();i++){
	for(int j=i+1;j<e.size();j++){
	  if(includes(get<1>(e[j]),get<2>(e[j]),get<0>(e[j]),get<1>(e[i]),get<2>(e[i]),get<0>(e[i]))){
	    dp[vi][j]=max(dp[vi][j],dp[vi][i]+1);
	  }
	}
      }
    }
    int ans=0;
    for(int i=0;i<v[1].size();i++){
      for(int j=0;j<v[2].size();j++){
	if(distsq(get<1>(v[1][i]),get<2>(v[1][i]),get<1>(v[2][j]),get<2>(v[2][j]))>(get<0>(v[1][i])+get<0>(v[2][j]))*(get<0>(v[1][i])+get<0>(v[2][j]))){
	  ans=max(ans,dp[1][i]+dp[2][j]);
	}
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
inline bool chmax (long long& a, long long b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<long long>> x(n, vector<long long>(3));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> x[i][j];
    }
  }
  long long ret = 0;
  for (int bs = 0; bs < 8; bs++) {
    vector<long long> sum(n, 0);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) {
        sum[i] += x[i][j] * (((bs >> j) & 1) ? 1 : -1);
      }
    }
    sort(sum.begin(), sum.end(), greater<long long>());
    long long qet = 0;
    for (int i = 0; i < m; i++) qet += sum[i];
    chmax(ret, qet);
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()


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

//最大公約数
ll gcd(ll a, ll b){
    if(a % b == 0)return b;
    else return gcd(b, a % b);
}

int main(){
    ll x, y;
    cin >> x >> y;
    cout << (x % y == 0 ? -1 : x * (y + 1)) << endl;
}


Measured memory_bytes: 256
package main

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

type Row struct {
	idx  int
	pref int
	year int
	cnt  int
}

type Rows []Row

func (r Rows) Len() int {
	return len(r)
}

func (r Rows) Less(i, j int) bool {
	return r[i].year < r[j].year
}

func (r Rows) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := scanInt(sc)
	m := scanInt(sc)

	rows := make([]Row, m)
	for i := 0; i < m; i++ {
		pref := scanInt(sc)
		year := scanInt(sc)
		rows[i] = Row{
			idx:  i,
			pref: pref,
			year: year,
			cnt:  0,
		}
	}

	// Sort by year.
	sort.Sort(Rows(rows))

	assocs := make([]int, m)
	prefs := make([]int, n+1)
	for i, row := range rows {
		assocs[row.idx] = i
		prefs[row.pref] += 1
		rows[i].cnt = prefs[row.pref]
	}

	out := bufio.NewWriter(os.Stdout)
	for _, i := range assocs {
		fmt.Fprintf(out, "%06d%06d\n", rows[i].pref, rows[i].cnt)
	}
	out.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
#define L long long
using namespace std;
const int q=1000000007;
int n,m,x,y,a[200010],b[200010],p;
inline int C(int n,int m)
{
	return (L)a[n]*b[m]%q*b[n-m]%q;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j;
	scanf("%d%d%d%d",&n,&m,&x,&y);
	a[0]=1;
	for(i=1;i<=2e5;i++)
	  a[i]=(L)a[i-1]*i%q;
	b[0]=b[1]=1;
	for(i=2;i<=2e5;i++)
	  b[i]=q-(L)q/i*b[q%i]%q;
	for(i=2;i<=2e5;i++)
	  b[i]=(L)b[i]*b[i-1]%q;
	p=C(n+m-2,n-1);
	for(x=n-x+1;x<=n && y;x++,y--)
	  p=(p-(L)C(x+y-2,x-1)*C(n+m-x-y,n-x))%q;
	p=(p+q)%q;
	printf("%d\n",p);
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        Scanner sc = null;

        try {
            sc = new Scanner(System.in);
            int countRectangle = 0;
            int countRhombus = 0;

            while (sc.hasNextLine()) {
                String[] input = sc.nextLine().split(",");
                int[] sides = convertToInt(input);

                if (isRectangle(sides)) {
                    countRectangle++;
                } else if (isRhombus(sides)) {
                    countRhombus++;
                }
            }

            System.out.println(countRectangle);
            System.out.println(countRhombus);

        } finally {
            sc.close();
        }
    }

    public static boolean isRectangle(int[] side) {
        return square(side[0]) + square(side[1]) == square(side[2]);
    }

    public static boolean isRhombus(int[] side) {
        return side[0] == side[1];
    }

    public static int square(int n) {
        return n * n;
    }

    public static int[] convertToInt(String[] strings) {
        int[] ints = new int[3];

        for (int i = 0; i < ints.length; i++) {
            ints[i] = Integer.parseInt(strings[i]);
        }
        return ints;
    }

}

Measured memory_bytes: 25908
import std.stdio, std.string, std.conv, std.algorithm;

void main() {
    int n = readln.chomp.to!int;
    int[] r = new int[n];
    foreach (i; 0 .. n) {
        r[i] = readln.chomp.to!int;
    }
    int maxv = int.min;
    int minv = r[0];
    foreach (i; 1 .. n) {
        maxv = max(maxv, r[i] - minv);
        minv = min(minv, r[i]);
    }
    maxv.writeln;
}


Measured memory_bytes: 3936
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

int main(void){
  ll n;
  cin >> n;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }

  vector<ll> hoge((n + 1)/2, 2);

  if (n % 2 == 1)
    hoge[0]--;

  int ok = 1;
  for (int i = 0; i < n; i++){
    if (a[i] % 2 == 0 && n % 2 == 0)
      ok = 0;
    if (a[i] % 2 == 1 && n % 2 == 1)
      ok = 0;

    hoge[a[i]/2]--;
  }

  for (int i = 0; i < n/2; i++){
    if (hoge[i] != 0)
      ok = 0;
  }
  if (ok){
    cout << power(2, n/2) << endl;
  }
  else
    cout << 0 << endl;


  return 0;
}


Measured memory_bytes: 4588
a = gets.chomp
b = {a[0].to_i + a[1].to_i + a[2].to_i + a[3].to_i => "#{a[0]}+#{a[1]}+#{a[2]}+#{a[3]}=7",
     a[0].to_i + a[1].to_i + a[2].to_i - a[3].to_i => "#{a[0]}+#{a[1]}+#{a[2]}-#{a[3]}=7",
     a[0].to_i + a[1].to_i - a[2].to_i + a[3].to_i => "#{a[0]}+#{a[1]}-#{a[2]}+#{a[3]}=7",
     a[0].to_i + a[1].to_i - a[2].to_i - a[3].to_i => "#{a[0]}+#{a[1]}-#{a[2]}-#{a[3]}=7",
     a[0].to_i - a[1].to_i + a[2].to_i + a[3].to_i => "#{a[0]}-#{a[1]}+#{a[2]}+#{a[3]}=7",
     a[0].to_i - a[1].to_i + a[2].to_i - a[3].to_i => "#{a[0]}-#{a[1]}+#{a[2]}-#{a[3]}=7",
     a[0].to_i - a[1].to_i - a[2].to_i + a[3].to_i => "#{a[0]}-#{a[1]}-#{a[2]}+#{a[3]}=7",
     a[0].to_i - a[1].to_i - a[2].to_i - a[3].to_i => "#{a[0]}-#{a[1]}-#{a[2]}-#{a[3]}=7"}
puts b[7]


Measured memory_bytes: 1788
import queue
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]

dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
INF = float("inf")
ss = [[INF] * w for i in range(h)]
def bfs():
    q = queue.Queue()
    ss[0][0] = 1
    q.put([0, 0])
    while not q.empty():
        now = q.get()
        nowx = now[0]
        nowy = now[1]
        for i in range(4):
            nextx = dx[i] + nowx
            nexty = dy[i] + nowy
            if nextx >= 0 and nexty >= 0 and nextx < h and nexty < w:
                if s[nextx][nexty] == "." and ss[nextx][nexty] == INF:
                    ss[nextx][nexty] = ss[nowx][nowy] + 1
                    q.put([nextx, nexty])

bfs()
cnt = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            cnt += 1

if ss[h - 1][w - 1] == INF:
    print("-1")
else:  
    print(cnt - ss[h - 1][w - 1])

Measured memory_bytes: 4080
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define all(a)  a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define _for(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)

using namespace std;

int main(){
   string S = "CODEFESTIVAL2016";
   string s;
   cin >> s;
   int res = 0;
   for(int n = 0; n < S.sz; ++n){
      res += (S[n] != s[n]);
   }
   cout << res << endl;
   return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX], d[MAX];
int color[MAX];

void dik()
{
  for (int i = 0; i < n; i++)
  {
    color[i] = WHITE;
    d[i] = INFTY;
  }

  d[0] = 0;
  color[0] = GRAY;
  int mincost;
  while (1)
  {
    mincost = INFTY;
    int u = -1;
    for (int i = 0; i < n; i++)
    {
      if (color[i] != BLACK && d[i] < mincost)
      {
        mincost = d[i];
        u = i;
      }
    }
    if (u == -1)
      break;

    color[u] = BLACK;

    for (int v = 0; v < n; v++)
    {
      if (color[v] != BLACK && M[u][v] != INFTY)
      {
        if (M[u][v] + d[u] < d[v])
        {
          d[v] = M[u][v] + d[u];
          color[v] = GRAY;
        }
      }
    }
  }
}

int main()
{
  int v, k, s, t;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      M[i][j] = INFTY;
    }
  }

  for (int i = 0; i < n; i++)
  {
    scanf("%d %d", &v, &k);
    for (int j = 0; j < k; j++)
    {
      scanf("%d %d", &s, &t);
      M[v][s] = t;
      //M[s][v] = t;
    }
  }
  dik();

  for (int i = 0; i < n; i++)
  {
    printf("%d %d\n", i, d[i] == INFTY ? -1 : d[i]);
  }

  return 0;
}


Measured memory_bytes: 2700
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
	string s;
	cin >> s;
	cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n,k;cin >> n >> k;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  n--;
  k--;
  Int ans = (n+k-1)/k;
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define re register
#define rep(i,a,b) for(re int i=a,i##end=b; i<=i##end; i++)
#define drep(i,a,b) for(re int i=a,i##end=b; i>=i##end; i--)
#define repp(i,a,b) for(re int i=a,i##end=b; i<i##end; i++)
#define drepp(i,a,b) for(re int i=a,i##end=b; i>i##end; i--)
#define Erep(i,x) for(int i=head[x]; ~i; i=Edge[i].nxt)
#define ll long long
#define debug(x) cerr<<#x<<" = "<<x<<endl
#define lowbit(x) (x&-x)
#define ms(x,a) memset(x,a,sizeof x)
using namespace std;
template <class T> inline bool Max(T &x, T y){
	return x<y?x=y,1:0;
}
template <class T> inline bool Min(T &x, T y){
	return x>y?x=y,1:0;
}
template <class T> inline T rd() {
	static char ch;static bool neg;
	static T x=0;
	for(ch=neg=0;ch<'0' || '9'<ch;neg|=ch=='-',ch=getchar());
	for(x=0;'0'<=ch && ch<='9';(x*=10)+=ch-'0',ch=getchar());
	return x=(neg?-x:x);
}
const int mod=1e9+7,oo=1e9,M=1e5+5;
int A[M];
int main(){
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	int n=rd<int>(),mx=0;
	rep(i,1,n){
		int x=rd<int>();
		if(i==1) continue;
		if(mx-x>1)return puts("No"),0;
		Max(mx,x);
	}
	puts("Yes");
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
  ll n,k;
  cin>>n>>k;
  ll i;
  ll a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  ll sol[n];
  sol[0]=0;
  sol[1]=abs(a[1]-a[0]);
  for(i=2;i<n;i++)
  {
    ll count=1;
    sol[i]=1e18;
    while((i-count)>=0&&count<=k)
    {
      sol[i]=min(sol[i],sol[i-count]+abs(a[i]-a[i-count]));
      count++;
     }
                 
  }
  cout<<sol[n-1];
                
  
                 }


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define forn1 for(i=1; i<=n; i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,e,k,u,t,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    long double b;
    cin>>a>>b;
    ll aaa=floor(a*b);
    cout<<aaa<<endl;
}



Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	long long ans=0;
	if(d<a){
		cout<<d<<endl;
	}else {
		ans+=a;
		d-=a;
		if(d>b){
			d-=b;
			if(d>=c){
				ans-=c;
				cout<<ans<<endl;
			}else {
				ans-=d;
				cout<<ans<<endl;
			}
		}else {
			cout<<ans<<endl;
		}
		
	}
	return 0;
}

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

#define ll     long long
#define fr     first
#define sec    second
#define rep(i,n)  for(i=0;i<n;i++)
#define vi     vector <int>
#define vc     vector <char>
#define vl     vector <ll>
#define vb     vector <bool>
#define pb     push_back
#define M      1000000007
#define ios    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open   freopen("input.txt","r",stdin);
#define close  freopen("output.txt","w",stdout);
#define M_PI   3.14159265358979323846
#define pp     pair<int,int>
#define nn 100003
#define MM 1000000000
#define MN 1000000000000000000
int main()
{
    ios;
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)
        cout<<k;
    else if(k>a && k<=(a+b))
        cout<<a;
    else
    {
        k=k-a-b;
        k=min(k,c);
        cout<<a-k;
    }
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n; cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    vector<int> v(n);
    rep(i,n) v[i] = i+1;
    int a,b;
    int counter =  1;
    do{
        bool a_j = true;
        bool b_j = true;
        rep(i,n){
            if (v[i] != p[i]) {
                a_j = false;
            }
            if (v[i] != q[i]) {
                b_j = false;
            } 
        }
        if (a_j) a = counter;
        if (b_j) b = counter;
        counter++;
    }while(next_permutation(v.begin(),v.end()));
    cout << abs(a-b) << endl;
}


Measured memory_bytes: 256
#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>;
#define chmax(x, y) x = max(x, y)

int a[3005][3005];
ll dp[3005][3005][4];

int main() {
  int R, C, K;
  cin >> R >> C >> K;
  rep(i, K) {
    int r, c, v;
    cin >> r >> c >> v;
    a[r-1][c-1] = v;
  }

  rep(i, R) rep(j, C) {
    for (int k = 2; k >= 0; k--) {
      chmax(dp[i][j][k+1], dp[i][j][k] + a[i][j]);
    }
    rep(k, 4) {
      chmax(dp[i+1][j][0], dp[i][j][k]);
      chmax(dp[i][j+1][k], dp[i][j][k]);
    }
  }

  ll ans = 0;
  rep(k, 4) chmax(ans, dp[R-1][C-1][k]);
  cout << ans << endl;
  return 0;
}

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

int p[300005];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n, a, b;
	cin >> n >> a >> b;

	if (a + b - 1 > n) return cout << -1 << endl, 0;
 
	for (int i = n - b + 1; i <= n; ++i) p[i] = n + n - b + 1 - i;

	--a;
	if (1LL * a * b < n - b) return cout << -1 << endl, 0;

	vector <int> vec;
	int sum = n - b;

	while(a) {
		int take = b;
		if (sum - b < a - 1) take = sum - a + 1;
		vec.push_back(take);
		sum -= take;
		--a;
	}

	int r = n - b;
	while(vec.size()) {
		int sz = vec.back();
		vec.pop_back();
		for (int i = r - sz + 1; i <= r; ++i) p[i] = r + r - sz + 1 - i;
		r -= sz;
	}

	for (int i = 1; i <= n; ++i) cout << p[i] << ' '; cout << endl;
}

Measured memory_bytes: 4212
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}
int dp[100000][3];
int rec(int mat[][3],int n,int p,int r)
{
	if(r>=n)
		return 0;
	
	int mx=0;
	for(int i=0;i<3;i++)
	{
		if(dp[r][i]==-1)
			dp[r][i]=rec(mat,n,i,r+1)+mat[r][i];
		if(i!=p)
			mx=max(mx,dp[r][i]);
	}
	return mx;
	
}
int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	ll T=1;
//	cin>>T;
	while(T--)
	{
		int x,y;
		cin>>x>>y;
		if(4*x<y)
			cout<<"No\n";
		else{
			int flag=0;
			for(int i=0;i<=x;i++)
			{
				if(2*i+4*(x-i)==y)
				{
					flag=1;
					break;
				}
			}
			if(flag==1)
				cout<<"Yes\n";
			else cout<<"No\n";
		}
		
		
		
	
	}
	return 0;
}





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

int n, p[200004];

int main() {
	cin>>n;
	for(int i = 0; i < n; i++)	cin>>p[i];
	int curMin = 987654321, cnt = 0;
	for(int i = 0; i < n; i++){
		if(curMin > p[i])	cnt++;
		curMin = min(curMin, p[i]);
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
int n,m;
bool p1[400100],p2[400100];
int main()
{
	scanf("%d%d",&n,&m);
	int s,t;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&s,&t);
		if(t==n)
		{
			p1[s]=1;
		}
		if(s==n)
		{
			p1[t]=1;
		}
		if(s==1)
		{
			p2[t]=1;
		}
		if(t==1)
		{
			p2[s]=1;
		}
	}
	for(int i=1;i<=n;i++)
		if(p1[i]&&p2[i])
		{
			printf("POSSIBLE\n");
			return 0;
		}
	printf("IMPOSSIBLE\n");
	return 0;
}

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

int a[505][505],q[505][505];
int h[505],sum[505];
int n,m,k;

int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<m;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		a[x][y]++;
	}
	for(int i=1;i<=n;i++){
		int sum=0;
		for(int j=1;j<=n;j++){
			h[j]+=a[j][i];
			sum+=h[j];
			q[j][i]=sum;
		}
	}
	for(int i=0;i<k;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		int ans=q[y][y]+q[x-1][x-1]-q[x-1][y]-q[y][x-1];
		printf("%d\n",ans);
	}	
	return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 2000000000
#define MOD 998244353
#define N 1000005
#define M 1442255
#define LOG 1000000
#define KOK 31623
#define EPS 0.000000001
using namespace std;

int main() {

	//freopen("input.txt","r",stdin);

	int a,b,c;

	scanf("%d %d %d",&a,&b,&c);

	printf("%lld",b+min(b+a+1,c));

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int s,i;
	cin >> s;
	set<int> v;
	v.insert(s);
	int tmp = s;
	int size_v = 1;
	for (i = 2;i < 10000000;i++){
		if (tmp % 2 == 0){
			v.insert(tmp / 2);
			tmp = tmp / 2;
		}
		else{
			v.insert(tmp * 3 + 1);
			tmp = tmp * 3 + 1; 
		}
		if (v.size() == size_v){
				break;
			}
		size_v++;
	}

	cout << i << endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define int long long
using namespace std;

int a, b, c, d;
int e[200005];
int f[200005];//??????
int K(int x, int y) {//a??????b????????£???
	if (x > 0) {
		if (y > 0) {
			return -(y - x)*c;
		}
		else {
			return x*c + (-y)*d;
		}
	}
	else {
		if (y > 0) {
			return (x)*d+(-y)*c;
		}
		else {
			return (x-y)*d;
		}
	}
}
signed main() {
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	for (int f = 0; f <= a; f++) {
		scanf("%lld", &e[f]);
	}
	int S = 0;
	for (int g = 0; g < a; g++) {
		f[g] = e[g + 1] - e[g];
		if (f[g] < 0) {
			S -= f[g] * d;
		}
		else {
			S -= f[g] * c;
		}
	}
	for (int i = 0; i < b; i++) {
		int x, y, z; scanf("%lld%lld%lld", &x, &y, &z); x--;
		S += K(f[x], f[x] + z);
		f[x] += z;
		if (y != a) {
			S += K(f[y], f[y] - z);
			f[y] -= z;
		}
		printf("%lld\n", S);
	}
}

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

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

  ll h;
  cin >> h;
  int count = 0;
  while (h > 0) {
    h /= 2;
    count++;
  }

  ll ans = 0;
  rep(i, 0, count) ans += pow(2, i);

  cout << ans << endl;
}


Measured memory_bytes: 384