akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ld long double
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(a)       (a).begin(),(a).end()
#define rep(i,a,n)   for(int i=a ; i<n ; i++)
 
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<ll,ll> mii;
typedef map<char,ll> mci;
 
ll gcd(ll a, ll b){
	if(b==0)return a;
	else return gcd(b, a%b);
}

signed main(){
    ll test=1;
    // cin>>test;
    while(test--){
        ll n, w; cin>>n>>w;
       long long  wt[10000], val[10000];
        rep(i, 0, n)cin>>wt[i]>>val[i];
        ll dp[n+1][w+1];
        memset(dp, 0, sizeof(dp));
        for(int i=1; i<n+1; i++){
        	for(int j=1; j<w+1; j++){
        		if(j>=wt[i-1])dp[i][j]=max(dp[i-1][j], val[i-1]+dp[i-1][j-wt[i-1]]);
        		else dp[i][j]=dp[i-1][j];
        	}
        }
        cout<<dp[n][w]<<endl;
 
    }    
}


Measured memory_bytes: 82312
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

//main
int main(){
  int A,B,T;
  cin >> A >> B >> T;
  cout << B*(T/A) << endl;
}




Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    long M = scanner.nextLong();
    long[] a = new long[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt();
    Arrays.sort(a);
    long[] s = new long[N + 1];
    for (int i = 0; i < N; i++) s[i + 1] = s[i] + a[i];

    long left = a[0] * 2;
    long right = a[N - 1] * 2;
    while (right - left > 1) {
      long mid = (right + left) / 2;
      long k = 0;
      for (int i = 0; i < N; i++) {
        int t = upperBound(a, mid - a[i]) + 1;
        k += N - t;
      }
      if (k >= M) {
        left = mid;
      } else {
        right = mid;
      }
    }

    long total = 0;
    long k = 0;
    for (int i = 0; i < N; i++) {
      int t = upperBound(a, left - a[i]) + 1;
      k += N - t;
      total += s[N] - s[t];
      total += a[i] * (N - t);
    }

    total += (M - k) * left;
    System.out.println(total);
  }

  private static int upperBound(long[] a, long k) {
    int left = -1;
    int right = a.length;
    while (right - left > 1) {
      int mid = (left + right) / 2;
      if (a[mid] < k) left = mid;
      else right = mid;
    }
    return left;
  }
}


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

