akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int a, b, c, x, y;
long long ans;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> a >> b >> c >> x >> y;
    int cost1 = 2*c;
    if(cost1<a+b) {
        while(x>0 && y>0) {
            ans += cost1;
            x--; y--;
        }
        while(x>0) {
            if(cost1<a) {
                ans += cost1;
            } else {
                ans += a;
            }
            x--;
        }
        while(y>0) {
            if(cost1<b) {
                ans += cost1;
            } else {
                ans += b;
            }
            y--;
        }
    } else {
        cout << (long long)a*x + b*y << endl;
        return 0;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int n,a[105],b[105];cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	int temp = 0,maks=0;
	for(int i=0;i<n-1;i++){
		if(a[i]!=b[i]){
			temp = 0;
			continue;
		}
		else{
			if(a[i+1]==b[i+1]){
				temp++;
				maks = max(temp,maks);
			}
			else{
				temp =0;
			}
		}
	}
	if(maks>=2)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<climits>
using namespace std;

class Node{
public:
    int parent, rank, weight;
    Node(int id): parent(id), rank(0), weight(0){}
};

int find(vector<Node>& nodes, const int& x){
    if(nodes[x].parent != x){
        int new_parent = find(nodes, nodes[x].parent);
        if(new_parent != nodes[x].parent){
            nodes[x].weight += nodes[nodes[x].parent].weight;
        }
        nodes[x].parent = new_parent;
    }
    return nodes[x].parent;
}
void unite(vector<Node>& nodes, const int& x, const int& y, const int& z){
    int px = find(nodes, x), py = find(nodes, y);
    int pz = nodes[y].weight - nodes[x].weight + z;
    if(nodes[px].rank < nodes[py].rank){
        nodes[px].parent = py;
        nodes[px].weight = pz;
    }
    else if(nodes[py].rank < nodes[px].rank){
        nodes[py].parent = px;
        nodes[py].weight = -pz;
    }
    else{
        nodes[py].rank++;
        nodes[px].parent = py;
        nodes[px].weight = pz;
    }
}
int main(){
    int n, q, c, x, y, z; 
    cin >> n >> q;
    vector<Node> nodes;
    for(int i = 0; i < n; i++){
        nodes.push_back(Node(i));
    }
    for(int i = 0; i < q; i++){
        cin >> c;
        if(c == 0){
            cin >> x >> y >> z;
            unite(nodes, x, y, z);
        }
        else{
            cin >> x >> y;
            int px = find(nodes, x), py = find(nodes, y);
            if(px != py) cout << "?" << endl;
            else{
                cout << nodes[x].weight - nodes[y].weight << endl;
            }
        }
    }
}



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

#define ll long long
#define pb push_back
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fr freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define mp make_pair
#define F first
#define S second

using namespace std;

const int N = 5e5 + 2;
const int mod = 1e9 + 7;

int n;
int a[N];
int m[N];
int main () {
	speed;
	int c=0;
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	m[0]=a[0];
	for (int i=1;i<n;i++){
		if (a[i]<m[i-1]){
			m[i]=a[i];
		}
		else {
			m[i]=m[i-1];
		}
	}
	for (int i=0;i<n-1;i++){
		if (m[i]!=m[i+1]){
			c++;
		}
	}
	cout<<c+1;
}



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

int p[100010],y[100010];
int idx[100010];
int cmp(const void*a,const void*b){
	if(p[*(int*)a]<p[*(int*)b])return -1;
	if(p[*(int*)a]>p[*(int*)b])return  1;
	if(y[*(int*)a]<y[*(int*)b])return -1;
	return 1;
}

long long ans[100010];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",p+i,y+i);
		idx[i]=i;
	}
	qsort(idx,m,sizeof(int),cmp);
	int pre=-1,cnt=0;
	for(int i=0;i<m;i++){
		if(pre==p[idx[i]])cnt++;
		else{
			pre=p[idx[i]];
			cnt=1;
		}
		ans[idx[i]]=p[idx[i]]*1000000LL+cnt;
	}
	for(int i=0;i<m;i++)printf("%012lld\n",ans[i]);
}

Measured memory_bytes: 3444
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
        
      String s[] = new String[N];
      for(int i=0; i<N; i++){
          s[i] =sc.next();//入力されるsが入る箱
      }
      Arrays.sort(s);
        int a =1;
        for(int j=0; j<N-1; j++){
            if(!s[j].equals(s[j+1])){
                 a++;
            }
        }
        System.out.println(a);
      }
}
     
      

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


