akhauriyash/Code-Regression huggingface dataset:
//#define _GRIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
int gcd(int a, int b)
{
    for (;;)
    {
        if (a == 0) return b;
        b %= a;
        if (b == 0) return a;
        a %= b;
    }
}
 
int lcm(int a, int b)
{
    int temp = gcd(a, b);
 
    return temp ? (a / temp * b) : 0;
}
 
signed main() {
    int n;
    cin >> n;
    int ans = 1;
    for(int i=0; i<n; ++i) {
        int t;
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100
using namespace std;
int n,m,p[N],ans;
string s[N],t;

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    ans=0;
    for(int i=0;i<n;i++)cin>>s[i]>>p[i];
    for(int i=0;i<m;i++){
      cin>>t;
      for(int j=0;j<n;j++){
	int f=0;
	for(int k=0;k<8;k++)
	  if(s[j][k]!='*'&&s[j][k]!=t[k])f=1;
	if(!f)ans+=p[j];
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

const int maxn = 65;
bool ch[maxn];
long long mask[maxn];
long long a[100005], all;
void Insert(long long t){
    for(int i=60;i>=0;i--){
        if(ch[i]) continue;
        if((t>>i)&1){
            if(mask[i]==0){
                mask[i] = t;
                return;
            }
            t^=mask[i];
        }
    }

}


int main()
{

    int n;
    scanf("%d", &n);
    all = 0;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld", &a[i]);
        all^=a[i];
    }
    for(int i=0;i<=60;i++){
        if((all>>i)&1) ch[i] = 1;
        else ch[i] = 0;
    }
    for(int i=0; i<=60; i++){
        if(ch[i]){
            for(int j=1;j<=n;j++){
                if((a[j]>>i)&1){
                    a[j]^=(1LL<<i);
                }
            }
        }
    }
    for(int i=1; i<=n; i++){
        Insert(a[i]);
    }
    long long ans = 0;
    for (int i = 60; i >= 0; i--) {
		if (!mask[i]) continue;

		if (ans & (1LL<<i)) continue;

		ans ^= mask[i];
	}
    printf("%lld\n", ans + (all ^ ans));

    return 0;
}



Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
namespace AOJ
{
    class AOJ202
    {
        bool[] sosu;//実はfalseが素数値

        void create_sosu_table(int n)
        {
            sosu = new bool[n + 1];
            for (int i=2; i <= n; i++)
            {
                if (sosu[i] == false)
                {
                    for (int j = 2; i * j <= n; j++)
                    {
                        sosu[i * j] = true;
                    }

                    if (i * i >= n)
                    {
                        //これ以上素数なし
                        break;
                    }
                }
            }
        }

        int[] vals;
        int n, x;
        int max_sosu;
        public string solve(int p_n,int p_x)
        {
            n = p_n;
            x = p_x;

            create_sosu_table(x);

            for (int i = x; i > 0; i--)
            {
                if (!sosu[i])
                {
                    max_sosu = i;
                    break;
                }
            }

                vals = new int[n];

            for (int i = 0; i < n; i++)
            {
                vals[i] = int.Parse(Console.ReadLine());
            }

            //最大値を取得
            int r = maxVal(0, 0);
            if (r > 0)
            {
                return r.ToString();
            }
            return "NA";
        }
        int max(int x, int y)
        {
            return (x > y) ? x : y;
        }
        int maxVal(int i,int sum)
        {
            if (i >= n)
            {
                if (!sosu[sum])
                {
                    return sum;
                }
                else
                {
                    return 0;
                }
            }

            int max_sum = 0;

            for (int j = 0; j <=x ; j++)
            {
                int tmp = (vals[i] * j) + sum;
                if (tmp > x) break;
                max_sum = max(maxVal(i + 1, tmp), max_sum);
                if (max_sum == max_sosu)
                {
                    break;
                }
            }
            return max_sum;
        }
    }
    class Program
    {
        
        static void Main(string[] args)
        {
            AOJ202 obj = new AOJ202();
            while (true)
            {
                char[] delimi = { ' ' };
                string[] str = Console.ReadLine().Split(delimi);
                int n = int.Parse(str[0]);
                int x = int.Parse(str[1]);
                if (n == 0 && x == 0) break;

                Console.WriteLine(obj.solve(n,x));
            }
        }
    }
}

Measured memory_bytes: 8916
#include<cstdio>
int main(){
	int a,b;
	for(int i=1;i<=10000;i++){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0){
			break;
		}else if(a < b){
			printf("%d %d\n",a,b);
		}else{
			printf("%d %d\n",b,a);
	}
}
}

Measured memory_bytes: 2700
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    ll x,t; cin>>x>>t;
    cout<<max(0LL,x-t)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    int a[n];
    rep(i,n){
        cin>>a[i];
    }
    //sort(a,a+n);
    int dp[1000003]{};
    
     bool z=false;
     rep(i,n){
         int q=a[i];
         for(int j=2;j*j<=q;j++){
             if(q%j==0){
                 if(dp[j]!=0){
                     z=true;
                     break;
                 }else{
                     dp[j]=1;
                     while(q%j==0)q/=j;
                 }
             }
         }
         if(q!=1&&dp[q]==1){
             z=true;
            break;
         }else if(q!=1){
             dp[q]=1;
         }
         if(z)break;
     }
    // rep(i,n){
    //     if(a[i]==a[i+1]){
    //         z=true;
    //         break;
    //     }

    //     for(int j=1;a[i]*j<=a[n-1];j++){
    //         if(j==1&&dp[a[i]*j]!=0){
    //             z=true;
    //             break;
    //             //z=true;
    //         }else dp[a[i]*j]=1;
    //     }
    //     if(z)break;
    // }
    // //cout<<z << " ";
    // rep(i,20)cout<<dp[i]<<" ";
    if(z==false){
        cout<<"pairwise coprime"<<endl;
        return 0;
    }
    int p=a[0];
    for(int i=1;i<n;i++){
        p=__gcd(p,a[i]);
    }
    if(p==1)cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;




    



}


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

inline int read(){
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}

inline void write(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}

inline void writeln(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
     puts("");
}

signed main(){
    int n=read();
    
    int m=n%1000;
    int ans=1000-m;
    
    if(n%1000==0)
        ans=0;
    
    writeln(ans);
    return 0;
}

Measured memory_bytes: 3628
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      int A = sc.nextInt();
      int P = sc.nextInt();
      System.out.println((A * 3 + P) / 2);
	}
}


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

