akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const ll inf=1001001001001001;
const int Inf=1001001001;
const int mod=1000000007;
int main(){
    ll n,ans;cin>>n;
    n/=2;
    ll v=100001;
    vi s(v),t(v);
    rep(i,n){
        ll a,b;cin>>a>>b;
        s[a]++;t[b]++;
    }
    vector<P> j,k;
    rep(i,v){
        if(s[i]!=0)j.eb(s[i],i);
        if(t[i]!=0)k.eb(t[i],i);
    }
    sort(all(j));
    sort(all(k));
    reverse(all(j));
    reverse(all(k));
    if(j[0].second!=k[0].second){
        ans=j[0].first+k[0].first;
    }
    else{
        ans=max(j[0].first+k[1].first,j[1].first+k[0].first);
    }
    cout<<n*2-ans<<endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	int res=1;
	for(int i=2;i<=n;i++){
		int x=i,t=1;
		while(x<=n) x*=i,t++;
		x/=i,t--;
		if(t>1) res=max(res,x);
	}
	cout<<res<<endl;
}

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

ans = 0
for i in range(1,N):
    if A[i] + A[i-1] <= X: continue
    diff = A[i] + A[i-1] - X
    ans += diff
    if diff < A[i]:
        A[i] -= diff
    else:
        #diff -= A[i]
        A[i] = 0
        #A[i-1] -= diff
print(ans)

Measured memory_bytes: 14052
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int A[N], sum = 0;
  for (int i = 0; i < N; i++) cin >> A[i], sum += A[i];
  sort(A, A + N);
  reverse(A, A + N);
  cout << (A[M - 1] * 4 * M < sum ? "No" : "Yes") << endl;
  return 0;
}


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

ll solve(const string &S)
{
    int N = S.size();
    vector<ll> val(2019, 0);
    ll fac = 1;
    ll cur = 0;
    val[cur]++;
    for (int i = 0; i < N; i++)
    {
        ll add = S[N - 1 - i] - '0';
        cur = (cur + fac * add) % 2019;
        fac = (fac * 10) % 2019;
        val[cur]++;
    }
    ll res = 0;
    for (int i = 0; i < val.size(); i++)
    {
        res += val[i] * (val[i] - 1) / 2;
    }
    return res;
}

int main()
{
    string s;
    cin >> s;
    cout << solve(s) << endl;

    return 0;
}


Measured memory_bytes: 3716
h = int(input())
w = int(input())
n = int(input())
if h >= w and n%h != 0:
    print(n//h+1)
elif h >= w and n%h == 0:
    print(n//h)
elif w >= h and n%w != 0:
    print(n//w+1)
else:
    print(n//w)

Measured memory_bytes: 9064
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = 998244353;
const long long INF_LL = 1e18+11; const int INF_int = 1e9+11;
#define ll long long
#define mp std::make_pair
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto x:a) cout << x << " ";cout << endl;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    rep(i,n){
        if(s[i]=='R') cnt++;
    }
    int ans = 0;
    rep(i,cnt){
        if(s[i]=='W') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3752
#include <stdio.h>
 
int main(void){
	
  int a,b,c,d;
  
  scanf("%d\n%d\n%d\n%d",&a,&b,&c,&d);
  
  if(a>b){
  printf("%d\n",b*c+(a-b)*d);
  } else {
  printf("%d\n",a*c);
  }
  return 0;
}

Measured memory_bytes: 128
import sys


def input():
    return sys.stdin.readline()[:-1]


N = int(input())

XL = []
for _ in range(N):
    x, l = map(int, input().split())
    XL.append((x-l, x+l))

XL.sort(key=lambda x: x[1])

ans = 0
cur = -1e9
for i in range(N):
    if cur <= XL[i][0]:
        ans += 1
        cur = XL[i][1]
print(ans)


Measured memory_bytes: 23896
import java.util.*;

public class Main {
	static final int INF = Integer.MAX_VALUE;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//nodeNにくるための最小を順次求めていく
		try(Scanner scan = new Scanner(System.in)){
			int N = Integer.parseInt(scan.next());
			int[] h = new int[N];
			int[] d = new int[N];
			//hに標準入力を格納
			//dpに最大値を格納 dp:コストの総和と考える
			for(int i=0;i<N;i++) {
				h[i] = Integer.parseInt(scan.next());
				d[i] = INF;
			}
			d[0]= 0;
			d[1]= Math.abs(h[1] - h[0]);
			
          	for(int i = 2; i<N; i++) {
				//2つ前からくる場合のd[i]のコスト
				int prepre = d[i-2] + Math.abs(h[i]-h[i-2]);
   			
                //1つ前からくる場合のd[i]のコスト
				int pre = d[i-1] + Math.abs(h[i]-h[i-1]);
              
				//１つ前と２つ前のどちらからきた時にコストが小さいか
				d[i] = Math.min(prepre, pre);
                
            }
			//d[N]にはNにおける最小コストが格納されている
			System.out.println(d[N-1]);
				
		}
	}

}


Measured memory_bytes: 48792
class Combination():  # nCr(mod p) #n<=10**6
    def __init__(self, N, MOD):  # cmbの前処理
        self.mod = MOD
        self.FACT = [1, 1]  # 階乗
        self.INV = [0, 1]  # 各iの逆元
        self.FACTINV = [1, 1]  # 階乗の逆元
        for i in range(2, N + 1):
            self.FACT.append((self.FACT[-1] * i) % self.mod)
            self.INV.append(pow(i, self.mod - 2, self.mod))
            self.FACTINV.append((self.FACTINV[-1] * self.INV[-1]) % self.mod)

    def calculate(self, N, R):  # nCr(mod p) #前処理必要
        if (R < 0) or (N < R):
            return 0
        R = min(R, N - R)
        return self.FACT[N] * self.FACTINV[R] * self.FACTINV[N-R] % self.mod



n, m, k = map(int, input().split())
mod = 998244353

cmb = Combination(n,mod)

cnt = 0
for i in range(k + 1):
    cnt += (m * pow(m - 1, n - i - 1, mod) * cmb.calculate(n - 1, i)) % mod

print(cnt % mod)


Measured memory_bytes: 32888
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextInt();
		}
		int t=0;
		int max=0;
	/*	for(int i=0;i<n;i++){
			for(int j=1;j<n;j++){
				if(i==0)
					t=a[1];
				else	
					t=a[0];
				if(j!=i)
				t=gcd(t,a[j]);
			}
			if(max<t)
				max=t;
				t=0;	
		}	*/
			int[] l=new int[n+1];
			l[0]=0;
			for(int j=0;j<n;j++){
				l[j+1]=gcd(l[j],a[j]);
			}
			int[] r=new int[n+1];
			r[n]=0;
			for(int j=n-1;j>0;j--){
				r[j]=gcd(r[j+1],a[j]);
			}
			for(int i=0;i<n;i++){
				max=Math.max(max,gcd(l[i],r[i+1]));
			}
		System.out.println(max);
	}
	static int gcd(int a,int b){
		int t;
		if(a==0)
			return b;
		if(b==0)
			return a;
		if(a<b){ 
			int p=a;
			a=b;
			b=p;
		}
		while((t=a%b)!=0){
			a=b;
			b=t;
			
		}
		return b;
	}
	
}

