akhauriyash/Code-Regression huggingface dataset:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

H, W, D =na()
A = [na() for _ in range(H)]
Q = ni()
d = {}
for i in range(H):
    for j in range(W):
        d[A[i][j]] = (i, j)

dp = [0 for _ in range(H*W+1)]

for i in range(1, D+1):
    dp[i] = 0

for i in range(D+1, H*W+1):
    ni, nj = d[i]
    pi, pj = d[i - D]
    dp[i] = dp[i - D] + abs(ni - pi) + abs(nj - pj)

for i in range(Q):
    ans = 0
    l, r = na()
    ans = dp[r] - dp[l]
    print(ans)

Measured memory_bytes: 105744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> h(n), dp(n);
    rep(i, n) cin >> h[i];
    dp[0] = 0;
    rep2(i, 1, n) {
        ll res = INF;
        rep2(j,1, k + 1) {
            if(i - j < 0) break;
            chmin(res, dp[i-j] + abs(h[i] - h[i-j]));
        }
        //cout << res << endl;
        dp[i] = res;
    }
    cout << dp[n-1] << endl;
}

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

using namespace std;

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <iostream>
#include <stdio.h>

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pairll;

#define sll(x) scanf("%lld",&x);
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout)

#define ff first
#define ss second

inline ll readInt()
{
    ll in; scanf("%lld",&in); return in;
}

inline ll ADD(ll a, ll b, ll mod)
{
    return (a + b + mod + mod)%mod;
}

inline ll SUBS(ll a, ll b, ll mod)
{
    return (a-b+mod + mod) %mod;
}

inline ll MUL(ll a, ll b, ll mod)
{
    return (a*b + mod)%mod;
}

ll bigMod(ll base, ll power, ll mod)
{
    if(!power) return 1;
    if(!base) return 0;

    ll temp = bigMod(base, power/2, mod);

    if(power%2 == 0)
    {
        return (temp*temp)%mod;
    }
    else return (((temp*temp)%mod)*base)%mod;
}

inline ll modInverse(ll a, ll modp)
{
    return bigMod(a, modp -2, modp);
}

inline ll modInverseExtended(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        ll q = a / m; 
        ll t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
  

void autoinput()
{
    #ifndef ONLINE_JUDGE
    READ; 
    //WRITE;

    #endif
}

int main()
{
    autoinput();

    ll N;

    sll(N);

    vector<ll> leaves(N+1), freedom(N+1);

    freedom[0] = 1;

    for(ll i = 0; i <= N; i++)
    {
        sll(leaves[i]);
    }

    for(ll i = 0; i <= N; i++)
    {
        if(!i)
        {   
            freedom[i] -= leaves[i];
        }
        else
        {
            if(freedom[i-1] < INT64_MAX/10) freedom[i] = 2*freedom[i-1] - leaves[i];
            else freedom[i] = freedom[i-1];
        }

        if(freedom[i] < 0)
        {
            puts("-1"); return 0;
        }

    }

    vll tree(N+1);


    tree[N] = leaves[N];

    ll sum = tree[N];
    
    for(ll i = N-1; i >= 0; i--)
    {
        tree[i] = min(freedom[i],tree[i+1]);
        tree[i] += leaves[i];

        sum += tree[i];

    }

    printf("%lld\n",sum);

}



Measured memory_bytes: 5604
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<cctype>
#include<cstring>
#include<list>
#include<map>
#include<sstream>
#include<set>
#include<string>
#include<vector>
typedef long long ll;
using namespace std;
#define MN 300005
#define MM 600005
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define F2(i,a,b) for(int i=a;i<(b);++i)
#define RF(i,a,b) for(int i=a;i>=(b);--i)
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define int long long
vector<int> v;
int n;
void dfs(int x, int depth ) {
    if (depth >= 10) return;
    v.push_back(x);
    if (x % 10 != 0) dfs(x * 10 + (x - 1) % 10, depth + 1);
    dfs(x * 10 + (x) % 10, depth + 1);
    if (x % 10 != 9) dfs(x * 10 + (x + 1) % 10, depth + 1);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
   F2(i,0,9) dfs(i + 1, 0);
    sort(v.begin(), v.end());
    cout << v[n - 1] << endl;

    return 0;
}

Measured memory_bytes: 3444
#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;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll Nmax=1e9;
const double pi=acos(-1);



//基本的に勝つ手をだす．
//勝つ手がなければ，K回後に勝つ手以外を出す．

int main(){
  ll n,m,k;
  cin>>n>>m>>k;
  vector<ll> a2(n+1); //i冊目まで読むのに必要な時間．
  vector<ll> b2(m+1);
  ll time=0;
  ll temp;

  rep1(i,n){
    cin>>temp;
    time+=temp;
    a2[i]=time;
  }
  time=0;
  rep1(i,m){
    cin>>temp;
    time+=temp;
    b2[i]=time;
  }

  ll ans=0;

  if(a2[n]+b2[m]<=k){
    cout<<n+m<<endl;
    return 0;
  }

  rep(i,n+1){// aの机をi+1番目まで読む時，机bは何冊読めるか？
    ll jmax=m;
    ll jmin=0;
    ll jmid=m;

    if(a2[i]>k){//aのみですでに超えてる．
      continue;
    }
    ll k2=k-a2[i];


    if(b2[jmax]<=k2){
      ans=max(ans,ll(i+jmax));
      continue;
    }

    jmid=(jmax+jmin)/2;

    while(jmax-jmin>1){
      if(b2[jmid]<=k2){// j>=jmid
        jmin=jmid;
      }else{// j<jmid;
        jmax=jmid;
      }
      jmid=(jmax+jmin)/2;
    }


    if(b2[jmax]<=k2){
      ans=max(ans,ll(i+jmax));
    }

    if(b2[jmin]<=k2){
      ans=max(ans,ll(i+jmin));
    }

  }

  cout<<ans<<endl;





}


Measured memory_bytes: 6372
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int n, m;
	cin >> n >> m;
  vi box(n);
  vi red(n);
  rep(i,n){
    box[i] = 1;
    red[i] = 0;
  }
  red[0] = 1; 

  rep(i,m){
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    if(red[x] == 1){
      if(box[x] == 1){
        red[x] = 0;
      }
      red[y] = 1;
    }
    box[x]--;
    box[y]++;
  }
  int count = 0;
  rep(i,n) count += red[i];
  cout << count << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int> a(n + 1);
  for(int i = 1; i <= n; i++)
    cin >> a.at(i);
  int button = 1;
  int cnt = 1;
  for(int i = 1; i <= 100000; i++){
    if(a.at(button) == 2){
      cout << cnt;
      return 0;
    }
    button = a.at(button);
    cnt++;
  }
  cout << -1;
}

