akhauriyash/Code-Regression huggingface dataset:
N = int(input())
D = [int(d) for d in input().split()]

D.append(0)
D.sort()
for i in range(1, N+1):
    if i%2 == 0:
        D[i] = 24-D[i]
D.sort()
ans = min(D[-1], 24-D[-1])
for i in range(N):
    ans = min(ans, D[i+1]-D[i])
print(ans)

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

int main(){
  long long N;
  cin >> N;
  int ans=12;
  for(long long i=1; i*i<=N; i++){
    if(N%i!=0) continue;
    long long temp= max(i, N/i);
    string S;
    S = to_string(temp);
    int L = S.size();
    ans = min(ans, L);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  //500円で払える分だけ払う
  if (a * b % 2 == 0) {
    cout << "Even" << endl;
  }else{
  	cout << "Odd" << endl;
  }
}

Measured memory_bytes: 3600
using System;

namespace aoj4a
{
    class Program
    {
        static void Main(string[] args)
        {
            
            double r = double.Parse(Console.ReadLine());
            Console.WriteLine((r * r * Math.PI).ToString("F6") + " " + (2 * r * Math.PI).ToString("F6"));


        }
    }
}

Measured memory_bytes: 9212
s=input()
t=input()
sl=len(list(s))
tl=len(list(t))
for i in range(sl-tl+1)[::-1]:
    c=0
    for j in range(tl):
        if s[i+j]==t[j] or s[i+j]=='?':c+=1
        else:break
    if c==tl:
        print((s[:i]+t+s[i+tl:]).replace("?", "a"))
        exit()
print('UNRESTORABLE')

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = 0;
		double o = 0, sum = 0, ave = 0;
		double points[] = new double[1000];
		
		while((num = sc.nextInt()) != 0) {
			for(int i = 0; i < num; i++) {
				points[i] = sc.nextInt();
				sum += points[i];
			}
			ave = sum / (double)num;
			for(int i = 0; i < num; i++) {
				o += (ave - points[i])*(ave - points[i]);
			}
			System.out.printf("%.8f\n", Math.sqrt(o / (double)num));
			sum = 0;
			o = 0;
		}
	}
}


Measured memory_bytes: 31648
#include<stdio.h>

int main(void){
    int n,m,i,j;
    int a[100][100],b[100],c[100]={0};
    
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    
    for(i=0;i<m;i++){
        scanf("%d",&b[i]);
    }
    
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c[i]+=a[i][j]*b[j];
        }
        printf("%d\n",c[i]);
    }
    
    return 0;
    
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    map<int, int> p;
    for (auto i = 0; i < n; i++) {
        int tmp; cin >> tmp;
        p[tmp]++;
    }

    if(x <= 0) {
        cout << x - 1 << endl;
        return 0;
    }

    for (auto i = 0; i < 100; i++) {
        if(p[x - i] == 0) {
            cout << x - i << endl;
            return 0;
        }
        else if(p[x + i] == 0) {
            cout << x + i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		for (int i = 1; i <= N; i++) {
			System.out.println(count(i));
		}
	}

	public static int count(int n) {
		double M = Math.pow(n, 0.5);
		int c = 0;
		for (int x = 1; x <= M; x++) {
			for (int y = (int) Math.min(x, M); y <= M; y++) {
				for (int z = (int) Math.min(y, M); z <= M; z++) {
					if (x * x + y * y + z * z + x * y + y * z + z * x == n) {
						if (x == y && y == z) {
							c += 1;
						} else if (x == y || y == z) {
							c += 3;
						} else {
							c += 6;
						}
					}
				}
			}
		}
		return c;
	}

}


Measured memory_bytes: 40792
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    int ans=0, curr=a[0], l=0;
    for(int i=0; i<n; i++){
        if(a[i]==curr) l++;
        else{
            ans+=l/2;
            curr=a[i];
            l=1;
        }
    }
    ans+=l/2;
    cout << ans << endl;
    return 0;
}

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

long long n;
vector<long long> l, r;

int main() {
  cin >> n;
  l.resize(n);
  r.resize(n);
  for (int i = 0; i < n; ++i) cin >> l[i] >> r[i];
  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  if (n % 2)
    cout << r[n / 2] + 1 - l[n / 2] << endl;
  else
    cout << r[n / 2 - 1] + r[n / 2] - l[n / 2] - l[n / 2 - 1] + 1 << endl;

  return 0;
}


Measured memory_bytes: 6356
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ep emplace_back
#define st first
#define sc second

using namespace std;

const ll mod = 998244353;
const int e = 1e6+69;
const int base = 311;
// dung igt thay cho gt luc tinh giai thua
// 0
// cach tao hoan vi tu n so : n*(n+1)/2;

ll a[e];

int main()
{
    int n;
    cin >> n;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
    }
    if(n%2 == 1)
    {
        cout << 0;
        return 0;
    }
    sort(a+1, a+n+1);
    ll k = a[n/2];
    ll k1 = a[n/2+1];
    cout << k1 - k;
}


