akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int a = scanner.nextInt();
        String s = scanner.next();

        int max = 0;
        String bef;
        String aft;

        for (int i = 0;i<a;i++) {
        	bef = s.substring(0, i+1);
        	aft = s.substring(i+1,s.length());
        	int cnt = 0;

        	String[] bef2 = bef.split("");
        	Set<String> hash_set = new HashSet<String>();
        	/*
        	for(String tmp : bef2) {
        		hash_set.add(tmp);
        	}
        	*/
        	for(int j=0;j<bef2.length;j++) {
        		hash_set.add(bef2[j]);
        	}
        	/*
        	for(String tmp : hash_set){
        		if(aft.contains(tmp)) {
        			cnt++;
        		}
        	}
        	*/
        	Iterator<String> iterator = hash_set.iterator();
        	for (int k=0;k<hash_set.size();k++) {
        		if(aft.contains(iterator.next())) {
        			cnt++;
        		}
        	}
        	if (cnt >= max) {
        		max = cnt;
        	}
        }
        System.out.println(max);

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using v  = vector<int>;
using vv = vector<v>;
const int MOD = 1000000007;

const ll INF = 1001001001001;

int main(){
    int n,m;cin>>n>>m;
    cout << n*m << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

const int MOD = 1000000007;
const int INF = 1 << 29;
const double EPS = 1e-9;


int main() {

	cin.tie(0);

	int N, K;
	cin >> N >> K;

	vector<int> a(N);
	FOR(i, 0, N) cin >> a[i];

	sort(a.begin(), a.end(), greater<int>());
	for (const auto &ele : a) DMP(ele);
	int sum = INF, st = 0, cnt = 0, ans = N;

	while (true) {

		sum = 0;
		cnt = 0;
		bool flag = true;

		while (st + cnt < N) {
			sum += a[st + cnt];
			cnt++;
			if (sum >= K) {
				flag = false;
				break;
			}
		}if (flag) break;

		while (sum >= K) {
			
			ans = min(ans, N - st - cnt);
			sum -= a[st + cnt - 1];
			if (st + cnt < N) {
				sum += a[st + cnt];
			}
			else break;
			cnt++;
		}
		
		st++;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
x,y,z,k=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
b=sorted(list(map(int,input().split())),reverse=True)
c=sorted(list(map(int,input().split())),reverse=True)

ab=[i+j for j in b for i in a]
ab.sort(reverse=True)
abc=[i+j for j in c[:k] for i in ab[:k]]
abc.sort(reverse=True)

print(*abc[:k],sep='\n')


Measured memory_bytes: 208068
{-# LANGUAGE BangPatterns #-}

import Data.Bits
import Data.List
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Data.Coerce

primes :: [Int]
primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]

-- given (p:prime) (n:nat), returns maximal e with p^e | n! 
exponentInFactorial :: Int -> Int -> Int
exponentInFactorial p = loop 0
  where
    loop !acc n | n < p = acc
    loop !acc n = loop (acc + n') n'
      where n' = n `div` p

query :: Int -> Int
query n =
  x74
  + x24 * (x2-1)
  + x14 * (x4-1)
  + ((x4 * (x4-1)) `div` 2) * (x2-2)
  where
    expts = (`exponentInFactorial` n) <$> primes
    x74 = length $ filter (>= 74) expts
    x24 = length $ filter (>= 24) expts
    x14 = length $ filter (>= 14) expts
    x4 = length $ filter (>= 4) expts
    x2 = length $ filter (>= 2) expts

main :: IO ()
main = getLine >>= putStrLn . show . query . read

Measured memory_bytes: 508
let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {
	
	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	
	let [a, b] = inputReader.readArray();
	//console.log(typeof c);
	a = parseInt(a);
	b = parseInt(b);
	//c = parseInt(c);
	let arr = [];
	for(let i=0;i<a;i++){
		let str = inputReader.readLine();
		arr.push(str);
	} 
	arr.sort();
	let res='';
	for (let array of arr){
		res+=array;
	} 
	console.log(res);
	
	
	// let input = inputReader.readLine().split(' ');
	// let a = input[0];
	// let b = input[1];
	// //let b = inputReader.readLine().split('');
	// //console.log(a,b);
	
	// let res = '';
	// for(let i=0;i<size;i++){
	//     res +=a[i];
	//     res+=b[i];
	// }
	// console.log(res);
	
	//console.log(noOfTestCases,typeof noOfTestCases);
	// while(noOfTestCases--){
	//     let [a,b] = inputReader.readNumberArray();
	//     let count = 1;
	//     if(a<=2){
	//         console.log(1);
	//         continue;
	//     }
	//     let floor;
	//     if((a-2)%b===0)
	//         floor = (a-2)/b +1;
	//     else
	//          floor = Math.ceil((a-2)/b)+1;
	//     console.log(floor);
	
	// }

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readArray() {
		return _inputLines[_lineNumber++].split(' ');
	}
		
	function readLine(){
		return _inputLines[_lineNumber++];
	}
		
	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}
		
	
	return {
		readArray,
		readLine,
		readNumberArray,
	}
}

Measured memory_bytes: 30916
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned char uchar;
#define umap unordered_map
const static ull INVALID_DIGIT = ~(ull)0;

int main()
{
    int a, b, c, d, e, K;

    cin >> a >> b >> c >> d >> e >> K;

    auto maxDist = e - a;

    if (maxDist > K) {
        cout << ":(" << endl;
    }
    else {
        cout << "Yay!" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
from collections import deque


N, M = map(int, input().split()) 
operation = [[1, card] for card in map(int, input().split())]

for _ in range(M):
    operation.append(list(map(int, input().split())))

operation.sort(key=lambda x:x[1], reverse=True)
operation = deque(operation)

maximum = 0
for _ in range(N):
    maximum += operation[0][1]
    operation[0][0] -= 1
    if operation[0][0] == 0:
        operation.popleft()

print(maximum)


Measured memory_bytes: 45048
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,c;
    cin >> a >> b >> c;
    cout << (a+b==c || b+c==a || c+a==b ? "Yes":"No") << endl;
}


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

#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std; 

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

	string s;
	cin>>s;

	for(int i=0;i<s.size();i++){
		s[i]='A'+((s[i]-'A')+n)%26;
	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String Sd = sc.next();
    String T = sc.next();
    
    String ans = "UNRESTORABLE";
    for (int i = Sd.length() - T.length(); i >= 0; i--) {
      if (match(Sd, i, T)) {
        ans = fill(Sd, i, T);
        break;
      }
    }
    
    System.out.println(ans);
  }
  
  private static boolean match(String Sd, int i, String T) {
    for (int j = 0; j < T.length(); j++) {
      char c = Sd.charAt(i+j);
      if (c != T.charAt(j) && c != '?') {
        return false;
      }
    }
    return true;
  }
  
  private static String fill(String Sd, int i, String T) {
    StringBuilder builder = new StringBuilder();
    for (int j = 0; j < Sd.length(); j++) {
      if (i <= j && j < i + T.length()) {
        builder.append(T.charAt(j-i));
      } else {
        char c = Sd.charAt(j);
        if (c == '?') {
          builder.append("a");
        } else {
          builder.append(c);
        }
      }
    }
    return builder.toString();
  }
}

Measured memory_bytes: 23764
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>
#include <limits>

using namespace std;

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  int days[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
  if (b == days[a - 1]) {
    printf("1\n");
  } else {
    printf("0\n");
  }
  return 0;
}


Measured memory_bytes: 128
//Let's play once again :)
#include<bits/stdc++.h>
using namespace std;

#define tarzan ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long 

int rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
int cc[] = {1, 1, 0, -1, -1, -1, 0, 1};

const int mod = 1e9 + 7;
const int N = 300050;

signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    tarzan;
    int test = 1;
    //cin >> test;
    while(test--) {
        char ch;
        cin >> ch;

        if(ch >= 'A' && ch <= 'Z') {
            cout << 'A';
        }
        else cout << 'a';
    }
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl;
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

int main() {
	int k, s;
	cin >> k >> s;

	int ans = 0;
	for (int x = 0; x <= k; x++)for (int y = 0; y <= k; y++) {
		ans += (k >= s-x-y && s-x-y >= 0) ? 1 : 0;
	}
	puts(ans)
	
	return 0;
}


Measured memory_bytes: 256
#include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include "algorithm"


using namespace std;
#define fori0(G) for(int i=0;i<G;i++)
#define fori1(G) for(int i=1;i<=G;i++)
#define forj0(G) for(int j=0;j<G;j++)
#define forj1(G) for(int j=1;j<=G;j++)
#define fork0(G) for(int k=0;k<G;k++)
#define fork1(G) for(int k=1;k<=G;k++)
int dx[] = { -1,0,1,0 ,0 }, dy[] = { 0,1,0,-1,0 };
#define nxnycon (0<=nx&&nx<h&&0<=ny&&ny<w) 


#define lo long long int



int main() {
	int n,c=0,i=1,t=1;
	cin >> n;
	//printf("%f",5.0 / 2.0);
	while (c < n) {
		int p = 1;
		i = 10 * t + 1;
		//cout << floor(sqrt(i));
		for(int j=2;j<=(floor(sqrt(i)));j++) {
			//printf("(%d,%d,%f)\n", i, j, (floor((double)i / (double)j) - ((double)i / (double)j)));
			if ((floor((double)i / (double)j) - ((double)i / (double)j)) ==0) { p=0; }
		}
		if (p) { cout << i<<" " ;c++; }
		//c++;
		t++;
	}
	//system("pause");
	return 0;

}



Measured memory_bytes: 256
import sys

if __name__ == '__main__':
    S = str(input())

    X = []

    for i in range(len(S)):
        if i == len(S)-1:
            X.append(int(S[i]))
        elif i == len(S)-2:
            X.append(int(S[i])*10+int(S[i-1]))
        else:
            X.append(int(S[i])*100+int(S[i+1])*10+int(S[i+2]))

    answer = sys.maxsize
    for x in X:
        if abs(x-753) < answer:
            answer = abs(x-753)

    print(answer)

Measured memory_bytes: 3064
//*
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <functional>
#define MOD 1000000007
#define MAX 0x3f3f3f3f
#define MAX2 0x3f3f3f3f3f3f3f3fll
#define ERR 1e-10
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

int n, m;
char a[10][10];

int check[10][10];

int main()
{
	int i, j, k, l;
	cin>>n>>m;
	int cnt=0;
	for(i=0;i<n;i++) cin>>a[i];
	for(i=0;i<n;i++) for(j=0;j<m;j++) cnt+=a[i][j]=='#';
	int nowx=0, nowy=0;
	while(nowx != n-1 || nowy != m-1)
	{
		if(nowy != m-1 && a[nowx][nowy+1] == '#') nowy++;
		else if(nowx != n-1 && a[nowx+1][nowy] == '#') nowx++;
		else break;
	}
	if(nowx == n-1 && nowy == m-1 && cnt == n+m-1) cout<<"Possible";
	else cout<<"Impossible";
	cout<<endl;
	return 0;
}
//*/

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

#define dbg(x) cerr<<#x": "<<x<<"\n"
#define dbg_p(x) cerr<<#x": "<<x.first<<","<<x.second<<"\n"
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define st first
#define nd second

using namespace std;

int n, k;
string s;

template<class T>
ostream& operator<<(ostream& out, vector<T> v) {
	out << v.size() << '\n';
	for(auto e : v) out << e << ' ';
	return out;
}

long long ans = 0;
unordered_map <string, int> m[20];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	cin >> s;

	// n *= 2;
	for(int i = 0; i < (1 << n); i++) {
		string red, blue;
		for(int j = 0; j < n; j++) {
			if((1 << j) & i)
				red += s[j];
			else 
				blue += s[j];
		}
		reverse(red.begin(), red.end());
		red += blue;
		m[__builtin_popcount(i)][red]++;
	}

	// dbg_ok;
	for(int i = 0; i < (1 << n); i++) {
		string red, blue;
		for(int j = 0; j < n; j++) {
			if((1 << j) & i)
				red += s[n + j];
			else 
				blue += s[n + j];
		}
		reverse(red.begin(), red.end());
		blue += red;
		ans += (long long) m[n - __builtin_popcount(i)][blue];
	}
	cout << ans << '\n';


}	

Measured memory_bytes: 69044
#include <stdio.h>
#include <string.h>
int main(void)
{
	int n,i,j;
	char w[101][101],tmp[101];
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%s",w[i]);
	}
	for(i=0; i<n-1; i++){
		if(w[i][strlen(w[i])-1]!=w[i+1][0]){
			printf("No\n");
			return 0;
		}
	}
	for(i=0; i<n; i++){
		for(j=i+1; j<n; j++){
			if(strcmp(w[i],w[j])<0){
				strcpy(tmp,w[i]);
				strcpy(w[i],w[j]);
				strcpy(w[j],tmp);
			}
		}
	}
	for(i=0; i<n-1; i++){
		if(strcmp(w[i],w[i+1])==0){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
if __name__ == "__main__":
    n = int(input())
    elements = list(map(lambda x: int(x), input().split()))
    sorted_elements = sorted(elements)
    total_cost = 0

    for i in range(n - 1):
        cost = 0
        cnt = 0
        x_idx = elements.index(sorted_elements[i])
        while i != x_idx:
            y_idx = elements.index(sorted_elements[x_idx])
            elements[x_idx], elements[y_idx] = (sorted_elements[x_idx],
                                                sorted_elements[i])
            cnt += 1
            cost += sorted_elements[x_idx] + sorted_elements[i]
            x_idx = y_idx
        if cnt:
            total_cost += min(cost,
                              (sorted_elements[i] + sorted_elements[0]) * 2 + cost
                              - (sorted_elements[i] - sorted_elements[0]) * cnt)

    print(total_cost)


Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;


int main(){
    ll n,m,v,p;
    cin >> n >> m >> v >> p;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    sort(a.rbegin(),a.rend());
    n--;
    ll ans = p;
    vector<ll>rs(n+1,0);
    rep(i,n+1)rs[i]=0;
    for(ll i=p-1;i<=n;i++){
        if(i-1<0)rs[i]=a[i];
        else rs[i]=rs[i-1]+a[i];
    }
    ll mv = m*v;
    for(ll i = p;i<=n;i++){
        if(a[i]+m<a[p-1])continue;
        ll s = m*p;
        s += m*(n-i);
        s += (i-p+1)*(a[i]+m)-rs[i-1];
        if(s>=mv)ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	int coin[6] = {500,100,50,10,5,1};
	while(1){
		int in;
		cin>> in;
		if(!in) break;
		int ans=0;
		in = 1000 - in;
		for(int i=0;i<6;i++){
			int c = coin[i];
			ans += in / c;
			in = in - c*(in/c);
		}
//		assert(in==0);
		cout<< ans<< endl;
	}

	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>
#include <deque>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10, SZ = 1e3 + 100;

char grid[SZ][SZ];
bool used[SZ][SZ];
ll dist[SZ][SZ];
vector<pair<ll, ll>> dir = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};

int main()
{
    fastInp;

    ll h, w;
	cin >> h >> w;

	pair<ll, ll> st, nd;
	cin >> st.first >> st.second;
	cin >> nd.first >> nd.second;
	st.first--; st.second--;
	nd.first--; nd.second--;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> grid[i][j];
			dist[i][j] = INF;
		}
	}
    
	dist[st.first][st.second] = 0;
	deque<pair<ll, ll>> q;
	q.push_back(st);

	while (!q.empty()) {
		pair<ll, ll> v = q.front();
		q.pop_front();

		for (auto cur : dir) {
			if (v.first + cur.first >= 0 && v.first + cur.first < h && v.second + cur.second >= 0 && v.second + cur.second < w && dist[v.first + cur.first][v.second + cur.second] > dist[v.first][v.second] && grid[v.first + cur.first][v.second + cur.second] == '.') {
				used[v.first + cur.first][v.second + cur.second] = 1;
				dist[v.first + cur.first][v.second + cur.second] = dist[v.first][v.second];
				q.push_front({v.first + cur.first, v.second + cur.second});
			}
		}

		for (int j = -2; j <= 2; j++) {
			for (int i = -2; i <= 2; i++) {
				pair<ll, ll> cur = {j, i};
				if (v.first + cur.first >= 0 && v.first + cur.first < h && v.second + cur.second >= 0 && v.second + cur.second < w && dist[v.first + cur.first][v.second + cur.second] > dist[v.first][v.second] + 1 && grid[v.first + cur.first][v.second + cur.second] == '.') {
					used[v.first + cur.first][v.second + cur.second] = 1;
					dist[v.first + cur.first][v.second + cur.second] = dist[v.first][v.second] + 1;
					q.push_back({v.first + cur.first, v.second + cur.second});
				}
			}
		}
	}

	if (dist[nd.first][nd.second] == INF) {
		cout << "-1";
	} else {
		cout << dist[nd.first][nd.second];
	}
    return 0;
}

Measured memory_bytes: 14560
#include<cstdio>

int a[200000];
int dp[200000];

int main(void) {
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++) {
        scanf("%d",&a[i]);
    }
    for(int i=0; i<n; i++) {
        dp[a[i]+1]++;
        dp[a[i]-1]++;
        dp[a[i]]++;
    }
    int max=0;
    for(int i=0; i<200000; i++) {
        if(max < dp[i])
            max = dp[i];
    }
    printf("%d\n", max);
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    if(s == "Sunny")
        cout << "Cloudy" << endl;
    else if(s == "Cloudy")
        cout << "Rainy" << endl;
    else
        cout << "Sunny" << endl;
}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    static immutable primes = () {
        long[] primes;
        long i;
        while (primes.length < 55)
        {
            long x = 5 * i + 2;
            if (factorize(x).length == 1)
                primes ~= x;
            i++;
        }
        return primes;
    }();
    long N = lread();
    primes[0 .. N].map!text().join(' ').writeln();
}

long[] factorize(long x)
{
    assert(0 < x, "x is negative");
    long[] result;
    while ((x & 1) == 0)
    {
        x /= 2;
        result ~= 2;
    }
    for (long i = 3; i * i <= x; i += 2)
        while (x % i == 0)
        {
            x /= i;
            result ~= i;
        }
    if (x != 1)
        result ~= x;
    return result;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;

using P=pair<ll,ll>;
void solve(){
    int n,m;
    cin>>n>>m;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    sort(all(a));
    vector<P>p(m);
    rep(i,m){
        cin>>p[i].second>>p[i].first;
    }
    sort(all(p));
    reverse(all(p));
    ll sum=0;
    int pos=0;
    rep(i,m){
        rep(j,p[i].second){
            if(pos>=n)break;
            if(a[pos]<=p[i].first)a[pos]=p[i].first;
            else break;
            ++pos;
        }
        if(pos>=n)break;
    }
    rep(i,n)sum+=a[i];
    cout<<sum;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 2560
def to_second(t):
  res = 0
  hour,minute,second = t.split(":")
  res += int(hour)*60*60
  res += int(minute)*60
  res += int(second)
  return res

while True:
  N = int(input())
  if N == 0: exit()
  times = [0] * (24*60*60)
  for _ in range(N):
    s,t = map(str,input().split())
    times[to_second(s)] += 1
    times[to_second(t)] -= 1

  for t in range(24*60*60-1):
    times[t+1] += times[t]

  print(max(times))


Measured memory_bytes: 9592
# input
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

mod = 1000000007

# dp
# dp[i][j]: i人目にj個目の飴を配る時のパターン
dp = [[0] * (K + 1) for i in range(N + 1)]

for i in range(N + 1):
  dp[i][0] = 1

for i in range(N):
  for j in range(K):

    if a[i] < j + 1:
      dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] - dp[i][j - a[i]]) % mod
    else:
      dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod
  
print(dp[N][K])

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

using ll = long long;

int main() {
  ll N;
  cin >> N;
  ll a[N+1], b[N];
  for (int i = 0; i < N + 1; i++) cin >> a[i];
  for (int i = 0; i < N; i++) cin >> b[i];

  // 前から貪欲法
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] <= b[i]) {
      ans += a[i];
      b[i] -= a[i];
    } else {
      ans += b[i];
      b[i] = 0;
    }

    if (a[i+1] >= b[i]) {
      ans += b[i];
      a[i+1] -= b[i];
    } else {
      ans += a[i+1];
      a[i+1] = 0;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
N=int(input())
A=list(map(int, input().split()))
S=[0]
ans=0
for i in range(len(A)):
  S.append(S[i] + A[i])
S.sort()
count = 1
for i in range(1, len(S)):
  if S[i-1] == S[i]:
    count += 1
  else:
    ans += count * (count-1) / 2
    count = 1
ans+=count*(count-1)/2
print(int(ans))


Measured memory_bytes: 26136
#define _CRT_NO_SECURE_WARNINGS
#pragma warning(disable:4996)

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <ctime>
#include <cstdlib>

using namespace std;

#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using namespace std;

int INF = 1e6;

typedef long long ll;
typedef double d;


void solve() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size() - 1; ++i) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			return;
		}

	}
	cout << "Good" << endl;
}

