akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while (true) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            Plant[] plants = new Plant[n];
            for (int i = 0; i < n; i++) {
                plants[i] = new Plant(sc.next(), sc.nextInt(), sc.nextInt() + sc.nextInt() + sc.nextInt(), sc.nextInt() + sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt());
            }
            Arrays.sort(plants);
            for (int i = 0; i < n; i++) {
                sb.append(plants[i].name).append("\n");
            }
            sb.append("#\n");
        }
        System.out.print(sb);
    }
    
    static class Plant implements Comparable<Plant> {
        String name;
        int income;
        int time;
        
        public Plant(String name, int cost, int firstTime, int everyTime, int count, int price, int dup) {
            this.name = name;
            income = count * price * dup - cost;
            time = dup * everyTime + firstTime;
        }
        
        public int compareTo(Plant another) {
            if (another.income * time == income * another.time) {
                return name.compareTo(another.name);
            } else {
                return another.income * time - income * another.time;
            }
        }
    }
}



Measured memory_bytes: 46040
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
LL n;
/**********************************************/

LL cnt_keta(LL num){
    int ret = 0;
    while(num != 0){
        num /= 10;
        ret++;
    }
    return ret;
}

int main(){
    cin >> n;
    
    LL i = sqrt(n);
    while(i != 0){
        if(n % i == 0){
            cout << max(cnt_keta(i), cnt_keta(n/i)) << endl;
            return 0;
        }
        i--;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define LL long long int
using namespace std;
const int N = 1e3 + 5;

int v[N];
vector<int> g[N];
int main() {
    FASTIO;
    int n, i, j, nd;
    cin >> n;
    nd = (n/2) * 2;
    vector<pair<int, int>> ans;
    for (i=1;i<=nd;i++) {
      for (j=1;j<=nd;j++) {
        if (j == i || j == nd+1-i) continue;
        if (i < j) ans.push_back({i, j});
      }
    }
    if (nd != n) {
      for (i=1;i<=nd;i++) ans.push_back({i, n});
    }

    for (auto it : ans) {
      g[it.first].push_back(it.second);
      g[it.second].push_back(it.first);
    }
    int sum = (n * (n - 1)) / 2;
    if (nd == n) sum--;
    for (i=1;i<=n;i++) {
      int now = 0;
      for (auto it : g[i]) now += it;
      assert(now == sum);
    }

    cout << ans.size() << '\n';
    for (auto it : ans) cout << it.first << " " << it.second << '\n';
    return 0;
}


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

int main() {
	string S,T, U;
	int A, B;

	cin >> S >> T >> A >> B >> U;

	if(U == S){
		cout << A - 1 << " " << B << endl;
	}else{
		cout << A << " " << B-1 << endl;
	}
}


Measured memory_bytes: 256
from collections import defaultdict
import heapq
v_num = int(input())
connect = defaultdict(list)

for _ in range(v_num):
    que = [int(n) for n in input().split(" ")]
    connect[que[0]] = [[v, w] for v, w in zip(que[2:len(que):2], que[3:len(que):2])]
    # weight_edge[que[0]] = {k:v for k, v in zip(que[2:len(que):2], que[3:len(que):2])}
queue = []
heapq.heapify(queue)
heapq.heappush(queue, [0, 0])
distance = [-1 for n in range(v_num)]
went = 0
visited = set()
while went < v_num:
    q = heapq.heappop(queue)
    weight, here = q
    if here in visited:
        continue
    visited |= {here}
    went += 1
    distance[here] = weight
    for conn in connect[here]:
        if conn[0] not in visited:
            heapq.heappush(queue, [weight + conn[1], conn[0]])
for i in range(v_num):
    print(i, distance[i])

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

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

	vector<int> vec(n);
	int p;

	for (int i = 0; i < n; i++) {
		cin >> p;
		vec[i] = p;
	}

	int cnt = 0;

	for (int i = 0; i < n - 2; i++) {
		if ((vec[i] < vec[i + 1] && vec[i + 1] < vec[i + 2]) ||
			(vec[i + 2] < vec[i + 1] && vec[i + 1] < vec[i]))
		{
			cnt++;
		}

	}
	cout << cnt << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>


#include <math.h>  /* M_PI */

int main(){

    double r;
    cin >> r;


    printf("%.15f\n", 2* r * M_PI);
}

Measured memory_bytes: 3232
fn main() {
    let mut s = String::new();
    let days = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
    std::io::stdin().read_line(&mut s).ok();
    s = s.trim().to_string();
    for (i, d) in days.iter().enumerate() {
        if s == d.to_string() {
            println!("{}", 7-i);
        }
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(){
    string s; cin >> s;
    for(int i=s.size()-1; i>=0; i--){
        cout << s.at(i);
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
const ll INF = 1E+18;

ll dp[305][305];

ll max(ll a, ll b) {
    if (a>b) return a;
    else return b;
}

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n+1);
    h[0] = 0;
    rep(i, n) cin >> h[i+1];
    ll sum = 0;
    rep(i, n+1) {
        if (i==0) continue;
        sum += max(0, h[i]-h[i-1]);
    }

    
    rep(i, 305) rep(j, 305) dp[i][j] = INF;
    dp[0][0] = 0;

    for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) {
            if (j==1) {
                dp[i][j] = h[i];
                continue;
            }
            for (int l=0; l<i; l++) {
                dp[i][j] = min(dp[i][j], dp[l][j-1]+max(0, h[i]-h[l]));
            }
        }
    }

    ll ans = INF;
    rep(i, n+1) {
        ans = min(ans, dp[i][n-k]);
    }
    
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
	string N;
	cin>>N;
	if(N[0]==N[1]&&N[1]==N[2])
	{
		cout<< "Yes";
	}
	else if(N[1]==N[2]&&N[2]==N[3])
	{
		cout<< "Yes";
	}
  else 
	  cout<< "No";

	return 0;
}

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

const int MAX = 510000;
const int MOD = 1000000007;
const int MAX_N = 200000;

int ctoi(const char c){
 switch(c){
   case '0': return 0;
   case '1': return 1;
   case '2': return 2;
   case '3': return 3;
   case '4': return 4;
   case '5': return 5;
   case '6': return 6;
   case '7': return 7;
   case '8': return 8;
   case '9': return 9;
   default : return -1;
 }
}

struct Neighbor{
  ll node_id;
  ll edge_id;
};


vector<vector<Neighbor>> neighbor_list;
vector<ll> ans;

int main(int argc, const char * argv[]) {
  ll N; cin >> N ; neighbor_list.resize(N); ans.resize(N,-1);

  for(ll i=0;i<N-1;i++){
    ll a,b; cin >> a >> b; a--; b--;
    neighbor_list[a].push_back((Neighbor){b,i});
    neighbor_list[b].push_back((Neighbor){a,i});
  }


  ll delta = 0;
  for(ll i=0;i<N;i++){
    delta = max(delta, (ll)neighbor_list[i].size());
  }



  queue<ll> que;
  que.push(0);
  while(!que.empty()){
    ll a = que.front(); que.pop();

    vector<bool> color(delta,false);
    for(auto next_node : neighbor_list[a]){
      if(ans[next_node.edge_id] != -1 ){
        color[ans[next_node.edge_id]] = true;
      }
    }

    ll color_cnt=0;
    for(auto next_node : neighbor_list[a]){
      if(ans[next_node.edge_id] != -1)
        continue;
      
      for(;color_cnt<delta;color_cnt++){
        if(color[color_cnt]) {
          continue;
        }
        ans[next_node.edge_id]=color_cnt;
        color[color_cnt] = true;
        que.push(next_node.node_id);
        break;
      }
    }
  }

  cout << delta << endl;
  for(ll i=0; i<N-1;i++){
    cout << ans[i]+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 8832
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
vector<tuple<int,long,int,int>> G[100000];
long S[100000];
int child[100000];
long ans[99999];
long sumcost[100000];
void Calc(){
	int N = rei();
	for(int i=0;i<N-1;i++){
		int a = rei()-1;
		int b = rei()-1;
		G[a].push_back({b,0,i,G[b].size()});
		G[b].push_back({a,0,i,G[a].size()-1});
	}
	for(int i=0;i<N;i++){
		S[i] = rel();
	}
	stack<pair<int,int>> sp;
	sp.push({0,-1});
	while(!sp.empty()){
		int v = sp.top().first;
		int f = sp.top().second;
		sp.pop();
		if(v >= N){
			v -= N;
			child[v] = 1;
			for(int i=0;i<G[v].size();i++){
				int t = get<0>(G[v][i]);
				if(t != f){
					child[v] += child[t];
				}
			}
		}
		else{
			sp.push({v+N,f});
			for(int i=0;i<G[v].size();i++){
				int t = get<0>(G[v][i]);
				if(t != f){
					sp.push({t,v});
				}
			}
		}
	}
	int halfchild1 = -1;
	int halfchild2 = -1;
	int halfedge = -1;
	stack<tuple<int,int,int>> sp2;
	sp2.push({0,-1,-1});
	while(!sp2.empty()){
		int v = get<0>(sp2.top());
		int f = get<1>(sp2.top());
		int fe = get<2>(sp2.top());
		sp2.pop();
		if(f != -1){
			if(child[v]*2 == N){
				halfchild1 = f;
				halfchild2 = v;
				halfedge = get<2>(G[f][fe]);
			}
			else{
				long cost = (S[v] - S[f]) / (N - child[v]*2);
				ans[get<2>(G[f][fe])] = cost;
				G[f][fe] = {get<0>(G[f][fe]),cost,get<2>(G[f][fe]),get<3>(G[f][fe])};
				int fe2 = get<3>(G[f][fe]);
				G[v][fe2] = {get<0>(G[v][fe2]),cost,get<2>(G[v][fe2]),get<3>(G[v][fe2])};
			}
		}
		for(int i=0;i<G[v].size();i++){
			int t = get<0>(G[v][i]);
			if(t != f){
				sp2.push({t,v,i});
			}
		}
	}
	if(halfchild1 != -1){
		sp.push({halfchild1,-1});
		while(!sp.empty()){
			int v = sp.top().first;
			int f = sp.top().second;
			sp.pop();
			if(v >= N){
				v -= N;
				child[v] = 1;
				for(int i=0;i<G[v].size();i++){
					int t = get<0>(G[v][i]);
					if(t != f){
						sumcost[v] += sumcost[t] + get<1>(G[v][i])*child[t];
						child[v] += child[t];
					}
				}
			}
			else{
				sp.push({v+N,f});
				for(int i=0;i<G[v].size();i++){
					int t = get<0>(G[v][i]);
					if(t != f){
						sp.push({t,v});
					}
				}
			}
		}
		ans[halfedge] = (S[halfchild1]-sumcost[halfchild1]) / (child[halfchild2]);
	}
	for(int i=0;i<N-1;i++){
		cout << ans[i] << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 14832
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;
int gcd(int a, int b) { while (a) { b %= a; swap(a, b); } return b; }
bool solve(int n, vector<int> & a) {
    ll sum = whole(accumulate, a, 0ll);
    bool is_first = (sum - n) % 2;
    int even = whole(count_if, a, [&](int ai) { return ai % 2 == 0; });
    auto odd = whole(find_if,  a, [&](int ai) { return ai % 2 == 1; });
    if (not is_first and even == n-1 and *odd != 1) {
        -- (*odd);
        int d = a[0]; repeat (i,n) d = gcd(d, a[i]);
        repeat (i,n) a[i] /= d;
        return not solve(n, a);
    } else {
        return is_first;
    }
}
int main() {
    int n; cin >> n;
    vector<int> a(n); repeat (i,n) cin >> a[i];
    cout << (solve(n, a) ? "First" : "Second") << endl;
    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main(){
	string str;
	cin >> str;
	int cnt = 0;
	for(int i = 0; i < str.size()/2; i++){
		if(str[i] == 'i'){
			if(str[str.size()-i-1] == 'i');
			else cnt++;
		}
		if(str[i] == 'w'){
			if(str[str.size()-i-1] == 'w');
			else cnt++;
		}
		if(str[i] == '('){
			if(str[str.size()-i-1] == ')');
			else cnt++;
		}
		if(str[i] == ')'){
			if(str[str.size()-i-1] == '(');
			else cnt++;
		}
	}
	if(str.size() % 2 == 1){
		int n = str.size()/2;
		if(str[n] == '(' || str[n] == ')'){
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void){
        int buildings[4][3][10]={0};
        int n;
        cin>>n;
        int b,f,r,v;
        for(int i=0; i<n; i++) {
                cin>>b>>f>>r>>v;
                buildings[b-1][f-1][r-1]+=v;
        }
        for(int i=0; i<4; i++) {
                for(int j=0; j<3; j++) {
                        for(int k=0; k<10; k++) {
                                printf(" %d",buildings[i][j][k]);
                        }
                        printf("\n");
                }
                if(i!=3) {
                        printf("####################\n");
                }
        }
        return 0;

}



Measured memory_bytes: 3144
package main

import (
	"bufio"
	"fmt"
	"os"
)

const Inf = 1 << 60

type Edge struct {
	Target, Cost int
}

func main() {
	N, M := ReadInt(), ReadInt()
	adjL := make([][]*Edge, N)
	for i := 0; i < M; i++ {
		L, R, D := ReadInt()-1, ReadInt()-1, ReadInt()
		adjL[L] = append(adjL[L], &Edge{
			Target: R,
			Cost:   D,
		})
		adjL[R] = append(adjL[R], &Edge{
			Target: L,
			Cost:   -D,
		})
	}
	x := make([]int, N)
	for i := 0; i < N; i++ {
		x[i] = Inf
	}
	ok := true
	for i := 0; i < N; i++ {
		if !dfs(i, x, adjL) {
			ok = false
		}
	}
	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func dfs(v int, x []int, adjL [][]*Edge) bool {
	if x[v] == Inf {
		x[v] = 0
	}
	for _, edge := range adjL[v] {
		if x[edge.Target] == Inf {
			x[edge.Target] = x[v] + edge.Cost
			if !dfs(edge.Target, x, adjL) {
				return false
			}
			continue
		}
		if x[edge.Target] != x[v]+edge.Cost {
			return false
		}
		continue
	}
	return true
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

int main(){
	int N;
	string S, T;
	cin >> N >> S >> T;
	rep(i, N) cout << S.at(i) << T.at(i);
	cout << endl;
	return 0;
}

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


struct mint {
    long long x;
    static const int MOD = 1000000007;
    mint(long long x=0): x(x%MOD) {}

    void operator=(const long long n) {
        x = n % MOD;
    }
    mint operator+(const mint n) {
        mint ret;
        ret.x = (x + n.x) % MOD;
        return ret;
    }
    mint operator-(const mint n) {
        mint ret;
        ret.x = (x - n.x + MOD) % MOD;
        return ret;
    }
    mint operator*(const mint n) {
        mint ret;
        ret.x = (x * n.x) % MOD;
        return ret;
    }
    mint operator/(const mint n) {
        mint ret;
        ret.x = (x * n.inv().x) % MOD;
        return ret;
    }

    mint inv() const {
        mint ret;
        long long a = x, b = MOD, u = 1, v = 0;
        while(b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        ret.x = u;
        return ret;
    }
};

mint mpow(mint a, int n) {
    mint ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * a;
        a = a * a;
        n >>= 1;
    }
    return ret;
}

void factorial(vector<mint>& fact) {
    for (int i = 0; i < fact.size(); i++) {
        if (i == 0 || i == 1) fact[i] = 1;
        else fact[i] = fact[i-1] * i;
    }
}

mint c(int n, int a, vector<mint>& fact) {
    return fact[n]/(fact[a]*fact[n-a]);
}

void p(int n, int max_a, vector<mint>& perm) {
    for (int i = 0; i <= max_a; i++) {
        if (i == 0) perm[i] = 1;
        else perm[i] = perm[i-1] * (n-i+1);
    }
}

ostream& operator<<(ostream& os, const mint& n)
{
    os << n.x;
    return os;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);


    int n, m;
    cin >> n >> m;

    vector<int> num;
    for (int i = 0; i < n; i++) {
        num.push_back(-1);
    }
    for (int i = 0; i < m; i++) {
        int s, c;
        cin >> s >> c;
        s--;
        if (num[s] == -1) {
            if (s == 0 && c == 0 && n > 2) {
                cout << -1 << endl; return 0;
            }
            else {
                num[s] = c;
            }
        } else if (num[s] != -1 && num[s] == c) {
            continue;
        } else {
            cout << -1 << endl; return 0;
        }
    }

    for (int i = 0; i < n; i++) {
        if (num[i] == -1) {
            if (i == 0 && n > 1) num[i] = 1;
            else num[i] = 0;
        }
        cout << num[i];
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int K;
	cin >> K;
	int ans = 0;
	int num = mod;
	if (K % 2 == 0 || K % 5 == 0) {
		cout << -1 << endl;
		return 0;
	}
	while (num != 0) {
		if (ans == 0) num = 0;
		ans++;
		num = (num * 10 + 7) % K;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

int n,m;
cin >> n >> m;

vector<pii> v;
if(n % 2) {
    for(int l = 1, r = n-1; l < r; l++,r--) {
        v.push_back(make_pair(l,r));
    }
}
else {
    bool flag = false;
    for(int l = 1, r = n-1; l < r; l++,r--) {
        if(!flag && r-l <= n/2) {
            r--;
            flag = true;
        }
        v.push_back(make_pair(l,r));
    }
}
rep(i,m) cout << v[i].first << ' ' << v[i].second << endl;
return 0;
}

Measured memory_bytes: 4100
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc090/d.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    ll ans = 0;
    ll n, k;
    cin >> n >> k;
    if(k == 0){
        for(ll b = k + 1; b <= n; b++){
            ans += n;
        }
        cout << ans << "\n";
        return 0;
    }
    for(ll b = k + 1; b <= n; b++){
        ll m = n / b;
        ans += (b - k) * m;
        if(n - m * b - k + 1 > 0) ans += n - m * b - k + 1;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = map(int, input().split())

ans = 'APPROVED'
for a_i in a:
    if a_i % 2 == 0:
        if not ((a_i % 3 == 0) or (a_i % 5 == 0)):
            ans = 'DENIED' 
            break
print(ans)


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int n,m,v,s,d,t[361],ans=1e9;
main(){
    cin>>n;
    r(i,n){
        cin>>m>>d>>v>>s;m--;
        int p=m*30+d,ss=s;
        while(v--){
            t[p]=max(t[p],s);
            p++;
            if(p>360)p=1;
        }
        int pp=m*30+d-1;
        if(pp==0)pp=360;
        while(s--){
            t[p]=max(t[p],s);
            p++;
            if(p>360)p=1;
        }
        while(ss--){
            t[pp]=max(t[pp],ss);
            pp--;
            if(pp==0)pp=360;
        }
    }
    r(i,360)ans=min(ans,t[i+1]);
    cout<<ans<<endl;
}

Measured memory_bytes: 3088
N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]
b=-sum(AB[i][1] for i in range(N))
AB.sort(key=lambda x:x[0]+x[1],reverse=True)
for i in range(N):
    if i%2==0:
        b+=sum(AB[i])
print(b)

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

namespace IO {
    const int maxn(1 << 21 | 1);

    char ibuf[maxn], *iS, *iT, c;
    int f;

    inline char Getc() {
        return iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin), (iS == iT ? EOF : *iS++)) : *iS++;
    }

    template <class Int> inline void In(Int &x) {
        for (f = 1, c = Getc(); c < '0' || c > '9'; c = Getc()) f = c == '-' ? -1 : 1;
        for (x = 0; c >= '0' && c <= '9'; c = Getc()) x = (x << 1) + (x << 3) + (c ^ 48);
        x *= f;
    }
}

using IO :: In;

const int maxn(2005);
const int maxm(maxn * maxn);
const int mod(1e9 + 7);

int n, k, f[maxn][maxn], fac[maxm], ifac[maxm], inv[maxm];

inline void Inc(int &x, int y) {
	x += y;
	if (x >= mod) x -= mod;
}

inline int C(int x, int y) {
	if (y > x) return 0;
	return 1LL * fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}

int main() {
	In(n), In(k), f[1][0] = 1;
	if (k == 1) return puts("1"), 0;
	int mx = n * k;
	fac[1] = ifac[1] = fac[0] = ifac[0] = inv[1] = 1;
	for (int i = 2; i <= mx; ++i) {
		inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
		fac[i] = 1LL * fac[i - 1] * i % mod;
		ifac[i] = 1LL * ifac[i - 1] * inv[i] % mod;
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= i; ++j) {
			if (i > j) Inc(f[i][j], f[i - 1][j]);
			if (j) Inc(f[i][j], 1LL * f[i][j - 1] * C(mx - i - (j - 1) * (k - 1) - 1, k - 2) % mod);
		}
	printf("%lld\n", 1LL * f[n][n] * fac[n] % mod);
    return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main()
{
  int a, N, M;
  priority_queue<int> A;
  long long res = 0;
  cin >> N >> M;
  REP(i, N)
  {
    cin >> a;
    A.push(a);
  }
  REP(i, M)
  {
    a = A.top();
    A.pop();
    A.push(a / 2);
  }

  REP(i, N)
  {
    res += A.top();
    A.pop();
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3904
N=int(input())
l=[]
from collections import Counter
for i in range(N):
  l.append(''.join(sorted(input())))
l1=Counter(l).values()
from math import factorial
ans=0
for a in l1:
  if a >= 2:
    ans+=int(factorial(a)/(factorial(a-2)*factorial(2)))
print(ans)

Measured memory_bytes: 19784
#include <iostream>
#include <cmath>
using namespace std;
int main (){

  int n,a,b,c=0,d,e;

  cin >>n;
  
  for( int i=0 ; i < n ; i++){
    
    cin >>a;
    
    b=0;
    e=a%2;

    if( e == 0 && a != 2)continue;

    if( a == 2 ){
      c++;
	}else{
    
      for( int j=1 ; j <= sqrt(a) ; j+=2 ){
	
	d=a%j;
	
	if( d == 0 ){
	  b++;
	}
	if( b == 2 )break;
      }
      
      if( b == 1 ){
	c++;
      }
    }
  }

  cout <<c<<endl;
  
  return 0;

}

Measured memory_bytes: 1160
PROGRAM ATCODER

implicit none
integer :: n,q,i,j
character(len=2*10**5) :: s
character(len=1),allocatable :: d(:),t(:)

read*, n,q,s
allocate(t(q),d(q))
do i = 1, q, 1
  read*, t(i),d(i)
end do

print'(i0)', bin_s(1)-bin_s(0)

contains
!!!!!! サブルーチンは↓
logical function isOK(index,key) !indexが条件を満たすかどうか
  implicit none
  integer,intent(in) :: index,key
  if ( check(index) >= key ) then !a(index)がkey以上になる最小のindex
    isOK = .true.
  else
    isOK = .false.
  end if
end function isOK

integer function bin_s(key)
  implicit none
  integer,intent(in) :: key
  integer :: ng,ok,mid
  ng = 0 ; ok = len_trim(s)+1
  do while ( abs(ok-ng) > 1 )
    mid = (ok+ng)/2
    if ( isOK(mid,key) ) then
      ok = mid
    else
      ng = mid
    end if
  end do
  bin_s = ok
end function bin_s

!とある地点(x=start)のゴーレムが落ちるか否か
integer function check(start)
  implicit none
  integer,intent(in) :: start
  integer :: i,x
  x = start
  do i = 1, q, 1
    if ( s(x:x) == t(i) ) then
      if ( d(i) == 'L' ) then
        x = x - 1
      else
        x = x + 1
      end if
    end if
    if ( x == 0 ) then
      check = -1
      return
    else if ( x == n+1 ) then
      check = +1
      return
    end if
  end do
  check = 0
end function

END PROGRAM ATCODER

Measured memory_bytes: 1084
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
typedef long long LL;
typedef long double DD;
const int inf = 1e9;
const int mo= 1e9+7;
const int N = 101010;
int n, m, num[N];
int l[N], r[N];
vector<int> son[N];
bool flag = 1;

void dfs(int x,int fa){
	if(num[x]!=-1){
		l[x] = r[x] = num[x];
	}
	else {
		l[x] = -inf;
		r[x] = inf;
	}
	for(unsigned int i = 0; i < son[x].size();i++){
		int y = son[x][i];
		if(y == fa)
			continue;
		dfs(y,x);
		if(!flag)return;
		if(l[y] == -inf) 
			continue;
		int tl = l[y] - 1, tr = r[y] + 1;
		if(l[x] == -inf){
			l[x] = tl;
			r[x] = tr;
			continue;
		}
		if( ((l[x] & 1) ^ (tl & 1)) || (tl > r[x]) || (tr < l[x])){
			flag=0;
			return ;
		}
		l[x] = max(l[x], tl);
		r[x] = min(r[x], tr);
	}
	
}

void getans(int x,int fa,int t){
	num[x] = t;
	for(unsigned int i = 0; i < son[x].size(); i++){
		int y = son[x][i];
		if(y == fa)
			continue;
		if(l[y] <= t - 1  && r[y] >= t - 1)
			getans(y, x, t - 1);
		else 
			if(l[y] <= t + 1 && r[y] >= t + 1)
				getans(y, x, t + 1);
	}
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i < n; i++){
		int x,y;
		scanf("%d%d", &x, &y);
		son[x].push_back(y);
		son[y].push_back(x);
	}
	memset(num, -1, sizeof(num));
	scanf("%d", &m);
	for(int i = 1; i <= m; i++){
		int x,t;
		scanf("%d%d", &x, &t);
		num[x] = t;
	}
	dfs(1, 0);
//	for(int i = 1; i<= n; i++)
//		printf("%d %d\n", l[i], r[i]);
	if(flag){
		puts("Yes");
		if(l[1] == -inf)
			l[1] = 0;
		getans(1, 0, l[1]);
		for(int i = 1; i <= n; i++)
			printf("%d\n", num[i]);
	}
	else puts("No");
	return 0;
}

Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll a,b;
  cin >> a >> b;
  if(a<=0&&0<=b) pr("Zero");
  else if(b<0&&abs(a-b)%2==0) pr("Negative");
  else pr("Positive");
}

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


Measured memory_bytes: 256
k,a,b=map(int,input().split())
if a+2>=b:print(k+1)
elif a>=k:print(k+1)
else:
    k-=(a+1)
    ans=b+(b-a)*(k//2)
    if k%2==1:print(ans+1)
    elif k%2==0:print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
const ll INF = 1LL << 60;
int main()
{
    int n, m;
    cin >> n >> m;
 
    cout << ((n*500>=m)?"Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}

int divnum(int n){

    int cnt = 0;
    for(int i = 1; i*i <= n; ++i){
        if(n%i == 0) cnt += 2;
        if(i*i == n) --cnt;
    }
    return cnt;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    int n;
    cin >> n;

    int cnt = 0;
    for(int i = 1; i <= n; i += 2){
        if(divnum(i) == 8) ++cnt;
    }
    cout << cnt << '\n';


    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>bool chmax(T &a, const T &b) { if (a<=b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<=a) { a=b; return 1; } return 0; }
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

vector<int> t_sort(vector<vector<int>> &g) {
    int n=sz(g);
    vector<int> order,iri(n);
    for(auto &v:g) {
        for(int &x:v) {
            iri[x]++;
        }
    }
    
    queue<int> q;
    rep(i,n) {
        if(iri[i]==0) q.push(i);
    }
    while(sz(q)) {
        int now=q.front(); q.pop();
        order.push_back(now);
        for(int x:g[now])  {
            iri[x]--;
            if(iri[x]==0) q.push(x);
        }
    }
    
    return order;
}

int main() {
    int n,m;
    cin>>n>>m;
    vector<vector<int>> to(n);
    rep(i,m) {
        int x,y;
        cin>>x>>y;
        x--;y--;
        to[x].push_back(y);
    }
    
    vector<int> vec=t_sort(to);
    vector<int> dp(n+10);
    rep(i,n) {
        for(int x:to[vec[i]]) {
            chmax(dp[x],dp[vec[i]]+1);
        }
    }
    cout<<dp[vec[n-1]]<<endl;
}


Measured memory_bytes: 6780
#!/usr/bin/env python3
import sys
# from scipy.special import comb
sys.setrecursionlimit(10**4)
from math import factorial

def comb(n, r):
    '''
    >>> comb(2, 1)
    2
    >>> comb(3, 2)
    3
    '''
    if r == 0:
        return 1
    if n == 0 or r > n:
        return 0
    return factorial(n) // factorial(n - r) // factorial(r)

def f(S, i, k):
    # ここに来るのは繰り下がりが発生していない状態...
    if k == 0:
        # 以降は0を選び続けるしかない
        return 1
    if len(S) <= i:
        # 走破したのにK個使いきれていない
        return 0
    n = int(S[i])
    if n == 0:
        # 注目する桁が0の場合、0を選ぶしかない
        return f(S, i+1, k)
    # 注目する桁の数値nより小さい値を選べば、以降は繰り下げで選び放題
    ret = (n - 1) * comb(len(S)-i-1, k-1) * pow(9, k-1)
    ret += comb(len(S)-i-1, k) * pow(9, k)
    # 注目する桁の数値nを選んだ場合、繰り下げができない状態が続行    
    ret += f(S, i+1, k-1)
    return ret

def solve(S: str, K: int):
    return f(S, 0, K)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    print(solve(N, K))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    test()
    main()


Measured memory_bytes: 7876
import java.util.*;

class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    char[] S = sc.next().toCharArray();
    int[] counts = new int[N];
    int min = 0;
    for(int i=1; i < N; i++){
      if(S[i] == 'E'){
        ++min;
      }
    }
    
    int current = min;    
    for(int i=1; i < N; i++){
      if(S[i] == 'E') --current;
      if(S[i - 1] == 'W') ++current;
      if(min > current){
        min = current;
      }
    }
    
    System.out.println(min);
  }
}

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

int main(){
    int a, b;
    bool flag = false;
    cin >> a >> b;

    if(a % 3 == 0){
        flag = true;
    }
    if(b % 3 == 0){
        flag = true;
    }
    if((a + b) % 3 == 0){
        flag = true;
    }

    if(flag){
        cout << "Possible" << endl;
    }
    else{
        cout << "Impossible" << endl;
    }

    return 0;
}

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

using namespace std;

int main()
{
	int N;

	while (true)
	{
		scanf("%d", &N);

		if (N == 0) { break; }

		vector<pair<int, int> > D(N);

		for (int i = 0; i < N; i++)
		{
			scanf("%d", &D[i].first);
			scanf("%d", &D[i].second);
		}

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

		int ret = 0;

		for (int i = 0; i < N; i++)
		{
			for (int j = i + 1; j < N; j++)
			{
				int rx1 = D[i].first - (D[j].second - D[i].second);
				int ry1 = D[i].second + (D[j].first - D[i].first);
				int rx2 = D[j].first - (D[j].second - D[i].second);
				int ry2 = D[j].second + (D[j].first - D[i].first);

				if (binary_search(D.begin(), D.end(), make_pair(rx1, ry1)) && binary_search(D.begin(), D.end(), make_pair(rx2, ry2)))
				{
					ret = max(ret, (D[j].first - D[i].first) * (D[j].first - D[i].first) + (D[j].second - D[i].second) * (D[j].second - D[i].second));
				}
			}
		}

		printf("%d\n", ret);
	}

	return 0;
}

Measured memory_bytes: 3232
#include<stdio.h>
#include<string.h>
int main()
{
    int a,b=0,c=0,i;

    scanf("%d",&a);
    for(i=0;i<a;i++){
        char x[100],y[100];
        scanf("%s%s",&x,&y);
        if (strcmp(x,y)>0)b+=3;
        else if (strcmp(x,y)<0)c+=3;
        else{
            b++;
            c++;
        }
    }
    printf("%d %d\n", b, c);
    return 0;
}

Measured memory_bytes: 604
strS = input()
S0 = []
S1 = []
changeA = 0
changeB = 0
S = [int(s) for s in strS]
for i in range(len(strS)):
    if (i % 2 == 0):
        S0.append(0)
        S1.append(1)
    else:
        S0.append(1)
        S1.append(0)

for i in range(len(S)):
    if not S[i] == S0[i]:
        changeA += 1
    if not S[i] == S1[i]:
        changeB += 1
if changeA > changeB :
    print(changeB)
else :
    print(changeA)


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

int main(){
	int N,K,a[5000];
	cin>>N>>K;
	rep(i,N) cin>>a[i];
	sort(a,a+N);

	int res=N;
	set<int> sum;
	sum.insert(0);
	for(int i=N-1;i>=0;i--){
		for(auto it=sum.rbegin();it!=sum.rend();++it){
			int next = *it+a[i];
			if(K<=next){
				res=i;
				break;
			}
			sum.insert(next);
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 512
n = int(input())
for i in range(n):
  x1, y1, x2, y2, x3, y3, x4, y4 = [float(j) * 10**10 for j in input().split()]
  if x2 == x1:
    if x4 == x3:
      print("YES")
    else:
      print("NO")
  elif x4 == x3:
    print("NO")
  else:
    print("YES" if (y2 - y1) / (x2 - x1) == (y4 - y3) / (x4 - x3) else "NO")

Measured memory_bytes: 5620
#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;

int seiyaku_check(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

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

	seiyaku_check(a,0,9);
	seiyaku_check(b,0,9);
	
	if(a>=b){
		cout << "10" << endl;
	}else{
		cout << "0" << endl;
	}
	
return 0;
}


Measured memory_bytes: 256
from collections import deque
n=int(input())
blist=deque([int(input()) for a in range(n)])
vlist=1
count=0
while True:
    if count>n:
        print(-1)
        break
    if 2 == vlist:
        print(count)
        break
    vlist=blist[vlist-1]
    count+=1

Measured memory_bytes: 53720
N = int(input())
S = input()

A = []

for n in range(N):
    if n == 0:
        L = 0
        R = sum([s == 'E' for s in S[n+1:]])
    else:
        L += 0 if S[n-1] == 'E' else 1
        R -= 0 if S[n]   != 'E' else 1
    A.append(L+R)

print(min(A))


Measured memory_bytes: 18804
n = int(input())
A = [int(i) for i in input().split()]
diff = [A[i+1] - A[i] for i in range(n-1)]
# if slope is upward, buy if possible
# if slope is negative, sell if possible
cash = 1000
stock = 0
for i in range(n-1):
    if diff[i] > 0:
        # buy
        inc_stock = cash //A[i]
        stock += inc_stock
        cash -= inc_stock * A[i]
    else:
        #sell all stock
        cash += stock * A[i]
        stock = 0
cash += stock * A[-1]
print(cash)

Measured memory_bytes: 61812
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define inl(a) cin >> a
#define prl(a) cout << a << " "
#define outl(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<int,pair<int,int> > >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define N 1005
typedef long long int ll;
int dp[N][N],v[N][N];
int sum(int a,int b)
{
    int c=a+b;
    if(c>M)
        c-=M;
    return c;
}
int main()
{
    int n,m,i,j;
    in2(n,m);
    string str;
    lp(i,1,n+1)
    {
        inl(str);
        rep(j,m)
            if(str[j]=='#')v[i][j+1]=1;
    }
    dp[0][1]=1;
    lp(i,1,n+1)
    {
        lp(j,1,m+1)
        {
            if(!v[i][j])
                dp[i][j]=sum(dp[i-1][j],dp[i][j-1]);
        }
    }
    out(dp[n][m]);


}


Measured memory_bytes: 8064
d = int(input())
c = tuple(map(int, input().split()))
s = [
    tuple(map(int, input().split()))
    for _ in range(d)
]

m = 0
ans = []
last = [0] * 26
for i in range(d):
    # for all contest
    mdmax = -10000000000000000
    mdi = 0
    for j, ss in enumerate(s[i]):
        md = 0
        # choose one contest to open
        for k in range(26):
            if j == k:
                md += ss
            else:
                md -= (i + 1 - last[k]) * c[k]
        if md > mdmax:
            mdi = j
            mdmax = md

    ans.append(mdi + 1)
    m += mdmax

    last[mdi] = d + 1

for a in ans:
    print(a)


Measured memory_bytes: 9400
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include "bits/stdc++.h"

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define deb(x) cerr << (#x) << " is " << (x) << '\n'

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef long long lint;
typedef double ld;

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

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

	int r;
	cin >> r;
	ld pi = 2 * acos(0);
	cout << fixed << setprecision(15) << pi * r * 2;
	return 0;               
}
// Write Here
	


Measured memory_bytes: 3804
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}


int main(){
  
  int h,w;
  cin>>h>>w;
  bool dp[h][w][2*6400+1] = {};
  int a[h][w];
  int b[h][w];
  REP(i,h){
    REP(j,w){
      cin>>a[i][j];
    }
  }
  REP(i,h){
    REP(j,w){
      cin>>b[i][j];
    }
  }
  REP(i,h){
    REP(j,w){
      if(i == 0 && j == 0){
        dp[i][j][a[i][j]-b[i][j]+6400] = true;
        dp[i][j][b[i][j]-a[i][j]+6400] = true;
      }else if(i == 0){
        REP(k,2*6400+1){
          if(dp[i][j-1][k]){
            if(-6400 <= k-6400+a[i][j]-b[i][j] && k-6400+a[i][j]-b[i][j]<=6400){
              dp[i][j][k+a[i][j]-b[i][j]] = true;
            }
            if(-6400 <= k-6400+b[i][j]-a[i][j] && k-6400+b[i][j]-a[i][j]<=6400){
              dp[i][j][k+b[i][j]-a[i][j]] = true;
            }
          }
        }
      }else if(j == 0){
        REP(k,2*6400+1){
          if(dp[i-1][j][k]){
            if(-6400 <= k-6400+a[i][j]-b[i][j] && k-6400+a[i][j]-b[i][j]<=6400){
              dp[i][j][k+a[i][j]-b[i][j]] = true;
            }
            if(-6400 <= k-6400+b[i][j]-a[i][j] && k-6400+b[i][j]-a[i][j]<=6400){
              dp[i][j][k+b[i][j]-a[i][j]] = true;
            }
          }
        }
      }else{
        REP(k,2*6400+1){
          if(dp[i][j-1][k]){
            if(-6400 <= k-6400+a[i][j]-b[i][j] && k-6400+a[i][j]-b[i][j]<=6400){
              dp[i][j][k+a[i][j]-b[i][j]] = true;
            }
            if(-6400 <= k-6400+b[i][j]-a[i][j] && k-6400+b[i][j]-a[i][j]<=6400){
              dp[i][j][k+b[i][j]-a[i][j]] = true;
            }
          }
        }
        REP(k,2*6400+1){
          if(dp[i-1][j][k]){
            if(-6400 <= k-6400+a[i][j]-b[i][j] && k-6400+a[i][j]-b[i][j]<=6400){
              dp[i][j][k+a[i][j]-b[i][j]] = true;
            }
            if(-6400 <= k-6400+b[i][j]-a[i][j] && k-6400+b[i][j]-a[i][j]<=6400){
              dp[i][j][k+b[i][j]-a[i][j]] = true;
            }
          }
        }
      }
    }
  }
  int ans = 6400;
  REP(k,2*6400+1){
    if(dp[h-1][w-1][k]){
      ans = min(ans, abs(k-6400));
    }
  }
  cout<<ans<<endl;   
  return 0; 
}


Measured memory_bytes: 80384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a ,b,c;
    scanf("%d %d",&a,&b);
    c=a*b;
    if(c%2==0)
    {
        printf("Even\n");
    }
    else
    {
        printf("Odd\n");
    }
    return 0;
}


Measured memory_bytes: 256
import * as fs from 'fs';

namespace AtCoder.abc100 {
    export class ProgramA {
        args: string[];

        constructor(args: string[]) {
            this.args = args;
        }

        main() {
            const [a, b]: number[] = this.args[0].split(' ').map(Number);

            if (a > 8 || b > 8) {
                console.log(':(');
                return;
            }
            console.log('Yay!');
        }
    }
}

const args: string[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const func: AtCoder.abc100.ProgramA = new AtCoder.abc100.ProgramA(args);
func.main();


Measured memory_bytes: 7372