akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <bitset>
#include <cmath>

using namespace std;
using ll = long long;
using ld = long double;
// const ll mod =  998244353 ;
const ll mod =  1000000007 ;
const ll inf = 1e15;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_root_nodes = power(base, exponent / 2); return root_root_nodes * root_root_nodes % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
template<typename T, typename F> ll sum(T begin, T end, F func) {return accumulate(begin, end, 0ll, func);}
struct combination{ vector<ll> fact, inv; combination(int size) : fact(size + 1), inv(size + 1){ fact[0] = 1; for(int i = 1; i <= size; i++){ fact[i] = fact[i - 1] * i % mod; } inv[size] = power(fact[size], mod - 2); for(int i = size - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

using Pair = pair<ll, ll>;

vector<vector<int>> g;
map<Pair, int> edge_no;
map<Pair, int> edge_co;

int dfs(int from_color, int current) {
  int color = 1;
  int max_c = color;
  for(auto next: g[current]) {
    if(color == from_color) color++;
    if(edge_co[{current, next}] > 0) {
      continue;
    }
    edge_co[{current, next}] = edge_co[{next, current}] = color;
    max_c = max({dfs(color, next), color, max_c});
    color++;
  }
  return max_c;
} 

signed main() {
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(12);
  ll n;
  cin >> n;
  g.resize(n);
  vector<int> a(n), b(n);
  REP(i, n-1) {
    int x, y;
    cin >> x >> y;
    x--;y--;
    g[x].push_back(y);
    g[y].push_back(x);
    a[i] = x;
    b[i] = y;
    edge_no[{x, y}] = i;
    edge_no[{y, x}] = i;
  }
  int k = dfs(0, 0);
  cout << k << endl;
  vector<int> ans(n-1);
  for(auto const& x: edge_co) {
    ans[edge_no[x.first]] = x.second;
  }
  REP(i, n-1) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 32256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a, b;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> a >> b;
	if (a <b)swap(a,b);
	if ((a+b)%2){cout << "IMPOSSIBLE";return 0;}else {
		cout << (a+b)/2;
		}

}

Measured memory_bytes: 256
'''
Created on 2020/09/08

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  N,M,K=map(int,pin().split())
  for i in range(N+1):
    for j in range(M+1):
      if i*(M-j)+(N-i)*j==K:
        print("Yes")
        return
  print("No")
  return
main()

Measured memory_bytes: 64240
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;

int main() {
  //char in[120];
  int n; cin>>n;
  std::vector<int> a(n);
  std::vector<int> b(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  int ans = 0;
  rep(i,n) {
    if (a[i] > b[i]) ans += (a[i] - b[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 888
/*
 * @Author: Luisvacson
 * @LastEditors: Luisvacson
 * @Descriptions: None
 * @Date: 2020-09-05 19:39:07
 * @LastEditTime: 2020-09-05 19:57:47
 * @FilePath: \VSC\C++\Public\Bomber.cpp
 */
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define int long long

int n, m;
int bn;
pii bomb[300005];
int row[300005];
int col[300005];
set<int> st;
signed main()
{
    scanf("%d%d", &n, &m);
    scanf("%d", &bn);
    register int i;

    for (i = 1; i <= bn; ++i) {
        scanf("%d%d", &bomb[i].first, &bomb[i].second);
        ++row[bomb[i].first];
        ++col[bomb[i].second];
        st.insert(bomb[i].first*3*1e5+bomb[i].second);
    }

    int maxr = -1 << 30, maxc = -1 << 30;
    for (i = 1; i <= n; ++i)
        maxr = max(maxr, row[i]);
    for (i = 1; i <= m; ++i)
        maxc = max(maxc, col[i]);

    vector<int> Qr, Qc;
    for (i = 1; i <= n; ++i)
        if (row[i] == maxr)
            Qr.push_back(i);
    for (i = 1; i <= m; ++i)
        if (col[i] == maxc)
            Qc.push_back(i);

    for (vector<int>::iterator it = Qr.begin(); it != Qr.end(); ++it) {
        for (vector<int>::iterator jt = Qc.begin(); jt != Qc.end(); ++jt) {
            int r = *it;
            int c = *jt;
            if (st.find(r*3*1e5+c) == st.end()) {
                printf("%d\n", maxr + maxc);
                return 0;
            }
        }
    }

    printf("%d\n", maxr + maxc - 1);
    return 0;
}

Measured memory_bytes: 35092
#include <iostream>
using namespace std;
 
int main() {
  int K;
  string S;
  cin >> K >>S;
 int x=S.size();
  if(x <= K){
  cout << S <<endl;
  }
  else{for(int i=0;i<K;i++){
  cout <<S.at(i);
  }
   cout <<"..."<<endl;
  }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
typedef pair<ll,mp> mypair;
#define MAXN 1001024
#define INF 1000000007
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
ll extgcd(ll a,ll b,ll &x,ll &y){
	if(b==0){
		x=1;
		y=0;
		return a;
	}
	ll d = extgcd(b,a%b,y,x);
	y -= a/b * x;
	return d;
}
//ax+by = c
mypair extgcd(ll a,ll b){
  ll x,y;
  ll d = extgcd(a,b,x,y);
  mp tmp = mp(x,y);
  return mypair(d,tmp);
}

//素数列挙
ll prime[MAXN] ;//segment_sieve [a,b)
bool is_prime[MAXN];
int sieve(int n){
	int res = 0;
	fill(is_prime,is_prime+MAXN,true);
	is_prime[0] = is_prime[1] = false;
	for(int i = 2;i<=n;i++){
		if(!is_prime[i])continue;
		prime[res++] = i;
		for(int j = 2*i;j<=n;j+=i)is_prime[j] = false;
	}
	return res;	
}
bool is_prime_ab[MAXN];
ll segment_sieve(ll a,ll b){
	fill(is_prime,is_prime+MAXN,true);
	fill(is_prime_ab,is_prime_ab+MAXN,true);
	for(int i=2;i*i <= b-1 ;i++){
		if(!is_prime[i]) continue;
		for(ll j = 2*i;j*j<=b-1;j+=i)is_prime[j] = false;
		for(ll j = a-a%i;j<b;j += i){
			if(j< a) continue;
			if(is_prime_ab[j-a]) is_prime_ab[j-a] = false;
		}
	}
	ll res = 0;
	for(ll i = a;i< b ;i++ )if(is_prime_ab[i-a] ) prime[res++] = i;
	return res;
}
// nが素数かどうかの判定
bool is_primef(ll n){
	if(n==1) return false;
	for(ll i=2;i*i<=n;i++)
		if(n%i==0)return false;
	return true;
}

vector<ll> divisors(ll n){
	vector<ll> res;
	for(ll i=1;i*i<=n;i++){
		if(n%i != 0) continue;
		res.push_back(i);
		if(n/i== i)continue;
		res.push_back(n/i);
	}
	return res;
}
map<ll,ll> prime_factors(ll n){
	map<ll,ll> res;
	if(n<=1){
		res[n] = 1;
		return res;
	}
	
	//for(int i=2,_n = n;i*i<=_n;i++){
	for(ll i=2;i*i<=n;i++){
		while(n%i==0){
			res[i]++;
			n /= i;
		}
	}
	if(n!=1)res[n] = 1;
	return res;
}

//1からnまででnと互いにそなものの数
ll euler_phi(ll n){
	ll cnt = n;
	map<ll,ll> res = prime_factors(n);
	for(auto it = res.begin(),end = res.end();it!=end;it++){
		cnt = cnt/it->first*(it->first-1);
	}
	return cnt;
}
ll pow(ll n,ll m){
	vector<ll> a(33);
	a[0] = n;
	for(int i=1;i<32;i++){
	a[i] = (a[i-1]*a[i-1])%INF;
	}
	ll res = 1;
	for(int i=0;i<32;i++){
	if( ( m&(1<<i) ) ){
		res = (res*a[i])%INF;
		}
	}
	return res;
}
int range = 1000001;

int main(){
	int num = sieve(range);
	while(1){
		int a,d,n;
		cin>>a>>d>>n;
		if(a==0) break;
		int cnt = 0;
		int p = a;
		while(cnt!=n){
			if(is_prime[p])cnt++;
			p+=d;	
		}
		cout<<p-d<<endl;
	}

	return 0;
}



Measured memory_bytes: 4668
def CountingSort(A, B, k):
    C = [0]*(k+2)
    for i in range(n):
        C[A[i]] += 1
    for i in range(1,k+1):
        C[i] = C[i] + C[i-1]
    x = list(range(n))
    x.reverse()
    for i in x:
        B[C[A[i]]] = A[i]
        C[A[i]] -= 1
    return B
n = int(input())
A = list(map(int,input().split()))
B = [0]*(n+1)
k = max(A)
res = CountingSort(A, B, k)
print(*res[1:])

Measured memory_bytes: 232300
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
using namespace std;

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


int main() {
	char c; cin >> c;
	string s = "aiueo";
	for (int i = 0; i < 5; i++) {
		if (s.at(i) == c) {
			cout << "vowel" << endl;
			return 0;
		}
	}
	cout << "consonant" << endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  for(int i=0; i<s.size()-1; i++){
    if(s[i]==s[i+1]){
      cout << "Bad"; return 0;
    }
  }
  
  cout << "Good";
  
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  static ArrayList[] edge;
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    edge = new ArrayList[N + 1];
    for(int i = 1; i < N + 1; i++) {
      edge[i] = new ArrayList<Integer>();
    }
    for(int i = 0; i < N - 1; i++) {
      int x = sc.nextInt();
      int y = sc.nextInt();
      edge[x].add(y);
      edge[y].add(x);
    }
    String ans = "Alice";
    if(dfs(1, 0) == 0) ans = "Bob";
    System.out.println(ans);
  }

  public static int dfs(int v, int p) {
    ArrayList<Integer> list = edge[v];
    int ret = 0;
    for(int i = 0; i < list.size(); i++) {
      int u = list.get(i);
      if(u != p) {
        ret = (ret ^ (dfs(u, v) + 1));
      }
    }
    return ret;
  }
}

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

/*
,,,,
　　　　　　　　　　　　　　　　　　　　　　　　　　,.斗*''“i:i:{
　　　　　　　　　　　　　,.　｡. . . * : : : ''' : : : :” :”“ ''ｰ - 弋,,_
　　　　　 　 　 ,.斗*''“ : : : : : : : : : : : : : ' ' ' ' ' ' : : : : : : : : : : :”: '':* ｡ ,
　　　 ,.斗*''“ ” ＼：　　 ”・・． ' ' ' '　　　　　　　　 ' ' ' ' : : : : : : : : : : : : ”ミ*｡,,,,,,　　　　　　 　 　 　 ＿
　　く.　 ◎　 ﾞ:.ﾞ:..　ﾟ:,　:　───────────　　　--　　,,,,,,__ ' ' ' :.:.:.:.:.”≧s｡.　　＿,,,｡s*i:i:i:i:<
　　ﾏ*s｡ :,　 }　ﾟ:,　 :}　　　　　　　　　　　　　　　　　　　　　　　　　　　　”　''　-　”””：：”：：`*｡i:i:i:i:i:i:i;:’
　　　` .｡`　 ,　,ノ ／｡ ,,,_　　　　　　　　　　　　　　　　　　　　　　　　　　　　　＿＿`　　} }　　ﾉi:i:i:i:i:ﾂ
　　　　　 `　*　｡　　`*｡i:i:i::*=-　　　　　　　　　　　＿＿　　　　　　,,,....｡s*'i,:’　　　”`*｡＿,*’i:i:i:i:r’
　　　　　　　　　　　”　─ --　　　　｡｡｡｡｡　　 -　－`''''''''ヽ ─ '''”　　　｀ｰ“　　　　　　　`*｡i:i:i:i:i:i:
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*｡i:i:::
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*ﾟ:,
         fozubaoyou    no BUGs alive!
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define debug_interval ','
#define dump_interval endl
#define debug_toggle 0

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cout<<endl;}
template<class...A> inline void debug_rest() {cout<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cout<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cout<<first,debug_rest(rest...);}