int main() {
  long long N,A,B;
  cin>>N>>A>>B;
  long long a=0;
  if(N%(A+B)>A){
     a=A;
  }
  else{
    a=N%(A+B);
  }
  cout<<N/(A+B)*A+a<< endl;
    
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, K;
  cin >> N >> K;
  cout << N - K + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

    #include <bits/stdc++.h>
    #define int long long
    #define endl '\n'
    #define null nullptr
    #define all(x) x.begin(),x.end()
    #define rall(x) x.rbegin(), x.rend()
    #define pb push_back
    #define mp make_pair
    #define test int t; cin>>t; while(t--)
    #define FAST                          \
        ios_base::sync_with_stdio(false); \
        cin.tie(NULL);                    \
        cout.tie(NULL)

    using namespace std;

    typedef vector<int> vi;
    typedef vector<pair<int,int>> vii;
    typedef pair<int,int> pii;
    typedef unordered_map<int,int> mp;

    const int mod = 1e9+7;



    int32_t main(){
        FAST;

    int n;   cin >> n;
    int a[n+1] , b[n+1];
    for(int x=0;x<n+1;x++) cin >> a[x+1];
    for(int x=0;x<n;x++)     cin >> b[x+1];

    int ans = 0;

    for(int x=1;x<=n;x++){

        int fi = a[x] , se = a[x+1];

        int cap = b[x];

        ans += (min(cap , fi));
        cap -= min(cap , fi);

        ans += (min(cap , se));
        a[x+1] -= min(cap , se);

    }

    cout << ans;

        return 0;
    }


Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    print(min(N*A, B))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
N,X = map(int, input().split())
L = list(map(int, input().split()))
D = [0 for _ in range(N+1)]
ans = 0
for i in range(1, N+1):
    D[i] = D[i-1] + L[i-1]
for j in range(0, N+1):
    if D[j] <= X:
        ans += 1
print(ans)

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

# O(NlogN)構築、クエリO(1)のRMQ
# 変更はできない
class SparseTable():
    def __init__(self, N, A):
        self.N = N
        self.logN = N.bit_length()
        self.A = A
        self.table = [[i for i in range(N)]]
        for k in range(self.logN):
            tab = []
            for i in range(self.N-(1<<(k+1))+1):
                ind1 = self.table[-1][i]
                ind2 = self.table[-1][i+(1<<k)]
                if self.A[ind1] <= self.A[ind2]:
                    tab.append(ind1)
                else:
                    tab.append(ind2)
            self.table.append(tab)
    
    # [l, r)のminの(val, key)
    def query_min(self, l, r):
        k = (r-l).bit_length()-1
        indl = self.table[k][l]
        indr = self.table[k][r-(1<<k)]
        if self.A[indl] <= self.A[indr]:
            return self.A[indl], indl
        return self.A[indr], indr

import heapq as hp
N = int(input())
A = list(map(int, input().split()))

def main():
    SP1 = SparseTable((N+1)//2, A[::2])
    SP2 = SparseTable(N//2, A[1::2])

    ans = []
    q = []
    v, k = SP1.query_min(0, N//2)
    dic = {}
    dic[v] = (k, 0, N//2, True)
    hp.heappush(q, v)
    for _ in range(N//2):
        valuea = hp.heappop(q)
        ka, l, r, is1 = dic[valuea]
        ans.append(str(valuea))
        if is1:
            valueb, kb = SP2.query_min(ka, r)
            if ka < kb:
                m2, nk2 = SP2.query_min(ka, kb)
                hp.heappush(q, m2)
                dic[m2] = (nk2, ka, kb+1, False)
            if l < ka:
                m1, nk1 = SP1.query_min(l, ka)
                hp.heappush(q, m1)
                dic[m1] = (nk1, l, ka, True)
            if kb+1 < r:
                m3, nk3 = SP1.query_min(kb+1, r)
                hp.heappush(q, m3)
                dic[m3] = (nk3, kb+1, r, True)
        else:
            valueb, kb = SP1.query_min(ka+1, r)
            if ka+1 < kb:
                m1, nk1 = SP1.query_min(ka+1, kb)
                hp.heappush(q, m1)
                dic[m1] = (nk1, ka+1, kb, True)
            if l < ka:
                m2, nk2 = SP2.query_min(l, ka)
                hp.heappush(q, m2)
                dic[m2] = (nk2, l, ka+1, False)
            if kb < r-1:
                m3, nk3 = SP2.query_min(kb, r-1)
                hp.heappush(q, m3)
                dic[m3] = (nk3, kb, r, False)

        ans.append(str(valueb))

    print(" ".join(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 147540
#include<bits/stdc++.h>
#define ll  long long int
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define inf 1000000000000LL
#define fast_io	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define range 200005
#define lg 22
using namespace std;
ll visited[range];
vector<ll>g[range];
ll sub[range];
void dfs(ll u,ll p)
{
	if(visited[u])return;
	visited[u]=1;
	ll s=1;
	for(auto i:g[u])
	{
		if(i==p||visited[i]==1)continue;
		dfs(i,u);
		s+=sub[i];
	}
	sub[u]=s;
}
int main()
{
	ll n,m,x,y;
	cin>>n>>m;
	ll ans=0;
	for(ll i=1;i<=m;i++)
	{
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);		
	}
	
	for(ll i=1;i<=n;i++)
	{
		if(visited[i]==1)continue;
		
		dfs(i,-1);
		ans=max(ans,sub[i]);
	}
	
	cout<<ans<<endl;
	
	
}

Measured memory_bytes: 33264
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <cmath>

int main(void){
    int n;
    std::cin >> n;
    char s[n];
    std::cin >> s;
    int k;
    std::cin >> k;


    for(int i = 0; i < n; i++){
        if(s[k-1] == s[i]) continue;
        s[i] = '*';
    }

    std::cout << s;
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int A,B,C,X,Y;
    cin>>A>>B>>C>>X>>Y;

    C*=2;

    int ans=1e18;
    for(int c=0;c<=max(X,Y);c++){
        int a=max(0LL,X-c);
        int b=max(0LL,Y-c);
        int cost=A*a+B*b+C*c;
        ans=min(ans,cost);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int x = a*b;
        if (x%2 == 0){
            System.out.println("Even");
        }
        else{
            System.out.println("Odd");
        }
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define int long long int
    int h,a,cnt=0;
    cin>>h>>a;
    while(1)
    {
        h-=a;
        cnt++;
        if(h<=0)break;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

alias Kukan = Tuple!(int, "l", int, "r");

void main() {
    int N;
    scan(N);

    Kukan[] ks;

    foreach (i ; 0 .. N) {
        int xi, li;
        scan(xi, li);
        ks ~= Kukan(xi - li, xi + li);
    }

    ks.sort!"a.r < b.r"();

    int p = -inf;
    int ans;

    foreach (i ; 0 .. N) {
        if (p <= ks.front.l) {
            ans++;
            p = ks.front.r;
        }
        ks.popFront();
    }

    writeln(ans);
}




void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 3964
// in the name of Allah

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

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

#define inf 1e9
#define max_n 123456
#define mod 1000000007

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

int n;
ll dp[1<<16];
int a[16][16];
ll cost[1<<16];
vector <int> g[1<<16];

ll memo(int msk) {
	if(msk == 0) return 0;
	if(dp[msk] != -1) return dp[msk];
	vector <int> v;
	for(int i=0; i<n; i++) if((msk&(1<<i)) > 0) v.pb(1<<i);
	ll res = 0;
	auto go = [&msk, &res, &v] (int MSK, int idx, auto &func) {
		if(idx == sz(v)) {
			if(MSK > 0) res = max(res, cost[MSK] + memo(msk^MSK));
			return;
		}
		func(MSK, idx+1, func);
		func(MSK|v[idx], idx+1, func);
	};
	go(0, 0, go);
	return dp[msk] = res;
}

int main() {
	// ll start = clock();
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i=0; i<n; i++) for(int j=0; j<n; j++) cin >> a[i][j];
	vector <int> v;
	for(int msk=0; msk<(1<<n); msk++) {
		v.clear();
		cost[msk] = 0;
		for(int i=0; i<n; i++) if((msk&(1<<i)) > 0) v.pb(i);
		for(int i=0; i<sz(v); i++) {
			for(int j=i+1; j<sz(v); j++) {
				cost[msk] += a[v[i]][v[j]];
			}
		}
	}
	memset(dp, -1, sizeof dp);
	cout << memo((1<<n)-1) << endl;
	// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
	return 0;
}

Measured memory_bytes: 2816
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	ll h, w, x, y;
	cin >> w >> h >> x >> y;
	bool judge = false;
	long double ans;
	if (h%2==0&&w%2==0) {
		ans = h * w / 2;
		if (w == 2 * x && h == 2 * y)judge = true;
	}
	else {
		judge = false;
		ans = h * w;
		ans /= 2;
	}
	cout << ans << " ";
	cout << judge << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int h,w;
    char s[55][55];
    cin >> h >> w;
    for(int i = 0;i<h;i++){
        for(int j = 0;j<w;j++){
            cin >> s[i][j];
        }
    }
    const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
    const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
    for(int i = 0;i<h;i++){
        for(int j = 0;j<w;j++){
            if(s[i][j] == '#'){
                continue;
            }
            int count = 0;
            for(int k = 0;k<8;k++){
                int x = j + dx[k];
                int y = i + dy[k];
                if(x<0 || w<=x){
                    continue;
                }
                if(y<0 || h<=y){
                    continue;
                }
                if(s[y][x] == '#'){
                    count++;
                }
            }
            s[i][j] = count + '0';
        }
    }
    for(int i = 0;i<h;i++){
        for(int j = 0;j<w;j++){
            cout << s[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
typedef long long int lli;
#define mod 1000000007
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string a,b;
    int n,m;
    cin>>a;
    cin>>b;
    n=a.length();
    m=b.length();
    int minn=INT_MAX;
    int count;
    for (int i=0;i<=(n-m);i++){
        count=0;
        for (int j=i;j<i+m;j++){
            if (a[j]!=b[j-i]){
                count+=1;
            }
        }
        if (count<minn){
            minn=count;
        }
    }
    cout<<minn<<'\n';
}

Measured memory_bytes: 3564
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int vx[4] = { 0,1,0,-1 };
int vy[4] = { 1,0,-1,0 };


int main(void)
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int count = 0;
	string str;
	cin >> str;
	REP(i, 3) {
		if (str[i] == '1') count++;
	}
	cout << count;
}

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

using namespace std;

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

	int best, lowest;
	cin >> lowest;
	best = numeric_limits<int>::min();

	while (--n) {
		int R;
		cin >> R;

		best = max(best, R - lowest);
		lowest = min(lowest, R);
	}

	cout << best << endl;
}


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

int main() {
	int n,ret,cnt[10001]={0};
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> ret;
		cnt[ret]++;
	}

	for(int i = 1; i < 10001; i++)
		cnt[i] += cnt[i-1];

	for(int i = 0, j = 0; i < n; i++){
		while(i == cnt[j]) j++;
		
		cout << j;
		if(i == (n-1)); else cout << " ";
		
	}
	cout << endl;
}

Measured memory_bytes: 1208
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
    int n,m ;
    char a[55][55],b[55][55] ;
    scanf ("%d%d",&n,&m) ;
    for (int i=0; i<n; i++){
        scanf ("%s",a[i]) ;
    }
    for (int i=0; i<n; i++){
        scanf ("%s",b[i]) ;
    }
    for (int i=0; i<n-m+1; i++){
        for (int j=0; j<n-m+1; j++){
            for (int k=0; k<m; k++){
                if (strncmp(b[k],a[i+k]+j,m)!=0){
                    break ;
                } else if (k==m-1) {
                    printf ("Yes\n") ;
                    exit (0) ;
                }
            }
        }
    }
    printf ("No\n") ;
	return 0 ;
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <regex>

using namespace std;

int main()
{
  string pattern;
  cin >> pattern;
  
  auto raw_pattern = R"(\b)" + pattern + R"(\b)";

  regex reggie { raw_pattern , regex::icase};

  int count {0};

  for (string line; getline(cin, line);) {
    if (line == "END_OF_TEXT") break;
    auto matches_begin = sregex_iterator(line.begin(), line.end(), reggie);
    auto matches_end = sregex_iterator();
    count += distance(matches_begin, matches_end);
  }
  
  cout << count << endl;
}


Measured memory_bytes: 3296
#include <iostream>

using namespace std;

int linerserch(int n,int A[],int key){
  for(int i=0;i<n;i++){
    if(A[i] == key) return 1;
  }
  return 0;
}

int main(){
  int n,A[10010],b,m;
  int cnt = 0;
  cin >> n;
  for(int i=0;i<n;i++){
     cin >> A[i];
   }
  cin >> m;
  for(int j = 0;j<m;j++) {
    cin >> b;
    if(linerserch(n,A,b) == 1) cnt++;
  }
  cout << cnt << '\n';
}



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

//***********************************************************************
int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{
    int n,m;
    cin >> n >> m;
    vector<int> v(n);
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin >> v[i];
        sum+=v[i];
    }
    sort(v.begin(),v.end(),greater<int>());
    float val=(float)(sum)/(float)(4*(m));
    int count=0;
    for(int i=0;i<n;i++)
    {
        if((float)v[i]>=val)
        count++;
    }
    if(count>=m)
    cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
    
 }


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF 0x3f3f3f3f
#define MAX 100010

ll dp[MAX];
bool been[MAX];
int n,k, v[MAX];

ll f(int i){
    if(i >= n) return INF;
    if(i == n-1) return 0;
    if(been[i]) return dp[i];
    been[i] = true;
    ll r = INF;
    for(int j = i+1;j<=i+k;j++){
        if(j >= n) break;
        r = min(r,f(j)+abs(v[i]-v[j]));
    }
    return dp[i] = r;
}
int main(){
    cin >> n >> k;   
    for(int i = 0;i<n;i++) cin >> v[i];
    cout << f(0) << '\n';
    return 0;
}

Measured memory_bytes: 6272
#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(){
	LL N;
	cin >> N;
	LL ans=1, res=0;
	LL x[1000010]={0};
	LL num = N-1;
	for(LL i=2; i*i<=N-1; i++){
		while(num%i==0){
			x[i]++;
			num/=i;
		}
	}
	for(LL i=2; i*i<=N-1; i++) ans*=x[i]+1;
    if(num!=1) ans*=2;
	for(LL K=2; K*K<=N; K++){
		LL Nc=N;
		while(Nc%K==0) Nc/=K;
		if(Nc%K==1) res++;
	}
	cout << res+ans/2+1 << endl;

	return 0;
}


Measured memory_bytes: 8192
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int N = S.length();
        boolean[] dp = new boolean[N];
        for(int n=0;n<N;n++){
        	if(n>=4 && S.substring(n-4,n+1).equals("dream"))   dp[n]=dp[n]||(n==4)||dp[n-5];
        	if(n>=6 && S.substring(n-6,n+1).equals("dreamer")) dp[n]=dp[n]||(n==6)||dp[n-7];
        	if(n>=4 && S.substring(n-4,n+1).equals("erase")) dp[n]=dp[n]||(n==4)||dp[n-5];
        	if(n>=5 && S.substring(n-5,n+1).equals("eraser")) dp[n]=dp[n]||(n==5)||dp[n-6];
        }
        System.out.println(dp[N-1] ? "YES" : "NO");
    }
}


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

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i=1;i<=n;i++){
        if(i%3 == 0 || i%5 ==0) continue;
        ans += i;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
ll n, k, a[1000], sum[1000000], s, o, f, m;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for(ll i = 0; i < n; i++)
		cin >> a[i];
	f = 0;
	for(ll i = 0; i < n; i++) {
		s = 0;
		for(ll j = i; j < n; j++) {
			s += a[j];
			sum[f] = s;
			f++;
		}
	}
	bool check[f + 1];
	for(ll i = 0; i < f; i++)
		check[i] = true;
	for (ll i = 50; i > 0; i--) {
        o = 0;
        for (ll j = 0; j < f; j++)
            if (check[j])
                if ((sum[j] >> i) & 1) 
                	o++;
        if (o >= k)
            for (ll j = 0; j < f; j++)
                if (check[j])
                    if (!((sum[j] >> i) & 1)) 
                    	check[j] = false;
    }
    ll ans = LLONG_MAX;
    for (ll i = 0; i < f; i++)
        if (check[i]) 
        	ans &= sum[i];
    cout << ans;
}

Measured memory_bytes: 4992
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		long[][] dp = new long[n-1][21];
		dp[0][sc.nextInt()] = 1;
		for(int i=1;i<n-1;i++){
			int t = sc.nextInt();
			for(int j=0;j<=20;j++){
				if(j-t>=0) dp[i][j] += dp[i-1][j-t];
				if(j+t<=20) dp[i][j] += dp[i-1][j+t];
			}
		}
		System.out.println(dp[n-2][sc.nextInt()]);
	}
}

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

#define f first
#define s second
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define px pair<db, db>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define input(a) for (auto& el : a) cin >> el;
#define output(a) cout << '!'; for (auto& el : a) cout << el << ' '; cout << '\n'; cout.flush();
#define sz(el) int(el.size())
#define sq(a) ((a) * (a))
#define xll bitset<128>
#define xmin(a,b) a = min(a, b)
#define xmax(a,b) a = max(a, b)
#define sun(a) sort(all(a)); a.resize(unique(all(a)) - a.begin());
/**/  /// extra
//#define forn(i,n) for (int i = 0; i < n; ++i)
//#define rforn(i,n) for (int i = n - 1; i >= 0; --i)
#define bn '\n'
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
//#define G vector<vector<pii>>
#define GVE vector<vector<edge>>
#define usi unordered_set<int>
#define usp set<pii>
/**/

using namespace std;

const int INF = 1'000'000'017;
const ll LLINF = 1'000'000'000'000'000'017LL;
const ld inf = 1.0 / 0.0;
const ld eps = 1e-9;
const int MOD = 998244353;

//mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

//uniform_int_distribution<int> uid(l, r); [l, r]
//int x = uid(rng);

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

    string s;
    cin >> s;
    if (s == "Sunny") {
        cout << "Cloudy";
    } else if (s == "Cloudy") {
        cout << "Rainy";
    } else {
        cout << "Sunny";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N;
    long long int sum = 0;
    cin >> N;
    for(int i=1; i<=N; i++){
        if(i%3==0 || i%5==0) continue;
        sum += i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main() {
	int N; cin >> N;
	int n = N / 2;
	vector<ll> A(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i];
	vector<ll> acc(N + 1, 0);
	acc[1] = A[0];
	for (int i = 2; i <= N; ++i)
		acc[i] = acc[i - 2] + A[i - 1];

	ll res = 0;

	// A1 A3 A5 ...
	for (int i = 0; i <= 2 * n - 2; i += 2)
		res += A[i];

	// A2 A4 A6 ....
	ll tmp = 0;
	for (int i = 1; i < N; i += 2)
		tmp += A[i];

	res = max(tmp, res);

	if (N % 2) {
		// A3 A5 A7 ...
		tmp = 0;
		for (int i = 2; i < N; i += 2)
			tmp += A[i];
		res = max(res, tmp);
	}

	// A1 A3 ... A[2i-1],  A[j] A[j+2] ... A[j + (n-i-1) * 2]
	for (int i = 1; i < n; ++i) {
		tmp = acc[2 * i - 1];
		ll additional = -(1LL << 60);
		for (int j = 2 * i + 2; j <= N - 2 * n + 2 * i + 2; ++j) {
			ll add = acc[j + (n - i - 1) * 2] - (j >= 2 ? acc[j - 2] : 0);
			additional = max(additional, add);
		}
		tmp += additional;
		res = max(res, tmp);
	}

	// A2 A4 ... A[2i], A[j] A[j + 2] ... A[j + (n-i-1) * 2]
	for (int i = 1; i < n; ++i) {
		tmp = acc[2 * i];
		ll additional = -(1LL << 60);
		for (int j = 2 * i + 3; j <= N - 2 * n + 2 * i + 2; ++j) {
			ll add = acc[j + (n - i - 1) * 2] - (j >= 2 ? acc[j - 2] : 0);
			additional = max(additional, add);
		}
		tmp += additional;
		res = max(res, tmp);
	}

	if (N % 2) {
		vector<vector<ll>> dp(N, vector<ll>(3, 0));
		dp[0][0] = A[0];
		// dp[0][2] = A[0];
		dp[1][0] = A[0];
		dp[1][1] = A[1];
		// dp[1][2] = A[0];
		for (int i = 2; i < N; ++i) {
			// そのまま継続
			for (int j = 0; j < 3; ++j)
				dp[i][j] = dp[i - 1][j];
			if (i % 2) {
				dp[i][1] += A[i];
			}
			else {
				dp[i][0] += A[i];
				dp[i][2] += A[i];
			}
			if (i % 2) {
				// 0 -> 1移行
				if (i >= 3) {
					tmp = dp[i - 3][0] + A[i];
					dp[i][1] = max(dp[i][1], tmp);
				}
			}
			else {
				// 1 -> 2移行
				if (i >= 3) {
					tmp = dp[i - 3][1] + A[i];
					dp[i][2] = max(dp[i][2], tmp);
				}
			}
		}
		tmp = max({ dp[N - 1][1], dp[N - 1][2] });
		res = max(tmp, res);
	}

	cout << res << endl;
	return 0;
}


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

using namespace std;

#define ll long long
#define ini(arr, val) memset(arr, (val), sizeof(arr))
#define loop(i,n)  for(ll i=0; i<n; i++)
#define loop1(i,n)  for(ll i=1; i<=n; i++)

#define all(a)      (a).begin(),(a).end()
#define dupli(a)     unique(all(a)),(a).end()
#define exist(s,e)  (s.find(e)!=s.end())
#define dbg(x)  cout << #x << " is " << x << endl;
#define pt(x) cout<<x<<"\n"
#define pts(x) cout<<x<<" "

#define mp make_pair
#define pb push_back
#define F first
#define S second


#define inf (int)1e9
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007


#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test   int t; cin>>t; while(t--)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef set<int> si;

typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
typedef map<ll,ll> mll;
typedef set<ll> sl;


//////////////////////////////////////////////////////////////////////////////////////////
//                      main starts
//////////////////////////////////////////////////////////////////////////////////////////
int const lmt=1e5+5;

int checkbit(int n,int k){
	int rem,q,c=0;
	while(n>0){
		c++;
		rem=n%k;
		
		n/=k;
	}
	return c;
}



int main(){

   

    ll n,k;
    cin>>n>>k;
    pt(checkbit(n,k));
    
    

}


/*

// 

*/

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

int main() {
	string s;
	cin >> s;

	int i = 0;
	if (s[0] == '1') i++;
	if (s[1] == '1') i++;
	if (s[2] == '1') i++;

	cout << i << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ll = long long;
using ii = pair<int, int>;
#define MAXN 200010
vector<int> adj[MAXN];
bitset<MAXN> visited;

void solve(){
	int n, m;
	cin >> n >> m;
	for(int i=0; i<m; ++i){
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	int ans = 0;
	for(int u=1; u<=n; ++u){
		if(visited[u]) continue;
		queue<int> q;
		q.push(u);
		visited[u] = true;
		int res = 0;
		while(not q.empty()){
			++res;
			int v = q.front(); q.pop();
			for(auto w:adj[v]){
				if(visited[w]) continue;
				visited[w] = true;
				q.push(w);
			}
		}
		ans = max(ans, res);
	}
	cout << ans << '\n';
}

int32_t main(){
	ios::sync_with_stdio(0);
	solve();
}

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

int n, ta =100, iwa = 0, ka = 0;

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		iwa = n - i;
		ka = i / 10000 + i / 1000 % 10 + i / 100 % 10 + i / 10 % 10 + i % 10 + iwa / 10000 + iwa / 1000 % 10 + iwa / 100 % 10 + iwa / 10 % 10 + iwa % 10;
		if (ka < ta) {
			ta = ka;
		}
	}
	cout << ta << endl;
	return 0;
}

Measured memory_bytes: 256
import math
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]

for i in range(0, math.ceil(N/M)):
    for j in range(0, math.ceil(N/M)):
        # 畳み込み
        flag = True
        for l in range(0, M):
            for m in range(0, M):
                if A[l+i][m+j] != B[l][m]:
                    flag = False
                    break
        if flag == True:
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  int a,b;
  cin >> a >> b;

  cout << max({a+b,a-b,a*b}) << endl;

}



Measured memory_bytes: 256
import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
public class Main{
	public static void main(String[] args)  throws IOException{
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);
		String str;
		double a,b,c,d,e,f,x,y;
		while((str=br.readLine())!=null){
			String[] num=str.split(" +");
            a = Double.parseDouble(num[0]);
            b = Double.parseDouble(num[1]);
            c = Double.parseDouble(num[2]);
            d = Double.parseDouble(num[3]);
            e = Double.parseDouble(num[4]);
            f = Double.parseDouble(num[5]);
/*			System.out.println(a+" "+b+" "+c+" "+d+" "+e+" "+f);
			System.out.println((b*f-c*e)+" "+(b*d-a*e));*/
            x=(b*f-c*e)/(b*d-a*e) == 0 ? 0 : (b*f-c*e)/(b*d-a*e);
            y=(a*f-c*d)/(a*e-b*d) == 0 ? 0 : (a*f-c*d)/(a*e-b*d);
			System.out.printf("%.3f %.3f\n", x,y);

		}
	}

}

