akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**7)
def main(n,ki,uv):
  # n: 頂点数
  # ki: 木
  # Euler Tour の構築
  S=[] # Euler Tour
  F=[0]*n # F[v]:vにはじめて訪れるステップ
  depth=[0]*n # 0を根としたときの深さ
  def dfs(v,pare,d):
    F[v]=len(S)
    depth[v]=d
    S.append(v)
    for i,w in ki[v]:
      if w==pare:continue
      dfs(w,v,d+1)
      S.append(v)
  dfs(0,-1,0)
  # Sをセグメント木に乗せる
  # u,vのLCAを求める:S[F[u]:F[v]+1]のなかでdepthが最小の頂点を探せば良い
  # F[u]:uに初めてたどるつくステップ
  # S[F[u]:F[v]+1]:はじめてuにたどり着いてつぎにvにたどるつくまでに訪れる頂点
  # 存在しない範囲は深さが他よりも大きくなるようにする
  INF = (n, None)
  # LCAを計算するクエリの前計算
  M = 2*n
  M0 = 2**(M-1).bit_length() # M以上で最小の2のべき乗
  data = [INF]*(2*M0)
  for i, v in enumerate(S):
    data[M0-1+i] = (depth[v], i)
  for i in range(M0-2, -1, -1):
    data[i] = min(data[2*i+1], data[2*i+2])
  # LCAの計算 (generatorで最小値を求める)
  def _query(a, b):
    yield INF
    a += M0; b += M0
    while a < b:
      if b & 1:
        b -= 1
        yield data[b-1]
      if a & 1:
        yield data[a-1]
        a += 1
      a >>= 1; b >>= 1
  # LCAの計算 (外から呼び出す関数)
  def query(u, v):
    fu = F[u]; fv = F[v]
    if fu > fv:
      fu, fv = fv, fu
    return S[min(_query(fu, fv+1))[1]]
  
  todo=[[0,[]]]
  path=[[]]*n
  mi=[1]*n
  while todo:
    v,ary=todo.pop()
    path[v]=ary
    mi[v]=0
    for i,nv in ki[v]:
      if mi[nv]==1:
        todo.append([nv,ary+[i]])
        mi[nv]=1

  for i in range(n):
    path[i]=set(path[i])
  memo={}
  for c in range(m):
    u,v=uv[c]
    dd=query(u,v)
    tmp=path[u]|path[v]
    tmp-=path[dd]
    memo[c]=tmp

  ans=0
  for i in range(2**m):
    chk=set(())
    for j in range(m):
      if (i>>j)&1:
        chk.add(j)
    must_w=set(())
    for c in chk:
      tmp=memo[c]
      must_w|=tmp
    t=n-1-len(must_w)
    if len(chk)%2==1:
      ans-=pow(2,t)
    else:
      ans+=pow(2,t)
  print(ans)
if __name__=='__main__':
  n=int(input())
  ki=[[] for _ in range(n)]
  for i in range(n-1):
    u,v=map(int,input().split())
    u,v=u-1,v-1
    ki[u].append([i,v])
    ki[v].append([i,u])
  m=int(input())
  uv=[]
  for _ in range(m):
    u,v=map(int,input().split())
    u,v=u-1,v-1
    uv.append([u,v])
  main(n,ki,uv)


Measured memory_bytes: 74556
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        int hp = 0;
        for(int j = 0; j < n; j++) {
            for(int k = j + 1; k < n; k++) {
                hp += arr[j] * arr[k];
            }
        }
        System.out.println(hp);
    }
}


Measured memory_bytes: 23892
#include<iostream>
#include<algorithm>
using namespace std;
#define N 100010

