akhauriyash/Code-Regression huggingface dataset:
/*
???????????????? ??
??????????| ??_?? _|
?? ????????`?? _x ??
???? ?? /?????? ?? |
?????? /??  ?c???? ?
??????|???? |??|??|
??| (???c??_?c_)_)
???ܶ???
 */

#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
	static short st[30];short tp=0;
	if(x<0) putchar('-'),x=-x;
	do st[++tp]=x%10,x/=10; while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int N = 2500;
ll n;
int q[N], l, r;
int cnt;

void solve(ll n) {
	if (!n) return; 
	if (n & 1) solve(n >> 1), cnt++, q[++r] = cnt;
	else solve(n - 1), cnt++, q[--l] = cnt;
}

int main() {
	l = 500, r = l - 1, read(n), solve(n);
	write(cnt + 100);
	for (int i = l;i <= r; i++) write(q[i], ' ');
	for (int i = 1;i <= 100; i++) write(i, ' ');
	return 0;
}

Measured memory_bytes: 3048
#include <stdio.h>
int main(){
  int x,y;
 while(1){
  scanf("%d %d",&x,&y);
  if(x == 0 && y == 0)break;
  if (x > y)
  printf("%d %d\n",y,x);
  else printf("%d %d\n",x,y);
 }
  return 0;
  }

Measured memory_bytes: 596
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <typeinfo>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>

const int INF = 100000001;

int x, t;

int main(){
    cin >> x >> t;
    if(x <= t) cout << 0 << endl;
    else cout << x - t << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
	int n,k;
	while(1){
		scanf("%d %d",&n,&k);
		if(n==0)	return 0;
		int a[n];
		for(int i=0;i<n;i++)	scanf("%d",&a[i]);
		ll bgs=0,temp=0;
		for(int i=0;i<k;i++)	temp+=a[i];
		bgs=temp;
		for(int i=1;i<=n-k;i++){
			temp=temp-a[i-1]+a[i+k-1];
			bgs=max(bgs,temp);
		}
		printf("%lld\n",bgs);
	}
}

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

int main() {
	int N;
	cin >> N;
	vector<int> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H.at(i);
	}
	vector<int> H_min(N);
	for (int i = N - 1; i >= 0; i--) {
		if (i == N - 1) {
			H_min.at(i) = H.at(i);
		} else {
			H_min.at(i) = min(H_min.at(i + 1), H.at(i));
		}
	}
	int flag = 0;
	for (int i = 0; i < N; i++) {
		if (H.at(i) - H_min.at(i) > 1) {
			flag = 1;
		}
	}
	if (flag == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int m;
  cin >> m;
  map<string, vector<bool>> mp;
  for (int i = 0; i < m; i++){
    string name;
    int lb, ub;
    cin >> name >> lb >> ub;
    mp[name] = vector<bool>(256, false);
    for (int j = lb; j <= ub; j++){
      mp[name][j] = true;
    }
  }
  int n;
  cin >> n;
  bool ok = true;
  stack<vector<bool>> st;
  for (int i = 0; i < n; i++){
    string S;
    cin >> S;
    if (mp.count(S)){
      st.push(mp[S]);
    } else if ('0' <= S[0] && S[0] <= '9'){
      vector<bool> tmp(256, false);
      tmp[stoi(S)] = true;
      st.push(tmp);
    } else {
      vector<bool> b = st.top();
      st.pop();
      vector<bool> a = st.top();
      st.pop();
      if (S == "/" && b[0]){
        ok = false;
        break;
      }
      vector<bool> r(256, false);
      for (int i = 0; i < 256; i++){
        for (int j = 0; j < 256; j++){
          if (a[i] && b[j]){
            if (S == "+"){
              r[(i + j) % 256] = true;
            }
            if (S == "-"){
              r[(i - j + 256) % 256] = true;
            }
            if (S == "*"){
              r[i * j % 256] = true;
            }
            if (S == "/"){
              r[i / j] = true;
            }
          }
        }
      }
      st.push(r);
    }
  }
  if (ok){
    cout << "correct" << endl;
  } else {
    cout << "error" << endl;
  }
}


Measured memory_bytes: 3244
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>


#define fs first
#define sc second

using namespace std;

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

int N, M;
bool x[750][750];
vector<int> edge[750];
int check[750];


P dfs(int s, int c){
    if(check[s] != 0){
        if(check[s] != c){
            return P(-1, -1);
        }
        else{
            return P(0, 0);
        }
    }
    check[s] = c;
    P ret = P(0, 0);
    for(auto v: edge[s]){
        P p = dfs(v, -c);
        if(p.fs == -1 && p.sc == -1){
            return P(-1, -1);
        }
        ret.fs += p.fs;
        ret.sc += p.sc;
    }
    if(c == 1){
        ret.fs += 1;
    }
    else{
        ret.sc += 1;
    }

    return ret;
}


