akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005


int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        int a,b;
        cin >> a >> b;
        cout << 6-(a+b);
        

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

    a += b;
    if (a < 10)
        cout << a << endl;
    else
        cout << "error" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
	int a, b;

	scanf("%d %d", &a, &b);

	
	if (a > b)
	{
		printf("a > b\n");
	}
	
	if (a < b)
	{
		printf("a < b\n");
	}
	
	if (a == b)
	{
		printf("a == b\n");
	}

	return 0;
}

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

int main() {
  int N = 0;
  cin >> N;
  vector<int> h(N, 0), dp(N, 0);
  for (int i=0;i<N;i++){
    cin >> h[i];
  }
  for (int i=1;i<N;i++){
    if (i==1) dp[i] = abs(h[i] - h[0]);
    else{
      dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
  }
  cout << dp[N-1] << endl;
}


Measured memory_bytes: 4012
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	long int i, j;
	long int n, d;
	long int flg;
	long int count = 1;
	long int max = 0;
	long int tugi = 0;
	long int index_max;
	long int index_tugi;
	long int a[200000];
	
	scanf("%ld", &n);
	
	printf("%ld\n", 3 * n * n );
	
	return 0;
}


Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize
    }

    if n == 1 {
        println!("{}", 1.0);
    } else if n % 2 == 0 {
        println!("{}", 0.5);
    } else {
        println!("{}", ((n-1)/2+1) as f64 / n as f64);
    }
}


Measured memory_bytes: 4352
#include <iostream>

int main() {
	int d;
	std::cin >> d;
	if (d == 25)
		std::cout << "Christmas" << std::endl;
	else if (d == 24)
		std::cout << "Christmas Eve" << std::endl;
	else if (d == 23)
		std::cout << "Christmas Eve Eve" << std::endl;
	else if (d == 22)
		std::cout << "Christmas Eve Eve Eve" << std::endl;
	return 0;
}


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

int wa(int x){
  int count =x%10;
  while(x/10>0){
    x/=10;
    count+=x%10;
  }
  return count;
}