Measured memory_bytes: 1024
n = int(input())
# h1, m1, h2, m2, k = list(map(int, input().split()))
#a, b = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# k = int(input())
#p = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
# py = [list(map(int, input().split())) for i in range(m)]
a = list(map(int, input().split()))
ans = 1
if 0 in a:
    print(0)
else:
    for i in range(n):
        ans *= a[i]
        # print(ans)
        if ans > 1000000000000000000:
            print(-1)
            exit()
    print(ans)


Measured memory_bytes: 21776
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int N, K, p[1100] = {};
	int sum = 0;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}
	sort(p, p + N);
	for (int i = 0; i < K; i++) {
		sum += p[i];
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3560
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        cout << "Possible" << endl;
    }
    else {
        cout << "Impossible" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N;cin>>N;
    deque<str> bk; deque<str> bg;
    str a;
    for(int i=1; i<=N;i++){
        cin>>a;
        // vector<str>::iterator itk = bk.begin();
        // vector<str>::iterator itg = bg.begin();
        if(i%2==1){
          bk.push_back(a);
          // bg.insert(itg, a);
          bg.push_front(a);
        }else{
          bg.push_back(a);
          // bk.insert(itk, a);
          bk.push_front(a);
        }
    }
    for(int i=0; i<N;i++){
      if(N%2==1){
        cout<<bg[i]<<" ";
      }else{
        cout<<bk[i]<<" ";
      }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 17664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll a,b,k;
    cin >> a >> b >> k;
    if (a >= k)
    {
        cout << a-k << " " << b << endl;
    }
    else if (a+b >= k)
    {
        cout << 0 << " " << a+b-k << endl;
    }
    else
    {
        cout << "0 0" << endl;
    }
    
    
    
}




Measured memory_bytes: 256
A, B, C, K = map(int, input().split())  

R = 0
if A >= K:
  R = K
  K = 0
else:
  R = A
  K -= A
#
if B >= K:
  K = 0
else:
  K -= B
#
if C >= K:
  R -= K
else:
  R -= C
#
print(R)



Measured memory_bytes: 9184
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <bitset>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0; i<n; i++)
#define RPA(i,s,e) for(int i=s; i<=e; i++)
#define RPD(i,s,e) for(int i=s; i>=e; i--)
#define PB(a) push_back(a)
#define MP(i,s) make_pair(i,s)
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(), (a).end()
#define PRT(a) cerr << #a << " = " << (a) << endl
#define PRT2(a,b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << endl
#define PRT3(a,b,c) cerr << (a) << ", " << (b) << ", " << (c) << endl

typedef long long lint;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;

lint w, h;
vector<string> mat;

string dp[80][80];

bool digit(char c) {
	return (c >= '0' && c <= '9');
}

void trim(string& s) {
	int i = 0;
	while(s[i] == '0') i++;
	s = s.substr(i);
}

string larger(string s1, string s2) {
	trim(s1);
	trim(s2);
	if(s1.size() != s2.size()) {
		return s1.size() > s2.size() ? s1 : s2;
	}
	return s1 > s2 ? s1 : s2;
}

void solve() {
	REP(y,h) REP(x,w) dp[y][x] = "";
	REP(x,w) {
		if(digit(mat[0][x])) {
			if(x == 0) dp[0][x] = mat[0][x];
			else dp[0][x] = dp[0][x-1] + mat[0][x];
		}
	}

	RPA(y,1,h-1) {
		REP(x,w) {
			if(!digit(mat[y][x])) continue;

			if(x == 0) {
				dp[y][x] = dp[y-1][x] + mat[y][x];
			} else {
				string s1 = dp[y-1][x] + mat[y][x];
				string s2 = dp[y][x-1] + mat[y][x];
				dp[y][x] = larger(s1, s2);
			}
		}
	}

	string ans = "";
	REP(y,h) REP(x,w) ans = larger(ans, dp[y][x]);
	trim(ans);
	cout << ans << endl;
}

void coding() {
	while(cin>>w>>h, w|h) {
		mat = vector<string>(h);
		REP(y,h) cin >> mat[y];
		solve();
	}
}

// #define _LOCAL_TEST

int main() {
#ifdef _LOCAL_TEST
	clock_t startTime = clock();
	freopen("test.dat", "r", stdin);
#endif

	coding();

#ifdef _LOCAL_TEST
	clock_t elapsedTime = clock() - startTime;
	cout << endl;
	cout << (elapsedTime / 1000.0) << " sec elapsed." << endl;
	cout << "This is local test" << endl;
	cout << "Do not forget to comment out _LOCAL_TEST" << endl << endl;
#endif
}

Measured memory_bytes: 1396
import java.util.*;
public class Main {
   public static void main(String args[]){
      //declaration and initialization
      Scanner sc = new Scanner(System.in);
      String input[];
       
      //reading the intput
      input = sc.nextLine().split(" ",0);
       
      //variables for each problem
      int time;
      int hour;
      int min;
      int sec;
       
      //assginment
      time = Integer.parseInt(input[0]);
             
      //calculation
       
      hour = time/3600;
      time -= hour * 3600;
       
      min = time/60;
      sec = time%60;
                   
     //output
      System.out.println(hour + ":" + min + ":" + sec);
       
       
       
   }//main
       
}//class