Measured memory_bytes: 48840
use std::io::*;
use std::str::*;
use std::f64::consts::*;
use std::f64;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: i32,
        v: [i32; n],
    }
    let mut score = [0; 2];
    let mut turn: usize = 0;
    let mut v = v;
    v.sort_unstable();
    v.reverse();
    for i in v {
        score[turn] += i;
        if turn == 0 {
            turn = 1;
        } else {
            turn = 0;
        }
    }
    println!("{}", score[0] - score[1]);
}

Measured memory_bytes: 2132
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int mod=1e9+7;
int p[2000005],pp[2000005];
int f[2000005],inv[2000005];
void init(){
	inv[1]=1;f[1]=1;f[0]=1;
	p[0]=1;pp[0]=1;
	p[1]=25;pp[1]=26;
	FOR(i,2,2000000){
		f[i]=f[i-1]*i%mod;
		inv[i]=(mod-mod/i)*inv[mod%i]%mod;
		p[i]=p[i-1]*25%mod;
		pp[i]=pp[i-1]*26%mod;
	}
}
int POW(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b/=2;
	}
	RE ans;
}
int C(int n,int m){
	RE f[n]*POW(f[m]*f[n-m]%mod,mod-2)%mod;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,ans=0,len;
	string t;
	init();
	cin>>len>>t;len+=t.size();
	int l=t.size();
	FOR(i,l,len){
		ans=(ans+((C(i-1,l-1)*p[i-l]%mod)*pp[len-i])%mod)%mod;
	}
	cout<<ans;
	return 0;
 } 




Measured memory_bytes: 66732
#include<iostream>
#include<vector>

