akhauriyash/Code-Regression huggingface dataset:
import * as fs from "fs";

let input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [a, b] = input[0].split(" ").map((x: string): number => +x);

const h = 100;
const w = 100;

const larger = a > b ? 1 : 0;
const s = Math.min(a, b);
const d = Math.abs(a - b);

const ans: Array<Array<0 | 1>> = new Array(h).fill([]).map(() => new Array(w).fill(-1 * (larger - 1)));

let cnt = 0;
let cnt_row = 0;
let x = 0;
let y = 0;

let flip = larger === 0;
let flg_terminal = false;
let remain = Math.max(a, b);

// よくわからないがこれを入れるとうまくいく
if (Math.min(a,b) >= 101 && Math.min(a, b) % 100 === 1) remain--;

if (s > 1) {
	while (true) {
		if (!flg_terminal) {
			if (flip) {
				ans[y][x] = 1;
				ans[y][x + 1] = 0;
				if (!flg_terminal && larger === 0) cnt_row++;
			}
			else {
				ans[y][x] = 0;
				ans[y][x + 1] = 1;
				if (!flg_terminal && larger === 1) cnt_row++;
			}
		}
		else {
			ans[y][x] = larger;
			ans[y][x + 1] = larger;
			if (x - 1 >= 0 && ans[y][x - 1] === larger) remain++;
		}
		if (cnt < s - 1) cnt++;
		if (cnt === s - 1) {
			if (!flg_terminal && ans[y][x] === larger) remain++;
			flg_terminal = true;
			if (y === h - 1) break;
		}
		if (!flg_terminal) flip = !flip;

		y += 1;
		if (y >= h) {
			cnt_row = 0;
			y = 0;
			x += 2;
		}
	}
	y = 0;
	x += 2;
}
while (y < h) {
	ans[y++][x] = larger;
}
y = 0;
x += 2;


remain = remain - (s - 1) + (cnt_row - 1);

// console.error(`${larger}(${["B:#", "A:."][larger]})`, s, cnt_row, remain);

while (remain > 0) {
	ans[y][x] = larger;
	remain--;
	y += 2;
	if (y >= h) {
		y = 0;
		x += 2;
	}
}

console.log(h, w);
for (const row of ans) {
	let line = "";
	for (const v of row) {
		if (v === 1) {
			line += ".";
		}
		else {
			line += "#";
		}
	}
	console.log(line);
}

const ans_checker = (ans: Array<Array<0 | 1>>, h: number, w: number) => {
	const checked: Array<Array<boolean>> = new Array(h).fill([]).map(() => new Array(w).fill(false));
	const fill = (y: number, x: number, color: number): boolean => {
		if (ans[y][x] !== color) return false;
		if (checked[y][x]) return false;
		checked[y][x] = true;
		const dx = [-1, 1, 0, 0];
		const dy = [0, 0, -1, 1];
		for (let i = 0; i < 4; i++) {
			const ny = y + dy[i];
			const nx = x + dx[i];
			if (ny < 0 || ny >= h || nx < 0 || nx >= h) continue;
			fill(ny, nx, color);
		}
		return true;
	};
	const islands = [0, 0];
	for (let i = 0; i < h; i++) {
		for (let ii = 0; ii < w; ii++) {
			const c = ans[i][ii];
			if (fill(i, ii, c)) islands[c]++;
		}
	}
	console.error(`A: ${islands[1]}, B:${islands[0]}`);
	return islands;
};

/*
try {
	ans_checker(ans, h, w);
}
catch {

}
*/



Measured memory_bytes: 8268
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k <= a) {
		cout << k << endl;
	}
	else if (k <= a+b&&a<k) {
		cout << a << endl;
	}
	else if(a+b<k&&a<k){
		cout << a - (k - (a + b)) << endl;
	}
	return 0;
}



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

int main(){
    string s;
cin >>s;
if(s=="SUN")cout <<7 <<endl;
else if(s=="MON")cout <<6 <<endl;
else if(s=="TUE")cout <<5 <<endl;
else if(s=="WED")cout <<4 <<endl;
else if(s=="THU")cout <<3 <<endl;
else if(s=="FRI")cout <<2 <<endl;
else if(s=="SAT")cout <<1 <<endl;
         return 0;   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define drep(i,a,b) for(int i=(a); i>=(b);i--) 

const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;




int main()
{
   ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
   int a,b;cin >> a >> b;
   cout << max(max(a+b,a-b),a*b);
   
   return 0;
}

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

int main() {
  int M,N,i,j;
  cin>>N;
  vector<int> A(N);
  int sumA=0;
  int sumE=0;
  int sumO=0;
  for(i=0;i<N;i++){
    cin>>A.at(i);
    sumA+=A.at(i);
    if(i%2!=0){
      sumE+=2*A.at(i);
    }else{
      sumO+=2*A.at(i);
    }
  }


vector<int> R(N);
  R.at(0)=sumA-sumE;
  for (i=1;i<N;i++){
    R.at(i)=2*A.at(i-1)-R.at(i-1);
  }
  for (i=0;i<N;i++){
  cout<<R.at(i)<<endl;
}

}


Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

int main(){
    int x;
    cin>>x;
    if(x<1200) cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;
}

Measured memory_bytes: 256
import numpy as np

n = int(input())
a = np.array([int(i) for i in input().split()])

ans = np.zeros_like(a)
for i in range(len(f'{np.max(a):b}')):
    p = (a >> i & 1)
    cnt = np.count_nonzero(p)
    ans += ((cnt - p) % 2) * 2**i

print(' '.join(map(str, ans)))


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

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

    string S;
    cin >> S;
    map<char, int> s;
    for (char i : S) {
        s[i]++;
    }
    
    for (auto e: s) {
        if (e.second != 2) {
            cout << "No" << '\n';
            return 0;
        }
    }
    cout << "Yes" << '\n';

    return 0;
}


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