int main() {
	int n, m, lx, ly;
	int x[110], y[110];

	cin >> n >> m >> lx >> ly;
	for (int i = 0; i < n; i++) cin >> x[i];
	for (int i = 0; i < m; i++) cin >> y[i];
	bool flag = true;
	for (int z = lx + 1; z <= ly; z++) {
		flag = true;
		for (int i = 0; (i < n) && flag; i++) {
			for (int j = 0; (j < m) && flag; j++) {
				if (!(x[i] < z && y[j] >= z)) {
					flag = false;
				}
			}
		}
		if (flag) {
			cout << "No War" << endl;
			return 0;
		}
	}
	cout << "War" << endl;
	return 0;
}


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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec[i];
  }
  
  int alice = 0,bob = 0;
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  for(int i=0;i<n;i++){ 
    if(i&1){
      bob+=vec.at(i);
    }else{
      alice+=vec.at(i);
    }
  }
  
  cout << alice-bob << endl;
  
}

Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        int N = scan.nextInt();
        int K = scan.nextInt();
        int[] arr = new int[N];
        for (int i=0;i<N;i++) arr[i] = scan.nextInt();
        Task tsk = new Task();
        System.out.println(tsk.solve(K-1, arr));
    }

    static class Task{
        public int solve(int k, int[] arr){
            int min = Integer.MAX_VALUE;
            for (int i=0;i+k<arr.length;i++) {
                int time = Math.min(Math.abs(arr[i]), Math.abs(arr[i+k]))
                        + Math.abs(arr[i] - arr[i+k]);
                min = Math.min(min, time);
            }
            return min;
        }
    }
}


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N;
    ll count = 0;
    vector<set<ll>> A;
    cin >> N;
    A.resize(N);
    for(ll i = 0;i < N;i++) {
        ll temp;
        cin >> temp;
        A[i].insert(temp - 1);
    }
    for(ll i = 0;i < N;i++) {
        for(auto &j: A[i]) {
            if(i < j && A[j].find(i) != A[j].end()) count++;
        }
    }
    cout << count << endl;
    return 0;
}


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

int main() 
{
  int a[4];
  int b[4];
  int brow, hit;
  while(cin>> a[0] >> a[1] >> a[2] >>a[3] >> b[0] >> b[1] >> b[2] >> b[3])
  {
    hit = brow = 0;
    for(int i = 0; i < 4; i++)
    {
      for(int j = 0; j < 4; j++)
      {
        if(a[i] == b[j])
        {
          brow++;
          break;
        }
      }
    }
    for(int i = 0; i < 4; i++)
    {
      if(a[i] == b[i])
      {
        hit++;
      }
    }
    cout << hit << " " << brow - hit << endl;
  }
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  int alp[26];
  int two = 0;
  for ( int i = 0; i < 26; i++ ) { alp[i] = 0; }
  for ( int i = 0; i < 4; i++ ) {
    int t = s[i]-'A';
    alp[t]++;
    if ( alp[t] == 2 ) { two++; }
  }
  string ans = ( two == 2 ) ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.stream.*;

class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int k = saori.saori_hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		for(int i = a;i <= b;i++){
			if(i % k == 0){
				System.out.println("OK");
				return;
			}
		}
		System.out.println("NG");
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n,l;
    while(cin >> n >> l) {
        vector<int> v(n);
        for(int i = 0; i < n; i++) {
            cin >> v[i];
        }
        int pos = -1;
        for(int i = 0; i < n-1 && pos == -1; i++) {
            if(v[i]+v[i+1] >= l) {
                pos = i;
            }
        }
        if(pos == -1) {
            cout << "Impossible" << '\n';
            continue;
        }
        cout << "Possible" << '\n';
        for(int i = 1; i <= pos; i++) {
            cout << i << '\n';
        }
        for(int i = n-1; i > pos+1; i--) {
            cout << i << '\n';
        }
        cout << pos+1 << '\n';
    }
    return 0;
}

Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main{ // 

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	static long now() {
		return System.currentTimeMillis();
	}

	static void trace(Object... objects) {
		assert null != System.out.format("trace:%s\n", Arrays.deepToString(objects));
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		// assert solve(1) == 1;

		int a = cin.nextInt();
		int b = cin.nextInt();

		long start = now();

		String ans = solve(a, b);
		cout.println(ans);

		trace("elapsed", now() - start);
	}

	private static String solve(int a, int b) {
		boolean ans = a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0;
		if (ans)
			return "Possible";
		return "Impossible";
	}

	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  cin >> s;
  int s1 = s/100;
  int s2 = (s - s1*100)/10;
  int s3 = s - s1*100 - s2*10;
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from operator import itemgetter
# gcd
# from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
# from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# fin = open('in_2.txt', 'r')
# sys.stdin = fin
# 提出時はコメントアウト+上のshebangを有効にする
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template

MOD = 1000000007  # type: int

def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word

if __name__ == '__main__':

    tokens = iterate_tokens()
    L = list(map(int, list(next(tokens))))  # type: int
    
    # print(L)
    # write code
    dp = [[0, 0] for _ in range(100005)]
    dp[0][0] = 1
    # 桁dpをする
    # dp[i][0]……i桁目までみて一致する個数
    # dp[i][0]……i桁目までみて真に小さい個数
    for i in range(len(L)):
        # a+b = 0の数
        if L[i] == 0:
            dp[i + 1][0] += dp[i][0]
            dp[i + 1][1] += dp[i][1]
        else:
            dp[i+1][1] += dp[i][0] + dp[i][1]
        # a+b = 1の数
        if L[i] == 0:
            dp[i + 1][1] += dp[i][1] * 2
        else:
            dp[i + 1][0] += dp[i][0] * 2
            dp[i + 1][1] += dp[i][1] * 2
        dp[i + 1][0] %= MOD
        dp[i + 1][1] %= MOD
    print((dp[len(L)][0]+dp[len(L)][1])%MOD)
        


Measured memory_bytes: 21044
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 

struct Line{
	int h,p,q;
	Line(int h,int p,int q): h(h),p(p),q(q){}
	bool operator < (Line l){
		return h>l.h;
	}
	void write(){cout<<h<<" "<<p<<" "<<q<<endl;}
};

bool cmp(Line a,Line b){
	return a<b;
}

int main(){
	int n,m,a;
	while(cin>>n>>m>>a){
		if(n==0 && m==0 && a==0) break;
		vector<Line> v;
		int h,p,q;
		int maxH=0;
		rep(i,m){
			cin>>h>>p>>q;
			v.pb(Line(h,p,q));
			maxH=max(maxH,h);
		}
		sort(all(v),cmp);

		// cout<<a<<endl;
		// rep(i,m) v[i].write();

		int idx=0;

		for(h=maxH; h>=0; h--){
			while(v[idx].h>=h){
				if(v[idx].h==h){
					if(v[idx].p==a) a=v[idx].q;
					else if(v[idx].q==a) a=v[idx].p;
					//cout<<idx<<" "<<a<<endl;
				}
				idx++;
				if(idx>=m) break;
			}
			if(idx>=m) break;
		}

		cout<<a<<endl;
	}

}

Measured memory_bytes: 1224
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
string S, T;

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

  cin >> S >> T;
  int cnt = 0;
  rep(i, 3){
    cnt += S[i] == T[i]?1:0;
  }

  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 764
import bisect

N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())

