akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
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;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int A,B,C,D; cin >> A >> B >> C >> D;
    cout << min(A,B)+min(C,D) << endl;
    return 0;
}


Measured memory_bytes: 3544
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (ll(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
#define mp make_pair
#define pb push_back
const ll MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e16;
const double PI = acos(-1.0);
int dx[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/06/10  Problem: ABC 064 D / Link: http://abc064.contest.atcoder.jp/tasks/abc064_d  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

ll N;

ll ans = 0LL;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	string S;

	cin >> N;
	cin >> S;
	int cnt1 = 0;
	int cnt2 = 0;
	int f = 0;
	stack<char>s1;
	stack<char>s2;
	FOR(i, 0, S.size()) {
		if (S[i] == '(') {
			s1.push(')');
		}
		else if (S[i] == ')') {
			if (s1.size() >= 1)s1.pop();
			else s2.push('(');
		}


	}
	int x = s2.size();
	FOR(i, 0, x) {
		cout << '(';
	}
	cout << S;
	
	 x = s1.size();
	FOR(i, 0, x) {
		cout << ')';
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    int n; cin>>n;
    vector<ll> a;
    rep(i,n){
        ll b; cin>>b;
        a.push_back(b);
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll ans=0;
    if(n%2==0){
        rep(i,n/2){
            ans+=a[i]*2;
        }
        ans-=a[0];
    }
    else{
        rep(i,n/2+1){
            ans+=a[i]*2;
        }
        ans-=(a[0]+a[n/2]);
    }
    cout<<ans<<endl;
}

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

def judge(x):
    now, cnt = 0, 0
    
    for i in range(n):
        if now+w[i]<=x:
            now += w[i]
        else:
            cnt += 1
            now = w[i]
    
    if now>0:
        cnt += 1
    
    return cnt<=k

def binary_search():
    l, r = max(w), 10**10
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            r = m-1
        else:
            l = m+1
    
    return l

n, k = map(int, input().split())
w = [int(input()) for _ in range(n)]
print(binary_search())



Measured memory_bytes: 9584
def Simple_Calculator(a,b,op):
    if op == '+':
        return a+b
    elif op == '-':
        return a-b
    elif op == '*':
        return a*b
    elif op == '/':
        return a/b
    else:
        return None


def main():
    while True:
        a,op,b= input().split()
        a,b = map(int,(a,b))
        if op == '?':
            break
        else:
            res = Simple_Calculator(a,b,op)
            print("%d" %(res))

if __name__ == "__main__":
    main()


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

int main()
{
    string s;
    string ss;
    string p;
    int lens, lenp;
 
    bool res = false;

    cin >> s;
    cin >> p;

    lens = s.length();
    lenp = p.length();

    if (lens >= lenp) {
        ss = s + s;
        for (int i = 0; i < lens; i++) {
            if (ss.at(i) == p.at(0)) {
                bool hit = true;
                for (int j = 1; j < lenp; j++) {
                    if (ss.at(i+j) != p.at(j)) {
                        hit = false;
                        break;
                    }
                }
                if (hit) {
                    res = true;
                    break;
                }
            }
        }
    }
 
    if (res) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main() {
    int N,x1,y1,t1,x0=0,y0=0,t0=0,flag = 0,mind=0,rem=0;
    cin >> N;

    for (int i = 0; i < N; ++i){
        cin >> t1 >> x1 >> y1;
        mind = abs(x1-x0)+abs(y1-y0);
        // impossible ( too far)
        if (mind > t1-t0){
            flag = 1;
            //cout << "NO" << endl;
            //break;
        }
        // まず最短で行かせて、そこから時間が潰せるか
        else
        {
            rem = t1-t0-mind;
            if (rem%2 ==1 ){
                flag = 1;
                //cout << "NO" << endl;
               // break;
            }
        }
        x0 = x1;
        y0 = y1;
        t0 = t1;
        
    }

    if (flag == 0){
            cout << "Yes" << endl;
    }
    else{
            cout << "No" << endl;
    }
        
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		boolean[] a = new boolean[1000001];Arrays.fill(a, false);
		a[s] = true;
		for (int m = 2; m < 1000001; m++) {
			s = (s%2==0)?s/2:s*3+1;
			if(a[s]) {
				System.out.println(m);
				break;
			}else a[s] = true;
		}
		sc.close();
	}
}

Measured memory_bytes: 23892
import java.util.Scanner;

public class Main{

	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		
		// input
		long width = scan.nextLong();
		long height = scan.nextLong();
		int x = scan.nextInt();
		int y = scan.nextInt();
		
		double area = (width * height) / 2.0;
		System.out.print(area + " ");
		
		if(x + x == width && y + y == height){
			System.out.println("1");
		} else {
			System.out.println("0");
		}
		
		
	}
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define inf 0x7f7f7f7f7f7f7f7f 
#define maxn 1010
#define ri register int
#define il inline
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define mod 998244353
#define db(x) cout << x << endl; 
#define eps 0.0001
using namespace std;
struct node
{
	int a,b,c,d;
}p[maxn];
int v[maxn]={0};
int n,m,q;
int a[maxn];
int ans = 0;
int cnt =0;
il void sol()
{
//	cnt++;
	int res = 0;
	for(int i=1;i<=q;i++)
		if(a[p[i].b] - a[p[i].a] == p[i].c)
			res+= p[i].d;
	ans = max(ans,res);
}
void dfs(int x,int pre)
{
	if(x==n+1)
	{
		sol();
		return;
	}
	for(int i=pre;i<=m;i++)
	//	if(v[i])
		{
			a[x] = i;
			dfs(x+1,i);
			a[x] = 0;
		}
}
signed main()
{
	ios::sync_with_stdio(0);
	cin >> n >> m>> q;
	for(int i=1;i<=q;i++)
	{
		cin >> p[i].a>>p[i].b>>p[i].c>>p[i].d;
	
	}
	dfs(1,1);
	cout << ans;
	return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	ll n,p;cin>>n>>p;
	map<ll,ll> mp;
	ll a=2,q=p;
	while(p>=a*a){
		if(p%a==0){
			p/=a;
			mp[a]++;
			mp[p]++;
		}
		else a++;
	}

//	for(auto i:mp) cout<<i.first<<" : "<<i.second<<"\n";

	ll s=mp.size(),ans=1;
	for(auto i:mp){
		if(i.second>=n) ans*=pow(i.first,(i.second/n));
	}

	if(n==1) ans=q;

	cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include<stdio.h>
int dp[20][20];
int dat[20][20];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<20;i++)
			for(int j=0;j<20;j++)dp[i][j]=dat[i][j]=0;
		for(int i=0;i<b;i++)
			for(int j=0;j<a;j++)
				scanf("%d",&dat[i][j]);
		for(int i=0;i<a;i++)if(dat[0][i]!=1)dp[0][i]=1;
		for(int i=0;i<b;i++){
			for(int j=0;j<a;j++){
				if(dat[i][j]==0){
					if(i<b-1&&j&&dat[i+1][j-1]==0)dp[i+1][j-1]+=dp[i][j];
					if(i<b-1&&j<a-1&&dat[i+1][j+1]==0)dp[i+1][j+1]+=dp[i][j];
					if(dat[i+1][j]!=1)dp[i+1][j]+=dp[i][j];
				}
				if(dat[i][j]==2){
					if(dat[i+2][j]!=1)dp[i+2][j]+=dp[i][j];
				}
			}
		}
		int ret=0;
		for(int i=b;i<20;i++)
			for(int j=0;j<a;j++)
				ret+=dp[i][j];
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 0
n = int(input())
a = list(map(int,input().split()))
dif = max(a) - min(a)
ans = -1
for i in range(dif+1):
    cost = 0
    target = min(a) + i
    for j in a:
        cost += (j - target) **2
    if ans == -1 or ans > cost:
        ans = cost
print(ans)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int integerX = sc.nextInt();  //元の整数
		int youso = sc.nextInt();  //整数列の要素数
		List<Integer> list = new ArrayList<Integer>();  //整数列を入れるリスト

		//配列を入力
		for(int i=0 ; i<youso ; i++) {
			list.add(sc.nextInt());
		}

		//配列が空または整数Xが含まれない場合
		if(list.isEmpty() || ! list.contains(integerX)) {
			System.out.println(integerX);
			return;
		}

		//整数Xから1ずつ足し引きしていく
		for(int i=1 ; i<=100 ; i++) {
			if(! list.contains(integerX-i)) {
				System.out.println(integerX-i);
				break;
			}
			else if(! list.contains(integerX+i)) {
				System.out.println(integerX+i);
				break;
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 27172
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  if (n % 2 != 0) {
    cout << "No" << endl;
  } else {
    if (s.substr(0, n / 2) == s.substr(n / 2, n / 2)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
n,xx=gets.split.map(&:to_i)
x=gets.split.map(&:to_i)
n.times do |i|
  x[i] = (x[i] - xx).abs
end
xm = x.min
i = 1
while true
  if xm % i != 0
    i += 1
    next
  end
  s = xm / i
  f = true
  n.times do |j|
    if x[j] % s != 0
      f = false
      break
    end
  end
  if f
    puts s
    exit
  end
  i += 1
end


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

int n, k, ans;
string s;
int main()
{
	int i;
	cin >> n >> k >> s;
	for (i = 1; i < s.size(); i++) ans += (s[i] == s[i - 1]);
    cout << ans + min(n - ans - 1, k * 2) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N;
	cin >> N;
	int I = 1, cnt = 0;
	for (int i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		if (a != I)
			cnt++;
		else
			I++;
	}
	if (I == 1)
		cout << -1 << endl;
	else
		cout << cnt << endl;
}



Measured memory_bytes: 256
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int main() {
    ll h,w;
    string s[2100];
    std::cin >> h>>w;
    for (int i = 0; i < h; i++) {
        std::cin >> s[i];
    }
    ll row[2500][2500];
    ll col[2500][2100];
    Fill(row,0);
    Fill(col,0);
    
    for (int i = 0; i < h; i++) {
        ll start=-1;
        for (int j = 0; j < w; j++) {
            if(s[i][j]=='#'){
                row[i][j]=0;
                if(start!=-1){
                    for (int k = start;k <= j-1; k++) {
                        row[i][k]=j-start;
                    }
                }
                start=-1;
            }else{
                if(start==-1){
                    start=j;
                }
              if(j==w-1){
                for (int k = start;k <= j; k++) {
                        row[i][k]=j+1-start;
                    }
                }
            }
        }
    }
    for (int j = 0; j < w; j++) {
        ll start=-1;
        for (int i = 0; i < h; i++) {
            if(s[i][j]=='#'){
                col[i][j]=0;
                if(start!=-1){
                    for (int k = start;k <= i-1; k++) {
                        col[k][j]=i-start;
                    }
                }
                start=-1;
            }else{
                if(start==-1){
                    start=i;
                }
              if(i==h-1){
                for (int k = start;k <= i; k++) {
                        col[k][j]=i+1-start;
                    }
                }
            }
        }
    }
   
    ll result=0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            result =max(result,col[i][j]+row[i][j]-1);
        }
    }
    std::cout << result << std::endl;
    
    
}   


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

using namespace std;

int A,B,C,X;
int dp[30000];
int main(){
    cin >> A >> B >> C >> X;
    int cnt = 0;
    for(int i=0; i<=A; i++){
        for(int j=0; j<=B; j++){
            for(int k=0; k<=C; k++){
                if( i * 500 + j * 100 + k * 50 == X ) cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
int main()
{
	int n, k;
	cin >> n >> k;
	map<int, int>mp;
	for (int i = 0; i < k; i++)
	{
		int d;
		cin >> d;
		for (int j = 0; j < d; j++)
		{
			int tmp;
			cin >> tmp;
			mp[tmp]++;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)if (mp[i] == 0)ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3640
n=int(input())
a=[int(i) for i in input().split()]

from collections import Counter

d=Counter(a)
d=d.most_common()
ans = [i for i,j in d if j>=2]
ans2 = [i for i,j in d if j>=4]

if len(ans) <2:
    a1=0
else:
    ans.sort()
    a1 = ans[-1]*ans[-2]
    
if len(ans2)<1:
    a2=0
else:
    ans2.sort()
    a2=ans2[-1]**2
print(max(a1,a2))

Measured memory_bytes: 71960
#include <iostream>

#include <bits/stdc++.h>
#include<string>
#include<string.h>
#define ll long long
#define ll long long
#define ld long double
#define ctoi(x) x-'0'
#define pshb(a) cin >> x;a.push_back(x)
#define fr(i,n) for(ll i=0;i<n;i++)
#define alph "abcdefghijklmnopqrstuvwxyz"
#define alph1 "abcdefghijklmnopqrstuvwxyz"
#include <vector>#include <bits/stdc++.h>
#include<string>
#include<string.h>
#define ll long long
#define ll long long
#define ld long double
#define ctoi(x) x-'0'
#define pb(x) cin>>x; a.push_back(x)
#define srt() sort(a.begin(),a.end())
#define fr(i,n) for(ll i=0;i<n;i++)
#define alph "abcdefghijklmnopqrstuvwxyz"
#define alph1 "abcdefghijklmnopqrstuvwxyz"
#include <vector>
#include<math.h>
#define WUBBAxxLUBAxxDUBxxDUB int main
#define salamo3lekooooom ios::sync_with_stdio(false)
using namespace std;
bool sortbysec(const pair<int,int> &a,
               const pair<int,int> &b)
{
    return (a.second < b.second);
}
#define LIMIT 1000000
long long i, j;
long long prime_flag[LIMIT];
void calculate_prime_flag()
{
    prime_flag[0] = prime_flag[1] = 1;
    for(i=2; i<LIMIT; i++)
    {
        if (prime_flag[i]==0)
        {
            for(j=i*i; j<LIMIT; j+=i)
            {
                prime_flag[j] = 1;
            }
        }
    }
}

#include <iostream>
#include <math.h>
using namespace std;
// Get SHWIFTY
vector<string>v;
int LPS(char *str)
{
    int n=strlen(str);
    int i,j,cl;
    int l[n][n];
    for(i=0; i<n; i++)
        l[i][i]=1;
    for(cl=2; cl<=n; cl++)
    {
        for(i=0; i<n-cl+1; i++)
        {
            j=i+cl-1;
            if(str[i]==str[j]&&cl==2)
                l[i][j]=2;
            else if (str[i]==str[j])
                l[i][j]=l[i+1][j-1]+2;
            else
                l[i][j]=max(l[i][j-1],l[i+1][j]);


        }
    }
    return l[0][n-1];


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

// Function to find gcd of array of
// numbers
int findGCD(int arr[], int n)
{
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}
/////3aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa


vector <int> adj[10];
    bool visited[10];

    void dfs(int s) {
        visited[s] = true;
        for(int i = 0;i < adj[s].size();++i)    {
         if(visited[adj[s][i]] == false)
             dfs(adj[s][i]);
        }
    }

    void initialize() {
        for(int i = 0;i < 10;++i)
         visited[i] = false;
    }

WUBBAxxLUBAxxDUBxxDUB()
{
    salamo3lekooooom;
    ll n;
    cin>>n;
  string x;
  cin>>x;
  ll cnt=0;

  for(int i=0;i<x.size();i++)
    { if(x[i]==x[i+1])
    cnt++;

    }
    cout<<x.size()-cnt<<endl;
}


Measured memory_bytes: 512
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using P = pair<int,int>;
const int INF = 1000100100;

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n, k; cin >> n >> k;
    int a[n];
    rep(i,n) cin >> a[i];

    int dp[k+1];
    rep(i,k+1) dp[i] = 0;

    rep(i,k+1){
        rep(j,n){
            if(i-a[j]>=0 && dp[i-a[j]] == 0) dp[i] = 1;
        }
    }
    if(dp[k]) cout << "First" << endl;
    else cout << "Second" << endl;
}

Measured memory_bytes: 3956
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Set<Integer> set = new HashSet<Integer>();
        for (int i = 0; i < 3; i++) {
            set.add(sc.nextInt());
        }
        if (set.size() == 2) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	ll l;
	cin>>l;
	string s="";
	for(;;){
		s+=(l-1)%26+'a';
		l=(l-1)/26;
		if(l==0){
			break;
		}
	}
	reverse(all(s));
	cout<<s;
	re 0;
}

Measured memory_bytes: 3624
def main():
    N, T = map(int, input().split())

    AB = [tuple(map(int, input().split())) for i in range(N)]

    AB.sort(key=lambda x: x[0])
    maxA = 0
    for a, b in AB:
        maxA = max(maxA, a)

    dp = [-1]*(T+maxA)
    dp[0] = 0

    for a, b in AB:
        for i in range(T+maxA-1, -1, -1):
            if i >= T:
                if i-a < T and i-a >= 0 and dp[i-a] >= 0:
                    dp[i] = max(dp[i], dp[i-a] + b)

            elif i - a >= 0 and dp[i-a] >= 0:
                dp[i] = max(dp[i], dp[i-a] + b)

    print(max(dp))


main()


Measured memory_bytes: 45932
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int r;cin>>r;
    cout<<3*r*r<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int md = 924844033;
const int maxn = 2005;
int a[maxn];
LL fact[maxn], dp[2][maxn][3], f[maxn];

template < class T >
void add(T &a, T b){
    a += b;
    if(a >= md ) a -= md;
}

int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    fact[0] = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = fact[i - 1] * i % md;
    }
    int sz = 0, step = k * 2;
    for(int i = 1; i <= step; i++){
        for(int j = i; j <= n; j += step){
            a[++sz] = j;
        }
    }
    a[0] = -1e9;
    int now = 0, pre = 1;
    dp[now][0][0] = 1;
    for(int i = 1; i <= n; i++){
        now ^= 1, pre ^= 1;
        memset(dp[now], 0, sizeof dp[now]);
        for(int j = 0; j < i; j++){
            for(int x = 0; x < 3; x++){
                if(a[i] - k < 1 && x == 1) continue;
                if(a[i] + k > n && x == 2) continue;
                for(int y = 0; y < 3; y++){
                    if(x == 1 && y == 2 && a[i] - a[i - 1] == 2 * k) continue;
                    add(dp[now][j + (x != 0)][x], dp[pre][j][y]);
                }
            }
        }
    }
    for(int i = 0; i <= n; i++){
        f[i] = (dp[now][i][0] + dp[now][i][1] + dp[now][i][2]) % md;
    }
    LL ans = 0;
    for(int i = 0; i <= n; i++){
        if(i & 1)
            add(ans, (md - fact[n - i] * f[i] % md));
        else
            add(ans, fact[n - i] * f[i] % md);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;
using i64=long long int;

int main() {
    int N;
    cin >> N;
    
    vector<pair<int, int>> s;
    for (int i = 0; i < N; ++i) {
        int A, B;
        cin >> A >> B;
        s.emplace_back(A+B, A);
    }

    sort(s.begin(), s.end(), greater<>());

    i64 t = 0, a = 0;
    bool tf = true;
    for (auto &&p: s) {
        if (tf) {
            t += p.second;
        } else {
            a += p.first - p.second;
        }
        tf = !tf;
    }

    cout << t - a << endl;

    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <vector>

class Node {
public:
	long key;
	int parent, left, right;
	Node() {
		key = -1;
		parent = left = right = -1;
	}
};

class CompleteBT {
public:
	int size;
	std::vector<long> heap;
	std::vector<Node> nodes;
	CompleteBT(int s, std::vector<long> inHeap) {
		heap = inHeap;
		size = s;
		Node n;
		nodes.assign(size, n);
	}
	void makeTree() {
		for (int i = 0; i < size; i++) {
			nodes[i].key = heap[i];
			if (i > 0) {
				nodes[i].parent = (i - 1) / 2;
			}
			if ((i + 1) * 2 - 1 < size) {
				nodes[i].left = (i + 1) * 2 -1;
			}
			if ((i + 1) * 2 < size) {
				nodes[i].right = (i + 1) * 2;
			}
		}
	}
};

void maxHeapify(const int i, std::vector<long> &heap) {
	int l = (i + 1) * 2 - 1; // 左の子
	int r = (i + 1) * 2; // 右の子
	int size = heap.size();

	int max = -1;
	if (l < size && heap[l] > heap[i]) {
		max = l;
	}
	else {
		max = i;
	}
	if (r < size && heap[r] > heap[max]) {
		max = r;
	}
	if (max != i) {
		long tmp = heap[i];
		heap[i] = heap[max];
		heap[max] = tmp;
		maxHeapify(max, heap);
	}
}

void buildMaxHeap(std::vector<long> &heap) {
	for (int i = (heap.size() - 1) / 2; i >= 0; i--) {
		maxHeapify(i, heap);
	}
}

void outputCBT(int size, const CompleteBT &tree) {
	for (int i = 0; i < size; i++) {
		std::cout << "node " << i + 1 << ": key = " << tree.nodes[i].key << ", ";
		if (tree.nodes[i].parent >= 0) {
			std::cout << "parent key = " << tree.nodes[tree.nodes[i].parent].key << ", ";
		}
		if (tree.nodes[i].left >= 0) {
			std::cout << "left key = " << tree.nodes[tree.nodes[i].left].key << ", ";
		}
		if (tree.nodes[i].right >= 0) {
			std::cout << "right key = " << tree.nodes[tree.nodes[i].right].key << ", ";
		}
		std::cout << std::endl;
	}
}

int main() {
	int size;
	std::cin >> size;
	std::vector<long> heap(size);
	for (int i = 0; i < size; i++) {
		std::cin >> heap[i];
	}

	buildMaxHeap(heap);

	//CompleteBT tree(size, heap);
	//tree.makeTree();

	//outputCBT(size, tree);
	for (int i = 0; i < size; i++) {
		std::cout << " " << heap[i];
	}
	std::cout << std::endl;
}


Measured memory_bytes: 6664
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
// x^y≡x^(y%(p-1))mod p
// but there is a condition that x needs to be coprime to p
///assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set; */
typedef long long int ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
#define  pb push_back
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define tests() int test_cases ; cin >> test_cases ; while(test_cases--)
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define sp " "
#define nl '\n'
#define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x,y) memset(x,y,sizeof(x));
#define INF 1000000000000000000
#define IO                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define debug(x) cerr << (#x) << " is " << (x) << endl;

#ifndef ONLINE_JUDGE
#define cerr if(true)cerr
#endif

template<int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
static_assert(D >= 1, "Vector dimension must be greater than zero!");
template<typename... Args>
	Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
	}
};
template<typename T>
struct Vec<1, T> : public vector<T> {
	Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {
	}
};

ll power(ll x, ll y,ll p)
{
    ll res = 1;     // Initialize result
    x = x % p;
    if (y==0)return 1;
    if(x==0)return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;  // Change x to x^2
    }
    return res;
}
int gcd(int a, int b) { if (a == 0)return b;return gcd(b % a, a);}

ll modinv(ll a,ll p){return power(a,p-2,p);}


void solve(){
    ll a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    return ;
}
int main()

{
    IO;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    // #endif
    int T=1;
	// cin >> T;
	f(c,0,T){
		solve();
	}
    return 0;
}// make_pair make_tuple  tuple<int,int,int> continue resize insert count size else true isValid second first false erase double priority_queue


Measured memory_bytes: 3612
import math
import sys
from operator import itemgetter

# N, K = map(int, input().split())
# h = list(map(int, input().split()))
# S = [input() for _ in range(H)]
# X = [[0 for j in range(100)] for i in range(200)]


def solve(d):
	ans = "Christmas"
	for i in range(25 - d):
		ans += " Eve"
	print(ans)

if __name__ == '__main__':
	### input
	d = int(input())

	###solve
	solve(d)
	
	

Measured memory_bytes: 3060
/*-------enazuma11----------------*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(v) v.begin(),v.end()
#define inc(a,n) sort(a,a+n)
#define dec(a,n) sort(a,a+n,greater<int>() )
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define F first
#define S second
#define M 1000000007
 
/* int x[]={-1,-1,0,1,1,1,0,-1};
int y[]={0,1,1,1,0,-1,-1,-1};
*/
/* int x[]={-1,0,1,0};
int y[]={0,1,0,-1};
*/

void solve()
{
	ll n;
	cin>>n;
	ll ans=n*n*n;
	cout<<ans;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


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

int main(void){
    ll n;
    cin >> n;
    vector<ll> time(5);
    for(int i=0;i<5;i++){
        cin >> time[i];
    }
    sort(time.begin(),time.end());
    ll ans = (n+time[0]-1)/time[0]+4;
    cout << ans << endl;

}

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

typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    string s; cin >> s;
    
    int num0=0, num1=0;
    for(uint i=0; i<s.size(); ++i){
        if(s[i]=='0'){ ++num0;
        }    else    { ++num1; }
    }
    cout << min(2*num0, 2*num1) << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
	int n, i, a[53], amin, amax, mini, maxi;

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

	amin = INF;
	amax = -INF;
	for (i = 0; i < n; i++) {
		if (amin > a[i]) {
			amin = a[i];
			mini = i;
		}
		if (amax < a[i]) {
			amax = a[i];
			maxi = i;
		}
	}

	if (amin >= 0) {
		printf("%d\n", n - 1);
		for (i = 0; i < n - 1; i++) {
			printf("%d %d\n", i + 1, i + 2);
		}
		return 0;
	}

	if (amax <= 0) {
		printf("%d\n", n - 1);
		for (i = n - 1; i > 0; i--) {
			printf("%d %d\n", i + 1, i);
		}
		return 0;
	}

	printf("%d\n", n * 2 - 1);

	if (amax >= -amin) {
		for (i = 0; i < n; i++) {
			printf("%d %d\n", maxi + 1, i + 1);
		}
		for (i = 0; i < n - 1; i++) {
			printf("%d %d\n", i + 1, i + 2);
		}
	}
	else {
		for (i = 0; i < n; i++) {
			printf("%d %d\n", mini + 1, i + 1);
		}
		for (i = n - 1; i > 0; i--) {
			printf("%d %d\n", i + 1, i);
		}
	}

	return 0;
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A, B = MAP()

cnt = 1
ans = 0
while cnt < B:
    cnt += A - 1
    ans += 1
print(ans)


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

#define gif(a,b) ((a)/(b)+((a)%(b)?1:0))
#define float long double
#define int long long 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define w(x) cout<<(#x)<<" is "<<(x)<<"\n";
using namespace std;

int32_t main()
{ 
    IOS
    int T; 
    T=1; 
    for (int t = 0; t < T; ++t)
    {
        int x, n;
       	cin >> x >> n;
      	int a[n];
        for (int i = 0; i < n; ++i)
        	cin >> a[i];
        sort(a , a + n);
        int p = x, q = x;
        while(1)
        {
        	int flag1 = 0, flag2 = 0;
        	for (int i = 0; i < n; ++i)
        	{
        		if(p == a[i])
        		{	
        			flag1 = 1;
        			break;
        		}
        	}
        	flag2 = 0;
        	for (int i = 0; i < n; ++i)
        	{
        		if(q== a[i])
        		{	
        			flag2 = 1;
        			break;
        		}
        	}
        	
        	if(flag1 == 0)
        	{	
        		cout << p;
        		return 0;
        	}
        	if(flag2 == 0)
        	{	
        		cout << q;
        		return 0;
        	}
        	p--;
        	q++;
        }
       
    }

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<string,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;
int main() {
  ll N,K;
  cin>>N>>K;
  vec A(N),B(K),C(K),D(N,0);
  rep(i,0,N) 
    cin>>A[i];
  rep(i,0,K) {
    cin>>B[i]>>C[i];
    if(A[B[i]-1]>=A[C[i]-1])
      D[C[i]-1]=-1;
    if(A[B[i]-1]<=A[C[i]-1])
      D[B[i]-1]=-1;
    
    
  }
  
  ll count=0;
  rep(i,0,N) {
    if(D[i]==0)
      count+=1;
  }
  cout<<count<<endl;
}
    

Measured memory_bytes: 6340
loop do
    n = gets.to_i
    break if n == 0
    a = (1..n).map { gets.split.map(&:to_i) }
    a.sort_by! {|_, d1, d2| - d1 - d2}
    puts [a[0][0], a[0][1] + a[0][2]] * ' '
end


Measured memory_bytes: 7988
package main

import "fmt"

func main() {
  var n int
  var k int
  fmt.Scan(&n, &k)
  k2 := k*2
  // 0 ≦ x,y ≦ 2K に圧縮
  squares := make([][]int, k2)
  for i := range squares {
    squares[i] = make([]int, k2)
  }
  for i := 0; i < n; i++ {
    var x int
    var y int
    var color string
    fmt.Scan(&x, &y, &color)
    // 'W'はY方向にKずらした'B'と同値
    if color == "W" {
      y += k
    }
    squares[x % k2][y % k2]++ 
  }
  // 計算量削減のために累積和を事前算出
  for i := 0; i < k2; i++ {
    for j := 1; j < k2; j++ {
      squares[i][j] += squares[i][j-1]
    }      
  }
  for j := 0; j < k2; j++ {
    for i := 1; i < k2; i++ {
      squares[i][j] += squares[i-1][j]
    }
  }  
  max_ := 0
  end := k2-1
  for i := 0; i < k; i++ {
    for j := 0; j < k; j++ {
      // ex) k = 2
      //      ■ □ □ ■ 
      //  j+k □ ■ ■ □
      //      □ ■ ■ □
      //    j ■ □ □ ■
      //      i   i+k
      cnt :=
      (squares[i][j]) +
      (squares[end][j] - squares[i+k][j]) +
      (squares[i+k][j+k] - squares[i+k][j] - squares[i][j+k] + squares[i][j]) +
      (squares[i][end] - squares[i][j+k]) +
      (squares[end][end] - squares[end][j+k] - squares[i+k][end] + squares[i+k][j+k])
      //max_ = max(max(cnt, n - cnt), max_)
      tmp := n - cnt
      if cnt > tmp {
        if cnt > max_ {
          max_ = cnt
        }
      } else {
        if tmp > max_ {
          max_ = tmp
        } 
      }
    }
  }  
  fmt.Print(max_)
}

func max(a int, b int) int {
  if a > b {
    return a
  } else {
    return b
  }
}

Measured memory_bytes: 45184
n = int(input())
a = sorted(list(map(int, input().split())))
b = [0] * 10**5
ans = 1
if n == 2:
    if abs(a[0] - a[1]) <= 2:
        ans = 2
for i in range(n):
    b[a[i]] += 1
for i in range(n-2):
    ans = max(ans, b[i]+b[i+1]+b[i+2])

print(ans)

Measured memory_bytes: 14008
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main() {
    
    int ans=INF;
    int a,b,m;
    cin>>a>>b>>m;
    vi A(a),B(b);
    rep(i,a)cin>>A[i];
    rep(i,b)cin>>B[i];
    vi x(m),y(m),c(m);
    rep(i,m)cin>>x[i]>>y[i]>>c[i];
    int mina=INF,minb=INF;
    rep(i,a)chmin(mina,A[i]);
    rep(i,b)chmin(minb,B[i]);
    chmin(ans,mina+minb);
    rep(i,m){
        chmin(ans,A[x[i]-1]+B[y[i]-1]-c[i]);
    }
    fin(ans);
}


Measured memory_bytes: 2176
#include<math.h>
#include<stdio.h>
#define PI 3.14159265358979323846264338327950L

int main(){
  double A,B,H,M;
  scanf("%lf %lf %lf %lf",&A,&B,&H,&M);
  double thetaH,thetaM,ans2;
  thetaH = 2*M_PI/12*(H + M/60);
  thetaM = 2*M_PI/60*M;
  
  ans2 = A*A + B*B - 2*A*B*cos(thetaH - thetaM);
  printf("%.20lf",sqrt(ans2));
}


Measured memory_bytes: 2596
#include <stdio.h>

int main(){




for( ; ; ){

int h, w, i, j;

scanf("%d%d", &h, &w);


if(h == 0 & w == 0){return 0;}

for(i = 0; i < h; i++){

for(j = 0; j < w; j++)
{printf("#");}

printf("\n");

}
printf("\n");

}

}

Measured memory_bytes: 1644
n = int(input())
a = list(map(int, input().split()))
cnt = 0
arr = [0] * n
for i in range(n-1):
  cnt += abs(a[i] - a[i+1])

td = cnt + abs(a[0]) + abs(a[-1])

for i in range(1,n-1):
  x = abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]) - abs(a[i+1] -a[i-1])
  arr[i] = x
arr[0] = abs(a[0]) + abs(a[0] - a[1]) - abs(a[1])
arr[-1] = abs(a[n-2] - a[n-1]) + abs(a[n-1]) - abs(a[n-2])
            
ans = [td - x  for x in arr]

for i in range(n):
  print(ans[i])

Measured memory_bytes: 20580
import fractions

[A, B, C, D] = [int(i) for i in input().split()]

l = int((C*D) / (fractions.gcd(C, D)))

s1 = A - ((A//C) + (A//D) - (A//l))
s2 = B - ((B//C) + (B//D) - (B//l))
s3 = 0

if A%C != 0 and A%D != 0:
    s3 = 1

print(s2-s1 + s3)


Measured memory_bytes: 5048
import java.util.*;
public class Main{   
    static int[] ans;
    static ArrayList<Pair>[] list;
    static int n;
    static int max;
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      n = sc.nextInt();
      list = new ArrayList[n];
      ans = new int[n-1];
      for(int i=0;i<n;i++)list[i]=new ArrayList<>();
      for(int i=0;i<n-1;i++){
        int a = sc.nextInt()-1;
        int b = sc.nextInt()-1;
        list[a].add(new Pair(b,i));
        list[b].add(new Pair(a,i));
      }
      dfs(-1,-1,0);
      System.out.println(max);
      for(int i=0;i<n-1;i++)System.out.println(ans[i]);
    }
    static void dfs(int front,int q,int now){
      int cnt = 1;
      for(Pair p:list[now]){
        if(p.a==front)continue;
        if(cnt==q)cnt++;
        max = Math.max(max,cnt);
        ans[p.b]=cnt;
        dfs(now,cnt++,p.a);
      }
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}
class Pair{
    int a,b;

    Pair(int a, int b){
      this.a = a;
      this.b = b;
    }
}

Measured memory_bytes: 101112
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  int h[100000];
  int p = -1;
  int f = 0;
  for(int i = 0 ; i < n; i++){
    cin >> h[i];
    if(p < h[i]){
      h[i]--;
    }
    if(p > h[i]) f =1;
    p = h[i];
  }
  if(f) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
	int H, W, i, j;
	
	while(1){
		cin >> H >> W;
		if(H == 0 && W == 0){
			break;
		}
		for(i = 0; i < H; i++){
			for(j = 0; j < W; j++){
				if(j == 0 || j == W - 1 || i == 0 || i == H - 1){
					cout << '#';
				}else{
					cout << '.';
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;	
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} 



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

string s; cin >> s;
i64 cnt = 0;
if (s.size() < 3){
    cout << "0\n";
    return 0;
}
int ss = s.size();
rep(i, 0, ss){
    if (s[i] == 'A'){
        ++i;
        int m = 1;
        for(; i < ss; ++i){
            if (s[i] == 'B' && s[i+1] == 'C') {++i; cnt += m;}
            else if (s[i] == 'A') ++m;
            else break;
        }
    }
}


cout << cnt << "\n";
return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int A, B, C, X;
	cin >> A >> B >> C >> X;

	int ans = 0;
	for( int a = 0; a <= A; a++ ) {
		for( int b = 0; b <= B; b++ ) {
			for( int c = 0; c <= C; c++ ) {
				if( a * 500 + b * 100 + c * 50 == X ) ans++;
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3580
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main()
{
    long long A, B, C, K;
    cin >> A >> B >> C >> K;
    long long ans = 0;
    if (A > K)
    {
        ans += K;
        K = 0;
    }
    else
    {
        ans += A;
        K -= A;
    }

    if (K > 0)
    {
        if (B > K)
        {
            K = 0;
        }
        else
        {
            K -= B;
        }
    }

    if (K > 0)
    {
        if (C > K)
        {
            ans -= K;
        }
        else
        {
            ans -= C;
        }
        
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
int main(void){
  vector<int> input(3);
  for(int i=0;i<3;i++){
    cin >> input[i];
  }
  int k;
  cin >> k;
  for(int i=0;i<k;i++){
  sort(input.begin(),input.end());
    input[2]*=2;
  }
  cout << accumulate(input.begin(), input.end(), 0) << endl;
  return 0;
}

Measured memory_bytes: 256
h, w, a, b = map(int, input().split())

s = [[0 for _ in range(w)] for _ in range(h)]

num = ["0", "1"]
flag = True
for i in range(h):
    for j in range(w):
        if b <= i and flag:
            num.reverse()
            flag = False
        if j < a:
            s[i][j] = num[0]
        else:
            s[i][j] = num[1]


for row in s:
    print("".join(row))

Measured memory_bytes: 12788