akhauriyash/Code-Regression huggingface dataset:
/*
    ##############################
    #  Author: Pratyush Gaurav   #
    #  College: NIT ROURKELA     #
    ##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define scan(n) scanf("%lld",&n)
#define scan2(a,b) scanf("%lld %lld",&a,&b)
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define print(n) printf("%lld\n",n)
#define scanS(s) scanf("%s",&s)
#define printS(s) printf("%s",s)

#define ff first
#define ss second
#define rep(i,a) for(i = 0 ; i < a ; i++)
#define repr(i,a) for(i = a ; i >= 0 ; i--)
#define REP(i,a,b) for(i = a ; i <= b ; i++)
#define REPR(i,a,b) for(i = a ; i >= b ; i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define pb push_back
#define popb pop_back

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

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

void solve() {
    lli ans = 0;
    lli k;
    cin >> k;
    lli i, j;
    REP(i, 1, k) {
        REP(j, 1, k) {
            if( i & 1 and !(j & 1))
                ans++;
        }
    }
    cout << ans << endl;
}

int main()
{
    opt;
    lli t = 1;
    //cin >> t;

    while(t--)
        solve();
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	
	string s;
	cin >> s;
	
	if (s == "ABC") {
		cout << "ARC" << endl;
	} else {
		cout << "ABC" << endl;
	}
	
    return 0;
}


Measured memory_bytes: 3616
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        Integer[] a = new Integer[m];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int sum = Arrays.stream(a).mapToInt(i -> i).sum();
        int remain = n - sum;

        boolean judge = 0 <= remain;
        int result = judge ? remain : -1;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 42292
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
 
const int mxN=2e5;
int n, a[mxN];
ll c[mxN], ans;
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	cin >> n;
	for(int i=0; i<n; ++i) {
		cin >> a[i], --a[i];
		++c[a[i]];
	}
	for(int i=0; i<n; ++i)
		ans+=c[i]*(c[i]-1)/2;
	for(int i=0; i<n; ++i) {
		ans-=c[a[i]]*(c[a[i]]-1)/2;
		--c[a[i]]*(c[a[i]]-1)/2;
		ans+=c[a[i]]*(c[a[i]]-1)/2;
		cout << ans << "\n";
		ans-=c[a[i]]*(c[a[i]]-1)/2;
		++c[a[i]]*(c[a[i]]-1)/2;
		ans+=c[a[i]]*(c[a[i]]-1)/2;
	}
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  string p="";
  string q="";
  rep(i, n){
    char x;
    cin >> x;
    p.pb(x);
  }
  rep(i, n){
    char x;
    cin >> x;
    q.pb(x);
  }
  vi v;
  rep(i,n){
    v.pb(i + 1);
  }
  ll pc = 0;
  ll qc = 0;
  ll c = 0;
  do{
    string tmp = "";
    rep(i,n){
      tmp += to_string(v[i]);
    }
    if(tmp==p){
      pc = c;
    }
    if(tmp==q){
      qc = c;
    }
    c++;
  } while (next_permutation(all(v)));
  cout << abs(pc - qc) << endl;
}

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


int main()
{
   lli n,a,b,d;
   cin>>n>>a>>b;
   if(n>=a+b)
   {
   lli t=n/(a+b);
   t*=a;
   d=n%(a+b);
   if(d<a)
   cout<<t+d;
   else cout<<t+a;
   }
   else
   {
       if(a<n) cout<<a;
       else cout<<n;
   }

}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> w(n), e(n);
    string str;
    cin >> str;
    for (int i = 0; i < n; i++) {
        e[i] = i ? e[i - 1] : 0;
        w[i] = i ? w[i - 1] : 0;
        if (str[i] == 'E') {
            e[i]++;
        } else {
            w[i]++;
        }
    }
    int ans = INT_MAX;
    for (int i = 0; i < n; i++) {
        ans = min(ans, (i ? w[i - 1] : 0) + (e[n - 1] - e[i]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k;
  cin >> a >> b >> k;
  bool tak = true;
  for(int i=0; i<k; i++){
    if(tak){
      if(a%2 == 1){
        a--;
      }
      b += a/2;
      a /= 2;
      tak = false;
    }else{
      if(b%2 == 1){
        b--;
      }
      a += b/2;
      b /= 2;
      tak = true;
    }
  }
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
import Data.List

q = 10^9+7

main = do
 [n,m] <- map read . words <$> getLine
 xs <- map read . words <$> getLine
 ys <- map read . words <$> getLine
 print (ttt n m xs ys)

ttt :: Integer -> Integer -> [Integer] -> [Integer] -> Integer
ttt n m xs ys = mod (adx * ady) q
 where
  adx = foldl' (\acc (k,dx) -> acc + ((k-1)*dx - (n-k)*dx)) 0 idxs
  ady = foldl' (\acc (k,dy) -> acc + ((k-1)*dy - (m-k)*dy)) 0 idys
  idxs = zip [1..n] xs
  idys = zip [1..m] ys


Measured memory_bytes: 80380
#include <iostream>

using namespace std;

int main()
{
    int n, h;
    int prevH = 0, maxH = 0;
    cin >> n;

    for(int i = 0; i < n; ++i) {
        cin >> h;
        if(prevH <= h) {
            maxH = max(maxH, h);
        }
        else {
            if(maxH - 1 > h) {
                cout << "No" << '\n';
                return 0;
            }
        }
        prevH = h;
    }
    cout << "Yes" << '\n';
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static Scanner scan;

    private static void start() {
        scan = new Scanner(java.lang.System.in);

    }

    private static void finish() {
    }


    public static void main(String[] args) {
        start();

        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();

        int total = Math.min(a, b) + Math.min(c, d);
        System.out.println(total);

        finish();
    }
}


Measured memory_bytes: 24020
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


bool yes = true;
vector<ll> dist(100010,INF);
matP G(100010,vp(0));
void dfs(ll p, ll to){
    if(p == -1) dist[to] = 0;
    for(P p : G[to]){
        if(dist[p.fi] == INF){
            dist[p.fi] = dist[to] + p.se;
            dfs(to, p.fi);
        }else if(dist[p.fi] != dist[to] + p.se){
            yes = false;
        }
    }
}

int main(){
    cin>>N>>M;
    for(int i = 0; i < M; i++) {
        // sからtへの辺を張る
        int s,t, d;
        scanf("%d %d %d", &s, &t, &d);
        --s; --t;
        G[s].emplace_back(t,d);
        G[t].emplace_back(s,-d);
    }
    rep(i,N) if(dist[i] == INF) dfs(-1, i);
    cout<<(yes ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 16512
import java.util.*;
import java.math.*;
public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0;
        ans += (n/500)*1000;
        n%=500;
        ans+=(n/5)*5;
        System.out.println(ans);

    }       
}






Measured memory_bytes: 23124
from collections import deque

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

vertex = [[] for i in range(N)]
for side in sides:
    vertex[side[0]-1].append(side[1])
    vertex[side[1]-1].append(side[0])

# print(vertex)

ans = 0

for side in sides:
    vertex[side[0]-1].remove(side[1])
    vertex[side[1]-1].remove(side[0])
    # print(vertex)
    for i in range(1,N+1):
        a = 1
        check = deque([i])
        fromcheck = {j:0 for j in range(1,N+1)}
        visit = {i}
        while len(check) != 0:
            v = check.popleft()
            for ver in vertex[v-1]:
                if fromcheck[ver] == 0:
                    fromcheck[ver] = 1
                    check.append(ver)
                    visit.add(ver)
            fromcheck[v] = 1
        if visit != {i for i in range(1,N+1)}:
            a = 0
            break
    if a == 0:
        ans += 1
    vertex[side[0]-1].append(side[1])
    vertex[side[1]-1].append(side[0])

print(ans)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int k;
	int total=0;

	cin>>k;

	for(int i=1; i<k+1; ++i){
		total+=i/2;

	}

	cout<<total<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main() {
  ll n,w;
  cin >> n >> w;
  v(ll) weight(n+1),value(n+1);
  vv(ll) dp(n+1,v(ll)(w+1));
  for (int i = 0; i < n; ++i) cin >> weight[i] >> value[i];
  rep(i,n){
    for (int sum_w = 0; sum_w <= w; ++sum_w) {

      // i 番目の品物を選ぶ場合
      if (sum_w - weight[i] >= 0) {
        maxs(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
      }

      // i 番目の品物を選ばない場合
      maxs(dp[i+1][sum_w], dp[i][sum_w]);
    }
  }
  cout << dp[n][w] << endl;
}    


Measured memory_bytes: 83248
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;
int main()
{
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	long long ans=a*c;
	if(a*d>ans) ans=a*d;
	if(b*c>ans) ans=b*c;
	if(b*d>ans) ans=b*d;
	cout<<ans<<endl;
}


Measured memory_bytes: 3632
# B - Toll Gates

# N M X
N, M, X = map(int, input().split())
my_list = list(map(int, input().split(maxsplit=M)))
count_start = 0
count_goal = 0

# 0へ行くパターン
for i in range(1, X):
    if i in my_list:
        count_start += 1

for i in range(X, N):
    if i in my_list:
        count_goal += 1

if count_start >= count_goal:
    answer = count_goal
else:
    answer = count_start

print(answer)


Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  vector<set<int>> E(n);
  for (int i = 0; i < m; i++){
    int s, t;
    cin >> s >> t;
    E[s].insert(t);
    E[t].insert(s);
  }
  vector<int> G(n, -1);
  for (int i = 0; i < n; i++){
    if (G[i] == -1){
      queue<int> Q;
      Q.push(i);
      G[i] = i;
      while (!Q.empty()){
        int v = Q.front();
        Q.pop();
        for (int w : E[v]){
          if (G[w] == -1){
            G[w] = G[v];
            Q.push(w);
          }
        }
      }
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++){
    int s, t;
    cin >> s >> t;
    if (G[s] == G[t]){
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}


Measured memory_bytes: 17276
using System;
class AOJ{
public static void Main(){
String[] st=Console.ReadLine().Split(' ');
int a=int.Parse(st[0]);
int b=int.Parse(st[1]);
int c=int.Parse(st[2]);
int sum=0;
for(int i=a;i<=b;i++){
if(c%i==0)
sum++;
}
Console.WriteLine(sum);

}
}

Measured memory_bytes: 9196
#A
N=input()

if N[-1]=="3":
    print("bon")
elif N[-1]=="0":
    print("pon")
elif N[-1]=="1":
    print("pon")
elif N[-1]=="6":
    print("pon")
elif N[-1]=="8":
    print("pon")
else:
    print("hon")

Measured memory_bytes: 61624
import math
import sys
def update(index,n):
    targ[index] = n
    index = (index - 1) // 2
    while True:
        targ[index] = min(targ[index * 2 + 1],targ[index * 2 + 2])
        if index <= 0:
            break
        index = (index - 1) // 2

def find(i,e,node,inode,enode):
    #print(i,e,node,inode,enode)
    if inode > e or enode < i:
        return float("inf")
    elif (i <= inode and enode <= e) or inode==enode:
        return targ[node]

    else:
        irange = find(i,e,2*node + 1,inode,(inode+enode)// 2 )
        erange = find(i,e,2*node + 2,(inode+enode)//2 + 1,enode)
        return min(irange,erange)

f = sys.stdin
num,query = (int(n) for n in f.readline().split(' '))
initial = 2147483647
ln = 2 ** math.ceil(math.log2(num)) - 1
if num == 1:
    tail = 2
else:
    tail = 2 ** math.ceil(math.log2(num)) - num
global targ
targ = [initial] * (ln + num + tail)

for q in range(query):
    #print(targ)
    temp = [int(n) for n in f.readline().split(' ') ]
    if temp[0] == 0:
        update(temp[1] + ln,temp[2])
    else:
        print(find(temp[1],temp[2],0,0,ln))

Measured memory_bytes: 11808
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    
    if(s=="SUN"){
        cout << 7 << endl;
    }else if(s=="MON"){
        cout << 6 << endl;
    }else if(s=="TUE"){
        cout << 5 << endl;
    }else if(s=="WED"){
        cout << 4 << endl;
    }else if(s=="THU"){
        cout << 3 << endl;
    }else if(s=="FRI"){
        cout << 2 << endl;
    }else{
        cout << 1 << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,m,i;
    cin>>n>>m;
    long long int a[m],sum=0;
    for(i=0;i<m;i++)
    {
        cin>>a[i];
    	sum+=a[i];
      }
      if(sum>n)
      cout<<"-1";
      else
      cout<<n-sum;
      }


Measured memory_bytes: 3708
from collections import deque

H, W = map(int, input().split())
S = [0] * H
shortest_path = [[-1] * W for i in range(H)]
sharp_count = 0
for i in range(H):
    S[i] = input()
    sharp_count += S[i].count("#")

que_list = deque()
que_list.append((0, 0))
shortest_path[0][0] = 0
while que_list:
    q = que_list.popleft()
    if H > q[0]-1 >= 0 and W > q[1] >= 0:
        if S[q[0]-1][q[1]] != "#" and shortest_path[q[0]-1][q[1]] == -1:
            que_list.append((q[0]-1,q[1]))
            shortest_path[q[0]-1][q[1]] = shortest_path[q[0]][q[1]]+1
    if H > q[0] >= 0 and W > q[1]+1 >= 0:
        if S[q[0]][q[1]+1] != "#" and shortest_path[q[0]][q[1]+1] == -1:
            que_list.append((q[0],q[1]+1))
            shortest_path[q[0]][q[1]+1] = shortest_path[q[0]][q[1]]+1
    if H > q[0] >= 0 and W > q[1]-1 >= 0:
        if S[q[0]][q[1]-1] != "#" and shortest_path[q[0]][q[1]-1] == -1:
            que_list.append((q[0],q[1]-1))
            shortest_path[q[0]][q[1]-1] = shortest_path[q[0]][q[1]]+1
    if H > q[0]+1 >= 0 and W > q[1] >= 0:
        if S[q[0]+1][q[1]] != "#" and shortest_path[q[0]+1][q[1]] == -1:
            que_list.append((q[0]+1,q[1]))
            shortest_path[q[0]+1][q[1]] = shortest_path[q[0]][q[1]]+1

if shortest_path[H-1][W-1] == -1:
    print(-1)
else:
    print(H*W - (shortest_path[H-1][W-1]+1+sharp_count))

Measured memory_bytes: 39920
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;


int main(){
  int N, M;
  cin >> N >> M;
  if (N > M){
    for (int i = 0; i < N; i++){
      cout << M;
    }
  }
  else {
    for (int i = 0; i < M; i++){
      cout << N;
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long x, i, j, k, n = 100;
	cin >> x;
	for (i = 1; ; i++) {
		n += n / 100;
		if (n >= x) break;
	}
	cout << i << "\n";

	return 0;
}




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

#define F(i, a, b) for(int i=a; i<b; i++)
#define mem(arr, val) memset(arr, val, sizeof(arr))

#define MOD 1000000007
#define INF 1000000001
#define epsilon 1e-15

typedef long long int ll;
typedef unsigned long long int ull;

int main()
{

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int N;
    cin >> N;
    int h[N];
    for(int i=0; i<N; i++){
        cin >> h[i];
    }

    ll dp[N];
    dp[N-1] = 0;
    dp[N-2] = abs(h[N-2] - h[N-1]);
    for(int i=N-3; i>=0; i--){
        dp[i] = min(dp[i+1] + abs(h[i+1]-h[i]), dp[i+2] + abs(h[i+2] - h[i]));
    }


    cout << dp[0] << '\n';

    return 0;
   
}

Measured memory_bytes: 4836
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll INF =  1LL << 60;
const int inf = 1 << 20;
ll n, m, x, y, q, d,z, w = 0, sum, ans = 0;
const int MAX = 510000;
const int MOD = 1000000007;
int main(void) {
	cin >> n; vector<ll> a(100010,0);
	rep(i, n) {
		cin >> z; a[z]++;
		ans += z;
	}cin >> m;
	rep(i, m) {
		cin >> x >> y;
		ans += (y - x) * a[x];
		cout << ans << endl;
		a[y] += a[x]; a[x] = 0;
	}
}

Measured memory_bytes: 4048
def find(x):
  if P[x] < 0:
    return x
  else:
    return find(P[x])

N, M, *X = map(int,open(0).read().split())
P = [-1] * (N + 1)
S = N * (N - 1) // 2
r = [S]

while X:
  b, a = find(X.pop()), find(X.pop())
  if a != b:
    S -= P[a] * P[b]
    if a > b:
      a, b = b, a
    P[a] += P[b]
    P[b] = a
  r.append(S)

r.pop()
print(*reversed(r), sep='\n')

Measured memory_bytes: 25308
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++)
        cin >> h[i];
    int ans = 0;
    for(int i = 0; i < n; i++)
        if(h[i] >= k)
            ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3700
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int maxn=100010,maxm=2000010,inf=0x3f3f3f3f;
int n,m,first[maxn],tot,d[maxn],s,t;
//dijkstra---
struct edge{int from,v,w;}e[maxm];
struct Node{
    int x,d;
    bool operator <(const Node &b)const{
        return d>b.d;
    }
}cyc;
priority_queue<Node>q;
void insert(int u,int v,int w)
{tot++;e[tot].v=v;e[tot].w=w;e[tot].from=first[u];first[u]=tot;}
int dijkstra()
{
    memset(d,0x3f,sizeof(d));
    d[s]=0;q.push((Node){s,d[s]});
    while(!q.empty())
     {
        cyc=q.top();q.pop();
        if(cyc.d!=d[cyc.x])continue;
        int x=cyc.x;
        for(int i=first[x];i;i=e[i].from)
         if(d[e[i].v]>d[x]+e[i].w)
          {
              d[e[i].v]=d[x]+e[i].w;
              q.push((Node){e[i].v,d[e[i].v]});
          }
     }
    return d[t];
}
//dijsktra---
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)for(int j=0;j<=9;j++)insert(i,((i-1)*10+j)%n+1,j);
    for(int j=1;j<=9;j++)insert(0,j+1,j);
    s=0;t=1;
    printf("%d",dijkstra());
    return 0; 
}

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

using namespace std;

int main(){
  int k;
  int a,b;
  cin>>k>>a>>b;
  int t = b/k - a/k;
  a%=k;
  b%=k;
  if(t>0 || a==0 || b==0){
    cout<<"OK"<<endl;
  } else{
    cout<<"NG"<<endl;
  }
}

Measured memory_bytes: 3648
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main { //atcoder
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = in.nextInt();
        int m = in.nextInt();
        out.println(n-m>0?n-m:0);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}



Measured memory_bytes: 32740
#include<bits/stdc++.h>
using namespace std;
const int M=10010;
int n,m;
int tot;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,x;i<=m;++i){
		scanf("%d",&x);
		tot+=x;
	}
	if(tot>n) printf("-1");
	else printf("%d",n-tot);
}

Measured memory_bytes: 3832
#include<stdio.h>
int main()
{
	int c,i,j,k,l,m,n;
	scanf("%d",&c);
	while(c--)
	{
		int a[7][7]={0},r=0,s;
		for(i=1;i<6;++i)for(j=1;j<6;++j)scanf("%d",&a[i][j]);
		for(i=1;i<6;++i)for(j=1;j<6;++j)
		{
			for(k=1;k<=6-i;++k)
			{
				for(l=1;l<=6-j;++l)
				{
					for(m=i;m<i+k;++m)for(n=j;n<j+l;++n)if(!a[m][n])goto N;
					s=k*l;
					r=(r>s?r:s);
N:;
				}
			}
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 0
n, k = map(int, input().split())
s = input()

blk_num = []
blk_sum = []
for i in range(len(s)):
  if i == 0 or s[i-1]!=s[i]:
    if i!= 0:
      blk_sum.append(n)
    blk_num.append(s[i])
    n = 0
  n += 1

blk_sum.append(n)

def cumsum(x):
    y = []
    current = 0
    for i in x:
        y.append(current + i)
        current += i
    return y

blk_csum = cumsum(blk_sum)
# iblkの始点を1が連続する箇所の始点とするときの数を見る

mx = 0
for i, n in enumerate(blk_num):
  if n == '0':
    endi = i + 2*k - 1
    endi = min(len(blk_num)-1, endi)
    if i == 0:
      sm = blk_csum[endi]
    else:
      continue
  else:
    endi = i + 2*k
    endi = min(len(blk_num)-1, endi)
    if i == 0:
      sm = blk_csum[endi]
    else:
      sm = blk_csum[endi] - blk_csum[i-1]
  if sm > mx:
    mx = sm
print(mx)
      





Measured memory_bytes: 8736
s = input()

flag = 0


if s[0] !="A":
  flag = 1

count=0
for i in range(2,len(s)-1):
  if s[i]=="C":
    count +=1 
    
if count !=1:
  flag =1


count =0
s_small = s.lower()
for i in range(len(s)):
  if s_small[i] !=s[i]:
    count += 1

if count !=2:
  flag =1
  
print("AC" if flag ==0 else "WA")

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a ; i <= b; ++ i)
using namespace std ;

int main() {
	int n, a, b ;
	scanf("%d%d%d", &n, &a, &b) ;
	if (a > b) {
		printf("0\n") ;
		return 0 ; 
	}
	if (n == 1) {
		if (a == b) printf("1\n") ;
			else printf("0\n") ;
		return 0 ;
	}
	ll A = (ll) a * (n - 1) + b, B = (ll) b * (n - 1) + a ;
	printf("%lld\n", B - A + 1) ;
	return 0 ; 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
    int n;
    cin >> n;
    int min = 40;
    for (int i = 0; i < n; i++) {
        int a, cnt = 0;
        cin >> a;
        while (a%2 == 0) {
            a /= 2;
            cnt++;
        }
        if (min > cnt) min = cnt;
    }
    cout << min << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  
 	string S, T;		cin >> S >> T;
  	int ans = 0;
  	for(int i = 0 ; i < 3 ; i++)
		if(S[i] == T[i])	ans += 1;
    
  	cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
while True:
    n,w=map(int,raw_input().split())
    if n==w==0:break
    L=[0]*(w+1)
    for i in range(n):
        v=input()
        L[v/w]+=1
    maxh=max(L)
    r=w
    while r>0 and L[r]==0:
        r-=1
    ink=0.01
    for i in range(r+1):
        if r<>0:
            ink+=float(r-i)/r*float(L[i])/maxh
        else:
            ink+=L[i]
    print ink

Measured memory_bytes: 4272
n=int(input())
l=list(map(int,input().split()))
c=0
k=1
f=0
for i in range(n):    
    if l[i]==k:
        f=1
        c+=1
        k+=1   

if not f:
    print(-1)
elif c==n:
    print(0)
else:
    print(n-c)


Measured memory_bytes: 24744
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
long long int __lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
 //__gcd 最大公約数
 //__lcm 最小公倍数

int main() {
  int a;
  cin>>a;
  vector<int> b(a);
  for(int i=0;i<a;i++)
    cin>>b[i];
  sort(b.begin(),b.end());
  int c=0;
  for(int i=0;i<a-1;i++)
    c+=b[i];
  if(b[a-1]<c)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define REP(i, n) for(int i = 0; i < n; i++)
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
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; }

int main(void){
  int n, w;
  cin>>n>>w;
  long long weight[110], value[110];
  long long dp[110][100100]={0};
  REP(i, n){
    cin>>weight[i]>>value[i];
  }
  REP(i, n){
    for(int sum_w=0; sum_w <= w; ++sum_w){
      if(sum_w - weight[i]>=0){
        chmax(dp[i+1][sum_w], dp[i][sum_w -weight[i]] + value[i]);
      }
      chmax(dp[i+1][sum_w], dp[i][sum_w]);
    }
  }
  cout<<dp[n][w]<<endl;  
  return 0;
}

Measured memory_bytes: 86400
while True:
    m, f, v = [int(n) for n in input().split()]

    if m == f == v == -1:
        break
    sum = m + f
    if m == -1 or f == -1:
        print("F")
    elif 80 <= sum:
        print("A")
    elif 65 <= sum < 80:
        print("B")
    elif 50 <= sum < 65:
        print("C")
    elif 30 <= sum < 50:
        if 50 <= v:
            print("C")
        else:
            print("D")
    else:
        print("F")

Measured memory_bytes: 7704
(* --------------Encoder-------------- *)
(* -----function----- *)
(*
let encoder = 0
*)

(* -------test------- *)
(* ----------------------------------- *)

(* --------------Decoder-------------- *)
(* -----function----- *)
(*
let decoder ans = ""
*)

(* -------test------- *)
(* ----------------------------------- *)

(* --------------Processor-------------- *)
(* -----function----- *)
(*
let processor dat = 0
*)

(* -------test------- *)
(* ----------------------------------- *)


(* ----------------main---------------- *)
(*
let () = print_endline (decoder (processor encoder))
*)
(* ------------------------------------ *)
let () = Scanf.scanf "%d %d" (fun a b -> if a * b mod 2 = 0 then
        "Even"
else
        "Odd") |> print_endline


Measured memory_bytes: 384
#include <cstdio>
#include <unordered_map>

int main()
{
    int n;
    scanf("%d", &n);

    std::unordered_map<long long, int> mp;
    long long a, ans = 0, sum = 0;
    ++mp[0];
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &a);
        sum += a;
        ans += mp[sum];
        ++mp[sum];
    }
    printf("%lld\n", ans);
}
/*
累積和が等しい2点間の、連続する部分列の和は０になる。
ある累積和がn個存在するとき、n個の中から2点を選ぶ組み合わせはnC2通り。

累積和１が３回現れる場合。
1回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 0 <- 初回の累積和はカウントされない
    ++mp[sum];  // mp[1] = 1

2回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 1 <- 累積和１が２回出たのでansがカウントされる。2C2=1通り
    ++mp[sum];  // mp[1] = 2 <- 累積和１が２点に存在する

3回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 2 <- 累積和１が３回出たのでansがカウントされる。3C2=3通り
    ++mp[sum];  // mp[1] = 3 <- 累積和１が３点に存在する
*/


