akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		if (arr[n - 1] < 0 && k % 2 == 1) {
		    long ans = 1;
		    for (int i = 0; i < k; i++) {
		        ans *= -arr[n - i - 1];
		        ans %= MOD;
		    }
		    System.out.println(MOD - ans);
		    return;
		}
		int left = 0;
		int right = n - 1;
		long ans = 1;
		if (k % 2 == 1) {
		    ans = arr[n - 1];
		    right--;
		    k--;
		}
		while(k > 0) {
		    long x;
		    if (arr[left] * arr[left + 1] > arr[right] * arr[right - 1]) {
		        if (arr[left] * arr[left + 1] < 0) {
		            x = (MOD + arr[left]) * arr[left + 1] % MOD;
		        } else {
		            x = arr[left] * arr[left + 1] % MOD;
		        }
		        left += 2;
		    } else {
		        if (arr[right] * arr[right - 1] < 0) {
		            x = (MOD + arr[right - 1]) * arr[right] % MOD;
		        } else {
		            x = arr[right] * arr[right - 1] % MOD;
		        }
		        right -= 2;
		    }
		    ans *= x;
		    k -= 2;
		    ans %= MOD;
		}
		System.out.println(ans);
	}
}


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

int main()
{
    int n,a,b;
    while(~scanf("%d",&n))
    {
        scanf("%d%d",&a,&b);
       if(n==1)
        printf("Hello World\n");
       else if(n==2)
        printf("%d\n",a+b);
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b){
	return (b > 0)? gcd(b, a % b) : a ;
}
long long int lcm(long long int a, long long int b){
	return a / gcd(a, b) * b; 
}
int main(){
	long long A, B; cin >> A >> B; 
	cout << lcm(A, B) << endl; 
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			int[] a = new int[n];
			for(int i=0;i<n;i++) a[i] = sc.nextInt();
			Arrays.sort(a);
			
			int[] b = new int[n];
			int c;
			for(int i=0;i<n;i++){
				c = sc.nextInt();
				for(int j=0;j<c;j++) b[j]++;
			}
			
			c = 0;
			for(int i=0;i<n;i++){
				if(a[i]!=b[n-1-i]){
					c = 1;
					break;
				}
			}
			
			if(c==0) System.out.println("Yes");
			else System.out.println("No");
		}	
	}	
}

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

int func(int n){
    return n%2==0? n/2:3*n+1;
}

int main(){
    int a,i=0;
    scanf("%d",&a);
    while(a){
        if(a==4 || a==2 || a==1) printf("%d",i+4), a=0;
        else a = func(a), i++;
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

   	private static final int DATASET = 30;

    public static void main(String[] args) {
    	
        //input
         Scanner sc = new Scanner(System.in);

         int[] n = new int[DATASET];
         
         int input_size = 0;
         while(sc.hasNext()){
        	n[input_size] = sc.nextInt();
        	input_size++;
         }

         //The maximum is computed.
         int max = 0;
         for(int i=0;i<input_size;i++){
        	 if(max < n[i]){max = n[i];}
         }
         max++;

         boolean prm[] = new boolean[max];
         
         //make prime table
         prm[0] = false;
         prm[1] = false;
         for(int i=2;i<max;i++){prm[i] = true;}
         for(int i=2;i<max;i++){
        	 if(!prm[i]){continue;}
        	 for(int j=i*2;j<max;j+=i){
        		 prm[j] = false;
        	 }
         }

         //make prime count table
         int cnt = 0;
         int[] prm_cnt = new int[max];
         for(int i=0;i<max;i++){
        	 if(prm[i] == true){cnt++;}
        	 prm_cnt[i] = cnt;
         }
         
         //search prime count table　 with input values.
         int[] ans = new int[input_size];
         for(int i=0;i<input_size;i++){
        	 ans[i] = prm_cnt[n[i]];
         }
         
         //output         
         for (int i:ans) {System.out.println(i);}
    }
}

Measured memory_bytes: 27384
N, M = map(int, input().split(' '))

break_list = [list(map(int, input().split(' '))) for _ in range(M)]
break_list = sorted(break_list, key = lambda key:key[1])

result = 1
most_min_right = break_list[0][1]

for i in range(1, M):
    if most_min_right <= break_list[i][0]:
        most_min_right = break_list[i][1]
        result += 1

print(result)

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int x, a, b;
  cin >> x >> a >> b;
  if (b - a <= 0) {
    cout << "delicious";
  }
  else if(b-a<=x){
    cout<<"safe";
  }
  else cout<<"dangerous";
    cout<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n,k;
	cin >> n >> k;
	int arr[n];
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	sort(arr,arr+n);
	int ans=1;
	int mod=1000000007;
	if((k&1) && (arr[n-1]==0)){
		cout << 0 << endl;
		return 0;
	}
	if((k&1) && (arr[n-1]<0)){
		for(int i=n-1;i>=n-k;i--){
			ans=(ans*arr[i]%mod);
			if(ans<0)	ans+=mod;
		}
		cout << ans << endl;
		return 0;
	}
	int low=0,high=n-1;
	if((k&1) && (arr[n-1]>0)){
		ans=(ans*arr[high]%mod);
		if(ans<0)	ans+=mod;
		high--;k--;
	}
	k/=2;
	for(int ii=0;ii<k;ii++){
		if(arr[low]*arr[low+1]>arr[high]*arr[high-1]){
			ans=(ans*arr[low]%mod);
			if(ans<0)	ans+=mod;
			low++;
			ans=(ans*arr[low]%mod);
			if(ans<0)	ans+=mod;
			low++;
		}
		else{
			ans=(ans*arr[high]%mod);
			if(ans<0)	ans+=mod;
			high--;
			ans=(ans*arr[high]%mod);
			if(ans<0)	ans+=mod;
			high--;
		}
	}
	if(ans<0)	ans+=mod;
	ans%=mod;
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 5172
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n=0,m,a,b,c,d,e;
	long double z,w;
	string str,str2,str3;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b>>c;
	cout<<a+b+c-max({a,b,c});





	cout<<endl;
} 


