akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#include <atcoder/all>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
using namespace atcoder;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main() {
    int t;
    scanf("%d", &t);
    rep(tt, t) {
        lint n, m, a, b;
        scanf("%lld%lld%lld%lld", &n, &m, &a, &b);
        printf("%lld\n", floor_sum(n, m, a, b));
    }
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	int  sum = 0;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		sum += a[i] - 1;
	}
	cout << sum << endl;

	return 0;
}

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

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); } } init_;

int main() {
    constexpr int n = 1e5;
    vector<int> p(n, 1);
    p[0] = p[1] = 0;
    for (int i = 2; i * i < n; i++) {
        if (p[i]) {
            for (int j = 2; i * j < n; j++) {
                p[i * j] = 0;
            }
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        if (p[i] && !p[(i+1)/2]) {
            p[i] = 0;
        }
    }
    partial_sum(p.begin(), p.end(), p.begin());
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << p[r] - p[l-1] << '\n';
    }
}


Measured memory_bytes: 1024
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int main(int argc, char const *argv[]) {
	int N;
	cin >> N;
	std::vector<vector<int> > G(N, vector<int>(N));
	for (int i = 0; i < N; ++i) {
		int u, k;
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; ++j) {
			int v;
			cin >> v;
			v--;
			G[u][v] = 1;
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			cout << G[i][j];
			if (j != N - 1) {
				cout << " ";
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}

ll kaijou(ll n){
  if(n==0) return 1;
  return ((n%1000000007)*(kaijou(n-1)%1000000007))%1000000007;
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}

ll comb(ll a, ll b){
 // cout<<a<<b<<endl;
  if((b)==0) return 1;
  return (a%1000000007)*(comb(a-1, b-1));
}

const int MAX = 1000000;
const int MOD = 1000000007;

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

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

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

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

   ll a,b;
  ll sum = 0;

  // 前処理
    COMinit();

   a = 0;
   while(1){
    b = x -2*a;
    if(b<0){
      break;
    }

    if(y == 2*b+a){
      //a+bCa;
      sum += COM(a+b, a);
    }
  
    sum = sum%MOD;
    a++;
  }

  cout<<sum<<endl;

    return 0;
}

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

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

    int n, m;
    cin >> n >> m;
    int vote = 0;
    int num = 0;
    int a[n];
    for(int i = 0; i < n; i++) {
    	cin >> a[i];
    	vote += a[i];
    }
    for(int i = 0; i < n; i++) {
    	if(a[i] >= (vote + 4 * m - 1) / (4 * m)) {
    		num++;
    	}
    }
    if(num >= m) {
    	cout << "Yes" << endl;
    }else {
    	cout << "No" << endl;
    }
}

Measured memory_bytes: 256
def examC():
    N = I()
    A = LI()
    d0 = defaultdict(int); d0[0] = 0
    d1 = defaultdict(int); d1[0] = 0
    for i in range(N):
        if i%2==0:
            d0[A[i]] +=1
        else:
            d1[A[i]] +=1
    n0 = sorted(d0.items(),key=lambda x:x[1])
    n1 = sorted(d1.items(),key=lambda x:x[1])
#    print(n0); print(n1)
    if n0[-1][0]!=n1[-1][0]:
        ans = N - n0[-1][1] - n1[-1][1]
    else:
        ans = N - max(n0[-1][1]+n1[-2][1],n0[-2][1]+n1[-1][1])
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,ALPHABET
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]
ALPHABET = [chr(ord('A') + i) for i in range(26)]

if __name__ == '__main__':
    examC()


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

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

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

#define endl '\n'
#define precise(n,k) fixed << setprecision(k) << n
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define uint  unsigned int
#define ll    long long
#define ull   unsigned long long
#define ld    long double

const int MOD = int(1e9+7);
const int oo  = int(1e9 + 20);
const ll lloo  = (ll)(1e18 + 10);


class SegmentTree {
    int NEUTRAL = -oo;
    int n;
    vector<int> tree;
public:
    
    SegmentTree(vector<int> values) {
        n = values.size();
        tree.resize(n*2);
        // Build
        for (int i=0; i < n; i++){
            tree[n+i] = values[i];
        }
        for (int i = n - 1; i > 0; --i) {
            tree[i] = max(tree[i<<1], tree[i<<1 | 1]);
        }
    }
    
