akhauriyash/Code-Regression huggingface dataset:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M, K = map(int, input().split())
    num_friends = [0 for _ in range(N)]
    blocks = [[] for _ in range(N)]
    uf = UnionFind(N)

    for _ in range(M):
        a, b = map(int, input().split())
        num_friends[a-1] += 1
        num_friends[b-1] += 1
        uf.union(a-1, b-1)
    for _ in range(K):
        a, b = map(int, input().split())
        blocks[a-1].append(b-1)
        blocks[b-1].append(a-1)

    for i in range(N):
        cnt = uf.size(i) - 1 - num_friends[i]
        for j in blocks[i]:
            if uf.same(i, j):
                cnt -= 1
        print(cnt, end=' ')

if __name__ == "__main__":
    main()

Measured memory_bytes: 110112
#!/usr/bin/python

n = []

while True:
  (a, b, c) = (i for i in input().split())
  if b == '?':
    break
  else:
    n.append((int(a),b,int(c)))

for i in range(len(n)):
  if n[i][1] == '+':
    print(n[i][0] + n[i][2])
  elif n[i][1] == '-':
    print(n[i][0] - n[i][2])
  elif n[i][1] == '*':
    print(n[i][0] * n[i][2])
  elif n[i][1] == '/':
    print(int(n[i][0] / n[i][2]))

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

using namespace std;

long long int n,x=0,k=0,o=0,u=0,s=0,l=1e10,a[300000];
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin >> n;
	
	for(int i=1; i<=n; i++)	
	{
		cin >> a[i];
		s+=a[i];
		k=max(k,a[i]);
		l=min(l,a[i]);
	}
	x=n*(n+1);
	x/=2;
	if(s%x!=0)
	{
		cout << "NO";
		return 0;
	}
	x=s/x;
	if(l<x || n*x<k)
	{
                cout << "NO";
                return 0;
        }
	s=0;
	//cout << "OK";
	for(int i=1; i<=n; i++)
        {
		if(i<n)
                	l=a[i+1]-a[i];
		else
			l=a[1]-a[n];
		k=x;
		if(l>=0)
		{
			k-=l;
			if(k%n!=0)
			{
				cout << "NO";
				return 0;
			}
			k/=n;
			s+=k;
		}
		else
		{
			l*=-1;
			o=l%(n-1);
			if(o>0)
				o=n-1-o;	
			l+=o;
			l/=(n-1);
			k-=o;
			k-=l;
			if(k%n!=0)
                        {
                                cout << "NO";
                                return 0;
                        }
			k/=n;
			k+=l;
			s+=k;
		}	
		//cout << i << ' ' << s << endl;
        }	
	//cout << s << " OK" << endl;
	if(s!=x)
	{
		cout << "NO";
		return 0;
	}
	cout << "YES";
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
int n,T;
vector<int> M,L,K;
bool check(int x){
  int cnt = 0;
  vector<int> call(n,0);
  vector<int> compute = M;
  vector<int> used(n,0);
 
  for(int t=0;t<=T;t++){
 
    for(int i=0;i<n;i++) if(used[i] && compute[i] && --compute[i] == 0) cnt--;
    for(int i=0;i<n;i++) if(t-call[i] == L[i] + K[i]) call[i] = t; 
     
    for(int i=0;i<n && cnt < x ;i++){
      if(used[i]) continue;
      if(t - call[i] <= L[i]) used[i] = 1,cnt++;
    }
  }
     
  for(int i=0;i<n;i++) if(compute[i] > 0) return 0;
  return 1;
}
 
   
signed main(){
  while(1){
    int sum = 0;
    cin>>n>>T;
    if( n == 0 && T == 0) break;
    M.clear(),L.clear(),K.clear();
    M.resize(n),L.resize(n),K.resize(n);
    for(int i=0;i<n;i++) cin>> M[i]>>L[i]>>K[i],sum += M[i];
     
    //for(int i=0;i<=n;i++) cout<<i<<" "<<check(i)<<endl;
 
    int ans = sum / T;
    for(;check(ans) == 0;ans++);
    cout<<ans<<endl;
  }
     
  return 0;
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    REP(i, n) {
        cin >> a[i];
        b[i] = a[i] - (i + 1);
    }
    SORT(b);
    ll c;
    if (n % 2 == 0) {
        c = (b[n / 2] + b[n / 2 - 1]) / 2;
    } else {
        c = b[n / 2];
    }
    ll ans = 0;
    REP(i, n) ans += abs(a[i] - (c + i + 1));
    cout << ans << EOL;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <vector>
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
const int MAX=2e3+5;
const int NAX=1e3+5;
const ll INF=1e18+5;
const double M=4e18;
using namespace std;
const int MOD=1e9+7;
typedef pair<int,int> pii;
const double eps=0.000000001;
int n,m;
ll dis[NAX];
int from[MAX],to[MAX];
bool neg[MAX];
ll cost[MAX];
ll an;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;++i)
    {
        scanf("%d%d%lld",&from[i],&to[i],&cost[i]);
        cost[i]=-cost[i];
    }
    fill(dis+1,dis+1+n,INF);
    dis[1]=0;
    for(int i=0;i<n-1;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(dis[from[j]]==INF)
                continue;
            if(dis[to[j]]>dis[from[j]]+cost[j])
            {
                dis[to[j]]=dis[from[j]]+cost[j];
            }
        }
    }
    an=dis[n];
    for(int i=0;i<n-1;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(dis[from[j]]==INF)
                continue;
            if(dis[to[j]]>dis[from[j]]+cost[j])
            {
                neg[to[j]]=true;
                dis[to[j]]=dis[from[j]]+cost[j];
            }
            if(neg[from[j]])
                neg[to[j]]=true;
        }
    }
    if(neg[n])
        printf("inf\n");
    else
        printf("%lld\n",-an);
}


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

