akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>

using namespace std;

int a[30];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int tmp;
      cin >> tmp;
      tmp--;
      a[tmp]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (a[i] == n)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int count=1;
  int N;
  cin>>N;
  vector<int>vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  int j=0;
  bool frag=true;
  while(frag==true){
    int m=vec.at(j);
    if(m==2){
      cout<<count<<endl;
      frag=false;
    }
    else if(m==0){
      cout<<-1<<endl;
      frag=false;
    }
    else{
      count=count+1;
      vec.at(j)=0;
      j=m-1;
    }
  }
}
      

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int, int> P;
const int INF = 1000000000;
struct edge { int to, cost; };
int V, E, r;
int d[100100];
vector<edge> G[100100];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push({0, s});

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (edge e: G[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push({d[e.to], e.to});
            }
        } 
    }
}

int main() {
    cin >> V >> E >> r;
    for (int i = 0; i < E; i++) {
        int s, t, d; cin >> s >> t >> d;
        G[s].push_back({t, d});
    }
    dijkstra(r);
    for (int i = 0; i < V; i++) {
        if (d[i] == INF) cout << "INF" << endl;
        else cout << d[i] << endl;
    }
}


Measured memory_bytes: 13016
#include<bits/stdc++.h>
using namespace std;
int s[999], k[9999], n, m, t, p, i, j;
main(){while(true){t=0;p=0;cin>>n>>m;if(n==-1){break;}
while(t<m){n++;if(n<2){goto E;}for(i=2;i*i<=n;i++){if(n%i==0){goto E;}}s[t]=n;t++;E:;}
for(i=0;i<m;i++){for(j=i;j<m;j++){k[p]=s[j]+s[i];p++;}}sort(k,k+p);cout<<k[m-1]<<endl;}}

Measured memory_bytes: 1200
//#pragma region ALL(include define etc)
#include <iostream>   // swap(a, b)
#include <string>
#include <cmath>      // abs(絶対値) sin cos tan(角度 / 180.0 * 3.141592)
#include <vector>     // vec.push_back(a) vec.pop_back()
#include <algorithm>  // max(a, b) min(a, b) reverse() sort()
#include <functional> // sort(a, a + N, greater<型>());
#include <math.h>
#include <iomanip>
#define int long long
#define ll long long
//#define double long double
using namespace std;
//#pragma endregion

signed main()
{
	//int x;

	//int h1, h2, m1, m2, k;
	//int box, box1,box2;

	//int N;
	//int n;
	int a, b;
	//int m;
	//int k;
	//string s;
	//string t;
	//int m1, m2;
	//int a, b, c, k;

	//long double aaa;

	//int k, d;
	int all = 0;
	//double all;
	//double a, b;
	//double h, m;
	//int a[30000] = { 0 };
	//double c, d, e;

	//double mbox, hbox;
	//double box, box2;

	//int b = 0;

	//int box[10000] = { 0 };

	//bool flag = true;

	//string str;

	//cin >> h1 >> m1 >> h2 >> m2 >> k;
	cin >> a >> b;

	all = a * b;

	//n = t.length();
	
	//cout << b << "\n";
	/*for (int i = 0; i < n; i++)
	{
		if (t[i] == '?')
		{
			t[i] = 'D';
		}
	}*/

	/*if (flag == true)
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}*/

	cout << all << "\n";

	//cout << fixed << setprecision(111) << all;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define int long long int
#define double long double
#define endl "\n"
#define sz(x) (int)x.size()
using namespace std;

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

  string s;
  cin>>s;

  int i=(int)s.size()-1;

  if(s[i]=='2' or s[i]=='4' or s[i]=='5' or s[i]=='7' or s[i]=='9') {
    cout<<"hon";
  } else if(s[i]=='0' or s[i]=='1' or s[i]=='6' or s[i]=='8') {
    cout<<"pon";
  } else {
    cout<<"bon";
  }

}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  LL N, M, ans =0;
  cin>>N>>M;

  LL x = min(N, M/2);
  ans += x;
  N-=x;
  M-=x*2;
  ans += M/4;
  cout<<ans<<endl;




  return 0;
}


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

vector<vector<double> > A;
vector<double> B;

void gauss_jordan(){
    for(int i=0;i<A.size();i++){
        B[i] /= A[i][i];
        double aii = A[i][i];
        for(int j=i;j<A.size();j++)
            A[i][j] /= aii;
        for(int j=0;j<A.size();j++){
            if(j == i) continue;
            B[j] -= A[j][i] * B[i];
            double aji = A[j][i];
            for(int k=i;k<A.size();k++)
                A[j][k] -= aji * A[i][k];
        }
    }
}


int main(){
    double a[2][2] = {0}, b[2] = {0};
    while(scanf("%lf %lf %lf %lf %lf %lf", &a[0][0], &a[0][1], &b[0], &a[1][0], &a[1][1], &b[1]) != EOF){
        A.clear();
        B.clear();
        A.resize(2);
        for(int i=0;i<2;++i){
            for(int j=0;j<2;++j){
                A[i].push_back(a[i][j]);
            }
            B.push_back(b[i]);
        }
        gauss_jordan();
        printf("%.3f %.3f\n", B[0], B[1]);
    }

    return 0;
}


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

using namespace std;

using ll = long long;

