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

class Main{
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();

        if(B/A>C){
            System.out.println(C);
        }else{
            System.out.println(B/A);
        }
    }
}

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

using namespace std;

long long inf=1000000007;

int main(){
	long long n;
	cin>>n;
	map<string,long long> hoge;
	for(long long i=0;i<n;i++){
		string t;
		cin>>t;
		hoge[t]++;
	}

	cout<<"AC x "<<hoge["AC"]<<endl;
	cout<<"WA x "<<hoge["WA"]<<endl;
	cout<<"TLE x "<<hoge["TLE"]<<endl;
	cout<<"RE x "<<hoge["RE"]<<endl;

	return 0;
}


Measured memory_bytes: 3632
import string

S = input()
ret = 1000

for c in string.ascii_letters:
    if c not in S:
        continue

    k = 0
    t = S
    nt = ""

    while t.count(c) != len(t):
        k += 1
        nt = ""
        for i in range(len(t) - 1):
            if t[i] == c or t[i + 1] == c:
                nt += c
            else:
                nt += t[i]
        t = nt

    ret = min(ret, k)

print(ret)


Measured memory_bytes: 4084
import sys
sys.setrecursionlimit(1000000000)

from math import factorial
n,k=map(int,input().split())
a=list(map(int,input().split()))
p=10**9+7

def combi(m, r):
    if m - r < r: r = m - r
    if r == 0: return 1
    if r == 1: return m

    nume = [m - r + j + 1 for j in range(r)]
    deno = [j + 1 for j in range(r)]

    for l in range(2,r+1):
        pivot = deno[l - 1]
        if pivot > 1:
            offset = (m - r) % l
            for j in range(l-1,r,l):
                nume[j - offset] /= pivot
                deno[j] /= pivot

    result = 1
    for l in range(r):
        if nume[l] > 1:
            result *= int(nume[l])

    return result

cnt=0
cnt2=0
if n==1:
    print("0")
else:
    for i in range(n-1):
        for j in range(i+1,n):
            if a[i]>a[j]:
                cnt+=1
    if k==1:
        coef=1
    else:
        for i in range(n-1):
            for j in range(i+1,n):
                if a[i] < a[j]:
                    cnt2+=1
        coef=combi(k,2)
    print(int((coef*(cnt+cnt2)+cnt*k) % p))

Measured memory_bytes: 3316
use std::io::{self, Read};

fn readLine() -> String {
    let mut buf = String::new();
    io::stdin().read_to_string(&mut buf);
    buf
}

fn main() {
    let vec : Vec<i32> = readLine().split_whitespace().map(|s| s.parse::<i32>().unwrap()).collect();
    let (x, a, b) = (vec[0], vec[1], vec[2]);
    // println!("{} {} {}", x, a, b);
    println!("{}", if a >= b {
        "delicious"
    } else if a + x >= b {
        "safe"
    } else {
        "dangerous"
    });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    int a[1010];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int q;
    cin >> q;
    int b, e, k;
    while(q--){
        cin >> b >> e >> k;
        int count=0;
        for(int i=b; i<e; i++){
            if(a[i]==k) count++;
        }
        cout << count << "\n";
    }
    
    
    return 0;
}


Measured memory_bytes: 3116
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine.toInt
  val Array(d, x) = StdIn.readLine.split(" ").map(_.toInt)
  val eated = Iterator.continually(StdIn.readLine.toInt)
    .take(n)
    .map(a => (1 to d by a).size)
    .toList
    .sum
  println(eated + x)
}

Measured memory_bytes: 25420
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int a,b,m;
  cin >> a >> b >> m;
  vi reizouko(a);
  vi wasureta(b);
  vector<tuple<int,int,int>> sale(m);
  rep(i,a) cin >> reizouko[i];
  rep(i,b) cin >> wasureta[i];
  rep(i,m) cin >> get<0>(sale[i]) >> get<1>(sale[i]) >> get<2>(sale[i]);
  int sum = 100100100100;
  rep(i,m) {
    int a = reizouko[get<0>(sale[i]) - 1] + wasureta[get<1>(sale[i]) - 1] - get<2>(sale[i]);
    sum = min(sum,a);
  }
  sort(reizouko.begin(), reizouko.end());
  sort(wasureta.begin(), wasureta.end());
  int ans = reizouko[0] + wasureta[0];
  cout << min(ans,sum) << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

void f()
{
  string s;
  cin>>s;
  for(int i=0;i<3;i++)
  {
    if(s[i]=='1')
      cout<<9;
    else
      cout<<1;
  }
  cout<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A+B == C+D) {
    cout << "Balanced" << endl;
  }
  else if (A+B > C+D){
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int L[100010];
int A[310][310];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, D;
    cin >> H >> W >> D;
    rep(i, H) rep(j, W) cin >> A[i][j];
    map<int, pair<int, int>> mp;
    rep(i, H) rep(j, W) {
        mp[A[i][j]] = {i, j};
    }
    rep(i, D) {
        int x = i + 1;
        while(x + D <= H * W){
            int x1 = mp[x].first;
            int y1 = mp[x].second;
            int x2 = mp[x + D].first;
            int y2 = mp[x + D].second;
            int cost = abs(x1 - x2) + abs(y1 - y2);
            L[x + D] = L[x] + cost;
            //cout << L[x + D] << " ";
            x += D;
        } 
    }
    int Q; cin >> Q;
    while(Q--) {
        int l, r; cin >> l >> r;
        cout << L[r] - L[l] << endl;
    }



    return 0;
}


