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

namespace IO {
    const int maxn(1 << 21 | 1);

    char ibuf[maxn], *iS, *iT, c;
    int f;

    inline char Getc() {
        return iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin), (iS == iT ? EOF : *iS++)) : *iS++;
    }

    template <class Int> inline void In(Int &x) {
        for (f = 1, c = Getc(); c < '0' || c > '9'; c = Getc()) f = c == '-' ? -1 : 1;
        for (x = 0; c >= '0' && c <= '9'; c = Getc()) x = x * 10 + (c ^ 48);
        x *= f;
    }
}

using IO :: In;

const int maxn(1e5 + 5);

int n, t[2][maxn];

int main() {
	In(n);
	for (int i = 1, a; i <= n; ++i) In(a), ++t[i & 1][a];
	int mx1 = -1, mx3 = -1, mx4 = -1, mx2 = -1, p1 = 0, p2 = 0;
	for (int i = 1; i <= 100000; ++i) {
		if (t[0][i] > mx1) mx3 = mx1, mx1 = t[0][i], p1 = i;
		else mx3 = max(mx3, t[0][i]);
		if (t[1][i] > mx2) mx4 = mx2, mx2 = t[1][i], p2 = i;
		else mx4 = max(mx4, t[1][i]);
	}
	if (p1 != p2) printf("%d\n", n - mx1 - mx2);
	else printf("%d\n", n - max(mx1 + mx4, mx2 + mx3));
    return 0;
}

Measured memory_bytes: 1664
import sys

class Node:
    def __init__(self, id, left, right):
        self.id = id
        self.parent = None
        self.left = left
        self.right = right

    def preorderTreeWalk(self):
        if self.id == -1:
            return []
        return [self.id] + self.left.preorderTreeWalk() + self.right.preorderTreeWalk()

    def inorderTreeWalk(self):
        if self.id == -1:
            return []
        return self.left.inorderTreeWalk() + [self.id] + self.right.inorderTreeWalk()

    def postorderTreeWalk(self):
        if self.id == -1:
            return []
        return self.left.postorderTreeWalk() + self.right.postorderTreeWalk() + [self.id]

def buildTree(id, nodeList):
    leftId, rightId = nodeList[id][0], nodeList[id][1]
    dummy = Node(-1, None, None)

    if leftId == -1 and rightId == -1:
        return Node(id, dummy, dummy)

    if leftId == -1:
        left = dummy
    else:
        left = buildTree(leftId, nodeList)

    if rightId == -1:
        right = dummy
    else:
        right = buildTree(rightId, nodeList)

    node = Node(id, left, right)
    node.left.parent = node
    node.right.parent = node

    return node

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    N = int(lines[0])
    del lines[0]

    nodeList = [[]] * N
    sum = N * (N - 1) / 2
    for line in lines:
        line = map(int, line.split())
        id, children = line[0], line[1:]
        nodeList[id] = children
        for child in children:
            if child == -1:
                continue
            sum -= child

    root = buildTree(sum, nodeList)
    root.parent = Node(-1, None, None)

    print "Preorder"
    order = root.preorderTreeWalk()
    print " " + " ".join(map(str, order))

    print "Inorder"
    order = root.inorderTreeWalk()
    print " " + " ".join(map(str, order))

    print "Postorder"
    order = root.postorderTreeWalk()
    print " " + " ".join(map(str, order))

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n; scanf("%d",&n);

	vector<vector<int>> a;
	if(n%2==1){
		rep(i,n/2) a.push_back({i+1,n-i-1});
		a.push_back({n});
	}else{
		rep(i,n/2) a.push_back({i+1,n-i});
	}

	vector<pair<int,int>> E;
	rep(i,a.size()) rep(j,i) {
		for(int u:a[i]) for(int v:a[j]) E.emplace_back(u,v);
	}

	printf("%lu\n",E.size());
	for(auto e:E) printf("%d %d\n",e.first,e.second);

	return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  if (K <= A + B) cout << min(A, K) << "\n";
  else {
    cout << A - (K - A - B) << "\n";
  }
  return 0;
}

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

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

  if (a * b % 2 == 0) {
    cout << "Even" << endl;
  }
  // a or bが偶数ならEven
  

   else {
    cout <<"Odd" << endl;
  }
   
}

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

using namespace std;

const int MOD=1e9+7;
const double PI=3.14159265359;


int main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    
    if(n==1){
        cout<<"Hello World";
    }
    else{
        int a,b;
        cin>>a>>b;
        cout<<a+b;
    }
    
    return 0;
    
}

Measured memory_bytes: 256
N , T = [int(i) for i in input().split()]

t = [int(i) for i in input().split()]

X = 0
mae = 0
for i in t:
    if(i == 0):
        X = T
        continue

    gap = i - mae

    if(gap < T):
        X = X + gap
    else:
        X = X + T

    mae = i

print(X)

