akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)

typedef pair<int, int> pii;
typedef vector<pii> vpii;

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

const int inf = 1e9;

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

int R;
int W[2], H[2];
int X[2], Y[2];
int A[2][502][502];

bool used[502][502];

vpii data[2];

void bfs(int num)
{
	typedef pair<int, pii> Data;
	memset(used, false, sizeof(used));

	priority_queue<Data> q;

	q.push(Data(-1, pii(Y[num], X[num])));
	used[Y[num]][X[num]] = true;

	if (num == 0) {
		data[num].PB(pii(1, 0));
	} else {
		data[num].PB(pii(0, 0));
		data[num].PB(pii(0, 1));
	}

	int ma = 1;
	int cnt = 0;
	int hoge = 0;

	while (q.size()) {
		Data p = q.top(); q.pop();

		int cur = -p.fst;

		if (ma < cur) {
			if (num == 0) {
				data[num].back().scd = cnt;
			} else {
				data[num].back().fst = cnt;
			}

			ma = cur;

			if (num == 0) {
				data[num].PB(pii(ma, 0));
			} else {
				data[num].PB(pii(0, ma));
			}
		}

		cnt++;

		rep(i, 4) {
			int ny = p.scd.fst + dy[i], nx = p.scd.scd + dx[i];

			if (ny < 0 || ny >= H[num] || nx < 0 || nx >= W[num] || used[ny][nx]) continue;
			used[ny][nx] = true;

			q.push(Data(-A[num][ny][nx], pii(ny, nx)));
		}
	}

	if (num == 0) {
		data[num].back().scd = cnt;
	} else {
		data[num].back().fst = cnt;
	}
}

signed main()
{
	while (cin >> R, R) {
		data[0].clear();
		data[1].clear();

		rep(i, 2) {
			cin >> W[i] >> H[i] >> X[i] >> Y[i];

			--X[i], --Y[i];

			rep(j, H[i]) rep(k, W[i]) {
				cin >> A[i][j][k];
			}
		}

		bfs(0);
		bfs(1);

		int mi = inf;

		data[1].PB(pii(inf, inf));

		rep(i, data[0].size()) {
			pii a = data[0][i];

			chmin(mi, a.fst + lower_bound(all(data[1]), pii(R - a.scd, -inf))->scd);
		}

		cout << mi << endl;
	}
}

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

int main() {
  int h, w, a, b;
  cin >> h >> w >> a >> b;

  for (int i = 1; i <= h; i ++) {
    for (int j = 1; j <= w; j ++) {
      if ((j <= a && i <= b) || (a < j && b < i)) cout << 1;
      else cout << 0;
    }
    cout << endl;
  }
}

Measured memory_bytes: 1280
H,N = map(int,input().split())

dp = [float("INF")]*(H+1)
dp[0] = 0
for i in range(N):
    a,b= map(int,input().split())
    for j in range(1,H+1):
        dp[j] = min(dp[j],dp[max((j-a),0)]+b)

print(dp[-1])

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


using namespace std;

const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;


#define DEBUG

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

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


int A, B;
int a[10010][10010], b[1000];
int dp[10010][3];
 
int main()
{
    double N; cin >> N;
    cout << N * 6.28318530717958623 << endl;

    return 0;
}


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

int main(void) {
	int N, M;
	vector<int> vn;

	cin >> N >> M;
	vn.resize(N + 1, 0);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		++vn[a];
		++vn[b];
	}

	bool flag = true;
	for (int i = 0; i <= N; ++i) {
		if (vn[i] % 2 != 0) {
			flag = false;
			break;
		}
	}

	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
	return 0;
}


Measured memory_bytes: 640
def main():

    n = int(input())
    a = list(map(int,input().split()))
    cnt_mns = 0
    mini = 10000000000
    sm = 0
    for i, aa in enumerate(a):
        if aa < 0:
            cnt_mns += 1

        if abs(aa) < mini:
            mini = abs(aa)
        sm += abs(aa)
    if cnt_mns % 2 == 1:
        print(sm - 2 * mini)
        
    else:
        print(sm)




if __name__ == '__main__':


    main()


Measured memory_bytes: 15020
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	string s;
	cin>>s;
	bool f = false;
	ll l = INF, r;
	FOR(i, 1, s.size()) {
		if(s[i] == s[i - 1]) {
			f = true;
			r = i + 1;
			l = i;
			break;
		}
	}
	FOR(i,2, s.size()) {
		if(s[i] == s[i - 2]) {
			f = true;
			r = i + 1;
			l = i - 1;
			break;
		}
	}
	if(l == INF) cout<<-1<<" "<<-1<<endl;
	else cout<<l<<" "<<r<<endl;
}


