akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}

int main() {
   fast();
   int n;
   cin>>n;
   int a[n];
   unordered_map<int,int> m;
   for(int i=0;i<n;i++){
    cin>>a[i];
   }
   int allgcd=a[0];
   for(int i=1;i<n;i++){
    allgcd=__gcd(a[i],allgcd);
   }
   const int N=1000001;
   vector<char> is_prime(N+1, true);
   is_prime[0] = is_prime[1] = false;
   for (int i = 2; i <= N; i++) {
    if (is_prime[i] && (long long)i * i <= N) {
        for (int j = i * i; j <= N; j += i)
            is_prime[j] = false;
    }
   }
   vector<int> c;
   for(int i=0;i<=N/2;i++){
       if(is_prime[i]){
           c.emplace_back(i);
       }
   }
  int g=1;
   for(int i=0;i<n;i++){
       int l=a[i];
       if(is_prime[l]){
           m[l]++;
           if(m[l]>1){
           	 g=0;
           	 i=n;
           }
       }else{
      for(int j=0;j<(int)c.size();j++){
          if(is_prime[l]){
              m[l]++;
              if(m[l]>1){
              	g=0;
              	i=n;
              }
              break;
          }
        if(l%c[j]==0){
          m[c[j]]++;
          if(m[c[j]]>1){
          	g=0;
          	i=n;
          	break;
          }
          while(l%c[j]==0){
               l=l/c[j];
          }
        }
        if(l<c[j]){
            break;
        }
      }
       }
   }
   
   if(g){
    cout<<"pairwise coprime"<<"\n";
    return 0;
   }
   if(allgcd==1){
      cout<<"setwise coprime"<<"\n";
      return 0;
   }
   cout<<"not coprime"<<"\n";
   return 0;


   
}


Measured memory_bytes: 8448
ans = []

