akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
      
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

using namespace std;

const int N = 1e6 + 5, P = 2005, Z = 8, MOD = 998244353;
int a[N], b[N], c[N], pr[P], dp[1 << Z], sz[1 << Z];
ll sum[N];
int cp = 0;
vector<int> v[N], d[N];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    for (int i = 0; i < (1 << Z); i++) {
        for (int j = 0; j < Z; j++)
            sz[i] ^= ((i >> j) & 1);
    }

    for (int i = 2; i < P; i++) {
        bool is_prime = true;
        for (int j = 2; j * j <= i; j++) {
            if (i % j == 0) {
                is_prime = false;
                break;
            }
        }
        if (is_prime) {
            pr[cp++] = i;
        }
    }

    for (int i = 1; i < N; i++) {
        int x = i;
        for (int j = 0; pr[j] * pr[j] <= x; j++) {
            if (x % pr[j] == 0) {
                v[i].push_back(pr[j]);
            }
            while (x % pr[j] == 0) {
                x /= pr[j];
            }
        }
        if (x > 1) {
            v[i].push_back(x);
        }

        fill(dp, dp + (1 << v[i].size()), 1);
        for (int j = 0; j < v[i].size(); j++) {
            dp[1 << j] = v[i][j];
        }

        for (int j = 1; j < (1 << v[i].size()); j++) {
            dp[j] = dp[j & -j] * dp[j ^ (j & -j)];
        }

        for (int j = 0; j < (1 << v[i].size()); j++) {
            d[i].push_back(sz[j] ? -dp[j] : dp[j]);
        }
    }

    int n;
    cin >> n;

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

    ll ans = 0;

    for (int i = 0; i < N; i++) {
        ans = (ans + b[i] * (ll)(b[i] - 1) / 2 % MOD * i) % MOD;
    }

    for (int i = 1; i < N; i++) {
        int mx = (N - 1) / i;

        for (int j = 1; j <= mx; j++) {
            c[j] += b[i * j];
        }

        ll cur = 0;

        for (int j = 1; j <= mx; j++) {
            if (c[j] != 0) {
                for (int x : d[j]) {
                    if (x < 0) {
                        cur = (cur - j * sum[-x] % MOD * c[j] % MOD + MOD) % MOD;
                        sum[-x] = (sum[-x] + c[j] * j) % MOD;
                    }
                    else {
                        cur = (cur + j * sum[x] % MOD * c[j]) % MOD;
                        sum[x] = (sum[x] + c[j] * j) % MOD;
                    }
                }
            }
        }

        ans = (ans + cur * i) % MOD;

        for (int j = 1; j <= mx; j++) {
            c[j] = sum[j] = 0;
        }
    }

    cout << ans << "\n";

    return 0;
}

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

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

    ll n;
    cin >> n;

    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    ll res = 0;
    ll cnt = 0;
    for(int i = n-1; i >=0; --i){
        a[i] += cnt;
        if(b[i] == 1 || a[i]%b[i]==0) continue;

        ll inc_tmp = b[i] - a[i]%b[i];
        a[i] += inc_tmp;
        cnt += inc_tmp;
        res += inc_tmp;
    }

    cout << res << endl;

    return 0;
}

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

int main(void)
{
	int base[3] = {0};
	char happend[50];
	int score, counts, n, i, j;

	scanf("%d\n", &n);
	

	for (i = 0; i < n; i++)
	{
		counts = 0;
		score = 0;

		while (counts != 3)
		{
			gets(happend);

			if (strcmp(happend, "HIT") == 0)
			{
				if (base[2] == 1)
				{
					score++;
					base[2] = 0;
				}
				if (base[1] == 1)
				{
					base[2]++;
					base[1] = 0;
				}
				if (base[0] == 1)
				{
					base[1]++;
					base[0] = 0;
				}
				base[0]++;
			}
			else if (strcmp(happend, "HOMERUN") == 0)
			{
				for (j = 0; j < 3; j++)
					if (base[j] == 1)
					{
						base[j] = 0;
						score++;
					}
				score++;
			}
			else if (strcmp(happend, "OUT") == 0)
				counts++;
		}

		base[0] = 0;
		base[1] = 0;
		base[2] = 0;

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

	return 0;
}

Measured memory_bytes: 592
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static long Solve(int N, long[] a)
        {
            long sum = 0;
            while (true)
            {
                Array.Sort(a);
                if (a[N - 1] < N) { return sum; }
                long n = (a[N - 1] - N) / N + 1;
                for (int i = 0; i < N - 1; ++i) { a[i] += n; }
                a[N - 1] -= n * N;
                sum += n;
            }
        }
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long[] a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            Console.WriteLine(Solve(N, a));
        }
    }
}