int main(){
    cin >> N >> M;
    for(int i = 0; i < 750; i++){
        fill(x[i], x[i]+750, false);
    }
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        x[a][b] = true;
        x[b][a] = true;
    }

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(i == j){
                continue;
            }
            if(!x[i][j]){
                edge[i].push_back(j);
            }
        }
    }

    fill(check, check+750, 0);
    vector<P> p_list;
    for(int i = 0; i < N; i++){
        if(check[i] != 0){
            continue;
        }
        P p = dfs(i, 1);
        if(p.fs == -1 && p.sc == -1){
            cout << -1 << endl;
            return 0;
        }
        p_list.emplace_back(P(min(p.fs, p.sc), max(p.fs, p.sc)));
    }

    bool can_make[2][450];
    fill(can_make[0], can_make[0]+450, false);
    fill(can_make[1], can_make[1]+450, false);

    can_make[0][0] = true;
    can_make[1][0] = true;
    int mi = 0;
    for(auto p: p_list){
        mi += p.fs;
        for(int i = 0; i <= N/2; i++){
            int dif = p.sc - p.fs;
            if(i >= dif && can_make[0][i-dif]){
                can_make[1][i] = true;
            }
        }
        for(int i = 0; i <= N/2; i++){
            can_make[0][i] = can_make[1][i];
        }
    }

    for(int i = N/2 - mi; i >= 0; i--){
        if(can_make[0][i]){
            mi += i;
            break;
        }
    }

    cout << (mi * (mi-1) + (N-mi)*(N-mi-1)) / 2 << endl;



    return 0;

}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define int long long
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define mod 1e9
int32_t main() {
	int n,a,b;
	cin>>n>>a>>b;
	cout<<a*(n/(a+b))+min(n%(a+b),a)<<"\n";
}

Measured memory_bytes: 256
def check(as, m)
  if as.inject(&:+) >= m
    (1..as.size).any?{|comb_num|
      # All combination of `as` in `com_num`
      as.combination(comb_num).any?{|nums|
        # Summation of nums equals to m
        nums.inject(&:+) == m
      }
    }
  else
    false
  end
end

_ = gets
as = gets.split(' ').map(&:to_i)
_ = gets
ms = gets.split(' ').map(&:to_i)

ms.each{|m|
  if check(as, m)
    puts("yes")
  else
    puts("no")
  end
}



Measured memory_bytes: 7440
#include <iostream>
#define ABS(X) (((X)>0)?(X):-(X))

using namespace std;

int x[90001],y[90001];
int costs[90001][20] = {0};

int dist(int n, int m){
	return ABS(x[n] - x[m]) + ABS(y[n] - y[m]);
}

int main(){
	int h, w, d;
	cin >> h >> w >> d;

	int max = h*w;


	for(int i=0; i<h; i++)
		for(int j=0; j<w; j++){
			int a;
			cin >> a;
			y[a] = i;
			x[a] = j;
		}
		
	for(int n=1; n<=max; n++){
		if(n+d <= max)
			costs[n][0] = dist(n, n+d);
	}
	
	int doubling = 2;
	for(int t=1; t<20; t++){
		for(int n=1; n<=max; n++){
			int next = n + d*doubling;
			if(next <= max)
				costs[n][t] = costs[n][t-1] + costs[(n+next)/2][t-1];
		}
		doubling *= 2;
		if(d * doubling > max)
			break;
	}


	int q;
	cin >> q;

	for(int i=0; i<q; i++){
		int l, r;
		cin >> l >> r;

		int gap = (r - l)/d;
		int ans = 0;

		int doubling = 1;
		for(int t=0; t<20; doubling*=2,t++){
			if(doubling * d > max)
				break;

			if(gap & doubling){
				ans += costs[l][t];
				l += d * doubling;
			}
		}
		
		cout << ans << endl;

	}


	return 0;
}



