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

int main(){
    int N,M;
    cin >> N >> M;
    vector<int>H(100001);
    vector<int>A(100001);
    for(int i=1; i<N+1; i++){
        cin >> H[i];
        A.at(i) = 0;
    }
    for(int i=0; i<M; i++){
        int a,b;
        cin >> a >> b;
        A.at(a) = max(A.at(a),H.at(b));
        A.at(b) = max(A.at(b),H.at(a));
    }
    int ans = 0;
    for(int i = 1;i < N + 1;i++){
        ans += H.at(i) > A.at(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4052
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    String[] str = new String[n];
    boolean flag = true;

    for(int i = 0; i < n; i++){
      str[i] = scan.next();
      if(i > 0 && (str[i-1].charAt(str[i-1].length()-1) != str[i].charAt(0))){
        flag = false;
      }
    }

    if(flag == true){
      Arrays.sort(str);
      for(int i = 0; i < n-1; i++){
        if(str[i].equals(str[i+1])){
          flag = false;
          break;
        }
      }
    }

    if(flag == true)
      System.out.println("Yes");
    else
    System.out.println("No");

  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int x,y,z;
    set<int> a,b,c;
    cin>>n;
    cin>>x;
    for(int i=0;i<x;i++){
        int g;cin>>g;
        a.insert(g);
    }
    cin>>y;
    for(int i=0;i<y;i++){
        int g;cin>>g;
        b.insert(g);
    }
    cin>>z;
    for(int i=0;i<z;i++){
        int g;cin>>g;
        c.insert(g);
    }
    int ans=0;
    for(set<int>::iterator i=c.begin();i!=c.end();i++){
        int g=*i;
        if(a.find(g)==a.end()||b.find(g)!=b.end()){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define swap(type ,a ,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(i=0;i<n;i++)
#define forR(i,s,n) for(i=s;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    int i,tmp,res;
    int n,k;
    vi h;
    cin >> n >> k;
    pb(int,h,n);
    res = 0;
    forN(i,n){
        if(h[i] >= k) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include<map>
#include<string>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<typeinfo>
#include<queue>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> h(N);
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	vector<int> tall(N, 0);
	int highest = 0;
	for (int i = 0; i < N; i++) {
		if (highest < h[i])highest = h[i];
	}
	int count=0;
	for (int i = 0; i < highest; i++) {
		bool flag = false;
		for (int j = 0; j < N; j++) {
			if (tall[j] < h[j]) {
				if (!flag ) {
					flag = true;
					count++;
				}
				tall[j]++;
			}
			else {
				flag = false;
			}
		}
	}
	cout << count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define plint pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    double r;
    cin >> r;
    cout << setprecision(15) << 2*M_PI*r << endl;
    return 0;
}


Measured memory_bytes: 3748
A, B = map(int, input().split())
c = 1
n = 0
while c < B:
  n += 1  # 電源タップを1つ用意
  c -= 1  # 差込口を1個使って
  c += A  # 差込口をA個得る
print(n)  # 必要な電源タップの個数

Measured memory_bytes: 2940
n=int(input())
temp=n
from math import floor,sqrt 
ans=n
for i in range(2,floor(sqrt(n))+1):
    if n%i:continue
    while n%i==0:
        n//=i
    ans=ans-ans//i
if n!=1:
    ans=ans-ans//n
print(ans)


Measured memory_bytes: 5664
#include<iostream>
using namespace std;
int N,M;
int k[10];
int s[10][10];
int p[10];
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		cin>>k[i];
		for(int j=0;j<k[i];j++)
		{
			int S;cin>>S;S--;
			s[i][S]=1;
		}
	}
	for(int i=0;i<M;i++)cin>>p[i];
	int ans=0;
	for(int i=0;i<1<<N;i++)
	{
		bool flag=1;
		for(int j=0;j<M;j++)
		{
			int cnt=0;
			for(int k=0;k<N;k++)
			{
				if(s[j][k]&&(i>>k&1))cnt++;
			}
			flag&=cnt%2==p[j];
		}
		ans+=flag;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
g1 = [1,3,5,7,8,10,12]
g2 = [4,6,9,11]

main = do
  [a,b] <- map read . words <$> getLine
  if (elem a g1 && elem b g1) || (elem a g2 && elem b g2) then putStrLn "Yes" else putStrLn "No"


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int main()
{



    long long a,b,st=0,td=0;
    cin>>a;
    vector<long long>v;
    vector<long long>area;
    long long arr[3]= {0,0,0};
    map<long long,long long>mp,pm;
    map<long long,long long> :: iterator it;
    for(int i=0; i<a; i++)
    {
        cin>>b;
        if(b-1>=0)
        mp[b-1]++;
        mp[b]++;
        mp[b+1]++;

    }
    for( it=mp.begin(); it!=mp.end(); it++)
    {
     long long abc=it->first;
     v.push_back(mp[abc]);

    }
    sort(v.begin(),v.end());
    cout<<v[v.size()-1];
}


Measured memory_bytes: 7288
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int INF=-1;
  int i,j,a[10];
  int b[10]={1,2,1,4,1,4,1,2};
  while(scanf("%d",&a[0])!=EOF){
    for(i=1;i<8;i++){
      cin >> a[i];
    }
    int x=2000000000;
    int ans=INF;
    for(i=0;i<8;i++){
      int count=0;
      for(j=0;j<8;j++){
        count+=min(a[j],b[(j+i)%8]);
      }
      if(count>ans){
        ans=count,x=0;
        for(j=0;j<8;j++){
          x+=b[(j+i)%8]*pow(10,7-j);
        }
      }
      else if(count==ans){
        int y=0;
        for(j=0;j<8;j++){
          y+=b[(j+i)%8]*pow(10,7-j);
        }
        if(y<x){
          x=y,ans=count;
        }
      }
    }
    vector<int> g;
    for(i=0;i<8;i++){
      g.push_back(x%10);
      x=x/10;
    }
    for(i=7;i>=0;i--){
      if(i==7){
        printf("%d",g[i]);
      }
      else{
        printf(" %d",g[i]);
      }
    }
    printf("\n");
  }
}


Measured memory_bytes: 3440
N, M, Q = map(int, input().split())

def make_group(now, n, i):
    if n == 0:
        groups.append(now)
    else:
        for j in range(i, M+1): 
            make_group(now+[j], n-1, j)

A = [0]*Q
B = [0]*Q
C = [0]*Q
D = [0]*Q
for i in range(Q):
    A[i], B[i], C[i], D[i] = map(int, input().split())

groups = []
now = []
make_group(now, N, 1)

ans = 0
for group in groups:
    tmp = 0
    for a, b, c, d in zip(A, B, C, D):
        if group[b-1]-group[a-1] == c:
            tmp += d
    ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 22972
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#define mp(a, b) make_pair(a, b)
using namespace std;
typedef pair<int, int> pp;
const int maxn = 1010;
const int oo = 1e9;
queue<pp> q;
int dis[maxn][maxn] = {0};
int n, m;
int ans = 0;
int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
bool in(int x, int y)
{
	return x > 0 && x <= n && y > 0 && y <= m;
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n >> m;
	memset(dis, -1, sizeof(dis));
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= m; j ++)
		{
			char a;
			cin >> a;
			if(a == '#')
			{
				dis[i][j] = 0;
				q.push(mp(i, j));
			}
		}
	while(!q.empty())
	{
		pp now = q.front();
		q.pop();
		for(int i = 0; i < 4; i ++)
		{
			int x = now.first + dir[i][0], y = now.second + dir[i][1];
			if(in(x, y) && dis[x][y] == -1)
			{
				dis[x][y] = dis[now.first][now.second] + 1;
				q.push(mp(x, y));
				ans = max(ans, dis[x][y]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12432
#すべて選ばない→ f = 0
#c>vの組を選ぶ→ f < 0
#c<vの組を選ぶ→ f > 0
#すなわち、c<vの組のみを選ぶのが最善

n=gets.to_i
mat = Array.new(2){gets.split.map(&:to_i)}.transpose
f=0

mat.each do |v|
  if v[0] > v[1]
    f+=v[0]-v[1]
  end
end

p f


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <numeric>
#include <array>
#include <set>

using namespace std;
using ll = long long;


int main()
{
    ll N;
    array<ll, 200001> A;
    bool M[1000001] = {0};

    cin >> N;
    for (ll i = 1; i <= N; i++) cin >> A[i];
    sort(A.begin() + 1, A.begin() + N + 1);

    set<ll> s;
    for (ll i = 1; i <= N; i++)
    {
      if (s.count(A[i]))
      {
        M[A[i]] = 1;
        continue;
      }
      for (ll j = A[i] * 2; j <= 1000000; j += A[i]) M[j] = 1;
      s.insert(A[i]);
    }

    ll ans = 0;
    for (ll i = 1; i <= N; i++)
    {
      if (M[A[i]] == 0) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 15512
#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;

struct Vertex {
    vector<pll> node;
};

Vertex V[100005];
bool U[100005];
ll S[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    REP(i, M) {
        ll l, r, d;
        cin >> l >> r >> d;
        l--;
        r--;
        V[l].node.push_back(pll(r, d));
        V[r].node.push_back(pll(l, -d));
    }

    bool exist = true;
    REP(i, N) {
        if (U[i])
            continue;
        U[i] = true;
        queue<pll> q;
        q.push(pll(i, 0));
        while (!q.empty()) {
            pll t = q.front();
            q.pop();
            REP(i, V[t.first].node.size()) {
                pll n = V[t.first].node[i];
                ll nxt = n.first;
                ll cost = n.second + t.second;
                if (U[nxt]) {
                    if (S[nxt] != cost)
                        exist = false;
                    continue;
                }
                U[nxt] = true;
                S[nxt] = cost;
                q.push(pll(nxt, cost));
            }
        }
    }

    if (exist)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 14576
n = int(input())
v = list(map(int, input().split()))
freq_odd = [0] * (10 ** 5 + 1)
freq_even = [0] * (10 ** 5 + 1)
for i in range(n // 2):
    freq_odd[v[2 * i]] += 1
    freq_even[v[2 * i + 1]] += 1
# print(freq_odd[:10], freq_even[:10])
freq_even, id_even = zip(*sorted(zip(freq_even, range(10 ** 5 + 1))))
freq_odd, id_odd = zip(*sorted(zip(freq_odd, range(10 ** 5 + 1))))
# print(freq_odd[-2:], freq_even[-2:])
# print(id_even[-1], id_odd[-1])
if id_even[-1] != id_odd[-1]:
    print(n - freq_even[-1] - freq_odd[-1])
else:
    print(min(n - freq_even[-2] - freq_odd[-1], n - freq_even[-1] - freq_odd[-2]))


Measured memory_bytes: 32084
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int>P;
/**********************************************/
int par[100005] = {0};
int r[100005] = {0};
struct edge{
	int from, to, cost;
};
int v, e;
edge es[100005];
int n;
void init(int n){
	for(int i = 0; i < n; i++){
		par[i] = i;
		r[i] = 0;
	}
}

int find(int x){
	if(par[x] == x){
		return x;
	}
	else{
		return par[x] = find(par[x]);
	}
}

void unite(int x,int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(r[x] < r[y]){
		par[x] = y;
	}
	else{
		par[y] = x;
	}
	if(r[x] == r[y]) r[x]++;
}

bool same(int x,int y){
	if(find(x) == find(y)) return true;
	else return false;
}

bool comp(edge esx, edge esy){
	return esx.cost < esy.cost;
}

int kruskal(){
	sort(es, es + e, comp);
	int res = 0;
	init(v + 5);
	for(int i = 0; i < e; i++){
		if(!same(es[i].from, es[i].to)){
			res += es[i].cost;
			unite(es[i].from, es[i].to);
		}
	}
	return res;
}

int main() {
	cin >> v >> e;
	for (int i = 0; i < e; i++) {
		int f, t, c;
		cin >> f >> t >> c;
		es[i].from = f;
		es[i].to = t;
		es[i].cost = c;
	}
	cout << kruskal() << endl;
}


Measured memory_bytes: 4392
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool solve(){
	string t;cin>>t;
	rep(i,t.size()){
		if(t[i]=='?')cout<<"D";
		else cout<<t[i];
	}
	cout<<endl;
	return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(30);
  solve();
}


Measured memory_bytes: 3792
//============================================================================
// Name        : aaa.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define SZ(x) (int)(x).size()
#define ALL(X) (X).begin(),(X).end()
#define ALLR(X) (X).rbegin(),(X).rend()
typedef vector<int> vi;

int count(string n) {
//	cout << n;
	int m = 0;
	for (int i = 0; i < SZ(n); ++i) {
		m += n[i];
	}
//	cout << "" << endl;
	return m;

}

int main() {

//	string n="Ahmed";
	int l = 0, n = 0;
	vector<string> s;
//	map<int, string> gquiz1;
	string q;
	cin >> n >> l;
	for (int i = 0; i < n; ++i) {
		cin >> q;
		s.push_back(q);
	}
	sort(ALL(s));
	for (int i = 0; i < SZ(s); ++i) {
//		m+=n[i];
		cout << s[i];

	}
//	cout << "m = " << m << endl; // prints !!!Hello World!!!
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main()
{
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	if (a*b > c*d)
	{
		printf("%d",a*b);
	}
	else if (a*b < c*d)
	{
		printf("%d", c*d);
	}
	else if (a*b == c*d)
	{
		printf("%d", a*b);
	}
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int a, b, c, d;cin >> a >> b >> c >> d;
    cout << ((abs(a-b) <= d && abs(b-c) <= d) || abs(a-c) <= d ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()
ans = s.count("R") * s.count("G") * s.count("B")
for i in range(n - 1):
    for j in range(min(i + 1, n - i)):
        if s[i] != s[i + j] and s[i] != s[i - j] and s[i + j] != s[i - j]:
            ans -= 1

print(ans)

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

typedef long long ll;

int main() {
    int N;
    int ans = 0;
    cin >> N;
    string S;
    string num = "0123456789";
    cin >> S;
    
    for (int x = 0; x < 10; x++) {
        for (int y = 0; y < 10; y++) {
            for (int z = 0; z < 10; z++) {
                bool x_check = true;
                bool y_check = true;
                bool z_check = true;
                int a, b, c;

                for (int i = 0; i < S.size(); i++) {
                    if (x_check) {
                        if (S[i] == num[x]) {
                            a = i;
                            x_check = false;
                        }
                    } else if (y_check) {
                        if (S[i] == num[y]) {
                            b = i;
                            y_check = false;
                        }
                    } else if (z_check) {
                        if (S[i] == num[z]) {
                            c = i;
                            z_check = false;
                        }
                    } else {
                        break;
                    }
                }
                if (!x_check && !y_check && !z_check) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3684
#include<stdio.h>

int main(){

int W,H,x,y,r;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

if((r<=x)&&(x<=(W-r))&&(r<=y)&&(y<=(H-r)))
printf("Yes\n");
else printf("No\n");

return 0;

}

Measured memory_bytes: 584
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>
//#include <atcoder/all>
 
using namespace std;
//using namespace atcoder;
 
/* template */
 
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
 
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};
 
struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};
 
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}
 
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
 
constexpr ll LNF = 1LL<<50;
 
constexpr int INF = 1e9+7;
 
const long double PI=acos(-1);

vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.size();
    if(s[n-1]=='s'){
        s += "es";
    }
    else{
        s += "s";
    }
    cout << s << endl;
}


Measured memory_bytes: 3652
/*
	Name: zhao yi (HangZhou JianLan Middle School, China) 
	Copyright: hkxadpall
	Author: hkxadpall
	Date: 2018-10-18
	Description: the program that can solve Luogu-P1981      
*/
#include <queue>
#include <vector>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using std::max;
using std::min;
using std::cerr;
using std::endl;
using std::sort;
using std::queue;
using std::vector;
using std::priority_queue; 

struct fast_IO {
#define fast_IO_all_DEBUG 0
#define fast_IO_read_DEBUG 0
#define fast_IO_write_DEBUG 0
	
	bool __read_sign_LowThan0; 
	char __read_buf_ch; 
	
	template <typename type> 
	void read(type &res)
	{
		__read_sign_LowThan0 = 0;
		__read_buf_ch = getchar();
		while (__read_buf_ch > '9' || __read_buf_ch < '0') {
			if (__read_buf_ch == '-') {
				__read_sign_LowThan0 = 1;
				__read_buf_ch = getchar();
				break;
			}
			__read_buf_ch = getchar();
		}
		res = (__read_buf_ch & 15); 
		__read_buf_ch = getchar();
		while (__read_buf_ch <= '9' && __read_buf_ch >= '0') {
			res = (res << 3) + (res << 1) + (__read_buf_ch & 15); 
			__read_buf_ch = getchar();
		}
		if (__read_sign_LowThan0) {
			res = ((~res) + 1);
		} 
#if fast_IO_all_DEBUG || fast_IO_read_DEBUG
		printf("[TEST $ read %d $ ]", res);
#endif
	}
} io;

#define read io.read
#define write io.write	

#define passing() fprintf(stderr, "passing line [%d] in function %s.\n", __LINE__, __FUNCTION__)
#define debug(x) cerr << "[debug] " << #x << " = " << x << endl 

#define INF_int(bit) ((1 << (bit - 2)) - 1)

#define Max_N (1000000 + 3)      
#define Max_X (9 + 3)        
#define P 10007     
  
int n;
//int a[Max_N] = {0}; 
char ch[5] = {0};

int main()
{
//	read(n);
	int a, b, k;
	read(a);
	read(b);
	read(k);
	while (k) {
		if (k) {
			b += (a >> 1);
			a >>= 1;
			k--;
		}
		if (k) {
			a += (b >> 1);
			b >>= 1;
			k--;
		}
	}
	printf("%d %d", a, b);
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <time.h>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <utility>
#include <iostream>
#include <cmath>
#include <deque>

#define MOD 998244353
#define pii pair<ll,ll>
#define X first
#define Y second
#define mp make_pair

typedef long long ll;
using namespace std;
#define MAXN 228228
#define MOD 1000000007
ll x, y, n, m, k;
ll a[MAXN];

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll x = 0, y = 0;
        for (int j = 0; j < n; j++) {
            if (j < i && a[j] < a[i]) {
                x++;
            }
            if (j > i && a[j] < a[i]) {
                x++;
                y++;
            }
        }
        ans += y * k % MOD + x * (k * (k-1) / 2 % MOD) % MOD;
    }
    cout << ans % MOD << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;


int main(){
  ll n,k;cin>>n>>k;
  vll a(100001,0);
  vector<vp> g(k);
  rep(i,0,n){
    ll s,t,c;cin>>s>>t>>c;
    g[c-1].push_back(make_pair(s,t));
    
  }
  rep(i,0,k){
    if(g[i].size()==0)continue;
    sort(g[i].begin(),g[i].end());
    rep(j,0,g[i].size()-1){
      if(g[i][j].second==g[i][j+1].first){
        g[i][j+1].first=g[i][j].first;
      }
      else{
        a[g[i][j].first]++;a[g[i][j].second+1]--;
      }
    }
    a[g[i][g[i].size()-1].first]++;a[g[i][g[i].size()-1].second+1]--;
    
  }

  rep(i,1,100001){
    a[i]+=a[i-1];
  }
  ll ans=0;
  rep(i,0,100001){
    ans=max(ans,a[i]);
  }
  cout<<ans<<endl;
}



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

int main(){
    string s;
    cin >> s;
    int n = s.length();
    int ret = 0;
    for(int i = 0; i < n/2; i++){
        ret += s[i] != s[n-1-i];
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 200003
int main()
{
    int a,b,c;
    in3(a,b,c);
    a+=(b+c);
    if(a>=22)
        printf("bust");
    else
        printf("win");

}









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

int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	for(int i=a;i<=b;i++)
	{
		if(i%n==0)
		{
			cout<<"OK";
			return 0;
		}
	}
	cout<<"NG";
	return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
using namespace std;

int main(){
	int n, m, x, y, dx, dy, z;
	char c;
	while(scanf("%d", &n), n){
		bool ex[32][32] = {};
		for(int i = 0; i < n; ++i){
			scanf("%d%d", &x, &y);
			ex[x][y] = true;
		}

		x = y = 10;
		scanf("%d", &m);
		for(int i = 0; i < m; ++i){
			scanf(" %c%d", &c, &z);
			switch(c){
				case 'N':
					dy = 1;
					dx = 0;
					break;
				case 'E':
					dy = 0;
					dx = 1;
					break;
				case 'S':
					dy = -1;
					dx = 0;
					break;
				case 'W':
					dy = 0;
					dx = -1;
					break;
			}

			while(z--){
				x += dx;
				y += dy;
				if(ex[x][y]){
					ex[x][y] = false;
					--n;
				}
			}
		}

		puts(n ? "No" : "Yes");
	}
}

Measured memory_bytes: 1012
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Aman
 */


#include<bits/stdc++.h>

using namespace std;

#include <iostream>

void __print(int x) { cout << x; }

void __print(long x) { cout << x; }

void __print(long long x) { cout << x; }

void __print(unsigned x) { cout << x; }

void __print(unsigned long x) { cout << x; }

void __print(unsigned long long x) { cout << x; }

void __print(float x) { cout << x; }

void __print(double x) { cout << x; }

void __print(long double x) { cout << x; }

void __print(char x) { cout << '\'' << x << '\''; }

void __print(const char *x) { cout << '\"' << x << '\"'; }

void __print(const string &x) { cout << '\"' << x << '\"'; }

void __print(bool x) { cout << (x ? "true" : "false"); }

template<typename T, typename V>
void __print(const pair<T, V> &x) {
    cout << '{';
    __print(x.first);
    cout << ',';
    __print(x.second);
    cout << '}';
}

template<typename T>
void __print(const T &x) {
    int f = 0;
    cout << '{';
    for (auto &i: x) cout << (f++ ? "," : ""), __print(i);
    cout << "}";
}


#define ll   long long
#ifdef LOCAL
#else
#define dbg(x...)
#endif
ll n, m = 1e9 + 7;

class CUbiquity {
public:


    ll fp(ll b, ll p) {
        ll ans = 1;
        while (p) {
            if (p & 1)
                ans = (ans * b) % m;
            p /= 2;
            b = (b * b) % m;
        }
        return ans;
    }

    void solve(std::istream &cin, std::ostream &cout) {
        cin >> n;
        ll ans = fp(10, n);
        ans = ans - fp(9, n) * 2 + fp(8, n);
        ans %= m;
        if (ans < 0)
            ans += m;
        cout << ans;
    }

};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    CUbiquity solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

typedef long long ll;

bool broken[100'005];

int n, m, dp[100'005], mod = 1'000'000'007;


int go(int p) {
    if(p == n) {
        return 1;
    }
    if(broken[p]) return 0;

    if(dp[p] != -1) return dp[p];

    int op1 = 0, op2 = 0;

    op1 = go(p + 1) % mod;
    if(p + 2 <= n) op2 = go(p + 2) % mod;

    return dp[p] = (op1 + op2) % mod;
}


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

    memset(dp, -1, sizeof(dp));

    cin >> n >> m;

    for(int i = 0; i < m; i++) {
        int b;
        cin >> b;

        broken[b] = true;
    }

    cout << go(0) % mod << endl;

}


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

using namespace std;

int main( void )
{
	int map[1001], save[1001];
	int w; long long count;
	count = 1;
	while(cin >> w, w) {
		++w;
		for(int i=0; i < w; ++i) map[i] = save[i] = 0;
		int n, value, weight;
		cin >> n;
		scanf("%d,%d", &value, &weight);
		save[weight] = map[weight] = max(save[weight], value);
		for(int i=1; i < n; ++i) {
			scanf("%d,%d", &value, &weight);
			save[weight] = max(save[weight], value);
			for(int j=0; j < w; ++j) {
				if(map[j]) {
					int ww = j + weight;
					if(ww < w)
						save[ww] = max(save[ww], map[j] + value);
					save[j] = max(save[j], map[j]);
				}
			}
			for(int j=0; j < w; ++j) {
				map[j] = save[j]; save[j] = 0;
			}
		}
		int Max = 0, idx;
		for(int i=1; i < w; ++i) {
			if(Max < map[i]) {
				Max = map[i];
				idx = i;
			}
		}
		cout << "Case " << count++ << ':' << endl;
		cout << Max << endl;
		cout << idx << endl;
	}

	return 0;
}

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

using namespace std;

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

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    vector<int> c(n + 1, 0), d(n + 1, 0);
    for (int i = 0; i < n; i++) {
        c[a[i]]++;
        d[b[i]]++;
    }

    vector<int> s(n + 1, 0);
    for (int i = 0; i <= n; i++) {
        s[i] = c[i] + d[i];
    }

    if (*max_element(s.begin(), s.end()) <= n) {
        for (int i = 1; i <= n; i++) {
            c[i] += c[i - 1];
            d[i] += d[i - 1];
        }

        int t = 0;
        for (int i = 1; i <= n; i++) {
            t = max(t, c[i] - d[i - 1]);
        }

        cout << "Yes" << endl;
        for (int i = 0; i < n; i++) {
            cout << (i == 0 ? "" : " ") << b[(i - t + n) % n];
        }
        cout << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 7228
n, k = map(int, input().split())
s = list(input())
snumbers = []

count1 = 0
for i in range(n):
    if i == 0 or (i >= 1 and s[i] == s[i - 1]):
        count1 = count1 + 1
    else:
        snumbers.append(count1)
        count1 = 1
snumbers.append(count1)

happier = 0
for i in snumbers:
    happier = happier + i - 1

for i in range(min(k, len(snumbers) // 2)):
    happier = happier + 2

print(min(n - 1, happier))


Measured memory_bytes: 4648
package main

import (
	"fmt"
	"math"
	)

func main() {
	var n int
	fmt.Scan(&n)

	t := make([]int, n+1)
	x := make([]int, n+1)
	y := make([]int, n+1)

	t[0] = 0
	x[0] = 0
	y[0] = 0

	for i := 1; i <= n; i++ {
		fmt.Scan(&t[i], &x[i], &y[i])
	}

	flag := true
	for i := 0; i < n; i++ {
		dift := float64(t[i+1] - t[i])
		difx := float64(x[i+1] - x[i])
		dify := float64(y[i+1] - y[i])
		d := math.Abs(difx) + math.Abs(dify)
		if int(d) % 2 != int(dift) % 2 || d > dift {
			flag = false
		}
	}
	if flag {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 5504
N, M = map(int, input().split())
ans = ["#" for _ in range(N)]
for i in range(M):
    s, c = map(int, input().split())
    if ans[s - 1] == "#" or ans[s - 1] == c:
        ans[s - 1] = c
    else:
        print(-1)
        exit()

if N == 1 and ans[0] == "#":
    print(0)
    exit()

for i in range(N):
    if ans[i] == "#":
        if i == 0:
            ans[i] = "1"
        else:
            ans[i] = "0"
if N != 1 and ans[0] == 0:
    print(-1)
else:
    print("".join(map(str, ans)))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int n;
    std::cin>>n;

    std::string s = std::to_string(n);
    std::cout<<(s[0] == s[2] ? "Yes" : "No")<<std::endl;
    return 0;
}

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

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

#define INF 1000000000

int maney,tf,minu;
int year;
int m,n;
double x;
int ans[101];


int main(){

  cin >> m;
  while(m){
    //テ・ツ青?」ツδ?」ツδシテ」ツつソテ」ツつサテ」ツδε」ツδ暗」ツ?ォテ・ツッツセテ」ツ?療」ツ?ヲテ」ツ??
    for(int i = 0; i < 101; i++){
      ans[i] = INF;
    }
    
    cin >> maney >> year >> n;

    for(int i = 0; i < n ; i++){
      //テ・ツ青?ゥツ?凝ァツ板ィテヲツ鳴ケテヲツウツ陛」ツ?ォテ・ツッツセテ」ツ?療」ツ?ヲテ」ツ??
      cin >> tf >> x >> minu;
      int mtmp = maney;
      if(tf){
	//ティツ、ツ?・ツ按ゥ

	for(int k = 0; k < year; k++){
	  int tmp = mtmp * x;
	  mtmp += (int)tmp;
	  mtmp -= minu;
	}
	ans[i] = mtmp;

      }else{
	//テ・ツ債佚・ツ按ゥ
	int r = 0;
	for(int k = 0; k < year; k++){
	  r += mtmp * x;
	  mtmp -= minu;
	}
	ans[i] = mtmp + r;
      }

    }
    sort(ans, ans+n);
  
    cout << ans[n-1] << endl;    
    m--;
  }

  return 0;

}

Measured memory_bytes: 1252
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef int ll;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef pair<int, int> pii;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int _;
string s;
map<int, int> A;
int main() {
	INIT
	cin >> s;
	ll ans = 0;
	int p = 2019;
	int n = s.size();
	int t = 0, e = 1;
	map<int, int> A;
	A[0] = 1;
	per(i, 0, n) {
		t = (t + (s[i] - '0') * e) % p;
		ans += A[t];
		++A[t];
		e = 10 * e % p;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3752
# ------ combination -------
N, MOD = 10**5 + 1, 10**9 + 7
fc, ifc = [0] * (N+1), [0] * (N+1)

def power(n, a):
    res, exp = 1, n
    while(a):
        if a & 1:
            res = res * exp % MOD
        exp = exp * exp % MOD
        a = a >> 1
    return res

fc[0] = 1
for i in range(1, N+1):
    fc[i] = fc[i-1] * i % MOD
ifc[N] = power(fc[N], MOD-2)
for i in range(N-1, -1, -1):
    ifc[i] = ifc[i+1] * (i+1) % MOD

def Comb(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    return fc[n] * ifc[r] % MOD * ifc[n-r] % MOD

# --------------------------

N, P = list(map(int, input().split()))
A = list(map(int, input().split()))

odd = 0
for a in A:
    if a % 2 == 1:
        odd += 1

ans = 0
for i in range(1, odd + 1, 2):
    ans += (Comb(odd, i) * (2**(N-odd)))

if P == 0:
    ans = 2**N - ans
print(ans)

Measured memory_bytes: 10868
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n, m;
	cin >> n >> m;
	Vec a(n), s(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	rep(i, n){
		s[i] = a[i];
		if(i) s[i] += s[i-1];
	}

	ll l = 0, r = 2e5+1;
	while(r-l > 1){
		ll mid = (l+r)/2;
		ll cnt = 0;
		rep(i, n){
			ll rest = mid-a[i];
			ll pos = lower_bound(all(a), rest)-a.begin();
			cnt += n-pos;
		}
		if(cnt >= m) l = mid;
		else r = mid;
	}

	ll ans = 0, cnt = 0;
	rep(i, n){
		ll rest = l-a[i];
		ll pos = lower_bound(all(a), rest+1)-a.begin();
		ans += s[n-1]+a[i]*(n-pos);
		cnt += n-pos;
		if(pos) ans -= s[pos-1];
	}
	co(ans+(m-cnt)*l);

	return 0;
}


Measured memory_bytes: 1792
/* ***********************************************
Author        :axp
Created Time  :2015/5/15 23:29:01
File Name     :1.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

int n,m;
int x,y;
string s;
int sta;
int go[4][2] = {
	{0,1},		// UP
	{1,0},		// RIGHT
	{0,-1},		// DOWN
	{-1,0}		// LEFT
};
int k;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopei("out.txt","w",stdout);
    while(cin>>n>>m && n && m)
	{
		sta=0;
		x=1;
		y=1;
		for(;;)
		{
			cin>>s;
			if(s[0]=='S')
				break;
			if(s[0]=='R')
				sta=(sta+1)%4;
			else if(s[0]=='L')
				sta=(sta+3)%4;
			else if(s[0]=='F')
			{
				cin>>k;
				x+=go[sta][0]*k;
				x=min(x,n);
				y+=go[sta][1]*k;
				y=min(y,m);
				x=max(1,x);
				y=max(1,y);
			}
			else
			{
				cin>>k;
				k=-k;
				x+=go[sta][0]*k;
				x=min(x,n);
				y+=go[sta][1]*k;
				y=min(y,m);
				x=max(1,x);
				y=max(1,y);
			}
			//cout<<x<<' '<<y<<endl;
		}
		cout<<x<<' '<<y<<endl;
	}
    return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  int N; cin >> N;
  vector<int> X(N); rep(i, N) cin >> X.at(i);
  sort(all(X));
  int ans = 1000000;
  for(int i = 1; i <= 100; i++){
    int HP = 0;
    rep(j, N){
      HP += (X.at(j) - i) * (X.at(j) - i);
    }
    ans = min(ans, HP);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;




int main() {
    
    ll n,a,b;
    cin>>n>>a>>b;
    cout<<max((b*(n-1)+a)-(a*(n-1)+b)+1,0LL)<<endl;
}


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

const int INF = 1001001001;

int main(){
    int n,x,t;
    cin>>n>>x>>t;
    int ans;
    if(n%x==0){ans = n/x;}
    else{ans = n/x+1;}
    ans*=t;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3616
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
        int a = int.Parse(ReadLine());
        int b = int.Parse(ReadLine());
        int c = int.Parse(ReadLine());
        int d = int.Parse(ReadLine());

        int ans = Math.Min(a, b) + Math.Min(c, d);
        WriteLine(ans);
    }
}


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

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

  int A[1001] = {};
  for ( int i = 0; i < M; i++ ) {
    int a;
    cin >> a;
    a--;
    A[a] = 1;    
  }

  int cnt = 0;
  while ( 1 ) {
    bool flag = true;    
    for ( int i = 0; i < M; i++ ) {
      if ( !A[i] ) flag = false;      
    }
    if ( flag ) break;

    int j = -1;
    int ma = 0;    
    for ( int i = 0; i < N; i++ ) {
      if ( !A[i] && j < 0 ) j = i;
      if ( A[i] && i >= M ) ma = i;      
    }

    A[j] = 1;
    A[ma] = 0;
    cnt++;
  }

  cout << cnt << endl;
  
  return 0;
}



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

int main(){
    int n;
    cin>>n;
    int a=n/100;
    int b=n%100;
    if(a>=20){
        cout<<1<< endl;
        return 0;
    }else{
        if(b>a*5){
            cout<<0<< endl;
        }else{
            cout<<1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())
h = [int(input()) for i in range(n)]

def check(k):
    cnt = 0
    for i in h:
        hp = i - k*b
        if hp > 0:
            cnt += -(-hp//(a-b))
    return cnt <= k

left = 0
right = 10**10
while right - left>1:
    mid = (right + left)//2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)


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

const int maxn=2e5+5;
const int mod=1000000007;
long long fac[maxn];

int qpow(long long a,long long b){
	long long ret=1;
	while(b){
		if(b&1) ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}

int C(int n,int m){
	return (long long)fac[n]*qpow(fac[m],mod-2)%mod*qpow(fac[n-m],mod-2)%mod;
}

int f(int n,int m){
	return C(n+m-2,n-1);
}

int main(){
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	fac[0]=1;
	for(int i=1;i<maxn;i++){
		fac[i]=fac[i-1]*i%mod;
	}
	int ret=0;
	for(int i=1;i<=h-a;i++){
		ret=(ret+(long long)f(i,b)*f(h-i+1,w-b))%mod;
	}
	cout<<ret;
}

Measured memory_bytes: 5176
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	vector<int>appear(26, 0);
	string w = in<string>();
	REPC(i, w)++appear[i - 'a'];
	bool res = true;
	REPC(i, appear)res &= i % 2 == 0;
	cout << (res ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

class Point{
public:
	double x;
	double y;
	double z;
	Point(double _x,double _y,double _z) : x(_x),y(_y),z(_z){}
};

bool diff(double a,double b){
	return abs(a-b) < 0.1;
}

int main(){
	int n;
	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++){
			double QR,RP,PQ;
			scanf("%lf %lf %lf",&QR,&RP,&PQ);

			int c;
			scanf("%d",&c);
			vector<Point> points;
			for(int j=0;j<c;j++){
				double x,y,z;
				scanf("%lf %lf %lf",&x,&y,&z);
				points.push_back(Point(x,y,z));
			}

			double minv = numeric_limits<double>::max();
			int resP,resQ,resR;
			for(int p=0;p<points.size();p++){
				for(int q=0;q<points.size();q++){
					if(p==q) continue;
					for(int r=0;r<points.size();r++){
						if(q==r || r== p) continue;

						double cQRx = abs(points[q].x - points[r].x);
						double cQRy = abs(points[q].y - points[r].y);
						double cQRz = abs(points[q].z - points[r].z);
						double cQR = sqrt(cQRx * cQRx +  cQRy * cQRy + cQRz * cQRz);

						double cRPx = abs(points[r].x - points[p].x);
						double cRPy = abs(points[r].y - points[p].y);
						double cRPz = abs(points[r].z - points[p].z);
						double cRP = sqrt(cRPx * cRPx +  cRPy * cRPy + cRPz * cRPz);

						double cPQx = abs(points[p].x - points[q].x);
						double cPQy = abs(points[p].y - points[q].y);
						double cPQz = abs(points[p].z - points[q].z);
						double cPQ = sqrt(cPQx * cPQx +  cPQy * cPQy + cPQz * cPQz);

						if(diff(cRP/RP,cQR/QR) && diff(cPQ/PQ,cQR/QR) && diff(cPQ/PQ,cRP/RP)){
							printf("%d %d %d\n",p+1,q+1,r+1);
							goto next;
						}
					}
				}
			}
next:;

		}
	}
}

Measured memory_bytes: 1228