int main(){
	int N;
	long long H[100001];
	cin >> N;
	for(int i = 1; i <= N; i++){
		cin >> H[i];
	}

	int flag = 0;
	for(int i = N; i > 1; i--){
		if( H[i-1] > H[i] ){
			H[i-1]--;
			if( H[i-1] > H[i] ){
				flag = 1;
				break;
			}
		}
	}
	
	if(flag == 0) cout << "Yes" << endl;
	else cout << "No" << endl;	
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;

int main(){
    double x1,y1,x2,y2;
    scanf("%lf %lf %lf %lf" ,&x1,&y1,&x2,&y2);
    printf("%f",sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
    return 0;
}


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

#define    ll     long long int

int main( )
{
    double mx_percent = 0.0;
    int mx_sugar_water = 0;
    int mx_sugar = 0;

    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    int i, j, k, l, mass_water, mass_sugar, need_sugar;
    double percent;

    for (i = 0; i <= 30; i++ ) {
        for (j = 0; j <= 30; j++) {
            mass_water = (i * a + j * b);
            if (mass_water == 0) continue;
            need_sugar = mass_water * e;
            for (k = 0; k <= f; k++) {
                for (l = 0; k * c + l * d <= need_sugar; l++) {
                    mass_sugar = k * c + l * d;
                    if (mass_sugar + mass_water * 100 <= f) {
                        percent = (100.0 * mass_sugar) / (mass_water * 100.0 + mass_sugar);
                        if (percent >= mx_percent) {
                            mx_percent = percent;
                            mx_sugar_water = (mass_sugar + mass_water * 100);
                            mx_sugar = mass_sugar;
                        }
                    }
                    else {
                        break;
                    }
                }
            }
        }
    }
    cout << mx_sugar_water << ' ' << mx_sugar << '\n';
    return 0;
}


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

bool is_prime(int n) {
    bool res = true;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            res = false;
            break;
        }
    }
    return res;
}

int main() {
    vector<int> ans;
    for (int i = 11; i < 60000; i += 10) {
        if (is_prime(i)) {
            ans.push_back(i);
        }
    }

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        if (i) cout << ' ';
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vc vector<int>
#define um unordered_map<int,int>
#define ll long long 
#define rep(i,a,b) for(__typeof(a) i=a; i<b; i++)
#define si(a) a.size()
#define all(a) a.begin(),a.end()
#define ss(a) a.second
#define ff(a) a.first
#define M 1000000
#define pb push_back
#define repit(i,a) for(auto i=a.begin(); i!=a.end(); i++)
#define take(arr,n) for(int i=0;i<n;i++)cin>>arr[i]
#define out(arr,n) for(int i=0;i<n;i++)cout<<arr[i]<<' '
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define reprev(i,b,a) for(__typeof(b) i=b; i>=a; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define doublearray vector<vector<int>>
#define mod 998244353 
using namespace std;
ll max(ll a, ll b){ return a>b?a:b; }
ll min(ll a, ll b){ return a<b?a:b; }
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}
int binaryS(int x, int sb[], int m){
    int l = 0, r=m;
    int mid = (l+r)/2;
    while(l<r){
        mid = (l+r)/2;
        if(sb[mid]<x) l= mid+1;
        else if(sb[mid]>x) r = mid-1;
        else return mid;
    }
    return l;
}
int main(){
    fastio;
    // int t; cin>>t;
    // while(t--){
       ll d,t,s; cin>>d>>t>>s;
       if((int)ceil(d/(float)s)<=t) yes;
       else no;
    //}
    return 0;
}


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

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n];

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    reverse(a, a + n);
    int alice = 0;
    int bob = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }
    cout << alice - bob << endl;

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0; i < (n); i++)

map<string, int> onkai;

int numOnkai = 0;

bool isok(int curT, int curS, int n, vector<int>& t, vector<int>& s) {
  while (curS >= 0 && curT >= 0 && curT < n) {
//    cout << "now:" << curT << ","<< t[curT] <<","<< s[curS] << endl;
    if (t[curT] == s[curS]) {
      curT--;
    }
    else if ((t[curT] + 1) % numOnkai == s[curS]) {
      curT -= 2;
    }
    else if (t[curT] == (s[curS] + 1) % numOnkai) {
      curT++;
    }
    else {
      break;
    }
    curS--;
  }
  return curS == -1 && ( curT == -1
  );
}

