akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>

using namespace std;

using ll = long long;

void solve(vector<set<int>> &tree, vector<ll> &cnts, int key = 0, int parent = -1) {
  for (auto child : tree[key]) {
    if (child == parent) {
      continue;
    }

    cnts[child] += cnts[key];
    solve(tree, cnts, child, key);
  }
}

int main(int argc, const char *argv[])
{
  int n, q;
  cin >> n >> q;

  vector<set<int>> tree(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].insert(b);
    tree[b].insert(a);
  }

  vector<ll> cnts(n, 0);
  for (int i = 0; i < q; i++) {
    int p;
    ll x;
    cin >> p >> x;
    p--;
    cnts[p] += x;
  }

  solve(tree, cnts);
  for (int i = 0; i < cnts.size(); i++) {
    cout << cnts[i];
    if (i != n - 1) {
      cout << " ";
    }
  }

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


Measured memory_bytes: 47744
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,k,i,j,a,d,c=0;
  cin>>n>>k;
  vector<int> f(n);
  for(i=0;i<k;i++){
    cin>>d;
    for(j=0;j<d;j++){
      cin>>a;
      f.at(a-1)=1;
    }
  }
  for(i=0;i<n;i++) if(f.at(i)==0) c++;
  cout<<c<<endl;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>

using namespace std;


int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        
        int customer[10001]={0};
        for(int i=0; i<n; i++){
            cin>>customer[i];
        }
        
        sort(customer,customer+n);
        
        long long int wait=0;
        long long int ret=0;
        
        for(int i=0; i<n; i++){
            ret+=wait;
            wait+=customer[i];
            
        }
        
        cout<<ret<<endl;
    }
       
}

Measured memory_bytes: 1212
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;

int h, w, n;
int x[1000][2], y[1000][2];
vector<int> xs, ys, z;
bool a[2500][2500];
long long int ans;
typedef pair<int, int> P;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
queue<P> q, r;

void bfs(int s, int t){
	if(a[s][t]) return;
//	printf("%d %d\n", s, t);
	ans++;
	q = r;
	q.push(P(s, t));
	while(!q.empty()){
		P p = q.front(); q.pop();
		a[p.first][p.second] = true;
		for(int i=0; i<4; i++){
			int nx = p.first+dx[i];
			int ny = p.second+dy[i];
			if(0 <= nx && 0 <= ny && nx < xs.size()-1 && ny < ys.size()-1)
				if(!a[nx][ny]){
					q.push(P(nx, ny));
					a[nx][ny] = true;
				}
		}
	}
}

int main(){
	while(1){
		scanf("%d %d", &w, &h);
		if(w == 0 && h == 0) break;
		scanf("%d", &n);
		for(int i=0; i<n; i++) scanf("%d %d %d %d", &x[i][0], &y[i][0], &x[i][1], &y[i][1]);

		xs.push_back(0);
		ys.push_back(0);
		xs.push_back(w);
		ys.push_back(h);
		for(int i=0; i<n; i++){
			for(int j=0; j<2; j++){
				xs.push_back(x[i][j]);
				ys.push_back(y[i][j]);
			}
		}
		sort(xs.begin(), xs.end()); sort(ys.begin(), ys.end());
		xs.erase(unique(xs.begin(), xs.end()), xs.end());
		ys.erase(unique(ys.begin(), ys.end()), ys.end());
/*
		for(int i=0; i<xs.size(); i++) printf("%d\n", xs[i]);
		for(int i=0; i<ys.size(); i++) printf("%d\n", ys[i]);
*/
		for(int i=0; i<n; i++){
			for(int j=0; j<2; j++){
				x[i][j] = find(xs.begin(), xs.end(), x[i][j]) - xs.begin();
				y[i][j] = find(ys.begin(), ys.end(), y[i][j]) - ys.begin();
			}
		}
/*
		for(int i=0; i<n; i++){
			printf("%d %d %d %d\n", x[i][0], y[i][0], x[i][1], y[i][1]);
		}
*/
		memset(a, 0, sizeof(a));
		for(int i=0; i<n; i++){
			for(int j=x[i][0]; j<x[i][1]; j++){
				for(int k=y[i][0]; k<y[i][1]; k++){
					a[j][k] = true;
				}
			}
		}
/*
		for(int i=0; i<xs.size(); i++){
			for(int j=0; j<ys.size(); j++){
				if(a[i][j]) printf("1 ");
				else printf("0 ");
			}
			printf("\n");
		}
*/
//		printf("%lu %lu\n", xs.size(), ys.size());

		ans = 0;
		for(int i=0; i<xs.size()-1; i++){
			for(int j=0; j<ys.size()-1; j++){
				bfs(i, j);
			}
		}

		printf("%lld\n", ans);
	}
}

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

