akhauriyash/Code-Regression huggingface dataset:
N_MAX = 1000000000

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

mergeCnt = 0

def merge(A, left, mid, right):
    
    global mergeCnt
    
    n1 = mid - left
    n2 = right - mid
    
    L = A[left:mid]
    R = A[mid:right]
    
    L.append(N_MAX)
    R.append(N_MAX)
    
    i = j = 0
    
    for k in range(left, right):
        mergeCnt += 1
        if(L[i] <= R[j]):
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def mergeSort(A, left, right):
    if (left + 1 < right):
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

if(__name__ == '__main__'):
    
    left = 0
    right = n
    
    mergeSort(S, left,right)
    
    print(*S)
    print(mergeCnt)


Measured memory_bytes: 61648
#include<iostream>
#define ll long long
using namespace std;
int gcd(int a,int b)
{
	if(a<b) swap(a,b);
	if(a%b==0) return b;
	return gcd(b,a%b);
}
int main()
{
	int k,sum=0;cin>>k;
	for(int i=1;i<=k;++i)
	{
		for(int j=1;j<=k;++j)
		{
			int t=gcd(i,j);
			for(int z=1;z<=k;++z)
			{
			sum+=gcd(t,z);	
			}
		}
		
	}
	cout<<sum;
 } 

Measured memory_bytes: 3624
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main() {
    int x, y;
    cin >> x >> y;

    for (int i = 0; i < x + 1; i++) {
        if (2 * i + 4 * (x - i) == y) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";

    

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < D; ++j) {
      cin >> X[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      int norm = 0;
      for (int k = 0; k < D; ++k) {
        int diff = abs(X[i][k] - X[j][k]);
        norm += diff * diff;
      }
      // check whether norm = k for some k
      bool flag = false;
      for (int k = 0; k <= norm; ++k) {
        if (k * k == norm) {
          flag = true;
        }
      }
      if (flag) ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);

		int N = 0,l = 0,r = 0,result = 0;

		N = sc.nextInt();
		for(int x = 1 ; x <= N ; x++) {
			l = sc.nextInt();
			r = sc.nextInt();
			l--;
			result += Math.abs(l - r);
		}
		System.out.println(result);
	}
}


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

typedef pair<int,bool> P;

