akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

int main() {
	int H, W, INF = 1000000000;
	cin >> H >> W;
	vector<string> S(H);
	for (int i = 0; i < H; i++) cin >> S[i];
	long long B[100][100][2];
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			B[i][j][0] = B[i][j][1] = INF;
		}
	}
	if (S[0][0] == '.') B[0][0][0] = 0;
	else B[0][0][1] = 1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int NX, NY;
			NX = i + 1, NY = j;
			if (NX < H && NY < W) {
				if (S[NX][NY] == '.') {
					B[NX][NY][0] = min(B[NX][NY][0], min(B[i][j][0], B[i][j][1]));
				}
				else {
					B[NX][NY][1] = min(B[NX][NY][1], min(B[i][j][0] + 1, B[i][j][1]));
				}
			}
			NX = i, NY = j + 1;
			if (NX < H && NY < W) {
				if (S[NX][NY] == '.') {
					B[NX][NY][0] = min(B[NX][NY][0], min(B[i][j][0], B[i][j][1]));
				}
				else {
					B[NX][NY][1] = min(B[NX][NY][1], min(B[i][j][0] + 1, B[i][j][1]));
				}
			}
		}
	}
	cout << min(B[H - 1][W - 1][0], B[H - 1][W - 1][1]) << endl;
}

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

using namespace std;

int main() {
	int n, x = 0, ans = 0;
	string s;

	cin >> n >> s;
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'I') {
			x++;
		}
		else {
			x--;
		}
		ans = max(ans, x);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import bisect
N = int(input())
A = [int(x) for x in input().split()]
B = sorted(A)
ans = 0
for i in range(N-1):
    ans = (B[0] + B[1]) / 2
    B.pop(0)
    B.pop(0)
    bisect.insort_left(B, ans)
print(ans)


Measured memory_bytes: 3188
package main

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

func main() {
	_ = intStdin()
	k := intStdin()
	x := splitIntStdin(" ")

	var distance int
	for _, p := range x {
		if p < k - p {
			distance += p * 2
		} else {
			distance += (k - p) * 2
		}
	}
	fmt.Println(distance)
}

/* template */
var sc = bufio.NewScanner(os.Stdin)

// 文字列を1行取得
func strStdin() (stringInput string) {
	sc.Scan()
	stringInput = sc.Text()
	stringInput = strings.TrimSpace(stringInput)
	return
}

// 整数値1つ取得
func intStdin() (num int) {
	stringInput := strStdin()
	num, _ = strconv.Atoi(strings.TrimSpace(stringInput))
	return
}

// 空白や空文字だけの値を除去したSplit()
func splitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
	stringSplited := strings.Split(stringTargeted, delim)

	for _, str := range stringSplited {
		if str != "" {
			stringReturned = append(stringReturned, str)
		}
	}
	return
}

// デリミタで分割して文字列スライスを取得
func splitStrStdin(delim string) (stringReturned []string) {
	// 文字列で1行取得
	stringInput := strStdin()

	// 空白で分割
	stringReturned = splitWithoutEmpty(stringInput, delim)

	return
}

// デリミタで分割して整数値スライスを取得
func splitIntStdin(delimiter string) (intAry []int) {
	// 文字列スライスを取得
	strAry := splitStrStdin(delimiter)

	// 整数スライスに保存
	for i := range strAry {
		num, err := strconv.Atoi(strAry[i])
		if err != nil {
			panic(err)
		}
		intAry = append(intAry, num)
	}
	return
}

/* template */


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

int main() {
  long N, K=0, Y=1000;
  cin >> N;
  int i=N-1;
  vector<int> A(N);
  rep(j, N) cin >> A.at(j);
  rep(j, N-1){
    if(A.at(j)<A.at(j+1)){
      K+=Y/A.at(j);
      Y-=A.at(j)*(Y/A.at(j));
      j++;
      i=j;
      break;
    }
  }
  for(int j=i; j<N-1; j++){
    if(A.at(j)<A.at(j+1)){
      K+=Y/A.at(j);
      Y-=A.at(j)*(Y/A.at(j));
    }
    else{
      Y+=K*A.at(j);
      K=0;
    }
  }
  Y+=K*A.at(N-1);
  cout << Y << endl;
}

Measured memory_bytes: 3548
def main():
    from builtins import int, map, list, print, max
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N = input_number()
    p = [input_number() for i in range(N)]
    ans = sum(p) - max(p) // 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

#define int long long

int min(int a, int b){
	if(a < b){
		return a;
	}
	else{
		return b;
	}
}