Measured memory_bytes: 7424
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
/* 最大公約数 */
long gcd(long m, long n) {
	long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}
int main()
{
	int		a,b,c,i,j,k,n,m,x,y,ans = 0;
	char	str[256];
	
	scanf("%d %d", &x,&y);

	a = gcd(x,y);
	if (a>1) ans = x + y - (a - 1);
	else ans = x + y;

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

	return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
      int N, A, B;
      cin >> N >> A >> B;
      
      int result = A * N;
      
      if(result < B){
        cout << result << endl;
      }else{
        cout << B << endl;
      }
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  int x;
  cin >> x;
  if (x==0) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}

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

using namespace std;

int main(){
  string S;
  cin >> S ;
  string SS;
  string firstSS;
  string lastSS;
  string flag;
  flag = "0";
  reverse_copy(S.begin(), S.end(), std::back_inserter(SS));
  
  if (S == SS) {
    string firstS = S.substr(0,(S.length()-1)/2);
    string lastS = S.substr(((S.length()+3)/2)-1);
    reverse_copy(firstS.begin(), firstS.end(), std::back_inserter(firstSS));
    reverse_copy(lastS.begin(), lastS.end(), std::back_inserter(lastSS));
    if (firstS == firstSS) {
      if(lastS == lastSS) {
        flag = "1";
      }
    }
  }
  if (flag == "0") {
    cout << "No" << endl;
  } else if (flag == "1") {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
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();
		for(int i=0;i<b;i++) {
			int k =sc.nextInt();
			a-=k;
		}
		if(a>=0) {
			System.out.println(a);
		}else {
			System.out.println(-1);
		}
		
		
	}

}


Measured memory_bytes: 46224
x1,y1,x2,y2=io.read("*n","*n","*n","*n")
a,b=x2-x1,y2-y1
x3,y3=x2-b,y2+a
x4,y4=x3-a,y3-b
print(x3.." "..y3.." "..x4.." "..y4)

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	std::string line;
	std::getline( std::cin, line );

	std::string::size_type p = 0,
						   s = line.size();
	int d = 'A' - 'a';
	char c;
	while( p < s )
	{
		c = line.at(p);

		if('a' <= c && c <= 'z')
			c = c + d;
		else if('A' <= c && c <= 'Z')
			c = c - d;

		std::cout << c;
		++p;
	}

	std::cout << "\n";

	return 0;
}

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

