akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int a[200000];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

    int tot = 0;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        tot ^= a[i];
    }

    for (int i=0; i<n; i++)
        cout << (tot ^ a[i]) << " \n"[i==n-1];

    return 0;
}


Measured memory_bytes: 4368
from math import floor

while True:
    n,m,p = map(int, input().split())
    if n == 0 :  break
    x = []
    for i in range(n):
        x.append(int(input()))
    pool = sum(x) * (100 - p)
    div = floor(pool / x[m - 1]) if x[m - 1] != 0 else 0
    print(div)

Measured memory_bytes: 6812
#include<stdio.h>
#include<string.h>

int main(void){
  char a[105];
  int len;
  int c = 0;
  
  scanf("%s",a);
  
  len = strlen(a);
  for(int i=1;i<=(len/2);i++){
    if(a[i-1] != a[len-i])
      c++;
  }
  
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 128
while True:
  x,y,s = map(int, raw_input().split())
  if x==y==s==0: break
  summax = 0
  for a in xrange(1, s):
    b = s-a
    basea = a*100/(100+x)
    if a*100%(100+x) != 0: basea += 1
    baseb = b*100/(100+x)
    if b*100%(100+x) != 0: baseb += 1
    if basea*(100+x)/100 != a or baseb*(100+x)/100 != b: continue
    summax = max(summax, basea*(100+y)/100+baseb*(100+y)/100)
  print summax

Measured memory_bytes: 6380
k, x = map(int, input().split())

# X - K-1 個　～　X + (k-1)
width = k - 1

left = x - width
right = x + width

if left < -1000000:
  left = -1000000
if right > 1000000:
  right = 1000000

print(' '.join([str(i) for i in range(left, right+1)]))

Measured memory_bytes: 3060
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please



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


	ll N;
	cin >> N;

	N *= 2;
	ll kotae = N - 1;
	for (ll i = 2; i * i <= N; i++) {
		if (N % i == 0) {
			ll j = N / i;
			
			vector<ll> r, m;
			r.pb(1);
			r.pb(0);
			m.pb(i);
			m.pb(j);
			auto c = crt(r, m);
			if (c.second) chmin(kotae, (c.first - 1 + c.second) % c.second);
			swap(m[0], m[1]);
			c = crt(r, m);
			if (c.second) chmin(kotae, (c.first - 1 + c.second) % c.second);
		}
	}
	co(kotae);

	Would you please return 0;
}

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

int main() {
    string s;
    cin >> s;
    string t = "", u = "";
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        t += s[i];
        if (t == u) continue;
        else {
            u = t;
            t = "";
            ans++;
        }
    }

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

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<complex>
#include<unordered_map>

#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-8

#define REP(i, m) for(long long i = 0; i < m; ++i)
#define FOR(i, n, m) for(long long i = n; i < m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
    
int main(){
	string s,t;
    cin>>s>>t;
    vector<vector<int>> ans(SZ(s)+1,vector<int>(SZ(t)+1));
    REP(i,SZ(s)){
        REP(j,SZ(t)){
            if(s[i]==t[j]){
                ans[i+1][j+1]=ans[i][j]+1;
            }else{
                
                    ans[i+1][j+1]=max(ans[i][j+1],ans[i+1][j]);
                
            }
        }
    }
    int x=SZ(s);
    int y=SZ(t);
    string sans;
    while(x>0&&y>0){
        if(ans[x][y]==ans[x][y-1]) y--;
        else if(ans[x][y]==ans[x-1][y]) x--;
        else{
            sans=s[x-1]+sans;
            x--;
            y--;
        }
    }
    OUT(sans);
	return 0;
}

Measured memory_bytes: 35584
let rec div n i lst =
  if i = 1 then (List.length lst) + 1
  else if n mod i = 0 then div n (i-1) (i :: lst)
  else div n (i-1) lst
let rec f n ans =
  if n = 1 then ans
  else if (div n n []) = 8 then f (n-2) (ans+1)
  else f (n-2) ans
let () =
  Scanf.scanf "%d\n"
    (fun n -> if n mod 2 = 0 then f (n-1) 0 else f n 0) 
  |> print_int

Measured memory_bytes: 384
#include<iostream>
#include<functional>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef unsigned long long ll;
typedef pair<int,int>P;
using namespace std;
const ll mod=1e9+7;

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ec=0;
    int wc=0;
    rep(i,n)
    {
        if(s[i]=='E')ec++;
    }
    int ans=ec;
    rep(i,n)
    {
        if(s[i]=='E')
        {
            ec--;
            ans=min(ans,ec+wc);
            
        }
        else
        {
            wc++;
        }
        
    }
    cout<<ans;
    
    
}