while True:
    tmp = input().split()

    a, b = map(int, [tmp[0], tmp[2]])
    op = tmp[1]

    if op == "?":
        break
    if op == "+":
        ans.append(a + b)
    if op == "-":
        ans.append(a - b)
    if op == "*":
        ans.append(a * b)
    if op == "/":
        ans.append(a // b)

print("\n".join(map(str, ans)))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  n*=2;
  int a[n];
  rep(i,n) R a[i];
  sort(a,a+n,greater<int>());
  int ans=0;
  for(int i=0; i<n; i+=2) ans+=a[i+1];
  pr(ans);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 764
R, G ,B, N = map(int, input().split())

tmp = [R, G, B]
tmp.sort()
R, G, B = tmp[2], tmp[1], tmp[0]


num_R = N // R + 1
num_G = N // G
RG = [[N - R*i for i in range(num_R)]]

for j in range(num_G):
    RG.append([RG[-1][i] - G for i in range(num_R)])

check = lambda x: 0 if x < 0 else 1 if x == 0 else 1 if x%B == 0 else 0

a = []
count = 0
for i in range(len(RG)):
    a = list(map(check, RG[i]))
    count += sum(a)

print(count)


Measured memory_bytes: 120156
<?php

function gcd($x, $y) {
    if ($y === 0) {
        return $x;
    }

    return gcd($y, $x % $y);
}

function lcm($x, $y) {
    return $x * $y / gcd($x, $y);
}

while (fscanf(STDIN, "%d %d", $a, $b)) {
    echo gcd($a, $b) . " " . lcm($a, $b) . "\n";
}


Measured memory_bytes: 9224
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.ARC076
{
    class Built
    {
        public static void Main()
        {
            var n = int.Parse(ReadLine().Trim());
            var points = new Point[n];
            for (int x, y, i = 0; i < points.Length; ++i) {
                Read(ReadLine().Trim(), out x, out y);
                points[i] = new Point(i, x, y);
            }
            var dist = new Distance[n * 2 - 2];
            points = points.OrderBy(_ => _.X).ToArray();
            for (var i = 1; i < points.Length; ++i) {
                dist[i - 1] = new Distance(points[i - 1].Id, points[i].Id, points[i].X - points[i - 1].X);
            }
            points = points.OrderBy(_ => _.Y).ToArray();
            for (var i = 1; i < points.Length; ++i) {
                dist[i + points.Length - 2] = new Distance(points[i - 1].Id, points[i].Id, points[i].Y - points[i - 1].Y);
            }
            dist = dist.OrderBy(_ => _.Dist).ToArray();
            var uft = new UnionFindTree[n];
            for (var i = 0; i < uft.Length; ++i) {
                uft[i] = new UnionFindTree();
            }
            long res = 0;
            foreach(var d in dist) {
                if (!uft[d.From].IsSameUnion(uft[d.To])) {
                    res += d.Dist;
                    uft[d.From].MergeUnion(uft[d.To]);
                }
            }
            WriteLine(res);
        }
        class UnionFindTree
        {
            UnionFindTree _parent = null;
            UnionFindTree Parent
            {
                get
                {
                    return (_parent == null) ? this : _parent = _parent.Parent;
                }
                set
                {
                    Parent._parent = value.Parent;
                }
            }
            public void MergeUnion(UnionFindTree other)
            {
                Parent = other.Parent;
            }
            public bool IsSameUnion(UnionFindTree other)
            {
                return Parent == other.Parent;
            }
        }
        static void Read(string str, out int x, out int y)
        {
            var s = str.Split(' ').Select(_ => int.Parse(_)).ToArray();
            x = s[0]; y = s[1];
        }
        struct Point
        {
            public Point(int id, int x, int y)
            {
                Id = id; X = x; Y = y;
            }
            public int X { get; private set; }
            public int Y { get; private set; }
            public int Id { get; private set; }
        }
        struct Distance
        {
            public int From
            {
                get; private set;
            }
            public int To
            {
                get; private set;
            }
            public int Dist
            {
                get; private set;
            }
            public Distance(int f, int t, int dist)
            {
                From = f; To = t; Dist = dist;
            }
        }
    }
}


Measured memory_bytes: 35264
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n,h,w;
  cin>>n>>h>>w;
  vector<int> a(n),b(n);
  REP(i,n) cin>>a[i]>>b[i];

  int ans=0;
  REP(i,n){
    if(a[i]>=h && b[i]>=w) ans++;
  }
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

int main() {
  int n, x, y, cnt = 0, maxi = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x == y) {
      cnt++;
    } else {
      cnt = 0;
    }
    maxi = max(maxi, cnt);
  }
  cout << (maxi >= 3 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3620
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                          ll                          long long int
#define                          mk                          make_pair
#define                          in(x)                       scanf("%lld",&x)
#define                          out(x)                      printf("%lld\n",x)
#define                          cy                          printf("YES\n")
#define                          cn                          printf("NO\n")
#define                          mx                          100005
#define                          inf                         1e17
#define                          pi                          pair<ll,ll>
#define                          fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


using namespace std;
vector<pi> adj[mx];
bool vis[mx];
ll dis[mx];
int main(){
    fast;
 ll edge ,vertex;
 cin>>vertex>>edge;
 ll i,c,u,v;
 for(i=1;i<=edge;i++){
    cin>>u>>v>>c;
    adj[u].push_back({v,c});
    adj[v].push_back({u,c});

 }
 for(i=2;i<=vertex;i++){
       adj[i].push_back({i-1,0});
 }
priority_queue<pi,vector<pi>,greater<pi> > q;

 for(i=1;i<=vertex;i++){
       dis[i]=inf;
 }
 dis[1]=0;
 q.push({dis[1],1});

 while(!q.empty()){
    pi temp;
    temp=q.top();
    q.pop();
    u=temp.second;
    ll cost=temp.first;
    if(vis[u])continue;
        vis[u]=1;
        for(auto x: adj[u]){
                v=x.first;
                c=x.second;

                if(dis[v]<=c+cost) continue;
                dis[v]=c+cost;
                q.push({dis[v],v});

        }

 }
   if(dis[vertex]>=inf) dis[vertex]=-1;
   cout<<dis[vertex]<<endl;
   return 0;
}


Measured memory_bytes: 15880
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

bool solve() {
  string s; cin >> s;
  if (s.at(0) == s.at(s.size() - 1)) {
    return s.size() % 2 == 0;
  }else {
    return s.size() % 2 != 0;
  }
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);
  cout << (solve() ? "First" : "Second") << endl;

  return 0;
}



Measured memory_bytes: 512
import java.util.*;
public class Main {
    static class Pos {
        int x;
        int y;
        public Pos(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// get a integer
		int N = sc.nextInt();
        Pos[] a = new Pos[N];
        Pos[] b = new Pos[N];

        for (int i = 0; i < N; i++) {
            a[i] = new Pos(sc.nextInt(), sc.nextInt());
        }
        for (int i = 0; i < N; i++) {
            b[i] = new Pos(sc.nextInt(), sc.nextInt());
        }
        
        boolean[][] d = new boolean[N][N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if ((a[i].x < b[j].x) && (a[i].y < b[j].y)) {
                    d[i][j] = true;
                }
            }
        }
        System.out.println(maxBPM(N, d));
    }
    