    void update(int index, int value) {
        tree[index+n] = value;
        index = index + n;
        for (int i = index; i > 1; i >>= 1){
            tree[i>>1] = max(tree[i], tree[i^1]);
        }
    }
    int query(int l, int r) {
        int ans = NEUTRAL;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l&1) {
                ans = max(ans, tree[l++]);
            }
            if (r&1) {
                ans = max(ans, tree[--r]);
            }
        }
        return ans;
    }
};



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    n++;
    vector<int> val(n);
    for(int i = 1; i < n; ++i) {
        cin >> val[i];
    }
    SegmentTree st(val);
    
    vector<bool> visited(n, false);
    int colors = 0;
    int last;
    for(int i = 1; i < n; ++i) {
        if(!visited[i]) {
            colors++;
            last = val[i];
            visited[i] = true;
            st.update(i, -oo);
            
            if(st.query(i+1, n) <= last) continue;
            
            for(int j = i + 1; j < n; ++j) {
                if(!visited[j] && last < val[j]) {
                    last = val[j];
                    visited[j] = true;
                    st.update(j, -oo);
                    if(st.query(j+1, n) <= last) break;
                }
            }
        }
    }
    cout << colors << endl;

    return 0;
}

Measured memory_bytes: 4752
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 2000000000000
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    ll k;
    cin>>s;
    cin>>k;
    char c='*';
    for(int i=0;i<s.length();++i)
    {
        if(c=='*'&&s[i]!='1')
        {
            cout<<s[i];
            return 0;
        }
        if(i+1>=k)
        {
            cout<<"1";
            return 0;
        }
    }
}

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

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

    char X, Y;
    cin >> X >> Y;

    if(X > Y) {
        cout << ">" << endl;
    } else if(Y > X) {
        cout << "<" << endl;
    } else {
        cout << "=" << endl;
    }
}

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#include <functional>
#include <bitset>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmax(T &a, const T&b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T&b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

vector<int> parent(1000010);
vector<P> sz(1000010);

void init(int n) {
	for (int i = 0; i < 100000; i++) {
		parent[i] = i;
		sz[i] = P(1, 0);
	}
	for (int i = 100000; i < 200000; i++) {
		parent[i] = i;
		sz[i] = P(0, 1);
	}
}

int find(int x) {
	if (parent[x] == x) return x;
	else return parent[x] = find(parent[x]);
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (sz[x].first + sz[x].second < sz[y].first + sz[y].second) {
		parent[x] = y;
		sz[y].first += sz[x].first;
		sz[y].second += sz[x].second;
	}
	else {
		parent[y] = x;
		sz[x].first += sz[y].first;
		sz[x].second += sz[y].second;
	}
}

int main() {
	int n;
	cin >> n;
	init(n);
	vector<int> x(n), y(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		x[i]--; y[i]--;
		y[i] += 100000;
		unite(x[i], y[i]);
	}
	set<int> st;
	ll ans = 0;
	for (int i = 0; i < 200000; i++) {
		if (!st.count(find(i))) {
			ll c = sz[find(i)].first*sz[find(i)].second;
			st.insert(find(i));
			ans += c;
		}
	}
	cout << ans - n << endl;
}

Measured memory_bytes: 29952
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  int N; cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A.at(i);
  vector<int> B(N);
  rep(i, N) cin >> B.at(i);
  vector<int> C(N);
  rep(i,N-1) cin >> C.at(i);
  int satisfaction = 0;
  rep(i, N) {
    int ind = A.at(i);
    satisfaction += B.at(ind-1);
    if (i < N-1) {
      if (A.at(i)+1 == A.at(i+1)) {
        satisfaction += C.at(ind-1);
      }
    }
  }
  cout << satisfaction << endl;
}

Measured memory_bytes: 256
import math
#import itertools
#import statistics
#import numpy as np
import collections
n = int(input())
#a = list(map(int, input().split()))
#a = list(map(int, input().split()))
s = []
for i in range(n):
    s.append(input())
m = int(input())
t = []
for j in range(m):
    t.append(input())