int main(){
  int N,M,r,q;
  int t,n,m,s;
  int ts,te;
  vector<P> log[10100];

  while(cin >> N >> M, N||M){
    for(int i=0;i<M;i++)log[i].clear();
    cin >> r;
    for(int i=0;i<r;i++){
      cin >> t >> n >> m >> s;
      log[m].push_back(P(t,s));
    }

    cin >> q;
    for(int i=0;i<q;i++){
      cin >> ts >> te >> m;

      int num = 0,ans = 0,pos = 0;
      while(pos < log[m].size() && log[m][pos].first<ts){
	if(log[m][pos].second)num++;
	else num--;
	pos++;
      }

      for(int i=ts;i<te;i++){
	while(pos < log[m].size() && log[m][pos].first==i){
	  if(log[m][pos].second)num++;
	  else num--;
	  pos++;
	}
	if(pos==log[m].size())break;

	if(num)ans++;
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    int N;
    cin >> N;
    int A[N];
    int B[N];
    int C[N-1];
    
    rep(i,N){
        int t=0;
        cin >> t;
        A[i] = --t;
    }
    rep(i,N){
        cin >> B[i];
    }
    rep(i,N-1){
        cin >> C[i];
    }

    int sum = 0;
    int pre_num=-20;
    rep(i,N){
        sum+=B[A[i]];
        
        if(A[i] == pre_num+1){
            sum+=C[pre_num];
        }
        
        pre_num = A[i];
    }
       
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
ans=[0]*4
for i in range(n):
  s=input()
  if s=='AC':
    ans[0]+=1
  elif s=='WA':
    ans[1]+=1
  elif s=='TLE':
    ans[2]+=1
  else:
    ans[3]+=1
print('AC x ',ans[0])
print('WA x ',ans[1])
print('TLE x ',ans[2])
print('RE x ',ans[3])

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

signed main() {
	string r,s,t;
	cin>>r; s=r+r;
	cin>>t;

	vector<vector<ll>> s_position(26,vector<ll>());
	vector<ll> t_num(26,0);
	rep(i,s.size()){
		ll ch=s[i]-'a';
		s_position[ch].push_back(i);
	}
	rep(i,t.size()){
		ll ch=t[i]-'a';
		t_num[ch]++;
	}
	rep(i,26){
		if(s_position[i].size()==0 && t_num[i]>0){
			cout<<-1<<endl;
			return 0;
		}
	}

	ll ans=0;
	ll index=0;
	rep(i,t.size()){
		ll ch=t[i]-'a';
		auto it=lower_bound(s_position[ch].begin(), s_position[ch].end(), index);
		ans+=*it-index+1;
		index=*it+1;
		if(index>=r.size())index-=r.size();
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3000
INF = float('inf')


def tc():
    n, cap = map(int, input().split())
    weights, values = [], []
    for _ in range(n):
        w, v = map(int, input().split())
        weights.append(w)
        values.append(v)
    # swap the definition from previous problem, so that
    # the smaller values are the dp dimension
    # dp[i]: min total weight with total value exactly i
    value_sum = sum(values)
    dp = [INF] * (value_sum + 1)
    dp[0] = 0

    for i in range(n):
        w, v = weights[i], values[i]
        # remember to reverse, because you don't want
        # to doublecount the same items
        for prev_v in reversed(range(value_sum - v + 1)):
            dp[prev_v + v] = min(dp[prev_v + v], dp[prev_v] + w)

    ans = 0
    for v, w in enumerate(dp):
        if w <= cap:
            ans = max(ans, v)

    print(ans)


tc()


Measured memory_bytes: 81992
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;



int main() {
  int n;
  scanf("%d",&n);
  vi a(n);
  cin>>a;
  int pre = -1, ans = 0;
  rep(i,n) {
    if (a[i] == pre) {
      ++ans;
      pre = -1;
    } else pre = a[i];
  }
  cout<<ans<<endl;
  return 0;
}






















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

const double eps = 1e-10;

int dcmp(double x) {
        if(fabs(x) < eps) return 0;
        return x < 0 ? -1 : 1;
}

bool same(double a, double b) {return dcmp(a - b) == 0;}
#define Vector P
struct P {
        double x, y;
        P(double x = 0, double y = 0): x(x), y(y) {}
        P operator + (P b) {return P(x + b.x, y + b.y);}
        P operator - (P b) {return P(x - b.x, y - b.y);}
        P operator * (double b) {return P(x * b, y * b);}
        P operator / (double b) {return P(x / b, y / b);}
        double operator * (P b) {return x * b.x + y * b.y;} // Dot
        double operator ^ (P b) {return x * b.y - y * b.x;} // Cross
        double abs() {return hypot(x, y);}
        P unit() {return *this / abs();}
        P spin(double o) {
                double c = cos(o), s = sin(o);
                return P(c * x - s * y, s * x + c * y);
        }
};

struct Line {
        //ax + by + c = 0
        double a, b, c, theta;
        P pa, pb;
        Line(): a(0), b(0), c(0), theta(0), pa(), pb() {}
        Line(P pa, P pb): a(pa.y - pb.y), b(pb.x - pa.x), c(pa ^ pb), theta(atan2(-a, b)), pa(pa), pb(pb) {}        P projection(P p) {return pa + (pb - pa).unit() * ((pb - pa) * (p - pa) / (pb - pa).abs());}                P reflection(P p) {return p + (projection(p) - p) * 2;}
        double get_ratio(P p) {return (p - pa) * (pb - pa) / ((pb - pa).abs() * (pb - pa).abs());}
        P dis(P p) {return ((pb - pa) ^ (p - pa)) / (pb - pa).abs();} // directed distance
};

struct Circle {
        P c;
        double r;
        Circle(P c, double r = 0): c(c), r(r) {}
};
bool onsegment(P p, P a, P b) {
        return dcmp((a - p) ^ (b - p)) == 0 && dcmp((a - p) * (b - p)) <= 0;
}
bool segment_intersection(P p1, P p2, P p3, P p4) { // end points are not allowed
        return dcmp((p2 - p1) ^ (p3 - p1)) * dcmp((p2 - p1) ^ (p4 - p1)) < 0
                && dcmp((p4 - p3) ^ (p1 - p3)) * dcmp((p4 - p3) ^ (p2 - p3)) < 0;

}
bool parallel(Line l1, Line l2) {return same(l1.a * l2.b, l1.b * l2.a);}
P line_intersection(Line l1, Line l2) {
        return P(-l1.b * l2.c + l1.c * l2.b, l1.a * l2.c - l1.c * l2.a) / (-l1.a * l2.b + l1.b * l2.a);     }
int main() {
        ios_base::sync_with_stdio(false); cin.tie(0);
        int q; cin >> q;
        while(q--) {
                P p0, p1, p2, p3;
                cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
                Line l1 = Line(p0, p1), l2 = Line(p2, p3);
                P p = line_intersection(l1, l2);
                cout << fixed << setprecision(12) << p.x << ' ' << p.y << '\n';
        }
        return 0;
}


Measured memory_bytes: 3624
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<vector>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define repd(i,x,y) for(int i=x; i>=y; --i)
#define mid (l+r>>1)
#define pb push_back

using namespace std;
const int N=140005;
typedef long long LL;
const LL INF=1000000000000000ll;
int n,x,L[N],R[N];
bool jdg;
LL d[N];
struct data{LL a,b;};
vector <data> st0[N],st1[N],vt0,vt1;

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

void dfs(int x,LL lim)
{
	if(!L[x] && !R[x])
	{
		st0[x].pb((data){d[x],d[x]}); 
		st1[x].pb((data){d[x],d[x]});
		return;
	}
	dfs(L[x],lim);
	dfs(R[x],lim);
	if(jdg) return;

	if(st0[L[x]].size()>st0[R[x]].size()) swap(L[x],R[x]);
	int u=L[x],v=R[x];
	int sz0=st0[u].size(),sz1=st0[v].size(),p0=-1,p1=-1;	

	vt0.clear();
	rep(i,0,sz0-1)
	{
		while(p0+1<sz1 && st0[v][p0+1].a+st0[u][i].b<=lim+2*d[x]) ++p0;
		while(p1+1<sz1 && st1[v][p1+1].a+st0[u][i].b<=lim+2*d[x]) ++p1;
		data tmp;
		if(p0>=0 || p1>=0) tmp=(data){st0[u][i].a,min(p0>=0?st0[v][p0].b:INF,p1>=0?st1[v][p1].b:INF)},vt0.pb(tmp);
	}

	p0=-1,p1=-1;

	vt1.clear();
	rep(i,0,sz0-1)
	{
		while(p0+1<sz1 && st0[v][p0+1].a+st1[u][i].b<=lim+2*d[x]) ++p0;
		while(p1+1<sz1 && st1[v][p1+1].a+st1[u][i].b<=lim+2*d[x]) ++p1;
		data tmp;
		if(p0>=0 || p1>=0) tmp=(data){st1[u][i].a,min(p0>=0?st0[v][p0].b:INF,p1>=0?st1[v][p1].b:INF)},vt1.pb(tmp);
	}

	p0=0,p1=0;
	while(p0<vt0.size() || p1<vt1.size())
	{
		if(p0>=vt0.size()) st0[x].pb(vt1[p1++]);
		else if(p1>=vt1.size()) st0[x].pb(vt0[p0++]);
		else
		{
			if(vt0[p0].a<=vt1[p1].a && vt0[p0].b<=vt1[p1].b) {++p1; continue;}
			if(vt0[p0].a>=vt1[p1].a && vt0[p0].b>=vt1[p1].b) {++p0; continue;}
			if(vt0[p0].a<vt1[p1].a) st0[x].pb(vt0[p0++]);
			else st0[x].pb(vt1[p1++]);
		}
	}
		
	int sz=st0[x].size();
	repd(i,sz-1,0) st1[x].pb((data){st0[x][i].b,st0[x][i].a});

	st0[u].clear();
	st1[u].clear();
	if(st0[x].size()==0) jdg=1;
}

bool check(LL lim)
{
	jdg=0;
	rep(i,1,n) st0[i].clear(),st1[i].clear();
	dfs(1,lim);
	return !jdg;
}

int main()
{
	n=getint();
	rep(i,2,n) x=getint(),L[x]?R[x]=i:L[x]=i,d[i]=d[x]+getint();
	LL l=0,r=INF;
	while(l<=r) check(mid)?r=mid-1:l=mid+1;
	printf("%lld\n",r+1);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i<N; i++)  cin >> a.at(i);
  int count = 0;
  vector<int> count2(N,0);
  int s = 1;
  while(true){
    count2.at(s-1) += 1;
    if (count2.at(s-1) == 2){
      cout << -1 << endl;
      break;
    }
    s = a.at(s-1);
    count++;
    if (s == 2){
      cout << count << endl;
      break;
    }
  }
}



Measured memory_bytes: 1024
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

ll cost (ll i,ll j,ll h[]){
return abs(h[i]-h[j]);

}

int main()
{
    ll n;cin>>n;
   ll h[n+1];
    for(ll i=1;i<=n;i++){
        cin>>h[i];
    }

    ll dp[n+1];
    dp[0]=0;
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    for(ll i=3;i<=n;i++){
       dp[i]=min(dp[i-2]+cost(i,i-2,h),dp[i-1]+cost(i,i-1,h));
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1792
H, N = map(int, input().split())

A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

dp = [float("inf") for _ in range(H + 1)]
dp[0] = 0

for h in range(H + 1):
    for i in range(N):
        dp[h] = min(dp[h], dp[max(0, h - A[i])] + B[i])

print(dp[H])


Measured memory_bytes: 42732
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            if (input=="a"|| input == "i"|| input == "u" || input == "e" || input == "o" )
            {
                Console.WriteLine("vowel");
            }
            else
            {
                Console.WriteLine("consonant");
            }
        }  
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    int n;
    ll sum=0;

    cin >> n;
    vector<ll>A(n);
    for(int i=0; i<n;i++){
        cin >> A[i];
    }
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            sum+= A[i]*A[j];
        }
    }
    cout << sum<< endl;
}

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

unsigned long long popcount(unsigned long long x) {
  x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) + (x & 0x5555555555555555UL);
  x = ((x & 0xccccccccccccccccUL) >> 2) + (x & 0x3333333333333333UL);
  x = ((x & 0xf0f0f0f0f0f0f0f0UL) >> 4) + (x & 0x0f0f0f0f0f0f0f0fUL);
  x = ((x & 0xff00ff00ff00ff00UL) >> 8) + (x & 0x00ff00ff00ff00ffUL);
  x = ((x & 0xffff0000ffff0000UL) >> 16) + (x & 0x0000ffff0000ffffUL);
  x = ((x & 0xffffffff00000000UL) >> 32) + (x & 0x00000000ffffffffUL);
  return x;
}

long long n;
long long memo[20][2] = {0};

long long solve();

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    long long tr = 0, fal = 0, x, y, a;
    cin >> a;
    for (int j = 0; j < a; ++j) {
      cin >> x >> y;
      --x;
      if (y)
        tr += 1LL << x;
      else
        fal += 1LL << x;
    }
    memo[i][1] = tr;
    memo[i][0] = fal;
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  int ans = 0;
  for (long long i = 0; i < (1LL << n); ++i) {
    bool ch = 1;
    for (int j = 0; j < n; ++j)
      if ((i >> j) & 1) {
        if ((i & memo[j][1]) != memo[j][1]) ch = 0;
        if ((~i & memo[j][0]) != memo[j][0]) ch = 0;
      }
    if (ch) ans = max(ans, (int)popcount(i));
  }
  return ans;
}


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

#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 FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

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

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)1e5+11;
ll const LG=(ll)log2(N)+1;

