akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long 
    #define ull unsigned long long 
    #define ld long double
    #define fi first
    #define se second
    #define pb push_back
    #define mp make_pair
    ll mod=1e9+7;
 
     ll a[200005];
       ll b[200005];
 
     ll idx[100005][2];
    // ll cnt[200005];
     ll pre[200005];
    // ll end[200005];
     map<ll,ll> m;
 
    bool comp(const pair<ll,ll>& a, const pair<ll,ll>& b){
      return (a.fi-a.se)>(b.fi-b.se);
    }
 
    bool revcomp(const pair<ll,ll>& a, const pair<ll,ll>& b){
      return (a.fi)>(b.fi);
    }
 
 
    ll ceil1(ll a, ll b){
      if(a%b!=0)return a/b+1;
      else return a/b;
    }
    ll power(ll a,ll b,ll n){ll ans=1;while(b>0){if(b%2==1)ans=(ans*a)%n;a=(a*a)%n;b/=2;}return ans;}
 
    ll count1=0;
 
 
    ll gcd(ll a, ll b){
      //if(a<b)swap(a,b);
      if(b==0)return a;
      return gcd(b,a%b);
    }
 
  ll primepos(ll fact, ll p) 
  { 
      ll res = 0; 
      while (fact > 0) {         
          res += fact / p; 
          fact /= p;  
      } 
    
      return res; 
  } 
 
  // void dfs(ll n, ll p){
  //   if(vis[n]!=0){
  //     return;
  //   }
  //   else{
  //     vis[n]=1;
  //     b[n]=p;
  //     for(int i=0;i<v[n].size();i++){
  //       dfs(v[n][i],p);
  //     }
  //   }
  // }

   int main(){

      ios::sync_with_stdio(0);
      ll n,W;
      cin>>n>>W;
      ll w[n],v[n];
      for(int i=0;i<n;i++){
        cin>>w[i]>>v[i];
      }
      ll dp[n+1][W+1];
      memset(dp,0,sizeof dp);
      for(int i=0;i<=n;i++){
        for(int j=0;j<=W;j++){
          if(i==0||w==0){
            dp[i][j]=0;
          }
          else if(w[i-1]<=j){
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
          }
          else{
            dp[i][j]=dp[i-1][j];
          }
        }
      }
      cout<<dp[n][W]<<endl;
      return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef unsigned long long ULL;
typedef long long LL;
void read(int& val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=1e9+7;
const int maxn =1e6+11;


int main(){
    int n,u,v;LL ans=0;
    read(n);
    fo(i,1,n){//长度为i
        ans += 1LL*(n-i+1)*i;
    }

    fo(i,1,n-1){
        read(u);read(v);
        ans -= 1LL*min(u,v)*(n-max(u,v)+1);
    }

    printf("%lld\n",ans);

    return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;



int main()
{
	int a, b;

	cin >> a >> b;

	if (a < b) cout << "a < b" << endl;
	else if (a > b) cout << "a > b" << endl;
	else cout << "a == b" << endl;

	return 0;
}



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

    using namespace std;

    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(6);
        int n;
        cin>>n;
        double ans= 2* (M_PI) * n;
        cout <<ans;
        return 0;
    }


Measured memory_bytes: 3696
#include<iostream>
#include<vector>
#include <algorithm>
#include<map>
#include<string>
#include<cstdio>
#include<set>
using namespace std;

//vector<int> name(size,syokiti);
//vector<vector<int>> name(size,vector<int>(size,syokiti));

int main(void)
{
	int n;
	set<int> st;
	cin >> n;
	for (int i = 0; i < n; i++){
		int x;
		cin >> x;

		st.insert(x);
	}
	
	cout << st.size() << 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 evenBalls = sc.nextInt();
        int oddBalls = sc.nextInt();
	    int result = execute(evenBalls,oddBalls);
        System.out.println(result);
    }

    public static int execute(int evenBalls, int oddBalls){
        //偶数と偶数、奇数と奇数でのみ組み合わせ
        return evenBalls*(evenBalls - 1)/2
                +oddBalls*(oddBalls - 1)/2;
    }
}

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

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

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

vector<int>dp(N);
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for(int i = 2; i < N; i++){ 
     int a, b;
     a = dp[i - 2] + abs(h[i] - h[i - 2]);
     b = dp[i - 1] + abs(h[i] - h[i - 1]);
     dp[i] = min(a, b);
}

cout << dp[N - 1]<< endl; 

}

Measured memory_bytes: 1024
#include <stdio.h>


int main(){

  int m,n,x1[200],y1[200],x2[1000],y2[1000],i,j,k,delx,dely;

  while(1){
    scanf("%d",&m);
    if(m == 0) break;
    for(i = 0;i < m;i++){
      scanf("%d",&x1[i]);
      scanf("%d",&y1[i]);
    }
    scanf("%d",&n);
    for(j=0;j<n;j++){
      scanf("%d",&x2[j]);
      scanf("%d",&y2[j]);
    }
    for(i=0;i<n;i++){
      delx = x2[i] - x1[0];
      dely = y2[i] - y1[0];
      for(j = 1;j<m;j++){
        for(k = 0;k<n;k++){
          if((x2[k] == x1[j] + delx)  && (y2[k] == y1[j] + dely)) break;
        }
         if(k == n) break;
      }
      if(j == m) break;
    }
    
    printf("%d %d\n",delx,dely);

  }

  return 0;

}