int main(){
  int N;
  cin >> N;
  int min=N;
  for(int i=1; i<N; i++){
    int A=i, B=N-i;
    if(min>wa(A)+wa(B))
      min=wa(A)+wa(B);
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define M 200010
#define PLL pair <ll, ll>
#define x first
#define y second

using namespace std;

typedef long long ll;

int n, X;

ll B[M], L[M], U[M];

struct node {
	ll A, B;
	node() {A = 0, B = 1;}
	node(ll _1, ll _2) {A = _1, B = _2;}
};

ll need = 0;

PLL Pr[M];

ll Sum[M], W[M];

bool cmp(PLL A, PLL B) {return A.x > B.x;}

ll check(ll x, ll forb, ll w) {
	ll fin = 0;
	if(forb <= x) fin = Sum[x + 1] - Pr[forb].x; else fin = Sum[x];
	if(fin > need) return X * x;
	if(fin + Pr[forb].x < need) return 1e18 + x;
	if(fin + L[w] * B[w] >= need) {
		ll res = need - fin;
		return X * x + res / L[w] + (res % L[w] != 0);
	} else {
		ll res = need - fin - L[w] * B[w];
		return X * x + B[w] + res / U[w] + (res % U[w] != 0);
	} 
}

int main() {
	scanf("%d%d", &n, &X);
	for(int i = 1; i <= n; i++) scanf("%lld%lld%lld", &B[i], &L[i], &U[i]), need += B[i] * L[i], Pr[i] = PLL((U[i] * (X - B[i]) + L[i] * B[i]), i);
	sort(Pr + 1, Pr + n + 1, cmp);
	for(int i = 1; i <= n; i++) Sum[i] = Sum[i - 1] + Pr[i].x, W[Pr[i].y] = i;
	ll ans = 1e18;
	for(int i = 1; i <= n; i++) {
		int w = W[i];
		ll l = 0, r = n - 1, nw = 0;
		for(; l <= r; ) {
			int md = (l + r) / 2;
			ll fin = w <= md ? Sum[md + 1] - Pr[w].x : Sum[md];
			if(fin > need) r = md - 1; else nw = md, l = md + 1;
		}
		for(int j = max((int) nw - 3, 0); j <= min((int) nw + 3, n - 1); j++)
		ans = min(ans, check(j, w, i));
	}
	printf("%lld\n", ans);
	return 0;
}

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


template<long long M>
class modint {
    public:
        long long a;
        modint(const long long x = 0LL) : a((x % M + M) % M) {}
        long long &value() { return a; }
        modint operator+(const modint rhs) const {
            return modint(*this) += rhs;
        }
        modint operator-(const modint rhs) const {
            return modint(*this) -= rhs;
        }
        modint operator*(const modint rhs) const {
            return modint(*this) *= rhs;
        }
        modint operator/(const modint rhs) const {
            return modint(*this) /= rhs;
        }
        modint &operator+=(const modint rhs) {
            a += rhs.a;
            if (a >= M) {
                a -= M;
            }
            return *this;
        }
        modint &operator-=(const modint rhs) {
            if (a < rhs.a) {
                a += M;
            }
            a -= rhs.a;
            return *this;
        }
        modint &operator*=(const modint rhs) {
            a = a * rhs.a % M;
            return *this;
        }
        modint pow(long long n) const {
            modint ret(1);
            modint x = *this;
            while (n) {
                if ((n & 1) == 1) {
                    ret *= x;
                }
                n >>= 1;
                x *= x;
            }
            return ret;
        }
        modint inv() const {
            return pow(M - 2);
        }
        modint &operator/=(const modint rhs) {
            return *this *= rhs.inv();
        }
};

// const long long M = 1000000007;
const long long M = 998244353;

using mint = modint<M>;


class Combination {
    std::vector<mint> fact, ifact;
    public:
        Combination(long long n) : fact(n + 1), ifact(n + 1) {
            fact[0] = 1;
            for (long long i = 1; i <= n; i++)
                fact[i] = fact[i - 1] * i;
            ifact[n] = fact[n].inv();
            for (long long i = n ;i >= 1; i--)
                ifact[i - 1] = ifact[i] * i;
        }
        mint comb(long long n, long long k) {
            if (k < 0 || k > n)
                return 0;
            return fact[n] * ifact[k] * ifact[n - k];
        }
        mint perm(long long n, long long k) {
            return fact[n] * ifact[n - k];
        }
} c(1000005);


using namespace std;

using ll = long long;


int main(void) {
    ll N, M, K;
    cin >> N >> M >>K;

    mint ans = 0;
    for (ll k = 0; k <= K; k++) {
        mint tmp = M;
        tmp *= c.comb(N - 1, k);
        tmp *= (mint(M - 1).pow(N - 1 - k));
        ans += tmp;
    }
    cout << ans.a << endl;
}


Measured memory_bytes: 18636
#include<iostream>
#include<vector> 
#include<algorithm>
using namespace std;
int main(){
int i,n;
long long b,ans,c;
cin >> n;
long long a[n],x[n+1];
	for(i=0;i<n+1;i++){
		x[i]=0;
	}
	b=0;
	x[0]=0;
for(i=0;i<n;i++){
	cin >> a[i];
	b += a[i];
	x[i+1] = b;
}
	c = 1;
	ans = 0;
	sort(x,x+n+1);
	for(i=0;i<n;i++){
		if(x[i] == x[i+1]){
			c += 1;
		}else{
			ans += c*(c-1)/2;
			c=1;
		}
	}
	ans += c*(c-1)/2;
	
	cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
//    std::sort(a.begin(), a.end(), std::greater<int>() );
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    string s;
    cin >> s;
    vector<int> a(26);
    rep(i,s.size())
        a[s[i]-'a']++;
    rep(i,a.size())
        if(a[i]==0){
            cout<<(char)(i+'a')<<endl;
            return 0;
        }
    cout<<"None"<<endl;
    return 0;
}

Measured memory_bytes: 512
def main():
    x, y = map(int, input().split())
    a = [1, 3, 5, 7, 8, 10, 12]
    b = [4, 6, 9, 22]
    c = [2]
    if x in a and y in a:
        ans = 'Yes'
    elif x in b and y in b:
        ans = 'Yes'
    elif x in c and y in c:
        ans = 'Yes'
    else:
        ans = 'No'

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
n=int(input())
r=[list(map(int, input().split())) for i in range(2)]
l=[[0,0] for _ in range(n)]
for i in range(n):
    l[i][0]=r[0][i]
    l[i][1]=r[1][i]
dp=[[0,0] for _ in range(n)]
dp[0][0]=l[0][0]
dp[0][1]=l[0][1]+dp[0][0]
for i in range(1,n):
    dp[i][0]=dp[i-1][0]+l[i][0]
    dp[i][1]=max(dp[i-1][1],dp[i][0])+l[i][1]
print(dp[-1][1])



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N, M;
    cin >> N >> M;
    if(N % 2 == 1){
        for(int i = 0; i < M; i++){
            cout << 1 + i << ' ' << N - i << endl;
        }
    }
    else{
        for(int i = 0; i < M; i++){
            if(i <= (M - 1)/ 2) cout << 1 + i << ' ' << N - i << endl;
            else cout << 2 + i << ' ' << N - i << endl;
        }
    }
}

Measured memory_bytes: 3644
// [modified](from: https://www.geeksforgeeks.org/knapsack-problem/)

// A Dynamic Programming based solution for 0-1 Knapsack problem
#include<stdio.h>

// Max number of items
#define MAX_N 100

// Max weight
#define MAX_W 10000

// DP Table
int K[MAX_N+1][MAX_W+1];

// Weights
int wt[MAX_N];

// Values
int val[MAX_N];

// A utility function that returns maximum of two integers
int max(int a, int b) { return (a > b)? a : b; }
 
// Returns the maximum value that can be put in a knapsack of capacity W
int knapsack(int W, int n) {
   int i, w;
 
   // Build table K[][] in bottom up manner
   for (i = 0; i <= n; i++) {
       for (w = 0; w <= W; w++) {
           if (i==0 || w==0)
               K[i][w] = 0;
           else if (wt[i-1] <= w)
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
           else
                 K[i][w] = K[i-1][w];
       }
   }

   return K[n][W];
}

int main() {
    int i;
    int n;
    int w;
    scanf("%d %d", &n, &w);
    for (i = 0; i < n ;i++){
        scanf("%d %d", (val+i), (wt+i));
    }
    int max_value = knapsack(w, n);
    printf("%d\n", max_value);
    return 0;
}
 


Measured memory_bytes: 5696
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
INF = 10**9

if __name__ == "__main__":
    n = int(input())
    m = [1]
    dp = [101010]*201010
    t = 6
    q = 9
    while t<=n:
        m.append(t)
        t*=6
    while q<=n:
        m.append(q)
        q*=9
    for i in m:
        dp[i] = 1
    
    for i in range(1,n):
        for j in m:
            dp[i+j] = min(dp[i+j],dp[i]+1)
    print(dp[n])

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

int main()
{
	int N, M;
  cin >> N >> M;
  
  vector<int> a(M);
  vector<int> b(M);
  vector<int> count(N);
  for(int i = 0; i < M; i++){
   cin >> a.at(i) >> b.at(i);
  }
  for(int j = 0; j < N; j++){
    for(int i = 0; i < M; i++){
      if(j+1 == a.at(i) || j+1 == b.at(i))
        count.at(j)++;
    }
	cout << count.at(j) << endl;
  }
}

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


def solve(N: int, d: "List[int]"):
    d.sort()
    print(d[N // 2] - d[N // 2 - 1])
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 53100
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I,m=26;
		var c=sc.Ia3("0 ","");
		var g=new int[n+1][];
		var h=new int[m+1];
		long p=0;
		for(int i = 1;i<=n;i++) {
			g[i]=sc.Ia3("0 ","");
		}
		var z=new int[n+1];
		for(int i = 1;i<=n;i++) {
			z[i]=sc.I;
		}
		for(int i = 1;i<=n;i++) {
			int e=z[i];
			p+=g[i][e];
			h[e]=i;
			for(int j = 1;j<=m;j++) {
				p-=c[j]*(i-h[j]);
			}
			Console.WriteLine(p);
		}
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 28248
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {
	int n, m;
	while (cin >> n >> m, n&&m) {
		vector<ll>h, w;
		vector<ll>sh, sw;
		for (int i = 0; i < n; i++) {
			int k; cin >> k;
			for (int j = 0; j < sh.size(); j++) {
				sh[j] += k;
				h.push_back(sh[j]);
			}
			h.push_back(k);
			sh.push_back(k);
		}
		sort(h.begin(), h.end());
		for (int i = 0; i < m; i++) {
			int k; cin >> k;
			for (int j = 0; j < sw.size(); j++) {
				sw[j] += k;
				w.push_back(sw[j]);
			}
			w.push_back(k);
			sw.push_back(k);
		}
		sort(w.begin(), w.end());
		long long ans = 0;
		for (int i = 0; i < h.size(); i++) 
			ans += upper_bound(w.begin(), w.end(), h[i]) - lower_bound(w.begin(), w.end(), h[i]);
		cout << ans << endl;
	}
}

Measured memory_bytes: 45072
#define _CRT_SECURE_NO_WARINGS
#include<iostream>
#include<stdio.h>
#include<iomanip>
#include<map>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<fstream>
#include<map>
#include<unordered_map>
using namespace std;
typedef int me;
typedef long long ll;
typedef unsigned long long ull;
#define andrew  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define sz(v)(int)(v.size())
#define all(v) v.begin(),v.end()
#define PI 3.1415926535
#define sin(i) (long double)sin(i*PI/180.0);
#define OO 1e18;
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ull lcm(ll x, ll y) { return x / gcd(x, y) * y; }
void the_end() {
#ifndef ONLINE_JUDGE;
    system("pause");
#endif
}
int dy8[] = { 0,0,1,-1,1,-1,-1,1 };
int dx8[] = { 1,-1,0,0,1,-1,1,-1 };
int id8[] = { 0, 1,2,3,4, 5,6, 7 };
// you can be specialist 
// soon will be (Cyain)
ll n, k;
vector<ll>v;
ll m[100001];
ll solve(int i)
{
    if (i >= n)
        return 1e18;
    if (i == n-1)
        return 0;
    if (m[i] != -1)
        return m[i];
    ll ch = LLONG_MAX;
    for (int l = 1; l <= k; l++)
    {
      ch = min(ch, solve(i + l) + abs(v[i] - v[i + l]));
    }
    return m[i] = ch;

}
int main()
{
    andrew;
    cin >> n >> k;
    v.resize(n + n + k);
    for (int i = 0; i < n; i++)cin >> v[i];
    for (int i = 0; i < 100000; i++)
        m[i] = -1;
    cout << solve(0) << endl;
    the_end();
}

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

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int):
    ret = NO
    for i in range(N):
        if (N - 4 * i) >= 0 and (N - (4 * i)) % 7 == 0:
            ret = YES
            break
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int main()
{
   long long int K;
   cin>>K;
   long long int sum=0;
   for(int i=1;i<=K;i++){
       for(int j=1;j<=K;j++){
           for(int k=1;k<=K;k++){
               sum+=gcd(i,gcd(j,k));
           }
       }
   }
   cout<<sum<<endl;
   return 0;
}

Measured memory_bytes: 3620
import sys
from collections import deque
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

ars = [0] * N
todo = deque([0])
done = {0}
while todo:
    p = todo.popleft()
    for np in G[p]:
        if np in done:
            continue
        todo.append(np)
        ars[np] = p + 1
        done.add(np)

if len(done) == N:
    print("Yes")
    for i in range(1, N):
        print(ars[i])
else:
    print("No")

Measured memory_bytes: 42260
n  = []
while True:
    try:n.append(int(raw_input()))
    except:break
R = max(n)+1
p = [1]*R
p[0] = p[1] = 0
p[4::2] = [0 for i in range(4,R,2)]
for i in range(3,int(R**0.5)+1,2):
    if p[i]:
        p[2*i::i] = [0]*len(p[2*i::i])
for i in n:
    print sum(p[:i+1])

Measured memory_bytes: 36984
#include <vector>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <queue>
#include <climits>
using namespace std;
typedef long long ll;

int main() {
  ll s;
  scanf("%lld", &s);

  ll x = ((ll)1e9 - s % (ll)1e9) % (ll)1e9;
  ll y = (s + x) / (ll)1e9;
  cout << "0 0 " << (ll)1e9 << " 1 " << x << " " << y << endl;;
  return 0;
}


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

int main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0){
    cout<<1<<endl;
  }
  else if(b==0){
    cout<<2<<endl;
  }
  else if(c==0){
    cout<<3<<endl;
  }
  else if(d==0){
    cout<<4<<endl;
  }
  else if(e==0){
    cout<<5<<endl;
  }
}

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

