akhauriyash/Code-Regression huggingface dataset:
class UnionFindTree():
    def __init__(self, n):
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
        
        # 常にxの要素数＞yの要素数とする
        if self.parents[x] > self.parents[y]:
            x, y = y, x
            
        # self.parents[x] に　yの要素数を追加してから併合
        self.parents[x] += self.parents[y]
        self.parents[y] = x

def main():
  N, M = map(int, input().split())
  uft = UnionFindTree(N)
  
  for m in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    uft.union(a, b)
    
  print(-min(uft.parents))
  
  
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 14352
/*
    Problem 48
    https://onlinejudge.u-aizu.ac.jp/problems/1611
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 306;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
int n;
vector<int> w(MAX);
vector<vector<int>> dp(MAX, vector<int>(MAX));
/* function */
void inputW() {for (int i = 0; i < n; i++) cin >> w[i];}
void init() { for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = 0; }
void calcDP() {
    // dp[s][t] = s ~ t番目を使ってられる最大値
    // s |s+1| ... |t-1| tの時の遷移
    // 1) |s+1| ~ |t-1| まで全部落とせる場合
    //    if (dp[s+1][t-1] == t-s-1 && abs(w[s] - w[t]) <= 1)
    //      dp[s][t] = dp[s+1][t-1] + 2
    // 2) 分割候補を探索して最大値を探す
    //    for k = s+1, ..., t-1
    //      dp[s][t] = max(dp[s][t], dp[s][k] + dp[k+1][t])
    for (int i = 1; i < n; i++) {  // s ~ t(=s+i)まで
        for (int s = 0; s < n - i; s++) {  // start位置
            int t = s + i;  // end位置
            // 1)
            if (dp[s+1][t-1] == t-s-1)
                dp[s][t] = dp[s+1][t-1] + (abs(w[s] - w[t]) <= 1 ? 2 : 0);
            // 2)
            for (int k = s+1; k <= t-1; k++)
                dp[s][t] = max(dp[s][t], dp[s][k] + dp[k+1][t]);
        }
    }
}
void printAns() { cout << dp[0][n-1] << '\n'; }
/* main */
int main(){
    while (cin >> n) {
        if (n == 0) return 0;
        inputW();
        init();
        calcDP();
        printAns();
    }
}


Measured memory_bytes: 3264
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
 
ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // #ifndef ONLINE_JUDGE
    // freopen("inp.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 
    // #endif

    ll n,x,t;
    cin>>n>>x>>t;

    ll num = ceil(n/(x*1.0));
    cout<<num*t<<"\n";

    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin >> N;
    vvint graph(N);
    vint a(N), b(N);
    vector<pair<int, int>> edges(N);
    map<pair<int, int>, int> color;
    for (size_t i = 0; i < N - 1; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]].push_back(b[i]);
        graph[b[i]].push_back(a[i]);
        edges[i] = {a[i], b[i]};
    }
    queue<pair<pair<int, int>, int>> q;
    q.push({{0, 0}, -1});
    int M = 0;
    while (!q.empty())
    {
        int prevcolor = q.front().second;
        pair<int, int> prevedge = q.front().first;
        int prevpoint = prevedge.second;
        q.pop();
        int c = 0;
        for (auto &&i : graph[prevpoint])
        {
            if (color.find({prevpoint, i}) != color.end() or color.find({i, prevpoint}) != color.end())
            {
                continue;
            }
            if (c != prevcolor)
            {
                q.push({{prevpoint, i}, c});
            }
            else
            {
                q.push({{prevpoint, i}, ++c});
            }
            color[{prevpoint, i}] = c;
            chmax(M, c);
            c++;
        }
    }
    cout << M+1 << endl;
    for (size_t i = 0; i < N - 1; i++)
    {
        cout << color[edges[i]]+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 13824
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;
import java.util.AbstractMap.SimpleEntry;
import java.util.HashSet;
import java.util.Iterator;

class Main {

    static final int MOD = 1000000007;
    static int MAX;

    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final ArrayList<Node> list = new ArrayList<Node>(N);
        final ArrayList<Bridge> bridge = new ArrayList<Bridge>(N);
        for (int i = 0; i < N; i++) {
            list.add(new Node(i));
        }

        for (int i = 0; i < N - 1; i++) {
            final int a = sc.nextInt()-1;
            final int b = sc.nextInt()-1;
            final Bridge edge = new Bridge(list.get(a), list.get(b));
            list.get(a).addEdge(edge);
            list.get(b).addEdge(edge);
            bridge.add(edge);
        }

        MAX = 0;
        Node st = null;
        for (int i = 0; i < N; i++) {
            if (MAX < list.get(i).edge.size()) {
                MAX = list.get(i).edge.size();
                st = list.get(i);
            }
        }

        st.setFirst();

        System.out.println(MAX);
        for (int i = 0; i < N - 1; i++) {
            System.out.println(bridge.get(i).col);
        }
    }
}