s2 = collections.Counter(s)
t2 = collections.Counter(t)
point = 0
ans  = 0
#print(s2)
#print(t2)
for i in s2.keys():
    for j in t2.keys():
        if i==j:
            point = s2.get(i)-t2.get(j)
            #print(i+j+""+str(point))
            break
        else:
            point = s2.get(i)
    #print(point)
    if ans < point:
        ans = point

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   ll k,n;
   cin>>k>>n;
   
   ll arr[n];
   rep(n)
        cin>>arr[i];
   ll ans = 0;
   for(ll i=1;i<n;i++)
        ans+=arr[i]-arr[i-1];
   ans+=abs(k-arr[n-1]+arr[0]);    
   ll fans = ans;
   for(ll i=0;i<n;i++)
   {
       ll prev;
       if(i == 0)
            prev = arr[0]+k-arr[n-1];
       else prev = arr[i]-arr[i-1];
       fans = min(fans,ans-prev);
   }
   cout<<fans;
   
   
   return 0;        
}  
   

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
  int n,a[3],b;
  cin>>n;
  for(int j=0;j<n;j++){
    b=0;
  cin>>a[0]>>a[1]>>a[2];
  if(a[0]*a[0]==a[1]*a[1]+a[2]*a[2])b=1;
  else if(a[1]*a[1]==a[0]*a[0]+a[2]*a[2])b=1;
  else if(a[2]*a[2]==a[0]*a[0]+a[1]*a[1])b=1;
  if(b==1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main()
{
    int n;
    cin >> n;
    int a, b;
    cin >> a >> b;
    vector<int> v(n);

    int c1=0, c2=0, c3=0;
    rep(i, n)
    {cin >>v[i];
        if (v[i] <= a)
        {
            c1++;
        }
        else if (v[i] > b)
        {
            c3++;
        }
        else
        {
            c2++;
        }
    }
    cout << min(c1, min(c2, c3)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <map>
#include <iomanip>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <queue>
#define pb push_back
#define mk make_pair
#define ll long long
#define fast ios_base::sync_with_stdio(false);
using namespace std;
int main()
{
	ll int n,k,b,s=0;
	cin>>n>>k;
	vector<int >v;
	for(int i=0;i<n;i++)
	{
		cin>>b;
		v.pb(b);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++)
	{
		if(i<n-k)
		{
			s+=v[i];
		}
		
	}
	cout<<s;
}



Measured memory_bytes: 1400
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
#define MAX_V 500
#define INF 1e9
#define f(i,n) for(int i=0;i<n;i++)
#define memu memset(used,0,sizeof(used))
int G[MAX_V][MAX_V],V,E,Q,F,T,m,a,b;
bool used[MAX_V];
void add_edge(int from,int to){
    G[from][to]=G[to][from]=1;
}
void erase_edge(int from,int to){
    G[from][to]=G[to][from]=0;
}
int dfs(int v,int t,int f){
    if(v==t)return f;
    used[v]=true;
    f(i,V){
        if(!used[i]&&G[v][i]>0){
            int d=dfs(i,t,min(f,G[v][i]));
            if(d>0){
                G[v][i]-=d;
                G[i][v]+=d;
                return d;
            }
        }
    }
    return 0;
}
int max_flow(int s,int t){
    int flow=0;
    while(1){
        memu;
        int f=dfs(s,t,INF);
        if(f==0)return flow;
        flow += f;
    }
}
int main(){
    scanf("%d%d%d",&V,&E,&Q);
    f(i,E){
        scanf("%d%d",&F,&T);
        add_edge(F-1,T-1);
    }
    int now=max_flow(0,V-1);
    f(i,Q){
        scanf("%d%d%d",&m,&a,&b);
        a--,b--;
        if(m==1){
            add_edge(a, b);
            now+=max_flow(0,V-1);
        } else {
            int c=G[a][b];
            erase_edge(a, b);
            if(c>1){
                swap(a,b);
            }
            if(c!=1){
                memu;
                int f=dfs(a,b,1);
                if(f==0){
                    memu;
                    dfs(a, 0, 1);
                    memu;
                    dfs(V-1,b,1);
                    now--;
                }
            }
        }
        printf("%d\n",now);
    }
}

Measured memory_bytes: 2192
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#define IFD(...)
#ifndef NDEBUG
#define NDEBUG
#endif
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <boost/hana/functional/fix.hpp>
using boost::hana::fix;
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, b, a) for (int i = (b); i >= (a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    vector<pair<i64, i64>> xy(n);
    rep(i, n)
    {
        cin >> xy[i].first >> xy[i].second;
    }
    sort(xy.rbegin(), xy.rend());

    constexpr i64 INF = 1000'000'000;
    i64 p = 0, q = -INF;
    i64 ans = 0;
    for (auto &[x,y] : xy)
    {
        chmax(p, x + y);
        chmax(q, x - y);

        chmax(ans, p - x - y);
        chmax(ans, q - x + y);
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 6336
#include <stdio.h>
#include <limits.h>
#define H 200000
int v[H+1];

int main(void){
    for(size_t i=0; i<H+1; i++){ v[i] = INT_MAX; }
    int h, w, n, x, y;
    scanf("%d %d %d\n", &h, &w, &n);
    for(int i=0; i<n; i++){
        scanf("%d %d\n", &x, &y);
        v[x] = y<v[x] ? y : v[x];
    }
    int right = 1;
    for(int x=1; x<h; x++){
        if(v[x+1]<right+1){
            printf("%d\n", x);
            return 0;
        }else if(v[x+1]>right+1){
            right++;
        }
    }
    printf("%d\n", h);
    return 0;
}


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

const ll MAX = 4000010;
const ll MOD = 1e9 + 7;
long long fac[MAX], finv[MAX], inv[MAX];
 
 
void COMinit() {
 fac[0] = fac[1] = 1;
 finv[0] = finv[1] = 1;
 inv[1] = 1;
  for (ll i = 2; i < MAX; i++){
  fac[i] = fac[i - 1] * i % MOD;
  inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
       finv[i] = finv[i - 1] * inv[i] % MOD;
        }
      }
 
   long long COM(ll n, ll k){
  if (n < k){ return 0;}
  if (n < 0 || k < 0) {return 0;}
     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
     }



int main(){
  COMinit();
  ll N,K; cin >> N >> K;
  vector<ll> A(N);
  
  for(ll i = 0; i < N; i++){ cin >> A[i];}
  
  sort(A.begin(),A.end());
  
  ll M = 0; ll m = 0;
  
  for(ll i = 0; i <= N-K; i++){
    m += A[i]*COM(N-i-1,K-1);
    m %= MOD;
  }
  
  for(ll i = K-1; i < N; i++){ 
    M += A[i]*COM(i,K-1);
    M %= MOD;
  }
  
  cout << (MOD+M-m)%MOD << endl;
  
  return 0;
}

Measured memory_bytes: 94720
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,sum = 0,tmp,cnt = 100000000,i;
    vector<int>v;
    cin>>a;
    for(i = 0;i < a;i++)
    {
        cin>>b;
        v.push_back(b);
    }
    for(i = 1;i <= 100;i++)
    {
        sum = 0;
        for(int j=0;j < a;j++)
        {
            sum+=abs(i-v[j])*abs(i-v[j]);
        }
        cnt = min(sum,cnt);
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <queue>
 
#define LL long long
 
using namespace std;
 
int a, b;
 
int main()
{
	//freopen("test_in.txt", "r", stdin);
	//freopen("test_out.txt", "w", stdout);
	int t;
	cin>>t;
	while(t--)
	{
		cin>>a>>b;
		LL p = 1ll*a*b-1, x;
		for(x = sqrt(p)-2; x <= sqrt(p)+2; x++)
			if(x*x<=p && (x+1)*(x+1) > p)	break;
		LL ans = x*2-(a<=x)-(b<=x)-(1ll*x*x<=p && 1ll*x*(x+1)>p);
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
int main(void)
{
	int n,pm[10000],pe[10000],pj[10000],i,j;
	scanf("%d",&n);
	while(n!=0){
		j=0;
		for(i=0;i<n;i++)
			scanf("%d %d %d",&pm[i],&pe[i],&pj[i]);
		for(i=0;i<n;i++){
			if(pm[i]==100||pe[i]==100||pj[i]==100||(pm[i]+pe[i])/2>=90||(pm[i]+pe[i]+pj[i])/3>=80)
				printf("A\n");
			else if((pm[i]+pe[i]+pj[i])/3>=70||(pm[i]+pe[i]+pj[i])/3>=50&&pm[i]>=80||(pm[i]+pe[i]+pj[i])/3>=50&&pe[i]>=80)
				printf("B\n");
			else
				printf("C\n");
		}
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
int main(){
	
	std::string str;
	int stack[101];
	int count=-1;

	while(std::cin >> str){
		count++;

		if(str=="+"){
			stack[count-2]=stack[count-2]+stack[count-1];
			stack[count]=0;
			stack[count-1]=0;
			count=count-2;
		}else if(str=="-"){
			stack[count-2]=stack[count-2]-stack[count-1];
			stack[count]=0;
			stack[count-1]=0;
			count=count-2;
		}else if(str=="*"){
			stack[count-2]=stack[count-2]*stack[count-1];
			stack[count]=0;
			stack[count-1]=0;
			count=count-2;
		}else if(str==" "){
			count--;
		}else{
			
			stack[count]=atoi(str.c_str());
		}
		
	}
	
	std::cout<<stack[0]<<"\n";
	return 0;
}



Measured memory_bytes: 3172
S = input()

ans = [S[0]]

for i in range(1,len(S)):
    candidate = []
    for j in ans:
        candidate.append(j+S[i])
        candidate.append(j+'+'+S[i])
        ans = candidate

num = []
for a in ans:
    num.append(eval(a))

print(sum(num))

Measured memory_bytes: 3060
conditions = input().split(' ')
n = int(conditions[0])
k = int(conditions[1])

counts = []
datas = []
for i in range(k):
    counts.append(int(input()))
    datas.append(input().split(' '))
    datas[i] = [int(x) for x in datas[i]]

s = set()
for i in range(n):
    s.add(i+1)

for d in datas:
    ss = set(d)
    s -= ss

print(len(s))

Measured memory_bytes: 9248
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
double dp[305][305][305];
ll n;
double dfs(int a,int b,int c){
    if(dp[a][b][c]!=0)return dp[a][b][c];
    if(a==0&&b==0&&c==0)return 0;
    if(a)dp[a][b][c]+=dfs(a-1,b,c)*a/(double)(a+b+c);
    if(b)dp[a][b][c]+=dfs(a+1,b-1,c)*b/(double)(a+b+c);
    if(c)dp[a][b][c]+=dfs(a,b+1,c-1)*c/(double)(a+b+c);
    dp[a][b][c]+=n/(double)(a+b+c);
    return dp[a][b][c];
}
int main(){
    cin>>n;
    ll a=0,b=0,c=0;
    rep(i,n){
        ll k;cin>>k;
        if(k==1)a++;
        else if(k==2)b++;
        else c++;
    }
    decimal;
    out(dfs(a,b,c));
}

Measured memory_bytes: 112612
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#include<functional>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.20f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 998244353
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define cotu cout
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

template<typename T>
class SegTree{
    int n;
    vector<T> data;
    T def;
    function<T(T,T)> operation;
    function<T(T,T)> update;

    T _query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return def;

        if(a <= l && r <= b) return data[k];
        else{
            T c1 = _query(a, b, 2*k+1, l, (l+r)/2);
            T c2 = _query(a, b, 2*k+2, (l+r)/2, r);
            return operation(c1, c2);
        }
    }

    public:

    SegTree(size_t _n, T _def, function<T(T,T)> _operation,
        function<T(T,T)> _update) : def(_def), operation(_operation), update(_update){
            n = 1;
            while(n < _n){
                n *= 2;
            }
            data = vector<T>(2*n-1, def);
    }

    void change(int i, T x){
        i += n-1;
        data[i] = update(data[i], x);
        while(i > 0){
            i = (i-1)/2;
            data[i] = operation(data[i*2+1], data[i*2+2]);
        }
    }

    T query(int a, int b){
        return _query(a, b, 0, 0, n);
    }

    T operator[](int i){
        return data[i+n-1];
    }
};

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    SegTree<ll> st(n,0,[](ll a, ll b){return (a+b)%MOD;}, [](ll a, ll b){return (a+b)%MOD;});
    vector<pair<int,int>> v(k);
    vector<ll> dp(n+1, 0);
    rep(i,0,k) cin >> v[i].fs >> v[i].sc;
    dp[0] = 1LL;
    st.change(0,dp[0]);

    rep(i,1,n){
        rep(j,0,k){
            int left = max(0, i - v[j].sc);
            int right = i - v[j].fs + 1;
            if(right < 1) continue;
            dp[i] += (st.query(left, right) % MOD + MOD) % MOD;
        }
        st.change(i, dp[i]);
    }
    cout << dp[n-1] % MOD << enld;
    return 0;
}

Measured memory_bytes: 9028
import java.util.Scanner;
import java.util.Collections;
import java.util.Arrays;
import java.math.BigInteger;

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

        BigInteger[] a = new BigInteger[n];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextBigInteger();
            if(a[i].equals(BigInteger.valueOf(0))) {
                System.out.println(0);
                System.exit(0);
            }
        }
        sc.close();
        java.util.Arrays.sort(a, Collections.reverseOrder());

        BigInteger ans = BigInteger.valueOf(1);
                   //1000000000000000000
        BigInteger limit = BigInteger.valueOf(1000000000000000000L);
        for(int i=0; i<n; i++) {
            ans = ans.multiply(a[i]);
            if(ans.compareTo(limit) > 0) {
                System.out.println(-1);
                System.exit(0);
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 67544
#masoyさんのコード

import numpy as np

N, Ma, Mb = map(int, input().split())
U = N * 10

dp = np.zeros((U + 1, U + 1), dtype = np.int64)
temp = np.zeros_like(dp)

INF = 10 ** 18
dp += INF
dp[0, 0] = 0

for _ in range(N):
    a, b, c = map(int, input().split())
    temp[:] = dp.copy()
    temp[a:, b:] = np.minimum(temp[a:, b:], dp[:-a, :-b] + c)
    dp = temp #毎回、一つ前の結果を残す

answer = INF
for t in range(1, 401):
    a = Ma * t
    b = Mb * t
    if max(a, b) >= U: #到達できない量に達したら終了
        break
    answer = min(answer, dp[a, b])

if answer == INF:
    answer = -1

print (answer)


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n);
    map<int, int> c1, c2;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        if (i % 2 == 0) c1[v[i]]++;
        else c2[v[i]]++;
    }

    using P = pair<int, int>;
    vector<P> v1;
    for (auto& p : c1) {
        v1.emplace_back(p.second, p.first);
    }
    sort(v1.rbegin(), v1.rend());

    vector<P> v2;
    for (auto& p : c2) {
        v2.emplace_back(p.second, p.first);
    }
    sort(v2.rbegin(), v2.rend());
    
    if (v1[0].second != v2[0].second) {
        cout << n - v1[0].first - v2[0].first << endl;
    } else {
        int ans = min(n - v1[0].first, n - v2[0].first);
        if (v1.size() > 1) {
            ans = min(ans, n - v1[1].first - v2[0].first);
        }
        if (v2.size() > 1) {
            ans = min(ans, n - v1[0].first - v2[1].first);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 6524
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;
ll const MAX = 1e18;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1;

  rep(i, n) {
    if (MAX / ans < a[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

using int64 = long long;

template< typename Monoid >
struct SegmentTree
{
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x)
  {
    seg[k + sz] = x;
  }

  void build()
  {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x)
  {
    k += sz;
    seg[k] = x;
    while(k > 1) {
      k >>= 1;
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b)
  {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const
  {
    return seg[k + sz];
  }
};


int main()
{
  int N, Q;
  scanf("%d %d", &N, &Q);
  SegmentTree< int > seg(N, [](int a, int b) { return min(a, b); }, INT_MAX);
  while(Q--) {
    int T, X, Y;
    scanf("%d %d %d", &T, &X, &Y);
    if(T == 0) seg.update(X, Y);
    else printf("%d\n", seg.query(X, Y + 1));
  }
}



Measured memory_bytes: 3888
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

ll dp[310][310][310];

int main(){
    int N,K; cin >> N >> K;
    vector<int> H(N);
    rep(i,N) cin >> H[i];
    rep(i,310)rep(j,310)rep(k,310) dp[i][j][k] = LINF;
    dp[0][0][0] = 0;
    rep(i,N)rep(j,K+1)rep(k,j+1){
        if(i-k >= 0) dp[i+1][j][0] = min(dp[i+1][j][0],dp[i][j][k]+max(0,(i-k == -1?H[i]:H[i]-H[i-k-1])));
        dp[i+1][j+1][k+1] = min(dp[i+1][j+1][k+1],dp[i][j][k]);
    }
    ll ans = LINF;
    rep(i,K+1)rep(j,i+1){
        ans = min(ans,dp[N][i][j]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 232960
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

vector<long long> divisor(long long n) {
	vector<long long> res;
	for (long long i = 1; i * i <= n; i++) {
  	if (n % i == 0) {
			res.push_back(i);
			if (i != n / i) res.push_back(n / i);
		}
	}
	SORT(res);
	return res;
}

int main(){	
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	ll sum = 0;
	rep(i, N) {
		cin >> A[i];
		sum += A[i];
	}
	ll res = 0;
	for (auto x : divisor(sum)) {
		ll cnt = 0, r = 0;
		vector<ll> b(N);
		copy(A.begin(), A.end(), b.begin());
		rep(i, N) {
			b[i] = b[i] % x;
		}
		SORT(b);
		vector<ll> summ(N+1), sump(N+1);
		repn(i, N) {
			summ[i] = summ[i-1] + b[i-1]; 
			sump[i] = sump[i-1] + x - b[i-1];
		}
		ll now = INF;
		rep(i, N+1) {
			now = min(now,max(summ[i], sump[N]-sump[i]));
		}
		if (now <= K) res = x;
	}
	cout << res << endl;
}


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

const int MOD = (int)1e9+7;

int main(){
	string S,T;
	cin >> S >> T;

	int ans=0;
	for(int i=0;i<S.size();i++){
		if(S.at(i)==T.at(i))	ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    vector<int>p(n+1);
    vector<int>c(n+1);
    for(int i=1;i<=n;i++)
        cin>>p[i];
    for(int i=1;i<=n;i++)
        cin>>c[i];
    long long ans=-2e18;
    for(int i=1;i<=n;i++)
    {
        int cur=i;
        long long sum=0;
        vector<long long> temp;
        while(p[cur]!=i)
        {
            sum+=c[p[cur]];
            temp.push_back(sum);
            cur=p[cur];
        }
        sum+=c[i];
        temp.push_back(sum);
        int sz=(int)temp.size();
        ans=max(ans,*max_element(temp.begin(),temp.begin()+min(k,sz)));
        if(k>sz)
        {
            ans=max(ans,(k/sz)*(temp[sz-1])+((k%sz>0)?(*max_element(temp.begin(),temp.begin()+k%sz)):0));
            ans=max(ans,(k/sz-1)*(temp[sz-1])+*max_element(temp.begin(),temp.end()));
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3744
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	if a > b {
		a, b = b, a
	}

	if (b-a)%2 == 1 {
		fmt.Println("IMPOSSIBLE")
	} else {
		fmt.Println(a + (b-a)/2)
	}
}


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

const int LEN = 100;
const int UNVISITED = 0;
const int FOUND = 1;
const int DONE = 2;

// 再帰関数による深さ優先探索
void dfs_visit(int n, int u, vector<vector<int> >& M, vector<int>& status, vector<int>& d, vector<int>& f, int& tt){
    // 頂点uの訪問状態を「発見」にし,その時刻を記録
    status[u] = FOUND;
    d[u] = ++tt; // ttをインクリメントしてからd[u]に代入

    int v;
    for(v = 0; v < n; v++){
        if(M[u][v] == 0) continue; // 0:隣接していない
        if(status[v] == UNVISITED){
            dfs_visit(n, v, M, status, d, f, tt);
        }
    }

    // 頂点uの訪問状態を「完了」にし,その時刻を記録
    status[u] = DONE;
    f[u] = ++tt; // ttをインクリメントしてからf[u]に代入
}

void dfs(int n, vector<vector<int> >& M){
    vector<int> status(LEN); // status:頂点の訪問状態
    vector<int> d(LEN); // d:頂点の発見時刻
    vector<int> f(LEN); // d:頂点の完了時刻
    int tt; // tt:時刻

    // 初期化 (頂点uの訪問状態を「未訪問」に,また時刻を0に)
    int u;
    for(u = 0; u < n; u++){
        status[u] = UNVISITED;
    }
    tt = 0;

    // 未訪問のuを始点として深さ優先探索
    for(u = 0; u < n; u++){
        if(status[u] == UNVISITED){
            dfs_visit(n, u, M, status, d, f, tt);
        }
    }

    // 結果を出力
    for(u = 0; u < n; u++){
        cout << u + 1 << " " << d[u] << " " << f[u] << endl;
    }
}

int main(){
    int n; // n:頂点数
    vector<vector<int> > M(LEN, vector<int> (LEN)); //  M:頂点同士の隣接を表す行列
    int u, v, k, i, j; // 入力受け取り用

    // 頂点数を受け取り,隣接行列を初期化
    cin >> n;
    int m;
    for(m = 0; m < n; m++){
        for (j = 0; j < n; j++){
            M[m][j] = 0;
        }
    }

    // 頂点番号,出次数,隣接する頂点番号を受け取り,隣接行列に反映
    for(i = 0; i < n; i++){
        cin >> u >> k;
        u--;
        for(j = 0; j < k; j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs(n, M);

    return 0;
}


Measured memory_bytes: 3204
#include<stdio.h>
int main(){
double a,b,x1,x2,y1,y2,xq,yq,x,y,c,d;
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf\n",&x1,&y1,&x2,&y2,&xq,&yq)!=EOF){
a=x2-x1,b=y2-y1;
c=xq-x1,d=yq-y1;
x=(2*d*a*b+a*a*c-b*b*c)/(a*a+b*b);
y=(b*b*d-a*a*d+2*a*b*c)/(a*a+b*b);
x=x+x1,y=y+y1;
printf("%lf %lf\n",x,y);
}
return 0;
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
    int n,q;
    cin >> n;
    vll S(n);
    cin >> S;
    cin >> q;
    vll T(q);
    cin >> T;
    int cnt=0;
    for(auto t:T){
        bool flag = true;
        int left = 0;
        int right = n;
        int mid;
        while(flag){
            mid = (left+right)/2;
            if(S[mid] == t){
                cnt++;
                break;
            }else if(S[mid]>t){
                right = mid;
            }else{
                left = mid+1;
            }
            if(right == left)flag = false;

        }
    }
    cout << cnt << endl;
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';


struct UnionFind {
private:
    vector<int> par,sizes;
public:
    UnionFind (int n) {
        par.resize(n);
        sizes = vector<int>(n,1);
        for (int i = 0;i < n;++i) par[i] = i;
    }

    int find(int x) {
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x,int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x,y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x,int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return sizes[find(x)];
    }
};

int main() {
    int n,m;
    cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0;i < m;++i) {
        int a,b;cin >> a >> b;a--;b--;
        uf.unite(a,b);
    }    
    int ans = 0;
    for (int i = 0;i < n;++i) ans = max(ans,uf.size(i));
    cout << ans << endl;
}

Measured memory_bytes: 4836
from sys import exit, setrecursionlimit
setrecursionlimit(1000000)

def dfs(v, dp, to):
  t = dp[v]
  if t >= 0:
    return t
  dp[v] = 0
  t = 0
  for u in to[v]:
    res = dfs(u, dp, to)
    if res == 0:
      print('-1')
      exit()
    if res > t:
      t = res
  t += 1
  dp[v] = t
  return t

def toId(i, j, id_db):
  if i < j:
    return id_db[i][j]
  else:
    return id_db[j][i]

def main():
  N = int(input())
  a = [[int(e) - 1 for e in input().split()] for _ in range(N)]

  id_db = [[0] * N for _ in range(N)]

  dp = [-1] * (N * (N - 1) // 2)
  to = [[] for _ in range(N * (N - 1) // 2)]

  v = 0
  for i in range(N):
    for j in range(i + 1, N):
      id_db[i][j] = v
      v += 1

  for i in range(N):
    for j in range(N - 1):
      a[i][j] = toId(i, a[i][j], id_db)
    for j in range(N - 2):
      to[a[i][j + 1]].append(a[i][j])

  print(max(dfs(i, dp, to) for i in range(N * (N - 1) // 2)))

main()


Measured memory_bytes: 114840
from itertools import permutations
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

t = 0
x = 0
y = 0
for i in permutations(range(1,n+1), n):
  t += 1
  if i == p: x = t
  if i == q: y = t
print(abs(x-y))

Measured memory_bytes: 9196
<?php
while (true) {
  $s = trim(fgets(STDIN));
  if ($s == "-") break;
  $m = trim(fgets(STDIN));

  for ($i = 0; $i < $m; $i++) {
    $h = trim(fgets(STDIN));
    $head = substr($s, 0, $h);
    $tail = substr($s, $h);
    $s = $tail . $head;
  }

  echo $s . "\n";
}



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

namespace ABC140_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            Console.WriteLine(Math.Pow(N, 3));
        }
    }
}


Measured memory_bytes: 11220
#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;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int maxn = 1e6 + 5;
int n,m;

map<int,vector<pair<int,int>>> g; // x -> (dist,y)
map<int,int> loc;

bool dfs(int at, int coord) {
  loc[at] = coord;
  for (auto p: g[at]) {
    int to = p.second;
    int dst = p.first;
    int coord_to = coord + dst;
    if (loc.find(to)!=loc.end() && loc[to] != coord_to) {
      return false;
    }
    if (loc.find(to) != loc.end()) {
      continue;
    }
    if (!dfs(to, coord_to)) {
      return false;
    }
  }
  return true;
}

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

  cin>>n>>m;
  while (m--) {
    int l,r,d; cin>>l>>r>>d;
    g[l].push_back({d,r});
    g[r].push_back({-d,l});
  }

  for (auto p: g) {
    if (loc.find(p.first) == loc.end()) {
      if (!dfs(p.first, 0)) {
	out("No");
      }
    }
  }

  out("Yes");  

  return 0;
}


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

int main() {
	string a;
	cin>>a;
	 
	for (int i = 0; i < 3; i++) {
		if (a[i]== '1') {
			a[i] = '9';
		}
		else if(a[i]=='9') {
			a[i] = '1';
		}
	}
	
	cout<<a<<endl;
}

Measured memory_bytes: 256
//Prefix and Suffix

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) int n;cin>>n;vector<int>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    int n;
    string s,t;
    cin>>n>>s>>t;
    int a=0;
    rep(i,1,n+1){
        if(s.substr(n-i,i)==t.substr(0,i))a=i;
    }
    string r = s.substr(0,n-a)+t;
    cout<<r.size()<<nnn;
    return 0;
}

Measured memory_bytes: 256