ll f(const ll &x) {
    ll ans;
    switch(x%4) {
        case 0:
            ans = x;
            break;
        case 1:
            ans = 1;
            break;
        case 2:
            ans = x+1;
            break;
        case 3:
            ans = 0;
            break;
        default:
            break;
    }
    return ans;
}

void getXor(const ll &a, const ll &b) {
     cout << (f(a - 1) ^ f(b)) << endl;
}

int main(){
    ll a, b;
    cin >> a >> b;
    getXor(a, b);
    return 0;
}


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

using namespace std;

int main() {
    int d, t, s;
    scanf("%d%d%d", &d, &t, &s);
    int division = d / s;
    int rest = d % s;
    if (division < t || division == t && rest == 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
}


Measured memory_bytes: 3688
#include<iostream>
using namespace std;
int  main(){
	int x,y,z,v,n,i,j,l,k,math[4][3][10]={0};
	cin>>n;
	for(k=0;k<n;k++){
	cin>>x>>y>>z>>v;
	math[x-1][y-1][z-1]+=v;
	}
	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(l=0;l<10;l++){
			cout<<" "<<math[i][j][l];
			}
			cout<<endl;
		}
		if(i==3){
		break;
		}
		cout<<"####################"<<endl;
	}
return 0;
}

Measured memory_bytes: 3052
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int M = 200;
bool N[201];
void can_buy(){
  for(int i=0;i<=M;i++) N[i] = false;

  for(int i=0;i<=M;i+=4){
    for(int j=0;i+j<=M;j+=7){
      N[i+j] = true;
    }
  }

}

int main(){
  can_buy();
  int n;
  cin >> n;
  
  if(N[n]) cout << "Yes" <<endl;
  else cout << "No" <<endl;

  return 0;
}

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

int main()
{
  int a, count_5 = 0, count_7 = 0;
  for (int i = 0; i < 3; i++)
  {
    cin >> a;
    if (a == 5)
      count_5++;
    else if (a == 7)
      count_7++;
    else
      break;
  }
  cout << ((count_5 == 2 && count_7 == 1) ? "YES" : "NO") << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
typedef long long lint;
using namespace std;

// input N


int main()
{
	int H,W;
	cin>>H>>W;
	int h,w;
	cin>>h>>w;

	int ans;
	ans = (H-h) * (W-w);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  string s; cin>>s;
  int n = s.size();
  ll ans = 0;
  for(int bit=0; bit<(1<<(n-1)); ++bit){
    string ss = "";
    for (int i=0; i<n; ++i){
      ss += s[i];
      if (bit & (1<<i)){
        ans += stoll(ss);
        ss = "";
      }
    }
    ans += stoll(ss);
    ss = "";
  }
  cout << ans << endl;
}


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

int main(){
	int a=1,b=1,i,l;
	while((cin>>a>>b)&&(a!=0||b!=0)){
		for(i=1;i<=a;i++){
			for(l=1;l<=b;l++){
				cout<<"#";
			}
			cout <<endl;
		}
		cout <<endl;
	}
}

Measured memory_bytes: 1152
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007
#A
def A():
    t,x = LI()
    print(t/x)

#B
def B():
    n = I()
    a = LI()
    m = max(a)
    if m >= sum(a)-m:
        print("No")
    else:
        print("Yes")


#C
def C():
    n,m = LI()
    x = LI()
    x.sort()
    l = [x[i+1]-x[i] for i in range(m-1)]
    l.sort()
    l = l[::-1]
    ans = sum(l[max(n-1,0):])
    print(ans)

#D
def D():
    n,k = LI()
    a = LI()
    k = list(map(int,list(bin(k)[2:])))
    l = len(k)
    for i in range(n):
        a[i] = list(map(int,list(bin(a[i])[2:])))
        l = max(l,len(a[i]))
    for i in range(n):
        for j in range(l-len(a[i])):
            a[i].insert(0,0)
    for j in range(l-len(k)):
        k.insert(0,0)
    s = [[0,0] for i in range(l)]
    pow2 = [1 for i in range(l)]
    for i in range(l-1)[::-1]:
        pow2[i] = pow2[i+1]*2
    for i in a:
        for j in range(l):
            s[j][0] += pow2[j]*i[j]
            s[j][1] += pow2[j]*(not i[j])
    dp = [0 for i in range(l+1)]
    small = False
    for i in range(l):
        if not small:
            if not k[i]:
                dp[i+1] += dp[i]+s[i][0]
            else:
                if s[i][0] >= s[i][1]:
                    dp[i+1] += dp[i]+s[i][0]
                    small = True
                else:
                    dp[i+1] += dp[i]+s[i][1]
        else:
            dp[i+1] += dp[i]+max(s[i])
    print(dp[l])

#E
if __name__ == "__main__":
    C()

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


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

#define MAX_N 81

using namespace std;

typedef long long lint;

const int MX  = 80*160;
const int ADD = 80*160;

lint rez;

int n, m;
int a[MAX_N + 1][MAX_N + 1];

bool dp[MAX_N + 1][MAX_N + 1][MX * 2 + 2];

int x[MAX_N + 1][MAX_N + 1];
int y[MAX_N + 1][MAX_N + 1];

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
    {
        for(int j = 1; j <= m; j ++)
        {
            cin >> x[i][j];
        }
    }
    for(int i = 1; i <= n; i ++)
    {
        for(int j = 1; j <= m; j ++)
        {
            cin >> y[i][j];
        }
    }

    for(int i = 1; i <= n; i ++)
    {
        for(int j = 1; j <= m; j ++)
            a[i][j] = abs(x[i][j] - y[i][j]);
    }


    dp[n][m][ADD + a[n][m]] = 1;

    for(int i = n; i >= 1; i --)
    {
        for(int j = m; j >= 1; j --)
        {
            for(int h = -MX; h <= MX; h ++)
            {
                if(i + 1 <= n && dp[i + 1][j][ADD + h] == 1)
                {
                    int nxt = h - a[i][j];
                   // if(nxt <= MX)
                        dp[i][j][ADD + nxt] = 1;

                    nxt = h + a[i][j];
                    //if(nxt <= MX)
                        dp[i][j][ADD + nxt] = 1;


                }

                if(j + 1 <= m && dp[i][j + 1][ADD + h] == 1)
                {
                    int nxt = h - a[i][j];
                   // if(nxt <= MX)
                        dp[i][j][ADD + nxt] = 1;

                    nxt = h + a[i][j];
                   // if(nxt <= MX)
                        dp[i][j][ADD + nxt] = 1;

                }

            }
        }
    }

    int rez = (int)(1e9);
    for(int i = -MX; i <= MX; i ++)
    {
        if(dp[1][1][ADD + i] == 1)
        {
            rez = min(rez, abs(i));
           // break;
        }
    }

    cout << rez << "\n";

    return 0;
}


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

