akhauriyash/Code-Regression huggingface dataset:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
TA = [LIST() for _ in range(N)]

T = TA[0][0]
A = TA[0][1]

for t, a in TA[1:]:
	p = max(T//t + (T%t!=0), A//a + (A%a!=0))
	T = t*p
	A = a*p
	
print(T+A)



Measured memory_bytes: 10584
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  val n, d = sc.nextInt()

  val x = 2 * d + 1

  val ans = n / x

  if (ans * x < n) {
    println(ans + 1)
  } else {
    println(ans)
  }

}


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

using namespace std;

int n, h, x;
long long sum;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> h >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        sum += x;
    }
    return cout << (sum >= h ? "Yes" : "No"), 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
      
      	if(N == 1) {
          System.out.println("Yes");
        }
        
        else {
      	Integer a[] = new Integer[N];
      	for (int i=0; i<N; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a, Comparator.reverseOrder());
      
      	double sum = 0;
        for (int i=0; i<N; i++) {
          sum += a[i];
        }
      
      	double sum2 = sum * 1 / (4 * M);
          
        int i2 = 0;
      	while(a[i2] >= sum2) {
          i2++;
          if(i2 >= N) break;
        }
      	
      	if (i2 >= M)
            System.out.println("Yes");
        else
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22736
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;
#define max 2147483647
vector<int> v;
int n,q;
int N;
int m;
void update(int i,int x){
    i+=N-1;
    v[i]=x;
    while(i>0){
        i=(i-1)/2;
        v[i]=min(v[i*2+1],v[i*2+2]);
    }
}
int find(int a,int b,int k,int l,int r){
    if(r<=a||b<=l)return max;
    if(a<=l&&r<=b){
        return v[k];
    }else{
        int c =find(a,b,2*k+1,l,(l+r)/2);
        int d=find(a,b,2*k+2,(l+r)/2,r);
        return min(c,d);
    }
    return 0;
}
int main(){
    
    cin >> n>>q;
    N=1;
    while(N<n){
        N *=2;
    }
    v=vector<int>(2*N-1,max);
    for(int i=0;i<q;i++){
        m=max;
        int com;
        cin >> com;
        int x,y;
        cin >> x>>y;
        if(com==0){
            update(x,y);
        }else{
            cout << find(x,y+1,0,0,N)<<endl;
        }
    }
   
    
    
}



Measured memory_bytes: 4920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> ans(n);
    for (int i = 1; i < n; i++) {
        int a;
        cin >> a;
        a--;
        ans[a]++;
    }
    for (int i : ans) {
        cout << i << '\n';
    }
    return 0;
}

Measured memory_bytes: 3984
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        List<City> cities = new ArrayList<>();
        for(int i = 0;i < n;i++){
            String[] ints = sc.nextLine().split(" ");
            int x = Integer.parseInt(ints[0]);
            int y = Integer.parseInt(ints[1]);
            cities.add(new City(x,y));
        }
        List<Double> distanceList = new ArrayList<>();
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                City city1 = cities.get(i);
                City city2 = cities.get(j);
                int x1 = city1.x;
                int y1 = city1.y;
                int x2 = city2.x;
                int y2 = city2.y;
                distanceList.add(Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
            }
        }
        double result = 0;
        for(Double d : distanceList){
            result += d;
        }
        System.out.println(result / n);

    }
}

class City{
    public int x;
    public int y;
    public City(int x,int y){
        this.x = x;
        this.y = y;
    }
}

Measured memory_bytes: 25300
// ユークリッドの互除法
func gcd(_ x: Int, _ y: Int) -> Int {
    if y == 0 { return x }
    return gcd(y, x % y)
}
// 再帰関数
func recursiveFunc(_ idx: Int, _ x: Int) {
    if idx == N-1 {
        print(x)
        return
    }
    recursiveFunc(idx+1, gcd(x, A[idx+1]))
}

let N = Int(readLine()!)!
let A: [Int] = readLine()!.split(separator: " ").map { Int($0)! }

recursiveFunc(1, gcd(A[0], A[1]))   // (๑•ૅㅁ•๑)

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
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;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------
vector<bool> prime_table(int n){
    vector<bool> res(n+1,true) ;

    res[0] = false ;
    res[1] = false ;

    for(int i=2;i*i<=n;i++){
        if(res[i]){
            int j = i+i ;
            while(j<=n){
                res[j] = false ;
                j += i ;
            }
        }
    }
    return res ;
}
//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<bool> num = prime_table(55555);
    ll cnt = 0;
    REP(i,55555){
        if(num[i] && i%5==1){
            cout << i <<" ";
            cnt++;
        }
        if(cnt==n){
            cout << endl;
            break;
        }
    }


    
    return 0;
}