Measured memory_bytes: 256
N, M = map(int, input().split())
m = 0
mi = 100001
for i in range(M):
    L, R = map(int, input().split())
    if L > m:
        m = L
    if R < mi:
        mi = R
if mi-m+1 >= 0:
    print(mi-m+1)
else:
    print(0)


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//Mirror Cave
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int[][] m1 = {{-1,0},{0,1},{1,0},{0,-1}}, m2 = {{-1,0},{0,-1},{1,0},{0,1}};
		for(;;){
			int w = sc.nextInt(), h = sc.nextInt();
			if((w|h)==0)break;
			sc.nextLine();
			char[][] a = new char[h][], b = new char[h][];
			for(int i=0;i<h;i++){
				String[] s = sc.nextLine().split(" ");
				a[i] = s[0].toCharArray(); b[i] = s[1].toCharArray();
			}
			int Li = 0, Lj = 0, Ri = 0, Rj = 0, GLi = 0, GLj = 0, GRi = 0, GRj = 0;
			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				if(a[i][j]=='%'){
					a[i][j] = '.'; GLi = i; GLj = j;
				}
				if(a[i][j]=='L'){
					a[i][j] = '.'; Li = i; Lj = j;
				}
				if(b[i][j]=='%'){
					b[i][j] = '.'; GRi = i; GRj = j;
				}
				if(b[i][j]=='R'){
					b[i][j] = '.'; Ri = i; Rj = j;
				}
			}
			boolean[][][][] u = new boolean[h][w][h][w];
			u[Li][Lj][Ri][Rj] = true;
			List<int[]> l = new ArrayList<int[]>();
			l.add(new int[]{Li, Lj, Ri, Rj});
			String res = "No";
			while(!l.isEmpty()){
				List<int[]> next = new ArrayList<int[]>();
				for(int[] v:l){
					int li = v[0], lj = v[1], ri = v[2], rj = v[3];
					if(li==GLi&&lj==GLj||ri==GRi&&rj==GRj){
						if(li==GLi&&lj==GLj&&ri==GRi&&rj==GRj){
							res = "Yes"; next.clear(); break;
						}
						continue;
					}
					for(int k=0;k<4;k++){
						int nli = li+m1[k][0], nlj = lj+m1[k][1], nri = ri+m2[k][0], nrj = rj+m2[k][1];
						if(!(0<=nli&&nli<h&&0<=nlj&&nlj<w&&a[nli][nlj]=='.')){
							nli = li; nlj = lj;
						}
						if(!(0<=nri&&nri<h&&0<=nrj&&nrj<w&&b[nri][nrj]=='.')){
							nri = ri; nrj = rj;
						}
						if(!u[nli][nlj][nri][nrj]){
							u[nli][nlj][nri][nrj] = true; next.add(new int[]{nli, nlj, nri, nrj});
						}
					}
				}
				l = next;
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

namespace ConsoleApp4
{
    class Sumo
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int k = S.Length;
            int remainChance = 15 - k;
            if (remainChance >= 0)
            {
                string SR = S.Replace("o", "");
                int win = S.Length - SR.Length;
                if(win+remainChance>=8)
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }
            }
            else
            {
                Console.WriteLine("Wrong Records");
            }
        }
    }
}

Measured memory_bytes: 13140
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);
		br.close();

		List<Integer> list = new ArrayList<Integer>();
		int n2 = n;
		int k2 = k;
		list.add(Math.max(n2 - k2 + 1, 0));
		while (k2 > 1) {
			n2 = Math.min(k2 - 1, n);
			k2 = (k2 + 1) / 2;
			list.add(Math.max(n2 - k2 + 1, 0));
		}

		BigDecimal ans = BigDecimal.ZERO;
		for (int i = 0; i < list.size(); i++) {
			BigDecimal bd = BigDecimal.valueOf(list.get(i)).divide(
					BigDecimal.valueOf(Math.pow(2, i)));
			ans = ans.add(bd);
		}
		System.out.println(ans.divide(BigDecimal.valueOf(n), 12, BigDecimal.ROUND_HALF_UP));
	}
}