const int N = 3005;

int n;
int a[N], dp[N][N][2];

int recur(int i, int j, int player)
{
    if(j < i)
        return 0;
    int &ans = dp[i][j][player];
    if(ans != -1)
        return ans;
    if(!player)
        ans=max(a[i] + recur(i + 1, j, player^1), a[j] + recur(i, j - 1, player^1));
    else
        ans=min(-a[i] + recur(i + 1, j, player^1), -a[j] + recur(i, j - 1, player^1));
    return ans;
}

int32_t main()
{
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    cout << recur(1, n, 0);
    return 0;
}


Measured memory_bytes: 141440
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;
/*

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s == "ARC"){
        cout<<"ABC\n";
    }
    else{
        cout<<"ARC\n";
    }
    return 0;
}
*/


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    int elev[n+2];
    for (int i = 1; i <= n; i++) {
        cin>>elev[i];
    }
    std::map<int, int> mp;
    for (int i = 1; i <= m; i++) {
        mp[i] = 0;
    }
    int a,b;
    for (int i = 1; i <= m; i++) {
        cin>>a>>b;
        if(elev[a] == elev[b]) {
            mp[a] = 1;
            mp[b] = 1;
        }
        else if(elev[a] < elev[b] ){
            mp[a] = 1;
        }
        else if(elev[a] > elev[b] ){
            mp[b] = 1;
        }
    }
    ll int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if(mp[i] == 0){
            cnt++;
            //dump(mp[i]);
            //dump(i);
        }
    }
    cout<<cnt<<"\n";
    return 0;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long x){
    cout<<(x>=30?"Yes":"No") << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3652
a=input()
if a=="SUN":
    print(7)
if a=="MON":
    print(6)
if a=="TUE":
    print(5)
if a=="WED":
    print(4)
if a=="THU":
    print(3)
if a=="FRI":
    print(2)
if a=="SAT":
    print(1)


Measured memory_bytes: 8908
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back

int mo[100005];
const int N=1000000007;
int binpow(int x, int y)  
{  
    int res = 1;     // Initialize result  
  
    x = x % N; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % N;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % N;  
    }  
    return res;  
} 