A=list(map(int,input().split()))
ans="APPROVED"
for i in range(n):
  if A[i]%2==0:
    if A[i]%3==0 or A[i]%5==0:
      ans="APPROVED"
    else:
      print("DENIED")
      exit()

print(ans)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int a[6];
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5];
  int flag = 1;
  for(int i=0;i<5;i++){
    for(int j=0;j<5;j++){
      if(abs(a[i]-a[j])>a[5]){
        flag = 0;
        break;
      }
    }
    if(!flag) break;
  }
  if(flag){
    cout << "Yay!";
  }else{
    cout << ":(";
  }
  return 0;
}

Measured memory_bytes: 256
data=[]
for i in range(int(input())):
    data.append(int(input()))
un=[num for num in data if num%10==0]
data=[num for num in data if num%10!=0]
if len(data)==0:
    print(0)
else:
    if sum(un+data)%10!=0:
        print(sum(un+data))
    else:
        print(sum(un+data)-min(data))

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n,k;cin >>n>>k;
    vector<ll>p(n);vector<ll>c(n);
    for (int i = 0; i < n; ++i){
        cin >>p[i];
        p[i]--;
    }
    for (int i = 0; i < n; ++i)cin >>c[i];
    vector<bool>used(n,false);
    vector<vector<ll>>ss;
    ll ans=-INFll;
    for (int i = 0; i < n; ++i) {
        if(used[i])continue;
        vector<ll>s;
        int now=i;
        while(!used[now]){
            s.push_back(c[now]);
            used[now]=true;
            now=p[now];
        }
        ss.push_back(s);
    }
    for(auto v:ss){
        ll loop=v.size();
        vector<ll>sum(2*loop+1,0);
        for (int i = 0; i <loop*2; ++i)sum[i+1]=sum[i]+v[i%loop];
        vector<ll>mx(loop,-INFll);
        for (int i = 0; i < loop; ++i) {
            for (int j = 0; j < loop; ++j) {
                mx[j]=max(mx[j],sum[i+j]-sum[i]);
            }
        }
//        for (int i = 0; i < loop; ++i) {
//            cout<<i<<" "<<mx[i]<<" ";
//        }
//        cout <<endl;
        for (int r = 0; r <loop; ++r) {
            if(r>k)continue;
            ll q=(k-r)/loop;
            if(r==0&&q==0)continue;
            if(sum[loop]>0)ans=max(ans,mx[r]+sum[loop]*q);
            else if(r>0)ans=max(ans,mx[r]);
        }
    }
    cout <<ans <<endl;
}


Measured memory_bytes: 3844
# 入力
H,W=map(int,input().split())

l=[]
for i in range(H):
    l.append(list(input()))

for i in range(H):
    for j in range(W):
    # 地雷数のカウンタ
        c=0

    # '#'の場合はなにもしない
        if l[i][j]=='#':
            pass

    # '#'以外の場合
        else:
      # 左上
            if 0<i and 0<j and l[i-1][j-1]=='#':
                c+=1
      # 上
            if 0<i and l[i-1][j]=='#':
                c+=1
      # 右上
            if 0<i and j<W-1 and l[i-1][j+1]=='#':
                c+=1
      # 左
            if 0<j and l[i][j-1]=='#':
                c+=1
      # 右
            if j<W-1 and l[i][j+1]=='#':
                c+=1
      # 左下
            if i<H-1 and 0<j and l[i+1][j-1]=='#':
                c+=1
      # 下
            if i<H-1 and l[i+1][j]=='#':
                c+=1
      # 右下
            if i<H-1 and j<W-1 and l[i+1][j+1]=='#':
                c+=1

      # 地雷隣接数を記載
            l[i][j]=str(c)

# 出力
for i in range(H):
    print(''.join(l[i]))