class Bridge {
    Node from;
    Node to;
    int col;

    Bridge(final Node from, final Node to) {
        this.from = from;
        this.to = to;
    }

    boolean contains(Node node) {
        if (from.equals(node) || to.equals(node))
            return true;
        else
            return false;
    }

    /**
     * @param col the col to set
     */
    public void setCol(final int col) {
        this.col = col;
    }
}

class Node {
    final int number;
    Node parent;
    boolean isLeaf = true;
    ArrayList<Bridge> edge = new ArrayList<Bridge>();

    Node(final int number) {
        this.number = number;
    }

    void addEdge(final Bridge bridge) {
        edge.add(bridge);
        if (edge.size() <= 1)
            isLeaf = true;
        else
            isLeaf = false;
    }

    void setFirst() {
        int cnt = 1;
        for (int i = 0; i < edge.size(); i++) {
            final Bridge next = edge.get(i);
            if (next.from.equals(this))
                next.to.setParent(this, next, (++cnt) % Main.MAX);
            else
                next.from.setParent(this, next, (++cnt) % Main.MAX);
        }
    }

    void setParent(Node from, final Bridge bridge,int cnt) {
        parent = from;
        bridge.setCol(cnt+1);
        for (int i = 0; i < edge.size(); i++) {
            final Bridge next = edge.get(i);
            if (next.contains(parent))
                continue;
            if (next.from.equals(this))
                next.to.setParent(this, next, (++cnt) % Main.MAX);
            else
                next.from.setParent(this, next, (++cnt) % Main.MAX);
        }
    }
}