Measured memory_bytes: 8832
fun main(args: Array<String>) {
    val S = readLine()!!
    val list = listOf("A", "C", "G", "T")
    var max = 0
    var sum = 0
    for (i in 0 until S.length) {

        if (list.contains(S[i].toString())) {
            sum++
            max = Math.max(max, sum)
        } else {
            max = Math.max(max, sum)
            sum = 0
        }
    }
    println(max)
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

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

int main() {
    int Q;
    cin >> Q;
    ll b_sum = 0;
    priority_queue<ll> left;
    priority_queue<ll, vector<ll>, greater<ll>> right;
    ll left_sum = 0;
    ll right_sum = 0;
    REP(_, Q) {
        int t;
        cin >> t;
        if (t == 1) {
            ll a, b;
            cin >> a >> b;
            b_sum += b;
            left.push(a);
            left_sum += a;
            while (left.size() > right.size() + 1) {
                ll c = left.top();
                right.push(c);
                right_sum += c;
                left.pop();
                left_sum -= c;
            }
            while (left.size() != 0 && right.size() != 0 && left.top() > right.top()) {
                ll c = left.top();
                ll d = right.top();
                left.pop();
                right.pop();
                left.push(d);
                right.push(c);
                left_sum += d - c;
                right_sum += c - d;
            }
            PRINT(left_sum);
            PRINT(right_sum);
        } else if (t == 2) {
            ll x = left.top();
            ll L = left.size();
            ll R = right.size();
            ll g = b_sum + L * x - left_sum - R * x + right_sum;
            cout << x << " " << g << "\n";
        }
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3828
X, Y = map(int, input().split())

def cos(c):
  if c==1:
    return 300000
  elif c==2:
    return 200000
  elif c==3:
    return 100000
  else:
    return 0
  
print(cos(X)+cos(Y)+ ( 400000 if X==1 and Y==1 else 0))

Measured memory_bytes: 38384
def p_b():
    s = int(input())
    u = {s}
    for i in range(1, 1000001):
        if s & 1 == 0:
            s //= 2
        else:
            s = 3 * s + 1
        if s in u:
            print(i + 1)
            exit()
        else:
            u.add(s)

            
p_b()

Measured memory_bytes: 38256
#include<stdio.h>
int main()
{
    int n,i,j;
    scanf("%d",&n);
    char s[n],t[n];
    scanf("%s%s",&s,&t);
    for(i=0,j=0;i<n,j<n;i++,j++)
    {
        printf("%c%c",s[i],t[i]);
    }
    return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var s int
	fmt.Scan(&s)

	numExistMap := map[int]bool{s: true}
	i := 2
	for {
		var n int
		if s%2 == 0 {
			n = s / 2
		} else {
			n = 3*s + 1
		}
		if numExistMap[n] {
			fmt.Println(i)
			return
		}
		numExistMap[n] = true
		s = n
		i++
	}
}


Measured memory_bytes: 1848
#include<iostream>
#include<string>
int main() {
	double w = 0, h = 0;
	int x = 0, y = 0;
	std::cin >> w >> h >> x >> y;
	if (w / 2 == x && h / 2 == y) {
		std::cout << w * h / 2 << " " << "1"<<std::endl;
	}
	else {
		std::cout << w * h / 2 << " " << "0" << std::endl;
	}

}

Measured memory_bytes: 256
import heapq
import sys
input = sys.stdin.readline

W, H = map(int, input().split())

inf = 10**10
yoko = [inf]
tate = [inf]

for _ in range(W):
    p = int(input())
    heapq.heappush(yoko, p)
for _ in range(H):
    p = int(input())
    heapq.heappush(tate, p)

#どこに引くかはあんまり関係ない
#短いやつを使えるだけ使うと良いぞ
ans = 0
while H > 0 or W > 0:
    if yoko[0] < tate[0]:
        ans += (H+1) * heapq.heappop(yoko)
        W -= 1
    else:
        ans += (W+1) * heapq.heappop(tate)
        H -= 1

print(ans)


Measured memory_bytes: 11092
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
using namespace std;
string s, t;
set<string> S;

void Work()
{
int lens = s.size();
int lent = t.size();
for(int i = 0; i < lens; i++)
{
if(s[i] == '?' || s[i] == t[0])//如果字符相等
{
string tmp = s;              //构造判断子串之前的字符
for(int j = 0; j < i; j++)
if(tmp[j] == '?')
tmp[j] ='a';
bool can = false;
for(int j = 0; j < lent; j++)    //判断是否为子串
{

if(tmp[i+j]!= '?' && tmp[i+j] != t[j])  //字符匹配
break;
tmp[i+j] = t[j];
if(j == lent - 1) can = true;
}
if(can)
{
for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';//处理匹配字符
S.insert(tmp);  //压
}
}
}
if(S.size() == 0) cout << "UNRESTORABLE" << endl;
else cout << *S.begin() << endl;
}
int main()
{
cin >> s >> t;
Work();
}

Measured memory_bytes: 256
import math
A, B, C, D = map(int, input().split())

def LCM(S, T):
    return (S*T)//math.gcd(S, T)

def f(N, S, T):#Nを含む
    return N- N//S - N//T + N//LCM(S, T)
    
    
print(f(B, C, D)-f(A-1, C, D))

Measured memory_bytes: 62200
n,a,b = map(int,input().split())
if n==1:
  if a==b:
    print(1)
  else:
    print(0)
else:
  k = b-a
  if k < 0:
    print(0)
  elif k==0:
    print(1)
  else:
    print((b-a)*(n-2)+1)

Measured memory_bytes: 3060
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        print('F')
    elif m + f >= 80:
        print('A')
    elif m + f >= 65:
        print('B')
    elif m + f >= 50:
        print('C')
    elif m + f >= 30:
        if r >= 50:
            print('C')
        else:
            print('D')
    else:
        print('F')


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=200000;
int n;
int a[N+1];
int buc[N+1];
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i],buc[a[i]]++;
	int ans=0;
	for(int i=1;i<=n;i++)ans+=buc[i]*(buc[i]-1)/2;
	for(int i=1;i<=n;i++)cout<<ans-(buc[a[i]]-1)<<"\n";
	return 0;
}

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

using namespace std;

int main() {
  int N;
  vector<long long> a_list;
  long long cusum = 0;
  
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    long long a;
    
    cin >> a;
    
    a_list.push_back(a);
    cusum ^= a;
  }
  
  for (int i = 0; i < N; i++) {
    cout << (cusum ^ a_list[i]);
    
    if (i < N - 1) {
      cout << " ";
    }
  }
  
  return 0;
}

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

