akhauriyash/Code-Regression huggingface dataset:
// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

ll dp[200005][4];

vector < ll > vec;

const ll mn = -1e18;

ll solve(ll pos, ll skip)
{
	ll &ret = dp[pos][skip];

	if(ret != mn) return ret;

	if(pos >= vec.size())
	{
		if(vec.size() & 1)
			if(skip == 2) return ret = mn + 2;

		return ret = 0;
	}

	ret = solve(pos + 2, skip) + vec[pos];

	if(skip) ret = max(ret, solve(pos + 1, skip - 1));

	return ret;
}
int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

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

//    freopen("output.txt", "w", stdout);

    while(cin >> n)
    {
		vec.clear();
		vec.resize(n);

		for(ll i = 0; i < n; i++) cin >> vec[i];

		for(ll i = 0; i <= n + 3; i++) for(ll j = 0; j < 4; j++) dp[i][j] = mn;

		ans = solve(0,(n % 2) + 1);

		cout << ans << "\n";

    }


}





Measured memory_bytes: 15664
#include <bits/stdc++.h>
using namespace std;
#define _K ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld long double
#define ll long long
#define ull unsigned ll
#define pb push_back
#define mod 1e9+7
#define eps 1e-7
#define pi acos(-1)
#define F first
#define S second
#define X real()
#define Y imag()
#define cross(a,b) (conj(a)*(b)).X
#define dot(a,b) (conj(a)*(b)).Y
typedef complex <ld> point ;
typedef vector <point> polygon ;
typedef tuple <int , int , int> line ;
//====================================
int main()
{
	_K
	ll n ;
	cin >> n ;
	ll h[n] , ans[n] ;
	for (int i =0 ; i < n ;  cin >> h[i++]);
	ans[0] = 0 ;
	ans[1] = abs(h[1]-h[0]) ;
	for (int i = 2 ; i < n ; i++)
		ans[i] = min(ans[i-1] + abs(h[i]-h[i-1]) , ans[i-2] + abs(h[i]-h[i-2])) ;
	cout << ans[n-1] ;
	return 0;
}

Measured memory_bytes: 1792
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG =  True
def ddprint(x):
  if DBG:
    print(x)

s = input()
mx = 0
cnt = 0
for i in range(len(s)):
    if s[i] in ['A', 'C', 'G', 'T']:
        cnt += 1
        if cnt > mx:
            mx = cnt
    else:
        cnt = 0

print(mx)


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

bool C(int N, string S, int k){
	int cnt = 0, cnt2 = 0, cnt3 = 0;
	for(int i = N - 1; i >= 0; i--){
		if(S[i] == 'I' && cnt < k) cnt++;
		else if(S[i] == 'O' && cnt2 < cnt) cnt2++;
		else if((S[i] == 'J' || S[i] == 'I') && cnt3 < cnt2) cnt3++;
	}
	if(cnt3 == k) return true;
	return false;
}

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;
	int lb = 0, ub = N / 3 + 1;
	while(ub - lb > 1){
		int mid = lb + (ub - lb) / 2;
		if(C(N, S, mid)) lb = mid;
		else ub = mid;
	}
	cout << lb << endl;
	return 0;
}


Measured memory_bytes: 4988
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

int dp[201][100001];

ll f(int n, int *s, int x) {
    if (n == 1) {
        return x % s[0];
    }
    if (dp[n][x] != -1) return dp[n][x];
    ll r = 0;
    r += f(n - 1, s + 1, x % s[0]);
    r += f(n - 1, s + 1, x) * (n - 1);
    return dp[n][x] = r % P;
}

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

    int n, x;
    cin >> n >> x;

    memset(dp, -1, sizeof(dp));

    vector<int> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    reverse(s.begin(), s.end());

    cout << f(n, &s[0], x) << endl;

    return 0;
}

Measured memory_bytes: 78848
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
typedef long long ll;
typedef pair<int, int> P;

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

    string ans = "";
    if (n == 0) {
        cout << 0 << endl;
        return 0;
    }

    int cnt = 0;
    while (n != 0) {
        if (n%2 == 0) {
            ans += '0';
            n /= -2;
        }
        else {
            ans += '1';
            n = (n-1)/(-2);
        }
        cnt++;
    }

    per(i, cnt) {
        cout << ans[i];
    }
    cout << endl;

}

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

using namespace std;

int main() {
  int a, b, c, k, ans, sum;
  scanf("%d %d %d", &a, &b, &c);
  sum = a + b + c;
  ans = max(a, max(b, c));
  sum -= ans;
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    ans *= 2;
  }
  printf("%d\n", sum + ans);
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

temp = {}
for i in range(N):
    if A[i] in temp:
        temp[A[i]].append(i)
    else:
        temp[A[i]] = [i]

jump_table = [0] * N
for val in temp.values():
    for i in range(len(val)):
        if i == len(val)-1:
            jump_table[val[i]] = val[0]+N-val[i]+1
        else:
            jump_table[val[i]] = val[i+1]-val[i]+1

a = 0
f = 0
while True:
    a += jump_table[a % N]
    if a % N == 0:
        f = a//N
        break

K %= f
a = 0
stack = []
while a < N*K:
    if a + jump_table[a % N] <= N*K:
        a += jump_table[a % N]
    else:
        stack.append(A[a % N])
        a += 1


