akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

killed = 0
for i, b in enumerate(B):
    if A[i] >= b:
        A[i] -= b
        killed += b
    else:
        b -= A[i]
        killed += A[i]
        A[i] = 0
        if A[i+1] >= b:
            A[i+1] -= b
            killed += b
        else:
            killed += A[i+1]
            A[i+1] = 0

print(killed)

Measured memory_bytes: 18468
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class Main {
    public static long dp(int[]w,int []v,int max){
        long[][] memo=new long[w.length+1][max+1];
        long ans=0;
        for(int i=w.length-1;i>=0;i--){
            for(int j=0;j<=max;j++){
                long take=0;
                long leave=0;
                if(j+w[i]<=max&&i!=w.length)take=memo[i+1][j+w[i]]+v[i];
                if(i!=w.length-1)leave=memo[i+1][j];
                memo[i][j]=Math.max(take,leave);
                ans=Math.max(memo[i][j],ans);
            }
        }

    return ans;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        //StringBuilder sb=new StringBuilder();
        //StringTokenizer st=new StringTokenizer(br.readLine());
        //PriorityQueue<Integer> pq=new PriorityQueue<>();
        //HashSet<Integer> hs=new HashSet<>();
        //int q = Integer.parseInt(br.readLine());
        int kk =1;
        while (kk-- > 0) {
            StringTokenizer st=new StringTokenizer(br.readLine());
            int n =Integer.parseInt(st.nextToken());
            int max =Integer.parseInt(st.nextToken());

            int w[]=new int[n];
            int v[]=new int[n];
            for(int i=0;i<n;i++){
                st=new StringTokenizer(br.readLine());
                w[i]=Integer.parseInt(st.nextToken());
                v[i]=Integer.parseInt(st.nextToken());
            }

            out.println(dp(w,v,max));
            // for(int i=0;i<a.length;i++){
            //  out.println(Arrays.toString(a[i]));
            //}
            //out.println();
            //out.println(Arrays.toString(b));
        }//out.println();
        out.close();
    }
}

Measured memory_bytes: 126292
N = int(input())
S = input()

ans = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for d in range(N):
        j = i+d
        k = j+d
        if k < N:
            if S[i] != S[j] and S[k] != S[j] and S[k] != S[i]:
                ans -= 1
print(ans)

Measured memory_bytes: 67936
#include <bits/stdc++.h>
//#define int long long

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables **************/

/**********************************************/

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(){
    string s;
    bool dp[505][505];

    cin >> s;

    int n = s.size();
    REP(i, n) REP(j, n) dp[i][j] = false;

    for(int len = 3; len <= n; len += 3){
        REP(l, n){
            int r = l + len - 1;
            if(r > n) break;

            for(int c = l+1; c < r; c++){
                if(s[l] == 'm' && s[c] == 'e' && s[r] == 'w'){
                    if(l != c-1 && !dp[l+1][c-1]) continue;
                    if(c != r-1 && !dp[c+1][r-1]) continue;
                    dp[l][r] = true;
                }
            }
        }
    }

    if(dp[0][n-1]) cout << "Cat" << endl;
    else cout << "Rabbit" << endl;
}


Measured memory_bytes: 3424
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<cstdlib>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<bitset>
#define lmid l,mid,rt<<1
#define rmid mid+1,r,rt<<1|1
#define ll long long
using namespace std;
int main() {
     long long n, m;
     scanf("%lld", &n);
     m = n;
     int res = 0, cnt = 0;
     while (m) {
          cnt = m % 10;
          m /= 10;
          res++;
     }
     if (res == 1) {
          printf("%lld\n", n);
          return 0;
     }
     m = n;
     int ans = 0;
     while (m) {
          int c = m % 10;
          m /= 10;
          if (c == 9)ans++;
          else break;
     }
     if (ans >= res - 1) {
          if(ans==res-1)
          printf("%d\n", cnt + ans * 9);
          else printf("%d\n",ans * 9);
          return 0;
     }printf("%d\n", cnt - 1 + (res - 1) * 9);
     return 0;
}


Measured memory_bytes: 256
/* ex 4_3
   cy_an  */

#include <stdio.h>
int height(int n);