int a,b,c[50][2],s[50][2],ans,dis;
int comp=101;

int main(){
  ans=__INT_MAX__;
    ios::sync_with_stdio(false);
    cin>>a>>b;
    for(int i=0;i<a;i++){
      cin>>s[i][0]>>s[i][1];
    }
    for(int i=0;i<b;i++){
      cin>>c[i][0]>>c[i][1];
    }
    for(int i=0;i<a;i++){
      for(int j=0;j<b;j++){
        if(ans>abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1])){
          ans=abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1]);
          dis=j;
        }
      }
      ans=__INT_MAX__;
      dump(dis+1);
    }
}

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  string s;
  cin >> n >> s;
  ll ans=0;
  ll res=0;
  rep(i,n){
    if(s[i]=='I')ans++;
    else ans--;
    res=max(res,ans);

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

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

def dfs(x, order, edges, visited):
  visited[x] = True
  for e in edges[x]:
    if not visited[e]:
      dfs(e, order, edges, visited)
  order.append(x)

def dfs_rev(x, rev_edges, visited):
  visited[x] = True
  ret = 0
  for e in rev_edges[x]:
    if not visited[e]:
      ret += 1
      ret += dfs_rev(e, rev_edges, visited)
  return ret


n = int(input())
alst = list(map(int, input().split()))
edges = [[] for _ in range(n)]
rev_edges = [[] for _ in range(n)]
for i in range(n):
  edges[i].append((i + alst[i]) % n)
  rev_edges[(i + alst[i]) % n].append(i)

order = []
visited = [False] * n
for i in range(n):
  if not visited[i]:
    dfs(i, order, edges, visited)
order.reverse()

visited = [False] * n
cycles = 0
for i in order:
  if not visited[i]:
    a = dfs_rev(i, rev_edges, visited)
    if a > 0 or i in rev_edges[i]:
      a += 1
    cycles += a
print(cycles)


Measured memory_bytes: 142708
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10, mod = 998244353;

ll cnt[N];

int main() {
	fast_cin();
	int n; cin >> n;
	ll ans = 1;
	for (int i = 1; i <= n; ++i) {
		int d; cin >> d;
		++cnt[d];
		if ((d == 0) != (i == 1)) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (int d = 1; d <= n; ++d) {
		if (cnt[d]) {
			for (int j = 0; j < cnt[d]; ++j) {
				ans *= cnt[d - 1];
				ans %= mod;
			}
		}
	}
	cout << ans << '\n';
}

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

int my_ceil(int a, int b){
  return (a + b - 1) / b;
}

int main(){
  int N;
  cin >> N;
  cout << my_ceil(N, 2) << endl;
}


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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


void solve(const vector<long long> &a) {
    long long all = 0;
    for (int i = 0; i < a.size(); ++i) all ^= a[i];
    for (int i = 0; i < a.size(); ++i) cout << (all^a[i]) << " ";
    cout << endl;
}

int main() {
    int N;
    while (cin >> N) {
        vector<long long> a(N);
        for (int i = 0; i < N; ++i) cin >> a[i];
        solve(a);
    }
}

















Measured memory_bytes: 4836
#include <iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  if(0 == (n & (n - 1)))
    cout << "No";
  else {
    cout << "Yes\n";

    cout << n + 1 << " " << 2 << '\n';
    cout << 2 << " " << 3 << '\n';
    cout << 3 << " " << 1 << '\n';
    cout << 1 << " " << n + 2 << '\n';
    cout << n + 2 << " " << n + 3 << '\n';
    for(int i = 4; i + 1 <= n; i += 2){
      cout << i << " " << i + 1 << '\n';
      cout << i + 1 << " " << 1 << '\n';
      cout << 1 << " " << n + i << '\n';
      cout << n + i << " " << n + i + 1 << '\n';
    }
    if(n % 2 == 0){
      int bit = (n ^ (n & (n - 1)));
      cout << n << " " << ((n ^ bit) ^ 1) << '\n';
      cout << n + bit << " " << n + n << '\n';
    }
  }
  return 0;
}


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

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

  int r = 0, k = 10001;;
  for (int i=1; i<n; i++) {
    if (a[i-1] == a[i]) {
      r++;
      a[i] = k++;
    }
  }
  cout << r << endl;

  return 0;
}

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