int mvl[2000][26];
int mvr[2000][26];
int dp[2000][2000];
char nx[2000][2000];

int L;
string str;

void calc()
{
	for(int i=0; i<L; i++)
	for(int j=0; j<26; j++) {
		mvl[i][j] = -1;
		mvr[i][j] = -1;
	}

	for(int i=0; i<L; i++)
	for(int j=0; j<26; j++) { 
		for(int k=i; k<L; k++) {
			if(str[k] == 'A' + j) {
				mvl[i][j] = k-i;
				break;
			}
		}

		for(int k=i; k>=0; k--) {
			if(str[k] == 'A' + j) {
				mvr[i][j] = i-k;
				break;
			}
		}
	}
}

int dfs(int l, int r)
{
	if(l > r) return 0;
	if(dp[l][r] != -1) return dp[l][r];

	int res = 0;
	for(int i=0; i<26; i++) {
		if(mvl[l][i] == -1 || mvr[r][i] == -1) continue;

		int nl = l + mvl[l][i];
		int nr = r - mvr[r][i];

		if(nl >= nr) continue;
		
		int tmp = dfs(nl + 1, nr - 1) + 2;
		if(res < tmp) {
			res = tmp;
			
			nx[l][r] = i;
		}
	}

	if(res == 0) {
		if(l <= r) {
			res = 1;
		}
	}

	dp[l][r] = res;

	return dp[l][r];
}

string result(int l, int r)
{
	if(nx[l][r] == '$') {
		if(l <= r) return string(1,str[l]);
		
		return "";
	}

	int nl = l + mvl[l][nx[l][r]];
	int nr = r - mvr[r][nx[l][r]];

	return str[nl] + result(nl+1, nr-1) + str[nl];
}

int main()
{
	while(cin >> str) {
		L = str.size();

		for(int i=0; i<L; i++)
		for(int j=0; j<L; j++) {
			dp[i][j] = -1;
			nx[i][j] = '$';
		}

		calc();
		dfs(0, L-1);

		string res=result(0, L-1);

		cout << res << endl;
	}
}

Measured memory_bytes: 20000
#include <stdio.h>
int main()
{
  int a,b;
  scanf("%d%d",&a,&b);
  int sum;
  sum = 0;
  if (a == 1)
    sum += 300000;
  else if (a == 2)
    sum += 200000;
  else if (a == 3)
    sum += 100000;
  if (b == 1)
    sum += 300000;
  else if (b == 2)
    sum += 200000;
  else if (b == 3)
    sum += 100000;
  if (a == 1 && b == 1)
    sum += 400000;
  printf("%d",sum);
}

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
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
from heapq import heappop, heapify, heappush

def input(): return sys.stdin.readline().strip()
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 = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()
S = [input() for i in range(A)]

S.sort()
print(*S, sep="")

Measured memory_bytes: 5180
import java.util.*;

public class Main{
  public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] a = new long[N];
		for(int i = 0;i < N;i++) {
			long A = sc.nextLong();
			a[i] += A;
		}
			Arrays.parallelSort(a);		
			for(int j=0;j<N-1;j++) {
				if(a[j]-a[j+1]==0) {
					System.out.println("NO");
					return;
				}
			}
			System.out.println("YES");
	}
}