main() {
	int n, k;
	cin>>n>>k;
	mo[1]=1;
	for(int i=2; i<100005; i++){
		int num=i;
		vector<int>f;
		for(int x=2; x*x<=num; x++){
			while(num%x==0){
				num=num/x;
				f.pb(x);
			}
		}
		if(num!=1){
			f.pb(num);
		}
		bool b=0;
		for(int j=0; j<f.size()-1; j++){
			if(f[j]==f[j+1]){
				b=1;
			}
		}
		if(b==1){
			mo[i]=0;
			continue;
		}
		if(f.size()%2==0){
			mo[i]=1;
			continue;
		}
		mo[i]=-1;
	}
	int fin=0;
	
	for(int i=1; i<=k; i++){
		int num=(k/i);
		int ans=0;
		for(int j=1; j<=num; j++){
			int nums=(num/j);
			ans=(ans+mo[j]*binpow(nums, n)+N)%N;
			
		}
		
		fin=(fin+i*ans)%N;
	}
	cout<<fin;
	return 0;
}

Measured memory_bytes: 4420
class UnionFind():
  def __init__(self,n):
    self.n=n
    self.root=[-1]*(n+1)
    self.rank=[0]*(n+1)
  def FindRoot(self,x):
    if self.root[x]<0:
      return x
    else:
      self.root[x]=self.FindRoot(self.root[x])
      return self.root[x]
  def Unite(self,x,y):
    x=self.FindRoot(x)
    y=self.FindRoot(y)
    if x==y:
      return
    else:
      if self.rank[x]>self.rank[y]:
        self.root[x]+=self.root[y]
        self.root[y]=x
      elif self.rank[x]<=self.rank[y]:
        self.root[y]+=self.root[x]
        self.root[x]=y
        if self.rank[x]==self.rank[y]:
          self.rank[y]+=1
  def isSameGroup(self,x,y):
    return self.FindRoot(x)==self.FindRoot(y)
  def Count(self,x):
    return -self.root[self.FindRoot(x)]
  