void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        
        for(i=1;i<=5;i++){
                cin>>x;
                if(x==0){
                        cout<<i;
                        return;
                }
        }
        
       
}   
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}

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

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var s = ReadLineStringSplit();
            Console.WriteLine(s[1] + s[0]);
            ReadLine();
        }

        /// <summary>
        /// コンビネーション
        /// </summary>
        /// <param name="n"></param>
        /// <param name="m"></param>
        /// <returns></returns>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        /// <summary>
        /// stringを一文字ずつintにキャストして配列に変換します。
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int[] StringCharArrayIntArray(string str)
        {
            List<int> b = new List<int>();
            for (int i = 0; i < str.Length; i++) {
                b.Add( int.Parse(str[i].ToString()));
            }
            return b.ToArray();
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static int ReadLineInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static string[] ReadLineStringSplit(char a = ' ')
        {
            return ReadLine().Split(a).ToArray();
        }

        public static int[] ReadLineIntSpilit(char a = ' ')
        {
            return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        }

        static string[] GetAplhaLowerArray() => new string[]{ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int sum = 0;

void dfs(int i, int pre, vector<vector<int>> &rel,vector<bool> &checked){
    bool all_checked = true;
    for (int j : rel[i])
    {
        if(!checked[j]) all_checked = false;
    }
    if(all_checked) return;
    for (int j : rel[i])
    {
        if(j == pre) continue;
        if(!checked[j]){
            checked[j] = true;
            dfs(j,i,rel,checked);
        }
    }    
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> rel(n);
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin>> a >> b >> c;
        rel[a-1].push_back(b-1);
        rel[b-1].push_back(a-1);
    }
    int i = 0;
    int sum = 0;
    vector<bool> checked(n,false);

    bool all_checked = false;
    for (int i = 0; i < n; i++)
    {
        if(!checked[i]){
            checked[i] = true;
            dfs(i,-1,rel,checked);
            sum ++ ;
        }
    }
    
    /*while (!all_checked)
    {
        dfs(i,-1,rel,checked);
        sum ++;
        if(yet_checked.size() == 0) all_checked = true;     
        i = yet_checked[0]; 
    }*/
    cout << sum << endl; 
}

Measured memory_bytes: 14636
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
const int MAX = 510000;
signed main(){
    int n;
    cin>>n;
    int d[100];
    for(int i=0;i<n;i++)cin>>d[i];
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=d[i]*d[j];
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int WWW = 0;WWW < (n);WWW++)cerr << v[WWW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL


typedef long long ll;
typedef pair<ll,ll> P;

#define N 3
ll mod[] = {999999937,1000000007,1000000009};
ll kake = 123123;

ll m_pow(ll a,ll b,ll p){
	ll ret = 1;
	ll tmp = a;
	for(ll i = 0LL;i < 60;i++){
		if(b & (1LL << i)){
			ret *= tmp;
			ret %= p;
		}
		tmp *= tmp;
		tmp %= p;
	}
	return ret;
}

vector<int> RollingHash(string str,string s){
	vector<int> ret;
	ll mark[N] = {};
	REP(i,s.size()){
		REP(j,N){
			mark[j] *= kake;
			mark[j] += (int)s[i];
			mark[j] %= mod[j];
		}
	}
	ll po[N];
	REP(i,N)po[i] = m_pow(kake,s.size()-1,mod[i]);
	ll now[N] = {};
	REP(i,str.size()){
		bool flag = true;
		REP(j,N){
			if(i >= s.size()){
				ll tmp = po[j] * (int)str[i-s.size()] % mod[j];
				now[j] = (now[j] + mod[j] - tmp) % mod[j];
			}
			now[j] *= kake;
			now[j] += (int)str[i];
			now[j] %= mod[j];
			if(now[j] != mark[j])flag = false;
		}
		if(flag)ret.PB(i-s.size()+1);
	}
	return ret;
}

int main(){
	
	string a,b;cin >> a >> b;
	vector<int> ans = RollingHash(a,b);
	REP(i,ans.size()){
		cout << ans[i] << endl;
	}
	
	return 0;
}



Measured memory_bytes: 9308
n,m,l=map(int,input().split())
A = [list(map(int,input().split())) for _ in range(n)]
B = [list(map(int,input().split())) for _ in range(m)]
for nnum in range(n):
    temp=[]
    for lnum in range(l):
        ret = 0
        for mnum in range(m):
            ret +=(A[nnum][mnum]*B[mnum][lnum])
        temp.append(ret)
    print(*temp)

Measured memory_bytes: 8684
#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
#include <cstdio>
using namespace std;

typedef complex<double> P;
typedef pair<P,P> L;
const double EPS = 1e-7;
const int MAX = 30000;
int n,m;

P dat[100];
double ans[100];

double equal(double a, double b){ return fabs(a-b) < EPS;}

double dot(P a, P b){ return real(conj(a)*b);}

double cross(P a, P b){ return imag(conj(a)*b);}

double calcArea(vector<P> v){
  double sum = 0.0;
  int n = v.size();
  for(int i=0;i<n;i++) sum += (v[i].real() - v[(i+1)%n].real()) * (v[i].imag() + v[(i+1)%n].imag());
  return fabs(sum) / 2;
};

int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}

vector<P> convex_cut(vector<P> G, L l){
  vector<P> ans;
  for(int i=0;i<G.size();i++){
    P A = G[i];
    P B = G[(i+1)%G.size()];
    if(ccw(l.first, l.second, A) != -1) ans.push_back(A);
    if(ccw(l.first, l.second, A) * ccw(l.first, l.second, B) < 0){
      L l2(A,B);
      ans.push_back(crossPoint(l2, l));
    }
  }
  return ans;
}

P rotate(P p, double theta){
  theta *= M_PI / 180.0;
  double x = p.real() * cos(theta) - p.imag() * sin(theta);
  double y = p.real() * sin(theta) + p.imag() * cos(theta);
  return P(x,y);
}

L bisector(L l){
  P p = (l.first + l.second) / 2.0;
  return L(p, p + rotate(l.second-l.first,90));
}

void solve(vector<P> v){
  for(int i=0;i<m;i++){
    vector<P> area = v;
    for(int j=0;j<m;j++){
      if(i == j) continue;
      area = convex_cut(area, bisector(L(dat[i], dat[j])));
    }
    printf("%f\n",calcArea(area));
  }
}

int main(){
  while(cin >> n >> m && (n|m)){
    vector<P> v;
    for(int i=0;i<n;i++){
      int x,y;
      cin >> x >> y;
      v.push_back(P(x,y));
    }
    for(int i=0;i<m;i++){
      int x,y;
      cin >> x >> y;
      dat[i] = P(x,y);
    }

    solve(v);
  }
}

Measured memory_bytes: 1236
use itertools::iproduct;
use std::collections::VecDeque;
use whiteread::parse_line;

type Point = (usize, usize);

fn main() {
    let (h, w): (usize, usize) = parse_line().unwrap();
    let source: Point = {
        let p: (usize, usize) = parse_line::<Point>().unwrap();
        (p.1 - 1, p.0 - 1)
    };
    let sink: Point = {
        let p: (usize, usize) = parse_line::<Point>().unwrap();
        (p.1 - 1, p.0 - 1)
    };
    let maze: Vec<Vec<char>> = (0..h)
        .map(|_| parse_line::<String>().unwrap().chars().collect())
        .collect();

    // eprintln!("{:?}", maze);
    let mut queue = VecDeque::from(vec![(source.0 as isize, source.1 as isize)]);

    let mut dist = vec![vec![None; w]; h];
    dist[source.1][source.0] = Some(0);

    while let Some(cur) = queue.pop_front() {
        for (dx, dy) in iproduct!(-2..=2isize, -2..=2isize) {
            let cost = match dx.abs() + dy.abs() {
                0 => continue,
                1 => 0,
                _ => 1,
            };

            let next = (cur.0 as isize + dx, cur.1 as isize + dy);

            if (0..h as isize).contains(&next.1)
                && (0..w as isize).contains(&next.0)
                && maze[next.1 as usize][next.0 as usize] == '.'
            {
                let cand = dist[cur.1 as usize][cur.0 as usize].expect("dist") + cost;
                let nd = dist[next.1 as usize][next.0 as usize].get_or_insert(usize::max_value());
                if *nd <= cand {
                    continue;
                }
                *nd = cand;
                match cost {
                    0 => queue.push_front(next),
                    _ => queue.push_back(next),
                }
            }
        }
    }

    // eprintln!("{:?}", dist);
    println!(
        "{}",
        dist[sink.1][sink.0].map_or(-1 as isize, |v| v as isize)
    );
}


Measured memory_bytes: 21860
#include<iostream>
#include<string>

using namespace std;

int main(){
	string s, s2 = "YAKI";
	cin >> s;
    if(s.size() < 4){
        cout << "No" << endl;
        return 0;
    }
    for(int i = 0; i < 4; i++){
        if(s[i] != s2[i]){
            cout << "No" << endl;
            return 0;
        }
    }
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
  v = A[i]
  j = i - 1
  while j >= 0 and A[j] > v:
    A[j+1] = A[j]
    j -= 1
  A[j+1] = v
  print(" ".join(list(map(str,A))))


Measured memory_bytes: 5600
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main() {
	int D;
	cin >> D;
	if (D == 25) {
		cout << "Christmas" << endl;
	} else if (D == 24) {
		cout << "Christmas Eve" << endl;
	} else if (D == 23) {
		cout << "Christmas Eve Eve" << endl;
	} else {
		cout << "Christmas Eve Eve Eve" << endl;
	}		

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, a=0, b=0, p;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> p;
        a=max(a,p);
        b+=p;
    }
    cout << b-a/2 << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <deque>

#include <atcoder/all>

using namespace atcoder;
using namespace std;
typedef long long ll;

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

    int N, M;
    cin >> N >> M;

    vector<string> grid(N);

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

    mf_graph<int> g(N * M + 2);
    int s = N * M, t = N * M + 1;

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            if (grid[i][j] == '#') continue;
            int v = i * M + j;
            if ((i + j) % 2 == 0) {
                g.add_edge(s, v, 1);
            } else {
                g.add_edge(v, t, 1);
            }
        }
    }

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            if ((i + j) % 2 == 1 || grid[i][j] == '#') continue;
            int v0 = i * M + j;
            if (i > 0 && grid[i - 1][j] == '.') {
                int v1 = (i - 1) * M + j;
                g.add_edge(v0, v1, 1);
            }
            if (j > 0 && grid[i][j - 1] == '.') {
                int v1 = i * M + (j - 1);
                g.add_edge(v0, v1, 1);
            }
            if (i + 1 < N && grid[i + 1][j] == '.') {
                int v1 = (i + 1) * M + j;
                g.add_edge(v0, v1, 1);
            }
            if (j + 1 < M && grid[i][j + 1] == '.') {
                int v1 = i * M + (j + 1);
                g.add_edge(v0, v1, 1);
            }
        }

    }

    cout << g.flow(s, t) << endl;

    auto edges = g.edges();

    for (auto e : edges) {
        if (e.from == s || e.to == t || e.flow == 0) continue;
        int i0 = e.from / M, j0 = e.from % M;
        int i1 = e.to / M, j1 = e.to % M;

        if (i0 == i1 + 1) {
            grid[i1][j1] = 'v';
            grid[i0][j0] = '^';
        } else if (j0 == j1 + 1) {
            grid[i1][j1] = '>';
            grid[i0][j0] = '<';
        } else if (i0 == i1 - 1) {
            grid[i0][j0] = 'v';
            grid[i1][j1] = '^';
        } else {
            grid[i0][j0] = '>';
            grid[i1][j1] = '<';
        }
    }

    for (int i = 0; i < N; ++i) {
        cout << grid[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

VVI edge(100010, VI(0));
VI diff(100010);
int c = 0;

void ddfs(int v, int p, int d) {
	diff[v] = d;
	for (int i = 0; i < edge[v].size(); i++) {
		if (edge[v][i] != p) {
			ddfs(edge[v][i], v, d + 1);
		}
	}
}

void dfs(int v, int p, int d) {
	if (d < diff[v])
		c = max(c, diff[v] - 1);
	if (d == diff[v])
		c = max(c, diff[v]);
	if (d >= diff[v])return;
	for (int i = 0; i < edge[v].size(); i++) {
		if (edge[v][i] != p) {
			dfs(edge[v][i], v, d + 1);
		}
	}
}

int main() {
	int n, u, v; cin >> n >> u >> v;
	int a, b;
	REP(i, n - 1) {
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	ddfs(v, -1, 0);
	dfs(u, -1, 0);
	cout << c;
}

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

int main() {
  int N;
  cin >>N;
  vector <int> A(N);
  for (int i=0;i<N-1;i++){
    cin >>A[i];
  }
  vector <int> B(N);
  for(int i=0;i<N-1;i++){
    B[A[i]-1]++;
  }
  for (int i=0;i<N;i++){
    cout << B[i] <<endl;
  }
}




Measured memory_bytes: 4856
n, k = map(int, input().split())
L=list(input())
cnt=0
if L[0]=='R' and L[1]=='R':
	cnt+=1 

for i in range(1,n-1):
	if L[i]=='R' and L[i+1]=='R':
		cnt+=1
	if L[i]=='L' and L[i-1]=='L':
		cnt+=1

if L[n-1]=='L' and L[n-2]=='L':
	cnt+=1

print(min(cnt+2*k,n-1))

Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10;

int n,m;
vector<int> a[maxn];
int avl[maxn]={0};
int kq=0;

void DFS(int u){
    avl[u]=1;
    for(int i=0;i<a[u].size();i++){
        int v=a[u][i];
        if (avl[v]==0) DFS(v);
    }
}

int main(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int x,y,z;
        cin>>x>>y>>z;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    for(int i=1;i<=n;i++)
        if (avl[i]==0){
            kq++;DFS(i);
        }
    cout<<kq;
}


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

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

    string S;
    cin >> S;

    int max_length = 0;
    int len = 0;
    for (int i = 0; i < S.length(); ++i) {
        char s = S[i];
        if (s == 'A' || s == 'T' || s == 'G' || s == 'C') {
            len++;
        } else if (len > 0) {
            max_length = max(max_length, len);
            len = 0;
        }
        if (i == S.length() - 1) {
            max_length = max(max_length, len);
        }
    }
    cout << max_length << '\n';

    return 0;
}


Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
import fractions

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

n, k = rm()
a = rl()
s = set()
b = a[0]
if k in set(a):
  print('POSSIBLE')
  exit()
if len(set(a)) == 1:
  if tuple(set(a))[0] == k:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')
  exit()
for i in a:
  g = fractions.gcd(i, b)
  if g == 1:
    print('POSSIBLE')
    exit()
  if k % g == 0 and k <= max(i, b):
    print('POSSIBLE')
    exit()
else:
  print('IMPOSSIBLE')

  




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

using namespace std;
#define ll long long int 
 const int INF= 1e9+ 1;



int main ()
{
    int n,w;
    cin>>n>>w;
    ll s;
    s=0;
    vector<ll> a,b;
    
    for(ll i=0;i<n;i++)
    {
        ll wi,vi;
        cin>>wi>>vi;
        a.push_back(wi);
        b.push_back(vi);
        s+=vi;
    }
    vector <ll> p(s+1,INF);
    p[0]=0;
    for (ll i = 0; i < n; i++)
    {
        for( ll j=s-b[i];j>=0;j--)
        {
         p[j+b[i]]=min(p[j]+a[i],p[j+b[i]]);
        }
    }
    ll ans;
    ans=0;
    for(ll i=0;i<=s;i++)
    {
        if(p[i]<=w)
        {
            ans=max((ll)i,ans);
        }
    }
    
     cout<<ans<<endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	int w,h;
    	while(true){
	    	h = scan.nextInt();
	    	w = scan.nextInt();
	    	if(h == 0 && w == 0) break;
	    	for(int i=0;i<h;i++){
	    		for(int j=0;j<w;j++) System.out.print("#");
	    		System.out.println();
	    	}
	    	System.out.println();
    	}
    }
}

Measured memory_bytes: 25112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;

int main(void) {
  string s;int k;
  cin >> s >> k;
  set<string> ans;
  int n = s.size();
  rep(i,n){
    rep(j,5){
      if(i+j+1>n)continue;
      ans.insert(s.substr(i,j+1));
    }
  }
  while(true){
    if(k==1){
      cout << *begin(ans) << endl;
      return 0;
    }
    ans.erase(*begin(ans));
    k--;
  }
    
}




Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
int n,m,k,a[20][20],sum[15],c[15],ans=0x3f3f3f3f,g;
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<n;i++){
	scanf("%d",&c[i]);	
	for(int j=0;j<m;j++) scanf("%d",&a[i][j]); 
	}
	for(int i=1;i<(1<<n);i++){
	  memset(sum,0,sizeof(sum)); g=0;
	 for(int j=0;j<n;j++){
	  if(!(i&(1<<j))) continue;
	  for(int l=0;l<m;l++) sum[l]+=a[j][l];
	  g+=c[j];
	 }
	bool flag=0;
	for(int j=0;j<m;j++) {
	 if(sum[j]<k) {
	 	flag=1;
	 	break;
	 }
	}
	if(!flag) ans=min(ans,g);
	}
	printf("%d\n",ans==0x3f3f3f3f? -1:ans);
 } 

Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 3e5 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