Measured memory_bytes: 61416
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x;cin>>x;
    ll p,a=0,b=0,ans,flag=0,c,aans;
    for(ll i=0;(ll)i*i*i*i*i<=1e18;++i)
    {
        ll k=0;
        c=0;
        ans=(ll)i*i*i*i*i-x;
        if(ans==0)
        {
            a=i;
            b=0;
            break;
        }
        if(ans==1)
        {
            a=i;
            b=1;
            break;
        }

        if(ans<0)
        {
            flag=1;
        }
        aans=abs(ans);
        p=pow(aans,0.2);
        while(aans>1 && aans%p==0 && k<100)
        {
            aans/=p;
            c++;
            k++;
            //cout<<"here\n";
        }
        if(aans<=1 && c==5 )
        {
            a=i;
            if(flag==0)
                b=p;
            else
                b=-p;
            break;
        }
        flag=0;
    }
    cout<<a<<" "<<b;
    return 0;
}

Measured memory_bytes: 4116
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    int solve(int n, int K) {
        const long long MOD = 1000000007;

        vector<int> X;
        for (int i = 1; i * i <= n; ++i) {
            X.push_back(i);
            if (i * i < n) {
                X.push_back(n / i);
            }
        }
        X.push_back(0);
        sort(X.begin(), X.end());
        X.erase(unique(X.begin(), X.end()), X.end());

        int N = X.size();
        vector<long long> dp(N, 1);
        dp[0] = 0;
        vector<long long> ndp(dp);

        for (int _ = 0; _ < K; ++_) {
            fill(ndp.begin(), ndp.end(), 0);

            for (int i = 1, j = N - 1; i < N; ++i) {
                while (j >= 1 && X[i] * 1LL * X[j] > n) {
                    --j;
                }
                long long cnt = X[i] - X[i - 1];
                ndp[i] = dp[j] * cnt % MOD;
                (ndp[i] += ndp[i - 1]) %= MOD;
            }
            swap(ndp, dp);
        }

        return dp[N - 1];
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;

    Solution sol;
    cout << sol.solve(n, k) << "\n";

    return 0;
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  string s;
  cin >> s;

  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j <= s.size() - i; j++) {
      string tmp = s;
      tmp.erase(i, j);
      if (tmp == "keyence") {
        cout << "YES" << endl;
        return 0;
      }
    }
  }

  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
mid_e = int(len(s) / 2)
if len(s) % 2 == 0:
    mid_s = mid_e - 1
else:
    mid_s = mid_e
first = s[:mid_e]
second = s[len(s):mid_s:-1]
count = 0
for i in range(len(first)):
    if first[i] != second[i]:
        count += 1
print(count)

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

using namespace std;

