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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> a[i];
  }
  sort(ALL(a));
  ll ans = accumulate(ALL(a), 0LL);
  if (ans % 10 == 0)
  {
	for(int i = 0; i < n; ++i)
	{
	  if (a[i] % 10 != 0)
	  {
	    ans -= a[i];
		break;
	  }
	}
  }
  cout << (ans % 10 == 0 ? 0 : ans);
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, m) cin >> b[i];
  rep(i, n) {
    rep(j, m) {
      cin >> a[i][j];
    }
  }

  int cnt = 0;
  rep(i, n) {
    int sum = c;
    rep(j, m) sum += a[i][j]*b[j];
    if (sum > 0) cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
s = S()
if s[5] == '1':
    print('TBD')
elif int(s[6]) < 5:
    print('Heisei')
else:
    print('TBD')

Measured memory_bytes: 3948
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include <vector>
using namespace std;
#define pi M_PI
typedef long long ll;

int main(){
    ll a, b, x;
    cin >> a >> b >> x;
    ll ans = b/x - a/x;
    if(a%x==0)ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstdio>
using namespace std;
int main(){
  int n;
  scanf("%d",&n);
  int cnt=10000000;
  for(int i=1;i<=(n+1)/2;i++){
    int j=n-i;
    int cnt1=0,cnt2=0;
    char s[10],t[10];
    sprintf(s,"%d",i);
    sprintf(t,"%d",j);
    string x=s,y=t;
    for(int i=0;i<x.size();i++)
      {if(s[i]==' ')
         break;
       cnt1+=s[i]-'0';}
    for(int i=0;i<y.size();i++){
      if(t[i]==' ')
        break;
      cnt2+=t[i]-'0';}
    cnt=min(cnt,(cnt1+cnt2));}
  cout<<cnt;
  return 0;
}

Measured memory_bytes: 256
// B - Making Triangle
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	int N; cin>>N;
	vector<int> L(N); rp(i, 0, N) cin>>L[i];
	int c = 0;
	rp(i, 0, N) rp(j, i+1, N){
		if(L[i] == L[j]) continue;
		rp(k, j+1, N){
			if(L[j] == L[k] || L[k] == L[i]) continue;
			if((int64_t)L[i] + L[j] + L[k] > max({L[i], L[j], L[k]})*2) c++;
		}
	}
	cout<< c <<endl;
}


Measured memory_bytes: 3596
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    long long int a,b;
    cin>>a>>b;
    //公約数計算
    while(a>0&&b>0){
        if(a<b){
            b=b%a;
        }
        else{
            a=a%b;
        }
    }
    if(b>0){a=b;}
    //素因数分解
    //素数列の生成
    vector<bool> isprime;
    vector<int> prime;
    long long int i=1;
    int p=0;
    while (i*i<a){i++;}
    isprime.resize(i+1,true);
    isprime[1]=false;
    for(int j=2;j<=i;j++){
        if(isprime[j]){
            prime.push_back(j);
            p++;
            for(int k=2;j*k<=i;k++){
                isprime[j*k]=false;
            }
        }
    }
    /*for(int j=0;j<p;j++){
        cout<<prime[j]<<endl;
    }*/
    //素数列に従って調査
    int cnt=0;
    for(int d=0;d<p;d++){
            if(a%prime[d]==0){
                cnt++;
                while(a%prime[d]==0){
                   a=a/prime[d];
                }
            }
    }
    if(a!=1){cnt++;}
    cout<<cnt+1<<endl;
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int D;
int C[26];
int S[400][26];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>D;
	FOR(i,26) cin>>C[i];
	FOR(i,D) {
		FOR(j,26) cin>>S[i][j];
		cout<<i%26+1<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3696
#include <stdio.h>
#include <stdlib.h>
#define N 20
#define Q 200

int A[2000];
int m[2000];
int n;

int res(int,int);

int main(){
  int q,i;

  scanf("%d",&n); 
  if(n>N){
    printf("error\n");
    exit(1);
  }
  
  for(i=0 ; i<n ; i++){
    scanf("%d",&A[i]);
  }
  
  scanf("%d",&q);
  if(q>Q){
    printf("error\n");
    exit(2);
  }
  
  for(i=0 ; i<q ; i++){
    scanf("%d",&m[i]);
  }
  
  for(i=0 ; i<q ; i++){
    if(res(0,m[i])==1)printf("yes\n");
  if(res(0,m[i])==0)printf("no\n");
  }
  return 0;
    }

     
int res(int i,int m){
  int result;
  
  if(m == 0)return 1;
  if(i >= n)return 0;
  result = res(i+1,m)||res(i+1,m-A[i]);
  return result;
}


  

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

L = []
L.extend(((int(x), 3)  for x in input().split()))
L.extend(((int(x), 2)  for x in input().split()))
L.extend(((int(x), 1)  for x in input().split()))

L = sorted(L, reverse=True)

cnt_C = 0
cnt_B = 0
cnt_A = 0
for x, i in L:
    if i == 1:
        cnt_C += 1
    elif i == 2:
        cnt_B += cnt_C
    elif i == 3:
        cnt_A += cnt_B

print(cnt_A)


Measured memory_bytes: 43892
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

bool odd[100001];
int main() {
	fup(i,1,9,1)odd[i]=1;
	fup(i,100,999,1)odd[i]=1;
	fup(i,10000,99999,1)odd[i]=1;
	int n;
	scanf("%d",&n);
	int ans=0;
	fup(i,1,n,1)ans+=odd[i];
	printf("%d",ans);
}

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

int main(){
  int K, T;
  vector<int> A;
  cin >> K >> T;
  for(int i=0; i<T; i++){
    int a; cin >> a;
    A.push_back(a);
  }
  sort(A.begin(), A.end(), greater<int>());
  int count=A[0];
  for(int i=1; i<A.size(); i++){
    count-=A[i];
  }
  if(count<0){
    cout << "0" << endl;
    return 0;
  }
  cout << count-1 << endl;
  return 0;
}

Measured memory_bytes: 256
def f(x):
    l = len(x)
    i = 0
    while x[i] == x[l-i-1]:
        i += 1
        if i > (l//2):
            return True
            break
    return False

A, B = map(int, input().split())
count = 0
for i in range(A, B+1):
    if f(str(i)):
        count += 1
print(count)


Measured memory_bytes: 9144
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(a:i64 b:i64 c:i64));
    std::cmp::max(0, c - (a - b)).to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}
tests! {
    test1: "6 4 3\n" => "1\n",
    test2: "8 3 9\n" => "4\n",
    test3: "12 3 7\n" => "0\n",
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);

ll calc(ll h){
	if(h==1)return 1;
	return 2LL*calc(h/2)+1LL;

}



int main(){
	ll H;
	cin >> H;

	cout << calc(H) << endl;

}


Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

int main(void){
	long n=nextlong();
	int q=sqrt(n);
	long ans=0;
	for(int i=1; i<=q; i++){
		if(n%i==0){
			if(i<n/i-1){
				ans+=n/i-1;
			}
		}
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdint>

int64_t const MOD = 1e9+7;
int const MAXN = 1e5;
int N, K;
int64_t A[MAXN];

template<int64_t Prime>
struct mod_int {
  int64_t v_;
  mod_int(int64_t x=0) : v_(x) { normalize(); }
  void normalize() { ((v_ %= Prime) += Prime) %= Prime; }
  mod_int operator+=(mod_int const& r){ (v_ += r.v_) %= Prime; return *this; }
  mod_int operator-=(mod_int const& r){ (v_ += Prime - r.v_) %= Prime; return *this; }
  mod_int operator*=(mod_int const& r){ (v_ *= r.v_) %= Prime; return *this; }
  mod_int operator+(mod_int const& r) { mod_int res(*this); return res += r; }
  mod_int operator-(mod_int const& r) { mod_int res(*this); return res -= r; }
  mod_int operator*(mod_int const& r) { mod_int res(*this); return res *= r; }
  mod_int pow(int x) const {
    int64_t res = 1, v = v_;
    while(x > 0) {
      if(x&1) (res *= v) %= Prime;
      x/=2; (v *= v) %= Prime;
    }
    return mod_int(res);
  }
  mod_int inv() const { return pow(Prime-2); }
};
typedef mod_int<MOD> mint;

mint fact[MAXN+1], ifact[MAXN+1];
void init() {
  fact[0] = fact[1] = mint(1);
  for(int i = 2; i <= N; ++i) fact[i] = fact[i-1]*i;
  ifact[N] = fact[N].inv();
  for(int i = N-1; i >= 0; --i) ifact[i] = ifact[i+1]*(i+1);
}
mint comb(int n, int k) { return fact[n]*ifact[k]*ifact[n-k]; }

int main() {
  std::cin >> N >> K;
  init();
  for(int i = 0; i < N; ++i) std::cin >> A[i];
  std::sort(A, A+N);
  /*mint vm, vM;
  for(int i = 0; i < N; ++i) {
    if(i+K<=N) vm += comb(N-i-1, K-1)*A[i];
    if(i>=K-1) vM += comb(i, K-1)*A[i];
  }
  std::cout << (vM - vm).v_ << std::endl;*/
  mint ans;
  for(int i = 0; i+K <= N; ++i) {
    mint diff = 
    ans += (mint(A[N-1-i]) - mint(A[i]))*comb(N-i-1, K-1);
  }
  std::cout << ans.v_ << std::endl;
  return 0;
}


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


int main() {
	
	int N,k,len;
	cin >> N >> k;
	vector<int> l(N);
	for(auto &i : l) cin >> i;
	sort(l.rbegin(),l.rend());
	for(int i=0; i<k; i++) len += l.at(i);
	cout << len << endl;
	
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String s = stdIn.next();
		
		int ans = 0;
		for(int i = 0; i < s.length();i++) {
			int cnt = 0;
			
			if(s.charAt(i)== 'A' ||s.charAt(i)== 'C' ||s.charAt(i)== 'G' || s.charAt(i)=='T') {
				cnt++;
				for(int j = i+1 ;j < s.length();j++) {
					if(s.charAt(j)== 'A' ||s.charAt(j)== 'C' ||s.charAt(j)== 'G' || s.charAt(j)=='T') {
						cnt++;
					}else {
						//ans = Math.max(ans, cnt);
						break ;
					}
				}
			}
			
			ans = Math.max(ans, cnt);
		}
		System.out.println(ans);
		
		
		
	}

}


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

int main() {
	
    string s;
    cin >> s;
    int n = s.size();

    int a, b = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'A') { a = i; break; }
    }

    for (int i = n; i > a; i--) {
        if (s[i] == 'Z') { b = i + 1; break; }
    }
    cout << b - a << endl;

    return 0;
    
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def main():
    N = int(input())
    B = list(map(int, input().split()))

    ans = B[0] + B[-1]
    for i in range(N-2):
        ans += min(B[i], B[i+1])

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n; cin >> n;
    ll k; cin >> k;
    vector<int> cost(n);
    vector<int> food(n);
    rep(i,n) cin >> cost[i];
    rep(i,n) cin >> food[i];
    sort(ALL(cost));
    sort(RALL(food));

    ll l = -1, r = 1e12;
    while(l+1<r) {
        ll mid = (r+l)/2;
        ll s = 0;
        rep(i,n) {
            s += max((ll)0,cost[i]-mid/food[i]);
        }
        if(s<=k) r = mid;
        else l = mid;
    }
    cout << r << endl;

    return 0;
}

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