using namespace std;

int main() {
	int N, W;
	cin >> N >> W;
	int weight[110], value[110];
	int dp[110][10010];
	for (int i = 0; i < N; i++) cin >> value[i] >> weight[i];

	for (int w = 0; w <= W; w++) dp[0][w] = 0;

	for (int i = 0; i < N; i++) {
		for (int w = 0; w <= W; w++) {
			if (w >= weight[i]) dp[i + 1][w] = max(dp[i][w - weight[i]] + value[i], dp[i][w]);
			else dp[i + 1][w] = dp[i][w];
		}
	}

	cout << dp[N][W] << endl;

	return 0;
}



Measured memory_bytes: 7052
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 5e3 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int cur = 0;
	int ans = 0;
	int n, t;
	cin >> n >> t;
	while (n--)
	{
		int x;
		cin >> x;
		cur = max(cur, x);
		ans += x + t - cur;
		cur = x + t;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int n,d;cin>>n>>d;
    int x[n][d];
    
    rep(i,n)rep(j,d)cin>>x[i][j];
    
    int ans = 0;
    rep(i,n)rep(j,i){
        int tmp = 0;
        rep(k,d)tmp+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        
        int tmp2 = tmp;
        tmp2 = sqrt(tmp2);
        tmp2*=tmp2;
        if(tmp==tmp2)++ans;
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
      int h,n,sum=0;
      cin>>h>>n;
      for(int i=0;i<n;i++)
      {
        int x;
        cin>>x;
        sum+=x;
        if(sum>=h)
        {
          cout<<"Yes";
          return 0;
        }
      }
      cout<<"No";
      return 0;
    }

Measured memory_bytes: 764
n = input()
xs = input().split(' ')
xs = [int(x) for x in xs]
xs = set(xs)
xs = list(xs)
xs.sort()
a = [x for x in xs if x % 2 == 1]
if len(a) > 0:
    print(0)
else:
    m = 10 ** 9
    for x, y in zip(xs[:-1], xs[1:]):
        q = y - x
        if q < m:
            m = q
    if m > xs[0]:
        m = xs[0]
    count = 0
    while m % 2 == 0:
        count += 1
        m = m / 2
    print(count)

Measured memory_bytes: 3064
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
ng = -1
ok = 10**12+100
while ok - ng > 1:
    mid = (ok + ng) // 2
    c = 0
    for a,f in zip(A,F):
        c += max(0,a-mid//f)
    if c <= K:
        ok = mid
    else:
        ng = mid
print(ok)

Measured memory_bytes: 119500
import math

n = 15  # 切り捨てしたい桁

L = int(input())
a = math.floor(L / 3 * 10 ** n) / (10 ** n)
b = math.floor(((L - a) / 2) * 10 ** n) / (10 ** n)
c = L - a - b

print(a * b * c)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	int len=s.length();
	if(s[0]==s[len-1])
		if(len%2==1)cout<<"Second";
		else cout<<"First";
	else if(len%2==1)cout<<"First";
		else cout<<"Second";
	return 0;
 } 

Measured memory_bytes: 512
#include<stdio.h>
#include <stdlib.h>
int main(){
    long int n,k;
  	scanf("%ld %ld",&n,&k);
  	long int n1,n2;
      n1=n%k;
      n2=k-n1;
  if(n1>=n2)
    printf("%ld\n",n2);
  else
    printf("%ld\n",n1);
}



Measured memory_bytes: 128
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   long N = sc.nextLong();
   long M = sc.nextLong();
   long ans = 0;
   
   if(N==1||M==1)
   {
     if(N==1&&M==1) ans =1;
     else if(N==1) ans =M-2;
     else if(M==1) ans = N-2;
   }
   else ans = (N-2)*(M-2);
   System.out.println(ans);
 }
}

Measured memory_bytes: 21844
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        while (true) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            int s = sc.nextInt();
            if (x == 0 && y == 0 && s == 0) {
                return;
            }
            int ans = 0;
            for (int i = 1; i < s; i++) {
                for (int j = 1; j < s; j++) {
                    int res = i * (100 + x) / 100 + j * (100 + x) / 100;
                    if (res == s) {
                        int res2 = i * (100 + y) / 100 + j * (100 + y) / 100;
                        ans = Math.max(ans, res2);
                    }
                }
            }
            System.out.println(ans);
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}



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

int main(){
    long long int N,sum=0;
    cin >> N;
    long long int A[N*3];
    for(int i=0;i<N*3;i++) cin >> A[i];

    sort(A,A+3*N,greater<int>());
    for(int i=0;i<N;i++){
      sum += A[i*2+1];
    }
    cout << sum << endl;

}


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

