akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  int M = 1e9 + 7;
  vector<int> dp[4][4][4];
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        dp[i][j][k] = vector<int>(N + 1, 0);
      }
    }
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        if ((i == 0 && j == 1 && k == 2) || (i == 0 && j == 2 && k == 1) || (i == 1 && j == 0 && k == 2)) {
          dp[i][j][k][3] = 0;
        } else {
          dp[i][j][k][3] = 1;
        }
      }
    }
  }
  
  for (int l = 3; l < N; l++) {
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
          if (j == 0 && k == 2) {
            dp[j][k][0][l + 1] = (dp[j][k][0][l + 1] + dp[i][j][k][l]) % M;
            dp[j][k][2][l + 1] = (dp[j][k][2][l + 1] + dp[i][j][k][l]) % M;
            dp[j][k][3][l + 1] = (dp[j][k][3][l + 1] + dp[i][j][k][l]) % M;
          } else if ((j == 0 && k == 1) || (j == 1 && k == 0) || (i == 0 && k == 1) || (i == 0 && j == 1)) {
            dp[j][k][0][l + 1] = (dp[j][k][0][l + 1] + dp[i][j][k][l]) % M;
            dp[j][k][1][l + 1] = (dp[j][k][1][l + 1] + dp[i][j][k][l]) % M;
            dp[j][k][3][l + 1] = (dp[j][k][3][l + 1] + dp[i][j][k][l]) % M;
          } else {
            for (int m = 0; m < 4; m++) {
              dp[j][k][m][l + 1] = (dp[j][k][m][l + 1] + dp[i][j][k][l]) % M;
            }
          }
        }
      }
    }
  }
  
  ll ret = 0;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        ret = (ret + dp[i][j][k][N]) % M;
      }
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=1000000+10;
ll dp[maxn];
ll a[maxn];
int n;

void solve(){
	memset(dp,INF,sizeof(dp));
	for(int i=n;i>=1;i--){
		*upper_bound(dp,dp+n,a[i])=a[i];
	}
	printf("%d\n",lower_bound(dp,dp+n,INF)-dp);
}

int main()
{
	while(~scanf("%d",&n) && n){
		for(int i=1;i<=n;i++){
			scanf("%lld",&a[i]);
		}
		solve();
	}
	return 0;
}


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

 
int main()
{
  int k;
  string s;
  cin>>k>>s;
  int n=s.length();
  if(k>=n){
      cout<<s<<endl;
  }
  else{
      string str="";
      for(int i=0;i<k;i++){
          str=str+s[i];
      }
      str=str+'.'+'.'+'.';
      cout<<str<<endl;
  }
  
   return 0;
}