int main(){
    int k, x;
    cin >> k >> x;
    
    int minimam, maxmam;
    minimam = max(-1000000, x - k + 1);
    maxmam  = min(1000000, x + k - 1);
    for(int i = minimam; i <= maxmam; i++){
        cout << i << " ";
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        int count = n;
        for (int i = 0 ; i < n ; i++) {
            boolean match = true;
            for (int j = 0 ; j < n - i ; j++) {
                if (s[j + i] != t[j]) {
                    match = false;
                }
            }
            if (match) {
                count = i;
                break;
            }
        }
        System.out.println(n + count);
    }

}

Measured memory_bytes: 23124
#include<stdio.h>

int main(){
	int H=0,W=0;
	while(true){
		//たて→H よこ→W
		scanf("%d",&H);
		scanf("%d",&W);
		if(H==0 && W==0){
			break;
		}
		for(int i=0; i<H; i++){
			if(i==0 || i==H-1){
				for(int j=0; j<W; j++){
					printf("#");
				}
			}else{
				for(int j=0; j<W; j++){
					if(j==0 || j==W-1){
						printf("#");
					}else{
						printf(".");
					}
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 2588
n,*l=map(int,open(0).read().split())
a,c=1000,0
for i in range(n-1):
  s,t=l[i:i+2]
  if s>t: a+=c*s; c=0
  if s<t: c+=a//s; a-=a//s*s
print(a+c*t)

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

using namespace std;

const int MOD = 1E9 + 7;
const int MAXN = 1000;
bool isWall[MAXN + 1][MAXN + 1];
int dp[MAXN + 1][MAXN + 1];

void add(int& a, int b)
{
    a += b;
    if (a >= MOD)
        a -= MOD;
}

int main()
{
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < w; j++)
            isWall[i][j] = s[j] == '#';
    }
    dp[h - 1][w - 1] = 1;
    for (int i = h - 1; i >= 0; i--)
    {
        for (int j = w - 1; j >= 0; j--)
        {
            if (!isWall[i][j])
            {
                if (!isWall[i][j + 1])
                    add(dp[i][j], dp[i][j + 1]);
                if (!isWall[i + 1][j])
                    add(dp[i][j], dp[i + 1][j]);
            }
        }
    }
    cout << dp[0][0] << endl;
    return 0;
}


Measured memory_bytes: 5120
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
long long a,b,c;
int main(void)
{
	scanf("%lld%lld%lld",&a,&b,&c);
	if(a+b>c)
	{
		printf("No\n");
		return 0;
	}
	long long tmp=(c-a-b)*(c-a-b);
	if(4*a*b<tmp)
		printf("Yes\n");
	else
		printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int k,sum=0; 
  string s; cin>>s;
  k=s.size();
  for(int i=0;i<k;i++){
    if(s[i]=='x') sum++;
    else continue;
  }
  if(sum>=8) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}  

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

using namespace std;

#define EPS 1e-10
#define equal(a,b) (fabs(a-b) < EPS)
#define not_equal(a,b) (!equal(a,b))
#define lt(a,b) (a-b < -EPS)

struct Point{
  double x,y;

  Point(){}
  Point(double x,double y) : x(x),y(y) {}

  Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
  Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
  Point operator * (const double &k)const{ return Point(x*k,y*k); }
};

double dot(const Point &a,const Point &b){ return a.x*b.x+a.y*b.y; }
double cross(const Point &a,const Point &b){ return a.x*b.y - b.x*a.y; }
double norm(const Point &p){ return dot(p,p); }
double abs(const Point &p){ return sqrt(norm(p)); }

istream &operator >> (istream &is,Point &p){ 
  return is >> p.x >> p.y;
}

#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
typedef Point Vector;

int ccw(Point p0,Point p1,Point p2){
  Vector a = p1 - p0;
  Vector b = p2 - p0;
  if(cross(a,b) > EPS){ return COUNTER_CLOCKWISE; }
  if(cross(a,b) < -EPS){ return CLOCKWISE; }
  if(dot(a,b) < -EPS){ return ONLINE_BACK; }
  if(norm(a) < norm(b)){ return ONLINE_FRONT; }
  return ON_SEGMENT;
}

struct Segment{
  Point s,t;
  Segment(){}
  Segment(Point s,Point t) : s(s),t(t) {}
};

typedef Segment Line;
typedef vector<Point> Polygon;

#define prev(G,i) (G[(i-1+G.size())%G.size()])
#define curr(G,i) (G[i%G.size()])
#define next(G,i) (G[(i+1)%G.size()])

Point crosspointLL(const Line &a,const Line &b){
  Vector va = a.t-a.s, vb = b.t-b.s;
  double d = cross(vb,va);
  if(abs(d) < EPS){ return b.s; }
  return a.s+va*cross(vb,b.t-a.s)*(1.0/d);
}

double getArea(const Polygon &p){
  int N = p.size();
  double res = 0;
  for(int i = 1 ; i < N+1 ; i++){
    res += (p[i%N].x-p[i-1].x)*(p[i%N].y+p[i-1].y);
  }
  res /= 2.0;
  return abs(res);
}

Polygon convex_cut(const Polygon &pg,const Line &l){
  Polygon res;
  for(int i = 0 ; i < (int)pg.size() ; i++){
    Point cp = curr(pg,i), np = next(pg,i);
    if(ccw(l.s,l.t,cp) != -1){ res.push_back(cp); }
    if(ccw(l.s,l.t,cp)*ccw(l.s,l.t,np) < 0){
      res.push_back(crosspointLL(Line(cp,np),l));
    }
  }
  return res;
}

int main(){
  int N,Q;
  cin >> N;
  Polygon p(N);
  for(int i = 0 ; i < N ; i++){
    cin >> p[i];
  }
  Line l;
  cin >> Q;
  for(int i = 0 ; i < Q ; i++){
    cin >> l.s >> l.t;
    Polygon res = convex_cut(p,l);
    printf("%.10f\n",getArea(res));
  } 
  return 0;
}

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

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

    string s, t;
    cin >> s;
    
    t = "CODEFESTIVAL2016";
    int cnt = 0;
    REP(i, 16){
        if(s[i] == t[i]);
        else cnt++;
    }
    cout << cnt << endl;
    
    return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
const int INF = 1001001001;
const ll mod = 1e9+7;



int main() {
  int n,m;
  cin>>n>>m;
  vector<vector<P>> v(n);
  vector<P> a(m);

  rep(i,m){
    int p1,y1;
    cin>>p1>>y1;
    p1--;
    v[p1].push_back(make_pair(y1,i));
  }
  rep(i,n){
    if (!v[i].empty()){
    sort(v[i].begin(),v[i].end());
    rep(j,v[i].size()){
      int ken=i+1;
      int yn=j+1;
      int ai=v[i][j].second;
      a[ai]=make_pair(ken,yn);
    }
  }
}
rep(i,m){
  std::cout << std::setfill('0') << std::right << std::setw(6) << a[i].first;
  std::cout << std::setfill('0') << std::right << std::setw(6) << a[i].second;
  cout<<endl;


}


}


Measured memory_bytes: 8576
N = int(input())
h = [int(i) for i in input().split()]
dp = [0, abs(h[0]-h[1])]
for i in range(2,N):
  c1 = dp[i-1] + abs(h[i]-h[i-1])
  c2 = dp[i-2] + abs(h[i]-h[i-2])
  dp.append(min(c1,c2))
print(dp[N-1])

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

const ll INF = 1001001001;
const ll mod = 1000000007;

int main(){
    int n; cin >> n;
    cout << n / 500 * 1000 + (n % 500) / 5 * 5 << endl;
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  int key;
  Node *r, *l, *p;
};

Node *root, *NIL;

Node *treeMinimum(Node *x){
  while(x->l != NIL) x = x->l;
  return x;
}

Node * find(Node *u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->l;
    else u = u->r;
  }
  return u;
}

Node *treeSuccessor(Node *x){
  if(x->r != NIL) return treeMinimum(x->r);
  Node *y = x->p;
  while(y != NIL && x == y->r){
    x = y;
    y = y->p;
  }
  return y;
}

void treeDelete(Node *z){
  Node *y, *x;

  if(z->l == NIL || z->r == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->l != NIL){
    x = y->l;
  }
  else{
    x = y->r;
  }

  if(x != NIL){
    x->p = y->p;
  }

  if(y->p == NIL){
    root = x;
  }
  else{
    if(y == y->p->l){
      y->p->l = x;
    }
    else{
      y->p->r = x;
    }
  }

if(y != z){
  z->key = y->key;
 }
free(y);
}

void insert(int k){
  Node *x = root,*y = NIL, *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->l;
    }
    else{
      x = x->r;
    }
  }

  z->p = y;
  if(y == NIL){
    root = z;
  }
  else{
    if(z->key < y->key){
      y->l = z;
    }
    else{
      y->r = z;
    }
  }
}

