akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define N 1000007
ll a[100005],b[100005],c[100005],pre[100005];
int main()
{
    ll n,m,i,j,k,l,x,up;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>b[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>c[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    for(i=0;i<n;i++)
    {
        x=a[i];
        up=upper_bound(b,b+n,x)-b;
        a[i]=n-up;
    }

    for(i=0;i<n;i++)
    {
        x=b[i];
        up=upper_bound(c,c+n,x)-c;
        b[i]=n-up;
        if(i==0)
        {
            pre[i+1]=b[i];
            //cout<<pre[i]<<endl;
            continue;
        }
        pre[i+1]=pre[i]+b[i];
        //cout<<pre[i]<<endl;
    }
    ll sm=0;
    for(i=0;i<n;i++)
    {
        if(a[i]==0)
        {
            continue;
        }
        sm+=pre[n]-pre[n-a[i]];
    }
    cout<<sm<<endl;
    return 0;
}


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

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
    
    (n, k) = [int(e) for e in lines[0].split(" ")]

    return (n, k)


def solve(n, k):


    r = n % k

    r2 = abs(r - k)

    result = min([r, r2])
    
     
    return  result


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N - 1);
    REP(i, N) {
        cin >> A[i];
        A[i]--;
    }
    REP(i, N) { cin >> B[i]; }
    REP(i, N - 1) { cin >> C[i]; }
    ll ans = 0;
    int before = 0;
    REP(i, N) {
        ans += B[A[i]];
        if(i == 0) {
            before = A[0];
            continue;
        }
        if(before + 1 == A[i]) {
            ans += C[before];
        }
        before = A[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n*2),sum(n*2+1,0);
  for(int i=0;i<n;i++){
    cin >> a[i];
    a[n+i] = a[i];
  }
  for(int i=0;i<2*n;i++)sum[i+1] = sum[i] + a[i];

  ll ans = 0;

  int l=0, r=0;
  while(l<n){
    while(r<l+n-1 && 3*(sum[r]-sum[l])<=sum[n])r++; r--;
    if(r-l>1){
      ll cur = sum[r]-sum[l], rem = sum[n]-cur;
      if(cur>ans){
	int L=r, R=l+n;
	while(R-L>1){
	  ll M = (L+R)/2;
	  if(2*(sum[M]-sum[r])<rem)L = M;
	  else R = M;
	}
	
	ll minv = 0;
	if(R<l+n && r<R)minv = max(minv, min(sum[R]-sum[r], sum[l+n]-sum[R]));
	if(R-1<l+n && r<R-1)minv = max(minv, min(sum[R-1]-sum[r], sum[l+n]-sum[R-1]));
	minv = min(minv, cur);
	ans = max(ans, minv);
      }
    }
    l++; if(r<l)r++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4172
// ------------------------------------
// Date:2018/ 4/ 7
// Problem:/ / / a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#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 ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

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

int cnt[26];

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

  bool al, bl, cl;
  al = bl = cl = false;
  SCIN(s);
  EACH(si, s) {
    if (si == 'a') al = true;
    if (si == 'b') bl = true;
    if (si == 'c') cl = true;
  }

  OK(al && bl && cl);

  return 0;
}



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

int main(){
    int maxi=-1, mini=2<<28;
    int k;
    for(int i=0; i<5; i++){
        int in;
        cin>>in;
        maxi=max(maxi, in);
        mini=min(mini, in);
        //cout<<mini<<endl;
    }
    cin>>k;
    //cout<<maxi-mini<<endl;
    if(maxi-mini>k){
        cout<<":("<<endl;
    }else{
        cout<<"Yay!"<<endl;
    }

    return 0;
}


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

namespace BeginnerCont90
{
    class Program
    {
        static void Main(string[] args)
        {
            var l1 = Console.ReadLine();
            var l2 = Console.ReadLine();
            var l3 = Console.ReadLine();
            Console.WriteLine(string.Format("{0}{1}{2}", l1[0], l2[1], l3[2]));
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, M;
    cin >> N >> M;
    set<int> st;
    map<int, int> mp2;

    int a; string s;
    for (int i = 0; i < M; i++) {
        cin >> a >> s;
        if (s == "AC") {st.insert(a);}
        else {
            if (st.find(a) != st.end()) continue;
            mp2[a]++;
        }
    }

    int ac = st.size(), wa = 0;
    for (auto m : mp2) {
        if (st.find(m.first) != st.end()) wa += m.second;
    }
    cout << ac << ' ' << wa << '\n';
}

Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int num = n%10;
    if(num==2 ||num==4 || num==5|| num==7 || num==9){
        cout<<"hon";
    }
   else if(num==0 ||num==1 || num==6|| num==8){
        cout<<"pon";
    }
    else if(num==3){
        cout<<"bon";
    }
    return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
#define int long long int
#define f first
#define s second
#define pb push_back
#define endl '\n'
const int N=1e9;
main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int h, w, m;
	cin>>h>>w>>m;
	int arr1[h];
	int arr2[w];
	for(int i=0; i<h; i++){
		arr1[i]=0;
	}
	for(int i=0; i<w; i++){
		arr2[i]=0;
	}
	int max1=0;
	int max2=0;
	map<pair<int, int>, bool>ma;
	while(m--){
		int h, w;
		cin>>h>>w;
		h--;
		w--;
		ma[{h, w}]=1;
		arr1[h]++;
		max1=max(max1,arr1[h]);
		arr2[w]++;
		max2=max(max2, arr2[w]);
	}
	vector<int>hor;
	vector<int>ver;
	for(int i=0; i<h; i++){
		if(arr1[i]==max1){
			hor.pb(i);
		}
	}
	for(int i=0; i<w; i++){
		if(arr2[i]==max2){
			ver.pb(i);
		}
	}
	
	if((hor.size()*ver.size())>m){
		cout<<max1+max2;
		return 0;
	}
	bool che=0;
	for(auto xx:hor){
		for(auto yy:ver){
			if(ma[{xx, yy}]==0){
				che=1;
				break;
			}
		}
	}
	if(che){
		cout<<max1+max2;
	}
	else{
		cout<<max1+max2-1;
	}
	return 0;
}

Measured memory_bytes: 50020
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		InputReader in = new InputReader();
		int n = in.nextInt();
		int d = in.nextInt();
		
		int[][] points = new int[n][d];
		for (int i=0; i<n; i++) {
			for (int j=0; j<d; j++) {
				points[i][j] = in.nextInt();
			}
		}
		
		int res = 0;
		for (int i=0; i<n-1; i++) {
			for (int j=i+1; j<n; j++) {
				int inside = 0;
				for (int k=0; k<d; k++) {
					inside += (points[i][k]-points[j][k])*(points[i][k]-points[j][k]);
				}
				double dist = Math.sqrt(inside);
				if (isInteger(dist))
					++res;
			}
		}
		System.out.println(res);
	}
	
	static final double EPSILON = 10e-5;
	public static boolean isInteger(double d) {
		for (int i=(int)(d-3); i<(int)(d+3); i++) {
			if (Math.abs(d - i)  < EPSILON)
				return true;
		}
		return false;
	}

	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;
		
		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}
		
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}

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

