akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;


int main(){
  string S;
  cin >> S;
  int K;
  cin >> K;
  vector<string> sub;
  for(int i=1; i<=min(K,(int)S.size()); i++){
    for(int j=0; j<(int)S.size()-i+1; j++){
      sub.push_back(S.substr(j,i));
    }
  }
  sort(sub.begin(),sub.end());
  unique(sub.begin(),sub.end());
  cout << sub[K-1] << endl;
  return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
const int inf = 2147483646;
const double eps = 1e-10;
typedef long long LL;
 
double n,t;
int main() {
    cin>>n;
    int fl = 0;
    for (int i=min(1,4000);i<=n;i++){
        if ((int)(i*1.08) == n) {
            cout<<i<<endl;
            fl = 1;
            break;
        }
    }
    
    if(!fl) cout<<":("<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]);
            long k = long.Parse(input[1]);

            long res = n;

            if (k < n)
            {
                res = n % k;
            }
            res = Math.Min(res, Math.Abs(res - k));
            Console.WriteLine(res);
        }
    }
}


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

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

	int A[n];

	for(int i=0;i<n;++i)	cin>>A[i];

	int ma = 0;
	
	int co = 0;

	for(int i=0;i<n-1;++i)
	{
		if(A[i]>= A[i+1])	++co;
		else
		{
			ma = (ma>co?ma:co);
			co = 0;
		}
	}
	// co++;
	ma = (ma>co?ma:co);
	// if(n==1)	ma = 0;

	cout<<ma<<"\n";

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

inline string reverse(string s){
	reverse(s.begin(), s.end());
	return s;
}

int main(){
	string train[71*6+2];
	int t; cin >> t;
	while(t--){
		string s; cin >> s;
		int n = s.size();
		string t = reverse(s);
		train[0] = s;
		train[1] = t;
		int pos = 2;
		for(int i=1;i<n;i++){
			string a = s.substr(0,i);
			string b = s.substr(i);
			string ra = reverse(a);
			string rb = reverse(b);
			train[pos++] = a + rb;
			train[pos++] = ra + b;
			train[pos++] = ra + rb;
			train[pos++] = b + a;
			train[pos++] = b + ra;
			train[pos++] = rb + a;
		}
		sort(train, train+pos);
		int ans = 1;
		for(int i=1;i<pos;i++) ans += train[i] != train[i-1];
		cout << ans << endl;
	}
}

