akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
ll MOD = 1e9+7;
ll MOD2 = 998244353;
int inf = 1e8;
ll INF = 1e16;
string alpha = "abcdefghijklmnopqrstuvwxyz";

ll f(ll a, ll b){return a+b;}
ll other = 0;

struct segment_tree{
    ll n;
    ll seg[1000000];
    //要素数Nのセグメント木を構築
    segment_tree(int N){
        n = 1;
        while(n < N) n *= 2;
        fill_n(seg, 2*n-1, other);
    }
    //i番目の要素をxに変更(0番目から数える)
    void update(int i, ll x){
        i += n-1;
        seg[i] = x;
        while(i > 0){
            i = (i-1)/2;
            seg[i] = f(seg[2*i+1], seg[2*i+2]);
        }
    }
    //i番目の要素にx加える
    void add(int i, ll x){
        i += n-1;
        seg[i] += x;
        while(i > 0){
            i = (i-1)/2;
            seg[i] = f(seg[2*i+1], seg[2*i+2]);
        }
    }
    //要素数N以上の最小の２べきnを取得
    ll size(){return n;}
    //query(a, b, 0, 0, n)でa番目からb-1番目までの演算の結果を取得
    ll query(int a, int b, int i, int l, int r){
        if(a >= r || b <= l) return other;
        elif(a <= l && r <= b) return seg[i];
        else{
            int vl = query(a, b, 2*i+1, l, (l+r)/2);
            int vr = query(a, b, 2*i+2, (l+r)/2, r);
            return f(vl, vr);
        }
    }
};

int main(){
    ll N;
    cin >> N;
    ll M = N*(N+1)/2;
    int a[N];
    rep(i, N) cin >> a[i];
    //解は[l,r]に存在する
    int l = 0, r = 1e9;
    while(l < r){
        int n = (l+r+1)/2, sub[N];
        //M個の中央値のうち、n以上のものの個数を計算
        rep(i, N){
            if(a[i] >= n) sub[i] = 1;
            else sub[i] = -1;
        }
        ll sum[N+1];
        sum[0] = 0;
        rep(i, N) sum[i+1] = sum[i]+sub[i];
        segment_tree seg(2*N+1);
        ll res = 0, m = seg.size();
        rep(i, N+1){
            res += seg.query(0, sum[i]+N+1, 0, 0, m);
            seg.add(sum[i]+N, 1);
        }
        if(res < M-(M/2)) r = n-1;
        else l = n;
    }
    cout << l << endl;
}

Measured memory_bytes: 7808
N, T = map(int, input().split())
lists = [list(map(int, input().split())) for i in range(N)]

cost = 1001
count = 0
for i in range(N):
    if lists[i][1] <= T:
        count += 1
        if i == 0:
            cost = lists[i][0]
        elif cost >= lists[i][0]:
            cost = lists[i][0]
        else:
            continue
    else:
        continue
if count == 0:
    print("TLE")
