akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
	string S;
	cin>>S;
	char s1,s2;
	s1 = S[0];
	s2 = s1;
	for(int i = 1;i<4;i++)
		if(S[i]!= s1)s2 = S[i];
	if(s1 == s2){
		cout<<"No";
		return 0;
	}	
	
	for(int i=0;i<4;i++){
		if(S[i] != s1 && S[i] != s2 ){
			cout<<"No";
		return 0;
		}
	}
	cout<<"Yes";
	
	return 0;
}

Measured memory_bytes: 256
n=int(input())
for m in range(1,n+1):
  if m*(m+1)//2==n:break
else:
  print('No')
  exit()
a=[]
k=1
for i in range(m):
  b=[0]*m
  for j in range(i+1):
    b[j]=k
    k+=1
  a.append(b)
ans=[]
for i in range(m):
  b=[m]
  for j in range(i+1):
    b.append(a[i][j])
  for k in range(j+1,m):
    b.append(a[k][j])
  ans.append(b)
b=[m]
for i in range(m):
  b.append(a[i][i])
ans.append(b)
print('Yes')
print(len(ans))
for i in ans:
  print(*i)

Measured memory_bytes: 71792
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n + 1];
    long[] b = new long[n];
    for(int i = 0; i < (n + 1); i++) {
      a[i] = sc.nextLong();
    }
    for(int i = 0; i < n; i++) {
      b[i] = sc.nextLong();
    }
    long ans = 0;
    for(int i = 0; i < n; i++) {
      if(a[i] >= b[i]) {
        ans += b[i];
      } else {
        ans += a[i];
        long r = b[i] - a[i];
        long t = Math.min(r, a[i + 1]);
        ans += t;
        a[i + 1] -= t;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 85040
using System;
class Program
{
	static void Main(string[] args)
	{
		// 個数の入力
		int n = int.Parse(Console.ReadLine());
		// たこぱ入力
		string[] input = Console.ReadLine().Split(' ');
		int sum = 0;
		int powSum = 0;
		for (int i = 0; i < n; i++) {
			int d = int.Parse(input[i]);
			sum += d;
			powSum += d * d;
		}
        int ans = (sum * sum - powSum) / 2;
		//出力
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13140
<?php
  list($n, $a) = explode(" ", trim(fgets(STDIN)));

  $x = array_map('intval', explode(" ", trim(fgets(STDIN))));

  $dp = [];
  for ($i=0; $i<=$n; $i++) {
    $dp[$i] = [];
    for ($j=0; $j<=$n; $j++) {
      $dp[$i][$j] = [];
      for ($k=0; $k<=$n*$a; $k++) {
        if($i==0 && $j==0 && $k==0){
          $dp[$i][$j][$k] = 1;
        }else if($i >= 1 && $k < $x[$i-1]){
          $dp[$i][$j][$k] = $dp[$i-1][$j][$k];
        }else if($i >= 1 && $j >= 1 && $k >= $x[$i-1]){
          $dp[$i][$j][$k] = $dp[$i-1][$j][$k]+$dp[$i-1][$j-1][$k-$x[$i-1]];
        }else{
          $dp[$i][$j][$k] = 0;
        }
      }
    }
  }

  $ans = 0;
  for ($i=1; $i<=$n; $i++){
    $ans += $dp[$n][$i][$i*$a];
  }
  echo $ans;
  

Measured memory_bytes: 224892
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#pragma GCC optimize("O3")
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
string s;
bool W,N,E,S;
int main() 
{
    fast;
    cin>>s;
    for (register int i=0;i<=s.size()-1;i++)
    {
    	if (s[i]=='W')
    	   W=true;
    	else if (s[i]=='N')
    	   N=true;
    	else if (s[i]=='E')
    	   E=true;
    	else
    	   S=true;
    }
    if (W && E && N && S || W && E && !N && !S || !W && !E && N && S || !W && !E && !N && !S)
       cout<<"Yes"<<endl;
    else
       cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	ll R, G, B, N;
	cin >> R >> G >> B >> N;
	ll ans = 0;
	for(ll i = 0; i * R <= N; i ++){
		for(ll j = 0; j * G <= N; j ++){
			if(0 <= N - i * R - j * G && (N - i * R - j * G)%B == 0){
				ans ++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for (int i=0; i<n; i+=1){
        cin >> a[i];
    }
    for (int j=1; j<=n; j+=1){
        if (j==n){
            cout << a[n-j] << "\n";
        } else{
            cout << a[n-j] << " ";
        }
    }
    
    return 0;
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val>
Val gcd(Val a, Val b) {
//use ll or int for gcd
    if (b==0) return a;
    else return gcd(b, a%b);
}
template <typename Val>
Val vec_max(vector<Val> v){
  return *max_element(v.begin(),v.end());
}
template <typename Val>
Val vec_min(vector<Val> v){
  return *min_element(v.begin(),v.end());
}
//---------------------------------------------------------------
int main(){
  int N,K;
  cin>>N>>K;
  vec d(K);
  vector<int>A(N,0);
  rep(i,K){
    int d;
    cin>>d;
    rep(j,d){
      int a;
      cin>>a;
      A.at(a-1)++;
    }

  }
  int ans = 0;
  rep(i,N){
    if(A.at(i)==0)ans++;
  }
  cout<<ans<<endl;



}


Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <chrono>

using namespace std;

const int MAXN = 200000;

char s[1 + MAXN];
bool dpa[1 + MAXN], dpb[1 + MAXN], dpc[1 + MAXN], dpd[1 + MAXN];

void dodp(int n, int x, bool* dp) {
    dp[x] = true;
    for (int i = x + 1; i <= n; i++)
        dp[i] = (s[i] != '#') && (dp[i - 1] || dp[i - 2]);
    for (int i = x - 1; i >= 1; i--)
        dp[i] = (s[i] != '#') && (dp[i + 1] || dp[i + 2]);
}

void print(bool answer) {
    if (answer)
        cout << "Yes\n";
    else
        cout << "No\n";
}

int main() {
    //ifstream cin("input.in");
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d >> (s + 1);
    dodp(n, a, dpa);
    dodp(n, b, dpb);
    dodp(n, c, dpc);
    dodp(n, d, dpd);
    if (c < d)
        print(dpa[c] && dpb[d]);
    else {
        for (int i = b; i <= d; i++)
            if (dpb[i] && dpd[i] && dpa[i - 1] && dpc[i + 1]) {
                print(true);
                return 0;
            }
        print(false);
    }
    return 0;
}







Measured memory_bytes: 1152
#include <stdio.h>
int main(){
	int a,i=0,j,k,data[100],n;
	scanf("%d",&n);
	while(i != n){
		scanf("%d",&data[i]);
		i++;
	}
	for(k=0;k<n;k++){
		k != n-1 ? printf("%d ",data[k]):printf("%d\n",data[k]);
	}

	for(i=1;i<=n-1;i++){
		a = data[i];
		j = i - 1;
		while(j >= 0 && data[j] > a){
			data[j+1] = data[j];
			j--;
		}
		data[j+1] = a;
		for(k=0;k<n;k++){
			k != n-1 ? printf("%d ",data[k]):printf("%d\n",data[k]);
		}
	}		
	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    //int k=gi();
        String s=gs();
        String t=gs();
        

	    //System.out.print(nr*2*Math.PI);
	    if (s.equals(t.substring(0, t.length()-1))) {
	    	System.out.print("Yes");
	    }else {
	    	System.out.print("No");
	    }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

int main() {
    int D, T, S;
    cin >> D >> T >> S;

    double time = (double)D / S;
    if (T >= time) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 998244353
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


#define M 100010


int main(){
    IOS;
 	
 	
	ll n;cin>>n;
	ll a[n],sum=0;
	map<ll,ll>mp;
	rep(i,0,n)cin>>a[i],mp[a[i]]++,sum+=a[i];
	ll q;cin>>q;
	while(q--){
		ll b,c;cin>>b>>c;
		ll x=mp[b];
		sum=sum-x*b+x*c;
		cout<<sum<<"\n";
		mp[c]+=x,mp[b]=0;
	}
    
     
    return 0;
}


Measured memory_bytes: 10320
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define big 998244353
#define ff first
#define se second
#define pb push_back
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define mp make_pair
#define pi 3.141592653589
int power(int x,int y){
    int r=1,z=x;
    while(y){
        if(y & 1)r*=z;
        z*=z;y=y>>1;}
    return r;}
int powerm(int x,int y,int p){
    int r=1;
    while(y){
        if(y & 1)r=(r*x)%p;
        y=y>>1;
        x=(x*x)%p;}
    return r%p;}
int modinv(int x,int m){
    return powerm(x,m-2,m);}
int logarithm(int a,int b){
    int x=0;
    while(a>1){
        x++;
        a/=b;}
    return x;}
int32_t main(){
    fast;
    string s;
    cin>>s;
    int n=s.length();
    if(s[n-1]=='s')
        cout<<s+"es";
    else
        cout<<s+'s';
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;

string s;
int sol[100002];

int main () {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> s;
	for (int i = 0; i < s.size()-1; i ++) {
		if (s[i] == 'R' && s[i+1] == 'L') {
			int p = i;
			while (s[p] == 'R') {
				if ((i-p) % 2 == 0) sol[i] ++;
				else sol[i+1] ++;
				
				p --;
			}
			
			p = i+1;
			while (s[p] == 'L') {
				if ((p-i) % 2 == 0) sol[i] ++;
				else sol[i+1] ++;
				
				p ++;
			}
		}
	}


	for (int i = 0; i < s.size(); i ++) cout << sol[i] << " ";

	return 0;
}

Measured memory_bytes: 1104
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	if ((a + b) % 2) {
		printf("IMPOSSIBLE\n");
	}
	else {
		printf("%d\n", (a + b) / 2);
	}
	return 0;
}

Measured memory_bytes: 128
n = int(input())
v = list(map(int, input().split(" ")))

#後で合成するものの影響力が大きいので、
#大きい数を後で合成する？

#昇順
v.sort()

while len(v) > 1:
  # 最小の2つを合成してappend
  v.append((v[0] + v[1]) / 2)
  # 合成した2つを除去しsort
  v = v[2:]
  v.sort()

print(v[0])

Measured memory_bytes: 3060
using namespace std;
#include <iostream>
    #include <bits/stdc++.h>
     
    int main() {
      int a,b,k;
      cin>>a>>b>>k;
      
      for (int i=a;i<=b;i++){
        if (i<=a+k-1 || b-k+1<=i){
          cout << i << endl;
        }
      }
     
      return 0;
    }

Measured memory_bytes: 256
import sys
s = int(input())
aaa = [s]
a_now = s
for i in range(2,1000000):
  if a_now%2 == 0:
    a_next = a_now/2
  else:
    a_next = 3 * a_now + 1
  if a_next in aaa:
    print(i)
    sys.exit()
  aaa.append(a_next)
  a_now = a_next


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

int a[100000];
int n, x, y, mx = 0;
int solve(int mid){
	int cnt = 0;
	for(int i = 0;i < n;i++){
		int tmp = a[i]-mid*y;
		if(tmp <= 0)continue;
		cnt += (tmp+x-1)/x;
	}
	return cnt <= mid;
}

signed main(){
	scanf("%lld%lld%lld", &n, &x, &y);
	for(int i = 0;i < n;i++){
		scanf("%lld", &a[i]);
		mx = max(mx, a[i]);
	}
	x = x-y;
	int lb = -1, ub = mx;
	while(ub-lb > 1){
		int mid = (lb+ub)/2;
		int res = solve(mid);
		if(res)ub = mid;
		else lb = mid;
	}
	printf("%lld\n", ub);
	return 0;
}

Measured memory_bytes: 1024
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    XY=LLIN(N)
    ans = 0
    cnt = 0
    for it in permutations(XY):
        res = 0
        for i,(x,y) in enumerate(it[:-1]):
            res += sqrt((x-it[i+1][0])**2 + (y-it[i+1][1])**2 )
        ans += res
        cnt+=1
    print(ans/cnt)
if __name__ == '__main__':
    main()

Measured memory_bytes: 42220
#include<bits/stdc++.h>
using namespace std;
#define INF 10000000000

bool comp(int a, int b){
    return a > b;
}

int main(){

    int n, h; cin >> n >> h;
    vector<int> a(n);
    vector<int> b(n);
    int amax = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        amax = max(amax, a[i]);
    }

    sort(b.begin(), b.end(), comp);

    
    int j = 0;
    int ans = 0;
    while(h > 0){
        //cout << h << endl;
        if(j < b.size() && b[j] > amax){
            h -= b[j];
            j++;
            ans++;
        }else{
            break;
        }
    }

    if(h > 0){
        ans += h / amax;
        if(h % amax != 0) ans++;
    }
    

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;main(){for(long long i,n,j[99999],s,a;;cout<<a<<endl){cin>>n;if(!n)break;for(i=s=0;i++<n;s+=a)cin>>a;for(i=n;i>1;cin>>j[--i]);for(sort(j+1,j+n);n>0;s+=j[n])a=max(n--*s,a);}}

Measured memory_bytes: 1688
#include<bits/stdc++.h>
using namespace std;
#define V vector
#define L long
#define W V<L>
#define R(n)for(L i;i<n;i++){L c
L E=70;W S(V<W>p){if(!E){return{1,0};}V<V<W>>T(2);for(W x:p){T[x[1]&1].push_back({x[0]/2,x[1]/2});if(x[0]&1){T[(x[1]+1)&1].push_back({x[0]/2,(x[1]+1)/2});}}R(2)=0;for(W x:T[!i]){L Q=(2*x[0]+x[1])%3;c^=Q+1;}if(!c){E--;W A=S(T[i]);A[0]*=2;A[1]*=2;A[1]+=i;return A;}}for(W&v:p){v[0]++;}W A=S(p);A[0]--;return A;}int main(){L M=2e17,n,b;cin>>n;V<W>p(n);R(n);cin>>c>>b;p[i]={c+M,b+M};}W x=S(p);cout<<x[0]-M<<" "<<x[1]-M;}

Measured memory_bytes: 62908
import numpy as  np


n = int(input())
p = np.array(input().split(), np.int32)

res =  0

for i in range(1, n-1):
    p_part = p[i-1:i+2]
    p_sorted = np.sort(p_part)
    if  p_part[1] == p_sorted[1]:
        res += 1

print(res)


Measured memory_bytes: 13432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

ll n,k,a[200010],b[200010];
ll ans=0;
ll l=0,r=1e12;

bool f(ll x){  // 最大値を以下に出来るかどうか
	ll sum=0;  // 最低何回必要か
	rep(i,n){
		ll c = a[i]*b[n-1-i];
		if(c>x)sum += (c-x+b[n-1-i]-1)/b[n-1-i];
	}
	// cerr<<x<<":"<<sum<<endl;
	return sum<=k;
}

int main(void){
	cin>>n>>k;
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	sort(a,a+n);
	sort(b,b+n);
	if(f(0)){
		cout<<0<<endl;
		return 0;
	}
	while(r-l>1){
		ll mid=(r+l)/2;
		if(f(mid)){
			r=mid;
		}else{
			l=mid;
		}
	}
	cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 3328
n=int(input())
CSF=[]
for _ in range(n-1):
  CSF.append(list(map(int,input().split())))

result=[]
for i in range(n-1):
  temp=CSF[i][1]+CSF[i][0]
  j=i+1
  while j<n-1:
    #at+b
    a,b=CSF[j][2],CSF[j][1]
    t=(temp-b)/a
    if t<=0:
      t=0
    else:
      t=-1*((b-temp)//a)
    temp=a*t+b+CSF[j][0]  
    j+=1
  result.append(temp)

for item in result:
  print(item)
print(0)

Measured memory_bytes: 40688
import sys


def solve():
    N, *H = map(int, sys.stdin.read().split())
    INF = 10 ** 10
    dp = [INF] * N
    dp[0] = 0
    dp[1] = abs(H[1] - H[0])
    h_2 = H[0]
    h_1 = H[1]
    for i, h in enumerate(H[2:], start=2):
        dp[i] = min(dp[i - 1] + abs(h - h_1), dp[i - 2] + abs(h - h_2))
        h_2 = h_1
        h_1 = h
    return dp[-1]


if __name__ == "__main__":
    answer = solve()
    print(answer)


Measured memory_bytes: 13876
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int N;
    cin >> N;
    while (N > 0) {
        if (N % 10 == 7) {
            cout << "Yes" << endl;
            exit(0);
        }
        N /= 10;
    }
    cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <limits>
#include <math.h>
#include <cmath>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vvi = vector<vector<int>> ;
using vll = vector<long long>;
using vvll = vector<vector<long long >>;
#define PI 3.141592653
#define rep(i, n) for(ll i = 0; i < n; i++)

int main(){
  int k, a, b;
  cin >> k >> a >> b;

  bool f = false;

  for(int i = a; i <= b; i++){
    if(i % k == 0){f = true;}
  }

  if(f){cout << "OK" << endl;}
  else{cout << "NG" << endl;}
}

Measured memory_bytes: 3636
A,B,C,D = [],[],[],[]


for j in range(3):
    A.append([0,0,0,0,0,0,0,0,0,0])
    B.append([0,0,0,0,0,0,0,0,0,0])
    C.append([0,0,0,0,0,0,0,0,0,0])
    D.append([0,0,0,0,0,0,0,0,0,0])


n = int(input())
  

for i in range(n):
    b,f,r,v = map(int,input().split())
    if b == 1:
        A[f-1][r-1] += v 
     
    elif b == 2:
        B[f-1][r-1] += v        
    elif b == 3:
        C[f-1][r-1] += v
    elif b == 4:
        D[f-1][r-1] += v

line = "#"*20

for i in A:
    for k in i:
        print("",k,end ="")
    print()

print(line)
for i in B:
    for k in i:
        print("",k,end ="")
    print()
print(line)
for i in C:
    for k in i:
        print("",k,end ="")
    print()
print(line)
for i in D:
    for k in i:
        print("",k,end ="")
    print()


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

int main()
{
	double PI = atan(1.0)*4;
	double a = 90;
	double x=0, y=0;

	while ( true )
	{
		char c;
		int r,t;
		cin>>r>>c>>t;
		if ( r==0 && t==0 )
			break;

		x += r*cos(a/360.*2*PI);
		y += r*sin(a/360.*2*PI);
		a -= t;
	}

	cout << (int)x << endl;
	cout << (int)y << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

map<string, int> tbl;
int getId(string& name) {
	if ( tbl.count(name) == 0 ) {
		int freshId = tbl.size();
		return tbl[name] = freshId;
	}
	return tbl[name];
}
struct Edge {
	int from, to, cost;
};
struct Node {
	int v, rest, cost;
};
bool operator>(const Node& n1, const Node& n2) {
	return n1.cost > n2.cost;
}
int dist[3010][2100];
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int E, M, cap;
	while ( cin >> E >> M >> cap, E || M || cap ) {
		tbl.clear();
		int s, t;
		{
			string src, dest; cin >> src >> dest;
			s = getId(src);
			t = getId(dest);
		}
		vector<Edge> edges;
		REP(i,E) {
			string un, vn; cin >> un >> vn;
			int u = getId(un), v = getId(vn);
			int d; cin >> d;
			edges.pb({u, v, d});
		}
		int N = tbl.size();
		vector< vector<Edge> > G(N);
		EACH(e,edges) {
			G[e.from].pb(e);
			G[e.to].pb({e.to, e.from, e.cost});
		}
		vector<bool> lpg(N, false);
		REP(i,M) {
			string s; cin >> s;
			int id = getId(s);
			lpg[id] = true;
		}
		fill(dist[0], dist[3010], inf); dist[s][cap] = 0;
		priority_queue<Node, vector<Node>, greater<Node> > Q; Q.push({s, cap*10, 0});
		while ( !Q.empty() ) {
			Node node = Q.top(); Q.pop();
			int v = node.v, rest = node.rest, cost = node.cost;
//			cout << v << " " << rest << " " << cost << endl;
			if (cost > dist[v][rest]) continue;
			EACH(e,G[v]) {
				int r = rest - e.cost;
				if (r < 0) continue;
				if (lpg[e.to]) r = cap*10;
//				cout << e.to << " " << r << " " << cost+e.cost << " " << dist[e.to][r] << endl;
				if (cost+e.cost < dist[e.to][r]) {
					dist[e.to][r] = cost+e.cost;
					Q.push({e.to, r, dist[e.to][r]});
				}
			}
		}
		int ans = inf;
		REP(i,cap*10+1) ans = min(ans, dist[t][i]);
		if (ans == inf) {
			cout << -1 << endl;
		}
		else {
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 53036
import java.util.*;

class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		long N = sc.nextInt();
		long M = sc.nextInt();
		
		if(N > 1L && M > 1L){
			System.out.println( (N  - 2L) * (M - 2L) );
		}
		if( N == 1L && M > 1L){
			System.out.println( M - 2L );
		}
		if( N > 1L && M == 1L){
			System.out.println( N - 2L );
		}
		if( N == 1L && M == 1L){
			System.out.println(1);
		}
	}
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		int W=sc.nextInt();	//横：x座標
		int H=sc.nextInt();	//縦：y座標
		int N=sc.nextInt();	//数列aの長さ

		int x_min=0,x_max=W;	//最終的に求める長方形の横
		int y_min=0,y_max=H;	//最終的に求める長方形の縦

		//最終的に求める長方形の面積
		int sum=0;

		for(int i=1;i<=N;i++){
			int x=sc.nextInt();
			int y=sc.nextInt();
			int a=sc.nextInt();

			if(a==1 && x>x_min) x_min=x;
			else if(a==2 && x<x_max) x_max=x;
			else if(a==3 && y>y_min) y_min=y;
			else if(a==4 && y<y_max) y_max=y;

		}

		//残っている長方形がない場合sumは0
		if(x_max<x_min || y_max<y_min) sum=0;
		else sum=(x_max-x_min)*(y_max-y_min);

		//答えを出力
		System.out.println(sum);
	}
} 

Measured memory_bytes: 23380
#include<iostream>

using namespace std;

int euclid(int A, int B) {

	int mod = A % B;
	if (B == 1)return 1;
	if (mod == 0)return B;
	else return euclid(B, mod);

}

int main() {

	int A = 0;
	int B = 0;

	cin >> A >> B;

	if (A < B) {

		int temp = A;
		A = B;
		B = temp;

	}

	cout << euclid(A, B) << endl;
	
	return 0;

}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <utility>

void print(std::vector<int> &vec){
    for(int i = 0; i < vec.size(); ++i){
        std::cout << vec.at(i);
        if(vec.size() - 1 != i){
            std::cout << " ";
        }else{
            std::cout << std::endl;
        }
    }
}

void insertionSort(std::vector<int> &vec){
    // This function sorts the partial array from the index "0" to "i" at each step.
    // In the loop where the "i + 1" th value is considered, the value will be inserted in a proper place in the "0-i" array or its end.
    for(int i = 1; i < vec.size(); ++i){
        auto v = vec.at(i), j = i - 1;
        while(0 <= j && v < vec.at(j)){
            vec.at(j + 1) = vec.at(j);
            --j;
        }
        // Because of "--j" at the end of the while loop, j indicate the index prior to the target place by 1.
        // Hence, j has to be incremented before the "v" is inserted in the proper place.
        vec.at(j + 1) = v;

        print(vec);
    }
}

int bubbleSort(std::vector<int> &vec){
    bool flg = true;
    int count = 0;
    while(flg){
        flg = false;
        // Compare the array in a reverse order
        for(int i = vec.size() - 1; 0 < i; --i){
            if(vec.at(i) < vec.at(i - 1)){
                std::swap(vec.at(i), vec.at(i - 1));
                flg = true; // If some two elements will be swapped, the next while loop will be activated.
                ++count;
            }
        }
    }

    return count;
}

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

    std::vector<int> a(n);
    for(int i = 0; i < n; ++i){
        std::cin >> a.at(i);
    }

    // for alds1_1_a.cpp
//    print(a);
//    insertionSort(a);

    // for alds1_2_a.cpp
    auto val = bubbleSort(a);
    print(a);
    std::cout << val << std::endl;
    
    return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#define rep(i, b) for(int i = 0; i < b; i++)

using namespace std;

bool smp[300001];

int main(){

  rep(i,300001){ //月曜土曜数の判定
        if((i%7==1)||(i%7==6))smp[i] = true;
        else smp[i] = false;
    }

    smp[1] = false;

    rep(i,300001){
        if(smp[i]){
            for(int j = i*2; j < 300001;j += i){
                smp[j] = false;
            }
        }
    }
    int n = 0;
    while(cin >> n, n != 1){
        cout << n << ':';
        rep(i,n+1){
	  if(smp[i] && n % i == 0) cout << ' ' << i;
        }
	cout << endl;
    }
}

Measured memory_bytes: 1452
M, D = map(int, input().split())
count = 0
for i in range(22, D+1):
    str_i = str(i)
    if int(str_i[0]) < 2 or int(str_i[1]) < 2:
        continue
    if int(str_i[0]) * int(str_i[1]) <= M:
        count += 1
print(count)

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

N = int(input())

grid = []
for i in range(N):
    array = list(map(int, input().split()))
    grid.append(array)

dp = a = [[0 for i in range(3)] for j in range(N)]
dp[0][0] = grid[0][0]
dp[0][1] = grid[0][1]
dp[0][2] = grid[0][2]


for i in range(0, N-1):
    dp[i+1][0] = max(dp[i][1] + grid[i+1][0], dp[i][2]+ grid[i+1][0])
    dp[i+1][1] = max(dp[i][0] + grid[i+1][1], dp[i][2]+ grid[i+1][1])
    dp[i+1][2] = max(dp[i][0] + grid[i+1][2], dp[i][1]+ grid[i+1][2])

print(max(dp[N-1][:]))




Measured memory_bytes: 47336
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	var n, m int
	fmt.Sscan(getNextLine(scanner), &n, &m)
	trees := make([]tree, n)
	for i := 0; i < n; i++ {
		trees[i].parent = i
	}

	for i := 0; i < m; i++ {
		xyz := getIntList(scanner)
		x := xyz[0] - 1
		y := xyz[1] - 1
		rx := root(x, trees)
		ry := root(y, trees)
		if rx == ry {
			continue
		}
		if rx < ry {
			trees[ry].parent = rx
			continue
		}
		trees[rx].parent = ry
	}
	ans := make(map[int]int)
	for i := 0; i < n; i++ {
		ans[root(i, trees)] = 1
	}
	sum := 0
	for _, x := range ans {
		sum += x
	}
	fmt.Println(sum)

}

type tree struct {
	parent int
}

func root(i int, trees []tree) int {
	if i == trees[i].parent {
		return i
	}
	trees[i].parent = root(trees[i].parent, trees)
	return trees[i].parent
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
int main(){
	int r,D,x0,x;
	cin>>r>>D>>x0;
	for(int i=0;i<10;i++){
		x = r*x0-D;
		printf("%d\n",x);
		x0 = x;
	}
	return 0;
}

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

using namespace std;

int main() {
	long n, cnt;
	cin >> n;

	cnt = 0;
	while(n > 0) {
		n = n/2;
		cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
const int MOD = 1e9+7;
int K, M, N;

constexpr int fpm(int base, int index) {
    int power = 1;
    while (index) {
        if (index & 1) {
            power = 1LL * base * power % MOD;
        }
        base = 1LL * base * base % MOD;
        index >>= 1;
    }
    return power;
}
constexpr int inv2 = fpm(2, MOD-2);

int ncr(int r) {
    // (N x M - 2) choose (K - 2)
    int n = (1LL * N * M % MOD + MOD - 2) % MOD;
    int c = 1;
    for (int i = 1; i <= r; ++i) {
        c = 1LL * c * (n - (i - 1)) % MOD * fpm(i, MOD-2) % MOD;
    }
    return c;
}

int sum(int n) { return 1LL * n * (n + 1) % MOD * inv2 % MOD; }

int main() {
    scanf(" %d%d%d", &N, &M, &K);
    int ret = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            int a = M-j;
            int b = N-i;
            ret = (1LL * sum(a - 1) * b % MOD + ret) % MOD;   // Forwards (>= i)
            ret = (1LL * sum(j) * (b - 1) % MOD + ret) % MOD; // Backwards (> i)
            ret = (1LL * sum(b - 1) * M % MOD + ret) % MOD;   // Downwards (all)
        }
    }
    ret = 1LL * ret * ncr(K-2) % MOD;
    printf("%d\n", ret);
    return 0;
}


Measured memory_bytes: 128
def fac(n):
    if n==0 or n==1:return 1
    e=1
    for i in range(1,n+1):
        e*=i
    return e

zero=lambda t:len(t)-max([t.rfind(str(i)) for i in range(1,10)])-1
r=[]
while 1:
    p=int(input())
    if not p:break
    r.extend([zero(str(fac(p)))])
[print(i) for i in r]



Measured memory_bytes: 5692
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int input = Integer.parseInt(br.readLine());
	if (input == 0) {
	    System.out.println(1);
	} else {
	    System.out.println(0);
	}
    }
}

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

// #define ONLINE_JUDGE

#define V vector
#define P pair

using LL = long long;
#define FOR(i, x, y) \
    for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) \
    for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
    do {                                      \
        cerr << "\033[32;1m" << #x << " -> "; \
        err(x);                               \
    } while (0)
void err() { cerr << "\033[39;0m" << endl; }
template <template <typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
    for (auto v : a) cerr << v << ' ';
    err(x...);
}
template <typename T, typename... A>
void err(T a, A... x) {
    cerr << a << ' ';
    err(x...);
}
#else
#define dbg(...)
#endif
#define sz(x) (int)x.size()

LL bin(LL a, LL b, LL p) {
    LL res = 1;
    a = (a % p + p) % p;
    for (; b; b >>= 1, a = a * a % p)
        if (b & 1) res = res * a % p;

    return res;
}



void solve() {
    int x;
    scanf("%d", &x);
    if (x >= 30) {
        puts("Yes");
    } else {
        puts("No");
    }
}

int main() {

    // int t;
    // cin >> t;
    // while (t--) solve();

    solve();

    return 0;
}

Measured memory_bytes: 3756
#include<iostream>
using namespace std;
int main () {
  char a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a == b) {
    if (a != c && c == d) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else {
    if (a == c) {
      if (b == d) cout << "Yes" << endl;
      else cout << "No" << endl;
    }
    else {
      if (a == d && b == c) cout << "Yes" << endl;
      else cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 256
S = gets.chomp
N = S.size
L = Rational(N, 2).ceil

if S[0] == '0' || S[-1] == '1'
  puts -1
  exit
end

cur = 0
sizes = []

1.upto(L) do |l|
  a = S[l - 1]
  b = S[N - l - 1]

  if a != b
    puts -1
    exit
  end
end

b_idx = -1
parents = Hash.new
indices = []

S.each_char.with_index(1) do |s, idx|
  next if s == '0'

  indices << idx
end

indices << N

1.upto(N - 1) do |u|
  v = indices.bsearch { |x| x > u }

  puts "#{u} #{v}"
end


Measured memory_bytes: 15476
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll w[200005];
ll v[200005];
ll c[200005];
ll h[200005];
ll dp[105][100005];
typedef pair<int, int> P;

int main() {
	ll n, W;
	cin >> n >> W;
	for (int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
	}
	for (int i = 0; i <= W; i++) {
		dp[0][i] = 0;
	}

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= W; j++) {
			if (j >= w[i]) {
				dp[i + 1][j] = max(dp[i][j],dp[i][j - w[i]] + v[i]);
			}
			else {
				dp[i + 1][j] = dp[i][j];
			}
		}
	}
	cout << dp[n][W] << endl;
	return 0;
}

Measured memory_bytes: 84224
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<map>
#include<set>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
	
using namespace std;
typedef long long LL;

const int N = 100010;
const int mo = 1e+9+7;

int a[N];
int b[N];
int n,m;

int main(){
	scanf("%d%d",&n,&m);
	fo(i,1,n)scanf("%d",&a[i]);
	fo(i,1,m)scanf("%d",&b[i]);
	sort(a+1,a+1+n);
	sort(b+1,b+1+m);
	LL x=0,y=0,tmp=0,ans=0;
	fo(i,1,n){
		x=((x+1ll*a[i]*(i-1)%mo)%mo+mo-tmp)%mo;
		tmp=(tmp+a[i])%mo;
	}
	tmp=0;
	fo(i,1,m){
		y=((y+1ll*b[i]*(i-1)%mo)%mo+mo-tmp)%mo;
		tmp=(tmp+b[i])%mo;
	}
	ans=x*y%mo;
	printf("%I64d\n",ans);
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    while (n-- > 0) {
        string line;
        cin >> line;

        int count = 0;
        while (line.size() > 1) {
            int sum = line[0] - '0' + line[1] - '0';
            stringstream ss;
            ss << sum;
            string temp = ss.str();
            line.replace(0, 2, temp);
            count++;
        }
        if (count % 2 == 0) {
            cout << "Audrey wins." << endl;
        } else {
            cout << "Fabre wins." << endl;
        }
    }
}

Measured memory_bytes: 944
import math
a,b,h,m = map(int, input().split())
time = 60*h + m
Adeg = 0.5*time
Bdeg = 6*time
Arad = math.radians(0.5*time) # ωt
Brad = math.radians(6*time)
x1 = a*math.sin(Arad)
y1 = a*math.cos(Arad)
x2 = b*math.sin(Brad)
y2 = b*math.cos(Brad)
ans = ((x1-x2)**2 + (y1-y2)**2)**0.5
print(ans)

Measured memory_bytes: 62680
import sys
import copy
from collections import deque
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()

def f(n):
    if n==0:
        return ''
    n -= 1
    return f(n//26) + chr(97+n%26)

print(f(n))



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

using namespace std;
typedef long long ll;
const int MAXH = 2 * 10005;
const ll INF = 2e18;

ll dp[MAXH];

struct magic {
  int damage, cost;
  magic(): damage(0), cost(0) {};
  magic(int d, int c): damage(d), cost(c) {};
};

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

  vector<magic> magics(n);
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    magics[i] = magic(a, b);
  }

  fill(dp, dp + MAXH, INF);

  dp[0] = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < n; ++j) {
      dp[i + magics[j].damage] = min(dp[i + magics[j].damage], dp[i] + magics[j].cost);
    }
  }

  ll ans = INF;
  for (int i = h; i < MAXH; ++i) {
    ans = min(ans, dp[i]);
  }
  cout << ans << endl;
  return 0;
}



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

using std::pair;
using std::vector;
using std::string;
 
typedef long long ll;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 100000;

int n;
int a[2 * N + 5], b[2 * N + 5];

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n);

    ++ a[N], ++ b[N];
    for(int i = 1; i <= n; ++i) {
        static int l, r;
        read(l), read(r);
        ++ a[r + N], ++ b[l + N];
    }

    ll ans = 0;
    for(int i = 1; i <= 2 * N; ++i) a[i] += a[i-1];
    for(int i = 2*N-1; i >= 0; --i) b[i] += b[i+1];
    for(int i = 0; i <= 2 * N - 1; ++i) ans += std::min(a[i], b[i + 1]);
    printf("%lld\n", ans * 2);

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	
	cout << min(B/A, C) << endl;

	return 0;
}

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
 int a, b;
 cin >> a >> b;
 if(a%2==1&&b%2==1)cout << "Yes" << endl;
 else cout << "No" << endl;
}

Measured memory_bytes: 3628
N, M = (int(x) for x in input().split())

A = [list(map(int, input().split())) for i in range(M)]

X = ['0' for i in range(N)]
X[0] = '1'
for i in A:
    X[i[0] - 1] = str(i[1])

F = 1
for i in A:
    if N > 1 and i[0] == 1 and i[1] == 0:
        F = 0
    for j in A:
        if i[0] == j[0] and i[1] != j[1]:
            F = 0
            
if N == 1 and M == 0:
    print(0)
elif F == 1:
    print(''.join(X))
else:
    print(-1)

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

int main(){
    double N;
    cin >> N;
    vector<double>a(N);
    double goukei = 0.0;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        goukei+=a[i];
    }
    goukei/=N;
    double sa = 100;
    for(int i = 0; i < N; i++) {
        sa = min(sa,abs(goukei-a[i]));
    }
    for(int i = 0; i < N; i++) {
        if(abs(goukei-a[i]) == sa) {
            cout << i << endl;
            return 0;
        }
    }
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define ll long long int 
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld",&a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define pb(v,a) v.push_back(a)
#define pll pair <ll, ll>
#define mp make_pair
#define pbp(v,a,i) v.push_back(make_pair(a,i)) 
#define srt(v) sort(v.begin(),v.end())
#define rv(v) reverse(v.begin(),v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'
 
 
 
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
 map<ll,ll>m;
int main()
{
	_fastio
	ll n,ar[200005],sm;
	cin>>n;
	for1(i,n)
	{
		cin>>ar[i];
		if(i==1)
			sm=ar[i];
		else
			sm=sm^ar[i];
	}
	for1(i,n)
	{
		ll as=sm^ar[i];
		cout<<as<<' ';
	}
	cout<<en;
}

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

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

    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    int mina = INT_MAX, minb = INT_MAX;
    for (auto &p : a) {
        cin >> p;
        mina = min(mina, p);
    }
    for (auto &p : b) {
        cin >> p;
        minb = min(minb, p);
    }
    int ans = mina + minb;
    for (int i = 0; i < M; ++i) {
        int x, y, c;
        cin >> x >> y >> c;
        int res = a.at(x - 1) + b.at(y - 1) - c;
        ans = min(ans, res);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  int n;
  while(~scanf("%d",&n)){
    vector<ll> h;
    for(int i=0;i<n;i++){
      ll hit_point;
      scanf("%ld",&hit_point);
      h.push_back(hit_point);
    }
    sort(h.begin(),h.end(),greater<ll>());
    ll res = 1;

    for(int i=0;i<h.size();i++){
      res += (h[i] - i/4 >= 0 ? h[i] - i/4 : 0);
    }

    printf("%ld\n",res);
  }
}

Measured memory_bytes: 1216
import bisect
n=int(input())
a=list(map(int,input().split()))
sum=[0 for i in range(n)]

sum[0]=a[0]
for i in range(1,n):
    sum[i]=sum[i-1]+a[i]

sum.sort()
S=list(set(sum))

ans=0
for i in range(len(S)):
    r=bisect.bisect_right(sum,S[i])
    l=bisect.bisect_left(sum,S[i])
    if S[i]==0:
        ans+=(r-l)*(r-l+1)//2
    else:
        ans+=(r-l-1)*(r-l)//2

print(ans)


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

using namespace std;

int ans=100000000;
int c[12], A[12][12];

void rec(int i, int ability[], int cost, int N, int M, int X)
{
    if(i==N)
    {
        return;
    }
    int flag=1;
    int newability[M];
    for(int j=0;j<M;j++)
    {
        newability[j]=ability[j]+A[i][j];
        //cout << newability[j] << " ";
        if(newability[j]<X)
        {
            flag=0;
        }
    }
    //cout << "\n";

    if(flag)
    {
        ans=min(ans, cost+c[i]);
    }

    rec(i+1, newability, cost+c[i], N, M, X);
    rec(i+1, ability, cost, N, M, X);
}

int main()
{
    int N, M, X;
    cin >> N >> M >> X;

    for(int i=0;i<N;i++)
    {
        cin >> c[i];
        for(int j=0;j<M;j++)
        {
            cin >> A[i][j];
        }
    }
    int ability[M]={0};
    rec(0, ability, 0, N, M, X);

    if(ans==100000000)
    {
        cout << "-1";
    }

    else{
    cout << ans;
    }
}


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

using namespace std;

int main(){
   int N;
   cin >> N;
   string S[N];
   for(int i=0;i<N;i++){
      cin >> S[i];
   }
   vector<pair<int, string>> v;
   vector<pair<int, string>> v2;
   for(int i=0;i<N;i++){
      int size = S[i].size();
      int cur = 0;
      int m = 10000000;
      for(int j=0;j<size;j++){
         if(S[i][j]==')') cur--;
         else cur++;
         m = min(m,cur);
      }
      if(cur > 0){ v.emplace_back(m,S[i]); }
      else{ v2.emplace_back(m-cur,S[i]); }
   }
   sort(v.begin(),v.end());
   reverse(v.begin(),v.end());
   sort(v2.begin(),v2.end());
   v.insert(v.end(),v2.begin(),v2.end());
   int cnt =0;
   bool ok = true;
   for(int i = 0 ; i < N&&ok; i++){
      //cout << v[i].second << endl;
      int size = v[i].second.size();
      for(int j=0;j<size&&ok;j++){
         if(v[i].second[j]==')'){
            cnt--;
            if(cnt<0){
               ok=false;
               break;
            }
         }
         else cnt++;
      }
   }
   if(ok&&cnt==0) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 112864
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>
#include <functional>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define PI 3.141592

using namespace std;

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

	priority_queue<double, vector<double>, greater<double> > vNum;

	rep(i, N)
	{
		float tmp = 0;
		cin >> tmp;
		vNum.push(tmp);
	}

	while (true)
	{
		if (vNum.size() == 1)
		{
			break;
		}

		double AA = vNum.top();
		vNum.pop();
		double BB = vNum.top();
		vNum.pop();

		double tmp = (AA + BB) / 2.0f;
		vNum.push(tmp);
	}


	printf("%.5lf", vNum.top());
}


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

int main() {
    int N;
    cin>>N;
    int ans=pow(N,3);
    printf("%d",ans);

 return 0;
}

Measured memory_bytes: 256