akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<UL> A(N); rep(i, N) cin >> A[i];
		UL P[20] = {};
		ULL ans = 0;
		UL p = 0;
		rep(i, N) {
			rep(j, 20) {
				UL f = 1 << j;
				if (A[i] & f) { p = max(p, P[j]); P[j] = i + 1; }
			}
			ans += (i - p + 1);
			//rep(j, 20) cout << P[j] << " ";
			//cout << " : " << p;
			//cout << endl;
		}
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <utility>
using namespace std;

#define fi first
#define se second
typedef pair<int,int> pii;

int X, Y, n;
vector<int> v;
vector<vector<int> > board;
vector<vector<int> > ans;
vector<vector<int> > out;
int ok[10][10][10][10];
bool use[16];

int solve(int y, int x) {
	int res = 0;
	if(y >= Y) {
		out = ans;
		return 1;
	}
	if(ans[y][x]) {
		return solve(y+(x+1)/X, (x+1)%X);
	}
	vector<vector<int> > cpy = ans;
	for(int i = y; i < Y; i++) {
		for(int j = x; j < X; j++) {
			if(ok[y][x][i][j] && !use[ok[y][x][i][j]]) {
				for(int k = y; k <= i; k++)
					for(int l = x; l <= j; l++)
						ans[k][l] = ok[y][x][i][j];
				use[ok[y][x][i][j]] = true;
				res += solve(y+(x+1)/X, (x+1)%X);
				ans = cpy;
				use[ok[y][x][i][j]] = false;
			}
		}
	}
	return res;
}