list.sort(A), list.sort(B), list.sort(C)

ans = 0

for b in B:
    a = bisect.bisect_left(A, b)
    c = len(C) - bisect.bisect_right(C, b)
    ans += a * c

print(ans)

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

int par[100005];
ll rank_[100005];
void init(int n){
  for(int i=0; i<n; i++){
    par[i] = i;
    rank_[i] = 1;
  }
}

int find(int x){
  if(x==par[x]){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

ll unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x==y) return 0;
  ll tmp = rank_[x]*rank_[y];
  if(rank_[x]<rank_[y]){
    par[x]=y;
    rank_[y] += rank_[x];
    rank_[x] = rank_[y];
    return tmp;
  }else{
    par[y]=x;
    rank_[y] += rank_[x];
    rank_[x] = rank_[y];
    return tmp;
  }
}

bool same(int x, int y){
  return find(x)==find(y);
}

 
int main(){
  int n, m, c;
  cin >> n >> m >> c;
  int b[m];
  int ans = 0;
  for(int i=0; i<m; i++) cin >> b[i];
  for(int i=0; i<n; i++){
    int tmp = c;
    for(int j=0; j<m; j++){
      int a;
      cin >> a;
      tmp += a*b[j];
    }
    if(tmp>0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
using namespace std;
typedef long long LL;

LL f(LL n) {
  switch (n%4) {
    case 0:
      return n;  // 0 ^ 1 ^ .. n-1 ^ n -> (1^1)^(1^1)^...^(1^1)^n = n
    case 1:
      return 1;  // 0 ^ 1 ^ .. n-1 ^ n -> (1^1)^(1^1)^...^(1^1)^((n-1)^n} = 1
    case 2:
      return n^1;  // 0 ^ 1 ^ .. n-1 ^ n -> (1^1)^(1^1)^...^1^n} = 1^n
    case 3:
      return 0;  // 0 ^ 1 ^ .. n-1 ^ n -> (1^1)^(1^1)^...^(1^1) = 0
  }
}

int main() {
  LL A, B; cin >> A >> B;
  cout << (f(A-1)^f(B)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  
  string s; cin >> s;
  if(s[s.size() - 1] == '3'){cout << "bon" << endl; return 0;}
  if(s[s.size() - 1] == '0' || s[s.size() - 1] == '1' || s[s.size() - 1] == '6' || s[s.size() - 1] == '8'){
  cout << "pon" << endl; 
  }
  else{cout << "hon" << endl;}

    return 0;
}

Measured memory_bytes: 3612
#include <cctype>
#include <string>
#include <iostream>
using namespace std;
string s, t; int n;
int main() {
	cin >> s;
	for(int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);
	while(cin >> t) {
		for(int i = 0; i < t.size(); i++) t[i] = tolower(t[i]);
		if(s == t) n++;
	}
	printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 3332
// う　し　た　ぷ　に　き　あ　く　ん　笑
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int n, d, x;
    cin >> n >> d >> x;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    int eat = 0;
    for (auto &&i : a) {
        eat += (d - 1) / i + 1;
    }

    cout << eat + x << endl;
}


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

using namespace std;

#define ll long long
#define pb push_back

const int mod = 1e9 + 7;
const int INF = 1e9;
const int N = 1e7 + 5;

int main(){
	ll n;
	cin >> n;
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		ll t = n / i;
		ans += ((t * (t + 1)) / 2 * i);
	}	
	cout << ans << endl;
}

Measured memory_bytes: 3644
N, K = map(int, input().split())
list1 = []
if N <= abs(N - K):
  print(N)
  exit()
else:
  N = N % K
  while N > abs(N-K):
    N = abs(N - K)
    list1.append(N)
  
if list1 ==[]:
  print(0)
else:
  print(min(list1))

Measured memory_bytes: 9124
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        // 入力
        Scanner sc = new Scanner(System.in);
        int A1 = sc.nextInt();
        int A2 = sc.nextInt();
        int A3 = sc.nextInt();
        sc.close();

        String r = "bust";
        if(A1+A2+A3<22){
            r = "win";
        }
        System.out.println(r);
    }
}

Measured memory_bytes: 21844
N, M = map(int, input().split())
s_list = list(map(int, input().split()))
t_list = list(map(int, input().split()))

mod = 10 ** 9 + 7


def solve(x, y):
    dp = [[0 for _ in range(M + 1)] for _ in range(N + 1)]
    for i in range(1, N + 1):
        for j in range(1, M + 1):
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]
            dp[i][j] %= mod
            if x[i - 1] == y[j - 1]:
                dp[i][j] += dp[i - 1][j - 1] + 1
                dp[i][j] %= mod
    return dp