n,m,k=map(int,input().split())
t=UnionFind(n+1)
cnt=[0]*(n+1)
for _ in range(m):
  a,b=map(int,input().split())
  cnt[a]+=1
  cnt[b]+=1
  t.Unite(a,b)
for _ in range(k):
  a,b=map(int,input().split())
  if t.isSameGroup(a,b)==True:
    cnt[a]+=1
    cnt[b]+=1
ans=[0]*(n+1)
for i in range(1,n+1):
  ans[i]=(t.Count(i)-1)-cnt[i]
print(*ans[1:])

Measured memory_bytes: 11828
#!/usr/bin/env python3

def read():
    n = int(input())
    ai = list(map(int, input().split()))
    assert len(ai) == n
    return n, ai

def shakutori(n, ai):
    l = 0
    r = 1  # [l, r)
    res = 1
    su = ai[0]
    xo = ai[0]
    while r < n:
        su += ai[r]
        xo ^= ai[r]
        while su != xo:
            su -= ai[l]
            xo ^= ai[l]
            l += 1
        r += 1
        res += r - l
    return res

def main():
    n, ai = read()
    print(shakutori(n, ai))

main()


Measured memory_bytes: 24840
import sys

input = sys.stdin.readline

def main():
    def hash_ini(t):
        h = 0
        p = 1
        for i in range(1, len(t) + 1):
            h = hash_table[i] = (h * base + t[i - 1]) % hash_md
            p = pw[i] = p * base % hash_md

    # インデックスがi以上j未満の文字列のハッシュ
    def hash_ij(i, j):
        return (hash_table[j] - hash_table[i] * pw[j - i]) % hash_md

    n = int(input())
    s = input()[:-1]

    # 初期化
    base = 31
    hash_md = pow(3, 19)
    ord_a = ord('a')
    t = [ord(c) - ord_a for c in s]
    hash_table = [0] * (len(t) + 1)
    pw = [1] * (len(t) + 1)
    hash_ini(t)

    # 長さを二分探索
    ok = 0
    ng = n // 2 + 1
    while ok + 1 < ng:
        w = (ok + ng) // 2
        hashes = []
        for i in range(w):
            hashes.append(hash_ij(i, i + w))
        passed = set()
        for i in range(w, n - w + 1):
            passed.add(hashes[i - w])
            cur = hash_ij(i, i + w)
            if cur in passed:
                ok = w
                break
            hashes.append(cur)
        else:
            ng = w

    print(ok)

main()


Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