print(*stack)


Measured memory_bytes: 121676
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = 0, h = 0;
        int num = Integer.parseInt(br.readLine());

        for (int i = 0; i < num; i++) {
            String n = br.readLine();
            String taro = n.substring(0, n.indexOf(' '));
            String hanako = n.substring(n.indexOf(' ') + 1);

            if ((taro.compareTo (hanako)) == 0) {
                t++;
                h++;
            } else if((taro.compareTo(hanako) > 0)) {
                t += 3;
            } else if((taro.compareTo(hanako) < 0)) {
                h += 3;
            }
        }
        System.out.println(t + " " + h);
    }
}

Measured memory_bytes: 24396
n = int(input())
w = []
noFlag = 0
for i in range(n):
    tmp = input()
    if tmp in w:
        noFlag = 1
    if not w == []:
        if not tmp[0] == w[-1][-1]:
            noFlag = 1
    w.append(tmp)

if noFlag == 0:
    print('Yes')
else:
    print('No')


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

struct C {
  int id;
  int w;
  int s;
  static bool compare(const C &l, const C &r) {
    if (l.w > r.w) {
      return true;
    } else if (l.w < r.w) {
      return false;
    } else {
      return (l.s > r.s);
    }
  }
};

int main() {
  C c[10];
  char f[10][21];
  int n, tw, a[10];
  bool u[10];
  while (1) {
    scanf("%d", &n);
    if (!n) break;
    for (int i=0; i<n; i++) {
      c[i].id = i;
      scanf("%s %d %d", f[i], &c[i].w, &c[i].s);
    }
    sort(c, c+n, C::compare);
    tw = 0;
    for (int i=0; i<n; i++) {
      tw += c[i].w;
    }
    for (int i=0; i<n; i++) {
      u[i] = false;
    }
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
        if (!u[j] && tw - c[j].w <= c[j].s) {
          tw -= c[j].w;
          a[i] = c[j].id;
          u[j] = true;
          break;
        }
      }
    }
    for (int i=0; i<n; i++) {
      printf("%s\n", f[a[i]]);
    }
  }
  return 0;
}

Measured memory_bytes: 1028
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
int n,k,x,maxt,ans=1; bool ok=0;

int aa;char cc;
int read() {
	aa=0;cc=getchar();
	while(cc<'0'||cc>'9') cc=getchar();
	while(cc>='0'&&cc<='9') aa=aa*10+cc-'0',cc=getchar();
	return aa;
}

int gcd(int a,int b){
	return b==0? a:gcd(b,a%b);
}