int main() {
	clock_t start = clock();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
	start = clock() - start;
	//cout << setprecision(10) <<"Program executed in: " <<  (float)start / CLOCKS_PER_SEC << endl;
}




Measured memory_bytes: 256
#include "vector"
#include "set"
#include "map"
#include "unordered_set"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define MOD 998244353

typedef vector<int> vi;
typedef pair<int, int> pii;


template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    bool first = true;
    for (const auto& x : v) {
        if (!first) {
            os << " ";
        }
        first = false;
        os << x;
    }
    return os;
}

template<typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& elem : v) {
        is >> elem;
    }
    return is;
}


void solve() {
    ll n;
    cin >> n;

    ll ans = 1;
    for (ll i = 2; i*i <= n; i++) {
        if (n % i == 0) {
            ll k = i;
            ll m = n;
            int x = 0;
            while (m % k == 0) {
                m /= k;
                x++;
            }
            if ((m - 1) % k == 0) {
                ll y = (m - 1) / k;
                ans++;
            }
        }
    }

    ll ans2 = 1;
    ll m = n-1;
    for (ll i = 2; i*i <= m; i++) {
        int x = 1;
        while (m % i == 0) {
            m /= i;
            x++;
        }
        ans2 *= x;
    }
    if (m > 1) {
        ans2 *= 2;
    }

    cout << ans + ans2-1;
}

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

    if (0) {
        int tests;
        cin >> tests;
        for (int i=1; i<= tests; i++) {
            //cout << "Case #" << i << ": ";
            solve();
            cout << endl;
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}

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

using namespace std;

const int mx = 6e2;
double f[mx], g[mx];
vector<int> adj[mx];
int n, m;

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

    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        x--, y--;
        adj[x].push_back(y);
    }
    for(int i = n - 2; i >= 0; i--){
        for(int v : adj[i]) f[i] += f[v] + 1;
        f[i] /= (adj[i].size());
    }

    double ans = f[0];
    for(int i = 0; i < n; i++){
        if(adj[i].size() <= 1) continue;
        double mxn = 0;
        for(int v : adj[i]) mxn = max(mxn, f[v] + 1);
        copy(f, f + n, g);
        g[i] = (g[i] * adj[i].size() - mxn) / (adj[i].size() - 1);
        for(int j = i - 1; j >= 0; j--){
            g[j] = 0;
            for(int v : adj[j]) g[j] += g[v] + 1;
            g[j] /= adj[j].size();
        }
        ans = min(ans, g[0]);
    }

    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 1408
