akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();

        int[] times = new int[n];
        for(int i = 0; i < n; i++)
            times[i] = sc.nextInt();

        long total = 0;
        int start = 0;
        if(times[0] > t) {
            start = times[0];
            total = t;
        }
        for(int i = 1; i < n; i++) {
          if(times[i] > times[i-1] + t) {
            total += times[i-1] - start + t;
            start = times[i];
          }
        }
        total += times[n-1] - start + t;

        System.out.println(total);
    }
}



Measured memory_bytes: 84952
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int h,w,n;
vector<P> vec;

int pos(int rest,int v){
	rest%=2*w;
	while(rest>0){
		int tmp;
		if((rest+v)%2)tmp=min(rest,w-1-v);
		else tmp=-min(rest,v);
		v+=tmp;
		rest-=abs(tmp);
		if(rest>0)rest--;
	}
	return v;
}

int seq[200001];
int res[200001];

int main(void){
	scanf("%d%d%d",&h,&w,&n);
	for(int i=0;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		vec.push_back(P(a,b));
	}
	for(int i=0;i<w;i++){
		seq[i]=i;
	}
	sort(vec.begin(),vec.end());
	for(int i=0;i<n;i++){
		swap(seq[pos(vec[i].first,vec[i].second)],seq[pos(vec[i].first,vec[i].second+1)]);
	}
	for(int i=0;i<w;i++){
		res[seq[pos(h,i)]]=i;
	}
	for(int i=0;i<w;i++){
		printf("%d\n",res[i]+1);
	}
	return 0;
}

Measured memory_bytes: 5960
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] x = new int[n];
        for(int i=0; i<n; i++){
            x[i] = sc.nextInt();
        }

        int min = Integer.MAX_VALUE;

        for(int i=0; i<n-k+1; i++){
            if(Math.abs(x[i]) + Math.abs(x[i+k-1] - x[i]) < min){
                min = Math.abs(x[i]) + Math.abs(x[i+k-1] - x[i]);
            }
            if(Math.abs(x[i+k-1]) + Math.abs(x[i+k-1] - x[i]) < min){
                min = Math.abs(x[i+k-1]) + Math.abs(x[i+k-1] - x[i]);
            }
        }

        System.out.println(min);


    }
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int dp[101][10001];

int main()
{
    rep(i, 101) rep(j, 10001) dp[i][j] = 1e9 + 1;
    dp[0][0] = 0;
    int n, w;
    cin >> n >> w;
    int value[n], wight[n];

    rep(i, n) cin >> value[i] >> wight[i];
    rep(i, n)
    {
        rep(j, 100 * n + 1)
        {
            if (j >= value[i])
                dp[i + 1][j] = min(dp[i][j], dp[i][j - value[i]] + wight[i]);
            else
                dp[i + 1][j] = dp[i][j];
        }
    }

    int ans = 0;

    rep(j, 100 * n + 1) if (dp[n][j] <= w) ans = j;

    OP(ans);

    return 0;
}


Measured memory_bytes: 7056
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
int main() {
	int N, c = 0;
	cin >> N;
	vector<ll> a(N), b(N);
	rep(i, 0, N)cin >> a[i];
	sort(all(a));
	b[0] = a[0];
	rep(i, 1, N)b[i] = b[i - 1] + a[i];
	if (b[0] * 2 >= a[1])c++;
	rep(i, 0, N - 1) {
		if (b[i] * 2 < a[i + 1])c = 0;
		c++;
	}
	printf("%d\n", c);
	return 0;
}


Measured memory_bytes: 1792
import java.io.IOException;
import java.util.Scanner;

/**
 * Created on 2017/09/29 7:16.
 */
public class Main {
    public static boolean isStrong(int a1, int b1, int a2, int b2) {
        int p1 = 100 * b1;
        int q1 = a1 + b1;
        int p2 = 100 * b2;
        int q2 = a2 + b2;

        if (q1 == 0) {
            return false;
        }
        if (q2 == 0) {
            return true;
        }

        return p1 * q2 > p2 * q1;
    }

    public static void main(String[] args) throws IOException {
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt() * 100;
        int B = sc.nextInt() * 100;
        int C = sc.nextInt();
        int D = sc.nextInt();
        int E = sc.nextInt();
        int F = sc.nextInt();

        int ansA = 0;
        int ansB = 0;

        for (int a = 0; a * A <= F; a++) {
            for (int b = 0; a * A + b * B <= F; b++) {
                int wa = a * A + b * B;
                int limit = Math.min(wa / 100 * E, F - wa);
                for (int c = 0; c * C <= limit; c++) {
                    for (int d = 0; c * C + d * D <= limit; d++) {
                        int wb = c * C + d * D;
                        if (isStrong(wa, wb, ansA, ansB)) {
                            ansA = wa;
                            ansB = wb;
                        }
                    }
                }
            }
        }
        System.out.println((ansA + ansB) + " " + ansB);
    }
}

Measured memory_bytes: 23124
N = int(input())
d1 = [0] * N
d2 = [0] * N
for i in range(N):
    d1[i], d2[i] = map(int, input().split())