int main() {
	n=read();k=read();
	for(int i=1;i<=n;++i) {
		x=read();if(x==k) ok=1;
		if(i==1) ans=x;
		else ans=gcd(x,ans);
		maxt=max(maxt,x);
	}
	if(ok) printf("POSSIBLE");
	else if(maxt<k||k%ans!=0) printf("IMPOSSIBLE");
	else printf("POSSIBLE");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
int main() {
  int buff;
  int cnt = 0;
  std::cin >> buff;
  for(int i=0; i<3; i++){
    if(buff%2==1) cnt+=1;
    buff /= 2;
  }
  std::cout << cnt << std::endl;
  return 0;
}

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

long gcd(long a, long b){
  long x = a * b;
  
  long tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  long r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
    
    return x/b;
}


int main(){
  long A, B, C, D;
  if(scanf("%ld %ld %ld %ld", &A, &B, &C, &D) == 1);
  
  long Ay = 0;
  if(D % C == 0)
    Ay = (A-1)/C;
  else
    Ay = ((A-1)/C) + ((A-1)/D) - ((A-1)/gcd(C,D));
  
  long By = 0;
  if(D % C == 0)
    By = B/C;
  else
    By = (B/C) + (B/D) - (B/gcd(C,D));
  
  long ABy = By - Ay;
  
  printf("%ld", B - A + 1 - ABy);
  return 0;
}

Measured memory_bytes: 128
N, A, B = [int(x) for x in input().split()]

def sumEachOrder(n):
    s = 0
    while n > 0:
        a = n % 10
        s += a
        n //= 10
    return s

ans=0
for n in range(1, N+1):
    s = sumEachOrder(n)
    if s >= A and s <= B:
        ans += n
print(ans)


Measured memory_bytes: 3060
def main(str)
  kn, as = str.split("\n")
  k, _n = kn.split(" ").map(&:to_i)
  as = as.split(" ").map(&:to_i)
  as << as[0] + k
  max_diff = (0...(as.length - 1)).map { |i| as[i + 1] - as[i] }.max
  k - max_diff
end

puts main($stdin.read.chomp)

Measured memory_bytes: 19904
#include <iostream>

using namespace std;

/*

階級	体重（kg）
light fly	48.00kg 以下
fly	48.00kg 超51.00kg 以下
bantam	51.00kg 超54.00kg 以下
feather	54.00kg 超57.00kg 以下
light	57.00kg 超60.00kg 以下
light welter	60.00kg 超64.00kg 以下
welter	64.00kg 超69.00 kg 以下
light middle	69.00kg 超75.00 kg 以下
middle	75.00kg 超81.00 kg 以下
light heavy	81.00kg 超91.00 kg 以下
heavy	91.00kg 超
*/

int main(){

	int cData[10] = {48,51,54,57,60,64,69,75,81,91};
	string str[11] = {"light fly","fly","bantam","feather","light",
							"light welter","welter","light middle",
							"middle","light heavy","heavy"};

	double num;
	while(cin>>num){
		int state=0;
		for(int i=0;i<10;i++){
			if(cData[i]>=num){
				cout<<str[i]<<endl;
				state=1;
				break;
			}			
		}
		if(state==0){
			cout<<str[10]<<endl;
		}
	}

	return 0;

}

Measured memory_bytes: 1228
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define NO return puts("No"),0
#define YES return puts("Yes"),0

const int N=1e5+5;
int n,m,cnt,tmp[2],vis[N];
vector <int> G[N];

template <typename _Tp> inline void IN(_Tp&x) {
	char ch;bool flag=0;x=0;
	while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	if(flag) x=-x;
}

inline void addedge(int u=0,int v=0) {
	IN(u),IN(v),G[u].push_back(v),G[v].push_back(u);
}
void dfs(int u) {
	vis[u]=true;
	for(auto v:G[u])
		if(vis[v]==2) tmp[cnt++]=v;
		else if(!vis[v]) dfs(v);
}

int main() {
	IN(n),IN(m);
	for(int i=1;i<=m;++i) addedge();
	int max_du=0,max_tot=0;
	for(int i=1;i<=n;++i)
		if(G[i].size()&1) NO;
		else if(G[i].size()==max_du) ++max_tot;
		else if(G[i].size()>max_du) max_du=G[i].size(),max_tot=1;
	if(max_du>=6||(max_du==4&&max_tot>=3)) YES;
	else if(max_du==2||max_tot==1) NO;
	else if(max_du==4&&max_tot==2) {
		for(int i=1;i<=n;++i) if(G[i].size()==4) vis[i]=2;
		for(int i=1;i<=n;++i) if(!vis[i]) {cnt=0,dfs(i);if(tmp[0]==tmp[1]) YES;}
	}NO;
}

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

//template
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define repr(i,n) for(ll i=n;i>0;i--)
#define all(v) v.begin(),v.end()
#define in cin>>
#define out cout<<
#define en <<endl
const ll INF = 10000000000000;

int main()
{
	int N;
	in N;
	vector<char> S(N);
	vector<char> T(N);
	rep(i, N)
	{
		in S.at(i);
	}
	rep(i, N)
	{
		in T.at(i);
	}
	rep(i, N)
	{
		out S.at(i) << T.at(i);
	}
	cout en;
}


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

typedef long long int int64;

const int mod=1000000007;

void run(void){
  int n;
  scanf("%d",&n);
  int *dp=(int *)calloc(n+1,sizeof(int));
  dp[0]=1;
  dp[1]=n;
  int sum=n-1;
  int i;
  for(i=2;i<=n;i++){
    int local=(dp[i-1]+(int64)(n-1)*(n-1)+sum)%mod;
    dp[i]=local;
    sum=((int64)sum-1+dp[i-2])%mod;
  }
  printf("%d\n",dp[n]);
}

int main(void){
  run();
  return 0;
}


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

using namespace std;

#define ll long long
#define rep(i,n) for(int i=1;i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)

const ll INF=1e9+7;
int n,a[101],g,h;
bool f[9];
int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n;
	rep(i,n){
		cin>>a[i];
		if(a[i]<400){
			f[1]=1;
		}
		else if(a[i]<800){
			f[2]=1;
		}
		else if(a[i]<1200){
			f[3]=1;
		}
		else if(a[i]<1600){
			f[4]=1;
		}
		else if(a[i]<2000){
			f[5]=1;
		}
		else if(a[i]<2400){
			f[6]=1;
		}
		else if(a[i]<2800){
			f[7]=1;
		}
		else if(a[i]<3200){
			f[8]=1;
		}
		else{
			g++;
		}
	}
	rep(i,8){
		if(f[i]){
			h++;
		}
	}
	cout<<max(h,1)<<' '<<g+h;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    cout<<(char)toupper(s1[0])<<(char)toupper(s2[0])<<
    (char)toupper(s3[0])<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
	int N;	cin >> N;
	vector<int> T(N);
	for (int i = 0; i < N; ++i) {
		cin >> T[i];
	}

	int M;	cin >> M;
	vector<int> P(M), X(M);
	for (int i = 0; i < M; ++i) {
		cin >> P[i] >> X[i];
	}

	vector<int> time(M);

	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < N; ++j) {
			if (j == P[i] - 1) {
				time[i] += X[i];
			}
			else {
				time[i] += T[j];
			}
		}
	}
	
	for (auto e : time) {
		cout << e << endl;
	}
	cin >> N;
}

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

int main() {
  
  string S ;
  int cost = 700 ;
  
  cin >> S;
  
  if(S.at(0) == 'o'){
    cost += 100 ;
  }
  
  if(S.at(1) == 'o'){
    cost += 100 ;
  }
  
  if(S.at(2) == 'o'){
    cost += 100 ;
  }
  
  cout << cost << endl;
  
 
}

Measured memory_bytes: 256
import sys
A, B, C = map(int, input().split())

lis = sorted([A, B, C])

ans = 0
while lis[1] != lis[2] and lis[1]+1 != lis[2]:
  lis[1] += 2
  ans += 1