int main(void){

    // 変数宣言
    int len_a, len_b, deff, depth;
    // 入力
    scanf("%d %d", &len_a, &len_b);

    // deffの計算
    deff = len_b - len_a;
    // depthの計算
    depth = height(deff - 1) - len_a;
    // depthの出力
    printf("%d\n", depth);

    return 0;
}
// 1からnまでの和を計算する関数
int height(int n){
    int value = 0, i;
    for(i = 1; i <= n; i++){
        value += i;
    }
    return value;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i,a,b) for(long long int i=a;i<b;i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1000000000;
const ll MOD = 1000000007;

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    cout.tie(NULL);
    register ll i,j,k,x,y,m,n,t,q,temp,sum=0,count=0,f=1;
    cin>>n>>k;
    vector<ll> a(n+1, 0);
    for(i=1;i<=n;i++){
        cin>>a[i];
    }
    set<ll> s;
    x = a[1];
    vector<ll> v;    
    do{        
        s.insert(x);        
        v.pb(x);
        x = a[x];        
    }while(s.find(x) == s.end());

    for(i=0;i<v.size();i++){       
        if(v[i] == x){            
            break;
        }
    }    
    if(k <= i){
        cout<<v[k-1];
    }else{
        ll loop = v.size() - i;        
        ll index = (k - i  - 1 + loop)%loop;
        // if(index == 0)index = v.size();
        // index = i + index - 1;
        // cout<<index<<"---\n";
        cout<<v[index+ i];
    }    
}    
    

Measured memory_bytes: 15432
#include<iostream>

using namespace std;

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

	cin >> a >> b >> c >> d;
	
	if (abs(a - c) <= d) {
		cout << "Yes" << endl;
		return 0;
	}

	if (abs(a - b) > d || abs(b - c) > d) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(i=0;i<n;i++)

using namespace std;

int v[3],n,c;
string s;

int f(){
  n++;
  int r;
  if(s[n-1]=='(')r=f(),n++,r=s[n-1]=='+'?max(r,f()):min(r,f()),n++;
  else if(s[n-1]=='-')r=2-f();
  else if(isdigit(s[n-1]))r=s[n-1]-'0';
  else r=v[s[n-1]-'P'];
  return r;
}

int main(){ 
  cin >> s;
  if(s!="."){
    c=0;
    rep(v[0],3)rep(v[1],3)rep(v[2],3)n=0,c+=f()/2;
    cout << c << endl;
    main();
  }
}

Measured memory_bytes: 1188
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{   
    int r,g;
    cin >> r >> g;
    cout << r+2*(g-r) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from math import gcd

    def judge(a, b, c, d):
        if a - b < 0:
            return False
        else:
            if d - b < 0:
                return False

            first = a - b

            l = c + 1
            r = b - 1
            x = gcd(b, d)

            mod_min = first + (first - l + x - 1) // x * x
            mod_max = first + (r - first) // x * x
            if l <= mod_min <= r or l <= mod_max <= r:
                return False
            else:
                return True

    T = int(readline())

    for _ in range(T):
        a, b, c, d = map(int, readline().split())
        print("Yes") if judge(a, b, c, d) else print("No")


if __name__ == '__main__':
    main()


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

typedef long long ll;

ll gcd (ll a, ll b) {
	return (b == 0 ? a : gcd(b, a%b));
}

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

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll a, b; cin >> a >> b;
	cout << lcm(a,b) << endl;
	return 0;
}


Measured memory_bytes: 256
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	int n;
	cin>>n;
	cout<<(n*n)<<endl;

}

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

//41
typedef long long ll;

int main() {
	ll n;
	cin >> n;
	vector<ll> v(5);
	ll minn = 1e18;
	for (int i = 0; i < 5; ++i) {
		cin >> v[i];
		minn = min(minn,v[i]);
	}
	if (minn >= n) {
		cout << 5;
		return 0;
	}
	ll ans = ((n - minn) / minn); 
	if ((n - minn) % minn != 0) ans++;
	ans = ans + 5;
	cout << ans;  
}


Measured memory_bytes: 3588
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = [INT() for i in range(N)]

visited = [False] * N
i = 1
cnt = 0
while 1:
    if visited[i-1] == False:
        visited[i-1] = True
        if i == 2:
            print(cnt)
            exit()
        i = A[i-1]
        cnt += 1
        # i = nex
    elif visited[i-1] == True:
        print("-1")
        exit()




Measured memory_bytes: 15272
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n ;
 cin >> n;
 int arr[n+2];
 int maxi=-1;
 for(int i=1;i<=n;i++)
    cin >> arr[i],maxi=max(arr[i],maxi);
 int mini = 100000000;
 for(int i=-100;i<=maxi;i++){
   int cost = 0 ;
   for(int j=1;j<=n;j++){
      int y = i;
      cost+= ((arr[j]-y)*(arr[j]-y));
   }
   mini=min(cost ,mini);
 }
 cout << mini <<endl;
 return 0;
}


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