Measured memory_bytes: 25196
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;

int main(){
	int n, ans = 0, temp = 0;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++){
		cin >> h[i];
	}
	for (int i = 1; i < n; i++){
		if (h[i-1] >= h[i]){
			temp++;
		}else{
			ans = max(ans, temp);
			temp = 0;
		}
	}
	cout << max(ans, temp) << endl;
	return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define F first
#define S second
typedef pair<int, int> P;
int board[25][25];
int w, h, ans = 11;
P s, g;
void dfs(P now, int cnt){
    if(now == g){
        ans = min(ans, cnt);
    }
    if(cnt >= 10){
        return;
    }
        for(int i = now.F + 1; i <= h; i++){
            if(board[now.F + 1][now.S] == 1){
                break;
            }
            if(i == h){
                break;
            }
            if(board[i][now.S] == 3){
                ans = min(ans, cnt + 1);
                return;
            }
            if(board[i][now.S] == 1){
                board[i][now.S] = 0;
                dfs(MP(i - 1, now.S), cnt + 1);
                board[i][now.S] = 1;
                break;
            }

        }
   
        for(int i = now.F - 1; i >= -1; i--){
            if(board[now.F - 1][now.S] == 1){
                break;
            }
            if(i == -1){
                break;
            }
            if(board[i][now.S] == 3){
                ans = min(ans, cnt + 1);
                return;
            }
            if(board[i][now.S] == 1){
                board[i][now.S] = 0;
                dfs(MP(i + 1, now.S), cnt + 1);
                board[i][now.S] = 1;
                break;
            }

        }
        for(int i = now.S + 1; i <= w; i++){
            if(board[now.F][now.S + 1] == 1){
                break;
            }
            if(i == w){
                break;
            }
            if(board[now.F][i] == 3){
                ans = min(ans, cnt + 1);
                return;
            }
            if(board[now.F][i] == 1){
                board[now.F][i] = 0;
                dfs(MP(now.F, i - 1), cnt + 1);
                board[now.F][i] = 1;
                break;
            }
        }
        for(int i = now.S - 1; i >= -1; i--){
            if(board[now.F][now.S - 1] == 1){
                break;
            }
            if(i == -1){
                break;
            }
            if(board[now.F][i] == 3){
                ans = min(ans, cnt + 1);
                return;
            }
            if(board[now.F][i] == 1){
                board[now.F][i] = 0;
                dfs(MP(now.F, i + 1), cnt + 1);
                board[now.F][i] = 1;
                break;
            }
            
        }
}
int main(){
    while(cin >> w >> h && w && h){
        ans = 11;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cin >> board[i][j];
                if(board[i][j] == 2){
                    s = MP(i, j);
                }
                if(board[i][j] == 3){
                    g = MP(i, j);
                }
            }
        }
        dfs(s, 0);
        if(ans != 11){
            cout << ans << endl;
        }
        else{
            cout << -1 << endl;
        }
    }
}


Measured memory_bytes: 2972
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
p = [True] * (10 ** 6 + 1)
s = list(set(a))
for x in s:
    t = x * 2
    while t <= 10 ** 6:
        p[t] = False
        t += x
ans = 0
for x in a:
    if c[x] == 1 and p[x] == True:
        ans += 1
print(ans)


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

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> dp(n + 10, vector<int>(4));
    vector<int> gain(4);
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= 3; ++j)
            cin >> gain[j];
        dp[i][1] = gain[1] + max(dp[i - 1][2], dp[i - 1][3]);
        dp[i][2] = gain[2] + max(dp[i - 1][1], dp[i - 1][3]);
        dp[i][3] = gain[3] + max(dp[i - 1][1], dp[i - 1][2]);
    }
    cout << max({dp[n][1], dp[n][2], dp[n][3]}) << '\n';
}

Measured memory_bytes: 5760
#include <iostream>
#include <set>