typedef long long ll;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a;
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        if (a.empty() || a.back() != t) {
            a.push_back(t);
        }
    }
    n = a.size();
    a.push_back(0);
    int ans = 1;
    int k = 1;
    if (a[1] < a[0]) {
        k = -1;
    }
    for (int i = 1; i + 1 < n; ++i) {
        if (k * a[i] > k * a[i + 1]) {
            if (a[i + 2] > a[i + 1]) {
                k = 1;
            } else {
                k = -1;
            }
            ++ans;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 892
N = int(input())
prices = list(map(int, input().split()))

# 所持金
money = 1000
# 保持株数
num_of_stocks = 0
for i in range(N):
    # 最終日に持っていれば売る
    if i == N - 1:
        if num_of_stocks > 0:
            money = money + num_of_stocks * prices[i]
    else:
        # i+1日目がi日より高ければ
        if prices[i] < prices[i+1]:
            if money >= prices[i]:
                # 買えるだけ買う
                num_of_stocks =  money // prices[i]
                money = money - num_of_stocks * prices[i]
        # i+1日目がi日より低ければ
        else:
            # 株を持っていたら売る
            if num_of_stocks > 0:
                money = money + num_of_stocks * prices[i]
                num_of_stocks = 0

print(money)

Measured memory_bytes: 9000
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(3*N);
    rep(i,3*N) cin >> A[i];
    sort(ALL(A));
    reverse(ALL(A));
    ll ans = 0;
    rrep(i,N){
        ans += A[i*2+1];
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
a, b, c, d = map(int,input().split())
if (b <= 0):
    if (d <= 0):
        print(a*c)
    elif (c >= 0):
        print(b*c)
    else:
        print(a*c)
elif (a >= 0):
    if (d <= 0):
        print(a*d)
    elif (c >= 0):
        print(b*d)
    else:
        print(b*d)
else:
    if (d <= 0):
        print(a*c)
    elif (c >= 0):
        print(b*d)
    else:
        x = a*c
        y = b*d
        print(max(x, y))


Measured memory_bytes: 9192
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] A = new int[N];
		int[] B = new int[N];
		int[] C = new int[N-1];
		for (int i=0;i<N;i++) {
			A[i] = Integer.parseInt(sc.next());
		}
		for (int i=0;i<N;i++) {
			B[i] = Integer.parseInt(sc.next());
		}
		for (int i=0;i<N-1;i++) {
			C[i] = Integer.parseInt(sc.next());
		}
		int ans = 0;
		int before = -10;
		for (int i=0;i<N;i++) {
			int index = A[i]-1;
			ans += B[index];
			if (before+1 == index) {
				ans += C[before];
			}
			before = index;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
constexpr int mod = 1000000007;
using namespace std;
int d, c[30], l[30], s[400][30];
signed main() {
	cin >> d;
	for1(i, 26)cin >> c[i];
	for1(i, d)for1(j, 26)cin >> s[i][j];
	for1(i, d) {
		int p = 0, k = -mod;
		for1(j, 26) {
			int kj = s[i][j] + c[j] * (i - l[j]) * 1.50;
			if (kj > k) { p = j; k = kj; }
			else if (kj == k && c[j] > c[p])p = j;
		}
		puts(p); l[p] = i;
	}
}

Measured memory_bytes: 3680
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    map<int, int> list;

    int num = a;
    while (true)
    {
        if (num % b == c)
        {
            cout << "YES" << endl;
            return 0;
        }
        if (!list.count(num % b))
        {
            list[num % b] = 0;
        }
        else
        {
            cout << "NO" << endl;
            return 0;
        }
        num += a;
    }
}


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

int main(){
  int h,w,d;
  cin >> h >> w >> d;

  map<int,pair<int,int>> mp;
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      int a;
      cin >> a;
      mp[a] = make_pair(i,j);
    }    
  }

  vector<int> dis(h*w+5);
  for (int i = 1; i < h*w+5; i++)
  {
    if(i>d){
      dis[i]=dis[i-d]+abs(mp[i].first-mp[i-d].first) + abs(mp[i].second-mp[i-d].second);
    }
  }  

  int q;
  cin >> q;
  for (int i = 0; i < q; i++)
  {
    int l,r;
    cin >> l >> r;
    int ans = dis[r]-dis[l];
    cout << ans << endl;
  }
}

Measured memory_bytes: 7040
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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



///////////////////////////


int main() {
	ll H;
	ll A;
	cin >> H >> A;
	cout << (H - 1) / A + 1;
	
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long K = sc.nextLong();
 
        long t = A;
        long a = B;
 
        if((A+B)<=K){
            t=0;
            a=0;
        }else if(A > K){
            t -= K;
        }else{
            t=0;
            a -= (K-A);
        }
 
        System.out.println(t);
        System.out.println(a);
    }
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define filename "lynext"
#define freop freopen(filename ".cik","w",stdout);freopen(filename ".gir","r",stdin)
const long long int N = ((long long int)1e3) + 5;
const long long int M = ((long long int)1e3) + 5;
const long long int llinf = (long long int)1e18;
const int inf = INT_MAX;
typedef long long int lli;

lli n, w;
lli cost[N];
lli wei[N];
lli dp[N][(lli)1e5 + 5];
lli ans = INT_MIN;

lli f (lli x, lli val)
{
	if (x == n + 1)
	{
		if (val != 0)
			return llinf;
		return 0;
	}
	if (dp[x][val] != -1)
		return dp[x][val];
	lli t1 = f(x + 1, val);
	lli t2 = f(x + 1, val - cost[x]) + wei[x];
	return dp[x][val] = min(t1,t2);
}

int main ()
{
	fast;
	//freop;
	cin >> n >> w;
	for (lli i = 1; i <= n; i++)
	{
		cin >> wei[i] >> cost[i];
	}
	memset(dp, -1, sizeof dp);
	for (lli i = (lli)1e5; i >= 0; i--)
	{
		lli wi = f(1,i);
		if (wi <= w)
			return cout << i << "\n",0;
	}
	//cout << ans << "\n";
}


Measured memory_bytes: 785536
def abc167_d():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    base, cycle = 0, 0
    order = [-1] * N
    order[0] = 0
    cnt = 1
    idx = A[0] - 1
    while True:
        if order[idx] == -1:
            order[idx] = cnt
            cnt += 1
            idx = A[idx] - 1
            continue
        base = order[idx]
        cycle = cnt - order[idx]
        break

    if base + cycle <= K:
        rest = (K - base) % cycle
        ans = order.index(base + rest) + 1
    else:
        ans = order.index(K) + 1
    print(ans)