Measured memory_bytes: 8520
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  while(1){
    ll a,b;cin>>a>>b;
    if(a==0 && b==0) return 0;
    vector<ll> v(a),w(b);
    rep(i,a) cin>>v[i];
    rep(i,b) cin>>w[i];
    ll s1=Svec(v),s2=Svec(w);
    bool flag=true;
    rep(i,a){
      rep(j,b){
        if(flag){
          if(s1-v[i]+w[j]==s2+v[i]-w[j]){
            cout<<v[i]<<' '<<w[j]<<endl;
            flag=false;
          }
        }
      }
    }
    if(flag){
   	  cout<<-1<<endl;
    }
    
  }
  
}


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

using LL = long long;

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); --(i))
#define SORT(x) sort(ALL((x)))
#define RSORT(x) sort(RALL((x)))
#define SZ(x) (int)(x).size()
#define debug(x) cerr << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e18;

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

  int ans = INF;
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  FOR(i, 0, N) { cin >> A[i]; }

  int dest = 0;
  int clockwise = 0;
  int counterclockwise = 0;

  FOR(i, 0, N) {
    // 時計回り
    if (i == 0) {
      clockwise = A[N - 1] - A[0];
    } else {
      dest = i - 1;
      clockwise = K - (A[i] - A[dest]);
    }

    // 反時計回り
    if (i == N - 1) {
      counterclockwise = A[N - 1] - A[0];
    } else {
      dest = i + 1;
      counterclockwise = K - (A[dest] - A[i]);
    }

    int temp = min(clockwise, counterclockwise);
    ans = min(ans, temp);
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 1024
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


n = int(input())
a = [''.join(sorted(input())) for _ in range(n)]
a.sort()
cnt = 0

# print(a)
cntsub = 1
for i in range(len(a) - 1):
    if a[i] == a[i + 1]:
        cntsub += 1
    elif cntsub > 1:
        # print(cntsub)
        cnt += int(cmb(cntsub, 2))
        cntsub = 1

if cntsub > 1:
    # print(cntsub)
    cnt += int(cmb(cntsub, 2))
print(cnt)


Measured memory_bytes: 11136
N=int(input())
S=list(input())
A=[0]*N
B=[0]*N
E=0
W=0
for i in range(1,N):
  if S[i-1]=="W":
    W+=1
  if S[N-1-i+1]=="E":
    E+=1
  A[i]+=W
  A[N-1-i]+=E
  
  
print(min(A))

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

bool isnum(char c) {
    return '0' <= c && c <= '9';
}

void solve(string s0, string s1) {
    if (s0 == s1) {
        cout << "+" << endl;
        return;
    }
    int pos = 0;
    while (1) {
        if (pos == s0.size() && pos < s1.size()) {
            cout << "+" << endl;
            return;
        }
        if (pos == s1.size() && pos < s0.size()) {
            cout << "-" << endl;
            return;
        }
        if (pos == s1.size() && pos == s0.size()) {
            cout << "+" << endl;
            return;
        }
        if (isnum(s0[pos]) && !isnum(s1[pos])) {
            cout << "+" << endl;
            return;
        }
        if (!isnum(s0[pos]) && isnum(s1[pos])) {
            cout << "-" << endl;
            return;
        }
        if (!isnum(s0[pos]) && !isnum(s1[pos])) {
            if (s0[pos] < s1[pos]) {
                cout << "+" << endl;
                return;
            }
            if (s0[pos] > s1[pos]) {
                cout << "-" << endl;
                return;
            }
            pos++;
            continue;
        }

        int p1 = pos, p0 = pos;
        while (1) {
            p0++;
            if (p0 > s0.size() || !isnum(s0[p0])) break;
        }
        while (1) {
            p1++;
            if (p1 > s1.size() || !isnum(s1[p1])) break;
        }
        if (p0 > p1) {
            cout << "-" << endl;
            return;
        }
        if (p0 < p1) {
            cout << "+" << endl;
            return;
        }
        for (int k = pos; k < p0; k++) {
            if (s0[k] < s1[k]) {
                cout << "+" << endl;
                return;
            }
            if (s0[k] > s1[k]) {
                cout << "-" << endl;
                return;
            }
        }
        pos = p0;
    }
    cout << "+" << endl;
}

int main(int argc, char *argv[]) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < n; i++) {
        string ss;
        cin >> ss;
        solve(s,ss);
    }
    return 0;
}