int main()
{
    int s; std::cin >> s;
    std::set<int> ss;
    ss.insert(s);
    int cnt = 1;
    while (true) {

        // std::cout << s << std::endl;

        s = ((s%2) == 0)?(s/2):(3*s+1);
        cnt++;
        if (ss.find(s) != ss.end()) {
            break;
        }
        ss.insert(s);
    }

    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define int long long
const int mod = 1e9 + 7;
inline int ksm(int a, int b)
{
	int ans = 1;
	for (; b; b >>= 1, a = a * a % mod)
		if (b & 1)
			ans = ans * a % mod;
	return ans;
}
int dp[200][22];int n,k;
int a[2000],top;
int dfs(int d,int lim,int s){
	if(d<1)return s==k;
	if(!lim && ~dp[d][s])return dp[d][s];
	int up=9;if(lim)up=a[d];
	int res=0;
//	cout<<d<<" "<<lim<<" "<<s<<endl;
	rep(i,0,up){
		if(s + (i>0)<=k)
		res += dfs(d-1,lim&&i==up,s+(i>0));
	}
//	cout<<d<<" "<<lim<<" "<<s<<" "<<res<<endl;
	return dp[d][s] = res;
}
signed main()
{
	memset(dp,-1,sizeof dp);
	string s;cin>>s;
	cin>>k;
	int top=s.size();
	rep(i,1,top){
		a[i] = s[top-i+1-1]-'0';
	}
	//rep(i,1,top)cout<<a[i]<<" ";cout<<endl;
//
//	cout<<top<<endl;

	cout<<dfs(top,1,0)<<endl;
	getchar(); //
	getchar();
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)
ll N, K;
ll cl[101010];
ll dp[60][60][5000];
ll i,j,k,l,ans;



int main(){
    scanf("%lld%lld", &N, &K);
    if(K%2){
        printf("0");
        return 0;
    }
    dp[0][0][0] = 1;
    fornum(i,0,N){
        //printf("%lld:\n", i + 1);
        fornum(j,0,N){
            fornum(k,2*j,N*N+1){
                if(j>0)
                    dp[i + 1][j][k] = ((1 + 2 * j) * dp[i][j][k - 2 * j] + j * j * dp[i][j - 1][k - 2 * j] + dp[i][j + 1][k - 2 * j])%MOD;
                else
                    dp[i + 1][j][k] = ((1 + 2 * j) * dp[i][j][k - 2 * j] + dp[i][j + 1][k - 2 * j])%MOD;
                //printf("%lld,", dp[i + 1][j][k]);
            }
            //printf("\n");
        }
    }
    printf("%lld", dp[N][0][K]);
    return 0;
}

Measured memory_bytes: 119040
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, k, a[100100], b[44], x, res;

signed main() {
	cin >> n >> k;
	rep(i,n) {
		cin >> a[i];
		rep(j,40) if (a[i]>>j&1) b[j]++;
	}
	repr(i,40) if (b[i]<=n/2 && (x|(1ll<<i))<=k) x |= 1ll<<i;
	rep(i,n) res += a[i]^x;
	cout << res << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
  int i=1,res,D,N,count=0,v,mod;
  scanf("%d %d",&D,&N);
  mod = (int)(pow(100,D));
  if(D == 0){
    if(N==100)
      N=101;
    printf("%d\n",N);
    return 0;
  }
  
  while(1){
    if(count == N){
      res = i-1;
      break;
    }
    if(((i % mod) == 0) && (((i / mod) % 100) != 0 )){
      count++;
    }
    i++;
  }
  printf("%d\n",res);
  return 0;

}


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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
#define LEN(x) ll(x.length()) //lengthをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    string n;
    cin >> n;
    ll ans = 0;
    for(ll i = 0; i < LEN(n); i++) ans += n[i]-'0';
    if(ans % 9 == 0) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll; 
int main() {
  ll a, b;cin>>a>>b;
  ll cnt=0;
  
  rep(i, 2) {
    if(a>=b) {
      cnt+=a;
      a--;
    }
    else {
      cnt+=b;
      b--;
    }
  }
  cout << cnt;
}
    

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();

        string s = cin.next();

        int ans = int.MaxValue;
        for (int i = 0; i < s.Length -2; i++)
        {
            int a = int.Parse(s.Substring(i, 3));
            ans = Math.Min(ans, Math.Abs(753 - a));
        }

        Console.WriteLine(ans);
    }

}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13140
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <stack>
#include <list>
using namespace std;
int N;
list<int> state;

void solve(int n, int left){
  if(n==0){
    list<int> tmp = state;
    cout << tmp.front();
    tmp.pop_front();
    while(!tmp.empty()){
      cout << " " << tmp.front();
      tmp.pop_front();
    }
    cout << endl;
  }
  for(int i=min(n,left); i>0; --i){
    state.push_back(i);
    solve(n-i, i);
    state.pop_back();
  }
}
int main(){
  while(cin >> N && N){
    
    solve(N, N);
  }
  return 0;
}

Measured memory_bytes: 1192
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <iostream>

using namespace std;