Measured memory_bytes: 3188
#define _CRT_SECURE_NO_WARNINGS
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

void sort(int[], int, int, int[]);

int main(void) {
#ifdef DEBUG
	printf("");
#endif

	int A, B, C;
	int five=0, seven = 0;

	scanf("%d %d %d", &A, &B, &C);

	if (A == 5) {
		five++;
	}
	else if (A == 7) {
		seven++;
	}
	if (B == 5) {
		five++;
	}
	else if (B == 7) {
		seven++;
	}
	if (C == 5) {
		five++;
	}
	else if (C == 7) {
		seven++;
	}

	if (five == 2 && seven == 1) {
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 128
package main

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

func main() {
	N := readi()
	X := readi()
	x := make([]int, N)
	for i := 0; i < N; i++ {
		x[i] = readi()
	}
	sort.Ints(x)

	ans := abs(X - x[0])
	for i := 1; i < N; i++ {
		tmp := abs(x[i] - x[i-1])
		ans = gcd(ans, tmp)
	}

	fmt.Println(ans)
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return (a * b) / gcd(a, b)
}

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func isPrime(n int) bool {
	if n == 1 {
		return false
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i*i != n {
				res = append(res, n/i)
			}
		}
	}
	sort.Ints(res)
	return
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7
)

var (
	readString func() string
)

func init() {
	readString = newReadString(os.Stdin)
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

func readi64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
    using namespace std;
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace __gnu_pbds; 
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
     
    #define ff first
    #define ss second
    #define sz size()
    #define mp make_pair
     
    #define pb push_back
    #define endl "\n"
     
    #define int long long int
    #define double long double
     
    #define bp __builtin_popcountll
    #define inf 1e17
    const int N=2e5+6;
    const int M=998244353;
    vector<int> v;
    signed main()
    {
        FAST
        int n;
        cin>>n;
        bool prime[3*n+3];
        memset(prime,true,sizeof(prime));
        for(int i=2;i<=3*n;i++)
        {
        	if(prime[i])
        	{
        		v.pb(i);
        		for(int j=i*i;j<=3*n;j+=i)
        		{
        			prime[j]=false;
        		}
        	}
        }
        int tt=lower_bound(v.begin(),v.end(),n)-v.begin();
        cout<<v[tt]<<endl;
    }


Measured memory_bytes: 896
n, k = map(int, input().split())
mod = 10 ** 9 + 7
from collections import deque

a = list(map(int, input().split()))
a.sort()
minus, zero, plus = 0, 0, 0
for i in range(n):
    if a[i] < 0:
        minus += 1
    elif a[i] == 0:
        zero += 1
    else:
        plus += 1

que = deque(a)

#ここを軽量化した
plus_flg = False
tmp = plus - k
if tmp >= 0:
    plus_flg = True
elif (-tmp <= minus and -tmp%2 == 0) or (-tmp < minus and plus >= 1):
    plus_flg = True

# plus可能
if plus_flg:
    ans = 1
    cnt = 0

    while cnt < k:
        if k - cnt >= 2:
            if que[0] * que[1] >= que[-1] * que[-2]:
                ans *= que.popleft()
                ans *= que.popleft()
                ans %= mod
                cnt += 2
            else:
                ans *= que.pop()
                ans %= mod
                cnt += 1
        else:
            ans *= que.pop()
            ans %= mod
            cnt += 1

    print(ans)



# zero
elif zero > 0:
    print(0)

# minus
else:
    a = [abs(a[i]) for i in range(n)]
    a.sort()
    ans = 1
    for i in range(k):
        ans *= a[i]
        ans %= mod
    ans = -ans % mod
    print(ans)


Measured memory_bytes: 32208
import functools
N,Y = map(int,input().split())

ans = [-1,-1,-1]
for man in range(0,N+1):
    for gosen in range(0,N-man+1):
        if(Y == man * 10000 + gosen * 5000 + (N-man-gosen)*1000):
            ans = [man,gosen,N-man-gosen]
print(functools.reduce(lambda x,y:str(x)+" "+str(y),ans))


Measured memory_bytes: 3572
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int get() { int r; cin >> r; return r; }
void solve() {
	double x[5], y[5], xs, ys, xt, yt;
	cin >> x[1] >> y[1] >> x[2] >> y[2] >> x[0] >> y[0] >> xs >> ys >> xt >> yt;
	int i1 = 1, i2 = 1, a = 1, b = 2, c = 0;
	for1(i, 3) {
		if (((x[a] - x[b]) * (ys - y[a]) - (y[a] - y[b]) * (xs - x[a])) * ((x[a] - x[b]) * (y[c] - y[a]) - (y[a] - y[b]) * (x[c] - x[a])) < 0)i1 = 0;
		if (((x[a] - x[b]) * (yt - y[a]) - (y[a] - y[b]) * (xt - x[a])) * ((x[a] - x[b]) * (y[c] - y[a]) - (y[a] - y[b]) * (x[c] - x[a])) < 0)i2 = 0;
		a++; b++; c++;
		if (a >= 3)a %= 3;
		if (b >= 3)b %= 3;
		if (c >= 3)c %= 3;
	}
	cout << (i1 + i2 == 1 ? "OK\n" : "NG\n");
}
signed main() {
	int n; cin >> n; for1(i, n)solve();
}


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


int main(){
    string s;cin>>s;
    ll countb = 0;
    ll ans = 0;
    int n = s.size();
    for(int i = 0;i<n;++i){
        if(s[i]=='W') {
            ans+=countb;
        }

        else {
            countb++;
        }

    }
    cout<<ans<<endl;

}


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

int main(){
  int A,B,H,M;
  cin >> A >> B >> H >> M;
  
  double a_hari;
  a_hari = 30 * H + 0.5*M;
  double b_hari;
  b_hari = 6 *M;
   //角度を求める
  double kakudo;
  if(a_hari>=b_hari){
    kakudo = a_hari - b_hari;
  }else{
     kakudo = b_hari - a_hari;
  }
  if(kakudo >=180){
    kakudo = 360 -kakudo;
  }
   //cout << kakudo << endl;
  kakudo = kakudo * (M_PI /180);
  double c = cos(kakudo);
  //cout << c << endl;
  
  //長さを求める
  double ans;
  ans = A*A + B*B -(2*A*B*c);
  ans=sqrt(ans);
  printf("%.16f",ans);
}

Measured memory_bytes: 4200
def gcd(x,y):
    while y!=0:
        x,y=y,x%y
    return x
def lcm(x,y):
    return (x*y)//gcd(x,y)
n=int(input())
t=int(input())
for i in range(n-1):
    t=lcm(t,int(input()))
print(t)

Measured memory_bytes: 2940
S = input()
l = [0] * (len(S)+1)
r = [0] * (len(S)+1)
for i in range(len(S)):
    if S[i] == '<':
        l[i+1] = l[i] + 1
for i in range(len(S)-1,-1,-1):
    if S[i] == '>':
        r[i] = r[i+1] + 1
print(sum([max(l[i],r[i]) for i in range(len(S)+1)]))


Measured memory_bytes: 116456
n=int(input())
v=[[] for _ in range(n)]
for i in range(n):
  x,l=map(int,input().split())
  v[i]=[x-l,x+l]
v.sort(key=lambda x: (x[1], x[0]))
ans=n
r=v[0][1]
for i in range(1,n):
  l=v[i][0]
  if r>l:
    ans-=1
  else:
    r=v[i][1]


print(ans)

Measured memory_bytes: 27620
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;
#define ALL(x)			(x).begin(),(x).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF				(int)2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<ll, string>	P;
typedef vector<ll>		VLL;
typedef vector<VLL>		VVLL;
typedef vector<VVLL>	VVVLL;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;
	vector<int> X(N);
	REP(i, N) cin >> X[i];

	vector<int> ans(100, 0);
	REP(i, 100) {
		int ansOne = 0;
		REP(j, N) {
			int dif = X[j] - (i + 1);
			ansOne += dif * dif;
		}
		ans[i] = ansOne;
	} 
	sort(ALL(ans));
	cout << ans[0] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
#define debug(x) cerr << x << endl
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1<<30;
const ll LINF = 1LL<<61;
const ll MOD = 1000000007;

int main()
{
    int s;
    cin >> s;
    vector<ll> dp(s+1), c(s+1);
    dp[0] = 1;
    rep(i,s+1)
    {
        if(i > 0)
        {
            c[i] += c[i-1];
        }
        if(i - 3 >= 0)
        {
            c[i] += dp[i-3];
            c[i] %= MOD;
        }
        dp[i] += c[i];
        dp[i] %= MOD;
    }
    cout << dp[s] % MOD << endl;
}


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

int main(){
  int N;cin>>N;
  vector<int> A(N);
  vector<int> B(1000010,0);
  set<int> S;
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    B.at(A.at(i))++;
    S.insert(A.at(i));
  }
  vector<bool> flag(1000010,false);
  for(int i:S){
    for(int j=2;j<1000001;j++){
      if(i*j>=1000001) break;
      flag.at(i*j)=true;
    }
  }
  int ans=0;
  for(int i=0;i<N;i++){
    if(B.at(A.at(i))==1 && !flag.at(A.at(i))) ans++;
  }
  cout<<ans<<"\n";
}


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

typedef long long ll;

#define pb push_back
#define ft first
#define sd second
#define all(x) begin((x)), end((x))
#define forn(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define isz(x) (int)(x).size()
/* <-------------------> */

int a[103];

void solve() {
    int n;
    cin >> n;
    forn (i, n) cin >> a[i];
    int ans = 0;
    for (int i = 0; i < n; ) {
        int j = i;
        while (j + 1 < n && a[i] == a[j + 1]) ++j;
        ans += (j - i + 1) / 2;
        i = j + 1;
    }
    cout << ans;
}

/* <-------------------> */
// #define LOCAL
int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
}


