akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n;
double dp[301][301][301]={}; //dp[3個ある皿][2個ある皿][1個ある皿] -> すべて空になるまでの期待値
/*
dp[i][j][k]からの遷移
->dp[i][j][k]     確率(n-(i+j+k))/n = p1
->dp[i][j][k-1]   確率k/n = p2
->dp[i][j-1][k+1] 確率j/n = p3
->dp[i-1][j+1][k] 確率i/n = p4
これらの状態に遷移するために1手必要なので +1 をする
dp[i][j][k] = 1 + dp[i][j][k]*p1 + dp[i][j][k-1]*p2 + dp[i][j-1][k+1]*p3 + dp[i-1][j+1][k]*p4
dp[i][j][k]が両辺にあるので移項をする
1-p1 = 1-(n-(i+j+k))/n = (i+j+k)/n = p5
dp[i][j][k]*p5 = 1 + dp[i][j][k-1]*p2 + dp[i][j-1][k+1]*p3 + dp[i-1][j+1][k]*p4
dp[i][j][k] = (1 + dp[i][j][k-1]*p2 + dp[i][j-1][k+1]*p3 + dp[i-1][j+1][k]*p4)/p5
            = (n + dp[i][j][k-1]*k + dp[i][j-1][k+1]*j + dp[i-1][j+1][k]*i)/(i+j+k)
初期条件 dp[i][j][k]=0
*/
double solve(int i, int j, int k){
  if(dp[i][j][k]>-1) return dp[i][j][k];
  double p=n;
  if(k>0) p += solve(i,j,k-1) * k;
  if(j>0) p += solve(i,j-1,k+1) * j;
  if(i>0) p += solve(i-1,j+1,k) * i;
  p /= (i+j+k);
  dp[i][j][k] = p;
  return p;
}
int main(){
  cin >> n;
  vector<int> num(4,0);
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    num[a]++;
  }
  for(int i=0;i<301;i++)for(int j=0;j<301;j++)for(int k=0;k<301;k++) dp[i][j][k]=-1;
  dp[0][0][0]=0; //初期条件
  cout << fixed << setprecision(12) << solve(num[3],num[2],num[1]) << endl;                                             
}

Measured memory_bytes: 216872
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include<iomanip>
using namespace std;

int N, M;

int root(int x, vector<int>& par) {
    if (par[x] == x) return x;
    return par[x] = root(par[x], par);
}

void unite(int x, int y, vector<int>& par) {
    x = root(x, par);
    y = root(y, par);
    if (x == y) return;
    par[x] = y;
}

int main() {
    cin >> N >> M;
    vector<int> par(N);
    for (int i = 0; i < N; i++) {
        par[i] = i;
    }
    int x, y, z;
    for (int i = 0; i < M; i++) {
        cin >> x >> y >> z;
        unite(x - 1, y - 1, par);
    }
    set<int> group;
    for (int i = 0; i < N; i++) {
        group.insert(root(i, par));
    }
    cout << group.size() << endl;
}


Measured memory_bytes: 5376
#pragma warning(disable: 4996)