int main(int argc, char const *argv[]) {
  int n;
  string s,t;
  std::cin >> n >> s >> t;
  rep(i,n+1){
    if(s.substr(i)==t.substr(0,n-i)){
      std::cout << n+i << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	int a,b; cin>>a>>b;
	if(b==1)cout<<0<<endl;
	else cout<<a-b<<endl;
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	int N,K;
	cin >> N >> K;
	int ans=0;
	for(int i=0; i<N; i++){
		int h;
		cin >> h;
		if(h>=K){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <climits>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <math.h>
#include <map>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> dp(n);

	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		dp[temp - 1] = i + 1;
	}

	for (auto x : dp) cout << x << " ";
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int v[55], c[55];

int main()
{
    int n, k;
    string s;
    cin>>n>>s>>k;
    REPALL(i,s) {
        cout<<(s[i] == s[k-1] ? s[i] : '*');
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 256
/*/-----


    Written By:- Sajal Agrawal
          (Have Patience)

/*/
#include<bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ll long long int
#define f(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define rf(i,a,b) for(ll (i)=(a);(i)>=(b);(i)--)
#define mod 1000000007
#define fi first
#define se second
#define pa pair <ll,ll>
#define mp make_pair
#define c(t) cout<<t<<"\n"
#define pb push_back
#define ln '\n'
#define forstl(i,v) for(auto &i: v)
#define PRI(x) cerr<<#x<<'='<<x<<endl;
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define all(con) con.begin(),con.end()
#define sz(x) ((long long)x.size())
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>

void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

int main(){


ll n,k;
cin>>n>>k;
    ll a[n];
    f(i,1,n+1){
        cin>>a[i];
    }

ll dp[n+2]={0};
f(i,0,n+2){
    dp[i]=0;
}
dp[1]=0;
for(ll i=2;i<=n;i++){

ll mi=i;
ll ans=INT_MAX;
ll cnt=0;
for(ll p=mi-1;p>=1;p--){
    cnt++;
ans=min(ans,abs(a[p]-a[mi])+dp[p]);
if(cnt==k){
    break;
}
}
dp[i]=ans;

}


cout<<dp[n]<<endl;
}





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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

unsigned long  gcd(unsigned long x, unsigned long y)
{
        if (y == 0) {
                return x;
        } else {
                return gcd(y, x % y);
        }
}



long long calc(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}


int main(void){
    int n;
    int i;
    int a;
    int max = -1;
    int min = 1005;
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &a);
        max = max>a?max:a;
        min = min<a?min:a;
    }

    printf("%d\n", max-min);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>

bool check(char** m, int n, int a, int b) {
    for (int i = 0; i < n-1; i++) {
        for (int j = i+1; j < n; j++) {
            int y = (i + a);
            int x = (j + b);

            int _y = (j + a);
            int _x = (i + b);

            if (m[y][x] != m[_y][_x]) {
                return false;
            }
        }
    }

    return true;
}

int main() {
    int n;
    char** m;
    char** M;

    std::cin >> n;

    m = new char*[n];
    M = new char*[2*n];

    for (int i = 0; i < n; ++i) {
        m[i] = new char[n];
    }

    for (int i = 0; i < n*2; ++i) {
        M[i] = new char[n*2];
    }

    for (int i = 0; i < n; ++i) {
        std::cin >> m[i];
    }

    for (int i = 0; i < n*2; ++i) {
        for (int j = 0; j < n*2; ++j) {
            M[i][j] = m[i%n][j%n];
        }
    }


    int count = 0;
    for (int a = 0; a < n; ++a) {
        if (check(M, n, 0, a)) {
            count++;
        }
    }

    std::cout << count*n << std::endl;

    for (int i = 0; i< n; ++i) {
        delete[](m[i]);
    }

    for (int i = 0; i< n*2; ++i) {
        delete[](M[i]);
    }
    delete[](M);
    delete[](m);
    return 0;
}


Measured memory_bytes: 768
# coding: utf-8
# Here your code !

l = input().split()

len_m = 0
for e in l:
    if len_m < len(e):
        len_m = len(e)
        a1 = e
    
d = {}

for e in l:
    if e not in d:
        d.update({
            e: 1
        })
    else:
        t = d[e]
        d.update({
            e: (t+1)
        })
print('%s %s' % (max(d.items(), key=lambda x: x[1])[0],a1))

Measured memory_bytes: 6720
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, K;
	ll ans;

	cin >> N >> K;

	ans = K;
	rep(i, N - 1) ans *= K - 1;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    string s, t;
    int q, a[112345], b[112345], c[112345], d[112345];

    cin >> s >> t >> q;
    REP(i, q)
    cin >> a[i] >> b[i] >> c[i] >> d[i];

    int ss[112345];
    int ts[112345];

    fill(ss, ss + s.size() + 1, 0);
    fill(ts, ts + t.size() + 1, 0);

    REP(i, s.size())
    ss[i + 1] = ss[i] + (s[i] == 'A');

    REP(i, t.size())
    ts[i + 1] = ts[i] + (t[i] == 'A');

    REP(i, q)
    {
        int st = (ss[b[i]] - ss[a[i] - 1]) - ((b[i] - a[i] + 1) - (ss[b[i]] - ss[a[i] - 1]));
        if (st > 0)
        {
            st %= 3;
            if (st == 2)
                st = -1;
        }
        if (st < 0)
        {
            st = -st;
            st %= 3;
            st = -st;
            if (st == -2)
                st = 1;
        }

        int tt = (ts[d[i]] - ts[c[i] - 1]) - ((d[i] - c[i] + 1) - (ts[d[i]] - ts[c[i] - 1]));
        if (tt > 0)
        {
            tt %= 3;
            if (tt == 2)
                tt = -1;
        }
        if (tt < 0)
        {
            tt = -tt;
            tt %= 3;
            tt = -tt;
            if (tt == -2)
                tt = 1;
        }

        cout << (st == tt ? "YES" : "NO") << endl;
    }

    return 0;
}

Measured memory_bytes: 3456
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class DIntegerCards {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N, M;
	    in >> N >> M;
	    vector<int> A(N);
	    vector<int> B(M), C(M);
	    REP(i,0,N) in >> A[i];
	    REP(i,0,M) in >> B[i] >> C[i];

	    sort(all(A));
	    vector<pair<int, int>> cOrder(M); // <C[i], index>
	    REP(i,0,M) cOrder[i] = {C[i], i};
	    sort(all(cOrder), greater<pair<int, int>>());

	    int replaced = 0;
        REP(i,0,M) {
            int b = B[cOrder[i].second];
            int c = cOrder[i].first;
            while (replaced < N && b > 0) {
                if (A[replaced] >= c) break;
                A[replaced] = c;
                b--;
                replaced++;
            }
            if (A[replaced] >= c || replaced >= N) break;
        }
        out << accumulate(all(A), 0ll) << "\n";
	}
};


int main() {
	DIntegerCards solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 2176
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] input = br.readLine().split(" ");
        int a = Integer.parseInt(input[0]);
        int b = Integer.parseInt(input[1]);
        int C = Integer.parseInt(input[2]);

        double S = a * b * Math.sin(Math.toRadians(C)) /2;
        double L = a + b + Math.sqrt(a*a + b*b -2*a*b*Math.cos(Math.toRadians(C)));
        double h = 2 * S / a;

        System.out.println(S);
        System.out.println(L);
        System.out.println(h);
    }
}

Measured memory_bytes: 24272
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

class BinaryIndexedTree {
    vector<int64_t> container;

public:
    BinaryIndexedTree(size_t size)
        : container(size + 1)
    {
        fill(container.begin(), container.end(), 0);
    }
    void add(size_t i, int64_t v)
    {
        size_t idx = i + 1;
        while (idx < container.size()) {
            container[idx] += v;
            idx += idx & -idx;
        }
    }
    int64_t find(size_t i)
    {
        size_t idx = i;

        int64_t result = 0;
        while (idx != 0) {
            result = container[idx] + result;
            idx -= idx & -idx;
        }
        return result;
    }
};

using L = tuple<int, int, int>;
using P = tuple<double, size_t>;

const double INF = 1e9;

int main()
{
    cout << fixed << setprecision(10);

    vector<L> ys;

    int n;
    cin >> n;
    const int half = ((n * (n - 1) / 2) + 1) / 2;
    rep(i, n)
    {
        int a, b, c;
        cin >> a >> b >> c;
        ys.push_back(make_tuple(a, b, c));
    }

    double result[2];
    rep(i, 2)
    {
        sort(ys.begin(), ys.end(), [](const L& lh, const L& rh) {
            int la, lb, ra, rb;
            tie(la, lb, ignore) = lh;
            tie(ra, rb, ignore) = rh;

            return -(double)la / lb > -(double)ra / rb;
        });

        double lb = -INF, ub = INF;
        rep(i, 256)
        {
            const double mid = ub / 2 + lb / 2;

            vector<P> tmp;
            tmp.reserve(ys.size());
            rep(i, ys.size())
            {
                int a, b, c;
                tie(a, b, c) = ys[i];
                tmp.push_back(make_tuple((c - a * mid) / b, i));
            }
            sort(tmp.begin(), tmp.end());

            int64_t intersection = 0;
            BinaryIndexedTree bit(tmp.size());
            rep(i, tmp.size())
            {
                size_t j;
                tie(ignore, j) = tmp[i];
                intersection += bit.find(tmp.size()) - bit.find(j + 1);
                bit.add(j, 1);
            }

            (intersection >= half ? ub : lb)
                = mid;
        }
        result[i] = ub;

        for (L& l : ys) {
            swap(get<0>(l), get<1>(l));
        }
    }
    cout << result[0] << " " << result[1] << endl;

    return 0;
}

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

#define ll long long
#define forn(i, n) for(int i=0; i<int(n); i++)
#define endl '\n'
const int N = 1e5+5;
ll h[N];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, k; 
    cin>>n>>k;

    forn(i, n ) cin>>h[i];
    vector<ll> dp(n, INT_MAX);
    dp[0] = 0;

    for(int i=0; i<n-1; i++) {
        for(int j=1; j<=k && i+j<n; j++) {
            dp[i+j] = min(dp[i+j], abs(h[i+j]-h[i]) + dp[i]);
        }

    }


    cout<<dp[n-1];

}



Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
int h[100001];
int n,a,b;
bool ok(int t){
	long long q=0;
	for(int i=1;i<=n;++i){
		if(1ll*a*t<h[i]) return false;
		long long x=h[i]-1ll*b*t;
		if(x>0)q+=(x-1)/(a-b)+1;
		if(q>t) return false; 
	}
	return true;
}
int main(){
	cin>>n>>a>>b;
	for(int i=1;i<=n; ++i) cin>>h[i];
	int l=1,r=1e9;
	while (l<=r){
		int md=(l + r)>>1;
		if(ok(md)) r=md-1;
		else l=md+1;
	}
	cout<<l;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int n,k,x[100];
  cin>>n>>k;
  for (int i(0);i<n;i++) cin>>x[i];
  int ans(0);
  for (int i(0);i<n;i++){
    ans+=min(x[i],abs(x[i]-k))*2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;
#define INT_MAX       2147483647    // maximum (signed) int value

int gcd(int p, int q) {
    if (p % q == 0)return q;
    return gcd(q, p % q);
}

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

    vector<long long> l(n,0),aa(3,0);
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }

    sort(l.begin(), l.end());

    long long sum = 0;
    
    for (int i = 0; i < n; i++) {
        aa[0] = l[i];
        for (int j = i + 1; j < n; j++) {
            if (aa[0] != l[j]) {
                aa[1] = l[j];
                for (int k = j + 1; k < n; k++) {
                    if (aa[0] != l[k] && aa[1] != l[k]) {
                        aa[2] = l[k];
                        if (aa[0] + aa[1] > aa[2]) {
                            sum++;
                        }
                    }
                }
            }
        }
    }

    cout << sum;
   

    return 0;
}