signed main(){
	int Q, H, S, D, N, ans = 0;
	scanf("%lld%lld%lld%lld%lld", &Q, &H, &S, &D, &N);
	int Qx8 = 8 * Q, Hx4 = 4 * H, Sx2 = 2 * S;
	if(D < Sx2 && D < Hx4 && D < Qx8){
		ans += D * (N / 2);
		if(N % 2 == 1){
			ans += min(min(4 * Q, 2 * H), S);
		}
	}
	else{
		ans += N * min(min(4 * Q, 2 * H), S);
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

int main()
{
	char a[10];
	cin >> a;
	int i = 0;
	for (;; i++) {
		int n = a[0] - '0';
		n += (a[1] - '0')*(i & 4 ? -1 : 1);
		n += (a[2] - '0')*(i & 2 ? -1 : 1);
		n += (a[3] - '0')*(i & 1 ? -1 : 1);
		if (n == 7) break;
	}
	cout << a[0] << (i & 4 ? '-' : '+') << a[1] << (i & 2 ? '-' : '+') << a[2] << (i & 1 ? '-' : '+') << a[3] << "=7" << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

def dfs(i, sum):
    if i == n:
        return sum
    else:
        return max(dfs(i + 1, sum), dfs(i + 1, sum + v[i] - c[i]))

ans = dfs(0, 0)

print(ans)

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

int main() {
  long long X;
  cin >> X;
  long long a = 0, b = 0;
  for (long long i = -7000; i < 7000; i++) {
    for (long long j = -7000; j < 7000; j++) {
      if (i*i*i*i*i - j*j*j*j*j == X) {
        a = i;
        b = j;
        break;
      }
    }
  }
  cout << a << ' ' << b;
  return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
set<int> E[101010];
string C;
int dp[101010];
int ma;

int dfs(int cur,int pre) {
	vector<int> V(2,0);
	FORR(e,E[cur]) if(e!=pre) V.push_back(dfs(e,cur));
	sort(ALL(V));
	reverse(ALL(V));
	
	ma=max(ma,C[cur]+V[0]+V[1]);
	return C[cur]+V[0];
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].insert(y-1);
		E[y-1].insert(x-1);
	}
	int ret=0;
	cin>>C;
	FOR(i,N) {
		C[i]=C[i]=='W';
		ret+=C[i];
	}
	if(ret==0) return _P("0\n");
	if(ret==1) return _P("1\n");
	
	queue<int> Q;
	FOR(i,N) if(E[i].size()==1) Q.push(i);
	
	while(Q.size()) {
		x=Q.front();
		Q.pop();
		if(C[x]==0) {
			C[x]=2;
			y=*E[x].begin();
			E[y].erase(x);
			if(E[y].size()==1) Q.push(y);
		}
	}
	ret=-2;
	int root;
	FOR(i,N) if(C[i]!=2) {
		C[i]^=(E[i].size()%2);
		//cout<<i<<" "<<(int)C[i]<<endl;
		ret+=2+C[i];
		root=i;
	}
	dfs(root,-1);
	//cout<<ret<<" "<<ma<<endl;
	cout<<ret-2*ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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


int main() {

    int y, m, d;
    char c1, c2;
    cin >> y >> c1 >> m >> c2 >> d;
    cout << (m <= 4 ? "Heisei" : "TBD") << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
#import collections as col
input=sys.stdin.readline

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().rstrip().split()))

def vinput(rep=1, ty=int, cvt=list):
	return cvt(ty(input().rstrip()) for _ in "*"*rep)

def facto(x, y, mod):
	re = 1
	for i in range(y, x+1):
		re *= i
		re %= mod
	#print(re, file=sys.stderr)
	return re

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    #return facto(n, n-r+1, mod) * g2[r] % mod
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
NN = 10**5+10
g1 = [1, 1] # factorial
g2 = [1, 1] # factorial^(-1)
inverse = [0, 1] # tmp

def init_comb():
    for i in range( 2, NN + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )


def main():
	A,B = linput()
	M = mod
	
	res = cmb(B+1, A+1, M)
	print(res)

def solve():
	S, = linput(str)
	res = 0
	mod = 9
	
	t = int(S)%9
	
	
	sT = "No Yes".split()
	res = sT[t < 1]
	print(res)
	
	
solve()

#init_comb()
#main()


Measured memory_bytes: 9384
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	int[] memo;

	public static void main(String args[]) {
		new Main().run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);

		memo = new int[1000000+1];
		Arrays.fill(memo, -1);

		while(true) {
			int N = sc.nextInt();
			if(N == 0) break;
			System.out.println(solve(N));
		}
	}

	private int solve(int n) {
		int r = memo[n];
		if(r != -1) return r;

		if(n == 1) return 0;

		if(n % 2 == 0) return memo[n] = solve(n / 2) + 1;
		else return memo[n] = solve(3 * n + 1) + 1;
	}
}

Measured memory_bytes: 16000
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int dp[100010];

int main(){
   int n;
   cin >> n;
   vector<int> v(n);
   rep(i,n){
      cin >> v[i];
   }
   rep(i,n){
      dp[i] = 1e9+7;
   }
   dp[0] = 0;
   rep(i,n){
      dp[i+1] = min(dp[i+1],dp[i] + abs(v[i]-v[i+1]));
      dp[i+2] = min(dp[i+2],dp[i] + abs(v[i]-v[i+2]));
   }
   cout << dp[n-1] << endl;
   

  
  return 0;
}


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