int arr[N];

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  sort(arr, arr + n, greater<int>());
  ll total = 0;
  for (int i = k; i < n; ++i) {
    total += arr[i];
  }
  cout << total;
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

using namespace std;
int fz[1000010];
int main(void){
    int n;
    long long sum=0;
    cin>>n;
    fz[0]=0;
    for (int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0){
            sum+=i;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

int main(){
  int n, m; cin >> n >> m;
  vector<pair<int, int> > p(m);
  rep(i, m){
    int a, b; cin >> a >> b; a--, b--;
    p[i] = make_pair(b, a);
  }
  sort(p.begin(), p.end());

  int max = -1;
  int cnt = 0;
  rep(i, m){
    int l, r;
    tie(r, l) = p[i];
    if(l <= max) continue;
    else{
      max = r-1;
      cnt++;
    }
  }
  
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int n;
  cin >> n;

  cout << pow(n, 3) << endl;
}


Measured memory_bytes: 4296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
  int H, N;
  cin >> H >> N;
  int A;
  int sum = 0;
  rep(i, N){
    cin >> A;
    sum += A;
  }
  if(sum >= H)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mx 100005
#define P pair<int, int>

int n, m, a, b, ans, pos;
P brd[mx];

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 0; i < m; i++){
		scanf("%d%d", &a, &b);
		brd[i] = P(b, a);
	}
	sort(brd, brd+m);
	for(int i = 0; i < m; i++){
		if(brd[i].second >= pos){
			ans++;
			pos = brd[i].first;
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int dp[10][2][2][2][2];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = (int)S.size();
    dp[0][0][0][0][0] = 1;
    rep(i, 0, N) rep(j, 0, 2) rep(k, 0, 2) rep(l, 0, 2) rep(m, 0, 2) {
        if (!k && !l && !m) {
            dp[i + 1][j | ((int)(S[i] - '0') > 0)][0][0][0] += dp[i][j][k][l][m];
        }
        int max_num = j ? 7 : (int)(S[i] - '0');
        for (int d : {3, 5, 7}) {
            if (d > max_num) {
                break;
            }
            dp[i + 1][j | (d < (int)(S[i] - '0'))][k | (d == 3)][l | (d == 5)][m | (d == 7)] += dp[i][j][k][l][m];
        }
    }
    cout << dp[N][0][1][1][1] + dp[N][1][1][1][1] << endl;
    return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  string moji[N];
  for (int i = 0; i < N; i++) {
    cin >> moji[i];
  }
  
  bool ng = false;;
  map<string, int> m;
  m[moji[0]]++;
  
  for (int i = 1; i < N; i++) {
    if (moji[i-1][moji[i-1].size()-1] != moji[i][0]) {
      ng = true;
      break;
    }
    m[moji[i]]++;
    if (m[moji[i]] > 1) {
      ng = true;
      break;
    }
  }

  if (ng) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

const int MAXN = (int)1e6 + 1;

int count[MAXN];

int solve(int n) {
  int ans = 0;
  for (int i = 2; i < MAXN; ++i) {
    int num_of_mul = 0;
    for (int j = i; j < MAXN; j += i) {
      num_of_mul += count[j];
    }
    if (num_of_mul == n) return 2;
    if (num_of_mul > 1) ans = 1;
  }
  return ans;
}

int main() {
  int n;
  std::cin >> n;
  for (int i = 0, in; i < n; ++i) {
    std::cin >> in;
    ++count[in];
  }

  int ans = solve(n);
  if (ans == 0) {
    std::cout << "pairwise coprime" << std::endl;
  } else if (ans == 1) {
    std::cout << "setwise coprime" << std::endl;
  } else {
    std::cout << "not coprime" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 7488
#include <stdio.h>
int main(void){
    int n, A[100], tmp, cnt=0;
    scanf("%d", &n);
    
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    
    for (int i = 0; i < n; i++) {
        int minj = i;
        for (int j = i; j < n; j++) {
            if (A[j] < A[minj]) minj = j;
        }
        if (i != minj) {tmp = A[i]; A[i] = A[minj]; A[minj] = tmp;cnt++;}
    }
    
    for (int i = 0; i < n; i++) {
        if (i) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    
    printf("%d", cnt);
    
    printf("\n");
    return 0;
}



Measured memory_bytes: 2048
#include<stdio.h>
int main()
{
    char ch[3];
    int i,j=0,l=0,k,a,n;
    scanf("%s",&ch);
    for(i=0;i<3;i++)
    {
        if(ch[i]=='A')
            j++;
        else if(ch[i]=='B')
            l++;
    }
    if(j==2 || l==2)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {

	ll x, y;
	cin >> x >> y;
	string ans;
	if (abs(x - y) <= 1) {
		ans = "Brown";
	}
	else {
		ans = "Alice";
	}
	cout << ans << endl;
}





Measured memory_bytes: 256
import itertools
import copy

N, M = map(int, input().split())
L = []

for i in range(M):
    k = list(map(int, input().split()))
    l = [i-1 for i in k[1:]]  # indexを渡していることに注意
    L.append(l)

p = list(map(int, input().split()))


def calc(idx, lampe):
    if idx == N:
        ans = 0
        for l in range(M):
            s = [lampe[v] for v in L[l]]
            if sum(s) % 2 != p[l]:
                return 0

        return 1

    ans = 0
    ans += calc(idx+1, lampe)
    lampe2 = copy.copy(lampe)
    lampe2[idx] = 1
    ans += calc(idx+1, lampe2)
    return ans


ans = calc(0, [0]*N)
print(ans)


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

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

int main() {
    int H,W,A,r=0;
    cin >> H >> W;
    vector<vector<int>> c(10, vector<int>(10));

    rep(i,10)
        rep(j,10)
            cin >> c.at(i).at(j);

    rep(i,10)
        rep(j,10)
            rep(k,10)
                c.at(i).at(j) = min(c.at(i).at(j), c.at(i).at(k)+c.at(k).at(j));
    rep(i,10)
        rep(j,10)
            rep(k,10)
                c.at(9-i).at(9-j) = min(c.at(9-i).at(9-j), c.at(9-i).at(9-k)+c.at(9-k).at(9-j));

    rep(i,H)
        rep(j,W) {
            cin >> A;
            if(A==1 || A==-1)
                continue;
            r += c.at(A).at(1);
        }

    cout << r << endl;
}

Measured memory_bytes: 256