Measured memory_bytes: 24720
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define nl cout<<"\n"
#define pb push_back
#define se second
#define fi first
#define pi =3.14159265358979323846264338327950L;
typedef long long int ll;
int mod=1e9+7;


int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    return 0;
}


Measured memory_bytes: 3664
#include<iostream>
#include<stdio.h>
#include<vector>
#include<string.h>
using namespace std;
const int N=100009;
vector<int> g[N];
int math[N],c[N],flag=true,n;// c 1 w，0 b； true,second,可以匹配 
void dfs(int u,int fa){

	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(v==fa)continue;
		if(flag)dfs(v,u);
		if(u&&c[v]==-1&&c[u]==-1){
			c[v]=0;//染黑 
			c[u]=1;//白	 
			math[v]=u,math[u]=v;
		}
		else if(c[u]==1&&c[v]==-1)flag=false;
	//	else if(!u&&c[v]==-1) flag=false;
	}	
}
int main(){
	int u,v;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	} 
	memset(c,-1,sizeof(c));
	dfs(1,0);
	if(c[1]==-1)flag=false;
	if(!flag)cout<<"First\n";
	else cout<<"Second\n";
	
}
 

Measured memory_bytes: 6528
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

bool canbemm(int x){
	return x>=1 && x<= 12;
}