ans = solve(s_list, t_list)
print((ans[N][M] + 1) % mod)


Measured memory_bytes: 73948
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, a[2][100], max = -1;
	cin >> n;
	REP(i, 2){
		REP(j, n) cin >> a[i][j];
	}

	REP(i, n){
		int cnt = 0;
		REP(j, n){
			if(i > j) cnt += a[0][j];
			elif(i == j) cnt += a[0][j] + a[1][j];
			else cnt += a[1][j];
		}
		if(max < cnt) max = cnt;
	}
	cout << max << endl;

	rtn 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long double a,b,c;
  long double A,B,C,sum;
  cin >> a >> b >> c;
  A = sqrt(a);
  B = sqrt(b);
  sum = a + 2 * A * B + b;
  if(sum < c){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.PriorityQueue
import kotlin.comparisons.compareByDescending
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfLong()
    //前半
    val first = fun(): LongArray {
    	val array = LongArray(N + 1)
    	val fQ = PriorityQueue<Long>(N)
    	fQ.addAll(A.subList(0, N))
    	var fS = fQ.toList().sum()
    	for (n in 0 .. N) {
        	array[n] = fS
        	fS += A[N + n]
        	fQ.add(A[N + n])
        	fS -= fQ.poll()!! //一番小さい引く
    	}
    	return array
	}()
    //後半
    val latter = fun(): LongArray {
	    val array = LongArray(N + 1)
    	val lQ = PriorityQueue<Long>(N, compareByDescending { it })
    	lQ.addAll(A.subList(2 * N, 3 * N))
    	var lS = lQ.toList().sum()
    	for (n in 0 .. N) {
        	array[N - n] = lS
        	lS += A[2 * N - n - 1]
        	lQ.add(A[2 * N - n - 1])
        	lS -= lQ.poll()!! // 一番大きい引く
    	}
    	return array
    }()
    var ans = (0 .. N).map { first[it] - latter[it] }.max()!!
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }
fun listOfLong(offset: Long = 0L) = listOfString().map { it.toLong() + offset}


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

int main() {

	int n, t[52], f;
	char s[52], suit[4] = { 'S','H','C','D' };

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> s[i] >> t[i];
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 1; j <= 13; j++) {
			f = 1;
			for (int k = 0; k < n; k++) {
				if (s[k] == suit[i] && t[k] == j) {
					f = 0;
				}
			}
			if (f == 1) {
				cout << suit[i] << " " << j << "\n";
			}
		}
	}
	

	return 0;
}

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

const int N = 2005;
int n, size[N], tot[N], dp[N];
vector<int> g[N];
char s[N];