Measured memory_bytes: 3720
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,K=MAP()

edges=[]
for i in range(1, N):
    edges.append((1, i+1))

if K>(N-1)*(N-2)//2:
    print(-1)
    exit()
else:
    cnt=(N-1)*(N-2)//2
    for i in range(1, N):
        for j in range(i+1, N):
            if cnt==K: break
            edges.append((i+1, j+1))
            cnt-=1

print(len(edges))
for u, v in edges:
    print(u, v)


Measured memory_bytes: 3992
#include <iostream>
#include <string>

using namespace std;
int main() {
	string s, t;
	cin >> s;
	cin >> t;
	int n = s.length();
	for(int i = 0; i < n; i++) {
		if(s.substr(i, n - i) + s.substr(0, i) == t) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	int kkt = 89;
	while (kkt) {
		int n; scanf("%d", &n); if (n == 0) break;
		vector<string> vs(n); for (int i = 0; i < n; i++) cin >> vs[i];
		int pre = 0;
		int res = 0;
		for (int i = 0; i < n; i++) {
			if (vs[i] == "lu") {
				if (pre == 0) pre = 1;
				else if (pre == 2) res++, pre = 0;
				else pre = 0;
			}
			if (vs[i] == "ru") {
				if (pre == 0) pre = 2;
				else if (pre == 1) res++, pre = 0;
				else pre = 0;
			}
			if (vs[i] == "ld") {
				if (pre == 0) pre = 3;
				else if (pre == 4) res++, pre = 0;
				else pre = 0;
			}
			if (vs[i] == "rd") {
				if (pre == 0) pre = 4;
				else if (pre == 3) res++, pre = 0;
				else pre = 0;
			}
		}
		cout << res << "\n";
	}
	return 0;

}


Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        long sum = 0;
        int max = 0;
        a[0] = sc.nextInt();
        for (int i = 1; i < n; i++) {
            a[i] = sc.nextInt();
            sum += a[i] - a[i-1];
            max = Math.max(max, a[i] - a[i-1]);
        }
        int se = k - a[n-1] + a[0];
        sum += se;
        max = Math.max(max, se);
        System.out.println(sum-max);
    }
}

Measured memory_bytes: 67060
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 5e3 + 5, b = 31, b2 = 37, mod = 1e9 + 7;

string s;
int n, inv[N], inv2[N], pw[N], pw2[N], val[N], val2[N];

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

int mul(int a, int b){
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return 1ll * a * b % mod;
}

int fp(int b, int p){
    if(p == 0) return 1;
    int ret = fp(b, p >> 1);
    ret = mul(ret, ret);
    if(p&1) ret = mul(ret, b);
    return ret;
}

void pre(){
    int mul_inv = fp(b, mod - 2), mul_inv2 = fp(b2, mod - 2);
    inv[0] = inv2[0] = pw[0] = pw2[0] = 1;
    for(int i = 1; i < N; i++){
        pw[i] = mul(pw[i - 1], b);
        pw2[i] = mul(pw2[i - 1], b2);
        inv[i] = mul(inv[i - 1], mul_inv);
        inv2[i] = mul(inv2[i - 1], mul_inv2);
    }
}