import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())

ans = []
 
for i in range(K+1):
  s_z = S - i

  if s_z < 0:
    pass

  elif K < s_z:
    if (K + 1) > (s_z - K):
      ans.append(K + K - s_z + 1)
      
  else:
    ans.append(s_z + 1)

print(sum(ans))

Measured memory_bytes: 3064
import itertools
N = int(input())
L = [int(i) for i in input().split()]
cnt = 0;
L.sort()

for v in itertools.combinations(L, 3):
  if v[2] < v[0] + v[1] and len(set(v)) == 3:
    cnt += 1
    
print(cnt)


Measured memory_bytes: 9172
#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include "math.h"
using namespace std;

struct UnionFind {
    // union tree
    // used for tracking a set of elements partitioned into a number of disjoint subsets
    // rankなしでの実装

    vector<int> par;
    // par[i] means i's parent
    // (ex) par[3] = 2 means 2 is a parent of 3

    UnionFind(int N) : par(N) {
      //used for initialization
      for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
      // データxが属する木の根を再帰で得る
      // root(x) = {xの木の根}
      if (par[x] == x) return x;
      return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
      // xとyのtreeのmerge
      int rx = root(x); //xの根をrx
      int ry = root(y); //yの根をry
      if (rx == ry) return; //同じ時はそのままに
      par[rx] = ry; //xの根rxをyの根ryにつける
    }