Measured memory_bytes: 512
float f,g;
int a[4],b[4];
main(i,j){
  for(;~scanf("%f%f",&f,&g);a[i]++,b[j]++)
    i=f<0.2?3:f<0.6?2:f<1.1?1:0,j=g<0.2?3:g<0.6?2:g<1.1?1:0;
  for(i=0;i<4;i++)
    printf("%d %d\n",a[i],b[i]);
  return 0;
}

Measured memory_bytes: 624
/*-----------------------------------------------
*	Filename: D.cpp
*	Author: zhuyutian
*	Date: 2018.08.11
-----------------------------------------------*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define mpii(a, b) make_pair(a, b)
const int maxn = 100005;
const int INF = 1 << 30;
const double eps = 1e-6;
const int mod = 1000000007;

int n,m;
map<int,int> mp;

int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d%d",&n,&m);
	int s = 0;
	ll ans = 0;
	mp[0] = 1;
	for(int i = 1; i <= n; i++) {
		int x; scanf("%d",&x);
		s = (s + x) % m;
		ans += mp[s];
		mp[s]++;
	}
	printf("%lld\n",ans);
	return 0;
}


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

const int MOD = (int)1e9+7;

int main(){
  int N;
  string s,t;
  cin >> N >> s >> t;

  for(int i=0;i<N+1;i++){
    bool flag=true;
    for(int j=0;j+i<N;j++){
      if(s.at(j+i)!=t.at(j))  flag=false;
    }
    if(flag){
      cout << N+i << endl;
      return 0;
    }
  }

  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> b(n+1, 0);
  rep(i, n) cin >> a[i];
  rep(ki, k){
    vector<int> b(n + 1);
    rep(i, n){
      int l = max(0, i - a[i]);
      int r = min(n, i + a[i]+1);
      b[l]++; b[r]--;
    }
    rep(i, n) b[i + 1] += b[i];
    b.pop_back();
    if(a == b) break;
    a = b;
  }
  rep(i, n) cout << a[i] << (i == n - 1 ? "\n" : " ");
}

Measured memory_bytes: 5632
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::input;
//use proconio::marker::Usize1;
// use proconio::marker::Chars;
// use std::collections::HashSet;
//use std::cmp::*;

const M: i64 = 1000_000_007i64;
fn main() {
    input! {
        Q:usize,
        lr:[(usize,usize);Q]

    }
    let mut rmax: usize = 200001;
    let mut primes = vec![true; rmax + 1];
    primes[0] = false;
    primes[1] = false;
    for i in 2..rmax + 1 {
        if !primes[i] {
            continue;
        }
        for j in 2..(rmax / i + 1) {
            primes[i * j] = false;
        }
    }

    let mut sum = vec![0usize; rmax + 1];
    //println!("{:?}", primes);
    // 1は素数ではない。
    sum[0] = 0;
    sum[1] = 0;
    for i in 1..rmax {
        sum[i] = sum[i - 1]
            + if i % 2 != 0 && primes[i] && primes[(i + 1) / 2] {
                1
            } else {
                0
            };
    }
    //println!("{:?}", sum);
    for (l, r) in lr {
        println!("{}", sum[r] - sum[l - 1]);
    }
}


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

using namespace std;


void solve() {
    int n; cin >> n;
    map<int, int> cnt;
    for (int _ = 0; _ < n; _++) {
        int x; cin >> x;
        cnt[x]++;
    }
    int res = 0;
    for (auto& p: cnt) {
        if (p.second & 1) res++;
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 4992
#include <iostream>

using namespace std;

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

    char C1, C2;
    int count = 1;
    cin >> C1;
    for (int i = 1; i < N; i++) {
        cin >> C2;
        if (C1 != C2) count++;
        C1 = C2;
    }

    cout << count << endl;
}

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

Measured memory_bytes: 580
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); 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 all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
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; }

using namespace std;
int a[3];


class UnionFind {
public:
    vector<int> rank, parent;

    UnionFind() {}

    UnionFind(int size) {
        rank.resize(size, 0);
        parent.resize(size, 0);
        for (int i = 0; i < size; ++i) {
            makeSet(i);
        }
    }

    void makeSet(int x) {
        parent[x] = x;
        rank[x] = 0;
    }

    void link(int x, int y) {
        if (rank[x] > rank[y]) {
            parent[y] = x;
        } else {
            parent[x] = y;
            if (rank[x] == rank[y]) {
                ++rank[x];
            }
        }
    }

    bool same(int x, int y) {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y) {
        link(findSet(x), findSet(y));
    }

    int findSet(int x) {
        if (parent[x] != x) {
            parent[x] = findSet(parent[x]);
        }
        return parent[x];
    }
};
int p[100000];
int x[100000];
int y[100000];
int main() {
    int n, m;
    cin >> n >> m;
    UnionFind* uf = new UnionFind(n);
    rep(i, n) {
        cin >> p[i];
    }
    rep(i, m){
        cin >> x[i] >> y[i];
        uf->unite(x[i]-1, y[i]-1);
    }
    int ans = 0;
    rep(i, n){
        if(uf->same(p[i]-1, i)) ans++;
    }
    cout << ans << endl;
}


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

int main()
{
	string s, t;
	cin >> s >> t;
	bool ans = false;
	for(auto i = (int)s.size() - (int)t.size(); i >= 0; --i){
		bool match = true;
		for(auto j = 0; j < (int)t.size(); ++j){
			if(s[i + j] == '?') continue;
			if(s[i + j] != t[j]){
				match = false;
				break;
			}
		}
		if(match){
			for(auto j = 0; j < (int)t.size(); ++j){
				s[i + j] = t[j];
			}
			ans = true;
			break;
		}
	}
	if(ans){
		for(auto i = 0; i < (int)s.size(); ++i){
			cout << (s[i] == '?' ? 'a' : s[i]);
		}
		cout << endl;
	}else{
		cout << "UNRESTORABLE" << endl;
	}
	return 0;
}

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

int main() {
  vector <string> s(3);
  for(int i = 0; i < 3; i++){
    cin >> s.at(i);
  }
  cout << char(s.at(0).at(0) - 32) << char(s.at(1).at(0) - 32) << char(s.at(2).at(0) - 32) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int solve(int K){
		int init = 7 % K;
		if(init == 0){
			return 1;
		}
		int vis[] = new int[K + 1];
		vis[init] = 1;
		for(int i = 2 ; ; ++i){
			init = init * 10 + 7;
			init = init % K;
			if(init == 0){
				return i;
			}
			if(vis[init] == 1){
				return -1;
			}
			vis[init] = 1;
		}		
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		System.out.println(solve(K));
	}
}


Measured memory_bytes: 39592
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();

    let mut counts: Vec<usize> = vec![0; n];
    for _ in 0..m {
        let ai: usize = iterator.next().unwrap().parse().unwrap();
        let bi: usize = iterator.next().unwrap().parse().unwrap();
        counts[ai - 1] += 1;
        counts[bi - 1] += 1;
    }

    if counts.iter().all(|&x| x % 2 == 0) {
        "YES".to_string()
    } else {
        "NO".to_string()
    }
}


Measured memory_bytes: 3928
#include "bits/stdc++.h"

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>

void print(T x)
{
	std::cout << x <<" " ;
}


signed main(void) {
	double W, H;
	int x, y;
	cin >> W>> H>> x >> y  ;
	double area = W * H / 2;
	print(area);
	if (x == W / 2 && y == H / 2) print(1);
	else print(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
	lld n,t[100] = {0},m,p[100],x[100];

	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> t[i];
	}
	cin >> m;
	for(int i = 0; i < m; i++)
	{
		cin >> p[i] >> x[i];
	}

	lld sum = accumulate(t,t+n,0);

	for(int i = 0; i < m; i++)
	{
		lld sol = sum;
		sol -= t[p[i]-1];
		sol += x[i];
		cout << sol << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import fractions

N, M = map(int, input().split())
S = input()
T = input()

# 最小公倍数を求める
l = (N * M) // fractions.gcd(N, M)

ans = {1: S[0]}
for i in range(1, N):
    c_num = i*l//N+1
    ans[c_num] = S[i]

for i in range(M):
    if i == 1:
        if ans[1] != T[0]:
            print(-1)
            exit(0)

    c_num = i*l//M+1
    if c_num in ans:
        if ans[c_num] != T[i]:
            print(-1)
            exit(0)
    else:
        ans[c_num] = T[i]
print(l)


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

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

    int N;
    cin >> N;
    for (int i = 0; i <= 9; i++) {
        for (int j = 0; j <= 9 ; j++) {
            if (i * j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>

using namespace std;

void b_golden_apple(void) {
	int n, d;
	cin >> n >> d;

	int cnt = 0;

	int div = (d << 1) + 1;

	if (n % div == 0) {
		cnt = n / div;
	}
	else {
		cnt = n / div + 1;
	}

	cout << cnt << endl;
}

int main()
{
    b_golden_apple();

    return 0;
}

Measured memory_bytes: 3612
S = input()

if S[0] == 'A':
    c = list(S[2:-1])
    if c.count('C') == 1:
        p = c.index('C')
        c.pop(p)
        ans = list(S[1]) + c + list(S[-1])
        anss = ''.join(ans)
        if anss.islower():
            print('AC')
        else:
            print('WA')
    else:
        print('WA')
else:
    print('WA')

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

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

  if(a%b==0) puts("-1");
  else {
  cout << a << endl;
  }
  
}


Measured memory_bytes: 256
s = int(input())

def f(n) :
    if n % 2 == 0 :
        return int(n/2)
    else :
        return 3*n + 1

a = [-1] * 1000000
a[0] = s
ans = 0

for i in range(1,1000000) :
    val = f(a[i-1])
    if val in a :
        ans = i + 1
        break
    a[i] = val

print(ans)



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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()

const int MAX = 3e5+10;

ll N, A, B;

void solve() {
    bool check = true;
    check &= (A+B <= N+1);
    check &= (A*B >= N);
    if (!check) {
        cout << -1 << endl;
        return;
    }

    viii res;
    REP (a, A) {
        res.PB(MT(2*MAX, a, a));
    }
    REP (b, B-1) {
        res.PB(MT(-2*MAX, -b, A+b));
    }
    FOR (i, A+B-1, N) {
        int k = i-(A+B-1);
        res.PB(MT(MAX-k/(A-1), k%(A-1), i));
    }
    sort(ALL(res));
    vi ans(N);
    REP (i, N) {
        ans[get<2>(res[i])] = i+1;
    }
    REP (i, N) {
        cout << ans[i] << ((i==N-1)?"\n":" ");
    }
}

int main() {
    cin >> N >> A >> B;
    solve();
}

Measured memory_bytes: 14572
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  ll ans = 0;
  ll A, K;
  ll tmp;
  ll l, r, m;
  for(int i=0;i<N;++i) {
    cin>>A>>K;
    while(A%K!=0) {
      tmp = A/K+1;
      l = 0;
      r = A/tmp+1;
      if(A<K) {
        A = 0;
        break;
      }
      if((A-(A/K*K))%tmp==0) {
        A = A/K*K;
        break;
      }
      while(l<r) {
        m = (l+r)/2;
        if((A-m*tmp)/K+1<tmp) r = m;
        else l = m+1;
      }
      A -= l*tmp;
    }
    ans ^= A/K;
  }
  if(ans==0) cout<<"Aoki"<<endl;
  else cout<<"Takahashi"<<endl;
}




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

int main(void){
  while(1){
    int n; cin >> n;
    if(n == 0) break;
    vector<int> a(n);
    for(auto& _a: a){
      cin >> _a;
    }
    sort(a.begin(), a.end());
    int ans = 1000000*2;
    for(int i = 1; i < a.size(); i++){
      ans = min(ans, a[i] - a[i-1]);
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3140
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>

using namespace std;
using ll = long long int;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
//#define MOD 1000000007 //10^9+7
#define MOD 10007

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

int main(void){

  ll s,w;
  cin>>s>>w;

  if(w>=s) cout<<"unsafe"<<endl;
  else cout<<"safe"<<endl;
  return 0;
}

Measured memory_bytes: 3636
import sys

input=sys.stdin.readline

N=int(input())
A=[]
B=[]
C=[]
for _ in range(0,N):
    a,b,c=map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(c)

dp=[[0 for i in range(0,3)] for j in range(0,N)]
dp[0][0]=max(B[0],C[0])
dp[0][1]=max(A[0],C[0])
dp[0][2]=max(B[0],A[0])
for i in range(1,N):
    dp[i][0]=max(dp[i-1][1]+B[i],dp[i-1][2]+C[i])
    dp[i][1]=max(dp[i-1][0]+A[i],dp[i-1][2]+C[i])
    dp[i][2]=max(dp[i-1][0]+A[i],dp[i-1][1]+B[i])

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

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

#define debug(x) cerr << "> " << #x << "\n" << x << endl;

template <typename T1, typename T2>
ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1) s << "\t";
  }
  return s;
}
template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& s, const map<T1, T2>& m) {
  s << "{" << endl;
  for (auto itr = m.begin(); itr != m.end(); ++itr) {
    s << "\t" << (*itr).first << " : " << (*itr).second << endl;
  }
  s << "}" << endl;
  return s;
}

template <typename T>
struct Dijkstra {
  struct Edge {
    int to;
    T cost;
  };
  vector<int> prev;
  vector<vector<Edge>> g;
  Dijkstra() {}
  Dijkstra(int n) : prev(n), g(n) {}

  void addEdge(int u, int v, T w) {
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  vector<T> build(int s) {
    vector<T> dist(g.size(), -1);
    prev.assign(g.size(), -1);
    using Node = pair<T, int>;
    priority_queue<Node, vector<Node>, greater<Node>> pq;
    pq.push({dist[s] = 0, s});

    while (!pq.empty()) {
      auto d = pq.top().first;
      auto u = pq.top().second;
      pq.pop();
      if (dist[u] < d) continue;
      for (auto&& v : g[u]) {
        if (dist[v.to] < 0 || dist[v.to] > dist[u] + v.cost) {
          dist[v.to] = dist[u] + v.cost;
          prev[v.to] = u;
          pq.push({dist[v.to], v.to});
        }
      }
    }
    return dist;
  }
  vector<int> getPath(int t) {
    vector<int> path;
    for (; t != -1; t = prev[t]) path.push_back(t);
    reverse(begin(path), end(path));
    return path;
  }
};

vector<int> color;
vector<int> c;
Dijkstra<int> g;
int p = 0;

void dfs(int s) {
  if (color[s] != -1) return;
  color[s] = 0;
  for (auto&& t : g.g[s]) {
    if (color[t.to] != -1) continue;
    dfs(t.to);
  }
  color[s] = c[p++];
}

int main() {
  int n;
  cin >> n;
  g = Dijkstra<int>(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g.addEdge(a, b, 1);
  }
  c.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    c[i]--;
  }
  sort(begin(c), end(c));
  auto d1 = g.build(0);
  int s = -1, mx1 = 0;
  for (int i = 0; i < n; i++) {
    if (d1[i] > mx1) {
      mx1 = d1[i];
      s = i;
    }
  }
  color.assign(n, -1);
  dfs(s);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += c[i] + 1;
  }
  cout << sum - (c[n - 1] + 1) << endl;
  for (int i = 0; i < n; i++) {
    cout << color[i] + 1 << ((i == n - 1) ? '\n' : ' ');
  }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define Fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long

int32_t main(){	
	Fast_IO
	// #ifndef ONLINE_JUDGE 
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w",stdout);
	// #endif
	int n;cin>>n;
	vector<int> a(n+1,0);
	vector<int> b(n+1,0);
	for(int i = 1; i<=n;i++)
		cin>>a[i];
	for(int j = 1; j<=n;j++)
		cin>>b[j];
	vector<int> prefixa(n+2,0);
	vector<int> suffixb(n+2,0);
	for(int i = 1; i<=n;i++){
		prefixa[i] = prefixa[i-1] + a[i];
	}
	for(int i = n;i>=1;i--){
		suffixb[i] = suffixb[i+1] + b[i];
	}
	int ans = 0;
	for(int i = 1;i<=n;i++){
		ans = max(ans,prefixa[i]+suffixb[i]);
	}
	cout<<ans;


}

Measured memory_bytes: 256
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

void read_problem(vector<int>& s, vector<int>& t)
{
    int n;
    scanf("%d", &n);

    s.resize(n);
    REP(i, n) {
        scanf("%d", &s[i]);
    }

    int q;
    scanf("%d", &q);

    t.resize(q);
    REP(i, n) {
        scanf("%d", &t[i]);
    }
}

int solve(const vector<int>& s, const vector<int>& t)
{
    int cnt = 0;

    for(int e : t) {
        if(binary_search(s.begin(), s.end(), e)) ++cnt;
    }

    return cnt;
}

int main()
{
    vector<int> s;
    vector<int> t;
    read_problem(s, t);

    int result = solve(s, t);
    printf("%d\n", result);

    return 0;
}

Measured memory_bytes: 2832
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n;
    cin>>n;
    vector<vector<long long int>> grid(3,vector<long long int>(n));
    REP(i,3){REP(j,n){
            cin >> grid[i][j];
        }
        sort(grid[i].begin(), grid[i].end());
    }

    long long int result = 0;

    REP(i,n){
        result += (distance(grid[0].begin(),lower_bound(grid[0].begin(), grid[0].end(), grid[1][i])) * (distance(upper_bound(grid[2].begin(),grid[2].end(),grid[1][i]),grid[2].end())));
    }
    cout << result << endl;
    return 0;

}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, K, T, W, H, M, C;

const int MAX = 510000;
const int MOD = 1e9;

const double PI=3.14159265358979323846;

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

vector<double> cx, cy, c;
 ll MM = 1e12;

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;
}

std::vector<int> Eratosthenes(int n ){
    std::vector<bool> is_prime( n + 1 );
    for( int i = 0; i <= n; i++ ) is_prime[ i ] = true;
    std::vector<int> P;
    for( int i = 2; i <= n; i++ ){
        if( is_prime[ i ] ){
            for( int j = 2 * i; j <= n; j += i ){
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}*/