int main(){
    int n,m,h[N],ma[N];
    cin>>n>>m;

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

    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        ma[a]=max(ma[a],h[b]);
        ma[b]=max(ma[b],h[a]);
    }

    int ans=0;
    for(int i=1;i<=n;i++){
        ans+=h[i]>ma[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4368
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;


LL part(LL n, LL g, LL b, LL c, LL h, LL e, LL f)
{
  LL answer = n;
  REP(i,g) {
    REP(j,g) {
      LL tmp = n - i * b - j * c;
      if(tmp<0) break;
      LL gcnt = tmp / g;
      answer = max(answer, tmp + i*e + j*f + gcnt*(h-g));
    }
  }
  return answer;
}


LL maximize(LL n,LL a,LL b, LL c, LL d, LL e, LL f)
{
  int mode = 0;
  LL val = d*b*c;
  if(e*a*c > val) {
    mode = 1;
    val = e*a*c;
  }
  if(f*a*b > val) {
    mode = 2;
  }
  if(mode == 0) return part(n,a,b,c,d,e,f);
  else if(mode == 1) return part(n,b,a,c,e,d,f);
  else return part(n,c,b,a,f,e,d);
}

int main(void)
{
  LL n, a,b,c,d,e,f;
  cin >> n >> a >> b >> c >> d >> e >> f;
  n = maximize(n, a, b, c, d, e, f);
  n = maximize(n, d, e, f, a, b, c);
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string s; cin >> s;
    ll k; cin >> k;
    bool same = true;
    for(size_t i = 1; i < s.size(); i++){
        if(s[i] != s[i - 1]){
            same = false;
            break;
        }
    }
    if(same){
        cout << s.size() * k / 2 << '\n';
        return 0;
    }
    auto calc = [&](const string& s){ 
        ll num = 0;
        for(size_t i = 1; i < s.size(); i++){
            if(s[i - 1] == s[i]){
                num++;
                i++;
            }
        }
        return num;
    };
    ll n1 = calc(s);
    ll n2 = calc(s + s);
    ll d = n2 - n1;
    cout << n1 + d * (k - 1) << '\n';
    // if(s.size() == 1){
    //     cout << k / 2 << '\n';
    //     return 0;
    // }
    // ll num = 0;
    // bool last = false;
    // for(size_t i = 1; i < s.size(); i++){
    //     if(s[i - 1] == s[i]){
    //         num++;
    //         i++;
    //         last = i == s.size();
    //     }
    // }
    // if(s[0] != s.back()){
    //     cout << num * k << '\n';
    //     return 0;
    // }else{
    //     if(last){
    //         cout << num * k << '\n';
    //         return 0;
    //     }else{
    //         cout << num * k + k - 1 << '\n';
    //         return 0;
    //     }
    // }
}


Measured memory_bytes: 888
IDENTIFICATION DIVISION.
        PROGRAM-ID. AtCoder.
      
        ENVIRONMENT DIVISION.
      
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 INP PIC X(100).
        01 A PIC 9(15).
        01 B PIC 9(15).
        01 C PIC 9(15).
      	01 D PIC 9(15).
      	01 E PIC 9(15).
        01 F PIC 9(15).
      	01 t PIC 9(15).
	    01 temp1 PIC 9(15).
        01 temp2 PIC 9(15).
        01 N PIC 9(15).
      
        PROCEDURE DIVISION.
      	MAIN.
			ACCEPT A.
      		ACCEPT B.
      		ACCEPT C.
      		ACCEPT D.
      		ACCEPT E.
      		ACCEPT F.
      		IF E - A > F THEN
      			DISPLAY ":("
      		ELSE
      			DISPLAY "Yay!"
      		END-IF.
		STOP RUN.

Measured memory_bytes: 384
H,W,M = map(int,input().split())

hlist = [0]*H
wlist = [0]*W
sets = set()
for i in range (M):
    h,w = map(lambda x: int(x)-1,input().split())
    hlist[h]+=1
    wlist[w]+=1
    sets.add((h,w))

hmax = 0
hind = []
for i in range(H):
    if hmax < hlist[i]:
        hmax = hlist[i]
        hind = [i]
    elif hmax == hlist[i]:
        hind.append(i)


wmax = 0
wind = []
for i in range(W):
    if wmax < wlist[i]:
        wmax = wlist[i]
        wind = [i]
    elif wmax == wlist[i]:
        wind.append(i)


flag = False
for h in hind:
    for w in wind:
        if (h,w) not in sets:
            flag = True
            break
    if flag:
        break

if flag:
    print(hmax + wmax)
else:
    print(hmax + wmax - 1)


Measured memory_bytes: 83428
package main

import (
	"fmt"
)

var n int
var g [8][8]int
var visited [8]bool

func done() bool {
	ok := true
	for i := 1; i < n; i++ {
		if !visited[i] {
			ok = false
			break
		}
	}
	return ok
}

func dfs(start int) int {
	if done() {
		return 1
	}

	ans := 0
	// skip i = 0 as we don't want to go back to the start
	for i := 1; i < n; i++ {
		if g[start][i] != 1 || visited[i] {
			continue
		}
		visited[i] = true
		ans += dfs(i)
		visited[i] = false
	}
	return ans
}

func main() {
	var m int
	fmt.Scan(&n, &m)
	var a, b int
	for i := 0; i < m; i++ {
		fmt.Scan(&a, &b)
		g[a-1][b-1] = 1
		g[b-1][a-1] = 1
	}

	visited[0] = true
	ans := dfs(0)
	fmt.Println(ans)
}


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

int N;
int A[210];

int main(){
	while(cin >> N && N>0){
		int ans = 100;
		for(int i=0;i<N;i++){
			cin >> A[i];
		}
		for(int i=0;i<N;i++){
			int a = A[i];
			int mi = 0;
			while(a%2 == 0){
				mi++;
				a /= 2;
			}
			ans = min(ans,mi);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    int H, W, whiteH, whiteW;
    cin >> H >> W >> whiteH >> whiteW;

    cout << H*W - whiteH*W - whiteW*H + whiteH*whiteW  << endl;
}

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

public class Test
{
	public static void Main()
	{
		
		var c = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
		long a = c[0];
		long b = c[1];
		long k = c[2];
		
		if(a+b<=k){
			Console.WriteLine("0 0");
		}else if(a>=k){
			Console.WriteLine((a-k)+" "+b);
		}else{
			Console.WriteLine("0 "+(a+b-k));
		}
		
	}
}

Measured memory_bytes: 13396
#include<iostream>
using namespace std;
int main(){

char a[1001];
	int i;
	for (i = 0; i < 1001; i++) {
		a[i] = '0';
	}
	cin >> a;
	int n, s, w, e;
	n = 0;
	s = 0;
	w = 0;
	e = 0;
	for (i = 0; i < 1001; i++) {
		if (a[i] == 'N') {
			n = 1;

		}
		else if (a[i] == 'S') {
			s = 1;
		}
		else if (a[i] == 'W') {
			w = 1;
		}
		else if (a[i] == 'E') {
			e = 1;
		}
	}
	if ((n == s) && (w == e)) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

	return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int S;
    cin >> S;
    int h, m, s;
    h = S / 3600;
    m = (S % 3600) / 60;
    s = S % 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3108
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();
        final int L = sc.nextInt();

        final int[] tastes = new int[N];
        for (int i = 0; i < N; i++) {
            tastes[i] = L + (i+1) - 1;
        }

        int x = -1;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < N; i++) {
            if (min > Math.abs(tastes[i])) {
                x = i;
                min = Math.abs(tastes[i]);
            }
        }

        tastes[x] = 0;

        System.out.println(IntStream.of(tastes).sum());
    }
}


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

int main(){
	int A, B, C, X, i, j, k, c=0;
	cin >> A >> B >> C >> X;
	for(i=0;i<=A;i++){
		for(j=0;j<=B;j++){
			for(k=0;k<=C;k++){
				if(500*i+100*j+50*k==X) c++;
			}
		}
	}
	cout << c << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n)-1; i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1<<28;
const int MOD = 1000000007;

int main(){
  while(true){
    int d, e; cin >> d >> e;
    if(d+e == 0)  break;
    double ans = (double)INF;
    for(int i=0; i<d; i++){
      ans = min(ans, fabs(sqrt(i*i + (d-i)*(d-i))-e));
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

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; }
constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

ll calc(ll x, ll y, ll z) {
  return x * x + y * y + z * z + x * y + y * z + z * x;
}

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

  ll n;
  cin >> n;

  for (int m = 1; m <= n; m++) {
    int ans = 0;
    for (int x = 1; x <= 100; x++) {
      int tmp = x * x;
      if (tmp >= n) break;
      for (int y = 1; y <= 100; y++) {
        int tmp2 = tmp + y * y + x * y;
        if (tmp2 >= n) break;
        for (int z = 1; z <= 100; z++) {
          int sum = tmp2 +  z * z + x * z + y * z;
          if (sum == m) ans++;
          if (sum >= m) break;
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3544
//L-Deque

#include<iostream>
#include<algorithm>
#include<utility>
#include<map>
#include<string>
#include<vector>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#undef INT_MIN
#undef INT_MAX
#define LL long long
#define INT_MIN -2147483647
#define INT_MAX 1000000009
#define LL_MIN -9223372036854775807
#define LL_MAX 9223372036854775807
#define MOD 1000000007

int N, l = 0, r = N - 1;
LL a[3009];
LL dp[3009][3009], ans = 0;

int main(){
	cin >> N;
	for(int i=0; i<N; i++)
		cin >> a[i];

	for(int i = N - 1; i >= 0; i--){
		for(int j = N - 1 - i; j >= 0; j--){
			if((i + j) % 2){
				if(i + j + 1 == N)
					dp[i][j] = -1 * a[j];
				else
					dp[i][j] = min(dp[i + 1][j] - a[N - 1 - i], dp[i][j + 1] - a[j]);
			}
			else {
				if(i + j + 1 == N)
					dp[i][j] = a[j];
				else
					dp[i][j] = max(dp[i + 1][j] + a[N - 1 - i], dp[i][j + 1] + a[j]);
			}
		}
	}
	cout << dp[0][0] << endl;
	return 0;
}




Measured memory_bytes: 70016
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;  
  int pi, s = 0, m = 0;
  for(int i = 0; i < n; i++){
      cin >> pi; s += pi;
      if(pi > m) m = pi;
  }
 
 cout << s - m/2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int const inf = 1 << 29;
int s;
int n[600];
int cs[] = { 500, 100, 50, 10, 5, 1 };

int out(int x){
    int res = 0;
    int sum = 0;
    for (int i : cs){
        int rest = x - sum;
        int t = min(n[i], rest / i);
        res += t;
        sum += t*i;
    }
    return sum == x ? res : inf;
}

int in(int x){
    int res = 0;
    int sum = 0;
    for (int i : cs){
        int rest = x - sum;
        int t = rest / i;
        res += t;
        sum += t*i;
    }
    return res;
}

int main(){
    int P;
    while (cin >> P && P){
        for (int i : {1, 5, 10, 50, 100, 500}){
            cin >> n[i];
        }
        int res = inf;
        int ans;
        for (int i = P; i <= P + 1000; i++){
            int x = out(i);
            int y = in(i - P);
            if (res > x + y){
                // cout << " " << x + y << endl;
                res = x + y;
            }
        }
        cout << res << endl;
    }
}

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

# input
x, y = map(int, input().split())

# solve
ans = [0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1]

# output
print('Yes' if ans[x] == ans[y] else 'No')


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
	int N;
	cin >> N;
	std::vector<int> L(N);
	for (int i = 0; i < N; i++)
	{
		cin >> L[i];
	}

	sort(L.begin(), L.end());
	int sum =0;
	/*for (int i = 0; i < N; ++i)
	{
		cout << L[i];
	}
	cout << endl;*/

	for (int a = 0; a < N-2 ; a++){
		for (int b = a+1; b < N-1; b++){
			int key = L[a]+L[b];
			int left = b;
			int right = N;
			while(right - left > 1){
				int mid = left + (right - left)/2;
				if (L[mid] >= key) right = mid;
				else left = mid; 
			}
			//cout << key << ":" << left << ":" << b <<  endl;
			sum += (left - b);
		}
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
/** coder Mohammad Al-Hussein *_^ */
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define All(v) v.begin(),v.end()
#define mod  1000000007
#define write freopen("output.txt","w",stdout)
#define read freopen("test (1).txt","r",stdin)
#define FIO std::ios_base::sync_with_stdio(false);
using namespace std;
char a[10][10];
bool vis[10][10];
int H,W;
void flood(int i,int j)
{
    if(i >= H || j >= W) return ;

    a[i][j] = '.';
    if(i == H-1 && j == W-1)
        return ;
    if(a[i][j+1] == '#')
        flood(i,j+1);
    else if(a[i+1][j] == '#')
        flood(i+1,j);
}
int main()
{
    cin >> H >> W;
    for(int i=0; i<H; i++)
        for(int j=0; j<W; j++)
            cin >> a[i][j];
    flood(0,0);
    for(int i=0; i<H; i++)
        for(int j=0; j<W; j++)
            if(a[i][j] == '#')
                return cout << "Impossible\n",0;
    cout << "Possible\n";

    return 0;
}


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

#define MAX 20

int main(){
    int N,M,T = 1;
 
    while(cin >> N >> M , N | M){
	int cnt = 0;
	vector<int> res(M+1,0);
	res[0] = N;
 
	while(true){
	    vector<int> tmp(M+1,0);
 
	    if(res[M]) break;  
	    cnt++;      
 
	    for(int i = 0 ; i < M ; i++){
		if(res[i] >= 2){
		    tmp[i+1] += res[i] / 2;
		    tmp[0] += res[i] / 2;
		    if(res[i] % 2) tmp[i]++;
		}
		else
		    tmp[i] += res[i];
	    }
 
	    res = tmp;
	}
	cout << "Case " << T++ << ": ";
	cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3080
#include <iostream>
using namespace std;
typedef long long ll;
ll q, h, s, d, n, a, b;
int main(void){
    // Your code here!
    cin >> q >> h >> s >> d >> n;
    a = min(q * 4, min(h * 2, s));
    b = min(a * 2, d);
    cout << n / 2 * b + n % 2 * a << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int R, C;
ll mn[2];
ll val[200000];
bool vis[200000];
vector<vector<pair<int, int> > > g;
void NO() {
	puts("No");
	exit(0);
}
void DFS(int u, ll should) {
	if (vis[u]) {
		if (should != val[u])
			NO();
		return;
	}
	val[u] = should;
	vis[u] = true;
	mn[u >= R] = min(mn[u >= R], val[u]);
	for (int i = 0; i < g[u].size(); ++i)
		DFS(g[u][i].first, g[u][i].second - val[u]);
}
int main()
{
	int n;
	scanf("%d%d%d", &R, &C, &n);
	g.resize(R + C);
	for (int r, c, k, i = 0; i < n; ++i) {
		scanf("%d%d%d", &r, &c, &k);
		--r; --c;
		g[r].push_back(make_pair(R + c, k));
		g[R + c].push_back(make_pair(r, k));
	}
	for(int i=0;i<g.size();++i)
		if (!vis[i]) {
			mn[0] = mn[1] = 1e18;
			DFS(i, 0);
			if (mn[0] + mn[1] < 0)
				NO();
		}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 12928
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

int dp[51][51][2550];

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,A; cin >> N >> A;
    int X[N]; rep(i,N) cin >> X[i];
    dp[0][0][0]=1;
    rep(i,N){
        rep(j,i+1){
            rep(k,2500){
                dp[i+1][j][k]+=dp[i][j][k];
                dp[i+1][j+1][k+X[i]]+=dp[i][j][k];
            }
        }
    }

    int ans=0;
    rep(i,N) ans+=dp[N][i+1][(i+1)*A];
    cout << ans << endl;
}

Measured memory_bytes: 50048
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    l = readInt()
    l.sort()
    ans = 0
    for i in range(n-2):
        for j in range(i+1,n-1):
            if l[i]==l[j]:
                continue
            for k in range(j+1,n):
                if l[i]==l[k] or l[j]==l[k]:
                    continue
                if l[k]<l[i]+l[j]:
                    ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 9204
#! /usr/bin/env python3

N = int(input())
t = 100
s = 0
for i in range(N):
    a = int(input())
    s += a
    t = min(t, a) if a % 10 else t
if s % 10 == 0:
    if t % 10 == 0:
        print(0)
    else:
        print(s - t)
else:
    print(s)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1e9 + 7, N = 1087;
ll dp[N],f[N],fi[N];
int main()
{
    f[0] = f[1] = fi[0] = fi[1] = 1;
    for (int i = 2; i < N; ++i) 
        f[i] = i * f[i-1] % M;
    for (int i = 2; i < N; ++i) 
        fi[i] = (M-M/i) * fi[M%i] % M;
    for (int i = 2; i < N; ++i)
        fi[i] = fi[i] *  fi[i-1] % M;

    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,a,b,c,d;    
    cin >> n >> a >> b >> c >> d;
    dp[0] = 1;
    for (ll i = a; i <= b; ++i)
        for (ll j = n; j >= i * c; --j) {
            ll t = fi[i];
            for (ll k = 1; k <= min(d,j/i); ++k) {
                if (k >= c) {
                    (dp[j] += t * f[j] % M * fi[j - k * i] % M * fi[k] % M *  dp[j - k * i] % M) %= M;
                }
                (t *= fi[i]) %= M;
            }
        }
    cout << dp[n] << endl;
}


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

int main()
{
  int a[3];
  for(int i = 0; i < 3; i++){
    cin >> a[i];
  }
  sort(a, a + 3);
  
  if(a[0] == a[1] && a[1] != a[2]) cout<< "Yes" << endl;
  else if(a[0] != a[1] && a[1] == a[2]) cout << "Yes" << endl;
  else  cout << "No" << endl;
}


Measured memory_bytes: 3576
const main = (input) => {
  const s = input.trim()

  return console.log(s[s.length-1] === 's' ? s+'es' : s+'s')
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29680
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtcoderTemplateForCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var input = Console.ReadLine()
                .Split(' ')
                .Select(int.Parse);

            if (input.ElementAt(0) == input.ElementAt(1) && input.ElementAt(1) == input.ElementAt(2))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 13268
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
  int x[101],top=0,i;
  char s[101];
  while(scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      top--;
      x[top]=x[top]+x[top+1];
    }
    else if ( s[0] == '-' ){
      top--;
      x[top]=x[top]-x[top+1];
    }
    else if ( s[0] == '*' ){
      top--;
      x[top]=x[top]*x[top+1];
    } 
    else {
      top++; 
      x[top] = atoi(s);
    } 
  }
  printf("%d\n",x[1]);
  return 0;
}

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

typedef long long ll;
const ll MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<int>c(N-1);
    vector<int>s(N-1);
    vector<int>f(N-1);
    for (int i = 0; i < N-1; i++) {
        cin >> c[i] >> s[i] >> f[i];
    }

    for (int i = 0; i < N; i++) {
        int now = 0;
        if (i == N-1) {
            cout << 0 << endl;
        } else {
            int cnt = 0;
            for (int j = i; j < N-1; j++) {
                if (cnt == 0) {
                    now += s[j]+c[j];
                } else {
                    if (now < s[j]) {
                        now = s[j] + c[j];
                    } else {
                        now = s[j] + ceil((double)(now-s[j])/(double)f[j]) * f[j] + c[j];
                    }
                }
                cnt++;
            }
            cout << now << endl;
        }
    }
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int cnt = 0, enda = 0, beginb = 0, both = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int i = 0; i < s.size() - 1; i++) {
            if (s[i] == 'A' && s[i + 1] == 'B') cnt++;
        }
        if (s.back() == 'A' && s.front() == 'B') both++;
        else if (s.back() == 'A') enda++;
        else if (s.front() == 'B') beginb++;
    }

    if (enda && beginb) {
        cout << cnt + min(enda, beginb) + both << endl;
        return 0;
    } else if (enda) {
        cout << cnt + both << endl;
        return 0;
    } else if (beginb) {
        cout << cnt + both << endl;
        return 0;
    } else if (both) {
        cout << cnt + both - 1 << endl;
        return 0;
    } else {
        cout << cnt << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 100000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
const int MAXN = 201+5;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	int n;
	cin >> n;
	std::vector<int> a(n);
	std::vector<int> b(n);
	for(int i=0; i<n; i++)cin >> a[i];
	for(int i=0; i<n; i++)cin >> b[i];
	if(a == b){
		cout << 0 << "\n";
		return 0;
	}
	if(a>b)swap(a,b);
	int cnt = 0;
	while(a<b){
		next_permutation(a.begin(),a.end());
		cnt++;
	}
	cout << cnt << "\n";
    return 0;
}




Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<55);
const ll MOD = (ll)(1e9+7);

#define l_ength size

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

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

vector<P> v;
vector<ll> u;

ll dp[225816][50];

bool comp(P a, P b){
	return (b.first*(a.second+1)<a.first*(b.second+1));
}

int main(void){
	int n,i,m,ans=0,j,tmp;
	ll a,b,t;
	cin >> n >> t;
	for(i=0; i<n; ++i){
		cin >> a >> b;
		if(a){
			v.push_back(P(a,b));
		}else{
			u.push_back(b+1);
		}
	}
	sort(v.begin(),v.end(),comp);
	sort(u.begin(),u.end());
	m = v.l_ength();
	fill(dp[0],dp[225816],INFLL);
	dp[0][0] = 0ll;
	for(i=0; i<m; ++i){
		for(j=0; j<41; ++j){
			if(dp[i][j]>t){
				continue;
			}
			dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
			dp[i+1][j+1] = min(dp[i+1][j+1],(dp[i][j]+1)*(v[i].first+1)+v[i].second);
		}
	}
	for(j=0; j<41; ++j){
		if(dp[m][j]>t){
			continue;
		}
		tmp = j;
		for(i=m; i<n; ++i){
			if(dp[m][j]+u[i-m]>t){
				break;
			}
			dp[m][j] += u[i-m];
			++tmp;
		}
		ans = max(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 92524
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int k,x;
    cin >> k >> x;
    int l = max(-1000000,x-k+1);
    int r = min(1000000,x+k-1);
    for(int i = l;i <= r;i++){
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
local N = io.read("n")
local A = {} for i=1,N+1 do A[i] = io.read("n") end
local B = {} for i=1,N do B[i] = io.read("n") end
B[N+1]=0
local count = 0
local prev_power = 0
for i=1,N+1 do
  local mon = A[i]
  if mon <= prev_power then
    count = count + mon
    mon = 0
  else
    count = count + prev_power
    mon = mon - prev_power
  end
  local power = B[i]
  if mon <= power then
    prev_power = power - mon
    count = count + mon
  else
    prev_power = 0
    count = count + power
  end
end
print(count)

Measured memory_bytes: 4472
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
#include <omp.h>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
int main() {
	string s;
	cin >> s;
	long long ans = 0;
	long long geko = 1;
	long long cnt = 0;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == 'W'){
			if (geko == 0) {
				geko = 1;
			}
			ans += cnt;
		}
		else {
			cnt++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	cin >> n;

	string s1, s2;
	cin >> s1 >> s2;
	
	ll ans = 1;
	int i=0;
	if(s1[0] == s2[0]){
		ans *= 3;
		ans %= MOD;
		i = 1;
	}else{
		ans *= 6;
		ans %= MOD;
		i = 2;
	}
	for(; i<n; i++){
		if(s1[i-1] == s2[i-1]){
			if(s1[i] == s2[i]){
				ans *= 2;
				ans %= MOD;
			}else{
				ans *= 2;
				ans %= MOD;
				i++;
			}
		}else{
			if(s1[i] == s2[i]){
				ans *= 1;
				ans %= MOD;
			}else{
				ans *= 3;
				ans %= MOD;
				i++;
			}
		}
	}

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


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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main() {
    int n;
    cin >> n;
    str s;
    cin >> s;
    char next = s[n - 1];
    int cnt = 1;
    REPR(i, n - 1) {
        if(next != s[i]) cnt++;
        next = s[i];
    }
    cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 512
#define tst(a, b) for (int i = 1; i <= (b); i++) {cout << (a)[i] << " ";} cout << endl;
#define ll long long
#define lf long double
#define ch char
#define F(a) for (int i = 1; i <= (a); i++)
#define For(a, b) for (int (a) = 1; (a) <= (b); (a)++)
#define Rep(a, b, c) for (int (a) = (b); (a) <= (c); (a)++)
#define FD(a) for (int i = (a); i >= 1; i--)
#define ForD(a, b) for (int (a) = (b); (a) >= 1; (a)--)
#define RepD(a, b, c) for (int (a) = (b); (a) >= (c); (a)--)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back(a)
#define fi first
#define se second
#define Mem0(a) memset((a), 0, sizeof(a))
#define MemInf(a) memset((a), 115, sizeof(a))
#define Mem(a, n) memset((a), (n), sizeof(a))
#include <cstdio>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;


ll N, L;
string Str[200];

int main()
{
	cin >> N >> L;
	for (int i = 1; i <= N; i++) {
		cin >> Str[i];
	}
	
	sort(Str + 1, Str + N + 1);
	
	for (int i = 1; i <= N; i++) {
		cout << Str[i];
	}
	
	return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner

object Main extends App {

  def distance2() = {
    val sc = new Scanner(System.in)

    def nextInt() = sc.next.toInt

    val n = nextInt
    val xs = List.fill(n)(nextInt)
    val ys = List.fill(n)(nextInt)

    
    val manhattan = {
      var acc = 0.0
      for ((x, y) <- xs zip ys) 
        acc += math.abs(x - y)
      acc
    }

    val p2 = {
      var acc = 0.0
      for ((x, y) <- xs zip ys) 
        acc += (x - y) * (x - y)
      math.sqrt(acc)
    }

    val p3 = {
      var acc = 0.0
      for ((x, y) <- xs zip ys) {
        val d = math.abs(x - y)
        acc += d * d * d
      }
      math.cbrt(acc)
    }

    val chebyshev = {
      for ((x, y) <- xs zip ys)
      yield math.abs(x - y)
    }.max

    println(manhattan)
    println(p2)
    println(p3)
    println(chebyshev)
  }

  distance2()
}



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

using namespace std;
#define ll long long
int main()
{
    ios::sync_with_stdio(false);
    int k,s;
    while(cin>>k>>s)
    {
        map<int,int> mp;
        for(int i=0;i<=k;i++)
        {
            for(int j=0;j<=k;j++)
            {
                mp[i+j]++;
            }
        }
        ll ans=0;
        for(int i=0;i<=k;i++)
        {
            ans+=mp[s-i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
int gcd(int n,int m){
	if(n==0) return m;
	else return gcd(m%n,n);
}


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

  int check = 1;
  int k = 0;
  while(check!=2 && k<N+1){
  	check = a[check];
  	k++;
  }

  if(k<=N) cout << k <<endl;
  else cout << -1 <<endl;
  
  

  return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = ReadLine().Split().Select(x => x == "H" ? 1 : -1).ToArray();

        WriteLine(n[0] * n[1] == 1 ? 'H' : 'D');
    }
}


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

int  main()
{
   int n,m;
   int  sum=0;
   cin>>n>>m;
   for(int i=0;i<m;i++)
   {
       int days;
       cin>>days;
       sum+=days;
       
   }
    cout<<max(n-sum,-1);
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define RANGE(i, x, n) for(int i = x; i < n; ++i)
using namespace std;
int main()
{
    map<int, int> b;
    int n;
    cin >> n;
    int tmp;
    REP(i, n) {
        cin >> tmp;
        ++b[tmp];
    }
    int ans = 0;
    for(auto x: b) {
        if(x.first > x.second) {
            ans += x.second;
        }else if(x.first < x.second) {
            ans += x.second - x.first;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4736
#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)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    ll s = 0;
    rep(i, m) {
        ll tmp; cin >> tmp;
        s += tmp;
    }
    ll ans = (n-s >= 0) ? n-s : -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
using namespace std;
int i[114514];
int main(){
	int a,b,c,d=0,e;
	cin >>a>>i[0];
	for(int n=1;n<a;n++){
		cin >>i[n];
		if(i[n]>i[n-1]) i[n]--;
		if(i[n-1]>i[n]) d++;
	}
	if(d>0) cout <<"No\n";
	else cout <<"Yes\n";
	return 0;
}

Measured memory_bytes: 640
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

ll d[MAXn];

int main()
{
    IOS();
    ll n, L;
    cin >> n >> L;
    for (int i = 1;i <= n;i ++)
        cin >> d[i];
    for (int i = 1;i <= n - 1;i++)
        if (d[i] + d[i + 1] >= L) {
            cout << "Possible\n";
            for (int j = 1;j < i;j ++)
                cout << j << endl;
            for (int j = n - 1; j > i;j --)
                cout << j << endl;
            cout << i << endl;
            return 0;
        }
    cout << "Impossible" << endl;
}


Measured memory_bytes: 1664
import scala.io.StdIn

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  val Array(x, y) = StdIn.readLine.split(" ").map(_.toLong)

  val ans = {
    var c = 0L
    var n = x
    while(n <= y) {
      c += 1
      n = n << 1
    }
    c
  }
  out.println(ans)
  out.flush
}


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

int main()
{
    int n, w;
    cin >> n >> w;
    vector<int> vs(n);
    vector<int> ws(n);
    for (int i = 0; i < n; i++) {
        cin >> vs[i] >> ws[i];
    }

    // dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i])
    vector<vector<int>> dp(n, vector<int>(w + 1, 0));
    for (int j = 0; j <= w; j++) {
        if (j - ws[0] >= 0) {
            dp[0][j] = vs[0];
        }        
    }
    for (int i = 1; i < n; i++) {
        for (int j = 0; j <= w; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j - ws[i] >= 0) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - ws[i]] + vs[i]);
            }
        }
    }
    cout << dp[n - 1][w] << endl;
}


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

#define pb push_back
#define mp make_pair

typedef long long ll;

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

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

  map<int, int> mp;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;

    if(mp[a] == 0){
      mp[a]++;
    }else{
      mp[a] = 0;
    }
  }

  int ans = 0;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    if(itr->second) ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4864
#include<iostream>
using namespace std;
int main(){
    int S=0;
    int s;
    int m;
    int h;
    cin>>S;
    m=(S%3600)/60;
    h=S/3600;
    s=(S%3600)%60;
    cout<<h<<":"<<m<<":"<<s<<endl;

}


Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <sstream>
#include <array>

using namespace std;

constexpr int STATION = 10;

int main()
{
    string buf;
    while (getline(cin, buf)) {
        for (unsigned i = 0; i < buf.size(); i++) {
            if (buf.at(i) == ',') {
                buf.at(i) = ' ';
            }
        }

        stringstream ss(buf);
        array<int, STATION> interval;
        double vel01, vel02, vel_sum;
        for (size_t i = 0; i < STATION; i++) {
            ss >> interval.at(i);
        }
        ss >> vel01 >> vel02;
        vel_sum = vel01 + vel02;

        double length = 0;
        for (size_t i = 0; i < STATION; i++) {
            length += interval.at(i);
        }

        int ans = 1;
        for (size_t i = 0; i < STATION; i++) {
            double time = interval.at(i) / vel01;
            length -= time * vel_sum;
            if (length > 0) {
                ans++;
            } else {
                break;
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1256
a,b = map(int,input().split())
a = str(a)
b = str(b)
c = a+b
c = int(c)
i = 1
flag = 0
for i in range(1000):
    if i*i == c:
        print("Yes")
        flag = 1
        break
    else:
        pass
if flag == 0:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>


using namespace std;
typedef long long ll;
ll N;

int main(){

    ll N;
    cin >> N ;

    vector<ll > t(N);

    for(ll i = 0; i < N; i++){
        cin >> t[i];
    }

    sort(t.rbegin(), t.rend());

    ll alice = 0;
    ll bob = 0;

    for(ll i = 0; i < N; i++){
        if(i % 2 == 0){
            alice += t[i];
        }else{
            bob += t[i];
        }
    }

    cout << alice - bob << endl;

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

def solve_iter(N: int, M: int, A: "List[int]", B: "List[int]"):
    ic = N * (N - 1) // 2
    uf = UnionFind(N+1)
    for a, b in zip(A[::-1], B[::-1]):
        yield ic
        if uf.same(a, b):
            continue
        ic -= uf.size(a) * uf.size(b)
        uf.union(a, b)

def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    for a in reversed(list(solve_iter(N, M, A, B))):
        print(a)

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

# https://note.nkmk.me/python-union-find/
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
 
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 17416