Measured memory_bytes: 900
n = int(input()) 
def yakusu(num):
    list_a = []
    for i in range(1, num//2 + 1):
        if num % i == 0:
            list_a.append(i)
    list_a.append(num)
    return list_a
  
ans = 0
for i in range(1, n + 1):
    if len(yakusu(i)) == 8 and i % 2 ==1:
        ans += 1
        
print(ans)

Measured memory_bytes: 3060
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  string S;
  cin >> S;
  string T;
  cin >> T;
  int ans = 0;
  rep(i, len(S)) {
    ans += S[i] != T[i];
  }
  cout << ans << endl;
}

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

#define y1 hasjdnasd
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define pb push_back
#define fr front()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)
#define REP(i , x) for(int i = 0 ; i < x ; ++i)

#define ll long long
#define oo 1e18 + 7
#define int long long

const int N = 1e5 + 5;
int n , mod;
int dp[N] , ans[N] , psum[N] , ssum[N];
vector < int > g[N] , pre[N] , suf[N];

int mul(int a , int b)
{
    return (a * b) % mod;
}

int add(int a , int b)
{
    return (a + b) % mod;
}

void DFS1(int i , int j)
{
    dp[i] = 1;
    REP(s , g[i].size())
    {
        int u = g[i][s];
        if(u != j)
        {
            DFS1(u , i);
            dp[i] = mul(dp[i] , dp[u] + 1);
        }
    }
}

void DFS2(int i , int j , int val)
{
    int sz = 0;
    ans[i] = mul(dp[i] , val);
    psum[0] = 1;
    REP(s , g[i].size())
    {
        int u = g[i][s];
        if(u != j)
        {
            sz++;
            psum[sz] = mul(psum[sz - 1] , dp[u] + 1);
        }
    }
    int k = g[i].size();
    ssum[sz + 1] = 1;
    int r = 0;
    FORD(s , k - 1 , 0)
    {
        int u = g[i][s];
        if(u != j)
        {
            ssum[sz - r] = mul(ssum[sz - r + 1] , dp[u] + 1);
            r++;
        }
    }
    FOR(j , 0 , sz + 1)
    {
        pre[i].pb(psum[j]);
        suf[i].pb(ssum[j]);
    }
    r = 0;
    REP(s , g[i].size())
    {
        int u = g[i][s];
        if(u != j)
        {
            r++;
            DFS2(u , i , mul(val , mul(pre[i][r - 1] , suf[i][r + 1])) + 1);
        }
    }
}

main()
{
    //freopen("V.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> mod;
    FOR(i , 1 , n - 1)
    {
        int u , v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    DFS1(1 , -1);
    DFS2(1 , -1 , 1);
    FOR(i , 1 , n)
        cout << ans[i] << "\n";
}


Measured memory_bytes: 31104
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      _t: usize,
      a: [usize; n]
   }

   let mut score = vec![];
   let mut mn = (a[0], 1);
   let mut mx = (a[0], 1);
   for i in 1..n {
      if a[i] == mn.0 {
         mn.1 += 1;
      } else if a[i] < mn.0 {
         score.push((mx.0 - mn.0, min(mx.1, mn.1)));
         mx.0 = a[i];
         mx.1 = 1;
         mn.0 = a[i];
         mn.1 = 1;
      } else if a[i] == mx.0 {
         mx.1 += 1;
      } else if a[i] > mx.0 {
         mx.0 = a[i];
         mx.1 = 1;
      }
   }
   score.push((mx.0 - mn.0, min(mx.1, mn.1)));
   score.sort_by(|a, b| b.cmp(a));
   let mx_score = score[0].0;
   let mut ans = 0;
   for &(s, v) in score.iter() {
      if s != mx_score {
         break;
      }
      ans += v;
   }
   println!("{}", ans);
}


Measured memory_bytes: 4704
import copy
import heapq
import math
n,m=map(int,input().split())
a=[0]*n
atmp=list(map(int,input().split()))
for i in range(n):
  a[i]=-atmp[i]

heapq.heapify(a)
for i in range(m):
  tmp=heapq.heappop(a)
  heapq.heappush(a,tmp/2)

total=0  
for i in range(n):
  total+=math.ceil(a[i])
print (-total)