pair<int, int> get_hash(int l, int r){
    int ret = val[r];
    if(l) ret = add(ret, -val[l - 1]);
    ret = mul(ret, inv[l]);

    int ret2 = val2[r];
    if(l) ret2 = add(ret2, -val2[l - 1]);
    ret2 = mul(ret2, inv2[l]);

    return {ret, ret2};
}

bool tmam(int len){
    map<pair<int, int>, int> mp;
    for(int i = 0; i + len - 1 < n; i++){
        int l = i, r = i + len - 1;
        auto x = get_hash(l, r);
        if(mp.find(x) == mp.end()){
            mp[x] = r;
        }
        else{
            if(mp[x] < l) return 1;
        }
    }
    return 0;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    pre();
    cin >> n >> s;
    for(int i = 0; i < n; i++){
        val[i] = add(mul(pw[i], s[i] - 'a' + 1), i ? val[i - 1] : 0);
        val2[i] = add(mul(pw2[i], s[i] - 'a' + 1), i ? val2[i - 1]: 0);
    }
    int low = 0, high = n / 2, mid, ans = 0;
    while(high >= low){
        mid = low + high >> 1;
        if(tmam(mid)){
            ans = mid;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    cout << ans;



    return 0;

}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n;
	cin >> n;
	vll a(n),ans(n);
	rep(i,n){
		cin >> a[i];
		if(i%2==0) ans[0]+=a[i];
		else ans[0]-=a[i];
	}
	rep(i,n-1){
		ans[i+1]=a[i]*2-ans[i];
	}
	for(auto&& e:ans){
		cout << e << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 2944
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        WeightedUnionFind wuf = new WeightedUnionFind(n);
        for(int i = 0; i < m; i++){
            int l = sc.nextInt()-1;
            int r = sc.nextInt()-1;
            long w = sc.nextLong();
            if(!wuf.union(l,r,w)){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}
class WeightedUnionFind{
    int[] parent;
    int[] rank;
    long[] weight;
    int[] size;
 
    public WeightedUnionFind(int size) {
		this.parent = new int[size];
		this.rank = new int[size];
        this.weight = new long[size];
		this.size = new int[size];
		
		for (int i = 0; i < size; i++) {
			makeSet(i);
		}
	}
	
	public void makeSet(int i) {
		parent[i] = i;
		rank[i] = 0;
		size[i] = 1;
	}
 
    public boolean union(int x, int y, long w) {
        w += getWeight(x);
        w -= getWeight(y);
        int xRoot = find(x);
        int yRoot = find(y);
        if(xRoot == yRoot){
            return getDistance(xRoot,yRoot) == w;
        } else if (rank[xRoot] > rank[yRoot]) { 
            parent[yRoot] = xRoot;
            size[xRoot] += size[yRoot];
            weight[yRoot] = w;
        } else if(rank[xRoot] < rank[yRoot]) {
            parent[xRoot] = yRoot;
            size[yRoot] += size[xRoot];
            weight[xRoot] = -w;
        } else if (xRoot != yRoot){
            parent[yRoot] = xRoot;
            size[xRoot] += size[yRoot];
            rank[xRoot]++; 
            weight[yRoot] = w;
        }
        return true;
    }
	
	public int find(int i) {
	    int p = parent[i];
	    if (i != parent[i]) {
	        parent[i] = find(parent[i]);
	        weight[i] += weight[p];
	    }
	    return parent[i];
	}
    
    public long getWeight(int i){
        find(i);
        return weight[i];
    }
    
    public long getDistance(int x, int y) {
        return getWeight(y) - getWeight(x);
    }
	
	public boolean same(int x, int y) {
		return find(x) == find(y);
	}
 
	public int size(int x) {
	    return size[find(x)];
	}
}


Measured memory_bytes: 154808
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back 
#define mp make_pair
#define sp ": "
#define cs "Case "
#define fi first
#define sn second 
#define po(x) x*x
/* STL */
#define vi vector<int>v
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxa(a) *max_element(a, a.size())
#define r(a) reverse(a.begin(),a.end())
/* loops */
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n)i=1;i<=(n);i++)
#define fa(i,a,n) for(__typeof(a)i=(a);i<=(b);i++)
/*Special*/
#define Ezio ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define db(something)   cerr<<#something<<" - "<<something<<"\n";         
int main()
{
  
   Ezio
   /*Variables*/
   /*Code*/
   int  t=0;
   int  n,m;
   int x; 
   vector<int>v;
   cin>>n>>m;
   fr(i,n){
     cin>>x;
     t+=x;
     v.pb(x);
   }
   
   sort(all(v),greater<int>());
   int  p=0;
   fr(i,sz(v)){
     if(v[i]*4*m>= t) p++;
     if(p==m){
       cout<<"Yes"<<endl;
       return 0;
     }
    
   }
   cout<<"No"<<endl;
   return 0;
}
    

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

using namespace std;

using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int          long long int
#define pll				   pair<int , int>

#define ALL(v)       v.begin(),v.end()
#define ALLR(v)      v.rbegin(),v.rend()
#define pii          3.14159265358979323
#define inf     		 LLONG_MAX
#define ones(x)      __builtin_popcount(x)
#define fill(a,b)    memset(a,b,sizeof(a))
#define mod 			   1000000007
#define hell         998244353

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a)
{
	return mod_pow(a , mod-2 , mod);
}

const int maxn = 1e5 + 5;

vector < vector < int > > a(maxn);

int vis[maxn];

void dfs(int u) {
  vis[u] = 1;

  for(auto v : a[u]) {
    if(!vis[v]) {
      dfs(v);
    }
  }
}

void solve()
{
      int n , m;

      cin >> n >> m;

      int x , y , z;

      for(int i = 0; i < m; ++i) {
        cin >> x >> y >> z;

        a[x].push_back(y);
        a[y].push_back(x);
      }

      int ans = 0;

      for(int i = 1; i <= n; ++i) {
        if(!vis[i]) {

          ans++;
          dfs(i);
        }
      }

      cout << ans;
}

signed main() {
    fast;

    int t = 1;

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

	  //cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}


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

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;

		while(!(str=br.readLine()).equals("0")){
			int n=Integer.parseInt(str);
			int mat[][] = new int[n+1][n+1];


			for(int i=0; i<n; i++){
				str = br.readLine();
				String strArray[] = str.split(" ");

				for(int j=0; j<n; j++){
					int f = Integer.parseInt(strArray[j]);
					mat[i][j] = f;
					mat[n][j] += f;
					mat[i][n] += f;
					mat[n][n] += f;
				}

			}
			for(int i=0; i<=n; i++){
				for(int j=0; j<=n; j++){
					System.out.printf("%5d",mat[i][j]);
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 22592
s = raw_input()

a = int(s[0:2])
b = int(s[2:4])

if 1 <= a <= 12 and 1 <= b <= 12:
    print("AMBIGUOUS")

elif 1 <= a <= 12:
    print("MMYY")

elif 1<= b <= 12:
    print("YYMM")

else:
    print("NA")

Measured memory_bytes: 2568
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>



using namespace std;

long long n, m;
long long a[11];
long long dp[10005];
vector<int> V;
vector<pair<int,int> >pd;
string s;
int k;



int num(int k){
  int answer = 0;
  if(k == 1){
    answer = 2;
  }else if(k == 2){
    answer = 5;
  }else if(k == 3){
    answer = 5;
  }else if(k == 4){
    answer = 4;
  }else if(k == 5){
    answer = 5;
  }else if(k == 6){
    answer = 6;
  }else if(k == 7){
    answer = 3;
  }else if(k == 8){
    answer = 7;
  }else if(k == 9){
    answer = 6;
  }
  return answer;
}

string solver(int n){
  for(int i = 1; i < n + 1; ++i){
    dp[i] = -10;
  }
  for(int i = 1; i < n + 1; ++i){
    for(int j = 0; j < m; ++j){
      if(i >= num(a[j])){
        dp[i] = max(dp[i - num(a[j])] + 1, dp[i]);
      }
    }
  }
  while(n > 0){
    //for(int i = 0; i < n; ++i){
      for(int j = 0; j < m; ++j){
        if(dp[n] == dp[n - num(a[j])] + 1 && n >= num(a[j])){
          if(dp[n] == 1){
            if(n != num(a[j])){
              continue;
            }
          }
          n -= num(a[j]);
          s += to_string(a[j]);
          break;
        }
      }
    //}
  }
  return s;
  
}



int main(){
  cin >> n >> m;
  for(int i = 0; i < m; ++i){
    cin >> a[i];
    //cout << num(a[i]) << endl;
    V.push_back(a[i]);
  }
  sort(V.begin(), V.end(), greater<int>());
  for(int i = 0; i < m; ++i){
    a[i] = V[i];
    //cout << a[i] << endl;
  }
  cout << solver(n) << endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
  ll n,b;
  cin>>n;ll a[n];fill(a,a+n,0);
  for(int i=0;i<n-1;i++){
    cin>>b;
    a[b-1]++;
  }
  for(int i=0;i<n;i++){
    cout << a[i]<<endl;
  }
}
  

Measured memory_bytes: 5196
n, r=map(int, input().split())
s=[int(input()) for _ in range(n)]
s.sort()
ans = s[-1] - s[0]
for i in range(n-r+1):
	if s[i+r-1] - s[i] < ans:
		ans = s[i+r-1] - s[i]
print(ans)

Measured memory_bytes: 7388
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def solv(N, M, SC):
    if N == 1 and M == 0:
        return 0
    ans = [" "] * N
    for s, c in SC:
        if ans[s-1] == " ":
            ans[s-1] = c
        elif ans[s-1] != c:
            return -1
    if ans[0] == " ":
        ans[0] = "1"
    elif ans[0] == "0" and N != 1:
        return -1
    ans = "".join(ans)
    ans = ans.replace(" ", "0")
    return int(ans)


if __name__ == "__main__":

    # N M
    # s_1 c_1
    # \vdots
    # s_M c_M
    #
    N, M = map(int, input().split())
    SC = []
    for _ in range(M):
        s, c = input().split()
        SC.append((int(s), c))

    ans = solv(N, M, SC)

    print(ans)


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

using namespace std;

#define endl '\n'
#define ll long long
#define int long long
const int32_t INFint = 1e9;
const ll INFll = 1e18;
const ll INF = 1LL << 60;
#define MOD 1000000007ll
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);

#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define foreach(it, v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)

#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb3(x, y, z) cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define deb4(a, b, c, d) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define deb5(a, b, c, d, e) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define deb6(a, b, c, d, e, f) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define nl cout << endl
// void bfs(vector<int> & dist , vector< vector<int> > & edges , int index )
// {
//     queue< pair<int,int> > q ;
//     dist[index] = -1 ; 
//     q.push(mp(index,0)) ;
//     while(!q.empty())
//     {
//         pair<int,int> top = q.front() ;
//         // deb2(top.ff,top.ss); 
//         q.pop() ; 
//         if(dist[top.ff] != -1 )
//             continue ;
//         // deb3(top.ff,top.ss,dist[top.ff]) ;
//         dist[top.ff] = top.ss ;
//         for(int i = 0 ; i < edges[top.ff].size(); i++ )
//         {
//             if (dist[edges[top.ff][i]] == -1)
//             {
//                 q.push(mp(edges[top.ff][i],dist[top.ff]+1));
//             }
//         }
//     } 
// }
int32_t main()
{
    fast;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    int t , m ;
    cin >> t >> m ;
    int ans = 0 ;
    for(int i = 0 ; i < m ; i++ )
    {
        int x ; cin>>x ; 
        ans += x ; 
    }    
    if(t-ans >= 0 )
        cout<<t-ans<<endl;
    else 
        cout<<-1<<endl;
}

Measured memory_bytes: 3648
#include <stdio.h>

int get_gcd(int x, int y);

int main(void)
{
	int x, y, gcd, lcm;
	while(scanf("%d %d", &x, &y)==2)
	{
		gcd = get_gcd(x, y);
		
		lcm = x / gcd * y;
		
		//printf("%d %d", gcd, lcm);
		printf("%d\n", gcd);
		
	}
	return 0;
}

int get_gcd(int x, int y)
{
	if(x<y)
	{
		y = y % x;
	}
	while(x >= 1 && y >= 1)
	{
		x = x % y;
		if(x == 0)
			break;
		
		y = y % x;
	}

	return (x + y);
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

char L[SIZE];
ll dp[2][SIZE];


int main(){

	scanf("%s",L);

	int len;
	for(len = 0; L[len] != '\0'; len++);

	for(int i = 0; i < 2; i++){
		for(int k = 0; k <= len; k++){
			dp[i][k] = 0;
		}
	}

	dp[true][0] = 2;//dp[Lと一致しているか][Lのインデックス] = 場合の数
	dp[false][0] = 1;

	for(int i = 1; i < len; i++){
		//trueからの遷移
		if(L[i] == '1'){

			dp[true][i] = dp[true][i-1]*2; //(a,b) = (1,0),(0,1)
			dp[true][i] %= MOD;

			dp[false][i] += dp[true][i-1]; //この桁は(a,b) = (0,0)
			dp[false][i] %= MOD;

		}else{ //L[i] == '0'

			dp[true][i] = dp[true][i-1]; //(a,b) = (0,0)
		}

		dp[false][i] += dp[false][i-1]*3; //(a,b) = (1,0),(0,1),(0,0)
		dp[false][i] %= MOD;
	}

	printf("%lld\n",(dp[true][len-1]+dp[false][len-1])%MOD);

	return 0;
}


Measured memory_bytes: 1920
local PairingHeap={}

PairingHeap.meld=function(self,a,b)
    if not a then
        return b
    elseif not b then
        return a
    elseif a[1]<b[1] then
        b[4]=a[3]
        a[3]=b
        return a
    else
        a[4]=b[3]
        b[3]=a
        return b
    end
end

PairingHeap.pair=function(self,a)
    local b,c,d,e
    while a do
        c=false
        b=a
        a=a[4]
        b[4]=false
        if a then
            c=a
            a=a[4]   
            c[4]=false
        end
        b=self:meld(b,c)
        b[4]=d
        d=b
    end
    while d do
        e=d
        d=d[4]
        a=self:meld(a,e)
    end
    return a
end

PairingHeap.empty=function(self)
    return not self.root
end

PairingHeap.push=function(self,key,value)
    local root=self.root
    if root and root[1]<key then
        root[3]={
            key,
            value,
            false,
            root[3],
        }
    else
        self.root={
            key,
            value,
            root,
            false,
        }
    end
end

PairingHeap.top=function(self)
	return self.root[2]
end

PairingHeap.pop=function(self)
    local root=self.root
    self.root=self:pair(root[3])
    for i=1,4 do
        root[i]=false
    end
    table.insert(self,root)
end

PairingHeap.join=function(self,other)
    local a=self.root
    local b=other.root
    if a[1]<b[1]then
        b[4]=a[3]
        a[3]=b
    else
        a[4]=b[3]
        b[3]=a
        self.root=b
    end
    return self
end

PairingHeap.new=function(self)
    local obj={}
    setmetatable(obj,{__index=PairingHeap})
    return obj
end

----------

local n=io.read("n")
local a={}
for i=1,3*n do
    a[i]=io.read("n")
end

local lsum={[0]=0}
local minq=PairingHeap:new()
for i=1,n do
    local A=a[i]
    lsum[i]=lsum[i-1]+A
    minq:push(A,A)
end
for i=n+1,2*n do
    local P=minq:top()
    local A=a[i]
    if A>P then
        lsum[i]=lsum[i-1]+A-P
        minq:push(A,A)
        minq:pop()
    else
        lsum[i]=lsum[i-1]
    end
end

local rsum={[0]=0}
local maxq=PairingHeap:new()
for i=1,n do
    local A=a[3*n-i+1]
    rsum[i]=rsum[i-1]+A
    maxq:push(-A,A)
end
for i=n+1,2*n do
    local P=maxq:top()
    local A=a[3*n-i+1]
    if A<P then
        rsum[i]=rsum[i-1]+A-P
        maxq:push(-A,A)
        maxq:pop()
    else
        rsum[i]=rsum[i-1]
    end
end
local max=-10^16
for i=n,2*n do
    max=math.max(max,lsum[i]-rsum[3*n-i])
end
print(max)

Measured memory_bytes: 52420
#include <bits/stdc++.h>
#define INF 1LL<<60
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int w,h;
ll K;
int n;
int x[100005],y[100005];
vector<int> vec[5005];
bool flag[10005];
ll cost[5005][3];
ll dp[5005];

ll calc(int y){
	for(int i=0;i<=(w+1)/2;i++){
		dp[i]=INF;
	}
	dp[0]=0;
	sort(vec[y].begin(),vec[y].end());
	memset(flag,false,sizeof(flag));
	for(int i=0;i<vec[y].size();i++){
		flag[vec[y][i]]=true;
	}
	for(int i=0;i<(w+1)/2;i++){
		dp[i+1]=min(dp[i+1],dp[i]+(flag[i*2]?2:1));
		dp[i+2]=min(dp[i+2],dp[i]+(flag[i*2+1]?4:2));
	}
	return dp[(w+1)/2];
}

int main(void){
	scanf("%d%d%lld",&w,&h,&K);
	if((w+1)/2LL>K){
		printf("-1\n");
		return 0;
	}
	K-=(w+1)/2LL;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&x[i],&y[i]);
		if(y[i]%2==1)continue;
		y[i]-=2;
		y[i]/=2;
		x[i]--;
		vec[y[i]].push_back(x[i]);
	}
	ll ans=0;
	ll pips=0;
	for(int i=0;i<h/2;i++){
		ans+=calc(i);
		pips+=(w+1)/2LL;
	}
	ll dcp=ans-pips;
	ans-=min(dcp,K)*2LL;
	K-=dcp;
	ans-=max(0LL,K);
	printf("%lld\n",max(ans,0LL));
	return 0;
}


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

int main() {
  int n;
  
  cin >> n;
  
  vector<string> keihin(n);
  
  for(int i=0; i<keihin.size(); i++){
    cin >> keihin.at(i);
  }
  
  sort(keihin.begin(),keihin.end());
  keihin.erase(unique(keihin.begin(), keihin.end()), keihin.end());
  
  cout << keihin.size();

  
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int main() {
	long long int a, sum = 1;
	cin >> a;
	for (int i = 1; i <= a; i++) {
		sum = (sum*i)%1000000007;
	}
	printf("%lld\n", sum);
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
#define mp make_pair
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
    ll n;
    cin >> n;
    ll ans=0;
    vl a(n);
    rep(i,n){
        cin >> a[i];
    }
    vl cnt(1000001,0);
    rep(i,n){
        cnt[a[i]]++;
    }
    rep(i,1000001){
        if(cnt[i]>=1){
          if(cnt[i]==1){
            ans++;
          }
            ll k=i;
            while(k<=1000000){
                cnt[k]=0;
                k+=i;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 12692
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    string O,E; cin>>O>>E;

    string ans="";
    int o=0,e=0;
    while(o<O.size() || e<E.size()){
        if(o<O.size()) ans+=O.at(o);
        if(e<E.size()) ans+=E.at(e);
        o++; e++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Vector
{
    internal double X { get; set; }
    internal double Y { get; set; }
}
class Pg
{
    static void Main()
    {
        string line;
        while (!string.IsNullOrEmpty(line = Console.ReadLine()))
        {
            var n = line.Trim().Split().Select(double.Parse).ToArray();
            var A1 = new Vector { X = n[0], Y = n[1] };
            var A2 = new Vector { X = n[2], Y = n[3] };
            var B1 = new Vector { X = n[4], Y = n[5] };
            var B2 = new Vector { X = n[6], Y = n[7] };
            Console.WriteLine(B2.Y >= A1.Y&& B2.X >= A1.X&&
                              A2.Y >= B1.Y&& A2.X >= B1.X
                               ? "YES" : "NO");
        }
    }
}




Measured memory_bytes: 18324
import sys
import math
input = sys.stdin.readline

def main():
    N = int(input())
    A = [int(input()) for i in range(N)]

    left = [0 for i in range(N)]
    right = [0 for i in range(N)]
    left[0] = A[0]
    right[-1] = A[-1]
    for i in range(1, N):
        left[i] = max(left[i-1], A[i])
        right[N-1-i] = max(right[N-i], A[N-1-i])

    for i in range(N):
        if i == 0:
            print(right[1])
        elif i == N-1:
            print(left[-2])
        else:
            print(max(left[i-1], right[i+1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 15612
# solution
k=int(input())

from collections import deque
todo = deque([i for i in range(1, 10)])
count = 0

while len(todo) > 0:
    value = todo.popleft()
    value_digit1 = value % 10
    count += 1
    if count == k:
        print(value)
        break
    if value_digit1==0:
        todo.append(10*value)
        todo.append(10*value+1)
    elif value_digit1==9:
        todo.append(10*value+8)
        todo.append(10*value+9)
    else:
        todo.append(10*value+value_digit1-1)
        todo.append(10*value+value_digit1)
        todo.append(10*value+value_digit1+1)

Measured memory_bytes: 11916
using System;
using System.Linq;

class B
{
    private static char[] c;
    private static int[] d1 = new int[3] { 0, 0, 0 };
    private static int[] d2 = new int[3] { -1, -1, -1 };
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            c = Console.ReadLine().ToCharArray();

            d1[2] = d1[1];
            d2[2] = d2[1];

            d1[1] = d1[0];
            d2[1] = d2[0];

            d1[0] = c[0] - '0';
            d2[0] = c[2] - '0';

            if (d1[0] == d2[0] && d1[1] == d2[1] && d1[2] == d2[2])
            {
                Console.WriteLine("Yes");
                return;
            }
        }

        Console.WriteLine("No");
    }
}

Measured memory_bytes: 27332
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

int getMinRewriteNum(const std::vector<int> org_values) {
  std::unordered_map<int, int> odd_counter;
  std::unordered_map<int, int> even_counter;

  for (int i = 0; i < static_cast<int>(org_values.size()); ++i) {
    auto &counter = (i % 2 == 0) ? odd_counter : even_counter;
    auto iter = counter.find(org_values[i]);
    if (iter == counter.end()) {
      counter[org_values[i]] = 1;
    } else {
      ++iter->second;
    }
  }
  const auto max_odd_elem = std::max_element(
      odd_counter.begin(), odd_counter.end(),
      [](const std::pair<int, int> &l, const std::pair<int, int> &r) {
        return l.second < r.second;
      });
  const auto max_even_elem = std::max_element(
      even_counter.begin(), even_counter.end(),
      [](const std::pair<int, int> &l, const std::pair<int, int> &r) {
        return l.second < r.second;
      });
  const int elem_max = static_cast<int>(org_values.size()) / 2;
  if (max_odd_elem->first != max_even_elem->first) {
    return (elem_max - max_odd_elem->second) +
           (elem_max - max_even_elem->second);
  } else {
    const auto second_max_odd_value =
        (odd_counter.size() == 1)
            ? 0
            : std::max_element(odd_counter.begin(), odd_counter.end(),
                               [&max_odd_elem](const std::pair<int, int> &l,
                                               const std::pair<int, int> &r) {
                                 if (l.first == max_odd_elem->first) {
                                   return true;
                                 } else if (r.first == max_odd_elem->first) {
                                   return false;
                                 }
                                 return l.second < r.second;
                               })
                  ->second;
    const auto second_max_even_value =
        (even_counter.size() == 1)
            ? 0
            : std::max_element(even_counter.begin(), even_counter.end(),
                               [&max_even_elem](const std::pair<int, int> &l,
                                                const std::pair<int, int> &r) {
                                 if (l.first == max_even_elem->first) {
                                   return true;
                                 } else if (r.first == max_even_elem->first) {
                                   return false;
                                 }
                                 return l.second < r.second;
                               })
                  ->second;

    const int value1 =
        (elem_max - max_odd_elem->second) + (elem_max - second_max_even_value);
    const int value2 =
        (elem_max - max_even_elem->second) + (elem_max - second_max_odd_value);
    return std::min(value1, value2);
  }
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> v[i];
  }
  std::cout << getMinRewriteNum(v) << std::endl;
  return 0;
}


Measured memory_bytes: 5144
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
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; }
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    ll N;cin>>N;
    const ll sz=110000;
    ll a[3][sz];
    ll dp[3][sz];
    REP(i,N){
        REP(k,3){
            dp[k][i]=0;
            cin>>a[k][i];
        }
    }
    REP(i,N){
        REP(k,3){
            chmax(dp[k][i+1],
                max(dp[(1+k)%3][i]+a[k][i],dp[(2+k)%3][i]+a[k][i])
            );
        }
    }
    ll ans=0;
    REP(k,3)chmax(ans,dp[k][N]);
    cout<<ans<<"\n";
}

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

using namespace std;
using ll=int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi=vector<int>;
using vii=vector<vi>;
using vl=vector<ll>;
using vll=vector<vl>;
using tpi=tuple<int, int, int>;

int main() {
    using miv=map<int, vi>;
    int N;
    cin >> N;

    using vti=vector<tpi>;
    vti edge(N - 1);
    vii table(N + 1);
    vi parents(N + 1);
    auto root = N + 1;
    for (auto i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        edge[i] = make_tuple(a, b, 0);
        table[a].push_back(i);
        parents[b] = i;
        root = min(root, a);
    }

    queue<int> q;
    q.push(root);
    auto pc = 0;
    auto max_color = 0;
    while (!q.empty()) {
        auto top = q.front();
        q.pop();

        auto color = 1;
        for (auto i:table[top]) {
            if (color == pc) {
                color++;
            }
            get<2>(edge[i]) = color;
            max_color = max(max_color, color);

            color++;
            q.push(get<1>(edge[i]));
        }
        if (!q.empty()) {
            auto p_node_i = parents[q.front()];
            pc = get<2>(edge[p_node_i]);
        }
    }

    cout << max_color << endl;
    for (auto &&e:edge) {
        cout << get<2>(e) << endl;
    }
    return 0;
}


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

int main() {
  int a;
  int b;
  int c;
  int d;
  int e;
  
  cin >> a;
  
  b = a / 1000;
  c = a % 1000;
  d = c /100;
  c = c % 100;
  e = c / 10;
  c = c % 10;

  if (b == d) {
    if (d == e) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else if (d == e) {
    if (e == c) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int w, h, dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}, ans;
bool flag;
void dfs(vector<string> s, int d, int x, int y) {
	if(d == 10) return;
	REP(i, 4) {
		//cout << "i:" << i << endl;
		int nx = x, ny = y;
		if(IN(0, w, nx+dx[i]) && IN(0, h, ny+dy[i]) && s[ny+dy[i]][nx+dx[i]] == '1')
			continue;
		//cout << nx << " " << ny << " " << s[ny][nx] << " " << (0<=nx&&nx<w&&0<=ny&&ny<h) << endl;
		while(0<=nx&&nx<w&&0<=ny&&ny<h) {
			//cout << nx << " " << ny << endl;
			if(s[ny][nx] == '1') {
				vector<string> t = s;
				t[ny][nx] = '0';
				dfs(t, d+1, nx-dx[i], ny-dy[i]);
				break;
			} else if(s[ny][nx] == '3') {
				ans = min(ans, d+1);
				return;
			}
			nx += dx[i], ny += dy[i];
		}
	}
}

signed main(void)
{
	while(true) {
		cin >> w >> h;
		if(!w && !h) break;
		vector<string> maze;
		int sx, sy;
		REP(i, h) {
			string tmp = "";
			REP(j, w) {
				char ss;
				cin >> ss;
				if(ss == '2') sx = j, sy = i;
				tmp += ss;
			}
			maze.PB(tmp);
		}
		ans = INF;
		dfs(maze, 0, sx, sy);
		if(ans == INF) cout << -1 << endl;
		else cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 3008
def height(cx, cy, D):
    for x, y, h in D:
        if h <= 0: continue
        return h + abs(x-cx) + abs(y-cy)
    return 0

def valid(cx, cy, H, D):
    for x, y, h in D:
        if h != max(H - abs(x-cx) - abs(y-cy), 0):
            return False
    return True

def solve():
    for cy in range(0, 101):
        for cx in range(0, 101):
            H = height(cx, cy, D)
            if valid(cx, cy, H, D):
                return (cx, cy, H)
    return (0, 0, 0)

N = int(input())
D = []
for i in range(N):
    x, y, h = map(int, input().split())
    D.append((x, y, h))
cx, cy, H = solve()
print(cx, cy, H)



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

int main()
{
    int a;
    cin >> a;
    int hour = a / 3600;
    int mi = a % 3600 / 60;
    int sec = a - hour*3600 - mi * 60;
    cout << hour << ":" << mi << ":" << sec << endl;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;

int main(){
    ll N, A, B; cin >> N >> A >> B;

    if ((B-A)%2 == 0){
        cout << (B-A)/2 << endl;
    }
    else{
        ll ans = 0;
        if ((N-B) < (A-1)){
            ans += N-B+1;
            A += (N-B)+1;
            ans += (N-A)/2;
        }
        else{
            ans += A;
            B-= (A);
            ans += (B-1)/2;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3604