akhauriyash/Code-Regression huggingface dataset:
N = gets.to_i
H = gets.split(' ').map(&:to_i)
result = 0
tmp = 0

for index in 1..N-1 do
  if H[index-1] >= H[index]
    tmp += 1
  else
    result = [result, tmp].max
    tmp = 0
  end
end

puts [result, tmp].max



Measured memory_bytes: 11012
import java.util.Scanner;

public class Main {

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

    final int mod = 1000000007;

    int[] steps = new int[n + 1];

    for (int i = 0; i < m; ++i)
      steps[sc.nextInt()] = -1;

    steps[n] = 1;
    steps[n - 1] = (steps[n - 1] == -1) ? -1 : 1;

    for (int i = n - 2; i >= 0; --i) {
      if (steps[i] == -1)
        continue;
      steps[i] = (steps[i + 1] == -1) ? steps[i] : steps[i] % mod + steps[i + 1] % mod;
      steps[i] = (steps[i + 2] == -1) ? steps[i] : steps[i] % mod + steps[i + 2] % mod;
    }

    System.out.println(steps[0] % mod);
  }
}

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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define I1000000007 (1000000007)
#define I998244353   (998244353)
#define IINF             (1<<28)
#define LINF           (1LL<<60)
#define ALL(a)         (a).begin(), (a).end()
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"
template<class T> inline bool chmin(T& a, const T& b) {
  if (a > b) { a = b; return true; } else return false;
}
template<class T> inline bool chmax(T& a, const T& b) {
  if (a < b) { a = b; return true; } else return false;
}

namespace solver {
  using namespace std;
  using ll = long long;

  struct edge {
    int to, cap, rev;
  };
  int N, as[110], bs[110], cs[110], ds[110];
  vector<vector<edge> > G;
  vector<int> used;

  void init() {
    cin >> N;
    rep(i, N) {
      cin >> as[i] >> bs[i];
    }
    rep(i, N) {
      cin >> cs[i] >> ds[i];
    }
    G.resize(2*N+2);
    used.resize(2*N+2);
  }