Measured memory_bytes: 0
#include <iostream>
#include <queue>
#include <vector>
#define MAX_N 8
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
vector<int> edge[MAX_N + 1];
int ENDH;

int dfs(int v, int h) {
  // cout << "v=" << v << " h=" << h << endl;
  if (h == ENDH) {
    return 1;
  }

  int ret = 0;
  for (auto itr = edge[v].begin(); itr != edge[v].end(); ++itr) {
    int nv = *itr;
    int mask = 0x01 << (nv - 1);
    if ((h & mask) != 0)
      continue;
    int nh = h | mask;
    ret += dfs(nv, nh);
  }
  return ret;
}

int main(void) {
  int N, M;
  cin >> N >> M;
  ENDH = 0;
  rep(i, N) { ENDH = (ENDH << 1) | 0x1; }
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  // dfs
  int ANS = dfs(1, 0x01);
  cout << ANS << endl;
  return 0;
}


Measured memory_bytes: 256
n  = int(input())
w = []

w.append(input())

ans = 'Yes'
for i in range(1,n,1):
  w.append(input())
  l = len(w[i-1])
  if w[i][0:1] != w[i-1][l-1:l]:
    ans = 'No'
    break
  for j in range(i):
    if w[i] == w[j]:
      ans = 'No'
      break

print(ans)


Measured memory_bytes: 3060
n, m, c = map(int,input().split())
b = list(map(int,input().split()))
ans = 0

for i in range(n):
  a = list(map(int,input().split()))
  x = 0
  for j in range(m):
    x += b[j]*a[j]
  if x + c > 0:
    ans += 1

print(ans)

Measured memory_bytes: 3060
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define N 102
ll C(ll a, ll b, ll c)
{
     return a*a + b*b + c*c + a*b + b*c + c*a ;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    map<ll,ll> mp;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            for(int k=1;k<=N;k++){
                ll val=C(i,j,k);
                mp[val]++;
            }
        }
    }
    int n; cin>>n;
    for(int i=1;i<=n;i++) cout<<mp[i]<<endl;
}

Measured memory_bytes: 6132
#include <iostream>
#include <map>
using namespace std;
map<int,string>mat;
map<int,string>mark;
int main(){
	int i,j,tmp;
	string ind;
	for(i=1;i<=3;i++)
		for(j=1;j<=3;j++){
			ind=to_string(i)+to_string(j);
			cin>>tmp;
			mat[tmp]=ind;
		}	
	int n,x;cin>>n;
	while(n--){
		cin>>tmp;
		auto x=mat.find(tmp);
		if(x!=mat.end())mark[tmp]=mat[tmp];
	}
	int r1=0,r2=0,r3=0,c1=0,c2=0,c3=0,d1=0,d2=0;
	for(auto it=mark.begin();it!=mark.end();it++){
		if(it->second=="11" || it->second=="12" || it->second=="13") r1++;if(it->second=="21" || it->second=="22" || it->second=="23") r2++;if(it->second=="31" || it->second=="32" || it->second=="33") r3++;
		if(it->second=="11" || it->second=="21" || it->second=="31") c1++;if(it->second=="12" || it->second=="22" || it->second=="32") c2++;if(it->second=="13" || it->second=="23" || it->second=="33") c3++;
		if(it->second=="11" || it->second=="22" || it->second=="33") d1++;if(it->second=="13" || it->second=="22" || it->second=="31") d2++;
	}
	if(r1==3 || r2==3 || r3==3 || c1==3 || c2==3 || c3==3 || d1==3 || d2==3)
		cout<<"Yes";else cout<<"No";

}

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

using namespace std;


int main () {

	ios_base::sync_with_stdio(false); cin.tie(NULL);


	string s;
	cin >> s;

	int cnt = 0;

	for (int i = 1; i < s.size(); ++i) {
		if (s[i] == s[i-1]) {
			if (s[i-1] == '1') s[i] = '0';
			else s[i] = '1';
			++cnt;
		}
	}


		cout << cnt << '\n';


	return 0;
}