void dfs(int u, int fa) {
	size[u] = s[u] - '0', tot[u] = 0;
	int sum = 0, sum_dp = 0;
	vector<pair<int, int>> a;
	for (int v : g[u])
		if (v != fa) {
			dfs(v, u);
			size[u] += size[v];
			tot[v] += size[v];
			tot[u] += tot[v];
			sum += tot[v] - 2 * dp[v];
			sum_dp += dp[v];
			a.emplace_back(tot[v], dp[v]);
		}
	if (a.empty())  {
		dp[u] = 0;
		return;
	}
	vector<int> pre(a.size()), suf(a.size());
	pre[0] = a[0].first - 2 * a[0].second;
	for (int i = 1; i < (int)a.size(); ++i)
		pre[i] = max(pre[i - 1], a[i].first - 2 * a[i].second);
	suf.back() = a.back().first - 2 * a.back().second;
	for (int i = (int)a.size() - 2; i >= 0; --i)
		suf[i] = max(suf[i + 1], a[i].first - 2 * a[i].second);
	dp[u] = 0;
	for (int i = 0; i < (int)a.size(); ++i) {
		int mx = max(!i ? 0 : pre[i - 1], i + 1 == (int)a.size() ? 0 : suf[i + 1]);
		if (a[i].first < mx) continue;
		int x = sum + 2 * a[i].second;
		if (2 * a[i].second >= 2 * a[i].first - x) {
			dp[u] = tot[u] / 2;
			break;
		}
		dp[u] = max(dp[u], sum_dp + min(a[i].first - 2 * a[i].second, sum - (a[i].first - 2 * a[i].second)));
	}
}

int main() {
	scanf("%d%s", &n, s + 1);
	for (int i = 1, u, v; i < n; ++i) {
		scanf("%d%d", &u, &v);
		g[u].push_back(v), g[v].push_back(u);
	}
	int ans = 1 << 30;
	for (int rt = 1; rt <= n; ++rt) {
		dfs(rt, 0);
		if (dp[rt] * 2 == tot[rt])
			ans = min(ans, dp[rt]);
	}
	if (ans == (1 << 30)) puts("-1");
	else printf("%d\n", ans);
	return 0;
}


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

int main(int argc, char const *argv[]) {
    int N;cin>>N;
    stack<int> stk;
    while(N){
        stk.push(10 - (N%10));
        N/=10;
    }
    while(!stk.empty()){
        cout << stk.top();
        stk.pop();
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
#coding:utf-8

i = input()
q = []
for n in range(i):
    l = map(int, raw_input(). split())
    a = min(l)
    l.remove(min(l))
    b = min(l)
    c = max(l)
    if a ** 2 + b ** 2 == c ** 2:
        q.append("YES")
    else:
        q.append("NO")

for s in xrange(len(q)):
    print(q[0])
    q.pop(0)

Measured memory_bytes: 6260
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = input()
    t = input()
    if s == t[:len(s)]:
        print("Yes")
    else:
        print("No")
    return

#Solve
if __name__ == "__main__":
    solve()


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

int main ()
{
    int n;
    cin >> n;
    
    long long happiness[n][3];
    for (int i=0; i<n; i++){
        for (int j=0; j<3; j++){
            cin >> happiness[i][j];
        }
    }
    long long dp[n][3];
    dp[0][0] = happiness[0][0];
    dp[0][1] = happiness[0][1];
    dp[0][2] = happiness[0][2];
    
    for (int i=1; i<n; i++){
        for (int j=0; j<3; j++){
            if (j == 0) dp[i][j] = max(dp[i-1][1], dp[i-1][2]) + happiness[i][j];
            else if (j == 1) dp[i][j] = max(dp[i-1][0], dp[i-1][2]) + happiness[i][j];
            else if (j == 2) dp[i][j] = max(dp[i-1][1], dp[i-1][0]) + happiness[i][j];
            //cout << dp[i][j] << " ";
        }
        //cout << endl;
    }
    
    long long answer = 0;
    for (int i=0; i<3; i++){
        answer = max(answer, dp[n-1][i]);
    }
    cout << answer << endl;
    
    return 0;
}

Measured memory_bytes: 4992
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int l = s.length();

    String first = s.substring(0,1);
    String last = s.substring(l-1,l);

    System.out.println(first+(l-2)+last);

  }

}


Measured memory_bytes: 21972
using System;
class Program{
  static void Main(string[] args){
    int n = int.Parse(Console.ReadLine());
    string s = Console.ReadLine();
    int k = int.Parse(Console.ReadLine());
    char c = s[k-1];
    string p="";
    for(int i=0;i<n;i++){
      p+=(s[i]==c)?c.ToString():"*";
    }
    Console.WriteLine(p);
  }
}

Measured memory_bytes: 13140
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] List = new int[n];
		
		for(int i=0;i<n;i++)
			List[i] = sc.nextInt();
		
		int q = sc.nextInt();
		
		for(int i=0;i<q;i++) {
			
			int b = sc.nextInt();
			int e = sc.nextInt();
			int t = sc.nextInt();
			
			for(int j=0;j<(e-b);j++) {
				int tmp = List[b + j];
				List[b + j] = List[t + j];
				List[t + j] = tmp;
			}
		}
		
		for(int i=0;i<List.length;i++) {
			System.out.print(List[i]);
			if(i != List.length - 1)
				System.out.print(" ");
			else
				System.out.println();
		}
	}
}


Measured memory_bytes: 35288
using System;