while lis[0] != lis[2] and lis[0]+1 != lis[2]:
  lis[0] += 2
  ans += 1

if lis[2] == lis[1] and lis[1] == lis[0]:
  print(ans)
elif lis[2] != lis[0] and lis[2] != lis[1]:
  print(ans+1)
else:
  print(ans+2)
  

Measured memory_bytes: 3064
n, m =map(int,input().split())
s = list(map(int,input().split()))
t = [0]*n #展望台が良いと0
for __ in range(m):
  a, b =map(int,input().split())
  if s[a-1] >= s[b-1]:
    t[b-1] += 1
  if s[a-1] <= s[b-1]:
    t[a-1] += 1
print(t.count(0))
  

Measured memory_bytes: 20016
# lとrの差が2019以上ならば間に必ず2019の倍数が存在するので0になる
# lとrの差が2019より小さければ、余りのリストを作成しi、jの組み合わせをすべて計算してminを求める
# 2019C2なので10**8を上回ることはない
import itertools

l, r = map(int, input().split())
l_rest = l % 2019
r_rest = r % 2019

if l_rest == 0 or r_rest == 0:
    print(0)
elif r-l < 2019:
    lr_list = list(range(l_rest, r_rest+1))
    lr_comb = list(itertools.combinations(lr_list, 2))
    min_rest = 2018
    for comb in lr_comb:
        rest = comb[0] * comb[1]
        min_rest = min(min_rest, rest%2019)
    print(min_rest)
elif r-l >= 2019:
    print(0)
        

Measured memory_bytes: 148280
#include"cstdio"
#include "iostream"
#include"algorithm"
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
ll F[110][110];
ll P[110][110];
ll D[110];
int main()
{
	ll n;
	while (cin >> n)
	{
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= 10; j++)
				scanf("%lld", &F[i][j]);
		for (int i = 1; i <= n; i++)
			for (int j = 0; j <= 10; j++)
				scanf("%lld", &P[i][j]);
		ll Max = -1 * INF;
		for (int s = 1; s < (1 << 10); s++)
		{
			for (int i = 1; i <= n; i++)
			{
				D[i] = 0;
				for (int j = 1; j <= 10; j++)
				{
					if ((F[i][j] << (j - 1)) & s)
						D[i]++;
				}

			}

			ll ans = 0;

			for (int i = 1; i <= n; i++)

				ans += P[i][D[i]];

			Max = max(Max, ans);

		}

		cout << Max << endl;

	}

}


Measured memory_bytes: 384
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
#include <string>
using namespace std;