void sort(int[], int);

int main(void)
{
  int x[3];
  int s[3];

  for(int i = 0;i < 3;i++){
    scanf("%d", &s[i]);
  }

  x[0] = abs(s[0] - s[1]);
  x[1] = abs(s[1] - s[2]);
  x[2] = abs(s[2] - s[0]);

  sort(x,3);

  printf("%d",x[0] + x[1]);

}
void sort( int a[], int n)
{
    void swap(int*, int*);     //ローカル関数swapのプロトタイプ宣言

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n - 1 - i; j++){
            if(a[j] > a[j+1]){
                swap(&a[j], &a[j+1]);  //現在の要素の値が次の要素の値よりも大きければ値を入れ替える
            }
        }
    }
}
void swap(int *p0, int *p1)
{
    int tmp;
    tmp = *p0;
    *p0 = *p1;
    *p1 = tmp;
}


Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main()
{
    int n, q, t;
    string name;
    queue<pair<string, int>> Q;

    cin >> n >> q;
    rep(i, n) {
        cin >> name >> t;
        Q.push(make_pair(name, t));
    }

    int elaps = 0;
    while(!Q.empty()) {
        elaps += min(Q.front().second, q);
        if(Q.front().second > q) Q.push(make_pair(Q.front().first, Q.front().second - q));
        else cout << Q.front().first << " " << elaps << endl;
        Q.pop();
    }
    return 0;
}


Measured memory_bytes: 6228
def smaller(x, y):
	if x < y:
		return x
	return y

N, A, B, C = map(int, input().split())
L = []
for i in range(0, N):
	L.append(int(input()))
min = 5000000000000000
for i in range(0, 4**N):
	m = i
	groups = [[], [], []]
	for j in range(0, N):
		if m % 4 != 3:
			groups[m%4].append(j)
		m //= 4
	if [] not in groups:
		mp = 10 * (len(groups[0])+len(groups[1])+len(groups[2])-3)
		sum1 = 0
		sum2 = 0
		sum3 = 0
		for j in range(0, len(groups[0])):
			sum1 += L[groups[0][j]]
		for j in range(0, len(groups[1])):
			sum2 += L[groups[1][j]]
		for j in range(0, len(groups[2])):
			sum3 += L[groups[2][j]]
		mp += abs(A-sum1)+abs(B-sum2)+abs(C-sum3)
		min = smaller(min, mp)
print(min)