Measured memory_bytes: 21460
#include<stdio.h>
int main()
{
    int N,i;
    long long sum=0;
    scanf("%d",&N);
    for(i=1;i<=N;i++)
    {
        if(i%3!=0 && i%5!=0)
        {
            sum=sum+i;
        }
    }
    printf("%lld\n",sum);
    return 0;
}




Measured memory_bytes: 2104
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    s = S()
    t = S()
    if s == t[:-1]:
        print("Yes")
    else:
        print("No")
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 76616
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, W; cin >> N >> W;
	vector<int> w(N), v(N); rep(i, 0, N) { cin >> w[i] >> v[i]; }
	vector<vector<int>>x(4, vector<int>(1, 0));
	rep(i, 0, N)x[w[i] - w[0]].emplace_back(v[i]);
	rep(i, 0, 4) {
		sort(1 + all(x[i]), greater<int>());
		rep(j, 1, x[i].size())x[i][j] += x[i][j - 1];
	}
	int ans(0);
	rep(i, 0, x[0].size()) {
		rep(j, 0, x[1].size()) {
			rep(k, 0, x[2].size()) {
				rep(l, 0, x[3].size()) {
					if (i*w[0] + j*(w[0] + 1) + k*(w[0] + 2) + l*(w[0] + 3) <= W)chmax(ans, x[0][i] + x[1][j] + x[2][k] + x[3][l]);
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}

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

const int MAX_ANS = 10000000;
int M, N;
bool is_prime[MAX_ANS];

int main(){
    while(cin >> M >> N, M|N){
        memset(is_prime, -1, sizeof(is_prime));
        
        int k = M;
        for(int i=0; i<N+1; i++){
            while(!is_prime[k])k++;
            
            for(int j=k; j<MAX_ANS; j+=k)
                is_prime[j] = false;
        }
        cout << k << endl;
    }
    return 0;
}

Measured memory_bytes: 12776
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n;
ll a[310][310];
ll ans;
ll check(ll x,ll y)
{
        bool f = false;
        for(ll i=1;i<=n;i++)
        {
                if(a[x][i] + a[i][y] < a[x][y]){
                        return -1;
                }
                if(i == x || i == y) continue;
                if(a[x][i] + a[i][y] == a[x][y]){
                        f = true;
                }
        }
        if(f) return 0;

        return 1;
}
int main()
{
        cin >> n;
        for(ll i=1;i<=n;i++)
        {
                for(ll j=1;j<=n;j++){

                        cin >> a[i][j];
                }
        }
        for(ll i=1;i<=n;i++)
        {
                for(ll j=1;j<=n;j++)
                {
                        if(check(i,j) == -1){
                                cout << "-1\n"; return 0;
                        }
                }
        }
        for(ll i=1;i<=n;i++)
        {
                for(ll j=1;j<=n;j++)
                {
                        if(check(i ,j) == 1){
                                ans += a[i][j];
                        }
                }
        }
        cout << ans / 2 << endl;
        return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    vector<string> v(N,"yet");
    cout << 0 << endl;
    cin >> v[0];
    int l = 0;
    int r = N;
    for(int i_ = 1; i_ <= 19; i_++){
      if(l >= r)l += N;
      cerr << l << " " << r << endl;
      int mid = (l + r) / 2;
      cout << mid << endl;
      cin >> v[mid];
      if(v[mid] == "Vacant")return 0;
      //偶奇同じ
      if(l % 2 == mid % 2){
        //異なったら、この中にある
        if(v[l] == v[mid])l = mid;
        else r = mid;
      }
      //偶奇が異なる
      else{
        //同じだったら、この中にある
        if(v[l] == v[mid]){
          r = mid;
        }
        else l = mid;
      }
    }
}

Measured memory_bytes: 1620
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
const int MOD = 1e9+7;
const int MOOD = 998244353;
typedef long long ll;
#define PI 3.14159265359
using namespace std;


int main(){
	int x;
	cin >> x;
	if (x < 600) cout << 8 << endl;
	else if (x < 800) cout << 7 << endl;
	else if (x < 1000) cout << 6 << endl;
	else if (x < 1200) cout << 5 << endl;
	else if (x < 1400) cout << 4 << endl;
	else if (x < 1600) cout << 3 << endl;
	else if (x < 1800) cout << 2 << endl;
	else cout << 1 << endl;
	return 0;
}

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

pair<int, int> compless(int d, int c){
	pair<int, int> res;
	if(c == 1){
		return pair<int, int>(d, 0);
	}
	else if(c % 2 == 0){
		if(d < 5){
			res = compless(2 * d, c / 2);
			return pair<int, int>(res.first, c / 2 + res.second);
		}
		else{
			int dd = (2 * d) / 10 + (2 * d) % 10;
			res = compless(dd, c / 2);
			return pair<int, int>(res.first, c + res.second);
		}
	}
	else{
		res = compless(d, c - 1);
		int d1 = res.first;
		if(d + d1 < 10){
			return pair<int, int>(d + d1, 1 + res.second);
		}
		else{
			int dd = (d + d1) / 10 + (d + d1) % 10;
			return pair<int, int>(dd, 2 + res.second);
		}
	}
}

signed main(){
	int M, i;
	scanf("%lld", &M);
	vector<int> d(M), c(M), a(M);
	int ans = 0;
	for(i = 0; i < M; i++){
		scanf("%lld%lld", &d[i], &c[i]);
		pair<int, int> res = compless(d[i], c[i]);
		a[i] = res.first;
		ans += res.second;
	}
/*	for(i = 0; i < M; i++){
		printf("a[%lld] = %lld\n", i, a[i]);
	}
	printf("ans = %lld\n", ans);
*/	for(i = M - 1; i > 0; ){
		if(a[i] + a[i - 1] < 10){
			a[i - 1] += a[i];
			i--;
		}
		else{
			int sub = a[i] + a[i - 1];
			a[i - 1] = sub / 10;
			a[i] = sub % 10;
		}
		ans++;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 5504
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
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;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int N, M;
using Graph = vector<vector<int>>;

int memo[110000];

int dfs(Graph &G, int p) {
  if (memo[p] != -1) return memo[p];

  int ans = -1;

  for (auto np: G[p]) {
    memo[np] = dfs(G, np);
    chmax(ans, dfs(G, np));
  }

  return ans + 1;
}

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

  Graph G(N+1);

  rep(i, M) {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
  }

  rep(i, N) {
    memo[i] = -1;
  }

  rep(i, N) {
    memo[i] = dfs(G, i);
  }

  int ans = 0;
  rep(i, N) {
    //cout << memo[i] << "\n";
    chmax(ans, memo[i]);
  }
  cout << ans << "\n";
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define ll long long
using namespace std;
/*int max(int arr[]){
	for(int i=0;i<k;i++){
		
	}
}*/
int main() {
	ll n,k;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll dp[n];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	ll m;
	for(ll i=2;i<n;i++){
		m=9999999999;
		for(ll j=1;j<=min(k,i);j++){
			m=min(m,abs(a[i]-a[i-j])+dp[i-j]);
		}
		dp[i]=m;
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll factorial(ll a){return a < 2 ? 1 : factorial(a - 1) * a;}
ll summation(ll a){return a < 1 ? 0 : (a * a + a) / 2;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ll N = 200005;
const ll M = 100005;
const string ALPHABETS = "abcdefghijklmnopqrstuvwxyz";
ll dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
//ll dx[] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
ll n, m, x, y, z, w, h;
string s, t;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> s){
        ll ans = INF, tmp = 0, cnt = 0, mx = -INF, mn = INF;
        ll a[N] = {}, b[N] = {}, c[N] = {};
        vll v;
        each(c, ALPHABETS){
            ll last = -1;
            cnt = 0;
            rep(i, s.size()){
                if(s[i] == c){
                    maxs(cnt, i - 1 - last);
                    last = i;
                }
            }
            maxs(cnt, ll(s.size() - 1 - last));
            mins(ans, cnt);
        }
        print(ans);
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int n;
  int a,b,c;
  int k;
  scanf("%d",&n);
  for(k=1;k<=n;k++){
    scanf("%d %d %d",&a,&b,&c);
    if(a*a+b*b==c*c||b*b+c*c==a*a||c*c+a*a==b*b){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 580
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int r = Integer.parseInt(sc.next());
	int g = Integer.parseInt(sc.next());
	int b = Integer.parseInt(sc.next());
	int n = Integer.parseInt(sc.next());
	int cnt = 0;
	for(int i = 0; i<=n; i++) {
	    for(int j = 0; j<=n; j++) {
		if((n-r*i-g*j )%b==0 && (n-r*i-g*j ) >= 0) {
		    cnt++;
		}
	    }
	}

	System.out.println(cnt);

    }
}

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




int main(){
  string S;
  cin >> S;
  string key = "keyence";

  // なんばんめから挿入されているか
  int num = 7;
  for(int i=0;i<key.length();++i){
    if(key[i]!=S[i]){
      num = i;
      break;
    }
  }
  // 先頭から全一致
  if(num==7){
    cout << "YES" << endl;
    return 0;
  }

  // 一個も先頭から一致してなければ後ろから数えて七個が
  for(int i=num;i < key.length();++i){
    if(S[S.length()-1-(6-i)]!=key[i]){
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;

  return 0;
}

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

int main()
{
  long long n;
  cin >> n;
  long long b = n;
//  long long a = 1;
  long long ansa = 1, ansb = n;
  long long x = n;
  for(long long i=2; i<=x; i++){
      if(b%i == 0 && i+(b/i) < ansa+ansb){
          ansa = i;
          ansb = b/i;
      }
    x = n/i;
  }
  long long ans = ansa + ansb - 2;
  
  cout << ans << endl;

}


Measured memory_bytes: 256
N = int(input())
B = [int(x) for x in input().split()]

ans = [0] * N
ans[0] = B[0]
for i in range(len(B)):
  ans[i + 1] = B[i]
  if B[i] < ans[i]:
    ans[i] = B[i]
  elif B[i] < ans[i + 1]:
    ans[i+1] = B[i] 
  
print(sum(ans))

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#include<string.h>
typedef long long lli;
int max(int a,int b){
   if(a>b) return a;
   return b;
}
int min(int a,int b){
   if(a<b) return a;
   return b;
}
void sort(char *a,int l){
    for(int i=0;i<l;i++){
       for(int j=i+1;j<l;j++){
          char t;
         if(a[i]>a[j]) {
            t=a[i];
            a[i]=a[j];
            a[j]=t;
         }

       }
    }


}
void rot(char *a,int l){
     char t=a[0];
   for(int i=1;i<l-1;i++){
      a[i-1]=a[i];
   }
   a[l-1]=t;
}

int main(){
   lli n,a,s=0;
   scanf("%lld",&n);
   for(lli i=0;i<n;i++){
      scanf("%lld",&a);
      s+=a;
   }
   printf("%lld",s-n);
}
   
   
   
   
   

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

using namespace std;

//#define endl '\n'
#define all(v) (v).begin(),v.end()
#define rall(v) (v).rbegin(),v.rend()
#define sz(v) (int)(v).size()
#define oo 1e15

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<string> vs;

int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#ifdef LOCAL
  freopen("test.in", "rt", stdin);
//  freopen("o.txt", "wt", stdout);
#endif
  vector<pair<pi, int>> v;
  int st = 8;
  for (int i = 400; i < 2000; i += 200) {
    v.push_back({{i, i + 199}, st--});
  }
  int x;
  cin >> x;
  for (auto k : v) {
    if (x >= k.first.first && x <= k.first.second) {
      return cout << k.second << endl, 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main(){
	int h,w,s;
	while(true){
	cin>>h>>w;
	if(h==0&&w==0)
		break;
	bool t=true;
	s=h*h+w*w;
	h++;
	while(true){
		if(h*h>=s-h*h)
			break;
		if(s==h*h+(int)sqrt((double)s-h*h+0.0)*(int)sqrt((double)s-h*h+0.0)){
			t=false;
			break;
		}
		h++;
	}
	s++;
	if(t==true){
	while(true){
		h=1;
		while(true){
		if(h*h>=s-h*h)
			break;
		if(s==h*h+((int)sqrt((double)s-h*h+0.0)*(int)sqrt((double)s-h*h+0.0))){
			t=false;
			break;
		}
		h++;
		}
		if(t==false)
			break;
		s++;
	}
	}
	cout<<h<<" "<<(int)sqrt((double)s-h*h+0.0)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	stdin.Split(bufio.ScanWords)
	A := nextInt()
	B := nextInt()
	fmt.Println((B + A - 3) / (A - 1))
}

func nextInt() int {
	stdin.Scan()
	i, err := strconv.Atoi(stdin.Text())
	if err != nil {
		panic(err)
	}
	return i
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
  int N, X;
  int min = 9999, sum = 0;
  scanf("%d %d", &N, &X);

  for (int i = 0; i < N; i++) {
    int m;
    scanf("%d", &m);
    sum += m;
    if (m < min) min = m;
  }
  printf("%d\n", N + (X - sum)/min);

  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    static ArrayList<Long> l=new ArrayList<>();
    static Map<Long,Integer> map;
    static long[]aa;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long n=Long.parseLong(sc.next());
        long po=n;
        long ans=0;
       map=new HashMap<>();
       
        for(long i=2;i*i<=n;i++){
            while(n%i==0){
                if(map.containsKey(new Long(i))){
                    map.put(i,map.get(i)+1);
                }
                else {
                    map.put(i,1);
                }
                n/=i;
            }
        }
        if(n!=1)map.put(n,1);
        aa=new long[map.size()];
        int index=0;
        for(Long key:map.keySet()){
            aa[index++]=key;
        }
        popo(map.size()-1,1);
        
        Collections.sort(l);
        for(int i=0;i<l.size()/2;i++){
            long a=Long.parseLong(l.get(l.size()-1-i)+"")-1;
            if(po%a==po/a)ans+=a;
        }
        System.out.println(ans);
    }
    public static void popo(int size,long value){
        if(size<0){
            l.add(value);
        }
        else{
            for(int i=0;i<Integer.parseInt(map.get(aa[size])+"");i++){
            if(i==0){
                popo(size-1,value);
            }
            popo(size-1,value*aa[size]);
            value*=aa[size];
        }
        }
    }
}


Measured memory_bytes: 23632
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;

const long long INF = 1e18;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    int si, sj, ti, tj;
    cin >> si >> sj >> ti >> tj;
    --si; --sj; --ti; --tj;

    vector<string> g(h);
    for(int i=0; i<h; ++i) cin >> g[i];

    auto toId = [&](int i, int j, int v){
        return (i*w+j)*4 +v;
    };

    auto modCeil = [&](long long x){
        //kで割って切り上げ
        return (x+k-1)/k*k;
    };

    vector<long long> dist(h*w*4, INF);

    priority_queue< pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > >q;
    auto push = [&](int i, int j, int v, long long x){
        int id = toId(i, j, v);
        if(dist[id] <= x)return;
        dist[id] = x;
        q.emplace(x, id);
    };

    //init
    for( int v=0; v<4; ++v){
        push(si, sj, v, 0);
    }

    //djikstra
    while(!q.empty()){
        long long d = q.top().first;
        int id = q.top().second;
        q.pop();
        //もし距離が更新されたあとに更新してないとpriorityqueueに残るので、それを飛ばす
        if(dist[id] != d)continue;
        int i = id/w/4;
        int j = id/4%w;
        int v = id%4;
        
        //向きを変える
        for(int nv = 0; nv<4; ++nv){
            push(i, j, nv, modCeil(d));
        }

        //同じ向きに進む
        int ni = i+di[v];
        int nj = j+dj[v];
        //範囲内かつ
        if( 0 <= ni && ni <h && 0<= nj && nj < w){
            //障害物じゃない
            if(g[ni][nj] == '.'){
                push(ni, nj, v, d+1);
            }
        }
    }

    long long ans = INF;
    for(int v=0; v<4; ++v){
        ans = min(ans, dist[toId(ti,tj,v)]);
    }
    if(ans == INF){
        cout << -1 << endl;
    }else{
        ans = modCeil(ans)/k;
        cout << ans << endl;
    }


}

Measured memory_bytes: 44112
#include <stdio.h>

int main(void) {
	int n,x,a=0,ans=1;
	scanf("%d%d",&n,&x);
	int l[n];
	for(int i=0;i<n;i++){
		scanf("%d",&l[i]);
		a+=l[i];
		if(a<=x)
		ans+=1;
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;



int main(void){
    ll n, d; cin >> n >> d; ll ans;
    if(n%(2*d+1) == 0)ans = n/(2*d+1);
    else ans = 1 + n/(2*d+1);
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int A[N],n,cnt,mx,mn;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;++i)
        scanf("%d",A+i);
    mn=A[0];
    for(int i=1;i<n;++i){
        if(A[i]<=mn){
            mx=max(++cnt,mx);
            mn=A[i];
        }else{
        cnt=0;
        mn=A[i];
        }
    }
    printf("%d",mx);


    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int ans=0;
  for(int i=1;i<=N;i++){
    if(i%2==1){
      ans++;
    }
  }
  double d=(double)ans/N;
  cout<<d<<endl;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int n,m,a,b;
int main()
{
    scanf("%d%d%d%d",&n,&m,&a,&b);
    rep(i,1,n){
        rep(j,1,m){
            if((i<=b&&j<=a)||(i>b&&j>a)) putchar('1');
            else putchar('0');
        }
        putchar('\n');
    }
    return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int A, B, C, K;
	scanf("%d %d %d %d", &A, &B, &C, &K);
	int max_sum = 0;
	while (K--) {
		if (A) {
			max_sum++;
			A--;
		}
		else if (B) {
			B--;
		}
		else if (C) {
			max_sum--;
			C--;
		}
	}
	printf("%d\n", max_sum);
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
bool compx(pair<int, int> a, pair<int, int> b) {
    return a.first < b.first;
}
bool compy(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<pair<int, int>> r(n), b(n);
    for (int i = 0; i < n; i++) {
        int x, y; cin >> x >> y;
        r[i] = pair<int, int>(x, y);
    }
    for (int i = 0; i < n; i++) {
        int x, y; cin >> x >> y;
        b[i] = pair<int, int>(x, y);
    }
    sort(b.begin(), b.end(), compx);
    sort(r.begin(), r.end(), compx);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int maxy = b[i].second;
        int idx = -1, ry = -1;
        int len = -1;
        while (len + 1 < n && r[len + 1].first < b[i].first) len++;
        if (len == -1) continue;
        for (int j = 0; j <= len; j++) {
            if (r[j].second < maxy) {
                if (r[j].second > ry) {
                    ry = r[j].second;
                    idx = j;
                }
            }
        }
        if (idx == -1) continue;
        ans++;
        r[idx].second = 1e9;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    double n = sc.nextDouble();
    double ans;

    if(n % 2 == 0){
      ans = (n / 2) / n;
    } else {
      ans = (((int)(n) / 2) + 1) / n;
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 23124
#include<stdio.h>

int dp[100][256][101];
long long mod,p[101];

int main(){
	int n,k,i,a[255],j,ii;
	long long sum=0;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	mod=1000000007;
	p[0]=1;
	for(i=1;i<=n;i++){
		p[i]=i*p[i-1];
		p[i]%=mod;
	}
	dp[0][0][0]=1;
	dp[0][a[0]][1]=1;
	for(i=1;i<n;i++){
		for(j=0;j<256;j++){
			for(ii=0;ii<i+1;ii++){
				dp[i][j][ii+1]+=dp[i-1][j^a[i]][ii];
				dp[i][j][ii+1]%=mod;
				dp[i][j][ii]+=dp[i-1][j][ii];
				dp[i][j][ii]%=mod;
			}
		}
	}
	for(i=1;i<=n;i++){
		sum+=dp[n-1][k][i]*p[i];
		sum%=mod;
	}
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 10240
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
set<int> s;
int main()
{
    int n; scanf("%d", &n);
    int cnt = 0;
    for(int i = 0; i < n; i++){
        int a; scanf("%d", &a);
        if(s.find(a) == s.end()){
            s.insert(a);
            cnt++;
        }else{
            s.erase(a);
            cnt--;
        }
    }
    printf("%d\n", cnt);
    return 0;
}


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

using namespace std;

//#define FILE_IO

typedef long long LL;

int N, X;
int v[2005];
int mn[2005][2005];
LL ans;

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d", &N, &X);
    for(int i = 1; i <= N; i++)
        scanf("%d", &v[i]);

    for(int i = 1; i <= N; i++)
    {
        int m = 1 << 30;
        for(int j = i; j <= N; j++)
        {
            m = min(m, v[j]);
            mn[i][j] = m;
        }
        for(int j = 1; j < i; j++)
        {
            m = min(m, v[j]);
            mn[i][j] = m;
        }
    }

    ans = 1LL << 60;
    for(int k = 0; k < N; k++)
    {
        LL pans = 1LL * k * X;
        for(int i = 1; i <= N; i++)
        {
            int dr = i;
            int st = i - k;
            if(st <= 0) st += N;
            pans += mn[st][dr];
        }
        ans = min(ans, pans);
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout<<fixed;cout<<setprecision(10);
#define in cin>>
#define out cout<<
#define br cout<<"\n";

void solve(){
    string s,t;
    cin>>s;
    cin>>t;
    int count=0;
    for(int i=0;i<s.length();i++){
        if(s[i]!=t[i]){
            count++;
        }
    }
    cout<<count<<"\n";
}

int32_t main(){
    FASTIO
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    #endif

    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    #ifndef ONLINE_JUDGE
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
    #endif

    return 0;
}

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

#define gc( ) std::getchar( )
#define pc( i ) std::putchar( i )
#define RE cout << "Passing [" << __FUNCTION__ << "] on " << __LINE__ << '\n'
#define DEBUG(...) for( auto &i: __VA_ARGS__ ) cout << i << " "; cout << '\n'
#define space ' '
#define enter '\n'
using std::make_pair;

template < typename T >
inline T read( )
{
 T x = 0;
 char ch = gc( );
 bool f = 0;
 while( !std::isdigit( ch ) )
 {
  f = ( ch == '-' );
  ch = gc( );
 }
 while( std::isdigit( ch ) )
 {
  x = x * 10 + ( ch - '0' );
  ch = gc( );
 }
 return f ? -x : x;
}

template < typename T >
void print( T x )
{
 if( x < 0 )
 {
  x = -x;
  pc( '-' );
 }
 if( x < 10 )
 {
  pc( x + 48 );
  return;
 }
 print < T > ( x / 10 );
 pc( x % 10 + 48 );
 return ;
}

namespace Solution
{
#define IOS std::ios::sync_with_stdio( false ), std::cin.tie( 0 ), std::cout.tie( 0 )
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
#define rdi( ) read < int > ( )
#define rdl( ) read < long long > ( )
#define pti( i ) print < int > ( i ), putchar( space )
#define ptl( i ) print < long long > ( i ), putchar( space )
#define For( i, j, k ) for( int i = j; i <= k; ++i )
 using std::cin;
 using std::cout;
 using std::endl;
 using std::vector;
 using std::map;
 using std::queue;
 using std::deque;
 using std::set;
 using std::pair;
 const int N = 204001, mod = 1e9 + 7;
 int n;
 char c[ N ];
 void Fakemain( )
 {
  IOS;
  cin >> n >> c + 1;
  int m = n, ans = 0;
  For( i, 1, n )
  {
   while( m > i && c[ m ] == 'W' )
    m--;
   if( m <= i )
     break;
   if( c[ i ] == 'R' )
    continue;
   else
   {
    std::swap( c[ i ], c[ m-- ] );
    while( m > i && c[ m ] == 'W' )
     m--;
    ans++;
   }
  }
  cout << ans;
  return;
 }

} // namespace Solution

int main( int argc, char* argv[] )
{
 Solution::Fakemain( );
 return 0;
}

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

int main()
{
	char str[11];
	int flag1 = 0,flag2=0,flag3=0;
	cin >> str;
	int num = strlen(str);

	if (str[0]!='A')
	{
		flag1 = 1;
	}
	for (int i = 2; i < num-1; i++)
	{
		if (str[i]=='C')
		{
			flag2 += 1;
		}
	}
	for (int i = 1; i < num; i++)
	{
		if (str[i]!='C')
		{
			if (isupper(str[i]))
			{
				flag3=1;
			}
		}
	}
	if (flag1 == 1 || flag2 == 0 || flag2 > 1 || flag3 == 1)
	{
		cout << "WA" << endl;
	}
	else
	{
		cout << "AC" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>

using namespace std;

int main()
{
  char str[27]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  string s;
  int n;
  cin>>n;
  cin>>s;
  int i,j;
  for( i=0;i<s.length();i++){
    for (j = 0; j < 26; j++){
      if (s[i] == str[j]) break;
	}
    cout<<str[(j+n)%26];
  }
  cout<<endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	string s;
	int a=0, b=0, c=0, m;
	cin >> s;
	for(char sc: s){
		if(sc == 'a') ++a;
		else if(sc == 'b') ++b;
		else ++c;
	}
	m = max({a,b,c});
	string ans = "YES";
	if(a > m || a < m-1) ans = "NO";
	if(b > m || b < m-1) ans = "NO";
	if(c > m || c < m-1) ans = "NO";
	
	cout << ans;
}


Measured memory_bytes: 512
from collections import defaultdict

while 1:
    ws, hs, w, h = defaultdict(int), defaultdict(int), [], []
    n, m = map(int, raw_input().split())
    if n|m == 0: break

    for i in range(n):
        t = s = input()
        ws[s]+=1
        for pw in reversed(w):
            s+=pw
            ws[s]+=1
        w.append(t)

    for i in range(m):
        t = s = input()
        hs[s]+=1
        for pw in reversed(h):
            s+=pw
            hs[s]+=1
        h.append(t)

    print sum(ws[a] * hs[a] for a in ws if a in hs)

Measured memory_bytes: 53180
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int MAX=100005;
struct entry{
	int f,s;
	long long int label;
} edge[MAX];
vector<int> llist[MAX];
int visited[MAX],n;
long long int weight[MAX];
void dfs(int v)
{
	visited[v]=1;
	int parent=0;
	long long int sum=0;
	for(int i=0;i<llist[v].size();++i){
		int temp=llist[v][i];
		int vertex;
		if(edge[temp].f!=v) vertex=edge[temp].f;
		else vertex=edge[temp].s;
		if(visited[vertex]==0){
			dfs(vertex);
			sum+=edge[temp].label;
		}
		else{
			parent=temp;
		}
	}
	if(llist[v].size()==1&&v!=1) edge[llist[v][0]].label=weight[v];
	else if(parent!=0){
		edge[parent].label=weight[v]*2-sum;
	}
}
int main()
{
	int a,b;
	cin>>n;
	for(int i=1;i<=n;++i) cin>>weight[i];
	for(int i=1;i<n;++i){
		cin>>a>>b;
		edge[i].f=a;
		edge[i].s=b;
		edge[i].label=0;
		llist[a].push_back(i);
		llist[b].push_back(i);
	}
	dfs(1);
	if(llist[1].size()==1){
		if(weight[1]!=edge[llist[1][0]].label){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	else{
		long long int sum=0;
		for(int i=0;i<llist[1].size();++i){
			sum+=edge[llist[1][i]].label;
		}
		if(sum!=weight[1]*2){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	for(int i=1;i<n;++i){
		if(edge[i].label<0){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	for(int i=1;i<=n;++i){
		if(llist[i].size()>1){
			long long int maximum=edge[llist[i][0]].label;
			long long int sum=edge[llist[i][0]].label;
			for(int j=1;j<llist[i].size();++j){
				sum+=edge[llist[i][j]].label;
				maximum=max(maximum,edge[llist[i][j]].label);	
			} 
			if(maximum>sum/2){
				cout<<"NO"<<endl;
				return 0;
			}
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 16512
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

s=input().rstrip("\n")
if s=="ABC":
    print("ARC")
else:
    print("ABC")

Measured memory_bytes: 8992
#include<bits/stdc++.h>
#define mod 1000000007
#define MOD(x) ((x)%mod)
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
using namespace std;
int n,k;
int h[100005],dp[100005];
int main()
{
	scanf("%d%d",&n,&k);
	memset(dp,64,sizeof dp);
	dp[1]=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&h[i]);
		for(int j=1;j<=k;j++)
			if(i-j>=1)
				dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
	}
	printf("%d",dp[n]);
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define DEBUG(x)        do { std::cerr << #x << " = " << x << std::endl;  } while(0)
#define DEBUGV(x)       for(auto e : x) { std::cerr << e << " "; }; cout << endl;
#define INFO(msg)       do { std::cerr << msg << std::endl; } while(0)
#define ll              long long
#define vi              vector<int>
#define pii             pair<int, int>
#define fori(i, s, e)   for(int i = s; i < e; i++)
#define ford(i, s, e)   for(int i = s; i >= e; i--)
 
using namespace std;

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

    int n, x, s = 0;

    cin >> n >> x;
    vi v(n, 0);

    fori(i, 0, n) {
        cin >> v[i];
    }

    sort(v.begin(), v.end());

    for(auto el : v) {
        if(x >= el) {
            x-= el;
            s++;    
        }
    }

    int l;
    fori(i, 0, n) {
        l = x / v[i];
        s += l;
        x -= l * v[i];
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3612