akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
ll bin_pow(ll a,ll b,ll m)
{
    ll res=1;
    a%=m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        b>>=1;
        a=a*a%m;
    }
    return res;
}
bool miller_rabin(ll d,ll n)
{
    ll a=2+rand()%(n-4);
    ll x=bin_pow(a,d,n);
    if(x==1 || x==n-1)
        return true;
    while(d!=n-1)
    {
        x=(x*x)%n;
        d*=2;
        if(x==1)
            return false;
        if(x==n-1)
            return true;
    }
    return false;
}
bool prime(ll n,ll k)
{
    if(n==1 || n==4)
        return false;
    if(n<=3)
        return true;
    ll d=n-1;
    while(d%2==0)
        d/=2;
    for(int i=0; i<k; i++)
    {
        if(!miller_rabin(d,n))
            return false;
    }
    return true;
}
uint64_t negabinary(int64_t num) {
    const uint64_t mask = 0xAAAAAAAAAAAAAAAA;
    return (mask + num) ^ mask;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    if(n==0)return 0*puts("0");
    ll m=negabinary(n);
    string s="";
    while(m){
        s+=(m%2)+'0';
        m/=2;
    }
    reverse(s.begin(),s.end());
    cout<<s;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}



signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(1){
    string str;
    cin>>str;
    if(str == "#") break;
    int y, m, d;
    cin>>y>>m>>d;

    if(y > 31) str = "?", y -= 30;
    else if(y == 31){
      if(m > 4) str = "?", y -= 30;
      else if(m == 4){
	if(d > 30) str = "?", y -= 30;
      }
    }
    cout<<str<<" "<<y<<" "<<m<<" "<<d<<endl;

  }
  return 0;
}



Measured memory_bytes: 3248
#define _USE_MATH_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int f(int x) {
    int sum = 0;
    while (x != 0) {
        sum += x % 10;
        x /= 10;
    }
    return sum;
}