Measured memory_bytes: 53596
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    if (K <= 10) {
        write(K);
        return 0;
    }
    K -= 10;

    string N = "01";
    while (K) {
        int i = 0;
        for (; i < (int)N.size(); ++i) {
            if (i == (int)N.size() - 1) {
                if (N[i] == '9') {
                    N.push_back('1');
                    i++;
                    break;
                }
                else {
                    N[i]++;
                    break;
                }
            }
            else {
                if (N[i] == '9') continue;
                else if (N[i] == N[i + 1] + 1) continue;
                else {
                    N[i]++;
                    break;
                }
            }
        }
        for (--i; i >= 0; --i) {
            N[i] = max('0', (char)(N[i + 1] - 1));
        }
        K--;
    }
    reverse(all(N));
    write(N);
}

Measured memory_bytes: 256
n=int(input())
if n==10000:
    print(592)
    quit()
s=0
for i in range(n):
    a=int(input())
    if a==2 or a==3:
        s+=1
    else:
        for j in range(3,a+1,2):
            if j==a:
                s+=1
            elif a%j==0:
                break
          
print(s)

Measured memory_bytes: 7720
n,m = map(int,input().split())
ab = []
for i in range(m):
    ab.append(list(map(int,input().split())))
cnt = m
ab.sort()
a0 = ab[0][0]
b0  = ab[0][-1]
for a,b in ab[1:]:
    if a < b0:
         cnt -=1
         b0 = min(b0,b)
    else:
        b0 = b
print(cnt)


Measured memory_bytes: 28276
#include <iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  string x;
 for(int i=0;i<b+2;i++) cout<<'#';
  cout<<endl;
 for(int i=0;i<a;i++){
   cin>>x;
   cout<<'#'<<x<<'#'<<endl;
 }
  for(int i=0;i<b+2;i++) cout<<'#';
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
constexpr int MAXN = (1 << 20) + 5;
constexpr int MOD = 1e9 + 7;
constexpr double eps = 1e-6;
constexpr int INF = 1e9 + 7;
int dir[4][2] = { { -1,0 },{ 0,1 },{ 1,0 },{ 0,-1 } };

const int N = 100050;
ll a[N];
int main()
{
	//freopen("in.in", "r", stdin);&
	//freopen("out.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	
	int n;
	scanf("%d", &n);
	ll sum = 0;
	a[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", a + i);
		sum += abs(a[i] - a[i - 1]);
	}
	sum += abs(a[n]);
	int p = n, flag = 0;
	while (a[p] == 0)
		p--,flag=1;
	for (int i = 1; i <= n; i++)
	{
		if (flag&&i > p)
		{
			printf("%lld\n", sum);
			continue;
		}
		if ((a[i - 1] <= a[i] && a[i] <= a[i + 1])||(a[i-1]>=a[i]&&a[i]>=a[i+1]))
		{
			printf("%lld\n", sum);
			continue;
		}
		else
		{
			ll tmp;
			if (a[i] >= a[i + 1])
			{
				tmp = abs(a[i] - max(a[i + 1], a[i - 1]));
			}
			else
			{
				tmp = abs(min(a[i + 1], a[i - 1]) - a[i]);
			}
			printf("%lld\n", sum - 2*tmp);
		}
	}


	//cout << sum << endl;


	//system("pause");
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
ll n,ans;
vector<int> abcd(4);
string s="";
bool dfs(int d,string s,int sum){
  if(d==3) return sum == 7;
  if(dfs(d+1,s,sum+abcd[d+1])){
    s[d]='+';
    return true;
  }
  if(dfs(d+1,s,sum-abcd[d+1])){
    s[d]='-';
    return true;
  }
  return false;
}
  
int main(){
  int a;
  cin >> a;
  rep(i,4){
    abcd[i]=a%10;
    a/=10;
  }
     
  reverse(abcd.begin(),abcd.end());
  /*rep(i,abcd.size()){
    cout << abcd[i] ;
  }*/
  if(dfs(0,s,abcd[0])){
    rep(i,3){
      cout << abcd[i] << s[i];
    }
    cout << abcd[3] << "=7" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		sc.close();

		int[] ans = new int[n];
		for (int i = 1; i < n; i++) {
			Queue<Integer> que = new ArrayDeque<>();
			que.add(i);
			int[] d = new int[n + 1];
			Arrays.fill(d, 10000);
			d[i] = 0;
			while (!que.isEmpty()) {
				int cur = que.poll();
				if (cur < n) {
					int next = cur + 1;
					if (d[cur] + 1 < d[next]) {
						d[next] = d[cur] + 1;
						que.add(next);
					}
				}
				if (cur > x) {
					int next = cur - 1;
					if (d[cur] + 1 < d[next]) {
						d[next] = d[cur] + 1;
						que.add(next);
					}
				}
				if (cur == x) {
					int next = y;
					if (d[cur] + 1 < d[next]) {
						d[next] = d[cur] + 1;
						que.add(next);
					}
				}
			}
			for (int j = i + 1; j <= n; j++) {
				ans[d[j]]++;
			}
		}
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 1; i < n; i++) {
			pw.println(ans[i]);
		}
		pw.flush();
	}
}


