akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll powmod(ll a, ll b, const ll mod = MOD) {
    a %= mod;
    ll res = 1;
    while (b > 0) {
        if (b % 2 == 1)res = res * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return res;
}

vector<ll> f, inv, finv;
void cominit(ll n = 210000, const ll mod = MOD) {
    f.resize(n + 1);
    inv.resize(n + 1);
    finv.resize(n + 1);
    f[0] = f[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    FOR(i, 2, n + 1) {
        f[i] = f[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

ll nCr(ll n, ll r, const ll mod = MOD) {
    if (n < r)return 0;
    if (n < 0 or r < 0)return 0;
    return f[n] * (finv[r] * finv[n - r] % mod) % mod;
}

ll nPr(ll n, ll r, const ll mod = MOD) {
    if (n < r)return 0;
    if (n < 0 or r < 0)return 0;
    return f[n] * finv[n - r] % mod;
}

ll nHr(ll n, ll r, const ll mod = MOD) {
    if (n < r)return 0;
    if (n < 0 or r < 0)return 0;
    return nCr(n + r - 1, r, mod);
}

ll k, ans;
string s;
int main() {
    cominit(2100000);
    cin >> k >> s;
    ll sz = s.size();   
    ll n = k + sz;
    ans = powmod(26, n);
    REP(i, sz){
        ans -= nCr(n, i) * powmod(25, n - i) % MOD;
        ans = (ans + MOD * 2) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 54536
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int n;
    string s;
    cin>>n>>s;
    int w[n]={},e[n]={};
    if(s[0]=='W'){
        w[0]=1;
    }else{
        e[0]=1;
    }
    for(int i=1;i<n;i++){
        if(s[i]=='W'){
            w[i]=w[i-1]+1;
            e[i]=e[i-1];
        }else{
            e[i]=e[i-1]+1;
            w[i]=w[i-1];
        }
    }
    int ans=e[n-1]-e[0];
    for(int i=1;i<n;i++){
        int tmp=w[i-1]+e[n-1]-e[i];
        ans=min(tmp,ans);
    }
    cout<<ans<<endl;
 return 0;   
}

Measured memory_bytes: 3076
def main():
    x = int(input())
    if x < 600:
        print(8)
    elif x < 800:
        print(7)
    elif x < 1000:
        print(6)
    elif x < 1200:
        print(5)
    elif x < 1400:
        print(4)
    elif x < 1600:
        print(3)
    elif x < 1800:
        print(2)
    else:
        print(1)

if __name__ == "__main__":
    main()

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

int main(){
	
	int n;
	cin >> n;
	vector<int> p,q;
	for(int i=0;i<n;i++){
		int temp;
		cin >> temp;
		p.push_back(temp);
	}
	for(int i=0;i<n;i++){
		int temp;
		cin >> temp;
		q.push_back(temp);
	}
	int count = 0;
	vector<int> v = p;
	sort(v.begin(),v.end());
	bool found=false;
	if(p==q) {cout << 0; return 0;}
	do{
		if (v==p || v==q){
			if(found) {
				cout<< count;
				return 0;}
			else found = true;
		}
		if (found) count++;
		
		
		
	}while(next_permutation(v.begin(),v.end()));
	
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int q = sc.nextInt();
		int MAX = 100001;
		boolean[] np = new boolean[MAX];
		int[] a = new int[MAX];

		np[0] = true;
		np[1] = true;
		for (int i = 2; i < MAX; i++) {
			if (!np[i]) {
				for (int j = i + i; j < MAX; j += i) {
					np[j] = true;
				}
			}
		}

		for (int i = 1; i < MAX; i++) {
			if (!np[i] && !np[(i+1)/2]) {
				a[i] = a[i - 1] + 1;
			} else {
				a[i] = a[i - 1];
			}
		}

		int[] ans = new int[q];
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			ans[i] = a[r] - a[l - 1];
		}

		for (int i = 0; i < q; i++) {
			System.out.println(ans[i]);
		}
	}
}


Measured memory_bytes: 68268
'''
Created on 2020/08/21

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  l=[0]*4
  for i in range(3):
    a,b=map(int,pin().split())
    l[a-1]+=1
    l[b-1]+=1
  t=sorted(list(set(l)))
  if t==[1,2]:
    print("YES")
  else:
    print("NO")
  return 

main()

Measured memory_bytes: 9144
#include <bits/stdc++.h>
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) v.begin(), v.end()

using namespace std;

inline ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

inline ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

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

inline ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

inline vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

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

ll mod = 1e9+7;

int main(){
    ll n;
    cin >> n;
    ll res = (n+1) / 2 -1;
    
    
    cout << res << endl;
    return 0;
}


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

int main(){
  int n, m, x;
  int fans=0, bans=0;
  cin >> n >> m >> x;
  int a[m];
  for(int i=0; i<m; i++){
    cin >> a[i];
    if(a[i]<x)  fans++;
    else if(a[i]>x) bans++;
  }
  cout << min(fans, bans) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String...args) {

		try (Scanner sc = new Scanner(System.in)) {
			int a = sc.nextInt();
			int b = sc.nextInt();

			if (a <= 9 && b <=9) {
				System.out.println(a * b);
			} else {
				System.out.println(-1);
			}
		}
	}
}

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

int n;
int a[200000];
bool ok(int kind) {
  map<int, int> mp;
  for (int i = 1; i < n; ++i) {
    if (a[i - 1] < a[i]) continue;
    if (kind == 1) return false;
    
    int k = a[i];
    while (mp[k] == kind - 1) {
      mp[k] = 0;
      --k;
    }
    if (k <= 0) return false;
    ++mp[k];
    
    mp.erase(mp.upper_bound(k), mp.end());
  }
  return true;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  
  int lo = 0;
  int hi = n;
  while (hi - lo > 1) {
    int mid = (lo + hi) / 2;
    if (ok(mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  cout << hi << endl;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{

    int n;
    cin >> n;

    cout << (n + 1) / 2 << '\n';
    return 0;
}


Measured memory_bytes: 3636
from functools import reduce
from fractions import gcd


def find_lcm(a, b):
    return a * b // gcd(a, b)


def main():
    n = int(input())
    t = [int(input()) for _ in range(n)]
    print(reduce(find_lcm, t))


if __name__ == '__main__':
    main()



Measured memory_bytes: 5512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

// template from zscoder

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
  ll n,ans(1); cin>>n;
  vi d(n);
  for(int i = 0; i < n; i++)
  {
    cin >> d[i];
  }
  sort(d.begin(),d.end());
  unique(d.begin(),d.end());
  for(int i = 1; i < n; i++)
  {
    if(d[i]>d[i-1])ans++;
    else break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <map>

using namespace std;

map< int64_t, int > prime_factor(int64_t n) {
    map< int64_t, int > ret;
    for(int64_t i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

int main()
{
    int64_t N;
    cin >> N;
    int sum = 0;
    map<int64_t, int> m = prime_factor(N);
    for (const auto& [key, value] : m){
        //std::cout << key << " => " << value << "\n";
        int base = 1;
        int i;
        int count = 0;
        for(i = base; i <= value; i+=base) {
            base += 1;
            count += 1;
        }
        sum += count;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
    long int w, h, x, y;
    long double result;
    scanf("%ld %ld %ld %ld", &w, &h, &x, &y);
    result = (double)w*h/2;
    
    if( w / 2 == x && h / 2 == y && w % 2 == 0 && h % 2 == 0 ){
        printf("%Lf 1\n", result);
    } else {
        printf("%Lf 0\n", result);
    }
    
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        long [] A = cin.ArrayLong(N);
        long ans = A[0];
        for (int i = 1; i < N; i++)
        {
            ans = lcm(ans, A[i]);
        }
        Console.WriteLine(ans);
    }

    long lcm(long a, long b)
    {
        return a / gcd(a, b) * b;
    }

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


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' '};

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

const int D = 62;
const int MAX_N = 200010;
int to[D][MAX_N];

int main() {
    int n; long long k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
        cin >> to[0][i];
        --to[0][i];
    }
    for(int i = 0; i < D-1; ++i) {
        for(int j = 0; j < n; ++j) {
            to[i+1][j] = to[i][to[i][j]];
        }
    }

    int v = 0;
    for(int i = D-1; i >= 0; --i) {
        long long l = 1LL << i;
        if(l <= k) {
            v = to[i][v];
            k -= l;
        }
    }
    cout << v + 1 << endl;
    return 0;
}

Measured memory_bytes: 52568
S = input()

s = S[0]
for i in range(1, len(S)+1):
    if (i == len(S)):
        break
    if S[i] == s:
        print(i, i+1)
        break
    elif i < len(S)-1 and S[i+1] == s:
        print(i, i+2)
        break
    s = S[i]

if (i == len(S)):
    print(-1, -1)

Measured memory_bytes: 3316
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if( n == 0 ) break;
			
			HashMap<Character, Character> trans = new HashMap<Character, Character>();
			for(int i=0;i<n;i++) {
				char c1 = sc.next().charAt(0);
				char c2 = sc.next().charAt(0);
				trans.put(c1, c2);
			}
			
			int m = sc.nextInt();
			for(int i=0;i<m;i++) {
				char c = sc.next().charAt(0);
				if( trans.containsKey(c) ) System.out.print( (char)trans.get(c) );
				else System.out.print( (char)c );
			}
			System.out.println();
		}
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 13000
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

s = input().split()[0]

ss = ""
co = 0
for i in range(n):
    if s[i] == ")" and co <= 0:
        ss = "(" + ss + ")"
    elif s[i] == ")":
        ss = ss + ")"
        co -= 1
    if s[i] == "(":
        co += 1
        ss = ss + "("
print(ss + ")" * co)









Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define N 600030

typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3f;

struct event {
	int id, apr; ll val;
	event (int _id = 0, int appear = 0, ll value = 0) : id(_id), apr(appear), val(value) {}
} v[N * 10];

int n, q;
ll t[N], T[N];
ll f[N], g[N], y[N];
ll fm[N], gm[N], fy[N];
ll A[N], B[N], tmp[N];
int stack[N];

inline void up(ll &x, const ll y) {x < y ? x = y : 0;}
inline bool test1(int u, int v, ll para, ll *a) {return a[u] - a[v] < para * (u - v);}
inline bool test2(int u, int v, int w, ll *a) {return (a[v] - a[w]) * (u - v) <= (a[u] - a[v]) * (v - w);}

ll DP(ll *f) {
	int i, j, top = 0; ll pf = 0;
	for (i = 1; i <= n; ++i) {
		T[i] = T[i - 1] + t[i];
		f[i] = pf + 2 - t[i]; y[i] = f[i] + T[i] + (ll)i * i;
		for (; top > 1 && test1(stack[top], stack[top - 1], 2 * i + 3, y); --top);
		if (j = stack[top]) up(f[i], y[j] - (2 * i + 3ll) * j + i * (i + 3ll) - T[i]);
		for (; top > 1 && test2(i, stack[top], stack[top - 1], y); --top);
		stack[++top] = i; up(pf, f[i]);
	}
	return pf;
}

void Fy(int L, int R) {
	if (L + 1 == R) return;
	int M = (L + R) / 2, i, j, k, top = 0;
	Fy(L, M); Fy(M, R);
	for (i = L; i < M; ++i) {
		for (; top > 1 && test2(i, stack[top], stack[top - 1], A); --top);
		stack[++top] = i;
	}
	for (i = M; i < R - 1; ++i) {
		for (; top > 1 && test1(stack[top], stack[top - 1], 2 * (i + 1), A); --top);
		tmp[i] = (k = i + 1, j = stack[top]) ? A[j] + B[k] - 2ll * j * k - 2 : -INF;
	}
	for (i = R - 3; i >= M; --i) up(tmp[i], tmp[i + 1]);
	top = 0;
	for (i = M; i < R; ++i) {
		for (; top > 1 && test2(i, stack[top], stack[top - 1], B); --top);
		stack[++top] = i;
	}
	for (i = L + 1; i < M; ++i) {
		for (; top > 1 && test1(stack[top], stack[top - 1], 2 * (i - 1), B); --top);
		tmp[i] = (j = i - 1, k = stack[top]) ? A[j] + B[k] - 2ll * j * k - 2 : -INF;
	}
	for (i = L + 2; i < M; ++i) up(tmp[i], tmp[i - 1]);
	for (i = L + 1; i < R - 1; ++i) up(fy[i], tmp[i]);
}

inline ll solve(int x, ll y) {
	ll ans = fm[x - 1] + gm[x + 1];
	up(ans, f[x] + t[x] - y);
	up(ans, g[x] + t[x] - y);
	up(ans, fy[x] + t[x] - y);
	return ans;
}

int main() {
	int i, x; ll y;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) scanf("%lld", t + i), t[i] *= 2;
	DP(f); std::reverse(t + 1, t + (n + 1));
	DP(g); std::reverse(t + 1, t + (n + 1));
	std::reverse(g + 1, g + (n + 1));
	for (i = 1; i <= n; ++i) up(fm[i] = fm[i - 1], f[i]);
	for (i = n; i; --i) up(gm[i] = gm[i + 1], g[i]);
	for (i = 1; i <= n; ++i) {
		T[i] = T[i - 1] + t[i];
		A[i] = f[i] + T[i] + i * (i - 3ll);
		B[i] = g[i] - T[i - 1] + i * (i + 3ll);
	}
	memset(fy, 192, sizeof fy);
	Fy(1, n + 1);
	for (scanf("%d", &q); q; --q) {
		scanf("%d%lld", &x, &y); y *= 2;
		printf("%lld\n", solve(x, y) / 2);
	}
	return 0;
}

Measured memory_bytes: 144128
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  int n,k;
  cin>>n>>k;
  int dp[n+1];
  int niza[n+1];
  for(int i=1; i<=n; i++)
  {
   	cin>>niza[i]; 
    dp[i]=INT_MAX;
  }
  dp[1]=0;
  for(int i=1; i<=n; i++)
  {
   	for(int j=1; j<=k; j++)
    {
      if(i+j<=n)
    	dp[i+j]=min(dp[i+j],dp[i]+abs(niza[i]-niza[i+j]));
    }
  }
  cout<<dp[n]<<endl;
  return 0;
}


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

#define lld long long
#define pp pair<int,int>
#define y1 y11
#define INF 1000000000
#define pb push_back

using namespace std;

int N;
int a[200002];
bool check[200002];

int main(){
	int x;
	scanf("%d %d",&N,&x);
	if(x == 1 || x == N*2-1){
		puts("No");
		return 0;
	}
	puts("Yes");
	a[N] = x; check[x] = true;
	a[N-1] = x-1; check[x-1] = true;
	a[N+1] = x+1; check[x+1] = true;
	if(x != 2){
		a[N+2] = x-2; check[x-2] = true;
	}else{
		a[N-2] = x+2; check[x+2] = true;
	}
	int t = 1;
	for(int i=1; i<=N*2-1; i++){
		if(a[i] == 0){
			while(1){
				if(!check[t]) break;
				t++;
			}
			a[i] = t; check[t] = true;
		}
		printf("%d\n",a[i]);
	}

	return 0;
}

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

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n,k=input2()
P=input_array()
P.sort()
count=0
for i in range(k):
	count+=P[i]
print(count)

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

int main() {
  int n, m = 0;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  cout << v[n-1] - v[0] << endl;
  return 0;
}

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

int main()
{
    double n;
    cin >> n;
    double sum = n/1.08;

    if(n ==(int)((int)sum * 1.08) )
        cout << (int)sum << endl;
    else if(n == (int)((int)(sum + 1) * 1.08))
            cout << (int)(sum + 1) << endl;
    else
        cout << ":(" << endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=200005;

int n;
string s[MAXN];

int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)cin>>s[i];
	sort(s+1,s+n+1);
	int ans=0;
	for(int i=1;i<=n;++i)
		if(s[i]!=s[i-1])++ans;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9892
#include <iostream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repext(i, a, b) for (int i = a; i < b; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define repextrev(i, a, b) for (int i = b - 1; i >= a; i--)
#define vec_all(vec) vec.begin(), vec.end()
#define sum(vec) accumulate(vec_all(vec), 0)

// vectorデバッグ
template <typename T>
void dump_vec(vector<T> vec)
{
    rep(i, vec.size())
    {
        cout << i << ": " << vec[i] << endl;
    }
}

// --- notice ---
// intの和はllにしろ

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

    if (n == 0) {
        cout << 0 << endl;
        return 0;
    }

    vector<char> c_vec;
    while (n != 0) {
        if (n % 2 == 0) {
            c_vec.push_back('0');
        } else {
            c_vec.push_back('1');
            if (n < 0) {
                n--;
            }
        }

        n /= (-2);
    }

    reprev(i, c_vec.size()) {
        cout << c_vec[i];
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#n,m = int(input())
	#b , c = tin()
	#s = input()	
	n, m = tin()
	
	ll=[[] for _ in range(n)]
	for _ in range(m):
		a, b = tin()
		ll[a-1].append(b-1)
		ll[b-1].append(a-1)
		
	gid=-1
	gg=[-1]*n
	for i in range(n):
		if gg[i] != -1:
			continue
		gid += 1
		gg[i] = gid
		q=collections.deque()
		q.append(i)
		while q:
			p = q.popleft()
			for np in ll[p]:
				if gg[np] != -1:
					continue
				gg[np]=gid
				q.append(np)
				
	cc=collections.Counter(gg)
	ret=0
	for k in cc:
		ret = max(ret, cc[k])
	return ret
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 124216
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    int t,i,j,n,m,l,r;
    cin>>n;
    (n==0)? n=1: n=0;
    cout<<n<<"\n";
    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main()
{
int n,a,b,c;
cin>>n;
a=n/100;
b=n/10%10;
c=n%10;
if (a==7 or b==7 or c==7)cout<<"Yes"<<endl;
else if (a==7 and b==7 and c==7)cout<<"Yes"<<endl;
else if (a==7 and b==7)cout<<"Yes"<<endl;
else if (a==7 and c==7)cout<<"Yes"<<endl;
else if (b==7 and c==7)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define ll long long
using namespace std;
 
const int sz=4e6+5;

int n,q,bit[sz],vis[sz],ar[sz];

struct st
{
    int l,r,idx;
};

bool cmp(st a,st b)
{
    return a.r<b.r;
}

void update(int idx,int val)
{
    for(;idx<=n;idx+=idx&(-idx))
    {
        bit[idx]+=val;
    }
}

int query(int idx)
{
    int sum=0;
    for(;idx>0;idx-=idx&(-idx))
    {
        sum+=bit[idx];
    }

    return sum;
}




 
  
int main() 
{ 
    // #ifndef ONLINE_JUDGE 
      
    //     // For getting input from input.txt file 
    //     freopen("input.txt", "r", stdin); 
      
    //     // Printing the Output to output.txt file 
    //     freopen("output.txt", "w", stdout); 
      
    // #endif 
 
    int t=1;
    // cin>>t;
    while(t--)
    {
        
        cin>>n>>q;
        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
        }
        st qr[q];
        for(int i=0;i<q;i++)
        {
            cin>>qr[i].l>>qr[i].r;
            qr[i].l--;
            qr[i].r--;
            qr[i].idx=i;
        }
        sort(qr,qr+q,cmp);

        memset(vis,-1,sizeof(vis));

        int ans[q];
        int qc=0;
        for(int i=0;i<n;i++)
        {
            // cout<<i<<endl;
            if(vis[ar[i]]!=-1)
            {
                update(vis[ar[i]]+1,-1);
            }
            // cout<<i<<endl;
            vis[ar[i]]=i;
            update(i+1,1);
            while(qc<q and qr[qc].r==i)
            {
                ans[qr[qc].idx]=query(qr[qc].r+1)-query(qr[qc].l);
                qc++;
            }

            // cout<<i<<endl;

        }

        for(int i=0;i<q;i++)
        {
            cout<<ans[i]<<endl;
        }







 
    }
    return 0; 
} 

Measured memory_bytes: 31120
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)
s = 0
for i in range(N+1):
    s += abs(A[i] - A[i+1])
for j in range(1, N+1):
    if A[j-1] <= A[j]:
        if A[j] <= A[j+1]:
            print(s)
        else:
            print(s - 2 * min(abs(A[j-1] - A[j]), abs(A[j+1] - A[j])))
    else:
        if A[j+1] <= A[j]:
            print(s)
        else:
            print(s - 2 * min(abs(A[j - 1] - A[j]), abs(A[j + 1] - A[j])))


Measured memory_bytes: 14048
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))

a=[i for i in range(1,n+1)]

from itertools import permutations, combinations,combinations_with_replacement,product

pcnt=0
qcnt=0
for i in permutations(a):
    if p>i:
        pcnt+=1
    if q>i:
        qcnt+=1

print(abs(pcnt-qcnt))
        

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
"""
http://abc068.contest.atcoder.jp/tasks/arc079_a
AC
"""

def solve(routes, N):
    result = 'IMPOSSIBLE'
    to_middle = set()           #  島1から渡ることのできる島
    from_middle = set()         #  島Nへ渡ることのできる島
    for f, t in routes:
        if f == 1:
            to_middle.add(t)
        elif t == N:
            from_middle.add(f)

    if to_middle & from_middle:
        result = 'POSSIBLE'
    return result



def main():
    N, M = map(int, input().split())
    routes = []
    for _ in range(M):
        routes.append([int(x) for x in input().split()])
    result = solve(routes, N)
    print(result)


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

    to_middle = set()           #  島1から渡ることのできる島
    from_middle = set()         #  島Nへ渡ることのできる島
    N, M = map(int, input().split())
    for _ in range(M):
        f, t = map(int, input().split())
        if f == 1:
            to_middle.add(t)
        elif t == N:
            from_middle.add(f)

    if to_middle & from_middle:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')




Measured memory_bytes: 19012
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.cpp
 * Author: Allen
 *
 * Created on January 12, 2019, 6:26 PM
 */

#include <cstdlib>
#include <iostream>
#include <stdio.h>
using namespace std;
double dp[301][301][301];
    int n;
double go(int one,int two, int three){
    if(dp[one][two][three]!=-1){
        return dp[one][two][three];
    }
    double ex=1;
    if(one){
        ex+=((double)one/(double)n)*go(one-1,two,three);
    }
    if(two){
        ex+=((double)two/(double)n)*go(one+1,two-1,three);
    }
    if(three){
        ex+=((double)three/(double)n)*go(one,two+1,three-1);
    }
    return dp[one][two][three]=ex/(double)(1-((double)(n-one-two-three)/(double)n));
}
/*
 * 
 */
int main(int argc, char** argv) {

    cin>>n;
    int arr[3];
    for(int i=0;i<3;i++){
        arr[i]=0;
    }
    int in;
    for(int i=0;i<n;i++){
        cin>>in;
        arr[in-1]+=1;
    }
    for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
    for(int k=0;k<=n;k++){
        dp[i][j][k]=-1;
    }
    }
    }
    dp[0][0][0]=0;
    printf("%.100f",go(arr[0],arr[1],arr[2]));
    return 0;
}



Measured memory_bytes: 213376
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
double x_1,y_1,x_2,y_2;
int main() {

	cin>>x_1>>y_1>>x_2>>y_2;
	printf("%.8lf",sqrt(pow(x_1-x_2,2)+pow(y_1-y_2,2)));
	return 0;
}



Measured memory_bytes: 3200
n, x = map(int, input().split())
lis = [int(input()) for i in range(n)]
x = x-sum(lis)
ans = n
if x <= 0:
    print(ans)
    exit()
while(x >= 0):
    x = x-min(lis)
    if x < 0:
        break
    ans += 1
print(ans)
    

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

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 200000;
ll N;
ll x[MAX_N], y[MAX_N];

ll calc1() {
  // pattarn [min, ?], [?, max]
  ll ma1 = 0, ma2 = 0, mi1 = 1e18, mi2 = 1e18;
  for (int i = 0; i < N; ++i) {
    ma1 = max(ma1, x[i]); mi1 = min(mi1, x[i]);
    ma2 = max(ma2, y[i]); mi2 = min(mi2, y[i]);
  }
  return (ma1-mi1)*(ma2-mi2);
}

ll calc2() {
  // pattarn [min, max], [?, ?]
  ll ma = 0, mi = 1e18;
  vector<pll> vec;
  multiset<ll> mset;
  for (int i = 0; i < N; ++i) {
    vec.push_back(pll(y[i], x[i]));
    ma = max(ma, x[i]);
    mi = min(mi, y[i]);
    mset.insert(y[i]);
  }
  sort(all(vec));
  ll res = 1e18;
  for (int i = 0; i < N; ++i) {
    mset.erase(mset.find(vec[i].fi));
    mset.insert(vec[i].sc);
    res = min(res, (ma-mi) * (*mset.rbegin() - *mset.begin()));
  }
  return res;
}

ll calc() {
  return min(calc1(), calc2());
}


int main() {
  cin >> N;
  rep(i,N) cin >> x[i] >> y[i];

  for (int i = 0; i < N; ++i) {
    if (x[i] < y[i]) swap(x[i], y[i]);
  }

  cout << calc() << endl;

  return 0;
}


Measured memory_bytes: 18164
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll r;
    cin >> r;
    if(r < 1200){ cout << "ABC" << endl; }
    else if(r < 2800){ cout << "ARC" << endl; }
    else{ cout << "AGC" << endl; }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <numeric>
#include <algorithm>
#include <tuple>

typedef long long ll;
using namespace std;

bool is_mm(int x){
    return (x <= 12) && (x > 0);
}

int main() {
    int k, n;
    string s;
    cin >> s;
    int bf, af;
    bf = (s[0] - '0')*10 +  (s[1] - '0');
    af = (s[2] - '0')*10 +  (s[3] - '0');
    string ret = "";
    if (is_mm(af) && is_mm(bf)){
        ret = "AMBIGUOUS";
    }else if(is_mm(af)){
        ret = "YYMM";
    }else if (is_mm(bf)){
        ret = "MMYY";
    }else{
        ret = "NA";
    }
    cout << ret << endl;
    return 0;
}


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int logp = 64;
const int logx = 32;

int tot = 0;

class Array{
public:
	int p;
	inline Array(int len){ p = tot; tot += len; }
	inline int operator [](const int x)const{
		return p + x;
	}
}a(1), b(1), c(1), pw(logp), s(logx), t(logx), r(logp);

inline void comp(int x, int y, int z){ printf("< %d %d %d\n", y, z, x); }
inline void add(int x, int y, int z){ printf("+ %d %d %d\n", y, z, x); }
inline void rev(int x){assert(x); comp(x, x, pw[0]); /* x = (x < 1)*/ }

inline void addPw(int x, int y, int z){
	Array tmp(2);
	int p = 0, q = 1;
	add(tmp[p], tmp[p], y); // tmp[q] = 0;
	FOR(i, 0, z){
		comp(tmp[q], tmp[q], tmp[q]); // tmp[q] = 0;
		add(tmp[q], tmp[p], tmp[p]); // tmp[q] = 2tmp[p];
		swap(p, q);
	}
	add(x, x, tmp[p]); // x[0] += tmp[p];
	return;
}

inline void toBin(Array &dec, Array &bin){
	Array tmp(2);
	int x = 0, y = 1;
	for(int i = logx - 1; i >= 0; --i){
		comp(tmp[x], tmp[x], tmp[x]); // tmp[x] = 0;
		add(tmp[x], tmp[y], pw[i]); // tmp[x] = tmp[y] + pw[i];
		comp(bin[i], dec[0], tmp[x]); // bin[i] = (dec < tmp[x]) ? 1 : 0;
		rev(bin[i]); // bin[i] = !bin[i];
		addPw(tmp[y], bin[i], i); // tmp[y] += (bin[i] * 2^i)
	}
	return;
}

int main(){
//	freopen("e.out", "w", stdout);
	puts("9664");
	comp(pw[0], pw[0], a[0]); // pw[0] = 1;
	FOR(i, 1, logp)
		add(pw[i], pw[i - 1], pw[i - 1]); // pw[i] = pw[i - 1] * 2
	toBin(a, s);
	toBin(b, t);
	FOR(i, 0, logx) FOR(j, 0, logx){
		Array res(0);
		add(res[0], s[i], t[j]); // res[0] = s[i] + p[j]
		comp(res[0], pw[0], res[0]); // res[0] = (res[0] == 2)
		add(r[i + j], r[i + j], res[0]); // r[i + j] += res[0]
	}
	FOR(i, 0, logp)
		addPw(c[0], r[i], i); // c[0] += r[i] * 2^(i+j) 
	return 0;
}


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

ll res[100005];
ll mod = 1000000007;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,m;cin>>n>>m;
  queue<int> q;
  for(int i=0;i<m;i++){
    int t;
    cin>>t;
    q.push(t);
  }

  res[0]=1;
  for(int i=1;i<=n;i++){
    int a = i-1;
    int b = i-2;
    if (i == q.front()){
      q.pop();
      continue;
    }
    if(a >= 0) {
      res[i] += res[a];
      res[i] %= mod;
    }
    if(b >= 0) {
      res[i] += res[b];
      res[i] %= mod;
    }
    // debug(i);
    // debug(res[i]);
  }

  cout<<res[n]<<endl;

  return 0;
}


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

#define MAX 25
#define NIL -1

struct Node{
	int parent;
	int left,right;
};

Node node[MAX];
int depth[MAX],height[MAX];

int sibling(int i){
	if(node[i].parent == NIL){
		return NIL;
	}else{
		int ori = i;
		int l=node[node[i].parent].left;
		int r=node[node[i].parent].right;
		
		if(ori==l){return r;}
		else{return l;}
	}
}

int degree(int i){
	if(node[i].left!=NIL && node[i].right!=NIL){
		return 2;
	}else if(node[i].left==NIL && node[i].right==NIL){
		return 0;
	}else{
		return 1;
	}
}

void fdepth(int u,int value){
	if(u == NIL){return;}
	depth[u]=value;
	fdepth(node[u].left,value + 1);
	fdepth(node[u].right,value + 1);
}

int fheight(int u){
	int h1=0,h2=0;
	if(node[u].left!=NIL){h1=fheight(node[u].left)+1;}
	if(node[u].right!=NIL){h2=fheight(node[u].right)+1;}
	return height[u]=(h1>h2 ? h1:h2);
}
void type(int i){
	if(node[i].parent==NIL){ cout<<"root";}
	else if(node[i].left == NIL && node[i].right == NIL){ cout<<"leaf";}
	else{cout<<"internal node";}
}

void output(int n){
	for(int i=0;i<n;i++){
		cout<<"node "<<i<<": ";
		cout<<"parent = "<<node[i].parent<<", ";
		cout<<"sibling = "<<sibling(i)<<", ";
		cout<<"degree = "<<degree(i)<<", ";
		cout<<"depth = "<<depth[i]<<", ";
		cout<<"height = "<<fheight(i)<<", ";
		//type
		type(i);
		cout<<endl;
	}
}

int main() {
	for(int i=0;i<MAX;i++){
		depth[i]=NIL;
		node[i].parent=NIL;
    }
	
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int id,left,right;
		cin>>id>>left>>right;
		
		node[id].left = left;
		node[id].right = right;
		if(left!=-1){node[left].parent = id;}
		if(right!=-1){node[right].parent = id;}
	}
	//find root
	int u=0;
	for(int i=0;i<n;i++){
		if(node[i].parent==NIL){
			u = i;
		}
    }
	fdepth(u,0);
	//output
	output(n);
	
	return 0;
}

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

string u[256];
bool lock = true;
int n, m;

int main(){
	cin >> n;
	for(int i = 0; i < n; i++) cin >> u[i];
	cin >> m;
	for(int i = 0; i < m; i++){
		bool ok = true;
		string t;
		cin >> t;
		for(int j = 0; j < n; j++){
			if(u[j] == t){
				ok = false;
				if(lock) cout << "Opened by " << t << endl;
				else cout << "Closed by " << t << endl;
				lock = (lock+1)%2;
				break;
			}
		}
		if(ok) cout << "Unknown " << t << endl;
	}
}

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

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

    set<int> S;
    for (int i = 0; i < N; i++) {
        int d;
        cin >> d;
        S.insert(d);
    }
    cout << S.size() << endl;
    
    return 0;
}

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

int main(){
    int w,h,n;
    cin >> w >> h >> n;
    
    vector<int> x(n);
    vector<int> y(n);
    vector<int> a(n);
    
    int minx = 0;
    int miny = 0;
    int maxx = w;
    int maxy = h;
    
    rep(i,n) cin >> x[i] >> y[i] >> a[i];
    
    for(int i = 0; i < n; i++){
        if(a[i]==1) minx = max(minx,x[i]);
        if(a[i]==2) maxx = min(maxx,x[i]);
        if(a[i]==3) miny = max(miny,y[i]);
        if(a[i]==4) maxy = min(maxy,y[i]);
    }
    if(maxx - minx <= 0 or maxy - miny <= 0) cout << 0;
    else{
    cout << (maxx - minx) * (maxy - miny) << endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Linq;

class E
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var a = read();

		var s = a.Sum();
		for (var i = s; i > 0; i--)
		{
			if (s % i != 0) continue;
			var m = a.Select(x => x % i).OrderByDescending(x => x).ToArray();
			if (m.Skip(m.Sum() / i).Sum() <= h[1]) { Console.WriteLine(i); return; }
		}
	}
}


Measured memory_bytes: 17580
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;
 
int main(){
	string s, t;
  	cin >> s >> t;
  
  	int sm = s.size();
  	int tm = t.size();
	int ans = t.size();
  
  	rep(i, sm-tm+1){
      	int cnt = 0;
    	rep(j, tm){
        	if(s[i+j] != t[j]) cnt++;
        }
      	ans = min(ans, cnt);
    }
  
  	cout << ans << endl;
}

Measured memory_bytes: 3592
a, b, m = gets.chomp.split(" ").map(&:to_i)
as = Array.new(gets.chomp.split(" ").map(&:to_i))
bs = Array.new(gets.chomp.split(" ").map(&:to_i))
ms = []
m.times {
    ms.push(gets.chomp.split(" ").map(&:to_i))
}

discount_prices = []
ms.each do |m|
    ai = m[0] - 1
    bi = m[1] - 1 
    discount_prices.push(as[ai] + bs[bi] - m[2])
end

p discount_prices.min < as.min + bs.min ? discount_prices.min : as.min + bs.min


Measured memory_bytes: 25272
// WARNING: Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;


/*--- Macro ---*/
#define rep(i, a, b) for(int i=(int)a; i<(int)b; i++)
#define erep(i, a, b) for(int i=(int)a; i<=(int)b; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// 4-direction
int dy4[] = {0,  1, -1,  0};
int dx4[] = {1,  0,  0, -1};

// 8-direction
int dy8[] = {0,  1,  1,  1,  0, -1, -1, -1};
int dx8[] = {1,  1,  0, -1, -1, -1,  0,  1};

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

/**
  辺
  to: 辺の行き先
  cost: 辺の重み
  T: 重みの型
*/
template <typename T = int>
struct Edge {
  int to;
  T cost;
  Edge(int to, T cost) : to(to), cost(cost) {}
};

/**
  n: 頂点数
  graph: グラフ本体
*/
template <typename T = int>
class Graph {
  public:
    int n;
    vector<vector<Edge<T>>> graph;

    Graph(int n) {
      this->n = n;
      this->graph.assign(n, vector<Edge<T>>());
    }

    void addEdge(int from, int to, T cost) {
      this->graph[from].push_back(Edge<T>(to, cost));
    }
};

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

  Graph<int> g = Graph<int>(N);
  vector<int> edgeN;
  edgeN.assign(N, 0);
  rep(i, 0, N-1) {
    int a, b;
    cin >> a >> b;
    g.addEdge(a-1, b-1, 0);
    g.addEdge(b-1, a-1, 0);
    edgeN[a-1]++;
    edgeN[b-1]++;
  }

  vector<int> c;
  rep(i, 0, N) {
    int _c;
    cin >> _c;
    c.push_back(_c);
  }
  sort(c.begin(), c.end());
  ll score = accumulate(c.begin(), c.end()-1, 0);

  vector<int> vc;
  vc.assign(N, 0);
  rep(i, 0, N-1) {
    rep(j, 0, N) {
      if(edgeN[j] == 1) {
        vc[j] = c[i];
        edgeN[j]--;
        for(Edge<int> e : g.graph[j]) {
          edgeN[e.to]--;
        }
        break;
      }
    }
  }
  rep(i, 0, N) {
    if(vc[i] == 0) vc[i] = c[N-1];
  }

  cout << score << endl;
  rep(i, 0, N) {
    if(i != N-1) {
      cout << vc[i] << " ";
    } else {
      cout << vc[i] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1024
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.*;

public class Main {

    public static void main(String args[]) {


        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        int h = scan.nextInt();
        int m = scan.nextInt();
        double c;

        double x = 30.0 * h + 30.0 * m / 60.0;
        double y = 6.0 * m;
        double z = Math.abs(x - y);

        BigDecimal r = BigDecimal.valueOf(2.0 * a * b * Math.cos(Math.toRadians(z)));
        BigDecimal a2 = BigDecimal.valueOf(a * a);
        BigDecimal b2 = BigDecimal.valueOf(b * b);
        BigDecimal c2 = a2.add(b2).subtract(r);
        MathContext mc = new MathContext(10);
        BigDecimal c1 = c2.sqrt(mc);

        System.out.println(c1.doubleValue());






    }


}

Measured memory_bytes: 36156
#!/usr/bin/ruby
N=gets.to_i
X=N.times.map{gets.chomp}
Y=N.times.map{gets.chomp}
attackX=attackY=0
N.times{|i|
	foulX=foulY=false
	if X[i]=='kougekida'
		foulX=true if attackX==0
		if Y[i]=='kougekida'
			foulY=true if attackY==0
			next if foulX&&foulY
			if foulX
				puts 'Nakajima-kun'
				exit
			elsif foulY
				puts 'Isono-kun'
				exit
			elsif attackX>attackY
				puts 'Isono-kun'
				exit
			elsif attackY<attackX
				puts 'Nakajima-kun'
				exit
			end
			attackY=0
		elsif foulX
			puts 'Nakajima-kun'
			exit
		elsif Y[i]=='tameru'
			puts 'Isono-kun'
			exit
		elsif Y[i]=='mamoru' && attackX>=5
			puts 'Isono-kun'
			exit
		end
		attackX=0
	elsif X[i]=='tameru'
		if Y[i]=='kougekida'
			if attackY==0
				puts 'Isono-kun'
				exit
			else
				puts 'Nakajima-kun'
				exit
			end
			attackY=0
		elsif Y[i]=='tameru'
			attackY+=1
		elsif Y[i]=='mamoru'
		end
		attackX+=1
	elsif X[i]=='mamoru'
		if Y[i]=='kougekida'
			if attackY==0
				puts 'Isono-kun'
				exit
			elsif attackY>=5
				puts 'Nakajima-kun'
				exit
			end
			attackY=0
		elsif Y[i]=='tameru'
			attackY+=1
		elsif Y[i]=='mamoru'
		end
	end
}
puts 'Hikiwake-kun'

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

int main()
{
  ll n;
  cin >> n;
  vector<ll> h(n);
  for (ll i = 0; i < n; i++)
  {
    cin >> h[i];
  }
  ll ans = 0;
  ll buf = 0;

  for (ll i = 0; i < n - 1; i++)
  {
    if (h[i] >= h[i + 1])
    {
      buf++;
      ans = max(ans, buf);
    }
    else
    {
      buf = 0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3996
ab = input().split()
A, B = int(ab[0]), int(ab[1])

if A == B:
    print(1)
elif A % 2 != B % 2:
    print("IMPOSSIBLE")
else:
    K = (A+B) // 2
    if abs(A-K) == abs(B-K):
        print(K)
    else:
        print("IMPOSSIBLE")

Measured memory_bytes: 3316
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323

//int calc1(float a,float b,float c,float d,float e,float f,float *x,float *y);
//void quick(int *,long long,long long);
//int comp(char *a,char *b);

int main(){
	
	int i,j,n,max1,max2,temp,x,flag;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		max1=0;
		max2=0;
		flag=1;
		for(j=0;j<10;j++){
			scanf("%d",&x);
			if(x>max1)
				max1=x;
			else if(x>max2)
				max2=x;
			else{
				flag=0;
			}
		}
		if(flag==1)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <stdio.h>

int main()
{
	int a, b, c;
	int tmp;
	scanf("%d %d %d", &a, &b, &c);
	tmp = b;
	b = a;
	a = tmp;
	tmp = c;
	c = a;
	a = tmp;
	printf("%d %d %d", a, b, c);
	return 0;
}

Measured memory_bytes: 128
import math
N = int(input())
ans = 0
for i in range(1,N+1,2):
    now = 0
    for j in range(1,math.ceil(math.sqrt(i))+1):
        if i%j == 0:
            now += 2
    if now == 8:
        ans += 1
print(ans)

Measured memory_bytes: 3060
N = int(input())

l = [0] * 3
for i in range(N):
    a = [int(x) for x in input().split()]
    c = [a[0] + max(l[1], l[2]), a[1] + max(l[2], l[0]), a[2] + max(l[0], l[1])]
    l = c
print(max(l))

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

int main() {
	int a,b,c,d ;
	cin>>a>>b>>c>>d;
	bool win = true; 
	while(a>0 && c>0){
		c-=b;
		if( c <= 0){ break;}
		else {
			a-=d;
			if(a <= 0){
				win = false;}
		}
	}
	if(win)
	{cout<<"Yes"<<endl;}
	else{
		cout<<"No"<<endl;}
  
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for(int i = (int)(n); i>=0; --i)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

int main()
{
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
#include<math.h>
int main(){
	int n,x;
	double x1,x2,x3,y1,y2,y3,xp,yp;
	double a1,b1,c1,a2,b2,c2,r;
	scanf("%d",&n);
	for(x=0; x<n; x++)    {
		scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
a1=2*(x2-x1);
 b1=2*(y2-y1);
 c1=x1*x1-x2*x2+y1*y1-y2*y2;
 a2=2*(x3-x1);
 b2=2*(y3-y1);
 c2=x1*x1-x3*x3+y1*y1-y3*y3;
 xp=(b1*c2-b2*c1)/(a1*b2-a2*b1);
 yp=(c1*a2-c2*a1)/(a1*b2-a2*b1);
 r=((xp-x2)*(xp-x2)+(yp-y2)*(yp-y2));
 r=sqrt(r);
 if(ceil(xp*1000)-xp*1000<=xp*1000-floor(xp*1000)){
	 xp=ceil(xp*1000)/1000;
 }else{
	 xp=floor(xp*1000)/1000;
 }
 if(ceil(yp*1000)-yp*1000<=yp*1000-floor(yp*1000)){
	 yp=ceil(yp*1000)/1000;
 }else{
	 yp=floor(yp*1000)/1000;
 }
 if(ceil(r*1000)-r*1000<=r*1000-floor(r*1000)){
	 r=ceil(r*1000)/1000;
 }else{
	 r=floor(r*1000)/1000;
 }
 printf("%.3f %.3f %.3f\n",xp,yp,r);
	}
	return 0;
}

Measured memory_bytes: 1088