Measured memory_bytes: 256
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

#define MOD 1000000007
#define N 2000005 //size of array

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

void com_init()
{
  fac[0] = 1;
  fac[1] = 1;
  finv[0] = 1;
  finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < N; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long combination(int a, int b)
{
  if (a < b)
    return 0;
  if (a < 0 || b < 0)
    return 0;
  return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main() {
  int r1, r2, c1, c2;
  scanf("%d %d %d %d", &r1, &c1, &r2, &c2);
  com_init();
  long ans = 0;
  for (int i=r1; i<=r2; i++) {
    ans += combination(i+c2+1, c2);
    ans %= MOD;
    ans -= combination(i+c1, c1-1);
    ans %= MOD;
  }
  if (ans < 0) ans += MOD;
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 46976
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;
bool isPal(string s) {
  int n = s.length();
  REP(i, n / 2) {
	if (s[i] != s[n - 1 - i]) {
		return false;
	  }
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.length();
  if (isPal(s) && isPal(s.substr(0, (n - 1) / 2)) && isPal(s.substr((n + 1) / 2, (n - 1) / 2))) {
	  cout << "Yes" << endl;
	} else {
	  cout << "No" << endl;
	}
  return 0;
}


Measured memory_bytes: 256
al = [0] * 26

while True:
    try:
        s = input()
        for i in s:
            if i.isalpha():
                al[ord(i.lower()) - ord("a")] += 1
    except EOFError:
        break
    
for i in range(ord("a"),ord("a")+26):
    print("{0} : {1}".format(chr(i),al[i - ord("a")]))


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

#define ll long long
#define pb push_back

void solve()
{
    int n,k;
    cin >> n >>k;
    ll sum=0;
    int cnt[n];
    for(int i=0;i<n;i++)
        cin >>cnt[i];
    sort(cnt,cnt+n);
    for(int i=0;i<k;i++)
        sum+=cnt[i];

    cout << sum << "\n";
}

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

    int tt=1;
    ///cin >> tt;
    while(tt--)
        solve();
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int a[101010];

main(){
	int s;
	int n;
	scanf("%d%d",&s,&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	int oddcnt=0;
	for(int i=0;i<n;i++)if(a[i]%2==1)oddcnt++;
	if(oddcnt>=3){
		puts("Impossible");
	}else{
		if(s==1){
			printf("1\n1\n1\n");
		}else if(n==1){
			printf("%d\n%d\n%d %d\n",a[0],2,a[0]-1,1);
		}else{
			vector<int> ev,od;
			for(int i=0;i<n;i++){
				if(a[i]%2==0)ev.push_back(a[i]); else od.push_back(a[i]);
			}

			vector<int> ans0,ans1;
			if(oddcnt==0){
				ans0=ev;
				ans1.push_back(ev[0]-1);
				for(int i=1;i<ev.size();i++)ans1.push_back(ev[i]);
				ans1.push_back(1);
			}
			if(oddcnt==1){
				ans0=ev;ans0.push_back(od[0]);
				ans1.push_back(ev[0]-1);
				for(int i=1;i<ev.size();i++)ans1.push_back(ev[i]);
				ans1.push_back(2);
				if(od[0]>1)ans1.push_back(od[0]-1);
			}
			if(oddcnt==2){
				ans0.push_back(od[0]);
				for(int i=0;i<ev.size();i++)ans0.push_back(ev[i]);
				ans0.push_back(od[1]);
				if(od[0]>1)ans1.push_back(od[0]-1);
				ans1.push_back(2);
				for(int i=0;i<ev.size();i++)ans1.push_back(ev[i]);
				if(od[1]>1)ans1.push_back(od[1]-1);
			}
			
			for(int i=0;i<ans0.size();i++){
				if(i>0)printf(" ");
				printf("%d",ans0[i]);
			}
			puts("");
			printf("%d\n",ans1.size());
			for(int i=0;i<ans1.size();i++){
				if(i>0)printf(" ");
				printf("%d",ans1[i]);
			}
			puts("");
		}
	}
}

Measured memory_bytes: 256
from copy import copy
def gcd(a, b):
	if a%b == 0:
		return b
	else:
		return gcd(b, a%b)

def factor(n):
	factors = [1, n]
	i=2
	while i*i <= n:
		if n%i==0:
			factors.append(i)
			factors.append(n//i)
		i+=1

	return factors

n = int(input())
A = list(map(int, input().split()))

if n==2:
	print(max(A))
	quit()

gcd1 = 0
fac1 = sorted(factor(A[0]),reverse=True)
for i in range(len(fac1)):
	count = 0
	for j in range(1, n):
		if A[j]%fac1[i]!=0:
			count += 1
			if count >= 2:
				break
	if count <= 1:
		gcd1 = fac1[i]
		break

fac2 = sorted(factor(A[1]),reverse=True)
gcd2 = 0
for i in range(len(fac2)):
	count = 0
	for j in range(2, n):
		if A[j]%fac2[i]!=0:
			count += 1
			break
	if count <= 0:
		gcd2 = fac2[i]
		break

print(max(gcd1, gcd2))


Measured memory_bytes: 14972
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

template <class T, class Container = std::vector<T>,
          class Compare = std::less<typename Container::value_type>>
struct SlideMinQueue {
  const Container& values;
  deque<int> que;
  int left;
  int right;
  Compare compare;

  explicit SlideMinQueue(const Container& values)
      : values(values), left(0), right(0) {}

  void slide(int l, int r) {
    assert(l >= left);
    assert(r >= right);
    pop_left(l);
    left = l;
    for (int i = right; i < r; ++i) {
      push_right(i);
    }
    right = r;
  }

  T fold() const {
    assert(!empty());
    return que.front();
  }

  bool empty() const { return que.empty(); }

 private:
  // Enqueues the i-th value.
  void push_right(int i) {
    while (!que.empty() && !compare(values[que.back()], values[i])) {
      que.pop_back();
    }
    que.emplace_back(i);
  }

  // Dequeues indices less than i.
  void pop_left(int i) {
    while (!que.empty() && que.front() < i) {
      que.pop_front();
    }
  }
};

template <class T, class Container = std::vector<T>>
using SlideMaxQueue = SlideMinQueue<T, Container, greater<T>>;

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

  i64 N, K;
  cin >> N >> K;
  vector<i64> P(N);
  for (auto& x : P) cin >> x;

  vector<int> lsorted(N), rsorted(N);
  for (int i = 0; i < N; ++i) {
    lsorted[i] = 1;
    if (i > 0 && P[i - 1] <= P[i]) {
      lsorted[i] = lsorted[i - 1] + 1;
    }
    int j = N - 1 - i;
    rsorted[j] = 1;
    if (i > 0 && P[j] <= P[j + 1]) {
      rsorted[j] = rsorted[j + 1] + 1;
    }
  }

  SlideMinQueue<i64> minq(P);
  SlideMaxQueue<i64> maxq(P);
  set<tuple<int, int>> sorted_ranges;
  bool nochange = false;
  for (int l = 0; l <= N - K; ++l) {
    int r = l + K;  // exclusive
    assert(r <= N);
    minq.slide(l, r);
    maxq.slide(l, r);

    if (r - lsorted[r - 1] <= l) {
      DEBUG(nochange, l, r);
      nochange = true;
      continue;
    }

    i64 mine = P[minq.fold()];
    i64 maxe = P[maxq.fold()];
    int al = l;
    if (l - 1 >= 0 && P[l - 1] < mine) {
      al = l - lsorted[l - 1];
    }
    int ar = r;
    if (r < N && P[r] > maxe) {
      ar = r + rsorted[r];
    }
    sorted_ranges.emplace(al, ar);
  }
  int ans = sorted_ranges.size() + int(nochange);
  cout << ans << endl;
}


Measured memory_bytes: 15504
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N,A,B,C,D; cin >>N >>A >>B >>C >>D;
  string s; cin >>s;
  A--; B--; C--; D--;
  bool ok = true;
  for (int i=A; i<max(C,D); i++){
    if (s[i] == '#' && s[i+1] == '#') ok = false;
  }
  if (!ok){   cout <<"No" <<endl; return 0; }
  if (C < D){ cout <<"Yes" <<endl; return 0; }

  ok = false;

  for (int i=B-1; i<D; i++){
    if (s[i] == '.' && s[i+1] == '.' && s[i+2] == '.') ok = true;
  }
  cout <<(ok ? "Yes" : "No") <<endl;
}

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

int main() {
  int h, w, s;
  cin >> h >> w >> s;
  vector<vector<char>> a(h, vector<char>(w));

  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      cin >> a[i][j];
    }
  }

  vector<vector<int>> ans(h, vector<int>(w));
  int num = 1;
  for(int i=0;i<h;i++) {
    vector<int> b;
    bool empty = true;
    b.emplace_back(-1);
    for(int j=0;j<w;j++) {
      if(a[i][j] == '#') {
        b.emplace_back(j);
        empty = false;
      }
    }
    b.pop_back();
    b.emplace_back(w-1);
    if(empty) {
      continue;
    }
    for(int j=0;j<b.size()-1;j++) {
      for(int k=b[j]+1;k<=b[j+1];k++) {
        ans[i][k] = num;
      }
      num++;
    }
  }

  for(int i=1;i<h;i++) {
    for(int j=0;j<w;j++) {
      if(ans[i][j] == 0) ans[i][j] = ans[i-1][j];
    }
  }

  for(int i=h-2;i>=0;i--) {
    for(int j=0;j<w;j++) {
      if(ans[i][j] == 0) ans[i][j] = ans[i+1][j];
    }
  }

  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      cout << ans[i][j] << " "; 
    }
    cout << endl;
  }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
long long MOD = 1000000007;


template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }


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

    vector<long long >A(N);

    long long gou = 0;
    rep(i,N){
        cin >> A[i];
        gou += A[i];
        gou %= MOD;
    }

    long long sum =0;
    rep(i,N){
        gou -=A[i];
        if(gou < 0)gou +=MOD;
        sum = (sum + A[i]*gou ) % MOD;
    }

    cout << sum << endl;
}