void dfs(int64_t s , int64_t &ans , int64_t n){
  
  if(s > n){
    return;
  }
  
  set<int> sss;
  string a = to_string(s);
  
  for(int i = 0 ; i < a.size() ; i++){
    if(a.at(i) == '3'){
      sss.insert(3);
    }
    if(a.at(i) == '5'){
      sss.insert(5);
    }
    if(a.at(i) == '7'){
      sss.insert(7);
    }
  }
    
  if(sss.count(3) && sss.count(5) && sss.count(7)){
    ans ++;
  }
  
  dfs(s*10 + 3 , ans , n);
  dfs(s*10 + 5 , ans , n);
  dfs(s*10 + 7 , ans , n);
}

int main(){
  
  int64_t n;
  cin >> n;
  
  int64_t ans = 0;
  
  dfs(0,ans,n);
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
int main()
{
ios_base::sync_with_stdio(false);
int d,n;
cin>>d>>n;
if(d==0)
    if(n==100)
        cout<<"101";
    else
        cout<<n;
if(d==1)
{
    if(n==100)
    {
        cout<<10100;
    }
    else
    {
        cout<<n*100;
    }
}
if(d==2)
{
    if(n==100)
    {
        cout<<1010000;
    }
    else
    {
        cout<<n*100*100;
    }
}
}

Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 1000 + 20 , mod = 1e9 + 7 ;
int n , m , a[N] , b[N] ;
int ans = 1 ;

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

	cin >> n >> m ;

	for (int i = 0 ; i < n ; i ++) cin >> a[i] ;
	for (int i = 0 ; i < m ; i ++) cin >> b[i] ;

	sort(a , a + n , greater<int>()) ;
	sort(b , b + m , greater<int>()) ;

	int p1 = 0 , p2 = 0 ;
	for (int x = n * m ; x >= 1 ; x --) {
		bool f1 = (p1 < n) && (a[p1] == x) ;
		bool f2 = (p2 < m) && (b[p2] == x) ;

		if (f1 && f2) p1 ++ , p2 ++ ;
		else if (f1) {
			ans = 1ll * ans * p2 % mod ;
			p1 ++ ;
		}
		else if (f2) {
			ans = 1ll * ans * p1 % mod ;
			p2 ++ ;
		}
		else ans = 1ll * ans * (p1 * p2 - (n * m - x)) % mod ;
	}

	cout << ans << '\n' ;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int n,a[13][13],i,j,b,sum=0;
while(1){
scanf("%d\n",&n);
if(n==0){
break;
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
scanf("%d",&b);
a[i][j]=b;
}
scanf("\n");
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
sum=sum+a[i][j];
}
a[i][n]=sum;
sum=0;
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
sum=sum+a[j][i];
}
a[n][i]=sum;
sum=0;
}
for(j=0;j<n;j++){
sum=sum+a[j][n];
}
a[n][n]=sum;
sum=0;
for(i=0;i<=n;i++){
for(j=0;j<=n;j++){
if(a[i][j]>9999){
printf("%d",a[i][j]);
}
else if(a[i][j]>999){
printf(" %d",a[i][j]);
}
else if(a[i][j]>99){
printf("  %d",a[i][j]);
}
else if(a[i][j]>9){
printf("   %d",a[i][j]);
}
else{
printf("    %d",a[i][j]);
}
}
printf("\n");
}
}
return 0;
}


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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int A, B;
  cin >> A >> B;
  cout << A * B <<endl;
}


Measured memory_bytes: 3648
"""
高橋くんはAtCoder銀行に100円を預けています。
AtCoder銀行では、毎年預金額の1%の利子がつきます(複利、小数点以下切り捨て)。
利子以外の要因で預金額が変化することはないと仮定したとき、高橋くんの預金額が初めてX円以上になるのは何年後でしょうか
"""
max = int(input())
money = 100
cnt = 0
loopf = True
while loopf:
    if money >= max:
        loopf = False
    else:
        up = money // 100
        money += up
        cnt += 1

print(cnt)


Measured memory_bytes: 9168
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

class UnionFindTree {
   public:
    vector<int> parent;
    vector<int> siz;

    UnionFindTree(int n) {
        siz.resize(n, 1);
        parent.resize(n);
        for (int i = 0; i < n; i++) {
            parent[i] = i;
        }
    }