int main(){

  vector<long long> store(0);
  int n,m;
  long home;
  long long d;
  long long place;
  long long sum;

  while(cin >> d && d){ 
    cin>> n >> m;
    store.clear();
    store.push_back(0);
    for(int i=0; i<n-1; i++){
      cin >> place;
      store.push_back(place);
    }
    store.push_back(d);
    sort(store.begin(),store.end());

    sum=0;
    for(int i=0; i<m; i++){
      //cout<<sum<<endl;
      
      cin >> home;
      
      for(int j=0; j<(int)store.size()-1; j++){
	
	if(store[j+1] > home){
	  if(home-store[j] < store[j+1]-home){
	    sum+= home-store[j];
	  }
	  else{
	    sum+= store[j+1]-home;
	  }
	  break;
	}
      
	/*else if(j==(int)store.size()-2){
	  if(home-store[j] < d-home){
	  sum += home-store[j];
	  }
	  else{
	  sum += d-home;
	  }
	  }*/

      }


    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 2128
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T>
inline T LCM(T a, T b) { return (a + (b - 1)) / b; }
template<class T>
inline T round_int(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int n, m;
	cin >> n >> m;
	
	int all = 0;
	vi a(n);
	rep(i, n) {
		cin >> a[i];
		all += a[i];
	}

	int cnt = 0;
	double b = (double)all / (4 * m);
	//cout << b << endl;
	rep(i, n) {
		if (a[i] < b) {
		}
		else {
			cnt++;
		}
	}

	if (cnt >= m) cout << "Yes" << endl;
	else cout << "No" << 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 a = sc.nextInt();
		String s = sc.next();
		
		if(a < 3200) {
			s = "red";
		}

		System.out.println(s);
		
		

	}

}

Measured memory_bytes: 21844
# PyPy3 (2.4.0)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------
from collections import defaultdict, deque
class DAG:
    def __init__(self, adjList, inDegreeArray):
        self.A = adjList
        self.In = inDegreeArray
        self.n = len(inDegreeArray)
        self.depth = [-1]*(self.n)
        self.nodes = []

    def sort(self):
        dq = deque()
        # 入次数が 0 の頂点を deque に入れる
        for i in range(self.n):
            if self.In[i] == 0:
                dq.append(i)
                self.depth[i] = 0
        while dq:
            v1 = dq.popleft()
            self.nodes.append(v1)
            for v2 in self.A[v1]:
                self.In[v2] -= 1
                self.depth[v2] = max(self.depth[v2], self.depth[v1] + 1)
                if In[v2] == 0:
                    dq.append(v2)
    
    def get_node_array(self):
        if len(self.nodes) == self.n:
            return self.nodes
        else:
            return []
    
    def get_depth(self):
        return self.depth

# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]

# 試合と頂点の対応表
M = [[-1 for _ in range(N)] for _ in range(N)]
cnt = 0
for i in range(N):
    for j in range(i+1,N):
        M[i][j] = cnt
        M[j][i] = cnt
        cnt += 1

# 試合 j が 試合 i の翌日以降にしか行えない -> G[i][j]

G = [[] for _ in range((N*(N-1)//2))]
# 頂点(試合) の入次数
In = [0]*(N*(N-1)//2)
# 入力からグラフ, 配列を生成
for i in range(N):
    for j in range(N-2):
        gagem_id = M[i][ A[i][j] - 1 ]
        next_game_id = M[i][ A[i][j+1] - 1 ]
        G[gagem_id].append(next_game_id)
        In[next_game_id] += 1

dag = DAG(G, In)
dag.sort()
node = dag.get_node_array()
depth = dag.get_depth()

if len(node) == 0:
    print(-1)
else:
    print(max(depth) + 1)

Measured memory_bytes: 142300
#include<stdio.h>
    int main()
    {
        int A,p[51],B=0, i;
        scanf("%d",&A);
        for(i=1;i<=A;i++){
            scanf("%d",&p[i]);
        }
        for(i=1;i<=A;i++){
            if(p[i]!=i){
                B++;
            }
        }if(B==2||B==0){
            printf("YES");
        }else{
            printf("NO");
        }
     
    return 0;
    }

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
using namespace std;
 
const int INT__MAX = 2147483647;
const int MOD = 1000000007;
 
int main() {
 
	int N;
	int h, o;
 
	cin >> N;
 
	h = (N - (N % 100)) / 100;
	o = N % 10;
 
	if (h == o)cout << "Yes" << endl;
	else cout << "No" << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

struct Edge {
    int from, to, cost;
    Edge(int f, int t, int c) : from(f), to(t), cost(c) { }
    bool operator <(const Edge& e) const {
        return cost < e.cost;
    }
};

const int INF = (int)1e9;
typedef pair<int, int> P;

vector<int> dijkstra(const vector<vector<Edge> >& g, int s) {
    vector<int> res(g.size(), INF);
    priority_queue<P, vector<P>, greater<P> > Q;
    Q.push(P(0, s));
    res[s] = 0;
    while(!Q.empty()) {
        P p = Q.top(); Q.pop();
        if(p.first > res[p.second]) continue;
        for(int i = 0; i < (int)g[p.second].size(); i++) {
            Edge e = g[p.second][i];
            if(res[e.to] > p.first + e.cost) {
                res[e.to] = p.first + e.cost;
                Q.push(P(res[e.to], e.to));
            }
        }
    }
    return res;
}

int main() {
    int N; cin >> N;
    vector<vector<Edge> > es(N);
    for(int i = 0; i < N; i++) {
        int u, k; cin >> u >> k;
        while(k--) {
            int v, c; cin >> v >> c;
            es[u].push_back(Edge(u, v, c));
        }
    }
    vector<int> res = dijkstra(es, 0);
    for(int i = 0; i < N; i++) {
        cout << i << ' ' << res[i] << endl;
    }
}

Measured memory_bytes: 8104
# -*- coding: utf-8 -*-
# 写経した
import re
class Num:
    def __str__(self):
        return str(self.x)
    def __init__(self, value):
        self.x = value
    def __add__(self, value):
        return Num(self.x + value.x)
    def __sub__(self, value):
        return Num(self.x - value.x)
    def __mul__(self, value):
        return Num(self.x * value.x)
    def __truediv__(self, value):
        return Num(int(self.x / value.x))
      
N = int(input())
for i in range(N):
    s = input()[:-1]
    s = re.sub(r'(\d+)',r'Num(\1)',s)
    print(eval(s))


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n >> m;
    vector<vector<ll>> g(n);
    for(i=0;i<m;i++){
        ll a,b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<ll> ret_f,ret_s;
    ret_f.push_back(0);
    ll now = 0;
    set<ll> st;
    st.insert(0);
    while(1){
        int f=1;
        for(i=0;i<g[now].size();i++){
            if(st.find(g[now][i])==st.end()){
                now = g[now][i];
                ret_f.push_back(now);
                st.insert(now);
                f=0;
                break;
            }
        }
        if(f==1)break;
    }
    int f=1;
    for(i=1;i<g[0].size();i++){
        if(st.find(g[0][i])==st.end()){
            f=0;
            break;
        }
    }
    if(f==1){
        cout << ret_f.size() << endl;
        for(auto &x:ret_f){
            cout << x+1 << " ";
        }
        cout << endl;
        return 0;
    }
    now = 0;
    while(1) {
        int f = 1;
        for(i = 0; i < g[now].size(); i++) {
            if(st.find(g[now][i]) == st.end()) {
                now = g[now][i];
                ret_s.push_back(now);
                st.insert(now);
                f = 0;
                break;
            }
        }
        if(f == 1) break;
    }
    reverse(ret_s.begin(),ret_s.end());
    for(i=0;i<ret_f.size();i++){
        ret_s.push_back(ret_f[i]);
    }
    cout << ret_s.size() << endl;
    for(auto &x : ret_s) {
        cout << x+1 << " ";
    }
    cout << endl;
    return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
std::vector<P> G;

bool can(){
    if(N == 1){
        return false;
    }

    unless(N % 2 == 1 || __builtin_popcount(N) >= 2){
        return false;
    }

    for(int i=2;i+1<=N;i+=2){
        G.emplace_back(1, i);
        G.emplace_back(i, i + 1);
        G.emplace_back(1, i + 1 + N);
        G.emplace_back(i + 1 + N, i + N);
    }

    G.emplace_back(3, 1 + N);

    if(N % 2 == 0){
        int u = N & -N, v = N ^ u;
        G.emplace_back((u ^ 1) + N, N);
        G.emplace_back(v, N * 2);
    }

    return true;
}

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

    std::cin >> N;

    if(can()){
        std::cout << "Yes" << std::endl;
        
        assert(G.size() == 2 * N - 1);

        for(auto &p : G){
            int u, v;
            std::tie(u, v) = p;

            std::cout << u << " " << v << std::endl;
        }
    }else{
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 4080
N = int(input())
A = list(map(int, input().split()))
A = [[a,i] for a,i in zip(A,range(N))]
A = sorted(A,reverse=True)

dp = [[0]*(N+1) for _ in range(N+1)]
ans = 0

for n in range(0,N+1):
    for y in range(0,n+1):
        x = n-y
        a = A[n-1]
        ind = a[1]
        if x==0 and y==0:
            dp[x][y] = 0
        elif x==0:
            dp[x][y] = dp[x][y-1] + a[0]*abs(ind-((N-1)-(y-1)))
        elif y==0:
            dp[x][y] = dp[x-1][y]+a[0]*abs(ind-(x-1))
        else:
            dp[x][y] = max(dp[x-1][y]+a[0]*abs(ind-(x-1)),dp[x][y-1] + a[0]*abs(ind-((N-1)-(y-1))))
        ans = max(ans,dp[x][y])

print(ans)

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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(10)





void solve() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	string k = "ABC";
	int cnt = 0;
	for(int i = 0; i + k.length() <= s.length(); i++) {
		bool ok = 1;
		for(int j = 0; j < k.length(); j++) {
			if(s[i + j] != k[j]) {
				ok = 0;
				break;
			}
		}
		if(ok) {
			cnt++;
		}
	}
	cout << cnt << "\n";


	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	solve();

	return 0;
}

Measured memory_bytes: 3588
<?php
$input = explode(" ", fgets(STDIN));

if (intval($input[0]) < intval($input[1])) {
    echo "a < b".PHP_EOL;
} else if (intval($input[0]) > intval($input[1])) {
    echo "a > b".PHP_EOL;
} else {
    echo "a == b".PHP_EOL;
}


Measured memory_bytes: 9188
/*
 * Circle.cpp
 *
 *  Created on: 2014/07/21
 *      Author: WanWan1985
 */
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main(void) {
	double dr = 0.0;
	cin >> dr;

	cout << fixed << setprecision(8) <<  pow(dr, 2.0) * M_PI << " " << 2 * M_PI * dr << endl;

	return 0;
}

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

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

#include <string>
#include <vector>
#include <algorithm>
int main(){
    string wlist[] = {"Sunny","Cloudy","Rainy","Sunny"};
    string *s = wlist;
    string str; cin >> str;
    while(*s!=str)s++;
    cout << *(s+1) << endl;
}

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

using namespace std;
typedef long long ll;

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

    vector<int> l(n);
    for(int i=0; i<n; i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end());

    int ans = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            int ab = l[i]+l[j];
            int k = lower_bound(l.begin(), l.end(), ab) - l.begin();
            ans += k - j - 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    vector<int> v(3);
    rep(i, 3) cin >> v[i];
    sort(all(v));
    if (v[0] == 5 && v[1] == 5 && v[2] == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

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

  if (N % (2*D+1) == 0){
    cout << N/(2*D+1) << endl;
  } else {
    cout << N/(2*D+1) + 1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    bool is_approved = true;
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        if (a % 2 == 0)
        {
            if (a % 3 != 0 && a % 5 != 0)
            {
                is_approved = false;
                break;
            }
        }
    }
    if (is_approved)
    {
        cout << "APPROVED" << endl;
    }
    else
    {
        cout << "DENIED" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()

d = [X[i] - X[i-1] for i in range(1,M)]
d.sort(reverse=True)
if N < M:
  print(sum(d[N-1:]))
else:
  print(0)

Measured memory_bytes: 13960
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    #divisors.sort()
    return divisors

n = int(input())

if is_prime(n) == True:
    print(n-1)
else:
    ls = (make_divisors(n))
    if (n / ls[-1]) == ls[-1]:
        print(ls[-1]+ls[-1]-2)
    else:
        print(ls[-1]+ls[-2]-2)
    

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

using namespace std;

int frand(int n){
	char s[10];
	sprintf(s,"%d",n*n);
	int len=strlen(s);
	
	n=0;
	int idx=len-6;
	while(idx<len-2){
		if(idx<0){
			++idx;
			continue;
		}else{
			n=10*n+(s[idx]-'0');
			++idx;
		}
	}
	
	return n;
}

int main(){
	int n;
	cin>>n;
	int count=0;
	while(n--){
		++count;
		int s;
		cin>>s;
		cout<<"Case "<<count<<":"<<endl;
		for(int i=0;i<10;i++){
			s=frand(s);
			cout<<s<<endl;
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) ((a>b)?a:b);
#define min(a,b) ((b>a)?a:b);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ template.cpp -o template.exe
//#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b)
{
    return (a.second < b.second);
}




int main()
{

unsigned long long int a,i;
long long int k=1;
cin>>a;
//unsigned long long int a[n];
long  double b,sum1;
cin>>b;
sum1=a*b;
cout<<(unsigned long long int)sum1;


return 0;
}

Measured memory_bytes: 3728
n = int(input())
S = {}

ans = []
for i in range(n):
	order = input().split()
	if order[0] == "insert":
		S[order[1]] = 0
	elif order[0] == "find":
		if order[1] in S:
			ans.append("yes")
		else:
			ans.append("no")

for i in range(len(ans)):
	print(ans[i])


Measured memory_bytes: 37104
/**
*    author:  Dooloper
*    created: 12.09.2020 21:54:51
**/

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <functional>
#include <cassert>

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define PI 3.14159265358979323846264338327950L

int main()
{
    int D, T, S;
    cin >> D >> T >> S;
    double Time = (double)D / S;

    if (T >= Time)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

// #include <iostream>
// using namespace std;

// int main()
// {
//     //入力を受け取る
//     int D, T, S;
//     cin >> D >> T >> S;

//     //高橋君の移動時間を計算する
//     double time = (double)D / S;

//     //Tとtimeの大小関係に応じて出力をする
//     if (T >= time)
//     {
//         cout << "Yes" << endl;
//     }
//     else
//     {
//         cout << "No" << endl;
//     }
// }


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>

using namespace std;

pair<int64_t, int64_t> comb[200005];

int main()
{
  int64_t N;
  vector<int64_t> A;

  cin >> N;
  A.resize(N);

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

  auto sorted_A = A;
  int64_t total = 0;

  sort(sorted_A.begin(), sorted_A.end());

  sorted_A.push_back(-1);

  for (int i = 0; i < sorted_A.size(); i++) {
    static int64_t count = 0;

    count++;

    if (sorted_A[i] != sorted_A[i + 1]) {
      comb[sorted_A[i]].first = max<int64_t>(0, count * (count - 1) / 2);
      comb[sorted_A[i]].second = max<int64_t>(0, (count - 1) * (count - 2) / 2);
      total += comb[sorted_A[i]].first;
      count = 0;
    }
  }

  for (auto &&i : A) {
    cout << total - comb[i].first + comb[i].second << endl;
  }

  return 0;
}


Measured memory_bytes: 9444
import Data.Bits

main = do
  [a, b] <- map read . words <$> getLine :: IO [Int]
  let xs = case (even a, even b) of
        (True, True) -> [if even ((b - a) `div` 2) then 0 else 1, b]
        (True, False) -> [if even ((b - a + 1) `div` 2) then 0 else 1]
        (False, True) -> [a, if even ((b - a - 1) `div` 2) then 0 else 1, b]
        (False, False) -> [a, if even ((b - a) `div` 2) then 0 else 1]

  putStrLn . show $ foldl1 xor xs


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int x;
    cin >> x;
    int res;
    if (x < 600) res = 8;
    else if (x < 800) res = 7;
    else if (x < 1000) res = 6;
    else if (x < 1200) res = 5;
    else if (x < 1400) res = 4;
    else if (x < 1600) res = 3;
    else if (x < 1800) res = 2;
    else res = 1;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3636
n,k = map(int,input().split())
v = list(map(int,input().split()))

m=[]
M = min(n,k) +1
for i in range(M):
 for j in range(M-i):
  # print(i,j)
  t=sorted(v[:i]+v[:~j:-1])

  while t and(k-i-j)*t[0]<0:t.pop(0);j+=1
  m.append(sum(t))
print(max(m))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

vector<ll> inv, fact, invfact;
void Mod_build(int n = 1010101) {
    fact.resize(n + 1);
    inv.resize(n + 1);
    invfact.resize(n + 1);
    fact[0] = inv[0] = invfact[0] = 1;
    inv[1] = 1;
    for (ll i = 0; i < n; i++) {
        fact[i + 1] = fact[i] * (i + 1) % mod;
        if (i > 0) inv[i + 1] = mod - inv[mod % (i + 1)] * (mod / (i + 1)) % mod;
        invfact[i + 1] = invfact[i] * inv[i + 1] % mod;
    }
}
ll perm(int n, int k) {
    if (n < 0 || k < 0 || k > n) return 0;
    return fact[n] * invfact[n - k] % mod;
}
ll comb(int n, int k) {
    if (n < 0 || k < 0 || k > n) return 0;
    return (fact[n] * invfact[n - k] % mod) * invfact[k] % mod;
}
ll powmod(ll n, ll k) {
    k %= mod - 1;
    if (k < 0) k += mod - 1;
    ll ret = 1;
    while (k) {
        if (k & 1) ret = ret * n % mod;
        n = n * n % mod;
        k >>= 1;
    }
    return ret;
}

int main() {
    Mod_build();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    for (i = 0; i <= n; i++) {
        if (i % 2 == 0)
            ans += comb(n, i) * comb(m, i) % mod * fact[i] % mod * comb(m - i, n - i) % mod * fact[n - i] % mod * comb(m - i, n - i) % mod * fact[n - i] % mod;
        else
            ans += mod - comb(n, i) * comb(m, i) % mod * fact[i] % mod * comb(m - i, n - i) % mod * fact[n - i] % mod * comb(m - i, n - i) % mod * fact[n - i] % mod;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 26740
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
  n = ni()
  ans = n // 11 * 2
  if 0 < n % 11 < 7:
    ans += 1
  elif n % 11 > 6:
    ans += 2
  print(ans)
main()

Measured memory_bytes: 3060
n = input()
ans = []
if n == 2:
	data = map(int, raw_input().split())
	hoge = min(data)
	for i in range(1, hoge + 1):
		if data[0] % i == 0:
			if data[1] % i == 0:
				ans.append(i)
	for j in range(len(ans)):
		print ans[j]

if n == 3:
	data = map(int, raw_input().split())
	hoge = min(data)
	for i in range(1, hoge + 1):
		if data[0] % i == 0:
			if data[1] % i == 0:
				if data[2] % i == 0:
					ans.append(i)
	for j in range(len(ans)):
		print ans[j]


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

int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    while(N-500 >= 0){
        N -= 500;
        ans += 1000;
    }
    while(N-5 >= 0){
        N -= 5;
        ans += 5;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define PRIM_NODE_MAX 100
#define INF 1e9
int prim(int n,int cost[][PRIM_NODE_MAX]){
	int determined[PRIM_NODE_MAX]={1};//node 0 determined
	int undeterminednodes=n-1;
	int mincost[PRIM_NODE_MAX],minnode,totalcost=0;
	int i;
	
	// initialize mincost
	mincost[0]=INF;
	for(i=1;i<n;i++){
		mincost[i]=cost[0][i];
	}

	for(;undeterminednodes;){
		// select the nearest undetermined node
		minnode=0;
		for(i=0;i<n;i++){
			if(mincost[i]<mincost[minnode])
				minnode=i;
		}

		// the node is determined
		determined[minnode]=1;
		totalcost+=mincost[minnode];
		mincost[minnode]=INF;
		undeterminednodes--;

		// update mincost around the minnode
		for(i=0;i<n;i++){
			if(!determined[i]&&cost[minnode][i]<mincost[i])
				mincost[i]=cost[minnode][i];
		}
	}
	return totalcost;
}
s,d,C[100][100];
main(){
	int i,j,v;
	for(;scanf("%d%d",&s,&d)*s;){
		memset(C,0,sizeof(C));
		for(j=0;j<s;j++){
			for(i=0;i<d;i++){
				scanf("%d",&v);
				C[j][s+i]=C[s+i][j]=v?v:INF;
			}
		}
		for(j=0;j<d-1;j++){
			for(i=0;i<d-j-1;i++){
				scanf("%d",&v);
				C[s+j][s+j+1+i]=C[s+j+1+i][s+j]=v?v:INF;
			}
		}
		printf("%d\n",prim(s+d,C));
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=(n);i++)

#define DEB(X) if(mode==1)cout<< #X <<": "<<X<<" ";
#define DEB2(X) if(mode==1)cout<<X<<" ";
#define ARDEB(i,X) if(mode==1)cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define FORDEB(n,X) if(mode==1)for(int i=0;i<(n);i++)ARDEB(i,X)
#define END if(mode==1)cout<<endl;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
//struct edge{int from,cost,to;};

const int INF=100000000;
int mode=1;

int main(){
	int ok,ng,n,a[100000],b[100000],c[100000];
	ll ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		cin>>c[i];
	}
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	REP(i,n){
		ll res=1;
		ok=0;ng=n;
		if(a[0]>=b[i])continue;
		while(abs(ok-ng)>1){
			int mid=(ok+ng)/2;
			if(a[mid]<b[i]) ok=mid;
			else ng=mid;
		}
		ok++;
		res*=ok;
		ok=n-1;ng=-1;
		if(c[n-1]<=b[i])continue;
		while(abs(ok-ng)>1){
			int mid=(ok+ng)/2;
			if(c[mid]>b[i]) ok=mid;
			else ng=mid;
		}
		res*=n-ok;
		ans+=res;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n);
    set<int> seen;
    for (int i = 0;i < n;i++) cin >> a[i];

    int next = 0, count = 1;
    
    while(true)
    {
        if (a[next] == 2)
        {
            cout << count << endl;
            return 0;
        }
        
        seen.insert(a[next]);
        next = a[next] - 1;
        
        if (seen.size() != count)
        {
            cout << -1 << endl;
            return 0;
        }
        count++;
    }    
    
    return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int a, b, ans, m[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

int main() {
	cin >> a >> b;
	
	incII(i, 1, 12) {
	incII(j, 1, m[i]) {
		if(i == j) { ans++; }
		if(i == a && j == b) { cout << ans << endl; return 0; }
	}
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

llint x,y;

void solve(){
  cin >> x >> y;
  llint ans=inf;
  for(int i=0;i<4;i++){
    int t,s;
    llint z;
    if(i==0){
      t=x;
      s=y;
      z=s-t;
    }
    if(i==1){
      t=(-x);
      s=y;
      z=s-t+1;
    }
    if(i==2){
      t=x;
      s=(-y);
      z=s-t+1;
    }
    if(i==3){
      t=(-x);
      y=(-y);
      z=s-t+2;
    }
    if(z>=0)ans=min(ans,z);
  }
  cout << ans << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


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

using namespace std;

#define INF 210000000
#define int long long

int gcd(int a, int b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

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

signed main() {
		int n,m;
		cin >> n >> m;
		map<int,int> cnt;
		for(int i=0;i<n;i++){
				int p;
				cin >> p;
				for(int j=0;j<p;j++){
						int tmp;
						cin >> tmp;
						cnt[tmp]++;
				}
		}
		int ans = 0;
		for(auto& A : cnt){
				if(A.second == n) ans++;
		}
		cout << ans;
}



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

const int N=3;

int n,a[N][N],x;
bool dp[N][N];

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

	cin>>n;
	while(n--)
	{
		cin>>x;
		for(int i=0;i<N;i++)
			for(int j=0;j<N;j++)
				if(a[i][j]==x) dp[i][j]=true;
	}

	bool ok1=false,ok2=false,ok3=true,ok4=true;
	for(int i=0;i<N;i++)
	{
		bool found=true;
		for(int j=0;j<N;j++)
			if(dp[i][j]==false) found=false;
		if(found) ok1=true;
	}
	for(int j=0;j<N;j++)
	{
		bool found=true;
		for(int i=0;i<N;i++)
			if(dp[i][j]==false) found=false;
		if(found) ok2=true;
	}
	for(int i=0;i<N;i++)
		if(dp[i][i]==false) ok3=false;
	for(int i=0;i<N;i++)
		if(dp[N-1-i][i]==false) ok4=false;
	if(ok1 or ok2 or ok3 or ok4) cout<<"Yes";
	else cout<<"No";
}

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

int main()
{
	int x,y,z;
	int i,l;

	l=0;

	cin >> x;
	cin >> y;
	cin >> z;

		for(i=x;i<=y;i++){
			if((z%i)==0){
				l++;
			}
		}
	

	cout<<l<<endl;

	return 0;
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


def left_diff(array):
    """
    array: ordered ndarray, len(array) >= 2
    """
    x = (array[-1] + 1) >> 1
    mid = np.searchsorted(array, x)
    if abs(array[-1] - array[mid] * 2) < abs(array[-1] - array[mid-1] * 2):
        return array[mid], array[-1] - array[mid]
    else:
        return array[mid-1], array[-1] - array[mid-1]


def right_diff(array, offset):
    """
    array: ordered ndarray, len(array) >= 2
        target array or list

    offset: int
        offset value for right array
    """
    x = (array[-1] - offset + 1) >> 1
    mid = np.searchsorted(array, x + offset)
    if abs(array[-1] - array[mid] * 2 + offset)\
            < abs(array[-1] - array[mid-1] * 2 + offset):
        return array[mid] - offset, array[-1] - array[mid]
    else:
        return array[mid-1] - offset, array[-1] - array[mid-1]


def calc_max_diff(p, q, r, s):
    return max(p, q, r, s) - min(p, q, r, s)


if __name__ == '__main__':
    N = d_in()
    a_array = np.array(ds_in())

    cum_a = np.cumsum(a_array)
    left_cut_points = (cum_a[1:-2] + 1) // 2
    left_mid_points = np.searchsorted(cum_a, left_cut_points)
    right_cut_points = (cum_a[-1] + cum_a[1:-2] + 1) // 2
    right_mid_points = np.searchsorted(cum_a, right_cut_points)
    
    ans = float('inf')
    for i in range(2):
        for j in range(2):
            P = cum_a[left_mid_points-i]
            Q = cum_a[1:-2] - P
            R = cum_a[right_mid_points-j] - cum_a[1:-2]
            S = cum_a[-1] - cum_a[right_mid_points-j]
            MAX = np.maximum(np.maximum(P, Q), np.maximum(R, S))
            MIN = np.minimum(np.minimum(P, Q), np.minimum(R, S))
            ans = min(ans, (MAX - MIN).min())

    print(ans)


Measured memory_bytes: 35916
/* Filename: AGC003B.java
 * Author: Mushiyo
 */

import java.util.Scanner;

public class Main{

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

		while (input.hasNext()) {
			int N = input.nextInt();
			
			long sum = 0;
			long countPair = 0;
			for(int i = 0; i < N; ++i){
				int Ai = input.nextInt();
				
				if(Ai != 0){
					sum += Ai;
				} else {
					countPair += sum / 2;
					sum = 0;
				}
			}
			countPair += sum / 2;
			
			System.out.println(countPair);
		}
	}

}


Measured memory_bytes: 21164
import math
A,B=map(int,input().split())
X=10001
c=[]

for i in range(10,X):
  if math.floor(i*0.08)==A and math.floor(i*0.1)==B:
    c.append(i)

if len(c)==0:
  print("-1")
else:
  print(min(c))
    

Measured memory_bytes: 3060
n, k = map(int, input().split())
a = tuple(map(int, input().split()))

dp = [None] * (k + 1)
# dp[手番の石の数] := 手番の勝敗
# True(勝ち) / None(負け)

for my_remains in range(k + 1):
    for my_take in a:
        opponent_remains = my_remains - my_take  # 相手が操作を行う石の数
        if opponent_remains >= 0 and dp[opponent_remains] is None:
            dp[my_remains] = True

ans = dp[k]
print('First' if ans else 'Second')


Measured memory_bytes: 3828
S = input()
K = int(input())

if(S.count(S[0]) == len(S)):
    print(len(S)*K//2)
else:
    cnt = 0
    lst = []
    tmp = S[0]
    for i in range(len(S)):
        if(tmp == S[i]):
            cnt += 1
        else:
            tmp = S[i]
            if(cnt > 1):
                lst.append(cnt)
            cnt = 1   
    if(cnt > 1):
        lst.append(cnt)
        
    ans = 0
    for i in lst:
        ans += K*(i//2)
    if(S[0] != S[-1]):
        print(ans)
    else:
        a = 0
        b = 0
        for i in range(len(S)):
            if(tmp != S[i]):
                break
            a += 1
        for i in S[::-1]:
            if(tmp != i):
                break
            b += 1
        print(ans+((a+b)//2-(a//2+b//2))*(K-1))

Measured memory_bytes: 9180
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N; cin >> N;
  vector<int> p(N);
  rep(i,N) cin >> p[i];
  sort(p.rbegin(), p.rend());
  p[0] /= 2;
  int ans = 0;
  rep(i,N) ans += p[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3148
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    ans=10**18
    for i in range(1,n):
        x=sum([int(j) for j in str(i)])+sum([int(j) for j in str(n-i)])
        ans=min(ans,x)
    print(ans)
resolve()

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out

int ans=0;
vvc v(30,vector<char> (30,'a'));
int dfs(int x,int y,int h,int w){
    // cout<<x<<" "<<y<<" "<<ans<<endl;
    if(v[y][x]=='%')return 0;
    if(v[y][x]=='@'||v[y][x]=='.'){
        ans++;
        v[y][x]='%';
        if(x+1<w&&v[y][x+1]=='.')dfs(x+1,y,h,w);
        if(x-1>=0&&v[y][x-1]=='.')dfs(x-1,y,h,w);
        if(y+1<h&&v[y+1][x]=='.')dfs(x,y+1,h,w);
        if(y-1>=0&&v[y-1][x]=='.')dfs(x,y-1,h,w);

    }
    else return 0;
    return 0;
}

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    
    int i,j,x,y,s,pi,pj,t;
    while(1){
        cin>>x>>y>>s;
        if(x==0&&y==0&&s==0)break;
        int ans=0;
        for(i=1;i<s;i++){
            j=s-i;
            // cout<<i<<" "<<j<<endl;
            
            pi=ceil((double)(100*i)/(100+x));
            pj=ceil((double)(100*j)/(100+x));
            if(pi*(100+x)/100+pj*(100+x)/100==s){
                t=pi*(100+y)/100+pj*(100+y)/100;
            // cout<<pi<<" "<<pj<<" "<<t<<endl<<endl;;
                ans=max(ans,t);
            }
            
        }
        cout<<ans<<endl;
    }
    
    

//////////////////////////////////////////////////////
return 0;}











Measured memory_bytes: 3120