Measured memory_bytes: 4824
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>

const long long int Z = 1000000007;
const long long int INF = 1 << 30;
int flag = 0;
using ll = long long;

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

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

int main() {
	std::string s;
	int n;
	std::cin >> s >> n;
	for (int i = 0;i < n;i++) {
		std::string t;
		std::cin >> t;
		if (t == "print") {
			int a, b;
			std::cin >> a >> b;
			for (int j = a;j <= b;j++) {
				std::cout << s[j];
			}
			std::cout << std::endl;
		}
		if (t == "reverse") {
			int a, b;
			std::cin >> a >> b;
			std::reverse(s.begin() + a, s.begin() + b + 1);
		}
		if (t == "replace") {
			int a, b;
			std::string p;
			std::cin >> a >> b >> p;
			int k = 0;
			for (int j = a;j <= b;j++) {
				s[j] = p[k];
				k++;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3156
#include"bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = b - 1; i >= a; i--)
#define RREP(i, n) RFOR(i, 0, n)
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define rrep(i, a, b) for (auto i = a; i > b; i--)
#define range(i, a, b) (a <= i && i < b)
#define ll long long
#define fi first
#define fs first
#define se second
#define sc second
//#define int long long
using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
typedef pair<int, int> P;

int n, k, s, en;
vector<pair<int, int>> v[2001];

int tmp;
void dfs(int no, int dep, int par) {
	if (no == en && dep > 1) tmp = -(1 << 30);
	if (dep == k) {
		for (auto to : v[no]) {
			if (to.fs == en && k > 2) tmp += to.sc;
		}
		return;
	}
	bool flag = true;
	for (auto to : v[no]) {
		if (to.fs == par) continue;
		tmp += to.sc;
		dfs(to.fs, dep+1, no);
		flag = false;
	}
	if (flag) tmp = -(1 << 30);
}

void solve() {
	rep(i, 0, 2001) v[i].clear();
	int x[2001], y[2001], z[2001];
	rep(i, 0, n) {
		cin >> x[i] >> y[i] >> z[i];
	}
	rep(i, 0, n) {
		rep(j, 0, n) {
			if (i == j) continue;
			int dx = s - abs(x[i] - x[j]);
			int dy = s - abs(y[i] - y[j]);
			int dz = s - abs(z[i] - z[j]);
			if (dx < 0 || dy < 0 || dz < 0) continue;
			v[i].push_back(make_pair(j, 2 * (dx * dy + dy * dz + dz * dx)));
		}
	}

	int res = -1;
	REP(i, n) {
		if (v[i].size() == 2) for (auto to : v[i]) tmp = 0, en = i, dfs(i, 1, to.fs), res = max(res, tmp);
		else tmp = 0, en = -1, dfs(i,1,-1), res = max(res, tmp);
	}

	if (res == -1) cout << -1 << endl;
	else cout << 6 * s*s*k - res << endl;

}

int main() {
	while (cin >> n >> k >> s, n) solve();
}


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

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

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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    REP(i,n){scanf("%d", &v[i]);}
    map<int,int> mp;
    for(int &x:v){
        mp[x]++;
    }

    int result=0;
    for(pair<int,int> x : mp){
        if(x.first>x.second){
            result+=x.second;
        }else if(x.first<x.second){
            result+=x.second-x.first;
        }
    }
    cout<<result<<endl;

    return 0;
}


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

int main(){
  int L;
  cin>>L;
  int k=0;
  for(int i=1;i<=L;i*=2)k++;
  int a=1;
  int i;
  cout<<k<<" ";
  int LL=L;
  int aa=1;
  for(i=1;i<k;i++)aa*=2;
  LL-=aa;
  int M=2*(k-1);
  while(LL){
    int aaa;
    for(aaa=1;aaa<=LL;aaa*=2){}
    LL-=aaa/2;
    M++;
  }
  cout<<M<<endl;
  for(i=1;i<k;i++){
    cout<<i<<" "<<i+1<<" "<<a<<endl;
    cout<<i<<" "<<i+1<<" "<<0<<endl;
    a*=2;
  }
  L-=a;
  int fa=a;
  while(L){
    int i;
    int s=0;
    for(i=1;i<=L;i*=2)s++;
    L-=i/2;
    cout<<s<<" "<<k<<" "<<fa<<endl;
    fa+=i/2;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
 
int main() {
	int n;
	int i, j;
	int b=1;
	int cnt = 0;
	cin >> n;

	vector<int> a(n);
	for (i=0;i<n;i++)
	{
		cin >> a.at(i);
	}
	while (b != 2)
	{
		if (a.at(b - 1) == 0)
		{
			cnt = -1;
			break;
		}
		int c;
		c = b;
		b = a.at(c - 1);
		a.at(c - 1) = 0;
		cnt++;
	}
	cout << cnt << endl;
}



/**/
/*#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define PI 3.141592653589793

int main(void) {
	return 0;
}
*/

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int N, M;
    cin >> N >> M;
    if (N > M) swap(N, M);
    if (N == 1 && M == 1) {
        cout << 1 << endl;
    } else if (N == 1) {
        cout << M - 2 << endl;
    } else {
        cout << ll(N - 2) * (M - 2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>

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

	int n,x,l,a = 0;
  	map<int, int> robots; 
	cin >> n;
	for (int i = 0; i < n; i++)
    {
		cin >> x;
      	cin >> l;
      	robots.insert(make_pair(x, l));
    }
  
  	x = -1;
  	for (const auto& robot : robots)
    {
		if (x == -1 || x + l <= robot.first - robot.second)
        {
          	a++;
          	x = robot.first;
          	l = robot.second;
        }
      else if (x + l > robot.first + robot.second)
      {
        x = robot.first;
        l = robot.second;
      }
    }
  
	cout << a << endl;
}

Measured memory_bytes: 4992
import math
import itertools
import numpy as np

N = int(input())
X, Y = [], []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)

dist = 0
for order in itertools.permutations(range(N), N):
    for i in range(1, len(order)):
        dist += np.sqrt((X[order[i]] - X[order[i - 1]])**2 +
                        (Y[order[i]] - Y[order[i - 1]])**2)
ans = dist / math.factorial(N)
print(ans)


Measured memory_bytes: 12496