abc167_d()

Measured memory_bytes: 32384
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
  int k,a,b,n1,n2;
  cin>>k>>a>>b;
  n1=(int)ceil(1.0*a/k);
  n2=(int)floor(1.0*b/k);
  if(n2>=n1) cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
  return 0;
}


Measured memory_bytes: 3596
def main():
    N = int(input())

    if N == int(int(N/1.08) * 1.08):
        print(int(N/1.08))
    elif N == int((int(N/1.08) - 1) * 1.08):
        print(int(N / 1.08) - 1)
    elif N == int((int(N/1.08) + 1) * 1.08):
        print(int(N / 1.08) + 1)
    else:
        print(":(")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import scala.math._

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val s = sc.next

  val ans = if (s.sliding(3).exists(_.distinct.length == 1)) "Yes" else "No"

  println(ans)

  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

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

int main()
{
	int n,l;
	cin>>n>>l;
	int sum=0;
	int min,max;
	min=l;
	max=l+(n-1);
	
	for(int i=l;i<=l+(n-1);i++){
		sum=sum+i;
	}

	if(min<=0 && max<=0)
		{
			sum=sum-max;
			cout<<sum;
		}
		else if(min>=0 && max>=0)
		{
			sum=sum-min;
			cout<<sum;
		}
		else if(min<=0 && max>=0)
		{
			cout<<sum;
		}

}



Measured memory_bytes: 256
line = input()

chars = list(map(int, line))

result = 0

for char_i in range(1, len(chars)):
  pre_char = chars[char_i-1]
  char = chars[char_i]
  
  if char == pre_char:
    result = 1
    
if result == 0:
  print("Good")
else:
  print("Bad")
  



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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  ll N, A, B;
  cin >> N >> A >> B;
  ll ans = 0;
  if (A <= B) {
    if (N == 1) {
      if (A == B) {
        ans = 1;
      }
    } else {
      ll n2 = N - 2;
      ans = B * n2 - A * n2 + 1;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500 * i + 100 * j + 50 * k == x:
                cnt += 1

print(cnt)


Measured memory_bytes: 3060
#include <stdio.h>

int A[1000000], n;

/* 二分探索 */
int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while(left < right) {
    mid = (left + right) / 2;
    if(key == A[mid]) return 1; /* keyを発見 */
    if(key > A[mid]) left = mid + 1; /* 後半を探索 */
    else if(key < A[mid]) right = mid; /* 前半を探索 */
  }
  return 0;
}

int main(void) {
  int i, q, k, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&k);
    if(binarySearch(k))
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}


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

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

using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,s,id=1,wei=0,nid;
  cin>>n;s=n;
  vector<int>a(n),b;
  rep(i,n)cin>>a[i];
  map<int,int>ma;
  rep(i,n)ma[a[i]]++;
  for(auto tp:ma)b.push_back(tp.second);
  sort(all(b),greater<int>());
  rep(i,b.size())
  {
    nid=n/b[i]+1+wei;
    repi(j,id,nid)cout<<n/(j-wei)<<"\n";
    id=nid;
    n-=b[i];
    wei++;
  }
  repi(i,nid,s+1)cout<<0<<"\n";
  cout<<endl;
  return 0;
}


Measured memory_bytes: 17140
#include <bits/stdc++.h>
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;

string a[3];
int ans;

bool match(int f, int s, int off){
    for(int i = 0; i+off < a[f].size() and i < a[s].size(); i++){
        if(a[f][i+off] != '?' and a[s][i] != '?' and a[f][i+off] != a[s][i])
            return 0;
    }
    return 1;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>a[0]>>a[1]>>a[2];
    ans = a[0].size()+a[1].size()+a[2].size();
    sort(a, a+3);
    do{
        int n = a[0].size(), m = a[1].size(), l = a[2].size();
        for(int st = 0; st <= n; st++){
            if(!match(0, 1, st))
                continue;
            int ed = 0;
            while(!match(1, 2, ed) or !match(0, 2, st + ed)){
                ed++;
                int v = max(n, max(m+st, l+st+ed));
                if(v >= ans)
                    break;
            }
            ans = min(ans, max(n, max(m+st, l+st+ed)));
        }
    } while(next_permutation(a, a+3));
    
    cout<<ans<<'\n';
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*; 
import java.lang.*; 

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int N = scan.nextInt();
                int K = scan.nextInt();
                
                long[] cnt = new long[N+1];
                long ans = 0;
                
                long[] p = new long[N+1];
                long[] q = new long[N+1];
                
                p[0]=0;
                q[0]=N;
                cnt[0]=q[0]-p[0]+1;
                
                for(int i=1; i<=N; i++){
                      p[i] = p[i-1] + i;
                      q[i] = q[i-1] + N-i;
                      cnt[i] = q[i]-p[i]+1;
                }
                
                for(int i=K-1; i<=N; i++){
                ans = ans + cnt[i];
                }
               ans = Math.floorMod(ans,(10*10*10*10*10*10*10*10*10)+7);
                
                System.out.println(ans);
                
	}
}

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