bool solve() {
  int n, m;
  cin >> n >> m;
  vector<int> t(n);
  vector<int> s(m);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    t[i] = onkai[s];
  }
  for (int i = 0; i < m; i++) {
    string st;
    cin >> st;
    s[i] = onkai[st];
  }
  return isok(n-1, m-1, n, t, s) || n > 1 && isok(n-2, m-1, n, t, s);

}

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

  int a=0;
  onkai["C"] = a++;
  onkai["C#"] = a++;
  onkai["D"] = a++;
  onkai["D#"] = a++;
  onkai["E"] = a++;
  onkai["F"] = a++;
  onkai["F#"] = a++;
  onkai["G"] = a++;
  onkai["G#"] = a++;
  onkai["A"] = a++;
  onkai["A#"] = a++;
  onkai["B"] = a++;
  numOnkai = a;

  for (int i = 0; i < n; i++) {
    cout << (solve() ? "Yes" : "No") << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1316
import heapq

N=int(input())
A=[int(x) for x in input().split()]

a=A[:N]
b=A[-N:]
c=A[N:-N]
res=[sum(a)]


heapq.heapify(a)
for i in range(N):
  heapq.heappush(a,c[i])
  k=heapq.heappop(a)
  res.append(res[-1]+c[i]-k)

cnt=sum(b)
for i in range(N):
  b[i]*=-1

max_ans=res[N]-cnt

heapq.heapify(b)
for i in range(N-1,-1,-1):
  heapq.heappush(b,-c[i])
  k=heapq.heappop(b)
  res[i]-=(cnt+c[i]+k)
  cnt=cnt+c[i]+k
  max_ans=max(max_ans,res[i])

print(max_ans)

Measured memory_bytes: 40196
n = int(input())
A = list(map(int, input().split()))
A.sort()
import sys

if A[0]==0:
  print(0)
  sys.exit()
  
ans = 1
for i in range(n):
  ans *= A[i]
  if ans > 10**18:
    print(-1)
    sys.exit()

print(ans)


Measured memory_bytes: 84628
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
using ll = long long;
using db = long double;
const int N = 1 << 17, MOD = 1e9 + 7;
ll A, B, C, D;
ll LCM(ll x, ll y){
  return x / __gcd(x,y) * y;
}
ll get(ll x){
  return x - (x / C + x / D - x / LCM(C,D));
}
int main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);cin.tie(0);
#endif // ONLINE_JUDGE
  cin >> A >> B >> C >> D;
  cout << get(B) - get(A-1) << '\n';
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = pow(10, 9) + 7
a, b = [0] * (n - 1), [0] * (m - 1)
c, s = n - 1, 0
for i in range(n - 1):
    s += c
    a[i] = s
    c -= 2
c, s = m - 1, 0
for i in range(m - 1):
    s += c
    b[i] = s
    c -= 2
sumx, sumy = 0, 0
for i in range(n - 1):
    sumx += (a[i] * (x[i + 1] - x[i]))
    sumx %= mod
for i in range(m - 1):
    sumy += (b[i] * (y[i + 1] - y[i]))
    sumy %= mod
ans = sumx * sumy % mod
print(ans)