int main () {
    int a, b;
    cin >> a >> b;
    
    if (a > b) {
        cout << "a > b" << endl;
    } else if (a < b) {
        cout << "a < b" << endl;
    } else {
        cout << "a == b" << endl;
    }
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <stack>
#include <iomanip>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

int n, cnt[100005];

// o o * * o o o o
// o o * * * * * *

// o
// * *
// * * *
// o o o o
// o o o o *
// o o o o o o
// o o o o o o o
// o o o o o o o o
// o o o o o o o o o
// o o o o o o o o o o
// * * * * * * * * * * *
// * * * * * * * * * * * *
// * * * * * * * * * * * * *
// * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * *
// o o o o o o o o o o o o o o o o
// o o o o o o o o o o o o o o o o *
// o o o o o o o o o o o o o o o o o o
// o o o o o o o o o o o o o o o o o o o
// * * * * * * * * * * * * * * * * * * * *

void de(vector<int> v) {
	REP(i, 1, n + 1) {
		cout << setw(2) << v[i] << " ";
	}
	cout << endl;
}

void cde() {
	REP(i, 1, n+1) {
		cout << setw(2) << cnt[i] << " ";
	}
	cout << endl;
}

void sp(stack<int> st) {
	while(st.size()) {
		cout << st.top() << " ";
		st.pop();
	}
	cout << endl;
}

int main() {
	while(cin >> n && n) {
		memset(cnt, 0, sizeof(cnt));

		vector<int> v(n+1);
		rep(i, n) cin >> v[i+1];

		stack<int> w, b;
		REP(i, 1, n+1) {
			if(i % 2 == 0 && v[i] != v[i-1]) {
				cnt[i-1]++;
				if(v[i] == 0) {
					if(w.size()) {
						int p = w.top();
						w.pop();
						cnt[p]--;

					}

					if(b.size()) b.pop();
				} else {
					if(b.size()) {
						int p = b.top();
						b.pop();
						cnt[p]--;

					}

					if(w.size()) w.pop();
				}
			}

			// cout << "i:" << i << " ";
			// cde();

			if(v[i] == 0) {
				if(w.size() && w.top() + 1 == i) {
					w.pop();
				}
				w.push(i);
			}
			else {
				if(b.size() && b.top() + 1 == i) {
					b.pop();
				}
				b.push(i);
			}

			// sp(w);
			// sp(b);
		}
		
		// cde();
		// de(v);

		for(int i = n; i >= 1; i--) {
			cnt[i-1] += cnt[i];
		}


		REP(i, 1, n+1) {
			if(cnt[i]%2 == 0) continue;
			v[i] = !v[i];
		}

		// cde();
		// de(v);

		int ans = 0;
		REP(i, 1, n+1) {
			ans += !v[i];
		}

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

Measured memory_bytes: 1796
n = int(input())
H = [int(i) for i in input().split()]
high = H[0]
for i in range(1,n):
    tmp = H[i]-high
    if -1<=tmp<=1:
        pass
    elif tmp > 1:
        high = H[i]
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool cmp(pair<string,pair<ll,ll> > &a,pair<string,pair<ll,ll> > &b)
{
	if(a.first==b.first)
		return a.second.first>b.second.first;
	return a.first<b.first;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	pair<string,pair<ll,ll> > a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i].first>>a[i].second.first;
		a[i].second.second=i;
	}
	sort(a,a+n,cmp);
	ll ans[n];
	for(ll i=0;i<n;i++)
	{
		ans[i]=a[i].second.second;
	}
	for(ll i=0;i<n;i++)
	{
		cout<<ans[i]+1<<"\n";
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<vi > vvi;
typedef std::vector<vll > vvll;
typedef std::pair<int,int> ii;
typedef std::pair< ll, ll > lp;
typedef std::vector<ii> vii;
typedef std::vector<vii > vvii;

#define pb push_back 
#define PB pop_back
#define pf push_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)
#define lb(a,b) lower_bound(all(a),b)
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define in1(a,n) F(i,1,n)cin>>a[i]
#define out(a,n) F(i,0,n-1)cout<<a[i]<<"";cout<<endl
#define ff first
#define ss second
#define F(i,a,b) for (ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define rep(i,n) F(i,0,n-1)
#define clr(a) (a).clear()
#define rz resize
#define sqr(a) ((a) * (a))
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin() ,(a).rend()
// #define endl '\n'

#define mod 1000000007

ll add(ll a, ll b){return (a%mod + b%mod)%mod;}
ll sub(ll a , ll b){return (a%mod - b%mod + mod)%mod;}
ll mul(ll a, ll b){return (a%mod * b%mod)%mod;}
ll poww(ll a,ll b){ll res=1;while(b){if(b&1){res*=a;}a=a*a;b>>=1;}return res;}
ll poww(ll a,ll b,ll MOD){ll res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define dbg(x) cout<<#x<<" :: "<<x<<endl;
#define dbg2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define dbg4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;

#define upb upper_bound
#define lwb lower_bound


const int N = 1e5 + 5; 

vector<pair <ll, ll > > gr[N];
ll d[N];
bool vis[N];

void dfs(ll u, ll p, ll dis){
	d[u] = dis;
	for (auto x : gr[u]){
		ll v = x.ff, w = x.ss;
		if (v == p) continue;
		dfs(v, u, dis+w);
	}
}

int main(int argc, char const *argv[])
{
	crap;
	rep(i, N){
		d[i] = 1e16 + 9;
	}

	int n;
	cin >> n;
	ll u, v, w;
	rep(i, n-1){
		cin >> u >> v >> w;
		w %=2 ;
		gr[u].pb(mp(v, w));
		gr[v].pb(mp(u, w));
	}
	dfs(1, 0, 0);
	F(i, 1, n){
		cout << d[i] % 2 << endl;
	}
	return 0;
}

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


int main() {
  int n,m;
  int flag = 0;

  cin >> n >> m;

  vector<int> a(n);

  int total = 0;

  for(int i=0; i<a.size(); i++){
    cin >> a.at(i);
    total += a.at(i);
  }

  sort(a.begin(),a.end(),greater<int>());


  double ninki = double(total/(4*m));

  //cout << ninki;

  for(int i = 0; i<m; i++){
    if(a.at(i)*4*m<total)
    flag++;
  }

  if(flag == 0)
  cout << "Yes";
  else
  cout << "No";


}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;

bool sortbysec(const pair<ll,ll> &a, 
              const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 

ll maxSubArraySum(ll a[], ll size) 
{ 
    ll max_so_far = INT_MIN, max_ending_here = 0; 
  
    for (ll i = 0; i < size; i++) 
    { 
        max_ending_here = max_ending_here + a[i]; 
        if (max_so_far < max_ending_here) 
            max_so_far = max_ending_here; 
  
        if (max_ending_here < 0) 
            max_ending_here = 0; 
    } 
    return max_so_far; 
} 

ll findSubarraySum(ll arr[], ll n, ll sum = 0) 
{
    unordered_map<ll, ll> prevSum;
    ll res = 0;
    ll currsum = 0;
    for (ll i = 0; i < n; i++)
    {
        currsum += arr[i];
        if (currsum == sum) res++;
        if (prevSum.find(currsum - sum) != prevSum.end()) res += (prevSum[currsum - sum]);
        prevSum[currsum]++;
    }
    return res; 
} 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
ll powmp(ll x, ll y, ll p) 
{ 
    ll res = 1;     x = x % p;   
    while (y > 0) 
    {  
        if (y & 1)  res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n,m,x;cin>>n>>m>>x;
    ll c[n],a[n][m],mini[n];
    f(i,0,n) mini[i]=INT_MAX;
    f(i,0,n)
    {
        cin>>c[i];
        f(j,0,m) cin>>a[i][j],mini[i]=min(mini[i],a[i][j]);
    }
    ll p[m]={};
    ll ans=INT_MAX;
    for(ll d=(1LL<<n)-1LL;d>0;d--)
    {
        ll cost=0;
        memset(p,0,sizeof(p));
        f(i,0,n)
        {
            if((d>>i)&1LL)
            {
                cost+=c[i];
                f(j,0,m)
                {
                    p[j]+=a[i][j];
                }
            }
        }
        int f=0;
        f(i,0,m) if(p[i]<x) f++;
        if(!f) ans=min(ans,cost);
    }
    if(ans<INT_MAX) cout<<ans<<endl;
    else cout<<-1<<endl;
}


Measured memory_bytes: 3644
s = list(input())
k = int(input())
n = len(s)

if s == [s[0]]*n:
    print(n*k//2)
else:
    ss = s*2
    ans1 = 0
    for i in range(1, n):
        if s[i] == s[i -1]:
            s[i] = ""
            ans1 += 1
    ans2 = 0
    for i in range(1, 2*n):
        if ss[i] == ss[i - 1]:
            ss[i] = ""
            ans2 += 1
    j = ans2 - ans1
    print(ans1 + j*(k - 1))

Measured memory_bytes: 9096
#include<stdio.h>
#include<stdlib.h>
#define N 3

int p[N][N],t[N][N];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void empty(int *x,int *y) {
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(!p[i][j]){
        *x = j;
        *y = i;
        return;
      }
    }
  }
}

void swap(int *a,int *b){
  int t;
  t = *a;
  *a = *b;
  *b = t;
}

int cal(){
  int i,a,sum=0;
  for(i=0;i<9;i++){
    a = p[i/N][i%N];
    if(a){
      a--;
      sum += abs(i/N - a/N) + abs(i%N - a%N);
    }
  }
  return sum;
}

int dfs(int x,int y,int pp,int dep,const int l){
  int i,h,sx,sy,res;
  h = cal();
  if(h == 0)return dep;
  if(dep+h>l)return -1;
  for(i=0;i<4;i++){
    sx = x+dx[i];
    sy = y+dy[i];
    if(~pp && i == (pp+2)%4)continue;
    if(!(0<=sx && sx<N && 0<=sy && sy<N))continue;
    swap(&p[y][x],&p[sy][sx]);
    res = dfs(sx,sy,i,dep+1,l);
    if(~res)return res;
    swap(&p[y][x],&p[sy][sx]);
  }
  return -1;
}

int main() {
  int i,j,ans,x,y,k;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      scanf("%d",&p[i][j]);
    }
  }
  empty(&x,&y);
  for(k=0;k<100;k++){
    for(i=0;i<N;i++){
      for(j=0;j<N;j++){
        t[i][j] = p[i][j];
      }
    }
    ans = dfs(x,y,-1,0,k);
    if(ans != -1){
      printf("%d\n",ans);
      break;
    }
    else {
      for(i=0;i<N;i++){
        for(j=0;j<N;j++){
          p[i][j] = t[i][j];
        }
      }
      ans = -1;
      if(k == (100-1)){
        printf("%d\n",ans);
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=998244353;
const int inf=0x3f3f3f3f;
int a[100005];
int main()
{
    ios::sync_with_stdio(false);
    string s;cin>>s;
    int sum=0;
    int ans=0;
    for(int i=1;i<s.size();i++)
    {
        if(s[i]!=s[i-1]) sum++;
    }
        cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 512
require 'pp'
n, k = gets.split.map &:to_i
a = gets.split.map(&:to_i)

sankaku_cnt = 0

sikaku_cnt = 0

a.size.times do |i|
  a.size.times do |ii|
    sikaku_cnt += 1 if a[ii] > a[i]
  end
end
# p sikaku_cnt

x = 1
n.times do |ii|
  x.upto(n-1) do |i|
    sankaku_cnt += 1 if a[ii] > a[i]
  end
  x += 1
end
# p sankaku_cnt

res = sankaku_cnt * k + (((k-1) * k)/2) * sikaku_cnt
p res % (10**9 + 7)
# 3 0 185297239
#     185297239


Measured memory_bytes: 4220
#include<bits/stdc++.h>
#define ll long long
#define ii pair<int, int>
#define vi vector<int>

using namespace std;

map<ll, int> vis;

ll n, k, ans;

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> k;
    ans = n;
    if(n > k) {
        n = n - ((n/k)*k);
        ans = min(ans, n);
    }
    if(n < k) {
        ans = min(ans, n);
        n = k - n;
        ans = min(ans, n);
    }
    if(n == k) {
        ans = 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define lld long long

int main(){
    string str;
    cin >> str;
    if(str == "AAA" || str == "BBB") {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
n,k = map(int, input().split())
p = 10 ** 9 + 7

##逆元計算
N = n  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

fact = [ 0 for i in range(N+1)]
factinv = fact.copy()
inv = fact.copy()


fact[0], fact[1] = 1, 1
factinv[0], factinv[1] = 1, 1
inv[0], inv[1] = 0, 1
cmb_list = fact.copy()
cmb_list_sub1 = fact.copy()

for i in range(2, N + 1):
    fact[i] = (fact[i-1] * i) % p##階乗のリスト
    inv[i] = (-inv[p % i] * (p // i)) % p
    factinv[i] =(factinv[i-1] * inv[i]) % p##階乗の逆数のリスト
    
#nCrの0=< r <=n までの値のリストがほしい場合
for r in range(1,N+1):
    cmb_list[r] = fact[N] * factinv[r] * factinv[N-r] % p

for r in range(1, n):
    cmb_list_sub1[r] =fact[n-1]*factinv[r]*factinv[n-1-r]%p

ans = 0
if k <= n-1:
    for i in range(0,k+1):
        ans = (ans + cmb_list[i] * cmb_list_sub1[n-1-i])%p
else:
    for i in range(0,n):
        ans = (ans + cmb_list[i] * cmb_list_sub1[n-1-i])%p
print(ans)

Measured memory_bytes: 42636
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define endl "\n" 
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;

int hito[200000];

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    int n; cin >> n;
    rep(i,n-1) {
        int a; cin >> a;
        hito[a-1]++;
    }
    rep(i,n) {
        cout << hito[i] << endl;
    }

    return 0;
}


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

using namespace std;

#define int long long
#define ll long long
#define double long double
#define f first
#define s second
#define all(el) el.begin(), el.end()
#define allr(el) el.rbegin(), el.rend()
//#define x first
//#define y second
#define pb push_back
#define in insert
#define mp make_pair
#define sz(el) (int)el.size()
#define endl "\n"

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

    int n;
    string s;
    cin >> n >> s;
    if (sz(s) <= n) {
        cout << s;
        return 0;
    }
    for (int i = 0; i < n; i++) {
        cout << s[i];
    }
    cout << "...";
    
    return 0;
    
}


Measured memory_bytes: 3592
import java.util.*
import kotlin.math.*

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}

fun <T> T.print() = println(this)

const val mod = 998244353L

fun main() {
	abc000X()
}

fun abc000X() {
	var (n,m,k) = list {toLong()}
	val a = (listOf(0L)+list {toLong()*2}).toLongArray()
	val b = list {toLong()*2}.toLongArray()

	Arrays.parallelPrefix(a) {i,j-> i+j}
	Arrays.parallelPrefix(b) {i,j-> i+j}

	k = k*2+1

	println(a.indices.map {if(a[it]>k) 0 else it+Arrays.binarySearch(b,k-a[it]).inv()}.max())
}


Measured memory_bytes: 81304
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
typedef long long ll;
typedef pair<int, pair<int, int> > cube_t;

int main(void) {
    int n, h;
    string s;
    int a, b;
    while (1) {
        cin >> n >> h;
        if (n == 0 && h == 0) break;
        set<cube_t> cube;
        for (int i = 0; i < h; i++) {
            cin >> s >> a >> b;
            for (int j = 1; j <= n; j++)
            if (s == "xy") {
                cube.insert(make_pair(a, make_pair(b, j)));
            } else if (s == "xz") {
                cube.insert(make_pair(a, make_pair(j, b)));
            } else {
                cube.insert(make_pair(j, make_pair(a, b)));
            }
        }
        cout << n*n*n-cube.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 4332
import math


def main():
    n = int(input())
    res = f(1, n)
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            res = min(res, f(i, n // i))
    print(res)


def f(a, b):
    return max(len(str(a)), len(str(b)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<stdio.h>

int main(void)
{
   int n,a[1000],i;
   scanf("%d",&n);
   for(i=0; i<n; i++){
      scanf("%d",&a[i]);
      if((((a[i]%2)==0) && ((a[i]%3) != 0)) && ((a[i]%5)!=0)){
         printf("DENIED\n");
         return 0;
      }
   }
   printf("APPROVED\n");
   return 0;
}


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

const int mxN=1e3+5;
int dx[4] = { -1, 1, 0, 0 };
int dy[4] = { 0, 0, -1, 1 };
int n, m, mat[mxN][mxN];
int stopx, stopy, startx, starty;
char a[mxN][mxN];
queue< pair<int,int> >cords;

bool ok(int i, int j){
	return i&&j&&i<=n&&j<=m&&mat[i][j]==-1&&a[i][j]!='#';
}

void Lee(){
    while(!cords.empty()){
        int i = cords.front().first;
        int j = cords.front().second;
        cords.pop();
        for(int k=0; k<4; ++k){
            int nexti = i + dx[k];
            int nextj = j + dy[k];
            if(ok(nexti,nextj)){
                cords.push({nexti,nextj});
                mat[nexti][nextj] = 1 + mat[i][j];
            }
        }
    }
}

int main(){
	int a;
	cin >> a;
	cout << a + a * a + a * a * a;

}


Measured memory_bytes: 3636
height, wide = map(int, input().split())
n = int(input())
anslist = []

a = list(map(int, input().split()))
for i, j in enumerate(a):
    for l in range(j):
        anslist.append(i+1)
for k in range(height):
    t = anslist[k*wide:(k+1)*wide]
    if k % 2 == 1:
        t.reverse()
    print(' '.join(map(str, t)))


Measured memory_bytes: 3444
#include<stdio.h>

int main(){
    int N, i; 
    int a[110];
    int num=0, sum=1, ans=0;

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

    for(i=0; i<N; i++){
        if(num!=a[i]){
            num=a[i];
            ans+=sum/2;
            sum=1;
        }else{
            sum++;
        }
        //printf("%d %d %d\n", sum, num, ans);
    }
    if(sum>0){
        ans+=sum/2;
    }
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int a,b,c,N;
  cin >> N;
  //vector<int> v;
  //while (cin >> a >> b >> c){
  //v.push_back(a,b,c);
  //  }
  //int x = a + b;
  //int y = b + c;
  //int z = c + a;
  //if (x => c || y => a || z => b){
  //cout << "NO" << endl;
  //} else if(x < c || y < a || z < b){
  //cout << "YES" << endl;
  //}
  while(N>0){
    cin >> a;
    cin >> b;
    cin >> c;
    //int x = a + b;
    //int y = b + c;
    //int z = c + a;
    if (//x <= c || y <= a || z <= b
   a * a + b * b == c * c || b * b + c * c == a * a || c * c + a * a == b * b ){
      cout << "YES" << endl; 
      N = N - 1;  
    }else if(//x > c || y > a || z > b
 a * a + b * b != c * c || b * b + c * c != a * a || c * c + a * a != b * b){
      cout << "NO" << endl;
      N = N - 1;
    }
  }
  return 0;
}



Measured memory_bytes: 3000
s = input()

if (s[0] == s[1] and s[2] == s[3]) or (s[0] == s[2] and s[1] == s[3]) or (s[0] == s[3] and s[1] == s[2]):
    if s[0] == s[1] and s[1] == s[2]:
        print("No")
    else:
        print("Yes")
else:
    print("No")

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

int main() {
	
	int n; cin >> n;
	int p = n + 5;
	vector<ll> num(p, 0);
	ll initial;
	ll maximumValue = 0;
	for (int i = 0; i < n; i++) {
		ll d; cin >> d;
		num[d]++;
		maximumValue = max(maximumValue, d);
		if (i == 0) initial = d;
	}
	if (initial != 0 || 2 <= num[0]) {
		cout << 0 << endl;
		return 0;
	}
	const ll mod = 998244353;
	ll ans = 1;
	for (int i = 2; i <= maximumValue; i++) {
		int tmpCnt = num[i];
		while (tmpCnt--) {
			ans *= num[i - 1];
			ans %= mod;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

const int timeLimit = 1980;

i64 xor128()
{
  static i64 x = 123456789, y = 362436069, z = 521288629, w = 88675123;
  i64 t = (x ^ (x << 11));
  x = y;
  y = z;
  z = w;
  return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

i64 D;
i64 c[26];
i64 s[365][26];
vector<i64> ans;

i64 eval(vector<i64> &ans)
{
  i64 score = 0;
  i64 last[26] = {};
  for (i64 i = 0; i < D; i++)
  {
    score += s[i][ans[i]];
    last[ans[i]] = i;
    for (i64 j = 0; j < 26; j++)
      score -= c[j] * (i + 1 - last[j]);
  }
  return score;
}

void solve()
{
  ans.resize(D);
  chrono::system_clock::time_point start = chrono::system_clock::now();
  chrono::system_clock::time_point end = start + chrono::milliseconds(timeLimit);
  i64 bestScore = 0, loop = 0;
  while (chrono::system_clock::now() < end)
  {
    i64 t[3] = {xor128() % D, xor128() % 26};
    t[2] = ans[t[0]];
    ans[t[0]] = t[1];
    i64 score = eval(ans);
    if (bestScore < score)
    {
      bestScore = score;
    }
    else
    {
      ans[t[0]] = t[2];
    }
    loop++;
  }
  cerr << "score: " << bestScore + (i64)(1e6) << endl
       << "loop: " << loop << endl;
}

void input()
{
  cin >> D;
  for (i64 i = 0; i < 26; i++)
    cin >> c[i];
  for (i64 i = 0; i < D; i++)
    for (i64 j = 0; j < 26; j++)
      cin >> s[i][j];
}

void output()
{
  for (i64 i = 0; i < D; i++)
    cout << ans[i] + 1 << endl;
}

int main()
{
  input();
  solve();
  output();
  return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include<vector>
#include <cstdlib>
#include<cmath>
#include<string>
#include <iomanip>
#include <sstream>

using namespace std;


void sort(vector<int> &a){

    int mini,k,j=0,i,n=a.size();

    for(i=0;i<n;i++){
        mini=50000000;
        for(j=i+1;j<n;j++){

            if( mini > a[j] ){

                mini=a[j];
                k=j;
            }


        }

        if(a[i] > mini){

            swap(a[i],a[k]);

        }

    }


}


int main () {

int k,n,i,j;

cin>>n>>k;

vector<int> a(n);


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

    cin>>a[i];
}

int u=0;

sort(a);

for(i=0;i<k;i++){

    u+=a[i];

}

cout<<u;


}







/*#include <iostream>
#include<vector>
#include <cstdlib>
#include<cmath>
#include<string>
#include <iomanip>
#include <sstream>

using namespace std;


int main (){


    unsigned long long n,i,j,m,cnt=0;

    cin>>n;

    vector<unsigned long long> a(n);

    stringstream s[n];

    string final[n];

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

        cin>>a[i];
    }

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

        s[i]<<a[i];
        s[i]>>final[i];

    }

    vector<long long>b(n,0);



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

        m=final[i].size();

        for(j=0;j<m;j++){

            b[i]+=final[i][j]-'0';


        }



    }

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


        cout<<b[i]<<endl;
    }



}
 */

Measured memory_bytes: 3572
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n1,n2;
	
	cin>>n1>>n2;
	
	for(int i=1;i<=3;i++)
	{
		if((n1*n2*i)%2!=0)
		{
			//std::cout<<n1<<" "<<n2<<" "<<i<<endl;
			std::cout<<"Yes"<<endl;
			return 0;
		}
	}
	
	std::cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
 
#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
 
#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
 
int main(){
	int d;
	cin>>d;
	cout<<"Christmas";
	while(d<25){
		d++;
		cout<<" Eve";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    S = input()
    N = len(S)
    if N % 2 == 0:
        first = list(S[:N//2])
        second = list(S[N//2:N])
        second.reverse()
        cnt = 0
        for i in range(N//2):
            if first[i] != second[i]:
                cnt += 1
    else:
        first = list(S[:N//2])
        second = list(S[N//2 + 1:N])
        second.reverse()
        cnt = 0
        for i in range(N//2):
            if first[i] != second[i]:
                cnt += 1


    print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define me(a,x) memset(a,x,sizeof(a))
#define sc scanf
#define pr printf
#define IN freopen("in.txt","r",stdin);
#define OUT freopen("out.txt","w",stdout);
typedef long long ll;
typedef unsigned long long ull;
const int N=1e6+6;
const int mod=1e9+7;
template<typename T>int O(T s){cout<<s<<endl;return 0;}
template<typename T>void db(T *bg,T *ed){while(bg!=ed)cout<<*bg++<<' ';pr("\n");}
template<typename T>void db(vector<T>it){for(auto i:it)cout<<i<<' ';pr("\n");}
inline ll mul_64(ll x,ll y,ll c){return (x*y-(ll)((long double)x/c*y)*c+c)%c;}
inline ll ksm(ll a,ll b,ll c){ll ans=1;for(;b;b>>=1,a=a*a%c)if(b&1)ans=ans*a%c;return ans;}
inline void exgcd(ll a,ll b,ll &x,ll &y){if(!b)x=1,y=0;else exgcd(b,a%b,y,x),y-=(a/b)*x;}
int H,W,K;
string s[15];
int _1(int n){
    int a=0;
    while(n)a++,n&=n-1;
    return a;
}
int main(){
    //IN
    cin>>H>>W>>K;
    for(int i=0;i<H;i++)cin>>s[i];
    int ans=N;
    for(int bit=0;bit<(1<<H-1);bit++){
        int res=_1(bit);
        vector<int>v[H+1],sum(H+1,0);
        for(int j=0;j<W;j++){
            int num=0;
            for(int i=0;i<H;i++){
                num+=s[i][j]-'0';
                if(bit>>i&1){
                    v[i].push_back(num);
                    num=0;
                }else {
                    if(i==H-1)v[i].push_back(num);
                    else v[i].push_back(0);
                }
            } 
        }
        int last=-1;
        for(int j=0;j<W;j++){
            int ma=0;
            for(int i=0;i<H;i++){
                sum[i]+=v[i][j];
                ma=max(ma,sum[i]);
            }
            if(ma>K){
                j--;
                if(j==last){
                    res=1e5;break;
                }
                last=j;res++;
                for(int i=0;i<H;i++)sum[i]=0;
            }
        }
        ans=min(ans,res);
    }
    O(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,D;
    cin >> N >> D;
    int dist[N][D];
    rep(i,0,N)rep(j,0,D)cin >> dist[i][j];
    int cnt = 0;
    rep(i,0,N)rep(j,i+1,N){
        int sum = 0;
        rep(k,0,D){
            sum += (dist[i][k] - dist[j][k]) * (dist[i][k] - dist[j][k]);
        }
        bool ok = 0;
        for(int k = 1;k * k <= sum;k++){
            if(k * k == sum){
                ok = 1;
            }
        }
        cnt += ok;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)
{
    long long Q, H, S, D; cin >> Q >> H >> S >> D;
    long long N;  cin >> N;

    Q <<= 2;
    H <<= 1;

    long long stdp = min(min(Q, H), S);
    long long res = 0;

    if ((Q<<1) > D && (H<<1) > D && (S<<1) > D)
    {
        res = (N / 2) * D;
        N = N % 2;
    }

    res += N * stdp;

    cout << res << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;
long long int gcd(long long int x,long long int y){
    long long int r;
    if(x == 0 || y == 0)  return 0;

    while((r = x % y) != 0) 
    {
         x = y;
        y = r;
    }
    return y;
}

int main(){
    long long int n,m;
    string s,t; cin >> n >> m >> s >> t;
    ll lcm = (n * m) / gcd(n,m);
    ll gc  = gcd(n,m);
    
  rep(i,gc){
        if(s[(n / gc) * i] != t[(m / gc) * i]){
            cout << -1 << endl;
            return 0;
        }
    }
    
    cout << lcm << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string.h>
using namespace std;

int main(void) {
	int R, G, B, N, answer = 0, num1, num2;
	cin >> R >> G >> B >> N;
	for (int i = 0; i <= N / R; i++) {
		num1 = N - R * i;
		for (int j = 0; j <= num1 / G; j++) {
			num2 = num1 - G * j;
			if (num2 % B == 0) {
				answer++;
			}
		}
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
from math import *
from heapq import *

def mi():
    return map(int, input().split())
def ii():
    return int(input())
def li():
    return list(mi())
def gcd(a,b):return a if(not b) else gcd(b,a%b)
def qw(a,b,p):
    '''quick pow'''
    ans = 1
    while b:
        if b & 1:
            ans = ans * a % p
        a = a * a % p
        b >>= 1
    return ans
def is_prime(x):
    if(x < 2): return 0
    for i in range(2,int(sqrt(x)+1)):
        if(x % i == 0) : return 0
    return 1

n = ii()
a = li()
ans = 1
ok = 1
a.sort()
for i in range(0,n):
    ans = ans * a[i]
    if(ans > 1000000000000000000):
        ok = 0
        break
# print(ans)
if(ok == 0):print(-1)
else: print(ans)





Measured memory_bytes: 84080
# 5
# ABC095 C Half and Half

a, b, c, x, y = map(int, input().split())

ans = a * x + b * y
for i in range(max(x,y)+1):
    _ans = 2 * i * c + a * max((x - i),0) + b * max((y - i),0)
    if _ans < ans:
        ans = _ans
        
print(ans)

Measured memory_bytes: 39152
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    internal static class CR
    {
        public static string GetText() { return Console.ReadLine(); }
        public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long GetLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
    }

    public class Program
    {
        public static long R { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            R = CR.GetLong();
            return 2 * Math.PI * R;
        }
    }
}


Measured memory_bytes: 27620
#include<iostream>
#include<cstring>
#include<climits>
using namespace std;
const int maxn = 155;
int flag[maxn];
int main() {
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)flag[i] = INT_MAX;
	for(int i=1;i<n;++i) {
		int x;cin>>x;
		flag[i] = min(flag[i],x);
		flag[i+1] = min(flag[i+1],x);
	}
	int ans = 0;
	for(int i=1;i<=n;++i) {
		ans += flag[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(){
  string s;
  cin >> s;
  int diff = 753;
  for(int i = 0;i < s.size()-2;i++){
    string xstr = s.substr(i,3);
    int x = atoi(xstr.c_str());
    if(diff > abs(x - 753)) diff = abs(x-753);
  }
  cout << diff << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <map>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;



const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    COMinit();
  
    long long int n,m;
    cin>>n>>m;
    map<long long int,long long int> mp;
    long long int divisor=2;
    while(m!=1){
        if(m%divisor==0){
            mp[divisor]++;
            m/=divisor;
        }else{
            divisor++;
        }
    }
    long long int result = 1;
    for(auto x:mp){
        result *=COM(x.second + n - 1,x.second);
        result %= mod;
    
    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 12288
n = int(input())

m = [[0 for _ in range(n)] for _ in range(n)]

for _ in range(n):
    tmp = [int(x) for x in input().split()]
    u = tmp[0]
    k = tmp[1]
    l = tmp[2:]
    for x in l:
        m[u-1][x-1] = 1

for i in range(n):
    print(' '.join(map(str,m[i])))


Measured memory_bytes: 5680
//ΔARC066E
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 111111;
const LL INF = 1e18;
int n,a[N],op[N];
LL dp[N][3];
int main()
{
	int i,x;
	char ch[5];
	scanf("%d",&n);
	for(i=1;i<n;i=i+1){
		scanf("%d%s",a+i,ch);
		op[i+1]=(ch[0]=='-');
	}
	scanf("%d",a+n);
	dp[1][0]=a[1];
	dp[1][1]=-INF;
	dp[1][2]=-INF;
	for(i=2;i<=n;i=i+1){
		if(op[i]){
			dp[i][0]=max(max(dp[i-1][0]-a[i],dp[i-1][1]+a[i]),dp[i-1][2]-a[i]);
			dp[i][1]=max(max(dp[i-1][0]-a[i],dp[i-1][1]+a[i]),dp[i-1][2]+a[i]);
			dp[i][2]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
		}
		else{
			dp[i][0]=max(max(dp[i-1][0]+a[i],dp[i-1][1]+a[i]),dp[i-1][2]+a[i]);
			dp[i][1]=dp[i-1][1]-a[i];
			dp[i][2]=dp[i-1][2]+a[i];
		}
	}
	cout<<max(max(dp[n][0],dp[n][1]),dp[n][2]);
	return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <utility>
#include <cmath>
#include <stdio.h>

using namespace std;

int main(void){

    pair<double, double> p0, p1, p, ans;
    int n;
    cin >> p0.first >> p0.second >> p1.first >> p1.second;
    cin >> n;

    while(n--){
        cin >> p.first >> p.second;
        double a;
        if(p1.second - p0.second == 0){
            ans.first = p.first;
            ans.second = p1.second;
        }else if(p1.first - p0.first == 0){
            ans.first = p1.first;
            ans.second = p.second;
        }else{
            a = (p1.second - p0.second) / (p1.first - p0.first);
            ans.first = (a / (a*a + 1) ) * (-p0.second + p.second + a*p0.first + p.first/a);
            ans.second = (-1/a) * (ans.first - p.first) + p.second;
        }
        printf("%.10f ", ans.first * 2 - p.first);
        printf("%.10f", ans.second * 2 - p.second);
        cout << endl;
    }

    return 0;
}

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

char a[100010],b[100010],c[100010];

int main()
{
    while(scanf("%s%s%s",a,b,c)!=EOF)
    {
        printf("%c%c%c\n",a[0],b[0],c[0]);
    }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string a, b, c;
  cin >> a >> b >> c;

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

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

const ll MOD = 1000000007;

ll f(vector<vector<ll>>& dp, vector<vector<int>>& graph, int N, int top, int color, int parent){
    if(dp[top][color] != -1)return dp[top][color];
    
    ll res = 1;
    for(int i = 0;i < graph[top].size();i++){
        if(graph[top][i] == parent)continue;
        ll mul = f(dp,graph,N,graph[top][i], 1, top);
        // cout<<"a"<<endl;
        if(color == 1)mul = (mul + f(dp,graph,N,graph[top][i], 0, top))%MOD;
        res = (res * mul) % MOD;
    }
    // cout<<top<<color<<endl;
    // cout<<res<<endl;
    dp[top][color] = res;
    return dp[top][color];

}

int main(){
    int N;cin>>N;
    vector<vector<int>> graph(N, vector<int>(0));
    // if(N == 1){
    //     cout<<2<<endl;
    //     return 0;
    // }
    for(int i = 0;i < N-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<vector<ll>> dp(N, vector<ll>(2, -1));
    cout<<(f(dp,graph,N,0,0,-1) + f(dp,graph,N,0,1,-1))%MOD;
}

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

int main( int argc, char *argv[] )
{
string A;
string B;
string C;

	cin >> A;
	cin >> B;
	cin >> C;
	if( A[ A.size() - 1 ] != B[ 0 ] || B[ B.size() - 1 ] != C[ 0 ] )
	{
		cout << "NO" << endl;

		return 0;
	}

	cout << "YES" << endl;

	return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>
#include<boost/multiprecision/cpp_int.hpp>


using namespace std;
using namespace boost::multiprecision;

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

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", (double)v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
template<typename A, typename B>
void mins(A& a, const B& b) { a = min(a, (A)b); };
template<typename A, typename B>
void maxs(A& a, const B& b) { a = max(a, (A)b); };


template<typename T>
class BIT {
public:
	long long N;
	vector<T> seg;
	BIT(long long N) : N(N) {
		seg.resize(N + 1);
		for (int i = 0; i < N + 1; ++i) seg[i] = 0;
	}

	//i番目にxを加算
	void add(int i, T x) {
		++i;
		while (i <= N) {
			seg[i] += x;
			i += i & (-i);
		}
	}

	//[0,i)の和
	T cumulative(int i) {
		T s = 0;
		while (i > 0) {
			s += seg[i];
			i -= i & (-i);
		}
		return s;
	}

	//[a,b)の和
	T sum(int a, int b) {
		return cumulative(b) - cumulative(a);
	}

	//i番目の要素
	T elem(int i) {
		return sum(i, i + 1);
	}

	//i番目に代入
	void assign(int i, T x) {
		add(i, -elem(i));
		add(i, x);
	}
};


int main() {
	ll N, K; cin >> N >> K;
	vector<ll> A(1+N); REP(i, 1, 1+N) cin >> A[i];
	vector<ll> S(1 + N);
	S[0] = 0;
	REP(i, 1, 1 + N) S[i] = S[i - 1] + A[i] - K;
	vector<ll> I(1 + N); REP(i, 0, 1+N) I[i] = i;
	sort(I.begin(), I.end(), [&](ll a, ll b) {
		if (S[a] == S[b]) return a < b;
		else return S[a] < S[b];
		});
	vector<ll> rank(1 + N); REP(i, 0, 1 + N) rank[I[i]] = i;
	BIT<ll> tree{ 1 + N };
	ll ans = 0;
	for (int i = N; i >= 0; --i) {
		int highrank_n = tree.sum(rank[i], N + 1);
		ans += highrank_n;
		tree.add(rank[i], 1);
	}
	PRI(ans);
	return 0;
}

Measured memory_bytes: 11116
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

int main(){
  ll A,B;
  cin>>A>>B;
  ll C=gcd(A,B);
  ll ans=1;
  for(ll i=2;i*i<=C;i++){
    if(C%i==0){
      ans++;
      while(C%i==0){C/=i;}
    }
  }
  if(C!=1){ans++;}
  cout<<ans<<endl;
  
  return 0;
}


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

typedef long long ll;
const ll mod=1e9+7;
const ll N=1e5+1;
const ll INF=1e10;
const double PI=acos(-1.0);

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	ll n,k;
	cin>>n>>k;
	vector<int> a(n+1);
	for(int i=1;i<=n;i++) cin>>a[i];
	vector<int> path,visited(n+1),dist(n+1);
	int cur=1;
	while(true){
		visited[cur]=true;
		path.push_back(cur);
		if(!visited[a[cur]]) dist[a[cur]]=1+dist[cur],cur=a[cur];
		else break;
	}
	if(k<dist[a[cur]]){
		cout<<path[k];
		return 0;
	}
	k-=dist[a[cur]];
	k%=(dist[cur]-dist[a[cur]]+1);
	cout<<path[dist[a[cur]]+k];
}


Measured memory_bytes: 6620
#include<stdio.h>
int main(){
	long long A,B,C,X,Y;
	scanf("%ld%ld%ld%ld%ld",&A,&B,&C,&X,&Y);
	long long cc=0;
	if(X>Y)cc=X;
    else cc=Y;
    long long money=cc*C*2;
	for(;cc>=0;cc--){
		long long sub=0;
		if(X>cc)sub+=(X-cc)*A;
		if(Y>cc)sub+=(Y-cc)*B;
		if(money<sub+cc*C*2)break;
		money=sub+cc*C*2;
	}
	printf("%ld\n",money);
}


Measured memory_bytes: 1736
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int M = scan.nextInt();
    scan.close();

    System.out.println(N*(N-1)/2 + M*(M-1)/2);
  }
}

Measured memory_bytes: 21844