countb = 0
for i in range(N):
    if d1[i] == d2[i]:
        countb += 1
        if countb == 3:
            print('Yes')
            break
    else:
        countb = 0
if countb != 3:
    print('No')

Measured memory_bytes: 9132
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;
ll mod = pow(10,9) + 7;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}
int main() {
	char c;
	cin >> c;
	const string vowel = "aeiou";
	cout << (vowel.find(c) != string::npos ? "vowel" : "consonant") << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define rnt re int
#define re register
#define I inline int
#define V inline void
#define B inline bool
#define isnum(ch) ('0'<=ch&&ch<='9')
#define FOR(i,a,b) for(rnt i=a;i<=b;i++)
#define ROF(i,a,b) for(rnt i=a;i>=b;i--)
#define gc (_op==_ed&&(_ed=(_op=_buf)+fread(_buf,1,100000,stdin),_op==_ed)?EOF:*_op++)
char _buf[100000],*_op(_buf),*_ed(_buf);
I getint(){
	rnt _s=0;re char _ch=gc;
	while(!isnum(_ch))_ch=gc;
	while(isnum(_ch))_s=_s*10+_ch-48,_ch=gc;
	return _s;
}
const int N=1e5+2,INF=1e9+1;
int n,ans;
I min(const int&x,const int&y){return x<y?x:y;}
I max(const int&x,const int&y){return x>y?x:y;}
struct node{
	int l,r;
	V input(){l=getint(),r=getint();}
	B operator<(const node&u)const{
		return r==u.r?l>u.l:r<u.r;
	}
	I len(){return max(0,r-l+1);}
	node operator+(const node&u)const{
		return (node){max(l,u.l),min(r,u.r)};
	}
}a[N],b[N],c[N];
V input(){n=getint();FOR(i,1,n)a[i].input();}
V init(){sort(a+1,a+1+n);}
V work(){
	rnt p=1,q=1,maxn=0;
	if(n<=2){
		ans=0;
		FOR(i,1,n)ans+=a[i].len();
		return void(cout<<ans);
	}
	FOR(i,2,n)
		if(a[i].l>a[p].l)
			maxn=max(maxn,a[p].len()),p=i;
		else maxn=max(maxn,a[i].len());
	ans=max(ans,maxn+max(0,(a[p]+a[q]).len()));
	b[0].r=c[n+1].r=INF;
	FOR(i,1,n)
		if(i!=q&&i!=p)b[i]=b[i-1]+a[i];
		else b[i]=b[i-1];
	ROF(i,n,1)
		if(i!=q&&i!=p)c[i]=c[i+1]+a[i];
		else c[i]=c[i+1];
	FOR(i,1,n-1)ans=max(ans,(a[q]+b[i]).len()+(a[p]+c[i+1]).len());
	cout<<ans<<'\n';
}
int main(){
	input();
	init();
	work();
	return 0;
}

Measured memory_bytes: 2688
n = input()
d_s = {}
d_h = {}
d_c = {}
d_d = {}
for x in map(str, xrange(1, 14)):
    d_s[x] = 0 
    d_h[x] = 0 
    d_c[x] = 0 
    d_d[x] = 0 
for x in xrange(1, n+1):
    line = raw_input().split()
    if line[0]=='S':
        d_s[line[1]] = 1
    elif line[0]=='H':
        d_h[line[1]] = 1
    elif line[0]=='C':
        d_c[line[1]] = 1
    else:
        d_d[line[1]] = 1
d_key = ['S', 'H', 'C', 'D']
d_all = {d_key[0]: d_s, d_key[1]: d_h, d_key[2]: d_c, d_key[3]: d_d} 
for shcd in d_key:
    for rank in xrange(1, 14):
        if d_all[shcd][str(rank)]==0:
            print '%s %s' % (shcd, rank)

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

int main(){
    string S,T;
    cin >> S >> T;
    int a = -1,flag;
    for(int i = 0;i < S.size()-T.size() + 1; ++i){
        flag = 1;
        for(int j = 0;j<T.size();++j){
            if(S[i + j] != T[j] && S[i+j] != '?'){
                flag = 0;
                break;
            }
        }
        if(flag){
            a = i;
        }
    }

    if(a != -1){
        for(int j = 0;j < T.size();++j){
            S[a+j] = T[j];
        }
    }
    for(int i = 0;i < S.size();++i){
        if(S[i] == '?'){
            S[i] = 'a';
        }
    }
    cout << (a == -1 ? "UNRESTORABLE":S) << endl;
    int k;
    cin >> k;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
 
#define mt make_tuple
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())
 
#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int dict[100005][4];
int timing[100005];

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

  int X, K, Q;

  // init
  cin >> X;
  int sa, sb, ta, tb;
  sa = 0;
  sb = X;
  ta = 0;
  tb = X;
  
  // REMEMBER
  timing[0] = 0;
  dict[0][0] = sa;
  dict[0][1] = sb;
  dict[0][2] = ta;
  dict[0][3] = tb;

  // process
  cin >> K;
  int i, state;
  int da, db;
  state = 0;
  for(int j = 1; j <= K; ++j) {
    cin >> i;
    timing[j] = i;
    i -= timing[j-1];
    if(state == 0) {
      da = min(ta, i);
      db = min(tb, i);
      ta -= da;
      tb -= db;
      sa += max(i-da, 0);
      sb += max(i-db, 0);
    } else {
      da = min(X-ta, i);
      db = min(X-tb, i);
      ta += da;
      tb += db;
      sa -= max(i-da, 0);
      sb -= max(i-db, 0);
    }
    dict[j][0] = sa;
    dict[j][1] = sb;
    dict[j][2] = ta;
    dict[j][3] = tb;
    state = (state + 1) % 2;
  }

  // query
  cin >> Q;
  int t, a;
  int target;
  int ma, md, ms;
  int ans;
  while(Q--) {
    cin >> t >> a;
    target = (upper_bound(timing, timing+(K+1), t) - timing)-1;

    ma = timing[target];
    md = t - ma;

    if(a <= dict[target][0]) {
      ans = dict[target][2];
    } else
    if(a >= dict[target][1]) {
      ans = dict[target][3];
    } else {
      ms = a - dict[target][0];
      ans = dict[target][2] + ms;
    }

    if(target % 2 == 1) {
      ans = min(X, ans+md);
    } else {
      ans = max(0, ans-md);
    }
    cout << ans << endl;
  }

  return 0;
}

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

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

  if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}

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