//#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using pii = pair<int, int>; using vi = vector<int>;
static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
static const int MOD = (int)(1e9 + 7);

using Weight = int;
class Edge {
public:
	int s; //source
	int d; //destination
	Weight w; //weight
	Edge(int s = 0, int d = 0, Weight w = INF) : s(s), d(d), w(w) {};
	bool operator<(const Edge &e)const { return w < e.w; }
};
using Edges = vector<Edge>;
//???????????\: g[u].push_back(Edge(u, v, c));
//????????¨???????????????????????°??????????????\?????????????????????
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

//?´?????????????????§????
//Union-Find??¨
struct UnionFind {
	vector<int> p; //parent
	int s; //size ???????????°
	UnionFind(int n) :p(n, -1), s(n) {}
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (size(x) < size(y)) swap(x, y);
		p[x] += p[y]; p[y] = x; s--;
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) { return p[x] < 0 ? x : p[x] = root(p[x]); }
	//?????????????´???°
	int size(int x) { return -p[root(x)]; }
};

//????°???¨?????¨
//Kruskal O(|E|log|E|)
pair<Weight, Edges> kruskal(const Graph &g) {
	UnionFind UF(g.size());
	Edges es;
	for (int i = 0; i < g.size(); i++) for (auto &e : g[i]) es.emplace_back(e);
	sort(es.begin(), es.end());
	Weight total = 0;
	Edges T;
	for (auto &e : es) if (!UF.same(e.s, e.d)) {
		T.push_back(e); total += e.w; UF.unite(e.s, e.d);
	}
	return make_pair(total, T);
}