int main(int argc, const char * argv[]) {
	string s;
	cin >> s;
	int a,b;
	a = (s[0]-'0')*10 + s[1]-'0';
	b = (s[2]-'0')*10 + s[3]-'0';
	if(canbemm(a) && canbemm(b)){
		println("AMBIGUOUS");
	}else if(canbemm(a)){
		println("MMYY");
	}else if(canbemm(b)){
		println("YYMM");
	}else{
		println("NA");
	}
	return 0;
}


Measured memory_bytes: 256
import heapq

def main():
    N, M = map(int, input().split())
    A = [int(x) for x in input().split()]
    A.sort()
    bc = []
    for _ in range(M):
        b, c = map(int, input().split())
        bc.append((b, c))

    bc = sorted(bc, key=lambda x: x[1], reverse=True)

    ai = 0
    bi = 0

    while ai < len(A) and bi < len(bc):
        a = A[ai]
        b, c = bc[bi]

        if a >= c:
            break

        A[ai] = c
        ai += 1
        b -= 1
        bc[bi] = (b, c)
        if b <= 0:
            bi += 1

    print(sum(A))


if __name__ == '__main__':
    main()

Measured memory_bytes: 23288
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  int a,b;
  cin >> a >> b;
  cout << a*b/2 << endl;
}