    bool same(int x, int y) {
      // 2つのデータx, yが属する木が同じならtrueを返す
      int rx = root(x);
      int ry = root(y);
      return rx == ry;
    }
};


int main(){
  int N,M,K;
  cin >> N >> M >> K;
  int friendnum [100010] = {};
  UnionFind friendtree(N);
  UnionFind blocktree(N);
  int ans[100010];
  for (int i = 0; i < M; i++){
    int a,b;
    cin >> a;
    cin >> b;
    friendtree.unite(a-1,b-1);
    friendnum[a-1] = friendnum[a-1] + 1;
    friendnum[b-1] = friendnum[b-1] + 1;
  }

  //ノード数の配列を作成
  int root_num[100010]={};
  for(int i=0;i<N;i++){
    root_num[friendtree.root(i)-1]++;
  }

  for(int i = 0; i < N; i++){
    int count = root_num[friendtree.root(i)-1];
    ans[i] = count - friendnum[i];
  }

  for (int i = 0; i < K; i++){
    int c,d;
    cin >> c;
    cin >> d;
    if(friendtree.same(c-1,d-1)){
      ans[c-1] = ans[c-1] - 1;
      ans[d-1] = ans[d-1] - 1;
    }
  }

  for(int i = 0; i < N; i++){
    cout << ans[i]-1 << " ";
  }





  return 0;
}