Measured memory_bytes: 13268
#include "bits/stdc++.h"
using namespace std;

int main(void) {
    int a, b, c;
    cin >> a >> b >> c;

    if(a+b == c || b+c == a || c+a == b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        System.out.println(Math.min(a, b) + Math.min(c, d));
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> minus, plus;
    for(int i = 0; i < N; i++){
        int x;
        cin >> x;
        if(x < 0){
            minus.push_back(x);
        }else{
            plus.push_back(x);
        }
    }
    reverse(all(minus));
    minus.insert(minus.begin(), 0);
    plus.insert(plus.begin(), 0);
    int ans = 1e9;
    for(int i = 0; i < minus.size(); i++){
        if(0 <= K - i && K - i < plus.size()){
            ans = min(ans, -minus[i] + plus[K - i] + min(-minus[i], plus[K - i]));
        }
    }
    cout << ans << endl;
}


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

int main(void)
{
    int n, temp;
    vector<int> d;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> temp;
        d.push_back(temp);
    }
    sort(d.begin(), d.end());
    cout << d[n/2]-d[n/2-1] << endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int main(){
    int h,n;
    scanf("%d%d",&h,&n);
    int a[n];
    int sum = 0;
    for (int i = 0; i < n; i++){
        scanf("%d",&a[i]);
        sum += a[i];
    }
    printf("%s",sum>=h?"Yes":"No");
}


Measured memory_bytes: 640
#include<stdio.h>

#define TMIN 2
#define TMAX 200000
#define nMIN 1
#define nMAX 1000000


int main(){
int n[nMAX],Time,i,max=0,sub;

scanf("%d",&Time);
if(TMIN<=Time&&Time<=TMAX){
for(i=0;i<Time;i++){
scanf("%d",&n[i]);
//if(nMIN>n[i]||n[i]>nMAX)exit(1);
}
max=n[i-1];
sub=n[i-1]-n[i-2];
for(i=Time-2;i>=0;i--){

if(max<n[i]&&i!=0){
max=n[i];
}
if(sub<max-n[i]&&n[i]!=max){
sub=max-n[i];
}
}
}
 else exit(1);

printf("%d\n",sub);
return 0;
}



Measured memory_bytes: 2584
# N 以下の平方数のうち、最大のものを求めてください。
# ただし、平方数とは、ある整数の 2 乗として表せる整数のことを指します。

n = gets.to_i

max = 0

n.times do |i|
  square = (i + 1) ** 2
  unless n >= square
    break
  end
  max = square
end

puts max


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

int main()
{
    long long a, b, c;
    cin >> a >> b >> c;
    int aaa = 0;
    for (int i = 1; i <= 100000000; i++)
    {
        if ((a * i) % b == c)
        {
            aaa++;
            break;
        }
    }
    if (aaa == 1)
    {
        cout << "YES" << endl;
    }
    if (aaa == 0)
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

map<I,I> mp;

int main(){
  I n;
  cin >> n;
  vector<map<I,I>> uvw(n+5);
  REP(i,n){
    I u,v,w;
    cin >> u >> v >> w; 
    uvw.at(u)[v] = w;
    uvw.at(v)[u] = w;
    if (i==0){
      mp[u] = 1;
      if (w % 2 == 0){
        mp[v] = 1;
      }else{
        mp[v] = -1;
      }
    }
  }
  queue<I> q;
  REP(i,n+1){
    if (i==0) continue;
    q.push(i);
  }

  while (q.size() > 0){
    I i = q.front();q.pop();
    if (mp.find(i) != mp.end()){
      map<I,I> m = uvw.at(i);
      MREP(j,m){
        auto key = j->first;
        auto value = j->second;
        if (mp.find(key) != mp.end()){
          continue;
        }else{
          if (value % 2 == 0){
            mp[key] = mp[i];
            q.push(key);
          }else{
            mp[key] = mp[i] * -1;
            q.push(key);
          }
        }
      }
    }else{
    }
  }
  REP(i,n+1){
    if (i==0) continue;
    if (mp[i] == 1){
      cout << 1 << endl;
    }else{
      cout << 0 << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 23968
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto n = readln.chomp.to!long;
    auto s = readln.chomp.to!long;

    long b = 2;
    for (; b^^2 <= n; ++b) {
        auto m = n;
        long t;
        while (m) {
            t += m % b;
            m /= b;
        }
        if (t == s) {
            writeln(b);
            return;
        }
    }
    auto x = n/(b-1);
    for (; x > 0; --x) {
        auto y = s - x;
        if (y < 0) continue;
        b = (n-y)/x;
        if (n-y >= 0 && (n-y)%x == 0 && b > 1 && n%b + (n/b)%b == s) {
            writeln(b);
            return;
        }
    }
    if (s == n) {
        writeln(n+1);
        return;
    }
    writeln(-1);
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define ep emplace_back
const int N = 2*1e5+10; 
ll a[N], b[N]; 
ll k, n; 
bool go(ll mid) 
{
	ll sum=0; 
	for (int i =1; i<=n;i++)
	{
		ll cur = a[i]*b[i]; 
		if (cur <= mid) continue; 
		ll dec = (cur - mid+b[i]-1)/b[i];
		sum += dec; 
	}
	return sum <= k; 
		
}
int main(void) 
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie();

	cin >> n >> k; 
	for (int i=1; i<=n; i++) cin >> a[i]; 
	for (int i=1; i<=n; i++) cin >> b[i]; 

	sort(a+1, a+1+n, greater<ll>()); 
	sort(b+1, b+1+n);
	
	ll l=0, r=1e18, ans=1e18; 
	while (l<=r) 
	{
		ll m = l+(r-l)/2; 
		if (go(m))
		{
			ans = m; 
			r = m-1; 
		}
		else
			l = m+1; 

	}
	cout << ans << '\n';


	
	return false; 
}




Measured memory_bytes: 3328
a_list1, a_list2, a_list3 = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b_list = []
for _ in range(n):
    b_list.append(int(input()))
a_list = a_list1 + a_list2 + a_list3
hit_list = []
for i in range(len(a_list)):
    if a_list[i] in b_list:
        hit_list.append(i)
bingo_list = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
ans = 'No'
for bingo in bingo_list:
    if set(bingo) <= set(hit_list):
        ans = 'Yes'
        break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

inline int nextInt()
{
    int x = 0;
    char c = getchar();
    int mi = (c == '-');
    if (c == '-') c = getchar();
    while ('0' <= c && c <= '9')
    {
        x = 10 * x + c - '0';
        c = getchar();
    }
    if (mi) return x * -1;
    return x;
}

string s;
ll dp[4][500000];
const ll MOD = 1e9 + 7;

ll inq(ll a, ll q)
{
    if (q == 0) return 1;
    ll l = inq(a, q / 2);
    if (q % 2) return l * l % MOD * a % MOD;
    return l * l % MOD;
}

ll solve(string t)
{
    for (int i = 0; i < s.size(); i++) for (int j = 0; j < 4; j++) dp[j][i] = 0;
    dp[0][0] = 1;
    for (int i = 1; i < s.size(); i++)
    {
        for (int j = 0; j < 4; j++)
        {
            dp[j][i] = dp[j][i - 1];
            if (j > 0 && s[i] == t[j - 1]) dp[j][i] = (dp[j][i] + dp[j - 1][i - 1]) % MOD;
        }
    }
    return dp[3][s.size() - 1];
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    s = "S" + s;
    int cnt = 0;
    F(i, s.size()) if (s[i] == '?') cnt++;
    ll ans = inq(3, cnt) * solve("ABC") + inq(3, cnt - 1) * solve("AB?") + inq(3, cnt - 1) * solve("A?C") +
             inq(3, cnt - 1) * solve("?BC") + inq(3, cnt - 2) * solve("A??") + inq(3, cnt - 2) * solve("?B?") +
             inq(3, cnt - 2) * solve("??C") + inq(3, cnt - 3) * solve("???");
    cout << ans % MOD;
}


Measured memory_bytes: 13420
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

struct edge_t {
  int o, dist;
};
vector<vector<edge_t>> adj;
bool chose_edge;
int centroid;

pair<lint, int> dfs(int v, int p, int n) {
  lint result = 0;
  int sts = 1;
  int max_sub_sts = 0;
  for (const edge_t &ed : adj[v])
    if (ed.o != p) {
      pair<lint, int> res = dfs(ed.o, v, n);
      int sub_sts = res.second;
      max_sub_sts = max(max_sub_sts, sub_sts);
      int edge_use_count;
      if (sub_sts == n - sub_sts) {
        edge_use_count = 2 * sub_sts - 1;
        chose_edge = true;
      } else {
        edge_use_count = 2 * min(sub_sts, n - sub_sts);
      }
      result += (lint)ed.dist * edge_use_count;
      result += res.first;
      sts += sub_sts;
    }
  if (centroid == -1 && max_sub_sts <= n / 2 && (n - sts) <= n / 2) {
    centroid = v;
  }
  return make_pair(result, sts);
}

int main() {
  int n;
  scanf("%d", &n);
  adj.resize(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c), --a, --b;
    adj[a].push_back((edge_t){b, c});
    adj[b].push_back((edge_t){a, c});
  }
  lint result;
  chose_edge = false;
  centroid = -1;
  tie(result, ignore) = dfs(0, -1, n);
  if (!chose_edge) {
    assert(centroid != -1);
    int min_edge = INT_MAX;
    for (const edge_t &ed : adj[centroid])
      min_edge = min(min_edge, ed.dist);
    result -= min_edge;
  }
  printf("%lld\n", result);
  return 0;
}


Measured memory_bytes: 12416
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //int n=Readint();
            //string[] str = Console.ReadLine().Split(' ');
            string[] str = Console.ReadLine().Split(' ');

            int l = int.Parse(str[0]);
            int r = int.Parse(str[1]);
            int d = int.Parse(str[2]);

            int count = 0;
            for(int i = l; i <= r; i++)
            {
                if (i % d == 0) count++;
            }

            Cout(count);

            //ここまで
        }

        static void Cout(string s)
        {
            Console.WriteLine(s);
            return;
        }

        static void Cout(int n)
        {
            Console.WriteLine(n);
            return;
        }

        static void Cout(long n)
        {
            Console.WriteLine(n);
            return;
        }

        static int Readint()
        {
            return int.Parse(Console.ReadLine());
        }

        static int[] ReadArray(int n)
        {
            string[] str = Console.ReadLine().Split(' ');
            int[] a = new int[n];
            for (int i=0; i < n; i++){ a[i] = int.Parse(str[i]); }
            return a;
        }
        static long[] ReadArray(long n)
        {
            string[] str = Console.ReadLine().Split(' ');
           long[] a = new long[n];
            for (long i = 0; i < n; i++) { a[i] = long.Parse(str[i]); }
            return a;
        }

        static long Readlong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int Min(int a, int b)
        {
            if (a < b) return a;
            return b;
        }

        static int Max(int a, int b)
        {
            if (a > b) return a;
            return b;
        }


    }

}