Measured memory_bytes: 3644
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

n,k = ma()
A = lma()
bu = []
for i in range(n):
    tmp=0
    for j in range(i,n):
        tmp+=A[j]
        bu.append(tmp)
mb = bin(max(bu))
ls = [0]*(len(mb)-2)
for b in bu:
    for i in range(len(bin(b))-2):
        if (b>>i &1):
            ls[i]+=1
ans = 0
tmp=bu
for i in range(len(mb)-3,-1,-1):
    if ls[i]<k:
        continue
    tmp2=[]
    for b in tmp:
        if (b>>i &1):
            tmp2.append(b)
    if len(tmp2)>=k:
        ans+=2**i
        tmp=tmp2
    else:
        pass
print(ans)


Measured memory_bytes: 110308
import bisect

n, d, a = [int(i) for i in input().split()]

xh = []
for i in range(n):
    xh.append([int(i) for i in input().split()])

# 座標でソート
xh.sort()

x = [xh[i][0] for i in range(n)]
h = [xh[i][1] for i in range(n)]

# i番目のモンスターに、i-k番目で使った爆弾が届いた場合の最小のi-k
bomb_bisect = []
for i in range(n):
    bomb_bisect.append(bisect.bisect_left(x, x[i]-2*d))

bomb_ruisekiwa = [0 for i in range(n)]
# 左から貪欲に爆弾を使用
for i in range(n):
    bomb = 0
    if i == 0:
        bomb = (h[i]) // a + ((h[i]) % a != 0)
        bomb_ruisekiwa[i] = bomb
    else:
        if bomb_bisect[i] == i:
            damage = 0
        elif bomb_bisect[i]-1 < 0:
            damage = (bomb_ruisekiwa[i-1]) * a
        else:
            damage = (bomb_ruisekiwa[i-1] - bomb_ruisekiwa[bomb_bisect[i]-1]) * a
        if h[i] - damage > 0:
            bomb = (h[i] - damage) // a + ((h[i] - damage) % a != 0)
        bomb_ruisekiwa[i] = bomb + bomb_ruisekiwa[i-1]