else:
    print(cost)

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acos(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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

#define DEBUG

ll fact(ll n)
{
	if(n == 0) return 1;
	return n * fact(n-1) % MOD;
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	ll n, m;
	cin >> n >> m;

	if(abs(n-m) > 1)
	{
		cout << 0 << endl;
		return 0;
	}
	int c = (abs(n-m) == 0 ? 2 : 1);
	cout << (fact(n) * fact(m) * c) % MOD << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q,K,R,W,H,P,L;
string S,T;
ll ans;
ll x[101010];
ll y[101010];
ll a[101010];
ll b[101010];
ll c[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;
ll tmp[101010];
int main() {
	cin>>N;
	ll num1=0,num2=0;
	rep(i,0,N){
		cin>>a[i];
		num1+=a[i];
	}
	rep(i,0,N){
		cin>>b[i];
		num2+=b[i];
		tmp[i]=a[i]-b[i];
	}
	if(num2>num1){
		cout<<-1<<endl;
		return 0;
	}
	vector<ll> posnum;
	ans=0;
	ll negativenum=0;
	rep(i,0,N){
		if(tmp[i]<0){
			negativenum+=(-1)*tmp[i];
		}
		if(tmp[i]>=0){
			posnum.push_back(tmp[i]);
		}
	}
	sort(posnum.begin(),posnum.end(),greater<ll>());
	rep(i,1,posnum.size()){
		posnum[i]+=posnum[i-1];
	}
	if(posnum.size()==N){
		cout<<0<<endl;
		return 0;
	}
	ans+=N-posnum.size();
	ans+=lower_bound(posnum.begin(),posnum.end(),negativenum)-posnum.begin()+1;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6264
D = gets.to_i
C = gets.chomp.split.map(&:to_i)
s = D.times.map{gets.split.map(&:to_i)}
c = Array.new(26, 0)

(0..D-1).each do |i|
ans = 0
boder = s[i][0]+c[0]

  (0..25).each do |l|
    c[l] += C[l]
  end
  (1..25).each do |e|
    if s[i][e]+c[e] > boder
      ans = e
      boder = s[i][e]+c[e]
    end
  end
c[ans] = 0
puts ans+1
end

Measured memory_bytes: 14380
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}
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; }

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

template<typename T>  
bool isOk(T key,T value){
  return key <= value;
}
template<typename T>
T binary_search(vector<T> a,T key){
  T ok = a.size();
  T ng = -1;

  while(abs(ok - ng) > 1){
    T mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }

  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}
vector<ll> primes(ll n){
  vector<ll> v;
  for (ll i = 2; i*i <= n; ++i) {
    while(n%i==0){
      n/=i;
      v.pb(i);
    }
  }
  if(n != 1)v.pb(n);
  return v;
}

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

int main() { 
  //cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  vector<int> a(n);rep(i,n)cin>>a[i];
  ll sum = SUM(a);
  vector<int> x(n);
  x[0] = sum;
  rep(i,n)if(i%2)x[0] -= a[i]*2;
  rep(i,n){
    if(!i)continue;
    x[i] = 2*a[i-1] - x[i-1];
  }
  rep(i,n)cout<<x[i]<<" \n"[i==n-1];
  return 0;
}

Measured memory_bytes: 2048
H, W = map(int, raw_input().split())
P = [list(raw_input()) for h in range(H)]
ans = True
P.insert(0, ['.' for w in range(W)])
P.append(['.' for w in range(W)])
for i in range(len(P)):
  P[i].insert(0, '.')
  P[i].append('.')
for h in range(1,H+1):
  for w in range(1, W+1):
    if P[h][w] == '#':
      if P[h][w+1] != '#' and P[h+1][w] !='#' and P[h][w-1] != '#' and P[h-1][w] != '#':
        ans = False
print 'Yes' if ans else 'No'


Measured memory_bytes: 2692
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

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

const ll INF = 1e15;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main(void) {
	int N, M; cin >> N >> M;
	ll ans = 0;
	vector<ll> A(N),sum(N+1,0);
	vector<P> B(M);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		ans += A[i];
	}
	sort(A.begin(), A.end());
	for (int i = 0; i < N; i++) {
		sum[i + 1] = sum[i] + A[i];
	}
	for (int i = 0; i < M; i++) {
		int b, c; cin >> b >> c;
		B[i] = { c,b };
	}

	sort(B.begin(), B.end());
	//for (int i = 0; i < M; i++) cout << B[i].first << endl;
	int pos = -1;
	for (int i = M - 1; i >= 0; i--) {
		int itr = lower_bound(A.begin(), A.end(), B[i].first) - A.begin() - 1;
		//cout << i << ',' << itr <<"--->"<<B[i].first<<endl;
		if (itr <= pos)continue;
		itr = min(itr, pos + B[i].second);
		//cout << pos << "," << itr << ',' << B[i].first << endl;
		ans -= sum[itr + 1] - sum[pos + 1];
		ans += B[i].first*(itr - pos);
		pos = itr;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3328
#!/usr/bin/env python3
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
mod = 10 ** 9 + 7
ans = 0

for j in range(60):
    li = (a >> j) & 1
    i = np.count_nonzero(li)
    o = n - i
    ans += o * i * 2 ** j

print(ans % mod)


Measured memory_bytes: 49932
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    unsigned long long n,a[100],x=0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]==a[i+1]){
            x++;
            i++;
        }
    }
    cout << x << endl;
}

Measured memory_bytes: 256
#if 0
date +%Y.%m.%d

solution will be written here.
#endif
#include <cstdio>
#include <queue>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;
struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
} read;

const int maxn = 100005;
int head[maxn << 1], nxt[maxn << 3], to[maxn << 3], cap[maxn << 3], hp = 1;
int cur[maxn << 1], level[maxn << 1];

inline void add(int u, int v, int c) {
	nxt[++ hp] = head[u];
	head[u] = hp;
	to[hp] = v;
	cap[hp] = c;
	if(!(hp & 1)) add(v, u, 0);
}

bool bfs(int s, int t) {
	std::queue<int> q;
	q.push(s);
	std::fill(level, level + t + 1, 0);
	level[s] = 1;
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(int i = head[u]; i; i = nxt[i])
			if(cap[i] and !level[to[i]]) {
				level[to[i]] = level[u] + 1;
				q.push(to[i]);
			}
	}
	return level[t];
}

int dinic(int u, int t) {
	if(u == t) return 1;
	for(int &i = cur[u]; i; i = nxt[i])
		if(cap[i] and level[to[i]] == level[u] + 1) {
			int f = dinic(to[i], t);
			if(f) {
				cap[i] -= f;
				cap[i ^ 1] += f;
				return f;
			}
		}
	return 0;
}

bool vis[maxn];
int match[maxn];
int ansx[maxn], ansy[maxn], ap;

