akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    CIN(H);
    CIN(W);
    char A = 'A';
    for(int a = 0;a < H;a++){
        for(int b = 0;b < W;b++){
            SCIN(str);
            if(str ==  "snuke"){
                char w = b+A;
                cout<<w<<a+1<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import sys


def solve(ppp):
    section_start = -1
    moved_left_max = 0
    moved_right_max = 0
    prev = True

    for i, p in enumerate(ppp, start=1):
        if i == p:
            if prev:
                moved_left_max = 0
                moved_right_max = 0
                section_start = -1
            prev = True
        else:
            if not prev:
                if moved_left_max > i - 1:
                    return False

                moved_left_max = 0
                moved_right_max = 0
                section_start = i

            if section_start == -1:
                section_start = i

            if i > p:
                if section_start > p:
                    return False
                if moved_right_max > p:
                    return False
                moved_right_max = p
            else:
                if moved_left_max > p:
                    return False
                moved_left_max = p

            prev = False
    return True


n, *ppp = map(int, sys.stdin)
print('Yes' if solve(ppp) else 'No')


Measured memory_bytes: 14996
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int N; cin >> N;
    int ans = N % 1000;
    if(ans == 0){
        cout << 0 << endl;
    }
    else{
        
        cout << 1000 - ans << endl;

    }

}

Measured memory_bytes: 3644
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)

a, b, x = getNM()
print(b // x - (a - 1) // x)

Measured memory_bytes: 38256
n,m=map(int,input().split())
x,y=[],[]
x=sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:x[0])
#小さい方から買うけど、余ったら減らす

#print(x)
for i in range(n):
    #print(m)
    c=m-x[i][1]
    if c<=0:
        s=0
        for j in range(i+1):
            #print(x[i])
            s+=x[j][0]*x[j][1]
        #print(s)
        print(s+c*x[i][0])
        break
    m=c


Measured memory_bytes: 29796
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) // <a> must be sorted in advance

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

int N;
vector<int> d;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) {
        int x;
        cin >> x;
        d.pb(x);
    }

    sort(ALL(d));
    UNIQUE(d);
    cout << SZ(d) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vs = vector<string>;
template <typename T>
using ost = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
#define forn(i,n) for(int i=0; i<int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ff first
#define ss second

const int N=128;

ll dp[N][N];

int main() {
    ios::sync_with_stdio(false);
    dp[0][0] = 1;
    for (int i=1; i<N; i++) {
        dp[i][0] = 1;
        for (int j=1; j<=i; j++)
            dp[i][j] = dp[i-1][j] + dp[i-1][j-1];
    }
    int n, p;
    cin >> n >> p;
    int odd=0, even=0;
    for (int x; cin >> x; x%2? odd++:even++);
    ll ans=0;
    for (int o=p; o<=odd; o+=2)
        for (int e=0; e<=even; e++)
            ans += dp[odd][o]*dp[even][e];
    cout << ans << '\n';
}


