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

typedef long long ll;
typedef long double ld;

int win[100005];
int niz[105];

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n, k;
    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> niz[i];
    for(int i=1; i<=k; i++){
        for(int j=1; j<=n; j++){
            if(niz[j] > i) continue;
            if(!win[i-niz[j]]){
                win[i] = 1;
                break;
            }
        }
    }
    if(win[k]){
        cout << "First\n";
    }
    else cout << "Second\n";
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int h, tmp;
	while (cin >> h, h) {
		vector<vector<int>>v(h, vector<int>());
		rep(i, h) {
			rep(j, 5) {
				cin >> tmp;
				v[i].push_back(tmp);
			}
		}
		bool flag = true;
		int ns = 0;
		while (flag) {
			flag = false;
			//?¶????
			rep(i, h) {
				rep(j, 5) {
					tmp = 0;
					while (true) {
						if (v[i][j] == 0 || (j + tmp + 1) == 5)break;
						if (v[i][j] == v[i][j + tmp + 1])tmp++;
						else break;
					}
					if (tmp >= 2) {
						ns += v[i][j] * (tmp + 1);
						rep(k, tmp + 1)v[i][j + k] = 0;
						flag = true;
					}
				}
			}
			//?????¨???
			bool cont = true;
			while (cont) {
				cont = false;
				for (int i = h - 1; i > 0; i--) {
					rep(j, 5) {
						if (v[i][j] == 0 && v[i - 1][j]) {
							v[i][j] = v[i - 1][j];
							v[i - 1][j] = 0;
							cont = true;
						}
					}
				}
			}
		}
		cout << ns << endl;
	}		
	return 0;
}

Measured memory_bytes: 3092
#include <stdio.h>

int main(void)
{
        int a[3];
        int f = 2;
        int n = 1;
        scanf("%d %d %d", &a[0], &a[1], &a[2]);
        int i;
        for (i = 0; i < 3; i++) {
                if (a[i] == 5) f--;
                if (a[i] == 7) n--;
        }
        if (f == 0 && n == 0)
                printf("YES\n");
        else
                printf("NO\n");
        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int n; cin >>n;
  int w[n],sum=0;
  for(int i=0; i<n; i++){
    cin >>w[i];
    sum+=w[i];
  }
  for(int i=0; i<n-1; i++){
    if(sum-2*w[i]<=0){
      cout <<min(sum,2*w[i]-sum);
      break;
    }
    sum-=2*w[i];
  }
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  solve();
return 0;}

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

using namespace std;

using Int = int;

struct ModInt {
    static constexpr Int mod = 1e9 + 7;
    Int v;

    ModInt(long long _v = 0) : v(set(_v)) {}
    ModInt(const ModInt &r) : v(set(r.v)) {}

    inline static Int set(const auto x) { return x < 0 ? (x % mod) + mod : x % mod; }
    inline void set() { v = set(v); }

    bool operator<(ModInt r) const { return v < r.v; }
    bool operator>(ModInt r) const { return r.v < v; }
    bool operator==(ModInt r) const { return v == r.v; }
    bool operator!= (ModInt r) const { return v != r.v; }

    ModInt operator-() const { return ModInt(v ? mod - v : v); }
    ModInt &operator=(const ModInt &r) { if (this != &r) v = set(r.v); return *this; }
    ModInt &operator+=(ModInt r) { (v += r.v) %= mod; return *this; }
    ModInt &operator-=(ModInt r) { (v -= r.v - mod) %= mod; return *this; }
    // ModInt &operator*=(ModInt r) { v = (__uint128_t(v) * r.v) % mod; return *this; }
    ModInt &operator*=(ModInt r) { v = 1ULL * v * r.v % mod; return *this; }
    ModInt &operator/=(ModInt r) { *this *= r.inv(); return *this; }
    ModInt operator+(ModInt r) const { return ModInt(*this) += r; }
    ModInt operator-(ModInt r) const { return ModInt(*this) -= r; }
    ModInt operator*(ModInt r) const { return ModInt(*this) *= r; }
    ModInt operator/(ModInt r) const { return ModInt(*this) /= r; }

    ModInt inv() const {
        long long a = v, b = mod, u = 1, w = 0;
        while (b) {
            long long t = a / b;
            std::swap(a -= t * b, b);
            std::swap(u -= t * w, w);
        }
        return ModInt(u);
    }

    ModInt pow(Int e) {
        ModInt a = *this, x(1);
        for ( ; 0 < e; e >>= 1) { if (e & 1) x *= a; a *= a; }
        return x;
    }
    inline ModInt pow(ModInt &e) { return pow(e.v); }
};
std::ostream &operator<<(std::ostream &os, const ModInt &r) { return os << r.v; }
std::istream &operator>>(std::istream &is, ModInt &r) { is >> r.v; r.set();return is; }

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

    ModInt n, m;
    cin >> n >> m;
    vector<ModInt> x(n.v), y(m.v);
    for (int i = 0; i < n.v; ++i) cin >> x[i];
    for (int i = 0; i < m.v; ++i) cin >> y[i];

    ModInt area_x, area_y;
    for (ModInt i(1); i < n; i += 1)
        area_x += (x[i.v] - x[i.v - 1]) * i * (n - i);
    for (ModInt i(1); i < m; i += 1)
        area_y += (y[i.v] - y[i.v - 1]) * i * (m - i);

    cout << area_x * area_y << endl;

    return 0;
}