print(bomb_ruisekiwa[-1])


Measured memory_bytes: 60692
#include <stdio.h>

int main(){
    int n, sum = 0;
    scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);

    for (int i = 0; i < n-1; ++i){
        for (int j = i+1; j < n; ++j){
            //printf("a[i]: %d %d\n", a[i], a[j]);
            //printf("i: %d %d\n", i, j);
            sum += a[i] * a[j];
        }
    }
    printf("%d\n", sum);

    return 0;
}


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

int main() {
    int H, W; cin >> H >> W;
    vector<vector<char>> C(H, vector<char>(W));
    rep(i, H) {
        rep(j, W) {
            cin >> C[i][j];
        }
    }
    rep(i, H) {
        rep(j, 2) {
            rep(k, W) {
                cout << C[i][k];
                if (k == W-1) {
                    cout << endl;
                }
            }
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
	int N;
    cin >> N;
    int num = N;
    string ans = "";
    while (num > 0) {
        num--;
        ans += ('a' + num % 26);
        num /= 26;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
 
    return 0;
	
	
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 100005
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';


int main() {

	LL x, k, d, ans = 0;
	
	cin>>x>>k>>d;

	if(x == 0) {

		if(k % 2 == 0) cout<<0<<endl;
		else cout<<x+d<<endl;

		return 0;
	}

	if(x < 0) x = -x;



		LL q = min(k, x/d);
		k-=q;
		x = x - q*d;

		if(k % 2 == 0) cout<<x<<endl;
		else cout<<min(x + d, abs (x-d))<<endl;

		return 0;
	

	
}

Measured memory_bytes: 3632
import java.util.Scanner;

class Main{
    
    public static void main(String[] args){
        
        Scanner sc =new Scanner(System.in);
        
        int n=sc.nextInt();
        
        int a[][][]=new int[5][4][11];

        for(int i=0;i<n;i++){
        int b =sc.nextInt();
        int f =sc.nextInt();
        int r =sc.nextInt();
        int v =sc.nextInt();
        a[b][f][r]+=v;
        }
        
        for(int i=1;i<=3;i++){
         for(int j=1;j<=3;j++){
          for(int k=1;k<=10;k++)
          System.out.print(" "+a[i][j][k]);
          System.out.print("\n");
         }
         System.out.println("####################");
        }

         for(int j=1;j<=3;j++){
          for(int k=1;k<=10;k++)
          System.out.print(" "+a[4][j][k]);
          System.out.print("\n");
         }
      }
      
  }


Measured memory_bytes: 28988
import java.util.*;


class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();

        int d[] = new int[N];

        for (int i = 1; i <= N; i++) {
            for (int j = i + 1; j <= N; j++) {
                int dij = Math.min(j - i, Math.abs(X - i) + 1 + Math.abs(j - Y));
                dij = Math.min(dij, Math.abs(Y - i) + 1 + Math.abs(j - X));
                d[dij]++;
            }
        }

        for (int i = 1; i < N; i++) {
            System.out.println(d[i]);
        }
    }
}


Measured memory_bytes: 21840
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);
int main(){
    ll n;
    cin>>n;
    vl ress;
    ll ans =0;
    for(ll i = 1;i<=sqrt(n)+1;i++){
        if(n%i==0){
            ress.push_back(i-1);
            ress.push_back(n/i-1);
        }
    }
    rep(i,ress.size()){
        if(ress[i]==0)continue;
        if(n%ress[i]==n/ress[i])ans+=ress[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3696
#define SUBMIT

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D

#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
    string s;
#ifdef SUBMIT
        std::cin >> s;
#else
    s = R"(\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\)";
#endif
    stack<int> down_x_pos;
    // (x, area) pair
    stack<pair<int, int>> left_and_area_buffer;
    for (int x = 0; x < s.length(); ++x) {
        switch (s[x]) {
            case '\\':
                down_x_pos.push(x);
                break;

            case '/':
                if (!down_x_pos.empty()) {
                    auto left = down_x_pos.top();
                    down_x_pos.pop();
                    auto a = x - left;
                    while (!left_and_area_buffer.empty() && left < left_and_area_buffer.top().first) {
                        a += left_and_area_buffer.top().second;
                        left_and_area_buffer.pop();
                    }
                    left_and_area_buffer.emplace(left, a);
                }
                break;

            default:
                break;
        }
    }

    // arrange
    vector<int> areas;
    while (!left_and_area_buffer.empty()) {
        areas.emplace_back(left_and_area_buffer.top().second);
        left_and_area_buffer.pop();
    }

    reverse(areas.begin(), areas.end());
    auto sum_area = accumulate(areas.begin(), areas.end(), 0);

    // print
    cout << sum_area << endl;
    cout << areas.size();
    for (int area : areas) {
        cout << " " << area;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3280
#include <bits/stdc++.h>
#define per(i,a,n) for(int i=a;i<=n;i++)
using namespace std;
typedef long long ll;
typedef vector<ll>vec;
typedef vector<vector<ll>> mat;
const int N=1e5+100;
vector<int>a[N];
vector<int>b[N];
int out[N],cnt[N];
int n,m,k;
int color[N],color_num[N],vis[N],num;
void dfs(int x)
{
    vis[x]=1;
    color[x]=num;
    for(auto v:a[x]){
        if(!vis[v])
        {
            color[v]=num;
            color_num[num]++;
            vis[v]=1;
            dfs(v);
        }
    }
}
int main()
{
  cin>>n>>m>>k;
  int x,y;
  per(i,1,m){
   scanf("%d%d",&x,&y);
   out[x]++;out[y]++;
   a[x].push_back(y);
   a[y].push_back(x);
  }
  per(i,1,k){
   scanf("%d%d",&x,&y);
   b[x].push_back(y);
   b[y].push_back(x);
  }
  per(i,1,n){
   if(!vis[i]){num++;dfs(i);}
  }
  per(i,1,num) color_num[i]++;
   per(i,1,n){
     for(auto v:b[i]){
        if(color[i]==color[v])cnt[i]++;
     }
   }
   per(i,1,n){
     // cout<<color_num[color[i]]<<endl;
     // cout<<out[i]<<endl;
     // cout<<cnt[i]<<endl;
      int ans=color_num[color[i]]-out[i]-cnt[i]-1;
      cout<<ans<<" ";
   }
  return 0;
}



Measured memory_bytes: 13440
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

l = [0]*(N+1)
for a in A:
    l[a] += 1

for i in range(1, N+1):
    if Q-l[i] < K:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 8636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int a[8];
  for(int i=0;i<8;i++){
    a[i]=pow(2,i);
  }
  for(int i=0;i<8;i++){
    if(a[i]<=N && a[i+1]>N ){
      cout<<a[i]<<endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define loopinc(i, a, b, inc) for(int i = a; i < (b); i += inc)
#define loop(i, a, b) for(int i = a; i < (b); i++)
#define rep(i, n) loop(i, 0, n)
#define rrep(i, n) for (int i = n-1; i >= 0; i--)
#define endl "\n"
#define all(c) (c).begin(),(c).end()
#define lloopinc(i, a, b, inc) for(ll i = a; i < (b); i += inc)
#define lloop(i, a, b) for(ll i = a; i < (b); i++)
#define lrep(i, n) lloop(i, 0, n)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tuple<int, int, int> tiii;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

constexpr int MAX = 1000001;
bitset<MAX> space;
vector<int> state;

signed main() {
	// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	vi arr(n);
	rep(i, n) cin >> arr[i];
	sort(all(arr));
	space.reset();
	state.resize(MAX);

	int total = n;
	rep(i, n) {
		if (space[arr[i]]) {
			total--;
			if (state[arr[i]] == 1) {
				total--;
				state[arr[i]]++;
			}
		} else {
			for (int j = arr[i]; j < MAX; j += arr[i])
				space[j] = 1;
			state[arr[i]]++;
		}
	}
	cout << total << endl;
}


Measured memory_bytes: 7952