int main() {
    int A, B;
    cin >> A;
    cin >> B;

    if(A < 9 && B < 9)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;

int main(void) {
	double r;
	scanf("%lf", &r);
	printf("%lf\n", 2 * r*M_PI);
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

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

class CommonIO {
public:
  CommonIO() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
  }
  ~CommonIO() {}

  template <class T>
  void scan(T &v) {
      std::cin >> v;
  }
  template <class T, class... Rest>
  void scan(T &v, Rest&... rest) {
      scan(v);
      scan(rest...);
  }

  template <class T>
  void print(T v) {
    std::cout << v;
  }
  template <class T>
  void print(std::vector<T> &v) {
    if (v.size() == 0) return;
    print(*v.begin());
    for (auto it = ++v.begin(); it != v.end(); ++it) {
        print(' ');
        print(*it);
    }
  }
  template <class T>
  void print(std::vector< std::vector<T> > &grid) {
    if (grid.size() == 0) return;
    print(*grid.begin());
    for (auto it = ++grid.begin(); it != grid.end(); ++it) {
      print('\n');
      print(*it);
    }
  }
  template <class T, class... Rest>
    void print(T v, Rest... rest) {
    print(v);
    print(' ');
    print(rest...);
  }

  template <class T>
    void printl(T v) {
    print(v);
    std::cout << '\n';
  }
  template <class T, class... Rest>
    void printl(T v, Rest... rest) {
    print(v);
    print(' ');
    printl(rest...);
  }
  #define original_output(obj) std::ostream& operator<<(std::ostream& stream, const decltype(obj)& obj)
} io;


struct Task {
  int rest;
  string name;
};

int main() {
  int n, q; io.scan(n, q);
  
  queue<Task> tasks;
  Task task;
  REP(i, n) {
    io.scan(task.name, task.rest);
    tasks.push(task);
  }
  
  int time = 0;
  while(!tasks.empty()) {
    task = tasks.front(); tasks.pop();
    if (task.rest <= q) {
      time += task.rest;
      io.printl(task.name, time);
    }
    else {
      time += q;
      task.rest -= q;
      tasks.push(task);
    }
  }

  return 0;
}



Measured memory_bytes: 6316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int solve()
{
    int n;
    cin >>n;
    int ct[3]={};
    rep(i,n)
    {
        int a;
        cin >>a;
        ++ct[a%3];
    }

    int x=ct[1], y=ct[2];
    if(x>y) swap(x,y);

    if(y==0) return 1;

    int ret = 1+ct[0];
    --y;

    int k = min(x,y);
    ret += 2*k;

    x-=k;
    y-=k;

    if(y>=2) ret+=2;
    else ret+=(x>0 || y>0);

    return ret;
}

int main()
{
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  if (n % k > 0) {
    ans = 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3160
while 1:
    s = raw_input().replace("north","0").replace("west","1")[::-1]
    if s == "#": break
    u = 90*int(s[0])
    d = len(s)-1
    for i in s[1:]: u = 2*u+(90 if i == "1" else -90)
    while (u+1)%2*d: u /= 2; d -= 1
    print u if d == 0 else "%d/%d"%(u,2**d)

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

void toss_dice(int _dice[], char direction){
    int temp;
    switch(direction){
        case 'N':
            temp = _dice[1];   
            _dice[1] = _dice[2];
            _dice[2] = _dice[6];
            _dice[6] = _dice[5];
            _dice[5] = temp;
        break;

        case 'S':
            temp = _dice[1];   
            _dice[1] = _dice[5];
            _dice[5] = _dice[6];
            _dice[6] = _dice[2];
            _dice[2] = temp;
        break;

        case 'E':
            temp = _dice[1];
            _dice[1] = _dice[4];
            _dice[4] = _dice[6];
            _dice[6] = _dice[3];
            _dice[3] = temp;
        break;
        
        case 'W':
            temp = _dice[1];
            _dice[1] = _dice[3];
            _dice[3] = _dice[6];
            _dice[6] = _dice[4];
            _dice[4] = temp;
        break;
    }
}

void counterclock_90(int _dice[]){
    toss_dice(_dice, 'E');
    toss_dice(_dice, 'S');
    toss_dice(_dice, 'W');
}

void print_dice(int _dice[]){
    int i;
    for(i=1; i<=6; i++)
        printf("%d ", _dice[i]);
    printf("\n");
}

int compare_dice(int _dice1[], int _dice2[]){
    int i;
    for(i=1; i<=6; i++){
        if(_dice1[i]!=_dice2[i]) return 0;
    }
    return 1;
}

int same_dice(int _dice1[], int _dice2[]){
    
    //printf("-----------------\n");

    int i,j;
    for(i=0; i<6; i++){
        if(i<4) toss_dice(_dice1, 'N');
        else if(i==4) toss_dice(_dice1, 'E');
        else{
            toss_dice(_dice1, 'W');
            toss_dice(_dice1, 'W');
        }
        for(j=0; j<4; j++){
            counterclock_90(_dice1);
            if(compare_dice(_dice1, _dice2)) return 1;
            //print_dice(_dice1);
        }
        //printf("-----------------\n");
    }
    return 0;
}

int main(){
    int dice1[7], dice2[7];
    int i,j;
    for(i=1; i<=6; i++)
        scanf("%d", &dice1[i]);
    //getchar();
    for(i=1; i<=6; i++)
        scanf("%d", &dice2[i]);
    if(same_dice(dice1, dice2)) printf("Yes\n");
    else printf("No\n");
    //same_dice(dice);
}



Measured memory_bytes: 2112
n,k = (int(i) for i in input().split())
s = input()
s,num = "x"+s+"x",0
for i in range(1,n+1):
    if (s[i]=="L" and s[i-1]=="L") or (s[i]=="R" and s[i+1]=="R"): num+=1
print(min(num+2*k,n-1))

Measured memory_bytes: 3316
#include <cstdio>
#include <algorithm>
using namespace std;
void read(int &a){
	a=0;
	char c=getchar();
	while(c<'0'||c>'9'){
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		a=(a<<1)+(a<<3)+(c^48);
		c=getchar();
	}
}
const int Maxn=200000;
struct Node{
	int x,y;
	int id;
	friend bool operator <(Node a,Node b){
		return a.x<b.x;
	}
}a[Maxn+5];
int n;
int ans[Maxn+5];
int main(){
	read(n);
	for(int i=1;i<=n;i++){
		read(a[i].x),read(a[i].y);
		a[i].id=i;
	}
	sort(a+1,a+1+n);
	int x=n+1;
	int last=0;
	for(int i=1;i<=n;i++){
		x=min(x,a[i].y);
		if(x==n-i+1){
			ans[a[i].id]=i-last;
			last=i;
		}
	}
	for(int i=n;i>0;i--){
		if(ans[a[i].id]==0){
			ans[a[i].id]=ans[a[i+1].id];
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d\n",ans[i]);
	}
	return 0;
}


Measured memory_bytes: 4744
#include <bits/stdc++.h>
#define INF (1<<30)
#define INFLL (1ll<<60)
using namespace std;
map <int,int> mp;
typedef pair<int, int> P;
typedef long long ll;
static const int MAX=100000;

int main(){
    int c[3];
    cin>>c[0]>>c[1]>>c[2];
    sort(c,c+3);
    if((c[0]==c[1]||c[1]==c[2])&&c[0]!=c[2])
        cout<<2<<"\n";
    else if(c[0]==c[1]&&c[1]==c[2])
        cout<<1<<"\n";
    else cout<<3<<"\n";    
    return 0;
}



Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 23.05.2020 15:47:40       
**/
#include <bits/stdc++.h>

using namespace std;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> order(n * n);
  for (int i = 0; i < n * n; i++) {
    cin >> order[i];
    --order[i];
  }
  vector<vector<int>> mat(n, vector<int>(n, 1));
  vector<vector<int>> dist(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dist[i][j] = min(min(i, j), min(n - 1 - i, n - 1 - j));
    }
  }
  vector<pair<int, int>> que;
  vector<vector<int>> inq(n, vector<int>(n, 0));
  long long ans = 0;
  for (int id : order) {
    int i = id / n;
    int j = id % n;
    ans += dist[i][j];
    mat[i][j] = 0;
    que.clear();
    que.emplace_back(i, j);
    inq[i][j] = 1;
    for (int b = 0; b < (int) que.size(); b++) {
      int mi = que[b].first;
      int mj = que[b].second;
      inq[mi][mj] = 0;
      int val = dist[mi][mj] + mat[mi][mj];
      for (int dir = 0; dir < 4; dir++) {
        int ni = mi + di[dir];
        int nj = mj + dj[dir];
        if (ni >= 0 && nj >= 0 && ni < n && nj < n && val < dist[ni][nj]) {
          dist[ni][nj] = val;
          if (inq[ni][nj] == 0) {
            que.emplace_back(ni, nj);
            inq[ni][nj] = 1;
          }
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 9184
from itertools import permutations
n, m, r = map(int, input().split())
INF = 1 << 60

d = [[INF] * n for i in range(n)]
rs = list(map(int, input().split()))

for i in range(m):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c

def warshall_floyd(d):
    """
    input
        d : 初期全点対距離
    output
        d : 最適化後全点対距離
    """
    n = len(d)
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d

d_optimized = warshall_floyd(d)
# print(d_optimized)

ans = INF
for inds in permutations([r-1 for r in rs]):
    cnt = 0
    for i in range(r-1):
        prev = inds[i]
        nxt = inds[i+1]
        cnt += d_optimized[prev][nxt]
    ans = min(ans,cnt)
print(ans)

Measured memory_bytes: 46936
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Peaks
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

int hs[MAX_N];
bool ngs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++) scanf("%d", hs + i);

  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    if (hs[a] < hs[b]) ngs[a] = true;
    else if (hs[a] > hs[b]) ngs[b] = true;
    else ngs[a] = ngs[b] = true;
  }

  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (! ngs[i]) cnt++;
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int h, w, K;
    cin >> h >> w >> K;
    V<string> c(h);
    read(c);
    int res = 0;
    for (int i = 0; i < (1 << h); i++) {
        for (int j = 0; j < (1 << w); j++) {
            int co = 0;
            for (int k = 0; k < h; k++) {
                for (int l = 0; l < w; l++) {
                    if (kbit(i, k) || kbit(j, l)) continue;
                    co += c[k][l] == '#';
                }
            }
            res += (co == K);
        }
    }
    cout << res << newl;
}

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

int main()
{
    
    map<int,int> mp;
    int n,i;
    cin>>n;
    for(i=0;i<n;i++)
    {   int a;
        cin>>a;
        mp[a]++;
    }
    int cnt=0;
    map<int,int>:: iterator it;
    for(it=mp.begin();it!=mp.end();it++)
    {
        if((it->second)%2!=0)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 4864
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
char in[210000];
long long dp[210000][3][3];
int main(){
	scanf("%s",in);
	int n=strlen(in);
	if(n==2){
		if(in[0]==in[1])printf("1\n");
		else printf("2\n");return 0;
	}
	int f=0;
	for(int i=0;i<n;i++)f+=in[i]-'a';
	f%=3;

	int t=1;
	int u=1;
	for(int i=0;i<n-1;i++){if(in[i]==in[i+1])t=0;else u=0;}
	if(u){
		printf("1\n");return 0;
	}
	if(n==3&&f==0){
		int ret=1;
		if(t)ret+=2;
		printf("%d\n",ret);return 0;
	}
	long long ret=pw(3,n-1);
	dp[1][0][0]=dp[1][1][1]=dp[1][2][2]=1;
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++)for(int k=0;k<3;k++){
			if(dp[i][j][k]==0)continue;
			for(int l=0;l<3;l++){
				if(k==l)continue;
				dp[i+1][(j+l)%3][l]=(dp[i+1][(j+l)%3][l]+dp[i][j][k])%mod;
			}
		}
	}
	ret=(ret+mod-dp[n][f][0])%mod;
	ret=(ret+mod-dp[n][f][1])%mod;
	ret=(ret+mod-dp[n][f][2])%mod;
	
	ret=(ret+t)%mod;

	printf("%lld\n",ret);
}


Measured memory_bytes: 16512
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> // sort
#include <math.h>

#define DEBUG 0

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll mod = 1000000007;
static const ll INF = 1000000000000000000LL;
                    //999999997000000003
                    //1000000000000000000

using namespace std;


ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b; //あまりが0ならそれが、最大公約数
}

int main(){
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    ll a,b;
    cin >> a >> b;
    ll res;
    res = 3 - (a+b)%3;
    cout << res << endl;
    return 0;
}


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

int main() {
  long long n, k;
  cin>>n>>k;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  int l_num[n], r_num[n];
  for (int i=0; i<n; i++) {
    l_num[i] = 0;
    r_num[i] = 0;
    for (int j=0; j<i; j++) {
      if (a[i] > a[j]) {
        ++l_num[i];
      }
    }
    for (int j=i+1; j<n; j++) {
      if (a[i] > a[j]) {
        ++r_num[i];
      }
    }
  }
  long long ans = 0;
  long long MOD = 1e9 + 7;
  long long tmp1 =  (k + 1) * k / 2 % MOD;
  long long tmp2 =  (k - 1) * k / 2 % MOD;
  for (int i=0; i<n; i++) {
    ans += tmp1 * r_num[i];
    ans %= MOD;
    ans += tmp2 * l_num[i];
    ans %= MOD;
  }
  cout<<ans<<endl;
}

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

int main(){

    int x,y,z,k;
    cin >> x >> y >> z >> k;

    vector<ll> a(x),b(y),c(z);

    rep(i,x){
        cin >> a[i];
    }
    rep(i,y){
        cin >> b[i];
    }
    rep(i,z){
        cin >> c[i];
    }

    vector<ll> ab;

    for(int i=0;i<x;i++){
        for(int j=0;j<y;j++){
            ab.push_back(a[i]+b[j]);
        }
    }

    sort(ab.begin(),ab.end(),greater<ll>());

    vector<ll> ans;
    for(int i=0;i<3001&&i<ab.size();i++){
        for(int j=0;j<z;j++){
            ans.push_back(ab[i]+c[j]);
        }
    }

    sort(ans.begin(),ans.end(),greater<ll>());

    rep(i,k){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 43240
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(RALL(x))
#define SUM(x) accumulate(ALL(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

int main () {
  int n, m;
  cin >> n >> m;
  vector<pii> key;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    int s = 0;
    rep(j,b) {
      int c;
      cin >> c;
      --c;
      s |= 1<<c;
    }
    key.emplace_back(s,a);
  }

  vi dp(1<<n,INF);
  dp[0] = 0;
  rep(s,1<<n) {
    rep(i,m) {
      int t = s | key[i].fi;
      int cost = dp[s] + key[i].se;
      dp[t] = min(dp[t], cost);
    }
  }
  int ans = dp.back();
  if (ans == INF) ans = -1;
  cout << ans << endl;
}

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

int main(void){
	int n;
	cin>>n;
	int p[n], a[n];
	for(int i=0; i<n ;i++){
		cin>>p[i];
		p[i]--;
		a[p[i]] = i;
	}
	int c[n];
	for(int i=0; i<n ;i++){
		c[i] = 1;
	}
	int ans = 1;
	for(int i=0; i<n; i++){
		if(a[p[i]] < a[p[i]+1]){
			c[p[i]+1] = c[p[i]]+1;
		}
		ans = max(ans, c[p[i]]);
	}
	cout<<n-ans<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
#define rep(i,m,n) for(int i=m;i<n;i++)

#define M 1000000007

typedef long long ll;

int main(int argc, char *argv[]) {

  // combination (mod M)
  vector<vector<ll> > comb;
  vector<ll> v(1,1LL);
  comb.push_back(v);
  rep(i,1,2001) {
    comb.push_back(v);
    rep(j,1,2001) {
      if(j==i) (comb.at(i)).push_back(1LL);
      else if(1<=j && j<=i-1) (comb.at(i)).push_back( ((comb.at(i-1)).at(j-1) + (comb.at(i-1)).at(j)) % M );
      else (comb.at(i)).push_back(0);
    }
  }

  /*rep(i,0,10) {
    rep(j,0,i+1) {
      cout << (comb.at(i)).at(j) << " ";
    }
    cout << endl;
  }*/
  
  int n,k,l;
  cin >> n >> k;
  l = n-k;


  rep(i,1,k+1) {
    cout << ((comb.at(l+1)).at(i)*(comb.at(k-1)).at(i-1)) % M << endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 32384
# printデバッグ用
import sys
argVec = sys.argv
if len(argVec) > 1:
    GBN_DEBUG = True
else:
    GBN_DEBUG = False

def dprn(s, i):
    if GBN_DEBUG:
        print(", " + s + " = " + str(i), end = "")

def dprns(s):
    if GBN_DEBUG:
        print(", " + s, end = "")

def dprni(i):
    if GBN_DEBUG:
        print(str(i), end=" ")

#S = input()
#N = int(input())
#S, T = input().split() 
H, N = map(int, input().split()) 
#W = [input() for _ in range(N)]
A = list(map(int, input().split()))

if sum(A) >= H:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 13964
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){

  int n,a,b;
  string str;

  int m;
  cin >>n>>m ;
  cout <<(n-1)*(m-1) fin;
  
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int tonum(int *lis){
    int ans=0;
    int pp=10000000;
    for(int i=0;i<8;i++){
        ans+=pp*(*(lis+i));
        pp/=10;
    }
    return ans;
}
int main(){
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        string S;
        cin>>S;
        int lis[8];
        for(int i=0;i<8;i++)lis[i]=S[i]-'0';
        sort(lis,lis+8);
        int mi=tonum(lis);
        reverse(lis,lis+8);
        int ma=tonum(lis);
        cout<<ma-mi<<endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#include<iostream>
using namespace std;
int main(){
char text[10001];
int joi,ioi;
while(cin>>text){
for(int i=0;i<9998;i++){
if(text[i]=='J'&& text[i+1]=='O' && text[i+2]=='I')joi++;
if(text[i]=='I'&& text[i+1]=='O' && text[i+2]=='I')ioi++;
}
cout<<joi<<endl<<ioi<<endl;
joi=0;ioi=0;
for( int i = 0; i < 10000; i++ ){
text[i] = '\0';
}

}
return 0;
}

Measured memory_bytes: 1148
import heapq

x, y, z, k = map(int, input().split())
ali = list(reversed(sorted(map(int, input().split()))))
bli = list(reversed(sorted(map(int, input().split()))))
cli = list(reversed(sorted(map(int, input().split()))))

done = {}
count = 0

heap = []


def main(a, b, c):
    global count
    if '{}'.format((a, b, c)) in done:
        return
    done['{}'.format((a, b, c))] = True
    count += 1
    print(ali[a] + bli[b] + cli[c])
    if a + 1 < x:
        heapq.heappush(heap, (-(ali[a + 1] + bli[b] + cli[c]), a + 1, b, c))
    if b + 1 < y:
        heapq.heappush(heap, (-(ali[a] + bli[b + 1] + cli[c]), a, b + 1, c))
    if c + 1 < z:
        heapq.heappush(heap, (-(ali[a] + bli[b] + cli[c + 1]), a, b, c + 1))


main(0, 0, 0)
while count < k:
    s, a, b, c = heapq.heappop(heap)
    main(a, b, c)


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#define NMAX (int)1e5
using namespace std;
int main(){
	int A,B,M,a[NMAX],b[NMAX],x[NMAX],y[NMAX],c[NMAX],answer = (int)1e9;
	cin >> A >> B >> M;
	for (int i = 0; i < A; ++i)
	{
		cin >> a[i];
		answer = min(answer,a[i]);
	}
	int m = (int)1e9;
	for (int i = 0; i < B; ++i)
	{
		cin >> b[i];
		m = min(m,b[i]);
	}
	answer += m;
	for (int i = 0; i < M; ++i)
	{
		cin >> x[i] >> y[i] >> c[i];
		answer = min(answer,a[x[i]-1]+b[y[i]-1]-c[i]);
	}
	cout << answer << endl;
}

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

#define rep(i,n) for(int i = 0;i < (n);i++)

using namespace std;
using ll = long long;
using P = pair<int,int>;



int main(){
	
	int N;
	
	cin >> N;
	
	vector<long> A(N);
	
	for(int i = 0;i < N;i++){
		cin >> A[i];
	}
	
	long sum = 0;
	
	for(int i = 1;i < N;i++){
		if( A[i] < A[i - 1] ){
			sum = sum + A[i - 1] - A[i];
			A[i] = A[i - 1];
		}
	}
	
	cout << sum;
	
	return 0;
	
}


Measured memory_bytes: 4732
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

ll gcd(ll x, ll y) {
  if(x > y)
    return gcd(y, x);
  else if(x == 0)
    return y;
  else
    return gcd(y % x, x);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k; cin >> k;
  ll sum = 0;
  rep(i, k) rep(j, k) rep(l, k) {
    sum += gcd(i+1, gcd(j+1, l+1));
  }
  cout << sum << "\n";
  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define MN 300000
typedef long long LL;
int n,a[MN+5],b[MN+5],c[MN+5];
bool check1(){
	for(int i=1;i<=n;i++)
		if((a[i]-i)&1) return false;
	return true;
}
LL merge_sort(int l,int r){
	if(l==r) return 0;
	int i,j,k,mid=(l+r)>>1;
	LL ret=merge_sort(l,mid)+merge_sort(mid+1,r);
	for(i=l,j=mid+1,k=l;i<=mid&&j<=r;){
		if(b[i]>b[j]){
			ret+=mid-i+1;
			c[k++]=b[j++];
		}else{
			c[k++]=b[i++];
		}
	}
	while(i<=mid) c[k++]=b[i++];
	while(j<=r) c[k++]=b[j++];
	for(int i=l;i<=r;i++) b[i]=c[i];
	return ret;
}
bool check2(){
	for(int i=1;i<=n;i++) b[i]=a[i];
	if(merge_sort(1,n)%3!=0) return false;
	return true;
}
bool check3(){
	for(int i=1;i<=n-2;i++)
		if(a[i]!=i&&a[i+1]!=i+1&&a[i+2]!=i+2) return false;
	return true;
}
bool check4(){
	memset(c,0x7f,sizeof(c));
	for(int i=n;i>=1;i-=2)
		c[std::lower_bound(c+1,c+1+n,a[i])-c]=a[i];
	if(c[3]!=0x7f7f7f7f) return false;
	memset(c,0x7f,sizeof(c));
	for(int i=n-1;i>=1;i-=2)
		c[std::lower_bound(c+1,c+1+n,a[i])-c]=a[i];
	if(c[3]!=0x7f7f7f7f) return false;
	return true;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	if(!check1()) return 0*puts("No");
	if(!check2()) return 0*puts("No");
	if(!check3()) return 0*puts("No");
	if(!check4()) return 0*puts("No");
	return 0*puts("Yes");
}

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

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

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

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

int main()
{
    ll S;
    pll g[3];
    g[0].first = 0;
    g[0].second = 0;

cin>>S;
    ll sq = (ll)std::ceil(sqrt(S));
  
    g[1].first = sq;
    g[2].second = sq;
    ll a = sq * sq - S;
    g[1].second = a;
    g[2].first = 1;

    REP(i, 3)
    {
        cout << g[i].first << " " << g[i].second << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
using namespace std;
int n; string s, dp[309][309];
int main() {
	while (cin >> s, s != "#END") {
		n = s.size();
		string ret;
		for (int i = 1; i < n; i++) {
			string l = s.substr(0, i), r = s.substr(i, n - i);
			for (int j = 1; j <= i; j++) {
				for (int k = 1; k <= n - i; k++) {
					if (l[j - 1] == r[k - 1]) dp[j][k] = dp[j - 1][k - 1] + r[k - 1];
					else if (dp[j][k - 1].size() > dp[j - 1][k].size()) dp[j][k] = dp[j][k - 1];
					else dp[j][k] = dp[j - 1][k];
				}
			}
			if (ret.size() < dp[i][n - i].size()) ret = dp[i][n - i];
		}
		cout << ret << endl;
	}
}

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

int main() {
  string w;
  cin>>w;
  sort(w.begin(),w.end());
  int size=w.size();
  char tmp=w.at(0);
  int count=0;
  for(int i=0;i<size;i++){
    if(tmp!=w.at(i)){
      if(count%2!=0){
        cout<<"No"<<endl;
        return 0;
      }
      tmp=w.at(i);
      count=0;
    }
    count++;
  }
  if(count%2!=0){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 256