void inorder(Node *u){
  if(u == NIL) return;
  inorder(u->l);
  printf(" %d", u->key);
  inorder(u->r);
}

void preorder(Node *u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->l);
  preorder(u->r);
}


int main(){
  int n, i, x;
  string com;

  scanf("%d", &n);

  for(i = 0 ; i < n ; i++){
    cin >> com;
    if(com[0] == 'f'){
      scanf("%d", &x);
      Node *t = find(root, x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(com == "insert"){
      scanf("%d", &x);
      insert(x);
    }
    else if(com == "print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(com == "delete"){
      scanf("%d", &x);
      treeDelete(find(root, x));
    }
  }
  return 0;
}


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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li n,k;

    cin>>n>>k;

    li b[k];

    vi a;

    u_map<li,li> m;

    f(i,0,9)
    {
        m[i]++;
    }

    f(i,0,k-1)
    {
        cin>>b[i];
        m.erase(b[i]);
    }

    f(i,0,9)
    {
        if(m.count(i))
            a.PB(i);
    }

    string s=to_string(n);

    li tp=s.length(),flag=0;

    f(i,0,tp-1)
    {
        if(m.count(s[i]-'0'))
        {
            continue;
        }
        else
        {
            if(flag==0)
            {
                auto temp=lower_bound(a.B,a.E,s[i]-'0');

                if(temp==a.E)
                {
                     // cout<<i<<endl;

                    if(i>0)
                    {
                        s[i-1]=s[i-1]+1;
                        i-=2;
                    }
                    else
                    {
                        if(a[0]==0)
                        {
                            string ch=to_string(a[1]);
                            s = ch+s;
                        }
                        else
                        {
                            string ch=to_string(a[0]);
                            s = ch+s;
                        }
                        s[i+1]='0';
                        tp++;
                        flag=1;
                    }
                }
                else
                {
                    s[i]=(char)(a[temp-a.B]+'0');
                    flag=1;
                }
            }
            else
            {
                s[i]=(char)(a[0]+'0');
            }
        }
    }

    cout<<s;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
#include<string>

using namespace std;

int main(int argc, char ** argv) {
	string str;
	int k = 0;

	cin >> str;
	cin >> k;

	int strSize = str.size();

	for (int i = 0; i < strSize; ++i) {
		char ch = str.at(i); 
		if (ch == 'a') continue;
		int dist = 'z' - ch + 1;
		if (k >= dist) {
			str.at(i) = 'a';
			k -= dist;
		}	
	}

	k = k % 26;
	int dist = 'z' - str.at(strSize - 1);
	str.at(strSize - 1) = (k > dist) ? ('a' + k - dist - 1) : str.at(strSize - 1) + k;


	cout << str << endl;


	//int N = 0;
	//vector <int> *ptrV = new vector<int>();
	//cin >> N;
	//while (N--) {
	//	int tmp = 0;
	//	cin >> tmp;
	//	ptrV->push_back(tmp);
	//}

	//int cnt = 0;
	//int sizeV = ptrV->size();
	//for (int i = 0; i < sizeV; ++i)
	//{
	//	int num = ptrV->at(i);
	//	if (num == -1) continue;
	//	if (ptrV->at(num - 1) == i + 1) {
	//		ptrV->at(num - 1) = -1;
	//		cnt++;
	//	}
	//	ptrV->at(i) = -1;
	//}

	//cout << cnt << endl;
	return 0;
}


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

int main(){
    ll n,m,d;
    cin>>n>>m>>d;
    double ans=0;
    if(d==0)ans=(1.0/n)*(m-1);
    else ans=((2.0*(n-d))/(n*n))*(m-1);
    printf("%.10f\n",ans);
}

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

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

    string s;
    cin >> s;

    if(s.size() == 2) cout << s << endl;
    else{
        for(int i = s.size()-1; i >= 0; --i){
            cout << s[i];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
(defvar N (read))
(defvar M (read))

(defvar ac 0)
(defvar wa 0)

(defvar ac-array (make-array N :initial-element 0))
(defvar wa-array (make-array N :initial-element 0))

(defun calc ()
  (let ((No (1- (read)))
        (Ans (read)))
    (cond ((string= Ans "AC")
           (when (zerop (aref ac-array No))
             (setq wa (+ wa (aref wa-array No)))
             (incf (aref ac-array No))
             (incf ac)))
          ((string= Ans "WA")
           (when (zerop (aref ac-array No))
             (incf (aref wa-array No)))))
    (decf M)
    (if (= M 0)
        (format t "~D ~D~%" ac wa)
        (calc))))

(if (= M 0)
    (format t "0 0~%")
    (calc))


Measured memory_bytes: 59752
// In the Name of God

#include <bits/stdc++.h>

using namespace std;

#define	ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(v) v.begin(), v.end()
#define bpc(v) __builtin_popcountll(v)
#define itr iterator
#define rep(i, a, b) for (ll i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define ub upper_bound
#define lb lower_bound

const int N = 2e5 + 5;
const int mod = 1e8 + 7;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const int pw = 257;

ll n, m;
string s, t;
bool ok = 1;

ll gcd(ll a, ll b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

int main() {
	#ifdef Madi
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
	#endif
	                                            	
	ios_base :: sync_with_stdio(false); cin.tie(NULL);

    cin >> n >> m;
    cin >> s >> t;

    ll lcm = n / gcd(n, m) * m;
    rep(i, 0, min(n / (lcm / m), m / (lcm / n)) - 1)
    	if (s[i * lcm / m] != t[i * lcm / n])
    		ok = 0;   

    if (ok)
    	cout << lcm;
    else
    	cout << -1;
	#ifdef Madi
    cerr << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
	return 0;
}

Measured memory_bytes: 640
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const ll INF=1e+18+1;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll N,K;
    cin>>N>>K;
    vector<ll> A(N);
    REP(i,N){
        cin>>A[i];
    }
    sort(ALL(A));
    ll l=-INF;
    ll r=INF;
    ll mid,mid2,l2,r2;
    while(r-l>1){
        ll cnt=0;
        mid=(l+r)/2;
        REP(i,N){
            l2=-1;
            r2=N;
            if(A[i]>0){    
                while(r2-l2>1){
                    mid2=(l2+r2)/2;
                    if(A[i]*A[mid2]>mid){
                        r2=mid2;
                    }else{
                        l2=mid2;
                    }
                }
                cnt+=r2;
            }else if(A[i]<0){
                while(r2-l2>1){
                    mid2=(l2+r2)/2;
                    if(A[i]*A[mid2]<=mid){
                        r2=mid2;
                    }else{
                        l2=mid2;
                    }
                }
                cnt+=(N-r2);
            }
            else if(mid>=0) cnt+=N;
        
            if(A[i]*A[i]<=mid) cnt--;
        }
        cnt/=2;
        if(cnt>=K) r=mid;
        else l=mid;
    }


    
    cout<<r<<endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

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

        while(true) {
            String x = sc.next();
            if (x.equals("0")) break;
            
            int sum = 0;
            for (int i = 0; i < x.length(); i++) {
                sum += (x.charAt(i) -'0');
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 26144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N,A,B;
  cin >> N>>A>>B;
  long C=B-A;
  long L=B-1;
  long R=N-A;
  long a=A-1;
  long b=N-B;
  long M=min(L,R);
  long c=min(a,b);
  long D=C/2+c+1;
  long d=D;
  if(C%2==0){
    cout<<C/2<<endl;
  }
  else if(N%2==0){
    cout<<min(M,D)<<endl;
  }
  else{
    cout<<min(M,d)<<endl;
  }
}

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

int main() {
    /*変数定義，入力*/
    string a,b;
    cin >> a;
    cin >> b;
    
    //int A, B;cin >> A >> B;
    //vector<int> a(N);  rep(i, N) cin >> a[i];
    
    /*演算*/
    
    /*出力*/
    cout << b << a << endl;

    /*終了*/
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
string s;
char str[15];
set<string> st;
int main()
{
	scanf("%d",&n);
	while (n--)
	{
		scanf("%s",&str);
		s=str;
		st.insert(s);
	}
	printf("%d",(int)st.size());
	return 0;
}

Measured memory_bytes: 19332
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

bool cmp(pair<long long, long long>& x, pair<long long, long long>& y){
	return x.first > y.first;
}

int main(void)
{
	long long n, k, ans=0;
	int ki=-1;
	cin >> n >> k;
	vector<long long> a(n);
	int d[n][40];
	vector<pair<long long, long long>> m;
	rep(i, n){
		long long _a;
		cin >> a[i];
		_a = a[i];
		rep(j, 40){
			d[i][j] = _a % 2;
			_a /= 2;
		}
	}

	rep(i, 40){
		long long cnt0=0;
		rep(j, n){
			if (d[j][i] == 0){
				cnt0++;
			}
		}
		if (2*cnt0 <= n){
			ans += (n-cnt0) << i;
		}else{
			ans += (n-cnt0) << i;
			m.push_back(make_pair((2*cnt0-n) << i, (long long)1 << i));
		}
	}
	sort(m.begin(), m.end(), cmp);
	rep(i, m.size()){
		if (k >= m[i].second){
			ans += m[i].first;
			k -= m[i].second;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
	int a,b,n;
	while(cin>>a){
		cin>>b>>n;
		int ans=0;
		int alt=a%b*10;
		for(int i=0;i<n;i++){
			ans+=alt/b;
			alt=alt%b*10;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
a, b, n = map(int, input().split())
alis = [x for x in range(1, a + 1) if a % x == 0]
blis = [x for x in range(1, b + 1) if b % x == 0]
lis = list(set(alis) & set(blis))
print(sorted(lis,reverse=True)[n - 1])

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


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

struct edge {int to; ll cost; };

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

ll GCD(ll a, ll b){
  if(b==0) return a;
  else return GCD(b, a%b);
}

ll LCM(ll a, ll b){
  if(a<b) swap(a,b);
  return a/GCD(a,b)*b;
}
 
int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int i = 0;
  while(a>=b){
    b *= 2;
    i++;
  }
  while(b>=c){
    c *= 2;
    i++;
  }
  string ans;
  if(i<=k) ans = "Yes";
  else ans = "No";
  cout << ans << endl;
  return 0;
}


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

int main() {
  ll N;
  cin >> N;
  ll upper = sqrt(N);
  ll res;
  for (ll i = upper; i > 0; i--) {
    if (N % i == 0) {
      res = i + N/i;
      break;
    }
  }
  cout << res - 2;
}


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	long long a,b,ans=0LL;
	multiset<long long> memo;
	for (int i = 0; i < n; ++i)
	{
		cin>>a>>b;
		ans-=b;
		memo.insert(a+b);
	}
	auto itr=memo.end();
	--itr;
	for (int i = 0; i < (n+1)/2; ++i)
	{
		ans+=*itr;
		--itr;--itr;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4992
n = gets.chomp.to_i
l_arr = gets.chomp.split(" ").map(&:to_i)

count = 0
(0..n-3).each do |i|
  (i+1..n-2).each do |j|
    (j+1..n-1).each do |k|
      l1 = l_arr[i]
      l2 = l_arr[j]
      l3 = l_arr[k]
      count += 1 if l1 != l2 && l2 != l3 && l3 != l1 && l1 < l2 + l3 && l2 < l3 + l1 && l3 < l1 + l2
    end
  end
end

puts count

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

int main(void){
    int N, K;
    long int sum = 0;
    long int mod = 1000000007;
    
    cin >> N >> K;
    
    long int max = 0;
    long int min = 0;
    for(int i = 0; i < K; i++){
        min += i;
        max += (N-i);
    }
    sum += (max - min + 1);
    
    for(int i = K; i < N+1; i++){
        min += i;
        max += (N-i);
        sum += (max - min + 1);
    }
    
    cout << sum%mod << endl;
    
    return 0;
}


Measured memory_bytes: 3636
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void pV(vector<ll> A){
    cout << "[vector]";
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

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

    // input
    ll N;
    cin >> N;

    ll SN = 0;
    ll n = N;
    while(n!=0){
        SN += n % 10;
        n /= 10;
    }

    if(N % SN == 0){
        p("Yes");
    }else{
        p("No");
    }
    
    return 0;
}

Measured memory_bytes: 256
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()

if N % 10 == 3:
    print('bon')
elif N % 10 == 0 or N % 10 == 1 or N % 10 == 6 or N % 10 == 8:
    print("pon")
else:
    print("hon")

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

const int N = 3010;
int moder;

int powermod(int a, int exp, int moder){
	int ret = 1;
	for ( ; exp > 0; exp >>= 1){
		if (exp & 1){
			ret = 1ll * ret * a % moder;
		}
		a = 1ll * a * a % moder;
	}
	return ret;
}

int s[N][N];
int comb[N][N];

int main(){
	int n;
	scanf("%d%d", &n, &moder);
	for (int i = 0; i < N; ++ i){
		comb[i][0] = 1;
		for (int j = 1; j <= i; ++ j){
			comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % moder;
		}
	}
	for (int i = 0; i < N; ++ i){
		s[i][0] = 1;
		for (int j = 1; j <= i; ++ j){
			s[i][j] = (1ll * s[i - 1][j] * (j + 1) + s[i - 1][j - 1]) % moder;
		}
	}
	int ans = powermod(2, powermod(2, n, moder - 1), moder);
	for (int i = 1; i <= n; ++ i){
		int sum = 0;
		for (int j = 0; j <= i; ++ j){
			sum = (sum + 1ll * s[i][j] * powermod(2, (n - i) * j, moder) % moder) % moder;
		}
		sum = 1ll * sum * powermod(2, powermod(2, n - i, moder - 1), moder) % moder;
		ans = (ans + (i & 1 ? -1ll : 1ll) * comb[n][i] * sum) % moder;
		ans += ans < 0 ? moder : 0;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 69888
import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const A = readInt();
      const B = readInt();
      writeln(min(A, B), " ", max(A + B - N, 0));
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
   int x, y, tmp;
   
   scanf("%d %d", &x, &y);
   
   if(x<y){
       tmp=y;
       y=x;
       x=tmp;
   }

    while(1){
        tmp=y;
        y=x%y;
        x=tmp;
        if(y==0) break;
    }
       
    printf("%d\n", x);
}



Measured memory_bytes: 2048
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, T;
    cin >> n >> T;
    int ans = 10000;
    REP(i, n) {
        int c, t;
        cin >> c >> t;
        if(t <= T) ans = min(ans, c);
    }
    if(ans == 10000) {
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	
	
	public void solve(){
		Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
		 System.out.println(x*x*x);
		 
		
	}
	
	public static void main(String[] args){
		Main obj = new Main();
		obj.solve();
	}
}	

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

using namespace std;

/**
ワーシャルフロイド
計算量O(n^3)
全体全の最短距離を求める
**/
#define NODE 301
long long dist[NODE][NODE];
void WF(int num)
{
	for(int k = 0; k < num; k++)
	{
		for(int i = 0; i < num; i++)
		{
			for(int j = 0; j < num; j++)
			{
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
}

int main()
{
	int H, W;
	cin >> H >> W;
	for(int i = 0; i < 10; i++)
	{
		for(int j = 0; j < 10; j++)
		{
			long long foo;
			cin >> foo;
			dist[i][j] = foo;
		}
	}
	WF(10);
	int sum = 0;
	for(int i = 0; i < H; i++)
	{
		for(int j = 0; j < W; j++)
		{
			int foo;
			cin >> foo;
			if(foo == 1 || foo == -1)
			{
				continue;
			}
			sum += dist[foo][1];
		}
	}
	cout << sum << endl;
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  ll ans = 0;
  REP(i, N) {
    int a = nextInt();
    while (a % 2 == 0) { ans++; a /= 2; }
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<int> A(N);
  bool zero = false;
  ll S = 0;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    if(!A[i]) zero = true;
    S += A[i];
  }
  ll ans=0;
  if(!zero) ans = S/2;
  else {
    S = 0;
    for(int i = 0; i < N; i++) {
      if(A[i] != 0) S += A[i];
      else {
        ans += S/2;
        S = 0;
      }
    }
    ans += S/2;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640