struct UnionFind {
  vector<int> parent;
  vector<int> height;

  // n要素で初期化
  UnionFind(int n) {
    for (int i = 0; i < n; i++) {
      parent.push_back(i);
      height.push_back(0);
    }
  }

  // 木の根を求める
  int find(int x) {
    if (parent.at(x) == x) {
      return x;
    } else {
      parent.at(x) = find(parent.at(x));
      return parent.at(x);
    }
  }

  // xとyの属する集合を併合
  void unite (int x, int y) {
    int p = find(x);
    int q = find(y);
    if (p == q) return;

    if (height.at(p) < height.at(q)) {
      parent.at(p) = q;
    } else {
      parent.at(q) = p;
      if (height.at(p) == height.at(q)) height.at(p)++;
    }
  }

  // xとyが同じ集合に属するか否か
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

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

  UnionFind u(N);

  rep(i, M) {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    X--; Y--;
    u.unite(X, Y);
  }

  set<int> parents;
  rep(i, N) {
    int p = u.find(i);
    parents.insert(p);
  }
  cout << parents.size() << endl;
  return 0;
}

Measured memory_bytes: 5748
N, M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]
ans = "X"*N

okflg = 1
for i in range(M):
    if N > 1 and sc[i][0] == 1 and sc[i][1] == 0:
        okflg = 0
    if ans[sc[i][0]-1] == "X":
        ans = list(ans)
        ans[sc[i][0]-1] = str(sc[i][1])
        ans = "".join(ans)
    else:
        if ans[sc[i][0]-1] != str(sc[i][1]):
            okflg = 0
for i in range(N):
    if ans[i] == "X":
        ans = list(ans)
        ans[i] = "0"
        ans = "".join(ans) 
        
if okflg == 0:
    print(-1)
elif len(str(int(ans))) == N:
    print(int(ans))
else:
    print(int("1"+str(ans[1:])))

Measured memory_bytes: 3064
while gets
  n, s = $_.split.map(&:to_i)
  break if n == 0 
  table = Hash.new(0)
  n.times do
    table[gets.to_i] += 1    
  end
  ret = 0
  table.each_key do |i|
    if i * 2 > s
      ret += table[i]*(table[i]-1) / 2
    end
    for j in (i+1)..100
      if table.key?(j) && i + j > s
        ret += table[i] * table[j]
      end
    end
  end
  p ret
end

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

#define NMAX 200100
#define INF 2000000000

#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)

typedef unsigned long long ull;
typedef long long int lli;

using namespace std;

// std::ifstream cin("f.in");
// std::ofstream cout("f.out");

int n, m, h, w;

int main()
{
    cin >> n >> m >> h >> w;
    cout << n * m - h * m - w * n + w * h << '\n';
    return 0;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();

int main() {

    int n;
    cin>>n;
    int a[n];
    int c=0;
    f1(i,n) {
        cin>>a[i];
        if(i%2==0 && a[i]%2!=0)++c;
    }
    cout<<c<<endl;
    
    return 0;
}

Measured memory_bytes: 3580
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	while(true){
		int n = sc.nextInt();
		if(n == 0) break;
		int no = 0;
		int dst = 0;
		for(int i = 0 ; i < n ; i++){
			int p = sc.nextInt();
			int d1 = sc.nextInt();
			int d2 = sc.nextInt();
				if(dst < d2 + d1){
					no = p;
					dst = d2 + d1;
				}
		}
		System.out.println(no + " " + dst);
	}
		sc.close();
	}

}

Measured memory_bytes: 157576
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
    }
    let ans = (n + 2 - 1) / 2;
    println!("{}", ans);
}


Measured memory_bytes: 4352
n, m, x = map(int, input().split())
info= [list(map(int, input().split())) for i in range(n)]

ans = 10 ** 18
for bit_state in range(1 << n):
    tmp = [0] * m
    cost = 0
    for i in range(n):
        if bit_state & (1 << i):
            for j in range(m):
                tmp[j] += info[i][j + 1]
            cost += info[i][0]
    flag = True
    for j in range(m):
        if tmp[j] < x:
            flag = False
    if flag:
        ans = min(cost, ans)
        
        