namespace Sample101
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var line = Console.ReadLine().Split(' ');
                var H = int.Parse(line[0]);
                var W = int.Parse(line[1]);
                if (H == 0 && W ==0)
                {
                    return;
                }

                for (int j = 0; j < H; j++)
                {
                    for (int i = 0; i < W; i++)
                    {
                        Console.Write('#');
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}


Measured memory_bytes: 15972
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

long long int n;
vector<long long int> v;
long long int ans;

bool cut(long long int x){
	bool f = false;
	for(int i=0; i<n; i++){
		int j, k;
		j = lower_bound(v.begin(), v.end(), v[i]+x)-v.begin();
		k = lower_bound(v.begin(), v.end(), v[j]+x)-v.begin();
//		if(x == 6) printf("%lld %lld %d %d %d\n", v[i]+x, v[j]+x, i, j, k);
		if(v[i+n] - v[k] >= x){
			f = true;
			break;
		}
	}
	return f;
}

long long int solve(){
	long long int l = 0;
	long long int r = 1000000000 * n + 1;
	while(r - l > 1){
//		printf("%lld %lld\n", l, r);
		long long int m = (l + r) / 2;
		if(cut(m)) l = m;
		else r = m;
	}
	return l;
}

int main(){
	scanf("%lld", &n);
	v.push_back(0);
	for(int i=0; i<n; i++){
		long long int t;
		scanf("%lld", &t);
		v.push_back(t);
	}
	for(int i=1; i<n+1; i++) v.push_back(v[i]);
	for(int i=1; i<2*n+2; i++) v[i] += v[i-1];

//	for(int i=0; i<v.size(); i++) printf("%lld\n", v[i]);
	printf("%lld\n", solve());
}

Measured memory_bytes: 4476
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
int N;
string S;

int main(){
	cin >> N >> S;

	vector<int> nE(N);
	for(int i=0; i<N; i++){
		nE[i] = i==0?0:nE[i-1];
		nE[i] += S[i]=='E'?1:0;
	}
	int ans = 1e8;
	for(int i=0; i<N; i++){
		int left = i>0?i-nE[i-1]:0;
		int right = nE[N-1]-nE[i];
		ans = min(ans, left+right);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1796
a, b, c, x = map(int, [input() for i in range(4)])

ans = 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:
                ans += 1
print(ans)

Measured memory_bytes: 9176
L=int(input())

def Volume(q):
  x,y=q
  x=abs(x)
  y=abs(y)
  z=L-x-y
  return -x*y*z

from scipy.optimize import fmin
res=fmin(Volume,(0,0),xtol=1e-8,ftol=1e-8,disp=0)
print(-Volume(res))

#???

Measured memory_bytes: 25524
package main

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

type scanner struct {
	sc *bufio.Scanner
}

func (sc *scanner) next() string {
	sc.sc.Scan()
	return sc.sc.Text()
}

func (sc *scanner) nextInt() int {
	i, err := strconv.Atoi(sc.next())
	if err != nil {
		panic(err)
	}
	return i
}

func newScanner(r io.Reader) *scanner {
	sc := bufio.NewScanner(r)
	sc.Split(bufio.ScanWords)
	return &scanner{
		sc: sc,
	}
}

var sc = newScanner(os.Stdin)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	w := sc.next()
	m := map[rune]int{}
	for _, c := range w {
		m[c] += 1
	}
	ans := "Yes"
	for _, cnt := range m {
		if cnt&1 == 1 {
			ans = "No"
			break
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
void dfs(ll t,vector <ll> v[],ll visited[],ll cnt[],ll sum){
    visited[t]=1;
    cnt[t]+=sum;
    for(auto itr=v[t].begin();itr!=v[t].end();++itr){
        if(visited[*itr]==0)dfs(*itr,v,visited,cnt,cnt[t]);
    }
    return ;
}

int main(){
    ll N,Q;
    cin >> N >>Q;
    ll i;
    ll a,b;
    vector <ll> v[N];
    for(i=0;i<N-1;i++){
        cin >> a >> b;
        v[a-1].push_back(b-1);
        v[b-1].push_back(a-1);
    }
    ll cnt[N];
    ll visited[N];
    for(i=0;i<N;i++){
        cnt[i]=0;
        visited[i]=0;
    }
    ll p,x;
    for(i=0;i<Q;i++){
        cin >> p >> x;
        cnt[p-1]+=x;
    }
    dfs(0,v,visited,cnt,0);
    for(i=0;i<N;i++){
        cout << cnt[i] << " ";
    }
    return 0;
}


Measured memory_bytes: 28928
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,k,s;cin>>n>>k>>s;
	if (n == k){
		for(int i = 0; i < n; i++) {
			cout << s << ' ';
		}
		cout << endl;
	}
	else if(s != 1){
		for(int i = 0; i < k + 1; i++) {
			if (i % 2 == 0){
				cout << s - 1 << ' ';
			}
			else{
				cout << 1 << ' ';
			}
		}
		for(int i = k + 1; i < n; i++) {
			cout << 1000000000 - 2 << ' ';
		}
		cout << endl;
	}
	else{
		for(int i = 0; i < k; i++) {
			cout << 1 << ' ';
		}
		for(int i = k; i < n; i++) {
			cout << 1000000000 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1280
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int MIN(int p, int r)
{
	return (p < r ? p : r);
}

int main()
{
	int a, b, c, d,total;

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

	total = MIN(a, b) + MIN(c, d);

	printf("%d\n", total);

	return 0;
}

Measured memory_bytes: 128
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    X, Y = MI()


    if (Y%2 == 0) and (2*X<=Y) and (Y <= 4*X):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
	main()

Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


int main(){
    long long x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<long long> a(x), b(y), c(z);
    for(int i = 0; i < x; ++i)  cin >> a[i];
    for(int i = 0; i < y; ++i)  cin >> b[i];
    for(int i = 0; i < z; ++i)  cin >> c[i];

    vector<long long> ab;
    for(int i = 0; i < x; ++i)
       for(int j = 0; j < y; ++j)
              ab.push_back(a[i] + b[j]);
    sort(ab.rbegin(), ab.rend());
    sort(c.rbegin(), c.rend());
    vector<long long> ans;
    for(int i = 0; i < min(x * y, k); ++i)
        for(int j = 0; j < min(z, k); ++j)
            ans.push_back(ab[i] + c[j]);
    
    sort(ans.rbegin(), ans.rend());
    for(int i = 0; i < k; ++i) cout << ans[i]<< endl;
}

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

int main(){
  
  int X;
  cin >> X;
  
  if(X == 3 || X == 5 || X == 7){
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
  return 0;
}

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

int p,q,a,n;

int dfs(int A,int B,int C,int D,int MAX){

  int res=0;

  if(B*p == A*q){
    //cout<<A<<' '<<B<<' '<<C<<' '<<D<<' '<<MAX<<endl;
    return 1;
  }

  if(B*p < A*q)return 0;

  if(D == n)return 0;

  for(int i=MAX;i*C<=a;i++){
    int t = __gcd(B,i);
    int bb = B*i/t;
    int aa = bb/B*A + bb/i;
    //cout<<A<<' '<<B<<' '<<i<<' '<<aa<<' '<<bb<<endl;
    res += dfs( aa , bb , C*i , D+1 , i );
  }

  return res;
}

signed main(){
  while(cin>>p>>q>>a>>n,n){
    cout<<dfs(0,1,1,0,1)<<endl;
  }
}


Measured memory_bytes: 3004
import re

S = input()

res = True

if S[0] != 'A':
  res = False
  
if S[2:-1].count('C') != 1:
  res = False
  
if len(re.findall('[a-z]', S)) != len(S) - 2:
  res = False
       
if res:
  print('AC')
else:
  print('WA')

Measured memory_bytes: 3188
#include<stdio.h>

int main(){
    
    int a,b,c,d,e;
    scanf("%d",&a);
    b = a%10;
    c = a/10;
    d = c%10;
    e = c/10;   
    if(b == 7){
        printf("Yes");
    }
    else if(d == 7){
        printf("Yes");
    }
    else if(e == 7){
        printf("Yes");
    }
    else{
        printf("No");
    }
    
    return 0;
}

Measured memory_bytes: 3204
#include <cstdio>
int main(){
	int n;
	int a[101];
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	while(n>1){ printf("%d ",a[n-1]); n--; }
	printf("%d\n",a[0]);
}



Measured memory_bytes: 2688
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <string>

#define INF 99999999
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;

int main(void){
    int64_t x;
    cin >> x;
    
    int n =(int64_t)sqrt(2*x+0.25d) - 5;
    
    if( n < 0 )n=0;
    
    while( n*(n+1) < 2*x )n++;
    cout << n << endl;
    
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

string tab = "mcxi";
string encode(int x){
  string res = "";
  int d = 3;
  while(x > 0){
	int m = x % 10;
	if(m >= 1)
	  res.insert(0, string(1,tab[d]));
	if(m > 1){
	  res.insert(0, string(1,m+'0'));
	}
	x /= 10;
	--d;
  }

  return res;
}

int decode(string str){
  int st = 1;
  int res = 0;
  REP(i, SZ(str)){
	if(isdigit(str[i]))
	  st = str[i] - '0';
	else{
	  int p = 1;
	  for(int d=3;d>=0;--d){
		if(str[i] == tab[d])
		  break;
		p *= 10;
	  }
	  res += p * st;
	  st = 1;
	}
  }

  return res;
}

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

  int n; cin >> n;
  REP(t,n){
	string s1, s2; cin >> s1 >> s2;
	cout << encode(decode(s1) + decode(s2)) << endl;
	//	cout << decode(s1) + decode(s2) << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

a, b, c, d = na()

print(max(a * b, c * d))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

int fact(int n){
    if(n == 0) return 1;
    return n * fact(n - 1);
}

signed main(){
    int n;
    cin >> n;
    double x[n], y[n];
    REP(i,n){
        cin >> x[i] >> y[i];
    }
    vector<int> v;
    REP(i,n){
        v.emplace_back(i);
    }
    double sum = 0.0;
    do{
        REP(i,v.size() - 1){
            sum += sqrt((x[v[i]] - x[v[i + 1]]) * (x[v[i]] - x[v[i + 1]]) + (y[v[i]] - y[v[i + 1]]) * (y[v[i]] - y[v[i + 1]]));
        }
    }while(next_permutation(ALL(v)));
    printf("%.10lf\n", sum / (double)fact(n));
    return 0;
}

Measured memory_bytes: 256
def check(i, j, high, width, data):
    pre_j = max(0, j - 1)
    aft_j = min(width - 1, j + 1)
    pre_i = max(0, i - 1)
    aft_i = min(high - 1, i + 1)

    if pre_i != i:
        if data[pre_i][j] == '#':
            return 1
    if aft_i != i:
        if data[aft_i][j] == '#':
            return 1
    if pre_j != j:
        if data[i][pre_j] == '#':
            return 1
    if aft_j != j:
        if data[i][aft_j] == '#':
            return 1
    # print(i, j)
    return 0


def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    # for i in range(high):
    #     print(data[i])

    for i in range(high):
        for j in range(width):
            if data[i][j] == '#':
                if check(i, j, high, width, data) == 0:
                    print('No')
                    return

    print('Yes')



if __name__ == '__main__':
    main()


Measured memory_bytes: 39664
def counting_sort(MAX):
    C = [0 for _ in range(MAX+1)]

    for i in range(N):
        C[A[i]] += 1

    for i in range(1, MAX+1):
        C[i] = C[i] + C[i-1]

    for i in range(N-1, -1, -1):
        C[A[i]] -= 1
        B[C[A[i]]] = A[i]

N = int(input())
A = list(map(int, input().split()))

MAX = 0
for n in A:
    if MAX < n:
        MAX = n

B = [0 for _ in range(N)]
counting_sort(MAX)
print(" ".join(map(str, B)))


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  vector<int> a(n);
  vector<int> b(n);
  LL a_sum = 0;
  LL b_sum = 0;
  REP (i, n) {
    cin >> a[i];
    a_sum += a[i];
  }

  REP (i, n) {
    cin >> b[i];
    b_sum += b[i];
  }

  vector<int> minus;
  vector<int> plus;
  REP (i, n) {
    int dif = a[i] - b[i];
    if (dif < 0) minus.push_back(abs(dif));
    else plus.push_back(dif);
  }

  LL plus_sum = accumulate(plus.begin(), plus.end(), 0LL);
  for (auto m : minus) {
    plus_sum -= m / 2;
  }

  if (b_sum - a_sum < 0 || plus_sum > 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 384
A = [1,3,5,7,8,10,12]
B = [4,6,9,11]
C = [2]
def grp(x,y):
    if x in y:
        return 1
    else:
      	return 0
x,y = map(int,input().split())
if grp(x,A)*grp(y,A) or grp(x,B)*grp(y,B) or grp(x,C)*grp(y,C):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3060
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	b := make([]int, n)
	for i := range b {
		fmt.Scan(&b[i])
	}
	fmt.Println(seek(n, a, b))
}

func seek(n int, a, b []int) int {
	sum := make([]int, n)
	for i := 0; i < n; i++ {
		for ia := 0; ia <= i; ia++ {
			sum[i] += a[ia]
		}
		for ib := i; ib < n; ib++ {
			sum[i] += b[ib]
		}
	}
	sort.Ints(sum)
	return sum[len(sum)-1]
}


Measured memory_bytes: 512
N = int(input())
S = [list(input()) for i in range(N)]
for i in range(N):
    S[i].sort()
    S[i]=''.join(S[i])
S.sort()
word = S[0]
ans = 0
cnt = 1
for i in range(1,N):
    if(word == S[i]):
        cnt += 1
    else:
       	ans += cnt*(cnt-1)//2
       	cnt = 1
    word = S[i]
    if(i == N-1):
        ans += cnt*(cnt-1)//2
print(ans)

Measured memory_bytes: 24208
#include<bits/stdc++.h>
#include<set>
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main() {
  fastIO  
  int n;
    cin>>n;
    set <string> s;
    string str;
    for(int i=0;i<n;i++){
        cin >> str;
        s.insert(str);
    }

    cout<<s.size()<<endl;

    return 0;
}


Measured memory_bytes: 19220
#include <iostream>
using namespace std;
int main(){
  int a,b;cin>>a>>b;
  string s;cin>>s;
  bool flg=true;
  if(s.size()!=(a+b+1))cout<<"No"<<endl,exit(0);
  if(s[a]!='-')cout<<"No"<<endl,exit(0);
  for(int i=0;i<a+b+1;i++){
  if(i==a)continue;
  if(!isdigit(s[i])){  cout<<"No"<<endl,exit(0);}
    }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    XYZ = [list(map(int, input().split())) for _ in range(n)]

    res = 0
    for x, y, z in product([-1, 1], repeat=3):
        total = []
        for X, Y, Z in XYZ:
            s = X * x + Y * y + Z * z
            total.append(s)
        total.sort(reverse=True)
        res = max(res, sum(total[:m]))
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9312