int main(){
  string s;
  cin >> s;
  
  vector<long long int> a;
  long long int count =0;
  if(s.at(0) == '<'){
    count =1;
  }else{
    count = 2;
  }
  
  long long int pcount = 1;
  long long int number = 0;
  for(int i = 0; i< s.size()-1; i++){
    if(s.at(i) !=s.at(i+1)){
      a.push_back(pcount);
      pcount = 1;
    }else{
      pcount++;
    }
  }
  a.push_back(pcount);
  
  long long int x,y,z,k;
  long long int sum = 0;
  if(count == 1){
    if(a.size()%2 == 0){
      for(int i = 0; i<a.size()/2; i++){
        x = max(a.at(2*i),a.at(2*i+1));
        y = min(a.at(2*i), a.at(2*i+1))-1;
        sum += (x+1)*x/2 + (y+1)*y/2;
       
      }
    }else{
      for(int i = 0; i<a.size()/2; i++){
     
        x = max(a.at(2*i),a.at(2*i+1));
        y = min(a.at(2*i), a.at(2*i+1))-1;
        sum += (x+1)*x/2 + (y+1)*y/2;
       
      }
      z = a.at(a.size()-1);
      sum+= (z+1)*z/2;
     
    }
  }else{
    if(a.size()%2 == 0){
      k = a.at(0);
      sum+= (k+1)*k/2;
      
      for(int i = 0; i<(a.size()/2)-1; i++){
        x = max(a.at(2*i+1),a.at(2*i+2));
        y = min(a.at(2*i+1), a.at(2*i+2))-1;
        sum += (x+1)*x/2 + (y+1)*y/2;
      }
      z = a.at(a.size()-1);
      sum+= (z+1)*z/2;
    
    }else{
      k = a.at(0);
      sum+= (k+1)*k/2;
      for(int i = 0; i<(a.size()/2); i++){
        x = max(a.at(2*i+1),a.at(2*i+2));
        y = min(a.at(2*i+1), a.at(2*i+2))-1;
        sum += (x+1)*x/2 + (y+1)*y/2;

      }
    }
  }
  cout << sum << endl;

}
        
    

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    ll n,k; cin >> n >> k;
    VL tele(n);

    rep(i,n){
        ll a; cin >> a;
        tele[i] = a-1;
    }

    bool flag = true;
    VL visit(n,0);
    ll cur = 0, t = 1, period, begin_loop;
    visit[0] = 1;
    while(flag){
        cur = tele[cur];
        t++;
        if(visit[cur] == 0){
            visit[cur] = t;
        }else{
            period = t - visit[cur];
            begin_loop = visit[cur] - 1;
            flag = false;
        }
    }

    if(k > begin_loop){
        k = (k - begin_loop) % period + begin_loop;
    }

    cur = 0;
    rep(i,k){
        cur = tele[cur];
    }

    cout << cur + 1 << endl;

    return 0;
}

Measured memory_bytes: 6424
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
$alphabet=("a".."j").to_a
$ans=[]
def dfs(s,now,mx)
  if now==N
    $ans.push(s)
    return
  end
  "a".upto(mx) do|c|
      #next if i+j<0
      dfs(s+c,now+1,(c==mx) ? $alphabet[c.ord-"a".ord+1] : mx)
  end   
end
dfs("",0,"a")
puts $ans.sort.join("\n")

Measured memory_bytes: 24388
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int n, c, *v, *w;
} list;

list g[100000];

int paint[100000];