    static int maxBPM(int N, boolean d[][]) {
        int matchR[] = new int[N];
        for (int i = 0; i < N; i++) {
            matchR[i] = -1;
        }
        int res = 0;
        for (int u = 0; u < N; u++) {
            boolean seen[] = new boolean[N];
            for (int i = 0; i < N; i++) {
                seen [i] = false;
            }
            if (bpm(N, d, u, seen, matchR)) {
                res += 1;
            }
        }
        return res;
    }
    static boolean bpm(int N, boolean d[][], int u, boolean seen[], int matchR[]) {
        for (int v = 0; v < N; v++) {
            if (!seen[v] && d[u][v]) {
                seen[v] = true;
                if (matchR[v] < 0 || bpm(N, d, matchR[v], seen, matchR)) {
                    matchR[v] = u;
                    return true;
                }
            }   
        }
        return false;
    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <string>
#include <utility>

#define repd(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue();
void inputArray(int*,int);
void inputVector(vector<int>*,int);
template <typename T>
void output(T,int);
int gcd(int a,int b);

int main(){
	//source
	int a,b,t;
	cin >> a >> b >> t;
	int ans=t/a;
	ans*=b;
	cout << ans << endl;
	return 0;
}

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template<typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}

int gcd(int a,int b){
	if(b>a){
		int temp=a;
		a=b;
		b=temp;
	}
	if(b==0){
		return a;
	}
	return (b,b%a);
}


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

int main(){
  int a, b;
  int coin[] = {1000, 500, 100};
  int ans[3];

  while(cin >> a >> b, a || b){
    b -= a;
    for(int i = 0; i < 3; i++){
      ans[i] = b / coin[i];
      b %= coin[i];
    }
    for(int i = 2; i >= 0; i--){
      if(i != 2) cout << " ";
      cout << ans[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1160
#include<cstdio>
#include<algorithm>
#define MN 1000005
using namespace std;
const int mod=1e9+7;
int dp[MN],sum[MN],n,res;
int main(){
	scanf("%d",&n);dp[0]=sum[0]=1;res=1ll*(n-1)*(n-1)%mod;
	for(int i=1;i<n;i++){
		dp[i]=dp[i-1]+(i-3>=0?sum[i-3]:0),dp[i]%=mod;
		sum[i]=sum[i-1]+dp[i],sum[i]%=mod;
		if(i<n-1)res+=1ll*dp[i]*(n-1)%mod*(n-1)%mod,res%=mod;else res+=1ll*dp[i]*(n-1)%mod,res%=mod;
	}
	for(int i=0;i<n-1;i++)dp[n]+=1ll*dp[i]*((i+n+1)-max(n,i+3)+1)%mod,dp[n]%=mod;res+=(dp[n]+dp[n-1])%mod;printf("%d\n",res%=mod);
}

Measured memory_bytes: 7936
#include <stdio.h>
#include <string>
#include <algorithm>
#include <map>
#include <iostream>

using namespace std;

map<string, int> a, b;
string str;

int main(){
	int N, M;
	cin>>N;
	for(int i=1; i<=N; ++i){ cin>>str; a[str]++; }
	cin>>M;
	for(int i=1; i<=M; ++i){ cin>>str; b[str]++; }
	int best = 0;
	for(map<string, int>::iterator it=a.begin(); it!=a.end(); ++it){
		best = max(best, it->second - b[it->first]);
	}
	printf("%d\n", best);
	return 0;
}
		

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


int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll>a(n);
  for(int i=0; i<n; i++){
   cin >> a[i];
   a[i]--;
  }
  
  if(k<=n){
    ll x = 0;
    for(int i=0; i<k; i++){
      x=a[x];
    }
    
    cout << x+1 << endl;
    return 0;
    
  }
  
  
  vector<ll>judge(n);
  vector<ll>keep[1];
  ll place=0;
  ll count=0;
  while(judge[place]<2){
   if(judge[place]==1)keep[0].push_back(place);
   judge[place]++;
   place=a[place];
   count++;
  }
  ll s = keep[0].size();
  ll start=count-2*s;
  
  ll ans=(k+1-start)%s;
  
  if(ans==0) cout << keep[0][s-1]+1 << endl;
  else cout << keep[0][ans-1]+1 << endl;
  
  
  
  
  return 0;
}
  
  


Measured memory_bytes: 7380
h , w , k = map(int,input().split())
cho = [list(input()) for i in range(h)]
ans = 10**9
for i in range(2**(h-1)):
    cut = [0 for i in range(h)]
    for j in range(h-1):
        if i >> j & 1 == 1:
            cut[j+1] = cut[j]+1
        else:
            cut[j+1] = cut[j]
    maxcut = max(cut)+1
    cou = [0 for i in range(maxcut)]
    ccho = [[0 for i in range(w)] for j in range(maxcut)]
    for j in range(h):
        for l in range(w):
            ccho[cut[j]][l] += int(cho[j][l])
    tyu = maxcut - 1
    hukanou = False
    for j in range(w):
        flag = True
        for l in range(maxcut):
            if cou[l] + ccho[l][j] > k:
                flag = False
                break
        if flag:
            for l in range(maxcut):
                cou[l] += ccho[l][j]
        elif not flag:
            tyu += 1
            for l in range(maxcut):
                if ccho[l][j] > k:
                    hukanou = True
                    break
                cou[l] = ccho[l][j]
        if hukanou:
            break
    if hukanou:
        continue
    ans = min(ans,tyu)
print(ans)

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

#define REP(i,n) for(int i=0;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()

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

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

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

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

int n,m;
int p[N_MAX];
int x[N_MAX],y[N_MAX];
bool ng[N_MAX];
vector<int> path[N_MAX];
bool visited[N_MAX];
vector<vector<pii>> group;
vector<pii> e;

void dfs(int s){
	for(int i=0;i<int(path[s].size());i++){
		int to=path[s][i];
		if(!visited[to]){
			visited[to]=true;
			e.push_back(pii(p[to],to));
			dfs(to);
		}
	}
}

int main(){
	cin>>n>>m;
	REP(i,n){
		cin>>p[i];
		p[i]--;
	}
	REP(i,m){
		cin>>x[i]>>y[i];
		x[i]--; y[i]--;
		ng[x[i]]=true;
		ng[y[i]]=true;
		path[x[i]].push_back(y[i]);
		path[y[i]].push_back(x[i]);
	}
	int ans=0;

	for(int i=0;i<n;i++){
		if(!visited[i] && ng[i]){
			dfs(i);
			group.push_back(e);
			e.clear();
		}
	}
	bool position[n];
	bool number[n];
	REP(i,group.size()){
		REP(j,n)position[j]=number[j]=false;
		REP(j,group[i].size()){
			int f=group[i][j].first;
			int s=group[i][j].second;
			number[f]=true;
			position[s]=true;
		}
		REP(j,n){
			if(number[j] && position[j])ans++;
		}
	}
	REP(i,n){
		if(!ng[i] && p[i]==i){
			ans++;
			//cout<<p[i]<<" "<<i<<endl;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 12788
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var X = ReadLine().Split().Select(int.Parse).ToArray();
        int[] a = new int[N];
        Array.Copy(X, a, X.Length);
        Array.Sort(a);
        var b = (a[N / 2] + a[N / 2 - 1]) / 2.0;
        for (int i = 0; i < N; i++)
        {
            if (X[i] < b) WriteLine(a[N / 2]);
            else WriteLine(a[N / 2 - 1]);
        }
    }
}

Measured memory_bytes: 38236
N = gets.to_i
A = gets.split.map(&:to_i).sort
MAX = 10 ** 6

counts = Array.new(MAX + 1, 0)

A.each do |x|
    counts[x] += 1
end

c = 0
counts.each_with_index do |count, i|
    next if count == 0
    c += 1 if count == 1
    i.step(MAX ,i) do |k|
        counts[k] = 0
    end
end
puts c


Measured memory_bytes: 38340
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
using namespace std;

int main() {

	int L, R;
	cin >> L >> R;

	int mod_L = L % 2019;
	int mod_R = R % 2019;
	int ans = 0;

	if (R - L >= 2019) {
		ans = 0;
	}
	else {
		if (mod_L < mod_R) {
			int val = 0;
			ans = 2019;
			for (int i = mod_L; i < mod_R; i++) {
				for (int j = i + 1; j <= mod_R; j++) {
					val = i * j;
					val = val % 2019;
					if (val < ans) {
						ans = val;
					}
				}
			}
		}
		else {
			ans = 0;
		}
	}

	cout << ans << endl;

	return 0;
}



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

int main()
{
	long long int h, sum = 1, one = 1;
	int a = 1;
	cin >> h;
	if (h == 1) {
		cout << 1;
		return 0;
	}
	while ((one << a) <= h) {
		sum += (one << a);
		a++;
	}
	cout << (sum);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using tiii = tuple<int,int,int>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#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 INF=1e9+7;

int main() {
  int N,M;
  cin >> N >> M;
  vi S(N),T(M);
  rep(i,N) cin >> S[i];
  rep(i,M) cin >> T[i];
  vvi dp(N+1,vi(M+1,1));
  rep(i,N) {
    rep(j,M) {
      ll x=dp[i+1][j]+dp[i][j+1]-dp[i][j];
      if(S[i]==T[j]) x+=dp[i][j];
      dp[i+1][j+1]=(x+INF)%INF;
    }
  }
  
  cout << dp[N][M] << endl;
}

Measured memory_bytes: 19084
require "numo/narray"

MOD = 998244353

n, s = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

dp = Numo::Int64.zeros(s + 1)
dp[0] = 1

a.each_with_index do |a, i|
  tmp = dp * 2
  tmp[a..-1] += dp[0..s-a] unless s < a
  tmp %= MOD
  dp, tmp = tmp, dp
end

puts dp[s]


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

int N, M;
vector<vector<int>> G;

int dfs(int d, int cur, int v) {
  if(d == N - 1 && v + 1 == 1 << N) return 1;
  int ret = 0;
  for(int nx : G[cur]) {
    int bit = 1 << nx;
    if((bit + v) == (bit | v)) ret += dfs(d + 1, nx, bit | v);
  }
  return ret;
}
int main() {
  cin >> N >> M;
  G.resize(N);
  rep(i, 0, M) {
    int a, b; cin >> a >> b; a--, b--;
    G[a].push_back(b); G[b].push_back(a);
  }
  cout << dfs(0, 0, 1 << 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s; cin >> s;
	long long n = s.size();
	long long sum = 0;
	for(int i = 0; i < n; i++){
		sum += (s[i]-'0');
		sum %= 9;
	}
	(sum%9==0) ? (cout << "Yes\n") : (cout << "No\n");
	return 0;
}



Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}

ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}

int main(){
    ll a,b,c,d,k;
    cin >> a >> b >> c >> d >> k;
    ll ans=(c-a)*60+(d-b)-k;
    cout << ans << endl;
    return 0;
}
 
 



Measured memory_bytes: 3632
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (unfoldr)

main :: IO ()
main = do
  (l : r : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  print $ f l r

f :: Int -> Int -> Int
f l r | p 673 && p 3 = 0
      | otherwise = minimum (concat $ unfoldr next [(l `mod` 2019)..(r `mod` 2019)])
  where
    next :: [Int] -> Maybe ([Int], [Int])
    next [] = Nothing
    next (x : xs) = Just (map ((`mod` 2019) . (x *)) xs, xs)
    p :: Int -> Bool
    p d = l `div` d < (r + 1) `div` d

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


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

#define ll long long

using namespace std;


int main(){
 int a,b,c,d;
 cin>>a>>b>>c;
 d=a+b+c;
 if(d>=22){
     cout<<"bust"<<endl;
 }
 else{
     cout<<"win"<<endl;
 }

}

Measured memory_bytes: 256
/*
g++ -std=c++14 -O2 -Wall a.cpp -o a && a
*/

//  io
#include <iostream>
//#include <fstream> //http://www.cplusplus.com/reference/fstream/fstream/
//#include <cstdio>
#include <iomanip> //http://www.cplusplus.com/reference/iomanip/
#include <limits>
//  util
#include <string>
#include <cstring>
#include <algorithm>
//#include <utility>
//#include <functional> //http://www.cplusplus.com/reference/functional/
//#include <cstdlib>
#include <cmath>
//#include <complex>
//#include <random>
//#include <bitset>
//  containers https://en.cppreference.com/w/cpp/container
#include <vector>
//#include <queue>
#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//  time
//#include <ctime>
//#include <chrono>
//                  https://en.cppreference.com/w/cpp/header/chrono
//                  http://www.cplusplus.com/reference/chrono/

using namespace std;
typedef vector<int> arri;
typedef vector<float> arrf;
typedef pair<int, int> pairi;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 0x7fffffffffffffff;
const ll infneg = -0x7fffffffffffffff;

//file input routed to stdinout
/*
std::ifstream inFile("input.txt");
std::ofstream outFile("output.txt");
std::cin.rdbuf(inFile.rdbuf());
std::cout.rdbuf(outFile.rdbuf());
*/

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

    int n, k, q;

    cin >> n >> k >> q;

    arri a(n);

    for (int i = 0; i < q; i++)
    {
        int aux;
        cin >> aux;

        a[aux - 1]++;
    }

    for (int i = 0; i < n; i++)
    {
        if (a[i] + k - q <= 0)
        {
            cout << "No\n";
        }
        else
        {
            cout << "Yes\n";
        }
    }
}

Measured memory_bytes: 1024
//
// Created by yamunaku on 2019/12/29.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

struct pos{
    int x;
    int y;
};

struct sta{
    int f;
    int l;
    int d;
};

int main(){
    // CFS;
    int h, w, K;
    cin >> h >> w >> K;
    vector<string> f(h);
    rep(i, h) cin >> f[i];
    vector<pos> app;
    rep(i, h){
        rep(j, w){
            if(f[i][j] == 'a'){
                app.push_back({i, j});
                f[i][j] = '.';
            }

        }
    }
    rep(i, h){
        rep(j, w){
            if(f[i][j] == 's' || f[i][j] == 'e'){
                app.push_back({i, j});
                f[i][j] = '.';
            }
        }
    }

    int sz = app.size();
    mti dist(sz, vi(sz, IINF));
    vi vx = {0, 1, 0, -1};
    vi vy = {1, 0, -1, 0};
    rep(i, sz){
        queue<pos> q;
        mti dis(h, vi(w, IINF));
        q.push({app[i].x, app[i].y});
        dis[app[i].x][app[i].y] = 0;
        while(!q.empty()){
            auto now = q.front();
            q.pop();
            rep(t, 4){
                int nx = now.x + vx[t];
                int ny = now.y + vy[t];
                if(nx < 0 || h <= nx || ny < 0 || w <= ny) continue;
                if(f[nx][ny] == '#') continue;
                if(dis[nx][ny] != IINF) continue;
                dis[nx][ny] = dis[now.x][now.y] + 1;
                q.push({nx, ny});
            }
        }
        rep(j, sz){
            dist[i][j] = dis[app[j].x][app[j].y];
        }
    }

//    rep(i, sz){
//        rep(j, sz){
//            cout << dist[i][j] << " ";
//        }
//        cout << endl;
//    }
    int ans = IINF;

    mti d(1 << sz, vi(sz, IINF));
    d[1 << (sz - 2)][sz - 2] = 0;
    rep(i, 1 << sz){
        rep(j, sz){
            if(d[i][j] == IINF) continue;
            rep(k, sz){
                if(dist[j][k] != IINF && (i&(1<<k))==0)
                    d[i | (1 << k)][k] = min(d[i | (1 << k)][k], d[i][j] + dist[j][k]);
            }
        }
        int c = 0;
        rep(k, sz){
            if(i & (1 << k)) c++;
        }
        if(c >= K + 2){
            ans = min(ans, d[i][sz - 1]);
        }
    }
    if(ans == IINF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 495472
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC084B {
    class Program {
        static void Main(string[] args) {
            int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int A = input[0];
            int B = input[1];
            string zip = Console.ReadLine();
            bool ok = true;
            for(int i = 0; i < A; i++) {
                if(zip.Substring(i , 1) == "-") {
                    ok = false;
                }
            }
            if(zip.Substring(A , 1) != "-") {
                ok = false;
            }
            for(int i = 0; i < B; i++) {
                if (zip.Substring(A + 1 + i, 1) == "-") {
                    ok = false;
                }
            }
            if (ok) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }
}

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

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


int main(){
    string s;cin >>s;
    ll n=s.size();
    ll sum=0;
    ll now=0;
    for (int i = 0; i < (1 << (n - 1)); ++i) {
        for (int j = 0; j < n; ++j) {
            now+=s[j]-'0';
            if(j==n-1)break;
            if(i&(1<<j)){
                sum+=now;
                now=0;
            }
            else now*=10;
           // cout <<now<<endl;
        }
        sum+=now;
        now=0;
    }
    cout <<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
const ll N=2e5+5;
ll v[N];
int main()
{
    ft
    ll n,k;
    cin>>n>>k;
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
    }
    sort(v,v+n);
    ll s=-1e18,e=1e18,mid;
    while(s+1<e)
    {
        mid=(s+e)/2;
        ll ind=0;
        for(int i=0; i<n; i++)
        {
            if(v[i]<0)
            {
                ll lo=i,hi=n,m;
                while(lo+1!=hi)
                {
                    m=(lo+hi)/2;
                    if(v[i]*v[m]<=mid)
                        hi=m;
                    else
                        lo=m;
                }
                ind+=n-hi;
            }
            else
            {
                ll lo=i,hi=n,m;
                while(lo+1!=hi)
                {
                    m=(lo+hi)/2;
                    if(v[i]*v[m]<=mid)
                        lo=m;
                    else
                        hi=m;
                }
                ind+=lo-i;
            }
        }
        if(ind<k)
        {
            s=mid;
        }
        else
        {
            e=mid;
        }
    }
    cout << e;
    return 0;
}


Measured memory_bytes: 1792
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
BC = [list(map(int, input().split())) for _ in range(M)]
count = 0

BC = sorted(BC, key=lambda x: x[1],reverse=True)
min_A = min(A)

for B,C in BC:
  if min_A >= C and count > N:
    break
  else:
    l = min(B, N-count)
    for i in range(l):
      count+=1
      A.append(C)

A.sort()

ans = sum(A[count:len(A)])

print(ans)


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

using namespace std;

typedef long long ll;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n * 3);
    multiset<int> l;
    multiset<int, greater<int>> r;
    ll s1 = 0, s2 = 0;
    for (int i = 0; i < n * 3; ++i) {
        cin >> a[i];
        if (i < n) {
            l.insert(a[i]);
            s1 += a[i];
        }
        if (i >= n * 2) {
            r.insert(a[i]);
            s2 += a[i];
        }
    }
    ll ans = s1 - s2;
    vector<ll> kek(n * 3), lol(n * 3);
    kek[n - 1] = s1;
    lol[n * 2] = s2;
    for (int i = n; i < n * 2; ++i) {
        if (a[i] > *l.begin()) {
            s1 += a[i] - *l.begin();
        }
        l.insert(a[i]);
        l.erase(l.begin());
        kek[i] = s1;
    }
    for (int i = n * 2 - 1; i >= n; --i) {
        if (a[i] < *r.begin()) {
            s2 += a[i] - *r.begin();
        }
        r.insert(a[i]);
        r.erase(r.begin());
        lol[i] = s2;
    }
    for (int i = n - 1; i < n * 2; ++i) {
        ans = max(ans, kek[i] - lol[i + 1]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 15488
/*
 * 0616.cc: JOI Park
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 200000;

typedef long long ll;
const ll LINF = 1LL << 60;

/* typedef */

typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<pii> vpii;

/* global variables */

vpii nbrs[MAX_N];
ll dists[MAX_N], dsums[MAX_N];
pli cds[MAX_N];
bool used[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m, c;
  cin >> n >> m >> c;

  ll sum = 0;
  for (int i = 0; i < m; i++) {
    int ai, bi, di;
    cin >> ai >> bi >> di;
    ai--, bi--;
    nbrs[ai].push_back(pii(bi, di));
    nbrs[bi].push_back(pii(ai, di));
    sum += di;
  }
  //printf("sum=%lld\n", sum);

  for (int i = 0; i < n; i++) dists[i] = LINF;
  dists[0] = 0;

  priority_queue<pli> q;
  q.push(pli(0, 0));

  while (! q.empty()) {
    pli u = q.top(); q.pop();
    ll ud = -u.first;
    int &ui = u.second;
    if (dists[ui] != ud) continue;

    vpii &nbru = nbrs[ui];
    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &vi = vit->first;
      ll vd = ud + vit->second;
      if (dists[vi] > vd) {
	dists[vi] = vd;
	q.push(pli(-vd, vi));
      }
    }
  }

  for (int i = 0; i < n; i++) cds[i] = pli(dists[i], i);
  sort(cds, cds + n);

  for (int i = 0; i < n; i++) {
    int &ui = cds[i].second;
    vpii &nbru = nbrs[ui];
    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++)
      if (used[vit->first]) dsums[ui] += vit->second;
    used[ui] = true;
  }
  //for (int i = 0; i < n; i++)
  //printf("%d: dists=%lld, dsums=%lld\n",
  //cds[i].second + 1, cds[i].first, dsums[cds[i].second]);

  ll mind = LINF;
  for (int i = 0; i < n; i++) {
    sum -= dsums[cds[i].second];
    ll d = cds[i].first * c + sum;
    //printf("%lld\n", d);
    if (mind > d) mind = d;
  }
  printf("%lld\n", mind);
  return 0;
}

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

#include <set>
int main(){
	std::string S;
	std::cin >> S;
	std::vector<int> count(3);
	count[0]=count[1]=count[2]=0;

	for(int i=0;i<S.size();i++){
		if(S[i]=='a'){
			count[0]++;
		}else if(S[i]=='b'){
			count[1]++;
		}else{
			count[2]++;
		}
	}
	std::sort(count.begin(),count.end());
	if(count[0]==count[1]&&count[1]==count[2]){
		std::cout <<"YES" <<std::endl;
	}else if(count[0]==count[1]&&count[2]==count[0]+1){
		std::cout <<"YES" <<std::endl;
	}else if(count[1]==count[2]&&count[0]==count[1]-1){
		std::cout <<"YES" <<std::endl;
	}else{
		std::cout << "NO" <<std::endl;
	}
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N = 1e5 + 5;
int n , m , in[N] , depth[N] , ans;
queue<int> q;
vector<int> g[N];
int main(){
	scanf("%d%d",&n,&m);
	for (int i = 0,x,y; i < m; ++i){
		scanf("%d%d",&x,&y),--x,--y;
		g[x].pb(y);
		in[y]++;
	}
	for (int i = 0; i < n; ++i){
		if(!in[i])q.push(i);
	}
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(auto x : g[u]){
			depth[x] = max(depth[x] , depth[u] + 1);
			ans = max(depth[x] , ans);
			if(--in[x] == 0)q.push(x);
		}
	}
	printf("%d\n",ans);
	//puts("XD");

	




}	

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int a, b;
    while(cin >> a >> b, a){
        vector<int> ans(3), v = {1000, 500, 100};
        int c = b - a;
        rep(i, 3){
            ans[i] = c / v[i];
            c %= v[i];
        }
        cout << ans[2] << " " << ans[1] << " " << ans[0] << endl;
    }

    return 0;
}


Measured memory_bytes: 3144
a,b,k = (int(x) for x in input().split())

if a > b:
	c = b
else:
	c = a

cnt = 0

while(1):
	if(a % c == 0) & (b % c == 0):
		cnt += 1

	if(cnt == k):
		print(c)
		exit()

	c -= 1

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int N = 2e5+7;
char s[N];
int main()
{
    scanf("%s",s + 1);
    long long res = 0,cur = 0;
    const int len = strlen(s + 1);
    for(int i = 1;i <= len;++i)
    {
        if(s[i] == 'W')
            res += cur;
        else ++cur;
    }
    printf("%lld",res);
    return 0;
}


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

#define int long long

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    vb v(110, false);
    REP(i, 3)
    {
        int a; cin >> a;
        v[a] = true;
    }
    cout << accumulate(ALL(v), 0) << endl;
}

Measured memory_bytes: 3620
# import sys
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()
# sys.setrecursionlimit(100000)
# INF = 1001001001001
# MOD = 1000000007

def main():

    N = int(input())
    A = list(map(int, input().split()))

    count = [0 for _ in range(N + 1)]
    comb = [0 for _ in range(N + 1)]

    for a in A:
        count[a] += 1

    for i in range(1, N + 1):
        comb[i] = count[i] * (count[i] - 1) * 0.5

    all_comb = sum(comb)
    # print(count)
    # print(comb)
    # print(all_comb)

    for i in range(1, N + 1):
        num = A[i - 1]
        ans = all_comb - comb[num] + (count[num] - 1) * (count[num] - 2) * 0.5
        print(int(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 91316
x,k,d=map(int,input().split())
if x==0:
    if k%2==0:
        print(0)
    else:
        print(d)
elif x>0:
    if x-k*d>=0:
        print(x-k*d)
    else:
        a=x//d
        x-=d*a
        k-=a
        if k%2==0:
            print(x)
        else:
            print(abs(x-d))
else:
    if x+k*d<=0:
        print(abs(x+k*d))
    else:
        a=(-x)//d
        x+=d*a
        k-=a
        if k%2==0:
            print(abs(x))
        else:
            print(abs(x+d))


Measured memory_bytes: 9212
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;

	int ans=0;
	for(int i=1;i<n;i++){
		int cnt=0;

		for(char c='a';c<='z';c++){
			bool left=false,right=false;

			for(int j=0;j<i;j++)
				if(s[j]==c)
					left=true;

			for(int j=i;j<n;j++)
				if(s[j]==c)
					right=true;

			if(left&&right)
				cnt++;
		}

		if(ans<cnt)
			ans=cnt;
	}

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


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    int N,M;
    cin >> N >> M;

    int ans = (1900*M + 100*(N - M)) * pow(2,M);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
// g++ hello.cpp && ./a.out
using namespace std;

int main () {
	int x;
	cin >> x;
	if (x >= 30) {
		cout << "Yes" <<endl;
	}
	else {
		cout << "No" <<endl;
	}
	return 0;
}


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

using namespace std;

#define LIMIT 100
typedef pair<int64_t, int64_t> ii;

char m[50][50];
int len[50][50];

int h, w;
int score = 0;

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


//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> h >> w;
  memset(len, 0, 50*50*sizeof(len[0][0]));

  int white = 0;

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> m[i][j];
      if (m[i][j] == '.') white++;
    }
  }

  queue<pair<int, int>> qu;
  if (m[0][0] == '.') {
    qu.push(ii(0, 0));
    len[0][0] = 1;
  }
  while(!qu.empty()){
    ii p = qu.front();
    qu.pop();
    int x = p.first;
    int y = p.second;
    m[x][y] = '#';
    for (int i = 0; i < 4; ++i) {
      int nx = x+dx[i];
      int ny = y+dy[i];
      if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
      if (m[nx][ny] != '.') continue;
      if (len[nx][ny] != 0) continue;
      len[nx][ny] = len[x][y] + 1;
      qu.push(ii(nx, ny));
    }
    //printf("%d %d\n", x, y);
  }

  int a = len[h-1][w-1];

  if( a == 0){
    std::cout << -1 << std::endl;
  }
  else{
    std::cout << white - a << std::endl;
  }

  return 0;

}



Measured memory_bytes: 256
n = int(input())

mat = [[0] * (n) for _ in range(n)]

for _ in range(n):
    array = list(map(int, input().split()))
    u = array[0]
    k = array[1]
    for i in range(2, len(array)):
        mat[u - 1][array[i] - 1] = 1
        # mat[array[i] - 1][u - 1] = 1

for i in range(n):
    for j in range(n):
        if j == n - 1:
            print("%d" % (mat[i][j]))
        else:
            print("%d " % (mat[i][j]), end="")



Measured memory_bytes: 6524
import java.util.*;

public class Main {
	int n;
	ArrayList<Integer> list;
	
	void loop(int x){
		for(int i=n-x;i>0;i--){
			if(list.size()==0 || list.get(list.size()-1)>=i){
				list.add(i);
				if(x+i==n) print();
				else loop(x+i);
				list.remove(list.size()-1);	
			}
		}
	}
	
	void print(){
		for(int i=0;i<list.size();i++){
			if(i!=0) System.out.print(" ");
			System.out.print(list.get(i));
		}
		System.out.println();
	}
	
	void solve(){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			n = sc.nextInt();
			if(n==0) break;
			list = new ArrayList<Integer>();
			loop(0);
		}
	}
	
	
	public static void main(String[] args) {
		new Main().solve();
	}	
}

Measured memory_bytes: 53004
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

const ll MAXA = 100001;
ll D[MAXA];

int main()
{
    ll S = 0;

    ll N;
    cin >> N;

    rep (i, N)
    {
        ll a;
        cin >> a;

        ++D[a];

        S += a;
    }

    ll Q;
    cin >> Q;

    rep (i, Q)
    {
        ll b, c;
        cin >> b >> c;

        S += (c - b) * D[b];
        cout << S << endl;

        D[c] += D[b];
        D[b] = 0;
    }

    return 0;
}


Measured memory_bytes: 4408
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

string s;

int main() {
    cin >> s;
    cout << s.substr(0, 4) + " " + s.substr(4) << "\n";
    return 0;
}

Measured memory_bytes: 256
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let kt: Vec<usize> = read_vec();
    let k = kt[0] as u32;
    let t = kt[1];
    let mut a: Vec<u32> = read_vec();
    a.sort();
    let m = a[t - 1];
    if m <= (k + 1) / 2 {
        println!("0");
    } else {
        println!("{}", 2 * m - k - 1);
    }
}


Measured memory_bytes: 4352