akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define E endl
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
double ar[N];
double dp[N];

double get(double n){
	double ans = (n*(1+n))/2;
	ans/=n;
	return ans;
}
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n , k ;
		cin >> n  >>k;
		fn1{
			cin >> ar[i];
		}
		for(int i=1;i<=n;i++){
			dp[i] = dp[i-1] + get(ar[i]);
		}
		double ans = 0;
		for(int i=1;i<=n-k+1;i++){
			// trace(i-1,i+k-1);
			ans = max(ans,dp[i+k-1]-dp[i-1]);
		}
		cout << fixed << setprecision(10);
		cout<<ans<<endl;
	
	}
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 5888
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def get_n(a_c):
	return ord(a_c)-ord('a')

def main():
	h,w  = IN()
	dd=[0]*(get_n('z')+1)
	for _ in range(h):
		s = input()
		for c in s:
			v=get_n(c)
			dd[v] += 1
			
	pa(dd)
	mmmd=[0]*4
	for v in dd:
		mmmd[v%4]+=1
	
	pa(mmmd)
	th_1_3=(h%2)*(w%2)
	th_2=(h%2)*(w//2)+(w%2)*(h//2)
	pa(th_2)
	if mmmd[1]+mmmd[3] > th_1_3:
		return 'No'
	if mmmd[2] > th_2:
		return 'No'
	return 'Yes'
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 39152
#include <stdio.h>

long gcf(long a, long b) {
    if (a == 0)
        return b;
    return gcf(b % a, a);
}

long lcm(long a, long b) {
    return (a * b) / gcf(a, b);
}

int main() {
    long a, b, c, d, e, l;
    scanf("%ld %ld %ld %ld", &a, &b, &c, &d);
    e = b - a + 1;
    l = lcm(c, d);

    long div1 = b / c - (a - 1) / c;
    long div2 = b / d - (a - 1) / d;
    long div3 = b / l - (a - 1) / l;

    printf("%ld\n", e - (div1 + div2 - div3));
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
cap = [[0, 0] for _ in range(N+1)]
cap[-1] = [A[-1], A[-1]]
for i in range(N-1,-1,-1):
    cap[i][0] = (cap[i+1][0] + 2 - 1)//2
    cap[i][1] = cap[i+1][1] + A[i]
ans = 1
nodes = 1
failed = nodes < cap[0][0]
for i in range(N):
    nodes = min((nodes - A[i])*2, cap[i+1][1])
    if nodes < cap[i+1][0]:
        failed = True
        break
    ans += nodes
print(-1 if failed else ans)


Measured memory_bytes: 90744
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int N;
    int A[100];
    cin>>N;
    int maxabs=-1,maxabspos=-1;
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(maxabs<abs(A[i])){
            maxabs=abs(A[i]);
            maxabspos=i;
        }
    }
    if(A[maxabspos]==0){
        cout<<0<<endl;
    }
    else if(A[maxabspos]>0){
        cout<<2*N<<endl;
        cout<<maxabspos+1<<' '<<1<<endl;
        cout<<maxabspos+1<<' '<<1<<endl;
        for(int i=0;i<N-1;i++){
            cout<<i+1<<' '<<i+2<<endl;
            cout<<i+1<<' '<<i+2<<endl;
        }
    }
    else{
        cout<<2*N<<endl;
        cout<<maxabspos+1<<' '<<N<<endl;
        cout<<maxabspos+1<<' '<<N<<endl;
        for(int i=N;1<i;i--){
            cout<<i<<' '<<i-1<<endl;
            cout<<i<<' '<<i-1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=100000;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int N;
    cin >> N;
    int a[N+1];
    int b[N];
    for(int i=0;i<=N;i++){
        cin >> a[i];
    }
    for(int i=0;i<N;i++){
        cin >> b[i];
    }
    ll ans=0;
    for(int i=0;i<N;i++){
        if(a[i]>=b[i]){
            ans+=b[i];
        }else{
            ans+=a[i];
            b[i]-=a[i];
            if(a[i+1]>=b[i]){
                ans+=b[i];
                a[i+1]-=b[i];
            }else{
                ans+=a[i+1];
                a[i+1]=0;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(args...) do { cout << "\033[32;1m" << #args << " -> "; err(args); } while (0)
#else
#define dbg(...)
#endif
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); }
template<typename T, typename... Args>
void err(T a, Args... args) { cout << a << ' '; err(args...); }

LL bin(LL x, LL n, LL MOD) {
    LL ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)
        if (n & 1) ret = ret * x % MOD;
    return ret;
}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
////////////////////////////////////////////////////////////////////////////////////

const int N = 1E3 + 100;
int n;
LL x[N], y[N];

vector<LL> w;

int main() {
    cin >> n;
    int parity = 0;
    FOR (i, 0, n) {
        cin >> x[i] >> y[i];
        parity = abs(x[i] + y[i]) % 2;
    }
    FOR (i, 0, n) {
        if (abs(x[i] + y[i]) % 2 != parity) {
            puts("-1");
            return 0;
        }
    }
    FORD (i, 31, -1)
        w.push_back(1LL << i);
    if (!parity) w.push_back(1);
    cout << w.size() << endl;
    FOR (i, 0, w.size()) printf("%lld%c", w[i], i == _i - 1 ? '\n' : ' ');
    FOR (i, 0, n) {
        LL a = x[i], b = y[i];
        string ans;
        for (LL& r: w) {
            if (abs(a) > abs(b)) {
                if (a > 0) ans += 'R', a -= r;
                else ans += 'L', a += r;
            } else {
                if (b > 0) ans += 'U', b -= r;
                else ans += 'D', b += r;
            }
            // dbg(a, b);
        }
        assert (a == 0 && b == 0);
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int64_t n, q; cin >> n >> q;
    vector<int64_t> a(n + 1, 0);
    vector<int64_t> x(q);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < q; i++) cin >> x[i];
    
    for (int qid = 0; qid < q; qid++) {
        int64_t ans = 0;
        int64_t lb = 0, ub = 0;
        int64_t sum = 0;
        
        bool prev_can = false;
        int64_t prev_mark = 0;
        
        while (ub <= n) {
            if (sum <= x[qid]) {
                if (ub == n) {
                    ans += (ub - lb) * (ub - lb + 1) / 2;
                    ans -= (prev_mark - lb) * (prev_mark - lb + 1) / 2;
                    break;
                }
                prev_can = true;
                sum += a[ub];
                ub++;
            } else {
                if (prev_can) {
                    ans += (ub - 1 - lb) * (ub - lb) / 2;
                    ans -= (prev_mark - lb) * (prev_mark - lb + 1) / 2;
                    prev_mark = ub - 1;
                }
                sum -= a[lb];
                lb++;
                prev_can = false;
            }
        }
        cout << ans << endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 3548
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n;
  cin >> n;
  vector<ll> t(n), a(n);
  REP(i, n) cin >> t[i] >> a[i];
  ll x = t[0], y = a[0];
  REP(i, n-1){
    ll m = max((x+t[i+1]-1)/t[i+1], (y+a[i+1]-1)/a[i+1]);
    x = m*t[i+1];
    y = m*a[i+1];
  }
  cout << x+y << endl;
  return 0;
}

Measured memory_bytes: 256
//#include "stdc++.h"
#include <bits/stdc++.h>
#include<iostream>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
//#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define endl "\n"
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p;}
const ll MOD =1000000007 ;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
#define pi 3.141592653589793238462
#define int  long long

int32_t main()
{
    IOS;
    int n,k;char ch;
    cin>>n>>k;
    string s;
    cin>>s;
    ch=s[k-1];
    ch=ch+32;
    s[k-1]=ch;
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
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;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
T intceil(T a, T b) {
    return (a + (b - 1)) / b;
}

signed main() {
    INIT;
    cin >> N;
    X = Y = 1;
    REP(i, N) {
        dump(X, Y);
        cin >> A >> B;
        ll tmp = max(intceil(X, A), intceil(Y, B));
        dump(tmp);
        X = tmp * A, Y = tmp * B;
    }
    cout << X + Y << endl;
}

Measured memory_bytes: 3612
#!/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()))

n,m,x = LI()
A = [LI() for _ in range(n)]

ans = inf
for i in range(1<<n):
    tmp = [0]*m
    preans = 0
    for j in range(n):
        if i >> j & 1:
            preans += A[j][0]
            for k,l in enumerate(A[j][1:]):
                tmp[k-1] += l
    for j in tmp:
        if j < x:
            break
    else:
        ans = min(ans, preans)
if ans == inf:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 68828
s = input()
qn = int(input())
pre, after = [], []
rev = False
for _ in range(qn):
    line = input()
    if line[0] == '1':
        rev = not rev
        pre, after = after, pre
    else:
        _, f, letter = line.split()
        if f == '1':
            pre.append(letter)
        else:
            after.append(letter)
if rev:
    s = s[::-1]
ans = ''.join(pre[::-1]) + s + ''.join(after)
print(ans)




Measured memory_bytes: 6252
#include <cstdio>
#define Mod 998244353ll
#define ll long long
ll dp[301][301*301];
ll dp2[301][301*301];
int v[301];
int main(){
    int n,s;
    ll p3,rez;
    scanf("%d",&n);
    s=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&v[i]);
        s+=v[i];
    }
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
    	for(int j=0;j<=s;j++){
    		if(j>=v[i]){
    			dp[i][j]=(dp[i-1][j]*2+dp[i-1][j-v[i]])%Mod;
			}
            else{
            	dp[i][j]=(2*dp[i-1][j])%Mod;
			}
		}
	}
    p3=1;
    for(int i=1;i<=n;i++){
    	p3=(p3*3)%Mod;
	}
    rez=0;
    for(int i=(s+1)/2;i<=s;i++){
    	rez=(rez+dp[n][i])%Mod;
	}
    if(s%2==0){
        dp2[0][0]=1;
        for(int i=1;i<=n;i++){
        	for(int j=0;j<=300*300;j++){
        		if(j>=v[i]){
        			dp2[i][j]=(dp2[i-1][j]+dp2[i-1][j-v[i]])%Mod;
				}
                else{
                	dp2[i][j]=(dp2[i-1][j])%Mod;
				}
			}
		}
        rez=(rez-dp2[n][s/2])%Mod;
    }
    rez=p3-rez*3;
    while(rez<0){
    	rez+=Mod;
	}
    rez%=Mod;
    printf("%lld\n",rez);
    return 0;
}


Measured memory_bytes: 425600
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

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

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

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

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  // 入力
  ll D;
  cin >> D;
  vll C(26);
  rep(i, 26) cin >> C[i];
  vvll S(D, vll(26));
  rep(i, D) rep(j, 26) cin >> S[i][j];
  vll T(D);  // その日に行ったコンテスト

  rep(i, D) {
    T[i] = (43 * i) % 26 + 1;
  }

  auto calc = [&]() -> ll {
    vll la(26, 0);
    ll res = 0;
    rep(i, D + 1) {
      if (i == 0) continue;
      ll t = T[i - 1];
      res += S[i - 1][t];
      la[t] = i;
      rep(j, 26) {
        res -= C[j] * (i - la[j]);
      }
    }
    return res;
  };

  // ll M;
  // cin >> M;
  // rep(i, M) {
  //   ll d, q;
  //   cin >> d >> q;
  //   d--;
  //   q--;

  //   T[d] = q;

  //   ll ns = calc();
  //   COUT(ns);
  // }

  rep(i, D) {
    COUT(T[i]);
  }

  return 0;
}

Measured memory_bytes: 3748
from collections import Counter

DEBUG = False

N = int(input())
S = []
patterns = []
ans = 0
for _ in range(N):
    s = input()
    # S.append(s)
    ans += s.count("AB")
    # 3進数表記 -> 1bit目: 先頭の文字, 2bit目: 末尾の文字
    # A = 0, B = 1, O:other = 2
    # A...A: 0, A...B: 1, A...O: 2
    # B...A: 3, B...B: 4, B...O: 5
    # O...A: 6, O...B: 7, O...O: 8
    pattern = ""
    pattern += "2" if (s[0] != "A"  and s[0] != "B") else "1" if s[0] == "B" else "0"
    pattern += "2" if (s[-1] != "A" and s[-1] != "B") else "1" if s[-1] == "B" else "0"
    patterns.append(int(pattern, 3))
    if DEBUG:
        print("s: {}, pattern: {}".format(s, pattern))

if DEBUG:
    print("patterns: {}".format(patterns))
    print("ans: {}".format(ans))

counter = Counter(patterns)
if DEBUG:
    print("counter: {}".format(counter))

ans += counter[3] - 1 if counter[3] else 0
if DEBUG:
    print("ans: {}".format(ans))


num_tail_A = counter[0] + counter[6]
num_head_B = counter[4] + counter[5]
if DEBUG:
    print("num_tail_A: {}, num_head_B: {}".format(num_tail_A, num_head_B))

if not num_tail_A and not num_head_B:
    pass
else:
    num_tail_A += 1 if counter[3] else 0
    num_head_B += 1 if counter[3] else 0
    ans += min(num_tail_A, num_head_B)

print(ans)


Measured memory_bytes: 3436
//31
#include<iostream>
#include<queue>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
  int h,w,n;
  cin>>h>>w>>n;
  char g[1000][1000];
  int y,x;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>g[i][j];
      if(g[i][j]=='S'){
	y=i;
	x=j;
      }
    }
  }
  int el=0;
  for(int i=1;i<=n;i++){
    static int t[1000][1000];
    fill_n(t[0],1000000,-1);
    t[y][x]=0;
    queue<pair<int,int> > que;
    que.push(make_pair(y,x));
    for(;;){
      int by=que.front().first;
      int bx=que.front().second;
      que.pop();
      for(int j=0;j<4;j++){
	int d[]={0,1,0,-1,0};
	int ny=by+d[j];
	int nx=bx+d[j+1];
	if(0<=ny&&ny<h&&0<=nx&&nx<w&&g[ny][nx]!='X'){
	  if(t[ny][nx]==-1){
	    t[ny][nx]=t[by][bx]+1;
	    if(g[ny][nx]=='0'+i){
	      el+=t[ny][nx];
	      y=ny;
	      x=nx;
	      goto next;
	    }
	    que.push(make_pair(ny,nx));
	  }
	}
      }
    }
  next:
    ;
  }
  cout<<el<<endl;
  return 0;
}

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