void add(int i, int j, int w) {
	if (g[i].n+1 > g[i].c) {
		g[i].c *= 2;
		g[i].v = realloc(g[i].v, g[i].c * sizeof *g[i].v);
		g[i].w = realloc(g[i].w, g[i].c * sizeof *g[i].w);
	}

	g[i].v[g[i].n] = j;
	g[i].w[g[i].n] = w;
	g[i].n++;
}

void dfs(int v) {
	list gc = g[v];
	for (int i = 0; i < gc.n; i++) {
		if (paint[gc.v[i]] != -1) continue;
		paint[gc.v[i]] = gc.w[i] ^ paint[v];
		dfs(gc.v[i]);
	}
}

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

	for (int i = 0; i < n; i++) {
		g[i].n = 0;
		g[i].c = 8;
		g[i].v = malloc(8 * sizeof *g[i].v);
		g[i].w = malloc(8 * sizeof *g[i].w);
		paint[i] = -1;
	}

	for (int i = 0; i < n-1; i++) {
		int a, b, w;
		scanf("%d%d%d", &a, &b, &w);
		a--; b--; w %= 2;
		add(a, b, w);
		add(b, a, w);
	}

	paint[0] = 0;
	dfs(0);

	for (int i = 0; i < n; i++) {
		printf("%d\n", paint[i]);
		free(g[i].v);
		free(g[i].w);
	}
}


Measured memory_bytes: 13952
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
a=[0]+a
d=defaultdict(int)

for i in range(1,n+1):
  d[a[i]+i]+=1

ans=0
for j in range(1,n+1):
  ans+=d[-a[j]+j]
print(ans)

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main() {
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    vector<vector<ll>> s(m);
    for(ll i = 0; i < m; i++){
        ll k;
        cin >> k;
        s[i].resize(k);
        for(ll j = 0; j < k; j++){
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vector<ll> p(m);
    for(ll i = 0; i < m; i++) cin >> p[i];


    for(ll swi = 0; swi < (1<<n); swi++){
        bool ok = true;
        for(ll i = 0; i < m; i++){
            ll a = 0;
            for(ll k = 0; k < s[i].size(); k++){
                a |= (1 << s[i][k]);
            }
            a &= swi;
            ll count = 0;
            for(ll k = 0; k < 10; k++){
                if((a>>k) & 1) count++;
            }
            if(count % 2 != p[i]) ok = false;
        }
        if(ok) ans++;
    }

    cout << ans << endl;





}


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))

to_remove = []
for i in range(m):
    a, b = map(int, input().split())
    if h[a-1] < h[b-1]:
        to_remove.append(a)
    elif h[a-1] > h[b-1]:
        to_remove.append(b)
    else:
        to_remove.append(a)
        to_remove.append(b)

print(n - len(set(to_remove)))

Measured memory_bytes: 20112
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1<<29;
int main() {
    int K; cin >> K;
    ll res = 0;
    for (int a=1;a<=K;a++) for (int b=1;b<=K;b++) for (int c=1;c<=K;c++){
        res += gcd(gcd(a,b),c);
    }
    cout << res << endl;
    return 0;
}

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

using ll = long long;

// 繰り返し自乗法(x^nをmで割った余り) O(logn)
ll power(ll x, ll n, ll m) {
  ll res = 1;
  if (n > 0) {
    res = power(x, n / 2, m);
    if (n % 2 == 0) res = (res * res) % m;
    else res = (((res * res) % m) * x) % m;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, p;
  string s;
  cin >> n >> p >> s;
  
  if (p == 2 || p == 5) {
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      if ((s.at(i) - '0') % p == 0) ans += i + 1;
    }
    cout << ans << '\n';
    return 0;
  }
  
  ll ans = 0;
  map<ll, ll> mp;
  mp[0]++;
  
  ll keep = 0;
  for (int i = 0; i < n; i++) {
    keep *= 10;
    keep += s.at(i) - '0';
    keep %= p;
    ll keep2 = power(10, n - i - 1, p);
    keep2 *= keep;
    keep2 %= p;
    ans += mp[keep2];
    mp[keep2]++;
  }
  
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1044
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



int main() {
    int N; cin>>N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin>>a[i];
    }
    for (int i = 0; i < N; i++) {
        if(a[i]%2){
            puts("first");
            return 0;
        }
    }
    puts("second");

    return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {
    int N, W;
    cin >> N >> W;
    const int INF = W + 1;
    const int V = 100 * 1000;

    vi dp(V + 1, INF);
    dp[0] = 0;
    rep(i, N) {
        int w, v;
        cin >> w >> v;
        for (int j = V - v; j >= 0; --j) {
            smin(dp[j + v], dp[j] + w);
        }
    }
    int ans = 0;
    rep(i, V + 1)if (dp[i] <= W)ans = i;
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

ll ch2 (ll n) { return n*(n-1)/2;}

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    map<string, ll> mp;
    rep(i,n) {
        cin >> s[i];
        ssort(s[i]);
    }
    rep(i,n) {
        mp[s[i]]++;
    }
    ll ans = 0;
    for (auto ele : mp) {
        ans += ch2(ele.second);
    }
    cout << ans << "\n";
    return 0;
}


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

const ll INF = pow(10, 9) + 7;

int main() {
  ll n,m;
  cin >> n >> m;
  priority_queue<ll> q;
  rep(i,n) {
    ll a;
    cin >> a;
    q.push(a);
  }
  rep(i,m){
    ll m = q.top();q.pop();
    q.push(m/2);
  }
  ll sum = 0;
  rep(i,n){
    ll l = q.top();q.pop();
    sum += l;
  }
  cout << sum << endl;
}

Measured memory_bytes: 1400
#include <iostream>
typedef long long ll;
using namespace std;

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}

ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll f(ll x,int c,int d){
  ll res = x;
  res -=x/c;
  res -=x/d;
  res +=x/lcm(c,d);
  return res;
}

