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

int main(){
  int N;
  cin >> N;
  int A[N];
  int ans=0;
  
  for(int i=0;i<N;i++){
  	cin >> A[i];
  }//入力完了
  
  while(1){
  	int i=0;
    while(i<N){
      if(A[i]%2==0){
          A[i]/=2;
          i++;
      }else{
          break;
      }
    }//A[i]が全て偶数ならi=N,違うならiはN未満
    if(i==N){
      ans++;
    }else{
    	break;
    }
  }
  cout << ans << endl;  
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import math

def main():
     a, b, c, d = map(int, input().split())

     t_hit = math.ceil(c / b)
     a_hit = math.ceil(a / d)

     if t_hit <= a_hit:
          print('Yes')
     else:
          print('No')

if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;

int main() {
    ll n,i,j;
    cin >> n;
    vector<ll> v(n + 1);
    for(i = 1; i <= n; i++) {
        cin >> v[i];
    }
    ll dp[n + 1][n + 1];
    for(i = 1; i <= n;i++){
        for(j = 1; j <= n - i; j++) {
            if(n % 2 == i % 2)dp[j][j + i - 1] = -1e13;
            else dp[j][j + i - 1] = 1e13;
        }
    }
    for(i = 0; i <= n;i++){
        if(n % 2 == 1) dp[i][i] = v[i];
        else dp[i][i] = -v[i];
    }
    for(i = 2; i <= n;i++){
        for(j = 1; j <= n - i + 1; j++){
            if(n % 2 == i % 2) {
                // 先手
                dp[j][j + i - 1] = max(dp[j + 1][j + i - 1] + v[j], dp[j][j + i - 2] + v[j + i - 1]);
            }
            else{
                // 後手
                dp[j][j + i - 1] = min(dp[j + 1][j + i - 1] - v[j], dp[j][j + i - 2] - v[j + i - 1]);
            }
        }
    }
    cout << dp[1][n] << endl;
    return 0;
}

Measured memory_bytes: 70400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);



int main() {

    int n,x,t;
    cin >> n >> x >> t;
    int aff = n/x;
    if(n%x != 0)aff+=1;
    if(n == x){
    	cout << t << endl;
    }else{
    	cout << aff*t << endl;
    }
}






















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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