int n;
int main()
{
    while(cin >> n)
    {
        int m;
        if(!n) break;
        for(int i=0;i<9;i++)
        {
            cin >> m;
            n -= m;
        }
        cout << n << endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
    if(a==0) return b;
    return gcd(b%a,a);
    }

int main(){
int sum=0;
int k;
cin>>k;
for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
        for(int l=1;l<=k;l++){
            sum+=(gcd(gcd(i,j),l));
        }
    }
}
cout<<sum<<endl;
return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll X, N;
  cin >> X >> N;
  vector<ll> p(N);
  set<ll> s;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    s.insert(p[i]);
  }
  ll min_res = INF;
  ll min_num;
  for (int i = -1; i <= 101; i++) {
    if (abs(X - i) < min_res && s.find(i) == s.end()) {
      min_res = abs(X - i);
      min_num = i;
    }
  }
  cout << min_num << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  string S;
  cin >> A >> B >> S;
  int count=0;
  for (int i=0;i<A+B+1;i++){
    if (S[i]=='-'){
      count++;
    }
  }
  if (count==1&&S[A]=='-'){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            decimal iA = decimal.Parse(sS[0]);
            decimal iB = decimal.Parse(sS[1]);
            decimal iC = decimal.Parse(sS[2]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            // √A + √B < √C
            // √を外す為、両辺2乗する
            // A + B + 2√A√B < C
            // A Bを移行
            // 2√A√B < C - A - B
            // さらに2乗
            // 4AB < (C - A - B)^2
            // 2乗したときの不等号の向きはC - A - Bがプラスの時のみ有効
            // そのため C - A - B > 0の条件も必要
            string sOut = "No";
            if ( 4 * iA * iB < (iC - iA - iB) * (iC - iA - iB) && (iC - iA - iB) > 0) { sOut = "Yes"; }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

struct nd{
    vector< int > ady;
}G[100010];

int n,u,v,d[100010][2],a,b,f[100010][2],currentNode,ans,maxD;
bool vis[100010][2];

void dfs( int node , int band , int dist ){
    vis[ node ][ band ] = true;
    d[ node ][ band ] = dist;
    for( auto sig:G[ node ].ady ) if( !vis[ sig ][ band ] ){
        dfs( sig , band , dist+1 );
        f[ sig ][ band ] = node;
    }
    return;
}

void dfs2( int node , int ant , int dist ){
    maxD = max( maxD , dist );
    for( auto sig:G[ node ].ady ) if( sig!=ant ) dfs2( sig , node , dist+1 );
    return;
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> u >> v;
    swap( u , v );
    for(int i=1; i<n; i++) cin >> a >> b , G[ a ].ady.pb( b ) , G[ b ].ady.pb( a );

    dfs( u , 0 , 0 );
    dfs( v , 1 , 0);
    f[ u ][ 0 ] = u;
    f[ v ][ 1 ] = v;

    currentNode = v;
    while( d[ f[ currentNode ][ 0 ] ][ 0 ] > d[ f[ currentNode ][ 0 ] ][ 1 ] ) currentNode = f[ currentNode ][ 0 ] , ans++;

    dfs2( currentNode , f[ currentNode ][ 0 ] , 0 );
    if( f[ currentNode ][ 0 ]!=u ){
        if( !maxD ){
            ans++;
        }else{
            ans+=maxD;
            if( d[ f[ currentNode ][ 0 ] ][ 0 ] == d[ f[ currentNode ][ 0 ] ][ 1 ] ) ans++;
        }
    }else{
        ans+=maxD;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 13952
//package atcoder;
 
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int S[][] = new int [N][M+1]; 
		
		for(int i=0;i<N;i++) {
			for(int j=0;j<M+1;j++) {
				S[i][j] = sc.nextInt();
				//System.out.println(S[i][j]);
			}
		}
		
		long MAX = Long.MAX_VALUE;
		for(int i=0;i<Math.pow(2, N);i++) {
			long skill[] = new long[M+1];
			int cost=0;
			//int s = i;
				for(int j=0;j<N;j++) {
					if(((i>>j)&1) == 1) {
						cost += S[j][0];
						for(int k=0;k<M;k++) {
							skill[k] += S[j][k+1];	
						}
						//System.out.println(cost);
					}
					boolean ok = true;
					for(int l=0;l<M;l++) {
						if(skill[l]<X) {
							ok = false;	
						}
					}
						if(ok) {
							MAX = Math.min(MAX, cost);
						}
					
				}
		}
		if(MAX == Long.MAX_VALUE){
		System.out.println("-1");}
		else {
			System.out.println(MAX);
		}
	}
		
}


Measured memory_bytes: 37756
s = input()
n = len(s)
ans = 0
for bit in range(1 << (n-1)):
    now = s[0]
    for i in range(n-1):
        if (bit >> i) & 1 == 1:
            now += '+'
        now += s[i + 1]
    ans += sum(map(int, now.split('+')))
print(ans)

Measured memory_bytes: 3060
n, k = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
now = sum(p[:k-1])
for i in range(n - k + 1):
    now += p[i + k - 1]
    if now > ans:
        ans = now
    now -= p[i]
ans += k
ans /= 2
print(ans)


Measured memory_bytes: 25060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){

  int n,a,b,i;
  vector <int> amo;
  
  cin>>n;

  for(i=0;i<n;i++){
    cin>>a>>b;
    a+=b;
    amo.push_back(a);    
  }
  int test,from;
  while(1){
    test=0;
    from=0;
    sort(amo.begin(),amo.end());
    for(i=0;amo[i]==-1;i++) from++;
    for(i=from;i<amo.size()-1;i++){
      if(amo[i]==amo[i+1]){
        amo[i]=-1;
        amo[i+1]++;
        test++;
      }
    }
    
    if(test==0) break;
    
  }
  
  for(i=from;i<amo.size();i++) cout<<amo[i]<<" 0"<<endl;

  return 0;

}
  

  

Measured memory_bytes: 3468
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,i,j,A,B;
	cin>>a>>b;
	for(i=1;i<1501;i++)
	{
		A=i*0.08,B=i*0.1;
		if(A==a&&B==b)goto loop;
	}
	cout<<"-1";return 0;
	loop: cout<<i;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	char a[1000],b[1000],c[2000];
	while(scanf("%s%s",a,b)!=EOF){
		int i,j,k,o=0,ans;
		i=strlen(a);
		j=strlen(b);
		if(i>j)  ans=2*j;
		else ans=2*i; 
		for(k=0;k<=ans-1;k+=2){
			c[k]=a[o];
			c[k+1]=b[o];
			printf("%c",c[k]);
			printf("%c",c[k+1]);
			o++;
		}
		if(2*j<2*i) printf("%c",a[i-1]);
		else if(2*j>2*i) printf("%c",b[j-1]);
		printf("\n");
	}
	return 0;
}

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