int main(){
  int N;
  long A, B;
  std::cin >> N >> A >> B;
  std::vector<long> X(N);
  for(int i = 0; i < N; i++) std::cin >> X.at(i);
  long tempDistance;
  long long hirou = 0;
  for(int i = 0; i < N - 1; i++){
    tempDistance = X.at(i + 1) - X.at(i);
    if(tempDistance * A > B) hirou += B;
    else hirou += tempDistance * A;
  }
  std::cout << hirou << std::endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long ans,dp[41][41][41];
int n;
char a[50][50];
long long solve(int l,int r,int i)
{
	if(l==r)return 1;
	if(l==i||r==i)return 0;
	if(~dp[l][r][i])return dp[l][r][i];
	long long sum=0;
	for(int j=l;j<i;++j)
		for(int k=i+1;k<=r;++k)
			if(a[j][k]=='1')
				for(int p=j;p<i;++p)
					for(int q=i;q<k;++q)
						sum+=solve(l,p,j)*solve(p+1,q,i)*solve(q+1,r,k);
	dp[l][r][i]=sum;
	return sum;
}
int main()
{
	memset(dp,-1,sizeof(dp));
	scanf("%d",&n);
	for(int i=1;i<=2*n;++i)scanf("%s",a[i]+1);
	for(int i=2;i<=2*n;++i)if(a[1][i]=='1')ans+=solve(2,2*n,i);
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;


}

using namespace atcoder;	

int main() {
	string s;
	cin >> s;
	lli ans = 0;
	int b_count = 0;
	for(int i=0;i<s.size();i++){
		if (s[i] == 'B')
			b_count++;
		else
			ans += b_count;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
N,X,M = gets.split.map(&:to_i)

M2N = [nil]*M
N2M = []
a = X
until M2N[a]
	M2N[a] = N2M.size
	N2M << a
	a = a*a%M
end
C = M2N[a]

p N2M[0...[C,N].min].sum + [N-C,0].max/(N2M.size-C)*N2M[C,N2M.size].sum + N2M[C,[N-C,0].max%(N2M.size-C)].sum


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

int i = 1, x, _n;
bool finish = false;

void checkNum();
void include3();
void endCheckNum();

void checkNum()
{
  x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    endCheckNum();
  }
  
}

void include3()
{
  if(finish) return;
  if ( x % 10 == 3 ){
    cout << " " << i;
    endCheckNum();
  }
  x /= 10;
  if ( x ) include3();
}

void endCheckNum()
{
  if ( ++i <= _n ) checkNum();
  else finish = true;
}

void call(int n)
{
  _n = n;
  while(!finish) {
    checkNum();
    include3();
    endCheckNum();
  }
  cout << endl;
}

int main()
{
  int n;
  cin >> n;
  call(n);
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main()
{
    int a;
    scanf("%d",&a);

    if(a>=0 && a<=10){
        int b=a+a*a+a*a*a;
        printf("%d\n",b);
    }
    else{
        printf("1<=a<=10で入力してください\n");
    }

    return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <queue>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

const int INF = 1001001001;
vector<int> to[100010];

int main(){
    int N, M;
    cin >> N >> M;
    rep(i, M){
        int A, B;
        cin >> A >> B;
        --A; --B;
        to[A].push_back(B);
        to[B].push_back(A);
    }

    queue<int> q;
    vector<int> dist(N, INF);
    vector<int> pre(N, -1);
    dist[0] = 0;
    q.push(0);
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(int u : to[v]){
            if(dist[u] != INF) continue;
            dist[u] = dist[v]+1;
            pre[u] = v;
            q.push(u);
        }
    }

    cout << "Yes" << endl;
    rep(i, N){
        if(i == 0) continue;
        int ans = pre[i];
        ++ans;
        cout << ans << endl;
    }


}


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

int main(){
    int h,w;
    cin >> h >> w;
    
    vector<vector<char>> a(h,vector<char>(w));
    
    rep(i,h){
        rep(j,w) cin >> a[i][j];
    }
    
    vector<bool> height(h,false);
    vector<bool> width(w,false);
    
    rep(i,h){
        rep(j,w){
            if(a[i][j]=='#'){
                height[i] = true;
                width[j] = true;
            }
        }
    }
    
    rep(i,h){
        if(height[i]){
            rep(j,w){
                if(width[j]){
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var W, H, x, y, r int
	fmt.Scan(&W, &H, &x, &y, &r)
	if r <= x && x <= W-r && r <= y && r <= H-y {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}



Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int N = sc.nextInt();
		int[][] input = new int[N][2];
		for (int i = 0; i < N; i++) {
			input[i][0] = sc.nextInt();
			input[i][1] = sc.nextInt();
		}
		long[][] dp = new long[N + 1][H + 10];
		for (int j = 0; j < dp[0].length; j++) {
			dp[0][j] = Integer.MAX_VALUE;
		}
		for (int i = 1; i <= N; i++) {
			for (int j = 0; j < dp[0].length; j++) {
				if (j <= input[i - 1][0]) {
					dp[i][j] = Math.min(dp[i - 1][j], input[i - 1][1]);
				} else {
					dp[i][j] = Math.min(dp[i - 1][j], dp[i][j - input[i - 1][0]] + input[i - 1][1]);
				}
			}
		}
		System.out.print(dp[N][H]);
	}
}

Measured memory_bytes: 127972
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"1 3
" => r"Yes",

r"2 4
" => r"No"
}

use std::cmp;
use std::cmp::{max, min};
use std::collections::HashSet;
use std::f32::MAX;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: i32,
        b: i32,
    }

    if a == 2 {
        "No".to_string()
    } else if a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10 || a == 12 {
        if b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12 {
            "Yes".to_string()
        } else {
            "No".to_string()
        }
    } else {
        if b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12 || b == 2 {
            "No".to_string()
        } else {
            "Yes".to_string()
        }
    }
}


Measured memory_bytes: 4352
X,K,D = list(map(int,input().split()))

if K % 2 == 1:
    K -= 1
    if abs(X - D) <= abs(X + D):
        X = X - D
    elif abs(X - D) > abs(X + D):
        X = X + D

if X == 0:
    print(0)

if X < 0:
    if D * K < abs(X):
        print(abs(X) - D * K)
    else:
        print(min(abs(X + 2*D * (abs(X) // (2 * D))), X + 2*D * (abs(X) // (2 * D)) + 2*D))
    
        
if X > 0:
    if D * K < abs(X):
        print(abs(X) - D * K)
    else:
        print(min(X - 2*D * (X // (2*D)), abs(X - 2*D * (X // (2*D)) - 2*D)))


Measured memory_bytes: 9136
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
 
int main(){
    ll n; cin >> n;
    vl v(n+1,-1);
    ll a;
    REP(i,2,n+1){
        ll tmp = i;
        a = 2;
        while(tmp >= a*a){
            if(tmp % a == 0){
                if(v[a]==-1) v[a] = 1;
                else v[a]++;
                tmp /= a;
            }else{
                a++;
            }
        }
        if(v[tmp]!=-1) v[tmp]++;
        else v[tmp] = 1;
    }
    ll cnt1=0,cnt2=0;
    ll ans = 0;
    rep(i,n+1){
        if(v[i]>=74) cnt1++;
    }
    ans += cnt1;
    cnt1 = 0; cnt2 = 0;
    rep(i,n+1){
        if(v[i]>=24) cnt1++;
        if(v[i]>=2) cnt2++;
    }
    ans += max(0LL,cnt1 * (cnt2 - 1));
    cnt1 = 0; cnt2 = 0;
    rep(i,n+1){
        if(v[i]>=14) cnt1++;
        if(v[i]>=4) cnt2++;
    }
    ans += max(0LL,cnt1 * (cnt2 - 1));
    cnt1 = 0; cnt2 = 0;
    rep(i,n+1){
        if(v[i]>=4) cnt1++;
        if(v[i]>=2) cnt2++;
    }
    ans += max(0LL,cnt1*(cnt1-1)/2 * (cnt2-2));
    cout << ans << endl;
}


Measured memory_bytes: 256
H,W,K = map(int,input().split())
c = []
for i in range(H):
    c.append(list(input()))
ans = 0
for i in range(2 ** H):
    dh = [True] * H
    for j in range(H):
        if (i >> j) & 1:
            dh[j] = False
    for j in range(2**W):
        dw = [True] * W
        for k in range(W):
            if (j >> k) & 1:
                dw[k] = False
        cnt = 0
        for k in range(H):
            for l in range(W):
                #print(k,l,dh,dw)
                if dh[k] == True and dw[l] == True and c[k][l] == '#':
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)


Measured memory_bytes: 68344
#include<stdio.h>
#include<math.h>
int main(void){
int N,L;
 scanf("%d",&N);scanf("%d",&L);

int apple[N],i;
for(i=0;i<N;i++){apple[i]=L+i;}

i=0;
int Apple[N];
for(i=0;i<N;i++){Apple[i]=fabs(apple[i]);}

int min;
min=Apple[0];
for(i=1;i<N;i++){if(min>Apple[i]){min=Apple[i];}}

int max=apple[0];

for(i=0;i<N;i++){if(max<apple[i]){max=apple[i];}}

int Taste,taste=0;

for(i=0;i<N;i++){taste=taste+apple[i];}

if(max>=0){Taste=taste-min;}else{Taste=taste+min;}

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

return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
using pqueg = priority_queue<int, vector<int>, greater<int>>;
using pquel = priority_queue<int, vector<int>, less<int>>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
int lcm(int a, int b){
  return a / __gcd(a, b) * b;
}
int r_int(int a, int b){
  return rand() % b + a;
}
const lint mod=1e9+7;



int main()
{
  lint x;
  cin >> x;

  lint money = 100;
  lint cnt = 0;
  while(money < x){
    money *= 1.01;
    cnt++;
  }

  cout <<cnt << "\n";
  return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
  ll n, a, b, c;
  cin >> n >> a >> b >> c;
  vst s(n);
  vin(s);

  vst ans(n);
  bl check = true;
  rep(i, 0, n){
    if(s.at(i) == "AB"){
      if(a == 0 && b == 0){
        check = false;
        break;
      }
      else if(a == 1 && b == 1){
        if(i == n - 1){
          a++;
          b--;
          ans.at(i) = "A";
        }
        else{
          if(s.at(i + 1) == "AC"){
            a++;
            b--;
            ans.at(i) = "A";
          }
          else{
            a--;
            b++;
            ans.at(i) = "B";
          }
        }
      }
      else if(a > b){
        a--;
        b++;
        ans.at(i) = "B";
      }
      else{
        a++;
        b--;
        ans.at(i) = "A";
      }
    }

    if(s.at(i) == "AC"){
      if(a == 0 && c == 0){
        check = false;
        break;
      }
      else if(a == 1 && c == 1){
        if(i == n - 1){
          a++;
          c--;
          ans.at(i) = "A";
        }
        else{
          if(s.at(i + 1) == "AB"){
            a++;
            c--;
            ans.at(i) = "A";
          }
          else{
            a--;
            c++;
            ans.at(i) = "C";
          }
        }
      }
      else if(a > c){
        a--;
        c++;
        ans.at(i) = "C";
      }
      else{
        a++;
        c--;
        ans.at(i) = "A";
      }
    }

    if(s.at(i) == "BC"){
      if(b == 0 && c == 0){
        check = false;
        break;
      }
      else if(b == 1 && c == 1){
        if(i == n - 1){
          b++;
          c--;
          ans.at(i) = "B";
        }
        else{
          if(s.at(i + 1) == "AB"){
            b++;
            c--;
            ans.at(i) = "B";
          }
          else{
            b--;
            c++;
            ans.at(i) = "C";
          }
        }
      }
      else if(b > c){
        b--;
        c++;
        ans.at(i) = "C";
      }
      else{
        b++;
        c--;
        ans.at(i) = "B";
      }
    }
  }
  if(check){
    cout << "Yes" << endl;
    vrep(i, ans) cout << i << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 9592
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main(void){
  map<string, int> mp;
  int n;
  
  cin >> n;
  for (int i=0; i<n; i++){
    string s; cin >> s;
    mp.insert(make_pair(s,0));
  }
  cout << (mp.size()) << endl;
  return 0;
}

Measured memory_bytes: 19224
#include <iostream>

using namespace std;

int main() {
  string in = "";
  cin >> in;
  bool check[26];
  for (int i=0; i<26; i++) check[i] = false;
  for (char c : in) check[c-'a'] = true;
  for (int i=0; i<26; i++) {
    if (!check[i]) {
      cout << (char)('a' + i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const int INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

ll ma(ll x, ll y){
    if(x>y)return x;
    return y;
}
int a[100000];
int nums[100000];
int main(void){
    int n; cin >> n; for(int i = 0;i < n;i++)cin >> a[i];
    sort(a, a + n);
    int mem = a[0]; int count = 1; int j = 0;
    for(int i = 1;i < n;i++){
        if(a[i] == mem)count++;
        else{
            nums[j] = count;
            count = 1;
            mem = a[i];
            j++;
        }
    }
    nums[j] = count;
    sort(nums, nums + j + 1);
    int sum = 0;
    for(int i = 0;i < j;i++)sum += nums[i];
    int ans = (sum + nums[j] - j)/2;
    ans = n - ans * 2;
    cout << ans << endl;
 	return 0;
}


Measured memory_bytes: 1024
def lcm(a, b):
    import fractions
    return a * b // fractions.gcd(a, b)

total = int(input())
param_list = [int(input()) for i in range(total)]

result = param_list[0]
for i in range(1, total):
    result = lcm(result, param_list[i])

print(result)

Measured memory_bytes: 5044
N = int(input())
S = []
for i in range(N):
    s = str(input())
    S.append(s)

result = ['AC', 'WA', 'TLE', 'RE']
C = [S.count(r) for r in result]

for (re, c) in zip(result, C):
    print(re + ' x ' + str(c))

Measured memory_bytes: 16128
N=input()
N=list(N)
list1=['2','4','5','7','9']
list2=['0','1','6','8']
list3=['3']
if N[len(N)-1] in list1:
    print('hon')
elif N[len(N)-1] in list2:
    print('pon')
elif N[len(N)-1] in list3:
    print('bon')

Measured memory_bytes: 8964
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
 
const long INF = (1l << 30);
const long LINF = (1l << 60);

typedef std::pair<long, long> P;
typedef std::pair<std::string, P> PP;

bool cmp(const PP &a, const PP &b){
	if(a.first < b.first){
		return true;
	}else if(a.first > b.first){
		return false;
	}else{
		if(a.second.first > b.second.first){
			return true;
		}else{
			return false;
		}
	}
}

long n;
PP r[105];

int main(){
	scanf("%ld", &n);
	for(int i = 0; i < n; i++){
		std::cin >> r[i].first >> r[i].second.first;
		r[i].second.second = i+1;
	}
	//printf("%ld\n", cmp(r[0], r[5]));
	std::sort(r, r+n, cmp);
	for(int i = 0; i < n; i++){
		std::cout << r[i].second.second << std::endl;
	}
	return 0;
}


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

using namespace std;

int main()
{
	const size_t NUM = 3;
	int values[NUM];

	for (int i = 0; i < NUM; ++i)
	{
		cin >> values[i];
	}

	int sum;
	int min = numeric_limits<int>::max();

	for (int i = 0; i < NUM - 1; ++i)
	{
		for (int j = i + 1; j < NUM; ++j)
		{
			sum = values[i] + values[j];
			if (sum < min)
			{
				min = sum;
			}
		}
	}

	cout << min << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np

N, K = [int(v) for v in input().strip().split(' ')]

H = np.array([int(v) for v in sys.stdin.readline().strip().split(' ')])

dp = np.zeros(N, dtype=int)

for i in range(1, N):
    st = max(0, i - K)
    dp[i] = min(dp[st : i] + np.abs(H[i] - H[st : i]))

print(dp[-1])



Measured memory_bytes: 23096
from collections import defaultdict
m = defaultdict(int)
n = int(input())
for _ in range(n):
    b, f, r, v = map(int, input().split())
    m[(b, f, r)] += v
for b in range(1, 5):
    for f in range(1, 4):
        for r in range(1, 11):
            print("", m[(b, f, r)], end="")
        print("")
    if b < 4:
        print("####################")



Measured memory_bytes: 6032
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int s=0,n,m;
  cin>>n>>m;
  if(n>1)
  s=(n*(n-1))/2;
  if(m>1)
  s=s+(m*(m-1))/2;
  cout<<s;
}
  

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

int main() {
	char c[1000],st[8010],d[32][9]={"100101","10011010","0101","0001","110","01001","10011011","010000","0111","10011000",
	"0110","00100","10011001","10011110","00101","111","10011111","1000","00110","00111","10011100",
	"10011101","000010","10010010","10010011","10010000","101","000000","000011","10010001","010001","000001"};
	int cn[256],i,j,k,p,n,a[6]={32,46,44,45,39,63};
    for (i=0;i<26;i++) cn[65+i]=i;
	cn[32]=26; cn[39]=27; cn[44]=28; cn[45]=29; cn[46]=30; cn[63]=31;
	while(gets(c)!=NULL) {
		p=0;
		for (i=0;i<strlen(c);i++) for (j=0;j<strlen(d[cn[(int)c[i]]]);j++) st[p++]=d[cn[(int)c[i]]][j];
		for (p;p % 5!=0;p++) st[p]='0';
		for (i=0;i<p;i+=5) {
         for (j=16,n=0,k=0;k<5;j/=2,k++) n+=j*(st[i+k]-'0');
		 if (n>=0 && n<=25) cout << (char)(65+n) ;
		 else  cout << (char)(a[n-26]);
		}
		cout << endl;
	}
    return 0;
}

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

using namespace std;

int main()
{
  int N, L;
  string S[1000], T[1000];

  cin >> N >> L;
  for(int i = 0; i < N; i++) {
    cin >> S[i];
  }
  sort(S, S + N);
  for(int i = 0; i < N; i++) {
    T[i] = S[i];
    reverse(begin(T[i]), end(T[i]));
  }

  string ret;
  for(int i = 0; i <= N; i++) {
    multiset< string > exist;
    vector< string > curr;
    for(int j = 0; j < N; j++) {
      if(i == j) continue;
      if(exist.count(T[j])) {
        exist.erase(exist.find(T[j]));
        curr.emplace_back(T[j]);
      } else {
        exist.emplace(S[j]);
      }
    }
    sort(begin(curr), end(curr));
    string all = accumulate(begin(curr), end(curr), string());
    string rev = all;
    reverse(begin(rev), end(rev));
    string beet = all;
    if(T[i] == S[i]) beet += T[i];
    beet += rev;
    if(ret.size() < beet.size()) ret = beet;
    else if(ret.size() == beet.size()) ret = min(ret, beet);
  }

  cout << ret << endl;
}

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

int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;

  cout << (h2 * 60 + m2) - (h1 * 60 + m1) - k << endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;


int main() {

	//入力
	int a, b, c, d, e;
	int k;
	cin >> a >> b >> c >> d >> e;
	cin >> k;

	//処理
	vector<int> v = { a, b, c, d, e };
	bool ok = true;
	//i, jの組み合わせを全部調べる
	for (int i = 0; i < v.size(); i++)
	{
		for (int j = 0; j < v.size(); j++)
		{
			//kを越えている値を見つけたら、okの値を更新する
			if (v[j] - v[i] > k) {
				ok = false;
			}
		}
	}
	string ans;
	if (ok) ans = "Yay!";
	else ans = ":(";

	//出力
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <tuple>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_NM 100000

using namespace std;
typedef pair<int, int> ipair;

char ID[MAX_NM + 1][20];
vector<ipair> cities[MAX_NM + 1];
vector<tuple<int, int, int>> ct_tmp;

int main(int argc, char **argv) {
    int N, M; 
    cin >> N >> M;
    for(int i = 1; i <= M; ++i) {
        int p, y;
        cin >> p >> y;
        ct_tmp.push_back(make_tuple(y, i, p));
    }
    
    sort(ct_tmp.begin(), ct_tmp.end());
    for(int i = 0; i < ct_tmp.size(); ++i)
        cities[get<2>(ct_tmp[i])].push_back(make_pair(get<0>(ct_tmp[i]), get<1>(ct_tmp[i])));

    
    for(int i = 1; i <= N; ++i) {
        for(int j = 0; j < cities[i].size(); ++j) {
            sprintf(ID[cities[i][j].second], "%06d%06d", i, j + 1);
        }
    }
    
    for(int i = 1; i <= M; ++i)
        cout << ID[i] << endl;
}

Measured memory_bytes: 10100
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };



void solve() {
    ll a, b, c, d, n, k, x,l,r;
    string s, t;
    ll ans = 0;
    double dans = 0;
    string sans = "Good";
    vector<ll> va;
    vector<ll> co;

    cin  >> n;

    rep(i,n) {
        ll tmp;
        cin >> tmp;
        va.push_back(tmp);
    }

    rep(i,n) {
        ll tmp;
        cin >> tmp;
        co.push_back(tmp);
    }

    rep(i,n){
        if(va[i] - co[i] > 0) ans+=va[i] - co[i];
    }


    std::cout << ans << endl; 
    // std::cout << sans << endl; 
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

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

int main(){
	int N;
	cin >> N;
	int M = 0;
	rep(i,N) {
		int a;
		cin >> a;
		if (a == M+1) M++;
	}

	if (M == 0) cout << -1 << endl;
	else cout << N-M << endl;

	return 0;
}


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

#define what_is(x) cerr << #x << " is " << x << endl;

const int N = 200001;
const ll MAX = (1LL<<61);

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; cin >> n;
	int ans = n; // all 1s
	for (int i = 0; i <= n; i++) {
		int running = 0;
		int t = i;
		while (t > 0) {
			running += t%6;
			t /= 6;
		}
		t = n-i;
		while (t > 0) {
			running += t%9;
			t /= 9;
		}
		ans = min(ans, running);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#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>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b;
  cin >> a >> b;
  cout << a / b << " " << a % b << " " << fixed << setprecision(10)
       << (double)a / b << endl;
}



Measured memory_bytes: 3304
package main

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

func main() {
	io := newIo()
	defer io.Flush()
	N := io.NextInt()
	X, Y, H := []int{}, []int{}, []int{}
	H0 := [][2]int{}
	for i := 0; i < N; i++ {
		x, y, h := io.NextInt(), io.NextInt(), io.NextInt()
		if h > 0 {
			X = append(X, x)
			Y = append(Y, y)
			H = append(H, h)
		} else {
			H0 = append(H0, [2]int{x, y})
		}
	}
	h := -1
	for x := 0; x <= 100; x++ {
		for y := 0; y <= 100; y++ {
			for i := 0; i < len(X); i++ {
				if H[i] == 0 {
					continue
				}
				if h == -1 {
					h = H[i] + int(math.Abs(float64(x-X[i]))+math.Abs(float64(y-Y[i])))
				} else {
					h2 := H[i] + int(math.Abs(float64(x-X[i]))+math.Abs(float64(y-Y[i])))
					if h != h2 {
						h = -1
						break
					}
				}
			}
			for _, h0 := range H0 {
				if h-int(math.Abs(float64(x-h0[0]))+math.Abs(float64(y-h0[1]))) > 0 {
					h = -1
					break
				}
			}
			if h != -1 {
				io.PrintIntLn([]int{x, y, h})
				return
			}
		}
	}
	io.PrintIntLn([]int{0, 0, 0})
}

type io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int N=110000;
ll a[N], b[N];

int main() {
    int i, n;
    ll ans=0;
    scanf("%d", &n);
    for(i=0; i<n; i++)
        scanf("%lld%lld", &a[i], &b[i]);
    for(i=n-1; i>=0; i--)
        ans+=(b[i]-(a[i]+ans)%b[i])%b[i];
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO.Pipes;

public class HelloWorld
{
    static bool res = false;
    static long[] avail;
    static long[] memo;
    static public void Main()
    {

        var N = long.Parse(Console.ReadLine());
        //var NX = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

        long ans = 0;
        for (int i = 1; i <= N; i++)
        {
            if(i%2 == 1 && PrimeFactorization(i) == 8)
            {
                ans++;
            }
        }

        Console.WriteLine(ans);
    }

    public static long Pow(long a, int n)
    {
        switch (n)
        {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                var p = Pow(a, n / 2);
                return p * p * Pow(a, n % 2);
        }
    }

    public static long PrimeFactorization(long n)
    {
        var res = 1L;

        for (long i = 2; i * i <= n; i++)
        {
            if (n % i != 0) continue;
            long exponents = 0;

            // 割り続ける
            while (n % i == 0)
            {
                exponents++;
                n /= i;
            }

            res *= exponents+1;
        }

        // 素数が残っている場合
        if (n != 1) res *= 2;
        return res;
    }
}



Measured memory_bytes: 27424
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL MOD = 1e9 + 7;
const LL MAX = 4321;
LL F[MAX];
LL IF[MAX];

// Fermat's little theorem を 適用するため, ap-2乗 などを計算できるようにする.
// @param a: べき乗したい正整数.
// @param b: 指数.
// @return: べき乗した計算結果(mod版).
LL inverse(LL a, LL b){
    LL t = 1;
    while(b) {
        if(b & 1) t = (t * a) % MOD;
        a *= a;
        a %= MOD;
        b >>= 1;
    }
    return t % MOD;
}

// 配列 IF に, 逆元を保存.
// @param: 特に無し.
// @return: 配列IF の update.
void initialize(){
    F[0] = 1, IF[0] = 1;
    for(LL i = 1; i < MAX; i++){
        F[i] = (F[i - 1] * i) % MOD;
        //逆元を、フェルマーの小定理を利用して求める
        IF[i] = inverse(F[i], MOD - 2) % MOD;
    }
}

// 組み合わせ(nCk)計算用(mod版).
// ※配列F, IF は, 事前に計算済のものを使う.
// @param n: 対象となる要素の個数.
// @param k: 選択する要素の個数.
// @return: 組み合わせ(nCk)の計算結果.
LL combination(LL n, LL k){
    if(n < 0 || k < 0 || k > n) return 0;
    LL ret = F[n] * IF[k] % MOD * IF[n - k] % MOD;
    return ret;
}

int main() {

    // 1. 入力情報取得.
    LL N, K;
    scanf("%lld %lld", &N, &K);
    initialize();
    
    // 2. 場合の数をカウントし, 出力.
    for(int i = 1; i <= K; i++){
        // 2-1. 各計算項目を設定.
        LL rp = i - 1;      // 仕切りに使う赤いボール.
        LL rr = N - K - rp; // 残った赤いボール.
        LL bp = i;          // 仕切りで使う青いボール.
        LL br = K - bp;     // 残った青いボール.
        // cout << "rp=" << rp << " rr=" << rr << " bp=" << bp << " br=" << br << endl;
        
        // 2-2. 場合の数を計算.
        // 残った赤いボールの並べ方.
        LL ans = combination(rr + bp, rr);
        ans %= MOD;
        // 残った青いボールの並べ方.
        ans *= combination(rp + br, br);
        ans %= MOD;
        
        // 2-3. 出力.
        printf("%lld\n", ans);
    }
    
    // 3. 後処理.
    return 0;

}

Measured memory_bytes: 256
N,M=map(int,input().split())
K_list = []

for i in range(M):
  K_list.append(tuple(map(int,input().split())))

p_list = list(map(int,input().split()))
################################################
count = 0
for i in range(2**N):
  switch_list = ["OFF" for _ in range(N)]
  for j in range(N):
    if i>>j & 1:
      switch_list[N-1-j] = "ON"
  #print("switch_list",switch_list)
  
  light_ON = 0
  for k in range(M):
    ON_switch = 0
    for sw in range(K_list[k][0]):
      #print(K_list[k][sw+1])
      if switch_list[K_list[k][sw+1] - 1] == "ON":
        #print("switch work") 
        ON_switch += 1
    #print("ONswitch",ON_switch)
    if ON_switch % 2 == p_list[k]:
      #print("lightON")
      light_ON += 1
  
  if light_ON == M:
    #print("all lamp light on in situation",switch_list)
    count += 1
    
print(count)
      
  

Measured memory_bytes: 74152
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int r, g;
	cin >> r >> g;
	cout << (2 * g - r) << endl;
}

Measured memory_bytes: 256
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define endl "\n"
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cini(n);
    cinai(h, n);

    int ans=0;
    int lans=0;
    for(int i=0; i<n-1; i++) {
        if(h[i]>=h[i+1])
            lans++;
        else
            lans=0;

        ans=max(ans, lans);
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int N,X,min=1000,m,ans;

    cin >> N >> X;

    for(int i=1;i<=N;i++){
        cin >> m;
        if(m<min)min=m;
        X=X-m;
    }

    ans = N+(X/min);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main(){
	int ten[2][10];
	for(int j=0;j<2;j++)for(int i=0;i<10;i++){
		cin>>ten[j][i];
	}
	sort(ten[0],ten[0]+10,greater<int>());
	sort(ten[1],ten[1]+10,greater<int>());
	cout<<ten[0][0]+ten[0][1]+ten[0][2]<<" "<<ten[1][0]+ten[1][1]+ten[1][2]<<endl;
	return 0;
}

Measured memory_bytes: 1180