akhauriyash/Code-Regression huggingface dataset:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

bit_count = S.count("1")
S_num = int(S,2)
S_min = S_num % (bit_count-1) if bit_count-1!=0 else 0
S_plu = S_num % (bit_count+1)




# calc_dict = {i:-1 for i in range(10000)}
# res_dict =  {i:-1 for i in range(10**4)}

# for i in range(1, 10000):
#     if calc_dict[i]==-1:
#         calc_dict[i] = bin(i).count("1")

#     res_dict[i] = i%calc_dict[i]+1

def mods(temp, count):
    count+=1
    if temp!=0:

#         if temp in res_dict:
#             return count+res_dict[temp]
        
#         if temp not in calc_dict:
#             calc_dict[temp]= bin(temp).count("1") 
        count = mods(temp%bin(temp).count("1") , count)

    return count

for i in range(N):
    if S[i]=="0":
        part = pow(2, (N-i-1), bit_count+1)
        num = (S_plu + part ) % (bit_count+1)
        print(mods(num, 0))
    else:
        if S_num == 2**(N-i-1):
            print(0)
            continue
        part = pow(2, (N-i-1), bit_count-1)
        num = (S_min - part)%(bit_count-1)
        print(mods(num, 0))




Measured memory_bytes: 83068
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(b - a) <= d && abs(b - c) <= d)
    printf("Yes\n");
  else if(abs(a-c) <= d)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}


Measured memory_bytes: 256
a=list(input())
a=a[::-1]
b=list(input())
b=b[::-1]
c=list(input())
c=c[::-1]

player_dict={"a":a,"b":b,"c":c}

last_card="a"

#while (len(player_dict["a"])!=0)and(len(player_dict["b"])!=0)and(len(player_dict["c"])!=0):
while True:
  try:
    last_card=player_dict[last_card].pop()
  except:
    last_card=last_card.upper()
    print(last_card)
    break

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