int main(){
  ll a,b;
  int c,d;
  cin >> a >> b >> c >> d;
  ll ans = f(b,c,d)-f(a-1,c,d);
  cout << ans << endl;
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int l, r;
  for(int i=0;i<s.size();i++){
    if(s[i] == 'A'){
      l = i;
      break;
    }
  }
  for(int i=0;i<s.size();i++){
    if(s[i] == 'Z'){
      r = i;
    }
  }
  cout << r-l+1 << endl;
}

Measured memory_bytes: 640
import std.stdio, std.algorithm, std.array, std.range, std.string, std.conv, std.uni;

void main() {
    auto s = readln.strip;

    auto yy = s[0..2].to!int;
    auto mm = s[2..$].to!int;

    if (1 <= mm && mm <= 12) {
        if (1 <= yy && yy <= 12) {
            writeln("AMBIGUOUS");
        } else {
            writeln("YYMM");
        }
    } else {
        if (1 <= yy && yy <= 12) {
            writeln("MMYY");

        } else {
            writeln("NA");
        }

    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,A[100];

void trace(){
    for ( int i = 0; i < n; i++ ){
        if ( i ) cout << " ";
        cout << A[i];
    }
     cout << endl;
}

int main(){
    int i,v,j;
    
    cin >> n;
    for ( int i = 0; i < n; i++ ) cin >> A[i];
    
    trace();
    
        for ( int i = 1; i <= n-1; i++){
            v = A[i];
            j = i-1;
        while (j >= 0 && A[j] > v ){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace();
     }
    
}
        
    

Measured memory_bytes: 1160
#include <stdio.h>

int n, A[50];

int solve(int i, int m) {
    if (m == 0) return 1;
    if (i >= n) return 0;

    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main() {
    int q, M, i;

    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &A[i]);

    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &M);
        if (solve(0, M)) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}



Measured memory_bytes: 2128
a = ['SAT', 'SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI']
b = [1, 7, 6, 5, 4, 3, 2]
s = input()

for i in range(len(a)):
    if s==a[i]:
        print(b[i])


Measured memory_bytes: 2940
import sys
import math

a, b = map(int, input().split())

for i in range(1, 1001):
    eat_in = math.floor(i * 0.08)
    eat_out = math.floor(i * 0.1)
    if eat_in == a and eat_out == b:
        print(i)
        sys.exit()
print(-1)

Measured memory_bytes: 3060
function main()
	N=parse(Int,readline())
	A=sort(map(x->parse(Int,x),readlines()))
	ans=0
	t=div(N,2)
	if N%2==0
		for i=1:t
			ans-=(i==t ? 1 : 2)*A[i]
			ans+=(i==t ? 1 : 2)*A[N+1-i]
		end
	else
		for i=1:t-1
			ans-=2*A[i]
			ans+=2*A[N+1-i]
		end
		ans+=max(A[t+2]+A[t+1]-2*A[t],2*A[t+2]-A[t+1]-A[t])
	end
	println(ans)
end
main()


Measured memory_bytes: 130816
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <fstream>

using namespace std;

template<class T> inline T cabs(const T &x) { return x > 0 ? x : (-x); }
template<class T> inline T gcd(const T &x, const T &y) { return (y == 0) ? x : gcd(y, x % y); }
template<class T> inline T _sgn(const T &x) { return (x > 0) - (x < 0); }

#define dbg(x) cout << #x << " = " << (x) << endl
#define dbg2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define dbg3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl
#define dbg4(x,y,z,w) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #w << " = " << w << endl

#define out(x) cout << (x) << endl
#define out2(x,y) cout << (x) << " " << (y) << endl
#define out3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define out4(x,y,z,w) cout << (x) << " " << (y) << " " << (z) << " " << (w) << endl

const int maxN = 100000 + 10;

char str[maxN];
int len;

int main()
{
    scanf("%s", str);
    len = strlen(str);
    int ans = 0;
    for(int i = 1; i < len; i ++)
        ans += str[i] != str[i - 1];
    out(ans);
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cctype>
#include<cstring>
#define maxn 100007
#define SDOI2020 RP++ 
using namespace std;
int n,m,k,ans;
inline int read()
{
	int x=0;
	int flag=0;
	char ch;
	ch=getchar();
	while(!isdigit(ch)) 
	{
		if(ch=='-') flag=1;
	ch=getchar();	
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+ch-48;
		ch=getchar();
		}
		if(flag==1) x=-x;	
		return x;
}

int main()
{
	n = read();
	m = read();
	k = read();
	ans = k / max(n,m);
	if(k % max(n,m)) ans++;
	printf("%d\n",ans);
	
	
	return 0;
}

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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int A = 100;
	int res = 0;
	while (A < N) {
		A += A / 100;
		res++;
	}
	cout << res << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define ull unsigned long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) (int)(x).size()
using namespace std;

const int N = 2e5+7;
const int M = 1<<19;

int n;

int p[N];

struct tree
{
	PII load[2*M];

	void insert(int a, int v)
	{
		a += M;
		load[a] = mp(v, a-M);
		a /= 2;

		while(a>=1)
		{
			load[a] = min(load[2*a], load[2*a+1]);
			a /= 2;
		}
	}

	PII query(int a, int b)
	{
		if(a>b)
			return mp(-1, -1);

		a += M;
		b += M;

		PII res = min(load[a], load[b]);

		while(a<b-1)
		{
			if(a%2==0)
				res = min(res, load[a+1]);

			if(b%2==1)
				res = min(res, load[b-1]);

			a /= 2;
			b /= 2;
		}

		return res;
	}

	tree()
	{
		for(int i = 0; i < 2*M; ++i)
		{
			load[i] = mp(inf, inf);
		}
	}
};

tree P, NP;

set<pair<pair<PII, PII>, PII> > Q;

void solve(pair<pair<PII, PII>, PII> v)
{
	Q.erase(Q.begin());

	int a = v.nd.st, b = v.nd.nd, l = v.st.st.nd, r = v.st.nd.nd;

	cout << p[l] << " " << p[r] << " ";

	PII A1, A2, B1, B2, C1, C2;

	if(a%2==1)
	{
		A1 = NP.query(a, l-1);
		A2 = P.query(A1.nd+1, l-1);	
	}
	else
	{
		A1 = P.query(a, l-1);
		A2 = NP.query(A1.nd+1, l-1);
	}

	if((l+1)%2==1)
	{
		B1 = NP.query(l+1, r-1);
		B2 = P.query(B1.nd+1, r-1);
	}
	else
	{
		B1 = P.query(l+1, r-1);
		B2 = NP.query(B1.nd+1, r-1);
	}

	if((r+1)%2==1)
	{
		C1 = NP.query(r+1, b);
		C2 = P.query(C1.nd+1, b);
	}
	else
	{
		C1 = P.query(r+1, b);
		C2 = NP.query(C1.nd+1, b);
	}

	if(a<l-1) Q.emplace(mp(A1, A2), mp(a, l-1));
	if(l+1<r-1) Q.emplace(mp(B1, B2), mp(l+1, r-1));
	if(r+1<b) Q.emplace(mp(C1, C2), mp(r+1, b));
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n;

	for(int i = 1; i <= n; ++i)
	{
		cin >> p[i];
	}

	for(int i = 1; i <= n; ++i)
	{
		if(i%2)
			NP.insert(i, p[i]);
		else
			P.insert(i, p[i]);
	}

	PII q1 = NP.query(1, n);
	PII q2 = P.query(q1.nd+1, n);

	Q.emplace(mp(q1, q2), mp(1, n));

	while(!Q.empty())
		solve(*Q.begin());
}


Measured memory_bytes: 21248
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int go = 0;
    int seven = 0;
    int a = sc.nextInt();
    if(a == 5) go++;
    if(a == 7) seven++;
    int b = sc.nextInt();
    if(b == 5) go++;
    if(b == 7) seven++;
    int c = sc.nextInt();
    if(c == 5) go++;
    if(c == 7) seven++;
    String ans = "NO";
    if((go == 2) && (seven == 1)) ans = "YES";
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

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

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
const double EPS = 1e-7;
const double MAX = 1000 + 5;


int main() {
	int n;
	cin >> n;
	vector<vector<int>> t(n);
	for (int i = 1; i < n; i++) {
		int a;
		cin >> a;
		a--;
		t[a].emplace_back(i);
	}

	stack<int> s;
	queue<int> q;
	q.push(0);
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (int u : t[v]) {
			q.push(u);

		}
		s.push(v);
	}

	vector<int> d(n);
	while (!s.empty()) {
		vector<int> dp;
		int v = s.top();
		s.pop();
		for (int u : t[v]) {
			dp.emplace_back(d[u]);
		}

		sort(dp.begin(), dp.end(), greater<int>());
		int l = dp.size();
		for (int i = 0; i < l; i++) {

			dp[i] += i + 1;
		}

		sort(dp.begin(), dp.end(), greater<int>());

		if (l > 0) {
			d[v] = dp[0];
		}
		else {
			d[v] = 0;
		}
	}
	/*
	for (int i = 0; i < n; i++) {
		cout << d[i] << " ";
	}
	cout << endl;
	*/
	cout << d[0] << endl;
}

Measured memory_bytes: 9424
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int a= (n+1)/1.08;
  if(a*108/100==n){
       cout << a << endl;
  }
  else{
       cout << ":(" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		System.out.println(Math.min(Math.min(a + b, b + c), c + a));

		sc.close();


	}

}