Measured memory_bytes: 106868
#include<iostream>
using namespace std;
int main() {
    string s;
    cin >> s;
    
    if (s == "SUN") {
        cout << "7";
    }
    else if (s == "MON") {
        cout << "6";
    }
    else if (s == "TUE") {
        cout << "5";
    }
    else if (s == "WED") {
        cout << "4";
    }
    else if (s== "THU") {
        cout << "3";
    }
    else if (s == "FRI") {
        cout << "2";
    }
    else if (s == "SAT") {
        cout << "1";
    }
 
 
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n;
		n = sc.nextInt();
		
		sc.close();
		
		String ans = "ABC";
		
		ans += Integer.toString(n);
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 22740
n = int(input())

f = ''
for i in range(1, 100):
    if n <= 26**i:
        n -= 1    #1→26から0→25への変換
        for i in range(i):
            f += chr(ord('a') + n%26)
            n //= 26
        break
    else:
        n -= 26**i

print(f[::-1])

Measured memory_bytes: 9188
#include<stdio.h>

int main(){
		char s[3][101];
		scanf("%s%s%s",s[0],s[1],s[2]);
		int si[3]={0},gen[3]={0},t=0,i;
		while(s[0][gen[0]]!=0)gen[0]++;
		while(s[1][gen[1]]!=0)gen[1]++;
		while(s[2][gen[2]]!=0)gen[2]++;
		while(1){
				for(i=0;i<3;i++){
						if(si[i]==gen[i]+1){
								printf("%c\n",'A'+i);
								return 0;
						}
				}
				t=s[t][si[t]++]-'a';				
//				printf("%d\n",t);
		}
}


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



int MOD=1000000007;
int main(void){
	int H,A;
	cin >> H >> A;
	if(H%A==0) cout << H/A << endl;
	else cout << H/A+1 << endl;
}


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

using namespace std;

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

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

const double EPS = 1e-10;
const int INF = 1001001001;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		vi ans;
		for(int i=0; n; i=!i){
			int tmp;
			if(!i){
				tmp = n>0 ? n%10 : (10-abs(n)%10)%10;
				n -= tmp;
			}
			else{
				tmp = n>0 ? (10-abs(n)%10)%10 : abs(n)%10;
				n += tmp;
			}
			ans.push_back(tmp);
			n /= 10;
		}
		rep(i, ans.size())
			printf("%d", ans[ans.size()-i-1]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1064
import numpy as np
import sys

class UnionFind:
	def __init__(self, n):
		self.n = n
		self.root = [-1]*(n+1)
		self.rnk = [0]*(n+1)
		self.Maxroot = -1

	def Find_Root(self, x):
		if (self.root[x] < 0):
			return x
		else:
			self.root[x] = self.Find_Root(self.root[x])
			return self.root[x]

	def Unite(self, x, y):
		x = self.Find_Root(x)
		y = self.Find_Root(y)
		if x == y:
			return 
		elif self.rnk[x] > self.rnk[y]:
			self.root[x] += self.root[y]
			if self.root[x] < self.Maxroot:
				self.Maxroot = self.root[x]
			self.root[y] = x
		else:
			self.root[y] += self.root[x]
			if self.root[y] < self.Maxroot:
				self.Maxroot = self.root[y]
			self.root[x] = y
			if self.rnk[x] == self.rnk[y]:
				self.rnk[y] += 1

	def isSameGroup(self, x, y):
		return self.Find_Root(x) == self.Find_Root(y)

	def Count(self, x):
		return self.root[self.Find_Root(x)] * (-1)

	def Max_tree(self):
		return min(self.root) * (-1)

n, m = map(int, input().split())
AB = np.array(sys.stdin.read().split(), np.int64)
A = AB[::2]
B = AB[1::2]

ans = 0
for i in range(m):
	solve = UnionFind(n+1)
	for j in range(m):
		if j == i:
			continue
		
		solve.Unite(A[j],B[j])

	if solve.Max_tree() != n:
		ans += 1

print(ans)



Measured memory_bytes: 12436
n = int(input())
primes = []
def is_prime(k):
    if k < 2:
        return False
    if k == 2:
        return True
    for p in primes:
        if k % p == 0:
            return False
        if k <= p*p:
            break
    return True


for i in range(1000000 + 100):
    if is_prime(i):
        primes.append(i)
        if i >= n:
            print(i)
            break


Measured memory_bytes: 73136
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

lli gcd(lli a,lli b){
    lli x,y;
    x=max(a,b);
    y=min(a,b);
    if(x%y==0){
        return y;
    }
    else{
        return gcd(y,x%y);
    }
}

lli lcm(lli a,lli b){
    lli x,y;
    x=max(a,b);
    y=min(a,b);
    return x*y/gcd(x,y);
}

int main(){
    lli n,m,l,g;
    string s,t,x;
    vector<char> nvec,mvec;
    lli i=0,j,k;
    cin>>n>>m>>s>>t;
    l=lcm(n,m);
    g=gcd(n,m);
    if(g!=1){
        m/=g;
        n/=g;
        rep(i,0,s.size()/n){
            if(s[n*i]!=t[m*i]){
                l=-1;
                break;
            }
        }
    }
    else{
        if(s[0]!=t[0]){
            l=-1;
        }
    }
    cout<<l<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
namespace std {
  template <>
  class hash<std::pair<Int, Int>> {
  public:
    const Int MOD = 1e9+7;
    size_t operator()(const std::pair<Int, Int>& x) const{
      return hash<Int>()(x.first)*MOD+hash<Int>()(x.second);
    }
  };
}
signed main(){
  Int n;
  cin>>n;
  unordered_map<Int, Int> cnt;
  
  auto add=[&](Int v,Int x){
    for(Int i=0;i<4;i++){
      cnt[v]+=x;
      v=((v&1023)<<30)|(v>>10);
    }
  };

  vector<Int> d(n);
  for(Int i=0;i<n;i++){
    Int v=0,x;
    for(Int j=0;j<4;j++) cin>>x,v|=x<<(j*10);
    add(v,1);
    d[i]=v;
  }
  sort(d.begin(),d.end());
  d.erase(unique(d.begin(),d.end()),d.end());
  
  vector<Int> b;
  for(auto p:cnt) b.emplace_back(p.first);

  using sq = vector<Int>;
  auto right=[&](const sq &v){
    static const sq ord({1,4,7,2,5,0,3,6});
    sq a(8);
    for(Int i=0;i<8;i++) a[i]=v[ord[i]];
    return a;
  };
  auto front=[&](const sq &v){
    static const sq ord({5,4,1,0,7,6,3,2});
    sq a(8);
    for(Int i=0;i<8;i++) a[i]=v[ord[i]];
    return a;
  };  
  auto clock=[&](const sq &v){
    static const sq ord({3,0,1,2,5,6,7,4});
    sq a(8);
    for(Int i=0;i<8;i++) a[i]=v[ord[i]];
    return a;
  };

  using P = pair<Int, Int>;
  auto calc=[](Int a,Int b,Int c,Int d){
    return ((((((d<<10)|c)<<10)|b)<<10)|a);
  };
  auto conv=[&](const sq &a){
    return P(calc(a[0],a[1],a[2],a[3]),calc(a[4],a[5],a[6],a[7]));
  };

  vector<sq> ord(24,sq(8));
  {
    sq a(8);
    iota(a.begin(),a.end(),0);
    Int x=0;
    for(Int i=0;i<6;i++){
      for(Int j=0;j<4;j++){
	for(Int k=0;k<8;k++) ord[x][a[k]]=k;
	a=clock(a);
	x++;
      }
      if(i==0||i==4) a=right(a);
      else a=front(a);
    }
  }
  
  unordered_set<P> used;
  auto dup=[&](const sq &a)->Int{
    Int res=0;
    sq b(8);
    for(Int i=0;i<24;i++){
      for(Int k=0;k<8;k++) b[ord[i][k]]=a[k];
      res+=(a==b);
      used.emplace(conv(b));
    }
    //cout<<res<<endl;
    return res;
  };

  Int ans=0;
  for(Int i=0;i<(Int)d.size();i++){
    sq a(8);
    for(Int k=0;k<4;k++) a[k]=(d[i]>>(k*10))&1023;
    
    for(Int j=0;j<(Int)b.size();j++){
      if(used.count(P(d[i],b[j]))) continue;
      for(Int k=0;k<4;k++) a[k+4]=(b[j]>>(k*10))&1023;
      
      Int w=calc(a[2],a[1],a[4],a[7]);
      Int x=calc(a[0],a[3],a[6],a[5]);
      Int y=calc(a[3],a[2],a[7],a[6]);
      Int z=calc(a[1],a[0],a[5],a[4]);
      if(cnt[w]==0||cnt[x]==0||cnt[y]==0||cnt[z]==0) continue;
      
      __int128_t res=cnt[d[i]];
      add(d[i],-1);      
      
      res*=cnt[b[j]];      
      add(b[j],-1);            
      
      res*=cnt[w];
      add(w,-1);

      res*=cnt[x];
      add(x,-1);

      res*=cnt[y];
      add(y,-1);

      res*=cnt[z];
      add(z,-1);

      add(d[i],1);
      add(b[j],1);
      add(w,1);
      add(x,1);
      add(y,1);
      add(z,1);

      res/=dup(a);
      ans+=res;
    }
  }

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


Measured memory_bytes: 28916
#include <stdio.h>


int main(void){
  int a, b, ans;
  
  scanf("%d %d", &a, &b);
  
  ans = a + b;
  
  if(ans <= a - b){
   ans = a - b; 
  }
  
  if(ans <= a * b){
   ans = a * b; 
  }
  

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  ll a,b;
  ll x,y;
  cin>>a>>b>>x;
  if(a==0) y = y=(b/x)+1;
  else y=(b/x)-((a-1)/x);

  cout << y <<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

int aux_x[4] = {0,0,1,-1};
int aux_y[4] = {1,-1,0,0};

int main() 
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int r,c;
    string M[55];
    while(cin >> r >> c)
    {
        for(int i = 0; i < r; i++)
            cin >> M[i];
        int posible = 1;
        for(int px = 0; px < r; px++)
            for(int py = 0; py < c; py++)
                if(M[px][py] == '#')
                {
                    int ok = 0;
                    for(int k = 0; k < 4; k++)
                    {
                        int nx = px + aux_x[k];
                        int ny = py + aux_y[k];
                        if(nx > -1 && ny > -1 && nx < r && ny < c && M[nx][ny] == '#')
                            ok = 1;
                    }
                    if(!ok)
                        posible = 0;
                }
        cout << (posible? "Yes" : "No") << '\n';
    }
    return 0;
}

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


int B[3][3];
bool C[3][3];
int main(void) {
    for(int i = 0; i < 3; i ++){
        for(int j = 0; j < 3; j++) {
            cin >> B[i][j];
            C[i][j] = false;
        }
    }

    int n ; cin >>n;

    int tot = 0;
    for(int k = 0; k < n; k++) {
        int tmp; cin >> tmp;
        for(int i = 0; i < 3; i ++){
            for(int j = 0; j < 3; j++) {
                if(tmp==B[i][j]){
                    C[i][j] = true;
                    tot++;
                }
            }
        }
    }
    bool ans = false;
    if(C[0][0] && C[1][1] && C[2][2]) {
        ans = true;
    }
    if(C[0][2] && C[1][1] && C[2][0]) {
        ans = true;
    }

    for(int i = 0; i < 3; i++) {
        if(C[i][0] && C[i][1] && C[i][2]) {
            ans = true;
        }
        if(C[0][i] && C[1][i] && C[2][i]) {
            ans = true;
        }
    }
    if(!ans) {
        cout << "No" << endl;
    }else {
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
// AOJ1167      
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

vector<int> simen;
vector<int> simen_odd;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int max_n=pow(10,6);
    int i=1;
    int cur=i*(i+1)*(i+2)/6;
    while(cur<=max_n){
        simen.emplace_back(cur);
        if(cur%2==1) simen_odd.emplace_back(cur);
        i++;
        cur=i*(i+1)*(i+2)/6;
    }
    int n;
    int l=simen.size();
    int l_odd=simen_odd.size();
    int max_=pow(10,7);
    vector<int> dp1(max_n+10,max_);
    dp1[0]=0;
    for(int i=0;i<l;i++){ //もらうDP
        for(int j=1;j<=max_n;j++){
            if(0<=j-simen[i]) dp1[j]=min(dp1[j-simen[i]]+1,dp1[j]);
        }
    }
    vector<int> dp2(max_n+10,max_);
    dp2[0]=0;
    for(int i=0;i<l_odd;i++){
        for(int j=1;j<=max_n;j++){
            if(0<=j-simen_odd[i]) dp2[j]=min(dp2[j-simen_odd[i]]+1,dp2[j]);
        }
    }
    while(cin>>n){
        if(n==0) break;
        cout<<dp1[n]<<" "<<dp2[n]<<endl;
    }
    return 0;
}


Measured memory_bytes: 10672
#include <bits/stdc++.h>
using namespace std;
int fnc (int a, int t) {
  int ret = 0;
  while (a < t) {
    a += 2;
    ret++;
  }
  ret += a - t;
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  int ret = 1e9;
  for (int t = -100; t < 200; t++) {
    ret = min(ret, fnc(a, t) + fnc(b, t) + fnc(c, t));
  }
  cout << ret << '\n';
  return 0;
}

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

using namespace std;
#define ll long long
#define int long long

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif
ll a[200000];
ll b[200000];
int N;

void modo(int k)
{
	k = (1 << k) - 1;
	rep(i, N) {
		a[i] = a[i] & k;
		b[i] = b[i] & k;
	}
}

signed main()
{
	cin >> N;
	rep(i, N) cin >> a[i];
	rep(i, N) cin >> b[i];
	ll res = 0;
	rreps(i, 31, 1) {
		int T = 1 << (i-1);
		modo(i);
		sort(b, b+N);
		ll sum = 0;
		rep(i, N) {
			int* itr11 = lower_bound(b, b+N, T - a[i]);
			int* itr12 = upper_bound(b, b+N, 2 * T - a[i]-1);
			int* itr21 = lower_bound(b, b+N, 3 * T - a[i]);
			int* itr22 = upper_bound(b, b+N, 4 * T - a[i]-1);
			sum += (itr12-itr11) + (itr22-itr21);
		}
		if (sum % 2) res += T;
	}
	cout << res << endl;
}


Measured memory_bytes: 3328
// Created by Manmeet Singh Parmar
// name of snippet-> temp.sublime-snippet
// path -> sublime text 3/packages/user/temp.sublime-snippet

#include <cmath>
#include <iostream>
#include <map>
using namespace std;

int32_t main()
{
   	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

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

    int n; cin >> n;
    int a;
    map<int, int> hm;
    for(int i=2; i<=n; i++) {
    	cin >> a;
    	hm[a]++;
    }
    for(int i=1; i<=n; i++) {
    	if(hm[i])
    		cout << hm[i] << '\n';
    	else
    		cout << 0 << '\n';
    }
}

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

using namespace std;

int main()
{
	int A, B, C, D, P;

	scanf("%d %d %d %d %d", &A, &B, &C, &D, &P);

	printf("%d\n", min(A * P, B + max(0, P - C) * D));

	return (0);
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    string s;cin >>s;
    ll n=s.size();
    bool flg=true;
    if(n%2==1)flg=false;
    else {
        for (int i = 0; i < n; i += 2) {
            if (s.substr(i, 2) != "hi")flg = false;
        }
    }
    if(flg)puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
h,w,k = map(int,input().split())
list1 = [list(input()) for i in range(h)]
import numpy as np
list2 = np.zeros((h,w),np.uint32) #list2に0の配列を用意
numcount = 1 #切り分けたケーキにふる番号
berrycount = 0 #1列に何回目のいちごが現れたか
flag = 0 #1列にいちごが一個も無かったときのフラグ
que = [] #その時の列をqueに入れてく
for i in range(h):
    flag = 0
    if not "#" in list1[i]: #いちごが乗ってない列
        flag = 1
        numcount -= 1
        que.append(i)
    if not flag: #いちごが乗ってる例
        for j in range(w):    
            if list1[i][j] == ".":
                list2[i][j] = numcount
            else:
                if berrycount == 0: #いちごが出現するのが1回目なら、特に気にせず番号をつける
                    berrycount += 1
                    list2[i][j] = numcount
                else: #2回目以降なら、振り分ける番号を+1する
                    berrycount += 1
                    numcount += 1
                    list2[i][j] = numcount
    berrycount = 0 #いちごリセット
    numcount += 1 #振り分け番号を+1

meme = 0 
"""
1列目から何列もいちごが現れないとき、
初めていちごが現れる列を探索し、その列の数字を1列目~にコピーする。
それ以外(普通に列の途中でいちごのない列が出現したとき)
は、一つ前の列を参照してコピーする
"""
for i in que:
    if i == 0:
        for j in range(1,h):
            if "#" in list1[j]:
                meme = j
                break
        list2[i] = list2[meme]
    else:
        list2[i] = list2[i-1]
for i in range(h):
    for j in range(w):
        list2[i][j] = int(list2[i][j])
for i in range(h):
    print(" ".join(map(str,list2[i])))

Measured memory_bytes: 15644
d,g=map(int,input().split())
pc=[list(map(int,input().split())) for _ in range(d)]
ans=0
for i in range(1<<d):
  p=0
  cnt=0
  for j in range(d):
    if (i>>j)&1:
      p+=100*(j+1)*pc[j][0]+pc[j][1]
      cnt+=pc[j][0]
  if g>p:
    for k in range(d)[::-1]:
      if (i>>k)&1==0:
        if g-p<=100*(k+1)*(pc[k][0]-1):
          cnt+=-(-(g-p)//(100*(k+1)))
          break
        else:
          cnt=10**5
          break
  if ans==0 or ans>cnt:
    ans=cnt
print(ans)

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt(),B=sc.nextInt(),X=sc.nextInt();
		if(X < A) {
			System.out.println("NO");
		}else if(X > A+B){
			System.out.println("NO");
		}else {
			System.out.println("YES");
		}
	}
}

Measured memory_bytes: 21584
import sys
input = sys.stdin.readline

N = int(input())

ans = [0] * (10 ** 4 + 1)
for x in range(1,int(N ** (1 / 2))):
    for y in range(1, int(N ** (1 / 2))):
        for z in range(1, int(N ** (1 / 2))):
            v = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if v <= N:
                ans[v] += 1

for i in range(1,N+1):
    print(ans[i])



Measured memory_bytes: 74928
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 10000000000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;

int H, W, K;
int sx, sy, gx, gy;
string S[1000010];
int dx[] = { 0,0,1,-1 };
int dy[] = { 1,-1,0,0 };



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

	cin >> H >> W >> K;
	cin >> sx >> sy >> gx >> gy;
	sx--, sy--, gx--, gy--;
	REP(i, H)cin >> S[i];
	
	vector<VI>d(H, VI(W, INF));
	d[sx][sy] = 0;
	queue<pii>Q;
	Q.push(pii(sx, sy));

	while (!Q.empty()) {
		int x = Q.front().first;
		int y = Q.front().second;
		Q.pop();
		REP(k, 4) {
			int co = 0;
			int nx = x, ny = y;
			while (++co <= K) {
				nx += dx[k], ny += dy[k];
				if (nx < 0 || nx >= H || ny < 0 || ny >= W)break;
				if (S[nx][ny] == '@')break;


				if (d[nx][ny] <= d[x][y])break;
				if (d[nx][ny] > d[x][y] + 1) {
					d[nx][ny] = d[x][y] + 1;
					Q.push(pii(nx, ny));
				}
			}
		}
	}

	int ans = d[gx][gy];
	if (ans == INF)ans = -1;
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 51048
#include <stdio.h>
main(){int n,s,i;
for(;;){scanf("%d",&n);if(!n)break;for(i=1;i*i<=n;i++){if(n!=i){if(n%i==0){s+=i;if(i!=n/i){s+=n/i;}}}}if(s<2*n){printf("deficient number\n");}else if(s==2*n){printf("perfect number\n");}else{printf("abundant number\n");}s=0;}
return 0;}

Measured memory_bytes: 1012
from sys import stdin
n = int(stdin.readline().rstrip())
h = [int(x) for x in stdin.readline().rstrip().split()]
ans = 1
tmp = h[0]
for i in range(n - 1):
    ans += 1 if tmp <= h[i + 1] else 0
    tmp = max(tmp, h[i + 1])
print("{}".format(ans))

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

int N, D[100], cnt[100], ans = 0;

int main() {
	cin >> N; cnt[0]++;
	for (int i = 1; i <= N; i++) { cin >> D[i]; cnt[D[i]]++; }

	for (int i = 0; i < (1 << 13); i++) {
		vector<int>vec;
		for (int j = 0; j <= 12; j++) {
			if (cnt[j] == 0) {

			}
			if (cnt[j] == 1) {
				if ((i / (1 << j)) % 2 == 0) vec.push_back(j);
				else vec.push_back((24 - j) % 24);
			}
			if (cnt[j] == 2) {
				vec.push_back(j);
				vec.push_back((24 - j) % 24);
			}
			if (cnt[j] >= 3) {
				cout << "0" << endl;
				return 0;
			}
		}
		sort(vec.begin(), vec.end());

		int minx = 24;
		for (int j = 0; j < vec.size(); j++) {
			int v1 = vec[j], v2 = vec[(j + 1) % vec.size()]; if (j == vec.size() - 1) v2 += 24;
			minx = min(minx, v2 - v1);
		}
		ans = max(ans, minx);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;

int main(int argc, char const *argv[]) {
    int k;
    ll ans=0;
    cin >> k;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            int g=gcd(i,j);
            for(int m=1;m<=k;m++){
                ans+=gcd(m,g);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#include<cctype>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repp(i,j,n) for (int i = (j); i < (n); i++)
using namespace std;
typedef long long ll;
int main() {
	int k, a, b;
	cin >> k >> a >> b;
	int d = b / k;
	if (d*k >= a) {
		cout << "OK" << endl;
	}
	else {
		cout << "NG" << endl;
	}
	return 0;
}

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

typedef long long ll;

int main() {
	int a, b;
	cin >> a >> b;
	int cnt = 1;
	int value = 0;
	while (b > 0 && a > 0) {
		//cnt++;
		value += (b % 10) * cnt;
		b /= 10;
		cnt = cnt * 10;
		if (b == 0) {
			while (a > 0) {
				//cnt++;c
			//	cout << value << endl;
				value += (a % 10) * cnt;
				a /= 10;
				cnt = cnt * 10;
			}
		}
		//cout << value << endl;
	}
	int k = sqrt(value);
	if (k * k == value) {
		cout << "Yes";
	}else {
		cout << "No";
	}
}


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

using namespace std;
const int MAXN=1e5+5;
int n;
int h[MAXN];
long long dp[MAXN];
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>h[i];
	}
	dp[2]=abs(h[2]-h[1]);
	
	if(n>2)dp[3]=min(dp[2]+abs(h[3]-h[2]),dp[1]+abs(h[3]-h[1]));
	for(int i=4;i<=n;++i)
	{
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n]<<endl;
	
	return 0;
}


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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int n,m;
    scanf("%d%d",&n,&m);
    int mn =1e9,mx=-1;
    int l,r;
    for(int i=0;i<m;i++){
        scanf("%d%d",&l,&r);
        mn=min(mn,r);
        mx=max(mx,l);
    }
    if(mn<mx)puts("0");
    else printf("%d",mn-mx+1);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val n, t = sc.nextInt
  val ans = Vector.fill(n)((sc.nextInt, sc.nextInt))
      .sortBy(_._1)
      .collectFirst { case (c, tt) if tt <= t => c }
      .getOrElse("TLE")
  println(ans)
}


Measured memory_bytes: 25804
#include <bits/stdc++.h>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define msg(x) debug() << x
#define int long long

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
typedef long long ll;
signed main(){
  int n , k;
  cin >> n >> k;
  vector<int>v(n);
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  vector<int>S(n+1 , 0);

  for(int i=1;i<=n;i++){
     S[i] = (v[i-1] + S[i-1]);
  }
  for(int i=0;i<=n;i++){
    S[i] = (S[i] - i + k) % k;
  }
  dg1(S);
  map<int,int>cnt;
  int ans = 0;
  for(int i=0;i<=n;i++){
    if(i>=k){
      cnt[S[i-k]]--;
    }
    ans += cnt[S[i]];
    cnt[S[i]]++;
  }
  cout << ans << '\n';
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200100;
const int MOD = 1e9+7;
int p[MAXN];
double sum[MAXN];
int main() {
	int n,k;
	cin >> n >> k;
	sum[0] = 0;
	for(int i = 1; i <= n;i++){
		cin >> p[i];
		sum[i] = sum[i-1]+(p[i]+1)/2.0;
	}
	double max_sum = 0;
	for(int i = 0; i<= n - k; i++){
		max_sum = max(sum[i+k] - sum[i],max_sum);
	}
	printf("%.12f\n",max_sum);
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair <long long, int>, null_type, less<pair <long long, int> >, rb_tree_tag, tree_order_statistics_node_update>

const int N = 2e5 + 7;
map <long long, int> cnt;
long long a[N], n, k;
ordered_set s;

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i], a[i] -= k;
	long long res = 0, t = 0;
	for (int i = 1; i <= n; i++) {
		s.insert({-t, cnt[-t]});
		cnt[-t]++;
		t += a[i];
		res += i - s.order_of_key({-t, 0});
	}
	cout << res;


	return 0;
}









Measured memory_bytes: 28672
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		try (Scanner s = new Scanner(System.in)) {
			int n = s.nextInt();
			int k = s.nextInt();
			int x = s.nextInt();
			int y = s.nextInt();
			int ax = k, bx = 0;
			if (n > k) {
				bx = n - k;
			} else {
				ax = n;
			}
			System.out.println(ax * x + bx * y);
		}
	}
}


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

int main(){
   int a,b;
   scanf("%d %d",&a,&b);
 
   int c=a-1 ,ans=1;
  if(b == 1 ) ans = 0 ;
  else   while(a<b){
     a += c;
     
     ans ++;
     }
   printf("%d", ans);
}
   

Measured memory_bytes: 256
fn main(){
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let n: i64 = s.trim().parse().unwrap();
	let mut x: i64 = n;
	loop {
		if x % 2 == 0 && x % n == 0 {
			println!("{}", x);
			break;
		}
		x *= 2;
	}
}



Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
    string str;
    cin>>str;
    if(str=="SUN")
        cout<<'7'<<endl;
    if(str=="MON")
        cout<<'6'<<endl;
    if(str=="TUE")
        cout<<'5'<<endl;
    if(str=="WED")
        cout<<'4'<<endl;
    if(str=="THU")
        cout<<'3'<<endl;
    if(str=="FRI")
        cout<<'2'<<endl;
    if(str=="SAT")
        cout<<'1'<<endl;
    return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,sum=0,pos,par[110000],ra[110000];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
int diff_weight[110000];

int root(int x){
    if(par[x]==x){
        return x;
    }
    else{
     int r=root(par[x]);
     diff_weight[x]+=diff_weight[par[x]];
     return par[x]=r;
    }
}

int weight(int x){
    root(x);
    return diff_weight[x];
}

int diff(int x,int y){
    return weight(y)-weight(x);
}

bool merge(int x,int y,int w){
    w+=weight(x);w-=weight(y);
    x=root(x);y=root(y);
    if(x==y)return false;
    
    if(ra[x]<ra[y])swap(x,y),w=-w;
    
    if(ra[x]==ra[y])ra[x]++;
    par[y]=x;
    
    diff_weight[y]=w;
    
    return true;
}

bool same(int x,int y){
    return root(x)==root(y);
}


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

       cin >> n >> m;
       rep(i,n)par[i]=i;//いつもとは型が違う　--があるのはそのため
       rep(i,m){
           cin>>a>>b>>c;
           a--;b--;
           if(same(a,b)){
               int difff=diff(a,b);
               if(difff!=c){
                   Cout("No");
                   return 0;
               }
           }
           else{
               merge(a,b,c);
           }
       }
       Cout("Yes");
       
return 0;
}


Measured memory_bytes: 2304
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char in[110][110];
int cnt[26];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%s",in[i]);
	for(int i=0;i<a;i++)for(int j=0;j<b;j++)cnt[in[i][j]-'a']++;
	int t=0;
	int o=0;
	for(int i=0;i<26;i++){
		if(cnt[i]%2)o++;
		if(cnt[i]&2)t++;
	}
	if(a%2==0&&b%2==0){
		if(t||o)printf("No\n");else printf("Yes\n");
	}else if(a%2==0){
		if(o||t>a/2)printf("No\n");else printf("Yes\n");
	}else if(b%2==0){
		if(o||t>b/2)printf("No\n");else printf("Yes\n");
	}else{
		if(o!=1||t>(a-1)/2+(b-1)/2)printf("No\n");else printf("Yes\n");
	}
}

Measured memory_bytes: 128
import os
import sys
from collections import Counter

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

ans = 0
for n, cnt in Counter(A).items():
    if cnt >= n:
        ans += cnt - n
    else:
        ans += cnt
print(ans)


Measured memory_bytes: 18332
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    int n, k;
    cin >> n >> k;
    ll a[n];
    rep(i, n) cin >> a[i];
    
    ll res = 22222222222222;
    
    rep(i, 1<<n){
        // 見る対象の家をk個未満として計算する場合はスキップ
        if(__builtin_popcount(i) != k) continue;
        
        ll max_h = 0;
        ll num = 0;
        
        rep(j, n){
            if(i>>j & 1){
                if(a[j] <= max_h){
                    ++max_h;
                    num += max_h - a[j];
                }else{
                    max_h = a[j];
                }
            }
            max_h = max(max_h, a[j]);
        }
        
        // cout << i << "," << num << endl;
        // cout << num << endl;
        res = min(num, res);
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;

void main() {
	int n;
	scanf("%d\n", &n);
	auto hs = readln.chomp.split.to!(int[]);
	int m = hs[0];
	foreach(h; hs){
		if (m - h > 1) {
			write("No");
			return;
		}
		m = max(m, h);
	}
	write("Yes");
}


Measured memory_bytes: 4496
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
typedef long long ll;
const int INF = 1e9;
const ll LLINF = 1e18;

int main() {
    int N, Ma, Mb;
    cin>>N>>Ma>>Mb;
    
    int dp[500][500];
    mem(dp,-1);
    dp[0][0]=0;
    
    rep(k,N){
        int a,b,c; cin>>a>>b>>c;
        rrep(i,400){
            rrep(j,400){
                if(dp[i][j]>=0){
                    if( dp[i+a][j+b]==-1 || dp[i+a][j+b]>dp[i][j]+c ){
                        dp[i+a][j+b] = dp[i][j] + c;
                    }
                }
            }
        }
    }
    
    int minv=INF;
    for(int i=1; max(i*Ma,i*Mb) <= 400; i++){
        if( dp[i*Ma][i*Mb]!=-1 && dp[i*Ma][i*Mb]<minv) minv = dp[i*Ma][i*Mb];
    }
    
    if(minv==INF){ cout1(-1);
    }else{ cout1(minv);}
}

Measured memory_bytes: 1280