    int root(int x) {
        if (parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }

    void unite(int x, int y) {
        int rx = root(x); int ry = root(y);
        if (rx == ry) return;
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        parent[ry] = rx;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return siz[root(x)];
    }
};

int main() {
    int N, M; cin >> N >> M;
    vector<pair<int, int>> bridge(M);
    REP(i, 0, M) {
        int a, b; cin >> a >> b;
        bridge[i] = {--a, --b};
    }

    UnionFindTree uft(N);
    vector<ll> ans(M);
    ans.back() = (ll)N * (N - 1) / 2;

    for (int i = M - 1; i > 0; i--) {
        if (uft.root(bridge[i].first) == uft.root(bridge[i].second)) {
            ans[i - 1] = ans[i];
        } else {
            ans[i - 1] = ans[i] - (ll)uft.size(bridge[i].first) * uft.size(bridge[i].second);
            uft.unite(bridge[i].first, bridge[i].second);
        }
    }
    for (auto a : ans) cout << a << endl;
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n, m;
    cin >> n >> m;
    vector<int> a(100001, 0);
    for(int i = 0; i < n; ++i){
        int foo;
        cin >> foo;
        ++a[foo];
    }

    vector<P> cnt(m, P(0, 0));
    for(int i = 1; i <= 100000; ++i){
        if(!a[i])   continue;
        int val = i % m;
        cnt[val].first += a[i] % 2;
        cnt[val].second += a[i] / 2;
    }

    int ans = 0;
    for(int i = 0; i <= m / 2; ++i){
        int j = (m - i) % m;
        if(i == j){
            ans += cnt[i].first / 2;
            ans += cnt[i].second;
        }
        else{
            if(cnt[i].first < cnt[j].first){
                swap(cnt[i], cnt[j]);
            }
            ans += cnt[j].first;
            cnt[i].first -= cnt[j].first;
            cnt[j].first = 0;
            if(cnt[i].first <= cnt[j].second * 2){
                ans += cnt[i].first;
                int dif = cnt[i].first / 2;
                dif += cnt[i].first % 2;
                cnt[j].second -= dif;
                ans += cnt[j].second;
            }
            else{
                ans += cnt[j].second * 2;
            }
            ans += cnt[i].second;
        }
    }
    cout << ans << endl;
}

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

int main() {
	string s;
	while (cin >> s) {
		if (s == "#")break;

		int now = 0;//axyzwbE

		for (int i = 0; i < s.size(); i++) {
			if (now == 6)break;

			if (now == 0) {
				if (s[i] == '0')now = 1;
				else now = 2;
			}
			else if (now == 1) {
				if (s[i] == '0')now = 6;
				else now = 3;
			}
			else if (now == 2) {
				if (s[i] == '0')now = 1;
				else now = 6;
			}
			else if (now == 3) {
				if (s[i] == '0')now = 4;
				else now = 5;
			}
			else if (now == 4) {
				if (s[i] == '0')now = 5;
				else now = 2;
			}
			else {
				if (s[i] == '0')now = 2;
				else now = 1;
			}
		}
		if (now == 5)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    { 
        static void Main(string[] args)
        {
            var price = int.Parse(Console.ReadLine());

            var a = price % 500;

            var yen = int.Parse(Console.ReadLine());
           
            if (a <= yen)
            {
                Console.WriteLine("Yes");
            }
            else
            { 
                Console.WriteLine("No");
            }

        }
    }
}


Measured memory_bytes: 11092
program atcoder
    implicit none
    integer :: length = 1
    integer(kind = 8) :: X, Y

    read *, X, Y
    do
        X = X*2
        if(X .le. Y) then
            length = length + 1
        else
            exit
        endif
    enddo
    print '(i0)', length

    stop

endprogram atcoder


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
struct node
{
	string s;
	int p, id;
	bool operator < (const node& x) const
	{
		return s==x.s ? p > x.p : s < x.s;
	}
}rest[N];
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	int n;
 	cin >> n;
 	for(int i=0; i<n; i++) 
	{
		cin >> rest[i].s >> rest[i].p;
		rest[i].id = i+1;
	}
 	sort(rest, rest+n);
 	for(int i=0; i<n; i++) cout << rest[i].id << '\n';
	return 0;
}


Measured memory_bytes: 3328
///A drunk man will find his way home, but a drunk bird may get lost forever...i
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define pf push_front
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
#define mp make_pair
const int mx = 1000 * 100;
bool mark[mx];
vector < int > ad[mx], tpl;
int ans[mx], n;
void dfs(int v){
	mark[v] = 1;
	for(int u : ad[v])
		if(!mark[u])
			dfs(u);
	tpl.pb(v);
	return;
}
void dfs_all(){
	for(int i = 0; i < n; i++)
		if(!mark[i])
			dfs(i);
	return;
}
int32_t main(){		
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	int m, u, v;
	cin >> n >> m;
	for(int i = 0; i < n + m - 1; i++){
		cin >> u >> v;
		u--, v--;
		ad[u].pb(v);
	}
	dfs_all();
	reverse(tpl.begin(), tpl.end());
	for(int v : tpl)
		for(int u : ad[v])
			ans[u] = v + 1;
	for(int i = 0; i < n; i++)
		cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 11252
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    int n;
    cin >> n;
    string ans;
    if(n==1)ans="Hello World";
    else{
        int a,b;
        cin >> a>>b;
        ans = to_string(a+b);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

ostream& operator<<(ostream& os, const pair<char, int>& unit) {
  return os << unit.first << "^" << unit.second;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n, m;
  cin >> n >> m; 
  vector<int> a(n * 2);
  cin >> a;
  sort(a.begin(), a.end());
  int l = 0, r = n;
  function<bool(int)> pred = [&](int x) {
    for (int i = 1; i <= x; ++i)
      if (a[n * 2 - i] + a[n * 2 - x * 2 + i - 1] < m)
        return false;
    return true;
  };
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (pred(mid))
      l = mid;
    else
      r = mid - 1;
  }
  int ans = 0;
  int x = l;
  for (int i = 1; i <= x; ++i)
    ans = max(ans, a[n * 2 - i] + a[n * 2 - x * 2 + i - 1] - m);
  for (int i = 0; i < n - x; ++i)
    ans = max(ans, (a[i] + a[(n - x) * 2 - i - 1]) % m);
  cout << ans;

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


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

const int N=2e5;
int n,m;
int f[N+5],cnt[N+5];
int gf(int x)
{
	if(f[x]==x) return x;
	return f[x]=gf(f[x]);
}
void merge(int x,int y)
{
	int fx=gf(x),fy=gf(y);
	f[fx]=fy;
}
int main()
{
	int i;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
		f[i]=i;
	for(i=1;i<=m;i++)
	{
		int t1,t2;
		scanf("%d%d",&t1,&t2);
		merge(t1,t2);
	}
	for(i=1;i<=n;i++)
		cnt[gf(i)]++;
	int ans=0;
	for(i=1;i<=n;i++)
		ans=max(ans,cnt[i]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 10620
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    cin.ignore();
    string inp;
    getline(cin, inp);
    stringstream s;
    s.str(inp);
    vector<int> vect;
    int total = 0;
    for (int i = 0; i < n; i++) {
        int tmp;
        s >> tmp;
        total += tmp;
        vect.push_back(tmp);
    }
    int selectvote = (total / (4 * m));
    bool checkNext = (total % (4 * m) == 0);
    int ctr = 0;
    for (int i = 0; i < n; i++) {
        if (!checkNext && vect[i] > selectvote) ctr++;
        if (checkNext && vect[i] >= selectvote) ctr++;
    }
    if (ctr >= m) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

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

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll 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(ret);
  return (ret);
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  init();
  ll N;
  cin >> N;

  rep(i, N) {
    string S;
    cin >> S;
    if (S == "Y") {
      COUT("Four");
      return 0;
    }
  }
  COUT("Three");
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int n, k, cnt=0;
    cin >> n >> k;
    for(int i=0; i<n; i++){
        int h;
        cin >> h;
        if(h >= k) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <time.h>
#include <complex>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
#define TEMP(type,x,y) do {temp temp=x,x=y,y=temp}while(0)
const ll INF = (1LL << 50);

int main() {

	int N, M;
	cin >> N >> M;

	vector<int>A(N, 0);
	REP(i, M) {
		int k;
		cin >> k;
		REP(j, k) {
			int s;
			cin >> s;
			s--;
			A[s] |= 1 << i;
		}
	}

	int p = 0;
	REP(i, M) {
		int x;
		cin >> x;
		p |= x << i;
	}

	int ans = 0;
	
	for (int s = 0; s < (1 << N); s++) {//N=8(=1000)だったら、s=000,001,010, ... ,111
		int t = 0;
		for (int i = 0; i < N; i++) {
			if (s >> i & 1) {//i=0→s=100>>0 = 100 →　100 & 1 = 000
				t ^= A[i];
			}
		}
		if (t == p) ans++;
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
X,Y,A,B,C=map(int,input().split())
from heapq import heappop,heappush,heapify
P=[]
for p in map(int,input().split()):
    heappush(P,-p)
Q=[]
for q in map(int,input().split()):
    heappush(Q,-q)
R=[]
for r in map(int,input().split()):
    heappush(R,-r)
x,y,z,a=0,0,0,0
while x<X and y<Y and x+y+z<X+Y:
    p,q,r=-P[0],-Q[0],-R[0]
    m=max(p,q,r)
    if m==p:
        x+=1
        a+=p
        if len(P)>1:
            heappop(P)
        else:
            P[0]=0
    elif m==q:
        y+=1
        a+=q
        if len(Q)>1:
            heappop(Q)
        else:
            Q[0]=0
    else:
        z+=1
        a+=r
        if len(R)>1:
            heappop(R)
        else:
            R[0]=0
while x<X and x+y+z<X+Y:
    p,r=-P[0],-R[0]
    m=max(p,r)
    if m==p:
        x+=1
        a+=p
        if len(P)>1:
            heappop(P)
        else:
            P[0]=0
    else:
        z+=1
        a+=r
        if len(R)>1:
            heappop(R)
        else:
            R[0]=0
while y<Y and x+y+z<X+Y:
    q,r=-Q[0],-R[0]
    m=max(q,r)
    if m==q:
        y+=1
        a+=q
        if len(Q)>1:
            heappop(Q)
        else:
            Q[0]=0
    else:
        z+=1
        a+=r
        if len(R)>1:
            heappop(R)
        else:
            R[0]=0
while x+y+z<X+Y:
    r=-R[0]
    z+=1
    a+=r
    if len(R)>1:
        heappop(R)
    else:
        R[0]=0
print(a)

Measured memory_bytes: 23456
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef vector<int>     Vi;
typedef vector<ll>      Vl;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD1    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define psb push_back
#define epb emplace_back
#define psf push_front
#define mkp make_pair
#define fst first
#define scd second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int a, b; cin >> a >> b;
    rep(i, 1000000000){
        if(abs(a - i) == abs(b - i)){
            cout << i << endl;
            return 0;
        }
    }

    cout << "IMPOSSIBLE" << endl;

return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>s;
    rep(i,Size(s))if(s[i]=='2')ans++;
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,ra,re) for((i)=ra;(i)<(re);(i)++)
#define _rep(i,ra,re) for((i)=ra;(i)>(re);(i)--)
#define rep_(i,ra,re) for((i)=ra;(i)<=(re);(i)++)
#define _rep_(i,ra,re) for((i)=ra;(i)>=(re);(i)--)
#define put(n) cout << n << " "; 
#define puts(n) cout << n << endl;
#define pu(n) cout << n;
#define mod 1000000007
int i,j,k,l;
static const int MAX=2001;

long fact[MAX],fact_i[MAX];
long power(int x, int y) {
    if (y == 1) return x;
    long p = power(x, y >> 1);
    if (y & 1) return p * p % mod * x % mod;
    else return p * p % mod;
}
 
long inv(long n) {
    return power(n, mod - 2);
}
 
void init(int n) {
    fact[0] = 1;
    rep(i,0, n) fact[i + 1] = fact[i] * (i + 1) % mod;
    fact_i[n] = inv(fact[n]);
    rep(i,0, n) fact_i[n - i - 1] = fact_i[n - i] * (n - i) % mod;
}
 
long nCr(long n, long r) {
    if (n < r || n < 0 || r < 0) return 0;
    return fact[n] * fact_i[r] % mod * fact_i[n - r] % mod;
}
int main(void){
	init(2001);
	int N,K;
		cin >> N >> K;
	rep_(i,1,K)
		puts(nCr(K-1,i-1)*nCr(N-K+1,i)%mod);
	return 0;
}


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

using namespace std;

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

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

int main(){
    int d;
    cin >> d;
    if(d == 25){
        cout << "Christmas" << endl;
    }else if(d == 24){
        cout << "Christmas Eve" << endl;
    }else if(d == 23){  
        cout << "Christmas Eve Eve" << endl;
    }else if(d == 22){
        cout << "Christmas Eve Eve Eve" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 300
#define MIN 3

int main(void)
{
	int height, width;
	
	while(1)
	{
		if( scanf("%d %d", &height, &width)==2 )
		{
			if((height==0) && (width==0))
			{
				break;
			}
			else if((height>=MIN) && (height<=MAX) &&
				(width>=MIN) && (width<=MAX))
			{
				for(int i=0; i<height; i++)
				{
					for(int j=0; j<width; j++)
					{
						if((i==0) || (i==height-1) ||
							(j==0) || (j==width-1))
						{
							printf("%c", '#');
						}
						else
						{
							printf("%c", '.');
						}
					}
					printf("\n");
				}
				printf("\n");
			}
			else
			{
				return -1;
			}
		}
		else
		{
			return -1;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int N, M, ans;
int like[30];


int main(void) {
    // insert code here...
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int a;
            cin >> a;
            like[a-1]++;
        }
    }
    
    for(int i = 0; i < M; i++){
        if(like[i]==N){
            ans++;
        }
    }
   
    cout << ans << endl;
    
    return 0;
}


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

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

    int n,d;
    cin>>n>>d;
    int x[n][d];
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>x[i][j];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int t=0;
            for(int k=0;k<d;k++){
                t+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            int m=sqrt(t);
            if(m*m==t){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def solv(N):
    fizz = N // 3
    buzz = N // 5
    fizzBuzz = N // 15
    return (
        N * (N + 1)
        - 3 * fizz * (fizz + 1)
        - 5 * buzz * (buzz + 1)
        + 15 * fizzBuzz * (fizzBuzz + 1)
    ) // 2


if __name__ == "__main__":

    # N
    #
    N = int(input())
    ans = solv(N)

    print(ans)


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

enum {
  MAXN = 100000 + 5
};

typedef long long i64;

int n;
i64 a[MAXN];
i64 b[MAXN];
i64 ans[MAXN];
i64 pre[MAXN];

int cmp(int x, int y) {
  return a[x] != a[y]? a[x] > a[y] : x < y;
}

void exec() {
  static int st[MAXN];
  int top;
  int i;
  scanf("%d", &n);
  for (i=0; i<n; ++i) scanf("%lld", &a[i]);
  for (i=0; i<n; ++i) b[i] = i;
  std::sort(b, b+n, cmp);

  for (i=0; i<n; ++i) pre[i+1] = pre[i] + a[b[i]];

  top = 0;
  for (i=0; i<n; ++i)
    if (!top || b[i] < b[st[top-1]])
      st[top++] = i;

  st[top] = n;
  for (i=0; i<top; ++i)
    ans[b[st[i]]] = pre[st[i+1]] - (i<top-1? a[b[st[i+1]]] * st[i+1] : 0) - pre[st[i]] + st[i] * a[b[st[i]]];
  for (i=0; i<n; ++i)
    printf("%lld\n", ans[i]);
}

int main() {
  if (fopen("E.in", "r") != NULL) {
    freopen("E.in", "r", stdin);
    freopen("E.out", "w", stdout);
  }
  exec();
  return 0;
}


Measured memory_bytes: 4608
#!/usr/bin/env python
# -*- coding: utf-8 -*-
a,b,c,x,y = [int(i) for i in input().split()]

min_price = a * x + b * y

for i in range(100001):
    sum_price = a * max(0, x - i) + b * max(0, y - i) + c * 2 * i
    if sum_price <= min_price:
        min_price = sum_price

print(min_price)


Measured memory_bytes: 2940
/*
Author: Deep Chaklasiya
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update> data_set;
#define fbo find_by_order
#define ook order_of_key




#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define piiii       pair<pii,pii>
#define viiii       vector<pair<pii,pii>>
#define mi          map<int,int>
#define mii         map<pii,int>
#define piii           pair<int,pair<int,int> >
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353
#define PI          3.141592653589
#define bs(v,n)     binary_search(all((v)),(n))
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007
#define ef else if





int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); }
bool mod(double a,double b) {return a/b - floor(a/b);}

int occurs(vi v,int n){
auto it=lb(v,n);auto it1=ub(v,n);int x=it1-it;return x;}

int logb(int base, int x) {
    return (log(x) / log(base));
}


template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}

void set_min(int &m,int a){
    if(m==-1||m>a)m=a;
}


signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector<int> v1(n),v2(n),v3(n,0);
    for(auto &x:v1) cin>>x;
    for(auto &x:v2) cin>>x;
    for(int i=0;i<n;i++) v3[i]=i+1;
    map < vector < int > , int > mp;
    do 
	{
      mp[v3] = mp.size();
    } while (next_permutation(v3.begin(), v3.end()));
    int ans = abs(mp[v1] - mp[v2]);
	cout << ans << endl;
    return 0;
}


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


int main(){
  int n,k,i,id;
  cin >> n >> k;
  vector<int>a(n+1);
  for(i=1;i<=n;++i){
    cin >> a[i];
    if(a[i]==1){
      id=i;
    }
  }
  int ans=0;
  int migi=id-1;
  int hidari=n-id;
  int ma=max(migi,hidari);
  int mi=min(migi,hidari);
  if(mi<(k-1) && mi>1){
    ans++;
    ma=ma-((k-1)-mi);
  }else{
    ans+=mi/(k-1);
    if(mi%(k-1)!=0){
      ans++;
      ma=ma-(mi%(k-1));
    }
  }

  ans=ans+ma/(k-1);
  if(ma%(k-1)!=0){
    ans++;
  }
  cout << ans << endl;
  return 0;

}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define P pair<int,int>
const LL inf = 0x3f3f3f3f;
const LL mod = 1e9+7;
const LL N = 4e3+10;
template <typename tp> inline void read(tp &x)
{
	x=0;char c=getchar();int f=0;
	for(;c>'9'||c<'0';f|=(c=='-'),c=getchar());
	for(;c<='9'&&c>='0';x=(x<<3)+(x<<1)+c-'0',c=getchar());
	if(f) x=-x;
}
int a,b;
int main()
{
	read(a),read(b);
	if(a<=0&&b>=0) return 0*puts("Zero");
	if(a<0&&(b-a)%2==0) puts("Negative");
	else puts("Positive");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int N, i, i2, max, n, a[100] = {0};
	do{
		scanf("%d", &N);
	}while(N < 0 || N > 100);

	for(i = 1; i <= N; i++){
		i2 = i;
		while(i2 % 2 == 0){
			i2 /= 2;	a[i]++;
		}
	}

	max = a[1];
	n = 1;
	for(i = 2; i <= N; i++){
		if(a[i] > max){
			max = a[i];	n = i;
		}
	}

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

	return 0;
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    SC = [[int(x) for x in input().split()] for _ in range(M)]

    f = False
    for i in range(1000):
        if len(str(i)) != N:
            continue

        x = str(i)
        for s, c in SC:
            if int(x[s - 1]) != c:
                break
        else:
            f = True

        if f:
            print(i)
            return
    else:
        print(-1)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
import numpy as np
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
A = np.cumsum(A)

dic = defaultdict(int)
for i in A:
    dic[i] += 1

# print (dic)

ans = 0
for i in dic:
    ans += dic[i] * (dic[i] - 1)
ans //= 2

if 0 in dic:
    ans += dic[0]

print (ans)

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int a = 0,b = 0,c = 0;
    for(int i = 0; i < s.size();i++){
        if(s[i] == 'a'){
            a++;
        }else if (s[i] == 'b'){
            b++;
        }else{
            c++;
        }
    }
    if(abs(a-b) <= 1 && abs(b-c) <= 1 && abs(c-a) <= 1){
        cout << "YES" << endl; 
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 512
#include <iostream>

int main()
{
	int a, b;
	std::cin >> a >> b;
	if (a > b) {
		std::cout << "a > b" << std::endl;
	}
	else if (a < b) {
		std::cout << "a < b" << std::endl;
	}
	else {
		std::cout << "a == b" << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 3e3 + 100;

ll DP[MAXN][MAXN][2];
ll n, A[MAXN];

ll rek(ll x, ll y, int pos) {
	if (x > y) return 0;
	ll &ret = DP[x][y][pos];
	if (ret != -1) return ret;
	if (pos == 0) ret = max(rek(x + 1, y, 1) + A[x], rek(x, y - 1, 1) + A[y]);
	else ret = min(rek(x + 1, y, 0), rek(x, y - 1, 0));
	return ret;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	ll sum = 0;
	REP(i, n) {
		cin >> A[i];
		sum += A[i];
	}
	memset(DP, -1, sizeof DP);
	cout << 2 * rek(0, n - 1, 0) - sum << '\n';
}

Measured memory_bytes: 150528
#include<iostream>
#include<string>
#include<set>

using namespace std;

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

    set<string> fruit_set;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        fruit_set.insert(s);
    }

    cout << fruit_set.size() << endl;

    return 0;
}


Measured memory_bytes: 19104
def washall_floyd(graph):
    num_v = len(graph)
    for k in range(num_v):
        for i in range(num_v):
            for j in range(num_v):
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
    return graph


n, m, r = map(int, input().split())
r_list = list(map(int, input().split()))
graph = [[float("inf") for _ in range(n)] for _ in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c

graph = washall_floyd(graph)
result = float("inf")
import itertools
permi = itertools.permutations(r_list)
for per in permi:
    r = 0
    start = per[0] - 1
    for p in per[1:]:
        end = p - 1
        r += graph[start][end]
        start = p - 1
    result = min(r, result)
print(result)


Measured memory_bytes: 60376
//20200517 C
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		double h=sc.nextInt();
		double m=sc.nextInt();
		double c=Math.cos(Math.toRadians(30*h+m/2-6*m));
		System.out.println(Math.sqrt(a*a+b*b-2*a*b*c));
	}
}


Measured memory_bytes: 27204
N = int(input())
A = [0]*N
for i in range (N):
    A[i] = int(input()) 

max1 = 0
max2 = 0
for i in range (N):
    if A[i] >= max1:
        max2 = max1
        max1 = A[i]
    elif A[i] >= max2:
        max2 = A[i]

if max2 == 0:
    for i in range (N):
        print(max1)
else:
    for i in range (N):
        if A[i] == max1:
            print(max2)
        else:
            print(max1)

Measured memory_bytes: 57432