int main(){
    ll n;
    cin>>n;
    ll ans = 0;
    
    for(ll j=n; j<=n*n;j++){
        ll k = 0;
        for(ll i=2;i<=sqrt(j);i++){
            if(j%i==0){
                k++;
                break;
            }
        }
        if(k==0){
            ans = j;
            cout << ans <<endl;
            return 0;
        }
    }
    return 0;
}



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

int main(){
    int x[3001];
    int y[3001];
    int cnum = 0;
    while(1){
        cnum += 1;
        cin >> x[cnum] >> y[cnum];
        if(x[cnum] == 0 && y[cnum] == 0) break;
    }
    for(int i = 1;i < cnum;i++){
        if(x[i] > y[i]){
            cout << y[i] << " " << x[i] << endl;
        }else{
            cout << x[i] << " " << y[i] << endl;
        }
    }
}


Measured memory_bytes: 2996
def main():
    L, R = map(int, input().split())
    # 60 の相異なる素因数は 3, 673 の 2つ
    if L + 672 <= R:
        print(0)
        return
    lst = []
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            lst.append(i * j % 2019)
            m = i * j % 2019
            if m <= 1:
                break
        if m <= 1:
            break
    print(min(lst))
    return


main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <limits>
#include <cstdlib>
#include <regex>
using namespace std;