if ans == 10 ** 18:
    print(-1)
else:
    print(ans)



Measured memory_bytes: 68224
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>

using namespace std;

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

typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int n;
	scanf("%d", &n);
	rep(i, n){
		char field[16][16];
		rep(j, 8) scanf(" %s", field[j]);
		pii fst;
		scanf("%d%d", &fst.second, &fst.first);
		fst.second--;
		fst.first--;

		queue<pii> Q;
		Q.push(fst);
		do{
			pii p = Q.front();
			Q.pop();
			if(field[p.first][p.second] == '0')
				continue;
			field[p.first][p.second] = '0';
			reep(j, -3, 4){
				int py = p.first + j, px = p.second + j;

				if(0<=px && px<8 && field[p.first][px] == '1')
					Q.push(pii(p.first, px));
				if(0<=py && py<8 && field[py][p.second] == '1')
					Q.push(pii(py, p.second));
			};

		}while(!Q.empty());

		printf("Data %d:\n", i+1);
		rep(j, 8)
			puts(field[j]);
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

bool IsPrime[100100];
bool nearPrime[100010];

void Sieve_Eratosthenes(int max){
    /*if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    }*/
    for(int i=0;i<max;i++){
      IsPrime[i]=true;
    }
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int Q;
  int l,r;
  cin >> Q;
  Sieve_Eratosthenes(100010);
  for(int i=3;i<100010;i+=2){
    if(IsPrime[i]==true && IsPrime[(i+1)/2]){
      nearPrime[i]=true;
      //cout << i << endl;
    }
  }
  int a[100010]={0};
  for(int i=1;i<100010;i++){
    if(nearPrime[i]){
      a[i]=a[i-1]+1;
    }else{
      a[i]=a[i-1];
    }
  }
  for(int i=0;i<Q;i++){
    int ans=0;
    cin >> l >> r;
    ans=a[r]-a[l-1];
    cout << ans << endl;
  }
  return 0;
}

// ABC084_素数_エラストテネスの篩

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
int main()
{
    ios::sync_with_stdio(false);
    int t; t = 1;
    while (t --){
        int a , b , c , cnt = 0 , k; cin >> a >> b >> c >> k;
        while (b <= a) cnt++ , b <<=1;
        while (c <= b) cnt++ , c <<=1;
      //  cout << cnt << endl;
        cout << (cnt <= k ? "Yes" : "No") << endl;
    }
    return 0;
}


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

  while(1){
       int n, x;
       cin >> n >> x;

       if(n==0 && x==0)break;

       int cnt = 0;

       for(int i=1; i<=n; i++){
           for(int j=i+1; j<=n; j++){
               for(int k=j+1; k<=n; k++){
                   if(i+j+k==x){
                       cnt++;
                   }
               }
           }
       }

       cout << cnt << endl;
   }

   return 0;
}


Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int[] a = new int[1000001];
        a[1] = 7 % k;
        for (int i = 2; i <= k; i++) {
            a[i] = (a[i - 1] * 10 + 7) % k;
        }
        for (int i = 1; i <= k; i++) {
            if (a[i] == 0) {
                System.out.println(i);
                return;
            }
        }
        System.out.println("-1");
    }

}


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

int main(){
  string s;
  while (cin >> s) {
    if (s == "-") break;

    int c; cin >> c;
    for (int i = 0; i < c; i ++) {
      int t; cin >> t;
      string a = s.substr(0, t);
      string b = s.substr(t, s.size() - t);
      s = b + a;
    }

    cout << s << endl;
  }
}


Measured memory_bytes: 3200
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author rahdirigs
 */

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

template <typename T> void add(T& a, T b, int mod) {
	a += b;
	if (a >= mod)
		a -= mod;
}

template <typename T> void sub(T& a, T b, int mod) {
	a -= b;
	if (a < 0)
		a += mod;
}

const int mxN = 10005, mxD = 110, mod = 1e9 + 7;
ll dp[mxN][mxD][2];

class TaskS {
public:
	string K;
	int D, n;
	vector<int> digits;

	void solve(std::istream& in, std::ostream& out) {
		in >> K >> D;
		for (char it : K) digits.push_back(it - '0');
		n = (int) digits.size();
		memset(dp, -1, sizeof(dp));
		ll ans = rec(0, 0, 1);
		sub(ans, 1ll, mod);
		out << ans;
	}