void insertion(std::vector<int>& a, int n){
    for(int i=0;i<n;i++){
        int v = a[i];
        int j = i-1;
        while(j>=0 && a[j]>v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        for(int k=0;k<n;k++){
            std::cout << a[k];
            if(k<n-1){
                std::cout << " ";
            }else{
                std::cout << '\n';
            }
        }
    }
}


int main(){
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for(int i=0;i<n;i++){
        std::cin >> a[i];
    }
    insertion(a,n);
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using ll = long long;
using namespace std;
const ll mod = 1000000007;

int main() {
    int N;
    ll ans = 1;
    cin >> N;
 
    for (int i = 1; i <= N; i++) {
        ans = (ans * i) % mod;
    }
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

ll l, r;

int main() {
    cin >> l >> r;
    ll ans = 2019;
    for (ll i = l; i < min(r,l+2100); i++) {
        for (ll j = i+1; j <= min(r, l+2100); j++) {
            ans = min(ans, i*j%2019);
        }
    }
    cout << ans << endl;
}


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

//#define N 244140625 // 5^12
#define N 48828125 // 5^11
#define TRUE 1
#define FALSE 0

char H[N];

void init(){
  int i;
  for(i=0; i<N; i++){
    H[i] = FALSE;
  }
}

int getNum(char c){
  switch (c) {
    case 'A': return 1;
    case 'C': return 2;
    case 'G': return 3;
    case 'T': return 4;
  }
  return 0;
}

// convert character string to Quintuple
int convertCtoI(char *str){
  long long i, sum=0, p=1;
  for(i=0; i<strlen(str); i++){
    sum += p * getNum(str[i]);
    p *= 5;
  }
  return sum;
}

void insert(char *str){
  H[convertCtoI(str)]= TRUE;
}

int find(char *str){
  if(H[convertCtoI(str)])  return 1;
  else return 0;
}

int main(){
  int i,n;
  char str[13], command[7];

  init();

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%s %s",command, str);
    if(!strcmp(command, "insert")){
      insert(str);
    }
    else if(!strcmp(command, "find")){
      if(find(str)){
        printf("yes\n");
      }
      else printf("no\n");
    }
  }

  return 0;
}



Measured memory_bytes: 49352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

	/* several useful subroutines */
	private static final BigDecimal BD1000000007 = new BigDecimal(1000000007);
	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	private static BigDecimal mod1000000007(BigDecimal bd) {
		return bd.subtract(BD1000000007.multiply(bd.divide(BD1000000007, BigDecimal.ROUND_DOWN))) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(int i) {
		return mod1000000007(new BigDecimal(i)) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(long l) {
		return mod1000000007(new BigDecimal(l)) ;
	}

	
	/* main routine */
	public static void main(String args[]) throws IOException {
		int a = getInt();
		int b = getInt();
		int ans = (b+a-3) / --a;
		System.out.println(ans);
	}
}


Measured memory_bytes: 21076
#include <iostream>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {

  string s; cin >> s;
  for(auto &c: s){
    if(c == '1')
      cout << 9;
    else
      cout << 1;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> List = new ArrayList<>();
        ArrayList<Long> L = new ArrayList<>();
        int N = sc.nextInt();
        int M = sc.nextInt();
        L.add((long)0);
        L.add((long)1);
        int num = 0;
        for(int i=0;i<M;i++) List.add(sc.nextInt());
        List.add(0);
        for(int i=2;i<N+2;i++){
            if(List.get(num)+2!=i+1){
                long sec = (L.get(i-1)+L.get(i-2))%1000000007;
                L.add(sec);
            }
            else if(List.get(num)+2==i+1){
                long sec = 0;
                L.add(sec);
                num++;
            }
        }
        System.out.println(L.get(L.size()-1));
    }
}

Measured memory_bytes: 48112
X, N = map(int, input().split(" "))
if N != 0:
  P = set(map(int, input().split(" ")))
  assert len(P) == N
else:
  P = set([])

for i in range(102):
  if X - i not in P:
    print(X - i)
  elif X + i not in P:
    print(X + i)
  else:
    continue
  break


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

using namespace std;

int main(){
    int N;cin>>N;
    vector<int> B(N,0);
    for(int i=0;i<N-1;i++)cin>>B[i];
    B[N-1]=100010;
    int ans=0;
    ans+=B[0];
    for(int i=0;i<N-1;i++){
        ans+=min(B[i],B[i+1]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import math

N=int(input())
x=[0]*N; y=[0]*N;
for i in range(N):
  x[i],y[i]=map(int,input().split())
count=[0]*N
for j in range(N):
  for k in range(N):
    if(k!=j):
      count[j]+=math.sqrt((x[j]-x[k])**2+(y[j]-y[k])**2)
res=0
for l in range(N):
  res+=count[l]
print(res/N)

Measured memory_bytes: 9068
#include <iostream>
#include <string>

using namespace std;
 
int main() {

    string obj;
    cin >> obj;

    int pc;
    cin >> pc;

    string direction;
    string xchange;

    int a, b;

    for (int i=0; i<pc; i++)
    {
        cin >> direction;
        if (direction == "replace")
        {
            cin >> a >> b >> xchange;
            obj.replace(a,b-a+1,xchange);
        }
        else if (direction == "reverse")
        {
            cin >> a >> b;
            string partial = obj.substr(a, b-a+1);

            string obj_s = "";
            if (a != 0)
            {
                obj_s = obj.substr(0, a);
            }

            string obj_e = "";

            if (b != obj.size()-1)
            {
                // obj.size()
                obj_e = obj.substr(b+1, obj.size()-(b+1));
            }

            string obj_xc = "";

            for (int j=b-a; j>=0; j--)
            {
                obj_xc += partial[j];
            }
            obj = obj_s + obj_xc + obj_e;
        }
        else if (direction == "print")
        {
            cin >> a >> b;
            // 二つ目の引数は置換文字数であることに注意
            cout << obj.substr(a, b-a+1) << endl;
        }
    }
    return 0;
}


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

int N;
char S[127];

int main(){
    scanf("%d", &N);
    scanf("%s", S);

    int res = 0;
    for(int i=0; i<N-1; i++){
        bool asc[26] = {false};
        int cnt = 0;
        for(int k=0; k<i+1; k++){
            asc[S[k] - 'a'] = true;
        }
        for(int j=i+1; j<N; j++){
            if(asc[S[j] - 'a']){
                cnt++;
                asc[S[j] - 'a'] = false;
            }
        }
        res = max(res, cnt);
    }
    printf("%d", res);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


  
int main(){
  int n;
  cin >> n;
  int a[200010];
  FOR(i,n){
    cin >> a[i+1];
  }
  int b[200010];
  int num=n,cnt=n,v=0;
  while(num){
    v++;
    num/=2;
    for(int i=cnt;i>num;i--){
      if(i==0)break;
      if(v==1){
        b[i]=a[i];
      }else{
        int c=0;
        for(int j=i*2;j<=n;j+=i){
          if(b[j]==1)c++;
        }
        
        if(a[i]==0)a[i]=2;
        if((a[i]-(c%2))%2==1){
          b[i]=1;
        }else{
          b[i]=0;
        }
      }
      
    }
    cnt=num;
    if(num==0)break;
  }
  vector<int> ans;
  for(int i=1;i<=n;i++){
    if(b[i]==1)ans.push_back(i);
  }

  cout << ans.size() << endl;
  FOR(i,ans.size()){
    cout << ans[i] << endl;
  }
  
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;

int mx = 60;

int main(){

    ll n, x, m;
    cin >> n >> x >> m;

    V<V<ll>> to(mx, V<ll>(m));
    V<V<ll>> sum(mx, V<ll>(m));

    rep(i,m) {
        to[0][i] = i*i % m;
        sum[0][i] = i;
    }

    rep(i,mx-1)rep(j,m) {
        to[i+1][j] = to[i][to[i][j]];
        sum[i+1][j] = sum[i][j] + sum[i][to[i][j]];
    }

    ll cur = x, ans = 0;
    for(ll i = mx-1; i >= 0; i--) {
        if(n>>i & 1) {
            ans += sum[i][cur];
            cur = to[i][cur];
        }
    }

    cout << ans << endl;
}

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

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

    int ans = 0;
    int now = 1;
    while(n>=now) {
        now *= k;
        ans++;
    }

    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
local n, t = io.read("*n", "*n")
local a = {}
for i = 1, n do a[i] = io.read("*n") end
local mmi, mma = math.min, math.max
local min = {}
min[1] = {}
min[1].c, min[1].v = 1, a[1]

for i = 2, n do
  min[i] = {}
  if a[i] < min[i - 1].v then
    min[i].c, min[i].v = 1, a[i]
  elseif min[i - 1].v == a[i] then
    min[i].c = min[i - 1].c + 1
    min[i].v = min[i - 1].v
  else
    min[i].c = min[i - 1].c
    min[i].v = min[i - 1].v
  end
end
local maxrate = 0
for i = 2, n do
  maxrate = mma(maxrate, a[i] - min[i].v)
end
local totcnt = 0
local mincnt = min[1].c
local maxcnt = 0
for i = 2, n do
  if min[i].v < min[i - 1].v then
    totcnt = totcnt + mmi(mincnt, maxcnt)
    mincnt = min[i].c
    maxcnt = 0
  else
    if maxrate == a[i] - min[i].v then
      maxcnt = maxcnt + 1
    end
  end
end
totcnt = totcnt + mmi(mincnt, maxcnt)
print(totcnt)


Measured memory_bytes: 11648
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
int first(int x)
{	
	string s=to_string(x);
	return s[0]-'0';
}
void solve()
{
	int n;cin>>n;
	int dp[10][10]={0};
	for(int i=1;i<=n;++i)
	{
		dp[first(i)][i%10]++;
	}
	ll ans=0;
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{	
			//cout<<i<<" "<<j;
			//cout<<" DP -> "<<dp[i][j]<<" "<<dp[j][i]<<endl;
			ans+=dp[i][j]*dp[j][i];
		}
	}
	cout<<ans<<endl;
}
int main()
{
	//int t;cin>>t;
	//while(t--)
	solve();
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S;
	cin >> S;
	int ans = 0;
	FOR(i, 1, S.size()) {
		if (S[i] == S[i - 1]) {
			if (S[i - 1] == '1')S[i] = '0';
			else S[i] = '1';
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 512
/*
   ~~~~~~~~~~~~~~~~~~~
   \  |\/| | |\ | |  /
   /  |  | | |/ |_|  \
   ~~~~~~~~~~~~~~~~~~~
*/
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#define pf push_front
#define lb lower_bound
#define up upper_bound
#define mp make_pair
#define sp setprecision
#define ll long long
using namespace std;
int main()
{	
	ll x,y,s[110],i,j;
	cin>>x>>y;
	for(ll i=0;i<y;i++){
		cin>>s[i];
	}
	sort(s,s+y);
	if(y==0) cout<<x<<endl;
	else{
		ll c1=x,c2=x;
		for(ll i=0;i<y;i++){
			for(ll j=0;j<y;j++){
				if(x==s[j]){
					if(i%2==0) {c1--;x=c1;}
					else {c2++;x=c2;}
					break;
				}
			}
		}
		
		cout<<x<<endl;
	}

	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int N, A, B;
    cin >> N >> A >> B;

    cout << MIN(N * A, B) << "\n";
    return 0;
}



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

int main(){
  int N,R,B,mod=1000000007;
  cin >> N >> B;
  R = N-B;
  vector<vector<int>> C(N+3,vector<int>(N+3,0));
  
  C[0][0] = 1;
  for(int i=1;i<N+3;i++){
    for(int j=0;j<=i;j++){
      if(j==0 || j==i) C[i][j] = 1;
      else C[i][j] = C[i-1][j] + C[i-1][j-1];
      C[i][j] %= mod;
    }
  }
  
  for(int i=1;i<=B;i++){
    long long ans;
    ans = C[R+1][i];
    ans *= C[B-1][i-1];
    ans %= mod;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 16000
#include<stdio.h>
#include<math.h>
  
typedef struct{
  double x;
  double y;
}koch;

void fractal(int,koch,koch);
 
int main(){
  
  koch p1,p2;
  int n;
  
  p1.x = 0;
  p2.x = 100;
  p1.y = 0;
  p2.y = 0;
  
  scanf("%d",&n);
  
  printf("%f %f\n",p1.x,p1.y);
  fractal(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);
  
  return 0;
}

void fractal(int n, koch p1, koch p2){
 
  if(n==0) return;
  koch s,t,u;
  
  s.x = (p2.x-p1.x)/3+p1.x;
  s.y = (p2.y-p1.y)/3+p1.y;
  t.x = 2*(p2.x-p1.x)/3+p1.x;
  t.y = 2*(p2.y-p1.y)/3+p1.y;
  u.x = (t.x-s.x)/2-sqrt(3)/2*(t.y-s.y)+s.x;
  u.y = (t.y-s.y)/2+sqrt(3)/2*(t.x-s.x)+s.y;
  
  fractal(n-1,p1,s);
  printf("%f %f\n",s.x,s.y);
    
  fractal(n-1,s,u);
  printf("%f %f\n",u.x,u.y);
    
  fractal(n-1,u,t);
  printf("%f %f\n",t.x,t.y);
  
  fractal(n-1,t,p2);
}

Measured memory_bytes: 636
//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

use std::cmp::*;
use std::collections::BTreeMap;

fn main() {
    input! {
        n: usize,
        s: [chars;n],
    }

    let mut cnt = vec![0; 26];

    for i in 0..n {
        let mut dic = BTreeMap::new();
        for e in s[i].iter() {
            *dic.entry(e).or_insert(0) += 1_u64;
        }
        for j in 0..26 {
            let t = *dic.get(&(('a' as u8 + j as u8) as char)).unwrap_or(&0);
            cnt[j] = if i == 0 { t } else { min(cnt[j], t) }
        }
    }

    for i in 0..26 {
        for _ in 0..cnt[i] {
            print!("{}", ('a' as u8 + i as u8) as char);
        }
    }

    println!();
}


Measured memory_bytes: 4352
#include<stdio.h>
#define NOT_FREE -1
#define N 8
#define FREE 1

int O[8][8];
int col[8];
int row[8];
int dneg[15];
int dpos[15];
int k,l,A;


void printboard(void)
{
  int i,j;

  for(i=0;i<8;i++)
    {
      for(j=0;j<8;j++)
	{
	  if(O[i][j])
	    {
	      if(row[i]!=j) return;
	    }
	}
    }

  for(i=0;i<8;i++)
    {
      for(j=0;j<8;j++)
	{
	  if(j!=row[i])printf(".");
	  else printf("Q");
	}
      printf("\n");
    }
}

void putQueen(int i)
{
 
  int j;
  if(i==N)
    {
      printboard();
      return;
    }
  /*for(j=0;j<A;j++)
    {
      if(i==k[j]) i++;;
    }
  */
  for(j=0;j<8;j++)
    {
      if(col[j]==NOT_FREE||dpos[i+j]==NOT_FREE||dneg[i-j+N-1]==NOT_FREE)
	{
	  continue;
	}
	
      row[i]=j;
      col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
      putQueen(i+1);
      col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
    }
}

    



int main()
{
  int i;

  for(i=0;i<N;i++)
    {
      col[i]=FREE;
      row[i]=FREE;

    }
 for(i=0;i<15;i++)
   {
      dneg[i]=FREE;
      dpos[i]=FREE;
   }
     
  scanf("%d",&A);
  for(i=0;i<A;i++)
    {
      scanf("%d%d",&k,&l);
      O[k][l]=1;

      //row[k[i]]=l;
      //  col[l]=dpos[k[i]+l]=dneg[k[i]-l+N-1]=NOT_FREE;
    }
  putQueen(0);

  return 0;
}

Measured memory_bytes: 572
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int result = a-2*b;
    if(result<0) result=0;
    System.out.println(result);
  }
}

Measured memory_bytes: 23764
N, M = map(int, input().split())
PY = []
for i in range(M):
    p, y = map(int, input().split())
    PY.append([p, y, i])
PY.sort()
cnt = 1
a = 0
for i in range(M):
    if PY[i][0] == a: cnt += 1
    else: cnt = 1
    a = PY[i][0]
    PY[i][1] = cnt
PY.sort(key=lambda x: x[2])
for i in range(M):
    print(str(PY[i][0]).rjust(6,'0') + str(PY[i][1]).rjust(6,'0'))

Measured memory_bytes: 24768
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1LL << 60;
constexpr int INF = 1000000007;
const double INFD = 1e100;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  return gcd(b, a%b);
}
int main(){
  ll a,b;
  cin >> a >> b;
  cout << (a*b)/gcd(a,b) << endl;
  return 0;
}


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

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int l = Integer.parseInt(in.next());
            String s[] = new String[n];
            for (int i = 0; i < n; i++) {
                s[i] = in.next();
            }

            Arrays.sort(s);

            for (int i = 0; i < n; i++) {
                out.print(s[i]);
            }
            out.println();

        }

    }
}



Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define pb push_back
#define all(v) v.begin(),v.end()
const int N=100005;
const int MOD=1e9+7;
 

// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
 
 
 int go(int n)
 {
	 int x=0;
	 for(int i=2;i<=n;i++)
	 {
		 while(n%i==0)
		 {
			 x++;
			 n=n/i;
		 }
	 }
	 return x;
	}
 
int32_t main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  /* stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?)
  * do smth instead of nothing and stay organized
*/







int n,m;
cin>>n>>m;
vector<int> v(n);
for(int i=0;i<n;i++)
{
	cin>>v[i];
}
sort(all(v));
int sum=0;
for(int i=0;i<m;i++)
{
	sum+=v[i];
}
cout<<sum;
}




Measured memory_bytes: 3648
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e9;

void Insertion(){
	int n;
	cin >> n;

	string s;
	cin >> s;
	int left = 0;
	int right = 0;
	int ok = 0;
	for (size_t i = 0; i < n; i++)
	{
		if (s[i] == '(') {
			left++;
		}
		else if (s[i] == ')') {
			right++;
			ok = min(left, ok + 1);
		}
	}

	cout << string(right - ok, '(') << s << string(left - ok, ')') << endl;
}

int main() {
	Insertion();
	return 0;
}



Measured memory_bytes: 256
a = str(input())
ans=0
i=0
for aa in a:
  i +=1
  if i%2 == 0:
    if  aa !='L' and aa !='U' and aa != 'D':
      ans=1
  else :
    if  aa !='R' and aa !='U' and aa != 'D':
      ans=1
if ans == 0 :
  print('Yes')
else:
  print('No')

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

using namespace std;

int main(){
  long long int N;
  long long int T[111];
  long long int i;
  long long int g,l;
  cin >> N;
  for(i=0;i<=N-1;i++)
    cin >> T[i];
  if(N>1){
  g = __gcd(T[0],T[1]);
  l = T[0]/g*T[1];
  for(i=0;i<=N-2;i++){
    g = __gcd(l,T[i+1]);
    l =  T[i+1] / g * l;
    }
  cout << l << endl;
  }
  else cout << T[0] << endl;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
List=[int(i) for i in input().split()]
count=0
for n in range(N) :
    if int(List[n]) >= float(sum(List)/(4*M)) :
        count=count+1
if int(count)>=M :
    print("Yes")
else :
    print("No")

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

int main() {
	int n;
    string s = "No";
    cin >> n;
    int m = n/100;
    if(n%10 == 7){
      s = "Yes";
    }else if(m == 7){
      s = "Yes";
    }else if(((n/10)-(m*10))==7){
      s = "Yes";
    }
    cout << s << endl;
}

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  char next = a[0];
  int ca = 1, cb = 0, cc = 0;
  while (true) {
    if (next == 'a') {
      if (ca == a.size()) {
        cout << 'A' << endl;
        return 0;
      } else {
        next = a[ca];
        ca++;
      }
    } else if (next == 'b') {
      if (cb == b.size()) {
        cout << 'B' << endl;
        return 0;
      } else {
      	next = b[cb];
      	cb++;
      }
    } else {
      if (cc == c.size()) {
        cout << 'C' << endl;
        return 0;
      } else {
      	next = c[cc];
      	cc++;
      }
    }
  }
}

Measured memory_bytes: 3504
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
		int H,W;
		do{
			H = scan.nextInt();
			W = scan.nextInt();
			if(H == 0 && W == 0){break;} // H = 0 W = 0 ??§??????
			for(int i = 0;i < H;i++){
				for(int j = 0;j < W;j++){
					if(i == 0 || i == H - 1|| j == 0 || j == W - 1){
					System.out.print("#");
					}
					else{
					System.out.print(".");
					}
				}
					System.out.print("\n");
			}
			System.out.print("\n");	
		}while(true);
	}
}

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

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

    while(t-- > 0){
        int a[9];
        for(int i = 0; i < 9; i++)  cin >> a[i];
        char x;
        for(int i = 0; i < 9; i++){
            cin >> x;
            if(x == 'G')    a[i] += 20;
            if(x == 'B')    a[i] += 40;
        }

        int b[50] = {};
        for(int i = 0; i < 9; i++)  b[a[i]]++;

        bool judge = true;
        for(int i = 0; i < 50; i++){
            if(b[i] == 0)   continue;
            if(b[i] >= 3)   b[i] -= 3;
            while(b[i] && b[i+1] && b[i+2]){
                b[i]--, b[i+1]--, b[i+2]--;
            }
            if(b[i])    judge = false;
        }

        cout << judge << endl;
    }
    return 0;
}


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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define ALL(r) (r).begin(), (r).end()

void Main();

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main() {
    int64_t x, k, d;
    cin >> x >> k >> d;
    x = abs(x);

    int64_t f1 = x / d;
    if (k <= f1) {
        cout << abs(x - k * d) << endl;
        return;
    }

    k -= f1;
    x %= d;

    if (k % 2 == 0) {
        cout << abs(x) << endl;
    } else {
        cout << abs(x - d) << endl;
    }
}


Measured memory_bytes: 3640
#include <algorithm>
#include <iostream>
#include <cstdio>

int main()
{
    int a = 0, b = 0, c = 0;
    std::cin >> a >> b >> c;
    if (a > b)
        std::swap(a, b);
    if (b > c)
        std::swap(b, c);
    if (a > b)
        std::swap(a, b);
    std::cout << a << " " << b << " " << c << std::endl;
    return 0;
}


Measured memory_bytes: 3116
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
aa=(a+9)//10*10
bb=(b+9)//10*10
cc=(c+9)//10*10
dd=(d+9)//10*10
ee=(e+9)//10*10
print(aa+bb+cc+dd+ee-max(aa-a,bb-b,cc-c,dd-d,ee-e))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>

#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
 
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}