int main(){
	string o, e;
	cin >> o >> e;

	for (int i=0;i<e.length(); ++i){
		cout << o[i] << e[i];
	}

	if (o.length() != e.length()){
		cout << o[o.length()-1];
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
int main()
{
   char s[1002];
   scanf("%s",s);
   if(s[strlen(s)-1]=='s')
   strcat(s,"es");
   else
      strcat(s, "s");


   //printf("%d",strlen(s));
   printf("%s",s);

}

Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

typedef pair<ll,ll> pii;
#define fi first
#define se second
#define mp make_pair

pii seph(int h, int w, int d){
  pii p = mp((ll)w*d, (ll)w*(h-d));
  return p;
}

pii sepw(int h, int w, int d){
  pii p = mp((ll)h*d, (ll)h*(w-d));
  return p;
}

ll dist(ll x, ll y, ll z){
  return max(x, max(y, z)) - min(x, min(y, z));
}

ll rec(int h, int w){
  pii p;
  ll s1, s2, s3;

  ll mi = INF;
  REP(i, 1, h-1){
    p = seph(h, w, i);
    s3 = p.se;

    s1 = (ll)w * (i/2);
    s2 = p.fi - s1;
    chmin(mi, dist(s1, s2, s3));

    s1 = (ll)i * (w/2);
    s2 = p.fi - s1;
    chmin(mi, dist(s1, s2, s3));
  }

  return mi;
}

int main(){
  int H, W;
  cin >> H >> W;
  
  cout << min(rec(H, W), rec(W, H)) << endl;

  return 0;
}


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

typedef pair<int, int> pr_i;
bool cmp(pr_i l, pr_i r) { return l.second < r.second; };

int main() {  
  int n, m; scanf("%d %d", &n, &m);
  
  pr_i ab[m];
  for (int i = 0; i < m; i++) {
    int a, b; scanf("%d %d", &a, &b);
    ab[i].first = a;
    ab[i].second = b;
  }
  sort(ab, ab + m, cmp);
  
  int ans = 0;
  int line = 0;
  for (pr_i pr : ab) {
    if (pr.first <= line) continue;
    line = pr.second - 1;
    ans++;
  }
    
  printf("%d\n", ans);
}

Measured memory_bytes: 896
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors
a = int(input())
b = make_divisors(a)
c = len(b)/2
d = len(b)-1
if c.is_integer()==False:
  print(b[d]*2-2)
else:
  print(b[d]+b[d-1]-2)

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
vector<int> dy = {1, 0, -1, 0};
vector<int> dx = {0, 1, 0, -1};
int main(){
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++){
    cin >> S[i];
  }
  vector<vector<bool>> used(H, vector<bool>(W, false));
  long long ans = 0;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (!used[i][j]){
        used[i][j] = true;
        long long b = 0;
        long long w = 0;
        queue<pair<int, int>> Q;
        Q.push(make_pair(i, j));
        while (!Q.empty()){
          int y = Q.front().first;
          int x = Q.front().second;
          Q.pop();
          if (S[y][x] == '#'){
            b++;
          } else {
            w++;
          }
          for (int k = 0; k < 4; k++){
            int y2 = y + dy[k];
            int x2 = x + dx[k];
            if (0 <= y2 && y2 < H && 0 <= x2 && x2 < W){
              if (S[y2][x2] != S[y][x]){
                if (!used[y2][x2]){
                  used[y2][x2] = true;
                  Q.push(make_pair(y2, x2));
                }
              }
            }
          }
        }
        ans += b * w;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3880
#import <stdio.h>
#import <stdlib.h>
int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}
int main(){
    int A[3];
    scanf("%d",A);
    scanf("%d",A+1);
    scanf("%d",A+2);
    qsort(A, 3, sizeof(int), compare_int);
    printf("%d",A[0]+A[1]);
}


Measured memory_bytes: 5976
// Copyright lzt
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
#include<ctime>
using namespace std;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef std::pair<long long, long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, j, k)  for (register int i = (int)(j); i <= (int)(k); i++)
#define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--)
#define Debug(...) fprintf(stderr, __VA_ARGS__)

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

const int maxn = 3030;
int n;
int a[maxn];
ll f[maxn][maxn];

void work() {
  n = read();
  rep(i, 1, n) a[i] = read();
  rep(l, 1, n) {
    rep(i, 1, n) {
      int j = i + l - 1;
      if (j > n) break;
      f[i][j] = max(a[j] - f[i][j - 1], a[i] - f[i + 1][j]);
    }
  }
  printf("%lld\n", f[1][n]);
}

int main() {
  #ifdef LZT
    freopen("in", "r", stdin);
  #endif

  work();

  #ifdef LZT
    Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
  #endif
}


Measured memory_bytes: 71936
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


class Program
{
    static int m = 0;
    static void Main(string[] args)
    {
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
        /*//僕のやり方  
           if (a[0] == a[1]&&a[1]==a[2]&&a[2]==a[0]) { Console.WriteLine(a[0]%2==0?"-1":"0"); }
             else
             {
                 long i = 0;
                 for (i = 0; i>-1; i++)
                 {
                     if (a[0] % 2 == 1 || a[1] % 2 == 1 || a[2] % 2 == 1) { break; }
                     long karia = a[0];
                     long karib = a[1];
                     long karic = a[2];
                     a[0] = (karib + karic) / 2;
                     a[1] = (karia + karic) / 2;
                     a[2] = (karia + karib) / 2;
                 }
                 Console.WriteLine(i.ToString());
             }
             Console.ReadLine();
         */
        long ans = func(a[1],a[0],a[2]);
        Console.WriteLine(ans);
    }
    static long func(long a, long b, long c)
    {
        if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1)
        {
            return 0;
        }
        if (a == b && a == c) { return -1; }
       
        return func((b + c) / 2, (c + a) / 2, (a + b) / 2)+1;
    }
}

Measured memory_bytes: 13396
N = int(input())
x = [0]*N
u = [0]*N
for i in range(N):
    x[i], u[i] = input().split()
y = list(map(float, x))

ans = 0
for i in range(N):
    if u[i] == 'JPY':
        ans += y[i]
    else:
        ans += y[i]*380000
print(ans)

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

int main(void){

  int a,b,c,d,x,y,z;
  cin >> a >> b >> c >> d;
  if( a<c){
    x=c;
  }else{
    x=a;
  }
    if( b<d){
    y=b;
  }else{
    y=d;
  }
  z=y-x;
  if(z<0){
    cout << "0";
  }else{
    cout << z;
  }
  return(0);
}
  

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    string s;cin>>s;
    if(s[1]=='R')puts("ABC");
    else puts("ARC");
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}

// end of Template

ll a,b,ans;
int main(){

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>a>>b;
    ans = a+b;
    ans = max(ans,a-b);
    ans = max(ans,a*b);
    cout<<ans<<newl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int dp[3001]; // dp[i] = j; := i[g]の砂糖水に溶ける最大の砂糖の量

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    for (int i = 0; i <= F; i++) {
        dp[i] = -1;
    }
    dp[0] = 0;

    // satoumizu: i
    // satou: dp[i]
    // mizu = i - dp[i]
    // E
    // mizu : maxsatou = i - dp[i] : E
    // 100 * dp[i] / (i - dp[i]) <= E
    // 100 * dp[i] <= E * (i - dp[i])
    for(int i = 0; i <= F; i++) {
        if (dp[i] == -1) continue;
        if (i + A * 100 <= F) dp[i + A * 100] = max(dp[i + A * 100], dp[i]);
        if (i + B * 100 <= F) dp[i + B * 100] = max(dp[i + B * 100], dp[i]);
        if (i + C <= F && (100 * (dp[i] + C) <= E * (i - dp[i]))) dp[i + C] = max(dp[i + C], dp[i] + C);
        if (i + D <= F && (100 * (dp[i] + D) <= E * (i - dp[i]))) dp[i + D] = max(dp[i + D], dp[i] + D);
    }
/*
    for (int i = 0; i <= F; i++) {
        cout << dp[i] << " ";
    }
    cout << endl;
*/
    double m = -1;
    int ans1, ans2;
    for (int i = 0; i <= F; i++) {
        if (dp[i] == -1) continue;
        if (100 * dp[i] <= E * i) {
            if (m < (double)dp[i] / i) {
                m = (double)dp[i] / i;
                ans1 = i;
                ans2 = dp[i];
            }
        }
    }
    cout << ans1 << " " << ans2 << endl;

    return 0;
}