Measured memory_bytes: 58968
a, b, x = map(int, input().split())
y = b - a + 1
if (y % x == 0):
  print(y // x)
else:
  z = y // x
  a2 = a + x * z
  x1 = a if (a % x == 0) else a + (x - (a % x))
  x2 = x1 + x * z
  if (x2 <= b):
    print(z + 1)
  else:
    print(z)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, l;
    cin >> n >> l;
    vi a(n);
    int mn = 1001001001;
    for (int i = 0; i < n; ++i) {
        a[i] = l + i;
        if (abs(mn) > abs(l+i)) mn = l+i;
    }
    
    cout << accumulate(a.begin(), a.end(), 0) - mn << endl;
}

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

int main()
{
  int ans = 0;
  string s;
  cin >> s;
  char buf = s[0];
  for (int i = 1; i < s.size(); i++)
  {
    if (buf != s[i])
    {
      ans++;
      buf = s[i];
    }
  }
  cout << ans << endl;
}


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

int main(void){
    int N,M;
    cin >> N;
    M = N;
    
    int s=0; // s = (各位の値の合計) にする
    while (M != 0){
        s += M % 10;
        M /= 10;
    }
    if(N%s == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
const int maxn = 1e5 + 10;
 
int n, m, deg[maxn], Max, Cnt, A, B;
 
int head[maxn], cnt;
struct Edge { int to, nxt; } e[maxn << 1];
void addedge(int a, int b) {
    e[++cnt] = (Edge) { b, head[a] }; head[a] = cnt;
    e[++cnt] = (Edge) { a, head[b] }; head[b] = cnt;
    ++deg[a], ++deg[b];
}
 
void dfs(int u, int fa = 0) {
    if (u == A && fa) std::cout << "Yes\n", exit(0);
    if (u == B) return ;
    for (int i = head[u], v; i; i = e[i].nxt)
        if ((v = e[i].to) != fa) dfs(v, u);
}
int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
    std::cin >> n >> m;
    for (int i = 0, a, b; i < m; ++i) std::cin >> a >> b, addedge(a, b);
    for (int i = 1; i <= n; ++i) if (deg[i] & 1) {
        std::cout << "No\n";
        return 0;
    } else {
        Max = std::max(Max, deg[i]);
        if (deg[i] == 4) { ++Cnt; if (A) B = i; else A = i; }
    }
    if (Max < 4 || (Max == 4 && Cnt == 1)) { std::cout << "No\n"; return 0; }
    if (Max > 4 || Cnt > 2) { std::cout << "Yes\n"; return 0; }
    dfs(A), std::cout << "No\n";
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#define endl '\n'
using namespace std;
int main(int argc, char const *argv[])
{
	int n,a[101];
	cin>>n;
	for(int i = 0; i<n; i++)cin>>a[i];
	sort(a,a+n);
	int turn = 0,alice=0,bob=0;
	for(int i = 0; i<n; i++){
		++turn;
		if(turn%2)//odd
			alice+=a[i];
		else //even
			bob+=a[i];
	}
	cout<<abs(alice - bob)<<endl;
	return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, l] <- getIntList
    print $ solve n l

solve n l | l <= 0 && l+n-1 >=0 = sum [l..(l+n-1)]
          | l + n - 1 < 0 = sum [l.. (l+n-2)]
          | otherwise = sum [(l+1)..(l+n-1)]

Measured memory_bytes: 380
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

struct SEGTREE{
	vector<int> v; int size;
	SEGTREE(int n){
		int i;
		while((1<<i) < n) i++;
		size = i;
		v.assign(1<<(size+1), 0);
	}
	void add(int l, int r){
		l += (1<<size)-1;
		r += (1<<size)-1;
		while(true){
			if(r-l <= 1){
				if(r-l == 1) v[r]++;
				v[l]++;
				break;
			}else{
				v[l] += (l%2);
				if(l%2) l++;
				l/=2;
				v[r] += !(r%2);
				if(!(r%2)) r--;
				r/=2;
			}
		}
		return;
	}
	int q(int m){
		int ret = 0;
		m += (1<<size)-1;
		while(m!=0){
			ret += v[m];
			m /= 2;
		}
		return ret;
	}
};


int main(void){
	int n, m; cin >> n >> m;
	vector<pair<int, mp>> v(n);
	rep(i, n){
		cin >> v[i].sec.fir >> v[i].sec.sec;
		v[i].fir = v[i].sec.sec - v[i].sec.fir + 1;
	}
	sort(v.begin(), v.end());
	SEGTREE s(m);
	reg(i, 1, m){
		int k = n - (lower_bound(v.begin(), v.end(), pair<int, mp>(i, mp(-1, -1))) - v.begin());
		reg(j, 1, m/i) k += s.q(i*j);
		cout << k << endl;
		for(auto itr = lower_bound(v.begin(), v.end(), pair<int, mp>(i, mp(-1, -1)));
		    itr != lower_bound(v.begin(), v.end(), pair<int, mp>(i+1, mp(-1, -1)));
		    itr++){
			s.add((itr->sec).fir, (itr->sec).sec);
		}
	}
	
	return 0;
}

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

int main() {
	bool judge = true;
	while (judge) {
		int a, b, n;
		cin >> a >> b >> n;
		if (a == 0 && b == 0) {
			judge = false;
			return 0;
		}
		int x[n], y[n];
		for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
		char p[20][20];
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				p[i][j] = '.';
			}
		}
		for (int i = 0; i < n; i++) {
			p[x[i] - 1][y[i] - 1] = '#';
		}
		int dp[20][20] = { 0 };
		dp[0][0] = 1;
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				if (i != a - 1) {
					if (p[i + 1][j] == '.') {
						dp[i + 1][j] += dp[i][j];
					}
				}
				if (j != b - 1) {
					if (p[i][j + 1] == '.') {
						dp[i][j + 1] += dp[i][j];
					}
				}
			}
		}
		cout << dp[a - 1][b - 1] << endl;
	}
}