double inf = numeric_limits<double>::infinity();

#define REP(i,n) for(int i=0;i<n;i++)
using LL = long long int;
LL GCD(LL a,LL b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LL LCM(LL a,LL b){ return (a/GCD(a,b))*b; }

vector<vector<LL>> v;
vector<LL> color;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    vector<int> v = {a,b,c};
    
    sort(v.begin(), v.end());
    
    if (v[0] == v[1]) {
        cout << v[2] << endl;
    } else {
        cout << v[0] << endl;
    }
}


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

int main(){
  int n,m;
  cin >> n >> m;
  
  vector<int> x(n+1), y(m+1);
  cin >> x[0] >> y[0];
  
  for(int i = 1; i <= n; i++)
    cin >> x[i];
  for(int i = 1; i <= m; i++)
    cin >> y[i];
  
  int max_x = *max_element(x.begin(), x.end());
  int min_y = *min_element(y.begin(), y.end());
  if(max_x < min_y)
    cout << "No War" << endl;
  else
    cout << "War" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeMap;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        if (K==1){
            System.out.println(0);
        } else {
            System.out.println(N-K);
        }
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

int main(void){
  long long answer=1;
  int D, N;
  cin >> D >> N;
  if(N==100)
    N++;
  for (int i = 0; i < D; i++)
  {
    answer *= 100;
  }

  answer *= N;
  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 380
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int a, v, b, w, t;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> a >> v >> b >> w >> t;
    if (a > b) swap(a, b);
    b -= a;
    a = 0;
    long long s = v * 1LL * t;
    long long tmp = b + w * 1LL * t;
    if (s >= tmp) cout << "YES" << E;
    else cout << "NO" << E;
    //system("pause");
    return 0;
}

Measured memory_bytes: 3596
N = int(input())
D = []
for _ in range(N):
    D.append(list(map(int, input().split())))

count = 0

for i in range(N):
    if D[i][0] == D[i][1]:
        count += 1
    else:
        count = 0
    if count == 3:
        print('Yes')
        exit()

print('No')

Measured memory_bytes: 9120
#include <iostream>
#include <fstream>
#include <cstring>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <random>
#include <complex>
#include <chrono>
#include <assert.h>

using namespace std;

//ifstream fin("input.in");
//ofstream fout("output.out");

typedef long long LL;
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long INF64 = 3e18 + 1;
const int N = 200555;
const int AMAX = 205;
const int LIM = 1000000000;

//typedef __uint128_t u128;

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const char invdir[]{'L', 'U', 'R', 'D'};
const char dir[]{'R', 'D', 'L', 'U'};

#define all(a) (a).begin(), (a).end()
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>

int n,m,D,dp[N][2],dp1[N][2];

string K;

void solve(){
    cin >> K >> D;

    dp[0][0] = 1;
    dp[0][1] = 0;

    for(int i = K.length() - 1; i >= 0; i--){
        int x = K[i] - '0';

        for(int sum = 0; sum < D; sum++){
            // dp[rest] [0] - solutii cu digit <= x pe pozitia anterioara
            // dp[rest] [1] - solutii cu digit > x pe pozitia anterioara

            // 3 Cazuri:

            // 1. Pe pozitia curenta digit < x (solutie de tip 0)
                // dp[...][0] si dp[...][1]. Ex  K=232  1XY (1 < 2)
            // 2. Pe pozitia curenta digit == x (solutie de tip 0)
                // dp[...][0]. Ex  K=232  2XY (1 < 2)
            // 3. Pe pozitia curenta digit == x (solutie de tip 1)
                // dp[...][1]
            // 4. Pe pozitia curenta digit > x (solutie de tip 1)
                // dp[...][0] + dp[...][1]. Ex  K=332  3XY (3 > 2)


            for(int dig = 0; dig <= 9; dig++){
                if(dig == x){
                    dp1[(sum + dig) % D][0] += (dp[sum][0])%MOD;
                    dp1[(sum + dig) % D][0] %= MOD;

                    dp1[(sum + dig) % D][1] += (dp[sum][1])%MOD;
                    dp1[(sum + dig) % D][1] %= MOD;
                }else{
                    dp1[(sum + dig) % D][(dig > x)] += (dp[sum][1] + dp[sum][0]) % MOD;
                    dp1[(sum + dig) % D][(dig > x)] %= MOD;
                }
            }
        }

        /*
        cout << "deb " << i << "\n";
        cout << "0: \n";
        for(int i = 0; i < D; ++i){
            cout << dp1[i][0] << " ";
        }
        cout << "\n";
        cout << "1: \n";
        for(int i = 0; i < D; ++i){
            cout << dp1[i][1] << " ";
        }
        cout << "\n";
         */

        for(int k = 0; k < D; k++){
            for(int b = 0; b <= 1; b++){
                dp[k][b] = dp1[k][b];
                dp1[k][b] = 0;
                //cout << dp1[k][b] << ' ';
            }
        }
    }

    int ans = dp[0][0] - 1;
    ans += MOD;
    ans %= MOD;
    cout << (ans);
}

int main() {
    //std::ios_base::sync_with_stdio(0);
    //cin.tie(0);
    int T = 1;

    //cin >> T;

    int i = 1;
    while(T--){
        solve();
        i++;
    }


    return 0;
}



Measured memory_bytes: 256
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
N = lines.shift() * 1
A = lines.shift().split(' ')

h = 0
cnt = 0
for (i=0; i<N; i++) {
    if (h<=A[i]*1) {
        cnt++
        h = A[i]*1
    }
}
console.log(cnt)

Measured memory_bytes: 7500
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl

int main(){
    ll N, K; cin>>N>>K;
    ll ans=min(N%K, abs((N%K)-K));
    cout<<ans<<endl;
}


Measured memory_bytes: 3560
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#define INF 2100000000
#define INVALID -1
using namespace std;
int dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
int absint(int a)
{
	return max(a , - a);
}
int main()
{
	string s,key="keyence";
	int i, j=0,k=0;
	cin >> s;
	for (i = 0; i < key.length(); i++)
	{
		if (s[i] == key[i]) j++;
		else break;
	}
	for (i = 0; i < key.length(); i++)
	{
		if (s[s.length() - i] == key[key.length()-i]) k++;
		else break;
	}
	//printf("j%dk%d\n", j, k);
	if (j + k >= 8) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
import datetime

# 入力
#N = int(input())
#S = str(input())
#H, W = map(int, input().split())
S = str(input())

if S[0] == S[1] or S[1] == S[2] or S[2] == S[3] :
  print ("Bad")
else :
  print ("Good")
  


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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    a=[1,3,5,7,8,10,12]
    b=[4,6,9,11]
    x,y=MI()
    if (x in a and y in a) or (x in b and y in b):
        print("Yes")
    else:
        print("No")

main()


Measured memory_bytes: 38384
N,M = map(int,input().split())
sc=[list(map(int,input().split()))for _ in range(M)]
ans = -1
for i in range(1000):
  s = str(i)
  if len(s) == N:
    flg = 0
    for a,b in sc:
      if int(s[a-1]) != b:
        flg = 1
    if flg == 0:
      ans = i
      break
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1236>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

vector<vector<int>> G;
vector<int> memo;
vector<pii> roomdoor;
map<int,pii> mp;
void dfs(int dep,int& i){
    if(i >= memo.size()) return;
    int idx = i;
    int n = roomdoor[i].second;
    mp[dep] = {i,n};

    i++;
    while(i < memo.size()){
        if(roomdoor[idx].first == 0) break;
        if(memo[i] > 0){
            int next = roomdoor[i].second;
            G[n].push_back(next);
            G[next].push_back(n);
            roomdoor[idx].first--; roomdoor[i].first--;
            dfs(dep+1,i);
        }else{

            pii p = mp[dep+memo[i]];

            int nextidx = p.first;
            int next = p.second;

            G[n].push_back(next);
            G[next].push_back(n);

            roomdoor[idx].first--; roomdoor[nextidx].first--;
            i++;
        }
    }
}
void solve(){
    mp.clear();
    memo.clear();
    roomdoor.clear();
    G.clear();
    int x; while(cin >> x,x) memo.push_back(x);
    roomdoor.assign(memo.size(),{0,0});
    int V = 0;
    for(int i = 0; i < memo.size();i++){
        if(memo[i] < 0) continue;
        roomdoor[i] = {memo[i],V++};
    }
    G.resize(V);
    int i = 0;
    dfs(0,i);
    for(int i = 0; i < V;i++){
        cout << i + 1 << " ";
        sort(G[i].begin(),G[i].end());
        for(int j = 0; j < G[i].size(); j++){
            cout << G[i][j]+1 << " \n"[j==G[i].size()-1];
        }
    }
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n; cin >> n;
    while(n--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 3168
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(){

    double a, b;            //WA原因不明
    scanf("%lf %lf", &a, &b);

    int i, answer = 0;
        for(i = floor(a*100/7); i >= ceil(a*100/8); i--){
            if((floor(i*8/100)==a)&&(floor(i*10/100)==b)){
                answer = i;
            }
        }

    if(answer == 0){
        printf("-1");
    }else{
        printf("%d",answer);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
          #include <chrono>
        
          using namespace std;
          using namespace std::chrono; 
       
          typedef long long int ll;
       
          #define MOD (ll)(1e9+7)
          #define endl "\n"
          #define pb push_back
          #define TEST_CASES  ll t;cin>>t;while(t--)
          #define forn(i,a,n) for (int i = a; i < n; ++i)
          #define f first
          #define s second
          #define all(x) x.begin(), x.end()


          
          ll powD(ll x,ll y){
            ll res = 1;
            while(y > 0){
              if(y & 1)
                res = (res*x);
              x = (x*x);
              y = y>>1;
            }
            return res;
          }
          int main()
          {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            ll n;
            cin>>n;
            vector<ll> cnt(1e5+1,0);
            ll sum = 0;
            forn(i,0,n){
              ll x;
              cin>>x;
              sum += x;
              cnt[x]++;
            }
            ll q;
            cin>>q;
            forn(i,0,q){
              ll b,c;
              cin>>b>>c;
              sum -= cnt[b]*b;
              cnt[c] += cnt[b];
              sum += cnt[b]*c;
              cnt[b] = 0;
              cout<<sum<<endl;
            }

          }

          
        


Measured memory_bytes: 3964
#define DEB
#include <map>
#include <set>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>

#include <cstring>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<lint,lint> pi;

namespace std{
    template<class S,class T>
    ostream &operator <<(ostream& out,const pair<S,T>& a){
        out<<'('<<a.fr<<','<<a.sc<<')';
        return out;
    }
}

//const int INF=5e8;

char s[505][505];
int h,w,K;
int res[505][505];
int main(){
    cin>>h>>w>>K;
    REP(i,h) scanf("%s",s[i]);

    memset(res,-1,sizeof(res));
    int cnt=0;
    REP(i,h) {
        vector<int> v;
        REP(j,w){
            if(s[i][j]=='#') v.pb(j);
        }
        if(!v.empty()){
            if(v.size()==1){
                REP(j,w) res[i][j]=cnt;
                ++cnt;
            }else{
                int t=0;
                REP(j,w){
                    res[i][j]=cnt;
                    if(s[i][j]=='#' && t<v.size()-1) ++cnt,++t;
                }
                ++cnt;
            }
        }
    }
    for(int i=1;i<h;++i) REP(j,w) if(res[i][j]==-1 && res[i-1][j]!=-1) res[i][j]=res[i-1][j];
    for(int i=h-2;i>=0;--i) REP(j,w) if(res[i][j]==-1 && res[i+1][j]!=-1) res[i][j]=res[i+1][j];

    REP(i,h) REP(j,w) printf("%d%c",res[i][j]+1,j==w-1?'\n':' ');
    return 0;
}





Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
typedef long long int ll;
const double pi = 3.14159265358979323846;
int arr[10];
int main() {
    fast
    //test
    {
        int i,j,n,k;
        cin>>n>>k;
      for(i=0;i<k;i++)
      {
        int y;
        cin>>y;
        arr[y]=1;
        
      }
      int flag=0;
      
      while(flag==0)
      {
        int p=n;
        flag=1;
        while(p>0){
        if(arr[p%10]==1)
        {n++;flag=0;break;}
        else
        {p/=10;}
          
        }
        if(flag==1)
          break;
      }
      cout<<n;
    }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll dp[N],a[N];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,k;cin>>n>>k;
    for(ll i=1;i<=n;i++)cin>>a[i];
    for(ll i=2;i<=n;i++){
        dp[i]=(1e16);
        for(ll j=i-1;j>=1&&(i-j)<=k;j--)dp[i]=min(dp[i] , dp[j] + abs(a[j]-a[i]));
    }
    cout<<dp[n];
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  vector<ll> t(2), a(2), b(2);
  rep(i, 2) cin >> t[i];
  rep(i, 2) cin >> a[i];
  rep(i, 2) cin >> b[i];

  // youtube editorial 1:33 で言われる
  rep(i, 2) { a[i] *= t[i]; b[i] *= t[i]; }

  if (a[0] + a[1] == b[0] + b[1]) { cout << "infinity" << endl; return; }

  // 1 周期後, a が上
  if (a[0] + a[1] < b[0] + b[1]) {
    rep(i, 2) swap(a[i], b[i]);
  }

  if (a[0] > b[0]) { cout << 0 << endl; return; }

  /*
  1 回目 t1 後 b - a = c (b を上とした差)
  1 回目 t2 (+t2 のこと) 後の差 b - a = -d
  2 回目 t1 後 b - a = -d + c = c - d

  いつ, t1 で上にいけなくなるか

  t1 で上にいけたら必ず t2 で交差して閉じる
  どんどん閉じて逆に開く方に行くから

  t1 で上にいけなかったら二度と閉じない
  逆に開き続ける

  最初 t1 後 b - a = c
  次 t1 後 b - a = c - d (上を参照)
  すなわち, -d されていく

  最後, t1 後ちょうど接して終わる場合 t2 で接しない
  */

  ll c = b[0] - a[0], d = (a[0] + a[1]) - (b[0] + b[1]);
  // cout << c << " " << d << endl;
  if (c % d != 0) {
    cout << c / d * 2 + 1 << endl;
  } else {
    cout << c / d * 2 << endl;
    /*
    1 1
    2 1
    1 3

    ans = 2
    */
  }
}


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

int main() {
    int D, T, S; cin >> D >> T >> S;
    if (S * T >= D) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>
int main(){
	int t = 0, d, r;
	float x, y;
	x = y = 0;
	for(; scanf("%d,%d",&r,&d),r|d;){
		y += r * cos( t /57.3 );
		x -= r * sin( t /57.3 );
		t -= d;
	}
	return!printf("%d\n%d\n",t=x,d=y);
}

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


int main()
{
	//変数定義
	int p;
	string S;
	p = 700;

	//変数入力
	cin >> S;

	//計算パート
	for (int i = 0 ;i < 3; i++)
	{
		if ( S[i] == 'o')
		{
			p += 100;
		}
	}
	cout << p ;

    return 0;
}


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

using namespace std;

void solve()
{
    int n;
    long long sum = 0;
    cin >> n;
    vector <int> a(n);
    map <int, int> mp;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        mp[a[i]]++;
        sum += a[i];
    }
    int q;
    cin >> q;
    while (q--)
    {
        int a, b;
        cin >> a >> b;
        sum -= mp[a] * 1ll * a;
        sum += mp[a] * 1ll * b;
        mp[b] += mp[a];
        mp[a] = 0;
        cout << sum << endl;
    }
}

int main() 
{
    int tt = 1;
    //cin >> tt;
    while (tt--) solve();
}


Measured memory_bytes: 7924
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
int n , m , k;
char a[15][1005];
int main() {
    abdelrahman010
    cin >> n >> m >> k;
    for(int i = 0;i < n;i++)
        for(int j = 0;j < m;j++)
            cin >> a[i][j];
    int ans = 1e9;
    for(int i = 0;i < (1 << (n - 1));i++) {
        vector<int> v;
        bool yes = true;
        for(int j = 0;j < n;j++)
            if((1 << j) & i)
                v.push_back(j);
        v.push_back(n - 1);
        int cnt = 0;
        vector<int> tmp(v.size() , 0);
        for(int j = 0;j < m;j++) {
            vector<int> tmp1(v.size() , 0);
            int p = 0;
            for(int r = 0;r < n;r++) {
                tmp1[p] += (a[r][j] == '1');
                if(r == v[p])
                    p++;
            }
            int cnt1 = 0;
            for(int r = 0;r < v.size();r++)
                if(tmp1[r] > k) {
                    yes = false;
                    break;
                } else if(tmp[r] + tmp1[r] > k) {
                    cnt1++;
                    break;
                }
            cnt += cnt1;
            if(!yes)
                break;
            for(int r = 0;r < v.size();r++)
                if(cnt1)
                    tmp[r] = tmp1[r];
                else
                    tmp[r] += tmp1[r];
        }
        if(!yes)
            continue;
        ans = min(ans , cnt + __builtin_popcount(i));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
<?php
$count = 0;
while (True){
  $count++;
  fscanf(STDIN, "%d %d", $a, $b);
  if ($a === 0 && $b === 0){
    break;
  }
  if($a <= $b){
    echo $a." ".$b;
  } else {
    echo $b." ".$a;
  }
  echo "\n";
}


Measured memory_bytes: 9212
n,k=map(int,input().split())
s=list(input())
s=list(map(int,s))
stack=[]
tmp=0
now=1
for i in range(n):
  if s[i]==now:
    tmp+=1
  else:
    stack.append(tmp)
    tmp=1
    now=1-now
stack.append(tmp)
if len(stack)%2==0:
  stack.append(0)
Acc=[0]*(len(stack)+1)
for i in range(len(stack)):
  Acc[i+1]=Acc[i]+stack[i]
ans=0
for i in range(0,len(stack),2):
  left = i
  right = min(i+k*2+1,len(stack))
  ans=max(ans,Acc[right]-Acc[left])
print(ans)

Measured memory_bytes: 8432
n = gets.chomp.split(' ').map(&:to_i)[0]

if n == 2
  a = gets.chomp.split(' ').map(&:to_i)[0]
  b = gets.chomp.split(' ').map(&:to_i)[0]
  puts "#{a + b}"
else
  puts 'Hello World'
end

Measured memory_bytes: 1788
#C - Attention
N = int(input())
S = input()
DP_w= []
DP_e = []
tmp = 0
tmpw = 0
tmpe = 0
ans = 10**9
for i in range(N):
    if S[i] == "W":
        tmpw += 1
        DP_w.append(tmpw)
    else:
        DP_w.append(tmpw)

for j in range(N-1,-1,-1):
    if S[j] == "E":
        tmpe += 1
        DP_e.append(tmpe)
    else:
        DP_e.append(tmpe)

DP_e.reverse()
for k in range(N):
    ans = min(ans,DP_w[k]+DP_e[k]-1)

print(ans)


Measured memory_bytes: 18080
#include <stdio.h>

int main(void){
	
	int n;
	
	scanf("%d", &n);
	
	if(n == 1){
		printf("Hello World");
	}
	if(n == 2){
		int a, b;
		scanf("%d %d", &a, &b);
		printf("%d", a + b);
	}
	
	return 0;
}

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

using namespace std;

const int N = 100'009;

int a[N];
int b[N];
int ab[N];
int o[N];

int main() {
  int n;
  scanf("%d", &n);
  long long sa = 0, sb = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", a + i, b + i);
    sa += a[i];
    sb += b[i];
    ab[i] = a[i] + b[i];
  }
  long long ans = min(sa, sb);
  if (n % 2 == 0) {
    sort(ab, ab + n);
    long long cur = 0;
    for (int i = 0; i < n / 2; ++i) {
      cur += ab[i];
    }
    ans = min(ans, cur);
  }
  auto cmp_mn = [](int i, int j) {
    int mni = min(a[i], b[i]);
    int mnj = min(a[j], b[j]);
    if (mni != mnj) {
      return mni > mnj;
    }
    return i < j;
  };
  auto cmp_mx = [](int i, int j) {
    int mxi = max(a[i], b[i]);
    int mxj = max(a[j], b[j]);
    if (mxi != mxj) {
      return mxi < mxj;
    }
    return i < j;
  };
  set<int, decltype(cmp_mn)> mn(cmp_mn);
  set<int, decltype(cmp_mx)> mx(cmp_mx);
  long long cur = 0;
  for (int i = 0; i < n; ++i) {
    cur += min(a[i], b[i]);
    mn.insert(i);
    mx.insert(i);
  }
  while ((int)mn.size() >= 3) {
    int i = *mn.begin();
    int j = *mx.begin();
    if (i != j) {
      cur -= min(a[i], b[i]);
      cur += max(a[j], b[j]);
      mn.erase(i);
      mn.erase(j);
      mx.erase(i);
      mx.erase(j);
    } else {
      long long tmp_mn = cur;
      tmp_mn -= min(a[i], b[i]);
      mx.erase(i);
      int k_mn = *mx.begin();
      tmp_mn += max(a[k_mn], b[k_mn]);
      long long tmp_mx = cur;
      tmp_mx += max(a[i], b[i]);
      mn.erase(i);
      int k_mx = *mn.begin();
      tmp_mx -= min(a[k_mx], b[k_mx]);
      if (tmp_mn < tmp_mx) {
        cur = tmp_mn;
        mn.erase(k_mn);
        mx.erase(k_mn);
      } else {
        cur = tmp_mx;
        mn.erase(k_mx);
        mx.erase(k_mx);
      }
    }
    ans = min(ans, cur);
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 10752
#include <stdio.h>

int main(void) {
	
	int l,m,n;
	
	scanf("%d %d %d",&l,&m,&n);
	
	if(l > m)
	{
		int temp;
		
		temp =l;
		
		l=m;
		m=temp;
		
	}
	if (m>n)
	{
		int temp1;
		
		temp1 =m;
		
		m=n;
		n=temp1;
	}
	if (l>m)
	{
		int temp2;
		
		temp2=l;
		
		l=m;
		m=temp2;
		
	}
	 
	
	
	printf("%d %d %d\n",l,m,n);
	
	// your code goes here
	return 0;
	
	
	
}



Measured memory_bytes: 2064