	ll rec(int pos, int sum, int flag) {
		if (pos == n) {
			if (sum % D == 0) return 1;
			return 0;
		}
		if (dp[pos][sum][flag] != -1) return dp[pos][sum][flag];
		int limit = 9;
		ll tot = 0;
		if (flag == 1) limit = digits[pos];
		for (int i = 0; i <= limit; i++) {
			if (i == digits[pos]) {
				add(tot, rec(pos + 1, (sum + i) % D, flag), mod);
			} else {
				add(tot, rec(pos + 1, (sum + i) % D, 0), mod);
			}
		}
		return dp[pos][sum][flag] = tot;
	}
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	TaskS solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 22028
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int help[10]={inf,2,5,5,4,5,6,3,7,6};
string dp[100010];

int main(){
  int n,m;
  cin >> n >> m;
  int a[m];
  rep(i,m){
    cin >> a[i];
  }
  sort(a,a+m,greater<int>());
  for(int i=0;i<m;i++){
    if(dp[help[a[i]]].size()==0){
      dp[help[a[i]]]+=a[i]+'0';
    }
  }
//    rep(i,n+1)cout << i << ' ' << dp[i] << endl;
  for(int i=0;i<=n;i++){
    int cnt=0;
    for(int j=0;j<m;j++){
      string temp="";
      if(i-help[a[j]]>=0 && dp[i-help[a[j]]].size()!=0){
        cnt++;
        temp=dp[i-help[a[j]]];
        temp+=a[j]+'0';
        if(cnt==1){
          dp[i]=temp;
        }
        if(temp.size()>dp[i].size()){
          dp[i]=temp;
        }
      }
      
    }
  }
  sort(dp[n].begin(),dp[n].end());
  reverse(dp[n].begin(),dp[n].end());
  cout << dp[n] << endl;
//  rep(i,n+1)cout << i << ' ' << dp[i] << endl;
return 0;}

Measured memory_bytes: 44160
void main() {
	auto ip = readAs!(int[]), A = ip[0], B = ip[1];
	ulong res;
	if(A > B) {
		res += A;
		A--;
	} else {
		res += B;
		B--;
	}
	res += max(A, B);
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int solve(int, int);
int A[2000], n, h = 0;
 
int main(){
  int i, q, M[2000];
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &A[i]);
  } 
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &M[i]);
  } 
  for(i = 0; i < q; i++){
    h = solve(0, M[i]);
    if(h == 1)
      printf("yes\n");
    else 
      printf("no\n");
  }
 
  return 0;
}
 
int solve(int p, int t){
  if(t == 0){ 
    return 1;
  }
  else if(p == n){
    return 0;
  }
  else if(solve(p+1, t-A[p]) || solve(p+1, t)){
    return 1;
}
  else return 0;
  }

Measured memory_bytes: 588
# -*- coding: utf-8 -*-
"""
C - Inserting 'x'
https://atcoder.jp/contests/code-festival-2017-qualc/tasks/code_festival_2017_qualc_c

"""
import sys


from collections import deque

def solve(s):
    d = deque(s)
    ans = 0
    while len(d) > 1:
        if d[0] == 'x' or d[-1] == 'x':
            if d[0] == 'x' and d[-1] == 'x':
                d.popleft()
                d.pop()
            elif d[0] == 'x':
                d.popleft()
                ans += 1
            else:
                d.pop()
                ans += 1
        else:
            if d[0] == d[-1]:
                d.popleft()
                d.pop()
            else:
                return -1
    return ans


def main(args):
    s = input()
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

namespace Areas_on_the_Cross
{
    class Program
    {
        static void Main()
        {
            var s = new Stack<int>();
            var a = new Stack<int[]>();

            var data = Console.ReadLine();

            for (var i = 0; i < data.Length; i++)
            {
                var c = data[i];

                if (s.Any() && c == '/')
                {
                    var x = s.Pop();
                    var y = i - x;

                    while (a.Any() && x < a.Peek()[0])
                        y += a.Pop()[1];
                    a.Push(new int[] { x, y });
                }

                if (c == '\\') s.Push(i);
            }

            var A = a.Select(e => e[1]).Reverse().ToArray();

            if (!A.Any())
            {
              Console.Write("0\n0\n");
              return;
            }

            Console.Write("{0}\n{1} {2}\n", A.Sum(), A.Length,
                string.Join(" ", Array.ConvertAll(A, e => e.ToString())));
        }
    }
}

Measured memory_bytes: 10948
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

typedef string::const_iterator ParseState;

class ParseError {

};


int expression(ParseState &begin);

int num(ParseState &begin);

int expression(ParseState &begin) {
    int ret = 0;
    if (isdigit(*begin)) {
        ret = num(begin) / 2 + 1;
        return ret;
    } else {
        vector<int> array;
        while (true) {
            if (*begin != '[') break;
            begin++;
            int d = expression(begin);
            begin++;
            array.push_back(d);
        }
        sort(array.begin(), array.end());
        for (int i = 0; i < (array.size() + 1) / 2; i++) ret += array[i];
    }
    return ret;
}

int num(ParseState &begin) {
    int ret = 0;
    while (isdigit(*begin)) {
        ret *= 10;
        ret += (*begin - '0');
        begin++;
    }
    return ret;
}