int main() {
	int n = read;

	int s = n * 2, t = n * 2 + 1;
	for(int i = 1; i < n; i ++)
		add(s, i, 1);
	for(int i = 1; i < n; i ++)
		add(n + i, t, 1);

	for(int i = 1; i < n; i ++) {
		int k = read;
		while(k --)
			add(read, n + i, 1);
	}

	int flow = 0;
	while(bfs(s, t)) {
		std::copy(head, head + t + 1, cur);
		int f;
		while((f = dinic(s, t)))
			flow += f;
	}

	if(flow != n - 1) return puts("-1"), 0;

	for(int u = n + 1; u < n * 2; u ++)
		for(int i = head[u]; i; i = nxt[i])
			if(cap[i])
				match[u - n] = to[i];

	std::queue<int> q;
	q.push(n);
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(int i = head[u]; i; i = nxt[i])
			if(to[i] != s and !vis[to[i] - n]) {
				vis[to[i] - n] = 1;
				q.push(match[to[i] - n]);
				++ ap;
				ansx[to[i] - n] = u;
				ansy[to[i] - n] = match[to[i] - n];
			}
	}

	if(ap != n - 1) return puts("-1"), 0;

	for(int i = 1; i <= ap; i ++)
		printf("%d %d\n", ansx[i], ansy[i]);
}


Measured memory_bytes: 14644
fn main() {
    let n = read::<usize>();
    let ret = (n - 1) * n / 2;
    println!("{}", ret);
}

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


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