Measured memory_bytes: 27536
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    vector<int> a(3);
    REP(i, 3)
    cin >> a[i];
    sort(a.begin(), a.end());

    cout << a[0] * a[1] / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdint>
#include<vector>
#include<utility>
template<typename T>
class basic_union_find{
	std::vector<T> data;
public:
	basic_union_find(std::size_t s) :data(s, -1){}
	T find(T t){ return data[t] < 0 ? t : data[t] = find(data[t]); }
	T find(T t)const{ return data[t] < 0 ? t : find(data[t]); }
	void unite(T t, T s){
		t = find(t);
		s = find(s);
		if (t == s)return;
		if (data[t] > data[s])std::swap(t, s);
		data[t] += data[s];
		data[s] = t;
	}
	bool is_same(T t, T s){ return find(t) == find(s); }
	bool is_same(T t, T s)const{ return find(t) == find(s); }
};

typedef basic_union_find<std::int32_t> union_find;



#include<cstdio>

int n, q;

int main(){
	scanf("%d %d", &n, &q);
	union_find U(n);
	for (int i = 0; i < q; ++i){
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		if (a == 0)
			U.unite(b, c);
		else 
			printf("%d\n", int(U.is_same(b, c)));
	}
	return 0;
}

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

int main() {
  int N,Min=100,Max=0;
  cin>>N;
  vector<int> data(N);
  rep(i,N){cin>>data[i];}
  rep(i,N){
    Min=min(Min,data[i]); Max=max(Max,data[i]);
  }
  vector<int> ptn(Max-Min+1);
  
  for(int p=Min;p<=Max;p++){
    int cnt=0;
    rep(i,N){
      cnt+=(p-data[i])*(p-data[i]);
    }
    ptn[p-Min]=cnt;
  }
  sort(ptn.begin(),ptn.end());
  cout<<ptn[0]<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	public void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] A = new int[n+1];
		int[] B = new int[n+1];
		StringTokenizer st = new StringTokenizer(reader.readLine());
		reader.close();
		int max = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			A[i+1] = Integer.parseInt(st.nextToken());
			max = Math.max(max, A[i+1]);
		}
		
		int[] C = new int[max+1];
		for (int i = 0; i < n; i++) C[A[i+1]]++;
		for (int i = 1; i <= max; i++) C[i] += C[i-1];
		
		for (int i = n; i >= 1; i--) {
			B[C[A[i]]] = A[i];
			C[A[i]]--;
		}
		
		StringBuilder sb = new StringBuilder();
		sb.append(B[1]);
		for (int i = 2; i <= n; i++) {
			sb.append(" " + B[i]);
		}
		System.out.println(sb.toString());
	}
}


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

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
set<string>getans(const int j, const int y, const int nj, const int ny) {

	{
		set<string>sets;
		if (j > nj) {
			const int nextj = nj + 1;
			const int nexty = ny;
			if (nextj == j&&nexty == y) {
				sets.emplace("A");
			}
			if ((nextj>=5||nexty>=5)&&abs(nextj-nexty)>1) {
				
			}
			else {
				
				set<string>aset(getans(j, y, nextj, nexty));
				for (auto s : aset) {
					s = "A" + s;
					sets.emplace(s);
				}
			}
		}
		if (y > ny) {
			const int nextj = nj ;
			const int nexty = ny + 1;
			if (nextj == j&&nexty == y) {
				sets.emplace("B");
			}
			if ((nextj >= 5 || nexty >= 5) && abs(nextj - nexty)>1) {

			}
			else {
				set<string>aset(getans(j, y, nextj, nexty));
				for (auto s : aset) {
					s = "B" + s;
					sets.emplace(s);
				}
			}
		}
		return sets;
	}
}
int main() {
	int j, y; cin >> j >> y; 
	set<string>anss(getans(j, y, 0, 0));
	
	for (auto ans : anss) {
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3208
n=int(input())
hh=list(map(int,input().split()))
ans=0
tmp=0
for i in range(n-1):
  if hh[i] >= hh[i+1]:
    tmp+=1
  else:
    ans=max(ans,tmp)
    tmp=0
ans=max(ans,tmp)
print(ans)


Measured memory_bytes: 15020
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
const ll MOD = 998244353;
const ll INF = 1e18;
using namespace std;


main(){    
    #ifdef XOX
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\Input.txt", "r", stdin);
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\OPT.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n;
    cin >> n;
    cout << 180 * (n - 2);
}

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

const char card_order[4] = {'S', 'H', 'C', 'D'};

int main() {
    int n; cin >> n;
    map<char, vector<int>> card_map;
    
    for (int i = 0; i < n; ++i) {
        char suit; cin >> suit;
        int num; cin >> num;
        
        card_map[suit].push_back(num);
    }
    
    for (int co_i = 0; co_i < 4; ++co_i) {
        vector<int> exist_card = card_map[card_order[co_i]];
        sort(exist_card.begin(), exist_card.end());
        
        for (int card_num = 1; card_num <= 13; ++card_num) {
            bool is_exist = false;
            for (auto ec_itr = exist_card.begin(); ec_itr != exist_card.end(); ++ec_itr) {
                if (card_num == *ec_itr) {
                    is_exist = true;
                    break;
                }
            }
            if (!is_exist) cout << card_order[co_i] << " " << card_num << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3092
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize);
    let mut count: usize = 0;
    dfs(n, 0, &mut count, 0, 0, 0);
    println!("{}", count);
}

fn dfs(n: usize, a: usize, count: &mut usize, x: usize, y: usize, z: usize) {
    if a <= n && x >= 1 && y >= 1 && z >= 1 {
        *count += 1
    }
    if a >= n {
        return;
    }
    dfs(n, a * 10 + 3, count, x + 1, y, z);
    dfs(n, a * 10 + 5, count, x, y + 1, z);
    dfs(n, a * 10 + 7, count, x, y, z + 1);
}


Measured memory_bytes: 2200
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    string T = S.substr(0, (S.size() - 1) / 2);
    string U = S.substr((S.size() + 3) / 2 - 1);
    string Sr = {S.rbegin(), S.rend()};
    string Tr = {T.rbegin(), T.rend()};
    string Ur = {U.rbegin(), U.rend()};
    cout << (S == Sr && T == Tr && U == Ur ? "Yes" : "No") << endl;
}

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

int main(){
  int N, K, X, Y;
  cin >> N;
  cin >> K;
  cin >> X;
  cin >> Y;
  
  if (N > K) cout << K * X + (N-K) * Y;
  else cout << N * X;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define 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;
	cin>>N;
	string s;
	cin>>s;
	int r = 0;
	int b = 0;

	rep(i,N){
		if(s[i] == 'R')r++;
		else b++;
	}
	string ans = "No";
	if(r>b)ans = "Yes";
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left #bisect_left(list, value)
#from fractions import gcd
enu = enumerate

sys.setrecursionlimit(10**7)
N = int(input())

L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(L[N-1])




Measured memory_bytes: 3572
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
a = tuple(map(int,input().split()))
mod =10**9+7

#dp[i][j]:0~iまでの子がj個分け合う場合の数
dp = [[0]*(k+1) for i in range(n)]
#b[q+1]-b[p] = dp[x][p]+...+dp[x][q]
b = [0]*(k+2)

for i in range(k+1):
    if i <= a[0]:
        dp[0][i] = 1
    b[i+1] = b[i]+dp[0][i] 

for i in range(1,n):
    for j in range(k+1):
        dp[i][j] = (b[j+1]-b[max(0,j-a[i])])%mod
    #bの更新
    b[0] = 0
    for j in range(k+1):
        b[j+1] = (b[j]+dp[i][j])%mod
        dp[i][j] = dp[i][j]%mod
print(dp[-1][-1])


Measured memory_bytes: 119532
#include<bits/stdc++.h>
using namespace std;
int data[150][150];
int memo[200][200];
int i;
int solve(int idx,int idxy){
  if(idx==i+1){
    return 0;
  }
  if(data[idx][idxy]==-1){
    return 0;
  }
  if(memo[idx][idxy]!=-1){
    return memo[idx][idxy];
  }
  int ret=data[idx][idxy];
  if(idx < i/2){
    ret=max(ret+solve(idx+1,idxy),ret+solve(idx+1,idxy+1));
  }else{
    ret=max(ret+solve(idx+1,idxy),ret+solve(idx+1,idxy-1));
  }
  return memo[idx][idxy]=ret;
}
	     
int main(){
  int w,j;
  i=j=0;
  memset(data,-1,sizeof(data));
  while(cin >> w){
    data[i][j]=w;
    j++;
    char c = cin.get();
    if(c == '\n'){
      i++;
      j=0;
    }
  }
  memset(memo,-1,sizeof(memo));
  cout<<solve(0,0)<<endl;
}

Measured memory_bytes: 1416
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
   int nexta=0,counter=0,n,tcard[100000],hcard[100000];
   int memo=0,tcounter=0,hcounter=0;
   bool bo=false,breaker=false;
   while(1){
	cin>>n;
	if(n==0){
		break;
	}
   for(int i=0;i<n;++i){
       cin>>tcard[i];
   }
   sort(tcard,tcard+n);
   for(int i=1;i<=n*2;++i){
       if(tcard[nexta]==i){
           nexta++;
       }
       else{
           hcard[counter]=i;
           counter++;
       }
       
   }
   for(int i=0;;++i){
       if(i%2==0){
           for(int j=0;j<n;++j){
               bo=true;
               if(memo<tcard[j]&&tcard[j]!=0){
                   bo=false;
                   memo=tcard[j];
                   tcard[j]=0;
                   tcounter++;
                   if(n==tcounter){
                       breaker=true;
                   }
                   break;
               }
           }
           if(breaker){
               break;
           }
           if(bo){
               memo=0;
               bo=false;
           }
       }
       else{
           for(int j=0;j<n;++j){
               bo=true;
               if(memo<hcard[j]&&hcard[j]!=0){
                   bo=false;
                   memo=hcard[j];
                   hcard[j]=0;
				   hcounter++;
                   if(hcounter==n){
                       breaker=true;
                   }
                   break;
               }
           }
           if(bo){
               memo=0;
               bo=false;
           }
       }
   }
   int tans=0,hans=0;
   for(int i=0;i<n;i++){
       if(tcard[i]!=0){
		   hans++;
	   }
	   if(hcard[i]!=0){
		   tans++;
	   }
   }
   cout<<tans<<endl<<hans<<endl;
   counter=0;tans=0;hans=0;memo=0;tcounter=0;hcounter=0;nexta=0;bo=false;breaker=false;
   }
   
   return 0;
}

Measured memory_bytes: 2960
import java.io.*;
import java.util.*;
import java.math.*;
     
public class Main{
	public static void main(String[] args) throws Exception {
	IO io = new IO();
	PrintWriter out = new PrintWriter(System.out);
	Solver sr = new Solver();
	sr.solve(io,out);
	out.flush();
	out.close();
    	}

	static class Solver
	{
	    void solve(IO io, PrintWriter out)
	    {
           int n = io.nextInt();
          	int[] count=new int[n+1];
          	for(int i=0 ; i<n-1 ; i++)
            {
              int tmp = io.nextInt();
              count[tmp]++;
            }
          for(int i=1 ; i<=n ; i++)
            	out.println(count[i]);
	    }
    	
	}
	//Special thanks to Petr (on codeforces) who inspired me to implement IO class!
	static class IO
	{
    	BufferedReader reader;
        StringTokenizer tokenizer;
    	public IO() {
                reader = new BufferedReader(new InputStreamReader(System.in));
                tokenizer = null;
            }
     
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public String nextLine() {
            String s="";
            try {
                    s=reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            return s;
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
    
        public long nextLong() {
            return Long.parseLong(next());
        }
    	double nextDouble()
    	{
    		return Double.parseDouble(next());
    	}
	}
}

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

int main(void){
  const int n=4;
  string arr;
  cin >> arr;
  
  int g=stoi(arr.c_str());  
  vector<int> a(n);
  for(int i=3;i>=0;--i){
    a.at(i) = g%10;
    g=g/10;   
  }
  
  for(int i=0;i<(1<<3);i++){
    int sum=0;
    string s;
    sum+=a.at(0);
    s=to_string(a.at(0));
    for(int j=0;j<3;j++){
      if(i&(1<<j)){
	sum+=a.at(j+1);
	s+="+"+to_string(a.at(j+1));
      }
      else{
	sum-=a.at(j+1);
	s+="-"+to_string(a.at(j+1));
      }
    }
    bitset<3> op(i);
    if(sum==7){
      s+="=7";
      cout << s << endl;
      return 0;
    }
  }
  
  return 0;
}


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

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

Measured memory_bytes: 11136
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
    char a[]={0};
    long long int  b[101]={0}, i=0, ch;
    while(1){
        scanf("%s", &a);
        if(a[0] == '+'){
            b[i-2] = b[i-2] + b[i-1];
            i = i-1;
        } else if(a[0] == '-'){
            b[i-2] = b[i-2] - b[i-1];
            i = i-1;
        }  else if(a[0] == '*'){
            b[i-2] = b[i-2] * b[i-1];
            i = i-1;
        } else if(isdigit(a[0])){
            b[i] = atoi(a);
            i++;
        }
        ch = getchar();
        if(ch == '\n'){
            printf("%lld\n", b[i-1]);
            break;
        }
    }
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	pair<pair<string,int>,int> p[n];
	for(int i = 0;i<n;i++)
	{
		string s;
		int t;
		cin >> s;
		cin >> t;
		p[i] = make_pair(make_pair(s,-t),i);
	}
	sort(p,p+n);
	for(int i = 0;i<n;i++)
	{
		cout << p[i].second + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
// AOJ
#include<stdio.h>

int main(){
	int a, b, r, t, aa, bb;
	while(scanf("%d %d", &a, &b) != EOF){
		aa = a;
		bb = b;
		while(1) {
			if(a<b){
				t = a;
				a =	b;
				b = t;
			}
			r = a%b;
			if(r == 0)
				break;
			a = r;
		}
		printf("%d %d\n", b, aa*(bb/b));
	}
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

const int LogN=20;

int main(){
    int n;
    cin>>n;
    vector<ll> x(n);
    for(int i=0;i<n;i++) cin>>x[i];
    
    vector<vector<int>> mv(LogN,vector<int>(n));

    ll l;
    cin>>l;

    for(int i=0;i<n;i++){
        int lb=i;
        int ub=n;
        while(ub-lb>1){
            int mid=(lb+ub)/2;
            if(x[mid]-x[i]<=l) lb=mid;
            else ub=mid;
        }
        mv[0][i]=lb;
    }

    for(int i=0;i+1<LogN;i++){
        for(int j=0;j<n;j++){
            mv[i+1][j]=mv[i][mv[i][j]];
        }
    }

    auto query=[&](int a,int b){
        int d=0;
        for(int i=LogN-1;i>=0;i--){
            int to=mv[i][a];
            if(to<b){
                d+=(1<<i);
                a=mv[i][a];
            }

        }
        return d+1;
    };
    
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        if(a>b) swap(a,b);
        cout<<query(a,b)<<endl;
    }

    
    return 0;
}


Measured memory_bytes: 9464
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	lli dp[n+1];
	for(int i=0;i<n;i++)
	   dp[i]=10000000001;
	dp[0]=0;;
	int x,diff;
	for(int i=1;i<n;i++)
	{
		x=1;
		while(x<=k && i-x>=0 )
		{
			diff=abs(a[i]-a[i-x]);
			dp[i]=min(dp[i],dp[i-x]+diff);
			x++;
		}
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1408
N = int(input())
t,x,y = [0]*(N+1),[0]*(N+1),[0]*(N+1)

for i in range(N):
    t[i+1],x[i+1],y[i+1] = map(int,input().split())

ans = "Yes"
for i in range(1,N+1):
    dl = abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
    dt = t[i]-t[i-1]
    if (dt < dl)or((dt-dl) % 2 != 0):
        ans = "No"
        break

print(ans)

    
    

Measured memory_bytes: 11636
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    string S;
    cin >> S;
    int L=S.length();
    int alf[26]={};
    rep(i,L) alf[S[i]-'a']++;
    int check=0;
    rep(i,26) if(alf[i]%2==1) check=1;
    if(check==1) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 256
from sys import stdin
n, m = map(int, stdin.readline().split())
grid = []
for i in range(n):
    row = list(input())
    grid.append(row)

dp = [[0 for j in range(m)] for i in range(n)]
for i in range(m):
    if grid[0][i] == '.':
        dp[0][i] = 1
    else:
        break
for i in range(n):
    if grid[i][0] == '.':
        dp[i][0] = 1
    else:
        break

for i in range(1, n):
    for j in range(1, m):
        if grid[i][j] == '#':
            continue
        if dp[i-1][j] > 0:
            dp[i][j] += dp[i-1][j]
            
        if dp[i][j-1] > 0:
            dp[i][j] += dp[i][j-1]
        

print(dp[-1][-1] % (10**9 + 7))

Measured memory_bytes: 166216
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007

int main()
{
    void solution();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    solution();

    return 0;
}

void solution()
{
    string str;
    cin >> str;
    if (str.at(str.length() - 1) == 's')
    {
        cout << str << "es";
    }
    else
    {
        cout << str << "s";
    }
}

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


void solve(vector<int> &ABCD){
    for (int i=0;i< (1<<4 -1) ;i++){
        char op[3];
        int ret =  ABCD[0];
        for (int j=0;j<3;j++){
            int mask = 1 << j;
            if (mask & i){
                ret += ABCD[j+1];
                op[j] = '+';
            }else{
                ret -=ABCD[j+1];
                op[j] = '-';
            }
        }
        if (ret == 7){
            printf("%d%c%d%c%d%c%d=7\n",ABCD[0],op[0],ABCD[1],op[1],ABCD[2],op[2],ABCD[3]);
            break;
        }
    }


}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    vector<int> ABCD(4);
    for (int i=0;i<4;i++){
        scanf("%1d",&ABCD[i]);
    }
    
    solve(ABCD);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    string S;
    cin >> S;
    ll N = S.size();
    ll summ = 0;
    loop(i, N) summ += ctoi(S[i]);
    if (summ % 9 == 0)
        putout("Yes");
    else
        putout("No");
    return 0;
}


Measured memory_bytes: 3644
import sys 
sys.setrecursionlimit(1000000)
N, M = map(int, input().split())
ab = [list(map(lambda x:int(x)-1, input().split())) for _ in range(M)]
adlist = [[] for _ in range(N)]
for a, b in ab:
  adlist[a] += [b] 
  adlist[b] += [a] 


used = [0]*N 
global ans 
ans = 0
def dfs(v):
  global ans 
  used[v] = 1 
  if sum(used) == N:
    ans += 1 
    return 

  for u in adlist[v]:
    if used[u] == 0:
      used[u] = 1 
      dfs(u)
      used[u] = 0  

  return 

dfs(0)
print(ans)

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<ll> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  ll k;
  cin >> n >> k;
  VL a(n);
  rep(i, n) cin >> a[i];
  VL s(n+1, 0);
  rep(i, n) s[i+1] = s[i] + a[i];
  rep(i, n) s[i+1] = (s[i+1] - (i+1) + 1000 * k) % k;
  ll ans = 0;
  map<ll, ll> mp;
  FOR(i, 0, n+1) {
    if(i >= k) mp[s[i-k]]--;
    ans += mp[s[i]];
    mp[s[i]]++;
  }
  out(ans);
  return 0;
}


Measured memory_bytes: 15872
N, Y = map(int, input().split())
ans = "-1 -1 -1"
if Y < 1000 * N or Y > 10000 * N:
    print(ans)
    quit()
for i in range(N + 1):
    sen = i
    go = int((10000 * (N - i) - (Y - 1000 * sen)) / 5000)
    man = N - sen - go
    if 1000 * sen + 5000 * go + 10000 * man == Y and sen >= 0 and go >= 0 and man >= 0:
        ans = [man, go, sen]
        ans = map(str, ans)
        result = " ".join(ans)
        print(result)
        quit()

print(ans)

Measured memory_bytes: 3064
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    ll h;
    while(cin>>h)
    {
        ll ans=1;
        ll mul=2;
        h/=2;
        while(h>=1)
        {
            ans+=mul;
            mul*=2;
            h/=2;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
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(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<vector<pair<int,int>>> A(N, vector<pair<int,int>>(N));
    REP(i,N){
        REP(j,N){
            int a; cin >> a;
            A[i][j] = {a,0};
        }
    }

    REP(i,N-1){
        FOR(j,i+1,N){
            REP(k,N){
                if(i==k || j==k) continue;
                if(A[i][k].first+A[k][j].first < A[i][j].first){
                    cout << -1 << endl;
                    return 0;
                }else if(A[i][k].first+A[k][j].first == A[i][j].first){
                    A[i][j].second = 1;
                }
            }
        }
    }

    ll ans = 0;
    REP(i,N-1){
        FOR(j,i+1,N){
            if(A[i][j].second==0) ans += A[i][j].first;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4308