int length(vector<int> v, int u, int HW){
    if(v.size() == 0) return HW;
    if(v[0] > u) return v[0];
    if(v[v.size() - 1] < u) return HW - v[v.size()- 1] -1;
    else{
        int i = lower_bound(ALL(v), u)- v.begin();
        return v[i] - v[i-1] -1;
    }
}

int main(){
    cin >> H >> W;
    vector<vector<int>> dp(H*W, vector<int> (H*W, 1e4));
    REP(i, H*W) dp[i][i] = 0;
    vector<bool> lattice(H*W, 0);
    string str;
    REP(i, H){
        cin >> str;
        REP(j ,W){
            if(str[j] == '#') lattice[i * W + j] = 1;
        }
    }
    REP(i,H){
        REP(j, W){
            if(lattice[i * W + j]) continue; 
            int p = i * W + j;
            int p_down = (i + 1) * W + j;
            int p_right = i * W + j + 1;
            if(j < W-1 and !lattice[p_right]) {dp[p][p_right] = 1; dp[p_right][p] = 1;}
            if(i < H-1 and !lattice[p_down]) {dp[p][p_down] = 1; dp[p_down][p] = 1;}
        }
    }

    int V = H * W;
    REP(k,V){
        REP(i, V){
            REP(j, V){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }
    int ans = -1;
    REP(i, V){
        REP(j ,V){
            if(i == j) continue;
            if(dp[i][j] >= 1e4) continue; 
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;


//D
struct LLPair {
	int a = 0;
	int b = 0;
	LLPair() {}
	LLPair(int a, int b) {
		this->a = a;
		this->b = b;
	}
};

int main() {
	int N;
	scanf("%d", &N);
	vector<LLPair> e(N - 1);
	for (int i = 0; i < N - 1; i++) {
		scanf("%d %d", &e[i].a, &e[i].b);
		e[i].a--;
		e[i].b--;
	}

	vector<map<int, int>> mp(N, map<int, int>()); //node[N] ���� node[N][next]�ւ̃G�b�W��index 

	vector<vector<int>> graph(N, vector<int>(0));
	for (int i = 0; i < N - 1; i++) {
		graph[e[i].a].push_back(e[i].b);
		graph[e[i].b].push_back(e[i].a);
		mp[e[i].a][e[i].b] = i;
		mp[e[i].b][e[i].a] = i;
	}

	vector<int> result(N - 1);
	int maxColor = 0;

	queue<LLPair> q;
	q.push(LLPair(0, -1)); //node:0 �e��color:-1

	vector<bool> visited(N, false);

	while (q.empty() == false) {
		LLPair node = q.front();
		q.pop();
		visited[node.a] = true;

		int color = 1;
		for (auto next : graph[node.a]) { 
			if (visited[next] == true) {
				//�e
				continue;
			}

			if (node.b == color) {
				//�e-�c����Ƃ͈Ⴄ�F��
				color++;
			}

			q.push(LLPair(next, color));
			maxColor = max(maxColor, color);
			result[mp[node.a][next]] = color;

			color++;
		}
	}

	printf("%d\n", maxColor);
	for (auto val : result) {
		printf("%d\n", val);
	}
}



//C
/*
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

ll A;
ll B;
ll X;

//2���T���̑ΏۂƂȂ�֐�(�P������)
ll BinarySearchFunc(ll x) {
	return A * x + B * GetDigit(x);
}

//2���T���̃e���v���[�g
ll BinarySearch(ll left, ll right, ll key) {
	while (right != left) {
		ll mid = (right + left + 1) / 2;
		ll val = BinarySearchFunc(mid);

		if (val > key) { //���̏�������K�v�ɉ����ĕς���
			right = mid - 1;
		}
		else {
			left = mid;
		}
	}
	return right;
}

int main() {
	scanf("%lld", &A);
	scanf("%lld", &B);
	scanf("%lld", &X);

	ll result;

	if (BinarySearchFunc(1000000000) <= X) {
		result = 1000000000;
	}
	else if(BinarySearchFunc(1) > X) {
		result = 0;
	}
	else {
		result = BinarySearch(0, 1000000000, X);
	}

	printf("%lld\n", result);
}
*/

//B
/*
int main() {
	ll N;
	scanf("%lld", &N);
	char S[101010];
	scanf("%s", S);
	ll len = strlen(S);

	for (ll i = 0; i < len; i++) {
		char c = S[i] + N;
		if (c > 'Z') {
			c -= 26;
		}

		S[i] = c;
	}

	printf("%s\n", S);
}
*/

//A
/*
int main() {
	string arr[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
	
	string s;
	cin >> s;

	ll result = 0;

	for (ll i = 0; i < 7; i++) {
		if (s == arr[i]) {
			result = 7 - i;
			break;
		}
	}

	printf("%lld\n", result);
}
*/


Measured memory_bytes: 21376
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//CODE
void solve(void)
{
  int A,B,K;
  cin>>A>>B>>K;
  for (int i = 0; i < B+1; i++)
  {
    if(((i >= A)&&(i<A+K)&&(i<=B))||((i >= B-K+1)&&(i<=B)&&(i>=A)))
    cout<<i<<endl;
  }
  
  
  
  

  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
#define fi first
#define se second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  string s, t;
  cin >> s >> t;

  int orig_s = sz(s);
  s += s;
  unordered_map<char, vec<int>> cnt;
  rep(i, 0, sz(s)) cnt[s[i]].pb(i);

  ll loop = 0;
  int index = -1;
  rep(i, 0, sz(t)) {
    if (sz(cnt[t[i]]) == 0) {
      put(-1);
      return 0;
    }

    index = *upper_bound(all(cnt[t[i]]), index);
    if (index < orig_s) continue;
    loop++;
    index -= orig_s;
  }

  put(loop * orig_s + index + 1);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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 <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 1788
n = int(input())
for i in range(n):
    r = 0
    p = 0
    o = 0
    while o < 3:
        e = input()
        if e == "OUT":
            o += 1
        elif e == "HIT":
            if r == 3:
                p += 1
            else:
                r += 1
        else:
            p += r + 1
            r = 0
    print(p)

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    cout << A * B / 2 << endl;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  int N, A, B;
  cin >> N >> A >> B;

  int P1 = A*N;
  int P2 = B;

  if(P1 > P2)
    cout << P2 << endl;
  else
    cout << P1 << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]

M = 0
A = 0
R = 0
C = 0
H = 0
res = 0
for s in S:
    if s[0] == 'M':
        M += 1
    elif s[0] == 'A':
        A += 1
    elif s[0] == 'R':
        R += 1
    elif s[0] == 'C':
        C += 1
    elif s[0] == 'H':
        H += 1

for m in range(2):
    for a in range(2):
        for r in range(2):
            for c in range(2):
                for h in range(2):
                    if m+a+r+c+h == 3:
                        temp = 1
                        if m == 1:
                            temp *= M
                        if a == 1:
                            temp *= A
                        if r == 1:
                            temp *= R
                        if c == 1:
                            temp *= C
                        if h == 1:
                            temp *= H
                        res += temp
                            
print(res)

Measured memory_bytes: 9776
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=2e5+5;
int n,a[maxn];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(int i=n-1;i>=0;i-=2){
        if(i!=n-1)printf(" ");
        printf("%d",a[i]);
    }
    int i=0;
    if(n%2)i=1;
    for(;i<n;i+=2){
        printf(" %d",a[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
    int n,m,state=0;//??????
    bool flag;
    cin >> n;
    vector<string> u(n);
    for(int j = 0; j<n; j++) {
        cin >> u[j];
    }
    cin >> m;
    vector<string> t(m);
    for(int i = 0; i<m; i++) {
        cin >> t[i];
    }
    for(int i = 0; i<m; i++) {
        flag = false;
        for(int j = 0; j<n; j++) {
            if (u[j] == t[i]) flag = true;
        }
        if (flag == true) {
            if (state == 0) {
                cout << "Opened by " << t[i] << endl;
                state = 1;
            } else {
                cout << "Closed by " << t[i] << endl;
                state = 0;
            }
        } else {
            cout << "Unknown " << t[i] << endl;
        }
    }
        return 0;
}

Measured memory_bytes: 3212
N,M = list(map(int, input().split()))
lis=[]
for i in range(N):
    a,b = list(map(int, input().split()))
    lis.append([a,b])

lis.sort()

count=0
money=0
ind=0
while count+lis[ind][1]<M:
    count+=lis[ind][1]
    money+=lis[ind][0]*lis[ind][1]
    ind+=1
    #print(ind)
    

money+=(M-count)*lis[ind][0]
print(int(money))

Measured memory_bytes: 20460
#include <bits/stdc++.h>
#define SEKAI_NO_OWARI return 0;
#define INIT cin.tie(0); ios::sync_with_stdio(false);
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

void solve() {
	int n; cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}

	int res = 0;
	for (int i = 1; i < n - 1; i++) {
		if ((p[i - 1] < p[i]) && (p[i] < p[i + 1])) {
			res++;
		}
		else if ((p[i - 1] > p[i]) && (p[i] > p[i + 1])) {
			res++;
		}
	}
	cout << res << endl;
}

int main(void) {
	//INIT
	solve();
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = list(str(input()))


# 初期スコア
count = 0
for i in range(1, n):
    if s[i] == 'E':
        count += 1


arr = [0] * n
arr[0] = count
for i in range(1,n):
    if s[i] == 'E':
        count -= 1
    if s[i-1] == 'W':
        count += 1
    arr[i] = count

print(min(arr))


Measured memory_bytes: 17592
from cmath import phase

N, *XY = map(int, open(0).read().split())

XY = sorted((complex(x, y) for x, y in zip(*[iter(XY)] * 2)), key=phase)
XY += XY


ans = 0
for i in range(2 * N + 1):
    for j in range(2 * N + 1):
        if j - i <= N:
            ans = max(ans, abs(sum(XY[i:j])))

print(ans)

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

int main()
{
  long long int N, A, B;
  cin >> N >> A >> B;
  long long int ans1 = 0, ans2 = 0, ans3 = 0, ans4 = 0, ans5 = 0;
  ans1 = max(A - 1, B - 1);
  ans2 = max(N - A, N - B);
  long long int ans = 1LL << 60;
  if ((max(A, B) - min(A, B)) % 2 == 0)
  {
    ans3 = (max(A, B) - min(A, B)) / 2;
    ans = min(ans, ans1);
    ans = min(ans, ans2);
    ans = min(ans, ans3);
  }
  else
  {
    ans4 = min(A, B) + (max(A, B) - min(A, B) - 1) / 2;
    ans5 = N - max(A, B) + 1 + (max(A, B) - min(A, B) - 1) / 2;
    ans = min(ans, ans1);
    ans = min(ans, ans2);
    ans = min(ans, ans4);
    ans = min(ans, ans5);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
//Name: Four Arithmetic Operations
//Level: 4
//Category: 数学
//Note:

/**
 * 最後の答えが必ず-2^31から2^31の範囲の整数に収まるので、2^32より大きな素数を法とした有限体の上で計算すればよい。
 * 途中で乗算が64bitに収まらない可能性があるので、乗算は自前でビットシフトを使ったものを実装するとよい。
 *
 * オーダーは O(N log P)。
 */
#include <iostream>

using namespace std;

const long long MOD = 8589934609LL; // 2^33 + 17

long long mul(long long a, long long b) {
    long long res = 0;
    while(b) {
        if(b & 1) {
            res += a;
            res %= MOD;
        }
        a *= 2;
        a %= MOD;
        b /= 2;
    }
    return res;
}

long long modpow(long long a, long long x) {
    long long res = 1;
    while(x) {
        if(x & 1) {
            res = mul(res, a);
        }
        a = mul(a, a);
        x /= 2;
    }
    return res;
}

bool solve() {
    int N;
    if(!(cin >> N)) return false;

    long long x = 0;
    for(int i = 0; i < N; ++i) {
        int o;
        long long y;
        cin >> o >> y;
        if(o == 1) {
            x += y;
            x %= MOD;
        } else if(o == 2) {
            x -= y;
            x += MOD;
            x %= MOD;
        } else if(o == 3) {
            x = mul(x, (y + MOD) % MOD);
        } else if(o == 4) {
            x = mul(x, modpow((y + MOD) % MOD, MOD-2));
        }
    }
    if(x >= (1LL<<31)) x -= MOD;
    cout << x << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

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

using namespace std;

const int N = 1e6 + 6;

int a[N];

int main() {
  long long ans1 = 0, ans2 = 0;
  long long now1 = 0, now2 = 0;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a+i);
    now1 += a[i];
    now2 += a[i];
    if (i & 1) {
      if (now1 <= 0) {
        ans1 += 1 - now1;
        now1 = 1;
      }
      if (now2 >= 0) {
        ans2 += now2 + 1;
        now2 = -1;
      }
    }
    else {
      if (now1 >= 0) {
        ans1 += now1+1;
        now1 = -1;
      }
      if (now2 <= 0) {
        ans2 += 1 - now2;
        now2 = 1;
      }
    }
  }
  cout << min(ans1, ans2) << endl;
  return 0;
}

Measured memory_bytes: 640
using System;

namespace atcorder
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            atcorder.Cut_and_Count.Run();
        }
    }
  public class Cut_and_Count
    {
        public Cut_and_Count()
        {
        }
        public static void Run(){
            int N;
            string S;
            string s = Console.ReadLine();
            N = int.Parse(s);
            S = Console.ReadLine();
            int count = 0;
            for (int i = 0; i < S.Length;i++){
                if (S.Length == 0) break;
                string pre = S.Substring(0, i);
                string suf = S.Substring(i);
                System.Collections.Generic.HashSet<char> hash_pre = new System.Collections.Generic.HashSet<char>(pre);
                System.Collections.Generic.HashSet<char> hash_suf = new System.Collections.Generic.HashSet<char>(suf);
                int n;
                hash_pre.IntersectWith(hash_suf);
                n = hash_pre.Count;
                if (count < n) count = n;
            }
            Console.WriteLine(count);
        }

    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int a,b;
ll ans=0;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>a>>b;
    if(b<a) swap(a,b);  //a<b

    {
        ll i=1;
        while(ans<LONG_MAX){
            if((a*i)%b==0){
                ans=a*i;
                break;
            }
            i++;
        }
    }

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

Measured memory_bytes: 256