Measured memory_bytes: 3592
# -*- coding: utf-8 -*-


#
import collections
H, W, N = map(int, input().split(' '))

point_frq_dict = collections.defaultdict(int)
for _ in range(N):
    a, b = map(int, input().split(' '))
    for i in range(3):
        for j in range(3):
            if 0 < a-i < H-1 and 0 < b-j < W-1:
                point_frq_dict[(a-i, b-j)] += 1

ans = [0 for _ in range(10)]
n = 0
for frq in point_frq_dict.values():
    ans[frq] += 1

ans[0] = (H-2)*(W-2) - sum(ans)
for a in ans:
    print(a)



Measured memory_bytes: 153716
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Double R;
  cin>>R;

  Double ans = 2 * R * PI;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3800
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  ull a,b,x; cin>>a>>b>>x;
  ull cnt = 0;
  if(a == 0) {
    cnt++;
    a = 1;
  }
  cnt += (b / x) - ((a - 1) / x);

  cout << cnt << endl;
}


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

          #define sqr(x) (x)*(x)
          using namespace std;
          int n, a[222], k, t = 1e9, dsds[3232];
          int main()
          {
            cin >> n;
            for(int i = 1; i <= n; i++)
              cin >> a[i];
            for(int i = 1; i <= 100; i++)
            {
              for(int j = 1; j <= n; j++)
                k += sqr(i-a[j]);
              t = min(t, k);
              k = 0;
            }
            cout << t;
          }

Measured memory_bytes: 256
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase

"""
    for _ in range(int(input())):
    n,m=map(int,input().split())
    n=int(input())
    a = [int(x) for x in input().split()]
"""

def main():
    n=int(input())
    a = [int(x) for x in input().split()]
    N = 10**6
    ans=[True]*(1+N)
    ct=[False]*(1+N)
    for x in a:
        if ct[x]:
            ans[x]=False
            continue
        ct[x]=True
        for j in range(2*x,N+1,x):
            ans[j]=False
    cnt=0
    for x in a:
        cnt+=ans[x]
    print(cnt)

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 109508
#include<bits/stdc++.h>
//#define int long long
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define mi(N) int N; cin >> N;
#define ms(s) string s; cin >> s;
#define md(d) double d; cin >> d;
#define mv(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

template<typename T>
void say(vector<T> s, char r) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << r << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("yes");
	else say("no");
}

void Yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

void Yay(bool b) {
	if (b)say("Yay!");
	else say(":(");
}