signed main() {
	for (int n, m; cin >> n >> m&&n;) {
		Graph g(n);
		rep(i, 0, m) {
			int a, b, cost; cin >> a >> b >> cost;
			g[a].emplace_back(a, b, cost);
			g[b].emplace_back(b, a, cost);
		}
		auto k = kruskal(g);
		cout << k.first << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
const main = stdin => {
  const input = stdin.trim().split('\n')
  const tasks = input[0].split(' ').map(x => parseInt(x)).sort((a, b) => a - b)

  console.log(Math.abs(tasks[0] - tasks[1]) + Math.abs(tasks[1] - tasks[2]))
}


// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 29520
// cpp219 - the 712534
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define fs first
#define sc second
#define mp make_pair
using namespace std;
const ll base = 7;
const ll N = 2e3 + 9;
const ll mod = 1e9 + 7;
typedef pair<ll,ll> LL;

ll n,i,j;
LL a[N];
ll dp[N][N];
int main(){
    ios_base::sync_with_stdio(false);
   	cin.tie(0); cout.tie(0);
    //freopen("test.inp", "r", stdin);
    cin>>n;
    for (i=1;i<=n;i++){
        cin>>a[i].fs;
        a[i].sc = i;
    }
    sort(a + 1,a + n + 1);
    ll maxx = 0;
    for (i = n;i >= 1;i--){
        for (j = 1;j <= n - i + 1;j++){
            if (i == 1) maxx = max(maxx,dp[j][j] + a[i].fs * (abs(a[i].sc - j)));
            else{
                dp[j + 1][i + j - 1] = max(dp[j + 1][i + j - 1],dp[j][i + j - 1] + a[i].fs*(abs(a[i].sc - j)));
                dp[j][i + j - 2] = max(dp[j][i + j - 2],dp[j][i + j - 1] + a[i].fs*(abs(a[i].sc - (i + j - 1))));
            }
        }
    }
    cout<<maxx;
}


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","w",stdout);
    //FILE *fptr2=freopen("out.txt","w",stdout);


    string s;
    cin>>s;
    int a=0;
    for(auto ch:s)
    {
        a+=(ch-48);
    }
    if(a%9==0) cout<< "Yes";
    else cout<< "No";


    return 0;
}


Measured memory_bytes: 3748
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int diff=Math.abs(N-M);

		if(diff>=2) {
			System.out.println(0);
			return;
		}


		int mod=1000000000+7;

		long n=1;

		for (int i = 1; i <= N; i++) {

			n=(n*(i))%mod;

		}

		long m = 1;

		for (int i = 1; i <= M; i++) {

			m=(m*(i))%mod;

		}

		long ans=0;

		if(diff==0) {
			ans=(2*n*m)%mod;
		}else if(diff==1) {
			ans=(n*m)%mod;
		}

		System.out.println(ans);


	}

	//以下テンプレート

	public static String numtoalpha(int i) {

		String alpha = "abcdefghijklmnopqrstuvwxyz";

		return alpha.substring(i, i + 1);

	}

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

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

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define int long long
template <typename T, typename U>
istream &operator>>(istream &in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	const int MOD=1e9+7;
	int n;
	cin>>n;
	priority_queue<P,vector<P>,greater<P>> que;
	rep(i,n){
	    int x,l;
	    cin>>x>>l;
	    que.push({x+l,x-l});
	}
	int before=INT_MIN,ans=0;
	while(!que.empty()){
	    P it=que.top();que.pop();
	    if(it.second<before)continue;
	    ans++;
	    before=it.first;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2420
#include<iostream>
using namespace std;
string str;
int cnt=0;
int x;
int main(){
  while(cin>>str){
    x=0;
    for(int i=0;i<=(int)str.size();i++){
      if('0'<=str[i]&&str[i]<='9'){
    x=x*10+str[i]-'0';
      }else{
    cnt+=x;
    x=0;
      }
    }
  }
  cout<<cnt<<endl;
  return 0;
}


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

int main(){
  string S,T;
  
  cin >>S>>T;
  
  int ans =0;
  rep(i,0,3) if(S[i]==T[i]) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int n,r;
	scanf("%d",&n);
	r=(n-n%111)/111+1;
	if(n%111==0){
		printf("%d",n);
	}
	else{
		printf("%d%d%d",r,r,r);
	}
	return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, a[100000];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	LL x = 0, sum = 0;
	inc(i, n) {
		sum += a[i];
		if(i % 2 == 0) {
			if(sum <= 0) { x -= sum - 1; sum = +1; }
		} else {
			if(sum >= 0) { x += sum + 1; sum = -1; }
		}
	}
	LL ans = x;
	
	x = 0; sum = 0;
	inc(i, n) {
		sum += a[i];
		if(i % 2 != 0) {
			if(sum <= 0) { x -= sum - 1; sum = +1; }
		} else {
			if(sum >= 0) { x += sum + 1; sum = -1; }
		}
	}
	
	setmin(ans, x);
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
n,m=gets.split.map(&:to_i)
sp=[]
m.times{x=gets.chomp.split;sp<<[x[0].to_i,x[1]]}
i=0
sp.sort_by!{|a|[a[0],i+=1]}
i=p=q=r=0
c=false
sp.each{|a|
  if a[0]==i
    if c
    elsif a[1]=="WA"
      r+=1
    elsif a[1]=="AC"
      p+=r
      r=0
      q+=1
      c=true
    end
  else
    i=a[0]
    r=0
    c=false
    if a[1]=="WA"
      r+=1
    elsif a[1]=="AC"
      p+=r
      r=0
      q+=1
      c=true
    end
  end  
  }
puts "#{q} #{p}"


Measured memory_bytes: 22976
#include <iostream>
#include <algorithm>
#include <set>
#include <functional>
#include <list>
#include <bitset>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>

#define INF 1e9
#define MOD 1000000007
#define ll long long
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
typedef unsigned long long ull;
typedef pair<ll, int> pr;
//pr a[102001],b[120001];
//ll c[120001],d[120001];
pair<ll,pair<ll,ll>> e[100002];
bool f[102001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    fill(f,f+n,false);
    ll x,y;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        e[i]=make_pair(x+y,make_pair(x,y));
    }
    sort(e,e+n,greater<pair<ll,pair<ll,ll>>>());
    ll aa=0,bb=0;
    for(int i=0;i<n;i++){
        if(i%2==0){
            aa+=e[i].second.first;
        }
        else{
            bb+=e[i].second.second;
        }
    }
    cout<<aa-bb<<endl;
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MOD 1000000009

int main(){
    cin.sync_with_stdio(false);
    string s;
    cin >> s;

    if (s.size() < 4) {
        cout << "No" << endl;
    } else {
        if (s.substr(0, 4) == "YAKI") cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#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()
typedef long long lint;
 
int main() {
  string S;
  cin >> S;
  
  bool flag = false;
  rep(i,3){
    if(S.at(i)==S.at(i+1))flag=true;
  }
  if(flag)cout << "Bad" << endl;
  else cout << "Good" << endl;
}



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

class UnionFind {
	vector<int> v;
	vector<int> mini;
public:
	UnionFind(const vector<int>& val) : v(val.size(), -1), mini(val) {}
	int find(int a) {
		return v[a] < 0 ? a : v[a] = find(v[a]);
	}
	bool same(int a, int b) {
		return find(a) == find(b);
	}
	void unite(int a, int b) {
		a = find(a);
		b = find(b);
		if (a == b) return;
		if (v[a] < v[b]) {
			mini[a] = min(mini[a], mini[b]);
			v[a] += v[b];
			v[b] = a;
		}
		else {
			mini[b] = min(mini[a], mini[b]);
			v[b] += v[a];
			v[a] = b;
		}
	}
	int get(int a) {
		return mini[find(a)];
	}
	int size(int a) {
		return -v[find(a)];
	}
};

int main()
{
	int n;
	cin >> n;
	vector<int> w(n);
	int mini = 1e4 + 1;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		mini = min(mini, w[i]);
	}
	auto a = w;
	sort(a.begin(), a.end());
	UnionFind uf(w);
	for (int i = 0; i < n; i++) {
		int it = lower_bound(a.begin(), a.end(), w[i]) - a.begin();
		uf.unite(i, it);
	}
	int res = 0;
	vector<int> rts;
	for (int i = 0; i < n; i++) {
		res += w[i] + (uf.get(i) == w[i] ? -w[i] : uf.get(i));
		if (i == uf.find(i)) rts.push_back(i);
	}
	for (auto rt : rts) {
		if (uf.get(rt) == mini) continue;
		int dis = (uf.get(rt) - mini) * (uf.size(rt) - 1) - (uf.get(rt) + mini) * 2;
		if (dis > 0) {
			res -= dis;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
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;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

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

ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k, ans = 0;
    cin >> k;
    for(ll a = 1; a <= k; a++) {
        for(ll b = 1; b <= k; b++) {
            for(ll c = 1; c <= k; c++) {
                ll tmp = GCD(a, b);
                tmp = GCD(tmp, c);
                ans += tmp;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3652
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  for (;;) {
    int a, b;
    cin >> a >> b;
    if (a == 0) break;

    int sum = b - a;

    int n10 = sum / 1000;
    sum = sum % 1000;

    int n5 = sum / 500;
    sum = sum % 500;

    int n1 = sum / 100;

    printf("%d %d %d\n", n1, n5, n10);
  }

  return 0;
}

Measured memory_bytes: 1144
import math
a,b,x = map(int,input().split())
y = (a*a*b - x)*2/(a*a)
if y <= b:
  print(math.degrees(math.atan(y/a)))
else:
  y = (2*x)/(a*b)
  print(90-math.degrees(math.atan(y/b)))



Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
struct UnionFind{
  vector<int> r;
  UnionFind(int n){
    r=vector<int>(n,-1);
  }
  int root(int a){
    if(r[a]<0) return a;
    else return r[a]=root(r[a]);
  }
  void unite(int a,int b){
    a=root(a);
    b=root(b);
    if(a==b) return;
    else if(a>b) swap(a,b);
    r[a]+=r[b];
    r[b]=a;
  }
  int size(int a){
    return -r[root(a)]-1;
  }
};
int main(void){
  int x,y,n,m,k; cin>>n>>m>>k;
  UnionFind UF(n);
  vector<vector<int>> f(n,vector<int>(0)),b(n,vector<int>(0));
  for(int i=0; i<m; ++i){ cin>>x>>y; f[--x].push_back(--y),f[y].push_back(x); UF.unite(x,y);}
  for(int i=0; i<k; ++i){ cin>>x>>y; b[--x].push_back(--y),b[y].push_back(x);}
  int res=0;
  for(int i=0; i<n; ++i){
    res=UF.size(i)-f[i].size();
    for(int j=0; j<b[i].size(); ++j) if(UF.root(b[i][j])==UF.root(i)) --res;
    printf("%d ",res);
  }
  return 0;
}

Measured memory_bytes: 14496
#include <iostream>
#include <cstdio>

using namespace std;


class Solution{

public:
    int area(int a, int b, int h){
        return (a + b) * h / 2;
    }
};

int main() {
    
    int a, b, h;
    scanf("%d%d%d", &a, &b, &h);
    printf("%d\n", Solution().area(a, b, h));
    
    return 0;
}


Measured memory_bytes: 3224