Measured memory_bytes: 3200
a,b,c,x,y=map(int,input().split())
ans=10**9
for i in range(0,max(x,y)*2+2,2):
    s1=(max(x-i//2,0))*a
    s2=(max(y-i//2,0))*b
    s3=i*c
    ans=min(ans,s1+s2+s3)
print(ans)

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





int main() {

    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    char c;
    ll a,b,d;
    cin>>a>>b>>c>>d;

    ll res = a*(100*b + d)/100;
    cout<<res<<endl;
    
    return 0;
}


Measured memory_bytes: 3640
while 1:
    x = ""
    H, W = map(int ,raw_input().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(W):
            if i%2 == 0:
                x += '#'
            else:
                x += '.'
        for i in range(H):
            if i%2 == 0:
                print x
            else:
                if len(x)%2 == 0:
                    print x[1:len(x)+1] + '#'
                else:
                    print x[1:len(x)+1] + '.'
        print ""

Measured memory_bytes: 6452
N,M,P = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]

g = [[] for i in range(N)]
revg = [[] for i in range(N)]

for a,b,_ in ABC:
    a,b = a-1, b-1
    g[a].append(b)
    revg[b].append(a)

st = set([0])
stack = [0]
while stack:
    v = stack.pop()
    for to in g[v]:
        if to in st: continue
        st.add(to)
        stack.append(to)

revst = set([N-1])
stack = [N-1]
while stack:
    v = stack.pop()
    for to in revg[v]:
        if to in revst: continue
        revst.add(to)
        stack.append(to)

use = st & revst
es = []
for a,b,c in ABC:
    a,b = a-1, b-1
    if a in use and b in use:
        es.append((a,b,c))

INF = float('inf')
d = [INF] * N
d[0] = 0
for i in range(N):
    for fr,to,c in es:
        cost = -(c-P)
        if d[to] > d[fr]+cost:
            d[to] = d[fr] + cost
            if i == N-1:
                print(-1)
                exit()

print(max(0,-d[-1]))

Measured memory_bytes: 52312
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<vector<int>>day(N, vector<int>(10));
	vector<vector<ll>>P(N, vector<ll>(11));
	rep(i, 0, N)rep(j, 0, 10)cin >> day[i][j];
	rep(i, 0, N)rep(j, 0, 11)cin >> P[i][j];
	ll ans = -INF * 2;
	for (int bit = 1;bit < (1 << 10);++bit) {
		ll sum = 0;
		rep(i, 0, N) {
			int cnt = 0;
			rep(j, 0, 10) {
				if (bit & (1 << j) && day[i][j] == 1)++cnt;
			}
			sum += P[i][cnt];
		}
		chmax(ans, sum);
	}
	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N;
    cin>>N;
    for(int i=0;i<=10;i++){
        if(N-i*1000<=0){
            cout<<i*1000-N<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3616
#include<stdio.h>
int main()
{
	int s[4],count=0;
	scanf("%ls",s);
	for(int i=0;i<4;i++)
	{
		if(s[i]==s[i+1])
			count++;
	}
	if(count>0)
		printf("Bad");
	else
		printf("Good");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define int long long
#define elif else if
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string
int sum(int a){
  int b=0;
  while(a){
      b+=a%10;
      a/=10;
  }
  return b;
}
signed main(){
  int N,M,O,P=0,c=0,c2=0,toSearch=1;
  double D,D2;
  char C;
  str S,T,U;
  cin>>N;
  vint Luka={2,1};
  rep(0,85){
    Luka.pb(Luka[i]+Luka[i+1]);
  }
  cout<<Luka[N]<<endl;
}


Measured memory_bytes: 256
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
ll x;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>x;
	cout<<48-x;
	return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

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

	ll N, M, V, P;
	cin >> N >> M >> V >> P;

	vector<ll> As(N);
	for (ll i = 0; i < N; ++i) {
		cin >> As[i];
	}
	sort(As.begin(), As.end(), greater<ll>());

	vector<ll> accums(N + 1);
	accums[0] = 0;
	for (ll i = 0; i < N; ++i) {
		accums[i + 1] = accums[i] + As[i];
	}

	ll res = P;
	for (ll i = P; i < N; ++i) {
		if (As[i] + M < As[P - 1]) {
			continue;
		}
		ll m_count = V - (N - i + P - 1);
		if (m_count < 0) {
			++res;
			continue;
		}
		if ((As[i] + M) * (i + 1 - P) - (accums[i] - accums[P - 1]) >= M * m_count) {
			++res;
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1792
<?php
fscanf(STDIN, "%d %d", $n, $k);
$l=explode(' ',trim(fgets(STDIN)));
for ($i=$n; $i < 100000; $i++) {
    $s = strval($i);
    $len = strlen($s);
    $ng = false;
    for ($j=0; $j < $len; $j++) {
        if (in_array($s[$j], $l)) {
            $ng = true;
            break;
        }
    }
    if (!$ng) {
        echo $i;
        exit;
    }
}


Measured memory_bytes: 3700
#include <stdio.h>

int main()
{

    int x, y, tmp, num, amari;

    scanf("%d%d", &x, &y);

    if (x < y)
    {
        tmp = x;
        x = y;
        y = tmp;
    }

    num = x % y;

    //numとyの最大公約数を求める。

    while (num != 0)
    {
        amari = y % num;
        y = num;
        num = amari;
        if (amari == 0)
            break;
    }
    printf("%d\n", y);

    return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9+7;
vector<vector<ll>>dp;
ll h,w;

ll solve(ll y,ll x){
  if(dp[y][x]!=-1)return dp[y][x];
  dp[y][x]=solve(y+1,x)+solve(y,x+1);
  return (dp[y][x]%=MOD);
}

main(){

  cin>>h>>w;
  vector<string> a(h);
  for(ll i=0;i<h;++i)cin>>a[i];

  dp = vector<vector<ll>>(h+1,vector<ll>(w+1,-1));
  dp[h-1][w-1]=1;
  for(ll i=0;i<=h;++i)dp[i][w]=0;
  for(ll i=0;i<=w;++i)dp[h][i]=0;
  for(ll i=0;i<h;++i)for(ll j=0;j<w;++j){
    if(a[i][j]=='#')dp[i][j]=0;
  }
  
  cout<<solve(0,0)<<endl;
  
}

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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()

int main() {

    int k, a, b;
    cin >> k >> a >> b;

    for (int i = a; i <= b; i++)
        if (i % k == 0) {
            puts("OK");
            return 0;
        }

    puts("NG");

    return 0;
}


Measured memory_bytes: 3636
[a,b,c] = raw_input().split(' ')
a = int(a)
b = int(b)
c = int(c)
t = 0
if a > b:
    t = a
    a = b
    b = t
if b > c:
    t = b
    b = c
    c = t
if a > b:
    t = a
    a = b
    b = t
print a,b,c

Measured memory_bytes: 4216
n = int(input())
A = list(map(int, input().split()))
all_sum = sum(A)
left_sum = 0
ans = 1<<40
for a in A:
	left_sum += a
	right_sum = all_sum - left_sum
	ans = min(ans, abs(right_sum - left_sum))
print(ans)

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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}


int N;
int A[1000010];



int main(){


    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];

    int four = 0;
    int two  = 0;
    for(int i = 0; i < N; i++){
        if(A[i] % 4 == 0){
            four++;
        }
        else if(A[i] % 2 == 0){
            two++;
        }
    }

    if(four * 2 + (two == 0 ? 1: two) >= N){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
using ll = long long;
using namespace std;

int main()
{
    int A, B, K;
    cin >> A >> B >> K;
    for (int i = 0; i < K; i++)
    {
        if (i % 2 == 0)
        {
            A -= A % 2;
            B += A / 2;
            A /= 2;
        }
        else
        {
            B -= B % 2;
            A += B / 2;
            B /= 2;
        }
    }
    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <map>
#include <queue>
#include <algorithm>
#define ri register int 
#define ll long long
using namespace std;
const int maxn=200005;
const int inf=0x7fffffff;
template <class T>inline void read(T &x){
    x=0;int ne=0;char c;
    while(!isdigit(c=getchar()))ne=c=='-';
    x=c-48;
    while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;
    x=ne?-x:x;
    return ;
}
int n;
ll a[maxn];
ll sum=0;
inline ll solve(int k){
    ll cnt=0;
    for(ri i=1;i<=n;i++)cnt+=abs(a[i]-k);
    return cnt;
}
int main(){
    read(n);
    for(ri i=1;i<=n;i++){
       read(a[i]);
       a[i]=a[i]-i;
    }
    ll ans,lmid,rmid;
    ll l=-1e9,r=1e9;
    while(l<r-1){
        lmid=(l+r)>>1,rmid=(lmid+r)>>1;    
        if(solve(lmid)>solve(rmid))l=lmid;
        else r=rmid;
    }
    if(solve(l)<solve(r))ans=l;
    else ans=r;
    printf("%lld\n",solve(ans));
    return 0;
}

Measured memory_bytes: 5180
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int N;
string S;
int main() {
	cin>>N;
    cin>>S;
	if(N>=3200){
		cout<<S<<endl;

	}else{
		cout<<"red"<<endl;
	}




	return 0;
}


Measured memory_bytes: 256
def solve(n, s, t):
    res = ""
    for i in range(n):
        res += s[i] + t[i]
    return res


def main():
    n = int(input())
    s, t = input().split()
    res = solve(n, s, t)
    print(res)


def test():
    assert solve(2, "ip", "cc") == "icpc"
    assert solve(8, "hmhmnknk", "uuuuuuuu") == "humuhumunukunuku"
    assert solve(5, "aaaaa", "aaaaa") == "aaaaaaaaaa"


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

ll cal(ll N){
    ll ans  = 0 ;

    while(N != 0){
        ans += N%10;
        N/=10;
    }
    return ans;
}

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

    ll N ;
    cin >> N;

    ll ans = 1000000;
    for(ll i = 1; i <= (N-1); i++){
        ll A = i;
        ll B = N - i;

        ans = min(ans, cal(A) + cal(B));
    }
    cout << ans << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256