using namespace std;
using ll = long long;
using pii = std::pair<int, int>;

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back
const int mn = 1e5 + 5;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 10;
using LL = long long;
LL fac[MAXN];
LL poww(LL a, LL n) {
    LL b = 1;
    while (n) {
        if (n & 1) b = b * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return b;
}
LL inv(LL a) { return poww(a, MOD - 2); }
LL C(LL n, LL m) { return fac[n] * inv(fac[n - m]) % MOD * inv(fac[m]) % MOD; }
int main() {
#ifdef trote
    freopen("../1.txt", "r", stdin);
#endif
    LL n, a, b, c;
    cin >> n >> a >> b >> c;
    fac[0] = 1;
    for (LL i = 1; i < n + n + 10; ++i) fac[i] = fac[i - 1] * i % MOD;
    LL inv100 = inv(100);
    a = a * inv100 % MOD, b = b * inv100 % MOD, c = c * inv100 % MOD;
    LL aw = a * inv(a + b) % MOD, bw = b * inv(a + b) % MOD;
    LL ans = 0;
    for (LL i = 0; i < n; ++i) {
        LL f = poww(aw, n) * poww(bw, i) % MOD * C(n + i - 1, i) % MOD;
        LL g = poww(bw, n) * poww(aw, i) % MOD * C(n + i - 1, i) % MOD;
        ans += (n + i) * f % MOD;
        ans += (n + i) * g % MOD;
        ans %= MOD;
    }
    c = (1 - c + MOD) % MOD;
    ans = ans * inv(c) % MOD;
    //cout << 372 * inv(64) % MOD << "\n";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
from itertools import*
n=int(input())
s=input()

*x,=accumulate(i=="R" for i in s)
*y,=accumulate(i=="G" for i in s)
*z,=accumulate(i=="B" for i in s)
x2=list(accumulate(i=="R" for i in s[::-1]))[::-1]
y2=list(accumulate(i=="G" for i in s[::-1]))[::-1]
z2=list(accumulate(i=="B" for i in s[::-1]))[::-1]

ans=0
if n<4:
    print(0)
else:
    for i in range(1,n-1):
        p=s[i]
        for j in range(1,min(i,n-i-1)+1):
            q,r=s[i-j],s[i+j]
            ans-=(p!=q and q!=r and r!=p)
                
    
    for i in range(1,n-1):
        if s[i]=="R":
            ans+=y[i-1]*z2[i+1]
            ans+=z[i-1]*y2[i+1]
        elif s[i]=="G":
            ans+=x[i-1]*z2[i+1]
            ans+=z[i-1]*x2[i+1]
        elif s[i]=="B":
            ans+=x[i-1]*y2[i+1]
            ans+=y[i-1]*x2[i+1]
    print(ans)

Measured memory_bytes: 69872
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int num = scan.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		StringBuffer sb = new StringBuffer();

		for(int i=0; i<num; i++){
			list.add(scan.nextInt());
		}
		Collections.reverse(list);
		/*for(int i: list){
			sb.append(i + " ");
		}*/
		for(int i=0; i<num; i++){
			if((i+1)==num){
				sb.append(list.get(i));
			}
			else{
				sb.append(list.get(i) + " ");
			}
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 26244
#include <stdio.h>
#include <math.h>

void swap(long long *xp, long long *yp) {
  long long temp = *xp; 
  *xp = *yp; 
  *yp = temp; 
} 

long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(&a, &b);
    u -= t * v; swap(&u, &v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

int main(void) {
  int X, Y;
  scanf("%d %d", &X, &Y);
  if ((Y * 2 - X) % 3 != 0 || (X * 2 - Y) % 3 != 0 || Y * 2 - X < 0 || X * 2 - Y < 0) {
    printf("0\n");
    return 0;
  }

  int v = (Y * 2 - X) / 3;
  int h = (X * 2 - Y) / 3;

  long long result = 1;
  for (int i = v + 1; i <= v + h; i++) {
    result *= i;
    result %= 1000000007;
  }
  for (int i = 2; i <= h; i++) {
    result = result * modinv(i, 1000000007) % 1000000007;
  }

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


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
void program(); int main() {cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); program();}
#define int long long
#define endl "\n"
#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>

int n,m;
map<int, vector<int>> gra;
map<int, map<int, int>> dp;

void visit_1(int x, int p = -1) {
    int res = 1;
    for (int w : gra[x]) if (w != p) {
        visit_1(w,x);
        res = (res * (1 + dp[w][x])) % m;
    }
    dp[x][p] = res;
}

void visit_2(int x, int p = -1) {
    int wn = gra[x].size();
    vector<int> lp, rp;
    for(int w : gra[x]) lp.pb(1 + dp[w][x]);
    rp = lp;
    for(int i=1;i<wn;i++) {
        lp[i] = (lp[i] * lp[i-1]) % m;
        rp[wn-1-i] = (rp[wn-1-i] * rp[wn-i]) % m;
    }
    for(int i=0;i<wn;i++) {
        int w = gra[x][i];
        if (w != p) {
            int res = 1;
            if (i > 0) res = (res * lp[i-1]) % m;
            if (i < wn - 1) res = (res * rp[i+1]) % m;
            dp[x][w] = res;
            visit_2(w,x);
        }
    }
}

int ans(int x) {
    int res = 1;
    for (int w: gra[x]) {
        res = (res * (1 + dp[w][x])) % m;
    }
    return res;
}


void program(){
    cin>>n>>m;
    
    for (int i=0; i<n-1; i++) {
        int u,v;
        cin>>u>>v;
        gra[u].pb(v);
        gra[v].pb(u);
    }

    visit_1(1);
    visit_2(1);
    for(int x=1; x<=n; x++)
        cout << ans(x) << endl;
}


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

typedef unsigned long long ull;


int main(){
	int k, a, b;
	cin >> k >> a >> b;
	for(int i = a; i <= b; i++){
		if(i % k == 0){
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	char ch[3][3];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
		scanf("%c",&ch[i][j]);
		}
		getchar();
	}
	printf("%c%c%c\n",ch[0][0],ch[1][1],ch[2][2]);
}

Measured memory_bytes: 256
#!python3.8
# -*- coding: utf-8 -*-
# abc173/abc173_a
import sys
import math

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    a = math.ceil(N / 1000)
    ans = a * 1000 - N
    print(ans)
    return

main()


Measured memory_bytes: 9136
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var st = Console.ReadLine().Split();
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = l[0], B = l[1];
            var U = Console.ReadLine();

            if (st[0] == U) A--;
            if (st[1] == U) B--;

            Console.WriteLine($"{A} {B}");
        }
    }
}


Measured memory_bytes: 13396
### constants

DELTA = 1.0e-9

### subroutines

def poly_area(vs)
  s = 0
  deg = 0

  for v in vs
    s += Math.sin(Math::PI * v / 180)
    deg += v
  end
  s += Math.sin(Math::PI * (360 - deg) / 180)

  s
end

### main

while true
  m = gets.strip.to_i
  break if m == 0

  vms = (m - 1).times.map{gets.strip.to_i}
  n = gets.strip.to_i
  vns = (n - 1).times.map{gets.strip.to_i}
  #p vms
  #p vns

  sm = poly_area(vms)
  sn = poly_area(vns)

  d = (sm - sn).abs

  puts (d <= DELTA) ? 0 : (sm > sn) ? 1 : 2
end

Measured memory_bytes: 6160
using System;

namespace WeatherPrediction
{
    class Program
    {
        static void Main(string[] args)
        {
            string word = Console.ReadLine();

            if (word == "Sunny")
            {
                word = "Cloudy";
            }
            else if (word == "Cloudy")
            {
                word = "Rainy";
            }
            else
            {
                word = "Sunny";
            }

            Console.WriteLine(word);
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n, a, b;
	cin >> n >> a >> b;
	long long temp = n/(a+b);
	long long ans = a*temp;
	n -= ((a+b)*temp);
	if(n >= a) cout << (ans+a) << endl;
	else cout << (ans+n) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, n, m, x);
  set<int> st;
  for (int i = 0; i < n; ++i) {
    Cin(int, tmp);
    st.insert(tmp);
  }

  int go0 = 0;
  for (int i = x; i >= 0; --i)
    if (st.count(i)) go0++;

  int gon = 0;
  for (int i = x; i <= n; ++i)
    if (st.count(i)) gon++;

  cout << min(go0, gon) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

class dice{
public: 
		int surface[6];
	void setsurface(int a,int b,int c,int d,int e,int f){
		surface[0] = a;
		surface[1] = b;
		surface[2] = c;
		surface[3] = d;
		surface[4] = e;
		surface[5] = f;
	}
	void load(){
		cout << surface[0] << endl;
	}
	void roll(char d){
		int n;
		if(d == 'E'){
			n = surface[5];
			surface[5] = surface[2];
			surface[2] = surface[0];
			surface[0] = surface[3];
			surface[3] = n;
		}
		if(d == 'W'){
			n = surface[3];
			surface[3] = surface[0];
			surface[0] = surface[2];
			surface[2] = surface[5];
			surface[5] = n;
		}
		if(d == 'N'){
			n = surface[4];
			surface[4] = surface[0];
			surface[0] = surface[1];
			surface[1] = surface[5];
			surface[5] = n;
		}
		if(d == 'S'){
			n = surface[5];
			surface[5] = surface[1];
			surface[1] = surface[0];
			surface[0] = surface[4];
			surface[4] = n;
		}
	}
};

int main(){
	dice dice1;
	int n[6];
	string str;
	for (int i = 0; i < 6; ++i)
	{
		cin >> n[i];
	}
	dice1.setsurface(n[0],n[1],n[2],n[3],n[4],n[5]);
	cin >> str;
	int i = 0;
	for(int i = 0; i < str.size(); i++){
		if(str[i] == 'E'){
			dice1.roll('E');
		}
		if(str[i] == 'N'){
			dice1.roll('N');
		}
		if(str[i] == 'S'){
			dice1.roll('S');
		}
		if(str[i] == 'W'){
			dice1.roll('W');
		}
	}
	dice1.load();
}

Measured memory_bytes: 1204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <numeric>
#include <iomanip>
#include <sstream>
using namespace std;

vector<string> split(const string& s, char delim) {
	vector<string> elems;
	stringstream ss(s);
	string item;
	while (getline(ss, item, delim)) {
		if (!item.empty()) {
			elems.push_back(item);
		}
	}
	return elems;
}

int main() {

	int n;
	cin >> n;
	vector<int> p(4);
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (s == "AC")
		{
			p[0]++;
		}
		if (s == "WA")
		{
			p[1]++;
		}
		if (s == "TLE") 
		{
			p[2]++;
		}
		if (s == "RE")
		{
			p[3]++;
		}
	}

	cout << "AC x " << p[0] << endl;
	cout << "WA x " << p[1] << endl;
	cout << "TLE x " << p[2] << endl;
	cout << "RE x " << p[3] << endl;

	return 0;
};

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int zh(string x)
{
	int s=0;
	for (int i=0;i<x.size();i++)
	  s=s*10+(x[i]-'0');
	return s;
}
int main()
{
	string a,b;
	cin>>a>>b;
	int s;
	s=zh(a+b);
	if (sqrt(s)==int(sqrt(s)))
	  cout<<"Yes"<<endl;
	else 
	  cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
//#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

string s, ss;

int dmx[3001][3001];
pair <int,int> p[3001][3001], pmx[3001][3001];

int maxi(int i, int j, int inc){
	if (inc){
		if (i && j){
			dmx[i][j] = dmx[i - 1][j - 1] + 1;
			pmx[i][j] = mp(i, j);
			p[i][j] = pmx[i - 1][j - 1];
		}
		else{ 
			pmx[i][j] = mp(i, j);
			p[i][j] = mp(-1, -1);
			dmx[i][j] = 1;
		}
	}
	else{
		if (i){
			dmx[i][j] = dmx[i - 1][j];
			pmx[i][j] = pmx[i - 1][j];
		}
		if (j){
			if (dmx[i][j] < dmx[i][j - 1]){
				dmx[i][j] = dmx[i][j - 1];		
				pmx[i][j] = pmx[i][j - 1];
			}
	 	}
	 	if (dmx[i][j] == 0){
	 		p[i][j] = mp(-1, -1);
	 		pmx[i][j] = mp(-1, -1);
	 	}
	}
	return dmx[i][j];
}

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s >> ss;
	int mx = 0;
	pair <int,int> id;
	for (int i = 0; i < s.size(); i++){
		for (int j = 0; j < ss.size(); j++){
			int x = maxi(i, j, (s[i] == ss[j]));
			if (mx < x) id = mp(i, j);
			mx = max(x, mx);
			//cout << p[i][j].f << " " << p[i][j].s << "  ";
		}
		//cout << endl;
	}
	string ans;
	if (mx == 0){
		return 0;
	}
	ans += s[id.f];
	while (p[id.f][id.s] != mp(-1,-1)){
		id = p[id.f][id.s];
		ans += s[id.f];
	}
	reverse(all(ans));
	cout << ans;
	return 0;
}












Measured memory_bytes: 176128
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

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...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 1000010;
const int MAXK = 510;
const int MAXQ = 200010;

int n, m, dp[MAXN];
vector<int> a[MAXN], b[MAXN];
bool visited[MAXN];
vector<int> topo;

void dfs(int u) {
    visited[u] = true;
    FOR(i,0,SZ(a[u])-1) {
        int v = a[u][i];
        if (!visited[u]) dfs(u);
    }
    topo.emplace_back(u);
}

void topologicalSort() {
    FOR(i,1,n) visited[i] = false;
    topo.clear();
    FOR(i,1,n)
        if (!visited[i]) dfs(i);
    reverse(ALL(topo));
}

int solve(int u) {
    if (dp[u] != -1) return dp[u];
    int Max = 0;
    FOR(i,0,SZ(b[u])-1) {
        int v = b[u][i];
        Max = max(Max, solve(v) + 1);
    }
    return dp[u] = Max;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,m) {
        int u, v;
        cin >> u >> v;
        a[u].emplace_back(v);
        b[v].emplace_back(u);
    }
    topologicalSort();
    FOR(i,1,n) dp[i] = -1;
    FORE(i,SZ(topo)-1,0)
        if (dp[topo[i]] == -1) solve(topo[i]);
    int res = 0;
    FOR(i,1,n) res = max(res, dp[i]);
    cout << res;
    return 0;
}


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

int N;
vector<vector <int> > wo(100001, vector<int>());
vector<int> odis(100001, 0);
vector<int> ndis(100001, 0);

void dfs(int now, int pre, int dist, vector<int> &dis){
  
  for(auto e: wo[now]){
    if(e != pre){
      dis[e] = dist + 1;
      dfs(e, now, dist + 1, dis);
    }
  }
  return;
}

int main(){
  cin >> N;
  
  for(int i = 0; i < N - 1; i++){
    int a, b; cin >> a >> b;
    wo[a].push_back(b);
    wo[b].push_back(a);
  }
  
  dfs(1, -1, 0, odis);
  dfs(N, -1, 0, ndis);
  
  int fnk = 0, snk = 0;
  for(int i = 1; i <= N; i++){
    if(odis[i] <= ndis[i]) fnk++;
    else snk++;
  }
  
  if(fnk > snk) cout << "Fennec";
  else cout << "Snuke";

}

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

int main(){
  ll k,a,b;
  cin>>k>>a>>b;
  if(a>=b-1){
    cout<<1+k<<endl;
    return 0;
  }
  if(k-(a-1)<=0){
    cout<<1+k<<endl;
    return 0;
  }
  k-=a-1;
  ll now=a;
  if(k%2==1){
    now++;
    k--;
  }
  cout<<now+k/2*(b-a)<<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define MP make_pair
#define pb push_back
const int INF = 1e18;
const int MOD = INF+7;
using P = pair<int,int>;

signed main(){
    int S;
    cin >> S;
    set<int> st;
    st.insert(S);
    int last=S,ans = 1;
    while(1){
        ++ans;
        if(last%2 == 0) last = last/2;
        else last = 3*last+1;
        if(st.count(last)) break;
        st.insert(last);
    }    

    cout << ans << endl;
}

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

using namespace std;

int main() {

    long n,m,sum = 0,x;
    cin >> n >> m;
    for(int i = 0;i < m; i++)
    {
        cin >> x;
        sum += x;
    }
    if (n < sum)
        cout << -1;
    else
        cout << n - sum;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cmath>
#include<vector>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

int main(){
	ll n; cin >> n;
	if(n == 1){
		cout << 1 << endl;
		return 0;
	}
	bool num[n + 1] = {0};
	num[0] = num[1] = 1;
	for(ll i = 2; i < sqrt(n); ++i){
		for(ll j = 2; i * j <= n; ++j){
			num[i * j] = 1;
		}
	}
	vector<pair<ll, ll> > prime;
	for(ll i = 2; i <= n; ++i){
		if(!num[i]) prime.push_back(pair<ll, ll>(i, 1));
	}
	for(ll i = 1; i <= n; ++i){
		for(ll j = 0; prime[j].first <= i && j < prime.size(); ++j){
			ll div = i;
			while(!(div % prime[j].first)){
				++prime[j].second;
				div /= prime[j].first;
			}
		}
	}
	ll ans = 1;
	for(ll i = 0; i < prime.size(); ++i){
		ans *= prime[i].second;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc106_c() {
	string S;
	ll K;

	cin >> S >> K;

	ll val;
	ll ans = 1;
	rep(i, S.size()) {
		val = (ll)(S[i] - '0');
		if (val != 1) {
			ans = val;
			break;
		}
		else if ((i+1) == K) {
			ans = 1;
			break;
		}
	}

	cout << ans << "\n";
}

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

	solve_abc106_c();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N, R; cin >> N >> R;
    if (N >= 10) cout << R << endl;
    else cout << R + 100 * (10-N) << endl;
}


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

namespace ConsoleApp15
{
    class Class31
    {
        static readonly long M = 998244353;
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var d = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int m = d.Max();
            var D = new int[m + 1];
            for (int i = 0; i < N; i++) D[d[i]]++;
            
            if (d[0] != 0 || D[0] != 1) { Console.WriteLine(0);return; }

            long ans = 1;
            for(int i = 1; i <= m; i++)
            {
                for(int j = 0; j < D[i]; j++)
                {
                    ans *= D[i - 1];
                    ans %= M;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 36624
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		ArrayList<String> results = new ArrayList<String>();
		
		try{
			int numDataSet = sc.nextInt();
			for(int i = 0; i < numDataSet; i++){
				results.add(getSumWith2Inputs());
			}
		}catch(NoSuchElementException e){
			//do nothing
		}
		
		for(int i = 0; i < results.size(); i++){
			System.out.println(results.get(i));
		}
	}
	
	private static String getSumWith2Inputs(){
		String overflowMessage = "overflow";
		BigDecimal result = new BigDecimal("0");
		
		//ツ禿シツ療債値ツづーツ堕ォツつキ
		for(int i = 0; i < 2; i++){
			result = result.add(new BigDecimal(sc.next()));
		}
		
		//ツ計ツ算ツ個仰嘉環づ個チツェツッツク
		String resultString = result.toString();
		if(isOver80(resultString)){
			return overflowMessage;
		}
		
		return resultString;
	}
	
	private static boolean isOver80(String str){
		if(str.length() > 80){
			return true;
		}
		else{
			return false;
		}
	}
}

Measured memory_bytes: 0
// Problem : B - Training Camp
// Contest : AtCoder - AtCoder Beginner Contest 055
// URL : https://atcoder.jp/contests/abc055/tasks/abc055_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

double pi=acos(-1.0);
const int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int n;cin>>n;
int ans=1;
for(int i=1;i<=n;i++)
ans=(ans*i)%md;
cout<<ans;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

def update_a(bi):
    for i in range(3):
        for j in range(3):
            if a[i][j]==bi:
                a[i][j]=-1
                return

def check_a():
    #yoko
    for ai in a:
        if sum(ai)==-3:
             return True
    #tate
    for i in zip(a[0],a[1],a[2]):
        if sum(i)==-3:
             return True

    #naname
    temp = 0
    for i in range(3):
        temp += a[i][i]
        if temp==-3:
            return True

    #naname2
    temp = 0
    for i in range(3):
        temp += a[i][2-i]
        if temp==-3:
            return True
    return False

for bi in b:
    update_a(bi)
if check_a():
    print("Yes")
else:
    print("No")

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

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

    // 1列ごとにロボットの距離を加算していけば良い
    // 初期座標 A:x=0 B:x=K
    int distance = 0;
    for (int i=0; i < N; i++) {
        int x_i;
        cin >> x_i;
        
        if (abs(x_i - 0) < abs(x_i - K)) {
            // A を使う
            distance += abs(x_i - 0) * 2;
        } else {
            distance += abs(x_i - K) * 2;
        }
    }
    cout << distance << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int n;
	scanf("%d",&n);
	char s[n];
	scanf("%s",s);
	int flag=0;
	int i;
	if(n%2==1){
		printf("No");
	}else{
		for(i=0;i<n/2;i++){
			if(s[i] == s[i+n/2]){
				flag++;
			}
		}
		if(flag == n/2){
			printf("Yes");
		}else{
			printf("No");
		}
	}
return(0);
}

Measured memory_bytes: 128
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

h, w = MAP()
s = [STR() for _ in range(h)]
dx = [1, -1, 0, 0, 1, 1, -1, -1]
dy = [0, 0, 1, -1, 1, -1, 1, -1]
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            ans = 0
            for k in range(8):
                nx = j + dx[k]
                ny = i + dy[k]
                if 0 <= nx < w and 0 <= ny < h and s[ny][nx] == '#':
                    ans += 1
            print(ans, end='')
        else:
            print('#', end='')
    print('')

Measured memory_bytes: 65252
// ABC085A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	cin >> s;
	s[3] = '8';
	for (int i = 0; i <= 9; i++)
	{
		cout << s[i] ;
	}
	return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
n=int(input())
ans_list=[]

for i in range(n):
	a=int(input())
	b=int(input())
	c=a+b
	if max(a,b,c)>=10**80:
		ans_list.append("overflow")
	else:
		ans_list.append(c)

for i in ans_list:
	print(i)

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

int main() {
    long long x;
    cin >> x;

    long long gohyaku = x / 500;
    long long amari = x % 500;

    long long goen = amari / 5;

    long long uresisa = gohyaku * 1000 + goen * 5;

    cout << uresisa << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = [int(i) for i in input().split()]
E = [[] for _ in range(N + 1)]
for a, b in [map(int, input().split()) for _ in range(M)]:
    E[a].append(b)
    E[b].append(a)

for e in E[1:]:
    print(len(e))


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
A = []
B = []
n,m = [int(i) for i in input().split(' ')]

for i in range(n):
    A.append([int(j) for j in input().split(' ')])
for j in range(m):
    B.append(int(input()))
#print(A)
#print(B)
c =0
for i in range(n):
    for j in range(m):
        c +=A[i][j] * B[j]
    print(c) 
    c =0

Measured memory_bytes: 8012
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;



int main(){
  double a, b, x;
  double theta;
  
  double pi = acos(-1);
  
  cin >> a >> b >> x;
  double V = a*a*b;
  
  if(x <= V/2){
    theta = atan(a*b*b/(2*x))*180/pi;
  }else{
    theta = atan(2*(V-x)/(a*a*a))*180/pi;
  }
  cout << fixed << setprecision(10) << theta;
  
  return 0;
}

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

#define ll long long
#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define repr(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back
#define debug(x) cout << x << endl;

int main() {
  int n,x; cin >> n >> x;
  if (x == 1 or x == 2 * n - 1) {
    cout << "No" << endl;
    return 0;
  } 
  if (n == 2) {
    cout << "Yes" << endl;
    cout << 1 << endl;
    cout << 2 << endl;
    cout << 3 << endl;
    return 0;
  }
  ll mmax = 2*n-1;
  deque<int> dq;
  ll a,b,c,d;
  if (x+2 > mmax) {
    dq.push_front(x);
    dq.push_front(x-2);
    dq.push_back(x+1);
    dq.push_back(x-1);
    a = x; b = x-2; c = x+1; d = x-1;
  } else {
    dq.push_front(x);
    dq.push_front(x+2);
    dq.push_back(x-1);
    dq.push_back(x+1);
    a = x; b = x+2; c = x-1; d = x+1;
  }
  ll cnt = 0;
  for (int i = 1; i <= mmax; ++i) {
    if (i == a or i == b or i == c or i == d) {
      continue;
    }
    cnt += 1;
    if (cnt % 2 == 0) {
      dq.push_back(i);
    } else {
      dq.push_front(i);
    }
  }

  cout << "Yes" << endl;
  for (auto itr : dq) {
    cout << itr << endl;
  }
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,M;cin >> N >> M;
    vector<int> k(M);
    vector<vector<int>> s(M);
    vector<int> p(M);

    vector<int> bit_flag(10);
    rep(i,11){
        bit_flag[i] = (1 << i);
    }

    rep(i,M){
        cin >> k[i];
        rep(j,k[i]){
            int t;cin >> t;
            s[i].push_back(t);
        }
    }
    rep(i,M)cin >> p[i];

    int ans = 0;

    for(int bit = 0;bit < (1 << N);++bit){
        bool ok = true;
        rep(i,M){
            if(!ok)break;
            int tmp = 0;
            rep(j,k[i]){
                int ind = s[i][j] - 1;
                if(bit & bit_flag[ind])tmp++;
            }
            if(tmp % 2 != p[i])ok = false;
        }
        if(ok)ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define For(i, l, r) for (int i = (l); i <= (r); ++i)

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

const int maxn = 100000 + 5;

int n;
LL tot;
int a[maxn], b[maxn];
int s[maxn], tmp[maxn];

LL merge_sort(int l, int r) {
  if (l == r) return 0;
  LL ret = 0;
  int mid = (l + r) / 2;
  ret += merge_sort(l, mid);
  ret += merge_sort(mid + 1, r);
  int i = l, j = mid + 1;
  For(k, l, r) {
    if (i <= mid && (j > r || s[i] <= s[j]))
      tmp[k] = s[i++];
    else
      tmp[k] = s[j++], ret += i - l;
  }
  For(k, l, r) s[k] = tmp[k];
  return ret;
}

bool check(int x) {
  s[0] = 0;
  rep(i, n) s[i + 1] = s[i] + (a[i] > x ? 1 : -1);
  return merge_sort(0, n) <= tot - (tot / 2 + 1);
}

int main() {
  scanf("%d", &n);
  tot = (LL)n * (n + 1) / 2;
  rep(i, n) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  sort(b, b + n);
  int l = 0, r = unique(b, b + n) - b - 1;
  while (l < r) {
    int mid = (l + r) / 2;
    if (check(b[mid]))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", b[r]);

  return 0;
}

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

int compare(const void *a,const void *b){
    if(*(int *)a>*(int *)b)return 1;
    return -1;
}
int main()
{   char s[11];
    scanf("%s",s);
    int l=strlen(s);
    if(l%2){
        printf("No");
        return 0;
    }
    for(int i=0;i<l;i+=2){
        if(s[i]=='h'&&s[i+1]=='i'){
            
        }else{
            printf("No");
            return 0;
        }
    }
    printf("Yes");

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <ext/rope>

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define last(s) (s)[int((s).size())-1]
#define prelast(s) (s)[int((s).size())-2]
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define elif else if
#define left asdasd
#define next zaza

#define cclear cout<<flush;
#define x0 kerker
#define time chas
#define y0 lolik
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define files freopen("a.in", "r", stdin);freopen("a.out", "w", stdout);
#define ref svyazi
#define int long long
#define ii pair<int, int>
#define ld long double
#define list spisok


using namespace std;
//using namespace __gnu_cxx;

int n,a[110],sm;
main(){
    kchay;
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> a[i];
        sm+=a[i];
    }
    long double s=(double)sm/n;
    long double dif=1e9;
    int ans=0;
    for (int i=0;i<n;i++){
        if (abs(s-a[i])<dif){
            dif=abs(s-a[i]);
            ans=i;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256