Measured memory_bytes: 3208
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int n;
long long a[100010];
long long l,r;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lld",a+i);
	if(a[n]!=2LL)
	{
		printf("-1");
		return 0;
	} 
	long long l=r=1LL;
	for(int i=n-1;i>=1;i--)
	{
		long long tl=(l*a[i+1]+a[i]-1)/a[i],tr=((r+1)*a[i+1]-1)/a[i];
		if(tl>tr)
		{
			printf("-1");
			return 0;
		}
		l=tl;r=tr;
	}
	printf("%lld %lld",l*a[1],(r+1)*a[1]-1);
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int t1 = sc.nextInt();
        int t2 = sc.nextInt();
        long a1 = sc.nextLong();
        long a2 = sc.nextLong();
        long b1 = sc.nextLong();
        long b2 = sc.nextLong();


        long d1 = t1 * a1 + t2 * a2;
        long d2 = t1 * b1 + t2 * b2;
        if(d1 == d2) {
            System.out.println("infinity");
            return;
        }
        if(a1 < b1 && a2 < b2 || a1 > b1 && a2 > b2) {
            System.out.println(0);
            return;
        }

        if(d1 < d2) {
            long temp = a1;
            a1 = b1;
            b1 = temp;
            temp = a2;
            a2 = b2;
            b2 = temp;
            temp = d1;
            d1 = d2;
            d2 = temp;
        }
        long d = d1 - d2;
        if(a1 > b1) {
            System.out.println(0);
            return;
        }

        long adv = ((b1-a1) * t1);

        long div = adv / d;
        long rem = adv % d;

        long res = div * 2;
        if( rem > 0) res++;


        System.out.println(res);
    }


}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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