Measured memory_bytes: 21844
function main(lines) {
  const [N, D] = splitN(lines[0]);

  let ans = 0;
  for (let i = 1; i <= N; i++) {
    const [x, y] = splitN(lines[i]);
    if (Math.sqrt(x*x + y*y) <= D) ans++;
  }
  
  return ans;
}


const ans = main( require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n") );
console.log( ans );

function splitN(s) {
  return s.split(' ').map(Number);
}


Measured memory_bytes: 62744
#include <iostream>
#include <stack>
#include <vector>
#include <string>
using namespace std;

typedef struct {
	int v, h;
	bool f;
}P;

stack<int> s;
vector<P> s2;
string str;

int main(){
	cin >> str;
	int ans = 0, h = 0, t;
	P v, u;
	for (int i = 0; i < str.size(); i++) {
		switch (str[i]) {
		case'\\':
			s.push(i);
			h--;
			break;
		case'/':
			if (!s.empty()) {
				t = i - s.top();
				ans += t;
				s.pop();
				s2.push_back({ t,h,true });
				while (s2.size() >= 2) {
					v = s2.back(); s2.pop_back();
					u = s2.back(); s2.pop_back();
					if (v.h > u.h && u.f) {
						v.v += u.v;
						s2.push_back(v);
					}
					else {
						s2.push_back(u);
						s2.push_back(v);
						break;
					}
				}
			}
			else if(!s2.empty()) {
				s2.back().f = false;
			}
			h++;
			break;
		default:
			break;
		}
	}
	cout << ans << endl;
	cout << s2.size();
	for (int i = 0; i < s2.size(); i++) {
		cout << " " << s2[i].v;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3324
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    long idx=0;
    long N, M;
    cin >> N >> M;
    if(N == M) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 384
N,M = map(int,input().split())
dic = dict(zip(list(range(1,N+1)),[0]*N))
bl = [True]*N
ac,wa = 0,0
for i in range(M):
    p,s = input().split()
    if s == "WA":
        dic[int(p)] += 1
    elif s == "AC":
        if bl[int(p)-1]:
            ac += 1
            wa += dic[int(p)]
            bl[int(p)-1] = False
print(ac,wa)

Measured memory_bytes: 17004
#include<stdio.h>
int main()
{
	double n,p,a[]={.5,.25,.125,.0625};
	while(scanf("%lf",&n),n>=0)
	{
		int s=n,c[4]={0},i;
		p=n-s;
		for(i=0;i<4;++i)if(p>=a[i])p-=a[i],c[i]=1;
		if(p||s>255)puts("NA");
		else
		{
			for(i=128;i;i/=2)putchar(s&i?'1':'0');
			putchar('.');
			for(i=0;i<4;++i)putchar(c[i]?'1':'0');
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 0
# string
# a, b, c = input().split()
# str_list = list(input().split())

# number
# a, b, c = map(int, input().split())
# num_list = list(map(int, input().split()))

# lows
# str_list = [input() for _ in range(n)]

# many inputs
# num_list = []
# for i in range(n): num_list.append(list(map(int, input().split())))

x, k, d = map(int, input().split())

if x < 0:
    x = -x

l = int(x/d)

if l < k:
    print(abs(x - ((k-l)%2 + l) * d))
else:
    print(abs(x - k*d))

Measured memory_bytes: 9048
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXT = 11, MAXN = 45, INF = 10000;
int cost[MAXT][MAXT];
int d[MAXT];
bool used[MAXT];
int a, b, c, t, n, anst, ansc, tcost;

int main()
{
    while(cin >> n && n)
    {
        memset(cost, INF, sizeof(cost));
        t = 0;
        REP(n)
        {
            cin >> a >> b >> c;
            cost[a][b] = cost[b][a] = c;
            t = max(t, a + 1); t = max(t, b + 1);
        }
        anst = MAXT; ansc = INF;
        rep(k, t)
        {
            memset(d, INF, sizeof(d));
            memset(used, false, sizeof(used));
            d[k] = 0;
            tcost = 0;
            while(true)
            {
                int v = -1;
                rep(i, t)if(!used[i] && (v == -1 || d[i] < d[v])) v = i;
                if(v == -1) break;
                used[v] = true;
                rep(i,t) d[i] = min(d[i], d[v] + cost[v][i]);
            }
            REP(t) tcost += d[i];
            if(tcost < ansc){ anst = k; ansc = tcost;}
        }
        cout << anst << " "<< ansc << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
R = lambda: map(int, input().split())
n, m = R()
h = [None, *R()]
g = [0] + [1] * n
for _ in range(m):
  a, b = R()
  if h[a] <= h[b]:
    g[a] = 0
  if h[b] <= h[a]:
    g[b] = 0
print(sum(g))    


Measured memory_bytes: 20036
#include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
    	string S;
    	cin >> S;
    	for (int i = 0; i < (int)S.size(); i += 2) {
    		cout << S[i];
    	}
    	cout << endl;
    	return 0;
    }

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<int,P>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
int mypow(int a,int b){
	if(b==0) return 1;
	if(b%2) return mypow(a,b-1)*a%mod;
	int z=mypow(a,b/2);
	return z*z%mod;
}
signed main(){
	int a[5],f=0,ans=0;
	f(i,5){
		cin>>a[i];
		ans+=((a[i]-1)/10+1)*10;
		f=max(f,10-(a[i]-1)%10-1);
	}
	cout<<ans-f<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double a[3025],dp[3025][3025];
int n,i,j;
int main()
{
	cin>>n;
	for(int i=1;i<n+1;i++)
	cin>>a[i];

	dp[1][0]=1-a[1];
	dp[1][1]=a[1];

	for(i=2;i<n+1;i++)
	{
		dp[i][0]=dp[i-1][0]*(1-a[i]);
		for(j=1;j<i;j++)
		{
			dp[i][j]=dp[i-1][j]*(1-a[i])+dp[i-1][j-1]*a[i];
		}
		dp[i][i]=dp[i-1][i-1]*a[i];
	}
	double ans=0;
	for(i=(n/2+1);i<n+1;i++)
	{
		ans+=dp[n][i];
	}
	cout<<setprecision(15)<<fixed<<ans;

	return 0;
}

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

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
	FASTIO;

	int n;
	cin >> n;

	vector<int> v(n);
	for (int i = 0; i < n; i++) cin >> v[i];

	vector<int> dp(n);
	dp[n - 1] = 0;

	for (int i = n - 2; i >= 0; i--)
	{
		if (i == n - 2) dp[i] = abs(v[i] - v[i + 1]);
		else {
			int jump_1 = abs(v[i] - v[i + 1]) + dp[i + 1];
			int jump_2 = abs(v[i] - v[i + 2]) + dp[i + 2];

			dp[i] = min(jump_2, jump_1);
		}
	}

	cout << dp[0];


}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
ll MOD = 1000000007;
ll INF =1<<30;



int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    int ans = 1,odd=1;
    rep(i,n) ans *=3;
    rep(i,n){
        if(a[i]%2==0) odd*=2;
    }
    cout << ans -odd <<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
  int a, p;
  cin >> a >> p;
  int ans = (3*a + p)/2;
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n;
  cin>>n;
  vector<int> V(n);
  for (int i=0; i<n; i++){
    cin>>V[i];
  }
  int k=0;
  for (int j=0;(V[j]%2==0 && j<n); j++){
    if(j==n-1){
      k++;
      j=0;
    }
    V[j]=V[j]/2;
  }
  cout << k <<endl;
}

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

front = array[0]
count = 0
length = len(array)
for i in range(1, len(array)):
    if front == array[i]:
        array[i] = length
        length -= 1
        count += 1
    front = array[i]
print(count)


Measured memory_bytes: 3060
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n;

int main() {
    cin >> n;
    if (n == 0) {
        cout << 0 << '\n';
        return 0;
    }

    Vi v;
    while (n != 0) {
        int m = n % (-2);
        if (m == -1) {
            n = n / -2 + 1;
            v.push_back(1);
        } else {
            n = n / -2;
            v.push_back(m);
        }
    }

    RFOR(i, v) {
        cout << *i;
    }

    cout << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const double PI = 3.14159;

int main()
{
	while (true) {
		int n;
		cin >> n;
		if (n==0) break;
		
		vector<double> x; x.reserve(100);
		vector<double> y; y.reserve(100);
		double tmp_x, tmp_y;
		char dummy;
		for (int i=0; i<n; i++) {
			cin >> tmp_x >> dummy >> tmp_y;
			x.push_back(tmp_x); y.push_back(tmp_y);
		}
		
		double min_y = y[0];
		int min_y_index = 0;
		for (int i=1; i<n; i++) {
			if (min_y > y[i]) { min_y = y[i]; min_y_index = i; }
		}
		
		int curr_index = min_y_index;
		int circumference_points = 0;
		double curr_deg = 0.0;
		do {
			double min_deg = PI;
			double min_deg_index;
			double tmp_deg;
			for (int i=0; i<n; i++) {
				if (i == curr_index) continue;
				tmp_deg = atan2( y[i] - y[curr_index], x[i] - x[curr_index] );
				tmp_deg -= curr_deg;
				if (tmp_deg < 0) tmp_deg += 2*PI;
				if (min_deg > tmp_deg) {
					min_deg = tmp_deg; min_deg_index = i;
				}
			}
			curr_deg += min_deg;
			curr_index = min_deg_index;
			circumference_points++;
			// cout << min_deg_index << " " << curr_deg * 180 / PI << endl;
		} while (curr_index != min_y_index);
		
		cout << n - circumference_points << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
int main(){
  int R;
  cin >>R;
  string ans;
  if(R < 1200){
    ans ="ABC";
  }
  else if(R < 2800){
    ans="ARC";
  }
  else{
    ans="AGC";
  }
  cout << ans << endl;
}






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

int main() {
    int a,b;
    cin >> a >> b;
    cout << (a+b+1)/2 << endl;
}

Measured memory_bytes: 256