def pow(n, x):
  if x == 0:
    return 1
  elif x % 2 == 0:
    return pow(n * n % mod, x // 2)
  else:
    return n * pow(n * n % mod, x // 2) % mod

def comb(n, r):
  p, q = 1, 1
  for i in range(r):
    p = p * (n-i) % mod
    q = q * (i+1) % mod
  return p * pow(q, mod-2) % mod

x, y = map(int, input().split())
m = abs(x - y)
n = (x + y) // 3
if (x + y) % 3 == 0 and n >= m:
  print(comb(n, (n + m) // 2))
else:
  print(0)

Measured memory_bytes: 3064
#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; ll k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);

  vector<int> path;
  vector<int> order(n + 1, -1);

  int next = 1;
  while (order.at(next) == -1) {
    order.at(next) = path.size();
    path.push_back(next);
    next = a.at(next - 1);
  }
  int cycle = path.size() - order.at(next);
  int before = order.at(next);

  if (k < before) {
    cout << path.at(k) << endl;
  } else {
    k -= before;
    k %= cycle;
    cout << path.at(before + k) << endl;
  }
  return 0;
}

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

using namespace std;

int main () {
    int n = 0;
    cin >> n;
    vector<string> moji(n);
    for (int i=0; i<n; i++) {
        cin >> moji.at(i);
    }
    vector<int> count(26);
    for (char s='a'; s<='z'; s++) {
        int min = 100000;
        for (string str : moji) {
            int buf = 0;
            for (char c : str) {
                if (c == s) buf++;
            }
            if (buf < min) min = buf;
        }
        count.at(s-'a') = min;
    }
    for (int i=0; i<26; i++) {
        char put = 'a' + i;
        for (int j=0; j<count.at(i); j++) {
            cout << put;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int d[1<<18];
map<long,long>M;
main()
{
	int n;cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>d[i];
	}
	long s=0,ans=0;
	for(long i=0;i<n;i++)
	{
		s+=d[i];
		if(!s)ans=max(ans,i+1);
		if(M[s])ans=max(ans,i-M[s]+1);
		else M[s]=i+1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 16392
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

int main() {
	size_t n; cin >> n;
	if (n & 1 || n < 10) {
		cout << 0 << endl;
		return 0;
	}
	size_t mul = 5, cnt = 0;
	for (int i = 0; i < 26; ++i) {
		cnt += n / mul / 2;
		mul *= 5;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        double[] WHxy = ReadLine().Split(' ').Select(double.Parse).ToArray();
        double W = WHxy[0];
        double H = WHxy[1];
        double x = WHxy[2];
        double y = WHxy[3];
        if(W / 2 == x && H / 2 == y)
        {
            WriteLine($"{W * H / 2} 1");
        }
        else if(y == (H - 2 * y) * x / (W - 2 * x) ||
           y == (2 * y - H) * (W - x) / (W - 2 * x) ||
           H - y == (H - 2 * y) * x / (W - 2 * x) ||
           H - y == (2 * y - H) * (W - x) / (W - 2 * x) ||
           x == W / 2 ||
           y == H / 2)
        {
            WriteLine($"{W * H / 2} 0");
        }
        else
        {
            WriteLine($"{W * H / 2} 0");
        }
    }
}

Measured memory_bytes: 13396
#include <stdio.h>

int main(){
  char a[3],b[3];
  int i, flag = 1;
  scanf("%s %s",a,b);
  
  for(i=0;i<3;i++){
  	if(a[i] != b[2-i]) flag = 0;
  }
  if(flag == 0) printf("NO\n");
  else printf("YES\n");
  return 0;
}

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

using namespace std;
#define ll long long int
int const mod=1000000007;

int main()
{
    ll n,d;
    cin>>n>>d;
    ll ans=0;
    while(n--)
    {
        ll x,y;
        cin>>x>>y;
        ll z=(x*x)+(y*y);
        if(sqrt(z)<=d)
            ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 3672
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int hx[4] = {0, 0, 1, -1};
int hy[4] = {1, -1, 0, 0};

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> mp(h);
  for (int i = 0; i < h; i++)
    cin >> mp[i];
  bool ans = true;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (mp[i][j] == '#') {
        bool c = false;
        for (int k = 0; k < 4; k++) {
          int y = i + hy[k];
          int x = j + hx[k];
          if (x < 0 || x >= w || y < 0 || y >= h)
            continue;
          if (mp[y][x] == '#')
            c = true;
        }
        if (!c)
          ans = false;
      }
    }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
    double a,b,c,d,e,f;

    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF){
        double x=(c*e-b*f)/(a*e-b*d);
        double y=(a*f-c*d)/(a*e-b*d);

        if(fabs(x)<0.001) x=0;
        if(fabs(y)<0.001) y=0;

        printf("%.3lf %.3lf\n",x,y);
    }

    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>    
#define pb push_back
typedef long long ll;
const int inf = 2e9;
using namespace std;
ll MOD = 1000000007;
typedef pair<int,int> ii;
typedef struct {int a,b,c;}iii;

int a,b,c,d,n,q,t,k,m,res,suma,minimo,ans=0,maxi,indi;
int A[30], B[30];


int main(){
    scanf("%d%d%d",&n,&m,&c);
    for(int i=0; i<m; i++) scanf("%d",B+i);

    for(int i=0; i<n; i++) {
      ll sum = 0;
      for(int j=0; j<m; j++){
        scanf("%d",&a);
        sum+=a*B[j];
      }
      if(sum>(c*-1)) ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
A,B,N=map(int, input().split())
import math
re=0
tmp=0

def hoge(i):
    hoge=math.floor(A*i/B)-A*math.floor(i/B)
    return hoge

if N<=B-1:
    re=hoge(N)
else:
    re=hoge(B-1)

print(re)

Measured memory_bytes: 62128
import numpy as np
import math as m

def main(**kwargs):
    r = int(m.log(n) / m.log(k)) + 1
    return r

if __name__ == "__main__":
    cin = np.array(input().split(" ")).astype("int")
    n, k = cin

    cout = main(n=n, k=k)
    print(cout)

Measured memory_bytes: 12500
#include <iostream>

using namespace std;

const int N = 500;
const int INF = 1000000000;

int H, W;
char input[N][N];

int solve(){
  int data[N][N];
  for(int i=0;i<H;i++){
    int cnt = 0;
    for(int j=W-1;j>=0;j--){
      if(input[i][j] == '*') cnt = 0;
      else cnt++;
      data[i][j] = cnt;
    }
  }
  /*  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << data[i][j] << ' ' ;
    }
    cout << endl;
    }*/
  int M = 0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int m = INF;
      for(int k=0;;k++){
	if(i+k >= H) break;
	if(m > data[i+k][j]) m = data[i+k][j];
	if(M < (k+1) * m){
	  M = (k+1) * m;
	  //cout << i << ' ' << j << ' ' << k << ' ' << m << endl;
	}
      }
    }
  }
  return M;
}

main(){
  while(cin >> H >> W){
    if(H == 0 && W == 0) break;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin >> input[i][j];
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 2084
#include<stdio.h>

int main(void){

  int a,b,c;

  scanf("%d%d%d",&a,&b,&c);

  if(a<=b&&b<=c){
    printf("%d %d %d\n",a,b,c);
  }else if(a<=c&&c<=b){
    printf("%d %d %d\n",a,c,b);
  }else if(b<=a&&a<=c){
    printf("%d %d %d\n",b,a,c);
  }else if(b<=c&&c<=a){
    printf("%d %d %d\n",b,c,a);
  }else if(c<=a&&a<=b){
    printf("%d %d %d\n",c,a,b);
  }else if(c<=b&&b<=a){
    printf("%d %d %d\n",c,b,a);
  }

  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define int                 long long
#define FF(i,a,b)           for(int i=a;i<b;i++)
#define BF(i,a,b)           for(int i=a;i>=b;i--)
#define vi                  vector<int>
#define MAP                 map<int,int>
#define pb                  push_back
#define MP                  make_pair
#define F                   first
#define S                   second
#define pi                  pair<int,int>
#define all(v)              v.begin(),v.end()
#define PIE                 3.1415926535897932384626433832795
#define print0(a)           cout<<a<<"\n"
#define print1(a)           cout<<a<<' '
#define print2(a,b)         cout<<a<<" "<<b<<" ";
#define print3(a,b,c)       cout<<a<<" "<<b<<" "<<c<<" ";
#define print4(a,b,c,d)     cout<<a<<" "<<b<<" "<<c<<" "<<d<<" ";
#define FastIO              ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
/**************************************************************************************/
                       /*Global Variables*/
const int mod = 1e9+7;
const int N = 2e5+10;
const int inf = 3e18;

/**************************************************************************************/
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
int Power(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b&1)res*=a;
        a*=a;
        b>>=1;
    }
    return res;
}
signed main()
{
    FastIO;
    // ifstream("a1.in");
    // ofstream("a1.out");
    //freopen("a1.in","r",stdin); freopen("a1.out","w",stdout);
    int T=1;
    //cin>>T;
    for(int t=1;t<=T;t++)
    {
        
        int a,b,n;
        cin>>a>>b>>n;
        int ans = floor((1.0*a*min(b-1,n))/b)-a*floor((1.0*min(b-1,n))/b);
        cout<<ans<<"\n";
        
    }

}
/*
|| Do what you can with all you have,wherever you are. ||

|| Knowing is not enough, we must apply. Wishing is not enough, we must do. ||

|| A goal is a dream with deadline. ||

|| Whether you think you can or you think you can't, you're right. ||
*/



Measured memory_bytes: 3736
#include <stdio.h>

int main()
{
    int X,Y,Z,count=0;

    scanf("%d%d%d",&X,&Y,&Z);

    X = X - 2*Z;

    while(1){
        if(X>=Y){
            count++;
            X = X - (Y+Z);
        }
        else break;
    }

    printf("%d",count);

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define N 100

int main()
{
  int a=0;
  int n,k,i,j,A[N];
  int flag;
  
  scanf("%d",&n);

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

  flag=1;

  while(flag){
    flag=0;
    for(j=n-1;j>=1;j--){
      if(A[j]<A[j-1]){
	k=A[j];
	A[j]=A[j-1];
	A[j-1]=k;
	a++;
	flag=1;
      }
    }
  }

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

  printf("\n%d\n",a);

  return 0;
}



Measured memory_bytes: 2104
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node
{
  int key;
  Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int key)
{
  Node *y = NIL;
  Node *x = root;

  Node *z;
  z = (Node *)malloc(sizeof(Node));
  z->key = key;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL)
  {
    y = x;
    if (z->key < x->key)
    {
      x = x->left;
    }
    else
    {
      x = x->right;
    }
  }
  // この時点でyはzの親か初期値のNIL
  z->parent = y;
  if (y == NIL)
  {
    // 親がNILなのはroot
    root = z;
  }
  else
  {
    // 親の子へ設定
    if (z->key < y->key)
    {
      y->left = z;
    }
    else
    {
      y->right = z;
    }
  }
}

void inorder(Node *u)
{
  if (u == NIL)
  {
    return;
  }
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u)
{
  if (u == NIL)
  {
    return;
  }
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main()
{
  int n;
  int x;
  string command;

  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    cin >> command;
    if (command == "insert")
    {
      scanf("%d", &x);
      insert(x);
    }
    else if (command == "print")
    {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}


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

typedef long long ll;
ll MOD = 1000000007;
ll MOD1 = 2019;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main()
{
    ll L, R, mi = 1LL<<60;
    cin >> L >> R;

    if (R - L > 2019) {
        cout << 0 << endl;
        return 0;
    } else {
        for (ll i = L; i < R; i++) {
            for (ll j = i+1; j <= R; j++) {
                chmin(mi, i*j%2019);
            }
        }
    }
    cout << mi << endl;
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  set<string> S;
  for(int i = 0; i < N; i++){
    string s;
    cin >> s;
    S.insert(s);
  }
  
  cout << S.size() << endl;
  
  return 0;
  
}

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

using namespace std;

int main()
{
	vector<int> tasks;
  	int cost = 0;
  	for (int i = 0; i < 3; i++){
    	int t; cin >> t;
      	tasks.push_back(t);
    }
  	sort(tasks.begin(), tasks.end());
  	for (int i = 0; i < 2; i++){
    	cost += tasks[i + 1] - tasks[i];
    }
  	cout << cost;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

x,y,z = li()

print((x-z)//(y+z))

Measured memory_bytes: 3064
#include <stdio.h>

//int rank_of_finished=0

typedef struct
{
  int time; 
  char name[10];
  
}SET_OF_VALUE;
  
int main()
{

  int i,time_of_passed = 0,n,q,order_of_finished[100000],element_of_finished = 0/*time[100000]*/;
  SET_OF_VALUE set[100000];
  //char name[100000][10];

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

  for(i = 0; i<n ; i++) scanf("%s %d",set[i].name,&set[i].time);
  // printf("\n");//test
  while(element_of_finished < n)
    {
      for(i = 0 ; i< n ; i++)
	{
	  if(set[i].time <= 0)continue;
	  if(set[i].time <= q)
	    {
	      time_of_passed += set[i].time;
	      set[i].time = -1*time_of_passed;
	      order_of_finished[element_of_finished] = i;
	      element_of_finished++;
	      continue;
	    }
	  else
	    {
	      set[i].time = set[i].time - q;
	      time_of_passed += q;
	    }

	}
    }

  for(i=0 ; i<n ; i++)
    {
      printf("%s %d\n",set[order_of_finished[i]].name,-1*set[order_of_finished[i]].time);
          }
  

}



Measured memory_bytes: 2672
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
long long x, y, a, b, c;
long long p[100010], q[100010], r[100010], z, ans;
priority_queue<pair<long long, int> > que;
int main() {
	cin >> x >> y >> a >> b >> c;
	for (long long i = 1; i <= a; i++) cin >> p[i], que.push(make_pair(p[i], 1));
	for (long long i = 1; i <= b; i++) cin >> q[i], que.push(make_pair(q[i], 2));
	for (long long i = 1; i <= c; i++) cin >> r[i], que.push(make_pair(r[i], 3));
	while (!que.empty()) {
		if (x + y <= z) break;
		int f = que.top().first;
		int s = que.top().second;
		que.pop();
		if (s == 1 && x > 0) {
			ans += f;
			x--;
		} else if (s == 2 && y > 0) {
			ans += f;
			y--;
		} else if (s == 3) {
			ans += f;
			z++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 12396
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

void c()
{
  int N, M;
  cin >> N >> M;
  int num[M];
  for (int i = 0; i < M; i++)
    cin >> num[i];
  sort(num, num + M);
  int div[M - 1];
  for (int i = 0; i < M - 1; i++)
    div[i] = num[i + 1] - num[i];
  sort(div, div + M - 1);
  int64_t sum = 0;
  for (int i = 0; i <= M - N - 1; i++)
    sum += div[i];
  cout << sum;
}
int main(void)
{
  c();
  return 0;
}


Measured memory_bytes: 1024
N, A, B = map(int, input().split())
ans = 0
for i in range(1, N+1):
    num_str = str(i)
    nums = list(num_str)
    nums_int = list(map(int, nums))
    num_sum = sum(nums_int)
    if A <= num_sum <= B:
        ans += i
print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		if (s.indexOf("a") != -1 && s.indexOf("b") != -1 && s.indexOf("c") != -1) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>

int main() {
    int n;
    
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        std::vector<int> V;
        int a, b, c; std::cin >> a >> b >> c;
        V.push_back(pow(a,2)); V.push_back(pow(b, 2)); V.push_back(pow(c, 2));
        std::sort(V.begin(), V.end());
        if (V[2] == V[1] + V[0]) printf("YES\n");
        else printf("NO\n");
    }
    
    return 0;
}



Measured memory_bytes: 3172
def gcd(a: int, b: int) -> int:
    return gcd(b, a % b) if b > 0 else a


A, B, C, D = map(int, input().split())


def calc(n: int, div: int) -> int:
    assert div > 0
    return n // div


def calc2(l: int, r: int, div: int) -> int:
    assert r >= l
    assert div > 0
    return calc(r, div) - calc(l - 1, div)


lcm = (C * D) // gcd(C, D)

k = calc2(A, B, C) + calc2(A, B, D) - calc2(A, B, lcm)
print(B - A + 1 - k)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
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;
    cin>>N;
    vector<int> A(N);
    map<int,int> Acnt;
    rep(i,N) cin>>A[i];
    rep(i,N) Acnt[A[i]]++;
    int cnt=0;
    for(auto i=Acnt.begin(); i!=Acnt.end(); i++){
        cnt+=-1+i->second;
    }
    if(cnt%2) cout<<Acnt.size()-1<<endl;
    else cout<<Acnt.size()<<endl;
}

Measured memory_bytes: 5376
#include <iostream>
#include <cmath>
using namespace std;
#define ll long long
const ll N = 1e6+107;
ll n,i,k,op,p[N];
ll gauss(ll x)
{
    ll y;
    double delta;
    delta=1+8*x;
    y=(sqrt(delta)-1)/2;
    return y;
}
int main ()
{
    cin>>n;
    for (i=2;i*i<=n;++i)
    {
        if (n%i==0)
        {
            k++;
            while (n%i==0)
            {
                p[k]++;
                n=n/i;
            }
        }
    }
    if (n>1) p[++k]=1;
    for (i=1;i<=k;++i)
        op+=gauss(p[i]);
    cout<<op<<"\n";
}



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


int main (void) {
    int N ;
    cin >> N ;
    int valu[N][3] ;
    for (int i = 0 ; i< N ; i++) {
        for (int j = 0 ; j<3 ; j++) {
            cin >> valu[i][j] ;
        }
    }
    int coshap[N][3] ;

    coshap[0][0] = valu[0][0] ;
    coshap[0][1] = valu[0][1] ;
    coshap[0][2] = valu[0][2] ;
    for (int i = 1 ; i < N ; i++) {
        coshap[i][0] = valu[i][0] + max(coshap[i-1][1], coshap[i-1][2]) ;
        coshap[i][1] = valu[i][1] + max(coshap[i-1][0], coshap[i-1][2]) ;
        coshap[i][2] = valu[i][2] + max(coshap[i-1][1], coshap[i-1][0]) ;
    }
    int ans ;
    ans = max(coshap[N-1][0],max(coshap[N-1][1],coshap[N-1][2])) ;
    cout << ans ;

}


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

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

int main() {
    int ans = 1;
    rep(i, 5) {
       int tmp;
        cin >> tmp;
        if(tmp==0){
            break;
        }
        ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3592
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    x, y, z = MI()

    print(z, x, y)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.util.Arrays.binarySearch;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {

    private static int mod = 998244353;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int a = in.nextInt();
        int b = in.nextInt();
        if (a >= 1 && a <= 9 && b >= 1 && b <= 9) {
            out.println(a * b);
        } else {
            out.println(-1);
        }
    }

}

class InputReader {

    private final BufferedReader reader;
    private StringTokenizer      tokenizer;

    public InputReader(InputStream stream){
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

}


Measured memory_bytes: 23380
#include<stdio.h>

int main(){

　int A,B,C;
  int change = 0;
  scanf("%d %d %d",&A,&B,&C);
  
  change = A;
  A = B;
  B = change;
  
  change = A;
  A = C;
  C = change;
  
  printf("%d %d %d",A,B,C);
  
  return 0;
  
  }

Measured memory_bytes: 128
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

fn main() {
    let n = read_i64() as usize;
    let xs = read_vec_i64();
    let mut ys = vec![];
    for i in 0..n {
        if i == 0 || xs[i] != xs[i-1] {
            ys.push((xs[i], 1));
        }
        else {
            let m = ys.len();
            ys[m-1].1 += 1;
        }
    }
    let mut res = 0;
    for &(_,m) in &ys {
        res += m/2;
    }
    println!("{}", res);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 4352
a = []
N = 100000
i = 6
a.append(1)
while i<=N:
    a.append(i)
    i*=6
i = 9
while i<=N:
    a.append(i)
    i*=9
a.sort()
n = len(a)
dp = [10*20]*100001

dp[0],dp[1]=0,1 

for mon in range(2,100001):
    for i in range(n):
        if a[i]>mon:
            break
        dp[mon] = min(dp[mon],dp[mon-a[i]]+1)
print(dp[int(input())])        

Measured memory_bytes: 3956
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

ll vs[3010][3010], dp[3010][3010][4][2];
int main() {
    int R, C, K; scanf("%d%d%d", &R, &C, &K);
    for(int i=0; i<K; i++) {
        int r, c, v; scanf("%d%d%d", &r, &c, &v);
        r--; c--;
        vs[r][c] = v;
    }

    fill(dp[0][0][0], dp[R][0][0], -LONGINF);
    dp[0][0][0][0] = 0;
    for(int r=0; r<R; r++) {
        for(int c=0; c<C; c++) {
            for(int k=0; k<=3; k++) {
                for(int f=0; f<2; f++) {
                    // ひろう
                    if(k < 3) {
                        chmax(dp[r][c][k+1][1], dp[r][c][k][0] + vs[r][c]);
                    }
                    // 右 (リセットしない)
                    if(c+1 < C) {
                        chmax(dp[r][c+1][k][0], dp[r][c][k][f]);
                    }
                    
                    // 下 (リセットする)
                    if(r+1 < R) {
                        chmax(dp[r+1][c][0][0], dp[r][c][k][f]);
                    }
                }
            }
        }
    }

    ll ans = 0;
    for(int k=0; k<=3; k++) {
        for(int f=0; f<2; f++) {
            chmax(ans, dp[R-1][C-1][k][f]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 638432
while line = gets.chomp do
  exit if line == "0 0"
  n, x = line.split(" ").map(&:to_i)
  count = 0
  for i in 1..n do
    for j in i+1..n do
      k = x - j - i
      next if n < k
      if (j < k) then
        count += 1
      else
        break
      end
    end
  end
  printf "%d\n", count
end

Measured memory_bytes: 8816
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    
    int all = 1, odd = 1;
    For(i, n){
        all *= 3;
        odd *= (a[i] % 2 == 0 ? 2 : 1);
    }
    Cout(all - odd);
}





Measured memory_bytes: 256
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        r: usize,
        g: usize,
        r_c: usize,
        g_c: usize,
        n_c: usize,
        r_v: [i64; r_c],
        g_v: [i64; g_c],
        n_v: [i64; n_c]
    }
    let top = r + g;
    let mut r_v = r_v;
    r_v.sort_by(|a, b| b.cmp(a));
    let r_tops = r_v[..r].to_vec();
    let mut g_v = g_v;
    g_v.sort_by(|a, b| b.cmp(a));
    let g_tops = g_v[0..g].to_vec();

    let mut alls = [r_tops, g_tops, n_v].concat();
    alls.sort_by(|a, b| b.cmp(a));
    let answer = alls[..top].iter().fold(0, |acc, x| acc+x);
    println!("{}", answer);
}


Measured memory_bytes: 14588
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, W; cin >> N >> W;
  vector<vector<ll>> dp(N + 1, vector<ll> (W + 1));
  for(ll i = 0; i < W + 1; i++) dp.at(0).at(i) = 0;
  for(ll i = 1; i < N + 1; i++) {
    ll v, w; cin >> w >> v;
    for(ll j = 0; j < W + 1; j++) {
      if(j - w >= 0) {
        dp.at(i).at(j) = max(dp.at(i - 1).at(j - w) + v, dp.at(i - 1).at(j));
      } else dp.at(i).at(j) = dp.at(i - 1).at(j);
    }
  }
  cout << dp.at(N).at(W) << endl;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll A, B, C, D; cin >> A >> B >> C >> D;
    string ans = "Yes";
    while (true) {
        C -= B;
        if (C <= 0) {
            ans = "Yes";
            break;
        }
        A -= D;
        if (A <= 0) {
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)


#define SZ(x) ((int)(x).size())


typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
struct Vector{
    double x, y;
};

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;
}
using namespace std;

int main()
{
    double L;
    cin >> L;
    double k = L*L*L / 27;
    printf("%.15f\n", k);
    return 0;
}


Measured memory_bytes: 3656
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   998244353
#define PI 2*acos(0.0)
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}

//=============================================ASIFAZAD==============================================//

int32_t main()
{
    io;
    int x;
    cin>>x;
    if(x >= 1800)
        cout<<1;
    else if(x >= 1600)
        cout<<2;
    else if(x >= 1400)
        cout<<3;
    else if(x >= 1200)
        cout<<4;
    else if(x >= 1000)
        cout<<5;
    else if(x >= 800)
        cout<<6;
    else if(x >= 600)
        cout<<7;
    else
        cout<<8;
    return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
	public static int LongSC(String a, String b) {
		int[][] data = new int[a.length()+1][b.length()+1];
		for (int i=1;i<a.length()+1;i++) {
			for(int j=1;j<b.length()+1;j++) {
				if(a.charAt(i-1)==b.charAt(j-1)) {
					data[i][j]=data[i-1][j-1]+1;
				}
				else{
					data[i][j]=max(data[i-1][j],data[i][j-1]);
				}
			}
			//for (int z =0;z<a.length();z++) {
			//	System.out.println(Arrays.toString(data[z]));
			//}
			//System.out.println();
		}
		return data[a.length()][b.length()];
	}
	public static int max(int a,int b) {
		if(a>=b) {
			return a;
		}
		else {
			return b;
		}
	}
	public static void main(String[] wjy) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		for (int m=0;m<num;m++) {
			String first = sc.next();
			String second=sc.next();
			System.out.println(LongSC(first,second));
		}
	}
}


Measured memory_bytes: 64724
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
// set<int>st{ 3,1,4,1,5,9,2,6,5,3,5 };
//     for (auto itr = st.begin(); itr != st.end(); ++itr) {
//         cout << *itr;
//     }
#include <bits/stdc++.h>
#include <regex>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
 int n,x,t;
 cin>>n>>x>>t;
 if(n%x==0){
   cout<<n/x*t<<endl;
 }else{
   cout<<(n/x+1)*t<<endl;
 }
}


Measured memory_bytes: 3580
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;
#define prin(num) cout << num << endl;
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000001
#define MAX 100000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> P;

int main(void) {
    ll i, n;
    string s, t;
    cin >> n;
    cin >> s >> t;
    
    for(i=0; i<n; i++) {
        if(s.substr(i, n-i)==t.substr(0, n-i)) {
            prin(i*2+n-i)
            return 0;
        }
    }
    prin(n*2)
    
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    
  
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e-a <= k) cout << "Yay!";
  else cout << ":(";
        return 0;
}


Measured memory_bytes: 256
function Main(input){
	input=input.split(/\n/);
	input.forEach(function(e,i,a){a[i]=Number(a[i]);});
	console.log((input[0]<input[1]?input[0]:input[1])+(input[2]<input[3]?input[2]:input[3]));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22204
import itertools
s=input()
ans=0
L=len(s)
for sta in itertools.product(range(2),repeat=L-1):  
  cut=[-1]+[i for i in range(L-1) if sta[i]]+[L-1]
  for i in range(len(cut)-1):
    ans+=int(s[cut[i]+1:cut[i+1]+1])
print(ans)


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

int main(){
  int n,w,h,p,x1,y1,x2,y2;
  int m[16][16];
  bool rh[16][16],rw[16][16];

  cin >> n;
  while(n--){
    cin >> w >> h;

    for(int i=0;i<=h;i++){
      for(int j=0;j<=w;j++)m[i][j] = 0;
    }
    m[0][0] = 1;

    for(int i=0;i<=h;i++){
      for(int j=0;j<=w;j++){
	rh[i][j] = true;
	rw[i][j] = true;
      }
    }

    cin >> p;
    for(int i=0;i<p;i++){
      cin >> x1 >> y1 >> x2 >> y2;
      if(x1 == x2)rh[min(y1,y2)][x1] = false;
      if(y1 == y2)rw[y1][min(x1,x2)] = false;
    }

    for(int i=0;i<=h;i++){
      for(int j=0;j<=w;j++){
	if(i>0 && rh[i-1][j])m[i][j] += m[i-1][j];
	if(j>0 && rw[i][j-1])m[i][j] += m[i][j-1];
      }
    }

    if(m[h][w])cout << m[h][w] << endl;
    else cout << "Miserable Hokusai!\n";
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
int lcm(int a, int b) { return a / __gcd(a, b) * b; }
 
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    
    //cin >> tc;
    while (tc--)
    {
        int n, m;
        cin >> n;
        int a[n];
        map<int, int> mp;
        int ans = 0;
        for (int i = 0;  i<n; i++)
        {
            cin >> a[i];
            mp[i - a[i]]++;
        }
        for (int i = 0; i <n;i++){
           
            ans += mp[a[i] + i];
            mp[i-a[i]]--;
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 27768
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskB {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int[] a = new int[n];
			long s = 0;
			for (int i = 0; i < n; i++) {
				a[i] = in.nextInt();
				s += a[i];
			}
			long s1 = n * (long) (n + 1) / 2;
			if (s % s1 != 0) {
				out.println("NO");
				return;
			}
			long m = s / s1;
			long used = 0;
			for (int i = 0; i < n; i++) {
				long x = a[(i + 1) % n] - a[i];
				if ((m - x) % n != 0) {
					out.println("NO");
					return;
				}
				long k = (m - x) / n;
				if (k < 0 || k > m) {
					out.println("NO");
					return;
				}
				used += k;
			}
			if (used != m) {
				out.println("NO");
				return;
			}
			out.println("YES");
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 24076
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  int N;  cin>>N;
  int mi = inf;
  for(int i=0 ; i<=100000 ; i++){
    if(1000*i-N<0) continue;
    chmin(mi, 1000*i-N);
  }
  cout<<mi<<endl;
  return 0;
}


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

int main(void) {
    int x1, y1, x2, y2; 
    int x3, y3, x4, y4; 

    cin >> x1 >> y1 >> x2 >> y2; 
        
    int x12, y12;
    x12 = x2 - x1; 
    y12 = y2 - y1; 

    x3 = x2 - y12;
    y3 = y2 + x12;
    x4 = x1 - y12;
    y4 = y1 + x12;

    cout << x3 << " " << y3 << " " << x4 << " " << y4;
    return 0;
}


Measured memory_bytes: 256