int i,n,a[103];

int main()
{
    FAST();

    //    freopen("input.txt","r",stdin);
    //    freopen("input.txt","w",stdout);


    cin >> n;
    for(i=1; i<n; i++)
    {
        cin >> a[i];
    }
    int ans=a[n-1]+a[1];
    for(i=2; i<n; i++)
    {
        ans+=(min(a[i],a[i-1]));
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;


public class my
{
	
	private static StringBuilder sb = new StringBuilder();
	
	public static void Main()
	{
		string s;
		
		while( null != ( s = Console.ReadLine()) ) {
			var n = Array.ConvertAll(s.Split(' '), long.Parse);
			
			sb.AppendLine( string.Format( "{0} {1}", GCD(n[0], n[1]), LCM(n[0], n[1]) ) );
		}
		
		my.Flush();
	}
	
	private static long LCM (long x, long y)
	{
		return x * y /GCD(x, y);
	}
	
	private static long GCD(long x, long y)
	{
		if(x % y == 0)	return y;
		else	return GCD(y, x%y);
	}
	
	private static int CountChar(string s, char c)
	{
		return s.Length - s.Replace(c.ToString(), "").Length;
	}
	
	private static void Flush()
	{
		Console.Write(sb);
		sb.Length = 0;
	}
	
	private static void AppendLine(int v)
	{
		sb.AppendLine(v.ToString());
	}
	
	private static void AppendLine(long v)
	{
		sb.AppendLine(v.ToString());
	}
	
	private static void AppendLine(string[] v)
	{
		sb.AppendLine(string.Join(" ", v));
	}

	private static void Swap(ref string a, ref string b) 
	{
		string tmp = a;
		a = b;
		b = tmp;
	}
	
	private static void Swap(ref int a, ref int b) 
	{
		int tmp = a;
		a = b;
		b = tmp;
	}
	
	private static int[] GetIntArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
	}
	
	private static void WriteArray(int[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}
	
	private static void WriteArray(long[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}
	
	private static int GetInt()
	{
		return int.Parse(Console.ReadLine());
	}
	
	private static long GetLong()
	{
		return long.Parse(Console.ReadLine());
	}
}

Measured memory_bytes: 9092
import java.util.Scanner;

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

int w = sc.nextInt();
int n = sc.nextInt();
int[] values = new int[w];
for(int i = 0; i < values.length;i++){
    values[i] = i + 1;
}
for( int i =0;i < n;i++){
    String str = sc.next();
    String[] ab = str.split(",");
   int a = Integer.parseInt(ab[0]) - 1;
   int b = Integer.parseInt(ab[1]) - 1;

   int value = values[a];
   values[a] = values[b];
   values[b] = value;

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

}





Measured memory_bytes: 26104
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int DIV = 1000000007; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	int N;
	cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	ll ans = 0;

	for (int i = 0; i < N; i++) {
		while (A[i] % 2 == 0) {
			A[i] /= 2;
			ans++;
		}
	}

	cout << ans;


}	


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

int main() {
    string s;
    cin >> s;
    int N=0,W=0,S=0,E=0;
    for(int i=0;i<s.size();i++){
        if(s.at(i) == 'N') N++;
        if(s.at(i) == 'W') W++;
        if(s.at(i) == 'S') S++;
        if(s.at(i) == 'E') E++;
    }
    
    bool ns,ew;

    if(N==0 && S==0) ns=true;
    else if(N != 0 && S != 0) ns = true;
    else ns = false;
    if(E==0 && W==0) ew=true;
    else if(E != 0 && W != 0) ew = true;
    else ew = false;

    if(ns && ew) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 384