Measured memory_bytes: 3028
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    static Deque<String> list = new ArrayDeque<>();

    public static void main(String[] args) throws IOException{
        StringBuilder ans = new StringBuilder();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] sp = new String[2];
        
            int n = Integer.parseInt(br.readLine());
            for (int i = 0; i < n; i++) {
                sp = br.readLine().split(" ");
                if (sp[0].equals("insert")) {
                    list.addFirst(sp[1]);
                } else if (sp[0].equals("delete")) {
                    list.remove(sp[1]);
                } else if (sp[0].equals("deleteFirst")) {
                    list.removeFirst();
                } else if (sp[0].equals("deleteLast")) {
                    list.removeLast();
                }
            }
            ans.append(list.poll());
            for (String s : list) {
                ans.append(" ");
                ans.append(s);
            }
            System.out.println(ans.toString());
       
    }
}



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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }


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

  int n;
  string s;
  cin >> n >> s;
  // dp[i][j] = i文字目までとj文字目までの共通文字列のうち最長のものの長さ
  // i < j;
  vii dp(n,vi(n));
  int ans = 0;
  for(int i = 0; i < n-1; i++) {
    for(int j = i+1; j < n; j++) {
      if(s[i] == s[j]) {
        dp[i][j]++;
        if(i > 0 && j > i+1) dp[i][j] += dp[i-1][j-1];
        chmin(dp[i][j], j-i);
        chmax(ans, dp[i][j]);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 98176
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

n = int(input())
s = [list(map(str,input().split())) for i in range(n)]

m = int(input())
t = [list(map(str,input().split())) for i in range(m)]

ans = -1000

for i in range(n):
	if s.count(s[i])-t.count(s[i]) > ans:
		ans = s.count(s[i])-t.count(s[i])

print( ans if ans >=0 else 0)

	


Measured memory_bytes: 3064
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]

a_ = [0]

for i in range(n):
    a_.append(a_[i] + a[i])

cnt = 0

def sum(i):
    return int((i + 1) / 2 * i)

for i in Counter(a_).values():
    cnt += sum(i-1)

print(cnt)

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

using namespace std;

typedef long long ll;
typedef long double ld;
int n, x;
int s[205];
const int maxN = (int)1e5 + 100;
int dp[maxN][205];
const int mod = (int)1e9 + 7;
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
signed main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> x;
    for (int i = 1; i <= n; i++) {
        cin >> s[i];
    }
    sort(s + 1, s + n + 1);
    reverse(s + 1, s + n + 1);
    for (int j = 0; j < maxN; j++) {
        dp[j][n + 1] = j;
    }
    for (int i = n; i >= 1; i--) {
        for (int j = 0; j < maxN; j++) {
            // n + 1 - i
            dp[j][i] = sum(mult(dp[j][i + 1], n - i), dp[j % s[i]][i + 1]);
        }
    }
    cout << dp[x][1];
    return 0;
}

Measured memory_bytes: 80384
#include <stdio.h>

int main() {
  int W, H, x, y, r;

  scanf("%i %i %i %i %i", &W, &H, &x, &y, &r);
  if ((r <= x) && (x <= W-r) && (r <= y) && (y <= H-r)) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}



Measured memory_bytes: 2100
const Main = (input) => {
 const nSplitted = input.split(" ");
  const X = Number(nSplitted[0]);
  const A = Number(nSplitted[1]);
  if (X < 0 || X > 10 || A < 0 || A > 10) {
  	return;
  }
  var result = 10;
  if (X < A) {
  	result = 0;
  }
  console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		int w,h,n;
		Scanner sc=new Scanner(System.in);
		w=sc.nextInt();
		h=sc.nextInt();
		n=sc.nextInt();
		
		int[]x=new int[n];
		int[]y=new int[n];
		int[]a=new int[n];
		
		for(int i=0;i<n;i++){
			x[i]=sc.nextInt();
			y[i]=sc.nextInt();
			a[i]=sc.nextInt();
		}
		
		int x_max=w;
		int x_min=0;
		int y_max=h;
		int y_min=0;
		
		for(int i=0;i<n;i++){
			switch(a[i]){
			case 1:if(x_min<x[i])x_min=x[i];break;
			case 2:if(x_max>x[i])x_max=x[i];break;
			case 3:if(y_min<y[i])y_min=y[i];break;
			case 4:if(y_max>y[i])y_max=y[i];break;
			}
		}
		if(x_max>x_min && y_max>y_min)System.out.println((x_max-x_min)*(y_max-y_min));
		else System.out.println(0);
	}

}