ll solve(vector<ll> b_sum, ll x) {
    ll ok = -1;
    ll ng = b_sum.size();
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;

        if (x >= b_sum[mid]) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n + 1), b(m + 1), b_sum(m + 1, 0);
    a[0] = 0;
    rep(i, n) cin >> a[i + 1];
    rep(i, m) {
        cin >> b[i];
        b_sum[i + 1] = b_sum[i] + b[i];
    }
    ll sum = 0, ans = 0;
    // rep(i, m + 1) cout << b_sum[i] << " ";
    // cout << endl;

    rep(i, n + 1) {
        sum += a[i];
        if (sum > k) break;
        // cout << "x = " << k - sum << endl;
        auto itr = upper_bound(b_sum.begin(), b_sum.end(), k - sum);
        // cout << "value = " << *itr << endl;
        ll num = itr - b_sum.begin() - 1;
        // ll num = solve(b_sum, k - sum);
        // cout << "i = " << i + 1 << " num = " << num << endl;
        ans = max(ans, num + i );
    }
    cout << ans << endl;

}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		if(N == 3){
			Console.WriteLine(2);
			Console.WriteLine("1 3");
			Console.WriteLine("2 3");
			return;
		}
		if(N % 2 == 0){
			int[][] a = new int[N][];
			for(int i=0;i<N;i++) a[i] = new int[N];
			for(int i=0;i<N;i++) for(int j=0;j<N;j++) if(i != j) a[i][j] = 1;
			for(int i=0;i<N;i++) a[i][N-1-i] = 0;
			int cnt = 0;
			for(int i=0;i<N;i++) for(int j=i+1;j<N;j++) cnt += a[i][j];
			Console.WriteLine(cnt);
			for(int i=0;i<N;i++){
				for(int j=i+1;j<N;j++){
					if(a[i][j] == 1) Console.WriteLine("{0} {1}",i+1, j+1);
				}
			}
		} else {
			int[][] a = new int[N][];
			for(int i=0;i<N;i++) a[i] = new int[N];
			for(int i=0;i<N;i++) for(int j=0;j<N;j++) if(i != j) a[i][j] = 1;
			for(int i=0;i<N-1;i++) a[i][N-2-i] = 0;
			int cnt = 0;
			for(int i=0;i<N;i++) for(int j=i+1;j<N;j++) cnt += a[i][j];
			Console.WriteLine(cnt);
			for(int i=0;i<N;i++){
				for(int j=i+1;j<N;j++){
					if(a[i][j] == 1) Console.WriteLine("{0} {1}",i+1, j+1);
				}
			}
		}
	}
	int N;
	public Sol(){
		N = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
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;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int N;cin>>N;
    int oc=0;
    REP(i,N){
        int a;cin>>a;
        if(a%2==1)oc++;
    }
    cout<<(oc%2==0?"YES":"NO")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	int N, L;
  int sum = 0;
  cin >> N >> L;
  if(L >= 0){
  	for(int i = 1; i < N; i++){
    	sum += L + i;
    }
  }
  
  if(L < 0 && L + N - 1 >= 0){
  	for(int i = 0; i < N; i++){
    	sum += L + i;
    }
  }
  
  if(L < 0 && L + N - 1 < 0){
  	for(int i = 0; i < N - 1; i++){
    	sum += L + i;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
 
int s,n; 
cin>>s;
n = s;
int sum = 0;
while(n>0){
    sum = sum + n%10;
    n = n/10;
}
 
if(s%sum==0){
    cout<<"Yes"<<endl;
    return 0;
}
cout<<"No"<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define sz(a) (a).size()
#define pb(a) push_back(a)
#define eb(...) emplace_back(__VA_ARGS__)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
using namespace std;
using pii = pair<int, int>;
constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr double EPS = 1e-10;

struct edge {
  int f, t, c;
  edge() {}
  edge(int f, int t, int c) : f(f), t(t), c(c) {}
  bool operator < (const edge& e) {
    return c < e.c;
  }
};

int N;
vector<pair<pii, int>> ps;
vector<edge> es;
int par[100010];

int find(int x) {
  return par[x] < 0 ? x : par[x] = find(par[x]);
}

void unite(int x, int y) {
  x = find(x); y = find(y);
  if (x == y) return;
  if (par[x] > par[y]) swap(x, y);
  par[x] += par[y];
  par[y] = x;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  rep(i, 0, N) {
    int x, y;
    cin >> x >> y;
    ps.eb(pii(x, y), i);
  }
  sort(all(ps));
  rep(i, 0, N-1) {
    auto p = ps[i];
    auto q = ps[i+1];
    es.eb(p.second, q.second, q.first.first-p.first.first);
  }
  rep(i, 0, N) {
    auto p = ps[i];
    swap(p.first.first, p.first.second);
    ps[i] = p;
  }
  sort(all(ps));
  rep(i, 0, N-1) {
    auto p = ps[i];
    auto q = ps[i+1];
    es.eb(p.second, q.second, q.first.first-p.first.first);
  }

  fill(par, par+N, -1);
  sort(all(es));

  int ans = 0;
  rep(i, 0, sz(es)) {
    int u = find(es[i].f);
    int v = find(es[i].t);
    if (u == v) continue;
    unite(u, v);
    ans += es[i].c;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 10864
#include<stdio.h>
int main()
{
	char s[100005], t[100005];
	scanf("%s%s", s, t);
	int q;
	scanf("%d", &q);
	int a[100005], b[100005], c[100005], d[100005];
	int i;
	for (i = 0; i < q; i++)
		scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
	int vs[100005], vt[100005];
	vs[0] = 0;
	for (i = 0; s[i] != '\0'; i++)
	{
		if (s[i] == 'A')
			vs[i + 1] = vs[i] + 1;
		else
			vs[i + 1] = vs[i] + 2;
	}
	vt[0] = 0;
	for (i = 0; t[i] != '\0'; i++)
	{
		if (t[i] == 'A')
			vt[i + 1] = vt[i] + 1;
		else
			vt[i + 1] = vt[i] + 2;
	}
	for (i = 0; i < q; i++)
	{
		if ((vs[b[i]] - vs[a[i] - 1]) % 3 != (vt[d[i]] - vt[c[i] - 1]) % 3)
			printf("NO\n");
		else
			printf("YES\n");
	}
	return 0;
}

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int h, a;
	cin >> h >> a;
	for (int x; a--; ) cin >> x, h -= x;
	if (h <= 0) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}


Measured memory_bytes: 256
mod = 10 ** 9 + 7

class Facts
  
  def initialize(mod=10**9+7, n_max=1)
    @mod = mod
    @n_max = n_max
    @fact = [1, 1]
    @inv = [0,1]
    @factinv = [1, 1]
    setup_table(t) if 1 < @n_max 
  end
  
  def cmb(n,r)
    return 0 if r < 0 || n < r
    setup_table(n) if @n_max < n
    @fact[n] * (@factinv[r] * @factinv[n-r] % @mod) % @mod
  end
  
  def factorial(n)
    setup_table(n) if @n_max < n
    @fact[n]
  end
  
  def prm(n,k)
    setup_table(n) if @n_max < n
    @fact[n] * @factinv[n-k] % @mod
  end
  
  private
  def setup_table(t)
    (@n_max+1).upto(t) do |i|
      @fact.push( @fact[-1] * i % @mod )
      @inv.push( -@inv[@mod % i] * (@mod / i) % @mod )
      @factinv.push( @factinv[-1] * @inv[-1] % @mod )
    end
    @n_max = t
  end
end

mod = 10 ** 9 + 7

n, k = gets.to_s.split.map{|i|i.to_i}
a    = gets.to_s.split.map{|i|i.to_i}.sort

f = Facts.new

ans = 0 
(n-k+1).times do |i|
  t = f.cmb( n-i-1, k-1 )
  mi = a[i] * t % mod
  ma = a[n-(i+1)] * t % mod
  ans += (ma - mi)
  ans %= mod if ans < 0 || mod <= ans
end
 
puts ans

Measured memory_bytes: 14204
from sys import stdin, stdout, stderr

mod = 10**9 + 7

def solve():
    def binom(n, k):
        res = (modfact[n] * factinv[k]) % mod
        res = (res * factinv[n - k]) % mod
        return res

    h, w, a, b = map(int, input().split())
    ans = 0
    modfact = [1] * (h + w)
    factinv = [1] * (h + w)
    inv = [1] * (h + w)

    for i in range(2, h + w):
        modfact[i] = (i * modfact[i - 1]) % mod
        inv[i] = (-(mod // i) * inv[mod % i]) % mod
        factinv[i] = (inv[i] * factinv[i - 1]) % mod

    for i in range(h - a):
        ans += (binom(b + i - 1, i) * binom(w + h - b - i - 2, h - i - 1)) % mod
        ans %= mod

    print(ans)

if __name__ == '__main__':
    solve()

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

ll mod = 1e9+7;
ll t = 1234569;

int main() {
    int N;
    cin >> N;
    vector<int> a(N), b(N), c(N), d(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    for (int i = 0; i < N; i++) cin >> b[i];
    for (int i = 0; i < N; i++) {
        c[i] = a[i]^a[(i+1)%N];
        d[i] = b[i]^b[(i+1)%N];
        //cout << c[i] << " " << d[i] << endl;
    }
    ll h = c[0];
    for (int i = 1; i < N; i++) h = (h*t+c[i])%mod;
    vector<ll> hash(2*N);
    hash[0] = d[0];
    for (int i = 1; i < 2*N; i++) {
        hash[i] = (hash[i-1]*t+d[i%N])%mod;
    }
    ll e = 1;
    for (int i = 0; i < N; i++) e = e*t%mod;
    vector<ll> ans;
    for (int i = 0; i < N; i++) {
        if (((hash[i+N]-hash[i]*e)%mod+mod)%mod == h) {
            ans.push_back(N-1-i);
        }
    }
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < (int)ans.size(); i++) {
        cout << ans[i] << " " << (b[0]^a[ans[i]]) << endl;
    }
    return 0;
}


Measured memory_bytes: 11376
<?php

fscanf(STDIN, "%d", $n);
$input = trim(fgets(STDIN));
$p_arr = explode(' ', $input);


$count = 0;
$tmp1 = $p_arr[0];
$tmp2 = $p_arr[1];
for ($i = 2; $i < $n; ++$i) {
    if (($tmp2 > $tmp1 && $tmp2 < $p_arr[$i]) || ($tmp2 < $tmp1 && $tmp2 > $p_arr[$i])) {
        ++$count;
    }

    $tmp1 = $tmp2;
    $tmp2 = $p_arr[$i];
}
echo $count;


Measured memory_bytes: 4856
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext())
		{
			int a = sc.nextInt(),
				b = sc.nextInt(),
				c = sc.nextInt();
			int count = 0;
			for (int i = 1; i <= 10; i++)
			{
				if (i != a && i != b && i != c && a + b + i > 20)
				{
					count++;
				}
			}
			if (count >= 4)
			{
				System.out.println("NO");
			}
			else
			{
				System.out.println("YES");
			}
		}
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
#define MAX 500000
#define NUMBER 1000000000

int Left[MAX/2+2],Right[MAX/2+2];
int count=0;

void Merge(int A[],int n,int left,int middle,int right)
{
  int i,j,k,m;
  n=middle-left;
  m=right-middle;
  for(i=0;i<n;i++) Left[i]=A[left+i];
  for(i=0;i<m;i++) Right[i]=A[middle+i];
  Left[n]=NUMBER;
  Right[m]=NUMBER;
  i=0;
  j=0;
  for(k=left;k<right;k++)
    {
      count++;
      if(Left[i]<=Right[j])
	{
	  A[k]=Left[i++];
	}
      else
	{
	  A[k]=Right[j++];
	}
    }
}

void MergeSort(int A[],int num, int left,int right)
{
  int mid;
  if(left+1<right)
    {
      mid=(left+right)/2;
      MergeSort(A,num,left,mid);
      MergeSort(A,num,mid,right);
      Merge(A,num,left,mid,right);
    }
}

int main()
{
  int A[MAX],n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  MergeSort(A,n,0,n);

  for(i=0;i<n;i++)
    {
      if(i) printf(" ");
      printf("%d",A[i]);
    }
  printf("\n");
  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 4508
#include <stdio.h>
#include <string.h>

int main(void)
{
 
  char s[100];
  scanf("%s",s);

  int len=strlen(s);

  for(int i=0;i<len;i++){
    s[i]='x';
  }
  
  printf("%s",s);

  return 0;
}


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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
ll a[100010];
int main()
{
  ios::sync_with_stdio(0), cin.tie(0);
    ll n,s=0,l=0,x,y;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
      if(a[n]>2)
      {
        cout<<"-1";
        return 0;
      }
      s=2;l=2;
      if(a[n]==2) l=3;
    for(int i=n-1;i>0;i--)
    {
      x=(s/a[i])*a[i];
      if(s%a[i]!=0)
        x+=a[i];
      y=(l/a[i])*a[i];
      y+=(a[i]-1);
      if((x/a[i+1])*a[i+1]>l)
      {
        cout<<"-1";
        return 0;
      }
      s=x;
      l=max(x,y);
    }
    cout<<s<<" "<<l;
  return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	string s, t;
	cin >> s;
	t = s;
	reverse(t.begin(), t.end());
	int res = 0;
	rep (i, (s.size() + 1) / 2) if (s[i] != t[i]) res++;
	cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
#include <string.h>
using namespace std;

#define N 200000
int a[N],b[N];
void solve() {
  int n;scanf("%d",&n);
  for(int i=0;i<n;++i) scanf("%d",&a[i]);
  priority_queue<pair<int,int> > pq;
  long long ret = 0;
  for(int i=0;i<n;++i) scanf("%d",&b[i]), pq.push(make_pair(b[i],i));
  while(!pq.empty()) {
    int v = pq.top().first, ind =pq.top().second;
    pq.pop();
    if(v<=a[ind]) {
      continue;
    }
    int maxi = max(b[(ind+n-1)%n],b[(ind+1)%n]);
    maxi = max(maxi,a[ind]);
    int t = b[(ind+n-1)%n] + b[(ind+1)%n];
    int diff = v - maxi;
    int add = max(1, diff/t);
    ret = ret + add;
    v -= add*t;
    b[ind] = v;
    if(v<a[ind]) {
      break;
    }
    if(v<=a[ind]) {
      continue;
    }
    pq.push(make_pair(b[ind],ind));
  }
  bool isGood = true;
  for(int i=0;i<n;++i) {
    if(a[i]!=b[i]) {
      isGood = false;
    }
  }
  if(isGood) {
    printf("%lld\n", ret);
  } else {
    printf("-1\n" );
  }
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


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

typedef pair<int,int> ii;

const int N = 2e3+5;
const int oo = 1e9;

int n;
int res[N]={0}, dist[N];
vector<int> AdjList[N];

void bfs(int s){ 
	//cout<<"s:"<<s<<endl;
	for(int i = 0; i < n; ++ i) dist[i] = oo;
	priority_queue<ii, vector<ii>, greater<ii> > pq;
	dist[s] = 0;
	pq.push({0, s});
	while(!pq.empty()){
		ii nodo = pq.top(); pq.pop();
		int d = nodo.first, u = nodo.second;
		//if(d > dist[u]) continue;
		res[d]++;
		for(int v: AdjList[u]){
			
			if( dist[v] > dist[u] + 1 ){
				dist[v] = dist[u] + 1;
				//cout<<u<<"-"<<v<<" "<<dist[v]<<endl;
				pq.push({dist[v], v});
				
			}
		}
	}
}

int main()
{
	int x, y;
	cin>>n>>x>>y;

	for (int i = 0; i < n-1; ++i){
		AdjList[i].push_back(i+1);
		AdjList[i+1].push_back(i);
	}
	AdjList[x-1].push_back(y-1);
	AdjList[y-1].push_back(x-1);

	for (int i = 0; i < n; ++i)
	{
		bfs(i);
	}
		


	for (int i = 1; i < n; ++i)
	{
		cout<<(res[i]>>1)<<endl;
	}

	
	return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    m = 1000
    c = 0

    dif = [t1 - t0 for t0,t1 in zip(A[:-1], A[1:])]
    for d in dif:
        if d!=0: break
    pre = d
    for d in range(N-1):
        if dif[d] == 0:
            dif[d] = pre
        pre = dif[d]


    if dif[0] > 0:
        c = m // A[0]
        m -= A[0] * c
    # print(dif)
    for i in range(1,N-1):
        if (dif[i-1] < 0)and(dif[i]>0):
            c = m // A[i]
            m -= A[i] * c
            # print("+")
        elif (dif[i-1] > 0)and(dif[i]<0):
            m += A[i] * c
            c = 0
            # print("-")
        # print(c,m)
    
    m += A[N-1] * c
    c = 0

    print(m)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

int main(){
  int a, b;
  cin >> a >> b;
  if(a <= 9 && b <= 9) cout << a*b << endl;
  else cout << -1 << endl;
  return 0;
}

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

int calc(int a,int b,int tax){
  return a*(100+tax)/100 + b*(100+tax)/100;
}

int main(){
  while(true){
    int x,y,s; cin>>x>>y>>s;
    if(x==0) break;
    int ans=0;

    for(int i=1;i<s;++i){
      for(int j=i;j<s;++j){

        if(s==calc(i,j,x))
          ans = max(ans, calc(i,j,y));
      }
    }
    cout << ans << endl;
  }
  return EXIT_SUCCESS;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define deb(x) cout << #x << "=" << x << endl
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
int M=1e9+7,N=205001;

int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M



void solve() {
	int n,m,k,i;
	cin>>n>>m>>k;
	int a[n],b[m],pa[n+1]={},pb[m+1]={};
	rep(i,0,n) {
		cin>>a[i];
		pa[i+1]=pa[i]+a[i];	
	}
	rep(i,0,m){
		cin>>b[i];
		pb[i+1]=pb[i]+b[i];	
	} 
	int mx=0;
	for(int i=0;i<=n;i++){
		if(k>=pa[i]){
			int j=upper_bound(pb,pb+m+1,k-pa[i])-pb-1;
			mx=max(mx,i+j);	
		}
	}
	cout<<mx;
	
}


signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}





Measured memory_bytes: 9900
#include <stdio.h>

int main(void) {
	int t = 0, h = 0;
	int x, y, d;
	while (scanf("%d,%d,%d", &x, &y, &d) != EOF) {
		if( x*x + y*y == d*d)
			t++;
		if( x == y)
			h++;
	}
	printf("%d\n%d\n", t, h);
	return 0;
}

Measured memory_bytes: 592
import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// キーマップを作る
		HashMap<Integer, String[]> keyMap = new HashMap<Integer, String[]>();
		String[] key1 = { ".", ",", "!", "?", " " };
		keyMap.put(1, key1);
		String[] key2 = { "a", "b", "c" };
		keyMap.put(2, key2);
		String[] key3 = { "d", "e", "f" };
		keyMap.put(3, key3);
		String[] key4 = { "g", "h", "i" };
		keyMap.put(4, key4);
		String[] key5 = { "j", "k", "l" };
		keyMap.put(5, key5);
		String[] key6 = { "m", "n", "o" };
		keyMap.put(6, key6);
		String[] key7 = { "p", "q", "r", "s" };
		keyMap.put(7, key7);
		String[] key8 = { "t", "u", "v" };
		keyMap.put(8, key8);
		String[] key9 = { "w", "x", "y", "z" };
		keyMap.put(9, key9);

		int n = nextInt();// テストケース数

		Scanner scanner = new Scanner(System.in);// 大きな数字が入力されるが、数字としては意味のない文字列なので、文字列として受け取る

		for (int i = 0; i < n; i++) {
			String array = scanner.nextLine();
			for (int j = 0; j < array.length(); j++) {
				int key = Character.getNumericValue(array.charAt(j));// 1文字ずつ取り出す
				if (key != 0) {
					String[] map = (String[]) keyMap.get(key);
					int push = -1;// 同じボタンを押した数（0起点なので最初に1引いておく）
					while (key != 0) {
						push++;
						j++;
						key = Character.getNumericValue(array.charAt(j));
					}

					push %= map.length;
					System.out.print(map[push]);
				}
			}
			System.out.print("\n");
		}

	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

}

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

int main() {
    long long K;
    cin >> K;
    vector<long long> ans(50, (K + 49) / 50 + 49);
    rep(i, (K + 49) / 50 * 50 - K) {
        ans[i] -= 50;
        rep(j, 50) {
            if (j != i) ++ans[j];
        }
    }
    cout << 50 << endl;
    rep(i, 50) {
        cout << ans[i];
        if (i == 49) cout << endl;
        else cout << " ";
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int n;
int q;
int v[1<<18], w[1<<18];
vector<pair<int, int>> dp[1<<10];

int fxxk(int x, vector<pair<int, int>>& brute_force) {
  if (x < (1 << 10)) {
    return x;
  }
  int l = brute_force.size();
  for (int i = 0; i < l; i++) {
    brute_force.push_back({brute_force[i].first + w[x], brute_force[i].second + v[x]});
  }
  return fxxk(x/2, brute_force);
}

void solve(int u) {
    if (!dp[u].empty()) {
      return;
    }
    if (dp[u/2].empty()) {
      solve(u/2);
    }
    vector<pair<int, int>> wtf1, wtf2;
    for (pair<int, int> pii: dp[u/2]) {
      int ww = pii.first;
      int vv = pii.second;
      wtf1.push_back(pii);
      wtf2.push_back({ww + w[u], vv + v[u]});
    }
    int i = 0;
    int j = 0;
    while (true) {
      if (i == wtf1.size() && j == wtf2.size()) {
        break;
      } else if (i == wtf1.size()) {
        dp[u].push_back(wtf2[j++]);
      } else if (j == wtf2.size()) {
        dp[u].push_back(wtf1[i++]);
      } else if (wtf1[i] < wtf2[j]) {
        dp[u].push_back(wtf1[i++]);
      } else {
        dp[u].push_back(wtf2[j++]);
      }
    }
    for (int i = 1; i < dp[u].size(); i++) {
      if (dp[u][i].second < dp[u][i-1].second) {
        dp[u][i].second = dp[u][i-1].second;
      }
    }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &v[i], &w[i]);
  }
  dp[1].push_back({0, 0});
  dp[1].push_back({w[1], v[1]});
  for (int i = 1; i <= n && i < (1 << 10); i++) {
    solve(i);
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int u, l;
    scanf("%d %d", &u, &l);
    if (u < (1 << 10)) {
      auto it = lower_bound(dp[u].begin(), dp[u].end(), make_pair(l+1, 0));
      if (it == dp[u].begin()) {
        printf("0\n");
      } else {
        printf("%d\n", (--it) -> second);
      }
    } else {
      vector<pair<int, int>> brute_force;
      brute_force.push_back({0, 0});
      brute_force.push_back({w[u], v[u]});
      int k = fxxk(u/2, brute_force);
      sort(brute_force.begin(), brute_force.end(), [] (auto x, auto y) {
        if (x.first == y.first) {
          return y.second < x.second;
        } else {
          return x.first < y.first;
        }
      });
      for (int j = 1; j < brute_force.size(); j++) {
        if (brute_force[j].second < brute_force[j-1].second) {
          brute_force[j].second = brute_force[j-1].second;
        }
      }
      int llllllll = brute_force.size();
      int p1 = dp[k].size() - 1;
      int p2 = 0;
      int ans = 0;
      while(p2 < llllllll && p1 >= 0) {
        if (dp[k][p1].first + brute_force[p2].first > l) {
          --p1;
        } else {
          ans = max(ans, dp[k][p1].second + brute_force[p2].second);
          ++p2;
        }
      }
      printf("%d\n", ans);
    }
  }
}


Measured memory_bytes: 10588
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  return ~~Math.min(intShift()*intShift(),intShift());
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
10 3 5
`);

Measured memory_bytes: 7372
import sys

def I(): return int(sys.stdin.readline().rstrip())

N = I()
mod = 10**9+7

import math

def sieve_of_eratosthenes(n):
    prime_list = []  # n以下の素数のリスト
    A = [1]*(n+1)    # A[i] = iが素数なら1,その他は0
    A[0] = A[1] = 0
    for i in range(2,math.floor(math.sqrt(n))+1):
        if A[i]:
            prime_list.append(i)
            for j in range(i**2,n+1,i):
                A[j] = 0
    for i in range(math.floor(math.sqrt(n))+1,n+1):
        if A[i] == 1:
            prime_list.append(i)
    return prime_list

prime_list = sieve_of_eratosthenes(N)

ans = 1
for p in prime_list:
    a = 0
    r = N
    while r >= p:
        a += r//p
        r //= p
    ans *= a+1
    ans %= mod

print(ans)

Measured memory_bytes: 38384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	static String array[][] = new String[][]{
		{null},
		{".",",","!","?"," "},
		{"a","b","c"},
		{"d","e","f"},
		{"g","h","i"},
		{"j","k","l"},
		{"m","n","o"},
		{"p","q","r","s"},
		{"t","u","v"},
		{"w","x","y","z"}
	};
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		Main app = new Main();
		String res;
		
		int n, e, count, i = Integer.valueOf(reader.readLine()) - 1;
		for(; i >= 0; i--){
			char ch[] = reader.readLine().toCharArray();
			res = "";
			count = 0;
			n = ch[0] - '0';
			for(int j = 1; j < ch.length; j++){
				e = ch[j] - '0';
				if(e == 0){
					res += app.message(n, count);
					n = 0;
					count = 0;
				}
				else if(n == e) count++;
				else n = e;
			}
			System.out.println(res);
		}
		reader.close();
	}
	
	public String message(int n, int c){
		if(n == 0) return "";
		if(n == 1) c %= 5;
		if(n == 7 || n == 9) c %= 4;
		if(n >= 2 && 6 >= n || 8 == n) c %=3;
		
		return array[n][c];
	}
}

Measured memory_bytes: 29060
#include <bits/stdc++.h>
using namespace std;
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define pb push_back
#define mp make_pair

int main(){
	fast;
	int test=1;
	//cin >> test;
	//int q=1;
	while(test--){
	    int h,w;
	    cin >> h >> w;
	    string arr[h];
	    for(int i=0 ; i<h ; i++){
	        cin >> arr[i];
	    }
	    int dp[h][w]={};
	    dp[0][0]=1;
	    for(int i=0 ; i<h ; i++){
	        for(int j=0 ; j<w ; j++){
	            if(i==0 && j==0){
	                continue;
	            }else if(arr[i][j]=='#'){
	                dp[i][j]=0;
	            }else{
	                if(i==0){
	                    dp[i][j]=dp[i][j-1];
	                }else if(j==0){
	                    dp[i][j]=dp[i-1][j];
	                }else{
	                    dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
	                }
	            }
	        }
	    }
	    cout << dp[h-1][w-1] << endl;
	}
	return 0;
}

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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

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

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(base, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)102;
ll N, W;
bool seen[100005];
ll dp[100005];
pll wv[MAXN];

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> W;
    for(int i=0; i<N; i++)
    {
        cin >> wv[i].f >> wv[i].s;
    }
    sort(wv, wv+N);
    seen[0] = true;
    for(int i=0; i<N; i++)
    {
        for(int j=W; j>=0; j--)
        {
            if(j+wv[i].f <= W && seen[j])
            {
                seen[j+wv[i].f] = true;
                dp[j+wv[i].f] = max(dp[j+wv[i].f], dp[j] + wv[i].s);
            }
        }
    }
    ll ans = 0;
    for(int i=0; i<=W; i++)
    {
        ans = max(ans, dp[i]);
    }
    cout << ans;
    return 0;
}


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

int main() {
  string S;
  cin >> S;

  int ans = 0;

  for (int i = 0; i + 2 < S.size(); i++) {
    if (i == 0) {
      int X = stoi(S.substr(i, 3));
      ans = abs(X - 753);
    }
    else {
      int X = stoi(S.substr(i, 3));
      ans = min(ans, abs(X - 753));
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import static java.util.Arrays.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}


	int[][] sum;
	// [i1, i2)
	int get(int i1, int j1, int i2, int j2) {
		return sum[i2][j2] - sum[i2][j1] - sum[i1][j2] + sum[i1][j1];
	}

	void solve() {
		int n = sc.nextInt();
		int[][] a = new int[n][n];
		for (int i = 0; i < n; i++) a[i] = sc.nextIntArray(n);
		sum = new int[n+1][n+1];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				sum[i+1][j+1] = -sum[i][j] + sum[i+1][j] + sum[i][j+1] + a[i][j];
			}
		}

		int res = a[0][0];
		for (int r1 = 0; r1 < n; r1++) {
			for (int r2 = r1 + 1; r2 <= n; r2++) {
				int last = 0;
				for (int c = 0; c < n; c++) {
					int here = get(r1, c, r2, c+1);
					last = Math.max(last + here, here);
					res = Math.max(res, last);
				}
			}
		}
		out.println(res);

	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1000111;

const ll MOD = 1000000007LL;

void solve() {

}

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

    int a, b;
    cin >> a >> b;
    cout << max({a+b, a-b, a*b});






    return 0;
}


Measured memory_bytes: 256
def rot_n(s, n):
  answer = ''
  for letter in s:
      answer += chr(ord('A') + (ord(letter)-ord('A')+n) % 26)

  return answer

### https://qiita.com/TodayInsane/items/94f495db5ba143a8d3e0

N = int(input())
S = str(input())

print(rot_n(S, N))

Measured memory_bytes: 9108
#include<stdio.h>
int main()
{
    double a,b,c,d,e,f,x,y;

    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF)
    {
        y=((a*f)-(c*d))/((a*e)-(b*d));
        x=(c-(b*y))/a;
        printf("%.3lf %.3lf\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 652
n = int(input())
t = [0] * n
x = [0] * n
y = [0] * n
ans = 'Yes'
for i in range(n):
  t[i], x[i], y[i] = map(int, input().split())

d = abs(x[0]) + abs(y[0])
if d not in range(t[0], -1, -2):
  ans = 'No'
  
for i in range(n-1):
  t_temp = t[i+1] - t[i]
  x_temp = abs(x[i+1] - x[i])
  y_temp = abs(y[i+1] - y[i])
  d = x_temp + y_temp
  if d in range(t_temp, -1, -2):
    continue
  else:
    ans = 'No'
print(ans)

Measured memory_bytes: 11636
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXXLIM = 10;
const int MAXYLIM = 10;

int xlim, ylim;
int d[MAXXLIM + 1][MAXYLIM + 1];

bool ok(int nx, int ny, int cnst) {
	FORE(x, 1, xlim) FORE(y, 1, ylim) {
		int cur = nx*x + ny*y + cnst;
		if (cur < d[x][y]) return false;
	}
	return true;
}

pair<int, int> search(int cx, int cy) {
	for (int nx = 0; nx*cx <= d[cx][cy]; ++nx) for (int ny = 0; nx*cx + ny*cy <= d[cx][cy]; ++ny) {
		int cnst = d[cx][cy] - nx*cx - ny*cy;
		if (ok(nx, ny, cnst)) return MP(nx, ny);
	}
	return MP(-1, -1);
}

map<pair<int, int>, int> e;

void run() {
	scanf("%d%d", &xlim, &ylim); FORE(cx, 1, xlim) FORE(cy, 1, ylim) scanf("%d", &d[cx][cy]);
	FORE(cx, 1, xlim) FORE(cy, 1, ylim) {
		pair<int, int> p = search(cx, cy);
		if (p.first == -1 || p.second == -1) { printf("Impossible\n"); return; }
		int cnst = d[cx][cy] - cx*p.first - cy*p.second;
		if (e.count(p)) assert(e[p] == cnst); else e[p] = cnst;
	}
	int mxx = 0, mxy = 0; for (auto it = e.begin(); it != e.end(); ++it) { int nx = it->first.first, ny = it->first.second; mxx = max(mxx, nx); mxy = max(mxy, ny); }
	vector<int> xid(mxx + 1), yid(mxy + 1); int nid = 0; REPSZ(i, xid) xid[i] = ++nid; REPSZ(i, yid) yid[i] = ++nid;
	printf("Possible\n");
	printf("%d %d\n", nid, mxx + mxy + SZ(e));
	REP(i, mxx) printf("%d %d X\n", xid[i], xid[i + 1]);
	REP(i, mxy) printf("%d %d Y\n", yid[i + 1], yid[i]);
	for (auto it = e.begin(); it != e.end(); ++it) printf("%d %d %d\n", xid[it->first.first], yid[it->first.second], it->second);
	printf("%d %d\n", xid[0], yid[0]);
}

int main() {
	run();
	return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
//#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

const int MAX = 1000000;
const long long MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void func(long long H, long long W, long long A, long long B){
    lli sum = 0;
    //left top
    REP(i,0,H-A){
        lli a = COM(i+B-1,i);
        //cout<<"H-i="<<H-i<<"W-B-1="<<W-B-1<<endl;
        lli b = COM(H-i+W-B-2,W-B-1);
        if(DEBUG)cout<<"a="<<a<<" b="<<b<<endl;
        sum += (a*b)%MOD;
        sum %= MOD;
    }
    cout<<sum<<endl;
}

int main(){
    // cout << fixed << setprecision(5);
    COMinit();
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    func(H, W, A, B);
    return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int W, H;
string maps[1000];
int d[6][1000][1000];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (cin >> W >> H, W || H) {
		REP(i, H) cin >> maps[i];
				
		int sx, sy, gx, gy;
		REP(i, H) REP(j, W) {
			if (maps[i][j] == 'S') sx = j, sy = i;
			if (maps[i][j] == 'G') gx = j, gy = i;
		}
		
		pii ans(INF, -1);
		REP(s, 5) {
			REP(k, 6) REP(i, H) REP(j, W) d[k][i][j] = INF;
			
			queue<pip> que;
			que.push(pip(0, pii(sy, sx)));
			d[0][sy][sx] = 0;
			
			while (!que.empty()) {
				pip now = que.front(); que.pop();
				int x = now.se.se, y = now.se.fi;
				int num = now.fi;
				
				if (d[num][y][x] + 1 >= ans.fi) break;
				
				char gl;
				if (num < 4) gl = (s + num + 1) % 5 + '1';
				else gl = 'G';
					
				int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
				REP(i, 4) {
					int nx = x + dx[i], ny = y + dy[i];
					if (!(nx >= 0 && nx < W && ny >= 0 && ny < H)) continue;
					if (maps[ny][nx] == gl && chmin(d[num + 1][ny][nx], d[num][y][x] + 1)) {
						if (num < 4) que.push(pip(num + 1, pii(ny, nx)));
						else goto end;
					}
					else if (chmin(d[num][ny][nx], d[num][y][x] + 1)) que.push(pip(num, pii(ny, nx)));
				}
			}
end:
			chmin(ans, pii(d[5][gy][gx], s));
		}
		if (ans.se == -1) cout << "NA\n";
		else cout << ans.se + 1 << " " << ans.fi << '\n';
	}
	return 0;
}

Measured memory_bytes: 28260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); 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 FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653

struct UnionFind { //leaderのtableが部下の数を返すtype
	vector<ll> table;

	UnionFind(ll n) : table(n) { //tableはleaderなら部下の数、そうでなければ所属する上司
		for (ll i = 0; i < n; i++) table[i] = -1;
	}
	
	ll find(ll x){ //leaderの番号を返す
		if (table[x] < 0){
			return x; //tableの値が負の場合はleaderなので自分
		}
		else{
			table[x] = find(table[x]); //xのleader
			return table[x];
		}
	}

	void unite(ll x, ll y){ //xとyをつなげる
		ll s1 = find(x); //xのleader
		ll s2 = find(y); //yのleader
		if (s1 != s2){ 
			if (table[s1] > table[s2]){ //xの木のほうが長い場合はxにyをくっつける
				table[s2] += table[s1];
				table[s1] = s2;
			}
			else if (table[s2] > table[s1]){
				table[s1] += table[s2];
				table[s2] = s1;
			}
			else{
				table[s1] += table[s2];
				table[s2] = s1;
			}
		}
		return;
	}
}; //structの最後には;が必要!!

int main(){
	ll n, m, x, y, a, b; cin >> n >> m;
	vector<ll> ansl(m);
	vector<vector<ll>> conn(m,vector<ll>(2));
	REP(i,m) {
		cin >> a >> b;
		conn[m-1-i][0]=a-1;
		conn[m-1-i][1]=b-1;
	}
	UnionFind uf(n);
	REP(i,m){
		x = uf.table[uf.find(conn[i][0])];
		y = uf.table[uf.find(conn[i][1])];
		if (i==0) ansl[i] = x*y;
		else {
			if (uf.find(conn[i][0])!=uf.find(conn[i][1])){
				ansl[i] = ansl[i-1]+x*y;
			}
			else{
				ansl[i] = ansl[i-1];
			}
		}
		uf.unite(conn[i][0],conn[i][1]);
	}
	FORD(i,m-2,0){
		cout << ansl[m-1]-ansl[i] << endl;
	}
	cout << ansl[m-1] << endl;
}

Measured memory_bytes: 8320
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{


	class Program
	{
		static void Main(string[] args)
		{
			var S = Console.ReadLine();
			var flag = true;

			for(int i = 0; i < S.Length; i++)
			{
				if(i % 2 == 0)
				{
					if(S[i] != 'h')
					{
						flag = false;
						break;
					}
				}
				else
				{
					if (S[i] != 'i')
					{
						flag = false;
						break;
					}

				}
			}

			if (S.Length % 2 == 1)
			{
				flag = false;
			}

			if (flag)
			{
				Console.WriteLine("Yes");
			}
			else
			{
				Console.WriteLine("No");
			}

		}
	}
}

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

using namespace std;

void Main() {
    int A, B;
    cin >> A >> B;

    cout << ((A % 2 == 1 && B % 2 == 1) ? "Yes" : "No") << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <set>
using namespace std;
const int N=1e5+10;
int p[N];
int find(int n){
    if(p[n]==n)return n;
    return p[n]=find(p[n]);
}
int main(){
    int n,m,a[N],ans=0,l,r;
    set<int> s[N];
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        p[i]=i;
    }
    while(m--){
        scanf("%d%d",&l,&r);
        l=find(l);
        r=find(r);
        if(l!=r)p[l]=r;
    }
    for(int i=1;i<=n;i++)s[find(i)].insert(i);
    for(int i=1;i<=n;i++)if(s[find(i)].find(a[i])!=s[find(i)].end())ans++;
    printf("%d\n",ans);
}

Measured memory_bytes: 10368
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
int tableh[1500 * 1000 + 1];
int tablew[1500 * 1000 + 1];
const int mmax = 1500 * 1000 + 1;
void init() {
    rep(i, mmax) {
        tableh[i] = 0;
        tablew[i] = 0;
    }
}
int main() {
    int n, m;
    while (cin >> n >> m && n) {
        init();
        int h[n], w[m];
        rep(i, n) cin >> h[i];
        rep(i, m) cin >> w[i];
        rep(i, n) {
            tableh[h[i]]++;
            int hh = h[i];
            rrep(j, i + 1, n) {
                hh += h[j];
                tableh[hh]++;
            }
        }
        rep(i, m) {
            tablew[w[i]]++;
            int ww = w[i];
            rrep(j, i + 1, m) {
                ww += w[j];
                tablew[ww]++;
            }
        }
        ll ans = 0;
        rep(i, 1500 * 1000) {
            ans += tableh[i] * tablew[i];
        }
        cout << ans << endl;
    }
    
}



Measured memory_bytes: 14804
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b,c;cin>>a>>b>>c;
  cout<<max((ll)(0),c-(a-b));
}


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

// 配列の要素を順番に出力
void trace(vector<int> A, int N){
  for (int i = 0; i < N; i++){
    if( i > 0 ) {cout << " ";}
    cout << A[i];
  }
  cout << "\n";
}

// 挿入ソート
void insertionSort(vector<int> A, int N){
  int j, i, v;
  for (int i = 1; i < N; i++){
    v = A[i];
    j = i-1;
    while( j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A, N);
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  
  trace(A, N);
  insertionSort(A, N);

  return 0;
}


Measured memory_bytes: 3160