int main()
{
    int n, a, b, cnt=0, f=0;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>a>>b;
        if(a==b)
            cnt++;
        else
            cnt=0;
        if(cnt>=3)
        f=1;
    }
    if(f)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3592
'''
allの定義
iterable の全ての要素が真ならば (もしくは iterable が空ならば)True を返します。
以下のコードと等価です:
def all(iterable):
    for element in iterable:
        if not element:
            return False
    return True
「イテラブル」は「iterable」で「反復可能な」です。
for文などで反復できるものだと考えてください。
'''

n=int(input())
a=list(map(int,input().split()))
ans=0

while all (i%2==0 for i in a):
  a=[i/2 for i in a]
  ans+=1
  
print(ans)


Measured memory_bytes: 9124
/*
https://suikaba.hatenablog.com/entry/2017/09/28/182203
十分に高速化を考えないとTLE
*/
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int R, C;
    cin>>R>>C;
    vector<string>s(R);
    for(int i=0;i<R;i++)cin>>s[i];
    vector<int>bitcount(1<<C);
    for(int i=0;i<(1<<C);i++)bitcount[i]=__builtin_popcount(i);
    vector<int>dp(1<<C, -1);
    dp[0] = 0;
    for(int i=0;i<R;i++){
        for(int j=0;j<C;j++){
            vector<int>nxt(1<<C, -1);
            for(int S=0;S<(1<<C);S++){
                if(dp[S]==-1)continue;
                int idx = bitcount[S & (1<<j) - 1];
                if(idx < s[i].size()){
                    int t = dp[S];
                    if(idx > 0 && (S & 1 << (j - 1)) && s[i][idx - 1] == s[i][idx]) {
                        t++;
                    }
                    if(i > 0 && (S & 1 << j) && s[i][idx] == s[i - 1][s[i - 1].size() - bitcount[S >> j]]) {
                        t++;
                    }
                    nxt[S | 1 << j] = max(nxt[S | 1 << j], t);
                }
                if(C - j > s[i].size() - idx) {
                    nxt[S & ~(1 << j)] = max(nxt[S & ~(1 << j)], dp[S]);
                }
            }
            dp.swap(nxt);
        }
    }
    int ans = 0;
    for(int i=0;i<dp.size();i++)ans=max(ans, dp[i]);
    cout<<ans*2<<endl;
    return 0;
}



Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n];
    ll b[n];
    for(int i=0;i<n;i++){
    	cin>>a[i];
    	if(i==0){
    		b[i]=a[i];
    	}else{
    		b[i]=b[i-1]+a[i];
    	}
    }
    ll ans=1e18;
    for(int i=0;i<n;i++){
    	ans=min(ans,abs(b[n-1]-2*b[i]));
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>

int main()
{
	int n, a, b, c, i;
	int d1, d2, d3;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d", &a, &b, &c);
		d1 = a*a + b*b - c*c;
		d2 = a*a + c*c - b*b;
		d3 = c*c + b*b - a*a;
		if(d1 * d2 * d3 ==0) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
 
#define AMAX 100001
 
 
struct card{
  char mark;
  int value;
  int cnt;
};
 
card a[AMAX];
int partion(int q, int r){
  int x = a[r].value;
  int i = q-1;
  for(int j = q; j < r; j++){
    if(a[j].value <= x){
      i = i + 1;
      swap(a[i],a[j]);
    }
  }
  swap(a[i+1],a[r]);
  return i+1;
}
 
 
void quicksort(int p, int r){
 
  if(p < r){
    int q;
    q = partion(p,r);
    quicksort(p,q-1);
    quicksort(q+1,r);
  }
}
 
int main(){
 
  int n;
  scanf("%d",&n);
 
  for(int i = 0; i < n; i++){
    scanf(" %c %d",&a[i].mark,&a[i].value);
    a[i].cnt = i;
  }
 
  quicksort(0,n-1);
  int junge = 0;
 
  for(int i = 1; i < n; i++){
    if(a[i-1].value == a[i].value&&a[i-1].cnt>a[i].cnt)junge=1;
  }
  if(junge == 1) printf("Not stable\n");
  else  printf("Stable\n");
 
  for(int i = 0; i < n; i++){
    printf("%c %d\n",a[i].mark,a[i].value);
  }
 
}

Measured memory_bytes: 2364
s = input()
t = input()
n = len(s)
m = len(t)
x = 0
for i in range(n - m + 1):
    c = 0
    for j in range(m):
        if s[i:(i + m)][j] == t[j]:
            c += 1
    if c > x:
        x = c
print(m - x)

Measured memory_bytes: 67884
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main(){
    ios;
    int n; cin >> n;
    string s; cin >> s;
    rep(i,s.size()){
        s[i] = (((s[i] - 'A') + n) % 26) + 'A';
    }
    cout << s;
    return 0;
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (ll i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int W, H, N;
    cin >> W >> H >> N;
    int w_min = 0, w_max = W;
    int h_min = 0, h_max = H;
    rep(i, N){
        int x, y, a;
        cin >> x >> y >> a;
        if(a==1) w_min = max(x, w_min);
        else if(a==2) w_max = min(x, w_max);
        else if(a==3) h_min = max(y, h_min);
        else h_max = min(y, h_max);
    }
    if(h_max-h_min<1||w_max-w_min<1) cout << 0 << endl;
    else{
        int ans = (h_max-h_min)*(w_max-w_min);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3616
$<.gets.to_i.times do |i|
  num = $<.gets.to_i
  rnd = Enumerator.new do |y|
    loop do
      num = (num * num).to_s.rjust(8, "0")[2, 4].to_i
      y << num
    end
  end
  puts "Case #{i + 1}:"
  puts rnd.take(10)
end


Measured memory_bytes: 6876
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	map<char,char> mp;
	string s,t; cin>>s>>t;
	int n=s.size();
	rep(i,0,n)mp[s[i]]=t[i];
	rep(i,0,n){
		if(mp[s[i]]!=t[i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	map<char,char> mp2;
	rep(i,0,n)mp2[t[i]]=s[i];
	rep(i,0,n){
		if(mp2[t[i]]!=s[i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

int main() {
	int a, b, c, d;
	std::cin >> a >> b >> c >> d;

	int x = (c + b - 1) / b;
	int y = (a + d - 1) / d;

	std::cout << (x <= y ? "Yes" : "No") << std::endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define sz size


int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

        int n;
        cin>>n;
        vector <int> v(n);
        for(int i=0;i<n;i++)
        {
                cin>>v[i];
        }
        int r=0;
        for(int i=0;i+2<n;i++)
        {
                int x=v[i];
                int y=v[i+1];
                int z=v[i+2];
                int mi=min(x,min(y,z)),mx=max(x,max(y,z));
                r+=(y==(x+y+z-mi-mx));
        }
        cout<<r<<"\n";

        return 0;
}


Measured memory_bytes: 256
while 1:
    N = int(input())
    if N == 0:break
    cals = [ list(map(int,input().split())) for i in range(N)]
    P,Q,R,C = list(map(int,input().split()))
    res = [ x for x in cals if x[1]<=P and x[2]<=Q and x[3]<=R and 4*x[1] + 9*x[2] + 4*x[3] <= C]
    if len(res) == 0:print('NA')
    else:
        for i in res:
            print(i[0])

Measured memory_bytes: 6980
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main()
{
	int N, T;
	cin >> N >> T;
	vector<pair<int, int>> pairs(N);
	
	for (int i = 0; i < N; i++)
	{
		int c, t;
		cin >> c >> t;
		pairs[i] = make_pair(c, t);
	}
	
	int answer = 1001;
	for (int i = 0; i < N; i++)
	{
		if (pairs[i].second <= T)
		{
			answer = min(pairs[i].first, answer);
		}
	}
	
	if (answer <= 1000)
	{
		cout << answer << endl;
	}
	else {
		cout << "TLE" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(!(a%3)||!(b%3)||!((a+b)%3)){
        cout<<"Possible"<<endl;
    }
    else {
        cout<<"Impossible"<<endl;
    }
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> num(100001);
  while(N--){
    int a;
    cin >> a;
    num.at(a)++;
  }
  int X = 0;
  for(int i=2; i<=100000; i++){
    X = max(X, num.at(i)+ num.at(i-1)+num.at(i-2));
  }

  cout << X << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int T, P, R;
    cin >> T >> P >> R;
    if (T == 0 && P == 0 && R == 0){
      break;
    }
    vector<vector<int>> s(T, vector<int>(P, 0));
    for (int i = 0; i < R; i++){
      int t, p, time;
      string message;
      cin >> t >> p >> time >> message;
      t--;
      p--;
      if (message == "CORRECT"){
        s[t][p] = time - s[t][p];
      }
      if (message == "WRONG"){
        s[t][p] -= 1200;
      }
    }
    vector<tuple<int, int, int>> ans(T);
    for (int i = 0; i < T; i++){
      int ac = 0;
      int time = 0;
      for (int j = 0; j < P; j++){
        if (s[i][j] > 0){
          ac++;
          time += s[i][j];
        }
      }
      ans[i] = make_tuple(ac, - time, - i);
    }
    sort(ans.rbegin(), ans.rend());
    for (int i = 0; i < T; i++){
      cout << - get<2>(ans[i]) + 1 << ' ' << get<0>(ans[i]) << ' ' << - get<1>(ans[i]) << endl;
    }
  }
}


Measured memory_bytes: 3224
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int f(const void *a, const void *b) {
    return *(char*)a - *(char*)b;
}

int sort_dict(const void *a, const void *b) {
 //   printf("%s, %s\n", a, b);
    return strcmp((char*)a, (char*) b);
}

// if a and b is sorted.
// these are same strings.
int is_anagram(char *a, char *b) {
    return !strcmp(a, b);
}

int main() {
    int N;
    scanf("%d", &N);
    char (*s)[11] = malloc(N * sizeof(char[11]));
    for (int i = 0; i < N; i++) {
        //s[i] = malloc(11 * sizeof(char));
        scanf("%s", s[i]);
        qsort(s[i], 10, sizeof(char), f);
    }

    qsort(s, N, sizeof(char[11]), sort_dict);
    //for(int i = 0; i < N; i++){
    //    printf("%s\n", s[i]);
    //}

    long ans = 0;
    long same_length = 1;
    char *current = s[0];

    for (int i = 1; i < N; i++) {
        if (!strcmp(s[i], s[i-1])) {
            same_length++;
        } else {
            if (same_length >= 2)
                ans += (same_length * (same_length - 1)) / 2;
            same_length = 1;
        }
        current = s[i];
    }
    if (same_length >= 2)
        ans += (same_length * (same_length - 1)) / 2;

    printf("%ld\n", ans);

    return 0;
}


Measured memory_bytes: 2300
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL x;
    LL a;
    LL b;
    LL ans;
    cin >> x >> a >> b;
    ans=(x-a)%b;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
const int Max_N=1e3;
int N,Num,clck=0,fa[Max_N+10]={},X[Max_N+10]={},sum[Max_N+10]={},f[2][5*Max_N+10]={},lin[Max_N+10]={};
struct kk{
	int Id,Next;
} e[Max_N*2+10]={};
inline void insert(int x,int y){
	e[++Num].Next=lin[x]; lin[x]=Num; e[Num].Id=y;
}
inline bool chck(int x){
	for(int i=lin[x];i;i=e[i].Next){
		if(!chck(e[i].Id)) return false;
		sum[x]+=sum[e[i].Id];
	}
	memset(f,0,sizeof(f)); f[0][0]=1;
	int g=1;
	for(int i=lin[x];i;i=e[i].Next,g^=1){
	 memset(f[g],0,sizeof(f[g])); 
	 for(int j=X[x];j>=0;j--){
	    if(j+X[e[i].Id]<=X[x]) f[g][j+X[e[i].Id]]|=f[g^1][j];
	 	if(j+(sum[e[i].Id]-X[e[i].Id])<=X[x]) f[g][j+(sum[e[i].Id]-X[e[i].Id])]|=f[g^1][j]; 
	 }
	} 
	for(int i=X[x];i>=0;i--){
		if(f[g^1][i]){
			sum[x]+=X[x]-i;
			return true;
		}
	}
	return false;
}
int main(){
	scanf("%d",&N);
	for(int i=2;i<=N;i++) {
		scanf("%d",&fa[i]);
		insert(fa[i],i); 
	}
	for(int i=1;i<=N;i++) scanf("%d",&X[i]);
	if(chck(1)) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
int main(){
    string s;cin>>s;
    if(s.size()==1)cout<<1<<endl;
    else{
    ll count=1;
    bool f=0;
    REP(i,1,s.size()){
        if(i==s.size()-1){
            if(f==1)count++;
            else{
                if(s[i]!=s[i-1])count++;
                else break;
            }
        }
        else{
        if(f==1){
            count++;
            f=0;
        }
        else if(f==0){
            if(s[i]==s[i-1]){
                f=1;
                i++;
                count++;
            }
            else count++;
        }
        }
    }
    cout<<count<<endl;
    }
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a); (i)<=(b); (i)++)
#define REP(i,N) FOR((i), 0, (N)-1)

int gcd(int a, int b){
    if(a>b) swap(a,b);
    return a==0 ? b : gcd(b%a,a);
}

int main(){
    int A,B,K;
    cin >> A >> B >> K;
    int cnt=0,ans;
    FOR(i,1,max(A,B)){
        if(A%i==0 && B%i==0){
            cnt++;
        }
        if(cnt == K){
            ans = gcd(A,B) / i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    if(s.at(2) == s.at(3) && s.at(4) == s.at(5)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
from bisect import bisect
from numpy import cumsum
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=cumsum(a)
b=cumsum(b)

read=bisect(a,k)
time=a[read-1]
ans=read

for i in range(read):
    extra=k-time
    r=bisect(b,extra)
    ans=max(ans,read+r)
    read-=1
    time=a[read-1]
read=bisect(b,k)
ans=max(ans,read)
print(ans)

Measured memory_bytes: 58452
n=int(input())
x=list(map(int,input().split()))

cnt=0

for i in range(1,n-1):
	j=i-1
	if (x[j]>x[j+1] and x[j+1]>x[j+2]) or (x[j]<x[j+1] and x[j+1]<x[j+2]):
		cnt+=1

print(cnt)

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

using namespace std;

vector<int> temp;

void Device(int num);
void Output();

int main() {

	int num;

	while (cin >> num && num != -1) {

		if (num == 0)
			cout << "0\n";

		else {
			Device(num);
			Output();

		}
	}
	
	return 0;

}

void Device(int num) {

	temp.clear();
	while (num) {

		temp.push_back(num % 4);
		num /= 4;

	}

}

void Output() {
	for (int i = temp.size() - 1; i >= 0; i--)
		cout << temp[i];
	cout << "\n";
}





Measured memory_bytes: 3052
from sys import stdin

inf = 10**10

h,w = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(10)]

lin = [list(map(int,stdin.readline().rstrip().split())) for _ in range(h)]

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    #k：中継
    for k in range(10):
        for i in range(10):
            for j in range(10):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

li = warshall_floyd(li)
liv = []
for i in range(10):
    liv.append(li[i][1])

point = 0
for i in range(h):
    for j in range(w):
        if lin[i][j] == -1:
            continue
        point += liv[lin[i][j]]

print(point)

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

int main(){
    int s,k; cin >> k >> s;
    int cnt=0;
    for(int ix=0;ix<=k;ix++){
        for(int ix2=0;ix2<=k;ix2++){
            if(s-ix-ix2<=k && 0<=s-ix-ix2) cnt++;
        }
    }
    cout << cnt << endl;
        
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n, x;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  cin >> ans;
  fi(0, n - 1) {
    cin >> x;
    ans = lcm(ans, x);
  }
  cout << ans << endl;
  return 0;
}



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

using namespace std;
#define int long long int
signed main(){
    
    int n,W;
    cin>>n>>W;
    
    int w[n+5],v[n+5];
    
    for(int i=1;i<=n;i++)
        cin>>w[i]>>v[i];
    
    int dp[n+1][W+1];
    
    for(int i=0;i<=n;i++)
        dp[i][0]=0;
        
    for(int j=0;j<=W;j++)
        dp[0][j]=0;
        
    for(int i=1;i<=n;i++){
        for(int j=1;j<=W;j++){
            if(j<w[i])
                dp[i][j] = dp[i-1][j];
                
            else
            {
                dp[i][j] = max(dp[i-1][j],v[i]+ dp[i-1][j-w[i]]);
            }
            
            
        }
        
    }
    
    
    
    cout<<dp[n][W];
    
    return 0;
    
}

Measured memory_bytes: 79104
#include<iostream>
using namespace std;
int main()
{
	int H, W, i, k;
	while(1)	
	{
		cin >> H >> W;
		if ( H == 0 && W == 0 )break;
		else
		{
			for ( i = 0; i < H; i++)
				{
					if ( i == 0 || i == H - 1 )
						{
							for ( k = 0; k < W; k++)
							{
								cout << "#";
							}
							cout << endl;
						}
					else 	{
							cout << "#";
								for ( k = 2; k < W; k++)
									{
										cout << ".";
									}
							cout << "#" << endl;
						}
				}
		}
	cout << endl;
	}
	return 0; 
}

Measured memory_bytes: 1152
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		ArrayList<Integer> list = new ArrayList<>();
		for(int i = 0; i< N; i++) {
			list.add(Integer.parseInt(sc.next()));
		}
		sc.close();

		int distance = 0;
		for(int i = 0; i< N; i++) {
			int x = list.get(i);
			if(2 * x < K) {
				distance += 2 * x;
			}else {
				distance += 2 * (K - x);
			}
		}
		System.out.println(distance);

	}
}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();
			int x=0;
			if(op.equals("?"))break;
			
			if(op.equals("+")){
				x=a+b;
				
			}
			else if(op.equals("-")){
				x=a-b;
				
			}
			else if(op.equals("*")){
				x=a*b;
				
			}
			else if(op.equals("/")){
				x=a/b;
				
			}
			System.out.println(x);

		}
		

	}
}


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

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

  if (a == "H") {
    if (b == "H") {
      cout << "H" << endl;
    } else {
      cout << "D" << endl;
    }
  } else {
    if (b == "H") {
      cout << "D" << endl;
    } else {
      cout << "H" << endl;
    }
  }
}

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

int main() {
  int n;
    cin >> n;
  int a,b,c,d;
  a = n / 1000;
  b = (n - 1000*a) / 100;
  c = (n - 1000*a - 100 *b) / 10;
  d = n - 1000*a - 100*b - 10*c;
  
  if(a == b && b== c){
    cout << "Yes" << endl;
    }else if(b == c && c == d){
    cout << "Yes" << endl;
  }else{
  cout << "No" << endl;
  }
}


Measured memory_bytes: 256