Measured memory_bytes: 15588
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  map<int,int> M;
  rep(i,0,N){
    int X; cin>>X;
    M[X]++;
  }
  int Q; cin>>Q;
  string ans="YES";
  rep(i,0,Q){
    int X; cin>>X;
    if(M[X]==0){
      ans="NO";
      break;
    }
    M[X]--;
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 12800
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;


int main(){
   int a, b, c, k;
   cin >> a >> b >> c >> k;
   while(k--){
      if(c > b && b > a)break;
      if(a >= b)b *= 2;
      else if(b >= c)c *= 2;
     //cout << a << " " << b << " " << c << endl;
   }
   cout << (c > b && b > a ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3616
#include <stdio.h>
 
 int main(void){
 int a[3][10][4] = {0};
 int i, j, k;
 int n, p;
 int b, f, r, v; 
 
 
scanf("%d", &n);
  
 
 
for(i=0; i<n; i++)
{
     scanf("%d %d %d %d", &b, &f, &r, &v);
 
    a[f-1][r-1][b-1] += v;
  
}
 
 for(k=0; k<4; k++)
{
  
    for(i=0; i<3; i++)
    {
        for(j=0; j<10; j++)
        {
            if(a[i][j][k] == 0)
            {
                printf(" 0");
            }
            else   
            {
                printf(" %d", a[i][j][k]);
            }
        }
  
        printf("\n");
    }
  
    if(k != 3)
    {
        printf("####################\n");
    }
 }
 
    return 0;
  
}

Measured memory_bytes: 612
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }

bool solve() {
    long long a, b, c, d; cin >> a >> b >> c >> d;
    if (a < b) return false;
    if (d < b) return false;
    long long g = gcd(b, d);
    long long rem = a % g;
    long long ma = (b - rem + g - 1) / g * g + rem - g;
    return ma <= c;
}

int main() {
    int T; cin >> T;
    while (T--) {
        cout << (solve() ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		String s = scanner.next();
		int max = 0;

		for (int i = 1; i < s.length(); i++) {
			String x = s.substring(0, i);
			String y = s.substring(i, s.length());
			Set<Character> setX = new HashSet<>();
			Set<Character> setY = new HashSet<>();
			for (int xi = 0; xi < x.length(); xi++) {
				setX.add(x.charAt(xi));
			}
			for (int yi = 0; yi < y.length(); yi++) {
				setY.add(y.charAt(yi));
			}
			int tmp = 0;
			for (char c : setX) {
				if (setY.contains(c))
					tmp++;
			}
			max = Math.max(tmp, max);
		}

		System.out.println(max);
	}
}


Measured memory_bytes: 24148
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
	int k;
	cin >> k;
	cout << (k + 1) / 2 * (k / 2) << endl;
	return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long

const int N=1005;
const int MOD=1e9+7;
 
 
int32_t main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string a,b;
  cin>>a>>b;
  int c,d;
  cin>>c>>d;
  string s;
  cin>>s;
  if(s==a)
  {
  	cout<<c-1<<" "<<d;
  }
  else
  {
  	cout<<c<<" "<<d-1;
  }
  
}




Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		double L = 0;
		Scanner sc = new Scanner(System.in);
		L = sc.nextInt();
		double X = (L / 3) * (L / 3) * (L / 3);
		String max = BigDecimal.valueOf(X).toPlainString();
		System.out.println(max);
		sc.close();
	}
}

Measured memory_bytes: 22228
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int A, B;

	cin >> A >> B;

	if (A < 10 && B < 10) {
		cout << A*B << endl;
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define inf 0x3fffffffffffffff
using namespace std;

int n,m,p[100010],v[100010];
vector<int> e[100010];
set<int> id,pe;

void dfs(int x)
{
    v[x]=1;
    id.insert(x);
    pe.insert(p[x]);
    for (auto y:e[x])
        if (!v[y]) dfs(y);
}

int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
        scanf("%d",&p[i]);
    int x,y;
    for (int i=1;i<=m;i++)
        scanf("%d%d",&x,&y),
        e[x].push_back(y),
        e[y].push_back(x);
    memset(v,0,sizeof(v));
    int ans=0;
    for (int i=1;i<=n;i++)
        if (!v[i])
        {
            id.clear();pe.clear();
            dfs(i);
            for (auto x:id)
                if (pe.find(x)!=pe.end()) ans++;
        }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 18944
f=lambda:map(int,input().split())
n,m=f()
S=[[0]*n for _ in range(m)]
for i in range(m):
  _,*s=f()
  for j in s: S[i][j-1]=1
p=[*f()]
a=0
for i in range(2**n):
  if all(sum(S[k][j] for j in range(n) if i>>j&1)%2==p[k] for k in range(m)): a+=1
print(a)

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

// int s[100000], t[100000], c[100000];
// typedef struct {
//   int start, end, ch;
//   bool rec;
// } bg;
// bool cmp(bg x, bg y) {
//   return x.end < y.end;
// }

bool x[30][100001];

int main() {
  int N, C, T = 0;
  cin >> N >> C;
  for (int i = 0; i < N; i++) {
    int s, t, c;
    cin >> s >> t >> c;
    c--;
    for (int j = s; j <= t; j++) x[c][j] = true;
    T = max(T, t);
  }
  int result = 0;
  for (int t = 0; t <= T; t++) {
    int c = 0;
    for (int j = 0; j < C; j++) c += x[j][t];
    result = max(result, c);
  }
  cout << result << endl;
  //   vector<bg> r;
  //   // r.resize(N);
  //   for (int i = 0; i < N; i++) {
  //     // cin >> s[i] >> t[i] >> c[i];
  //     int s, t, c;
  //     cin >> s >> t >> c;
  //     bg p;
  //     p.start = s;
  //     p.end = t;
  //     p.ch = c;
  //     p.rec = false;
  //     r.push_back(p);
  //   }
  //   sort(r.begin(), r.end(), cmp);
  //   int rlen = r.size();
  //   int result = 0;
  //   while (true) {
  //     int t = ~0x7fffffff;
  //     int reccount = 0;
  //     int cc = -1;
  //     for (int i = 0; i < rlen; i++) {
  //       if (r[i].rec) continue;
  //       if (r[i].start > t - (cc == r[i].ch)) {
  //         r[i].rec = true;
  //         t = r[i].end;
  //         cc = r[i].ch;
  //         // cout << result << ":" << reccount << " " << t << " " <<
  //         r[i].start
  //         //      << "-" << r[i].end << "(" << r[i].ch << ")\n";
  //         reccount++;
  //       }
  //     }
  //     if (reccount) {
  //       result++;
  //     } else {
  //       break;
  //     }
  //   }
  //   cout << result << endl;
}


Measured memory_bytes: 3200
s = input()

a = int(s[0]+s[1])
b = int(s[2]+s[3])

if (a==0 or 12<a<100) and (b==0 or 12<b<100):
    print('NA')

elif (a==0 or 12<a<100) and 1<=b<=12:
    print('YYMM')

elif 1<=a<=12 and (b==0 or 12<b<100):
    print('MMYY')

else:
    print('AMBIGUOUS')

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  int N,K; cin >> N >> K;
  string s; cin >> s;
  
  char temp=s[0];
  int num_switch=0, left=0, sep=0;
  for(int i=0; i<N; i++){
    if(s[i]!=temp){
      sep++;
      temp = s[i];
      if(sep%2==0){
        for(int j=left; j<i; j++) s[j] = s[left-1];
        num_switch++; 
      }
      left=i;
      if(num_switch==K) break;
    }
  }
  if(s[N-1]!=s[left-1] && num_switch<K){
    sep++;
    if(sep%2==0) for(int j=left; j<N; j++) s[j] = s[left-1];
  }
  
  temp=s[0];
  int happiness=0;
  for(int i=0; i<N; i++){
    if(s[i]=='L' && i>0){
      if(s[i-1]=='L') happiness++;
    }else if(s[i]=='R' && i<N-1){
      if(s[i+1]=='R') happiness++;
    }
  }
  
  cout << happiness << "\n";
}

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