Measured memory_bytes: 26148
#include<cstdio>
#include<iostream>
#include<cmath>
#include<map>
#define ll long long
using namespace std;
ll a[101010],x[101010],y[101010];
ll n,ans;
map<ll,ll> mp,br;
int main()
{
	scanf("%lld",&n);
	for (ll i=1;i<=n;++i)
	{
		scanf("%lld",&a[i]);
		x[i]=1; y[i]=1;
		for (ll j=2;j*j*j<=a[i];++j)
		if (a[i]%j==0)
		{
			int k=0;
			while (a[i]%j==0) a[i]/=j,++k;
			if (k%3==1) x[i]*=j,y[i]*=j*j;
			if (k%3==2) x[i]*=j*j,y[i]*=j;
		}
		x[i]*=a[i];
		if ((ll)sqrt(a[i])*(ll)sqrt(a[i])==a[i]) y[i]*=sqrt(a[i]);
		else y[i]*=a[i]*a[i];
		++mp[x[i]];
	}
	for (int i=1;i<=n;++i)
		if (br[x[i]]==0)
		{
			br[x[i]]=1;
			br[y[i]]=1;
			if (x[i]==1) ++ans;
			else ans+=max(mp[x[i]],mp[y[i]]);
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 27648
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

int main() {
  string s, t; cin>>s>>t;
  if (s.size() != t.size()) {
    print("No");
    return 0;
  }

  vector<set<int>> ss(30), ts(30);
  rep(i, s.size()){
    ss[s[i]-'a'].emplace(t[i]-'a');
    ts[t[i]-'a'].emplace(s[i]-'a');
  }
  rep(i, 30) if (ss[i].size() > 1 or ts[i].size() > 1) {
    print("No");
    return 0;
  }
  print("Yes");

  return 0;
}

Measured memory_bytes: 776
N, A, B = map(int, input().split())
X = list(map(int, input().split()))

sa_cost = [0] * (N - 1)
for i in range(N - 1):
    sa_cost[i] = (X[i + 1] - X[i]) * A


ans = 0
for i in range(len(sa_cost)):
    if sa_cost[i] <= B:
        ans += sa_cost[i]
    else:
        ans += B

print(ans)


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

int N;
vector<int> d;

int main() {

  cin >> N;
  for (int i=0;i<N;++i ) {
    int din;
    cin >> din;
    d.push_back(din);
  }
  sort(d.begin(), d.end());
  int mid = d[ N/2] - d[N/2-1];
  cout << mid << endl;
}


Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <iomanip>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main()
{
	double t, x;
	cin >> t >> x;
	cout << fixed;
	cout << setprecision(10) << t/x <<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int m[101][101],p[101];
void mcm(int n){
  int i,j,l,k;
  for(i=1;i<=n;i++){
    m[i][i]=0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=1000000000;
      for(k=i;k<=j-1;k++){
	m[i][j]=fmin(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
}
int main(){
  int n,i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }
  mcm(n);
  printf("%d\n",m[1][n]);
  return 0;
}



Measured memory_bytes: 2080
#include<bits/stdc++.h>
using namespace std;
int n, k, c;
string s;
int a[200005], b[200005];

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

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    cin >> n >> k >> c >> s;

    int id = 0;
    for (int i = 0; i < n;){
        if (s[i] == 'o') a[id++] = i, i += c + 1;
        else i++;
        if (id == k) break;
    }

    id = k - 1;
    for (int i = n - 1; i >= 0;) {
        if (s[i] == 'o') b[id--] = i, i -= (c + 1);
        else i--;
        if (id == -1) break;
    }

    for (int i = 0; i < k; i++) {
        if (a[i] == b[i]) cout << a[i] + 1 << '\n';
    }
}


Measured memory_bytes: 3348
#include<stdio.h>
#include<math.h>

int main(){

	double x1,y1,x2,y2,x3,y3;
	double a1,a2,b1,b2,c1,c2;
	int n;
	double px1,py1,r;
	int i;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
		a1=2*(x2-x1);
		b1=2*(y2-y1);
		c1=(x1*x1)-(x2*x2)+(y1*y1)-(y2*y2);
		a2=2*(x3-x1);
		b2=2*(y3-y1);
		c2=(x1*x1)-(x3*x3)+(y1*y1)-(y3*y3);
		px1=(b1*c2-b2*c1)/(a1*b2-a2*b1);
		py1=(c1*a2-c2*a1)/(a1*b2-a2*b1);
		r = sqrt((x1-px1)*(x1-px1)+(y1-py1)*(y1-py1));
		printf("%.3lf %.3lf %.3lf\n",px1,py1,r);
	}

	return 0;
}

Measured memory_bytes: 664
/*  -*- coding: utf-8 -*-
 *
 * 1619.cc: Making Lunch Boxes
 */

#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 = 500;
const int MAX_M = 500;

/* typedef */

typedef vector<bool> vb;
typedef map<vb,int> mvbi;

/* global variables */

char s[MAX_M + 4];
mvbi umap, vmap;

/* subroutines */

void printv(const vb &v, const int d) {
  for (int i = 0; i < v.size(); i++) printf("%d", v[i] ? 1 : 0);
  printf(" = %d\n", d);
}

/* main */

int main() {
  for (int n, m; scanf("%d%d", &n, &m) == 2 && n > 0;) {
    vb zv(m, false), sv(zv), vv(zv);
    umap.clear();
    umap[zv] = 0;

    while (n--) {
      scanf("%s", s);
      //puts(s);
      for (int i = 0; i < m; i++) sv[i] = (s[i] == '1');
      vmap = umap;

      for (mvbi::iterator mit = umap.begin(); mit != umap.end(); mit++) {
	const vb &uv = mit->first;
	//printv(uv, mit->second);
	int vd = mit->second + 1;

	for (int i = 0; i < m; i++) vv[i] = uv[i] ^ sv[i];

	mvbi::iterator pit = vmap.find(vv);
	if (pit == vmap.end()) vmap[vv] = vd;
	else if (pit->second < vd) pit->second = vd;
      }

      swap(umap, vmap);
    }

    printf("%d\n", umap[zv]);
  }
  return 0;
}



Measured memory_bytes: 199868
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _086
{
    class Program
    {
        static void Main(string[] args)
        {
            ProblemA.Solve();
        }
    }

    class ProblemA
    {
        public static void Solve()
        {
 
            int[] array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            if ( (array[0] * array[1] % 2) == 0)
            {
                Console.WriteLine("Even");
            }
            else
            {
                Console.WriteLine("Odd");

            }           
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define isNum(a) (a>='0'&&a<='9')
#define SP putchar(' ')
#define EL putchar('\n')
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
template<class T1>void read(T1 &r_e_a_d);
template<class T1>void write(T1 w_r_i_t_e);
int a[5];
int main(){
    int ans=0,now;
    read(a[1]);
    read(a[2]);
    read(a[3]);
    sort(a+1,a+4,greater<int>());
    ans+=(a[1]-a[2]);
    a[2]=a[1];
    a[3]+=ans;
    now=a[1]-a[3];
    ans+=now/2;
    if(now&1){
        ans+=2;
    }
    write(ans);
    EL;
    return 0;
}
template<class T1>void read(T1 &r_e_a_d){
    T1 k=0;
    char ch=getchar();
    int flag=1;
    while(!isNum(ch)){
        if(ch=='-'){
            flag=-1;
        }
        ch=getchar();
    }
    while(isNum(ch)){
        k=(k<<1)+(k<<3)+ch-'0';
        ch=getchar();
    }
    r_e_a_d=flag*k;
}
template<class T1>void write(T1 w_r_i_t_e){
    if(w_r_i_t_e<0){
        putchar('-');
        write(-w_r_i_t_e);
    }else{
        if(w_r_i_t_e<10){
            putchar(w_r_i_t_e+'0');
        }else{
            write(w_r_i_t_e/10);
            putchar((w_r_i_t_e%10)+'0');
        }
    }
}


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

#define endl         '\n'
#define ll 			long long


int main()
{
	//freopen("input.txt","r",stdin);
	int x,n;
	cin >> x >> n;
	// vector<int> v(100,0);
	set<int> s;
	int a;
	for(int i = 0;i<n;i++) {
		cin >> a;
		s.insert(a);
	}
	if(n == 0) {
		cout<<x<<endl;
		return 0;
	}
	int temp1 = x,temp2 = x;
	
	while(1){
		if(s.find(temp1) == s.end()) {
			cout<<temp1<<endl;
			break;
		} else if(s.find(temp2) == s.end()) {
			cout<<temp2<<endl;
			break;
		}
		temp1 -= 1;
		temp2 += 1;
	} 
	return 0;
}

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

int n, num, b1, b2, b4;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d", &num);
        if (num % 4 == 0) b4++;
        else if (num % 2 == 0) b2++;
        else b1++;
    }

    if (b4 + 1 < b1 + b2 % 2) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

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

n = N % 10

if n  == 3 :
    print("bon")

if n == 0 or n == 1 or n == 6 or n == 8 :
    print("pon")

if n == 2 or n == 4 or n == 5 or n == 7 or n == 9 :
    print("hon")

Measured memory_bytes: 61788
N = int(input())
len_N = len(str(N))

ans = 0

if len_N == 6:
    ans = ((10**5 -1) - (10**4) +1) + ( (10**3 -1) -(10**2) +1) + 9
if len_N == 5:
    ans = (N - (10**4) +1) + ( (10**3 -1) -(10**2) +1) + 9 
if len_N == 4:
    ans = ( (10**3 -1) -(10**2) +1) + 9 
if len_N == 3:
    ans = ( N -(10**2) +1 ) + 9 
if len_N == 2:
    ans =  9
if len_N == 1:
    ans = N

print(ans)

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

int main() {

    int n;
    scanf("%d", &n);
    int mysum = 0;

    if (n < 10) {
        mysum += n;
    } else if (n < 100) {
        mysum += 10 - 1;
    } else if (n < 1000) {
        mysum += n - 100 + 1;
        mysum += 10 - 1;
    } else if (n < 10000) {
        mysum += 10 - 1;
        mysum += 1000 - 100;
    } else if (n < 100000) {
        mysum += n - 10000 + 1;
        mysum += 10 - 1;
        mysum += 1000 - 100;
    } else {
        mysum += 10 - 1;
        mysum += 1000 - 100;
        mysum += 100000 - 10000;

    }

    printf("%d", mysum);

    return 0;
}


Measured memory_bytes: 1724
def mod_power(m, n, mod)
	return 1 if n.zero?

	m %= mod
	e = n.to_s(2).size - 2

	rslt = m
	e.downto(0) do |i|
		rslt = rslt ** 2 % mod
		rslt = rslt * m % mod unless n[i].zero?
	end

	return rslt
end

p mod_power(*gets.split.map(&:to_i), 1_000_000_007)

Measured memory_bytes: 6108
n = int(input())
a = [int(m) for m in input().split()]
S = 0
for i in range(n):
    S += abs(a[i])
fu = 0
minabs = float("INF")
for i in range(n):
    if a[i] < 0:
        fu += 1
    minabs = min(minabs, abs(a[i]))

if n % 2 == 0:
    if fu % 2 == 0:
        print(S)
    else:
        print(S - 2 * minabs)
else:
    if fu % 2 == 0:
        print(S)
    else:
        print(S - 2 * minabs)

Measured memory_bytes: 14332
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 100000;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    vector<int> backet(MAX+1, 0);
    for(int i = 0; i < n; i++) backet[a[i]]++;

    int ansmax = 0;
    int ans = 0;
    for(int i = 0; i <= MAX; i++){
        if(i-3 >= 0) ans -= backet[i-3];
        ans += backet[i];
        if(ansmax < ans) ansmax = ans;
    }
    cout << ansmax << endl;
    return 0;
}

Measured memory_bytes: 4012
#include<iostream>

using namespace std;

int search1(int A[],int n,int key)
{
    int i=0;
    A[n]=key;
    while(A[i]!=key)
    {
        i++;
    }
    if(i==n)return 0;
    return 1;
}

int main()
{
    int A[10001],q,n,B[500];
    int sum=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }

    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>B[i];
        if(search1(A,n,B[i])) sum++;

    }
    cout<<sum<<endl;

}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int N; 
    cin >> N;
    long long L[87];
    L[0] = 2; L[1] = 1;
    for (int i = 2; i <= 86; i++) {
        L[i] = L[i - 1] + L[i - 2];
    }

    cout << L[N] << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  bool flag = false;
  char S;
  for(int i = 0; i < N; ++i){
    cin >> S;
    if(S == 'Y'){
      flag = true;
      break;
    }
  }
  
  if(flag) cout << "Four" << endl;
  else cout << "Three" << endl;
}

Measured memory_bytes: 256
n, m = map(int,input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
li = [-1] * n

for s, c in sc:
    if li[s - 1] == -1 or li[s - 1] == c:
        li[s - 1] = c
    else:
        print(-1)
        exit()

    if n != 1 and s == 1 and c == 0:
        print(-1)
        exit()

for i in range(n):
    if li[i] == -1:
        if i == 0 and n != 1:
            li[i] = 1
        else:
            li[i] = 0

a = ''
for i in li:
    a+=str(i)
print(a)

Measured memory_bytes: 3064
def pr(sequence):
    string = ''
    for i in sequence[:-1]:
        string += str(i) + ' '
    string += str(sequence[-1])
    print(string)

def insertion_sort(a,n,g,cnt):
    for i in range(g,n):
        key = a[i]
        j = i-g
        while (j >=0) and (a[j] > key):
            a[j+g] = a[j]
            j = j-g
            cnt = cnt + 1
        a[j+g] = key
    return a,cnt

n = int(input())
a = [int(input()) for _ in range(n)]


cnt = 0
# m = min(n-1,100)
# if n == 1:m=1
# g = [i for i in range(m,0,-1)]
# g = 1
if n !=1:
    g = [1]
    while g[0] < n:
        g.insert(0, 3*g[0]+1)
    g.pop(0)
else:
    g = [1]
m = len(g)

for i in range(m):
    a,cnt = insertion_sort(a,n,g[i],cnt)


print(m)
pr(g)
print(cnt)
for i in a:
    print(i)


Measured memory_bytes: 45524
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

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

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

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

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

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

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

fn main() {
  input! {
    _n: usize,
    m: usize,
    war: [(usize, usize); m],
  }
  let mut war = war;
  war.sort_by_key(|&(_, b)| b);
  let mut last_cut = 0;
  let mut count = 0;
  for &(a, b) in &war {
    if a < last_cut {
      continue;
    }
    last_cut = b;
    count += 1;
  }

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


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

using namespace std;

int main() {
    long long a[3], k;
    cin >> a[0] >> a[1] >> a[2] >> k;
    sort(a, a+3);
    while (k--) {
        a[2] *= 2;
    }

    cout << a[0] + a[1] + a[2] << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    string s;
    cin>>s;
    int count=0;
    rep(i,s.size()){
        if(s[i]=='+'){
            count++;
        }else{
            count--;
        }
    }
    cout<<count<<endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
#define INF 2147483647
const int maxn=110;

int n,m[maxn][maxn];
int d[maxn],vis[maxn];
vector <pair<int ,int> > adj[maxn];
void dijkstra(){

    priority_queue<pair<int ,int> > q;
    int d[maxn];
    int color[maxn];
    for(int i=0;i<n;i++){
        d[i]=INF;
        color[i]=0;
    }
    d[0]=0;
    q.push(make_pair(0,0));
    color[0]=1;
    while(!q.empty()){

        pair<int ,int> f=q.top(); q.pop();
        int u=f.second;

        color[u]=2;

        if(d[u]<f.first*(-1)) continue;

        for(int j=0;j<adj[u].size();j++){

            int v=adj[u][j].first;
            if(color[v]==2) continue;
            if(d[v]>d[u]+adj[u][j].second){

                d[v]=d[u]+adj[u][j].second;
                q.push(make_pair(d[v]*(-1),v));
                color[v]=1;
            }
        }

    }
    for(int i=0;i<n;i++)
        cout<<i<<" "<<(d[i]==INF?-1:d[i])<<endl;

}


int main(){

    cin >>n;
    int k,c,u,v;
    for(int i=0;i<n;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>v>>c;
            adj[u].push_back(make_pair(v,c));
        }

    }
    dijkstra();

    return 0;
}



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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

ll bit_count(ll bits) {
    ll cnt = 0;
    for (; bits != 0; bits >>= 1) {
        cnt += bits & 1;
    }
    return cnt;
}

int A[21][21];
mint dp[22][1 << 21];

int main() {
    int N;
    cin >> N;
    rep(i, N) rep(j, N) cin >> A[i][j];

    dp[0][0] = 1; // dp[i][j] 男性i番目までマッチング済,集合jのbitが立っている女性がマッチング済
    rep(i, N) {
        rep(bit, 1 << N) {
            if (i != bit_count(bit)) continue; // 男性マッチング数=女性マッチング数(bitが立ってる数) が不一致の状態は無効なのでスキップ
            rep(j, N) { // j番目の女性とマッチングできるか試す
                int flg = 1 << j;
                if (!(bit & flg) && A[i][j]) dp[i + 1][bit | flg] += dp[i][bit];
            }
        }
    }

    cout << dp[N][(1 << N) - 1].x << endl;
}

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

using namespace std;

int main()
{
	int e;

	while (scanf("%d", &e), e){
		int min = INT_MAX;

		for (int i = 0; i * i * i <= e; i++){
			for (int j = 0; j * j <=  e - i * i * i; j++){
				if (min > i + j + e - (i * i * i + j * j)){
					min = i + j + e - (i * i * i + j * j);
				}
			}
		}

		printf("%d\n", min);
	}

	return (0);
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int w,a,b;cin >> w >> a >> b;
    if(b < a)swap(a,b);
    cout << max(0ll,b-a-w) << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 1e5+50;
const int oo = 1e9;
const int mod = 1e9+7;

pair<ll,ll> a[N];
ll cost[N],cost2[N];
int main(){
	ll n,c;
	cin>>n>>c;
	for(int i=0;i<n;i++)
		cin>>a[i].first>>a[i].second;
	ll sum=0;
	for(int i=n-1;i>=0;i--){
		sum += a[i].second;
		cost[i] = max(sum - (c-a[i].first),cost[i+1]);
	}
	sum =0;
	for(int i=0;i<n;i++){
		sum += a[i].second;
		if(i)
			cost2[i] = cost2[i-1];
		cost2[i] = max(sum - a[i].first,cost2[i]);
	}
	ll ans = 0;
	sum = 0;
	for(int i=0;i<n;i++){
		sum += a[i].second;
		ans = max(ans, sum-a[i].first);
		ans = max(ans,sum - a[i].first + cost[i+1] - a[i].first);
	}
	sum = 0;
	for(int i=n-1;i>=0;i--){
		sum += a[i].second;
		ans = max(ans,sum - (c-a[i].first));
		ans = max(ans,sum - (c-a[i].first) + cost2[i-1] - (c-a[i].first));
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=1e5+10;
char s[maxn];
int n;
ll dp[maxn][15];
int m13[maxn];
int main()
{
	scanf("%s",s);
	n=strlen(s);
	m13[0]=1;
	for(int i=1;i<maxn;i++)
		m13[i]=m13[i-1]*10%13;
	dp[0][0]=1;
	for(int i=0;i<n;i++)//n-i-1
	{
		int p=n-1-i;
		if(s[i]=='?')
		{
			for(int j=0;j<10;j++)
			{
				for(int k=0;k<13;k++)if(dp[i][k])
				{
					dp[i+1][(k+j*m13[p])%13]+=dp[i][k];
				//	cout<<i<<" "<<j<<" "<<k<<" "<<(k+j*m13[p])%13<<endl;
					if(dp[i+1][(k+j*m13[p])%13]>=MOD)dp[i+1][(k+j*m13[p])%13]-=MOD;
				}
			}
		}
		else
		{
			int j=s[i]-'0';
			for(int k=0;k<13;k++)if(dp[i][k])
			{
				dp[i+1][(k+j*m13[p])%13]+=dp[i][k];
			//		cout<<i<<" "<<j<<" "<<k<<" "<<(k+j*m13[p])%13<<endl;
				if(dp[i+1][(k+j*m13[p])%13]>=MOD)dp[i+1][(k+j*m13[p])%13]-=MOD;
			}
		}
	//	system("pause");
	}
	printf("%lld\n",dp[n][5]);
	return 0;
}

Measured memory_bytes: 12416
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int H = sc.nextInt();
		int W = sc.nextInt();

		int cnt = 0;

		for (int i = W; i <= N; i++) {
			for (int j = H; j <= N; j++) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 1;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans %= mod;
        ans *= power(i + 1, mod - 2);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll h,w,n;
    queue<ll> c;
    cin >> h >> w >> n;
    rep0(i, n){
        ll a;
        cin >> a;
        rep0(j, a)c.push(i + 1);
    }
    ll g[h][w];
    rep0(i, h)rep0(j, w)g[i][j] = 0;
    rep0(i, h){
        rep0(j, w){
            g[i][j] = c.front();
            c.pop();
        }
        ++i;
        if(h <= i)break;
        rrep0(j, w){
            g[i][j] = c.front();
            c.pop();
        }
    }
    rep0(i, h){
        rep0(j, w){
            cout << g[i][j] << " ";
        }
        pf("");
    }
    return 0;
}


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

int main() {
  long long N, K;
  cin >> N >> K;
  if (N == 0 || K == 0) {
    cout << N << endl;
  } else {
    long long amari = N % K;
    long long over = amari - K > 0 ? amari - K : -(amari - K);
    long long result = min(amari, N);
    result = min(result, over);
    cout << result << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(void){
	int x,i=0,a=0,b=0;
	char stack[100];
	int ans[100]={0};
	while( scanf("%s",stack) != EOF){
		if(stack[0]=='+'){
			a=ans[--i];
			b=ans[--i];
			ans[i]=b+a;
			i++;
		}
		else if(stack[0]=='-'){
			a=ans[--i];
			b=ans[--i];
			ans[i]=b-a;
			i++;
		}
		else if(stack[0]=='*'){
			a=ans[--i];
			b=ans[--i];
			ans[i]=b*a;
			i++;
		}
		else{
			x = atoi(stack);
		ans[i] = x;
		i++;
		}
	}
	printf("%d\n",ans[--i]);
	
	return 0;
}
			
			
		
		

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

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

    rep(i, n - 1) {
        cin >> tmp;
        a[tmp - 1]++;
    }

    rep(i, n) { cout << a[i] << endl; }

    return 0;
}

Measured memory_bytes: 4052
N,M = map(int,input().split())
H = list(map(int,input().split()))

max_height = [0]*N
for i in range(M):
    a,b = map(int,input().split())
    max_height[a-1]=max(max_height[a-1],H[b-1])
    max_height[b-1]=max(max_height[b-1],H[a-1])


print((sum(H[i] > max_height[i] for i in range(N))))

Measured memory_bytes: 19952
#include<bits/stdc++.h>
#define test int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
int main()
{
string s; cin>>s;
ll c=0,c1=0;
ll k=s.size();
for(ll i=0;i<k/2;i++)
{
    if(s[i]!=s[k-i-1])
    {
        c++;
    }
//    else
//    {
//        c1=1;
//    }
//}
//if(c1){
//ll n=k-c;
//if(k%2==1)
//cout<<n<<endl;
//else
//    cout<<n-1<<endl;
//}
//else
//{
//    cout<<0<<endl;
//}
}
cout<<c<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf=1e9+7;
ll power[200005];
int main()
{
    power[0]=1LL;
    for(ll i=1;i<200005;i++)
        power[i]=(power[i-1]*3LL)%inf;
    string x;cin>>x;
    ll n=x.length();
    ll pre[n][2]; //number of A and number of ? before character at position i not including i
    ll suff[n][2]; // number of C and number of ? after character at position i not includeing i
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<2;j++)
        {
            pre[i][j]=0;
            suff[i][j]=0;
        }       
    }

    for(ll i=1;i<n;i++)
    {
        if(x[i-1]=='A')
        {
            pre[i][0]=pre[i-1][0]+1;
            pre[i][1]=pre[i-1][1];
        }
        else if(x[i-1]=='?')
        {
            pre[i][1]=pre[i-1][1]+1;
            pre[i][0]=pre[i-1][0];
        }
        else
        {
            pre[i][0]=pre[i-1][0];
            pre[i][1]=pre[i-1][1];
        }
    }

    for(ll i=n-2;i>=0;i--)
    {
        if(x[i+1]=='C')
        {
            suff[i][0]=suff[i+1][0]+1;
            suff[i][1]=suff[i+1][1];
        }
        else if(x[i+1]=='?')
        {
            suff[i][1]=suff[i+1][1]+1;
            suff[i][0]=suff[i+1][0];
        }
        else
        {
            suff[i][1]=suff[i+1][1];
            suff[i][0]=suff[i+1][0];   
        }
    }
    
    /*cout<<"pre\n";
    for(ll i=0;i<n;i++)
        cout<<pre[i][0]<<" "<<pre[i][1]<<endl;
    cout<<"suff\n";
    for(ll i=n-1;i>=0;i--)
        cout<<suff[i][0]<<" "<<suff[i][1]<<endl;*/
    ll ans=0;
    ll a,l,c,r;

    ll term1,term2,term3,term4;
    for(ll i=0;i<n;i++)
    {
        if((x[i]=='B')||(x[i]=='?'))
        {   
            a=pre[i][0];
            l=pre[i][1];
            c=suff[i][0];
            r=suff[i][1];
    
            term1=(((r*l)%inf)*power[r+l-2])%inf;
            term2=(((a*r)%inf)*power[r+l-1])%inf;
            term3=(((c*l)%inf)*power[r+l-1])%inf;
            term4=(((a*c)%inf)*power[r+l])%inf;
    
            ans+=(term1+term2+term3+term4)%inf;
            ans%=inf;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5120
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w = map(int, input().split())
a = [None]*h
for i in range(h):
    a[i] = input()
cx = 0
cy = 0
d = set()
while (cx,cy)!=(h-1, w-1):
    val = 0
#     print(cx,cy)
    for dx, dy in [(1,0), (0,1)]:
        ccx = cx+dx
        ccy = cy+dy
        if ccx>=h or ccy>=w or a[ccx][ccy]==".":
            continue
        nx, ny = ccx, ccy
        val += 1
    if val>=2 or val==0:
        ans = "Impossible"
        break
    cx, cy = nx, ny
else:
    vv = sum(sum(item=="#" for item in items) for items in a)
    if vv==h+w-1:
        ans = "Possible"
    else:
        ans = "Impossible"
print(ans)

Measured memory_bytes: 62068
s = gets.chomp.split("")
a = s[0..1].join.to_i
b = s[2..3].join.to_i

if 1 <= a && a <= 12
    if 1 <= b && b <= 12
        @ans = "AMBIGUOUS"
    else
        @ans = "MMYY"
    end
else
    if 1 <= b && b <= 12
        @ans = "YYMM"
    else
        @ans = "NA"
    end    
end
puts @ans

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define REP(i,n) for(int i=0;i<(n);++i)
#define INF 1e9
typedef long long llong;
using namespace std;

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

	vector<char> c;
	int n = s.size();
	REP(i, n) c.push_back(s[i]);
	sort(c.begin(), c.end());

	bool jud = true;
	for(int i = 1; i < n; ++i){
		if(c[i] == c[i - 1]) jud = false;
	}

	if(jud) cout << "yes" << endl;
	else cout << "no" << endl;

	return 0;
}


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


int main()
{
    int N, X, Y;
    cin >> N >> X >> Y;
    vector<int> D(N);
    int t = Y - X + 1;
    for (int i = 1; i <= N - 1; i++) {
        for (int j = i + 1; j <= N; j++) {
            if (i < X) {
                if (j <= X)
                    D[j - i]++;
                else if (j <= Y)
                    D[X - i + min(j - X, t - j + X)]++;
                else
                    D[X - i + 1 + j - Y]++;
            } else if (i < Y) {
                if (j <= Y)
                    D[min(j - i, t - j + i)]++;
                else
                    D[j - Y + min(Y - i, t - Y + i)]++;
            } else {
                D[j - i]++;
            }
        }
    }
    for (int i = 1; i <= N - 1; i++)
        cout << D[i] << endl;
    return 0;
}


Measured memory_bytes: 256