Measured memory_bytes: 512
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        x: i64,
        k: i64,
        d: i64,
    }
    // annotate for rust-analyzer
    let x: i64 = x;
    let k: i64 = k;
    let d: i64 = d;

    let ans;
    let kk = x.abs() / d;
    if kk >= k {
        ans = x.abs() - k * d;
    } else {
        let n = x.abs() - kk * d;
        let remain = k - kk;
        if remain % 2 == 0 {
            ans = n;
        } else {
            ans = (n - d).abs();
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2148
#include <stdio.h>

int main() {
	char ch;

	while(1){
    scanf("%c", &ch);
    if ('a' <= ch && ch <= 'z') {
    	ch -= 32;
    	
    } else if ('A' <= ch && ch <= 'Z') {
    	ch += 32;
    } 
    printf("%c", ch);
    if ( ch == '\n' ) break;
	}
	
	return 0;
}


Measured memory_bytes: 2576
def c(a, b):
    if a is '0':   
        if b is '0':
            return False
    elif a is '1':
        if b is '0'or b is '1' or b is '2':
            return True
        else:
            return False
    else:
        return False
    return True


s = (input())

a = c(s[0],s[1])
b = c(s[2],s[3])

if a and b:
    print("AMBIGUOUS")
elif a:
    print("MMYY")
elif b:
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 3060
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        vector<int> a(n), b(n);
        long long suma = 0, sumb = 0;
        for (int i = 0; i < n; i ++) {
                scanf("%d", &a[i]);
                suma += a[i];
        }
        for (int i = 0; i < n; i ++) {
                scanf("%d", &b[i]);
                sumb += b[i];
        }
        long long diff = sumb - suma;
        if (diff < 0) {
                puts("No");
                return 0;
        }
        long long need = 0;
        for (int i = 0; i < n; i ++) {
                if (a[i] < b[i]) {
                        need += (b[i] - a[i] + 1) / 2;
                }
        }
        puts(need > diff ? "No" : "Yes");
        return 0;
}


Measured memory_bytes: 384
import random

def main():
    D = int(input())
    c_list = list(map(int, input().split()))
    s_list = [list(map(int, input().split())) for _ in range(D)]
    
    basic_bad = sum(c_list)

    # 初期解生成は必要っぽい
    res = 0
    bad = 0
    last_open = [0] * 26
    t_list = [0] * D
    for i in range(D):
        # find t
        t = 0
        max_val = s_list[i][0] - (basic_bad - (i+1 - last_open[0]) * c_list[0])
        
        for d in range(1,26):
            val = s_list[i][d] - (basic_bad - (i+1 - last_open[d]) * c_list[d])
            if val >= max_val:
                t = d

        t_list[i] = t 
        
        res += s_list[i][t]
        bad += basic_bad - (i+1 - last_open[t]) * c_list[t]
        last_open[t] = i+1

        res -= bad

    init_res = res

    # loop
    for m in range(10**5):
        d = random.randint(1,D)
        q = random.randint(0,25)

        pre_t = t_list[d-1]
        pre_res = init_res

        t_list[d-1] = q
        res = 0
        
        bad = 0
        last_open = [0] * 26
        for i in range(D):
            t = t_list[i]
            
            res += s_list[i][t]
            bad += basic_bad - (i+1 - last_open[t]) * c_list[t]
            last_open[t] = i+1

            res -= bad
            
        if pre_res > res:
            res = pre_res
            t_list[d-1] = pre_t

    # tが0-index
    for t in t_list:
        print(t+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 78836
import java.io.*;
import java.util.*;

public class Main {
    //-------------------------------------------------------------//
    public static final void main(String[] args) {
        new Main().solve();
    }
    //-------------------------------------------------------------//
    private final Scanner sc = new Scanner(System.in);
    void solve() {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (b - a == c - b) System.out.println("YES");
        else System.out.println("NO");

    }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  for (int i = 0, a, b; cin >> a >> b; i++) {
    G.at(--a).push_back(--b);
    G.at(b).push_back(a);
  }
  for (int i = 1; i < N - 1; i++) {
    int a = 0, b = 0;
    for (auto g : G.at(i)) {
      if (g == 0) a++;
      if (g == N - 1) b++;
    }
    if (a && b) return cout << "POSSIBLE" << "\n", 0;
  }
  cout << "IMPOSSIBLE" << "\n";
}

Measured memory_bytes: 15064
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vi v(n);
    priority_queue<double, vector<double>, greater<double>> pq;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        pq.push(v[i]);
    }
    while (pq.size() != 1) {
        double a = pq.top();
        pq.pop();
        double b = pq.top();
        pq.pop();
        pq.push((a + b) / 2);
    }
    cout << fixed << setprecision(10) << pq.top() << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
#define mod 924844033
int a[4001];
int prod[100001];
int f[4001][2001][2];
signed main()
{
	int n,k,cnt=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++)
		for(int j=i;j<=n;j+=k)
			a[++cnt]=j;
	for(int i=1;i<=k;i++)
		for(int j=i;j<=n;j+=k)
			a[++cnt]=j;
	prod[0]=1;
	for(int i=1;i<=n;i++)
		prod[i]=1ll*prod[i-1]*i%mod;
	f[1][0][0]=1;
	for(int i=2;i<=2*n;i++)
	{
		for(int j = 0; j <= min(n, i/2); ++j)
		{
			f[i][j][0]=(f[i-1][j][1]+f[i-1][j][0])%mod;
			if(j>0&&a[i]==a[i-1]+k) f[i][j][1]=f[i-1][j-1][0];
		}
	}
	int ans=prod[n];
	for(int i=1;i<=n;i++)
	{
		int sum=(f[2*n][i][0]+f[2*n][i][1])%mod;
		ans+=1ll*((i%2==1)?-1:1)*sum%mod*prod[n-i]%mod;
		ans%=mod;
	}
	printf("%d",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 61312
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        String s = scan.next();
        String t = scan.next();
        if (s.equals(t)) {
            System.out.println(N);
            return;
        }
        char[] d_s = s.toCharArray();
        char[] d_t = t.toCharArray();
        int max = 0;
        for (int i = N-2 ; 0 <= i; i--) {
            if (d_t[i] != d_s[N-1]) {
                continue;
            }
            boolean found = true;
            for (int j = i; 0 <= j; j--) {
                if (d_t[j] != d_s[N-1-(i-j)]) {
                    found = false;
                    break;
                }
            }
            if (found) {
                max = Math.max(max, i + 1);
            }
        }
        System.out.println(2 * N - max);
    }
}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
//		List<String> divisor = new ArrayList<>();
//		int[] in = Stream.of(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		int x = Integer.parseInt(sc.next());
//		int S = Integer.parseInt(sc.next());
//		String[] S = sc.next().split("");
		