#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++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, long long K){
    if(N == 2 && K == 0) {
        cout << 1 << endl;
        cout << 1 << " " << 2 << endl;
        return;
    }

    LL max_k = (N - 1) * (N - 2) / 2;
    if(max_k < K) {
        cout << -1 << endl;
        return;
    }

    vector<PII> ans;
    REP(i, N-1) {
        ans.PB({1, i+2});
    }

    LL l = 2, r = 3;
    REP(i, max_k - K) {
        ans.PB({l, r});
        if(r == N) {
            l++;
            r = l + 1;
        } else {
            r++;
        }
    }

    cout << ans.size() << endl;
    REP(i, ans.size()) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


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

int main() {
    double a, b, x;
    cin >> a >> b >> x;
    double y = x / a;
    double rad;
    if (x >= a*a*b/2) {
        double c = (a*b-y)*2/a;
        rad = atan2(c, a);
    } else {
        double c = 2*y/b;
        rad = atan2(b, c);
    }
    double ans = rad/M_PI*180;
    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

//#define _USE_MATH_DEFINES
//#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;


const i64 MAXN = 300004;

i64 n, h;
i64 a[MAXN];

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);
    i64 n, k;
    cin >> n >> k;
    for (i64 i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a, a + n, greater<i64>());

    i64 s = 0;
    for (i64 i = k; i < n; i++) {
        s += a[i];
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 1792
while True:
    a=int(input())
    if a==0:
        break
    x=0
    b=1000-a
    if b-500>=0:
        x=x+1
    else:
        pass
    c=b%500
    x=x+(c-c%100)//100
    d=c%100
    if d-50>=0:
        x=x+1
    else:
        pass
    e=d%50
    x=x+(e-e%10)//10
    f=e%10
    if f-5>=0:
        x=x+1
    else:
        pass
    g=f%5
    x=x+g
    print(x)


Measured memory_bytes: 5588
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	cin>>n>>m;
	vi co(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		if(a==1)co[b-1]++;
		if(b==n)co[a-1]++;
	}
	bool h=false;
	rep(i,n)if(co[i]==2)h=true;
	if(h)cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
}








Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
#include<math.h>
#include<sstream>
typedef long long ll;
#define N (1000000000+7)
using namespace std;
typedef pair<int, int> P;

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