Measured memory_bytes: 3592
program hitachi
	implicit none
	character(len=10) :: x, y
    integer :: i
    read(*,*) x
    y = "hi"
    do i = 1,5
    	if(x == y) then
        	write(*,*) "Yes"
            stop
        end if
        y = trim(y) // "hi"
    end do
    
    write(*,*) "No"
    stop
end program hitachi

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S,R;
  cin>>N>>S;
  for(int i=1;i<N;i++){
    if(S.at(i)!=S.at(i-1))
      R+=S.at(i-1);
    }
  R+=S.at(N-1);
  cout<<R.size()<<endl;
  }

Measured memory_bytes: 640
import sys

input = sys.stdin.readline

def main():
    ans = 0
    A, B, C, K = map(int, input().split())
    if K%2 == 0:
        ans = A - B
    else:
        ans = B - A
    if ans >= 10**18:
        ans = 'Unfair'
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    long long int k,a,b,tmp,tmp2;
    cin >> k >> a >> b;
    if(a>=b){
        cout << 1+k;
        return 0;
    }else if(a+1==b||a+2==b){
        cout << 1+k;
        return 0;
    }else{
        if((k-(a-1))%2==0){
            tmp=(k-(a-1))/2;
            tmp2=b-a;
            cout << (a-1)+1+tmp2*tmp;
        }else{
            tmp=(k-(a-1)-1)/2;
            tmp2=b-a;
            cout << (a-1)+1+tmp2*tmp+1;
        }
    }
}

Measured memory_bytes: 256
def mi():
    return map(int, input().split())

def main():
    N = int(input())
    s = 0
    for _ in range(N):
        x, u = input().split()
        x = float(x)*(1 if u == 'JPY' else 380000.0)
        s += x

    print(s)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
    int N, K;
    cin >> N >> K;
    unsigned int a[N], dp[K + 1][N];//intでは若干ケタが足らずWAが出る
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for(int j = 0; j < N; j++) {
        dp[0][j] = 1;
    }
    for(int i = 1; i <= K; i++) {
        if(i <= a[0]) {
            dp[i][0] = 1;
        } else {
            dp[i][0] = 0;
        }
        for(int j = 1; j < N; j++) {
            if(a[j] == 0) {
                dp[i][j] = dp[i][j - 1];
            } else {
                if(i <= a[j]) {
                    dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1000000007) % (1000000007);
                } else {
                    dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1 - a[j]][j - 1] + 1000000007) % (1000000007);
                }
            }
        }
    }
    cout << dp[K][N - 1] << endl;
    return 0;
}
 

Measured memory_bytes: 39296