Measured memory_bytes: 888
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int x;
    cin>>x;
    vi dp(x+1,0);
    dp[100] = dp[101] = dp[102] = dp[103] = dp[104] = dp[105] = 1;

    for(int i=200;i<=x;i++){
        if(dp[i-100]!=0 || dp[i-101]!=0 || dp[i-102]!=0 ||dp[i-103]!=0 || dp[i-104]!=0 ||dp[i-105]!=0)  dp[i] = 1;
    }
    cout<<dp[x]<<endl;
   /* 
    if(x>=2000){
        cout<<1<<endl;
        return 0;
    }
    int i=100,j=5;
    vi allowed;
    for(int k=i;k<=i+j;){
        allowed.pb(k);
        if(k==i+j){
            i += 100;
            j += 5;
            k = i;
        }
        else    k++;
        if(k==2000) break;
    }
    //for(int i=0;i<allowed.size();i++)
    //    cout<<allowed[i]<<" ";
    //cout<<endl;
    if(binary_search(all(allowed), x))  cout<<1<<endl;
    else                                cout<<0<<endl;
    */
    return 0;
}



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

int main(){



  int a=0;
  cin>>a;

  vector<int> x(a);
  for(int i=0;i<a;i++)
    {cin>>x[i];}
  int num=1;
  int as=0;
  for(int i=0;i<a;i++){
    if(num==x[i]) ++num;
    else ++as;
  }
  if(a==as) as=-1;
  cout<<as<<endl;
}



Measured memory_bytes: 1152
N = int(input())
numbers = list(map(int, input().split(' ')))

count = 0
counter = 0
for num in range(N):
    for num1 in range(num):
      if numbers[num] >= numbers[num1]:
        counter += 1
      else:
        continue
    if counter == num:
      count += 1
    counter = 0

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

char s[412345];
char u[3];

int main(){
	char *t[2] = {s + 201234, NULL};
	int r = 0;
	int q; scanf("%s%d", t[0], &q);
	t[1] = *t + strlen(*t);
	REP(i, q){
		int a; scanf("%d", &a);
		if(a == 1){
			r = 1 - r;
		} else {
			int f; scanf("%d%s", &f, u);
			int z = r ^ (f - 1);
			if(z == 0){
				*(--t[0]) = u[0];
			} else {
				*(t[1]++) = u[0];
				*t[1] = '\0';
			}
		}
	}
	if(r) reverse(t[0], t[1]);
	printf("%s\n", t[0]);
}