int main() {

    int N;
    cin >> N;

    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;

        auto iter = s.cbegin();
        cout << expression(iter) << endl;

    }

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  int N2=0, N4=0;
  for(int i=0; i<N; i++){
    cin >> A.at(i);
    if(A.at(i)%2==0 && A.at(i)%4!=0){
      N2++;
    }
    if(A.at(i)%4==0){
      N4++;
    }
  }
  if(N4*2+N2>=N || (N2==0 && N4*2==N-1)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define LL long long
#define LD long double
#define VI vector<int>
#define VPII vector<PII>
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define FOR(a,s,d) for (int a = (s); a <= (int)(d); ++a)
#define FORD(a,s,d) for (int a = (s); a >= (int)(d); --a)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(x) x.begin(), x.end()
#define siz(x) ((int)x.size())
#define Sim template <class s
Sim, class d> ostream & operator<<(ostream &os, pair<s,d> x){return os << "<" << x.f << ", " <<
  x.s << "> ";}
Sim> auto operator<<(ostream &os, s x) -> typename enable_if<!is_same<s,string>::value,
  decltype(x.begin(), os)>::type
{ int o = 0; os << "{"; for (auto c : x) {if(o++) os << ", "; os << c;}return os << "} ";}
void dor() {cerr << endl;}
Sim, class ...t> void dor(s x, t...y) {cerr << x << " "; dor(y...);}
#ifdef DEB
#define debug(c...) dor(__FUNCTION__, ":", __LINE__, ": ", c)
#else
#define debug(...)
#endif

bool notin(char c, string s)
{
  for (auto x : s)
  {
    if (x == c)
    {
      return false;
    }
  }
  return true;
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin>> s;
  if (s == "zyxwvutsrqponmlkjihgfedcba")
  {
    cout<< "-1\n";
    return 0;
  }
  if (s.size() < 26)
  {
    for (int i = 0; i < 26; i++)
    {
      char x = (char)('a' + i);
      if (notin(x, s))
      {
        debug(x);
        s += x;
        break;
      }
    }
    cout<< s << "\n";
    return 0;
  }
  string ss = s;
  next_permutation(s.begin(), s.end());
  int ind = 0;
  while (ind < 26 && ss[ind] == s[ind])
  {
    ind++;
  }
  for (int i = 0; i <= ind; i++)
  {
    cout<< s[i];
  }
  cout<< "\n";
  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc162/tasks/abc162_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    bool flag = false;
    for (auto &x : s) {
        if (x == '7') {
            flag = true;
            break;
        }
    }
    if (flag) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 3648
type Plan=[(Int,Int,Int)]

eater::(Int,Int,Int)->Plan->Bool
eater now [] = True
eater now ((t',x',y'):rest) = let (t,x,y) = now in
                       let dist = (abs (x'-x))+(abs (y'-y)) in
                       if (dist <= t'- t)&&(mod (dist - (t'-t)) 2 == 0) then eater (t',x',y') rest else False

n_get::Int -> IO [(Int,Int,Int)]
n_get 0 = return []
n_get n = do
  c<-getLine
  let t:x:y:[]=map read (words c)
  rest<-n_get (n-1)
  return ((t,x,y):rest)

main::IO()
main=do
 nc<-getLine
 let n = read nc
 plan<-n_get n
 putStr (if (eater (0,0,0) plan) then "Yes\n" else "No\n")

Measured memory_bytes: 99708
import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))
d = np.diff(H)

ra = []
m = []
for i in range(len(d) - 1):
    if d[i] <= 0 and d[i + 1] > 0:
        ra.append(i + 1)
        m.append(H[i + 1])

ra = [0] + ra + [N]
M = []
for i in range(len(ra) - 1):
    M.append(np.max(H[ra[i]:ra[i + 1]]))

print(sum(M) - sum(m))


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

bool cmp(int a, int b) {
    return a > b;
}

int main() {
    int N, i;
    double tmp;
    double x, y;
    
    while (cin >> N) {
        vector<double> v;
        for (i=0; i<N; i++) {
            cin >> tmp;
            v.push_back(tmp);
        }
        
        while (v.size() > 1) {
            sort(v.begin(), v.end(), cmp);
            x = v[N-1];
            y = v[N-2];
            v.pop_back();
            v.pop_back();
            v.push_back((x+y)/2.0);
            N--;
        }
        cout << v[0] << endl;
    }
    return 0;
}


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

mt19937_64 llrand(random_device{}());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

vi adj[N];
int inc[N], dp[N];

queue <int> q;

int n, m, a, b;

int main () {
    scanf("%d%d", &n, &m);
    while (m--) {
        scanf("%d%d", &a, &b);
        adj[a].pb(b);
        inc[b]++;
    }

    for (int i = 1; i <= n; ++i) if (inc[i] == 0) q.push(i);

    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int v : adj[u]) {
            dp[v] = max(dp[v], dp[u]+1);
            if (inc[v] > 0 and --inc[v] == 0) {
                q.push(v);
            }
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 6528
N,M=map(int, input().split())
wa=[0]*N # カウント
ac=[0]*N # 何回目でacか
ac_n=0
for _ in range(M):
    p,s=input().split()
    p=int(p)
    if s=='WA':
        wa[p-1]+=1
    if (s=='AC') and (ac[p-1]==0):
        ac[p-1]=wa[p-1]+1
        ac_n+=1
print(str(ac_n)+' '+str(sum(ac)-ac_n))

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
 
int main() { 
  int N;
  cin >> N;
  int a = N/1000;
  int b = (N-1000*a) / 100;
  int c = (N-1000*a-100*b) / 10;
  int d = N%10;
  
  if(a==b&&b==c||b==c&&c==d||a==b&&b==c&&c==d){
    cout << "Yes" << endl;}
  else{
  cout << "No" << endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  int n, m;
  cin >> n >> m;
  int ans = (n-1)* (m-1);

  cout << ans << endl;
   
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
template<class T> void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
using namespace std;

const long long LLINF = 1LL << 60;

int main(void) {
	double x_1, y_1, x_2, y_2;
	cin >> x_1 >> y_1 >> x_2 >> y_2;

	double ans = sqrt(pow(x_1 - x_2, 2) + pow(y_1 - y_2, 2));
	printf("%.9f\n",ans);
}


Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <stack>
#include <set>
#include <algorithm>
using namespace std;
#define ll long long int

int main( ) {
  int h,w;
  cin >> h >> w;
  vector <string> a(h);
  for ( int i = 0; i < h; i++ ) {
      cin >> a[i];
  }
  vector <bool> row(h,false);
  vector <bool> col(w,false);
  for ( int i = 0; i < h; i++ ) {
    for ( int j = 0; j < w; j++ ) {
      if(a[i][j] == '#'){
        row[i] = true;
        col[j] = true;  
      }
    }
  }

  for ( int i = 0; i < h; i++ ) {
    if (row[i] == true) {
      for ( int j = 0; j < w; j++ ) {
        if( col[j] ) {
          cout << a[i][j];  
        }  
      }  
      cout << endl;
    }  
  }
  return 0;
}



Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<i32>();
    let a: Vec<i32> = (0..n).map(|_| read::<i32>()).collect();

    let mut avg: f64 = a.iter().fold(0f64, |sum, i| sum + *i as f64) / n as f64;
    avg = avg.round();

    println!("{}", a.iter().fold(0, |sum, i| sum + i32::pow(avg as i32 - *i, 2)));
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        try {
            int x, y;
            do {
                String[] list = br.readLine().split(" ");
                x = Integer.parseInt(list[0]);
                y = Integer.parseInt(list[1]);
                if (x == 0 && y == 0) {
                    break;
                } else {
                    if (x > y) {
                        System.out.println(y + " " + x);
                    } else {
                        System.out.println(x + " " + y);
                    }
                }
            } while (true);
        } catch (IOException e) {
            e.printStackTrace();
        }
		
	}

}

Measured memory_bytes: 27040
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int N; cin>>N;
    int ans=1e18;
    for(int i=1;i*i<=N;i++) if(N%i==0){
        chmin(ans,i+N/i-2);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
def readLine_int_list():return list(map(int, stdin.readline().split()))

n = int(input())
a = readLine_int_list()
even = [i for i in a if i%2 == 0]
e = len(even)

if e == 0:
    if n == 1:
        print(2)
    else:
        print(3**n - 1)
else:
    print(3**n - (2**e))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int dp[500001];
	dp[0]=0, dp[1]=0;
	int i0=-1;
	if(s[1]=='0') i0=1;
	for(int i=2; i<n; i++){
		dp[i]=dp[i-1];
		if(s[i]=='1'){
			if(i0==-1 || s[i0-1]=='0') continue;
			if(i0==i-1){
				for(int j=i-2; j>=0; j--){
					if(s[j]=='0') break;
					if(j>0) dp[i]=max(dp[j-1]+i-1-j, dp[i]);
                  else dp[i]=max(i-1, dp[i]);
				}
			}else{
				if(i0==1) dp[i]=max(i-1, dp[i]);
				else dp[i]=max(dp[i0-2]+i-i0, dp[i]);
			}
		}else{
			i0=i;
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

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

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

int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

int main() {
    char s[1000000];
    stin(s);
    int i, count = 0;
    REP(i, strlen(s) - 1) {
        if (s[i] == s[i+1]) {
            if (s[i] == '1') {
                s[i + 1] = '0';
            } else {
                s[i + 1] = '1';
            }
            count++;
        }
    }
    iout(count);
    return 0;
}


Measured memory_bytes: 256