using namespace std;

int main(void){
	double p[2][100],ret;
	int n;
	while(cin >> n && n){
		int cur=0,nxt=1;
		ret=0;
		FILL(p,0);
		p[cur][0] = 1;
		for(int i=0;i<n;i++){
			for(int j=0;j<100;j++){
				if(p[cur][j] == 0) continue;
				p[nxt][0] += p[cur][j] * (1 - pow(0.5,j));
				p[nxt][j+1] += p[cur][j] * pow(0.5,j);
				ret += p[cur][j] * pow(0.5,j);
				//cout << p[cur][j] << " " <<pow(0.5,j) << endl;
			}
			cur = 1 - cur;
			nxt = 1 - nxt;
			for(int j=0;j<100;j++) p[nxt][j] = 0;
		}
		printf("%.8lf\n", ret);
	}
}

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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long int
#define MAX 1e9
#define MIN -1e9
#define mod 998244353
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define output(x) cout << ( x ? "Yes" : "No" ) << '\n' ;
#define mxn 100005
using namespace std;

void solve(){
    int n,k;
    cin >> n >> k;
    int l[k],r[k];
    for(int i = 0; i < k; i++){
        cin >> l[i] >> r[i];
    }
    int dp[n + 5] = {};
    int pref[n + 5] = {};
    dp[1] = 1;
    pref[1] = 1;
    for(int i = 2; i <= n; i++){
        for(int j = 0; j < k; j++){
            if(i <= l[j])
                continue;

            int left = l[j];
            int right = min(r[j], i - 1);
            int val = (pref[i - left] - pref[i- right - 1] + mod) % mod;
            
            dp[i] = (dp[i] + val ) % mod;
        }
        pref[i] = (pref[i - 1] % mod + dp[i] % mod) % mod;
    }
    cout << dp[n] ;
}