Measured memory_bytes: 896
xs = [11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381, 1451]
print(*xs[:int(input())])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
void solve(){
    ll n,W;
    cin>>n>>W;
    vector<ll>wt(n+1),val(n+1);
    ll dp[n+1][W+1];
    for(ll i=1;i<=n;i++){
        cin>>wt[i]>>val[i];
    }
    for(ll i=0;i<=n;i++){
        for(ll w=0;w<=W;w++){
            if(i==0||w==0)
            dp[i][w]=0;
            else if(wt[i]<=w)
            dp[i][w]=max(dp[i-1][w],dp[i-1][w-wt[i]]+val[i]);
            else
            dp[i][w]=dp[i-1][w];
        }
    }
    cout<<dp[n][W];
}
int main(){
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 79104
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  int ab[26]={};
  int i;
  while(getline(cin,str)){
    for(i=0;i<str.size();i++){
      if(str[i]>='a'&&str[i]<='z') ab[str[i]-'a']++;
      else if(str[i]>='A'&&str[i]<='Z') ab[str[i]-'A']++;
    }
  //cout << str << endl;
  }
  for(i=0;i<26;i++){
    cout << (char)('a'+i) << " : " << ab[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3172
import numpy as np

n, m, x = list(map(lambda x: int(x), input().split(' ')))


sets = []

for i in range(n):
  sets.append(list(map(lambda x: int(x), input().split(' '))))  
sets = np.array(sets)


mincost = 10000000
maxnum = int(''.join(["1" for i in range(n)]), 2)

if not np.all((np.sum(sets[:, 1:], axis=0) >= x)):
  print(-1)
else:
  for i in range(0, maxnum+1):
    status = np.array(list(format(i, '0{}b'.format(n)))) == '1'
    used_data = sets[status]
    cost = np.sum(used_data[:, 0])
	
    if cost > mincost:
      continue
    if np.all((np.sum(used_data[:, 1:], axis=0) >= x)):
      if cost < mincost:
        mincost = cost
        next
    
  print(mincost)

  
  

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

int main(){
    stack<int> S;
    int a, b, x;
    string s;

    while (cin >> s){
        if(s.at(0) == '+'){
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(a + b);
        }
        else if(s.at(0) == '-'){
            b = S.top(); S.pop();
            a = S.top(); S.pop();
            S.push(a - b);
        }
        else if(s.at(0) == '*'){
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(a * b);
        }
        else{
            S.push(stoi(s));
        }
    }

    cout << S.top() << endl;

    return 0;
}



Measured memory_bytes: 3188
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>

using namespace std;

clock_t timeStart, timeFinish;

void timeBegin() {
    timeStart = clock();
}

void timeEnd() {
    timeFinish = clock();
}

void timeDuration() {
    double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);
    cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
    cout << " sec " << endl;
}

class InputReader {
public:
    InputReader() {
        input_file = stdin;
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    InputReader(const char *file_name) {
        input_file = fopen(file_name, "r");
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    inline InputReader &operator >>(int &n) {
        while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }
private:
    FILE *input_file;
    static const int SIZE = 1 << 17;
    int cursor;
    char buffer[SIZE];
    inline void advance() {
        ++ cursor;
        if(cursor == SIZE) {
            cursor = 0;
            fread(buffer, SIZE, 1, input_file);
        }
    }
};

const int MAXN = 200000;
const int MAXLOG = 50;

int have[1 + 2 * MAXLOG][1 + 2 * MAXLOG];

int main() {
    timeBegin();
    //ifstream cin("input.txt");
    //ofstream cout("papagali.out");
    int n;
    cin >> n;
    long long answer = 0;
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        long long a = 0;
        int z = 0;
        bool decimal = false;
        for (auto ch : s) {
            if (ch == '.') {
                decimal = true;
            } else {
                a = a * 10 + ch - '0';
                if (decimal) {
                    z++;
                }
            }
        }
        int p2 = -z, p5 = -z;
        while (a % 2 == 0) {
            p2++;
            a /= 2;
        }
        while (a % 5 == 0) {
            p5++;
            a /= 5;
        }
        answer += have[-p2 + MAXLOG][-p5 + MAXLOG];
        for (int i = p2 + MAXLOG; i >= 0; i--) {
            for (int j = p5 + MAXLOG; j >= 0; j--) {
                have[i][j]++;
            }
        }
    }
    cout << answer << "\n";
    //timeDuration();
    return 0;
}

Measured memory_bytes: 3684
import kotlin.math.abs

fun main() {
    val s = readLine() ?: return
    fun String.isPalindrome() = take(length / 2) == takeLast(length / 2).reversed()
    val withoutX = s.replace("x", "")
    if (!withoutX.isPalindrome()) {
        println("-1")
        return
    }
    var i = 0
    var index = 0
    val half = withoutX.length / 2 + withoutX.length % 2
    val counter = Array(half) { 0 }
    while (half > i) {
        when (s[index]) {
            'x' -> counter[i]++
            else -> {
                i++
            }
        }
        index++
    }
    i = 0
    index = 0
    var count = 0
    while (half > i) {
        when (s[s.length - index - 1]) {
            'x' -> counter[i]--
            else -> {
                count += abs(counter[i])
                i++
            }
        }
        index++
    }
    println(count.toString())
}


Measured memory_bytes: 54964
#include <stdio.h>

int main()
{
	long long int a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	if(a<0) a*=-1;
	
	long long int d = a/c;
	if(b<=d) printf("%lld",a-b*c);
	else
	{
		long long int s1 = a%c;
		long long int s2 = c-s1;
		if((b-d)%2==0) printf("%lld",s1);
		else printf("%lld",s2);
	}
}

Measured memory_bytes: 1736
def bit_index(n: int) -> list:
    '''n の立っているビットのインデックスを返します。
    '''
    res = []
    idx = 0
    while n > 0:
        if n & 1:
            res.append(idx)
        n >>= 1
        idx += 1
    return res


def shopping_street(N: int, F: list, P: list) -> int:
    max_profits = -float('inf')
    # 10 ビットのフラグの t 番目が立っている時、
    # t // 2 曜日の時間帯 t % 2 に出店するとする。
    # 少なくとも 1 回は出店しないといけないので、0
    # は除く。
    for i in range(1, 1 << 10):
        open_times = bit_index(i)
        profits = 0
        # 各店舗と出店日がかぶる回数を数える。
        for n in range(N):
            shop_count = sum(F[n][t] for t in open_times)
            profits += P[n][shop_count]
        max_profits = max(max_profits, profits)
    return max_profits


if __name__ == "__main__":
    N = int(input())
    F = [[int(s) for s in input().split()] for _ in range(N)]
    P = [[int(s) for s in input().split()] for _ in range(N)]
    ans = shopping_street(N, F, P)
    print(ans)


Measured memory_bytes: 3064
c=1
M=10**9+7
*I=s=j=0
eval"N,K,*A="+`dd`.split*?,
A.sort!
K.upto(N){|i|s+=c.*A[i-1]-A[-i]
c=c*i*(I[j+=1]=j<2?1:M/j*-I[M%j]%M)%M}
p s%M

Measured memory_bytes: 31560
#include<bits/stdc++.h>
using namespace std;
long long n, i, j, a[1<<18], b, c, d;


int main(){
  cin >> n;
  for(i=1;i<=n;++i){
    cin >> a[i];
    b += a[i];
  }
  c = b;
  for(i=1; i<=n;++i){
    d += a[i];
    c = min(c, abs(d-(b-d)));
  }
  cout <<c;
}


Measured memory_bytes: 5184
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	a := nextInt()
	b := nextInt()
	_ = nextInt()
	k := nextInt()

	ans := a - b
	if k%2 == 1 {
		ans = b - a
	}

	fmt.Println(ans)

}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007
 

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < 8; i++) {
		s.pop_back();
	}
	print(s);



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s,t;
int n,m;
int dp[5000][5000];
int lcs(int sl,int tl)
{
    if(sl>=n||tl>=m)
        return 0;
    if(dp[sl][tl]!=-1)
        return dp[sl][tl];
    if(s[sl]==t[tl])
        return dp[sl][tl] = 1 + lcs(sl+1,tl+1);
    return dp[sl][tl] = max(lcs(sl+1,tl),lcs(sl,tl+1));
}


void path(int sl,int tl)
{
    if(sl>=n||tl>=m)
        return;
    int ans = dp[sl][tl];
    if(s[sl]==t[tl])
    {
        cout<<s[sl];
        return path(sl+1,tl+1);
    }
    else
    {
        if(dp[sl+1][tl] == ans)
            return path(sl+1,tl);
        else
            return path(sl,tl+1);
    }
    return;
}

int main()
{
   
    
    cin>>s>>t;
    n=s.length();
    m=t.length();
    memset(dp,-1,sizeof(dp));
    int len = lcs(0,0);
    //cout<<len<<"\n";
    path(0,0);
    return 0;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000007;


ll pow_mod(ll n, ll k, ll m) {
	ll r = 1;
	for (; k > 0; k >>= 1) {
		if (k & 1)r = (r*n) % m;
		n = (n*n) % m;
	}
	return r;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long 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() {
	COMinit();

	ll n, a, b, c;
	cin >> n >> a >> b >> c;
	if (a == 0) {
		cout << n * 100 * modinv(b, mod)%mod << endl;
		return 0;
	}
	else if (b == 0) {
		swap(a, b);
		cout << n * 100 * modinv(b, mod)%mod << endl;
		return 0;
	}

	ll d = pow_mod(a + b, 2 * n - 1, mod);
	ll e = pow_mod(a, n, mod);
	ll h = pow_mod(b, n, mod);
	ll f = 0;
	REP(i, n) {
		ll g = pow_mod(a + b, n - 1 - i, mod);
		g *= COM(n + i, i);
		g %= mod;
		g *= pow_mod(b, i, mod);
		g %= mod;
		f += g;
		f %= mod;
	}
	ll ff = e * f%mod;
	f = 0;
	REP(i, n) {
		ll g = pow_mod(a + b, n - 1 - i, mod);
		g *= COM(n + i, i);
		g %= mod;
		g *= pow_mod(a, i, mod);
		g %= mod;
		f += g;
		f %= mod;
	}
	ll fff = h * f%mod;
	ff += fff;

	ff *= 100 * n;
	ff %= mod;
	d *= (100 - c);

	cout << ff * modinv(d, mod)%mod << endl;


}

Measured memory_bytes: 12160
fun main(args: Array<String>) {

    val (n, l) = readLine()!!.split(" ").map { it.toInt() }

    val tastes = (1..n).map { l + it - 1 }
    val expect = tastes.sum()

    val eat = tastes.map { i -> Math.abs(i) }.min()!!

    if(expect >= 0) println(expect - eat) else println(expect + eat)
}

Measured memory_bytes: 37988
using System;
using System.Collections.Generic;

namespace ITP1_5_C_2 {
    class Program {
        static void Main(string[] args) {
            while(true) {
                string[] s = Console.ReadLine().Split(' ');
                int H = int.Parse(s[0]), W = int.Parse(s[1]);
                if(H == 0 && W == 0) break;
                var strlist = new List<string>();
                for(int i = 0; i < H; i++) {
                    for(int j = 0; j < W; j++) {
                        if(i == 0 || i % 2 == 0) {
                            if(j == 0 || j % 2 == 0) {
                                strlist.Add("#");
                            } else {
                                strlist.Add(".");
                            }
                        } else {
                            if(j == 0 || j % 2 == 0) {
                                strlist.Add(".");
                            } else {                                
                                strlist.Add("#");
                            }
                        }
                    }
                    string line = string.Join("", strlist.ToArray());
                    Console.WriteLine(line);
                    strlist.Clear();
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9080
N,M=map(int,input().split())
a=[0]*(M+1)
b=[0]*(M+1)
c=[[] for _ in range(M)]
for i in range(M):
    a[i],b[i]=map(int,input().split())
    c[i]=list(map(int,input().split()))

 #各鍵で明けられる宝箱のbit列
d=[0]*M
for i in range(M):
    for cij in c[i]:
        d[i]+=pow(2,cij-1)

inf=10**9
#dp[i][j]はi番目の鍵で状態jにたどり着く時に必要な最小コスト
dp = [[inf]*pow(2,N) for _ in range(M+1)]

#初期化
for i in range(M+1):
    dp[i][0] = 0


for i in range(M):
    for j in range(pow(2,N)):
        dp[i+1][j|d[i]] =min(dp[i+1][j|d[i]] , dp[i][j]+a[i])
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])

ans=dp[-1][-1]
if ans==inf:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 77928