//		for (int i = 1; i <= N; i++) {
//		}
		
		String res = x < 1200 ? "ABC" : "ARC";
		
		System.out.println(res);		
	}
}


Measured memory_bytes: 21716
#include<stdio.h>
#define EPS 0.0000001
int main(void){
    double x,y,a,b,c,d,e,f,i,j,r,p,n,m;
    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF){
        n = c * e - f * b;
        m = a * e - d * b;
        x = n / m;
        r = a * f - d * c;
        y = r / m;

        if(-EPS<=x&&x<=0)x=0;
        if(-EPS<=y&&y<=0)y=0;

        printf("%.3f %.3f\n",x,y);
    }

    return 0;
}

Measured memory_bytes: 652
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

int main()
{
    int i, j, k, n;
    double a[100],ans=0;
    scanf("%d", &n);
    for (i = 0; i < n;i++)
    {
        scanf("%lf", &a[i]);
        ans += (1 / a[i]);
    }
    ans = 1 / ans;
    printf("%.8lf", ans);
    return 0;
}

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

int X[12] = { 0,2,5,5,4,5,6,3,7,6};

int main() {
	int A, B, Q; cin >> A >> B >> Q;
	vector<long long> s(A+1,-1e12), t(B+1,-1e12), x(Q+1,1e12);
	for (int i = 1; i <= A; i++)cin >> s[i];
	for (int i = 1; i <= B; i++)cin >> t[i];
	for (int i = 1; i <= Q; i++)cin >> x[i];
	for (int i = 1; i <= Q; i++) {
		auto y = lower_bound(s.begin(), s.end(), x[i]);
		auto z = lower_bound(t.begin(), t.end(), x[i]);
		if (x[i] > s[A])y--;
		if (x[i] > t[B])z--;
		long long ans=1e12,a[4];
		a[0] = s[y-s.begin()]; a[1] = s[y-s.begin() - 1];
		a[2] = t[z - t.begin()]; a[3] = t[z - t.begin()-1];
		for(int j=0;j<=1;j++){
			for (int k = 2; k <= 3; k++) {
				long long u, t;
				u=abs(a[j]-x[i]) + abs(a[k] - a[j]);
				t= abs(a[k] - x[i]) + abs(a[k] - a[j]);
				ans = min(ans, u);
				ans = min(ans, t);
			}
		}
		cout << ans << endl;
	}
}




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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if ((a+b)>(c+d))
      cout << "Left";
  else if ((a+b)<(c+d))
      cout << "Right";
  else
      cout << "Balanced";
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, A[3], L[10];

	cin >> N;
	rep(i, 0, 3)cin >> A[i];
	rep(i, 0, N)cin >> L[i];
	sort(L, L + N);

	int ans = INF;
	rep(i, 0, (int)(pow(4, N)))
	{
		int ss[3] = { 0 };
		int sum[3] = { 0 };
		int ti = i;
		rep(j, 0, N)
		{
			if (ti % 4 != 3)
			{
				ss[ti % 4]++;
				sum[ti % 4] += L[j];
			}
			ti /= 4;
		}

		if (ss[0] == 0 || ss[1] == 0 || ss[2] == 0)continue;

		int res = 0;
		rep(j, 0, 3)
		{
			res += (ss[j] - 1) * 10 + abs(sum[j] - A[j]);
		}
		chmin(ans, res);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = 0;
		for (int i = 0; i < n; i++) {
			String a = sc.next();
			if (a.equals("Y")) {
				c++;
			}
		}
		if (c != 0) {
			System.out.println("Four");
		} else {
			System.out.println("Three");
		}
		sc.close();
	}

}


Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.function.BiConsumer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int n = in.nextInt();
			int k = in.nextInt();
			List<Double> list = new ArrayList<Double>();
			list.add(0.0);
			for (int i = 1; i <= 1000; i++) {
				double tmp = 0;
				for (int j = 1; j <= i; j++) {
					tmp += j / (double) i;
				}
				list.add(tmp);
			}

			// out.println(list.get(2));
			// out.println(list.get(4));
			// out.println(list.get(5));

			double ans = 0;
			double tmp = 0;
			int[] arr = new int[n + 1];
			for (int i = 1; i <= n; i++) {
				arr[i] = in.nextInt();
				tmp += list.get(arr[i]);
				if (i >= k) {
					// out.println(tmp);
					ans = Math.max(ans, tmp);
					// out.println("i-k" + arr[i - k]);
					tmp -= list.get(arr[i - k + 1]);
					// out.println(tmp);
				}
			}
			out.println(ans);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 41800