template<typename T>
void maxi(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T& a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

template<typename T>
vector<vector<T>> fill_vector(int h, int w, T val) {
	vector<vector<T>> ret;
	vector<T> v(w, val);
	rep(h)ret.push_back(v);
	return ret;
}

template<typename T>
T max(vector<T> v) {
	T ret = v[0];
	Rep(1, v.size())maxi(ret, v[i]);
	return ret;
}

template<typename T>
T min(vector<T> v) {
	T ret = v[0];
	Rep(1, v.size())mini(ret, v[i]);
	return ret;
}

signed main() {
	mi(n);
	mv(v, n);
	int ans = 0;
	int Max = 0;
	rep(n) {
		if (v[i] >= Max) ans++;
		maxi(Max, v[i]);
	}
	say(ans);
}


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

int main(){
  long N;
  cin >> N;
  long a[N];
  for(int i=0; i<N; i++) cin >> a[i];
  long target = 1;
  long num = 0;

  for(int i=0; i<N; i++){
    if(a[i]==target){
      num++;
      target++;
    }
  }
  long res;
  res = N - num;
  if(res==N) res = -1;
  cout << res << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <string>

using namespace std;

int main() {

	const char *origin;
	//chartransformed[1200];
	string str;
	//cin >> origin;
	getline(cin, str);
	origin = str.c_str();

	//cout << strlen(origin) << endl;
	
	//???????????????????????????
	for (int i = 0; i < strlen(origin); i++) {

		//cout << "i=" << i << endl;

		//?¨?????????´???
		if (isupper(origin[i]) == 0 && islower(origin[i]) == 0) {
			//cout << "kigou" << endl;
			//????????????
			//transformed[i] = origin[i];
			cout << (char)origin[i];
		}
		//??§???????????´???
		else if (isupper(origin[i]) != 0) {
			//cout << "upper" << endl;
			//transformed[i] = tolower(origin[i]);
			cout << (char)tolower(origin[i]);
		}
		//?°????????????´???
		else if (islower(origin[i]) != 0) {
			//cout << "lower" << endl;
			//transformed[i] = toupper(origin[i]);
			cout << (char)toupper(origin[i]);
		}

	}

	cout << endl;

	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

vector<vi> adj;
vector<bool> seen;
vector<bool> finished;
vi topo;

bool dfs(int v)
{
    bool ret=true;
    seen[v]=true;
    for(auto u:adj[v]){
        if (finished[u]) continue;
        if (seen[u] && !finished[u]) return false;
        if (!dfs(u)) ret=false;
    }
    finished[v]=true;
    topo.pb(v);
    return ret;
}

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<vi> a(n,vi(n-1));
    vector<vi> rev(n,vi(n));
    rep(i,n)rep(j,n-1){
        cin>>a[i][j]; a[i][j]--;
        rev[i][a[i][j]] = j;
    }
    int N=0;
    vector<vi> p(n,vi(n-1,-1));
    rep(i,n)rep(j,n-1){
        if (p[i][j]!=-1) continue;
        int oi = a[i][j];
        int oj = rev[oi][i];
        p[i][j] = N;
        p[oi][oj] = N++;
    }
    adj.resize(N);
    seen.resize(N);
    finished.resize(N);
    rep(i,n)rep(j,n-2){
        adj[p[i][j]].pb(p[i][j+1]);
    }
    rep(i,N)if(!seen[i] && !dfs(i)){
        cout<<"-1\n";
        return 0;
    }
    reverse(all(topo));
    vi dist(N);
    int ans=0;
    rep(i,N){
        int v = topo[i];
        for(auto u:adj[v]){
            chmax(dist[u],dist[v]+1);
        }
        chmax(ans,dist[v]);
    }
    cout<<ans+1<<"\n";
    return 0;
}


Measured memory_bytes: 43636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn= 5e5+5;
#define mod 1000000007
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main() {
    int a,b;
    cin>>a>>b;
    a--;b--;
    int temp=b/a+(b%a!=0);
    cout<<temp;
}



Measured memory_bytes: 3636
n,m = map(int, input().split())
l,r = map(int, input().split())
for i in range(m-1):
    l2,r2 = map(int, input().split())
    if l<l2:
        l = l2
    if r>r2:
        r = r2
print(max(r-l+1,0))

Measured memory_bytes: 3188
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    var ans = 0

    for (i in 1..n step 2){
        var c = 0
        for(j in 1..i){
            if(i % j == 0) c++
        }
        if(c == 8) ans++
    }

    println(ans)
}

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

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

Node T[MAX];
int n;

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

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

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

int main(){
  int i, v, l, r, root;

  scanf("%d", &n);
  for(i = 0; i < n; i++)
    T[i].p = NIL;

  for(i = 0; i < n; i++){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }

  for(i = 0; i < n; i++){
    if(T[i].p == NIL){
      root = i;
      break;
    }
  }

  printf("Preorder\n");
  preorder(root);
  printf("\n");
  printf("Inorder\n");
  inorder(root);
  printf("\n");
  printf("Postorder\n");
  postorder(root);
  printf("\n");
  return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef /*long long*/ int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,K;
  cin>>N>>K;
  vector<ll> A(N),B(N);
  cin>>A;
  vector<ll> bef(N);
  vector<ll> ans(N);
  for(int i=0;i<N;i++){A[i]--;B[A[i]]=i;}
  for(int i=1;i<N;i<<=1){
    for(int j=0;j+i<N;j+=i<<1){
      int lf=j,mid=j+i,rg=min<ll>(N,j+(i<<1));
      priority_queue<pll,vector<pll>,greater<pll>> Q1,Q2;
      for(int k=lf;k<mid;k++){Q1.push({B[k],k-lf});}
      for(int k=mid;k<rg;k++){Q2.push({B[k],k-mid});}
      
      int mx=-1;
      while(!Q2.empty()){
        pll a=Q2.top(); Q2.pop();
        while(!Q1.empty() && Q1.top().F<a.F+K){
          mx=max<ll>(mx,Q1.top().S);
          Q1.pop();
        }
        bef[a.S]=mx;
      }
      for(int k=1;k<rg-mid;k++){bef[k]=max(bef[k],bef[k-1]);}
      int idx=0;
      int k=0;
      for(int l=0;l<mid-lf;l++){
        while(k<rg-mid && bef[k]<l){ans[idx++]=B[k+mid]; k++;}
        ans[idx++]=B[l+lf];
      }
      for(int i=0;i<idx;i++){B[lf+i]=ans[i];}
    }
  }
  for(int i=0;i<N;i++){A[B[i]]=i;}
  for(auto &I:A){cout<<I+1<<endl;}

  return 0;
}


Measured memory_bytes: 16308
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  struct mys{int i;int p;int y;int x;};
  vector<mys> s;
  for(int i=0;i<m;i++) {
    int p,y; cin>>p>>y;
    s.push_back(mys{i,p,y,0});
  }
  sort(s.begin(),s.end(),[](mys& l,mys& r){return l.y<r.y;});
  vector<int> p(n+1);

  for(auto& a:s){
    p[a.p]++;
    a.x=p[a.p];
  }

  sort(s.begin(),s.end(),[](mys& l,mys& r){return l.i<r.i;});
  for(auto a:s){
    printf("%06d%06d\n",a.p,a.x);
  }
  return 0;
}

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