Measured memory_bytes: 1004
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext())
		{
			int a=sc.nextInt();
			int b=sc.nextInt();
			int c=sc.nextInt();
			int sum = a+b;
			int count=0;

			if(sum <=14)
			{
				System.out.println("YES");
				continue;
			}
			for(int i=1; i<=10; i++)
			{
				if(i==a||i==b||i==c)
					continue;
				if(sum +i <= 20)
					count++;
			}
			if(count>=4)
				System.out.println("YES");
			else
				System.out.println("NO");
		}

	}

}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ll long long
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
using namespace std;
const int inf=1e9+10;
const int mod=1e9+7;
const int maxn=1e5+10;
int n,m,k;
int f[maxn],a[maxn];
set<int>g[maxn];
int find(int k){
	if(k==f[k]) return k;
	else return f[k]=find(f[k]);
}
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n>>m>>k;
	for (int i = 1; i <= n; ++i)
	{
		f[i]=i;a[i]=1;
	}
	while(m--){
		int x,y;
		cin>>x>>y;
		int rx=find(x),ry=find(y);
		if(rx!=ry){
			f[rx]=ry;
			a[ry]+=a[rx];
		}
		g[x].insert(y);
		g[y].insert(x);
	}
	while(k--){
		int x,y;
		cin>>x>>y;
		g[x].insert(y);
		g[y].insert(x);		
	}
	for(int i=1;i<=n;i++){
		int ans=a[find(i)]-1;
		for(int x:g[i]){
			if(find(x)==find(i)) ans--;
		}
		cout<<ans<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 25600
// E

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  ll n;
  cin>>n;
  ll cnt(0);
  if (n%2==1){
    cout << 0 << endl;
  }else{
    ll tmp = 1;
    while(tmp<n){
      tmp*= 5;
      cnt += n / (tmp*2);
    }
    cout <<cnt << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;

int main(){
    int w, h;
    while(cin >>w >>h && (w || h)){

        int black = 0, white = 0;
        vector< vector<char> > m(h, vector<char>(w));

        REP(i, h){
            REP(j, w){
                cin >>m[i][j];
            }
        }

        REP(i, h){
            REP(j, w){
                if(m[i][j] == '.'){

                    int cntb = 0, cntw = 0, cntd = 0;
                    queue<P> open;
                    open.push( P(i, j) );
                    m[i][j] = '@';
                    while(!open.empty()){
                        P now = open.front();
                        open.pop();
                        cntd++;

                        //debug
                        //cout <<now.first <<", " <<now.second <<endl;

                        int my[] = {0, 0, 1, -1};
                        int mx[] = {1, -1, 0, 0};
                        REP(i, 4){
                            int ny = now.first + my[i];
                            int nx = now.second + mx[i];
                            if(ny >= 0 && nx >= 0 && ny < h && nx < w){
                                if(m[ny][nx] == 'B') cntb++;
                                if(m[ny][nx] == 'W') cntw++;
                                if(m[ny][nx] == '.'){
                                    open.push( P(ny, nx) );
                                    m[ny][nx] = '@';
                                }
                            }
                        }
                    }
                    if(cntb == 0 && cntw != 0) white += cntd;
                    else if(cntw == 0 && cntb != 0) black += cntd;

                }
            }
        }
        cout <<black <<" " <<white <<endl;
    }
    return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, dp[200008];
string s;
ll MOD = 1e9+7;

int main(){
	cin >> n >> s;
	
	ll ans = 1;
	dp[0] = 0;
	for(ll i = 1; i <= 2*n; i++){
		if(dp[i-1] == 0){
			if(s[i-1] == 'W'){
				cout << 0 << endl;
				return 0;
			}
			else{
				dp[i] = 1;
			}
		}
		else{
			if((s[i-1] == 'W' && dp[i-1]%2 == 1) || (s[i-1] == 'B' && dp[i-1]%2 == 0)){
				dp[i] = dp[i-1]+1;
			}
			else{
				ans *= dp[i-1];
				ans %= MOD;
				dp[i] = dp[i-1]-1;
			}
		}
	}
	
	if(dp[2*n] > 0){cout << 0 << endl;}
	else{
		for(ll i = 1; i <= n; i++){
			ans *= i;
			ans %= MOD;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h> 
using namespace std;
#define pb push_back
#define ll long long int
#define vi vector<int>
#define ii pair<int,int>
#define vli vector<ll>
#define graph vector<vector< int > >
#define vpi vector<pair<int ,int> >
#define vpli vector<pair<ll ,ll> >
#define mp make_pair
#define F first
#define S second
#define mod 37
#define INF (ll)1e18
#define wh(a) cout<<#a<<"  is  "<<a<<endl;
#define INI(a) memset(a,0,sizeof(a))
#define LIMIT 40000010

void solve(){
    int n;
    cin>>n;
    if(n%10==2 || n%10==4 || n%10==5 || n%10==7 || n%10==9){
        cout<<"hon";
    }
    if(n%10==0 || n%10==1 || n%10==6 || n%10==8){
        cout<<"pon";
    }
    if(n%10==3){
        cout<<"bon";
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // #endif
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
from math import ceil
n,m = map(int,input().split())
l = list(map(int,input().split()))
l.sort(reverse=True)
val = sum(l)
f = 1
for i in range(m):
  if l[i] < ceil(val/(4*m)):
    f = 0
    break
if f:
  print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#define lli long long int
#define Div 1000000007
long long int Pow(lli m, lli n);
int main() {
	long long int m,n,a;
	scanf("%lld%lld", &m, &n);
	a=Pow(m,n);
	printf("%lld\n", a);
	return 0;
}

long long int Pow(lli m, lli n)
{	
	long long res = 1;
	if (n == 0) return 1;
	res = Pow(m*m%Div, n / 2);
	if (n % 2 == 1) res = res*m%Div;
	return res;
}

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

int main(){
	int n;
	
	while(cin >> n,n){
		double sum = 0.0;
		double m=0.0;
		vector<double> s(n);
		for(int i=0; i<n; i++){
			cin >> s[i];
			m += s[i]/n;
		}
		for(int i=0; i<n; i++)
			sum += pow(s[i]-m,2.0);
		cout << fixed << setprecision(8) << sqrt(sum/n) << endl;
	}
	return 0;
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = (1<<30);
 
int loop(int n) {
  int sum = 0;
  while(n != 0) {
    sum += n%10;
    n /= 10;
  }
  return sum;
}

int main() {
  int n;
  cin >> n;
  int sum = loop(n);
  
  if(n % sum == 0)
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3576
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
const int MAX_N = 110000;
using namespace std;

int main(){
    ll N; cin >> N;
    string S; cin >> S;
    //２つの累積和を使う
    ll W[N+1]={},E[N+1]={};
    for(int i=0; i<=N; i++){
        if(S[i]=='W'){
            W[i+1]=W[i]+1;
        }else{
            W[i+1] = W[i];
        }
    }
    for(int i=N; i>=0; i--){
        if(S[i]=='E'){
            E[i-1] = E[i]+1;
        }else{
            E[i-1]= E[i];
        }
    }
    /*
    for(int i=0; i<N+1; i++){
        cout << "E[" << i <<"]" << " " << E[i] << " ";
        cout << "W[" << i <<"]" << " " << W[i] << endl;
    }
    */
    ll ans = 3e9;
    for(int i=0; i<N+1; i++){
        ans = min(ans, W[i]+E[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5380
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1 , OO = 0x3f3f3f3f, M = 1LL << 21 , MOD = 1e9 + 7;
typedef long long ll ;
int n ;
vector < int > adj[N];
bool vis[N];
ll mem[N][3];
//int solve(int s , int pre  ){
//
//     mem[s][0] = 1;
//     mem[s][1] = 1;
//     for(int i = 0 ; i < adj[s].size() ; ++i){
//        int to = adj[s][i];
//        if(to == pre) continue;
//            mem[s][0]*=mem[to][0]+mem[to][1];
//            mem[s][0]%=MOD;
//            mem[s][1]*=mem[to][0];
//            mem[s][1]%=MOD;
//     }
//
//
//}
void dfs(int node,int parent=-1){
    mem[node][0]=1;
    mem[node][1]=1;
    for(int i=0;i<adj[node].size();i++){
        if(parent!=adj[node][i]){
            dfs(adj[node][i],node);
            mem[node][0]*=mem[adj[node][i]][0]+mem[adj[node][i]][1];
            mem[node][0]%=MOD;
            mem[node][1]*=mem[adj[node][i]][0];
            mem[node][1]%=MOD;
        }
    }

}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(mem , 0 , sizeof mem);
    cin >> n;
    int u , v;
    for(int i = 0 ; i < n -1 ; ++i){
        cin >> u >> v ;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
     dfs(1 , -1);
      cout << (mem[1][0] + mem[1][1] )% MOD;
//    cout << solve(2 , 0) << endl;
//    ll ans1 = solve(st , 0 ) % MOD ;
//  //  cout << solve(1 , 0 , 1) << endl;
//    memset(vis , 0 , sizeof vis);
//    memset(mem , -1 , sizeof mem);
//    ll ans2 = solve(st , 1) % MOD;
//    cout << (ans1 + ans2) % MOD  << endl;



}


Measured memory_bytes: 13696
from heapq import heappop, heappush

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

pq = []
heappush(pq, (-A[0] - B[0] - C[0], 0, 0, 0))
appeared = set((0, 0, 0))

for _ in range(K):
    # Pop maximum value
    val, i, j, k = heappop(pq)
    print(-val)

    # Add next value
    if i + 1 < X and (i + 1, j, k) not in appeared:
        heappush(pq, (-A[i + 1] - B[j] - C[k], i + 1, j, k))
        appeared.add((i + 1, j, k))

    if j + 1 < Y and (i, j + 1, k) not in appeared:
        heappush(pq, (-A[i] - B[j + 1] - C[k], i, j + 1, k))
        appeared.add((i, j + 1, k))

    if k + 1 < Z and (i, j, k + 1) not in appeared:
        heappush(pq, (-A[i] - B[j] - C[k + 1], i, j, k + 1))
        appeared.add((i, j, k + 1))


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

int main(void){
  ll h;
  cin>>h;

  ll ans = 0;
  ll step = 1;
  while(h>0){
    h/=2;
    ans+=step;
    step*=2;
  }
  cout<<ans<<endl;
}	

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

int main() {
    int n; cin >> n;
    vector<int> x(n), y(n), h(n);
    for(int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i] >> h[i];
    }
    int ans_x, ans_y, ans_h;
    for(int cx = 0; cx <= 100; ++cx) {
        for(int cy = 0; cy <= 100; ++cy) {
            set<int> hs;
            for(int i = 0; i < n; ++i) {
                if(h[i] == 0) continue;
                hs.insert(h[i] + abs(cx - x[i]) + abs(cy - y[i]));
            }
            if(hs.size() == 1u && *hs.begin() > 0) {
                bool ok = true;
                for(int i = 0; i < n; ++i) {
                    ok &= max(0, *hs.begin() - abs(x[i] - cx) - abs(y[i] - cy)) == h[i];
                }
                if(!ok) continue;
                ans_x = cx, ans_y = cy;
                ans_h = *hs.begin();
            }
        }
    }
    cout << ans_x << ' ' << ans_y << ' ' << ans_h << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      int n = int.Parse(Console.ReadLine());
      List<int> a = new List<int>();
      for (int i=1;i<=n;i++){
        a.Add(int.Parse(Console.ReadLine()));
      }
      int j =0;
      int num=1;
      bool flag = false;
      while (j<n){
        j+=1;
        num=a[num-1];
        if (num==2){
          flag=true;
          break;
        }
      }
      if (flag){
        Console.WriteLine(j);
      }
      else{
        Console.WriteLine(-1);
      }
    }
}


Measured memory_bytes: 31744
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000ll
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  
///////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n;
	cin>>n;
	int a[n];
	vector<int> po,ne;
	int bo=0;
	for(int i=0;i<n;++i)
	{
		cin>>a[i];
		if(a[i]>0)
			po.push_back(a[i]);
		if(a[i]==0)
			++bo;
		if(a[i]<0)
			ne.push_back(a[i]);
	}
	while(bo)
	{
		if(po.size()>=ne.size())
		{
			po.push_back(0);
		}
		else
			ne.push_back(0);
		--bo;
	}
	sort(po.begin(), po.end());
	sort(ne.begin(), ne.end());
	reverse(ne.begin(), ne.end());
	vector<pair<int,int>> ans;
	if(po.size()==0)
	{
		int v=ne[0];
		for(int i=1;i<ne.size();++i)
		{
			ans.push_back({v,ne[i]});
			v-=ne[i];
		}
		cout<<v<<"\n";
		for(auto r:ans)
		{
			cout<<r.F<<" "<<r.S<<"\n";
		}
		return 0;
	}
	if(ne.size()==0)
	{
		int v=po[0];
		for(int i=1;i<((int)po.size())-1;++i)
		{
			ans.push_back({v,po[i]});
			v-=po[i];
		}
		ans.push_back({po[po.size()-1],v});
		v=po[po.size()-1]-v;
		cout<<v<<"\n";
		for(auto r:ans)
		{
			cout<<r.F<<" "<<r.S<<"\n";
		}
		return 0;
	}
	int v1=po[0],v2=ne[0];
	for(int i=1;i<ne.size();++i)
	{
		ans.push_back({v1,ne[i]});
		v1-=ne[i];
	}
	for(int i=1;i<po.size();++i)
	{
		ans.push_back({v2,po[i]});
		v2-=po[i];
	}
	ans.push_back({v1,v2});
	v1-=v2;
	cout<<v1<<"\n";
	for(auto r:ans)
	{
		cout<<r.F<<" "<<r.S<<"\n";
	}
}

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

int main(){
    int N;
    int a[110];
    cin >>N;
    for (int i=0; i<N;i++){
        cin >> a[i] ;
    }

    sort(a, a+N, greater<int>());

    int Alice=0;
    int Bob=0;

    for(int i=0;i<N;i++){
        if(i%2==0){
            Alice= Alice +a[i];
        }
        if(i%2==1){
            Bob=Bob+a[i];
        }
    }

    cout << (Alice -Bob) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int N;
	scanf("%d", &N);
	int D[N][2], i, flag=0;
	for (i=0; i<N; i++){
		scanf("%d %d", &D[i][0], &D[i][1]);
	}
	for (i=2; i<N; i++){
		if (D[i][0]==D[i][1] && D[i-1][0]==D[i-1][1] && D[i-2][0]==D[i-2][1]){
			flag=1;
			break;
		}
	}
	if (flag) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 1660
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int a, b, c = 0, d, e;
	cin >> a;
	if (a/1000 == a / 100 - a / 1000 * 10  && a / 1000 == (a % 100 - a % 10) / 10 && a / 100 - a / 1000 * 10 == (a % 100 - a % 10) / 10) {
		cout << "Yes" << endl;
	}
	else if (a / 100 - a / 1000 * 10 == (a % 100 - a % 10) / 10 && a / 100 - a / 1000 * 10 == a % 10 && (a % 100 - a % 10) / 10 == a % 10) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	cin >> e;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main(){
    input!{
        k: u64,
        n: u64,
        a: [u64; n]
    }
    let mut sub: Vec<u64> = vec![0; n as usize];
    for i in 0..n-1 {
        sub[i as usize] = a[(i+1) as usize] - a[i as usize];
    }
    sub[(n-1) as usize] = k - a[(n-1) as usize] + a[0];
    let m = sub.iter().fold(0, |max, a| if max < *a {*a} else {max});
    print!("{}", sub.iter().fold(0, |sum, a| sum + *a) - m);
}


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

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

    int a = 1;
    rep(i, n) a = min(a * 2, a + k);

    cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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 (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int r,c; cin >> r >> c;
    vector<vector<int>> v(r+1,vector<int>(c+1,0));
    int all = 0;
    rep(i,r) {
        int sum = 0;
        rep(j,c) {
            cin >> v[i][j];
            sum += v[i][j];

        }
        v[i][c] += sum;
        all += sum;
    }
    rep(j,c) {
        int sum = 0;
        rep(i,r) {
            sum += v[i][j];
        }
        v[r][j] = sum;
    }
    v[r][c] = all;
    rep(i,r+1) {
        rep(j,c+1) {
            if (j) {
                cout << " ";
            }
            cout << v[i][j];
        }
        cout << "\n";
    }
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 3e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

ll rbits[MAXN][62];

int main() 
{
    fastio();

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

    for(int i=n-1;i>=0;i--)
    {
        for(int b=60;b>=0;b--)
        {
            if( i < n-1 )
                rbits[i][b] = rbits[i+1][b];
            if( (a[i]>>b)&1 )
                rbits[i][b]++;
        }
    }

    ll ans = 0;
    for(int b=60;b>=0;b--)
    {
        ll mul = mod(1ll<<b);
        for(int i=0;i<n-1;i++)
        {
            ll add = 0;
            if( (a[i]>>b)&1 )
            {
                add = n-1-i-rbits[i+1][b];
            }
            else
            {
                add = rbits[i+1][b];
            }
            add = mod( add );
            add = mod( add * mul );
            ans = mod( ans + add );
        }
        // cout<<b<<" "<<ans,nl;
    }
    cout<<ans,nl;

    return 0;
}

Measured memory_bytes: 147968
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n-- > 0) {
            String snake = sc.next();
            if (snake.indexOf('#') > 0 && snake.length() > 4 && snake.charAt(0) == '>' && snake.charAt(1) == '\'' && snake.charAt(snake.length() - 1) == '~') {
                int count = 0;
                for (int i = 2, j = snake.length() / 2 + 1; i < snake.length() / 2; i++, j++) {
                    if (snake.charAt(i) == '=' && snake.charAt(j) == '=') {
                        count += 2;
                    }
                }
                if (count == snake.length() - 4) {
                    System.out.println("A");
                } else {
                    System.out.println("NA");
                }
            } else if (snake.charAt(0) == '>' && snake.length() > 4 && snake.charAt(1) == '^' && snake.charAt(snake.length() - 2) == '~' && snake.charAt(snake.length() - 1) == '~' && snake.replaceAll("Q=", "").equals(">^~~")) {
                System.out.println("B");
            } else {
                System.out.println("NA");
            }
        }
    }
}



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

int main()
{
    long long int l,r,c,i,m=2019,j;
    cin>>l>>r;
if(r>l+2019)
   r=l+2019;
    for(j=l;j<r;j++)
    {

    for(i=l+1;i<=r;i++)
    {
    c=((j*i)%2019);

    if(c<m)
        m=c;

    }
    }
    cout<<m<<endl;


    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <math.h>
#include <random>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
 
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> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;
   
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

int n;
vector<string> res;

void dfs(int k,string s,char maxc){
  if(k == n){
    res.emplace_back(s);
    return;
  }
  for(char c = 'a'; c <= maxc + 1 && c - 'a' <= k; ++c){
    dfs(k+1,s + string(1,c),max(maxc,c));
  }
  return;
}

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

  cin >> n;
  dfs(0,"",'a');

  sort(all(res));

  for(auto e : res){
    cout << e << '\n';
  }

  return 0;
}

Measured memory_bytes: 7796
module.exports=function(r){var e={};function t(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=r,t.c=e,t.d=function(r,e,n){t.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,e){if(1&e&&(r=t(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var o in r)t.d(n,o,function(e){return r[e]}.bind(null,o));return n},t.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(e,"a",e),e},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.p="",t(t.s=0)}([function(r,e,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(r,e){r.exports=function(r){var e=Number(r[0]),t=r[1].split(" ").map(function(r){return Number(r)}),n=r[2].split(" ").map(function(r){return Number(r)}),o=r[3].split(" ").map(function(r){return Number(r)});t.sort(function(r,e){return r-e}),n.sort(function(r,e){return r-e});for(var u=new Array(e),f=0;f<e;f++){for(var i=-1,a=e;Math.abs(i-a)>1;){var l=Math.floor((i+a)/2);t[l]<n[f]?i=l:a=l}u[f]=i+1,f>0&&(u[f]+=u[f-1])}for(var c=0,p=0;p<e;p++){for(var s=-1,d=e;Math.abs(s-d)>1;){var b=Math.floor((s+d)/2);n[b]<o[p]?s=b:d=b}s>=0&&(c+=u[s])}console.log(c)}},function(r,e){r.exports=require("fs")}]);

Measured memory_bytes: 56324
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main(){
	FIO
	
	int a, b;
	cin >> a >> b;
	if(a + b >= 10)puts("error");
	else cout << a + b << '\n';
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const dft = -1

var match = [9]int{2, 5, 5, 4, 5, 6, 3, 7, 6}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	a := make([]int, m)
	for i := range a {
		fmt.Scan(&a[i])
	}

	dp := make([]int, n+1)
	for i := range dp {
		dp[i] = dft
	}
	dp[0] = 0

	for i := range dp {
		if dp[i] == dft {
			continue
		}
		for _, v := range a {
			mv := match[v-1]
			if i+mv > n {
				continue
			}
			if dp[i+mv] == dft || dp[i]+1 > dp[i+mv] {
				dp[i+mv] = dp[i] + 1
			}
		}
	}

	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	wr := bufio.NewWriter(os.Stdout)
	for i := n; i > 0; {
		for _, v := range a {
			mv := match[v-1]
			if i-mv >= 0 && dp[i-mv] == dp[i]-1 {
				wr.WriteString(strconv.Itoa(v))
				i -= mv
				break
			}
		}
	}
	wr.WriteString("\n")
	wr.Flush()
}


Measured memory_bytes: 640
#include<stdio.h>
#include<cstdlib>
#include<cstring>

struct Node{
	int key;
	Node *prev, *next;
};

Node *nil;

void init () {
	nil = (Node*)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}
void end () {
	free(nil);
}

void insert (int key) {
	Node *p = (Node*)malloc(sizeof(Node));
	p->key = key;
	p->next = nil->next;
	nil->next->prev = p;
	nil->next = p;
	p->prev = nil;
}

void deleteNode (Node *p) {
	if (p == nil) {
		return;
	}
	p->prev->next = p->next;
	p->next->prev = p->prev;
	free(p);
}
void deleteKey (int key) {
	Node *p = nil->next;
	while(p != nil && p->key != key) {
		p = p->next;
	}
	if (p->key == key) {
		deleteNode(p);
	}
}

void deleteFirst () {
	deleteNode(nil->next);
}

void deleteLast () {
	deleteNode(nil->prev);
}

void printList () {
	Node *p = nil->next;
	bool isFirst = true;
	while (p != nil) {
		if (!isFirst) {
			printf(" ");
		}
		isFirst = false;
		printf("%d", p->key);
		p = p->next;
	}
	printf("\n");
}

int main () {
	int num = 0, key;
	char com[20];
	scanf("%d", &num);
	init();
	for (int i=0; i<num; i++) {
		scanf("%s%d", &com, &key);
		if (com[0] == 'i') {
			insert(key);
		} else if (strlen(com) > 6) {
			if (com[6] == 'F') {
				deleteFirst();
			} else {
				deleteLast();
			}
		} else {
			deleteKey(key);
		}
	}
	printList();
	end();
	return 0;
}


Measured memory_bytes: 33940
#include <stdio.h>

#define M 2000001
#define N 10000
int A[M],B[M];
//CountingSort(A, B, k)
int main(){
  int C[N];
  int i,n,j;
  scanf("%d",&n);
  for(i=0;i<=N;i++) C[i]=0;
  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
    C[A[i + 1]]++;
  }
  for(i=1;i<=N;i++){
    C[i]=C[i]+C[i-1];
  }

  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(i=1;i<=n;i++){
    if(i>1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 16264
#include <stdio.h>
int main(){
	int n;
	int a;
	1<n<10000;
	0<a<1000;
	scanf("%d",&n);
	scanf("%d",&a);
	if (n%500 <=a){
		printf("Yes");
		}else{
			printf("No");
		}return 0;
	}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        int[] box = SpIntRead(' ');
        Console.WriteLine(box[0] * box[1] - (box[1] + box[0]) + 1);
    }

}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static long LCM(long a, long b)
    {
        long c = a * b;
        if (a < b) Swap(ref a, ref b);
        long d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static int[] SpIntRead(char c)
    {
        return Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
    }
    public static string ToConvertBit(int N, int e)
    {
        string ret = "";
        int r = 0;
        while (N != 0)
        {
            r = N % e;
            ret += r.ToString();
            N -= r;
            N /= e;
        }
        ret = strReverce(ret);
        return ret;
    }

}


Measured memory_bytes: 13268
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  string s1;
  cin>>s1;
  string s;
  rep(i,0,s1.sz-1){
    if(s1[i]=='B'&&s1[i+1]=='C'){
      s += "D";
      i++;
    }
    else{
      s += s1[i];
    }
  }
  ll c = 0;
  ll ans = 0;
  rep(i,0,s.sz){
    if(s[i]=='A'){
      c++;
    }
    else if(s[i]=='D'){
      ans += c;
    }
    else{
      c = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  string s;
   cin>>s;
   int ans=s.size();
   for(int i=0;i<s.size();i++){
       if(s[i]==s[i+1]){
           ans--;
           i+=2;
       }
   }
   cout<<ans<<endl;
  return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

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

const int64 mod = 1e9+7;

int main(void){
	int32 n;
	while(cin >> n && n){
		vector<int32> x(n);
		int32 sum = 0;
		REP(i, n){
			cin >> x[i];
			sum += x[i];
		}
		cout << (sum-*(max_element(all(x)))-*min_element(all(x)))/(n-2) << endl;
	}
}


Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    bool a=false;
    cin >> S;
    for(int i=0;i<3;i++){
        if(S.at(i)=='7'){
            a=true;
        }
    }
    if(a==false){
        cout << "No";
    } else {
        cout << "Yes";
    }
    return 0;
}

Measured memory_bytes: 3628
/***********************************************************
	When you are inspired by passion 
	and you want to live for the current moment

	When your every thought and action
	has the power to become the story of your future

	When difficulties stand to demolish your Glory
	Just remember that Life is a 'Golden adverse Story'

	Withstand it to acheive your passion and dreams
	more amazingly more easily.

	Why then? When writing the story of your Life
	You want to Let someone else hold your pen

					huzaifa242©

***********************************************************/
#include "bits/stdc++.h"
using namespace std;
#define int int32_t
#define MAX 100005
#define x first 
#define y second

int seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = numeric_limits <int>::max())
{return uniform_int_distribution<int> (l, r)(rng);}

template <typename T, typename G>
ostream& operator << (ostream& out, const pair <T, G> &a) 
{return out << "( " << a.x << ", " << a.y << ")";}

template <typename T>
ostream& operator << (ostream& out, const vector <T> &a) 
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

template <typename T>
ostream& operator << (ostream& out, const set <T> &a) 
{out << "{ "; for(const auto &i: a) out << i << ", "; return out << "}" << endl;}

template <typename T, typename G>
ostream& operator << (ostream& out, const map <T, G> &a) 
{out << "< "; for(const auto &i: a) out << i << ", "; return out << ">" << endl;}

template <typename T, size_t N>
typename enable_if<!is_same <typename remove_cv <T>::type, char>::value,
ostream&>::type operator << (ostream& out, T (&a)[N])
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

void debug_out(){cerr << endl;} 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{cerr << (H) << ' '; debug_out(T...);}
 
#ifdef LOCAL
#define debug(...) cerr << '#' << #__VA_ARGS__ << ":\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 24
#endif

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2] && s[2] == 'R') {
		cout << "3\n";
	} else if (s[0] == s[1] && s[1] == 'R') {
		cout << "2\n";
	} else if (s[1] == s[2] && s[2] == 'R') {
		cout << "2\n";
	} else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
		cout << "1\n";
	} else {
		cout << "0\n";
	}
	return 0;
}


Measured memory_bytes: 3656
n, m, l = map(int, input().split())
A = []
B = []
C = []

for i in range(n):
    a = list(map(int, input().split()))
    A.append(a)

for i in range(m):
    b = list(map(int, input().split()))
    B.append(b)

trans_B = [x for x in zip(*B)]

for i in A:
    c = []
    for j in trans_B:
        tmp = 0
        for k, l in zip(i, j):
            tmp += k * l
        c.append(tmp)
    C.append(c)

for i in C:
    print(*i)


Measured memory_bytes: 7144
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int (i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int (i) = (int)(initial); (i) < (int)(n); ++(i))
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int (i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int (i) = (int)(initial); (i) > (int)(n); (i)--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define variable
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
	vector< pair<ll, ll> > p;
	for(ll i = 2; i*i <= n; i++) {
		if ((n % i) != 0) continue;
		p.push_back(make_pair(i, 0));
		while((n % i) == 0) {
			n /= i;
			p[i].second += 1;
		}
		p.push_back(make_pair(n, 0));
	}

	if (n != 1) p.push_back(make_pair(n, 1));
	return p;
}

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

	int a, b;
	map<int, vector<int> >m;
	repeat(i, M) {
		cin >> a >> b;
		m[a].push_back(b);
	}

	string result = "POSSIBLE";
	int pos = 1;
	for(int j = 0; j < m[1].size(); j++) {
		if (pos == m[1][j]) continue;
		pos = m[1][j];

		for(int k = 0; k < m[pos].size(); k++) {
			if (pos == m[pos][k]) continue;

			if (N == m[pos][k]) {
				cout << result << endl;
				return 0;
			}
		}
	}

	result = "IMPOSSIBLE";
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 19320
import java.util.*;

public class Main{
	public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
    int cnt = 0;
		int[] num = new int[n];

		for(int i=0; i< n;i++) {
			num[i] = sc.nextInt();
		}
    int m = sc.nextInt();
		for(int i = 0;i<m;i++) {
			int a = sc.nextInt();
			if (Arrays.binarySearch(num, a) > -1)
				cnt++;
		}
		System.out.println(cnt);
  }
}


Measured memory_bytes: 69368
package main

import (
    "fmt"
    "os"
)

func main() {

    var num int
    fmt.Fscanf(os.Stdin, "%d", &num)
    ans := -1
    for i := 0; i < num; i++ {
        var v int
        fmt.Fscanf(os.Stdin, "%d", &v)
        count := 0
        for v%2 == 0 {
            count++
            v /= 2
        }

        if count == 0 {
            ans = 0
            break
        }
        if ans == -1 {
            ans = count
        } else {
            if count < ans {
                ans = count
            }
        }
    }
    fmt.Printf("%v\n", ans)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    ll a,b,c,d; cin >> a>>b>>c>>d;
    ll s=a*c,t=b*d,u=a*d,v=b*c;
    AA(max(s,max(t,max(u,v))));
    return 0;
}

Measured memory_bytes: 3632
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
num = 0
for i in range(N):
    a = list(map(int, input().split()))
    tmp = 0
    for j in range(M):
        tmp += B[j] * a[j]
    if tmp + C > 0:
        num += 1

print(num)




Measured memory_bytes: 3064
#include<stdio.h>
   
#define N 8
#define free -1
#define notfree 1
#define FALSE 2
#define TRUE 3
   
int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
int X[N][N];
   
void initialize(void);
void printboard(void);
void recursive(int);
   
void initialize(){
  int i;
   
  for(i=0;i<N;i++){
    row[i] = free;
    col[i] = free;
  }
   
  for(i=0;i<2*N-1;i++){
    dpos[i] = free;
    dneg[i] = free;
  }
}
   
void printboard(){
  int i,j;
   
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j] == TRUE){
    if(row[i] != j)return;
      }
    }
  }
   
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i] == j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}
   
void recursive(int i){
  int j;
   
  if(i == N){
    printboard();
    return;
  }
   
  for(j=0;j<N;j++){
    if(notfree == col[j] || notfree == dpos[i+j] || notfree == dneg[i-j+N-1])continue;
    row[i] =j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = notfree;
    recursive(i+1);
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = free;
  }
}
int main(){
  int i,j,k,r,c;
   
  initialize();
   
  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      X[i][j] = FALSE;
   
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d %d",&r,&c);
    X[r][c] = TRUE;
  }
   
  recursive(0);
   
  return 0;
}

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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;


struct edge { int to, cost; };
vector<vector<edge>> g;
vector<int> dist;

bool shortest_path(int s){
	int N = g.size();
	dist.assign(N, INF);
	dist[s] = 0;

	bool negative_cycle = false;

	for (int i = 0; i < N; i++){
		for (int v = 0; v < N; v++){
			for (edge e : g[v]){

				if (dist[v] != INF && dist[e.to] > dist[v] + e.cost){
					dist[e.to] = dist[v] + e.cost;
					// n回目にもN-1に更新があれば、N-1にいたる途中に負サイクルあり
					if (i == N - 1 && e.to==N-1){
						dist[e.to] = -INF;
						negative_cycle = true;
					}
				}
			}
		}
	}
	return negative_cycle;
}

signed main(){

	int V, E;
	cin >> V >> E;
	g.assign(V, vector<edge>());
	for (int i = 0; i < E; i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back(edge{ b, -c });
	}
	bool negative_cycle = shortest_path(0);

	if (negative_cycle){
		cout << "inf" << endl;
	}
	else{
		cout << -dist[V - 1] << endl;
	}


	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void) 
{
    int n,a, i, min, max ;
    long goukei = 0;
    
    scanf("%d", &a);
    scanf("%d", &n);
    
    min = goukei=max=n;
    
    for (i = 1;i<a ;i++) 
    {
        scanf("%d", &n);

        goukei = goukei + n;

        if (min > n)
        {
            min = n;
        }
        else
        {
            if (max < n)
            {
                max = n;
            }
        }
    }
    printf("%d %d %ld\n", min, max, goukei);

    return 0;
}



Measured memory_bytes: 2104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String[] inputs = input.readLine().split(" ");
        int N = Integer.parseInt(inputs[0]);
        int K = Integer.parseInt(inputs[1]);
        long answer = K;
        for (int i = 1; i < N; i++) {

            answer = answer * (K - 1);
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 21332