int main(){
    int n,a,b,sum;
    cin>>n>>a>>b;

    sum = n*a;

    if(sum>b){
        cout<<b;
    }
    else if(sum==b){
        cout<<sum;
    }
    else{
        cout<<sum;
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

a,b,c,d=map(int,input().split())
if (a*b>=c*d):
    print(a*b)
else:
    print(c*d)

Measured memory_bytes: 38384
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

H, W = map(int, input().split())
pic = [['#' for i in range(W+2)] for j in range(H+2)]

for i in range(H):
    S = input()
    for j in range(W):
        S1 = S[j]
        pic[i+1][j+1] = S1

for i in range(H+2):
    for j in range(W+2):
        print(pic[i][j], end="")
    print('', end='\n')


Measured memory_bytes: 9164
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 500050;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;


double dist(double x1, double x2, double y1, double y2) {
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
double dist(P &p1, P &p2) {
	double x1 = p1.first, x2 = p2.first, y1 = p1.second, y2 = p2.second;
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}



int cnt[10][10];
void solve() {
	int N; cin >> N;
	FOR(i, 1, N + 1) {
		int r = i % 10;
		int x = i;
		int l = 0;
		while (x > 0) {
			l = x % 10;
			x /= 10;
		}
		cnt[l][r]++;
	}
	ll ans = 0;
	REP(l, 10)REP(r, 10)ans += cnt[l][r] * cnt[r][l];
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;


/*そのような値Pは何かというと、
「ペアの積のうち、P以下のものがK個以上存在する」を満たすような最小のPのことである。
*/
long long N, K;
long long A[200000];
int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	sort(A, A + N);
	long long int_min = -2000000000000000000;
	long long int_max = 2000000000000000000;
	while (int_max - int_min > 1) {
//		cout << int_min << " " << int_max << "\n";
		long long int_mid = (int_min + int_max) / 2;
//		ペアの積のうち、int_mid以下のものがK個以上存在するか？
		long long count = 0;
		for (int i = 0; i < N; i++) { 
//			A[i] * A[j], j=i+1,...,Nを考える
			if (A[i] < 0) {
//				A[i] * A[j] <= int_mid ... A[j] >= int_mid/A[i]  
//				A[i] * A[j] <= int_midを満たすような最小のjを探したい。
				int jmin = i;
				int jmax = N;
				while (jmax - jmin > 1) {
					int jmid = (jmax + jmin) / 2;
					if (A[i] * A[jmid] <= int_mid) {
						jmax = jmid;
					}
					else {
						jmin = jmid;
					}
				}

				count += N - jmax;
//				cout << N - jmax << "\n";
			}
			else {
//				A[i] * A[j] <= int_mid ... A[j] <= int_mid/A[i] 
//				A[i] * A[j] <= int_midを満たすような最大のjを探したい。
				int jmin = i;
				int jmax = N;
				while (jmax - jmin > 1) {
					int jmid = (jmax + jmin) / 2;
					if (A[i] * A[jmid] <= int_mid) {
						jmin = jmid;
					}
					else {
						jmax = jmid;
					}
				}
				count += jmin - i;

//				cout << jmin - i << "\n";
			}
		}
//		cout << "count:" << count << "\n";
		if (count >= K) { int_max = int_mid; }
		else { int_min = int_mid; }
	}

	cout << int_max;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{

    ll n,m,i,j,k,p,q,o,l,s,t;
   cin>>n>>m;
   if(n*500>=m)
   {
       cout<<"Yes"<<endl;
   }
   else{cout<<"No"<<endl;}
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

class SegmentTree {
        int sz, e;
        vector<int> node;
    public:
        SegmentTree() {}
        SegmentTree(int n, int e_): e(e_) {
            sz = 1;
            while (sz < n) sz <<= 1;
            node.assign(2 * sz - 1, e);
        }

        void update(int idx, int exist) {
            idx += sz - 1;
            node[idx] = exist;
            while (idx > 0) {
                idx = (idx - 1) / 2;
                node[idx] = max(node[idx * 2 + 1], node[idx * 2 + 2]);
            }
        }

        int query(int a, int b) {
            return query(a, b + 1, 0, 0, sz);
        }

        int query(int a, int b, int k, int l, int r) {
            if (a >= r || b <= l) return 0;
            if (a <= l && b >= r) return node[k];
            int c = query(a, b, 2 * k + 1, l, (l + r) / 2);
            int d = query(a, b, 2 * k + 2, (l + r) / 2, r);

            return max(c, d);
        }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<SegmentTree> alp;
    rep (i, 26) {
        SegmentTree seg = SegmentTree(n, 0);
        alp.push_back(seg);
    }
    rep (i, s.size()) alp[s[i] - 'a'].update(i, 1);
    rep (_, q) {
        int t;
        cin >> t;
        if (t == 1) {
            int idx;
            char c;
            cin >> idx >> c;
            idx--;
            rep (i, 26) alp[i].update(idx, 0);
            alp[c - 'a'].update(idx, 1);
        } else {
            int res = 0;
            int l, r;
            cin >> l >> r;
            l--, r--;
            rep (i, 26) res += alp[i].query(l, r);
            cout << res << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 113432
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p=-1) {
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i,q) {
    int p, x;
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);
  rep(i,n) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 24320
use std::io::{self, BufRead};
use std::cmp::max;

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let n: usize = lines.next().unwrap().unwrap().parse().unwrap();
  let mut xss: Vec<Vec<usize>> = Vec::new();
  for _ in 0..n {
    let zs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse::<usize>().unwrap() - 1).collect();
    xss.push(zs);
  }
  let mut ixs: Vec<usize> = vec![0; n];
  let mut ds: Vec<usize> = vec![0; n];
  let mut i: usize = 0;
  let mut updated = false;
  loop {
    if ixs[i] < xss[i].len() {
      let j = xss[i][ixs[i]];
      if ixs[j] < xss[j].len() {
        let k = xss[j][ixs[j]];
        if i == k {
          updated = true;
          ixs[i] += 1;
          ixs[j] += 1;
          let d = max(ds[i], ds[j]) + 1;
          ds[i] = d;
          ds[j] = d;
        }
      }
    }
    i += 1;
    if n <= i {
      if !updated {
        break;
      }
      i = 0;
      updated = false;
    }
  }
  let ok = (0..n).all(|i| xss[i].len() == ixs[i]);
  if ok {
    println!("{}", ds.iter().max().unwrap());
  } else {
    println!("-1");
  }
}

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

signed main(){
    int X,Y; cin>>X>>Y;
    if((Y-2*X)%2!=0 or (4*X-Y)%2!=0){
        cout<<"No"<<endl;
        return 0;
    }else if(Y-2*X<0 or 4*X-Y < 0){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
}

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

using namespace std;

#define int long long

const int N = 3e5+5,mod = 998244353;

int binpow(int a,int n){
	int res = 1;
	while(n){
		if(n&1) (res*=a)%=mod,n--;
		else (a*=a)%=mod,n>>=1;
	}
	return res;
}

int inverse(int x){
	return binpow(x,mod-2);
}

vector<int> fact(N,1),inv(N,1);

void preset(){
	fact[0] = 1;
	inv[0] = 1;
	for(int i=1;i<N;i++){
		fact[i] = (fact[i-1]*i)%mod;
		inv[i] = (inv[i-1]*inverse(i))%mod;
	}
}

int nCk(int n,int k){
	if(n<k) return 0;
	return (((fact[n]*inv[k])%mod)*inv[n-k])%mod;
}

signed main(){
	int n,a,b,k,ans = 0;
	cin >> n >> a >> b >> k;
	preset();
	for(int x=0;x<=n;x++){
		if((k-x*a)%b==0){
			int y = (k-x*a)/b;
			if(y<=n && y>=0){
				ans+=nCk(n,x)*nCk(n,y)%mod;
				ans%=mod;
			}
		}
	}
	cout << ans;
}

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

using namespace std;

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

    int p[m];
    string s[m];

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

    int penalty_count[n+1];
    bool is_ac[n+1];
    for (int i=0; i<n+1; i++) {
        is_ac[i] = false;
        penalty_count[i] = 0;
    }

    int success = 0;
    for (int i=0; i<m; i++) {
        if (is_ac[p[i]]) {
            continue;
        }

        bool current_is_ac =  s[i] == "AC";
        if (current_is_ac) {
            is_ac[p[i]] = true;
            success++;
        } else {
            penalty_count[p[i]]++;
        }
    }

    int penalty = 0;
    for (int i=1; i<n+1; i++) {
        if (is_ac[i]) {
            penalty += penalty_count[i];
        }
    }

    cout << success << " " << penalty << endl;
}


Measured memory_bytes: 6656
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int a;
    int b;
    int x;
    cin>>a>>b>>x;
    if (a<=x && a+b>=x) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin>>N>>K;
  vector<int> as(N+1,0);
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    as.at(a)++;
  }
  as.erase(remove(as.begin(),as.end(),0),as.end());
  sort(as.begin(),as.end());
  int res=0;
  for(int i=0;i<as.size();i++){
    if(as.size()-i<=K){cout<<res<<endl;return 0;}
    res+=as.at(i);
  }
}

Measured memory_bytes: 1024
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7


n = int(readline())

#nCrをmodで割った余りO(r)
def comb(n, r, mod):
    r = min(r, n-r)
    mol = 1
    deno = 1
    for i in range(1, r+1):
        mol = mol * (n-r+i) % mod
        deno = deno * i % mod
    ret = mol * pow(deno, mod-2, mod) % mod
    return ret

k = n//3
ans = 0
for i in range(1,k+1):
    ans = (ans + comb(n-2*i-1, i-1, mod))%mod

print(ans)



Measured memory_bytes: 65148
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long x = (long) Math.pow(k-1, n-1) * k;
        System.out.println(x);
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;

struct edge {
  int from, to, cost;
  edge(int arg_from,int arg_to, int arg_cost) {
    from = arg_from; to = arg_to; cost = arg_cost;
  }
  
  bool operator<(const edge& o) const{
  return cost<o.cost;
  }
};

struct UnionFind {
  vector<int> par;
  int forest_size;
  UnionFind(int N) : par(N) {
    rep(i,N) par[i] = i;
    forest_size = N;
  }

  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }
  bool sameParent(int x, int y) {
    return root(x) == root(y);
  }
};

P x[100100], y[100010];
int main() {
  int n;
  cin >> n;
  rep(i,n) {
    int a,b; cin >> a >> b;
    x[i] = P(a,i); y[i] = P(b,i);
  }
  sort(x,x+n);
  sort(y,y+n);
  
  vector<edge> e;
  rep(i,n-1) {
    int f = x[i].second, t = x[i+1].second;
    int c = x[i+1].first - x[i].first;
    e.push_back(edge(f,t,c));
  }
  rep(i,n-1) {
    int f = y[i].second, t = y[i+1].second;
    int c = y[i+1].first - y[i].first;
    e.push_back(edge(f,t,c));
  }
  
  sort(e.begin(), e.end());
  
  ll ans = 0;
  UnionFind uf(n);
  rep(i,e.size()) {
    int a = uf.root(e[i].from), b = uf.root(e[i].to);
    if (a == b) continue;
    ans += e[i].cost;
    uf.unite(a,b);
    //cout << ans << endl;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7980
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int64_t N;
    cin >> N;
    int64_t sensor=0;
    int64_t hosuu=1E13;
    for(int i = 1; i < 1E6+1; i++){
            if( N % i == 0){
              int64_t j = 0;
              j = N / i;
                if( hosuu > i + j - 2){
                    hosuu = i + j - 2;
                }
            }
        }
    
    cout << hosuu << endl;
}

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

int main()
{
	vector<int> h;
	int n;
	int temp;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> temp;
		h.push_back(temp);
	}
	int count = 0;
	for (int i = 0; i < n; i++) {
		int ok = 1;
		for (int j = 0; j < i; j++) {
			if (h[i] < h[j])
				ok = 0;
		}
		if (ok)
			count++;
	}
	cout << count;
}

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

const int N=2005;

int n,m,q;
int a[N][N],b[N][N],c[N][N];
char ch[N];
int f[N][N];

int get1(int x1,int y1,int x2,int y2)
{
	return a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1];
}

int get2(int x1,int y1,int x2,int y2)
{
	int x=f[x2][y2]-f[x1-1][y2]-f[x2][y1-1]+f[x1-1][y1-1];
	x-=b[x2][y2]-b[x2][y1-1];
	x-=c[x2][y2]-c[x1-1][y2];
	return x;
}


int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",ch+1);
		for(int j=1;j<=m;j++) a[i][j]=ch[j]-'0';
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			f[i][j]=f[i-1][j]+f[i][j-1]-f[i-1][j-1];
			if(a[i][j]) f[i][j]+=a[i+1][j]+a[i][j+1];
		}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			b[i][j]=b[i][j-1];
			if(a[i][j]&&a[i+1][j]) b[i][j]++;
		}
	for(int j=1;j<=m;j++)
		for(int i=1;i<=n;i++)
		{
			c[i][j]=c[i-1][j];
			if(a[i][j]&&a[i][j+1]) c[i][j]++;
		}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
	while(q--)
	{
		int x1,y1,x2,y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		cout<<get1(x1,y1,x2,y2)-get2(x1,y1,x2,y2)<<endl;
	//	cout<<get1(x1,y1,x2,y2)<<' '<<get2(x1,y1,x2,y2)<<endl;
	}
}
	
		
	
	