int main(void) {
	int c[3][3];
	for (int i = 0;i < 3;i++) {
		for (int j = 0;j < 3;j++) {
			cin >> c[i][j];
		}
	}
	int a[3] = { 0 }, b[3] = { 0 };
	for (int i = 0;i <= 100;i++) {
		a[0] = i;
		for (int i = 0;i < 3;i++)b[i] = c[0][i] - a[0];
		for (int i = 1;i < 3;i++)a[i] = c[i][0] - b[0];
		if (a[1] + b[1] == c[1][1]) {
			if (a[2] + b[1] == c[2][1]) {
				if (a[1] + b[2] == c[1][2]) {
					if (a[2] + b[2] == c[2][2]) {
						cout << "Yes" << endl;
						return 0;
					}
				}
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
H, K = map(int, input().split())
lst_0=list(map(int,input().split()))
DP=[float("INF")]*H
DP[0]=0
for i in range(1,H):
    for j in range(1,K+1):
        if i - j >= 0:
            DP[i]=min(DP[i],abs(lst_0[i]-lst_0[i-j])+DP[i-j])
print(DP[H-1])

Measured memory_bytes: 55388
import scala.io.StdIn._
object Main extends App {
  val n = readInt
  val num = Array.tabulate(n){_ ⇒ readInt}.sorted(Ordering.Int.reverse)
  println(solve(num))
  def solve(num: Array[Int]): Long = {
    val mod: Long = 998244353L
    val sum = num.sum
    val overHalfMemo = Array.tabulate(num.length){_ ⇒ Array.tabulate((sum + 1) / 2){_ ⇒ -1L}}
    val justHalfMemo = Array.tabulate(num.length){_ ⇒ Array.tabulate((sum + 1) / 2){_ ⇒ -1L}}
    val power3: Array[Long] = Array.tabulate(num.length + 1){_ ⇒ 1L}
    for (i ← 1 until power3.length) power3(i) = (power3(i - 1) * 3) % mod
    def overHalf(position: Int, currentSum: Int): Long = {
      if (currentSum * 2 >= sum) return power3(num.length - position)
      if (position >= num.length) return 0
      if (overHalfMemo(position)(currentSum) < 0) overHalfMemo(position)(currentSum) = (overHalf(position + 1, currentSum + num(position)) + 2 * overHalf(position + 1, currentSum)) % mod
      overHalfMemo(position)(currentSum)
    }
    def justHalf(position: Int, currentSum: Int): Long = {
      if (currentSum * 2 > sum) return 0
      if (currentSum * 2 == sum) return 1
      if (position >= num.length) return 0
      if (justHalfMemo(position)(currentSum) < 0) justHalfMemo(position)(currentSum) = (justHalf(position + 1, currentSum + num(position)) + justHalf(position + 1, currentSum)) % mod
      justHalfMemo(position)(currentSum)
    }

    val over = overHalf(0, 0)
    val just = justHalf(0, 0)
    ((power3.last - (over - just) * 3) % mod + mod) % mod
  }
}

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

template<typename T>
struct BellmanFord {
	struct Edge {
		const int from;
		const int to;
		const T cost;
		Edge(const int from, const int to, const T cost) :
			from(from),
			to(to),
			cost(cost)
			{}
	};
	const int V;
	vector<vector<Edge>> G;
	int start;
	const T INF = numeric_limits<T>::max();
	vector<T> dist;
	bool hasNegativeCycle = false;
	vector<bool> negative;
	vector<int> rec;
	BellmanFord(const int V) :
		V(V),
		G(vector<vector<Edge>>(V, vector<Edge>())),
		negative(vector<bool>(V))
		{}
	void addEdge(const int from, const int to, const T cost) {
		G[from].emplace_back(from, to, cost);
	}
	bool negativeCycle() {
		return hasNegativeCycle;
	}
	void build(const int start) {
		(*this).start = start;
		dist = vector<T>(V, INF);
		rec = vector<int>(V, -1);
		dist[start] = 0;
		for(int i = 0; i < V; ++i) {
			bool update = false;
			for(int from = 0; from < V; ++from) {
				if(dist[from] == INF) continue;
				for(Edge e : G[from]) {
					if(dist[e.from] + e.cost < dist[e.to]) {
						dist[e.to] = dist[e.from] + e.cost;
						rec[e.to] = e.from;
						update = true;
					}
				}
			}
			if(not update) break;
			if(i == V - 1) hasNegativeCycle = true;
		}
		for(int i = 0; i < V; ++i) {
			bool update = false;
			for(int from = 0; from < V; ++from) {
				if(dist[from] == INF) continue;
				for(Edge e : G[from]) {
					if(dist[e.from] + e.cost < dist[e.to]) {
						dist[e.to] = dist[e.from] + e.cost;
						negative[e.to] = true;
						update = true;
					}
					if(negative[e.from]) {
						negative[e.to] = true;
					}
				}
			}
			if(not update) break;
		}
	}
	T distance(const int to) {
		if(negative[to]) throw "INVALID";
		if(dist[to] == INF) throw "INVALID";
		return dist[to];
	}
	vector<int> route(int to) {
		distance(to);
		vector<int> ret;
		while(to != start) {
			ret.push_back(to);
			to = rec[to];
		}
		ret.push_back(start);
		reverse(ret.begin(), ret.end());
		return ret;
	}
};

int main() {
	int V, E, r; cin >> V >> E >> r;
	BellmanFord<int> bf(V);
	while(E--) {
		int s, t, d; cin >> s >> t >> d;
		bf.addEdge(s, t, d);
	}
	bf.build(r);
	if(bf.negativeCycle()) {
		cout << "NEGATIVE CYCLE" << '\n';
		return 0;
	}
	for(int to = 0; to < V; ++to) {
		try {
			cout << bf.distance(to) << '\n';
		}
		catch(...) {
			cout << "INF" << '\n';
			continue;
		}
	}
	return 0;
}


Measured memory_bytes: 3176
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    if N%2 == 0:
        print(N,N,N//2)
    else:
        x,y,z = 0,0,0
        for h in range(1,3501):
            for k in range(h,3501):
                if ((4*h*k-N*(h+k))>0 and (N*h*k)%(4*h*k-N*(h+k)) == 0):
                    x = h
                    y = k
                    z = (N*h*k)//(4*h*k-N*(h+k))
                    break
            if z != 0:
                break
        print(x,y,z)

if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define int long long
#define addm(X, Y) ((X) = ((X) + (Y) % mod) % mod)



int n ,m ,r;
int city[8];
struct edge{int to, cost;};
vector<vector<edge>> g(205);
bool used[8];
vector<int> ret;
vector<vector<int>> dist(205);


vector<ll> dijkstra(int s, int n, vector<vector<edge>>& g){
    priority_queue<plli, vector<plli>, greater<plli>> que;
    vector<ll> d(n, LLONG_MAX / 10); d[s] = 0;
    que.push(plli(0, s));

    while (!que.empty()){
        plli p = que.top();que.pop();
        int fr = p.second;
        if (d[fr] < p.first) continue;
        for (edge e: g[fr]){
            if (d[e.to] > d[fr] + e.cost){
                d[e.to] = d[fr] + e.cost;
                que.push(plli(d[e.to], e.to));
            }
        }
    }
    return d;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> r;
    rep(i, r) {
        cin >> city[i];
        city[i]--;
    }
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g[a].push_back(edge{b, c});
        g[b].push_back(edge{a, c});
    }

    rep(i, r) {
        dist[city[i]] = dijkstra(city[i], n, g);
    }
    int ans = INF;
    vector<int> v(r);
    iota(v.begin(), v.end(), 0);
    do {
        int tmp = 0;
        rep(i, r - 1) {
            tmp += dist[city[v[i]]][city[v[i + 1]]];
        }
        ans = min(tmp, ans);

    } while( next_permutation(v.begin(), v.end()) );
    cout << ans << endl;
    return 0;
}


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

int main(){
  string a,b;
  cin >> a >> b;
  if(a.size()>b.size()){
    cout << "GREATER" << endl;
  }
  else if(a.size()<b.size()){
    cout << "LESS" << endl;
  }
  else{
    if(a==b){
      cout << "EQUAL" << endl;
    }
    else{
      cout << (a>b?"GREATER":"LESS") << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//繰り返し2乗法 mod p
ll anp(ll a, ll n, ll p) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        ll x = anp(a, n / 2, p);
        return x * x % p;
    }
    return (a % p) * anp(a, n - 1, p) % p;
}

//二項係数 mod p
ll modinv(ll n, ll p) {
  ll a = p, u = 1, v = 0;
  while (a) {
    ll t = n / a;
    n -= t * a;
    swap(n, a);
    u -= t * v;
    swap(u, v);
  }
  u %= p;
  if (u < 0) u += p;
  return u;
}

ll ncr(ll n, ll r, ll p) {
  r = min(r, n - r);
  ll ans = 1;
  for (ll i = 0; i < r; i++) {
    ans *= (n - i) % p;
    ans %= p;
  }
  for (ll i = 0; i < r; i++) {
    ans *= modinv(i + 1, p);
    ans %= p;
  }
  return ans;
}

int main() {
  ll n, a, b, p = 1000000007;
  cin >> n >> a >> b;

  ll ans = anp(2, n, p) - 1;
  ll aa = ncr(n, a, p);
  ll bb = ncr(n, b, p);
  ans -= aa;
  if (ans < 0) ans += p;
  ans -= bb;
  if (ans < 0) ans += p;
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
 
N = int(input())
raw_numbers = list(map(int, input().split()))
Q = int(input())
 
total = sum(raw_numbers)
 
numbers = defaultdict(int)
 
for item in raw_numbers:
    numbers[item] += 1

for i in range(Q):
    a, b = map(int, input().split())
    taken = numbers[a]
    total -= numbers[a]*a
    numbers[b] += numbers[a]
    numbers[a] = 0
    total += taken*b
    print(total)

Measured memory_bytes: 89316
#include<stdio.h>
#include<string.h>
char s[100][101],o[101],q[101];
int n,m,i,j,k,p[100],a,b;
int f(char *t)
{
	int i;
	for(i=0;i<n&&strcmp(s[i],t);i++);
	return i;
}
int main()
{
	for(;scanf("%d",&n),n;)
	{
		for(i=0;i<n;i++)
			scanf("%s%d",s[i],&p[i]);
		scanf("%d",&m);
		for(i=0;i<m;i++)
		{
			scanf("%s%d",o,&k);
			b=f(o);
			for(a=0;k--;)
			{
				scanf("%s",q);
				a+=p[f(q)];
			}
			p[b]=p[b]>a?a:p[b];
		}
		scanf("%s",o);
		printf("%d\n",p[f(o)]);
	}
	return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;

signed main(){
  int n; cin >> n;
  string s; cin >> s;
  vector<set<int> > data(26);
  for(int i = 0; i < n; i++) data[s[i] - 'a'].insert(i);
  for(int i = 0; i < 26; i++) data[i].insert(INF);
  int Q; cin >> Q;
  for(int i = 0; i < Q; i++){
    int type; scanf("%d", &type);
    if(type == 1){
      int x; char c; cin >> x >> c; --x;
      if(s[x] == c) continue;
      data[s[x] - 'a'].erase(x);
      data[c - 'a'].insert(x);
      s[x] = c;
    }
    if(type == 2){
      int l, r; scanf("%d%d", &l, &r);
      int ans = 0;
      --l; 
      for(int j = 0; j < 26; j++){
        if(data[j].empty()) continue;
        if(*data[j].lower_bound(l) < r) ans++;
      }
      cout << ans << '\n';
    }
  }
}

Measured memory_bytes: 24324
from math import gcd

def solve():
    n, m = map(int, input().split())
    d = m // n
    p = m % n
    res = max(1, gcd(d, d + p))
    if p == 0:
        print(res)
        exit()
    while d > res:
        d -= 1
        p += n
        if p % d == 0:
            res = max(res, d)
    print(res)


solve()


Measured memory_bytes: 63116
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;

int main(int argc, char **argv) {
    i64 n, k;
    cin >> n >> k;

    int ans{0};
    int rat{1};
    if (n>k) {
        for (int i=0; i<n; ++i) {
            ans+=k*rat;
            rat*=10;
        }
    } else {
        for (int i=0; i<k; ++i) {
            ans+=n*rat;
            rat*=10;
        }

    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto h = readln.chomp.to!int;
  auto w = readln.chomp.to!int;
  writeln((n-h+1)*(n-w+1));
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <stack>
#include <limits>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <numeric>
#include <tuple>

constexpr long long mod = static_cast<long long>(1e9 + 7);

void dfs1(int i, const std::vector<std::vector<int>>& edges, std::vector<std::pair<int, int>>& memo, int& cnt) {
    memo[i] = {i, 0};
    for(auto v: edges[i]) {
        if(memo[v].second < 0) dfs1(v, edges, memo, cnt);
    }
    memo[i].second = cnt++;
}

void dfs2(int i, const std::vector<std::vector<int>>& edges, std::vector<int>& memo, int cnt) {
    memo[i] = cnt;
    for(auto v: edges[i]) {
        if(memo[v] < 0) dfs2(v, edges, memo, cnt);
    }
}

int main() {
    int V, E;
    std::cin >> V >> E;
    std::vector<std::vector<int>> edges(V);
    std::vector<std::vector<int>> redges(V);
    while(E--) {
        int s, t;
        std::cin >> s >> t;
        edges[s].push_back(t);
        redges[t].push_back(s);
    }
    int cnt = 0;
    std::vector<std::pair<int, int>> memo(V, {-1, -1});
    for(int i = 0; i < V; ++i) {
        if(memo[i].second < 0) dfs1(i, edges, memo, cnt);
    }
    std::sort(begin(memo), end(memo), [](auto x, auto y){return x.second > y.second;});
    std::vector<int> ans(V, -1);
    cnt = 0;
    for(auto val: memo) {
        if(ans[val.first] < 0) {
            dfs2(val.first, redges, ans, cnt++);
        }
    }

    int Q;
    std::cin >> Q;
    while(Q--) {
        int u, v;
        std::cin >> u >> v;
        std::cout << (ans[u] == ans[v] ? 1 : 0) << "\n";
    }
    std::cout << std::flush;

    return 0;
}



Measured memory_bytes: 4884
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int inf = 1e9;

int main() {
	int N,M;
	cin>>N>>M;
	vector<int> K(N);
	int A[100][100];
	rep(i,N){
		cin>>K[i];
		rep(j,K[i]){
			cin>>A[i][j];
			A[i][j]--;
		}
	}
	vector<int> ans(M);
	rep(i,N)rep(j,K[i]){
		ans[A[i][j]]++;
	}
	int cnt=0;
	rep(i,M){
		if(ans[i]==N)cnt++;
	}
	cout<<cnt<<endl;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n, m;
	cin >> n >> m;

	vector<int> ans(n, -1);
	for(int i = 0; i < m; ++i)
	{
		int s, c;
		cin >> s >> c;
		s--;

		if (c == 0 && s == 0 && n > 1)
		{
			cout << -1;
			return;
		}

		if (ans[s] == -1 || ans[s] == c)
		{
			ans[s] = c;
		}
		else
		{
			cout << -1;
			return;
		}
	}

	if (ans[0] == -1 && n > 1)
	{
		ans[0] = 1;
	}

	for(int i = 0; i < n; ++i)
	{
		cout << max(0, ans[i]);
	}

}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define BUFSIZE 10000000
typedef long long ll;
#define WDSIZE 10000

int N,M;
int a[BUFSIZE];



int main(void){

  scanf("%d",&N);
  if(N%10 == 2 || N%10 == 4||N%10 ==5||N%10 ==7||N%10 == 9) printf("hon");
  if(N%10 == 0|| N%10 == 1 || N%10 ==6 || N%10 ==8) printf("pon");
  if(N%10 == 3) printf("bon");

}


Measured memory_bytes: 1736
#include<iostream>
using namespace std;
int main(){
  int floor[4][3][10]={{{}}},n,b,f,r,v;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> b >> f >> r >> v;
    floor[b-1][f-1][r-1] += v;
  }
  for(int i=0;i<4;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<10;k++){
    cout << " " << floor[i][j][k];
      }
      cout << endl;
    }
    if(i!=3)
    cout << "####################" << endl;
  }
}


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

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int ans = 0;
		String s,t;
		s = bf.readLine();
		t = bf.readLine();
		for(int i = 0;i < 3;++i) {
			if(s.charAt(i) == t.charAt(i)) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21076
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	ll a[n];
	for(int i= 0; i<n; i++)
		cin>>a[i];
	ll ans  = a[0];
	for(int i = 1; i<n; i++)
	{
		ans /=__gcd(a[i],ans);
		ans *= a[i];
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int a,b,c;
  char ch1,ch2;
  int ans1=0,ans2=0;
  while(cin>>a>>ch1>>b>>ch2>>c){
    if(a*a+b*b==c*c)ans1++;
    if(a==b) ans2++;
  }
  cout<<ans1<<endl<<ans2<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<math.h>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>
// 追加１
#include <fstream>



using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

    vector<int> A(N, 0);

    rep(i, N - 1)
    {
        int tmp;
        cin >> tmp;
        A[--tmp]++;
    }

    rep(i, N)
    {
        cout << A[i] << endl;
    }

    return 0;
}

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

int main()
{
    int n, m, from, to, res = 0;
    cin >> n >> m;

    vector<ll> h(n + 1);
    vector<set<int>> edges(n + 1, set<int>());

    for(int i = 1; i <= n; ++i) cin >> h[i];

    for(int i = 0; i < m; ++i)
    {
        cin >> from;
        cin >> to;
        edges[from].insert(to);
        edges[to].insert(from);
    }

    for(int i = 1; i <= n; ++i)
    {
        bool higher = true;
        for(auto j : edges[i])
        {
            if(h[i] <= h[j]) higher = false;
        }

        if(higher) res++;
    }

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

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

int main(){
    int k;
    string s;
    cin >> k;
    cin >> s;
    if(s.length()<=k) cout << s << endl;
    else{
        s = s.substr(0,k);
        s = s + "...";
        cout << s << endl;
    }
}

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

int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.length()+1, id = 0;
	vector<int> p(n), c(n), t(n), lcp(n-1);
	vector<vector<int>> cnt(n);
	for (int i=0; i<n; i++) {
		p[i]= i;
	}
	sort(begin(p), end(p), [&](const int& i, const int& j) {
		if (i == n-1)
			return true;
		if (j == n-1)
			return false;
		return s[i] < s[j];
	});
	c[p[0]] = 0; c[p[1]] = 1;
	for (int i=2; i<n; i++)
		c[p[i]] = c[p[i-1]] + (s[p[i]] != s[p[i-1]]);
	for (int k = 2; k<2*n && c[p[n-1]]<n-1; k*=2) {
		for (auto &v : cnt)
			v.clear();
		for (int i=0; i<n; i++)
			cnt[c[(p[i]-(k/2)+n+n)%n]].emplace_back((p[i]-(k/2)+n+n)%n);
		id = 0;
		for (const auto & v : cnt)
			for (const int & x : v)
				p[id++] = x;
		t[1] = 0;
		for (int i=1; i<n; i++)
			t[i] = t[i-1] + (!(c[p[i]] == c[p[i-1]] && c[(p[i]+(k/2))%n] == c[(p[i-1]+(k/2))%n]));
		for (int i=0; i<n; i++)
			c[p[i]] = t[i];
	}
	for (int i=0; i<n; i++)
		t[p[i]] = i;
	int k = 0;
	for (int i=0; i<n-1; i++) {
		if (t[i] == n-1) {
			k = 0;
			continue;
		}
		int j = p[t[i]+1];
		while (i+k<n-1 && j+k<n-1 && s[i+k] == s[j+k])
			k++;
		lcp[t[i]] = k;
		if (k)
			--k;
	}
	ll ans = s.length();
	for (ll i=1; i<n; i++) {
		ans += (ll)s.length()-i-(ll)lcp[p[i]];
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 65728