import java.util.Scanner

fun main(args: Array<String>) {
  val scanner = Scanner(System.`in`)
  val N = scanner.nextInt()
  val M = scanner.nextInt()
  val C = scanner.nextInt()
  val B = IntArray(M + 1)
  var ans = 0
  for (i in 1..M) {
    B[i] = scanner.nextInt()
  }
  for (i in 1..N) {
    var temp = C
    for (j in 1..M) {
      temp += B[j] * scanner.nextInt()
    }
    if (temp > 0) ans++
  }
  print(ans)
  scanner.close()
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}


int main() {
  string S;
  cin >> S;
  int ret = inf;
  for(int p = 0; p < 2; p++) {
    int add = 0;
    for(int i = 0; i < S.size(); i++) {
      if(i%2==p) add += S[i] == '0';
      else add += S[i] == '1';
    }
    chmin(ret, add);
  }
  cout << ret << endl;
}




Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);

		boolean[] spade = new boolean[13];
		boolean[] dia = new boolean[13];
		boolean[] club = new boolean[13];
		boolean[] heart = new boolean[13];

		int n = stdin.nextInt();
		for (int i = 0; i < n; ++i) {
			String markChar = stdin.next();
			int number = stdin.nextInt();
			boolean[] check = null;

			if (markChar.equalsIgnoreCase("S")) {
				check = spade;
			}
			if (markChar.equalsIgnoreCase("D")) {
				check = dia;
			}
			if (markChar.equalsIgnoreCase("C")) {
				check = club;
			}
			if (markChar.equalsIgnoreCase("H")) {
				check = heart;
			}
			check[number - 1] = true;
		}

		for (int i = 0; i < spade.length; ++i) {
			if (!spade[i]) {
				System.out.println("S " + (i + 1));
			}
		}

		for (int i = 0; i < heart.length; ++i) {
			if (!heart[i]) {
				System.out.println("H " + (i + 1));
			}
		}

		for (int i = 0; i < club.length; ++i) {
			if (!club[i]) {
				System.out.println("C " + (i + 1));
			}
		}

		for (int i = 0; i < dia.length; ++i) {
			if (!dia[i]) {
				System.out.println("D " + (i + 1));
			}
		}

	}
}

Measured memory_bytes: 26240
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N=100099;
int n, m, par[N];
bool pos[N];
vector<int> graf[N];
void bfs() {
    queue<int> q;
    q.push(1);
    while(!q.empty()) {
        int tren=q.front(); q.pop();
        for(auto adj:graf[tren]) {
            if(!pos[adj]) {
                pos[adj]=true;
                par[adj]=tren;
                q.push(adj);
            }
        }
    }
}
int main() {
    IOS; cin >> n >> m;
    for(int i=0; i<m; ++i) {
        int u,v; cin >> u >> v;
        graf[u].push_back(v);
        graf[v].push_back(u);
    }
    bfs();
    cout << "Yes\n";
    for(int i=2; i<=n; ++i) cout << par[i] << endl;
}


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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define INF 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;