Measured memory_bytes: 3588
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	unsigned int k;
	while(cin >> n >> k) {
		vector<unsigned int> a(n);
		vector<LL> b(n);
		REP(i,n) cin >> a[i] >> b[i];
		LL ans = 0;
		FOR(i,1,31) if((k>>(i-1))&1){
			DEBUG(i);
			unsigned int mask = ~((((unsigned int)1)<<i)-1);
			unsigned int km = k&mask;
			LL sum = 0;
			DEBUG(bitset<32>(mask));
			REP(j,n){
				DEBUG(j);
				DEBUG(((mask&a[j])|km) == km);
				if(((mask&a[j])|km) == km and !(((a[j]>>(i-1))&1))) {
					DEBUG(a[j]);
					sum += b[j];
				}
			}
			DEBUG(sum);
			chmax(ans, sum);
		}
		{
			LL sum = 0;
			REP(j,n){
				if((a[j]|k) == k) {
					sum += b[j];
				}
			}
			chmax(ans, sum);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long h,w;
    cin >> h >> w;
    long long oddColomn = h/2 + h%2;
    long long evenColomn = h/2;
    long long ans = oddColomn*(w/2+w%2) +evenColomn*(w/2);
    // cout << oddColomn << endl;
    // cout << evenColomn << endl;
    if(w==1){
        cout << 1 << endl;;
    }else if(h==1){
        cout << 1 << endl;
    }else{
        cout << ans << endl;
    }

}

Measured memory_bytes: 3616
#-*- coding: utf-8 -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
"""
from collections import defaultdict
import sys
import math
from datetime import datetime
import re

def howmany_power(n, k):
    if n >= k:
        return 0
    else:
        return howmany_power(n*2, k) + 1


def sol(N, K):
    P = 0
    for n in range(1, N+1):
        if n < K:
            x = howmany_power(n, K)
            tmp = 2**x
            fst = N
            #print("n:%s, K:%s, P:%s, x:%s, tmp:%s, fst:%s" % (n, K, P, x, tmp, fst))
            P += (1/tmp)*(1/fst)
        else:
            #print("n:%s, K:%s, P:%s" % (n, K, P))
            P += (1.0/N)
    return P


do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    #print(parsed_lines)
    n = int(parsed_lines[0][0])
    k = int(parsed_lines[0][1])
    #S = parsed_lines[0][0]
    return n, k


if not do_submit:
    n, k = input_parse("""
    3 10
    """)
    print(sol(n, k))

    n, k = input_parse("""
    100000 5
    """)
    print(sol(n, k))


else:
    n, k = list(map(int, input().split()))
    #S = input()
    print(sol(n, k))

    # S = input().strip()
    # print(sol(S))





Measured memory_bytes: 3816
n = int(input())
taro=0
hanako=0
for i in range(n):
    T,H = input().split()
    if T==H:
        taro = taro+1
        hanako = hanako+1
    elif T>H:
        taro = taro+3
    elif T<H:
        hanako = hanako+3
print(taro,hanako)


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

using namespace std;

typedef long long ll;

const long long MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int N;
  cin >> N;
  string res;
  if (N == 0) res = "0";
  while (N != 0) {
    int s = abs(N % 2);
    res = to_string(s) + res;
    N -= s;
    N /= -2;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
/*
* @Author: Kabid
* @Date:   2020-04-16 00:45:39
*/

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define in(x)  scanf("%d", &x);
#define ins(x) scanf("%s", &x);
#define out(x) printf("%d", x);
#define outs(x) printf("%s", x);
#define _ putchar(' ');
#define lin puts("");

int t,i,j=0,k,l,x=0,r,la,lb;
int c=0,m=1,ci=0,ca=0,cb=0;
char s[100001];
char sa[501],sb[501];
int a[1001],b[1001]={0},e[101]={0},g[101]={0},d;
int main(){
	in(x)
	sprintf(s,"%d",x);
	l=strlen(s);
	for(i=0;i<l;i++){
		if(s[i]=='7'){
			j=1;
			//puts("dkfjuds");
		}
	}
	if(j)puts("Yes");
	else puts("No");
	//puts(s);
	//putchar(s[2]);lin
	//out(s[2]-'7')


		

	
	
	
	
	


    return 0;
 }
	
		


Measured memory_bytes: 1736
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int X,N;
  cin>>X>>N;
  VI P(N);
  rep(i,N) cin>>P[i];
  VI Y(200);
  rep(i,N) Y[P[i]]++;
  int ans=-1;
  int tmp=1000;
  rep(i,200){
    if(Y[i]==0 and tmp>abs(i-X)){
      tmp=abs(i-X);
      ans=i;
    }
  }
  if(tmp>abs(-1-X)) ans=-1;
  cout<<ans<<endl;
}



Measured memory_bytes: 3632
//intのオーバーフローに気をつけろ,AGCはだいたいlongにしておけ
//毎回余りを求めることでオーバーフローしなくなる
//nextLineよりnextだ
//charは''で囲うんだぞ
//読み込みは先に全部やっておけ
//for文を回す回数に気をつけろ
	//for文は10^3の三重はTLE,10^5の二重はTLE

import java.util.Scanner;

public class Main {

	public static void main(String args[]) throws InterruptedException {
		    Scanner sc = new Scanner(System.in);
		    
		    int s = sc.nextInt();
		    String id = sc.next();
		    int max = 0;
		    int tmp = 0;
		    
		    for(int i = 0; i < s; i++) {
		    	if(id.charAt(i) == 'I') {
		    		tmp++;
		    		if(tmp > max) {
		    			max = tmp;
		    		}
		    	}else {
		    		tmp--;
		    	}
		    }
		    System.out.println(max);
		    sc.close(); }

	public static void saiki(int a, String b) {
		//再帰コーディングのお手本

		if(a == 0) {
			System.out.println(b);
		}else {
			for(char ch = 'a'; ch <= 'c'; ch++) {
				saiki(a-1,b + ch);
			}
		}
	}

	public static  int gcd(int a, int b) {
	    if (a < b) {
	        int tmp = a;
	        a = b;
	        b = tmp;
	    }

	    int r = -1;
	    while (r != 0) {
	        r = a % b;
	        a = b;
	        b = r;
	    }

	    return a;
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#define maxn 150005
using namespace std;
typedef long long ll;
inline int getint(){
  char c; int res = 0;
  for(c = getchar();c < '0' || c > '9';c = getchar());
  for(;c >= '0' && c <= '9';c = getchar()) res = res * 10 + (c - '0');
  return res;
}
int p[maxn];
int remove_bit(int pos,int x){//remove pos-th bit from x
  return ((x & ~((pos << 1) - 1)) >> 1) | (x & (pos - 1));
}
int ins_bit(int pos,int x){
  return (x & (pos - 1)) | ((x & ~(pos - 1)) << 1) | pos;
}
void solve(int st,int n,int a,int b){
  if(n == 1){
    p[st] = a, p[st + 1] = b;
    return;
  }
  int c = a;
  b = a ^ b;
  int fir = b & -b, sec;
  if(b ^ fir) sec = (b ^ fir) & -(b ^ fir);
  else if(fir == 1) sec = 2;
  else sec = 1;
  solve(st,n - 1,0,remove_bit(fir,sec));
  solve(st + (1 << (n - 1)),n - 1,remove_bit(fir,sec),remove_bit(fir,b));
  for(int i = st;i < st + (1 << (n - 1));i++) p[i] = ins_bit(fir,p[i]) & ~fir;
  for(int i = st + (1 << (n - 1));i < st + (1 << n);i++) p[i] = ins_bit(fir,p[i]);
  for(int i = st;i < st + (1 << n);i++) p[i] ^= c;
}
int n,a,b;
int main(){
  n = getint(), a = getint(), b = getint();
  if(!__builtin_parity(a ^ b)){
    puts("NO");
    return 0;
  }
  solve(1,n,a,b);
  puts("YES");
  for(int i = 1;i <= (1 << n);i++) printf("%d%c",p[i],i == (1 << n) ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    ll res = 0;
    REP(i,n){
        cin >> a[i] >> b[i];
    }
    
    RREP(i,n){
        ll temp = (a[i]+res+b[i]-1)/b[i]*b[i];
        res = temp - a[i];
    }
    put(res);
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef float fl;
#define input ll t;cin>>t;while(t--)
#define fast() ios_base::sync_with_stdio(false),cin.tie(NULL);
#define mod 1000000007
#define pb push_back

int main(void) {
    fast();
    ll x,rem,ans=0;
    cin>>x;
    rem=x/500;
    ans+=(1000*rem);
    x%=500;
    rem=x/5;
    ans+=(5*rem);
    cout<<ans<<endl;
    return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int main() {
  string s; cin >> s;
  string alpha = "abcdefghijklmnopqrstuvwxyz";
  bool tmp;
  for(int j = 0; j < alpha.length(); j++) {
    tmp = false;
    for(int i = 0; i < s.length(); i++) {
      if(s[i] == alpha[j]) tmp = true;
    }
    if(!tmp) {
      cout << alpha[j] << endl;
      return 0;
    }
  }
  cout << "None" << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rev(i, n) for (int i = n - 1; i > 0; --i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int n;
    cin >> n;
    vector<int> vi(n);
    rep(i, n) cin >> vi.at(i);
    for (int i = vi.size() - 1; i >= 0; --i) {
        cout << vi.at(i);
        cout << ((i != 0) ? " " : "\n");
    }
}




Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	string s,t;
	cin >> s;
	cin >> t;
	ll cnt=0;
	rep(i,s.length()){
		if(s[i]!=t[i])
			cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3896
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int k;
 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){
    double r;
    cin>>r;

    cout<<r*2*3.1415;

    return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}




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

    cout << (A*3+P)/2 << endl;

}

Measured memory_bytes: 3604
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define PII pair<int,int>
#define MP make_pair
#define fir first
#define sec second
#define PB push_back
#define db long double
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
int n;
int lowbit(int x) {
	int y=1;
	while(!(x&y)) y<<=1;
	return y;
}
int main() {
	rd(n);
	int k=1; while(k<n) k<<=1;
	if(k==n) { printf("No\n"); return 0; }
	printf("Yes\n");
	printf("%d %d\n",n+1,n+2);
	printf("%d %d\n",n+2,3);
	printf("%d %d\n",3,1);
	printf("%d %d\n",1,2);
	printf("%d %d\n",2,n+3);
	for(int j=4;j+1<=n;j+=2) {
		int k=j+1;
		printf("%d %d\n",j,1);
		printf("%d %d\n",j,n+k);
		printf("%d %d\n",k,1);
		printf("%d %d\n",k,n+j);
	}
	if(!(n&1)) {
		for(int x=2;x<=n-1;++x) {
			int y=n^x^1;
			if(y>=2&&y<=n-1) {
				printf("%d %d\n",n+n,x);
				printf("%d %d\n",n,y);
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;

int main(){
int n;cin >> n;
for(int t = 1;t<=n;t++)

{
	char mcxi[10];
	for(int j = 0;j <=9;j++)mcxi[j]='\0';
	cin >> mcxi;
	int num1 = 0,num2 = 0,prenum = 1;
	int i = 0;
	while(mcxi[i]!='\0'){
		switch(mcxi[i]){
			case 'm':num1+=prenum * 1000;
			prenum = 1;
			break;
			case 'c':num1+=prenum * 100;
			prenum = 1;
			break;
			case 'x':num1+=prenum * 10;
			prenum = 1;
			break;
			case 'i':num1+=prenum;
			prenum = 1;
			break;
			default:prenum = mcxi[i]-'0';
		}
		i++;
	}
	for(int j = 0;j <=9;j++)mcxi[j]='\0';
	cin >> mcxi;
	i = 0;prenum = 1;
	while(mcxi[i]!='\0'){
		switch(mcxi[i]){
			case 'm':num2+=prenum * 1000;
			prenum = 1;
			break;
			case 'c':num2+=prenum * 100;
			prenum = 1;
			break;
			case 'x':num2+=prenum * 10;
			prenum = 1;
			break;
			case 'i':num2+=prenum;
			prenum = 1;
			break;
			default:prenum = mcxi[i]-'0';
		}
		i++;
	}
	char ans[10];
	for(int j = 1;j<=9;j++)ans[j]='\0';
	int k = 0;
	switch((num1+num2)/1000){
		case 1:ans[0]='m'; k++; break;
		case 0:break;
		default:ans[0]=(num1+num2)/1000+'0';ans[1]='m';k+=2; break;
		}
	switch(((num1+num2)/100)%10){
		case 1:ans[k]='c';k++;break;
		case 0:break;
		default:ans[k]=((num1+num2)/100)%10+'0';ans[k+1]='c';k+=2; break;
	}
	switch(((num1+num2)/10)%10){
		case 1:ans[k]='x';k++;break;
		case 0:break;
		default:ans[k]=((num1+num2)/10)%10+'0';ans[k+1]='x';k+=2; break;
	}	
	switch((num1+num2)%10){
		case 1:ans[k]='i';break;
		case 0:ans[k]='\0';break;
		default:ans[k]=(num1+num2)%10+'0';ans[k+1]='i';k+=2; break;
	}
	printf("%s\n",ans);
	
	
	}

	return 0;
}

Measured memory_bytes: 0
X, N = map(int, input().split())
p = []
if N != 0:
  p = list(map(int, input().split()))
d = 0
f = 0
while 1:
  if (X - d) not in p:
    print(X - d)
    break
  elif (X + d) not in p:
    print(X + d)
    break
  d += 1

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    string s;
    cin >>s;
    int l=0,r=s.size()-1;
    int ans=0,N=s.size();
    //-----------------------------------
    rep(i,N){
        if(l==r)break;
        if(s[l]==s[r]){
            l++;r--;
            if(r<l)break;
        }else if(s[l]!='x'&&s[r]=='x'){
            ans++;
            r--;
        }else if(s[l]=='x'&&s[r]!='x'){
            ans++;
            l++;
        }else{
            ans=-1;
            break;
        }
    }

    cout << ans <<endl;
    return (0);
}

Measured memory_bytes: 512
fun main(args: Array<String>){

    var N = readLine()!!.toInt()
    var D = readLine()!!.split(" ").map{it.toLong()}
    var countArray = LongArray(N){0}
    var ans :Long = 1
    val MOD = 998244353

    for(i in countArray.indices){
        countArray[D[i].toInt()]++
    }

    for(i in countArray.indices){

        for(j in 0 until countArray[i]){
            if(i != 0) ans = ans * countArray[i-1] % MOD
        }
    }

    if(D[0] != 0L){
        println(0)
    } else if(countArray[0] != 1L) {
        println(0)
    } else {
            if(ans < 0) ans += MOD
            println(ans)
        }
}


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

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

        int n,i,j,k; cin>>n;
        int h[n][3];
        for(i=0;i<n;i++) {
                for(j=0;j<3;j++)
                    cin>>h[i][j];
        }

        int dp[n][3];
        //memset(dp,0,sizeof(dp));

        dp[0][0]=h[0][0];
        dp[0][1]=h[0][1];
        dp[0][2]=h[0][2];

        for(i=1;i<n;i++)
        {

            dp[i][0]=h[i][0]+max(dp[i-1][1], dp[i-1][2]);
            dp[i][1]=h[i][1]+max(dp[i-1][0], dp[i-1][2]);
            dp[i][2]=h[i][2]+max(dp[i-1][0], dp[i-1][1]);


        }

        //for(i=0;i<3;i++) cout<<dp[n-1][i]<<"  ";

        cout<<*max_element(dp[n-1],dp[n-1]+3)<<"\n";

    return 0;
}


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

int main() {
  long n,ans=0,x=0,y=0;
  cin >> n;
  vector<long> a(n);
  for(long i=0;i<n;i++) cin >> a[i];
  for(long i=0;i<n;i++) {
    while((y^a[i])!=y+a[i]) y-=a[x],x++;
    ans+=i-x+1;
    y+=a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
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 keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
int main() {
    int n;cin >> n;
    vvi ans(n,vi(2));
    rep(i, n) {
        cin >> ans[i][0] >> ans[i][1];
        ans[i][0]*=-1;
        reverse(all(ans[i]));
    }
    sort(all(ans));
    // for(auto p:ans)cout << p[0] << ' ' << p[1] << endl;
    int minute = 0;
    // int count = 0;
    rep(i, n) {
        minute+=ans[i][1]*-1;
        if(ans[i][0]<minute) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

const int N = 300005;

template <class T>
void read (T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}

template <class T>
void write (T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

int n, perm[N], bit[N];
long long inv1 = 0ll, inv2 = 0ll, inv = 0ll;
int lowbit (int x) {
	return x & -x;
}
void add (int x) {
	for (; x <= n; x += lowbit(x)) bit[x]++;
}
int query (int x) {
	int ans = 0;
	for (; x; x ^= lowbit(x)) ans += bit[x];
	return ans;
}

int main () {
	read(n);
	for (int i = 0; i < n; i++) read(perm[i]);

	for (int i = 1; i <= n; i++) bit[i] = 0;
	for (int i = n - 1; i >= 0; i--) inv += query(perm[i]), add(perm[i]);

	for (int i = 1; i <= n; i++) bit[i] = 0;
	for (int i = n - 1; i >= 0; i -= 2) inv1 += query(perm[i]), add(perm[i]);

	for (int i = 1; i <= n; i++) bit[i] = 0;
	for (int i = n - 2; i >= 0; i -= 2) inv2 += query(perm[i]), add(perm[i]);

	if (inv == 3ll * (inv1 + inv2)) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>

using namespace std;

const long long INF = (1LL << 60);

struct Edge {
	Edge(int d, int c) : dst(d), cost(c) {}
	int dst;
	int cost;
};

struct Data {
	Data(long long a, long long b){ val[0] = a; val[1] = b; }
	long long val[2];
	void add(int v){ for(int i=0;i<2;i++) val[i] += v; }
	bool operator < (const Data& d) const {
		if(val[0] < d.val[0]) return true;
		return val[0] == d.val[0] && val[1] < d.val[1];
	}
};

void search(vector<Data>& res, const vector<vector<Edge>>& g, int pos, long long upper){
	res.clear();
	if(g[pos].size() == 0){
		res.emplace_back(Data(0, 0));
		return;
	}
	vector<Data> data[2];
	for(int i=0;i<2;i++){
		search(data[i], g, g[pos][i].dst, upper);
		if(data[i].empty()) return;
		for(int j=0;j<data[i].size();j++){
			data[i][j].add(g[pos][i].cost);
		}
	}
	if(data[1].size() < data[0].size()) swap(data[0], data[1]);
	int idx0[2] = {0, (int)data[0].size()-1};
	int idx1[2][2] = {{0, (int)data[1].size()-1}, {0, (int)data[1].size()-1}};
	while(idx0[0] < data[0].size() || idx0[1] >= 0){
		int check = 0;
		if(idx0[0] == data[0].size()){
			check = 1;
		} else if(idx0[1] == -1){
			check = 0;
		} else {
			check = (data[0][idx0[0]].val[0] < data[0][idx0[1]].val[1] ? 0 : 1);
		}
		const auto baseVal = data[0][idx0[check]].val[1-check];
		long long minVal = INF;
		for(int i=0;i<2;++i){
			while(0 <= idx1[check][i] && idx1[check][i] < data[1].size() && baseVal + data[1][idx1[check][i]].val[i] <= upper){
				minVal = min(minVal, data[1][idx1[check][i]].val[1-i]);
				idx1[check][i] += 1 - 2*i;
			}
		}
		if(minVal < INF){
			Data d(data[0][idx0[check]].val[check], minVal);
			if(res.empty() || (res.back().val[0] < d.val[0] && res.back().val[1] > d.val[1])){
				res.push_back(d);
			} else if(d < res.back()){
				res.back() = d;
			}
		}
		idx0[check] += 1 - 2*check;
	}
	return;
}

int main(){
	int N;
	while(cin >> N){
		vector<vector<Edge>> g(N);
		for(int i=0;i<N-1;i++){
			int d, c; cin >> d >> c;
			g[d-1].emplace_back(Edge(i+1, c));
		}
		long long low = -1, high = 1LL << 35;
		vector<Data> vd;
		while(high - low > 1){
			long long mid = (low+high)/2;
			search(vd, g, 0, mid);
			if(!vd.empty()){
				high = mid;
			} else {
				low = mid;
			}
		}
		cout << high << endl;
	}
}


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

int main(){
    ll h,w;
    cin>>h>>w;
    if(h==1||w==1){
    	cout<<'1';
    	return 0;
	}
    ll ans=0;
    if(h*w%2==0){
    	cout<<h*w/2;
    	return 0;
	}
    for(ll i=1;i<=w;i++){
    	if(i%2==1)ans+=h/2+1;
    	else ans+=h/2;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
# ABC125C - GCD on Blackboard
# Accumulative GCD
import sys
input = sys.stdin.readline

from fractions import gcd

n = int(input())
a = list(map(int, input().rstrip().split()))

left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
    left[i + 1] = gcd(left[i], a[i])
    right[n - i - 1] = gcd(right[n - i], a[n - i - 1])

ans = 0
for i in range(n):
    ans = max(ans, gcd(left[i], right[i + 1]))
print(ans)

Measured memory_bytes: 16136
#include <iostream>
#include <algorithm>
#include <string>
#include<vector>

using namespace std;

int main() {
    int x;
    cin >> x;
    vector<bool>e(x + 1);
    e[1] = 1;
    for (int b = 2; b <= x; b++) {
        int v = b * b;
        while (v <= x) {
            e[v] = 1;
            v *= b;
        }
    }
    for (int i = x; i >= 1; i--) {
        if (e[i]) {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
n=int(input())
arr=list(map(int,input().strip().split()))[:n]
dict1={}
for i in arr:
	if i in dict1:
		dict1[i]+=1
	else:
		dict1[i]=1
sum1=0
for i in dict1:
	sum1+=((dict1[i]*(dict1[i]-1))//2)
for i in arr:
	k=sum1
	n1=dict1[i]
	k-=((n1*(n1-1))//2)
	k+=((n1-1)*(n1-1-1)//2)
	print(k)

	



Measured memory_bytes: 24744
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll rui[222222];
ll rui2[222222];
ll gcd(ll a,ll b){
    ll r=a%b; 
    while(r!=0){a=b;b=r;r=a%b;}
    return b;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n);
  for(int i=0;i<n;i++){
    cin>>A[i];
    if(i==0)rui[i]=A[i];
    else rui[i]=gcd(rui[i-1],A[i]);
    if(i==n-1)rui2[i]=A[i];
  }
  ll ans=0;
  for(int i=n-2;i>=0;i--)
    rui2[i]=gcd(rui2[i+1],A[i]);
  for(int i=0;i<n;i++){
    if(i==0){
      // cout<<rui[i+1]<<endl;
      ans=max(ans,rui2[i+1]);
    }else if(i==n-1){
      //cout<<rui[i-1]<<endl;
      ans=max(ans,rui[i-1]);
    }else{
      //cout<<gcd(rui[i-1],rui2[i+1])<<endl;
      ans=max(ans,gcd(rui[i-1],rui2[i+1]));
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
    int64_t n;
    cin >> n;
    string s = to_string(n);

    int64_t f = 0;
    int64_t nn = n;
    for(int i=0;i<s.size();i++){
        f += nn %10;
        nn /= 10;
    }

    if(n % f == 0) cout << "Yes" <<endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a[210000];int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]),a[i]-=(LL)i;
	sort(a+1,a+1+n);int md=(n+1)/2;LL ans=0;
	for(int i=1;i<=n;i++)ans+=abs(a[i]-a[md]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define NMAX 200005

using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll binPow(ll a, ll p){
    ll ans=1;
    while(p){
        if(p&1) ans=ans*a%MOD;
        p>>=1;
        a=a*a%MOD;
    }
    return ans;
}
int main()
{
    ll n;
    cin>>n;
    cout<<(binPow(10,n)+binPow(8,n)-2*binPow(9,n)+MOD*2)%MOD;
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int l = s.length();
    int ap = 0;
    int zp = l;
    
    for (int i = 0; i < l; i++) {
        if (s[i] == 'A') {
            ap = i;
            break;
        }
    }
    
    for (int i = (l - 1); i >= 0; i--) {
        if (s[i] == 'Z') {
            zp = i;
            break;
        }
    }
    
    cout << (zp - ap + 1) << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
    #include <stdlib.h>
     
    int main(void){
      long l,r;
      int min = 2019;
      scanf("%ld",&l);
      scanf("%ld",&r);
      if((r - l) >= 2019){
	printf("%d",0);
	exit(0);
      }

      for(long i = l; i <= r; i++){
        for(long j = i + 1; j <= r; j++){
          if((i * j) % 2019 < min){
            min = (i * j) % 2019;
	    
            if(min == 0){
    			printf("%d",min);
                exit(0);
            }
          }
        }
      }
      printf("%d",min);
    }

Measured memory_bytes: 128
import scala.io.StdIn

object Main extends App {
  
  var index = -1
  val inp = StdIn.readLine().trim
  val result = inp.foldLeft(List.empty[Int], List.empty[(Int, Int)], 0){
    case ((allstack, eachstack, allmenseki), e) =>
    //println(allstack)
    //println(eachstack)
    index += 1
    if(e == '\\') {
      (index :: allstack, eachstack, allmenseki)  
    } else if(e == '/' && allstack.nonEmpty){
      var j = allstack.head
      var men = index - j
      var a = index - j
      var temp = eachstack
      while(temp.nonEmpty && temp.head._1 > j){
        a += temp.head._2
        temp = temp.tail
      }
      temp = (j, a) :: temp
      (if(allstack.length == 1) Nil else allstack.tail,
        temp, allmenseki + men)
    } else (allstack, eachstack, allmenseki)

  }
  
  println(result._3)
  println(result._2.size + (if(result._2.isEmpty) "" else
    " " + result._2.reverse.map(e => e._2).mkString(" ")))
  
}



Measured memory_bytes: 50344
while True:
  try:
    w = float(input())
  except:break
  if w <= 48.0:print("light fly")
  elif w<=51.0:print("fly")
  elif w<=54.0:print("bantam")
  elif w<=57.0:print("feather")
  elif w<=60.0:print("light")
  elif w<=64.0:print("light welter")
  elif w<=69.0:print("welter")
  elif w<=75.0:print("light middle")
  elif w<=81.0:print("middle")
  elif w<=91.0:print("light heavy")
  else:print("heavy")      



Measured memory_bytes: 5576
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

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

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

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

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

  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

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

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

const int MOD = 1e9 + 7;

using mint = ModInt<MOD>;

int main(){
    ll n;
    cin >> n;
    mint ten =  10, nine = 9, eight = 8;
    cout << ten.pow(n) - (mint)2 * nine.pow(n) + eight.pow(n) << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define DREP(i, x, y, d) for(ll i = x; i < y; i += d)
#define PER(i, x, y) for(ll i = x; i > y; i--)
#define DPER(i, x, y, d) for(ll i = x; i > y; i -= d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

vector< vector<ll> > matrixproduct(vector< vector<ll> > &matA, vector< vector<ll> > &matB) {
    assert(matA[0].size() == matB.size());
    ll a = matA.size(), b = matB[0].size(), c = matA[0].size();
    vector< vector<ll> > ansmat(a, vector<ll>(b, 0));
    for (ll i = 0; i < a; i++) {
        for (ll j = 0; j < b; j++) {
            for (ll k = 0; k < c; k++) {
                ansmat[i][j] += matA[i][k] * matB[k][j];
            }
        }
    }
    return ansmat;
}

int main() {
    ll n, m, l;
    cin >> n >> m >> l;
    vector< vll > A(n, vll(m, 0)), B(m, vll(l, 0));
    REP(i, 0, n) {
        REP(j, 0, m) {
            cin >> A[i][j];
        }
    }
    REP(j, 0, m) {
        REP(k, 0, l) {
            cin >> B[j][k];
        }
    }
    vector<vll> ans = matrixproduct(A, B);
    REP(i, 0, n) {
        REP(k, 0, l) {
            cout << ans[i][k];
            if (k != l - 1) {
                cout << " ";
            }
        }
        // if (i != n - 1) {
        //     cout << endl;
        // }
        cout << endl;
    }
}



Measured memory_bytes: 3244
//
//  problemA.c
//  ADSWeek01
//
//  Created by Yuta Nemoto on 2019/04/08.
//  Copyright © 2019 Yuta Nemoto. All rights reserved.
//

#include <stdio.h>

void initialize(int[]);
double length(int, int, int, int);
double sqrt(double);
double absolute(double);

int main(int argc, const char * argv[]) {
    
    // Counter Variable
    int i, j;
    // Array for input
    int input[6];
    // Variable to store the distance between 2 centers
    double distance = 0.0;
    
    // Get the input first
    initialize(input);
    
    // Get the distance between 2 input points
    distance = length(input[0], input[1], input[3], input[4]);
    
    // Judge if a part of one circle is included in another circle
    if(distance == input[2] + input[5]) printf("%d\n", 3);
    else if(distance > input[2] + input[5]) printf("%d\n", 4);
    else{
        if(distance + input[2] == input[5] || distance + input[5] == input[2]) printf("%d\n", 1);
        else if(absolute(input[2] - input[5]) > distance || absolute((input[5] - input[2]) > distance)) printf("%d\n", 0);
        else printf("%d\n", 2);
    }
    
    return 0;
}

/* Initialization processes (Get the input) */
void initialize(int input[6]){
    int i = 0;
    for(i = 0; i < 6; i++){
        scanf("%d", &input[i]);
    }
}

/* Return the length between point x and y (Arguments: x1, x2, y1, y2) */
double length(int x1, int y1, int x2, int y2){
    int distance_x, distance_y;
    if(x1 >= x2) distance_x = x1 - x2;
    else distance_x = x2 - x1;
    if(y1 >= y2) distance_y = y1 - y2;
    else distance_y = y2 - y1;
    return sqrt(distance_x * distance_x + distance_y * distance_y);
}

/* Return the square root of the given argument */
double sqrt(double s){
    // Initial value to get the sqrt result
    double comp = s / 2.0 ;
    // Initial value of the last step
    double last_comp = 0.0 ;
    
    // Continue until the smaller difference
    while ( comp != last_comp ){
        // Adopt Babylonian method step
        last_comp = comp ;
        comp = (comp + s / comp) / 2.0 ;
    }
    return comp ;
}

/* Return the absolute value of the given argument */
double absolute(double x){
    if(x < 0) return -x;
    else return x;
}



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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

class UnionFind {
    private :
        std::vector<int> par;
    public :
        UnionFind(int n) {
            par.resize(n);
            for (int i=0; i<n; i++) par.at(i) = i;
        }
        void unite(int x, int y) {
            int xPar = find(x);
            int yPar = find(y);
            if (xPar == yPar) return;

            par.at(xPar) = yPar;
        }
        int find(int x) {
            if (par.at(x) == x) return x;
            else return par.at(x) = find(par.at(x));
        }
        bool same(int x, int y) { return find(x) == find(y); }
};

void solve() {
    ll n;
    cin >> n;
    vector<int> p(n);
    for (int i=0; i<n; ++i) {
        cin >> p.at(i);
        if (p.at(i) > 0) --p.at(i);
    }

    UnionFind uf(n);
    for (int i=0; i<n; ++i) {
        if (p.at(i) != -1) uf.unite(i, p.at(i));
    }
    vector<pair<int, bool>> cnt(n, {0, false});
    for (int i=0; i<n; ++i) {
        ++cnt.at(uf.find(i)).first;
        if (p.at(i) == -1) cnt.at(uf.find(i)).second = true;
    }
    vector<ll> groups;
    int loops = 0;
    for (auto p : cnt) {
        if (p.first > 0) {
            if (p.second) groups.push_back(p.first);
            else ++loops;
        }
    }

    int k = (int)groups.size();
    vector<vector<ll>> dp(k+1, vector<ll>(k+1));
    for (int i=0; i<k+1; ++i) dp.at(i).at(0) = 1;
    for (int i=1; i<k+1; ++i) {
        for (int j=1; j<k+1; ++j) {
            dp.at(i).at(j) = dp.at(i-1).at(j) + dp.at(i-1).at(j-1) * groups.at(i-1) % MOD;
            dp.at(i).at(j) %= MOD;
        }
    }
    ll res = n - loops;
    for (int i=0; i<k; ++i) {
        res *= n-1;
        res %= MOD;
    }
    ll fact = 1;
    for (int i=1; i<k+1; ++i) {
        dp.back().at(i) *= fact;
        if (i == 1) dp.back().at(i) -= k;
        dp.back().at(i) %= MOD;
        fact *= i;
        fact %= MOD;
    }
    ll power = 1;
    for (int i=k; i>0; --i) {
        dp.back().at(i) *= power;
        dp.back().at(i) %= MOD;
        power *= n-1;
        power %= MOD;
    }
    for (int i=1; i<k+1; ++i) {
        res -= dp.back().at(i);
        res %= MOD;
    }
    if (res < 0) res += MOD;
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 198728
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <unordered_map>
#include <iterator>
#include <functional>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	while(cin >> n, n){
		vector<vi> d(5, vi(n));
		REP(i, n)REP(j, 5) cin >> d[j][n-1-i];
		int ans = 0;
		while(1){
			int update = 0;
			REP(i, n){
				REP(j, 3)if(d[j][i]){
					int k = j+1;
					for(;k<5;k++) if(d[k][i] != d[j][i]) break;
					if(k-j < 3) continue;
					update = 1;
					for(;j<k;j++){
						ans += d[j][i];
						d[j][i] = 0;
					}
				}
			}
			if(!update) break;
			REP(i, 5){
				d[i].erase(remove_if(ALL(d[i]), [](int i){return !i;}), d[i].end());
				d[i].resize(n);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1216