int main() {
	while(cin >> X >> Y >> n, X || Y || n) {
		v.clear(); board.clear(); ans.clear();
		out.clear();
		v.resize(n+1);
		board.resize(Y);
		ans.resize(Y);
		for(int i = 0; i < 10*10*10*10; i++)
			ok[0][0][0][i] = 0;
		for(int i = 0; i < 16; i++)
			use[i] = false;
		for(int i = 1; i < v.size(); i++) v[i] = -1;
		for(int i = 0; i < n; i++) {
			int b, k;
			cin >> b >> k;
			v[b] = k;
		}
		for(int i = 1; i < v.size(); i++) {
			if(v[i] < 0) {
				cout << "NA" << endl;
				continue;
			}
		}
		for(int i = 0; i < Y; i++) {
			board[i].resize(X);
			ans[i].resize(X);
			for(int j = 0; j < X; j++) {
				cin >> board[i][j];
				ans[i][j] = 0;
			}
		}

		for(int i = 0; i < Y; i++) {
			for(int j = 0; j < X; j++) {
				for(int k = i; k < Y; k++) {
					for(int l = j; l < X; l++) {
						int cnt = 0;
						for(int m = 1; m < v.size(); m++) {
							if((k-i+1) * (l-j+1) == v[m]) {
								bool flg = true;
								for(int y = 0; y < Y && flg; y++) {
									for(int x = 0; x < X && flg; x++) {
										if(i <= y && y <= k && j <= x && x <= l) {
											if(board[y][x] != 0 && board[y][x] != m)
												flg = false;
										}
										else {
											if(board[y][x] == m)
												flg = false;
										}
									}
								}
								if(flg) {
									ok[i][j][k][l] = m;
									cnt++;
								}
							}
						}
						if(cnt != 1) ok[i][j][k][l] = 0;
					}
				}
			}
		}

		int res = 0;
		res = solve(0,0);
		int sum = 0;
		for(int i = 0; i < v.size(); i++) sum += v[i];
		bool flg = true;
		for(int i = 0; i < out.size(); i++)
			for(int j = 0; j < out[i].size(); j++)
				flg &= out[i][j] != 0;

		if(res == 1 && sum == X*Y && flg) {
			for(int i = 0; i < out.size(); i++) {
				cout << out[i][0];
				for(int j = 1; j < out[i].size(); j++) {
					cout << " " << out[i][j];
				}
				cout << endl;
			}
		}
		else {
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 1292
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
 
immutable MOD = 1_000_000_007;

auto solve(string s_)
{
    auto NC = s_.split.map!(to!int);
    immutable N=NC[0], C=NC[1];
    immutable A = readln.split.map!(to!long).array();
    immutable B = readln.split.map!(to!long).array();
    immutable u = B.reduce!max();
    auto p = new long[][](u+1,C+1);
    foreach(int v, ref a;p)
    {
        a[0]=1;
        foreach(c;1..C+1) a[c]=a[c-1]*v%MOD;
    }
    foreach(c;0..C+1) foreach(v;1..u+1) p[v][c]=(p[v][c]+p[v-1][c])%MOD;
    auto dp = new long[][](N+1,C+1);
    dp[0][0]=1;
    foreach(n;1..N+1)
    {
        auto a = p[A[n-1]-1];
        auto b = p[B[n-1]];
        foreach(c;0..C+1)
            foreach(i;0..c+1)
                dp[n][c]=(dp[n][c]+dp[n-1][c-i]*(b[i]-a[i]+MOD))%MOD;
    }
    return dp[N][C];
}

void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }

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

int main()
{
    long long arr[] = {0, 1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111};
    long long a, b;
    cin >> a >> b;
    cout << (a * arr[b] > b * arr[a] ? a * arr[b] : b * arr[a]) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> pii;
typedef tuple<ll,ll,ll> t3;

using namespace std;

int main() {
    string s;
    cin >> s;
    if(s.find("YAKI") == 0)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());

    string t;
    cin >> t;
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,T;
	cin >> N >> T;
	vector<pair<int,int>> p(N);
	rep(i,N)cin >> p[i].first >> p[i].second;
	sort(ALL(p));
	vector<vector<int>> dp(N,vector<int>(3500));
	rep(i,N){
		rep(j,T){
			if(i==0){
				dp[i][j] = 0;
				if(j>=p[i].first)dp[i][j] = p[i].second;
			}else{
				dp[i][j] = dp[i-1][j];
				if(j>=p[i].first){
					dp[i][j] = max(dp[i][j],dp[i-1][j-p[i].first] + p[i].second);
				}
			}
		}
	}
	int ans = 0;
	rep(i,N){
		if(i==0)ans = p[i].second;
		else ans = max(ans,dp[i-1][T-1]+p[i].second);
	}
	cout << ans << endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

bool table[1000001];

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    map<int,int> M;
    rep(i,N){
        int a; cin>>a;
        M[a]++;
    }

    int ans=0;
    for(auto e:M){
        if (table[e.fi]) continue;
        for(int j=e.fi; j<=1000000; j+=e.fi){
            table[j]=true;
        }
        if (e.se==1) ans++;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 14008
n,C,T=map(int,input().split())
t=[int(input()) for i in range(n)]
t.sort()
res=t[0]+T
cnt=1
ans=0
for i in range(1,n):
  if t[i]<=res and cnt<C:
    cnt+=1
  elif t[i]>res or cnt==C:
    ans+=1
    res=t[i]+T
    cnt=1
print(ans+1)

Measured memory_bytes: 13252
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,M;
    cin >> N >> M;
    vector<int> a(M);
    vector<int> b(M);
    for(int i=0;i<M;i++){
        cin >> a.at(i) >> b.at(i);
    }
    for(int j=0;j<N;j++){
        int count = 0;
        for (int k=0;k<M;k++){
          if(a.at(k) == j+1){
            count++;
          }else if(b.at(k) == j+1){
            count++;
          }
        }
        cout << count <<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int,int>
#define eb emplace_back
#define MOD 1000000007
#define int long long
using namespace std;
#define s second
#define f first

pii a[50], b[50];
int dis(int i, int j)
{
    return abs(a[i].f - b[j].f) + abs(a[i].s - b[j].s);
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i=0;i<n;i++)
        cin >> a[i].f >> a[i].s;

    for(int i=0;i<m;i++)
        cin >> b[i].f >> b[i].s;
    
    for(int i=0;i<n;i++)
    {
        int ans, d = 1e9;
        for(int j=0;j<m;j++)
        {
            if( dis(i, j) < d )
            {
                ans = j;
                d = dis(i, j);
            }
        }
        cout << ans+1 << '\n';
    }
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
#define chmax(a,b) if(b>a) a = b
#define chmin(a,b) if(b<a) a = b
typedef long long ll;
using namespace std;

using namespace std;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n,k; cin >> n >> k;

    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    
    vector<ll> c(n+1,0);

    chmin(k,41);

    rep(i,k){
          rep(i,n+1) c[i] = 0;
          rep(i,n){
              if(a[i] == 0){ c[i]++; c[i+1]--;}
              else{
                  if(i - a[i] >= 0) c[i-a[i]]++;
                  else c[0] ++;
                  if(i+a[i]+1 <= n) c[i+a[i]+1]--;
                  else c[n]--;
              }
          }
          rep(i,n+1) if(0 < i) c[i] += c[i-1];

          rep(i,n) a[i] = c[i]; 
    }

    rep(i,n) cout << a[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 6352
<?php
list($N, $M) = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

$A = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

$target = array_sum($A) / (4 * $M);

$is_popular = 0;
foreach ($A as $a) {
    if ($a >= $target) {
        $is_popular += 1;
    }
    if ($is_popular === $M) {
        echo 'Yes';
        return;
    }
}

echo 'No';


Measured memory_bytes: 15916
#include <stdio.h>
#define MAX 100000
//int partition(A, p, r)

int main()
{
  int n,c,A[MAX],x,i=0,j,chang1,chang2,k;
  scanf("%d",&n);
  for(c=1;c<=n;c++)
    {
      scanf("%d",&A[c]);
    }
  x=A[n];
  //i=p-1;
  for (j=1;j<=n-1;j++)
    {
      if (A[j]<=x)
	{
	  i = i+1;
	  //A[i] と A[j] を交換
	  chang1=A[i];
	  A[i]=A[j];
	  A[j]=chang1;
	}
    }
  chang2=A[i+1];
  A[i+1]=A[n];
  A[n]=chang2;
  for(k=1;k<=n;k++)
    {
      if(k==i+1)
	{
	  printf("[%d] ",A[k]);
	}
      else if(k==n)
	{
	  printf("%d",A[k]);
	}
      else
	{
	  printf("%d ",A[k]);
	}
    }
  printf("\n");
  return 0;
}

/*
  partition(A, p, r)
  {
  int chang1,chang2;
  x=A[r];
  //i=p-1;
  for (j=1;j<=r-1;j++)
  {
  if (A[j]<=x)
  {
  i = i+1;
  //A[i] と A[j] を交換
  chang1=A[i];
  A[i]=A[j];
  A[j]=chang1;
  }
  }
  //A[i+1] と A[r] を交換
  chang2=A[i+1];
  A[i+1]=A[r];
  A[r]=chang2;
  return i+1;
  }
  for(k=1;k<=n;k++)
  {
  if(k==i+1)
  {
  printf("[%d] ",A[k]);
  }
  else if(k==n)
  {
  printf("%d",A[k]);
  }
  else
  {
  printf("%d ",A[k]);
  }
  }
*/



Measured memory_bytes: 2132
dict={}
ans=[]
n=int(input())
for i in range(n):
	a,b=input().split()
	if a=='insert':
		dict.setdefault(b,i)
	elif a=='find':
		if b in dict:
			ans.append('yes')
		else:
			ans.append('no')

for i in ans:
	print(i)


Measured memory_bytes: 45816
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
using namespace std;
void read(int &x){
	char ch;bool ok;
	for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
	for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=1<<16;
int n,m,v[20][20];
long long ans,in[maxn],f[maxn][20];
vector<int>d[20];
int main(){
	read(n),read(m);
	for(rg int i=1,x,y,z;i<=m;i++){
		read(x),read(y),read(z),v[x][y]=v[y][x]=z;
		ans+=z;
		d[x].push_back(y),d[y].push_back(x);
	}
	int tot=1<<n;
	for(rg int i=0;i<tot;i++){
		for(rg int j=1;j<=n;j++)
			if(!(i&(1<<(j-1)))&&!in[i|(1<<(j-1))]){
				int w=d[j].size(),sum=in[i];
				for(rg int k=0;k<w;k++)
					if(i&(1<<(d[j][k]-1)))sum+=v[j][d[j][k]];
				in[i|(1<<(j-1))]=sum;
		}
	}
	memset(f,-1,sizeof f);
	f[1][1]=0;
	for(rg int i=0;i<tot;i++)
		for(rg int k=1;k<=n;k++){
			if(f[i][k]==-1)continue;
			if(i&(1<<(k-1))){
				for(rg int j=1;j<=n;j++)
					if(!(i&(1<<(j-1)))&&v[k][j])
						f[i|(1<<(j-1))][j]=max(f[i][k]+v[k][j],f[i|(1<<(j-1))][j]);
				int now=((tot-1)^i)|(1<<(k-1));
				for(rg int j=now;j;j=(j-1)&now)
				    if(j&(1<<(k-1)))f[i|j][k]=max(f[i][k]+in[j],f[i|j][k]);
			}
		}
	printf("%lld\n",ans-f[tot-1][n]);
}


Measured memory_bytes: 10752
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll x, t;std::cin >> x >> t;
  std::cout << max((ll)0, x-t) << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    if(x<1200){
        cout << "ABC" << endl;
    } else {
        cout << "ARC" << endl;
    }
}

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

int main() {
  int N, K;
  cin >> N >> K;

  int x[N];
  rep(i, 0, N) {
    cin >> x[i];
  }

  int Ans = 0;

  rep(i, 0, N) {
    int DistanceA = x[i]*2;
    int DistanceB = (K-x[i])*2;
    Ans += min(DistanceA, DistanceB);
  }

  cout << Ans << endl;
}


Measured memory_bytes: 256
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    int n;
    cin >> n;
    cout << "ABC" << n << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>

#define REP(i,n) for(int i=0; i<n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
 
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9

using namespace std;
typedef long long ll;

int main(){
	int x;
	cin >> x;
	if (x==7 || x==5 || x==3){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 888
W = int(input())
N = int(input())
edges = [tuple(map(lambda c:int(c)-1, input().split(","))) for _ in [0]*N]
result = list(range(1, W+1))

for a, b in edges:
    result[a], result[b] = result[b], result[a]

print("\n".join(map(str, result)))

Measured memory_bytes: 7728
#include<iostream>
using namespace std;
int main(){
  int m,f,r;
  cin >> m >> f >> r;
  while(m!=-1||f!=-1||r!=-1){
    if(m==-1||f==-1) cout << "F" << endl;
    else if(m+f>=80) cout << "A" << endl;
    else if(m+f>=65) cout << "B" << endl;
    else if(m+f>=50) cout << "C" << endl;
    else if(m+f>=30)
      if(r>=50) cout << "C" << endl;
      else cout << "D" << endl;
    else cout << "F" << endl;

    cin >> m >> f >> r;
  }
  return 0;
}



Measured memory_bytes: 3088
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, int>;

long long V, E;
long long d[100][100];
const long long INF = 100000000000000;
bool b[100][100];

int main() {
  cin >> V >> E;

  rep(i, V) {
    rep(j, V) {
      if(i == j) d[i][j] = 0;
      else d[i][j] = INF;
    }
  }

  rep(i, E) {
    long long x, y, temp;
    cin >> x >> y >> temp;
    d[x][y] = temp;
    b[x][y] = true;
  }
  
  rep(k, V) {
    rep(i, V) {
      rep(j, V) {

        d[i][j] = min(d[i][k] + d[k][j], d[i][j]);
        // cout << d[i][j] << " " << k << " " << i << " " << j << endl;
      }
    }
  }

  rep(i, V) {
    rep(j, V) {
      if(i == j && d[i][j] < 0) {
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
      }
    }
  }


  rep(i, V) {
    rep(j, V) {
      if(d[i][j] < 1e10) {
        cout << d[i][j];
      } else {
        cout << "INF";
      }
      if(j != V - 1) cout << " ";
      else cout << endl;
    }
  }
  return 0;
}


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

void dfs(int depth, int limit, std::string s, char max, std::vector<std::string>& ans)
{
	if (depth == limit)
	{
		ans.emplace_back(s);
		return;
	}

	for (char c = 'a'; c <= max + 1; ++c)
	{
		dfs(depth + 1, limit, s + c, std::max(max, c), ans);
	}
}

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<std::string> ans;
	dfs(1, n, "a", 'a', ans);
	std::sort(ans.begin(), ans.end());
	for (auto& s : ans)
	{
		std::cout << s << "\n";
	}
	return 0;
}


Measured memory_bytes: 7796
'use strict'

function calcDistance(I, J, D) {
    let dist = 0;
    for (let d = 0; d < D; d++) {
        dist += Math.pow(I[d] - J[d], 2);
    }

    dist = Math.sqrt(dist);
    return dist;
}
function main(input) {
    const tmp = Array.from(input.split('\n'));
    const ND = tmp.shift().split(' ');
    const N = parseInt(ND[0], 10);
    const D = parseInt(ND[1], 10);

    const X = tmp.map((line) => line.split(' ').map((x) => parseInt(x, 10)));

    let count = 0;
    for (let i = 0; i < N - 1; i++) {
        for (let k = i + 1; k < N; k++) {
            if (Number.isInteger(calcDistance(X[i], X[k], D))) {
                count++;
            }
        }
    }
    console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <iostream>

using namespace std;

int main(void) {
  int n, i = 0;
  while(cin >> n) {
    int num = 0;
    for(int a = 0; a < 10; a++) {
      for(int b = 0; b < 10; b++) {
        for(int c = 0; c < 10; c++) {
          for(int d = 0; d < 10; d++) {
            if(a + b + c + d == n) num++;
          }
        }
      }
    }

    cout << num << '\n';
  }

  return 0;
}

Measured memory_bytes: 2980
n = int(input())
num = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]

for x in range(n):
  b,f,r,v = list(map(int, input().split()))
  num[b-1][f-1][r-1] += v

for x in range(4):
  for y in range(3):
    for z in range(10):
      print(" "+str(num[x][y][z]),end = "")
    print("")
  if x == 3:
    break
  else:
    print("####################")


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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int N = 1e6;

int lp[N + 1];
int cnt[N + 1];

void solve() {
  for (int i = 2; i <= N; i++) {
    if (lp[i]) continue;
    lp[i] = i;
    if (1LL * i * i > N) continue;
    for (int j = i * i; j <= N; j += i) {
      if (!lp[j]) lp[j] = i;
    }
  }
  int n, g; cin >> n;
  for (int i = 0; i < n; i++) {
    int v; cin >> v;
    if (i == 0) g = v;
    else g = __gcd(g, v);
    while (v != 1) {
      int p = lp[v];
      while (v % p == 0)
        v /= p;
      cnt[p]++;
    }
  }
  int flag = 1;
  for (int i = 2; i <= N; i++) {
    flag &= (cnt[i] <= 1);
  }
  if (flag)
    cout << "pairwise coprime";
  else if (g == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}


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


int prime = 1000000007;
int n, m;
long long x[100000], y[100000];



int main(){
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        scanf("%lld", x+i);
    }
    for(int j = 0; j < m; j++){
        scanf("%lld", y+j);
    }
    //sort(x, x+n);
    //sort(y, y+m);

    long long width = 0, height = 0;
    for(long long i = 0; i < n - 1; i++){
        width += (x[i+1]-x[i]) % prime * (i+1) % prime * ((n-1) - (i+1) + 1) % prime;
        width %= prime;
    }
    //printf("width: %lld\n", width);
    for(long long j = 0; j < m - 1; j++){
        height += (y[j+1]-y[j]) % prime * (j+1) % prime * ((m-1)-(j+1)+1) % prime;
        height %= prime;
    }
    //printf("height: %lld\n", height);

    long long res = width * height % prime;
    cout << res << endl;
    return 0;

    
}

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

namespace _1_6_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = new string[n];
            s = Console.ReadLine().Split(' ');
            for (int t = n - 1; t >= 0; t--)
            {
                if (t == 0)
                {
                    Console.Write(s[t]);
                }
                else
                {
                    Console.Write(s[t]);
                    Console.Write(' ');
                }
            }
            Console.Write('\n');
            Console.ReadKey();
        }
    }
}




Measured memory_bytes: 15972
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

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

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

vector<intmax_t> divisor(intmax_t n) {
    vector<intmax_t> ret;
    for (intmax_t i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

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

    intmax_t N, M;
    cin >> N >> M;

    intmax_t res = 0;
    for (auto &elem: divisor(M)) {
        if (elem <= M / N) {
            chmax(res, elem);
        }
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

n = getN()
a = input()
b = input()
c = input()
ans = 0
for s,t,r in zip(a,b,c):
    ans += len(list(set([s,t,r]))) - 1

print(ans)

Measured memory_bytes: 3064
import scala.io.StdIn._
object Main extends App {
  val allSquares = (1 to 150).flatMap(height ⇒ (height + 1 to 150).map(width ⇒ Square(height, width))).sorted.toArray
  case class Square(h: Int, w: Int) extends Ordered[Square] {
    override def compare(that: Square): Int = {
      if (h * h + w * w == that.h * that.h + that.w * that.w) h.compare(that.h)
      else (h * h + w * w).compare(that.h * that.h + that.w * that.w)
    }

    override def toString: String = s"$h $w"
  }
  loop
  def loop: Unit = {
    val Array(h, w) = readLine.trim.split(' ').map(_.toInt)
    if (h == 0) return
    println(
      allSquares(upperBound(allSquares, Square(h, w)))
    )
    loop
  }

  def upperBound[T <: Ordered[T]](array: Array[T], target: T): Int = {
    var left = 0
    var right = array.length
    while(left < right){
      val mid = (left + right) / 2
      if (array(mid) <= target){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
}



Measured memory_bytes: 50240
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const int inf = 1e9;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W; cin >> H >> W;
  // ワーシャルフロイド
  int n,m;// 頂点、辺
  int dist[10][10];
  FOR(i,0,10) {
    FOR(j,0,10) {
      int cost; cin >> cost;
      dist[i][j] = cost;
    }
  }

  FOR(k,0,10) FOR(i,0,10) FOR(j,0,10) {
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
  }
  int ans = 0;
  FOR(h,0,H) {
    FOR(w,0,W) {
      int a; cin >> a;
      if(a == -1 || a == 1) continue;
      ans += dist[a][1];
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

char lower(char c) {
    if (c >= 'A' && c <= 'Z') {
        return c + ('a' - 'A');
    } else {
        return c;
    }
}

void solve() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    for (int i = 0; i < S.size(); i++) {
        if (i == K - 1) {
            cout << lower(S[i]);
        } else {
            cout << S[i];
        }
    }
    cout << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	#define sz 2020
	#define mod 1000000007ll
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(register int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cout<<(clock()-t)/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

ll fac[sz],_fac[sz];
void init(){_fac[0]=fac[0]=1;rep(i,1,sz-1) _fac[i]=inv(fac[i]=fac[i-1]*i%mod);}
ll C(int n,int m){return n>=m&&m>=0?fac[n]*_fac[m]%mod*_fac[n-m]%mod:0;}

int A,B;
ll f[sz][sz],g[sz][sz];

int main()
{
	file();
	init();
	read(A,B);
	rep(i,0,sz-1) f[i][0]=f[0][i]=1;
	rep(i,1,sz-1) rep(j,1,sz-1) f[i][j]=(f[i-1][j-1]+f[i][j-1])%mod;
	rep(j,0,sz-1) rep(i,1,sz-1) (f[i][j]+=f[i-1][j])%=mod;
	rep(i,1,sz-1) rep(j,1,sz-1) g[i][j]=f[i][j-1]; 
	rep(i,0,sz-1) g[i][0]=g[0][i]=1;
	ll ans=0;
	rep(i,0,A) rep(j,B-1-A+i,B-1) (ans+=C(B-1,j)*g[A-i-(B-1-j)][B-1-j]%mod)%=mod;
	cout<<ans;
	return 0;
}

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

//static const int MAX = 200000;

int main() {
	
	int R,n;
	
	cin>>n;
	
	int maxv=-2000000000;
	int minv;
	cin>>minv;
	for(int i=1;i<n;i++){
		cin>>R;
		maxv=max(maxv,R-minv);
		
		minv=min(minv,R);
	}
	
	cout<<maxv<<endl;
	
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (ll i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<ll, ll>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    map<ll, ll> mp;
    rep(i, n) {
        mp[a[i]]++;
    }
    ll q;
    cin >> q;
    ll ans = 0;
    for (auto m: mp) {
        ans += m.first*m.second;
    }
    rep(qi, q) {
        ll b, c;
        cin >> b >> c;
        ll x = mp[b];
        ans -= b*mp[b];
        mp.erase(b);
        mp[c] += x;
        ans += c*x;
        cout << ans << endl;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 7876
#include <stdio.h>
#include <stdlib.h>

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

    int a[n];
    for(int i = 0;i < n;i++){
        scanf("%d",&a[i]);
    }
    int temp1 = a[0];
    int temp1pos = 0;
    int temp2 = 0;
    
    for(int i = 1;i < n;i++){
        if (temp1 < a[i]){
            temp2 = temp1;
            temp1 = a[i];
            temp1pos = i;
        } else if(temp2 < a[i]){
            temp2 = a[i];
        }
    }
    
    for(int i = 0;i < n;i++){
        if (temp1pos == i){
            printf("%d\n",temp2);
        } else {
            printf("%d\n",temp1);
        }
    }

}



Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}



int main(){
  cout<<setprecision(1000);
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,K;
  cin>>N>>K;
  vector<ll> A,mA;
  REP(N){
    ll tmp;
    cin>>tmp;
    if(tmp<0){
      mA.push_back(-tmp);
    }else{
      A.push_back(tmp);
    }
  }
  sort(A.begin(),A.end());
  sort(mA.begin(),mA.end());
  dump(A);
  dump(mA);
  ll l=-1000000000000000005LL,r=1000000000000000005LL;
  while(l+1<r){
    ll cnt=0;
    ll mid=(l+r)/2;
    for (auto &&i : mA)
    {
      ll j;
      if(mid<0){
        j=(-mid)/i+(mid%i?1:0);
        cnt+=A.end()-lower_bound(A.begin(),A.end(),j);
      }else{
        j=mid/i;
        cnt+=upper_bound(mA.begin(),mA.end(),j)-mA.begin();
        cnt+=A.size();
        if(j>=i){
          --cnt;
        }
      }
    }
    for (auto &&i : A)
    {
      if(i==0){
        if(mid>=0){
          cnt+=mA.size()+A.size()-1;
        }else{

        }
        continue;
      }
      ll j;
      if(mid<0){
        j=(-mid)/i+(mid%i?1:0);
        cnt+=mA.end()-lower_bound(mA.begin(),mA.end(),j);
      }else{
        j=mid/i;
        cnt+=upper_bound(A.begin(),A.end(),j)-A.begin();
        if(j>=i){
          --cnt;
        }
        cnt+=mA.size();
      }
    }
    dump(mid);
    dump(cnt);
    cnt/=2;
    if(cnt>=K){
      r=mid;
    }else{
      l=mid;
    }
  }
  cout<<r<<endl;
  return 0;
}


Measured memory_bytes: 2548
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<deque<int>> a(n, deque<int> (m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int ans = 1232432235938789;
  vector<bool> visited(m + 1, false);
  for (int j = 0; j < m - 1; j++) {
    for (int i = 0; i < n; i++) {
      while (visited[a[i][0]]) {
        a[i].pop_front();
      }
    }

    vector<int> cnt(m + 1, 0);
    for (int i = 0; i < n; i++) {
      cnt[a[i][0]]++;
    }
    int mx = max_element(cnt.begin(), cnt.end()) - cnt.begin();
    visited[mx] = true;
    ans = min(ans, cnt[mx]);
    for (int i = 0; i < n; i++) {
      if (a[i][0] == mx) a[i].pop_front();
    }
  }
  if (m == 1) {
    ans = n;
  }
  cout << ans << "\n";
}



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String mes = sc.nextLine();
        int count = 0;
        boolean flag1 = false;
        boolean flag2 = false;
        boolean flag3 = false;
        if (mes.charAt(0) == 'A') {
            flag1 = true;
        }
        for (int i = 2; i < mes.length() - 1; i++) {
            if (mes.charAt(i) == 'C') {
                count++;
            }
        }
        if (count == 1) {
            flag2 = true;
        }
        String MES = mes.toUpperCase();
        int check = 0;
        for (int i = 0; i < mes.length(); i++) {
            if (MES.charAt(i) == mes.charAt(i)) {
                check++;
            }
        }
        if (check == 2) {
            flag3 = true;
        }
        if (flag1 && flag2 && flag3) {
            System.out.println("AC");
        } else {
            System.out.println("WA");
        }
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    double surface = w * h;
    cout << surface/2 << " " ;
    if (w==2*x && h==2*y) cout << 1;
    else cout << 0;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ll n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);
	if (n == 1)
	{
		if (a == b)
		{
			printf("1\n");
		}
		else
		{
			printf("0\n");
		}
		return 0;
	}
	if (a > b)
	{
		printf("0\n");
		return 0;
	}
	printf("%lld\n", (b * (n - 1) + a) - (a * (n - 1) + b) + 1);
	return 0;
}

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

ll sum[1000010],sum1[1000010];
ll cnt[1000010],miu[1000010],p[1000010],inv[1000010],n,tot;
bool bo[1000010];

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline ll pls(const ll &x,const ll &y) { return (x+y<mod)?x+y:x+y-mod; }
inline ll mns(const ll &x,const ll &y) { return (x-y<0)?x-y+mod:x-y; }
inline ll ksm(ll x,ll y) { ll res=1;for (;y;y>>=1,x=x*x%mod) if (y&1) res=res*x%mod;return res; }

inline void pre_gao()
{
	miu[1]=1;
	for (int i=2;i<=1000000;i++)
	{
		if (!bo[i]) p[++tot]=i,miu[i]=mod-1;
		for (int j=1;j<=tot&&i*p[j]<=1000000;j++)
		{
			bo[i*p[j]]=true;
			if (i%p[j]==0) break;
			miu[i*p[j]]=mod-miu[i];
		}
	}
	inv[1]=1;
	for (int i=2;i<=1000000;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
}

int main()
{
	n=rd();pre_gao();
	for (int i=1;i<=n;i++) cnt[rd()]++;
	ll ans=0;
	for (int i=1;i<=1000000;i++) ans=pls(ans,i*(cnt[i]*(cnt[i]-1)/2%mod)%mod);
	for (int i=1;i<=1000000;i++) for (int j=i;j<=1000000;j+=i) sum[i]=pls(sum[i],cnt[j]*j%mod),sum1[i]=pls(sum1[i],cnt[j]*j%mod*cnt[j]%mod*j%mod);
	ll inv2=ksm(2,mod-2);
	for (int i=1;i<=1000000;i++) sum[i]=mns(sum[i]*sum[i]%mod,sum1[i])*inv2%mod;
	for (int i=1;i<=1000000;i++)
	{
		ll res=0;
		for (int j=i;j<=1000000;j+=i) res=pls(res,miu[j/i]*sum[j]%mod);
		ans=pls(ans,res*inv[i]%mod);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 42112
<?php

while(1){

	list($H,$W)=explode(" ",trim(fgets(STDIN)));

	if($H==0 && $W==0){

		break;
	}

	for($i=1;$i<=$H;$i++){

		for($j=1;$j<=$W;$j++){

			if($j==$W){

				print "#\n";

			}elseif($j==1 || $i==1 || $i==$H){

				print "#";

			}else{

				print ".";
			}
		}
	}

	print "\n";

}

Measured memory_bytes: 15268
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,e) for(int i = a;i < e;++i)

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	a.push_back(1e9 + 10);
	bool ok = 1;
	for (int i = N - 1; i >= 0; i--) {
		if (a[i] > a[i + 1]) {
			a[i]--;
			if (a[i] > a[i + 1])ok = 0;
		}
	}
	if (ok)puts("Yes");
	else puts("No");
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s=="SUN"){
    	cout << "7"; 
	}else if(s=="MON"){
		cout << "6";
	}else if(s=="TUE"){
		cout << "5";
	}else if(s=="WED"){
		cout << "4";
	}else if(s=="THU"){
		cout << "3";
	}else if(s=="FRI"){
		cout << "2";
	}else{
		cout <<"1";
	}
}

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

int main(void) {
	int N;
	char mise_name[100];
	char old_board[200];
	int i,j,k;
	int count;
	int board_num;
	int board_length;
	int mise_length;
	int ok,nowok;
	scanf("%d",&N);
	scanf("%s",mise_name);
	mise_length=strlen(mise_name);
	count=0;
	for(board_num=0;board_num<N;board_num++) {
		scanf("%s",old_board);
		board_length=strlen(old_board);
		ok=0;
		for(i=0;i<board_length;i++) {
			for(j=1;j<board_length;j++) {
				if(i+j*(mise_length-1)>=board_length)break;
				nowok=1;
				for(k=0;k<mise_length && nowok;k++) {
					if(old_board[i+j*k]!=mise_name[k])nowok=0;
				}
				if(nowok)ok=1;
			}
		}
		if(ok)count++;
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 600
void main()
{
    long[] tmp = rdRow;
    long h = tmp[0], a = tmp[1];

    writeln((h + a - 1) / a);
}

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

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

int main(void){
    int N,T,L;
    int X[100000] = {};
    int W[100000] = {};
    int i;
    cin >> N >> L >> T;
    //cout << N << L << T << endl;
    for(i=0;i<N;i++){
        cin >> X[i] >> W[i];
        //cout << X[i] << W[i] << endl;
    }

    vector<int> v;
    for(i=0;i<N;i++){
        if(W[i]==1){
            v.push_back((X[i] + T) % L);
        }
        if(W[i]==2){
            v.push_back((((X[i] - T) % L) + L) % L);
        }
        //cout << v[i] << endl;
    }
    int cross = 0;
    if(W[0]==1){
        for(i=1;i<N;i++){
            if(W[i]==2){
                if(2*T-(X[i]-X[0])>=0){cross++;}
                //cout << "cross " << cross << endl;
                cross += (2*T-(X[i]-X[0]))/L;
                //cout << "cross " << cross << endl;
            }
        }
    }
    if(W[0]==2){
        for(i=1;i<N;i++){
            if(W[i]==1){
                if(2*T-(L - X[i] + X[0])>=0){cross++;}
                //cout << "cross " << cross << endl;
                cross += (2*T-(L - X[i] + X[0]))/L;
                //cout << "cross " << cross << endl;
            }
        }
    }
    cross %= N;
    int tmp = v[0];
    sort(v.begin(), v.end());
    vector<int>::iterator iter = find(v.begin(), v.end(), tmp);
    int index = distance(v.begin(), iter);
    if(W[0]==1){
        if(v[index] == v[(index+1+N)%N]){index++;}
        for(i=0;i<N;i++){
            cout << v[(index-cross+i+N)%N] << endl;
        }
    }
    if(W[0]==2){
        for(i=0;i<N;i++){
            cout << v[(index+cross+i+N)%N] << endl;
        }
    }
    //cout << "index " << index << endl;

    return 0;
}


Measured memory_bytes: 2552
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;

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

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

ll pow(ll base, ll num, ll mod)
{
    if (num == 0)
        return 1;
    ll prev = pow(base, num / 2, mod);
    if (num % 2 == 0)
    {
        return (prev * prev) % mod;
    }
    else
    {
        return (((prev * prev) % mod) * base) % mod;
    }
}

int main()
{

    int n;
    cin >> n;

    VL v(n);
    ll sgcd = v[0];
    bool f1 = true;
    ll curmul = 1;
    VL fact(1000000 + 5, 0);
    rep(i, n)
    {
        cin >> v[i];
        sgcd = gcd(sgcd, v[i]);
        int x = v[i];
        int cur = 2;
        while (cur * cur <= x)
        {
            if (x % cur == 0)
            {
                while (x % cur == 0)
                {
                    x /= cur;
                }
                fact[cur]++;
            }
            cur++;
        }
        if (x != 1)
            fact[x]++;
    }
    rep(i, 1000000 + 5)
    {
        f1 &= (fact[i] <= 1);
    }

    bool f2 = sgcd == 1;
    if (f1)
    {
        cout << "pairwise coprime" << endl;
    }
    else if (f2)
    {
        cout << "setwise coprime" << endl;
    }
    else
    {
        cout << "not coprime" << endl;
    }

    return 0;
}


Measured memory_bytes: 18776
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        for(long a = -1500; a <= 1500; a++) {
            for(long b = -1500; b <= 1500; b++) {
                if(((long)(Math.pow(a, 5) - Math.pow(b, 5))) == x) {
                    System.out.println(a + " " + b);
                    b = 100000;
                    a = 100000;
                }
            }
        }
    }
}


Measured memory_bytes: 38944