int main(){
    int N;
    int ave = 0,ans = 0;
    cin >> N;
    int a[200];
    rep(i,N) cin >> a[i];
    rep(i,N) ave += a[i];
    ave = round((double)ave/N);
    rep(i,N) ans += (a[i]-ave)*(a[i]-ave);

    
    
    cout << ans;
    //printf("%.15lf",ans);
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100001

map<string,int> MAP;

struct Info{
	bool operator<(const struct Info &arg) const{
		return value > arg.value;
	}
	int value;
	string name;
	bool is_favorite;
};

int N,M,K,L;
int ally[NUM],enemy[NUM];
Info info[NUM];



bool strCmp(char* base, char* comp){
	int length1,length2;
	for(length1=0;base[length1] != '\0';length1++);
	for(length2=0;comp[length2] != '\0';length2++);
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

bool is_OK(int num){

	int sum = 0;

	if(ally[num-1] <= K-1)return true;

	int base_loc = enemy[K-num];

	for(int i = 0; i < num; i++){
		if(info[ally[i]].value > info[base_loc].value){
			sum += 0;
		}else if(info[ally[i]].value == info[base_loc].value){
			if(info[ally[i]].name < info[base_loc].name){
				sum += 0;
			}else{
				sum += 1;
			}
		}else{
			if(info[ally[i]].name < info[base_loc].name){
				sum += info[base_loc].value-info[ally[i]].value;
			}else{
				sum += info[base_loc].value-info[ally[i]].value+1;
			}
		}
		if(sum > L)return false;
	}
	return true;
}


void func(){

	MAP.clear();

	char buf[11];

	for(int i = 0; i < N; i++){
		scanf("%s %d",buf,&info[i].value);
		info[i].name = buf;
		info[i].is_favorite = false;
		MAP[info[i].name] = i;
	}

	string name;
	for(int loop = 0; loop < M; loop++){
		scanf("%s",buf);
		name = buf;
		info[MAP[name]].is_favorite = true;
	}

	sort(info,info+N);

	for(int i = 0; i < NUM; i++){
		ally[i] = BIG_NUM;
		enemy[i] = BIG_NUM;
	}

	int ally_index = 0,enemy_index = 0;

	for(int i = 0; i < N;i++){
		if(info[i].is_favorite){
			ally[ally_index++] = i;
		}else{
			enemy[enemy_index++] = i;
		}
	}


	int left = 0,right = min(K,M),m = (left+right)/2;
	int ans = 0;

	while(left <= right){
		if(is_OK(m)){
			ans = m;
			left = m+1;
		}else{
			right = m-1;
		}
		m = (left+right)/2;
	}
	printf("%d\n",ans);
}

int main(){

	while(true){
		scanf("%d %d %d %d",&N,&M,&K,&L);
		if(N == 0 && M == 0 && K == 0 && L == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 17336
#include<stdio.h>

#define Max 100000
#define S 1000000000

struct Card{
  char suit;
  int value;
};


struct Card L[Max / 2 + 2], R[Max / 2 + 2];

void mer(struct Card a[], int n, int l, int m, int r){
  int i, j, k, n1, n2;
  n1 = m - l;
  n2 = r - m;
  
  for(i = 0 ; i < n1 ; i++) 
                L[i] = a[l + i];
  for(i = 0 ; i < n2 ; i++) 
             R[i] = a[m + i];
  
  L[n1].value = R[n2].value = S;
  i = j = 0;
  
  for(k = l ; k < r ; k++){
    if(L[i].value <= R[j].value){
      a[k] = L[i++];
    }
    else{
      a[k] = R[j++];
    }
  }
}

void Sort(struct Card A[], int n, int l, int r){
  int m;
  if(l + 1 < r){
    m = (l + r) / 2;
    Sort(A, n, l, m);
    Sort(A, n, m, r);
    mer(A, n, l, m, r);
  }
}

int partition(struct Card A[], int n, int p, int r){
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p - 1;

  for(j = p ; j < r ; j++){
    if(A[j].value <= x.value){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }

  t = A[i + 1];
  A[i + 1] = A[r];
  A[r] = t;


  return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r){
  int q;
  if(p < r){
    q = partition(A, n, p, r);
    quickSort(A, n, p, q - 1);
    quickSort(A, n, q + 1, r);
  }
}


int main(){
  int n, i, v, stable = 1;
  struct Card A[Max], b[Max];
  char s[10];

  scanf("%d", &n);

  for(i = 0 ; i < n ; i++){
    scanf("%s %d", s, &v);
    A[i].suit = b[i].suit = s[0];
    A[i].value = b[i].value = v;
  }

  Sort(A, n, 0, n);
  quickSort(b, n, 0, n - 1);
  
  for(i = 0 ; i < n ; i++){
    if(A[i].suit != b[i].suit) 
             stable = 0;
  }

  if(stable == 1)
         printf("Stable\n");
  else  
         printf("Not stable\n");
  for(i = 0 ; i < n ; i++){
    printf("%c %d\n", b[i].suit, b[i].value);
  }

  return 0;
}




Measured memory_bytes: 4052
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N, M; cin >> N >> M;
    vector<vector<LLONG>> xyzs(3, vector<LLONG>(N));
    for (int i = 0; i < N; ++i)
    {
        cin >> xyzs[0][i] >> xyzs[1][i] >> xyzs[2][i];
    }
    LLONG ans = 10e-13;
    // x, y, zについて，それぞれ正負どちらの方向で絶対値を最大化するか全探索:O(N)
    for (int bit = 0; bit < (1 << 3); ++bit)
    {
        // bit全探索で符号を変えながら評価値の総和を計算:O(N)
        vector<LLONG> sums(N);
        for (int i = 0; i < N; ++i)
        {
            for (int xyz = 0; xyz < 3; ++xyz)
            {
                if (bit & (1 << xyz))
                {
                    sums[i] += xyzs[xyz][i];
                }
                else
                {
                    sums[i] -= xyzs[xyz][i];
                }
            }
        }
        // 合計の大きい順にM個選ぶ:O(NlogN)
        sort(sums.rbegin(), sums.rend());
        ans = max(ans, accumulate(sums.begin(), sums.begin() + M, 0LL));
    }
    cout << ans << endl;
}


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

using namespace std;

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

	vector<int> A(N);
	vector<int> B(N);
	vector<int> C(N - 1);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		--A.at(i);
	}
	for (int i = 0; i < N; i++) {
		cin >> B.at(i);
	}
	for (int i = 0; i < N - 1; i++) {
		cin >> C.at(i);
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans += B[A[i]];
		if (i > 0 && A[i] == A[i - 1] + 1) {
			ans += C[A[i - 1]];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for(auto i = (c).begin(); i != (c).end(); ++i)
#define BIT(n, m) (((n) >> (m)) & 1)

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

const ll inf = 1e15;
const ll mod = 1000 * 1000 * 1000 + 7;
const double eps = 1e-9;

template <typename S, typename T> ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  REP(i, v.size()){
    if (i > 0) out << ", ";
    out << v[i];
  }
  out << "]";
  return out;
}


const int MAX = 401;
map<vector<int>, int> M;

void rec(int p_pos, int n, int d_pos, vector<int> &P, vector<int> &D, vector<int> &C){
  if (p_pos == n){
    vector<int> R = P;
    sort(ALL(R));
    M[R]++;
  } else if (C[D[d_pos]] == 0){
    rec(p_pos, n, d_pos + 1, P, D, C);
  } else {
    REP(t, 2) if (t == 0 || D[d_pos]  * 2 != P[1]){
      bool ok = true;
      P[p_pos] = t == 0 ? D[d_pos] : P[1] - D[d_pos];
      REP(i, p_pos) {
        C[abs(P[p_pos] - P[i])]--;
        if (C[abs(P[p_pos] - P[i])] < 0) ok = false;;
      }
      if (ok) rec(p_pos + 1, n, d_pos, P, D, C);
      REP(i, p_pos) C[abs(P[p_pos] - P[i])]++;
    }
  }
}

int main(){
  int n;
  while (cin >> n && n){
    M.clear();
    vector<int> D(n * (n - 1) / 2);
    REP(i, n * (n - 1) / 2) cin >> D[i];
    vector<int> P(n);
    P[0] = 0;
    P[1] = D[0];
    vector<int> C(MAX);
    REP2(i, 1, D.size())  C[D[i]]++;
    rec(2, n, 0, P, D, C);
    for (const auto &p : M){
      const vector<int> &R = p.first;
      REP2(i, 1, R.size()) cout << (R[i] - R[i - 1]) << (i +  1 == R.size() ? '\n' : ' ');
    }
    cout << "-----" << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
n,k,q = map(int,input().split())

arr = []

for i in range(q):
    arr.append(int(input()))

arr2 = [0] * n

for j in arr:
    arr2[j-1] += 1

border = q - k
for m in range(n):
    if arr2[m] > border:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 8636
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 1e5 + 7;

vector<int> from[MAXN];
int result[MAXN], idx;
int dp[MAXN];

int dfs(int u)
{
    if (dp[u] || from[u].empty())
        return dp[u];
    for (int v : from[u])
        dp[u] = max(dp[u], 1 + dfs(v));
    return dp[u];
}

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    idx = n;
    for (int i = 0; i != m; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        from[u].push_back(v);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        if (!dp[i])
            ans = max(ans, dfs(i));
    printf("%d\n", ans);
}

Measured memory_bytes: 7424
/*
    A - B +/- A
    https://atcoder.jp/contests/abc118/tasks/abc118_a
*/
#include <bits/stdc++.h>
using namespace std;

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

    int a, b;
    cin >> a >> b;

    if (b % a == 0)
        cout << a + b << endl;
    else
        cout << b - a << endl;
}

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

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    if ((g * 10 + b) % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <numeric>// accumulate

using namespace std;
typedef long long ll;

int main(){
  string s;
  cin >> s;

  int N=s.size()+1;

  vector<ll> c(N,0);

  for(int i=0;i<N-1;i++){
    if(s[i]=='<'){
      c[i+1]=max(c[i]+1,c[i+1]);
    }
  }
  //for(int i=0;i<N-1;i++) cout << c[i] << s[i]; cout << c[N-1] << endl;
  for(int i=N-1;0<=i;i--){
    if(s[i]=='>'){
      c[i]=max(c[i],c[i+1]+1);
    }
  }
  //for(int i=0;i<N-1;i++) cout << c[i] << s[i]; cout << c[N-1] << endl;

  cout << accumulate(c.begin(),c.end(),(ll)0) << endl;

  return 0;
}

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

int n, a[1025][1025], vis[1025];
bool flag;
bool ok() {
  for (int i = 1; i <= n; i++)
    if (a[i][0] != n) return 0;
  return 1;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n - 1; ++j) cin >> a[i][j];
    a[i][0] = 1;
  }
  for (int z = 0; z <= 0x3f3f3f3f; z++) {
    if (ok()) {
      cout << z << '\n';
      return 0;
    }
    flag = 0;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; i++) {
      if (vis[i] || a[i][0] == n) continue;
      int x = a[i][a[i][0]];
      if (!vis[i] && !vis[x] && a[x][a[x][0]] == i) {
        a[i][0]++;
        a[x][0]++;
        vis[i] = vis[x] = 1;
        flag = 1;
      }
    }
    if (!flag) {
      cout << -1 << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define int long
using namespace std;
using pi=pair<int,int>;
main(){
	int n,m,r=0;
	cin>>n>>m;
	vector<pi> job(n);
	for(auto& p:job)cin>>p.first>>p.second;
	sort(job.begin(),job.end(),[](pi a,pi b){return a.first<b.first;});
	priority_queue<int> que;
	for(int day=1,pos=0;day<=m;++day){
		while(pos<n&&job[pos].first<=day)que.push(job[pos++].second);
		if(!que.empty()){r+=que.top();que.pop();}
	}
	cout<<r;
}

Measured memory_bytes: 2936
//by Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int,int>
#define p64 pair<ll,ll>
#define fi first
#define se second
#define ln '\n'
#define debug(x) cout << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream& operator<<(ostream& out, const pair<T,U>& p){
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename ...Args>
void print_container(const ContainerType<ValueType, Args...>& c){
	cout << "{ ";
	for(const auto& v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

int main()
{
	FASTIO;
	ll l,r;
	cin >> l >> r;
	ll temp = r / 2019;
	temp = 2019 * temp;
	if(l <= temp && temp <= r)
		cout << 0 << ln;
	else
	{
		ll ans = 1e18;
		for(ll i = l;i < r;i++)
			for(ll j = i + 1;j < r + 1;j++)
				ans = min(ans,mul(i,j,2019));
		cout << ans << ln;
	}
	return 0;
}


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

namespace Miscelleneous {
   class Program {
      public static int cin() { return int.Parse(Console.ReadLine()); }
      static HashSet<int> Prime;
      static void Main(string[] args) {
         Filt(50000);
         int n, Res = 0;
         while (true) { 
            n=cin();
            if (n==0) return;
            if ((n&1)==1) 
               Res=Prime.Contains(n-2) ? 1 : 0;
            else 
               for (int j = 2; j<=n/2; j++) 
                  if (Prime.Contains(j)&&Prime.Contains(n-j))
                     Res++;
            Console.WriteLine(Res);
            Res=0;
         }
      }
      static void Filt(int a) { 
         bool[] Compose = new bool[a];
         Compose[0]=true;
         for (int j = 2; j<=Math.Sqrt(a); j++) {
            if (Compose[j-1]) continue;
            for (int k = 2; k*j<=a; k++) Compose[k*j-1]=true;
         }
         Prime = new HashSet<int>(Compose.Select((i,j)=>(i?0:j+1)).Where(i=>i>0));
      }
   }
}

Measured memory_bytes: 10364
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define MOD 1e9 + 7
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265359

template <typename T>
void printVector(string name, vector<T> vec)
{
    cout << name << ": ";
    rep(i, vec.size())
    {
        cout << vec[i] << " ";
    }
    cout << endl;
}

void Main()
{
    ld a, b;
    cin >> a >> b;
    cout << (ll)(a * b) << endl;
    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3732
// B - Toll Gates
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N,M,X; cin>>N>>M>>X;
	vector<bool> A(N+1, false);
	while(M--){
		int a; cin>>a;
		A[a] = true;
	}

	int l = 0, r = 0;
	rp(i, 1, N){
		if(!A[i]) continue;
		if(i<=X) l++;
		else r++;
	}
	cout<< min(l,r) <<endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>){
    val input: List<String> = readLine()!!.split(" ")
    val num = Integer.parseInt(input[0])
    val k = Integer.parseInt(input[1])
    val trees = mutableListOf<Int>()

    for(i in 1..num){
        trees.add(Integer.parseInt(readLine()))
    }

    val sortedTree = trees.sorted()
    var min = sortedTree[num - 1]

    for(i in 0..(num - k)){
        val tmp = sortedTree[i+k-1] - sortedTree[i]
        if(tmp < min) min = tmp
    }
    println(min)
}

Measured memory_bytes: 42036
#include <cstdio>
#include <cmath>
#include <limits>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric> // 最大公約数が使える
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
const int inf = 1000000000; //10^9

int main(){
    int N;
    cin >> N;
    vector<pair<ll,ll>>A(N);
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        A[i] = make_pair(i+1,a);
    }
    map<ll,ll>B;
    for (int i = 0; i < N; i++)
        {
            int u = A[i].first + A[i].second;
            B[u]++ ; //  uが前のll,B[u]が後ろのll
        }
    ll ans =0;
    for (int j = 0; j < N; j++)
    {
        int t = A[j].first - A[j].second;
        ans += B[t];
    }
    cout << ans <<endl;
    
}

Measured memory_bytes: 28980
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

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

double len(double x1, double y1, double x2, double y2){
	return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

int fact(int n){
	int m;
	if(n==0)
		return 1;
	m = fact(n-1);
	return n*m;
}

int main(void){
	int n;
	int i, j;
	scanf("%d",&n);
	double x[n], y[n];
	double l[n];
	double sum=0;
	double ans;
	int a,count = 0;
	rep(i,n){
		scanf("%lf%lf",&x[i], &y[i]);
	}
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			sum += len(x[i], y[i], x[j], y[j]);
		}
	}
	if(n == 2){
		ans = sum;
	}
	else{
		ans = sum*2/(double) n;
	}
	printf("%lf\n",ans);
    return 0; 
}


Measured memory_bytes: 128