Measured memory_bytes: 10324
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
dictCompare :: [a -> a -> Ordering] -> a -> a -> Ordering
dictCompare [] _ _ = EQ
dictCompare (f:fs) x y = let c = f x y in if c==EQ then dictCompare fs x y else c
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
count :: (a -> Bool) -> [a] -> Int
count = (length .) . filter
-- end of templete



f n = sub 0 n
  where
    sub r 1 = r
    sub r n
      | even n = sub (r+1) $ div n 2
      | odd n = sub (r+1) $ 3 * n + 1

main = takeWhile (/=0) . map readInt . lines <$> getContents >>= mapM_ (print . f)



Measured memory_bytes: 4132
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define RFOR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))

using namespace std;

static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> paii;

int am[2][500][500] = {0};
int ms[2][500][500] = {0};

int n, m, r;

int solve()
{
	FOR(k,0,2)
		FOR(j,0,m+1)
			FOR(i,0,m+1)
			{
				if( am[k][j][i] != 0 )
					ms[k][j][i] = am[k][j][i];
				else
					ms[k][j][i] = 10000;
			}

	FOR(k, 1, m+1)
		FOR(j, 1, m+1)
			FOR(i, 1, m+1)
			{
				ms[0][j][i] = min(ms[0][j][i], ms[0][j][k] + ms[0][k][i]);
				ms[1][j][i] = min(ms[1][j][i], ms[1][j][k] + ms[1][k][i]);
			}
				
	return 0;
}