Measured memory_bytes: 26276
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define mem1(x)  memset(x,1,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
 
ll dp[3004][3004];

int32_t main(){
    IOS;
    string s,t,e;
    ll i,j,k,n,m,p,q;
    cin >> s >> t;
    n = s.size();m = t.size();
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(s[i-1]==t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else {
                dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
            }     
        }
    }
    i = n;j=m;
    while(i >= 1 && j >= 1){
        if(s[i-1]==t[j-1]) {
            e += s[i-1];
            i--;j--;
        }
        else {
            if(dp[i-1][j]>=dp[i][j-1]){
                i--;
            }
            else j--;
        }
    }
    reverse(all(e));
    cout << e <<"\n";
} 

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

int main() {

	int n, m; cin >> n >> m;
	string ans = "";
	for (int i = 0; i < n; i++) {
		ans += 'x';
	}
	for (int i = 0; i < m; i++) {
		int s; char c; cin >> s >> c;
		s--;
		if (ans[s] != 'x') {
			if (ans[s] == c) {}
			else { // ans[s] != c
				cout << -1 << endl;
				return 0;
			}
		}
		else { // ans[s] == 'x'
			ans[s] = c;
		}
	}
	for (int i = 0; i < n; i++) {
		if (i != 0 && ans[i] == 'x') ans[i] = '0';
		else if (i == 0 && ans[i] == 'x' && ans.size() != 1) ans[i] = '1';
		else if (i == 0 && ans[i] == 'x' && ans.size() == 1) ans[i] = '0';
	}
	if (ans[0] == '0' && 2 <= ans.size()) ans = "-1";
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
int main()
{
    long long int N;
    cin >> N;
    if(N%2==1)cout << "0" << endl;
    else{
        long long int count = 0;
        long long int K = 10;
        while(N>=K){
            //cout << N/K << endl;
            count += N/K;
            K *= 5;
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int i, j, k;

  for(i = 1 ; i <= 9 ; i++)
    {
      for(j = 1 ; j <= 9 ; j++)
	{
           k = i*j;
           printf("%dx%d=%d\n", i,j,k);
	}
    } 
  return(0);
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    cout << ((n - 1) + (k - 1) - 1) / (k - 1) << endl;
    return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll n,ans;
	cin >> n;
	ans = n;
	map<ll, ll> m;
	vll a(n);
	rep(i, 0, n) {
		cin >> a[i];
		m[a[i]]++;
	}

	for (auto itr = m.begin(); itr != m.end(); itr++) {
		if (itr->second > 1) {
			ans -= itr->second - 1;
		}
	}
	if (ans % 2 == 0) {
		ans--;
	}
	outn(ans);
	return 0;

}


Measured memory_bytes: 7296
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            x = gcd(i,j)
            ans += gcd(x,k)
print(ans)

Measured memory_bytes: 73860
import sys
n = int(input())
A = [int(e)for e in sys.stdin]
cnt = 0
G = [int(4**i+3*2**(i-1)+1)for i in range(9,0,-1)]+[1]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')


Measured memory_bytes: 53312
#include<bits/stdc++.h>
#pragma optimize("", off)
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long int k;
	string s;
	cin>>k>>s;
	if(k>=s.length()){
		cout<<s<<"\n";
	}else{
		string answer="";
		for(int i=0;i<k;i++){
			answer+=s[i];
		}
		answer+="...";
		cout<<answer<<"\n";
	}
	return 0;
}


Measured memory_bytes: 3656
def resolve():
    a,b,k=map(int, input().split())
    l=[]
    for i in range(1,min(a+1,b+1)):
        if a%i==0 and b%i==0:
            if i not in l:
                l.append(i)
    l.sort(reverse=True)
    print(l[k-1])
resolve()

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n, c;
	cin >> n >> c;
	vector<vector<int>> d(c, vector<int>(c));
	for(int i = 0; i < c; i++) {
		for(int j = 0; j < c; j++) {
			cin >> d[i][j];
		}
	}
	vector<vector<int>> col(3, vector<int>(c));
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			int a;
			cin >> a;
			a--;
			col[(i + j) % 3][a]++;
		}
	}
	long long ans = LLONG_MAX;
	for(int i = 0; i < c; i++) {
		for(int j = 0; j < c; j++) {
			for(int k = 0; k < c; k++) {
				if(i == j || j == k || k == i) {
					continue;
				}
				long long tmp = 0;
				for(int l = 0; l < 3; l++) {
					for(int m = 0; m < c; m++) {
						if(l == 0) {
							tmp += d[m][i] * col[l][m];
						}
						if(l == 1) {
							tmp += d[m][j] * col[l][m];
						}
						if(l == 2) {
					    tmp += d[m][k] * col[l][m];
						}
					}
				}
				ans = min(tmp, ans);
			}
		}
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
  {
  string s;
  cin>>s;
  int temp1=0;
  for(int i=0;i<s.size();i++)
    {
    if(s[i]=='+')
      temp1++;
    else if(s[i]=='-')
      temp1--;
    }
  cout<<temp1<<endl;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
const ll INF = 9223372036854775807;

int main()
{
  int H, W;
  cin >> H >> W;
  string in;
  vector<vector<string>> table(H, vector<string>(W));
  rep(i, H)
  {
    cin >> in;
    rep(j, W) table.at(i).at(j) = in.at(j);
  }
  vector<vector<int>> Ans(H + 1, vector<int>(W + 1, 0));
  rep(y, H)
  {
    rep(x, W)
    {
      if (table.at(y).at(x) == "#")
      {
        if (y > 0 && x > 0)
          Ans[y - 1][x - 1]++;
        if (y > 0)
          Ans[y - 1][x]++;
        if (y > 0)
          Ans[y - 1][x + 1]++;
        if (x > 0)
          Ans[y][x - 1]++;
        Ans[y][x + 1]++;
        if (x > 0)
          Ans[y + 1][x - 1]++;
        Ans[y + 1][x]++;
        Ans[y + 1][x + 1]++;
      }
    }
  }
  rep(i, H)
  {
    rep(j, W)
    {
      if (table.at(i).at(j) == "#")
        cout << "#";
      else
        cout << Ans.at(i).at(j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 3692
using System;

class Program
{
    static void Main(string[] args)
    {
        int n;
        int min = 1000000;
        int max = -1000000;
        long total = 0;

        string num1 = Console.ReadLine();
        n = int.Parse(num1);

        string[] num2 = Console.ReadLine().Split(' ');
        int[] array = new int[n];

        for (int i = 0; i < n; i++)
        {
            array[i] = int.Parse(num2[i]);
        }
            
        foreach (int ai in array)
        {
            total += ai;

            if (min > ai)
            {
                min = ai;
            }
            if (max < ai)
            {
                max = ai;
            }
        }
        Console.WriteLine(min + " " + max + " " + total);
    }
}


Measured memory_bytes: 9948
#include<cstdio>
int f[2000];
int main()
{
	int a,b,c,x,ans=0;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	x/=10;
	for(int i=0;i<=a;i++)
		for(int j=0;j<=b;j++)
			for(int k=0;k<=c;k++)
				if(5*k+10*j+50*i==x)
					ans++;
	printf("%d",ans);
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    LL res = 0;
    while(x > 0 && y > 0 && a + b >= c * 2) {
        x--, y--;
        res += c * 2;

    }

    while(x > 0) {
        res += min(a, c * 2);
        --x;

    }
    while(y > 0) {
        res += min(b, c * 2);
        --y;

    }
    cout << res << endl;
    return 0;
}



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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

vector<int> zAlgorithm(string s) {
    int n = s.size();
    vector<int> ret(n,0);
    ret[0] = n;
    int i = 1,j = 0;
    while (i < n) {
        while (i+j < n && s[j] == s[i+j]) ++j;
        ret[i] = j;
        if (j == 0) {
            ++i;
            continue;
        }
        int k = 1;
        while (i+k < n && k+ret[k] < j) {
            ret[i+k] = ret[k];
            ++k;
        }
        i += k;
        j -= k;
    }
    return ret;
}

int main() {
    string s,t;
    cin >> s >> t;
    int n = s.size(),m = t.size();
    for (int i = 0;i < (m+n-1)/n+1;++i) t += s;
    vector<int> a = zAlgorithm(t);
    vector<bool> b(n,false),used(n,false);
    for (int i = 0;i < n;++i) if (a[m+i] >= m) b[i] = true;
    int ans = 0;
    for (int i = 0;i < n;++i) if (b[i] && !used[i]) {
        if (b[(i-m%n+n)%n]) continue;
        int cnt = 0,j = i;
        while (b[j]) {
            cnt++;
            used[j] = true;
            (j += m) %= n;
            ans = max(ans,cnt);
        }
    }
    for (int i = 0;i < n;++i) if (b[i] && !used[i]) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 12616
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n, x, y;
  cin >> n >> x >> y;
  map<ll, ll> mp;
  for(ll i = 1; i <= n; i++) {
  	for(ll j = i+1; j <= n; j++) {
  		ll t = j - i;
  		t = min(t, abs(x - i) + abs(j - y) + 1);
  		t = min(t, abs(y - i) + abs(j - x) + 1);
  		mp[t]++;
  	}
  }
  for(ll i = 1; i < n; i++)cout << mp[i] << endl;
  return 0;
} //good night.

Measured memory_bytes: 384
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  

n,m=input2()
AB=[input_array() for _ in range(n)]

AB=sorted(AB,key=lambda x:x[0])
ans=0

for i in range(n):
	a= AB[i][0]
	b= AB[i][1]
	if b>m:
		ans+=a*m
		break
	elif b==m:
		ans+=a*b
		break
	else:
		ans+=a*b
	m-=b
print(ans)

Measured memory_bytes: 29100
H, W = map(int, input().split())

def diff(a, b, c) :
    return max([a, b, c]) - min([a, b, c])

def div2(H, W, s) :
    h2, w2 = H//2, W//2
    m = float('inf')
    m = min(m, diff(s, h2*W, (H-h2)*W))
    m = min(m, diff(s, w2*H, (W-w2)*H))
    return m
    

def div3(H, W) :
    m = float('inf')
    h3, w3 = H//3, W//3
    m = min(m, div2(H-h3, W, h3*W))
    m = min(m, div2(H-(h3+1), W, (h3+1)*W))
    m = min(m, div2(H, W-w3, w3*H))
    m = min(m, div2(H, W-(w3+1), (w3+1)*H))
    return m
    
print(div3(H, W))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  if (N <= 81)
  {
    for (int i = 0; i < 9; i++)
    {
      for (int j = 0; j < 9; j++)
      {
        if (((i + 1) * (j + 1)) == N)
        {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool ans = true;
int main()
{
	int N,l=9,arr[]={1,2,3,4,5,6,7,8,9};
	cin>>N;
	for(int i=0;i<9;i++)
 	{
		 for(int j=9-1;j>=0;j--){
			 if(arr[i]*arr[j]==N)
			{
				ans=true;
				break;
			}
			else
			{
				ans=false;
			}
		 }
			if(ans)
				break;
	}
	if(ans)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int i = 0;
  
  bool flag = false;
  while (i < N) {
    string S;
    cin >> S;
    if (S == "Y") {
      flag = true;
    }
    i++;
  }
  if (flag)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}

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

int f(vector<int> a)
{
    int n = a.size();
    vector<int> b(n);
    int x = 1;
    for (int &bb : b)
    {
        bb = x;
        x++;
    }
    int ret = 0;
    for (bool finish = false; !finish; next_permutation(b.begin(), b.end()))
    {
        bool flag = true;
        for (int i = 0; i < n; i++)
        {
            if (a[i] != b[i])
            {
                flag = false;
            }
        }
        if (flag)
        {
            break;
        }
        else
        {
            ret++;
        }
    }
    return ret;
}

int main()
{
    int N;
    cin >> N;
    vector<int> P(N);
    for (int &p : P)
    {
        cin >> p;
    }
    vector<int> Q(N);
    for (int &q : Q)
    {
        cin >> q;
    }

    int a = f(P);
    int b = f(Q);
    cout << abs(a - b) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>

using namespace std;

unsigned long long int a = 0, b = 0, c = 100, d = 0, e = 0, n = 0, maxy = 0, min = 0, ans = 0, counter = 0, sur = 0;
std::vector<unsigned long long int> vec{}, vecniki{};
int yoko = 0, tate = 0;
int arraykun[2300] = {}, nyan[200] = {}, koji[50][50];
std::string output, output2, output3, input;
int kakunou[50][50] = { 53 }, moji[50];
bool okada = false, sink = false, backsink = false;
char one, two;
int dp(int i, int j) {
	bool okada = true;
	if (i == 0 || j == 0) {
		okada = false;
		return 0;
	}
	if (koji[i][j] == -1) {
		okada = false;
		return 0;
	}
	if (i == 1 && j == 1) {
		okada = false;
		return 1;
	}
	if (okada) {
		return dp(i - 1, j) + dp(i, j - 1);
	}

}
int main()
{

	cin >> a;
	if (a == 3 || a == 5 || a == 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}






Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

a.append(90)
money=1000
kabu=0
for i in range(n):
  if a[i+1] > a[i]:
    kabu+=int(money/a[i])
    money-=a[i]*int(money/a[i])
  elif a[i+1] < a[i]:
    money+=kabu*a[i]
    kabu=0
print(money)


Measured memory_bytes: 9184
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  P.append([])
  for j in range(26):
    P[i].append(j)
  P[i].sort(reverse=True,key=lambda x:X[x]+S[i][x])
  XX[P[i][0]]-=X[P[i][0]]
  X[P[i][0]]=0
SC,SC2=0,0
for i in range(D):
  SC+=S[i][P[i][0]]
YY=[]
Y=[]
for l in range(25):
  for k in range(25):
    for i in range(D):
      SC2=SC
      YY=XX[:]
      Y=X[:]
      SC2-=S[i][P[i][0]]
      SC2+=S[i][P[i][k+1]]
      for j in range(26):
        Y[j]=0
      YY[P[i][0]],YY[P[i][k+1]]=0,0
      for j in range(D):
        if j==i:
          Z=P[j][k+1]
        else:
          Z=P[j][0]
        Y[P[i][0]]+=C[P[i][0]]
        Y[P[i][k+1]]+=C[P[i][k+1]]
        Y[Z]=0
        YY[P[i][0]]+=Y[P[i][0]]
        YY[P[i][k+1]]+=Y[P[i][k+1]]
      if SC2-sum(YY)>SC-sum(XX):
        P[i].insert(0,P[i][k+1])
        del P[i][k+2]
        XX=YY[:]
        SC=SC2
for i in range(D):
  print(P[i][0]+1)

Measured memory_bytes: 85396
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (1 <= A && A <= 9 && 1<= B && B <= 9) {
			System.out.println(A * B);
		} else {
			System.out.println(-1);
		}
	}
}

Measured memory_bytes: 21844
#include <stdio.h>
 #include <math.h>

#define PI 3.14159265358979323846264338327950L

 int main(void) {
 int a, b, h, m;
 scanf("%d%d%d%d", &a, &b, &h, &m);
 long double rad = PI * 2 * (
 (long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long
double)m / 60.0);

 long double rsq = (long double)(a * a + b * b) - (long double)(2 * a *
b) * cosl(rad);

 printf("%20.20Lf\n", sqrtl(rsq));

 return 0;
 }


Measured memory_bytes: 2580
m[9999][9999];
main(){
	int n,k,x,y,i,j;
	char c[2];
	scanf("%d%d",&n,&k);
	for(;n--;){
		scanf("%d%d%s",&x,&y,c);
		if(*c=='W')y+=k;
		x%=2*k;
		y%=2*k;
		for(i=0;i<4;i++){
			for(j=i%2;j<4;j+=2){
				m[x+i*k][y+j*k]++;
				m[x+i*k+k][y+j*k]--;
				m[x+i*k][y+j*k+k]--;
				m[x+i*k+k][y+j*k+k]++;
			}
		}
	}
	for(i=0;i<6*k;i++)for(j=1;j<6*k;j++)m[i][j]+=m[i][j-1];
	for(i=1;i<6*k;i++)for(j=0;j<6*k;j++)m[i][j]+=m[i-1][j];
	for(y=i=0;i<6*k;i++)for(j=0;j<6*k;j++)y=(x=m[i][j])>y?x:y;
	printf("%d\n",y);
}

Measured memory_bytes: 235136
def main(a, b):
    outputs = ''
    m = len(b)
    for row in a:
        result = 0
        for j in range(m):
            result += row[j]*b[j]
        outputs += '{}\n'.format(result)
    return outputs


if __name__ == "__main__":
    n, m = map(int, input().split())
    a = [list(map(int, input().split())) for i in range(n)]
    b = [int(input()) for m in range(m)]
    print(main(a, b), end='')



Measured memory_bytes: 6008
import sys
input=sys.stdin.readline
def main():
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    zeros=[0]*n

    if min(a)==n:
        print(*a)
        exit()

    for i in range(k):
        x=zeros.copy()
        for j in range(n):
            if a[j]==0:
                l=j
                r=min(j+1,n)
                #print(l,r)
                x[l]+=1
                if r!=n:
                #print(r)
                    x[r]+=-1
                #print(x)
            else:
                l=max(0,j-a[j])
                r=min(j+a[j]+1,n)
                #print(l,r)
                x[l]+=1
                if r!=n:
                    #print(r)
                    x[r]+=-1
                #print(x)
        ruiseki=[0]*n
        ruiseki[0]=x[0]
        a[0]=ruiseki[0]
        for i in range(1,n):
            ruiseki[i]=ruiseki[i-1]+x[i]
            a[i]=ruiseki[i]
        if min(a)==n:
            print(*a)
            exit()
 
        #print(*ruiseki)
    print(*a)
if __name__=="__main__":
    main()


Measured memory_bytes: 153116
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<long long int> vint;
typedef vector<string> vstr;
typedef long long int llint;



int main(void) {
	int N, M;
	int cou = 0;
	cin >> N >> M;
	vector<tuple<int, int, int>> P(M);
	vector<tuple<int, int, int>> ans(M);
	for (int i = 0; i < M; i++){
		int p, y;
		cin >> p >> y;
		P[i] = make_tuple(p, y, i);
	}
	sort(P.begin(), P.end());
	for (int i = 0; i < M; i++){
		int num0, num2;
		num0 = get<0>(P[i]);
		num2 = get<2>(P[i]);
		cou++;
		if (i != 0){
		    int jur=get<0>(P[i-1]);
			if (num0 != jur)cou = 1;
		}
		ans[i] = make_tuple(num2, num0, cou);
	}
	sort(ans.begin(), ans.end());
	for (int i = 0; i < M; i++){
			int town = get<1>(ans[i]);
			int num = get<2>(ans[i]);
			cout << setw(6) << setfill('0')<<town <<setw(6) << setfill('0')<< num << endl;
		}
	

}


Measured memory_bytes: 3840
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
//#include<>
using namespace std;

typedef long long int64;
typedef int int32;
typedef char int8;
typedef int32 int__;
#define rep(i,j) for(int__ i=0;i<j;i++)
#define repeat(i,j,k) for(int__ i=(j);i<(k);i++)
#define repeat_eq(i,j,k) for(int__ i=(j);i<=(k);i++)
#define all(v) (v).begin(),(v).end()

const int INF=1<<30;//=10E10

enum Direction{U,R,D,L,None};

struct state{
  int x,y;
  Direction dir;
  int cost;
  state(int x_,int y_,Direction dir_,int c):x(x_),y(y_),dir(dir_),cost(c){;}
  bool operator>(const state &r)const{
    return cost>r.cost;
  }
};

int main()
{
  int w,h;
  while(true){
    //input
    cin>>w>>h;
    if(!w&&!h)break;
    int s[30][30];
    rep(i,h)rep(j,w)cin>>s[i][j];
    int cost[4];rep(i,4)cin>>cost[i];

    //solve
    int dijk[30][30][4];//[y][x][dir]
    rep(i,h)rep(j,w)rep(k,4)dijk[i][j][k]=INF;
    priority_queue<state,vector<state>,greater<state> > que;
    que.push(state(0,0,R,0));
    
    while(!que.empty()){
      state now =que.top();que.pop();
      if(dijk[now.y][now.x][now.dir]!=INF)continue;
      dijk[now.y][now.x][now.dir]=now.cost;

      Direction afturn;
      if(s[now.y][now.x]==4)
	afturn=None;
      else
	afturn=(Direction)((now.dir+s[now.y][now.x])%4);
      
      if(now.x  >0)que.push(state(now.x-1,now.y,L,now.cost+(afturn==L?0:cost[(L-now.dir+4)%4])));
      if(now.y  >0)que.push(state(now.x,now.y-1,U,now.cost+(afturn==U?0:cost[(U-now.dir+4)%4])));
      if(now.x+1<w)que.push(state(now.x+1,now.y,R,now.cost+(afturn==R?0:cost[(R-now.dir+4)%4])));
      if(now.y+1<h)que.push(state(now.x,now.y+1,D,now.cost+(afturn==D?0:cost[(D-now.dir+4)%4])));
    }
    
    int ans=INF;
    rep(i,4)
      ans=min(ans,dijk[h-1][w-1][i]);
    cout<<ans<<endl;
  }

  
  return 0;
}

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

int main()
{
    int N;
    scanf("%d", &N);
    ll A[N];
    for(int i = 0; i < N; ++i) scanf("%lld", &A[i]);
    for(int i = 1; i < N; ++i) A[i] += A[i-1];
    ll res = (2e14 + 100);
    for(int i = 0; i < N-1; ++i) {
        ll snuke = A[i];
        ll kuma = A[N-1] - A[i];
        res = min(res, abs(snuke - kuma));
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <memory>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < (i##_MACRO); i++)
#define RANGE(i, a, b) for(int i = (a); i < (b); i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), a + n
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

auto init_mod_comb() {
#ifndef MODNUM
	static_assert(false, "MODNUM is not defined.");
#endif
#ifndef MOD
	static_assert(false, "MOD() is not defined.");
#endif

	const int COMB_MAX = 10000000;
	vector<ll> fact(COMB_MAX);
	vector<ll> fact_inv(COMB_MAX);
	vector<ll> inv(COMB_MAX);

	fact[0] = fact[1] = 1;
	fact_inv[0] = fact_inv[1] = 1;
	inv[1] = 1;

	RANGE(i, 2, COMB_MAX) {
		fact[i] = MOD(fact[i - 1] * i);
		inv[i] = MODNUM - MOD(inv[MODNUM % i] * (MODNUM / i));
		fact_inv[i] = MOD(fact_inv[i - 1] * inv[i]);
	}

	return
		[fact = move(fact), fact_inv = move(fact_inv)](const ll n, const ll r) {
			if(n < r || n < 0 || r < 0) {
				return 0LL;
			}
			return MOD(fact[n] * MOD(fact_inv[r] * fact_inv[n - r]));
		};
}

int main() {
	int x, y;
	scanf("%d %d", &x, &y);

	double nx, ny;
	nx = (2 * y - x) / 3.0;
	ny = y - 2 * nx;

	if(abs(nx - static_cast<int>(nx)) > EPS ||
	   abs(ny - static_cast<int>(ny)) > EPS) {
		puts("0");
		return 0;
	}

	auto mod_comb = init_mod_comb();

	printf("%lld\n", mod_comb(nx + ny, nx));

	return 0;
}

Measured memory_bytes: 234624
n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
ans=-10**18
for i in range(1,2**10):
  idx=set()
  for j in range(10):
    if (i>>j)&1:
      idx.add(j)
  s=0
  for j in range(n):
    cnt=0
    for k in range(10):
      if k in idx:
        if f[j][k]:
          cnt+=1
    s+=p[j][cnt]
  ans=max(ans,s)
print(ans)

Measured memory_bytes: 43500
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	int a[200001];
	ll asum[200001];
	scan(N);
	rep(i,N){
		scan(a[i]);
		if(i!=0) asum[i]=asum[i-1]+a[i];
		else asum[0]=a[i];
	}
	ll goukei=asum[N-1];
	ll absmin=INFl;
	rep(i,N-1){
		absmin=min(absmin,abs(asum[i]-(goukei-asum[i])));
		//prin(absmin);
	}
	prin(absmin);
	return 0;
}


Measured memory_bytes: 2560
n, h = map(int,input().split())
throw = []
attack = 0
for _ in range(n):
    a, b = map(int,input().split())
    throw.append(b)
    attack = max(attack, a)
throw.sort(reverse=True)

ans = 0
for t in throw:
    if t > attack:
        ans += 1
        h -= t
        if h <= 0:
            break
    else:
        break
if h > 0:
    ans += -(-h//attack)

print(ans)

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

long long ans = 0;
int n;
char str[500005];

long long parse_segment(int &st){
	int op = 0, clo = 0;
	while(st < n && str[st] == '<'){
		op++;
		st++;
	}
	while(st < n && str[st] == '>'){
		clo++;
		st++;
	}
	int top_elem = max(op, clo);
	return top_elem + 1LL * op * (op - 1) / 2 + 1LL * clo * (clo - 1) / 2;
}

int main(){
	cin.getline(str, 500005);
	n = strlen(str);
	for(int i = 0; i < n;){
		ans += parse_segment(i);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.InputStreamReader;

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]);
		String s = br.readLine();
		br.close();

		int ans = 0;
		int idx = 0;
		while (idx < n) {
			idx = s.indexOf("ABC", idx);
			if (idx >= 0) {
				ans++;
				idx++;
			} else {
				break;
			}
		}
		System.out.println(ans);
	}
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
#define allsortg(v)sort(v.begin(),v.end(),greater<int>());
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	cout << "ABC" << N << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define maxn 200005
#define endl '\n'
using namespace std;
int col[maxn];
vector<int> G[maxn];
ll cal(int n) {
	return (ll)n * (n + 1) / 2;
}
int sz[maxn];
ll cnt[maxn];
ll ans[maxn];
void dfs(int u,int pa) {
	sz[u] = 1;
	ll tem = cnt[col[u]];
	cnt[col[u]] = 0;
	for(int v : G[u])
		if(v != pa) {
			dfs(v,u);
			sz[u] += sz[v];
			ans[col[u]] -= cal(sz[v] - cnt[col[u]]);
			cnt[col[u]] = 0;
		}
	cnt[col[u]] = tem + sz[u];
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		cin >> col[i];
	for(int i=1,u,v;i<n;i++) {
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	fill(ans+1,ans+1+n,cal(n));
	dfs(1,1);
	for(int i=1;i<=n;i++)
		cout << ans[i] - cal(n - cnt[i]) << endl;
	return 0;
}

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

using namespace std;

int main(){
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  
  vector<long long> p(A), q(B), r(C);
  
  for(int i = 0; i < A; i++) cin >> p[i];
  for(int i = 0; i < B; i++) cin >> q[i];
  for(int i = 0; i < C; i++) cin >> r[i];
  
  sort(p.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());
  sort(r.rbegin(), r.rend());
  
  priority_queue<long long, vector<long long>, greater<long long>> ps, qs;
  for(int i = 0; i < X; i++) ps.push(p[i]);
  for(int i = 0; i < Y; i++) qs.push(q[i]);
  
  for(int i = 0; i < C; i++){
    if(ps.top() >= qs.top() && qs.top() < r[i]){
      qs.pop();
      qs.push(r[i]);
    }else if(ps.top() < qs.top() && ps.top() < r[i]){
      ps.pop();
      ps.push(r[i]);
    }else break;
  }
  
  long long sum = 0;
  while(!ps.empty()){
    sum += ps.top();
    ps.pop();
  }
  
  while(!qs.empty()){
    sum += qs.top();
    qs.pop();
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 4852
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <iomanip>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int lli;
using namespace std;
// #define int long long int

inline void swap(int &a, int &b) {
    int tmp = a;
    a = b;
    b = tmp;
}

inline lli mod_pow(lli x, lli y) {
    lli ret = 1;
    while (y > 0) {
        if (y & 1) ret = ret * x;
        x = x * x;
        y = y >> 1;
    }
    return ret;
}

signed main() {
    lli N, K;
    cin >> N >> K;
    // コイントスの回数をm
    vector<long double> m_arr;
    lli k = K;
    lli n = N;
    while (n > 0) {
        if (n > k - 1) {
            m_arr.push_back(n - k + 1);
            n -= n - k + 1;
        }
        else {
            m_arr.push_back(0);
        }
        k = (k + 1) / 2;
    }
    long double div = 1.;
    long double ans = 0.;
    for (auto it = m_arr.begin(); it != m_arr.end(); ++it) {
        ans += (long double)(*it) * div;
        div /= 2.;
    }
    cout << fixed;
    cout << setprecision(9) << ans / (long double) N << endl;
    return 0;
}


Measured memory_bytes: 888