Measured memory_bytes: 1024
#ABC046

s =list(input())
n = len(s)
h = [0,0]#p,g
point = 0#win,lose

for i in range(n):
    if h[0] < h[1]:
        h[0] += 1
        if s[i] == "g":
            point += 1
    
    else:
        h[1] += 1
        if s[i] == "p":
            point -= 1
        
print(point)



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

int main(){
    int n; cin>>n;
    int kind = 0;
    map<ll, ll> list;
    for(int i=0; i<n; i++){
        ll a; cin>>a;
        if(list.count(a)) list[a]+=1;
        else{
            list[a]=1;
            kind ++;
        }
    }
    if(kind>3) cout << "No" << endl;
    else if (kind==3){
        auto iter = list.begin();
        ll a1 = iter->first, a1_n=iter->second; iter++;
        ll a2 = iter->first, a2_n=iter->second; iter++;
        ll a3 = iter->first, a3_n=iter->second;
        if(a1_n==a2_n && a2_n==a3_n){
            if(((a1^a3)^a2)==0) cout << "Yes" << endl; //ここだけがおかしい
            else cout << "No" << endl;
        }
        else cout << "No" << endl;
    }
    else if(kind==2){
        auto iter = list.begin();
        ll a1 = iter->first, a1_n=iter->second; iter++;
        ll a2 = iter->first, a2_n=iter->second;
        if(a1==0){
            if (a1_n*2==a2_n) cout << "Yes" << endl;
            else cout << "No" << endl;
        }
        else cout << "No" << endl;
    }
    else if(kind==1){
        if(list.count(0)) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

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

int main() {

	long long n,i,j,k,sum=0,count=0,ans=0,x,b,c,d,mx=0,mn=1000000,a;
	cin>>a>>b>>c>>d;
	k=__gcd(c,d);
    k=(c*d)/k;
	ans=(b/c-(a-1)/c+b/d-(a-1)/d-(b/k-(a-1)/k));
	
	cout<<(b-a-ans+1);

	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int w,a,b; cin >>  w >> a >> b;
  
  if( a - b < -w) { cout << b - a - w;return 0;}
  else if( a - b > w){cout << a - b - w; return 0;}
  else{cout << 0 ; return 0;}
  
}

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

string STR;
bool N, S, E, W;


int main() {
	cin >> STR;
	
	for(char c : STR) {
		if(c == 'N')
			N = true;
		if(c == 'E')
			E = true;
		if(c == 'W')
			W = true;
		if(c == 'S')
			S = true;
	}
	
	if((N + S) % 2 || (E + W) % 2) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
//const lint MOD = pow(10, 9) + 7;

int main() {
	int N;
	while (1) {
		cin >> N;
		if (N == 0) {
			return 0;
		}
		vector<double>S(N);
		rep(i, N) {
			cin >> S[i];
		}
		double m = 0;
		rep(i, N) {
			m += S[i];
		}
		m /= N;
		double a = 0;
		rep(i, N) {
			a += (S[i] - m) * (S[i] - m);
		}
		a /= N;
		a = sqrt(a);
		cout <<setprecision(20)<< a << endl;
	}
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for (int i = 1; i < n - 1; i++) {
    string x = s.substr(0, i);
    string y = s.substr(i);
    int countx[26], county[26];
    fill(countx, countx + 26, 0);
    fill(county, county + 26, 0);
    for (int i = 0; i < x.size(); i++) {
      countx[x[i] - 'a']++;
    }
    for (int i = 0; i < y.size(); i++) {
      county[y[i] - 'a']++;
    }
    int res = 0;
    for (int i = 0; i < 26; i++) {
      if (countx[i] && county[i]) res++;
    }
    ans = max(res, ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
M = 3.times.map{ gets.split.map(&:to_i) }.flatten
N = gets.to_i
NUM = Array.new(110,false)
N.times do
  n = gets.to_i
  NUM[n] = true
end

LINES = [
    [0,1,2],[3,4,5],[6,7,8],
    [0,3,6],[1,4,7],[2,5,8],
    [0,4,8],[6,4,2]
  ]
  .map{|l| l.map{|x| NUM[M[x]] } }

puts LINES.any?(&:all?) ? 'Yes' : 'No'


Measured memory_bytes: 1788
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

int main() {
	int a;
	string s;
	cin >> a >> s;
	if (a >= 3200) {
		cout << s << endl;
	}
	else {
		cout << "red" << endl;
	}
}
	


Measured memory_bytes: 256
import java.util.*;


import java.io.*;
/**
 * MLASERP
 */
public class Main {

    
    static MyScanner in  = new MyScanner();
   static int mod  = 1000000007;
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      static StringTokenizer st;
      static int []dr  = {1,-1,0,0};
      static int [] dc = {0,0,-1,1};
public static void main(String[] args) {
    int N = in.nextInt();
    int [] A = new int[N];
   long sum=0;
    for(int i=0;i<N;i++){
       A[i] = in.nextInt();
       sum+=A[i];
       sum%=mod;
    }
    long ans =0;
    for(int i=0;i<N-1;i++){
       sum-=A[i];
       if(sum<0) sum+=mod;
       ans+=A[i]*sum;
       ans%=mod;
    }
    out.println(ans);
   out.flush();

}
static int rcToxy(int r, int c,int W){
    return r*W+c;
}
static class Node{
    int r, c,prev,change;
    Node(int r, int c){
        this.r =r ;
        this.c = c;
    }
}
public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
}

Measured memory_bytes: 54184
n = gets.to_i

spade, heart, club, diamond = [], [], [], []
suits = ["S", "H", "C", "D"]
num = 1..13

n.times do |i|
  suit, number = gets.split
  case suit 
  when suits[0]
  	spade << number.to_i
  when suits[1]
    heart << number.to_i
  when suits[2]
  	club << number.to_i
  when suits[3]
  	diamond << number.to_i
  end
end

all = [spade, heart, club, diamond]

# ????????????
all.each.with_index do |nums, i|
  nums.sort
  num.each do |element|
    if !nums.include? element then
      puts "#{suits[i]} #{element}"
    end
  end
end

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

int n,a,d,m;
int get(int x){
    return a+d*(x-1);
}

map<int,int>mp;

int main(){
    cin>>n>>a>>d>>m;
    while(m--){
        int x,y,z;
        cin>>x>>y>>z;
        if(x){
            if(mp.find(z)==mp.end())mp[z]=get(z);
            mp[y]=mp[z];
        }
        else{
            if(mp.find(y)==mp.end())mp[y]=get(y);
            if(mp.find(z)==mp.end())mp[z]=get(z);

            swap(mp[y],mp[z]);
        }
    }
    int k;cin>>k;
    if(mp.find(k)==mp.end())cout<<get(k)<<endl;
    else cout<<mp[k]<<endl;
    return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>

int main()
{
	int i = 1;
	int x,y;
	
	while (i <= 3000) {
		scanf("%d %d",&x,&y);
		if (x == 0 && y == 0) break;
		if (x <= y) {
			printf("%d %d\n",x,y);
		} else {
			printf("%d %d\n",y,x);
		}
		
		i++;
	}
	
	return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(System.Console.ReadLine().Trim());
        int[] line = Array.ConvertAll(System.Console.ReadLine().Trim().Split(' '),int.Parse);

        Dictionary<int, int> s = new Dictionary<int, int>();
        Dictionary<int, int> t = new Dictionary<int, int>();
        Dictionary<int, int> tmp;

        for (int i = 0; i < n ; i++)
        {
           
            tmp = (i % 2 == 0) ? s: t;

            if(tmp.ContainsKey(line[i]))
            {
                tmp[line[i]]++;
            }
            else
            {
                tmp.Add(line[i], 1);
            }
        }

        int s1 = 0, s2 = 0, t1 = 0, t2 = 0;

        s = s.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
        t = t.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);

        s1 = s[s.Keys.ToList()[0]];
        t1 = t[t.Keys.ToList()[0]];

        if(s.Keys.ToList()[0] != t.Keys.ToList()[0])
        {
            //最頻値が異なればsもtも最頻値で置換
            System.Console.WriteLine("{0}", (n - s1 - t1));

        }
        else{

            //最頻値が同じならいずれかを2番目の頻度の値で置換
            if (s.Count > 1) s2 = s[s.Keys.ToList()[1]];
            if (t.Count > 1) t2 = t[t.Keys.ToList()[1]];

            //sを最頻値で、tを二番目で書き換え
            //tを最頻値で、sを二番目で書き換え
            int sRlt = n - s1 - t2;
            int tRlt = n - s2 - t1;

            System.Console.WriteLine("{0}", Math.Min(sRlt, tRlt));

        }


    }

    


}


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

int main() {
  int n;
  cin >> n;
  vector<int> ans(10050,0);
  int v;
  for (int i = 1; i<106;i++){
    for (int j = 1; j<106; j++){
      for (int k = 1; k<106; k++){
        v = i*i+j*j+k*k+i*j+j*k+k*i;
        if (v < 10050){
          ans.at(v) += 1;
        }
      }
    }
  }
  for (int i = 0; i<n; i++){
    cout << ans.at(i+1) << endl;
  }
}

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

const int MAX = 200005;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
  COMinit();
  int n, k;
  cin >> n >> k;
  int64_t ans = 0;
  int m = min(n-1, k);
  for(int i=0; i<=m; i++){
    ans += COM(n, i) * COM(n-1, i) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}



Measured memory_bytes: 4992
#include <stdio.h>

int main()
{
	int a,b,c,x,d,T=0;

	scanf("%d %d %d",&a,&b,&c);
	for (x=a;x<=b;x++) {
		if (c%x == 0) {
			T++;
		}
	}
	printf("%d\n",T);
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define int long long
#define mod 1e18+10
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int32_t main() {
	int n,sum=0,i;
	cin>>n;
	for(i=1;i<=n;i++)
	{	if(i%3==0 || i%5==0)
			continue;
		sum+=i;
	}
	cout<<sum;
	
	
	
}


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

int main()
{
    int N, A, B;
    cin >> N;
    cin >> A >> B;
    int num1 = 0, num2 = 0, num3 = 0;
    int x;
    for (int i = 0; i < N; i++)
    {
        cin >> x;
        if (x <= A)
        {
            num1++;
        }
        else if (A + 1 <= x && x <= B)
        {
            num2++;
        }
        else
        {
            num3++;
        }
    }

    cout << min(min(num1, num2), num3) << endl;

    return 0;
}

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

int main(){
    int num[7], p, a, b;
    for (int i=1; i<7; i++) cin >> num[i];
    cin >> p;
    for (int i=0; i<p; i++){
        cin >> a >> b;
        // num[1]
        if (num[2]==a&&num[3]==b || num[3]==a&&num[5]==b ||\
        num[5]==a&&num[4]==b || num[4]==a&&num[2]==b)
            cout << num[1] << endl;
        // num[2]
        if (num[4]==a&&num[6]==b || num[6]==a&&num[3]==b ||\
        num[3]==a&&num[1]==b || num[1]==a&&num[4]==b)
            cout << num[2] << endl;
        // num[3]
        if (num[1]==a&&num[2]==b || num[2]==a&&num[6]==b ||\
        num[6]==a&&num[5]==b || num[5]==a&&num[1]==b)
            cout << num[3] << endl;
        // num[4]
        if (num[2]==a&&num[1]==b || num[1]==a&&num[5]==b ||\
        num[5]==a&&num[6]==b || num[6]==a&&num[2]==b)
            cout << num[4] << endl;
        // num[5]
        if (num[1]==a&&num[3]==b || num[3]==a&&num[6]==b ||\
        num[6]==a&&num[4]==b || num[4]==a&&num[1]==b)
            cout << num[5] << endl;
        // num[6]
        if (num[2]==a&&num[4]==b || num[4]==a&&num[5]==b ||\
        num[5]==a&&num[3]==b || num[3]==a&&num[2]==b)
            cout << num[6] << endl;
    }
    return 0;
}


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

long long K;
long long A[100005];

int main(){
	cin >> K;
	for(long long i = 0; i < K; i++){
		cin >> A[i];
	}
	long long curmax = 2;
	long long curmin = 2;


	for(long long i = K -1; i >= 0; i--){
		long long before;
		if(curmin % A[i] == 0){
			before = A[i];
		} else {
			before = (curmin/A[i] + 1)*A[i];
		}
		if(before > curmax){
			cout << -1 << endl;
			return 0;
		}


		if(curmin % A[i] == 0){
			curmin = curmin;
		} else {
			curmin = (curmin/A[i] + 1)*A[i];
		}

		if(curmax % A[i] == 0){
			curmax = curmax + A[i] - 1;
		} else {
			curmax = (curmax/A[i] + 1)*A[i] - 1;
		}

		if(curmin > curmax){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << curmin << " ";
	cout << curmax << endl;
}


Measured memory_bytes: 1024
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
for i in range(n):
    p[i]-=1
ans=-10**18

for si in range(n):
    score=[]
    x=si
    while(1):
        x=p[x]
        score.append(c[x])
        if(x==si):
            break
    l=len(score)
    accum=[score[0]]
    for i in range(1,l):
        accum.append(score[i]+accum[i-1])
    total=sum(score)
    z=k//l
    if(total>0):
        for i in range(l):
            if(((z-1)*l+i)>=0):
                tmp=accum[i]+total*(z-1)
                ans=max(ans,tmp)
            if((z*l+i)<k):
                tmp=accum[i]+total*z
                ans=max(ans,tmp)
    else:
        for i in range(l):
            if(i<k):
                tmp=accum[i]
                ans=max(ans,tmp)
print(ans)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> list(2 * m);
  
  for (int i = 0; i < 2 * m; i++)
	cin >> list.at(i);
  
  for (int j = 1; j <= n; j++) {
	int x = 0;
    for (int k = 0; k < 2 * m; k++) {
      if (list.at(k) == j)
        x++;
    }
    cout << x << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main(){
	int n;
	double a[1001] , total =0 ;
	while(1){
		total=0;
	cin >> n ;
	if( n==0 ) break;
	for( int i=0 ; i<n ; i++ ){
		cin >> a[i] ;
		total += a[i] ;
	}
	double average = total/(double)n;
	total = 0;
	for( int i=0 ; i<n ; i++){
		total += pow((a[i] - average ) , 2 );
	}
	total = total/n;
	cout << sqrt( total ) << endl;
}
}

Measured memory_bytes: 3180
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfLong()
    val S = LongArray(N + 1)
    for (m in 0 until N) S[m + 1] = S[m] + A[m]
    var ans = Long.MAX_VALUE
    var l = 1
    var r = 3
    for (m in 2 .. N - 2) {
        while (Math.abs(S[l] - (S[m] - S[l])) > Math.abs(S[l + 1] - (S[m] - S[l + 1]))) l++
        while (Math.abs(S[N] - S[r] - S[r] + S[m]) > Math.abs(S[N] - S[r + 1] - S[r + 1] + S[m])) r++
        val list = listOf(S[l], S[m] - S[l], S[r] - S[m], S[N] - S[r])
        ans = Math.min(ans, Math.abs(list.max()!! - list.min()!!))
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { java.lang.Long.parseLong(it) }


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

using namespace std;
#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

int main ()
{
  string S,T;
  int res;

  cin >> S;
  cin >> T;
  res = 0;
  REPI(S.size ())
  {
    if (S[i] != T[i])
      res++;
  }

  cout << res << endl;
  return 0; 
}

Measured memory_bytes: 3832
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws Exception {
        String line = readLine();
        StringTokenizer st = new StringTokenizer(line, " ");
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int c = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());

        int dis_ac = Math.abs(c-a);
        int dis_ab = Math.abs(b-a);
        int dis_bc = Math.abs(c-b);

        if (d >= dis_ac ) {
        	System.out.println("Yes");
        } else if ((d >= dis_ab)&&(d >= dis_bc)) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }
    }

    private static String readLine() throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        return br.readLine();
    }

}

Measured memory_bytes: 21588
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    vector<int> d(N);
    for(int i=0;i<N;i++){
        cin >> d[i];
    }
    sort(d.begin(),d.end());
    cout << d[N/2]-d[N/2-1] << endl;
    return 0;
}


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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef long long ll;

const int MOD = 1000000007;

void solve() {
  int N;
  cin >> N;
  vi perm(N);
  vector<string> permstr;
  string P = "", Q = "";
  for (int i = 0; i < N; i++) {
    char p;
    cin >> p;
    P += p;
    perm[i] = i + 1;
  }
  for (int i = 0; i < N; i++) {
    char q;
    cin >> q;
    Q += q;
  }
  do {
    string pstr = "";
    for (int i = 0; i < N; i++) {
      pstr += (char)(perm[i] + '0');
    }
    permstr.push_back(pstr);
  } while (next_permutation(all(perm)));
  sort(all(permstr));
  int a, b;
  for (int i = 0; i < permstr.size(); i++) {
    if (permstr[i] == P) a = i;
    if (permstr[i] == Q) b = i;
  }
  cout << abs(a - b) << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 2424
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	vector<int> a;
	int total, x;

	for (int i = 0; i < 3; i++) {
		cin >> x;
		a.push_back(x);
	}
	
	sort(a.begin(), a.end());

	cout << a[0] + a[1] << endl;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(string s) {
    int n = cast(int)s.length;
    auto es = new int[n];
    auto ws = new int[n];

    int e = 0;
    int w = 0;
    for (int i = 0; i < n; i++) {
        switch (s[i]) {
            case 'E': e++; break;
            case 'W': w++; break;
            default: break;
        }
        es[i] = e;
        ws[i] = w;
    }

    int ans = int.max;
    for (int i = 0; i < n; i++) { // i がリーダー
        // リーダーの左側で W を向いている人数
        int left = i > 0 ? ws[i - 1] : 0;
        // リーダーの右側で E を向いている人数
        int right = i == n-1 ? 0 : es[n - 1] - es[i];
        ans = min(ans, left + right);
    }
    return ans;
}

void main() {
    readint;
    auto s = readln.chomp;
    auto ans = calc(s);
    writeln(ans);
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    int b = 0;
    for (int i=0; i<n; ++i) {
        cin >> a[i];
        b ^= a[i];
    }
    vector<int> ans(n);
    for (int i=0; i<n; ++i) {
        cout << (b ^ a[i]) << (i == n-1 ? "\n" : " ");
    }
}

Measured memory_bytes: 4828
#include <iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#define ll long long

using namespace std;

int main(){
    float N,T,A;
    cin >> N >> T >> A;
    vector<float> H(N,0);
    for(int i=0;i<N;i++){
        cin >> H[i];
    }
    vector<float> V_A;
    for(int i=0;i<N;i++){
        V_A.push_back(abs(A-(T-H[i]*0.006)));
    }
    int ans_num=0;
    for(int i=1;i<N;i++){
        if(V_A[ans_num]>V_A[i]){
            ans_num=i;
        }
    }
    cout << ans_num+1 << endl;
    return 0;
}


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

long long binarySearch(long long ok, long long ng, std::function<bool(int)> check) {
    while (abs(ok - ng) > 1) {
        long long mid = ok + ng >> 1;
        (check(mid) ? ok : ng) = mid;
    }
    return ok;
}

int main() {
    int n;
    cin >> n;
    vector<int> S(n + 1);
    for (int i = 0; i < n; i++) { cin >> S[i]; }
    S[n] = INT_MAX;
    int q;
    cin >> q;
    vector<int> T(n);
    for (int i = 0; i < q; i++) { cin >> T[i]; }
    int ans = 0;
    for (int i = 0; i < q; i++) {
        int idx = binarySearch(n - 1, -1, [&](int x) { return S[x] >= T[i]; });
        if (S[idx] == T[i]) { ans++; }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3528
n = int(input())
if n == 0:
	 print ("0")
out = []
while n != 0:
	 n, rem = divmod(n, -2)
	 if rem < 0:
	 	 n += 1
	 	 rem -= -2
	 out.append(rem)
print ("".join(map(str, out[::-1])))


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

int main() {
	int num_of_nums = 0;
	cin >> num_of_nums;
    int* nums = new int[num_of_nums];
    for (int i = 0; i < num_of_nums; i++) {
 	   cin >> nums[i];
    }
    for (int i = 0; i < num_of_nums; i++) {
		if (i != num_of_nums - 1) {
			cout << nums[num_of_nums - 1 - i] << ' ';
		}
		else {
			cout << nums[num_of_nums - 1 - i];
		}
	   }
	cout <<'\n';
    return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	int N,answer;
  cin >> N;
  answer=0;
  for(int i=0;i<N;i++){
    int l,r;
    cin>> l >> r;
    int s =r-l+1;
      answer+= s;
  }
  cout << answer << endl;
      
    
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a,b,max;
    scanf("%d %d",&a,&b);
    max=a+b;
    if(max<a-b)
			max=a-b;
		if(max<a*b)
			max=a*b;
		
		printf("%d\n",max);
		return 0;
}

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

using namespace std;

long long n;
long long dp1[20000];
long long dp2[26000000];

int main() {
  int g1, s1, b1, g2, s2, b2;
  cin >> n >> g1 >> s1 >> b1 >> g2 >> s2 >> b2;
  int vg = g2 - g1, vs = s2 - s1, vb = b2 - b1;
  
  for (int i = 0; i < n; ++i) {
    dp1[i+g1] = max(dp1[i+g1], dp1[i]+vg);
    dp1[i+s1] = max(dp1[i+s1], dp1[i]+vs);
    dp1[i+b1] = max(dp1[i+b1], dp1[i]+vb);
  }
  
  long long mx = 0;
  for (int i = 0; i <= n; ++i) mx = max(mx, dp1[i]);
  n += mx;
  
  for (int i = 0; i < n; ++i) {
    dp2[i+g2] = max(dp2[i+g2], dp2[i]-vg);
    dp2[i+s2] = max(dp2[i+s2], dp2[i]-vs);
    dp2[i+b2] = max(dp2[i+b2], dp2[i]-vb);
  }
  
  mx = 0;
  for (int i = 0; i <= n; ++i) mx = max(mx, dp2[i]);
  n += mx;
  
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 196992
import math
import numpy as np

def main():
    N = int(input())
    As = list(map(int, input().split()))
    As = np.array(As)
    idx = np.argsort(As)
    ret = ' '.join(map(str, idx+1))
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 23348
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            while (sc.hasNextInt()) {
                String s = "No";
                int a = Integer.parseInt(sc.next());
                int b = Integer.parseInt(sc.next());
                int c = Integer.parseInt(sc.next());
                if(a==b && b==c) s = "Yes";
                System.out.println(s);
            }
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
int main()
{
    long long n,m;
    cin>>n>>m;
    pair<long long,long long> arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i].ff>>arr[i].ss;
    sort(arr,arr+n);
    long long co=0,ans=0;
    for(int i=0;i<n;i++)
    {
        long long a;
        a=min(arr[i].ss,m-co);
        ans+=a*arr[i].ff;
        co+=a;
        if(co>=m)
            break;
    }
    cout<<ans;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main (void)
{
    int n, m, x;
    int i;
    int a;
    int cost;
    
    scanf("%d %d %d", &n, &m, &x);

    for(i = 0; i < m; ++i){
        scanf("%d", &a);
        if(a < x) cost++;
    }

    printf("%d\n", (m - cost) < cost ? (m - cost) : cost);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
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; }
const ll INF = 1e10;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    int h,w,n;
    cin >> h >> w >> n;
    h = max(h,w);
    if (n%h == 0) PRINT(n/h);
    else PRINT(n/h+1);
}

Measured memory_bytes: 256
cards ={S:(1..13).to_a, H:(1..13).to_a, C:(1..13).to_a,D:(1..13).to_a}

n = gets.to_i
n.times{
   rank,label = gets.split(" ")
    case rank
   when "S"
     cards[:S] -= [label.to_i]
   when "H"
     cards[:H] -= [label.to_i]
   when "C"
     cards[:C] -= [label.to_i]
   when "D"
     cards[:D] -= [label.to_i]
     end
}
cards[:S].each do |i|
    puts "S #{i}"
end
cards[:H].each do |i|
    puts "H #{i}"
end
cards[:C].each do |i|
    puts "C #{i}"
end
cards[:D].each do |i|
    puts "D #{i}"
end

Measured memory_bytes: 8684
#include<stdio.h>
int main(void) {
	int n;
	int l[100000], r[100000];
	int i, j;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &l[i]);
		scanf("%d", &r[i]);
	}

	int count=0;

	for (i = 0; i < n; i++) {
		if (l[i] != r[i]) {
			count = count + r[i] - l[i] + 1;
		}
		else {
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
# abc152/abc152_a
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    if N == M:
        print('Yes')
    else:
        print('No')
    return

main()


Measured memory_bytes: 3064
#include <string>
#include <iostream>
using namespace std;
int dir[] = { 0, 1, 0, -1 };
int H, W; string s[55]; bool vis[55][55];
int main() {
	cin >> H >> W; s[0] = s[H + 1] = string(W + 2, '#');
	for (int i = 1; i <= H; i++) cin >> s[i], s[i] = '#' + s[i] + '#';
	H += 2; W += 2;
	int x = -1, y = -1, d = -1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '>') x = i, y = j, d = 0;
			if (s[i][j] == 'v') x = i, y = j, d = 1;
			if (s[i][j] == '<') x = i, y = j, d = 2;
			if (s[i][j] == '^') x = i, y = j, d = 3;
		}
	}
	vis[x][y] = true;
	int cnt = 0;
	while (cnt++ < 100000) {
		int tx = x + dir[d], ty = y + dir[d ^ 1];
		if (s[tx][ty] == '#') d = (d + 3) & 3;
		else {
			x = tx, y = ty; vis[x][y] = true;
			if (s[x][y] == 'G') break;
			int ux = x + dir[(d + 1) & 3], uy = y + dir[((d + 1) & 3) ^ 1];
			if (s[ux][uy] != '#') x = ux, y = uy, d = (d + 1) & 3, vis[x][y] = true;
			if (s[x][y] == 'G') break;
		}
	}
	if (cnt >= 100000) {
		cout << -1 << endl;
		return 0;
	}
	int ret = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (vis[i][j]) ret++;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3128
import sys
from collections import defaultdict
range = xrange
input = raw_input

inp = [int(x) for x in sys.stdin.read().split()]; ii = 0

n = inp[ii]; ii += 1
m = inp[ii]; ii += 1
k = inp[ii]; ii += 1

R = inp[ii + 0: ii + 3 * k: 3]
C = inp[ii + 1: ii + 3 * k: 3]
V = inp[ii + 2: ii + 3 * k: 3]

items = [defaultdict(list) for _ in range(n)]
for i in range(k):
    r = R[i] - 1
    c = C[i] - 1
    v = V[i]
    items[r][c].append(v)

DP0 = [0] * m
DP1 = [0] * m
DP2 = [0] * m
DP3 = [0] * m

for r in range(n):
    itemsr = items[r]
    for c in range(m):
        if c:
            DP0[c] = max(DP0[c], DP0[c - 1])
            DP1[c] = max(DP1[c], DP1[c - 1])
            DP2[c] = max(DP2[c], DP2[c - 1])
            DP3[c] = max(DP3[c], DP3[c - 1])
        if c in itemsr:
            for v in itemsr[c]:
                DP3[c] = max(DP3[c], DP2[c] + v)
                DP2[c] = max(DP2[c], DP1[c] + v)
                DP1[c] = max(DP1[c], DP0[c] + v)
    for c in range(m):
        DP0[c] = DP1[c] = DP2[c] = DP3[c]
print DP0[-1] 


Measured memory_bytes: 149816
a, b = map(int, input().split())
def xsum(n):
    b = n%4
    c = 0
    if b == 0:
        c = n
    elif b == 1:
        c = 1
    elif b == 2:
        c = n+1
    return c
print(xsum(b)^xsum(a-1))

Measured memory_bytes: 3060
#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];
  sort(h.begin(), h.end());

  int ans = 1e9;
  for (int i = 0; i + k - 1 < h.size(); i++) {
    ans = min(h[i + k - 1] - h[i], ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

t1, t2 = LI()
a1, a2 = LI()
b1, b2 = LI()

a = a1 * t1 + a2 * t2
b = b1 * t1 + b2 * t2

if a == b:
    print('infinity')
else:
    if b > a:
        if a1 * t1 < b1 * t1:
            print(0)
        elif a1 * t1 == b1 * t1:
            print(1)
        elif a1 * t1 > b1 * t1:
            c = b - a
            d = a1 * t1 - b1 * t1
            e = d % c != 0
            print(2 * (d // c) + e)
    else:
        if b1 * t1 < a1 * t1:
            print(0)
        elif b1 * t1 == a1 * t1:
            print(1)
        elif b1 * t1 > a1 * t1:
            c = a - b
            d = b1 * t1 - a1 * t1
            e = d % c != 0
            print(2 * (d // c) + e)


Measured memory_bytes: 65776
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		X++;
		int Y = sc.nextInt();
		int[] x = new int[N];
		int[] y = new int[M];
		for(int i = 0; i < N; i++) x[i] = sc.nextInt();
		for(int i = 0; i < M; i++) y[i] = sc.nextInt();
		int max_x = -101;
		int min_y = 101;
		
		for(int i = 0; i < N; i++)
			if(max_x < x[i]) max_x = x[i];
		max_x++;
		
		for(int i = 0; i < M; i++)
			if(min_y > y[i]) min_y = y[i];
		
		boolean ans = false;
		if(X <= Y && max_x <= min_y && ((Y >= max_x && Y <= min_y) || (min_y >= X && min_y <= Y))) ans = true;
		
		System.out.println(ans?"No War":"War");
	}
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    string s; cin >> s;

    int start;
    int end;

    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'A') {
            start = i;
            break;
        }
    }

    for (int i = s.size()-1; i >= 0; --i) {
        if (s[i] == 'Z') {
            end = i;
            break;
        }
    }

    cout << end - start + 1 << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順

int a[300000];
int b[300000];
queue<int> q;

signed main(){
  int n;
  cin >> n;
  REP(i,n){
    cin >> a[i];
  }
  REP(i,n){
    cin >> b[i];
  }
  REP(i,n){
    if(b[i]<a[i]){
      cout << -1 << endl;
      return 0;
    }
  }
  REP(i,n){
    if(b[i]>b[(n+i-1)%n]+b[(n+i+1)%n]&&b[i]!=a[i]){
      q.push(i);
    }
  }
  int ans = 0;
  while(q.size()>0){
    int now = q.front();
    q.pop();
    if(b[now]-b[(n+now-1)%n]-b[(n+now+1)%n]<a[now]){
      cout << -1 << endl;
      return 0;
    }
    ans += (b[now]-a[now])/(b[(n+now-1)%n]+b[(n+now+1)%n]);
    int nkai = (b[now]-a[now])/(b[(n+now-1)%n]+b[(n+now+1)%n]);
    b[now] -= (b[(n+now-1)%n]+b[(n+now+1)%n]) * nkai;
    if(b[(n+now+1)%n]>b[(n+now)%n]+b[(n+now+2)%n]&&a[(n+now+1)%n]!=b[(n+now+1)%n]){
      q.push((n+now+1)%n);
    }
    if(b[(n+now-1)%n]>b[(n+now-2)%n]+b[(n+now)%n]&&a[(n+now-1)%n]!=b[(n+now-1)%n]){
      q.push((n+now-1)%n);
    }
  }
  REP(i,n){
    if(b[i]!=a[i]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int INFTY=1e9;
const int N=3000;
vi adj[N];
int n, k, dp[N][N], s[N], t[N], ans=INFTY;

void dfs(int x, int p) {
	int i, j, h;
	s[x]=1;
	dp[x][0]=1;
	for(int y:adj[x]) if(y!=p) {
		dfs(y, x);
		for(i=0; i<=s[x]+s[y]; i++)
			t[i]=INFTY;
		for(i=1; i<=s[x]; i++) for(j=0; j<=s[y]; j++) {
			if(i+j-1>k) break;
			h=max(i, j+1);
			t[h]=min(t[h], dp[x][i]+dp[y][j]);
		}
		s[x]+=s[y];
		dp[x][0]=s[x];
		for(i=1; i<=s[x]; i++) {
			dp[x][i]=t[i];
			ans=min(ans, t[i]+n-s[x]);
		}
	}
}

int main() {
	int i, u, v;
	scanf("%d%d", &n, &k);
	for(i=0; i<n-1; i++) {
		scanf("%d%d", &u, &v);
		adj[u].pb(v);
		adj[v].pb(u);
	}
	dfs(1, 0);
	for(i=0; i<=n; i++) ans=min(ans, dp[1][i]);
	printf("%d\n", ans);
   	return 0;
}

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

int main() {
    string s; cin >> s;
    int k = s.size() - 1;
    int ans = k * 9;

    bool is_all_9 = true;
    for (int i = 1; i < s.size(); i++) {
        int a = s[i]-'0';
        if (a != 9) {
            is_all_9 = false;
            break;
        }
    }
    if (is_all_9) cout << ans+(int)(s[0] - '0') << endl;
    else cout << ans+ (int)(s[0]-'0' -1) << endl;
}

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

int main(){
  int n;
  cin >> n;
  int odds = (n+2-1)/2;
  double ans = double(odds)/n;
  printf("%.10f",ans);
}

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

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

    ll n;
    cin >> n;

    // ll ans = n * (n - 1) / 2;
    ll ans = 0;
    if (n == 1) ans = 0;
    else {
        if (n % 2) ans = n * (n / 2);
        else ans = n * ((n-1) / 2) + (n / 2);
    }

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


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

ll f(ll n) {
	if(n <= 0) return 0;
	ll res = (n%4 == 1 || n%4 == 2);
	ll cnt = 1;
	while (cnt+1 <= n) {
		cnt <<= 1;
		int now;
		if(n%(cnt<<1) < cnt) now = 0;
		else {
			now = (n%2 == 0);
		}
		res += now * cnt;
		// cout << cnt << " " << now << endl;
	}
	return res;
}

int main() {
	ll a, b;
	cin >> a >> b;
	if(a < b) swap(a, b);
	ll fa = f(a);
	ll fb = f(b-1);
	ll ans = fa ^ fb;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
r,c=list(map(int,input().split()))
s=[0 for i in range(c+1)]

for i in range(r):
    l=list(map(int,input().split()))
    l.append(sum(l))
    print(' '.join(map(str,l)))
    s=[s[i]+l[i] for i in range(c+1)]
print(' '.join(map(str,s)))

Measured memory_bytes: 7788
from collections import deque

def only_color(s, monos):
  if s in monos:
    return True
  else:
    return False

def new_color(s, i, rgb):
  for color in rgb:
    if color != s[i] and color != s[i + 1]:
      break
  return s[:i] + color * 2 + s[i + 2:]

def solve(s):
  length = len(s)
  monos = ["r" * length, "g" * length, "b" * length]
  if s in monos:
    print(0)
    return
  dic = {s:0}
  rgb = "rgb"
  que = deque()
  que.append((s, 0))

  while que:
    colors, score = que.popleft()
    score += 1
    temp = colors[0]
    for i in range(1, length):
      ci = colors[i]
      if ci != temp:
        new = new_color(colors, i - 1, rgb)

        if new in monos:
          print(score)
          return

        if new not in dic:
          dic[new] = score
          que.append((new, score))

      temp = ci

  print("NA")

def main():
  while True:
    s = input()
    if s == "0":
      break
    solve(s)

main()


Measured memory_bytes: 7824
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  string S;
  cin >> S;
  int s = S.size();
  long x = 0, ans = 0;
  for (int i = 0; i < s; i++) {
    if (S.at(i) == 'W') {
      ans += i-x;
      x++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640