int32_t main()
{
    FLASH
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 6752
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;

int main(){
  ll n,cnt=0;
  cin>>n;
  ll tmp=0;
  irep(i,sqrt(n)+1,1){
    if(n%i==0&&n/i>=i){tmp=n/i;break;}
  }
  string x=to_string(tmp);
  cout<<x.length();
}
  

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

int ctoi(char num) {
    return num - '0';
}

int main(void) {
    string S;
    cin >> S;
    
    int num;
    
    int str_len = int(S.size());
    
    int min_diff = 100000;
    
    for (int i=0; i <= str_len - 3; i++) {
        num = ctoi(S[i]) * 100 + ctoi(S[i+1]) * 10 + ctoi(S[i+2]);
        min_diff = min(abs(num - 753), min_diff);
    }
    
    cout << min_diff << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

int A,B;
char ans[100][100];

int main ()
{
    cin >> A >> B;

    swap (A, B);

    REP(x,100) {
        REP(y,100) {
            if (x % 2) {
                ans[x][y] = '#';
            } else {
                ans[x][y] = '.';
            }
        }
        ans[x][0] = '.';
        ans[x][99] = '#';
    }

    A--;
    B--;

    for (int x = 97; A > 0; x -= 2) {
        for (int y = 2; y < 95 && A > 0; y += 2) {
            A--;
            ans[x][y] = '.';
        }
    }

    for (int x = 2; B > 0; x += 2) {
        for (int y = 97; y >= 5 && B > 0; y -= 2) {
            B--;
            ans[x][y] = '#';
        }
    }

    cout << 100 << " " << 100 << endl;
    REP(i,100) {
        REP(j,100) cout << ans[i][j];
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
n=int(input())
mod=1000000007
s=[int(i) for i in input().split()]
ans=1
for i in s:
    ans*=i//gcd(ans,i)
print(sum(ans//i for i in s)%mod)


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
const int N_max=51;
const int M_max=N_max*(N_max-1);
vector<int> v[51];
bool isVisited[N_max];
void initialize(){
    REP(i,N_max){
        isVisited[i]=false;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int M=in();
    int Q=in();
    int d[509][509]={};
    int l;int r;
    int c[509][509]={};
    REP(i,M){
        cin>>l>>r;
        d[l][r]++;
    }
    REP1(i,N){
        REP1(j,N){
            REP1(k,j){
                c[i][j]+=d[i][k];
            }
        }
    }
    int lq[Q+10],rq[Q+10];
    int ans;
    REP1(i,Q){
        cin>>lq[i]>>rq[i];
    }
    REP1(i,Q){
        ans=0;
        for(int j=lq[i];j<=rq[i];j++){
            ans+=c[j][rq[i]]-c[j][lq[i]-1];
        }
        print(ans);
    }
    
    return 0;
}

Measured memory_bytes: 3712