akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n, q;
    string s;
    cin >> n >> s >> q;

    while(--q >= 0){
        int k;
        cin >> k;

        int d = 0;
        int m = 0;
        long long x = 0;
        long long ans = 0;
        for(int i=0; i<n; ++i){
            if(i >= k){
                if(s[i-k] == 'D'){
                    -- d;
                    x -= m;
                }
                else if(s[i-k] == 'M'){
                    -- m;
                }
            }
            if(s[i] == 'D'){
                ++ d;
            }
            else if(s[i] == 'M'){
                ++ m;
                x += d;
            }
            else if(s[i] == 'C'){
                ans += x;
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1412
/*
[agc026] A - Colorful Slimes 2
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

int N;
vector<int> a;

int solve() {
    int prev_color = -1;
    int prev_i = -1;
    int ans = 0;
    for (int i = 0; i <= N; i++) {
        if (a[i] == prev_color) {
            continue;
        }
        ans += (i - prev_i) / 2;
        prev_color = a[i];
        prev_i = i;
    }
    return ans;
}

int main() {
    cin >> N;
    a.resize(N + 1);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    a[N] = -1;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
 
using namespace std;
typedef pair<int,int> P;
 
int main() {
    int i,j,n,p,q,temp;
    int t=0;
    int flag=0;
    string s;
    cin>>s;
    for(i=0; i<3; i++){
        if(s[i]=='o'){flag++;}
    }
    t=700+flag*100;
    cout<<t;
 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int>VI;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define fi first
#define se second
#define MAX 100100//5
#define MAX_N 200100
#define MAX_B 1001001//6
#define MAX_S 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL
#define MAX_INT INT_MAX
//greater<int>()
int dp[MAX];

int main(){
    int n;cin>>n;
    rep(i,MAX)dp[i]=n;
    dp[0]=0;
    for(int i=1;i<=n;i++){
        for(int pow6=1;pow6<=i;pow6*=6)
            dp[i]=min(dp[i],dp[i-pow6]+1);
        for(int pow9=1;pow9<=i;pow9*=9)
            dp[i]=min(dp[i],dp[i-pow9]+1);   
    }
    cout<<dp[n]<<endl;
}

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

int main() {
  int N;
  string S;
  scanf("%d", &N);
  cin >> S;
  for (int i = 1; i <= N / 2; i++) {
    string T = S.substr(0, i) + S.substr(0, i);
    if (T == S) {
      printf("Yes");
      return 0;
    }
  }
  printf("No");
  return 0;
}

Measured memory_bytes: 256
from math import sqrt
from itertools import combinations
n,d=map(int,input().split())
ct=0
list1=[[0 for i in range(d)]for j in range(n)]
list2=list(range(n))
pair=list(combinations(list2,2))
for i in range(n):
    list1[i]=list(map(int,input().split()))
for i in range(len(pair)):
    ans=0
    for j in range(d):
        ans+=(list1[pair[i][0]][j]-list1[pair[i][1]][j])**2
    if int(sqrt(ans))-sqrt(ans)==0:
        ct+=1
print(ct)

Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;
int main(){
    int A,B,C,ans,i;
    cin >> A >> B >> C;
    ans = 0;
    for(i=0;i<B;i++){
        if((i*A)%B==C) ans = 1;
    }
    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main()
{
    ll A, B, C; cin >> A >> B >> C;
    ll K; cin >> K;

    rep(i,K) {
        if (B <= A) {
            B *= 2;
        }
        else if (C <= B) {
            C *= 2;
        }
    }
    if (B > A && C > B) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }


}


Measured memory_bytes: 3640
K=int(input())
n=1
k=0
x=[]
y=x.append
while(n<=10**15):
    plus=10**k
    if n>=1350*plus:
        n+=9*plus
        k+=1
        plus*=10
    y([n,n/sum(map(int,list(str(n))))])
    n+=plus
x2=[]
y2=x2.append
min_=10**15
for i in range(len(x)-1,-1,-1):
    if x[i][1]<=min_:
        y2(x[i][0])
        min_=x[i][1]
x2=list(reversed(x2))
for i in range(K):
    print(x2[i])

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

/*
高橋君は500円玉で1000, 5円玉で5のうれしさ．うれしさの最大化
*/
int main() {
	int X;
	cin >> X;

	int Hap = 0;//うれしさ(これを最大化)
	int A = 0;//500円玉の枚数
	int B = 0;//5円玉の枚数

		if (X >= 500) {
			A = X / 500;
			X = X - A * 500;

			B = X / 5;
		}
		else {
			B = X / 5;
			//X = X - B * 5;
		}
	
	cout << 1000 * A + 5 * B << endl;


}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
const LL MOD = (LL)1e9 + 7;
char s[MAXN];
int cnt[26];

int main() {
    int N;
    scanf("%d", &N);
    scanf("%s", s);
    for (int i = N - 1; i >= 0; i--) {
        int cur = s[i] - 'a';
        cnt[cur]++;
    }
    LL ans = 1;
    for (int i = 0; i < 26; i++) {
        ans = (ans * (cnt[i] + 1)) % MOD;
    }
    printf("%lld\n", ans - 1);
    return 0;
}


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

int a, b, c, d;

int main(){
    cin >> a >> b >> c >> d;
    if( ( abs(a-c) <= d ) | ( abs(a-b) <= d && abs(b-c) <= d )){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  using P = function<E(E,size_t)>;
  Int n;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  P p;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(Int n_,F f,G g,H h,T ti,E ei,
	      P p=[](E a,size_t b){b++;return a;}):
    f(f),g(g),h(h),ti(ti),ei(ei),p(p){
    init(n_);
  }
  void init(Int n_){
    n=1;
    while(n<n_) n*=2;
    dat.assign(2*n-1,ti);
    laz.assign(2*n-1,ei);
  }
  void build(Int n_, vector<T> v){
    for(Int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(Int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  inline void eval(Int len,Int k){
    if(laz[k]==ei) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
    }
    dat[k]=g(dat[k],p(laz[k],len));
    laz[k]=ei;
  }
  T update(Int a,Int b,E x,Int k,Int l,Int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return g(dat[k],p(laz[k],r-l));
    }
    return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
		    update(a,b,x,k*2+2,(l+r)/2,r));
  }
  T update(Int a,Int b,E x){
    return update(a,b,x,0,0,n);
  }
  T query(Int a,Int b,Int k,Int l,Int r){
    eval(r-l,k);
    if(r<=a||b<=l) return ti;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(Int a,Int b){
    return query(a,b,0,0,n);
  }
  void update(Int k,T x){
    query(k,k+1);//evaluate
    k+=n-1;
    dat[k]=x;
    while(k){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
};


template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,q,a,b;
  cin>>n>>q>>a>>b;
  a--;b--;
  
  SegmentTree<Int, Int>::F f=[](Int a,Int b){return min(a,b);};
  SegmentTree<Int, Int>::G g=[](Int a,Int b){return a+b;};
  const Int INF = 1e15;
  SegmentTree<Int, Int> sl(n,f,g,g,INF,0);
  SegmentTree<Int, Int> sr(n,f,g,g,INF,0);

  auto update=[&](Int x,Int v){
    sl.update(x,v-x);
    sr.update(x,v+x);
  };
  auto query=[&](Int x){
    Int vl=sl.query(0,x+1)+x;
    Int vr=sr.query(x,n)-x;
    return f(vl,vr);
  }; 

  update(a,0);
  for(Int i=0;i<q;i++){
    Int x;
    cin>>x;
    x--;
    Int y=query(x);
    //cout<<x<<" "<<y<<endl;
    sl.update(0,n,abs(x-b));
    sr.update(0,n,abs(x-b));
    update(b,y);
    b=x;
  }
  
  Int ans=query(0);
  for(Int i=0;i<n;i++) chmin(ans,query(i));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
#define maxn 605
#define maxm maxn*maxn/2
using namespace std;
int n,m,deg[maxn],stk[maxn],top;
double f[maxn],g[maxn],ans;
vector<int>G[maxn];
double dfs(int u){
	if(u==n) return 0;
	if(f[u]) return f[u];
	for(int v: G[u]) f[u]+=dfs(v);
	return f[u]=f[u]/G[u].size()+1;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,x,y;i<=m;i++) scanf("%d%d",&x,&y),G[x].push_back(y),deg[y]++;
	dfs(1);
	g[1]=1;
	for(int i=1;i<=n;i++) if(!deg[i]) stk[++top]=i; 
	while(top){
		int u=stk[top--]; if(u==n) break;
		for(int v: G[u]){
			g[v]+=g[u]/G[u].size();
			if(!--deg[v]) stk[++top]=v;
		}
	}
	for(int u=1;u<n;u++) if(G[u].size()>1){
		double tmp=0; for(int v: G[u]) tmp+=f[v];
		for(int v: G[u])
			ans=max(ans,g[u]*(f[u]-((tmp-f[v])/(G[u].size()-1)+1)));
	}
	printf("%.10f\n",f[1]-ans);
}

Measured memory_bytes: 1408
import fractions
n,m=map(int,input().split())
tosi = list(map(int,input().split()))
for i in range(n):
    tosi[i]=abs(m-tosi[i])
answer=min(tosi)
while max(tosi)!=0:
    for i in range(n):
        if tosi[i]%answer==0:
            tosi[i]=0
        else:
            answer=fractions.gcd(answer,tosi[i])
print(answer)

Measured memory_bytes: 16280
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const double DET = 0.00000000000001;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;




int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	int N;
	cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

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

	int ans = 0;
	for (int i = 0; i < N; i++) {

		int count = 1;
		for (int j = 1; i + j < N; j++) {
			if (A[i + j] == A[i] ) {
				count++;
				if (i + j == N - 1) {

					if (count >= A[i]) {
						ans += count - A[i];
					}
					else {
						ans += count;
					}
					break;

				}
			}
			else {
				if (count >= A[i]) {
					ans += count - A[i];
				}
				else {
					ans += count;
				}
				break;
			}
		}

		i += count -1;

		if (i == N - 1 && count == 1 && A[N-1] != 1) {
			ans++;
		}

	}

	cout << ans;

}




Measured memory_bytes: 1024
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		Arrays.setAll(A, i -> sc.nextInt());
		long m = 1000;
		int l = 300;
		for(int i = 0; i < N; i++) {
			if(A[i] > l) {
				m += (A[i] - l) * (m / l);
				l = A[i];
			}
			else
				l = Math.min(A[i], l);
		}
		System.out.println(Math.max(m, 1000));
	}

}

Measured memory_bytes: 35908
#!/usr/bin/env python3
#ABC113 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,m = LI()
lst = [[] for _ in range(n)]
py = [LI() for _ in range(m)]
for i in range(m):
    p,y = py[i]
    lst[p-1].append(y)
for i in lst:
    i.sort()
for i in range(m):
    p,y = py[i]
    s1 = '00000' + str(p)
    s2 = '00000' + str(bisect.bisect_right(lst[p-1],y))
    ans = s1[-6:] + s2[-6:]
    print(ans)


Measured memory_bytes: 37148
a = gets.to_i.times.map{gets[0]}.reduce({'M'=>0,'A'=>0,'R'=>0,'C'=>0,'H'=>0}) do |e, c|
  e[c] += 1 if e[c]
  e
end.map{|e|e[1]}

res = 0
5.times do |i|
  ((i+1)...5).each do |j|
    ((j+1)...5).each do |k|
      res += a[i]*a[j]*a[k]
    end
  end
end

puts res


Measured memory_bytes: 9340
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){

  int a, b, c;
  cin >> a >> b >> c;
  cout << a * b / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
#define DBG 0 //submit 0
#define ll long long
#if DBG
    #include <algorithm>
    #include <array>
    #include <ctime>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <unordered_map>
    #include <iostream>
    #include <cmath>
    #include <queue>
    #include <numeric>
#else
    #include <bits/stdc++.h>
#endif
 
using namespace std;
 
 
int main(){
    int a[200005];
    //bool flag=false,d[100005];
    int n,ans=0;
    //char s[105],t[105],u;
   
    cin >> n;
    for(int i=0;i<n;i++) cin >> a[i];
    //for(int i=0;i<n;i++) cin >> t[i];

   for(int i=0;i<n;i++){
       if(a[i] == ans + 1) ans++;
   }
   ans = n-ans;
   if(ans == n)ans = -1;

    
    //cout << (!flag ? "Yes" : "No");
    cout << ans;
    //cout << s;
    //printf("%.10f",ans_d);
    cout << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e2+5;
const int p=998244353;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}
void write(int x)
{
	if (x<0)
	{
		putchar('-');
		x=-x;
	}
	if (x<10) putchar(x+'0');
	else
	{
		write(x/10);
		putchar(x%10+'0');
	}
}
void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}
char a[N];
bool f[N][N][N];
int dp[N][N][N];
void add(int &x,int y)
{
	x+=y;
	if (x>=p) x-=p;
}

signed main()
{
	memset(f,0,sizeof(f));
	memset(dp,0,sizeof(dp));
	scanf("%s",a+1);
	int n=strlen(a+1),ans=0;
	f[0][0][0]=1;
	for (int i=0;i<n;i++)
	for (int j=0;j<=i;j++)
	for (int k=0;k<=i;k++)
	if (f[i][j][k])
	{
		f[i+1][j][k]=1;
		if (a[i+1]=='0'||a[i+2]=='0') f[i+2][j+1][k]=1;
		if (a[i+1]=='1'||a[i+2]=='1') f[i+2][j][k+1]=1;
		if (a[i+1]=='0'&&k) f[i+1][j+1][k-1]=1;
		if (a[i+1]=='1'&&j) f[i+1][j-1][k+1]=1;
	}
//	for (int i=1;i<=n;i++){for (int j=0;j<=i;j++){for (int k=0;k<=i;k++)putchar(f[i][j][k]+'0');puts("");}puts("");}
	dp[n][0][0]=1;
	for (int i=n;i>=1;i--)
	for (int j=0;j<=i;j++)
	for (int k=0;k<=i;k++)
	{
		add(dp[i-1][j][k],dp[i][j][k]);
		if (a[i]=='1') add(dp[i][j+1][k],dp[i][j][k]);
		if (a[i]=='0') add(dp[i][j][k+1],dp[i][j][k]);
	}
	for (int i=1;i<=n;i++)
	for (int j=0;j<=i;j++)
	for (int k=0;k<=i;k++)
	add(ans,f[i][j][k]*dp[i][j][k]);
	print(ans);

	return 0;
}

Measured memory_bytes: 253132
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1275
//ヨセフスの問題 ブログを書きましょう！！
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;
int main(void)
{
    string s;
    int y, m, d;
    while (cin >> s >> y >> m >> d)
    {
        if (s == "#")
            break;

        if ((y == 31 && m >= 5) || y >= 32)
        {
            y -= 30;
            s = "?";
        }
        cout << s << " " << y << " " << m << " " << d << endl;
    }
    return 0;
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=1e5+5;
//ll a[N],sum[N];
struct node{
    ll a,b,c;
}p[N];
int n,m,i,j,k;
bool cmp(node x,node y){
    return x.a*i+x.b*j+x.c*k>y.a*i+y.b*j+y.c*k;
}
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n>>m;
    ll ans=0;
    for(int i=1;i<=n;i++)   cin >>p[i].a>>p[i].b >>p[i].c;
    for( i=-1;i<=1;i+=2){
        for( j=-1;j<=1;j+=2){
            for( k=-1;k<=1;k+=2){
                sort(p+1,p+1+n,cmp);
                ll t[4]={0};
                for(int te=1;te<=m;te++)    t[1]+=p[te].a,t[2]+=p[te].b,t[3]+=p[te].c;
                ans=max(ans,t[1]*i+t[2]*j+t[3]*k);
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }


        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Ai = Slist();
            var oddnum = Ai.Count(a => a % 2 != 0);
            var cnum = Ai.Count(a => a % 4 == 0);
            if (N / 2 <= cnum) WriteLine("Yes");
            else if (oddnum <= cnum) WriteLine("Yes");
            else WriteLine("No");
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 22112
x,k,d=map(int,input().split())

minx=x-k*d
maxx=x+k*d
targetx=minx%(2*d)
if targetx>d:
    targetx-=2*d
if targetx==d:
    if x<0:
        targetx-=2*d

if minx>targetx:
    print(abs(minx))
    exit()
if maxx<targetx:
    print(abs(maxx))
    exit()
print(abs(targetx))


Measured memory_bytes: 9192
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
import bisect as bi
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########
n=int(input())
ans=""
now=n
if n==0: print(0);exit()
while now!=0:
    if now%(-2)==-1:
        ans+="1"
        now=(now-1)//(-2)
    else:
        ans+="0"
        now=now//(-2)
print(ans[::-1])


Measured memory_bytes: 77408
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1){unsigned day;if (dow < dow1) dow += 7;day = dow - dow1;day += 7 * n - 6;return day;}
signed gcd(long long x, long long y) {if (y == 0)return x;return gcd(y, x % y);}
signed lcm(long long x, long long y){return x / gcd(x, y) * y;}
unsigned DayToWeekNumber(unsigned day){return (day - 1) / 7 + 1;}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0){return (dow0 + 35 + day - day0) % 7;}
using namespace std;
int main() {
    long long N, K; cin >> N >> K;
    vector<int>A(N);
    vector<bool>B(N, false);
    B[0] = true;
    for (int i = 0; i < N; i++)cin >> A[i];
    vector<int>C(N+1);
    C[0] = 0;
    for (long long i = 1; i < N+1; i++) {
        C[i] = A[C[i-1]]-1;
        if (B[A[C[i]]] == true) {
            for (long long j = 0; j < i; j++) {
                if (C[j] == C[i]) {
                    int a=(K-(j+1))%(j-i);
                    cout << C[j+a+1]+1 << endl;
                    return 0;
                }
            }
        }
        B[A[C[i]]] = true;
        if(i==K){
          cout<<C[i]+1<<endl;
          return 0;
        }
    }
    cout<< C[K%N]+1 <<endl;
}

Measured memory_bytes: 4804
#include<iostream>
using namespace std;
int main() {
	int N, A[210];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int ans=0;
	bool exist_odd=false;

	while (true) {

		for (int i = 0; i < N; i++) {
			if (A[i] % 2 != 0) {
				exist_odd = true;
			}
		}
		if (exist_odd) {
			break;
		}
		for (int i = 0; i < N; i++) {
			A[i] /= 2;
		}
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
J, I, X, Y, n, m, rm, A['   '];
main() {
  scanf("%d%d", &n, &m);
  for (; ~scanf("%d%d", &X, &Y);) {
    int b = Y + 1;
    for (J = 1; J * J <= m; J++) {
      int tx = (X + J - 1) / J, ty = Y / J;
      A[tx]++;
      A[ty + 1 < b ? ty + 1 : b]--;
      b = tx;
    }
    for (I = 1; I < b; I++) {
      if ((X - 1) / I < Y / I) {
        A[I]++;
        A[I + 1]--;
      }
    }
  }
  for (I = 1; I <= m; I++) {
    A[I] += A[I - 1];
    printf("%d\n", A[I]);
  }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define  rep(i,n) for(li i = 0; i < (n); ++i)
#define  red(i,n) for(li i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;


int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<((a+b>=c)?"Yes":"No")<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;

long long gcd(long long x, long long y){
    if(y==0)return x;
    return gcd(y,x%y);
}

bool solve(long long a, long long b, long long c, long long d){
    if(b>d)return false;
    if(a<b)return false;
    //suppose a>=b, b<=d
    if(c>=b-1)return true;
    //suppose c<b-1;
    long long k = a%b;
    long long l = gcd(b,d);
    if (l * (b/l - 1) + k % l > c)return false;
    return true;
}


int main(int argc, char const *argv[]) {
    int t;cin>>t;
    for(int tt=0;tt<t;tt++){
        long long a,b,c,d;cin>>a>>b>>c>>d;
        if(solve(a,b,c,d))cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define show(x) cout<< #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};
int dx[]={1,0,-1,1,-1,1,0,-1};
int dy[]={1,1,1,0,0,-1,-1,-1};

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

int main(){
	int d,n;
	cin>>d>>n;
	vector<int> a;
	int i=1;
	while(int(a.size())<n){
		if(i%100!=0)a.pb(i);
		i++;
	}
	cout<<a[n-1]*(int)pow(100,d)<<endl;
	return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	result := 0
	for i := 1; i < 100000; i++ {
		if i*i > N {
			break
		}
		result = i
	}
	fmt.Println(result * result)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}

func (s *FastScanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int count = 0;
		String ans = "No";

		int[] d1 = new int[n];
		int[] d2 = new int[n];

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

		for(int i=0 ; i<n ; i++) {
			if(d1[i]==d2[i]) {
				count++;
				if(count == 3) {
					ans  = "Yes";
					break;
				}
			}else {
				count=0;
			}
		}

		System.out.println(ans);


		sc.close();

	}

}


Measured memory_bytes: 36056
/*input
4 5
1 2
3 4
1 3
2 3
1 4
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element

typedef long long int ll;
#define int ll
#define ld double
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=4e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
ll par[maxn],rank1[maxn];
pii arr[maxn];
int find(int u){
    return u==par[u]?par[u]:find(par[u]);
}
void merge(int a,int b){
    a=find(a),b=find(b);
    if(a==b) return;
    if(rank1[a]>rank1[b]) swap(a,b);
    par[a]=b;
    rank1[b]+=rank1[a];
}
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(0);
    ll n,m;
    cin>>n>>m;
    REP(i,n) par[i]=i,rank1[i]=1;
    REP(i,m){
        cin>>arr[i].f>>arr[i].s;
        --arr[i].f,--arr[i].s;
    }
    ll ans=(n*(n-1))/2;
    vector<ll> v;
    for(int i=m-1;i>=0;i--){
        assert(ans>=0);
        v.pb(ans);
        //if(ans==0) continue;
        if(find(arr[i].f)!=find(arr[i].s)) ans-=rank1[find(arr[i].f)]*rank1[find(arr[i].s)];
        merge(arr[i].f,arr[i].s);
    }
    reverse(ALL(v));
    for(auto x:v) cout<<x<<'\n';
}

Measured memory_bytes: 7924
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int Q = scanner.nextInt();
    char[] s = scanner.next().toCharArray();

    int[] sum = new int[N];
    for (int i = 1; i < N; i++) {
      sum[i] = sum[i - 1];
      if (s[i - 1] == 'A' && s[i] == 'C') sum[i]++;
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < Q; i++) {
      int l = scanner.nextInt() - 1;
      int r = scanner.nextInt() - 1;
      sb.append(sum[r] - sum[l]).append('\n');
    }
    System.out.println(sb.toString());
  }
}


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

int main(void){
    long long n, a[100010], first = 0, second = 0;
    cin >> n;
    for(int i=0;i<n;++i) cin >> a[i];
    sort(a, a+n);
    for(int i=n-1;i>=1;--i) {
        if(a[i]==a[i-1]){
            if(first==0){
                first = a[i];
                --i;
            }else{
                second = a[i];
                break;
            }
        }
    }
    if(first==0 || second==0){
        cout << "0\n";
    }else{
        cout << first*second << endl;
    }
}

Measured memory_bytes: 1024
n,m,c=map(int,input().split())
b=list(map(int,input().split()))

count=0
sum=0

for i in range(n):
    a=list(map(int,input().split()))
    for j in range(m):
        sum+=a[j]*b[j]

    sum+=c
    if sum>0:
        count+=1
    sum=0

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>

using namespace std;

int pairs_count[9][9];

int calc_digit(int x){
    int digit = 0;

    while(x > 0){
        x /= 10;
        digit += 1;
    }

    return digit;
}

int main(void)
{
    int max_val;

    cin >> max_val;
    int digit = calc_digit(max_val);

    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            int count = 0;
            if(i == j && i <= max_val){
                count += 1;
            }

            for(int k = 2; k < digit; k++){
                count += pow(10, k - 2);
            }

            int val = pow(10, digit - 1) * j + i;
            int end_val = pow(10, digit - 1) * (j + 1) + i;
            if(val % 10 != 0){
                while(val < end_val && val <= max_val){
                    if(val % 10 != 0){
                        count += 1;
                    }
                    val += 10;
                }
            }

            pairs_count[i - 1][j - 1] = count;
        }
    }

    int sol_count = 0;

    for(int i = 1; i <= max_val; i++){
        int bottom = i % 10;
        if(bottom != 0){
            int top = i / pow(10, calc_digit(i) - 1);
            sol_count += pairs_count[top - 1][bottom - 1];
        }
    }

    cout << sol_count << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
const int inf=1001001001; const long long INF=1001001001001001001;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int to, from, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
//
//
//
//          ∧ ∧  ／￣￣￣￣￣￣￣￣￣￣￣＼
// ～′￣￣( ˚д˚)＜  Let's start coding!!  |
//  UU￣￣  U U  ＼                      ／
//                 ￣￣￣￣￣￣￣￣￣￣￣

ll n, k;
int main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n >> k;
  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }
  ll ans = 0;
  erep(i, 1, n) {
    if (i >= k + 1) {
      ans += n / i * (i - k);
      ans += max(0LL, (n % i) - k + 1);
    }
  }
  cout << ans << endl;
  return 0;
}



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

int main() {
  ll n,x;cin>>n>>x;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  sort(all(a));
  int cnt=0;
  rep(i,n){
    x-=a[i];
    if(x<0)break;
    cnt++;
  }
   if(x>0)cnt--;
  cout<<cnt<<endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
    int n, k;
    cin >> n >> k;
    int p[n];
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    sort(p, p + n);
    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += p[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3556
#include<stdio.h>


int main(void){

  long int a, b;
  int n;


  while(scanf("%ld %ld", &a, &b) != EOF){
    a += b;

    n=0;
    while(1){
      a /= 10;
      n++;
      if(a==0) break;
    }

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


  return(0);
}



Measured memory_bytes: 2028
import java.util.ArrayList;
import java.util.List;

public class Main {


  private static void solve() {
    int n = ni();
    int k = ni();
    
    if (k > (n - 1) * (n - 2) / 2) {
      System.out.println(-1);
      return;
    }
    
    
    List<int[]> list = new ArrayList<>();
    for (int i = 1; i < n; i ++) {
      list.add(new int[] {0, i});
    }
    
    int now = (n - 1) * (n - 2) / 2;
    
    int last = now - k;
    
    outer: for (int i = 1; i < n; i ++) {
      for (int j = i + 1; j < n; j ++) {
        if (last == 0) {
          break outer;
        }
        list.add(new int[] {i, j});
        last --;
        
      }
    }
    
    System.out.println(list.size());
    for (int[] v : list) {
      System.out.println((v[0] + 1) + " " + (v[1] + 1));
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

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

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

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 24276
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int n = 0;
    int k = 0;
    int snake[50];
    int ans = 0;
    cin >> n >> k;
    for (int i = 0; i <n ; ++i) {
        cin >> snake[i];
    }
    sort(snake,snake + n,greater<int>());
    for (int j = 0; j < k; ++j) {
        ans += snake[j];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define P pair<int,int>
#define Sort(a) sort((a).begin(),(a).end())
#define Reverse(a) reverse((a).begin(),(a).end())
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;

signed main(){
    int n,w;
    cin >> n >> w;
    int a[n][w+1]={};
    REP(i,n){
        int wei,v;
        cin >> wei >> v;
        if(i==0){
            FOR(j,wei,w+1){
                a[i][j] = v;
            }
          
        }
      	
        else{
            REP(j,w+1){
                if(j-wei>=0){
                    a[i][j] = a[i-1][j-wei] + v;
                }
              
                if(j!=0){
                    a[i][j] = max({a[i][j],a[i][j-1],a[i-1][j]});
                  
                }
              
            }
        }

    }
    cout << a[n-1][w] << endl;
    
    return 0;
}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
int n,m,fa[100005],dis[100005];
bool ok=1;
int find(int x)
{
    if(fa[x]!=x)
    {
        int nf=fa[x];
        fa[x]=find(fa[x]);
        dis[x]+=dis[nf];
    }
    return fa[x];
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        fa[i]=i;
    for(int i=1;i<=m;i++)
    {
        int l,r,d;
        cin>>l>>r>>d;
        int rl=find(l),rr=find(r);
        if(rl==rr&&dis[l]-dis[r]!=d)
            ok=0;
        if(rl!=rr)
        {
            fa[rl]=rr;
            dis[rl]=d+dis[r]-dis[l];
        }
    }
    if(ok)
        cout<<"Yes"<<endl;
    else 
        cout<<"No"<<endl;
    return 0;
} 

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"sort"
)

// https://atcoder.jp/contests/agc003/tasks/agc003_c
//

func swap(a []int, i, j int) {
	tmp := a[i]
	a[i] = a[j]
	a[j] = tmp
}

func solve(a []int) {
	count := 0
	aOrg := make(map[int]int, len(a))

	for i := 0; i < len(a); i++ {
		aOrg[a[i]] = i
	}
	sort.Ints(a)

	for i := 0; i < len(a); i++ {
		j := aOrg[a[i]]
		if j > i {
			count += (j - i) % 2
		} else {
			count += (i - j) % 2
		}
	}
	fmt.Printf("%v\n", count/2)
}

func main() {
	var n int
	var a []int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var ta int
		fmt.Scanf("%d\n", &ta)
		a = append(a, ta)
	}
	solve(a)
}


Measured memory_bytes: 8068
MOD=10**9+7
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)


#----------------------------------------------------------
# nCk mod 10**9+7
# 前計算
fact=[1]
fact_inv=[1]
mod=10**9+7
for i in range(n+1):
  new_fact=fact[-1]*(i+1)%mod
  fact.append(new_fact)
  fact_inv.append(pow(new_fact,mod-2,mod))

def mod_comb_k(n,k,mod):
  return fact[n]*fact_inv[k]%mod*fact_inv[n-k]%mod
#----------------------------------------------------------

  
c=[]
for i in range(1,n-k+1+1):
  c.append(mod_comb_k(n-i,k-1,MOD))
  
lc=len(c)
sum=0
for i in range(lc):
  sum+=c[i]*(a[i]-a[-i-1])%MOD
  
print(sum%MOD)


Measured memory_bytes: 71080
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int N;
  cin >> N;
  bool ans = false;
  rep(i, 9) {
    if (N % (i + 1) == 0) {
      if (N / (i + 1) < 10) {
        ans = true;
      }
    }
  }
  if (ans == true) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}


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

int main(){
    bool is_prime[1000000];

    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<1000000;i++){
        is_prime[i]=true;
    }

    for(int i=2;i*i<1000000;i++){
        if(is_prime[i]){
            for(int j=i*i;j<1000000;j+=i){
                is_prime[j]=false;
            }
        }
    }

    while(true){
        int n;
        cin>>n;

        if(n==0) break;
        
        int cnt=0;
        for(int i=2;i<=n;i++){
            if(is_prime[i]&&is_prime[n-i]) cnt++;
        }
        if(n%2==1) cout<<cnt/2<<endl;
        else{
            cout<<cnt/2+(is_prime[n/2]==true)<<endl;
        }
        
    }
    
    return 0;
}


Measured memory_bytes: 4056
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a=0,b=0,m=0,n=0,t=0;
		while(scan.hasNext()){
			a = scan.nextInt();
			b = scan.nextInt();
			if(a < b){
				m = b;
				n = a;
			}else{
				m = a;
				n = b;
			}
			while(true){
				if((t=m % n) == 0){
					break;
				}
				m = n;
				n = t;
			}
			System.out.println(n + " " + a/n*b);
		}
	}
}

Measured memory_bytes: 12000
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int min_val=1,c=0,d=0;
    for(int i=0;i<n;i++)
    {
        c=min_val*2;
        d=min_val+k;
        min_val=min(c,d);
    }
    cout<<min_val;

    return 0;
}


Measured memory_bytes: 3640
def solve():
    N, P = map(int,input().split())
    A = list(map(int,input().split()))

    odd_cnt = 0
    even_cnt = 0

    for a in A:
        if a % 2 == 0:
            even_cnt += 1
        else:
            odd_cnt += 1
    
    odd_perm = 0
    for r in range(0,odd_cnt+1,2):
        odd_perm += n_combination(odd_cnt, r)
    
    if P == 0:
        print(odd_perm * pow(2,even_cnt))
    else:
        print(pow(2,N) - (odd_perm * pow(2,even_cnt)))
        
def n_combination(n, r):
    numer_sum = 1
    denom_sum = 1
    for i in range(r):
        numer_sum *= n - i
        denom_sum *= r - i
    
    return numer_sum // denom_sum
if __name__ == '__main__':
    solve()

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  vector<int> c(M-1);
  for(int i=0; i<M; i++) cin >> X.at(i);
  sort(X.begin(), X.end());
  for(int i=0; i<M-1; i++) c.at(i)=X.at(i+1)-X.at(i);
  sort(c.begin(), c.end());
  int ans=0;
  for(int i=0; i<M-N; i++) ans+=c.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint N,M,X;
    cin >> N >> M >> X;
    lint A[N][M];
    lint C[N];
    rep(i,N){
        cin >> C[i];
        rep(j,M) cin >> A[i][j];
    }
    lint ans=LINF;
    rep(i,(1<<N)){
        lint und[M]={};
        bool che=true;
        lint value=0;
        rep(j,N) if((1<<j)&i){
            value+=C[j];
            rep(k,M) und[k]+=A[j][k];
        }
        rep(j,M) if(und[j]<X) che=false;
        if(che) ans=min(ans,value);
    }
    if(ans!=LINF) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 3648