Measured memory_bytes: 64640
def make_divs(n):
    divs = []
    
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            divs.append(i)
            
            if i!=n//i:
                divs.append(n//i)
    
    return divs

N = int(input())
divs = make_divs(N)
ans = 0

for d in divs:
    if d==1:
        continue
    
    N2 = N
    
    while N2%d==0:
        N2 //= d
    
    if (N2-1)%d==0:
        ans += 1

divs = make_divs(N-1)
ans += len(divs)-1

print(ans)

Measured memory_bytes: 39024
def solve():
    V, E = map(int, input().split())
    edges = [[] for _ in [0]*V]
    for _ in [0]*E:
        s, t, d = map(int, input().split())
        edges[s].append((t, d))

    result = float("inf")
    beam_width = 66
    for i in range(V):
        q = [(0, i, {i})]
        for j in range(V-1):
            _q = []
            append = _q.append
            for cost, v, visited in q[:beam_width+1]:
                for dest, d_cost in edges[v]:
                    if dest not in visited:
                        append((cost+d_cost, dest, visited | {dest}))
            q = sorted(_q)
        for cost, v, visited in q[:beam_width+1]:
            for dest, d_cost in edges[v]:
                if dest == i:
                    if result > cost + d_cost:
                        result = cost + d_cost
                        break

    print(result if result < float("inf") else -1)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 8584
#include <bits/stdc++.h>
using namespace std;
int a[10000000];
int main()
{
    int n,cnt=0;
    cin>>n;
    for(int i=1;i<=2*n;i++)cin>>a[i];
    sort(a+1,a+2*n+1);
    for(int i=1;i<=2*n;i+=2)cnt+=a[i];
    cout<<cnt<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
std::vector<int>A['   '];int N,M,S['   '],B,L,R,I;int U(int z,int u){while(z<=N)S[z]+=u,z+=z&-z;}main(){scanf("%d%d",&M,&N);for(;~scanf("%d%d",&L,&R);)A[R-L+1].push_back(L);for(L=1;L<=N;L++){for(B=M,I=L;I<=N;I+=L)for(R=I;R;)B+=S[R],R-=R&-R;for(int u:A[L])U(u,1),U(u+L,-1),M--;printf("%d\n",B);}}

Measured memory_bytes: 53760
x = gets.to_i

pows = [] # 1000以下のべき乗数の集合
pows << 1

(2..31).each do |n|
  p = 2
  while n ** p <= 1000
    pows << n ** p
    p += 1
  end
end

ans = pows.delete_if {|n| n > x}

puts ans.max

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

int main() {
	vector<int> a(3),b(3),c(4);
	for(int i=0;i<3;i++){
		cin>>a[i]>>b[i];
		c[a[i]-1]++;
		c[b[i]-1]++;
	}
	for(int i=0;i<4;i++){
		if(c[i]==3){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner (System.in)){
			int n = sc.nextInt();
			List<Long> list = new ArrayList<Long>();
			for (int i=0; i<n; i++) list.add(sc.nextLong());
			int times = sc.nextInt();
			for (int i=0; i<times; i++) {
				int start = sc.nextInt();
				int end = sc.nextInt();
				List<Long> sublist = list.subList(start, end);  //参照型にして、変更が反映できるように
				Collections.reverse(sublist);
			}
			for (int i=0; i<n-1; i++) System.out.print(list.get(i) + " ");
			System.out.println(list.get(n-1));
		}
	}
}


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

int main(){
	ll n;
	cin >> n;
	vector <ll> arr(n);
	for (int z=0;z<n;z++){
		cin >> arr[z];
	}
	vector <ll> aaa;
	ll count = n;
	while (arr.size() > 0){
		if (count < 0 ){
			cout << -1 << endl;
			return 0;
		}
		for (int z=n-1;z>-1;z--){
			if (arr[z] == z+1 && arr[z] <= count){
				aaa.push_back(z+1);
				arr.erase(arr.begin()+z);
				break;
			}
		}
		count--;
	}
	for (int z=n-1;z>-1;z--){
		cout << aaa[z] << endl;
	}
	cin >> n;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
    	//final int MAX =200000;
    	
    
    	Scanner sc = new Scanner(System.in);
    	//int n = Integer.parseInt(sc.next());
    	int n =sc.nextInt();
    	int[] R=new int[n];
    	
    	for(int i=0;i<n;i++){
    		// R[i]=Integer.parseInt(sc.next());
    		 R[i]=sc.nextInt();
    	}
    	long maxv=-2000000000;
    			 
    	long minv=R[0];
    	for(int i=1;i<n;i++){
    		maxv=Math.max(maxv,R[i]-minv);
    		minv=Math.min(minv,R[i]);
    	}
    	System.out.println(maxv);
    	
    }
}

Measured memory_bytes: 96456
#include<bits/stdc++.h> 
using namespace std;
#define se second
#define fr first
#define int long long int
#define pb push_back
#define inf 1e18
#define all(v) v.begin(),v.end()
#define CHAL_BAAP_KO_MT_SIKHA ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
/*
    Damn Fast:TheFuckinMastermind
    while(How to solve the Question?){
                Read the Question Again!!
           }
        do
            Practise
    #Motivation::::0/0  
*/
const int N=2e4;
int dp[N+1][101][2];
int n,d;
vector<int> v;
int solve(int idx,int sum,int tight){
    if(idx==n)
    {
        return sum==0;
    }
    if(dp[idx][sum][tight]!=-1)
        return dp[idx][sum][tight];
    int lmt=(tight)?9:v[idx];
    int ans=0;
    for(int i=0;i<=lmt;i++){
        int new_sum=(sum+i)%d;
        ans+=solve(idx+1,new_sum,tight|(i<v[idx]));
        ans%=mod;
    }
    return dp[idx][sum][tight]=ans;
}
signed main()
{
    CHAL_BAAP_KO_MT_SIKHA
    string s;
    cin>>s>>d;
    n=s.length();
    for(int i=0;i<n;i++){
        v.pb(s[i]-'0');
    }
    memset(dp,-1,sizeof(dp));
    int x=(solve(0,0,0)-1+mod)%mod;
    cout<<x<<endl;
}

Measured memory_bytes: 32768
package main

import (
	"fmt"
)

func main() {
	var (
		L int
		R int
	)
	fmt.Scanf("%d %d", &L, &R)

	var mod = 2019

	if R-L+1 > 2019 {
		mod = 0
	} else {

		for i := L; i <= R; i++ {
			for j := i + 1; j <= R; j++ {
				if m := (i * j) % 2019; m < mod {
					mod = m
				}
			}
		}
	}

	fmt.Println(mod)
}

Measured memory_bytes: 512
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


def solve(x):
    return x.index(0) + 1


if __name__ == "__main__":
    x = arr_in()
    out(solve(x))

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

int main () {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    if (A + B > C + D) {
        cout << "Left" << endl;
    }
    else if (A + B == C + D) {
        cout << "Balanced" << endl;
    }
    else {
        cout << "Right" << endl;
    }
}

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

int gcd(LL a, LL b){
	if(b == 0) return a;
	return gcd(b, a % b);
}

int main() {
	LL a, b;
	while(cin >> a >> b){
		cout << gcd(a, b) << " " << a * b / gcd(a, b) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

struct UnionFind{
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};

signed main(){
  int n,m;
  cin>>n>>m;
  int a=-1;
  UnionFind uf(m+1);
  vector<int> used(m+1,0);
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    int x;
    cin>>x;
    if(a==-1)a=x;
    used[x]=1;
    for(int i=1;i<k;i++){
      int y;
      cin>>y;
      used[y]=1;
      uf.unite(x,y);
    }
  }
  bool f=true;
  for(int i=1;i<m+1;i++){
    if(used[i]){
      if(!uf.same(a,i))f=false;
    }
  }
  if(f)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 2560
using System;

class ABC075C
{
	static bool[,] connected;
	static bool[] check;
	static int N, M;
	static public void Main(string[] args)
	{
		string[] vals = Console.ReadLine().Split(' ');
		N = int.Parse(vals[0]);
		M = int.Parse(vals[1]);
		int[] a = new int[M+1];
		int[] b = new int[M+1];
		connected = new bool[N+1, N+1];
		for(int i=1; i<=M; i++)
		{
			vals = Console.ReadLine().Split(' ');
			a[i] = int.Parse(vals[0]);
			b[i] = int.Parse(vals[1]);
			connected[a[i],b[i]] = true;
			connected[b[i],a[i]] = true;
		}

		int ans = 0;
		for(int i=1; i<=M; i++)
		{
			connected[a[i],b[i]] = false;
			connected[b[i],a[i]] = false;
			if(!isConnected())
				ans++;
			connected[a[i],b[i]] = true;
			connected[b[i],a[i]] = true;
		}
		Console.WriteLine(ans);
		
	}

	static bool isConnected()
	{
		check = new bool[N+1];
		dfs(1);
		bool ret = true;
		for(int i=1; i<=N; i++)
		{
			if(check[i] == false)
			{
				ret = false;
				break;
			}
		}
		return ret;
	}

	static void dfs(int n)
	{
		check[n] = true;
		for(int m = 1; m<=N; m++)
		{
			if(connected[n,m] && check[m] == false)
			{
				dfs(m);
			}
		}
	}
}


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

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
	vector<ll> v(4,0);
	rep(i,0,3){
		ll a,b;
		cin>>a>>b;
		a--;b--;
		v[a]++;
		v[b]++;
	}
	sort(all(v));
	ll flag = 1;
	ll d[4] = {1,1,2,2};
	rep(i,0,4){
		if(v[i]!=d[i])flag = 0;
	}
	if(flag==1){
	    cout << "YES" << endl;
	}
	else{
	    cout << "NO" << endl;
	}
 	return 0;
}

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

using namespace std;

int main() {
    vector<int> a;
    for (int i = 0; i < 3; ++i) {
        int b;
        cin >> b;
        a.push_back(b);
    }
    sort(a.begin(), a.end());
    cout << a[0] << " " << a[1] << " " << a[2] << '\n';
}


Measured memory_bytes: 3044
#include<stdio.h>
#define MAX 100000

int main( ){
  int i,j,n;
  int A[MAX+1];

  scanf("%d",&n);
  for(i = 1; i <= n; i++){
    scanf("%d",&A[i]);
  }

  for(i = 1; i <= n; i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i/2>=1){
      printf("parent key = %d, ",A[i/2]);
    }
    if(i * 2 <= n){
      printf("left key = %d, ",A[i*2]);
    }
    if(i*2+1 <= n){
      printf("right key = %d, ",A[i*2+1]);
    }
      printf("\n");
    
  }
    return 0;
  }



Measured memory_bytes: 2044
import sys
sys.setrecursionlimit(1000000)
 
def ans():
    def dfs(v, p, d):
        depth[v] = d
        for e, cost in tree[v]:
            if e == p:
                continue
            dfs(e, v, d + cost)
 
    n = int(input())
    tree = [[] for _ in range(n + 1)]
    depth = [0] * (n * 2)
    for _ in range(1, n):
        a, b, c = map(int, input().split())
        tree[a].append((b, c))
        tree[b].append((a, c))
 
    q, k = map(int, input().split())
    dfs(k, -1, 0)
    for _ in range(q):
        x, y = map(int, input().split())
        print(depth[x] + depth[y])
 
 
ans()

Measured memory_bytes: 153200
#include<stdio.h>
int main()
{
    int n,i,j;
     scanf("%d",&n);
    char s1[n];
     char s2[n];
     char s3[n+n];
    //gets(s1);
    //gets(s2);
    scanf("%s",s1);
      scanf("%s",s2);
    for(i=0,j=0;j<2*n;i++)
    {
        s3[j]=s1[i];
        j++;
        s3[j]=s2[i];
        j++;

    }
    s3[j]='\0';
   printf("%s\n",s3);
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    ll n, m, d;
    cin >> n >> m >> d;
    if (d != 0LL)
        printf("%.10lf\n", (double)(2LL * (n - d) * (m - 1LL)) / (double)(n * n));
    else 
        printf("%.10lf\n", (double)((m - 1)) / (double)(n));
}

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

int main()
{
	string s, t;
  	cin >> s >> t;
  
    int count = 0;
  	for (int i = 0; i < s.size(); i++)
    {
    	if (s.at(i) != t.at(i)) count++;
    }
  
    cout << count << endl;
  
  	return 0;
}

Measured memory_bytes: 3832
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    dn = [0]*13
    dn[0] = 1
    for i in ipt().split():
        dn[int(i)] += 1
    st = set()
    if dn[12] > 1:
        print(0)
        exit()
    elif dn[12] == 1:
        st.add(12)
    if dn[0] > 1:
        print(0)
        exit()
    elif dn[0] == 1:
        st.add(0)
    p = 1

    for i,di in enumerate(dn[1:12:]):
        if di > 2:
            print(0)
            exit()
        elif di == 2:
            st.add(i+1)
            st.add(24-i-1)
        elif di == 1:
            if p:
                st.add(i+1)
                p = 0
            else:
                st.add(24-i-1)
                p = 1

    ma = 25
    st = sorted(st)
#    print(st)
    for i,si in enumerate(st):
        if ma > abs(si-st[i-1]):
            ma = abs(si-st[i-1])
    print(ma)

    return None

if __name__ == '__main__':
    main()


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

int main(){
  while(true){
    int e;
    cin >> e;
    if(e == 0) break;

    int m;
    m = e;

    for(int z = 0 ; z * z * z <= e ; z++){
      for(int y = 0 ; y * y + z * z * z <= e ; y++){
	int x = e - z * z * z - y * y;
	if(m > x + y + z) m = x + y + z;
      }
    }
    cout << m << endl;
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S,T;
  cin >> S >> T;
  string copy;
  int flag=10;
  
  for(int j=0;j<S.size();j++){
    copy=S;
    //Sを汽車ポッポさせて比較する
    for(int i=0; i<S.size();i++){
      if(i==0){//一番前と後ろの交換
        S.at(i)=copy.at(S.size()-1);
      }
      else{
        S.at(i)=copy.at(i-1);
      }
    }
    if(T==S){
      cout<< "Yes" <<endl;
      flag=5;
      break;
    }
  }
  
  if(flag!=5){
    cout<<"No"<<endl;
  }
  
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

typedef long long LL;
const LL MOD = 1000000007;

vector<vector<int> > G, rG;
vector<int> vs;
vector<char> used;
vector<int> cmp;
vector<vector<char> > con;

void add_edge(int f, int t){
	G[f].push_back(t);
	rG[t].push_back(f);
}

void dfs(int v){
	used[v] = 1;
	for(size_t i = 0; i < G[v].size(); ++i){
		if(!used[G[v][i]]){
			dfs(G[v][i]);
		}
	}
	vs.push_back(v);
}

void rdfs(int v, int k){
	used[v] = 1;
	cmp[v] = k;
	for(size_t i = 0; i < rG[v].size(); ++i){
		if(!used[rG[v][i]]){
			rdfs(rG[v][i], k);
		}
	}
}

int scc(){
	used.assign(G.size(), 0);
	cmp.assign(G.size(), 0);
	vs.clear();
	for(size_t v = 0; v < G.size(); ++v){
		if(!used[v]){
			dfs(v);
		}
	}
	used.assign(G.size(), 0);
	int k = 0;
	for(size_t i = vs.size(); i--; ){
		if(!used[vs[i]]){
			rdfs(vs[i], k);
			++k;
		}
	}
	return k;
}

LL solve(int u){
	LL res = 1;
	for(size_t v = 0; v < con.size(); ++v){
		if(con[v][u]){
			LL ret = solve(v);
			res = res * ret % MOD;
		}
	}
	++res;
	return res;
}

int main(){
	int n, m, s, d;
	scanf("%d%d", &n, &m);
	G.resize(n);
	rG.resize(n);
	for(int i = 0; i < m; ++i){
		scanf("%d%d", &s, &d);
		add_edge(s - 1, d - 1);
	}
	
	int c = scc();
	con.assign(c, vector<char>(c));
	for(int i = 0; i < n; ++i)
	for(size_t j = 0; j < G[i].size(); ++j){
		con[cmp[i]][cmp[G[i][j]]] = 1;
	}
	for(int i = 0; i < c; ++i){
		con[i][i] = 0;
	}

	LL ans = 1;
	for(int i = 0; i < c; ++i){
		int cnt = accumulate(con[i].begin(), con[i].end(), 0);
		if(!cnt){
			LL ret = solve(i);
			ans = ans * ret % MOD;
		}
	}
	
	printf("%lld\n", ans);
}

Measured memory_bytes: 2064
#include<stdio.h>
#include<stdbool.h>

short mat[55][55]={{0}};
int a[55],b[55];
short fromlist[60]={0};
int N,M;

bool check(int from,int to,int num);

int main(void){
  int i,j,k;
  int count=0;
  scanf("%d%d",&N,&M);
  for(i=0;i<M;i++){
    scanf("%d%d",&a[i],&b[i]);
    mat[a[i]][b[i]]=mat[b[i]][a[i]]=1;
  }
  
  for(i=0;i<M;i++){
      mat[a[i]][b[i]]=0;
      //printf("i=%d\n",i);
      if(!check(a[i],b[i],0)) count++;
      mat[a[i]][b[i]]=1;
  }
  printf("%d\n",count);
  return 0;
}

bool check(int from,int to,int num){
  int i,j,k;
  if(num==0) for(i=0;i<60;i++) fromlist[i]=0;
  fromlist[num]=from;
  // printf("\tnum=%d\n",num);
  if(from==to || mat[from][to]==1) return true;
  //if(num>N) return false;
  for(i=1;i<=N;i++){
    for(j=0;j<num;j++) if(fromlist[j]==i) break;
    if(j<num && fromlist[j]==i) continue;
    if(mat[from][i]==0) continue;
    if(check(i,to,num+1)) return true;
  }
  return false;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;

int main(){
	int n;
	cin>>n;
	vector<int>p(n),q(n),tmp1(n);
	for(int i=0;i<n;i++){
		cin>>p[i];
		tmp1[i]=p[i];
	}
	for(int i=0;i<n;i++){
		cin>>q[i];
	}
	sort(tmp1.begin(),tmp1.end());
	int ans1=0,ans2=0,res=0;
	bool ok1=true,ok2=true;
	do{
		res++;
		for(int i=0;i<n;i++){
			if(tmp1[i]!=p[i])ok1=false;
			if(tmp1[i]!=q[i])ok2=false;
		}
		if(ok1)ans1=res;
		if(ok2)ans2=res;
		ok1=true,ok2=true;
	}while(next_permutation(tmp1.begin(),tmp1.end()));
	cout<<abs(ans2-ans1)<<endl;
	return 0;
}


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

using namespace std;

//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();}

//typedef
//------------------------------------------
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstring;
typedef pair<int, int> pint;
typedef pair<pint, int> ppint;
typedef pair<int, pint> pintp;
typedef unsigned int uint;
typedef long long llint;
typedef unsigned long long int ullint;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const int INF = 100000000;

//clear memory
#define clear(a) memset((a), 0 ,sizeof(a))

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



int main() {
	while(true) {
		static int n;
		cin >> n;
		if(n == 0)
			break;
		int sum = 0;
		for(int i = 1; i * i < n; i++) {
			if(n % i == 0) {
				sum += i + n / i;
			}
		}
		if(ceil(sqrt((double)n)) == floor(sqrt((double)n))) {
			sum += (int)sqrt((double)n);
		}
		sum -= n;
		if(sum == n) {
			cout << "perfect number" << endl;
		} else if(sum > n) {
			cout << "abundant number" << endl;
		} else {
			cout << "deficient number" << endl;
		}
	}
	return 0;
}

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

int main(){
    int n;
    cin >>n;
    list<int> b;
    int a;
    bool isToback=true;//後ろに追加すべきか
    while(cin >>a){
        if (isToback){
            b.push_back(a);
            isToback=false;
        }else{
            b.push_front(a);
            isToback=true;
        }
    }
    if (isToback){
        for(list<int>::iterator i=b.begin();i != b.end();){
            cout << *i;
            i++;
            if (i!=b.end()){
                cout << " ";
            }
        }
        cout <<endl;
    }else{
        for(list<int>::reverse_iterator i=b.rbegin();i != b.rend();){
            cout << *i;
            i++;
            if (i!=b.rend()){
                cout << " ";
            }
        }
        cout <<endl;
    }

    return 0;
}

Measured memory_bytes: 8576
#include <stdio.h>
#include <string.h>

int main() {

	char arr[12];
	scanf("%s", arr);
	
	char output[12];
	int j=0;
	for(int i=0; arr[i]!='\0'; i++){
		if(arr[i]=='1' || arr[i]=='0'){
			output[j]=arr[i];
			j++;
			}
		else if(j>0){
			if(arr[i]=='B'){
				j--;
				output[j]='\0';
				j--;
			}
			j++;
		}

	}
	
	output[j]='\0';
	printf("%s\n", output);

    return 0;
}


Measured memory_bytes: 3136
import math
n,d=map(int,input().split())
plot=[list(map(int,input().split())) for i in range(n)]
res=0
for i in range(n-1):
  for j in range(i+1,n):
    dist=0
    for k in range(d):
      dist += (plot[j][k]-plot[i][k])**2
    temp = int(math.sqrt(dist))
    res += dist == temp**2
    
print(res)

Measured memory_bytes: 9132