int main() {
    int N, A, B, ans = 0;
    cin >> N >> A >> B;

    for (int i = 1; i <= N; i++) {
        if (A <= f(i) && f(i) <= B)ans+=i;;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <utility>
#include <map>
#include <set>
using namespace std;

long long int pow(long long int n, long long int k){
    long long int x = 1;
    
    while(k > 0){
        if(k&1){
            x = x * n % 1000000007;
        }
        n = n * n % 1000000007;
        k >>= 1;
    }
    
    return x;
}

int main(){
    long long int a, b;
    
    cin >> a >> b;
    
    cout << pow(b, a) << endl;
}



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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

int mp[111111];

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	
	int n, k;cin >> n >> k;
	string str;cin >> str;
	char pre = '1';
	int cou = 0;
	
	REP(i, n){
		if(pre == '1' && str[i] == '0')cou++;
		pre = str[i];
		mp[i] = cou;
	}
	
	SHOW1d(mp, n+1);
	
	int r = 0;
	while(r < n && mp[r] <= k)r++;
	ll ans = r;
	REP(i, n){
		//cout << i << " " << r << " " << ans << endl;
		if(str[i] == '0')continue;
		while(r < n && mp[r] <= k + mp[i])r++;
		ans = max(ans, r - i);
	}
	
	cout << ans << endl;
	
	return 0;
}


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

typedef long long ll;
using namespace std;

bool can[52][52];
vector<int>with;
void go(int org, int n, int p){
	if(can[org][n])
		return;
	can[org][n] = 1;
	if(!n)
		return;
	for(int i = min(n, p); i > 0; i--)
		go(org, n % i, p);
	for(int i = 0; i < with.size(); i++)
		if(with[i] <= n)
			go(org, n % with[i], p);
}

vector<int>a, b;
bool avoid(int p){
	memset(can, 0, sizeof can);
	for(int i = 0; i <= 50; i++)
		go(i, i, p - 1);
	for(int i = 0; i < a.size(); i++)
		if(!can[a[i]][b[i]])
			return 0;
	return 1;
}

int main() {
	ios::sync_with_stdio(false);
	//	srand(time(NULL));
	int n; cin >> n;
	a.resize(n);
	b.resize(n);
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++){
//		cerr << can[a[i]][b[i]][2] << endl;
		cin >> b[i];
	}

	if(!avoid(51)){
		cout << -1 << endl;
		return 0;
	}

	ll res = 0;
	for(int p = 50; p > 0; p--){
		if(avoid(p))
			continue;
		with.push_back(p);
		res += (1LL << p);
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
struct node{int parent,left,right;};
node t[10001];
int n;

//ここから先行順巡回
void preparse(int u){
  if(u==-1) return;
  cout<<" "<<u;
  preparse(t[u].left);
  preparse(t[u].right);
}

//ここから中間順巡回
void inparse(int u){
  if(u==-1) return;
  inparse(t[u].left);
  cout<<" "<<u;
  inparse(t[u].right);
}

//ここから後行順巡回
void postparse(int u){
  if(u==-1) return;
  postparse(t[u].left);
  postparse(t[u].right);
  cout<<" "<<u;
}

//main関数
int main(){
  int v,l,r,root;
  cin>>n;
  for(int i=0;i<n;i++) t[i].parent=-1;
  for(int i=0;i<n;i++){
    cin>>v>>l>>r;
    t[v].left=l; //その節点においての左の子の情報を代入
    t[v].right=r; //右の子の情報を代入
    if(l!=-1) t[l].parent=v;
    if(r!=-1) t[r].parent=v;
    //それぞれの子の番地に親の情報を代入
  }
  for(int i=0;i<n;i++) if(t[i].parent==-1) root=i;
  //rootがどこかを探す
  
  cout<<"Preorder"<<endl;
  preparse(root);
  cout<<endl;
  cout<<"Inorder"<<endl;
  inparse(root);
  cout<<endl;
  cout<<"Postorder"<<endl;
  postparse(root);
  cout<<endl;
  return 0;
}
  
  

Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

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

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

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

	int N; cin >> N;

	vector<pair<int, int>> p, q;
	int vmax = 0;
	int psum = 0, qsum = 0;

	for (int i = 0; i < N; i++) {
		string s; cin >> s;
		int m = 0, t = 0;
		for (int j = 0; j < s.size(); j++) {
			if (s[j] == '(') { t++; }
			else { t--; }
			chmin(m, t);
		}
		if (t > 0) { p.push_back({ -m,t }); psum += t; }
		else if (t < 0) { q.push_back({ t - m, -t }); qsum += t; }
		else { chmax(vmax, -m); }
	}
	if (psum + qsum != 0) {
		cout << "No" << endl; return 0;
	}
	sort(p.begin(), p.end());
	sort(q.begin(), q.end());

	bool f = true;
	int k = 0;
	for (auto itr = p.begin(); itr != p.end(); itr++) {
		if (itr->first > k) { f = false; break; }
		k += itr->second;
	}

	k = 0;
	for (auto itr = q.begin(); itr != q.end(); itr++) {
		if (itr->first > k) { f = false; break; }
		k += itr->second;
	}

	if(f == false){ 
		cout << "No" << endl; return 0;
	}

	if (psum < vmax) {
		cout << "No" << endl; return 0;
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 10920
#include <stdio.h>

#define MAX 2000000

int H;
int A[MAX + 1];

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

	if(l <=H && A[l] > A[i]){ 
		largest = l; 
	}else{
		largest = i;
	}
	
	if(r <=H && A[r] > A[largest]){
		largest = r;
	}

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

void buildMaxHeap(){
	int i;	
	for(i=H/2;i>=1;i--){ maxHeapify(i); }
}


int main(void){

	int i;
	scanf("%d",&H);

	for(i=1;i<=H;i++){
		scanf("%d",&A[i]);
	}
	buildMaxHeap();
	
	for(i=1;i<=H;i++){
		printf(" %d",A[i]);
	}
	
	printf("\n");

return 0;

}



Measured memory_bytes: 3680
package main

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

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	a, b, c := io.NextInt(), io.NextInt(), io.NextInt()
	k := io.NextInt()
	cnt := 0
	for a >= b {
		b *= 2
		cnt++
	}
	for b >= c {
		c *= 2
		cnt++
	}
	if cnt <= k {
		io.Println("Yes")
	} else {
		io.Println("No")
	}
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


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

int main() {
	ll x;
	cin >> x;
	ll ans = 0, a = 100;
	while (a < x) {
		a += a / 100;
		++ans;
	}
	cout << ans << endl;
	return 0;
}






Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    rep(i,1,m){
        int x;cin>>x;
        n-=x;
    }
    cout<<(n<0?-1:n)<<endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
int i, n, m, q;
int a[50],b[50],c[50];
ll d[50];
ll ans = 0;
int v[10];

void check() {
    ll res = 0;
    rep(0, q) {
        if (v[b[i]-1] - v[a[i]-1] == c[i]) {
            res += d[i];
        }
    }
    if (res > ans) ans = res;
}

void search(int v[], int s, int rest) {
  if (rest == 0) {
      check();
  } else {
    if (s <= 0) return;
    search(v, s - 1, rest);
    v[rest - 1] = s;
    search(v, s, rest - 1);
    v[rest - 1] = s;
    search(v, s - 1, rest - 1);
  }
}

int main() {
    scanf(" %d %d %d", &n, &m, &q);
    rep(0,q) scanf(" %d %d %d %lld", &a[i], &b[i], &c[i], &d[i]);
    search(v, m, n);

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

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

int main()
{
    int a[]={4,6,9,11};int x,z;cin>>x>>z;
    if(x==2||z==2)
    cout<<"No\n";
    else
    {
        bool f1=false,f2=false;
        for(int i=0;i<4;++i)
        {
            if(a[i]==x)
            f1=true;
            if(a[i]==z)
            f2=true;
        }
        if(f1==f2)
        cout<<"Yes\n";
        else
        cout<<"No\n";
    }

    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(auto& i : v){
        cin >> i;
    }
    ll ans = 0;
    for(int i=1; i<=100; i++){
        bool flag = false;
        for(auto j : v){
            if(!flag && j >= i){
                flag = true;
                ans++;
            }else if(flag && j < i){
                flag = false;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	while(1)
	{
		int n,k; cin >> n >> k ;
		if(n==0 && k==0) break;
		int* a=new int[n]; int sum=0; int max=0;
		for(int i=0;i<n;i++) cin >> a[i] ;
		for(int i=0;i<k;i++) sum+=a[i];
		max=sum;
		for(int i=k;i<n;i++)
		{
			sum=sum+a[i]-a[i-k];
			if(sum>max) max=sum;
		}
		cout << max << '\n';
	}
}

Measured memory_bytes: 1580
import math

N = int(input())
lines = [list(map(int, input().split())) for i in range(N-1)]

cost = []

for i in range(N):
    time = 0
    for j in range(i, N-1):
        C, S, F = lines[j]
        if time < S:
            time = S + C
        else:
            time = F*math.ceil(time/F) + C
    cost.append(time)

for c in cost:
    print(c)




Measured memory_bytes: 9084
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (n, m, d) = i.read3::<usize, usize, usize>();

    writeln!(o, "{}", solve(n, m, d)).unwrap();
}
fn solve(n: usize, m: usize, d: usize) -> f64 {
    //  b : 隣り合う二つの美しさ
    let b = if d == 0 {
        n
    } else if d <= n {
        (n - d) * 2
    } else {
        0
    };
    (b * (m - 1)) as f64 / (n as f64).powi(2)
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        {$f:ident($($v:ident: $t:ident),*)} => {
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                $(
                    let $v = i.next().unwrap().parse().ok().unwrap();
                )*
                ($($v),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read3(v1: T1, v2: T2, v3: T3) }
    }
}


Measured memory_bytes: 4352
l = 'abcdefghijklmnopqrstuvwxyz'

while True:
    try:
        s = input()
    except:
        exit()
    for d in range(1,27):
        t = s[:-1].translate(str.maketrans(l,l[d:] + l[:d]))
        if 'that' in t or 'this' in t or 'the' in t:
            print(t + '.')
            break



Measured memory_bytes: 5568
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        n:usize,
        a:[i64;n],
    }
    if a.iter().filter(|&x| x % 2 == 1).count() % 2 == 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}


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

using namespace std;

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, n) for(int i=0; i<(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair

typedef long long int ll;

int main(){
  char s[7];
  scanf("%s",s);
  int sum=0;
  rep(i,6){
    if(s[i]=='1')sum++;
  }
  printf("%d",sum);
  return 0;
}


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

using namespace std;
#define int long long
signed main() {
    int n;
    cin >> n;
    int arr[4] = {0};
    int i;
    for(i=0;i<n;i++)
    {
        string str;
        cin >> str;
        if(str == "AC")
            arr[0]++;
        else if(str == "WA")
            arr[1]++;
        else if(str == "TLE")
            arr[2]++;
        else
            arr[3]++;
    }
    cout << "AC x " << arr[0] << '\n';
    cout << "WA x " << arr[1] << '\n';
    cout << "TLE x " << arr[2] << '\n';
    cout << "RE x " << arr[3] << '\n';
}

Measured memory_bytes: 3628
#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 reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int n;
int C[50];
bool used[50];
bool full[50];

bool searchFrom();

bool searchTo(int v, int src)
{
	reps(i, src+1, n){
		if(!used[i]){
			full[i] = used[i] = true;
			if(C[i] == v){
				if(searchFrom())
					return true;
			}
			else if(C[i] < v && searchTo(v-C[i], i))
				return true;
			full[i] = used[i] = false;
		}
	}
	
	return false;
}

bool searchFrom()
{
	int unused = -1;
	rep(i, n){
		if(!used[i]){
			unused = i;
			break;
		}
	}
	if(unused == -1)
		return true;
	
	rep(i, unused){
		if(full[i]){
			full[i] = false;
			if(searchTo(C[i], i))
				return true;
			full[i] = true;
		}
	}
	return false;
}

int main()
{
	while(scanf("%d", &n), n){
		rep(i, n)
			scanf("%d", &C[i]);
		
		sort(C, C+n, greater<int>());
		fill(used, used+n, false);
		fill(full, full+n, false);
		used[0] = full[0] = true;
		puts(searchFrom() ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 1184
#include<stdio.h>


typedef struct{
  int id;
  int left;
  int right;
  int p;
  int s;
  int dep;
  int deg;
  int h;
}Tree;

Tree A[25];

int main(){
  int in,n,i,s1,s2;
  int pa,pc,hc,he;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    A[i].p=-1;
    A[i].s=-1;
    A[i].deg=0;
    A[i].h=0;
  }
 
  for(i=0;i<n;i++){
    scanf("%d",&in);
    A[in].id=in;
    scanf("%d %d",&A[in].left,&A[in].right);
    if(A[in].left!=-1&&A[in].right!=-1){
      A[in].deg=2;
    }else if(A[in].left!=-1||A[in].right!=-1){
      A[in].deg=1;
    }
 
    s1=A[in].left;
    s2=A[in].right;
    A[s1].p=A[in].id;
    A[s2].p=A[in].id;
    A[s1].s=s2;
    A[s2].s=s1;
  }
 
  for(i=0;i<n;i++){
    if(A[i].p==-1){
      A[i].dep=0;
    }else{
      pa=A[i].p;
      pc=1;
     
      while(A[pa].p!=-1){
    pc++;
    pa=A[pa].p;
      }
      A[i].dep=pc;
    }
  }
 
 
 
  for(i=0;i<n;i++){
    if(A[i].deg==0){
      hc=0;
      A[i].h=hc;
      pa=A[i].p;
 
      while(pa!=-1){
    hc++;
    if(A[pa].h<=hc){
      A[pa].h=hc;
      pa=A[pa].p;
    }
      }
    }
  }
 
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,A[i].p,A[i].s,A[i].deg,A[i].dep,A[i].h);
    if(A[i].p==-1){
      printf("root\n");
    }else if(A[i].left==-1&&A[i].right==-1){
      printf("leaf\n");
    }else{
      printf("internal node\n");
    }
  }
 
  return 0;
}

Measured memory_bytes: 612
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(x+a<b)cout<<"dangerous"<<endl;
  else if(b<=a)cout<<"delicious"<<endl;
  else cout<<"safe"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	ll ans=0;
	ll cnt=0;
	for(ll i=0;i<s.size();i++){
		if(s[i]=='W'){
			ans+=(i-cnt);
			cnt++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

using namespace std;

class BIT{
	vector<int> bit;
	
public:
	
	BIT(){
	}
	
	BIT(int size){
		init(size);
	}
	
	void init(int size){
		bit.clear();
		bit.resize(size+1);
	}
	
	int sum(int i){
		int s = 0;
		while(i > 0){
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}

	void add(int i , int x){
		while(i < bit.size()){
			bit[i] += x;
			i += i & -i;
		}
	}

	int lower_bound(int w){
		if(w <= 0) return 0;
		int x = 0, t = 1;
		while(t*2 < bit.size()) t *= 2;
		
		for(int k = t; k > 0; k /= 2){
			if(x + k < bit.size() && bit[x + k] < w){
				w -= bit[x + k];
				x += k;
			}
		}
		return x + 1;
	}
};


signed main(){
	
	int n, q;
	BIT bit;
	
	cin>>n>>q;
	
	bit.init(n);
	
	for(int _ = 0; _ < q; _++){
		int com, x, y;
		
		cin>>com>>x>>y;
		
		if(com){
			cout<<bit.sum(y) - bit.sum(x-1)<<endl;
		} else {
			bit.add(x, y);
		}
	}
	
	
	return 0;
}


Measured memory_bytes: 3112
from collections import Counter
def solve():
  n = int(input())
  a = [input() for _ in range(n)]
  c = Counter(a)
  values, counts = zip(*c.most_common())
  maxc = max(counts)
  array = []
  for i in range(len(values)):
    if counts[i] == maxc:
      array.append(values[i])
    else:
      break
  array.sort()
  for i in array:
    print(i)
solve()

Measured memory_bytes: 125008
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
#define rep(i,N) for(int i = 0 ; (i) < (int)(N) ; i++)

struct NODE{
	int x,y,dir;
	int P,Q;
	NODE(int x,int y,int dir,int P,int Q) : x(x) , y(y) , dir(dir) , P(P) , Q(Q) {}
};
char c[110][110];

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

int memo[110][110][4][11][11];
int main(){
	memset(memo,-1,sizeof(memo));
	int H,W,A;
	cin >> H >> W >> A;
	int sx,sy,gx,gy;
	rep(i,H){
		rep(j,W){
			cin >> c[i][j];
			if( c[i][j] == 'S' ){
				sx = j , sy = i;
			}
			if( c[i][j] == 'G' ){
				gx = j , gy = i;
			}
		}
	}
	queue<NODE> Q;
	
	Q.push(NODE(sx,sy,0,A,A));
	int answer = 1e9;
	while(Q.size()){
		NODE q = Q.front(); Q.pop();
		if( q.dir == 2 && c[q.y][q.x] == 'S' ) continue;
		if( q.x < 0 || q.x >= W || q.y >= H || q.y < 0 || c[q.y][q.x] == '#' || c[q.y][q.x] == '#') continue;
		if( q.x == gx && q.y == gy ){
			answer = min( answer , 2*A - q.P - q.Q );
			continue;
		}
		for(int i = 0 ; i < 4 ; i++){
			int pp = 0 , qq = 0;
			if( q.dir != i && c[q.y][q.x] == 'S' ) continue;
			if( (q.dir+2)%4 == i ) continue;
			if( q.dir == 0 && i == 1 || q.dir == 1 && i == 0 || q.dir == 2 && i == 3 || q.dir == 3 && i == 2 ) pp = 1;
			if( q.dir == 0 && i == 3 || q.dir == 3 && i == 0 || q.dir == 2 && i == 1 || q.dir == 1 && i == 2 ) qq = 1;
			int nx = q.x + dx[i];
			int ny = q.y + dy[i];
			if( nx < 0 || nx >= W || ny >= H || ny < 0 || q.P-pp < 0 || q.Q-qq < 0 || c[ny][nx] == '#' || ~memo[nx][ny][i][q.P-pp][q.Q-qq] ) continue;
			memo[nx][ny][i][q.P-pp][q.Q-qq] = 0;
			//cout << nx << " " << ny << " " << i << " " << q.P-pp << " " << q.Q-qq << endl;
			Q.push(NODE(nx,ny,i,q.P-pp,q.Q-qq));
		}
		
	}
	
	if( answer > 1e8 ){
		cout << -1 << endl;
	}else{
		cout << answer << endl;
	}
	
};

Measured memory_bytes: 24236
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string Yes[2] = {"Yes", "No"};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

using Graph = vector<vector<int>>;
Graph G;

/*------------------------------------------------------------------*/

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

    int x; cin >> x;
    if(x == 1) cout << 0 << endl;
    else cout << 1 << endl;
}


Measured memory_bytes: 3652
##C problem
N = int(input())
v = list(map(float, input().split()))

vs = sorted(v)

for i in range(N-1):

    a=vs[0]

    b=vs[1]
    c=(a+b)/2
    vs.remove(b)
    vs.insert(0,c)
    vs.remove(a)
    #print(i)
    #print(vs)

print(vs[0])

Measured memory_bytes: 3064
import bisect

N,K = list(map(int,input().strip().split()))
xlist = list(map(int,input().strip().split()))
ans = int(10e10)

if 0 not in xlist:
    bisect.insort_left(xlist,0)
else:
    K -= 1

if (bisect.bisect_left(xlist,0)+1) > K:
    del xlist[0:(bisect.bisect_left(xlist,0) - K)]
if len(xlist) < (bisect.bisect_left(xlist,0) + K):
    del xlist[(bisect.bisect_left(xlist,0)+K +1):]

for i in range(len(xlist)-K):
    low = min(abs(xlist[i]),abs(xlist[i+K]))
    high = max(abs(xlist[i]),abs(xlist[i+K]))
    ans = min(ans,low*2+high)

print(ans)

Measured memory_bytes: 14548
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()
#define pb push_back

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

	ll n, k;
	cin >> n >> k;

	// a+b, b+c, c+aがkの倍数 %k == 0
	// O(nlogn)かO(n)以下

	ll ans = 0;

	// aになりうる値はb,cにもなりうる　cnt^3

	if (k % 2) { // 奇数の場合はこれでいい
		ll cnt = n / k;
		ans = cnt * cnt * cnt;
	}
	else { // 偶数の時は...
		ll cnt = n / k;
		ll ccnt = (n + (k/2)) / k;
		ans = cnt * cnt * cnt + ccnt * ccnt * ccnt;
	}

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

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

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

	cin >> a >> b >> c >> d;

	while(1){
		c -= b;
		if(c <= 0){
			cout << "Yes" << endl;
			break;
		}

		a -= d;
		if(a <= 0){
			cout << "No" << endl;
			break;
		}
	}
}



Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;

ll dp[100001];

int main(void){
    ll n;
    cin>>n;
    vl h(n);
    rep(i,n) cin>>h[i];
    rep(i,n) dp[i] = inf;
    dp[0] = 0;
    rep(i,n){
        if(i+1<n) dp[i+1] = min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        if(i+2<n) dp[i+2] = min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
l, r = map(int,input().split())
if  r - l >= 2019:
    print(0)
else:
    ans = 2019
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            ans = min(ans, (i*j)%2019)
    print(ans)
                


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


int main(){
  int h,w;
  cin >> h >> w;
  int tate=0;
  char yoko;
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      string s;
      cin >> s;
      if(s=="snuke"){
        tate=i+1;
        yoko=j+'A';
      }
    }
  }
  cout << yoko << tate << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
typedef long long ll;
using namespace std;
int main()
{

  int n;
  cin>>n;
  if(n>=30)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;

return 0;

}


Measured memory_bytes: 3632
# include<iostream>
# include<cstdio>
# include<algorithm>
# include<cmath>
# include<vector>
// c
# include<stdio.h>
# include<stdlib.h>
# include<string.h>
using namespace std;
int top,S[1000];

void push(int x){
    top++;
    S[top]=x;
}
int pop(){
    top--;
    return S[top+1];
}

int main(){
    int a,b,x;
    char s[100];
    top = 0 ;
    // 読み込みの指定がない場合はEOF判定をする
    while(scanf("%s",s)!= EOF){
        if(s[0] == '+'){
            a = pop();
            b = pop();
            push(a+b);
        }else if(s[0]=='-'){
            a = pop();
            b = pop();
            push(b-a);
        }else if(s[0]=='*'){
            a = pop();
            b = pop();
            push(a*b);
        }else{
            x = atoi(s);
            push(x);
        }
    }
    // printf("%d\n",pop());
    cout << pop() << endl;
    return 0;
}


Measured memory_bytes: 3228
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  double maxd = -1, max_water, max_suger;
  for(int a = 0; a <= 30; a++) {
    for(int b = 0; b <= 30; b++) {
      int water = 100 * A * a + 100 * B * b;
      if (water > F) continue;
      int ma = water * E / 100;
      for(int c = 0; c * C <= ma; c++) {
        for(int d = 0; c * C + d * D <= ma; d++) {
          int suger = c * C + d * D;
          if (water + suger == 0) continue;
          if (water + suger > F) continue;
          
          double d_ = 100.0 * suger / (water + suger);

          if (maxd < d_) {
            maxd = d_;
            max_water = water;
            max_suger = c * C + d * D;
          }
        }
      }
    }
  }

  cout << max_water + max_suger << " " << max_suger << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int h[N];
vi v[N];
int main()
{
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		cin >> h[i];
	for(int i = 1; i <= m; i ++){
		int x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	int ans =0;
	for(int i = 1; i <= n; i ++)
	{
		int mx = 0;
		for(auto it : v[i])
		{
			mx = max(mx, h[it]);
		}
		if(h[i]  > mx)
			ans ++;
	}
	cout << ans;





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 12016
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

// =========ここまでテンプレ============

int main()
{
    char alpha;
    cin >> alpha;
    string smalls = "abcdefghijklmnopqrtsuvwxyz";
    if (contains_itr(smalls, alpha))
    {
        cout << "a" << endl;
    }
    else
    {
        cout << "A" << endl;
    }
}

Measured memory_bytes: 3028
#include<stdio.h>

#define MAX 250

int left(int i);
int right(int i);
int parent(int i);

int main(void)
{
  int A[MAX];
  int H,i;

  scanf("%d",&H);
  for(i = 1;i <= H;i++){
    scanf("%d",&A[i]);
  }

  for(i = 1;i <= H;i++){
    printf("node %d",i);
    printf(": key = %d",A[i]);
    putchar(',');
    putchar(' ');

    if(parent(i) >= 1){
      printf("parent key = %d",A[parent(i)]);
    putchar(',');
    putchar(' ');
    }
    if(left(i) <= H){
      printf("left key = %d",A[left(i)]);
    putchar(',');
    putchar(' ');
    }
    if(right(i) <= H){
      printf("right key = %d",A[right(i)]);
    putchar(',');
    putchar(' ');
    }
    
    puts("");
  }

  return 0;
}




int left(int i){
  return i*2;
}

int right(int i){
  return i*2 + 1;
}

int parent(int i){
  return i/2;
}



Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main()
{
	string s;
	ll ans=0;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(i>=s.size()-1-i)
			break;
		if(s[i]!=s[s.size()-1-i])
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

using PP = pair<long, long>;
const long inf = 1e18;
int n, m, p;
vector<PP> G[2500];

long dist[2500];
bool update() {
  bool flg = false;
  for (int from = 0; from < n; ++from) {
    for (auto e : G[from]) {
      int to = e.first;
      int c = e.second;
      if (dist[from] + c < dist[to]) {
        dist[to] = dist[from] + c;
        if (to == n - 1) flg = true;
      }
    }
  }
  return flg;
}

int main() {
  cin >> n >> m >> p;
  for (int j = 0; j < m; ++j) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    G[a].push_back(PP(b, p - c));
  }
  
  fill(dist, dist + n, inf);
  dist[0] = 0;
  
  for (int z = 0; z < n; ++z) update();
  bool loop = false;
  for (int z = 0; z < n; ++z) {
    if (update()) loop = true;
  }
  
  if (loop) {
    cout << -1 << endl;
  } else {
    cout << max(0l, -dist[n - 1]) << endl;
  }
}

Measured memory_bytes: 512
N, K = map(int,input().split())
LIST = []
for i in range(K): 
    d_i = int(input())
    # nest_list = [int(input()) for j in range(d_i)]
    nest_list = list(map(int,input().split())) 
    LIST.append(nest_list)

all_set = set(list(range(1, N+1)))
difference_set = all_set

for nest_list in LIST:
    nest_set = set(nest_list)
    difference_set = difference_set - nest_set 

print(len(difference_set))

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

class Main {

    public static void main( String[] args ) {

	final Scanner stdin = new Scanner(System.in);
	final Map<Integer, Integer> cur = new HashMap<Integer, Integer>();
	final Map<Integer, Integer> next = new HashMap<Integer, Integer>();
	
	while ( true ) {

	    final String line = stdin.nextLine();
	    if ( line.trim().equals( "" ) ) {
		break;
	    }
	    final String[] input = line.split( "," );
	    final int val = Integer.parseInt( input[0] );
	    if ( !cur.containsKey( val ) ) {
		cur.put( val, 1 );
	    } else {
		cur.put( val, cur.get( val ) + 1 );
	    }	    
	}

	while ( stdin.hasNextLine() ) {
	    final String[] input = stdin.nextLine().split( "," );
	    final int val = Integer.parseInt( input[0] );
	    if ( !next.containsKey( val ) ) {
		next.put( val, 1 );
	    } else {
		next.put( val, next.get( val ) + 1 );
	    }	    
	}

	final ArrayList<Integer> keyArray = new ArrayList<Integer>( next.keySet() );
	Collections.sort( keyArray );
	for ( Integer key : keyArray ) {
	    if ( cur.containsKey( key ) ) {
 		System.out.printf( "%d %d\n", key, ( cur.get( key ) + next.get( key ) ) );
	    }
	}
	
    }
    
}

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

using namespace std;

int insertionSort(int ,int);
void trace(int , int);

void trace(int A[],int N)
{
  for(int i=0;i<N;i++)
    {
      if(i>0) cout<<" ";
      cout<<A[i];
    }
  cout<<endl;
}

int insertionSort(int A[],int N)
{
  int j,v;
  for(int i=1;i<N;i++)
    {
      v=A[i];
      j=i-1;
      while(j>=0 && A[j]>v)
	{
	  A[j+1]=A[j];
	  j--;
	}
      A[j+1]=v;
      trace(A,N);
    }
}
  
int main()
{
  int N,A[1000];
  cin>>N;
  for( int i;i<N;i++) cin>>A[i];
  trace(A,N);
  insertionSort(A,N);
}
  
  



Measured memory_bytes: 3072
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll T[N + 1];
    ll ans = 0;
    REP(i, N){
        cin >> T[i];
        ans += T[i];
    }

    ll M;
    cin >> M;

    ll P, X;
    REP(i, M){
        cin >> P >> X;
        cout << ans - (T[P] - X) << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	int n = s.size(), m = t.size();
	if(n < m){
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	for(int i = n-m; i >= 0; --i){
		bool match = true;
		rep(j,m){
			if(s[i+j] == '?') continue;
			if(s[i+j] != t[j]) match = false;
		}
		if(match){
			rep(j,m) s[i+j] = t[j];
			break;
		}
		if(i == 0){
			cout << "UNRESTORABLE" << endl;
			return 0;
		}
	}
	rep(i,n){
		if(s[i] == '?') s[i] = 'a';
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int n,d;
cin >> n >> d;
vector<vector<int>> vec(n,vector<int>(d));
for (int i = 0;i < n;i++) {
    for (int j = 0;j < d;j++) {
        cin >> vec.at(i).at(j);
    }
}
int count = 0;
for(int i = 0;i < n;i++) {
    
    for (int l = 0; l < n-i;l++) {
        int ans = 0;
    for (int j = 0;j < d;j++) {
        int kota = vec.at(i).at(j) - vec.at(i+l).at(j);
        ans = ans + kota * kota;
    }
     for (int k = 1;k < INF;k++) {
         if (ans == k*k) count++;
         if (ans <= k*k) break;
        }
    }
}

cout << count << endl;

return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
# your code goes here
from heapq import heappop ,heappush
def bfs(k):
    
    q=[k]
    vis[k]=1
    #p.append(k+1)
    while len(q):
        
        
        curr=heappop(q)
        p.append(curr+1)
        #print(vis, v[curr+1])
        for c in v[curr+1]:
            #print(c)
            if vis[c-1]==0:
                a.append(c)
                
                heappush(q,c-1)
                vis[c-1]=1
            
    
n,m=map(int,input().split())
v=defaultdict(list)
vis=[0]*n
p=[]

for i in range(m):
    a,b=map(int,input().split())
    v[a].append(b)
    v[b].append(a)
ans=0      
for i in range(n):
    if vis[i]==0:
        a=[i+1]
        bfs(i)
        ans=max(ans,len(a))
        #print(a)
    

print(ans)
    
	

Measured memory_bytes: 152840
using System;

namespace ABC152a
{
    class Program
    {
        static void Main(string[] args)
        {

			int n, m;
			var word = Console.ReadLine().Split(' ');
			n = int.Parse(word[0]);
			m = int.Parse(word[1]);
			if (n == m)
			{
				Console.WriteLine("Yes");
			}
			else
			{
				Console.WriteLine("No");
			}
			Console.ReadKey();
		}
    }
}


Measured memory_bytes: 11092
S=input()
l=len(S)
L1=[0]*(l+1)
L2=[0]*(l+1)
for i in range(l):
    if S[i]=='<':
        L1[i+1]=L1[i]+1
    else:
        L1[i+1]=0
for i in reversed(range(l)):
    if S[i]=='>':
        L2[i]=L2[i+1]+1
    else:
        L2[i]=0
Ans=[0]*(l+1)
for i in range(l+1):
    Ans[i]=max(L1[i],L2[i])
print(sum(Ans))

Measured memory_bytes: 54728
#include<iostream>
#include<vector>

using namespace std;

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

    vector<int> t(n+1,0), x(n+1,0), y(n+1,0);

    for(int i=1;i<=n;i++)
        cin >> t[i] >> x[i] >> y[i];
    
    int t1, x1, y1;

    for(int i=0;i<n;i++){
        t1=t[i+1] - t[i];
        x1=x[i+1] - x[i];
        y1=y[i+1] - y[i];
        
        if(t1<(x1+y1)){
            cout << "No" << endl;
            return 0;
        } else if(((t1 - x1 - y1) % 2) == 1){
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define loop(i,a,n) for (ll i=a;i<n;i++)
#define loopm(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define tr(container,it)\
for(auto it=container.begin();it!=container.end();it++)
#define SZ(x) ((int)(x).size())
#define WGraph(n) vector < vector < pair < ll , ll > > >(n)
typedef vector<long long> VI;
typedef long long ll;
typedef vector < vector < ll > > VII;
typedef pair<ll,ll> PII;
typedef double db;
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    string s="";
    cin>>s;
    vector<ll> posi;
    loopm(i,0,n)
    if(s[i]=='R')
      posi.pb(i);
    ll ans=0;
    ll j=0;
    loop(i,0,n){
      if(s[i]=='W'){
        if(j>=0&&j<posi.size()){
           if(posi[j]>i){
            ans++;
            swap(s[i],s[posi[j]]);
            j++;
           }
        }
      }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 5468
/* 一見どういう場合にスコアが最大になるかがわかりにくいが、
(マスの総数) = (黒のマスの数) + (白のマスの数)
            = (元の黒のマスの数) + (新たに塗った黒のマスの数) + (通過できるマスの数)
が成り立つので、右辺第二項を最大化するには第三項を最小にすればよいとわかる。
したがって最短経路でゴールに到達するときの通過するマスの数をBFS で求めればよい。
*/

// 今回はマス目の数を求めたいので、s[0][0] は0 ではなく1 で初期化する。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 60;
const int INF = 10000;

typedef pair<int, int> P;

int h, w;
char maze[MAX_N][MAX_N];
int s[MAX_N][MAX_N];
int black, path;

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

int bfs(){
    queue<P> que;

    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++) s[i][j] = INF;
    }

    que.push(P(0, 0));
    s[0][0] = 1;

    while(que.size()){
        P p = que.front(); que.pop();
        if (p.first == h - 1 && p.second == w - 1) break;
        for (int i = 0; i < 4; i++){
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (0 <= nx && nx < h && 0 <= ny && ny < w
                && maze[nx][ny] != '#' && s[nx][ny] == INF){
                    que.push(P(nx, ny));
                    s[nx][ny] = s[p.first][p.second] + 1;
            }
        }
    }

    return s[h - 1][w - 1];
}

int main(){
    cin >> h >> w;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >> maze[i][j];
            if (maze[i][j] == '#') black++;
        }
    }

    path = bfs();
    if (path == INF){
        cout << -1 << endl;
        return 0;
    }

    int ans = h * w - black - path;
    
    cout << ans << endl;

    return 0;
}

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

fn main() {
  let stdin = stdin();
  let stdout = stdout();
  let mut stdout = BufWriter::new(stdout.lock());

  for line in stdin.lock().lines() {
    let line = line.unwrap();
    let mut args = line.split_whitespace().map(|str| str.parse::<usize>().unwrap());
    let h = args.next().unwrap();
    let w = args.next().unwrap();

    if h == 0 { break }

    let mut str1 = String::with_capacity(w);
    for i in 0..w {
      str1.push(
        if i % 2 == 0 { '#' }
        else { '.' }
      )
    }

    let mut str2 = String::with_capacity(w);
    for i in 0..w {
      str2.push(
        if i % 2 == 1 { '#' }
        else { '.' }
      )
    }

    for i in 0..h {
      let str = if i % 2 == 0 { &str1 } else { &str2 };
      writeln!(&mut stdout, "{}", str).unwrap();
    }

    writeln!(&mut stdout).unwrap();
  }
}



Measured memory_bytes: 5028