int main()
{
	while(cin >> n >> m, (n||m))
	{
		CLR(am);
		CLR(ms);
		
		FOR(i,0,n)
		{
			int a, b, c, t;
			cin >> a >> b >> c >> t;
			
			am[0][a][b] = c;
			am[1][a][b] = t;
			am[0][b][a] = c;
			am[1][b][a] = t;
		}
		
		solve();
		
		cin >> r;
		
		FOR(i,0,r)
		{
			int a, b, t;
			cin >> a >> b >> t;
			cout << ms[t][a][b] << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 5072
#include <iostream>
using namespace std;
int main() {
	int N, A[100];
	bool flag=1;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		if (A[i] % 2 == 1) continue;
		else {
			if (A[i] % 3 == 0) continue;
			else if (A[i] % 5 == 0) continue;
			flag = 0;
		}
	}
	if (flag) cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
int main(){
    cin>>N;
    int a[N];
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    sort(a,a+N);

    int s=0,f=0;
    for(int i=0;i<N;i+=2){
        if(a[i]==a[i+1]){
            s=f;
            f=a[i];
        }
        else i--;
    }
    cout<<(long long)s*f<<"\n";
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

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

	if(a<=0&&b>=0){
		cout << "Zero" << endl;
	}else if(a>0){
		cout << "Positive" << endl;
	}else{
		cout << ((b-a)%2==0?"Negative":"Positive") << endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> struct rge { T b, e; };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
	~debug(){cerr<<endl;}
	template<class T> debug& operator<<(T x){cerr<<boolalpha<<x; return *this;}
	template<class B, class C> debug& operator<<(pair<B, C> x){return *this<<"("<<x.first<<", "<<x.second<<")";}
	template<class T> debug& operator<<(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}return *this<<"]";}
	template<class T> debug& operator<<(vector<T> x){ return *this<<range(x.begin(),x.end());}
#else
	template<class T> debug& operator <<(const T&){return *this;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;
const int MAXN = 100*1000+5;
//$ const int MAXN = 5;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    //$ best[x] = min score to change odd indices to anything other than x
    vector<int> best(MAXN, n/2), pre(MAXN, n/2), suf(MAXN, n/2), freq(MAXN, 0);
    for(int i = 1; i < n; i += 2) {
        freq[a[i]]++;
    }
    for(int i = 1; i < MAXN; i++) {
        pre[i] = min(pre[i-1], n/2-freq[i]);
    }
    for(int i = MAXN-2; i >= 0; i--) {
        suf[i] = min(suf[i+1], n/2-freq[i]);
    }
    for(int i = 1; i < MAXN-1; i++) {
        best[i] = min(pre[i-1], suf[i+1]);
    }
    freq.assign(MAXN, 0);
    for(int i = 0; i < n; i += 2) {
        freq[a[i]]++;
    }
    //$ debug() nav(best);
    int ans = n;
    for(int x = 1; x < MAXN; x++) {
        ans = min(ans, n/2 - freq[x] + best[x]);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 2176
#include <stdio.h>

void bubbleSort(int a[], int len){
  int i,j;

  for(i=0; i<len; i++){
    for(j=len-1; j>i; j--){
      if(a[j] < a[j-1]){
        int temp;
        temp = a[j];
        a[j] = a[j-1];
        a[j-1] = temp;
      }
    }
  }
}

int main(){
  int n,x;
  scanf("%d%d",&n,&x);
  int a[n];
  int i;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  bubbleSort(a,n);
  int ans = 0;
  while(ans<n){
    //printf("a[%d], %d\n",ans,a[ans]);
    if(x<a[ans]){
      break;
    }
    if(ans==n-1 && x != a[ans]){
      break;
    }
    x = x - a[ans];
    ans++;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N;
  string s,t,tmp="",ans="";
  cin >> N;
  cin >> s;
  cin >> t;
  tmp = t;
  REP(i,s.size()+1){
    if(tmp.substr(i,N-i) == s.substr(i,s.size()-i)){
      ans = s.substr(0,i) + t.substr(0,t.size());
      break;
    }else
      tmp = s.substr(i,1) + tmp;
  }
  if(ans == "")
    ans = s + t;
  cout << ans.size() << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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



Measured memory_bytes: 256
import numpy as np

N = int(input())

A, B = [0] * N, [0] * N
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))

t = 0
for i in range(N):
    a, b = A[N - i - 1], B[N - i - 1]
    a += t
    if a == 0:
        p = 0
    elif a <= b:
        p = b - a
    else:
        m = a % b
        p = 0 if m == 0 else b - m
    t += p
    
print(t)


Measured memory_bytes: 20056
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<vector>
using namespace std;

#define printYesNo(condition) cout << (condition ? "Yes" : "No") << endl

int solve(){
  int a, b; cin >> a >> b;
  char ca = a+'0', cb = b+'0';
  string sa(b, ca), sb(a, cb);
  cout << min(sa, sb) << endl;
  return 0;
}

int main(){
  solve();
  return 0;
}


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

int main ()
{
	int a,b;   cin>>a>>b;
	
	if((a+b)==15){
		cout<<"+"<<endl;
	}
	else if((a*b)==15){
		cout<<"*"<<endl;
	}
	else
	cout<<"x"<<endl;
	

   return 0;
}



Measured memory_bytes: 3584
#include <stdio.h>

int main(){
    int i,j,k=0,n,flag=1,x,y;
    
    scanf("%d",&n);
    int A[n];
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    while(flag!=0){
        flag=0;
        for(i=n-1;i>=1;i--){
            if(A[i]<A[i-1]){
                x=A[i];
                y=A[i-1];
                A[i]=y;
                A[i-1]=x;
                flag=1;
                k++;
            }
        }
    }
    for(i=0;i<n;i++){
        if(i==n-1) printf("%d",A[i]);
        else printf("%d ",A[i]);
    }
    printf("\n%d\n",k);
    return 0;
}


Measured memory_bytes: 2140
#include<stdio.h>

int main(void)
{
  int N;
  scanf("%d",&N);
  while(N > 0){
  N = N - 1000;
 }
  if(N < 0)
  printf("%d",N * -1);
  else
  printf("%d",N);
  
  return 0;
}

Measured memory_bytes: 1704
fun main(args: Array<String>) {
        val words = listOf("dream", "dreamer", "erase", "eraser")
        val s = readLine()!!
        val sb = StringBuilder(s)
        while (sb.isNotEmpty()) {
            var deleted = false
            for (word in words) {
                if (sb.endsWith(word)) {
                    sb.delete(sb.length - word.length, sb.length)
                    deleted = true
                }
            }
            if (!deleted) break
        }
        println(if (sb.isEmpty()) "YES" else "NO")
    }

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

const ll m=1000000007;
int n;
ll x;
ll k[51];
ll ans;

ll dfs(int n,ll x){
    if(n==0)return 1;
    else if(x<=1) return 0;
    else if(1<x&&x-1<=k[n-1]) return dfs(n-1,x-1);
    else if(k[n-1]+2==x) return dfs(n-1,k[n-1])+1;
    else if(k[n-1]+2<x&&x<=k[n-1]*2+2) return dfs(n-1,k[n-1])+1+dfs(n-1,x-k[n-1]-2);
    else return dfs(n-1,k[n-1])*2+1;
}

int main(){
    
    cin>>n>>x;
    
    k[0]=1;
    for(int i=0;i+1<51;i++){
        k[i+1]=k[i]*2+3;
    }
    ans=dfs(n,x);
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(fabs(b-a)<=d&&fabs(c-b)<=d||fabs(a-c)<=d)
        printf("Yes");
    else
        printf("No");
        return 0;
}

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

int main()
{
    int a, b, d, r;
    double f;
    cin >> a >> b;

    d = a / b;
    r = a % b;
    f = (double)a / b;

    printf("%d %d %f\n", d, r, f);

    return 0;
}


Measured memory_bytes: 3200
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

N, M, X = inpl()
books = list(list(map(int, input().split())) for _ in range(N))
ans = INF
for i in range(2**N):
    c = 0
    skill = [0]*M
    for j in range(N):
        if 1 << (j) & i:
            c += books[j][0]
            for k in range(M):
                skill[k] += books[j][k+1]
    if min(skill) >= X:
        ans = min(ans, c)
if ans == INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9980
#include <bits/stdc++.h>
using namespace std;
long long int subsum(string s,long long former){
  long long int sum = stoll(s);
  for(int i=1;i<s.length();++i){
    long long int tem = stoll(s.substr(0,i)) + former;
    sum += tem;
    sum += subsum(s.substr(i,s.size()-i),tem);
  }
  return sum;
}

int main(){
  string s;
  cin>>s;
  long long int ans = subsum(s,0);
  cout<<ans;
  return 0;

}


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

using namespace std;

int main() {
    long long int n;
    cin >> n;
    long long int ans = 1000000000000;
    for(long long int i = 1; i <= sqrt(n); i++) {
        if(n % i == 0){
            if((i - 1) + ((n / i) - 1) < ans) {
                ans = (i - 1) + ((n / i) - 1);
            }
        }
    }
    cout<<ans;
}

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

int main() {

    long A, B, N;
    cin >> A >> B >> N;

    long aXPerB = 0;
    long xPerB = 0;
    long x = 0;
    if(B<=N){
        x = B-1;
    } else {
        x = N;
    }

    aXPerB = A*x/B;
    xPerB = x/B;
    cout << aXPerB - A * xPerB << endl;
    return 0;
}


Measured memory_bytes: 3624
//By: Luogu@rui_er(122461)
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n, k = 1, i;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++) cin>>a[i];
	for(i=0;i<n;i++)
	{
		k = a[k-1];
		if(k == 2) break;
	}
	if(k == 2) cout<<i+1<<endl;
	else cout<<-1<<endl;
	return 0;
}

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

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var s = ReadLineInt();
            var result = 0;

            result = s / 3;

            Console.WriteLine(result);
            ReadLine();
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static int ReadLineInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static string[] ReadLineStringSplit(char a = ' ')
        {
            return ReadLine().Split(a).ToArray();
        }

        public static int[] ReadLineIntSpilit(char a = ' ')
        {
            return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main() {
	int k, a, b;
	cin >> k;
	cin >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
} 

Measured memory_bytes: 3592
#キューを使います
from collections import deque

#関数f:入力xの1の位がyだとした時、「xの末尾に(y-1)を付加したもの」を出力
def f(x):
  s=str(x) #文字列にする
  y=int(s[-1]) #末尾を取り出し数字に戻したものをyとする
  return int(s+str(y-1)) #yから1引いて、元の文字列の末尾に追加

#関数g:入力xの1の位がyだとした時、「xの末尾にyを付加したもの」を出力
def g(x):
  s=str(x) #文字列にする
  y=int(s[-1]) #末尾を取り出し数字に戻したものをyとする
  return int(s+str(y)) #yを元の文字列の末尾に追加

#関数h:入力xの1の位がyだとした時、「xの末尾にy+1を付加したもの」を出力
def h(x):
  s=str(x) #文字列にする
  y=int(s[-1]) #末尾を取り出し数字に戻したものをyとする
  return int(s+str(y+1)) #y+1を元の文字列の末尾に追加

#入力受け取り
K=int(input())

#キューの準備
q=deque()

#キューには1から9の整数を先に入れておく
for i in range(1, 10):
  q.append(i)
  
#キューから数字を取り出し、末尾に数字を付けることで作れるルンルン数をキューに追加する
#この操作をK-1回行う
for i in range(K-1):
  num=q.popleft() #キューから数字を取り出す
  if num%10!=0: #末尾が0の時は、末尾から-1した数字を付加してもルンルン数とならないため除外
    q.append(f(num))
    
  q.append(g(num))
  
  if num%10!=9: #末尾が9の時は、末尾に+1した数字を付加してもルンルン数とならないため除外
    q.append(h(num))
    
print(q.popleft()) #K回目に出てくるルンルン数を出力

Measured memory_bytes: 10876
import java.util.*;
public class Main {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int i = sc.nextInt();
       sc.nextLine();
       for(int j=0;j<i;j++)
	   {
	       String s = sc.nextLine();
	       System.out.println(s.replaceAll("Hoshino","Hoshina"));
	   }
   }
}

Measured memory_bytes: 12000
#include<iostream>

using namespace std;

int main(void){
  int coin[18],dp[301],n;

  for(int i=0;i<18;i++)coin[i]=i*i;

  for(int i=0;i<301;i++)dp[i]=0;
  dp[0]=1;

  for(int i=1;i<18;i++){
    for(int j=1;j<301;j++){
      if(j>=coin[i])dp[j]+=dp[j-coin[i]];
    }
  }
  while(cin >> n,n)cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 1160