int main() {
  string x,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z;
  cin >> x;

  if ( x == "A" || x == "B" || x == "C" || x == "D" || x == "E" || x == "F"||x == "G"||x == "H"||x == "I"||x == "J"||x == "K"||x == "L"||x == "M"||x == "N"||x == "O"||x == "P"||x == "Q"||x == "R"||x == "S"||x == "T"||x == "U"||x == "V"||x == "W"||x == "X"||x == "Y"||x == "Z") {
    cout << "A" << endl;
  }
  else {
    cout << "a" << endl;
  }
}

Measured memory_bytes: 3628
N,M=map(int,input().split())
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

a = cmb(N+M,2)-N*M
print(a)

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


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class ASheepAndWolves {
public:
    void solve(std::istream& cin, std::ostream& cout) {
		ios::sync_with_stdio(false);
        cin.tie(nullptr);

        int s,w;
        cin >> s >> w;

        if (w >= s){
            cout << "unsafe" << endl;
        }else {
            cout << "safe" << endl;
        }
	}
};


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


Measured memory_bytes: 3640
// https://atcoder.jp/contests/abc172/tasks/abc172_c
#include<bits/stdc++.h>
using namespace std;

int main() {
	long long n, m, k;
	cin >> n >> m >> k;
	vector<long long> a(n+1);
	vector<long long> b(m+1);
	for (long long i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] += a[i-1];
	}
	for (long long i = 1; i <= m; i++) {
		cin >> b[i];
		b[i] += b[i-1];
	}
	long long ans = 0;
	long long i;
	for (i = 0; i <= n; i++) {
		if (k >= a[i]) {
			long long s = k - a[i];
			long long st = 0, en = m;
			while (st < en) {
				long long mi = (st+en)/2;
				if (s > b[mi]) {
					st = mi+1;
				} else if (s < b[mi]) {
					en = mi-1;
				} else {
					break;
				}
			}
			if (b[st] > s) {
				ans = max(ans, i+st-1);
			} else {
				ans = max(ans, i+st);
			}
			
		}
		
	}
	cout << ans << endl;
	return 0;
}

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

int card[255][14]={{0}};

int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        char c;
        int num;
        cin >> c >> num;
        card[(int)c][num]=1;
    }
    for(int i=1;i<=13;i++){
        if(card[(int)'S'][i]==0){
            cout<<"S "<<i<<endl;
        }
    }
    for(int j=1;j<=13;j++){
        if(card[(int)'H'][j]==0){
            cout<<"H "<<j<<endl;
        }
    }
    for(int k=1;k<=13;k++){
        if(card[(int)'C'][k]==0){
            cout<<"C "<<k<<endl;
        }
    }
    for(int l=1;l<=13;l++){
        if(card[(int)'D'][l]==0){
            cout<<"D "<<l<<endl;
        }
    }



}


Measured memory_bytes: 3088
inp = list(map(int,input().split()))
x=inp[0]
n=inp[1]
inp = list(map(int,input().split()))
from collections import Counter
c=Counter(inp)
if c[x]==0:
  print (x)
else:
  i=1
  while (1):
    if c[x-i]==0:
      print (x-i)
      break
    elif c[x+i]==0:
      print (x+i)
      break
    i+=1

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


def solve(N: int, A: "List[int]"):
    B = [0] * (N + 1)
    for a in A:
        B[a] += 1
    S = 0
    for b in B:
        S += b * (b-1) // 2
    for a in A:
        c = B[a]
        print(S - c*(c-1)//2 + (c-1)*(c-2)//2)
    return


# Generated by 1.1.6 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
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 30196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    char c;
    cin >>c;
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
        cout<<"vowel"<<endl;
    }else{
        cout<<"consonant"<<endl;
    }
    
    


    return 0;
    

}

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