  int dfs(int u, int t, int f) {
    used[u] = true;
    if(u == t) return f;
    for(auto& e : G[u]) {
      if(used[e.to] || e.cap <= 0) continue;
      int d = dfs(e.to, t, min(f, e.cap));
      if(d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
    return 0;
  }

  void solve() {
    int s = 2 * N, t = s + 1;
    rep(i, N) {
      G[s].push_back((edge){ i, 1, (int)G[i].size() });
      G[i].push_back((edge){ s, 0, (int)G[s].size()-1 });
      G[i+N].push_back((edge){ t, 1, (int)G[t].size() });
      G[t].push_back((edge){ i+N, 0, (int)G[i+N].size()-1 });
    }
    rep(i, N) rep(j, N) {
      if(as[i] < cs[j] && bs[i] < ds[j]) {
        G[i].push_back((edge){ j+N, 1, (int)G[j+N].size() });
        G[j+N].push_back((edge){ i, 0, (int)G[i].size()-1 });
      }
    }
    int ans = 0;
    while(1) {
      fill(ALL(used), false);
      int d = dfs(s, t, IINF);
      if(d <= 0) break;
      ans += d;
    }
    cout << ans << "\n";
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

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

using namespace std;

typedef long long LL;
const int MAXN=2e5+10;
LL h[MAXN],dp[MAXN];
LL n,c;
deque<int> que;

double slope(int j, int k) {
	return double((dp[j]+h[j]*1ll*h[j])-(dp[k]+h[k]*1ll*h[k]))/(2ll*h[j]-2ll*h[k]);
}

int main(){
	cin>>n>>c;
	for(int i=1;i<=n;i++) cin>>h[i];
	
	que.push_front(1);
	
	for(int i=2;i<=n;i++){
		while(que.size()>1&&slope(que[0],que[1])<=h[i]){
			que.pop_front();
		}
		int j=que[0];
		dp[i]=dp[j]+(h[i]-h[j])*(h[i]-h[j])+c;
		int sz=que.size();
		while(sz>1&&slope(que[sz-1],que[sz-2])>=slope(que[sz-1],i)){
			que.pop_back();
			sz=que.size();
		}
		que.push_back(i);
	}
	cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 3968
#include <stdio.h>
#define MOD 1000000007

int main(){
  int n,k;
  scanf("%d %d",&n,&k);
  long c[2001][2001] = {};
  c[0][0] = 1;
  c[1][0] = 1;
  c[1][1] = 1;
  for(int a=2;a<2001;a++){
    c[a][0] = 1;
    c[a][a] = 1;
    for(int b=1;b<a;b++){
      c[a][b] = (c[a-1][b-1] + c[a-1][b]) % MOD;
    }
  }
  long long answer;
  for(int i=1;i<=k;i++){
    if(i <= n-k+1){
      answer = (c[n-k+1][i] % MOD)*(c[k-1][i-1] % MOD);
      printf("%lld\n",answer % MOD);
    }else{
      printf("0\n");
    }
  }
  return 0;
}

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

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

    int n, k;
    cin >> n >> k;

    cout << n-k+1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define max(a,b) ((a>b) ? a : b)
#define min(c,d) ((c<d) ? c : d)
#define NUM 200010

typedef struct
{
	int time;
	int place;
	char con;//startなら1,endなら-1
}roadwork;

//ここから二分探索木
typedef struct bt
{
	int value;
	struct bt *left;
	struct bt *right;
}btree;

//int btsize=0;
btree *root;
//root = NULL;

void insert(int value)
{
	btree *x,*y,*z;
	z = (btree *)(malloc(sizeof(btree)));//新しい要素のメモリ確保
	z->value=value;
	z->left=NULL;
	z->right=NULL;
	
	x=root; y=NULL;
	while(x!=NULL)
	{
		y=x;
		if(z->value < x->value)x = x->left;
		else x = x->right;
	}
	if(y==NULL)root=z;
	else if(z->value < y->value)y->left=z;
	else y->right=z;
	//printf("inserted %d\n",value);
}

btree *del(btree *dstt, btree *t)
{
	btree *q;
	if(t->right!=NULL)t->right = del(dstt,t->right);
	else
	{
		dstt->value = t->value; 
		q = t;
		t = t->left;
		free(q);
	}
	return(t);
}

void delete(int value)
{
	btree *x,*y,*z,*p;
	x=root;
	while(x!=NULL && x->value!=value)
	{
		p=x;//親になる
		if(value < x->value)x = x->left;
		else x = x->right;
	}
	//printf("%d %d\n",x->left,x->right);
	y=x;//削除されるべき値を持ったノード
	if(y->right==NULL)//右部分木がない
	{
		z = y;
		if(y==root)root =y->left;
		else if(value < p->value)p->left =y->left;
		else p->right = y->left;
		free(z);
	}
	else if(y->left==NULL)//左部分木がない
	{
		z = y;
		if(y==root)root =y->right;
		else if(value < p->value)p->left =y->right;
		else p->right = y->right;
		//printf("%d %d\n",y,*(y));
		free(z);
	}
	else
	{
		y->left = del(y,y->left);//左部分木の最右節点をこの木の根に移動する
	}
	//printf("deleted %d\n",value);
}

int minvalue()
{
	btree *x,*y;
	x=root;
	while(x!=NULL)
	{
		y=x;
		x=x->left;
	}
	if(x==root)return -1;
	else return (y->value);
}

//ここまで二分探索木

int cmp(const void *p,const void *q)//降順
{
	if(((roadwork*)p)->time == ((roadwork*)q)->time)return ((roadwork*)p)->con - ((roadwork*)q)->con;
	else return ((roadwork*)p)->time - ((roadwork*)q)->time;
}

int main()
{
	int n,q,s,t,x;
	int ans,i,j;
	roadwork rwlst[NUM*2];
	int qlst[NUM];
	int anslst[NUM];
	
	scanf("%d %d",&n,&q);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&s,&t,&x);
		rwlst[i*2].time=s-x;//max((s-x),0);
		rwlst[i*2].place=x;
		rwlst[i*2].con=1;
		rwlst[i*2+1].time=t-x;//=max((t-x),0);
		rwlst[i*2+1].place=x;
		rwlst[i*2+1].con=-1;
	}
	for(j=0;j<q;j++)
	{
		scanf("%d",qlst+j);
		anslst[j]=-1;
	}
	
	qsort(rwlst,n*2,sizeof(roadwork),cmp);
	/*
	for(int i=0;i<2*n;i++)
	{
		printf("event: time=%d,place=%d,con=%d\n",rwlst[i].time,rwlst[i].place,rwlst[i].con);
	}
	*/
	
	int clock=0;
	//int lasttime=min((rwlst[n*2-1].time),qlst[q-1]);
	int rwnum=0,qnum=0;
	//printf("%d",lasttime);
	while(rwnum<n*2&&qnum<q)
	{
		if(rwlst[rwnum].time<=qlst[qnum])
		{
			if(rwlst[rwnum].con==1)insert(rwlst[rwnum].place);
			else delete(rwlst[rwnum].place);
			rwnum++;
		}
		else
		{
			anslst[qnum]=minvalue();
			qnum++;
		}
	
	}
	
	for(j=0;j<q;j++)
	{
		printf("%d\n",anslst[j]);
	}
	return 0;
}


Measured memory_bytes: 13632
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN
    
    ll n,m;cin>>n>>m;
    vll a(m), b(m);
    vll c(n+2,0);
    REP(i,m){
        cin>>a[i]>>b[i];
        a[i]--; b[i]--;
    }
    
    set<ll> st;
    string ans="IMPOSSIBLE";
    REP(i,m){
        if (a[i]==0) c[b[i]]=1;
    }
    REP(i,m){
        if(b[i]==n-1 && c[a[i]]) {ans="POSSIBLE"; break;}
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7924
#include <iostream>
using namespace std;
int main() {
	int w;
	int h;
	int x;
	int y;
	int r;
	cin >> w;
	cin >> h;
	cin >> x;
	cin >> y;
	cin >> r;
	if (((w >=x+r ) && (h >= y+r))&&((x-r >= 0)&&(y-r >= 0)))
		cout << "Yes" << endl;
	else
		cout << "No"  << endl;
	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;

signed main(){
    string S;
    cin >> S;
    
    int cnt = 0;
    if(S[2] != S[3]) cnt++;
    if(S[4] != S[5]) cnt++;
    
    if(cnt == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int val;
        cin >> val;
        N -= val;
    }
    N >= 0 ? cout << N : cout << -1;
    return 0;
}


Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
    static int MAX = 2000000;
    static int H;
    static int[] A = new int[MAX+1];

    static void maxHeapify(int i) {
        int l, r, largest;
        l = 2 * i;
        r = 2 * i + 1;

        // 左の子、自分、右の子で値が最大のノードを選ぶ
        if(l <= H && A[l] > A[i]) largest = l;
        else largest = i;
        if(r <= H && A[r] > A[largest]) largest = r;

        if(largest != i) {
            int tmp = A[i];
            A[i] = A[largest];
            A[largest] = tmp;
            maxHeapify(largest);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        H = sc.nextInt();
        for(int i = 1; i <= H; i++) A[i] = sc.nextInt();

        for(int i = H / 2; i >= 1; i--) maxHeapify(i);

        for(int i = 1; i <= H; i++) {
            System.out.print(" " + A[i]);
        }
        System.out.println();
    }
}



Measured memory_bytes: 178656
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

#val = 0

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def get_nodes(self):
		return self.graph.keys()

def DFS(G, W, node):
	cnt = 0
	child = []
	for i in G.graph[node]:
		DFS(G, W, i)
		child.append(W[i])
		cnt += 1

	child.sort()
	rev = [i for i in range(cnt, -1, -1)]
	weight = 0
	for i in range(cnt):
		weight = max(weight, rev[i] + child[i])

	W[node] = weight


def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	G = Graph()
	for i in range(N - 1):
		a = int(input()) - 1
		b = i + 1
		G.add_edge(a, b)

	# print(G.graph)

	#DFS
	W = [0] * N
	DFS(G, W, 0)

	print(W[0])



if __name__ == '__main__':
	main()

Measured memory_bytes: 123808
from bisect import bisect_left as bil
from bisect import bisect_right as bir
x, N = map(int, input().split())
*A, = map(int, input().split())
S = set(A)

mn = 1 <<60
mna = -1
for i in range(-100, 200):
    if i in S:
        continue
    if abs(i - x) < mn:
        mn  = abs(i - x)
        mna = i

print(mna)

Measured memory_bytes: 9196
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  
  string s = "";
  while(n != 0) {
    int r = n % 2;
    if (r < 0) {
      r += 2;
    }
    n = (n - r) / (-2);
    s += (char)('0' + r);
  }
  
  reverse(s.begin(), s.end());
  if (s == "") {
    s = '0';
  }
  
  cout << s << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  map<string,int> m;
  rep(i,n){
    string s; cin >> s;
    sort(all(s));
    m[s]++;
  }
  ll ans=0;
  for(auto p : m){
    int s=p.second;
    ans+=(ll)s*(s-1)/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 11136
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld =long double;
const ld eps = 1e-9;

bool check(const vector<vector<pair<int, int>>>&humans, int x, int y) {
	for (int i = 0; i < 4; ++i) {
		auto it=find(humans[i].begin(),humans[i].end(),make_pair(x,y));
		if(it!=humans[i].end())return false;
	}
	return true;
}

int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };

int main()
{
	while (true) {
		int W,H;cin>>W>>H;
		if(!W)break;
		vector<vector<int>>field(H,vector<int>(W));

		string name="WSEN";

		vector<vector<pair<int,int>>>humans(4);
		for (int i = 0; i < H; ++i) {
			string st;cin>>st;
			for (int j = 0; j < W; ++j) {
				char ch(st[j]);
				if(ch=='#')field[i][j]=1;
				else if(ch=='.')field[i][j]=0;
				else if(ch=='X')field[i][j]=2;
				else {
					int k=name.find(ch);
					if (k == string::npos) {
						assert(false);
					}
					else {
						field[i][j]=0;
						k=k%4;
						humans[k].push_back(make_pair(j,i));
					}
				}
			}
		}

		int time;
		for (time = 1; time < 200; ++time) {
			vector<vector<int>>ways(4);
			vector<vector<pair<int, int>>>next_humans(4);
			for (int i = 0; i < 4; ++i) {
				for (auto human : humans[i]) {
					int now_x = human.first;
					int now_y = human.second;

					int ans = 4;

					for (int plus_way = -1; plus_way <3; ++plus_way) {
						int next_way = (i + 4 + plus_way) % 4;

						int next_x = now_x + dx[next_way];
						int next_y = now_y + dy[next_way];

						if (field[next_y][next_x] != 1 && check(humans, next_x, next_y) == true) {
							ans = next_way;
							break;
						}
					}
					ways[i].push_back(ans);
				}
			}

			vector<vector<int>>moved(H, vector<int>(W));

			for (int k = 0;k < 5; ++k) {
				for (int i = 0; i < 4; ++i) {
					for (int j = 0; j < humans[i].size(); ++j) {
						if (ways[i][j] == k) {
							if (k == 4) {
								next_humans[i].push_back(humans[i][j]);
							}
							else {
								int next_x = humans[i][j].first + dx[ways[i][j]];
								int next_y = humans[i][j].second + dy[ways[i][j]];

								if (moved[next_y][next_x]) {
									next_humans[ways[i][j]].push_back(humans[i][j]);
								}
								else {

									moved[next_y][next_x] = true;
									if (field[next_y][next_x] == 2) {
										continue;
									}
									next_humans[ways[i][j]].push_back(make_pair(next_x, next_y));
								}
							}
						}
					}
				}
			}
		
			humans=next_humans;
			if (all_of(humans.begin(), humans.end(), [](const vector<pair<int, int>>&v) {return v.empty(); })) {
				break;
			}
		}
		if (time > 180) {
			cout<<"NA"<<endl;
		}
		else {
			cout<<time<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3120
#include <iostream>

int main()
{
    int h1, h2, k1, k2;
    std::cin >> h1 >> h2 >> k1 >> k2;
    
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;

    auto calc_point = [&](int i, int y) -> int {
        return (i / 10) * c + i * a +
               (y / 20) * d + y * b;
    };
    
    int hp = calc_point(h1, h2);
    int kp = calc_point(k1, k2);
    
    if (hp > kp) {
        std::cout << "hiroshi" << std::endl;
    } else if (hp < kp) {
        std::cout << "kenjiro" << std::endl;
    } else {
        std::cout << "even" << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 3116
C = []
for i in range(0, 3):
	C.append([int(x) for x in input().split(' ')])


def sol():
	if (sum(C[0]) - sum(C[1])) % 3 != 0:
		return('No')
	elif (sum(C[1]) - sum(C[2])) % 3 != 0:
		return('No')
	elif (sum(C[2]) - sum(C[0])) % 3 != 0:
		return('No')
	
	elif (C[0][0] + C[1][0] + C[2][0] - (C[0][1] + C[1][1] + C[2][1])) % 3 != 0:
		return('No')
	elif (C[0][1] + C[1][1] + C[2][1] - (C[0][2] + C[1][2] + C[2][2])) % 3 != 0:
		return('No')
	elif (C[0][2] + C[1][2] + C[2][2] - (C[0][0] + C[1][0] + C[2][0])) % 3 != 0:
		return('No')
	else:
		return('Yes')

print(sol())



Measured memory_bytes: 3064
def find(parents, x):
    if parents[x] == x:
        return x
    else:
        parents[x] = find(parents, parents[x])
        return parents[x]

def union(parents, x1, x2):
    y1 = find(parents, x1)
    y2 = find(parents, x2)
    if y1 != y2:
        parents[y1] = y2


n, k, l = map(int, input().split())

parents1 = list(range(n))
for _ in range(k):
    p, q = map(int, input().split())
    union(parents1, p - 1, q - 1)

parents2 = list(range(n))
for _ in range(l):
    r, s = map(int, input().split())
    union(parents2, r - 1, s - 1)

import collections

counter = collections.defaultdict(int)
for i in range(n):
    p1, p2 = find(parents1, i), find(parents2, i)
    counter[(p1, p2)] += 1

ans = ' '.join(str(counter[(find(parents1, i), find(parents2, i))]) for i in range(n))
print(ans)

Measured memory_bytes: 60460
import java.io.BufferedReader
import java.util.*
import kotlin.math.max

fun main() = abc175d()

@OptIn(ExperimentalStdlibApi::class)
fun abc175d() = SimpleFastIOWithToken_abc175d().exec {
    val (n, k) = readInt() to readLong()
    val nexts = IntArray(n) { readInt() - 1 }
    val points = LongArray(n) { readLong() }

    val befores = IntArray(n)
    nexts.forEachIndexed { index, next ->
        befores[next] = index
    }

    var answer = Long.MIN_VALUE

    for (startIndex in 0 until n) {
        var pointPerAround = 0L
        var currIndexAround = startIndex
        val visited = mutableSetOf<Int>()
        while (true) {
            if (!visited.add(currIndexAround)) break
            currIndexAround = nexts[currIndexAround]
            pointPerAround += points[currIndexAround]
        }
        val round = visited.size

        var currIndex = startIndex
        var point = if (pointPerAround > 0) pointPerAround * (k / round - 1) else 0
        repeat((k % round + round).toInt()) {
            currIndex = nexts[currIndex]
            point += points[currIndex]
            answer = max(answer, point)
        }
    }

    println(answer)
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_abc175d(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readLong(): Long = java.lang.Long.valueOf(readString())

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_abc175d.() -> Unit) {
        var t: Throwable? = null
        Thread(null, { action() }, "solve", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, t1 -> t = t1 } }
            .apply { start() }.join()
        t?.let { throw it }
        kotlin.io.print(sb)
    }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 56720
#include <stdio.h>


void rectangle(int H, int W) {

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            printf("#");
        }
        printf("\n");
    }
    printf("\n");

}

int main(int argc, char const *argv[]) {

    while (1) {
        int H, W;
        scanf("%d %d", &H, &W);

        if (H == 0 && W == 0) {
            break;
        } else {
            rectangle(H, W);
        }
    }

    return 0;
}



Measured memory_bytes: 2088
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <string>
#include <cstring>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#include <tuple>

using namespace std;
mt19937_64 rng(58);

vector<int> arrange(int n, int k, int c, string s) {
    // greedy
    vector<int> pos;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'o' && (pos.size() == 0 || pos[pos.size() - 1] < i - c))
            pos.push_back(i);
        if (pos.size() == k) break;
    }
    return pos;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n, k, c;
    string s;
    cin >> n >> k >> c;
    cin >> s;

    // find the leftmost arangement and the rightmost arrangement
    vector<int> left = arrange(n, k, c, s);
    reverse(s.begin(), s.end());
    vector<int> right = arrange(n, k, c, s);
    for (int i = 0; i < k; i++) right[i] = n - 1 - right[i];
    reverse(right.begin(), right.end());
    for (int i = 0; i < k; i++) {
        if (left[i] == right[i])
            cout << left[i] + 1 << endl;
    }
}

Measured memory_bytes: 3572
n = int(input())
h = list(map(int,input().split()))
# 全要素について前後比較。また、比較時に変数に後方を保存
# 次の要素の方が大きかったら、大きくみると山が一区切りするので差分を答えに加える
# 次の要素が小さい場合は、無視。変数の後方保存だけを行う。
# やってることはつまりh[i+1]-h[i]で正のときのみの評価
res = 0
pre = 0
for i in h:
    if i>pre:
        res += i-pre
    pre = i
else:
    print(res)


Measured memory_bytes: 2940
def printlist(al):
    print " ".join(map(str,al))
        

l = input()
al = map(int,raw_input().split())
printlist(al)
for i in xrange(1,l):
    v = al[i]
    j = i-1
    while j >= 0 and al[j]>v:
        al[j+1] = al[j]
        j-=1
    al[j+1]=v
    printlist(al)

Measured memory_bytes: 6444
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#define debug(...) std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;

int main()
{
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int M, D; std::cin >> M >> D;
  auto ret = 0;
  rep(d, 1, D + 1)
  {
    auto a = d % 10;
    auto b = d / 10;
    if (a < 2 || b < 2) continue;
    // debug(a, b, d);
    if (a * b <= M) ret++;
  }
  std::cout << ret << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<unordered_map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok = true, flag = false;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222


 

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


  cin >> s;
  ans = inf;
  rep(i, s.length() - 2) {
    tmp = 0;
    rep(j, 3) {
      ll x = s[i + j] - '0';
      tmp += x * powl(10, 2 - j);
    }
    ans = min(ans, abs(753 - tmp));
  }
  cout << ans << endl;



  return 0;
}



Measured memory_bytes: 512
fun main(){
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val rennrakuList = MutableList(m){ MutableList(2) { 0 } }
    for (i in 0 until m){
        rennrakuList[i] = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
        if (rennrakuList[i][0] > rennrakuList[i][1]) {
            var tmp = rennrakuList[i][0]
            rennrakuList[i][0] = rennrakuList[i][1]
            rennrakuList[i][1] = tmp
        }
    }
    val tunagariList = MutableList(n){ mutableListOf<Int>() }//下のforとあわせてこのListにどの洞窟とどの洞窟がつながってるか書いておく
    for (i in 0 until m){
        tunagariList[rennrakuList[i][0] - 1].plusAssign(rennrakuList[i][1])
        tunagariList[rennrakuList[i][1] - 1].plusAssign(rennrakuList[i][0])
    }


    val seen = MutableList(n){ 0 }
    var todo = mutableListOf<Int>()

    var count = 0//何回再帰したか数える
    tailrec fun myBfs(theNum: Int){

        count++
        val tunagarukazu = tunagariList[theNum-1].size

        for (i in 0 until tunagarukazu){
            if (seen[tunagariList[theNum-1][i] - 1] == 0){
                seen[tunagariList[theNum-1][i] - 1] = theNum
                todo.add(tunagariList[theNum-1][i])
            }
        }

        if (count != n){
            myBfs(todo[count-1])
        } else {
            return
        }
    }



    myBfs(1)

    println("Yes")
    for (i in 1 until n){
        println(seen[i])
    }
}

Measured memory_bytes: 94412
// -*- coding:utf-8-unix -*-

use proconio::input;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

fn main() {
    let (H1, M1, H2, M2,K) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let mut iter = s.split_whitespace().map(|i| i.parse::<i32>().unwrap());
        (
            iter.next().unwrap(),
            iter.next().unwrap(),
            iter.next().unwrap(),
            iter.next().unwrap(),
            iter.next().unwrap(),
        )
    };
    println!("{}", (H2*60+M2)-(H1*60+M1)-K);
}

Measured memory_bytes: 2124
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
int n, f[2], g[2];
int main()
{
    n = read();
    for(int i = 1; i <= n; ++i) 
    {
        int x = read();
        if(!f[0]||f[0] == x) f[0] = x, ++f[1];
        else if(!g[0]||g[0] == x) g[0] = x, ++g[1];
    }
    if(f[0] > g[0]) swap(f[0], g[0]), swap(f[1], g[1]);
    if(!f[0]&&g[0] == n-1&&g[1] == n) puts("Yes");
    else if(f[1]+g[1] != n||(f[0]+1 != g[0]&&f[0])||f[1]+(g[0]-f[1])*2 > n||f[1]+1 > g[0]) puts("No");
    else puts("Yes");
    return 0;
}

Measured memory_bytes: 128
data = input().split()
a = int(data[0])
b = int(data[1])
k = int(data[2])
 
ans = []
for i in range(1, a+1 if a < b else b+1):
    if a%i == 0 and b%i == 0:
        ans.append(i)

print(ans[len(ans)-k])

Measured memory_bytes: 3064
from collections import Counter

CounterKey = ("1", "2", "3", "4", "5", "6", "7", "8", "9")

inputCount = int(input())

for _ in range(inputCount):
    puzzle = []
    mark = []

    if _ != 0:
        print()

    for lp in range(9):
        puzzle.append([item for item in input().split(" ")])
        mark.append([item for item in " " * 9])

    # 横
    for rowIndex, row in enumerate(puzzle):
        counter = Counter(row)
        needNum = [num for num in CounterKey if 1 < counter[num]]

        if not needNum:
            continue

        for colIndex, item in enumerate(row):
            if item in needNum:
                mark[rowIndex][colIndex] = "*"

    # 縦
    for colIndex, col in enumerate(
            zip(puzzle[0], puzzle[1], puzzle[2], puzzle[3], puzzle[4], puzzle[5], puzzle[6], puzzle[7], puzzle[8])):
        counter = Counter(col)
        needNum = [num for num in CounterKey if 1 < counter[num]]

        if not needNum:
            continue

        for rowIndex, item in enumerate(col):
            if item in needNum:
                mark[rowIndex][colIndex] = "*"

    # 四角
    for lp in range(3):
        block = []

        for blockCount, col in enumerate(zip(puzzle[lp * 3], puzzle[lp * 3 + 1], puzzle[lp * 3 + 2])):
            block.extend(col)

            if blockCount % 3 - 2 == 0:

                counter = Counter(block)
                needNum = [num for num in CounterKey if 1 < counter[num]]

                if needNum:

                    for index, item in enumerate(block):
                        if item in needNum:
                            rowIndex, colIndex = lp * 3 + index % 3, blockCount - 2 + index // 3
                            mark[rowIndex][colIndex] = "*"

                block = []

    # 出力
    for p, m in zip(puzzle, mark):
        output = []

        for num, state in zip(p, m):
            output.append(state)
            output.append(num)

        print("".join(output))



Measured memory_bytes: 6012
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    cin >> n;
    int sum = n / 1000;
    if(sum==0){
        cout << "ABC" << endl;
    }
    if(sum==1){
        cout << "ABD" << endl;
    }
    

    return 0;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n,ans=1;
    string s;
    cin>>n>>s;
    
    int now=0;
    REP(i,0,2*n){
        if(i%2==0){
            if(s[i]=='B'){
                now++;
            }else{
                ans = (ans * now)%MOD;
                now--;
                if(now<0){cout<<0<<endl; return 0;}
            }
        }else{
            if(s[i]=='W'){
                now++;
            }else{
                ans = (ans*now)%MOD;
                now--;
                if(now<0){cout<<0<<endl; return 0;}
            }
        }
    }
    int c=1;
    REP(i,0,n){
        c = (c*(i+1))%MOD;
    }
    if(now==0) cout<<(ans*c)%MOD<<endl;
    else cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 720
N = int(input())


def prime_factorization(n):
    table = []
    for x in range(2, int(n**0.5)+2):
        while n % x == 0:
            table.append(x)
            n //= x
    if n > 1:
        table.append(n)
    return table


print("{}:".format(N), *prime_factorization(N))



Measured memory_bytes: 5636
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

using mint = modint998244353;

struct CoordinateCompressor {
private:
    vector<ll> _i2v;
    map<ll, ll> _v2i;
public:
    CoordinateCompressor(const vector<ll>& v) : _i2v(v) {
        sort(_i2v.begin(), _i2v.end());
        _i2v.erase(unique(_i2v.begin(), _i2v.end()), _i2v.end());
        for(ll i = 0; i < _i2v.size(); ++i){ _v2i[_i2v.at(i)] = i; }
    }
    size_t size() const { return _i2v.size(); }
    ll i2v(ll i) const { return _i2v.at(i); }
    ll v2i(ll v) const { return _v2i.at(v); }
};

struct mintcomb{
    vector<mint> fact;
    vector<mint> ifact;
    mintcomb(ll n) : fact(n + 1, 1), ifact(n + 1, 1) {
        for(ll i = 2; i <= n; ++i){
            fact.at(i) = fact.at(i - 1) * i;
            ifact.at(i) = fact.at(i).inv();
        }
    }

    mint factorial(ll k) const { return fact.at(k); }
    mint combination(ll k, ll l) const {
        return fact.at(k) * ifact.at(l) * ifact.at(k - l);
    }
};


int main(){
    ll n;
    cin >> n;
    vector<ll> h(2 * n);
    REP(i, 2 * n){ cin >> h.at(i); }

    CoordinateCompressor cc(h);
    vector<ll> count(cc.size(), 0);
    REP(i, 2 * n){ count.at(cc.v2i(h.at(i)))++; }

    mintcomb mc(2 * n);

    queue<vector<mint>> q;
    REP(i, count.size()){
        const ll k = count.at(i);
        const ll np = k / 2;
        // cerr << "i=" << i << ", k=" << k << ", np=" << np << endl;
        q.push(vector<mint>(np + 1));
        vector<mint>& v = q.back();
        // cerr << "  ";
        REP(j, np + 1){
            v.at(j) = mc.factorial(k) / (mc.factorial(k - 2 * j) * mc.factorial(j) * mint(2).pow(j));
            // cerr << v.at(j).val() << " ";
        }
        // cerr << endl;
    }

    while(q.size() > 1){
        vector<mint> v1 = q.front(); q.pop();
        vector<mint> v2 = q.front(); q.pop();
        vector<mint> v3 = convolution(v1, v2);
        q.push(v3);
    }

    vector<mint> sfact(2 * n + 1);
    sfact.at(0) = 1;
    sfact.at(1) = 1;
    for(ll i = 2; i < sfact.size(); ++i){ sfact.at(i) = i * sfact.at(i - 2); }

    const vector<mint>& v = q.front();

    // cerr << "v = ";
    // REP(i, v.size()){
    //     cerr << v.at(i).val() << " ";
    // }
    // cerr << endl;

    mint ans = sfact.at(2 * n - 1);
    for(ll i = 1; i < min((ll)v.size(), n + 1); ++i){
        mint tmp = 1;
        if(i % 2 == 1){ tmp *= -1; }
        if(2 * (n - i) - 1 >= 0){
            tmp *= sfact.at(2 * (n - i) - 1);
        }
        tmp *= v.at(i);
        ans += tmp;
    }
    cout << ans.val() << endl;

    return 0;
}


Measured memory_bytes: 18124
L = gets.to_i

list = L.times.collect{gets.to_i}

c0 = 0
c1 = 0
c2 = 0
c3 = 0
c4 = 0

list.each{|a|
#p [c0, c1, c2, c3, c4]
	new_c0 = c0 + a
	new_c1 = [c0, c1].min         + (a == 0 ? 2 : (a == 1 ? 1 : (a % 2 == 0 ? 0 : 1)))
	new_c2 = [c0, c1, c2].min     + (a % 2 == 0 ? 1 : 0)
	new_c3 = [c0, c1, c2, c3].min + (a == 0 ? 2 : (a == 1 ? 1 : (a % 2 == 0 ? 0 : 1)))
	new_c4 = [c1, c2, c3, c4].min + a
	
	c0 = new_c0
	c1 = new_c1
	c2 = new_c2
	c3 = new_c3
	c4 = new_c4
}

#p [c0, c1, c2, c3, c4]
puts [c0, c1, c2, c3, c4].min




Measured memory_bytes: 3892
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define int long long
using namespace std;

typedef pair<int, int> Pii;

void readint(int N, vector<int> &a);
void readdouble(int N, vector<double> &a);
void readindex(int N, vector<int> &a);



signed main(){

    int N;
    cin >> N;
    string S;
    string MARCH = "MARCH";
    vector<int> count(5, 0);

    REP(i, N){
        cin >> S;
        REP(j, 5){
            if(S[0] == MARCH[j]) count[j]++;
        }
    }

    int ans = 0;
    FOR(i1, 0, 5){
        FOR(i2, i1 + 1, 5){
            FOR(i3, i2 + 1, 5){
                ans += count[i1] * count[i2] * count[i3];
            }
        }
    }

    cout << ans;

    return 0;
}








void readint(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readdouble(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}
void readindex(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str()) - 1;
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str()) - 1;
}

Measured memory_bytes: 256
#include<stdio.h>

#define BLACK -1
#define GRAY  -2
#define WHITE -3

void DFSvisit(int);

int G[100][100],d[100],f[100],color[100];
int n,time;

void DFS(int n){
  int i;

  for(i=0;i<n;i++){
    if(color[i]==WHITE){
      DFSvisit(i);
    }
  }
}

void DFSvisit(int u){
  int i;

  color[u]=GRAY;
  time++;
  d[u]=time;

  for(i=0;i<=n;i++){
    if(G[u][i] && color[i]==WHITE){
      DFSvisit(i);
    }
  }
  color[u]=BLACK;
  f[u]=++time;
}

main(){
  int  i,j,k,m;

  scanf("%d",&n);

  for(i=0;i<100;i++){
    for(j=0;j<100;j++){
      G[i][j]=0;
    }
    color[i] = WHITE;
  }

  for(i=0;i<n;i++){ 
    scanf("%d%d",&j,&k);
    for(j=0;j<k;j++){
      scanf("%d",&m);
      G[i][m-1]=1;
    }
  } 
 
  DFS(n);

  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main()
{
    char word;

    while(scanf("%c", &word) != EOF)
    {

        if('a' <= word && word <= 'z')
        {
            word = word - 'a' + 'A';
        }

        else if('A' <= word && word <= 'Z')
        {
            word = word - 'A' + 'a';
        }

        printf("%c", word);
        

    }

    return 0;

}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define f(i,a,b) for(int i=(a); i<=(b);++i)
const unsigned int M = 1000000007;
int main()
{
    int n,a,b,c=1;
    cin>>n>>a>>b;
    f(i,a,b){
        if(i%n==0){
            printf("OK\n");
            c=0;
            break;
        }
        }
       if(c) printf("NG\n");


    return 0;
}




Measured memory_bytes: 3636
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    MOD = 10**9 + 7
    from collections import Counter
    A_c = Counter(A)
    for k,v in A_c.items():
        if k == 0 and v != 1:
            return print(0)
        elif k != 0 and v != 2:
            return print(0)
    else:
        print(2 ** (N//2) % MOD)
if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
ll n;
ll d[MAXN], sum;
vector< ll > adj[MAXN];
map< ll , ll > mp;
int h[MAXN], sz[MAXN];
void dfs(int u){
	sum += h[u];
	for(int i = 0; i < adj[u].size(); i++){
		ll v = adj[u][i];
		h[v] = h[u] + 1;
		dfs(v);
	}
	
	return;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i ++) cin >> d[i], mp[d[i]] = (ll)i;
	for( int i = 0; i < MAXN; i ++) sz[i] = 1LL;
	sort(d, d + n, greater<ll>());
	for(int i = 0; i < n - 1; i ++){
		ll ind = mp[d[i]];
		ll s2 = d[i] + 2LL*sz[ind] - n;
		if( mp.count(s2)){
			if( s2 == d[i]) return cout << -1 << endl, 0;
			ll indpar = mp[s2];
			sz[indpar] += sz[ind], adj[indpar].push_back(ind);
		}
		else return cout << -1 << endl, 0;
	}
	h[mp[d[n - 1]]] = 0;
	dfs(mp[d[n - 1]]);
	if( sum != d[n - 1]) return cout << -1 << endl, 0;
	for(int i = 0; i < n; i ++){
		for( int j = 0; j < adj[i].size(); j ++){
			cout << i + 1LL << " " << adj[i][j] + 1LL << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 19260
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x,m;
    cin >> n >> m >> x;
    int ans = 0;
    bool ok = false;
    vector<int> price(n);
    vector<vector<int>> a(n, vector<int>(m));
    for(int i=0; i<n; i++){
        cin >> price.at(i);
        ans += price.at(i);
        for(int j=0; j<m; j++){
            cin >> a.at(i).at(j);
        }
    }
    for(int i= 0; i<(1<<n); i++){
        bool possible = true;
        vector<int> buy(n,0);
        for(int j=0; j<n; j++){
            if(i & (1<<j)){
                buy.at(j) = 1;
            }
        }
        int money = 0;
        for(int j=0; j<n; j++){
            money += buy.at(j) * price.at(j);
        }
        for(int j=0; j<m; j++){
            int know_j=0;
            for(int k=0; k<n; k++){
                know_j += buy.at(k) * a.at(k).at(j);
            }
            if(know_j < x){
                possible = false;
            }
        }
        if(possible){
            ok = true;
            ans = min(ans, money);
        }
    }
    if(ok){
        cout << ans << endl;
    }
    else{
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 3648
// Problem : B - Trick or Treat
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n,k;
		cin>>n>>k;
		set<int> st;
		while(k--)
		{
			int d;
			cin>>d;
			while(d--)
			{
				int x;
				cin>>x;
				st.insert(x);
			}
		}
		cout<<n-st.size();    	
    }
    return 0;
}



Measured memory_bytes: 3672
#include <stdio.h>
#include <algorithm>
#include <tuple>
#include <queue>
using namespace std;
using ll = long long;

using pii = pair<ll, ll>;
ll n, d, a, x[200010], h[200010];
pii s[200010];

queue<pii> q;
int main() {
	scanf("%lld %lld %lld", &n, &d, &a);
	for (int i = 0; i < n; i++)
		scanf("%lld %lld", x + i, h + i);

	for (int i = 0; i < n; i++)
		s[i] = pii(x[i], h[i]);
	sort(s, s + n);
	for (int i = 0; i < n; i++)
		tie(x[i], h[i]) = s[i];

	ll sum = 0, c = 0;
	for (int i = 0; i < n; i++) {
		while (!q.empty() && q.front().first < x[i])
			sum -= a * q.front().second, q.pop();
		ll u = max(0ll, (h[i] - sum + a - 1) / a);
		sum += a * u;
		c += u;
		q.emplace(x[i] + 2 * d, u);
	}
	printf("%lld\n", c);
}

Measured memory_bytes: 9728
import sys
from collections import deque


class MaxFlow:
    class Edge:
        def __init__(self, to, cap, rev):
            self.to, self.cap, self.rev = to, cap, rev

    def __init__(self, node_size, inf):
        self._node = node_size
        self._inf = inf
        self._level = [-1]*self._node
        self._iter = [0]*self._node
        self._graph = [[] for _ in range(self._node)]

    def add_edge(self, from_, to, cap):
        self._graph[from_].append(self.Edge(to, cap, len(self._graph[to])))
        self._graph[to].append(self.Edge(from_, 0, len(self._graph[from_])-1))

    def bfs(self, start):
        self._level = [-1]*self._node
        que = deque()
        self._level[start] = 0
        que.append(start)
        while que:
            cur_vertex = que.popleft()
            for e in self._graph[cur_vertex]:
                if e.cap > 0 > self._level[e.to]:
                    self._level[e.to] = self._level[cur_vertex] + 1
                    que.append(e.to)

    def dfs(self, cur_vertex, end_vertex, flow):
        if cur_vertex == end_vertex:
            return flow
        for e in self._graph[cur_vertex][self._iter[cur_vertex]:len(self._graph[cur_vertex])]:
            if e.cap > 0 and self._level[cur_vertex] < self._level[e.to]:
                flowed = self.dfs(e.to, end_vertex, min(flow, e.cap))
                if flowed > 0:
                    e.cap -= flowed
                    self._graph[e.to][e.rev].cap += flowed
                    return flowed
        return 0

    def solve(self, source, sink):
        flow = 0
        while True:
            self.bfs(source)
            if self._level[sink] < 0:
                return flow
            self._iter = [0]*self._node
            while True:
                f = self.dfs(source, sink, self._inf)
                if f == 0:
                    break
                flow += f

if __name__ == '__main__':
    n, m = map(int, sys.stdin.readline().split())
    mf = MaxFlow(n, 10**10)
    for _ in range(m):
        u, v, c = map(int, sys.stdin.readline().split())
        mf.add_edge(u, v, c)
    print(mf.solve(0, n-1))



Measured memory_bytes: 6336
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int imos[2010];
int main() {
    int a, b; cin >> a >> b;
    int N; cin >> N;
    for(int i=0; i<N; i++) {
        int s, t; cin >> s >> t;
        imos[s]++;
        imos[t]--;
    }

    for(int i=1; i<=2000; i++) imos[i] += imos[i-1];
    bool ok = true;
    for(int i=a; i<b; i++) ok &= (imos[i] == 0);

    cout << (ok ? 0 : 1) << endl;
    return 0;
}



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

int main() {
    int N; cin >> N;
    long long sum = 0, tmp;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        if (i == 0) {
            tmp = A.at(i);
        } else {
            long long k = tmp * A.at(i) % 1000000007;
            sum += k;
            tmp += A.at(i);
            sum %= 1000000007;
            tmp %= 1000000007;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 4052
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String s = sc.next();
		
		sc.close();

		if(!s.startsWith("A")) {
			out.println("WA");
			return;
		}
		
		int n=0;
		for(int i=2;i<=s.length()-2;i++) {
			if(s.charAt(i) == 'C') {
				n++;
			}
		}
		if(n!=1) {
			out.println("WA");
			return;
		}
		
		String s2 = s.substring(1,s.length()-1).replace('C', 'c') + s.substring(s.length()-1);
		if(!s2.equals(s2.toLowerCase())){
			out.println("WA");
			return;
		}
		
		out.println("AC");
		
	}

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

}


Measured memory_bytes: 23124
#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() {
  string o, e;
  cin >> o >> e;
  string p = "";
  rep(i, e.size()) {
    p += o[i];
    p += e[i];
  }
  if (o.size() - e.size() == 1) p += o[o.size()-1];
  cout << p << endl;
  return 0;
}

Measured memory_bytes: 3644