Measured memory_bytes: 384
// inputに入力データ全体が入る
function Main(input) {
    input = input.split(' ');
    //文字列から10進数に変換するときはparseIntを使います
    var a = parseInt(input[0], 10);
    var b = parseInt(input[1], 10);
    
    if (a < 9 && b < 9) {
        console.log('Yay!');
    } else {
        console.log(':(');
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 8652
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 0

class state{
  public:
	int w,t,p;

	bool operator<(const state& a)const{
		if( t==a.t ) return p<a.p;
		return t<a.t;
	}
};
	
int main(){
	int n,m,a,b;
	state hito[256];
	
	while(scanf("%d",&n),n){
		int sz = 0;
		rep(i,n){
			scanf("%d%d%d",&m,&a,&b);
			hito[sz].w = m; hito[sz].t = a; hito[sz].p = 1;
			sz++;
			hito[sz].w = m; hito[sz].t = b; hito[sz].p = 0;
			sz++;
		}
		sort(hito,hito+sz);
#if DEB		
		rep(i,sz){
			printf("%d %d %d\n",hito[i].w, hito[i].t, hito[i].p);
		}
#endif
		int cnt = 0;
		int sum = 0;
		bool f = true;
		rep(i,sz){
			if( hito[i].p == 1){
				sum += hito[i].w;
				if( sum>150 ){ f=false; break; }
			}else{
				sum -= hito[i].w;
			}
#if DEB
			printf("t:%d  sum:%d\n",hito[i].t, sum);
#endif			
		}

		puts(f?"OK":"NG");
	}
	return 0;
}

Measured memory_bytes: 0
import sys
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
XY = [lr() for _ in range(N)]
XY.sort()
answer = float('inf')
# 端の4点、まずはx軸の2点を選ぶ
for left,right in itertools.combinations(range(N),2):
  width = XY[right][0] - XY[left][0]
  pts = sorted(XY[left:right+1], key = lambda xy: xy[1])
  if len(pts) < K:
    continue
  for D in range(len(pts) - K + 1):
    y_max = pts[D+K-1][1]
    y_min = pts[D][1]
    area = (y_max - y_min) * width
    if area < answer:
      answer = area
    
print(answer)

Measured memory_bytes: 3064
// https://beta.atcoder.jp/contests/abc109

#define SUBMIT
//#define DEBUG

#include <bits/stdc++.h>
using namespace std;

int a[500 + 1][500 + 1];
int H, W;

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    stringstream stream(R"(2 3
1 2 3
0 1 1
)");
#endif
    stream >> H >> W;
    for (int y = 1; y <= H; ++y) {
        for (int x = 1; x <= W; ++x) {
            stream >> a[y][x];
        }
    }

    vector<string> ans;
    for (int y = 1; y <= H; ++y) {
        for (int x = 1; x <= W; ++x) {
            if (y == H && x == W) continue;

            if (a[y][x] % 2 == 1) {
                a[y][x]--;

                stringstream ss;
                // move right or down if odd
                if (x < W) {
                    a[y][x + 1]++;
                    ss << y << " " << x << " " << y << " " << (x + 1);
                }
                else {
                    a[y + 1][x]++;
                    ss << y << " " << x << " " << (y + 1) << " " << x;
                }

                ans.push_back(ss.str());
            }
        }
    }

    cout << ans.size() << endl;
    for (auto s : ans) cout << s << endl;
#ifdef DEBUG
    cout << "debug" << endl;
    for (int y = 1; y <= H; ++y) {
        for (int x = 1; x <= W; ++x) {
            cout << a[y][x] << " ";
        }
        cout << endl;
    }
#endif
    return 0;
}

Measured memory_bytes: 9972
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
typedef pair<int,int>pi;

const int N=100005,inf=0x3f3f3f3f;

int n,m,col[N],t[N],a[N],num[N];
vector<int>e[N];
pi f[N];

void build(int x,int fa){
	num[x]=col[x]!=inf;f[x]={-inf,inf};
	for(int v:e[x])if(v!=fa)build(v,x),num[x]+=num[v];
}

inline bool ok(int x,int y){
	if(!num[x])return true;return y>=f[x].fi&&y<=f[x].se&&(y&1)==(f[x].fi&1);
}

void dfs(int x,int fa){
	if(!num[x])return;
	int cur=0;
	for(int v:e[x])if(v!=fa&&num[v]){
		dfs(v,x);
		if(cur){
			int fb=~f[x].fi&1;
			if((f[v].fi&1)!=fb)puts("No"),exit(0);
			f[x].fi=max(f[x].fi,f[v].fi-1);
			f[x].se=min(f[x].se,f[v].se+1);
			if((f[x].fi&1)==fb)f[x].fi++;
			if((f[x].se&1)==fb)f[x].se--;
			if(f[x].fi>f[x].se)puts("No"),exit(0);
		}else f[x]={f[v].fi-1,f[v].se+1};
		cur+=num[v];
	}
	if(col[x]!=inf){
		if(cur&&!ok(x,col[x]))puts("No"),exit(0);
		f[x]={col[x],col[x]};
	}
}

void check(int x,int fa,int r){
	a[x]=r;
	for(int v:e[x])if(v!=fa){
		if(ok(v,r-1))check(v,x,r-1);else check(v,x,r+1);
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),e[u].pb(v),e[v].pb(u);
	scanf("%d",&m);
	memset(col,0x3f,(n+1)<<2);
	for(int i=1,p;i<=m;i++)scanf("%d",&p),scanf("%d",&col[p]);
	build(1,0);
	dfs(1,0);
	puts("Yes");
	check(1,0,f[1].fi);
	for(int i=1;i<=n;i++)printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string s;
  cin>>s;
  int n =s.size();
  string ans="yes";
  for (int i = 0; i < n; i++) {
 for (int j = i+1; j < n; j++) {
 if(s[i]==s[j]){
   ans="no";
 }
}
}
cout<<ans<<endl;
 
 
}

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

int main(void)
{
    char day[10];
    scanf("%s",day);
    if(strcmp(day,"Sunny")==0) printf("Cloudy");
    else if(strcmp(day,"Cloudy")==0) printf("Rainy");
    else printf("Sunny");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 100005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d:\n", t)
#define pii pair<int, int>
#define MOD 1000000007
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(int N, int pos){return (bool)(N & (1<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    int n;
    cin>>n;
    ll cnt[10][10];
    memset(cnt, 0, sizeof(cnt));
    for(int i = 1; i <= n; i++)
    {
        int first;
        int last = i % 10;
        int cur = i;
        while(cur > 0)
        {
            first = cur % 10;
            cur = cur / 10;
        }
        cnt[first][last]++;
    }
    ll ans = 0;
    for(int i = 0; i < 10; i++)
        for(int j = 0; j < 10; j++)
            ans+=(cnt[i][j] * cnt[j][i]);
    cout<<ans<<endl;

    //End();
    return 0;
}


Measured memory_bytes: 256
N=int(input())
A=[int(input()) for _ in range(N)]
c=0
m=0
for i in range(N):
  if m<A[i]:
    m=A[i]
    d=i
B=A
B[d]=0
for i in range(N):
  if i==d:
    print(max(B))
  else:
    print(m)

Measured memory_bytes: 12520
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC diagnostic ignored "-Wunknown-pragmas"

#include <bits/stdc++.h>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define ALL(x)          (x).begin(), (x).end()
#define rALL(x)         (x).rbegin(), (x).rend()
#define REP(i, n)       for(int i = 0; (i) < (int)(n); (i)++)
#define rREP(i, n)      for(int i = n - 1; (i) >= 0 ; (i)--)
#define FOR(i, a, b)    for(int i = (a); (i) < (int)(b) ; (i)++)
#define CtoI(c)         int((c)) - int('0')

//functions=============
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };



/*--------additional--------*/

#pragma region abc
#pragma endregion

/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

	int a, b; cin >> a >> b;
  	cout << a * b << endl;

return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
using namespace std;
int main(void){
  string s;
  cin>>s;
  int a,z;
  size_t size=s.length();
  for(int i(0);i<size;i++){
    if(s[i]=='A'){
      a=i;
      break;
    }
  }
  for(int i(size-1);i>=0;i--){
    if(s[i]=='Z'){
      z=i;
      break;
    }
  }
  cout<<z-a+1<<endl;
  return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define cost first
#define from second.first
#define to second.second
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

int n;
ll a,b,h[123456];

bool judge(ll x){
	int i;
	ll cnt=0ll;
	for(i=0; i<n; ++i){
		if(h[i] <= x*b){
			continue;
		}
		cnt += ((h[i]-x*b-1)/(a-b))+1;
	}
	return (cnt <= x);
}

int main(void){
	int i;
	ll hmx=-INF,l,r,m;
	cin >> n >> a >> b;
	for(i=0; i<n; ++i){
		cin >> h[i];
		hmx = max(hmx,h[i]);
	}
	r = ((hmx-1)/b)+1;
	l = 0;
	while(r - l > 1){
		m = (l + r)/2;
		if(judge(m)){
			r = m;
		}else{
			l = m;
		}
	}
	cout << ((judge(l))?l:r) << endl;
	return 0;
}

Measured memory_bytes: 1152
N = int(input())
s = [input() for i in range(N)]
import collections
s1 = sorted(s)
 
c = collections.Counter(s1)
s2 = c.most_common()
 
s3 = []
a = 0
for i in range(len(s2)):
    if s2[0][1] == s2[i][1]:
        s3.append(s2[i][0])
s4 = sorted(s3)
for i in range(len(s4)):
    print(s4[i])

Measured memory_bytes: 50896
import java.util.Arrays;

public class Main {

  private static void solve() {
    int n = ni();

    String[] a = new String[n];
    for (int i = 0; i < n; i++) {
      char[] s = ns();
      Arrays.sort(s);
      a[i] = new String(s);
    }

    Arrays.sort(a);
    long ret = 0;
    long cnt = 0;
    String pre = "";
    for (int i = 0; i < n; i++) {
      if (!pre.equals(a[i])) {
        ret += cnt * (cnt - 1) / 2;
        cnt = 1;
      } else {
        cnt++;
      }
      pre = a[i];
    }
    ret += cnt * (cnt - 1) / 2;

    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



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

int main() {
	int a,b,c,x;
	cin >> a >> b >> c;
	if(b < a){
		x = a;
		a = b;
		b = x;
	}
	if(b > c){
		x = b;
		b = c;
		c = x;
	}
	if(b < a){
		x = a;
		a = b;
		b = x;
	}
	cout << a << " " << b << " " << c << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    ll n, m;
    double res = 0;
    cin >> n >> m;

    cout << (m*1900 + (n-m)*100) * pow(2, m) << endl;

    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
S = input()
ans = []
cur = n
temp = 0
flag = True
while cur != 0:
    kouho = 0
    for i in range(1,m+1):
        if cur-i >= 0:
            if S[cur-i] == '0':
                kouho = max(kouho, i)
    if kouho == 0:
        flag = False
        break
    else:
        ans.append(kouho)
        cur = cur-kouho
if flag:
    ans.reverse()
    print(' '.join(map(str, ans)))
else:
    print(-1)


Measured memory_bytes: 49908
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<queue>
#define LL long long
#define M 200020
using namespace std;
LL read(){
    LL nm=0ll,fh=1ll;char cw=getchar();
    for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
    for(;isdigit(cw);cw=getchar()) nm=nm*10ll+(cw-'0');
    return nm*fh;
}
void fad(){puts("Impossible");exit(0);}
LL n,m,tpe,pos,h1,h2,st1,st2,v[M],ans,cnt,gt;
bool ff=false;
struct Leftist_tree{
    LL ls,rs,fa,dst,num,sz;
    void init(){ls=rs=fa=dst=0ll,sz=1ll,num=read();}
}p[M];
struct node{
	LL pt;
	bool operator <(const node&ot)const{return p[pt].sz<p[ot.pt].sz;}
}tmp;
priority_queue<node> Q;
LL find(LL x){return p[x].fa==0?x:find(p[x].fa);}
LL merge(LL x,LL y){
    if(x*y==0) return x+y;
    if(p[x].num>p[y].num) return merge(y,x);
    if(p[x].num==p[y].num&&x>y) return merge(y,x);
    LL L=p[x].ls,R=p[x].rs;
    LL tot=p[x].sz+p[y].sz;
    LL k=merge(R,y);
    p[k].fa=x,p[x].rs=k;
    if(p[k].dst>p[L].dst) swap(L,k);
    p[x].dst=p[k].dst+1;
    p[x].ls=L,p[x].rs=k,p[x].sz=tot;
    return x;
}
LL del(LL x){
    LL lson=p[x].ls,rson=p[x].rs;
    p[lson].fa=p[rson].fa=0ll;
    p[x].num=-1;
	return merge(lson,rson);
}
int main(){
    n=read(),m=read(),p[0].dst=-1,p[0].sz=0ll;
    for(LL i=1;i<=n;i++) p[i].init();
    for(LL i=1;i<=m;i++){
    	h1=read()+1,h2=read()+1;
		st1=find(h1),st2=find(h2);
		merge(st1,st2);
    }
	for(LL i=1;i<=n;i++){
	    if(p[i].fa!=0ll) continue;
		tmp.pt=i,Q.push(tmp);
	}
	while(m<n-1){
		if(Q.size()<=1) fad();
		h1=Q.top().pt,Q.pop(),h2=Q.top().pt,Q.pop();
		ans+=p[h1].num+p[h2].num;
		st1=del(h1),st2=del(h2);
		gt=merge(st1,st2);
		if(gt!=0ll) tmp.pt=gt,Q.push(tmp);
		m++;
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 9332
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

vector<long long> A, F;
long long N, K;

bool judge(long long time) {
	long long k = K;
	for (int n = 0; n < N; n++) {
		if (A[n] * F[n] <= time)continue;
		long long needed = floor((long double)time / F[n]);
		k -= (A[n] - needed);
		if (k < 0)return false;
	}
	return true;
}

int main() {
	cin >> N >> K;
	A.resize(N);
	F.resize(N);
	for (int n = 0; n < N; n++)cin >> A[n];
	for (int n = 0; n < N; n++)cin >> F[n];
	sort(A.begin(), A.end(), [](long long a, long long b) {
		return a < b;
	});
	sort(F.begin(), F.end(), [](long long a, long long b) {
		return a > b;
	});
	long long s = -1, e = LLONG_MAX - 1;
	while (e - s > 1) {
		long long m = (e + s) / 2;
		if (judge(m))e = m;
		else s = m;
	}
	cout << e << endl;
	return 0;
}


Measured memory_bytes: 3328
n=int(input())
h=list(map(int,input().split()))
ans="Yes"
FL=False
Fx=-1
for i in range(n-1):
  if n==1:
    break
  if h[i]>=Fx:
    FL=False 
  if h[i]-h[i+1]==1:
    if FL:
      ans="No"
      break  
    else:
      FL=True
      Fx=h[i]
  elif h[i]-h[i+1]>1:
    ans="No"
    break  
    
print(ans)

Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
int lower_case(char x[],int n,bool b){
    for(int i=0;i<n;i++)
        if(x[i]>=65&&x[i]<=90)
            {b=1;break;}
return b;}

int main(){
string s,t,u;
int a,p;
bool b = 0;
cin>>s>>t;
cin>>a>>p;
cin>>u;
int n = s.length(),m=t.length(),v=u.length();
int x1,x2,x3;
char x[n+1],y[m+1],z[v+1];
strcpy(x,s.c_str());strcpy(y,t.c_str());strcpy(z,u.c_str());
x1=lower_case(x,n,b);
x2=lower_case(y,m,b);
x3=lower_case(z,v,b);
if(x1==0&&x2==0&&x3==0&&n<=10&&m<=10&&n>=1&&m>=1&&s!=t&&(s==u||t==u)&&a>=1&&p>=1&&a<=10&&p<=10){
    if(s==u)
        cout<<(a-1)<<" "<<p<<endl;
    else if(t==u)
        cout<<a<<" "<<(p-1)<<endl;
}


return 0;}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 998244353;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t szi, szj;
        inp(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
    };
    inp inp1;
}

int main() {

    int n, a;
    cin >> n >> a;
    vector<int> x = inp(n);
    sort(allof(x));
    const int kMax = accumulate(allof(x), 0) + 1;

    // dp[i][j][k] := i番目までみて，j個選んだ時に総和がkになる場合の数
    vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(n + 1, vector<ll>(kMax)));
    dp[0][0][0] = 1;

    rep(i, n) {
        rep(j, n) {
            rep(k, kMax) {
                // 選ぶ
                if (k + x[i] < kMax) dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
                // 選ばない
                dp[i + 1][j][k] += dp[i][j][k];
            }
        }
    }

    ll ans = 0LL;
    Rep(i, 1, n + 1) {
        if (i * a >= kMax) continue;
        ans += dp[n][i][i * a];
    }

    Cout(ans);

    return 0;
}


Measured memory_bytes: 52224
a,b,h,m = list(map(int, input().split()))

h = (h*30) + (m * 0.5 )
m = m*6

s = abs(h-m)
if s >= 180:
    s  = 360 - s

import math 
cos = math.cos(math.radians(s))
# print(cos)

ans = math.sqrt((a ** 2) + (b ** 2) - 2 * a * b * cos)
print(ans)

Measured memory_bytes: 9492
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        a = a^b;
        b = a^b;
        a = a^b;
    }
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }
    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}


void solve(void){
    int n;
    cin >> n;
    vector<string>w(n);
    rep(i,0,n) cin >> w[i];
    rep(i,0,n-1){
        rep(j,i+1,n){
            if(w[i] == w[j]){
                ns();
                return;
            }
        }
    }
    rep(i,0,n-1){
        if(w[i][w[i].size()-1] != w[i+1][0]){
            ns();
            return;
        }
    }
    ys();
}


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


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;
 
use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;

    input!{
        a: usize, b: usize, c: usize,
    }

    let ans = if b / a < c { b / a } else { c };
    println!("{}", ans)
}

fn main() {
    solve();
}


Measured memory_bytes: 2160
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
#define pb push_back
#define F first
#define S second
#define ld long double
#define vi vector<ll>
const int N = 1e9 + 5;

void solve() {
	string s;
	cin >> s;
	vi MOD(2019, 0);
	MOD[0] = 1;
	ll n = 0, a = 1;
	for (int i = s.size() - 1; i >= 0; i--) {
		ll cur = s[i] - '0';
		n = (n + (a * cur) % 2019) % 2019;
		//cout << a << " " << n << endl;
		a *= 10;
		a %= 2019;
		MOD[n]++;
	}
	ll ans = 0;
	for (auto c : MOD) ans += (c * (c - 1)) / 2;
	cout << ans;
}

int main() {

	FASTIO;
/*
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
*/
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3784
N=int(input())
T=[int(x) for x in input().split()]
V=[int(x) for x in input().split()]

def solve(N, T, V):
    from itertools import accumulate
    ds = [0] + list(accumulate(T))
    vs = [0] + [min(V[i], V[i + 1]) for i in range(len(V) - 1)] + [0]
    for i in range(len(vs)):
        d = ds[i]
        vs[i] = min([v + abs(d - ds[j]) for j, v in enumerate(vs)])
    def calc(t, v0, v1, maxv):
        t0 = maxv - v0
        t1 = maxv - v1
        if t0 + t1 < t:
            return t * maxv - t0 * t0 / 2 - t1 * t1 / 2
        else:
            t0 = (t + v1 - v0) / 2
            t1 = (t + v0 - v1) / 2
            v = (t + v0 + v1) / 2
            S = v * t - t0 * t0 / 2 - t1 * t1 / 2
            return S
    r = 0
    for i in range(N):
        c = calc(T[i], vs[i], vs[i + 1], V[i])
        r += c
    return r

print(solve(N, T, V))

Measured memory_bytes: 3064
/*Remember: The Struggle Is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,M=1e9+7;
const int N=1;

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

    cout<<(n*(n-1))/2;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}



Measured memory_bytes: 256
# https://atcoder.jp/contests/abc120/tasks/abc120_b
def y(p):
    r = set()
    for i in range(1, p + 1):
        if p % i == 0:
            r.add(i)
    return(r)

a, b, k = [int(x) for x in input().split()]
print(sorted(list(y(a) & y(b)))[-k])


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

// 素因数分解O(sqrt(n))
map<ll, ll> prime_factor(ll n) {
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;

    auto p = prime_factor(n);
    ll i;
    ll ans = 0;
    for (auto t : p)
    {
        i = 1;
        while (i <= t.second)
        {

            t.second -= i;
            i++;
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

// struct UnionFind {
//     vector<int> par;
//     vector<int> rank;
//     vector<ll> diff_weight;

//     UnionFind(int n) {
//         init(n);
//     }

//     void init(int n) {
//         par.resize(n); rank.resize(n); diff_weight.resize(n);
//         rep(i, n) par[i] = i, rank[i] = 0, diff_weight[i] = 0;
//     }

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

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

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

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

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

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

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

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

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

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

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

int main() {
    ll n, m; cin >> n >> m;
    UnionFind<ll> uf(n);
    rep(i, m) {
        ll l, r, d; cin >> l >> r >> d; l--; r--;
        if(uf.issame(l, r) && d != uf.diff(l, r)) {
            cout << "No" << endl;
            return 0;
        }
        uf.merge(l, r, d);
    }
    cout << "Yes" << endl;
}


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

int main() {
	long long int m, a;
	cin >> a >> m;
	long long int ar[a];
	long long int s=0;
	for(int i=0;i<a;++i){
		cin >> ar[i];
	}
	sort(ar, ar+a);
	for(int i=0;i<a-m;++i){
		s += ar[i];
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 1792
mod = 10**9+7

n, m = gets.to_s.split.map{|t|t.to_i}

if n == 1
  puts 1
  exit
end

stairs = Array.new(n+1){ 1 }

m.times do
  stairs[gets.to_s.to_i] = 0
end

2.upto(n) do |i|
  next if stairs[i] == 0
  stairs[i] = stairs[i-1] + stairs[i-2]
  stairs[i] %= mod if stairs[i] >= mod 
end

puts stairs[-1] % (10**9+7)

Measured memory_bytes: 2812
object Main extends App {
  var s = scala.io.StdIn.readLine()
  val sArray = s.map(_.toString.toInt).toVector
  val length = sArray.length
  var array1 = Vector.empty[Int]
  var array2 = Vector.empty[Int]
  for (i <- 1 to (length)) {
    val twoExtra = i % 2
    array1 :+= twoExtra
    if (twoExtra == 0) {
      array2 :+= 1
    } else {
      array2 :+= 0
    }
  }
  var diffCount1 = sArray.zipWithIndex.map { case(s, index) =>
    if(s == array1(index)) {
      0
    } else {
      1
    }
  }.sum
  val diffCount2 = sArray.zipWithIndex.map { case(s, index) =>
    if(s == array2(index)) {
      0
    } else {
      1
    }
  }.sum
  if(diffCount1 >= diffCount2) {
    print(diffCount2)
  } else {
    print(diffCount1)
  }
}


Measured memory_bytes: 55912
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int H=0,W=0;
  while(1){
    cin >> H >> W;
    if(H==0&&W==0){
      break;
    }
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cout << "#";
      }
      cout << "\n";
    }
    cout <<"\n";
  }
  return(0);
}



Measured memory_bytes: 3088
import scala.math._

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val c1 = sc.next
  val c2 = sc.next

  val ans = if (c1.reverse == c2) "YES" else "NO"

  println(ans)

  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

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

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> V(N);
  for (int i = 0; i < N; i++) {
    int X, L;
    cin >> X >> L;
    V.at(i) = {X - L, X + L};
  }
  sort(V.begin(), V.end());
  reverse(V.begin(), V.end());
  pair<int, int> now = V.at(0);
  int ans = 0;
  for (int i = 1; i < N; i++) {
    if (now.first >= V.at(i).second) now = V.at(i);
    else ans++;
  }
  cout << N - ans << "\n";
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;

int main(){
int a,b,c,x;
int cnt=0;
cin>>a>>b>>c>>x;
for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
        for(int k=0;k<=c;k++){
            if(i*500+j*100+k*50==x){
                cnt++;
            }
        }
    }
}
cout<<cnt<<endl;
}














Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    char a[65535];
    int i,t;

    for(i=0;;i++){
                if(scanf("%c",a+i)==EOF){
                      t=i;break;
                }
        }
    for(i=0;i<t;i++){
        if(a[i]>96&&a[i]<123){
            a[i]-=32;
        }
    }
    printf(a);
    return 0;
}

Measured memory_bytes: 532
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define int long long
#define sz(x) (int)x.size()
pair < int , int > a[1000 * 100 + 5];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i].f;
		a[i].s = i;
	}
	sort(a + 1 , a + n + 1);
	for(int i = 1; i <= n; i++)
		cout << a[i].s << " ";
	return 0;
}


Measured memory_bytes: 2432
#include<iostream>
#include<vector>
#include<queue>
#include<math.h>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

struct status{
    bool o[24];
};

int n;
double x[24], y[24], r[24];
int c[24];
double d[24][24];

double dist(double x1, double y1, double x2, double y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

bool gone[1<<24];

int o2idx(bool (&o)[24]){
    int output = 0;
    REP(i, n){
        if(o[i]){
            output = output | 1<<i;
        }
    }
    return output;
}

int main(){
    while(1){
        cin >> n;
        if(n==0) break;

        REP(i, n){
            cin >> x[i] >> y[i] >> r[i] >> c[i];
        }

        int colnum = 0;
        REP(i, n){
            colnum = max(colnum, c[i]);
        }

        REP(i, n){
            REP(j, n){
                d[i][j] = dist(x[i], y[i], x[j], y[j])-(r[i]+r[j]);
            }
        }

        REP(i, 1<<n) gone[i]=false;

        int maxnum = 0;
        queue<status> que;
        status s;
        REP(i, n) s.o[i] = true;
        que.push(s);
        gone[o2idx(s.o)] = true;
        while(!que.empty()){
            status s = que.front();
            que.pop();

            int count = 0;
            REP(i, n){
                if(!s.o[i]) count += 1;
                // cout << s.o[i] << " ";
            }
            // cout << endl;
            maxnum = max(maxnum, count);

            vector<int> top[4];
            REP(i, n){
                if(s.o[i]){
                    bool flag = true;
                    REP(j, i){
                        if(s.o[j] && d[i][j]<0) flag = false;
                    }
                    if(flag){
                        top[c[i]-1].push_back(i);
                    }
                }
            }

            REP(i, colnum){
                if(top[i].size()>=2){
                    REP(j, top[i].size()-1){
                        for(int k=j+1; k<top[i].size(); k++){
                            status ns;
                            REP(l, n) ns.o[l] = s.o[l];
                            ns.o[top[i][j]] = false;
                            ns.o[top[i][k]] = false;
                            if(!gone[o2idx(ns.o)]){
                                gone[o2idx(ns.o)] = true;
                                que.push(ns);
                            }
                        }
                    }
                }
            }
        }
        cout << maxnum << endl;
    }
}

Measured memory_bytes: 27624