int main()
{
    string s;
    cin >> s;
    string::size_type posc, posf;
    posc = s.find_first_of("C");
    posf = s.find_last_of("F");
    if (posc != string::npos && posf != string::npos && posc < posf)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3592
n = int(input())
A = list(map(int, input().split()))

d = {}
for a in A:
    d[a] = d.get(a, 0) + 1

ans = 0
for a in d:
    if d[a]>a:
        ans += d[a]-a
    elif d[a]<a:
        ans += d[a]
print(ans)

Measured memory_bytes: 21744
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
	
 
 
int main(){
    while(1){
        int m,n;
        cin >> m >> n;
        if(m==0&&n==0) break;
        //m,m+1,m+2,...,2m-1,2m+1,...
        //竹の年数の選び方は自明
        //すでに選んだものの倍数を避け、1ずつ増やしていく
        vector<bool> v(7368792,false);
        int now = m;
        for(int i=0;i<m;i++){v[i]=true;}
        for(int i=0;i<n;i++){
            while(v[now]==true){now++;}
            for(int j=1;j>0;j++){
                if(now*j>7368792) break;
                v[now*j]=true;
            }

        }
        now = 0;
        while(v[now]==true){now++;}
        cout << now << endl; 
        

    }
}




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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
const int mod = 1e9+7;
//Write From this Line


#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
int main()
{
	int n;
	cin >> n;
	vector<char> a(n);
	rep(i,n) cin >> a[i];
	leftunique(a);
	int k = a.size();
	if(k==3){
		puts("Three");
	} else {
		puts("Four");
	}
}


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

int main(){
    int a,b,c,k; cin >> a >> b >> c >> k;
    for (int i=0; i<k; i++){
        if(a>=b) b=2*b;
        else c=2*c;
    }
    if(a<b && b<c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

public class Main {
    int A,N;
    int[] xs;
    long[][] dp;
    int nx;
    int na;
    Main () {
    }
    public static void main(String[] args) {
        Main m = new Main();
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String[] strs = br.readLine().split(" ");
            m.N = Integer.parseInt(strs[0]);
            m.A = Integer.parseInt(strs[1]);
            strs = br.readLine().split(" ");
            m.xs = new int[m.N];
            for (int i = 0; i < m.N; i++) {
                m.xs[i] = Integer.parseInt(strs[i]) - m.A;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        m.nx = m.N * 50;
        m.na = m.A * m.N;
        m.dp = new long[m.N+1][2*m.nx + 1];
        m.dp[0][m.na] = 1;
        m.update();
        System.out.println(m.result());
//        m.check();
    }

    void update () {
        for (int i = 1; i <= N; i++) {
            int trg = xs[i - 1];
            for (int j = 0; j < dp[0].length; j++) {
                if (j < trg || j > 2 * nx - trg) {
                    dp[i][j] = dp[i - 1][j];
                } else if (j - trg >= 0 && j - trg < dp[0].length) {
                    dp[i][j] = dp[i - 1][j] + dp[i - 1][j - trg];
                }
            }
        }
    }

    long result () {
        long res = dp[N][na] - 1;
        return res;
    }

    void check () {
        for (int i = 0; i < dp.length; i++) {
            for (int j = 0; j < dp[0].length; j++) {
                    if (dp[i][j] != 0)
                        System.out.printf("%d, %d: %d\n", i, j, dp[i][j]);
            }
        }
    }
}


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

bool check(ll n)
{
    ll n2=0;
    ll n3=n;
    while(n3>0)
    {
        ll r=n3%10;
        n2=(10*n2)+r;
        n3=n3/10;
    }
 //   cout<<n2<<endl;
    return (n2==n);
}
int main()
{
    ll x,y;
    cin>>x>>y;
    ll ans=0;
    check(123);
    check(121);
    for(ll i=x;i<=y;i++)
    {
        if(check(i))
        {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char c;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(cin>>c)
        if(c=='9')
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    cout<<"No"<<endl;
}

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

#define I inline void 

using namespace std ; 

using ld = long double ; 
using ll = long long ; 

const int N = 1e6  + 7 , mod = 1e9 + 7 ; 

int n;   

ll a[N] ; 

ll bit[N] ; 
ll num[N]; 

I add(ll i , ll x){
	for(;i<N;i+=i&-i)
		bit[i]+=x ;
}

ll upto(ll x){
	ll ret = 0 ; 
	for(;x;x-=x&-x)
		ret+=bit[x] ; 
	return ret ; 
}

ll check(ll x){
	memset(bit , 0 , sizeof bit) ; 
	ll ret = 0 ; 
	ll aux[N] ; 
	for(int i = 0 ; i < n ;i++){
		if(a[i] >= x)aux[i] =1 ; 
		else aux[i] = -1 ; 
	}
	for(int i = 1;i < n ;i++)
		aux[i]+=aux[i-1]; 
	add( 200000  , 1) ; 
	for(int i = 0 ;i < n;i++){
		ret+=upto(aux[i] + 200000 ) ; 
		add(aux[i] + 200000  , 1) ; 
	}
	return ret ;
}

int main(){
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ; 
	//freopen("in.in"  ,"r" , stdin) ; 

	cin >> n ; 

	std::vector<pair<int , int > > v;

	for(int i = 0 ;i < n;i++){
		int x ; 
		cin >> x ; 
		v.push_back({x , i}) ; 
	}
	sort(v.begin() , v.end()) ;
	a[v[0].second] = 1;  
	for(int i = 1 ;i < n;i++)
		a[v[i].second] = a[v[i-1].second] + (v[i].first > v[i-1].first) ; 

	ll lo = 1 , hi = n; 
	ll ans = v[n-1].first ; 
	ll m = 1ll * n * (n + 1) / 2ll  ; 

	m = (m + 1ll) / 2ll ;

	for(int i = 0 ; i< n;i++){
		num[ a[v[i].second] ] = v[i].first ;
	}

	while(lo<=hi){
		ll mid = (lo + hi) >> 1; 
		if(check(mid) >= m){
			lo = mid +1 ; 
			ans = mid ; 
		}
		else {
			hi = mid -1 ;
		}
	}
	cout<< num[ans] ; 
	return 0 ; 
}

Measured memory_bytes: 14268
#include<stdio.h>
#include<string.h>
typedef struct{
  char name[35];
  int page[1001];
  int flg;
}P;

main(){
  int i=0,j,k,pa,flg2,cnt=0,l,tmp;
  char str[35];
  P index[1000];
  P temp;
  while(scanf("%s %d",str,&pa)!=EOF){
    flg2=0;
    for(j=0;j<cnt;j++){
      if(strcmp(str,index[j].name)==0){
	index[j].page[pa]=1;
	flg2++;
	index[j].flg++;
	break;
      }
    }
    if(flg2==0){
      strcpy(index[cnt].name,str);
      index[cnt].page[pa]=1;
      cnt++;
      index[cnt].flg=1;
    }
  }
  for(i=0;i<cnt-1;i++){
    for(j=cnt-1;j>i;j--){
      if(strcmp(index[j].name,index[j-1].name)<0){
	temp=index[j];
	index[j]=index[j-1];
	index[j-1]=temp;
      }
    }
  }

  for(i=0;i<cnt;i++){
    printf("%s\n",index[i].name);
    for(j=1,tmp=0;j<=1000;j++){
      if(index[i].page[j]==1){
	if(tmp!=0)printf(" ");
	printf("%d",j);
	tmp=1;
      }
    }
    printf("\n");
  }
    
  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define mod 1000000007
#define long long long
using namespace std;
int n,m,k;
void readdata()
{
    cin>>n>>m>>k;
}

long power(long x,long y)
{
    if (y==0) return 1;
    long kq=power(x,y/2);
    kq=(kq*kq)%mod;
    if (y%2==1) kq=(kq*x)%mod;
    return kq;
}

long first()
{
    long s=1;
    for (int i=2;i<=k-1;i++)
    {
        s=(s*((n*m-i)%mod))%mod;
    }
    long d=1;
    for (int i=1;i<=k-2;i++)
    {
        d=(d*i)%mod;
    }
    d=power(d,mod-2);
    d=(d*s)%mod;
    return d;
}

long second()
{
    long s=0;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
            long k1=1,k2=1,l1=1,l2=1;
            k1=((k1*(i-1)*(i))%mod*m)%mod;
            l1=((l1*(n-i)*(n-i+1))%mod*m)%mod;
            k2=((k2*(j-1)*(j))%mod*n)%mod;
            l2=((l2*(m-j)*(m-j+1))%mod*n)%mod;
            s=(s+k1+l1+k2+l2)%mod;
        }
    }
    s=(s*power(4,mod-2))%mod;
    return s;
}

void solve()
{
    cout<<((first()*second())%mod);
}

int main()
{
    //freopen("a.inp","r",stdin);
    //freopen("a.out","w",stdout);
    readdata();
    solve();
    return 0;
}


Measured memory_bytes: 256
program test
 implicit none
 integer(8)::N,i,ans
 real(8)::X,Y,D
 read*,N,D
 ans=0
 do i=1,N
 	read*,X,Y
 	if(sqrt(X*X+Y*Y)<=D) then
    	ans=ans+1
    else 
    	ans=ans
    end if
end do
print*,ans
end program test

Measured memory_bytes: 2940
#include<stdio.h>
char c[4];

void search(int a[],int b[]){
  int s=a[0];
  int i;
  if(c[0]!=0) return;

  for(i=0;i<3;i++){
    if(b[i]>=2) return;
    if(b[i]==0)
      s+=a[i+1];
    else
      s-=a[i+1];
  }
  if(s==7){
    for(i=0;i<3;i++){
      if(b[i]==0)
        c[i]='+';
      else
        c[i]='-';
    }
  }

  for(i=0;i<3;i++){
    b[i]++;
    search(a,b);
    b[i]--;
  }

}


int main(void){
  int a[4],b[4];
  int i,n;

  scanf("%d",&n);

  for(i=0;i<4;i++){
    a[3-i] = n %10;
    b[i] = 0;
    c[i] = 0;
    n/=10;
  }

  search(a,b);

  for(i=0;i<3;i++)
    printf("%d%c",a[i],c[i]);
  printf("%d=7\n",a[3]);

  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(void)
{
  int i,j,n,m,s;
  int b[1000];
  int a[2][1000];

  scanf("%d",&n);

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

  scanf("%d",&m);
  
  for(i=0;i<m;i++)
    scanf("%d %d",&a[0][i],&a[1][i]);

  for(j=0;j<m;j++){
    s=0;
    for(i=0;i<n;i++){
      if(i+1==a[0][j])
        s+=a[1][j];
      else
         s+=b[i];
    }
    printf("%d\n",s);
  }

  return 0;
}




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

int main(void) {
	int n = 0, cnt = 0, tmp = 0;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		if (tmp == 2) continue;
		if (tmp <= 1 || tmp % 2 == 0) {
			cnt++;
			continue;
		}
		for (int j = 3; j <= sqrt(tmp); j += 2) {
			if (tmp%j == 0) {
				cnt++;
				break;
			}
		}
	}
	printf("%d\n", n-cnt);
	return 0;
}


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

int n,arr[200000],temp[200000];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		temp[i] = arr[i];
	}
	sort(temp, temp+n, greater<int>());
	for(int i=0;i<n;i++){
		if(arr[i] < temp[0])
			cout<<temp[0]<<endl;
		else{
			cout<<temp[1]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3200
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

const Inf = 1 << 60

func main() {
	H, W, K := ReadInt(), ReadInt(), ReadInt()
	x1, y1, x2, y2 := ReadInt()-1, ReadInt()-1, ReadInt()-1, ReadInt()-1
	x1, y1 = y1, x1
	x2, y2 = y2, x2
	c := make([]string, H)
	for y := 0; y < H; y++ {
		c[y] = ReadString()
	}

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

	toID := func(x, y, dir int) int {
		return 4*(W*y+x) + dir
	}
	splatID := func(id int) (x, y, dir int) {
		return id / 4 % W, id / 4 / W, id % 4
	}

	dist := make([]int, W*H*4)
	for i := 0; i < W*H*4; i++ {
		dist[i] = Inf
	}

	q := Heap{}
	push := func(dir, x, y, cost int) {
		id := toID(x, y, dir)
		if dist[id] <= cost {
			return
		}
		dist[id] = cost
		q.push(State{
			Cost: cost,
			ID:   id,
		})
	}

	for i := 0; i < 4; i++ {
		push(i, x1, y1, 0)
	}
	for len(q) > 0 {
		now := q.pop()
		x, y, dir := splatID(now.ID)
		if c[y][x] == '@' {
			continue
		}
		if dist[now.ID] < now.Cost {
			continue
		}
		dist[now.ID] = now.Cost
		if x == x2 && y == y2 {
			break
		}
		for i := 0; i < 4; i++ {
			push(i, x, y, (now.Cost+K-1)/K*K)
			// nCost := (now.Cost + K - 1) / K * K
			// nID := toID(x, y, i)
			// if dist[nID] <= nCost {
			// 	continue
			// }
			// q.push(State{
			// 	Cost: nCost,
			// 	ID:   nID,
			// })
		}
		nx := x + dx[dir]
		ny := y + dy[dir]
		if 0 <= nx && nx < W && 0 <= ny && ny < H {
			push(dir, nx, ny, now.Cost+1)
			// nCost := now.Cost + 1
			// nID := toID(nx, ny, dir)
			// if dist[nID] <= nCost {
			// 	continue
			// }
			// q.push(State{
			// 	Cost: nCost,
			// 	ID:   nID,
			// })
		}
	}
	ans := Inf
	for i := 0; i < 4; i++ {
		id := toID(x2, y2, i)
		if dist[id] < ans {
			d2 := (dist[id] + K - 1) / K
			if d2 < ans {
				ans = d2
			}
		}
	}
	if ans < Inf {
		fmt.Println(ans)
	} else {
		fmt.Println(-1)
	}
}

type State struct {
	Cost, ID int
}

type HeapElement = State
type Heap []HeapElement

func (h Heap) Less(i, j int) bool    { return h[i].Cost < h[j].Cost }
func (h Heap) Len() int              { return len(h) }
func (h Heap) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *Heap) Push(x interface{})   { *h = append(*h, x.(HeapElement)) }
func (h *Heap) Pop() (x interface{}) { *h, x = (*h)[:len(*h)-1], (*h)[len(*h)-1]; return }
func (h *Heap) push(v HeapElement)   { heap.Push(h, v) }
func (h *Heap) pop() HeapElement     { return heap.Pop(h).(HeapElement) }

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 84644
#include <bits/stdc++.h>
using namespace std;
#define int long long
int findLowerBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{

    auto low = lower_bound(arr.begin(),
                           arr.end(), p);

    return low - arr.begin();
}
int findUpperBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{
    auto up = upper_bound(arr.begin(),
                          arr.end(), p);

    return up - arr.begin();
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string str;
    int n, m;
    cin >> n;
    int arr[n];
    int sum[n] = {0};
    int sum1 = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
        sum1 += arr[i];
    }
    sum[0] = arr[0];
    for (int i = 1; i < n; i++)
        sum[i] = sum[i - 1] + arr[i];
    int min1 = 1000000000000;
    for (int i = 0; i < n - 1; i++)
    {
        int p = sum1 - sum[i];
        int p1 = fabs(sum[i] - p);
        // cout << p1 << "\n";
        min1 = min(min1, p1);
    }
    cout << min1 << "\n";

    return 0;
}


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

int
main(void)
{
        int N;
        int *V;
        int *C;
        int value = 0;

        scanf("%d\n", &N);
        V = malloc(sizeof(int) * N);
        C = malloc(sizeof(int) * N);

        for (int i = 0; i < N; i++)
                scanf("%d%*c", &V[i]);
        for (int i = 0; i < N; i++)
                scanf("%d%*c", &C[i]);

        for (int i = 0; i < N; i++) {
                int gain = V[i] - C[i];
                if (gain > 0)
                        value += gain;
        }

        printf("%d", value);
}


Measured memory_bytes: 128
while True:
    m,f,r=map(int,input().split())
    if  m==f==r==-1:
        break
    else:
        if m==-1 or f==-1 or m+f<30:
            print('F')
    
        elif m+f>=80:
            print('A')
        
        elif m+f>=65 and m+f<80:
            print('B')
        elif (m+f>=50 and m+f<65) or r>=50:
            print('C')
        
        elif m+f>=30 and m+f<50:
            print('D')
        
        else:
            print('F')


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    string c;
    cin >> c;
    c[0]++;
    c(c);
    return 0;
}

Measured memory_bytes: 256
import math
def task():
    n=int(input())
    if(n>=1000):
        a=math.ceil(n/1000)
        a=a*1000
        n=a-n
    else:
        n=1000-n
    print(n)
def default():
    t=1
    while(t):
        t-=1
        task()
if(__name__=="__main__"):
    default()


Measured memory_bytes: 61888
a,b,c = input().split()
dic = {"a":"A","b":"B","c":"C","d":"D","e":"E","f":"F","g":"G","h":"H","i":"I","j":"J","k":"K","l":"L","m":"M","n":"N","o":"O","p":"P","q":"Q","r":"R","s":"S","t":"T","u":"U","v":"V","w":"W","x":"X","y":"Y","z":"Z"}
print(dic[a[0]]+dic[b[0]]+dic[c[0]])

Measured memory_bytes: 3064
fn main() {
    let a = read::<usize>();
    let b = read::<usize>();
    let c = read::<usize>();
    let x = read::<usize>();

    let mut cnt = 0;
    for i in 0..a+1 {
        for j in 0..b+1 {
            for k in 0..c+1 {
                if 500*i + 100*j + 50*k == x {
                    cnt += 1;
                }
            }
        }
    }

    println!("{}", cnt);
}

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: 4352
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

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

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

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int A[3][3] = {};
	int B[3][3] = {};
	
	for(int  i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			cin>>B[i][j];
			A[i][j] = i * 3 + j;
		}
	}
	
	int N;
	
	cin>>N;
	
	for(int i = 0; i < N; i++){
		int b;
		
		cin>>b;
		
		for(int  i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				if(b == B[i][j]){
					A[i][j] = -1;
					// cout<<i<<" "<<j<<" "<<b<<endl;
				}
			}
		}
	}
	
	bool flag = false;
	for(int  i = 0; i < 3; i++){
		int con = 0;
		for(int j = 0; j < 3; j++){
			if(A[i][0] == A[i][j] ) con++;
		}
		
		if(con == 3) flag = true;
	}
	
	for(int  i = 0; i < 3; i++){
		int con = 0;
		for(int j = 0; j < 3; j++){
			if(A[0][i] == A[j][i] ) con++;
		}
		
		if(con == 3) flag = true;
	}
	
	if(A[0][0] == A[1][1] && A[0][0] == A[2][2]) flag = true;
	if(A[2][0] == A[1][1] && A[2][0] == A[0][2]) flag = true;
	
	
	cout<<(flag?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256