#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
#include <deque>
#include <map>
#include <queue>
using namespace std;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int INF = 1e9;
	int h, n;
	cin >> h >> n;
	vector<int> dp(20100, INF);
	dp[0] = 0;
	int a, b;
	for (int i = 0; i < n; ++i) {
		cin >> a >> b;
		for (int j = 0; j <= h; ++j) {
			dp[j + a] = min(dp[j] + b, dp[j + a]);
		}
	}
	int ans = INF;
	for (int i = h; i < 20100; ++i) {
		ans = min(ans, dp[i]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
using ll=long long;

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n%2!=0){
        cout<<"No"<<endl;
        return 0;
    }
    int mid=n/2;
    string t1=s.substr(0,mid);
    string t2=s.substr(mid,mid);
    if(t1==t2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
open System.IO
open System

let sw = new StreamWriter(Console.OpenStandardOutput())
sw.AutoFlush <- false

let _n = stdin.ReadLine()
let _a = stdin.ReadLine().Split() |> Array.map int

let countByA = 
    let res = Array.zeroCreate(200001)
    for num in _a do
        res.[int num]<- res.[int num] + 1
    res

//let c2 n = n * (n - 1L) / 2L
let c2 = seq[0L..200000L] |> Seq.map(fun i ->i*(i-1L)/2L)|>Seq.toArray

// 全部の答えを出して余分な数を引く方針
let ansWhole = 
    seq[1..int _n]
    |> Seq.map (fun x -> c2.[countByA.[x]])
    |> Seq.sum

let unNeeded aNum = 
    let x = int64 countByA.[aNum]
    // xC2 - (x-1)C2 = x-1
    x-1L

/// それぞれの答え
let ansEach aNum = ansWhole - unNeeded aNum |> string

_a
|> Seq.map ansEach
|> Seq.iter stdout.WriteLine

stdout.Flush()
stdout.Close()

Measured memory_bytes: 52424
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 998244353;
 
signed main(){
    int n;
    string s;
    cin >> n >> s;
    int allb = 0;
    int allw = 0;
    rep(i,n){
        if(s[i] == '.')allw++;
        else allb++;
    }
    int b = 0;
    int w = 0;
    int ans = allw;
    rep(i,n){
        if(s[i] == '.')w++;
        else b++;
        ans = min(ans,b+allw-w);
    }
    cout << ans << endl;

   
    

    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://tenka1-2019.contest.atcoder.jp/tasks/tenka1_2019_c

Measured memory_bytes: 640
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node {
    int p,l,r;
};

struct Node t[MAX];
int n;

void pre(int );
void in(int );
void post(int );

int main(){
    int i,v,l,r,root;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        t[i].p=NIL;
    }
    
    for(i=0;i<n;i++){
        scanf("%d %d %d",&v,&l,&r);
        t[v].l=l;
        t[v].r=r;
        if(l!=NIL) t[l].p=v;
        if(r!=NIL) t[r].p=v;
    }
    
    for(i=0;i<n;i++) if(t[i].p==NIL) root=i;
    
    printf("Preorder\n");
    pre(root);
    printf("\n");
    printf("Inorder\n");
    in(root);
    printf("\n");
    printf("Postorder\n");
    post(root);
    printf("\n");
    
    return 0;
}

void pre(int u){
    if(u==NIL) return;
    printf(" %d",u);
    pre(t[u].l);
    pre(t[u].r);
}

void in(int u){
    if(u==NIL)return;
    in(t[u].l);
    printf(" %d",u);
    in(t[u].r);
}

void post(int u){
    if(u==NIL)return;
    post(t[u].l);
    post(t[u].r);
    printf(" %d",u);
}




Measured memory_bytes: 2052
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 2 * 105000;
const long long INF = 1e18L + 123;

struct node {
    long long mn;
    long long add;
};
node tree[4 * MAXN];

void add(int v, int L, int R, int l, int r, long long val) {
  if (l > r) 
    return;
  if (L == l && R == r) {
    tree[v].add += val;
  } else {
    int mid = L + (R - L) / 2;
    add(2 * v + 1, L, mid, l, min(mid, r), val);
    add(2 * v + 2, mid + 1, R, max(mid + 1, l), r, val);
    tree[v].mn = min(tree[2 * v + 1].mn + tree[2 * v + 1].add, tree[2 * v + 2].mn + tree[2 * v + 2].add);
  }
}

long long getMin(int v, int L, int R, int l, int r) {
    if (l > r) {
      return INF;
    }
    if (L == l && R == r) {
      return tree[v].mn + tree[v].add;
    }
    int mid = L + (R - L) / 2;
    return tree[v].add + min(getMin(2 * v + 1, L, mid, l, min(mid, r)), getMin(2 * v + 2, mid + 1, R, max(l, mid + 1), r));
}

int n, m;
vector < pair<int, int> > v[MAXN];
long long dp[MAXN];
long long totalSum;

int main() { 

  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int l, r, a;
    scanf("%d %d %d", &l, &r, &a);
    v[r].push_back({l, a});
    totalSum += a;
  }

  long long minRem = 0;
  for (int i = 1; i <= n + 1; i++) {
    dp[i] = getMin(0, 0, n + 1, 0, i - 1);
    minRem = min(minRem, dp[i]);
    for (auto p : v[i]) {
      int l = p.first, cost = p.second;
      add(0, 0, n + 1, 0, l - 1, cost);
    }
    add(0, 0, n + 1, i, i, dp[i]);
  }

  cout << totalSum - minRem << endl;

  return 0;
}


Measured memory_bytes: 22784
#include <iostream>
#include <algorithm>
#include <cassert>
#include <vector>
using namespace std;
typedef long long ll;

const ll inf = 1e18;

struct SegmentTree {
private:
    int n;
    vector<ll> node; 
public:
    SegmentTree(vector<ll> v) {
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, inf);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }
 
    void update(int x, ll val) {
        x += (n - 1);
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = min(node[2*x+1], node[2*x+2]);
        }
    }
 
    ll getmin(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return inf;
        if(a <= l && r <= b) return node[k];
        ll vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

int N;
ll T,E;

int main(){
    cin >> N >> E >> T;
    vector<ll> X(N+2,0),dp(N+2,0);
    for(int i=1;i<=N;i++){
        cin >> X[i];
        dp[i] = inf;
    }
    SegmentTree seg1(vector<ll>(N+2,inf)),seg2(vector<ll>(N+2,inf));
    X[N+1] = E;
    dp[0] = X[1];
    seg1.update(0,dp[0]-X[1]);
    seg2.update(0,dp[0]-3*X[1]);
    for(int i=1;i<=N;i++){
        int id = lower_bound(X.begin(),X.end(),X[i]-T/2)-X.begin();
        dp[i] = min(dp[i],seg1.getmin(max(id-1,0),i)+T+X[i+1]);
        if(id>0) dp[i] = min(dp[i],seg2.getmin(0,id-1)+2*X[i]+X[i+1]);
        seg1.update(i,dp[i]-X[i+1]);
        seg2.update(i,dp[i]-3*X[i+1]);
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 6640
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;


int main(void) {
    double t, x;
    cin >> t >> x;
    
    printf("%.10f\n", t/x);
    
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;



int main() {
    ios_base::sync_with_stdio(false); 

    ll n,m;
    cin >> n >> m;
    ll ans;
    if (n==1 && m==1) ans=1;
    else if (n==1) ans=m-2;
    else if (m==1) ans=n-2;
    else ans=(n-2)*(m-2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    long w=s.nextLong();
    long[] weights=new long[n];
    int[] value=new int[n];
    for(int i=0;i<n;i++){
      weights[i]=s.nextLong();
      value[i]=s.nextInt();
    }
    int total=0;
    for(int i:value){
      total+=i;
    }
    long[] dp=new long[total+1];
    Arrays.fill(dp,w+1);
    dp[0]=0;

    for(int i=0;i<weights.length;i++){
      for(int j=total;j>=0;j--){
        if(j>=value[i]){
          dp[j]=Math.min(dp[j],dp[j-value[i]]+weights[i]);
        }
      }
    }
    long max=0;
    for(int i=0;i<=total;i++){
      if(dp[i]<=w)
      max=Math.max(i,max);
    }
      System.out.println(max);
    }
  }
        
    
    
    

Measured memory_bytes: 24020
import math
n,d = map(int,input().split())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
ans = 0
tmp = 0
for i in range(n):
  tmp = math.sqrt(x[i]**2 + y[i]**2)
  if(tmp <= d):
    ans+= 1
print(ans)

Measured memory_bytes: 116740
// Problem : D - ABS
// Contest : AtCoder - AtCoder Regular Contest 085
// URL : https://atcoder.jp/contests/arc085/tasks/arc085_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n,a,b;
	cin>>n>>a>>b;
	vi c(n);
	loop(i,n)
	cin>>c[i];
	if(n==1)
	cout<<abs(c[n-1]-b);
	else
	cout<<max(abs(c[n-1]-c[n-2]),abs(c[n-1]-b));
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3612
import heapq
n,m=map(int,input().split(" "))
a=list(map(int,input().split(" ")))
a=[i*-1 for i in a]
heapq.heapify(a)
for i in range(m):
    maxVal=heapq.heappop(a)*-1
    maxVal/=2
    heapq.heappush(a,int(maxVal*-1))
print((sum(a)*-1))


Measured memory_bytes: 14180
#include<iostream>
using namespace std;
int num[1000000];
int main(){
	 int n,k;
	 cin>>n>>k;
	 int ans=0;
	 for(int i=0;i<n;i++)
	 {
	 	int x;
	 	cin>>x;
	 	if(x>=k)ans++;
	  } 
	  cout<<ans;
	  
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1], reverse=True)

ans = 0
j = 0
for b, c in BC:
    for i in range(b):
        if j < n:
            ans += max(c, A[j])
            j += 1
        else:
            break

if j < n:
    for i in range(n - j):
        ans += A[n - 1 - i]

print(ans)


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> count(N);
  for (int i = 0; i < K; i++) {
    int number;
    cin >> number;
    for (int j = 0; j < number; j++) {
      int c;
      cin >> c;
      count[c - 1] += 1;
    }
  }
  int result = 0;
  for (int i = 0; i < N; i++) {
  	if (count[i] == 0) {
    	result ++;
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 3624
n = int(input())
x = [int(i) for i in input().split()]

xp = []
b = 0
for i in range(min(x), max(x) + 1):
  xp.append([])
  for j in x:
    xp[b].append((j ** 2) - (2*j*i) + (i**2))
  b += 1

all_sum = []
for i in xp:
 all_sum.append(sum(i))

print(int(min(all_sum)))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 998244353 
#define pb push_back
#define mb make_pair
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int a,p; cin >> a >> p;
    cout << (a*3+p)/2 << endl;



    return 0;

}



Measured memory_bytes: 256
N = int(input())
def dfs(s):
  if int(s) > N :
    return 0
  if all(s.count(c)>0 for c in '753'):
    ret = 1
  else:
    ret = 0
  for c in '753':
    ret += dfs(s+c)
  return ret
print(dfs('0'))


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

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define pp pop_back
#define pf push_front
#define sqr(a) (a)*(a)
#define mpr(a,b) make_pair(a, b)
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mpii;
typedef map<string, int> mpsi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef queue<int> qi;
typedef queue<ll> qll;
typedef queue<pair<int, int>> qpi;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pqll;
typedef priority_queue<pair<int,int>> pqpi;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T> T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
template<class T> T lcm(T a, T b){return a*(b/gcd(a,b));}
template<class T, class TT>bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0, 31, 28, 31, 30, 31,30, 31, 31, 30, 31, 30, 31};

int main()
{
	ll a, b, c, k, ans = 0;
	cin >> a >> b >> c >> k;
	if(k % 2 == 0)
		ans = a - b;
	else
		ans = b - a;
	if((abs(ans) > 1e18))
		cout << "Unfair";
	else
		cout << ans;
	
	
	/*
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i ++)
	{
		
	}
	*/
	
	getchar();
	getchar();
	return 0;
	//freopen("Ganiyev.txt", "r", stdin);
	//freopen("Asadullo.txt", "w", stdout);
	//ios::sync_with_stdio(0);
	//cin.tie(0);cout.tie(0);
	
	
	
	
	
	
	
	
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

int mod=1e9+7;

int power(int x,int n,int mod){
    //(x^n)%mod
    int result=1;
    while(n){
        if(n%2)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return result;
}

int inverseMod(int x,int mod){
    return power(x,mod-2,mod);
}


int32_t main() {

    fast

    int n;
    cin>>n;

    vector<int>arr(n);
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        sum+=arr[i];
        sum%=mod;
    }
    int curr;
    int ans=0;
    int currSum=0;
    for(int i=0;i<n;i++){
        currSum+=arr[i];
        currSum%=mod;
        curr=(sum-currSum+mod)%mod;
        int toadd=(curr*arr[i])%mod;
        ans+=toadd;
        ans%=mod;
    }
    cout<<ans;


    return 0;
}



Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


/*
A, B, Nが与えられる。
floor(Ax/B) - A * floor(x/B)の最大値を求める
x はN以下の数字

floor(Ax/B)について
(Ax)%B が小さいほど無駄が少ない

x%Bが小さいほど無駄が少ない
 

Ax/B-floor(Ax/B) = ((Ax)%B)/B ...1
Ax/B-A*floor(x/B) =  A(x%B)/B ...2

1を最小化しつつ、2を最大化
((Ax)%B) - A(x%B)の最小値を求めたい
答えは　x = B-1 + Bkになる。（Nの制限がなければ。。。）

x%B = m のとき、

(Am)%B - Am = (A%B)*(m%B) - Am = (A%B - A)m
mが取り得る最大値のときが答え

*/

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

    //x%bが最大となる時が答え
    ll x = 0;
    if (n < b-1){
        x = n;        
    } else {
        x = b-1;
    }

    cout << (a*x)/b - a*(x/b) << endl;
}



Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int n,a,b,c;
char solve(){
  if(a==100||b==100||c==100)return 'A';
  if(a+b>=180)return 'A';
  if(a+b+c>=240)return 'A';
  if(a+b+c>=210)return 'B';
  if(a+b+c>=150&&(a>=80||b>=80))return 'B';
  return 'C';

}
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      cout<<solve()<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
#include <string.h>

int main(void)
{
  unsigned long  n, a, b;
  scanf("%lu%lu%lu", &n, &a, &b);

  if(a == 0)
    {
      puts("0\n");
      return 0;
    }

  unsigned long a_plus_b = a + b;
  unsigned long pre_ball_count = n / a_plus_b * a;

  unsigned long remainder = n % a_plus_b;

  unsigned long diff = remainder;
  if(remainder > a)
    diff = a;

  printf("%lu\n", pre_ball_count + diff);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pii pair<int, int>
#define pll pair<ll , ll>
#define mpi make_pair
#define F first
#define S second
#define pb push_back
#define N 200005
#define INF 1000000000000000

ll dp[3005][3005];


int main()
{   
    fastio
    
    int n;cin>>n;
    vector< ll> arr(n);
    for(int i = 0 ;i<n;i++)
    {
        cin>>arr[i];
        dp[i][i] = arr[i];
    }

    vector<ll> psum(n+1,0);

    for(int i = 1 ; i<=n;i++)
    {
        psum[i] = psum[i-1] + arr[i-1];
    }

    for(int k = 2;k<=n;k++)
    {
        for(int i =0;i+k<=n;i++)
        {
            int j = i+k-1;

            dp[i][j] = psum[j+1]-psum[i]-min(dp[i+1][j] , dp[i][j-1]);


        }
    }
    
    ll ans = 2*dp[0][n-1] - psum[n];\

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

Measured memory_bytes: 70016
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

vector<int> adj[200005];

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

	int n, m, ans = 0;
	cin >> n >> m;

	vector<int> H(n + 1);
	for(int i = 1; i <= n; i++) cin >> H[i];

	for(int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}

	for(int x = 1; x <= n; x++){
		bool yes = true;
		for(auto y : adj[x]){
			yes &= H[x] > H[y];
		}
		if(yes) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 12140
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void AGC018B();

int main()
{
	AGC018B();
	fflush(stdout);
	return 0;
}

static void AGC018B()
{
	int N, M;
	getint(N, M);

	std::vector<std::vector<int>> likes(N, std::vector<int>(M, 0));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			getint(likes[i][j]);
		}
	}

	int ans = 1000;
	while (likes[0].size()) {
		std::map<int, int> count;
		for (int i = 0; i < N; i++) {
			count[likes[i][0]]++;
		}

		int maxPeople = 0;
		int target = -1;
		for (auto it = count.begin(); it != count.end(); it++) {
			if (it->second > maxPeople) {
				maxPeople = it->second;
				target = it->first;
			}
		}
		ans = std::min(ans, maxPeople);

		for (int i = 0; i < N; i++) {
			for (auto it = likes[i].begin(); it != likes[i].end(); it++) {
				if (*it == target) {
					likes[i].erase(it);
					break;
				}
			}
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    int a,b,c;cin>>a>>b>>c;
    if(a==b and a==c) cout<<"No"<<endl;
    else if(a==b or b==c or a==c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import Data.List

main :: IO ()
main = do
  l1 <- getLine
  let s1 = l1
  print $ f s1

f [] = 0
f s = g n + g m - min n m + f s3
  where
    (s1, s') = span (=='<') s
    (s2, s3) = span (=='>') s'
    (n, m) = (length s1, length s2)

g n = (n*(n+1))`div`2

Measured memory_bytes: 20092
l, r = map(int, input().split())
nums_of_2019 = r//2019 - (l-1)//2019
if nums_of_2019 >= 2:
    print(0)
else:
    min_num = 2020
    for i in range(l,r):
        for j in range(i+1,r+1):
            min_num = min(min_num, (i*j)%2019)
    #сдайся уже
    print(min_num)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <cstring>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)

using namespace std;

const int N = 200010;

char s[N], s0[N];
bool vis[27];
int f[N], ne[N][27], nn[27], g[N], al;
char anss[N];
int main()
{

	scanf("%s", s0 + 1);
	int len = strlen(s0 + 1), cnt = 0, kl = 0;
	Rep(i, len) s[i] = s0[i];
	Rep(i, len) s[i] = s0[len - i + 1];
	
	for (int i = len; i; i --) {
		if (!vis[s[i] - 'a']) cnt ++, vis[s[i] - 'a'] = true;
		if (!kl && cnt == 26) kl = i;
		Rep0(j, 25) ne[i][j] = nn[j];
		nn[s[i] - 'a'] = i;
	}
	
	if (!kl) {
		Rep0(i, 25) if (!vis[i]){
			printf("%c\n", i + 'a');
			return 0;
		}
	}
	
	Rep0(i, 25) ne[0][i] = nn[i];

	int ans = 1e9, ti, mx = 1e9, tt = 0;
	Rep(i, len) f[i] = 1e9;
	Rep0(i, len - 1) if (f[i] <= len){
		Rep0(j, 25) if (ne[i][j]){
			if (f[ne[i][j]] > f[i] + 1 || (f[ne[i][j]] == f[i] + 1 && s[i] < s[g[ne[i][j]]]))
				f[ne[i][j]] = f[i] + 1, g[ne[i][j]] = i;
		}
	}
	
	for (int i = kl; i <= len; i ++) mx = min(mx, f[i] + 1);
	memset(vis, false, sizeof(vis));
	//printf("%d\n", mx);
	kl = -1;
	for (int i = len; i; i --) {
		if (f[i] + 1 == mx) {
			if (kl == -1 || (s[i] < s[ti] && kl == tt)) {
				kl = tt, ti = i;
			}
		}
		vis[s[i] - 'a'] = true;
		while (tt <= len && vis[tt]) tt ++;
		if (tt > len) break;
	}
	printf("%c", kl + 'a');
	while (ti) {
		printf("%c", s[ti]);
		ti = g[ti];
	}
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 23168
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    ll A, B, N, result, tmp3, x;
    cin >> A >> B >> N;
    /*if (N < B) {
        int x = N;
        double tmp1 = A * x / B * 1.0;
        double tmp2 = x / B * 1.0;
        result = tmp1 - A * tmp2;
    } else {
        int x = N;
        double tmp1 = A * x / B * 1.0;
        double tmp2 = x / B * 1.0;
        result = tmp1 - A * tmp2;
        FOR(x, B-1, N+1) {
            double tmp1 = A * x / B * 1.0;
            double tmp2 = x / B * 1.0;
            tmp3 = tmp1 - A * tmp2;
            if (tmp3 > result) {
                result = tmp3;
            }
        }
    }*/
    if (N < B) {
        x = N;
    } else {
        x = B-1;
    }
    double tmp1 = A * x / B * 1.0;
    double tmp2 = x / B * 1.0;
    result = tmp1 - A * tmp2;
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(N);
    vector<int> Point(N);
    for(int i=0; i<Q; i++) {
        int tmp;
        cin >>tmp;
        Point[tmp-1]++;
    }
    // cout << "debug" << endl;
    // for(int i=0; i<N; i++) cout << Point[i] << endl;
    // cout << "result" << endl;

    for(int i=0; i<N; i++) {
        if(K-Q+Point[i] >0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long int a,b,c,d,x;
  cin>>a>>b>>c;
  d=a-b;
  x=d-c;
  if(x>0)cout<<"0"<<endl;
  else cout<<abs(x)<<endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  map<int,ll> m, p;
  for (int i = 1; i <= N; i++) {
    int x;
    cin >> x;
    m[i-x] += 1;
    p[x+i] += 1;
  }
  ll ans = 0;
  for (auto r : p) {
    ans += r.second*m[r.first];
  }
  cout << ans << endl;
}

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

namespace ACBO098
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, max;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            max = a + b;
            if (max < a - b) max = a - b;
            if (max < a * b) max = a * b;


            Console.WriteLine(max);

            Console.ReadKey();

        }
    }
}


Measured memory_bytes: 13140
n,m,v,p=map(int,input().split())
A=sorted(list(map(int,input().split())))[-p::-1]
s=m*v-m*n;u=0
for a in A:
 if a<A[0]-m or s>u*a:break
 s+=a;u+=1
print(p-1+u)

Measured memory_bytes: 62576
import numpy as np

n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(n)]

dp = np.zeros((n+1, w+1), np.int64)
for i, (wi, vi) in enumerate(wv):
    dp[i + 1] = dp[i]
    np.maximum(dp[i+1][wi:], dp[i][:-wi] + vi, out=dp[i+1][wi:])
print(dp[n, w])

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

int	main()
{
  int	N;
  
  cin >> N;
  
  int	N_1 = (N % 10) / 1;
  int 	N_10 = (N % 100) / 10;
  int 	N_100 = (N % 1000) / 100;
  int 	N_1000 = N / 1000;
  
  if ((N_1 == N_10 && N_1 == N_100 && N_1 == N_1000)
     || (N_1 == N_10 && N_1 == N_100 && N_1 != N_1000)
     || (N_1000 == N_10 && N_1000 == N_100 && N_1 != N_1000))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return (0);
}


Measured memory_bytes: 256
N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
blue = [list(map(int, input().split())) for _ in range(N)]
# y座標で降順ソート
red.sort(reverse=True)
# x座標でソート
blue.sort(key=lambda x: x[1])

# print(blue)
# print(red)
blue_list = [0] * N
red_list = [0] * N


for b in range(N):
    for r in range(N):
        if blue_list[b] == 1 or red_list[r] == 1:
            continue
        if red[r][0] < blue[b][0] and red[r][1] < blue[b][1]:
            # print(b, r)
            blue_list[b] = 1
            red_list[r] = 1
            break

print(sum(blue_list))


Measured memory_bytes: 67608
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

long long power(long long x, long long n){
		long long ans = 1;
		for(;n;n >>= 1, x *= x, ans %= MOD, x %= MOD)
			if(n&1)ans*=x;
		return ans % MOD;
	}
	
int dp[2][10][2][2];

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N;
	cin>>N;
	
	dp[0][0][0][0] = 1;
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= 9; j++){
			for(int k = 1; k <= 8; k++){
				
				dp[(i+1)%2][k][0][0] += dp[(i)%2][j][0][0];
				dp[(i+1)%2][k][0][0] %= MOD;
				
				dp[(i+1)%2][k][0][1] += dp[(i)%2][j][0][1];
				dp[(i+1)%2][k][0][1] %= MOD;
				
				dp[(i+1)%2][k][1][0] += dp[(i)%2][j][1][0];
				dp[(i+1)%2][k][1][0] %= MOD;
				
				dp[(i+1)%2][k][1][1] += dp[(i)%2][j][1][1];
				dp[(i+1)%2][k][1][1] %= MOD;
				
			}
			dp[(i+1)%2][9][1][0] += dp[(i)%2][j][0][0];
			dp[(i+1)%2][9][1][0] %= MOD;
			
			dp[(i+1)%2][9][1][1] += dp[(i)%2][j][0][1];
			dp[(i+1)%2][9][1][1] %= MOD;
			
			dp[(i+1)%2][9][1][0] += dp[(i)%2][j][1][0];
			dp[(i+1)%2][9][1][0] %= MOD;
			
			dp[(i+1)%2][9][1][1] += dp[(i)%2][j][1][1];
			dp[(i+1)%2][9][1][1] %= MOD;
			
			dp[(i+1)%2][0][0][1] += dp[(i)%2][j][0][0];
			dp[(i+1)%2][0][0][1] %= MOD;
			
			dp[(i+1)%2][0][0][1] += dp[(i)%2][j][0][1];
			dp[(i+1)%2][0][0][1] %= MOD;
			
			dp[(i+1)%2][0][1][1] += dp[(i)%2][j][1][0];
			dp[(i+1)%2][0][1][1] %= MOD;
			
			dp[(i+1)%2][0][1][1] += dp[(i)%2][j][1][1];
			dp[(i+1)%2][0][1][1] %= MOD;
		
		}
		
		for(int j = 0; j <= 9; j++){
			dp[i%2][j][0][0] = 0;
			dp[i%2][j][0][1] = 0;
			dp[i%2][j][1][0] = 0;
			dp[i%2][j][1][1] = 0;
		}
	}
	
	int sum = 0;
	
	for(int i = 0; i <= 9; i++){
		sum += dp[N%2][i][1][1];
		sum %= MOD;
	}
	
	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 3640
using System;
class Program
{
	static void Main(string[] args)
	{
        string[] input = Console.ReadLine().Split(' ');
        int[] len = new int[4];
        for(int i=0; i<4; i++){
            len[i] = int.Parse(input[i]);
        }
        int scaleA = len[0] * len[1];
        int scaleB = len[2] * len[3];
        if(scaleA >= scaleB){
            Console.WriteLine(scaleA);
        }else{
            Console.WriteLine(scaleB);
        }
	}
}

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

#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int N;
V<int> p;

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cin >> N;
    p.resize(N);
    REP(i,N) cin >> p[i];
    std::sort(ALL(p), DESC(int));

    int ans = p[0] / 2;
    FOR(i,1,N) {
        ans += p[i];
    }
    OUT(ans) NL;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

template <typename T>
vector<T> divisor(T &n) {
    vector<T> res;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i * i != n) {
                res.push_back(n / i);
            }
        }
    }
    return res;
}

signed main() {
    cin >> N;
    ans = LLINF;
    auto div = divisor(N);
    REP(i, div.size()) {
        ll a = div[i];
        ll b = N / div[i];
        ans = min(ans, a + b);
    }
    cout << ans - 2 << endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<int,int> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=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{
      mint res(*this);
      return res/=a;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

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

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            sS = Console.ReadLine().Trim().Split(' ');
            List<int> lstInp = new List<int>();
            for (int i = 0; i < sS.Length; i++) { lstInp.Add(int.Parse(sS[i])); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<int> lstRet = new List<int>();
            int iIpc = lstInp.Count;
            int iRst = 1;                                   // 奇数 折返しスタート 1から
            if (iIpc % 2 == 0) { iRst = 0; }                // 偶数 折返しスタート 0から
            for (int i = iIpc - 1; i >= 0; i -= 2) { lstRet.Add(lstInp[i]); }
            for (int i = iRst; i < iIpc; i += 2)   { lstRet.Add(lstInp[i]); }

            //出力
            List<string> lstOut = new List<string>();
            for (int i = 0; i < lstRet.Count; i++)
            {
                lstOut.Add(lstRet[i].ToString());
            }
            Console.WriteLine("{0}", string.Join(" ", lstOut.ToArray()));

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 58792
# -*- coding: utf-8 -*-
"""
Shopping in JOI Kingdom
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0562

"""
import sys
from heapq import heappush, heappop
from itertools import combinations


def dijkstra(adj, s):
    WHITE, GRAY, BLACK = 0, 1, 2
    color = [WHITE] * len(adj)
    d = [float('inf')] * len(adj)
    d[s] = 0
    pq = []
    heappush(pq, (0, s))
    while pq:
        cost, u = heappop(pq)
        color[u] = BLACK
        if d[u] < cost:
            continue
        for v, cost in adj[u]:
            if color[v] == BLACK:
                continue
            if d[v] > d[u] + cost:
                d[v] = d[u] + cost
                heappush(pq, (d[v], v))
                color[v] = GRAY
    return d


def solve(adj, malls, n):
    distance = dijkstra(adj, malls[0])
    ans = [max([(d + j[1] + distance[j[0]])/2 for j in adj[n]]) for n, d in enumerate(distance[1:], start=1)]
    return int(max(ans) + 0.5) 


def main(args):
    n, m, k = map(int, input().split())
    adj = [[] for _ in range(n+1)]
    for _ in range(m):
        f,t, c = map(int, input().split())
        adj[f].append((t, c))
        adj[t].append((f, c))

    malls = [int(input()) for _ in range(k)]
    for f, t in combinations(malls, 2):
        adj[f].append((t, 0))
        adj[t].append((f, 0))
    ans = solve(adj, malls, n)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

using namespace std;

int main(int argc, const char *argv[]) {
  int N;
  string s, t;
  cin >> N;
  cin >> s >> t;

  for(int i =0; i<N; i++){
    cout << s[i] << t[i];
  }
  putchar('\n');
  return 0;
}


Measured memory_bytes: 256
from math import sqrt
if __name__=='__main__':
  n,d=[int(i) for i in input().split()]
  c=0
  for i in range(n):
    x,y = [int(i) for i in input().split()]
    if sqrt(x**2 + y**2) <= d:
      c+=1
  print(c)

Measured memory_bytes: 9124
#include <stdio.h>

int main(void)
{
	int num[30];
	int i;
	int in;

	for (i = 0; i < 30; i++){
		num[i] = 0;
	}

	for (i = 0; i < 28; i++){
		scanf("%d", &in);
		in--;
		num[in] = 1;
	}

	for (i = 0; i < 30; i++){
		if (num[i] == 0){
			printf("%d\n", i + 1);
		}
	}

	return (0);
}

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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

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

    int p[n];
    REP(i, n){
        cin>>p[i];
    }

    int ans = 0;
    int i, j;
    for(i=0; i<n-2; i++){
        if(p[i]<=p[i+1] && p[i+1]<=p[i+2]){
            ans++;
        }
        else if(p[i]>=p[i+1] && p[i+1]>=p[i+2]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void)
{
	char w[101],a;
	int i,c;
	scanf("%s",w);
	for(a='a'; a<='z'; a++){
		c=0;
		for(i=0; i<strlen(w); i++){
			if(w[i]==a){
				c+=1;
			}
		}
		if(c%2!=0){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#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(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}


int main()
{
	int x;
	cin >> x;
	if (x >= 30)
		puts("Yes");
	else
		puts("No");

	return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll inf = (1LL << 60LL);
int n;
int arr[105];
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> n;
    for(int i =0; i < n; i ++){
        cin >> arr[i];
    }
    sort(arr, arr + n);
    int alice = 0, bob = 0;
    int turn = 0;
    for(int i = n - 1; i >= 0; i --){
        if(turn == 0){
            alice += arr[i];
        }
        else{
            bob += arr[i];
        }
        turn ^= 1;
    }
    cout << alice - bob << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var scan = bufio.NewScanner(os.Stdin)

func main() {
	scanWords()
	a := readNextInt()
	b := readNextInt()
	c := readNextInt()

	count := 0
	for a <= b {
		if canDividable(c, a) {
			count++
		}
		a++
	}

	fmt.Println(count)
}

func scanWords() {
	scan.Split(bufio.ScanWords)
}

func readNextInt() int {
	scan.Scan()

	input, err := strconv.Atoi(scan.Text())
	if err != nil {
		panic(err)
	}
	return input
}

func canDividable(a, division int) bool {
	rest := a % division
	return rest == 0
}



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

using namespace std;

char in[11];
pair<pair<string,int>,int> p[101];

int main(){
int a;scanf("%d",&a);
for(int i=0;i<a;i++){
  int t;scanf("%s%d",in,&t);
  p[i]=make_pair(make_pair(in,-t),i);
}
sort(p,p+a);
for(int i=0;i<a;i++) printf("%d\n",p[i].second+1);
}


Measured memory_bytes: 256
H, W = [int(i) for i in input().split()]

a = []

for i in range(H):
    a.append([str(input())])

ans = []

for i in range(H+2):
    if (i ==0) | (i==H+1):
        add_st = '#'*(W+2)
    else:
        add_st = '#' + str(a[i-1][0]) + '#'
        
        
    ans.append(add_st)

for i in range(H+2):
    print(ans[i])

Measured memory_bytes: 3064
S = str(input())

if S=="SUN":
  print("7")
elif S=="MON":
  print("6")
elif S=="TUE":
  print("5")
elif S=="WED":
  print("4")
elif S=="THU":
  print("3")
elif S=="FRI":
  print("2")
else:
  print("1")

Measured memory_bytes: 3060