akhauriyash/Code-Regression huggingface dataset:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, K = MAP()
P = LIST()
C = LIST()

check = [0]*N 
score = []

i = 0
while 1:
	while i < N and check[i]:
		i += 1
	if i == N:
		break

	tmp = []
	while check[i] == 0:
		check[i] = 1
		i = P[i]-1
		tmp.append(C[i])
	score.append(tmp)

ans = -INF
for x in score:
	x_acc = list(accumulate([0] + x + x))
	n = len(x)
	tmp_max = -INF

	cnt = 0
	p, q = 0, 0
	for i, j in combinations(range(2*n+1), 2):
		if j-i <= min(K, n):
			if tmp_max < x_acc[j]-x_acc[i]:
				tmp_max = x_acc[j]-x_acc[i]
				cnt = j-i
				p, q = i, j


	tmp_ans = -INF
	lis = x[(q-1)%n+1:]+x[:(q-1)%n+1]

	if 0 >= x_acc[n]:
		tmp_ans = tmp_max

	else:
		if cnt <= K%n:
			tmp_ans = x_acc[n]*(K//n) + tmp_max
		else:
			tmp_max2 = 0
			for i, j in combinations(range(2*n+1), 2):
				if j-i <= K%n:
					if tmp_max2 < x_acc[j]-x_acc[i]:
						tmp_max2 = x_acc[j]-x_acc[i]
			tmp_ans = max(x_acc[n]*(K//n-1)+tmp_max, x_acc[n]*(K//n) + tmp_max2)

	ans = max(ans, tmp_ans)

print(ans)


Measured memory_bytes: 79948
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int a,b,c; cin >> a >> b >> c;
    map <int,int> mp;
    mp[a]++;
    mp[b]++;
    mp[c]++;
    if (mp[5] == 2 && mp[7] == 1) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ToStreak
{
    class ABC116_B
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int s = ReadInt();
            int[] array = new int[1000000];
            array[0] = s;
            var dict = new Dictionary<int, bool>();
            dict.Add(array[0], true);
            for(int i = 1; i < array.Length; i++)
            {
                int prev = array[i - 1];
                if (prev % 2 == 0) array[i] = prev / 2;
                else array[i] = prev * 3 + 1;
                if (dict.ContainsKey(array[i]))
                {
                    Console.WriteLine(i + 1);
                    return;
                }
                else
                {
                    dict.Add(array[i], true);
                }
            }
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13152
K,A,B = map(int, input().split())

ans = 1
if B-1 <= A: ans += K
else:
    if K <= A: ans += K
    else:
        ans = B
        ans += ((K-A-1)//2) * (B-A)
        ans += ((K-A-1) % 2)

print(ans)

Measured memory_bytes: 3060
def main():
    A, B = map(int, input().split())
    res = 0
    if A % 2 == 0 and B % 2 == 1:
        res = ((B - A + 1) // 2) % 2
    elif A % 2 == 0 and B % 2 == 0:
        res = (((B - A) // 2) % 2)^B
    elif A % 2 == 1 and B % 2 == 0:
        res = (((B - A - 1) // 2) % 2)^A^B
    else:
        res = (((B - A) // 2) % 2)^A

    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 61920
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,L;
  cin >> N >> L;
  string S[N];
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  sort(S,S+N);
  for (int i = 0; i < N; i++) {
    cout << S[i];
  }
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
int main(){
    int N ,Q;

    int ans[200001]={};
    cin >>N>>Q;

    vector<pair<int, int> > ab(N);
    vector<pair<int, int> > px(Q);

    rep(i,N-1){
        int a, b;
        cin >> a >> b;
        ab[i] = make_pair(a,b);
        //cout << pairs[i].first << ' ' << pairs[i].second<< endl;
    }
    rep(i,Q){
        int a, b;
        cin >> a >> b;
        px[i] = make_pair(a,b);
        //cout << pairs[i].first << ' ' << pairs[i].second<< endl;
    }
     sort(ab.begin(),ab.end(), compare_by_b);
    rep(i,Q){
        ans[px[i].first-1] += px[i].second;
    }
    rep(i,N){
        ans[ab[i].second-1] += ans[ab[i].first-1];
    }

    rep(i,N){
        cout << ans[i] << ' ';
    }
    cout << endl;
    
    
    return 0;
    

}

Measured memory_bytes: 6272
#include <iostream>

int main()
{
	int h, w;
	while (true)
	{
		std::cin >> h >> w;
		if (h == 0 && w == 0)break;
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				if ((i+j)%2==0)
					std::cout << "#";
				else
					std::cout << ".";
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}
	return 0;
}

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

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

#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 ALL(v) ((v).begin(),(v).end())
#define COUT(x) cout<<(x)<<"\n"

int a[200010];

int main(){
    ll n,k;
    cin >> n >> k;
    vector<int> vec(n);
    REP(i,n)cin >> vec[i];
    int count = 1,num=0,start=vec[0];
    a[1]++;
    vector<int> test;
    test.push_back(vec[0]);
    while(num<2){
        start = vec[start-1];
        a[start]++;
        num = a[start];
        test.push_back(start);
        count++;
    }
    int count1 = 0;
    set<int> set1;
    vector<int> vec1;
    while(1){
        vec1.push_back(start);
        set1.insert(start);
        start = vec[start-1];
        a[start]++;
        num = a[start];
        count1++;
        if(set1.size()!=count1)break;
    }
    //COUT(count-set1.size());//サイクルが開始するまでの個数
    //COUT(set1.size());//サイクルの中の個数
    vec1.pop_back();
    if(k<count-set1.size()){
        COUT(test[k-1]);
    }
    else{
        k-=count-set1.size();
        k%=set1.size();
        int count12 = 0;
        for(int x:vec1){
            if(count12==k){
                COUT(x);
            }
            count12++;
        }
    }
    return 0;
}

Measured memory_bytes: 14644
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll v[100004],ans=0;
int main(){
	int n;
	cin>>n;
	for (int i=0;i<n;i++) cin>>v[i];
	for (int i=0;i<n;i++){
		ll x;
		cin>>x;
		if (x<v[i]) ans+=v[i]-x;
	}
	cout<<ans;
}

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

int main(){
	int H,W;
	while(cin >> H >> W,H||W){
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if((i+j)%2) cout << ".";
				else cout <<"#";
			}
			cout <<endl;
		}
		cout << endl;
	}

	return 0;
}

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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e5 + 1;
const ld pi = acos(-1);
const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 0, (int)A.size()) out << A[i] << " ";
    return out;
}

int32_t main() {
    IOS int d,t,s;  cin>>d>>t>>s;
    puts((s*t >= d) ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 3668
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define int long long
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 1e7 + 10 ;
const ll INF = 1e18 + 10 ;
bool go(string s){
    string t = s ;
    reverse(t.begin(), t.end()) ;
    return t == s ;
}
signed main(){
    fastio
    string s; 
    cin >> s ;
    int n = (int) s.size() ;
    if ( not go(s) ){
        cout << "No" << endl;
        return 0 ;
    }
    if ( not go(s.substr(0, (n - 1) / 2 )) ){
        cout << "No" << endl;
        return 0;
    }
    if ( not go(s.substr((n + 3) / 2 - 1)) ){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0; 
}

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

using namespace std;

int main()
{
	
	long long small = 123412993994123;
	long long big = -123412341234123;
	long long sum = 0;
	int n;
	long long input;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> input;
		sum += input;
		small = min(input, small);
		big = max(input, big);
	}

	cout << small << " " << big << " " << sum << endl;

}


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

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

Measured memory_bytes: 256
n = int(input())
res = [0] * 100001
for x in range(1,110):
    for y in range(1,110):
        for z in range(1,110):
            v = x*x + y*y + z*z + x*y + y*z + x*z
            if v < 100001:
                res[v] += 1
for i in range(n):
    print(res[i+1])

Measured memory_bytes: 69404
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

bool Mark(int v,
          int pv,
          int c,
          const vector<vector<int>>& gr,
          vector<int>& color) {
  color[v] = c;
  for (int u : gr[v]) {
    if (u != pv) {
      if (color[u] == -1) {
        if (!Mark(u, v, 1 - c, gr, color)) {
          return false;
        }
      } else {
        if (color[u] == c) {
          return false;
        }
      }
    }
  }

  return true;
}

int main() {
//  freopen("../Console/1.txt", "rb", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int N, M;
  cin >> N >> M;

  vector<vector<int>> gr(N);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;

    gr[a].push_back(b);
    gr[b].push_back(a);
  }

  vector<int> color(N, -1);
  if (!Mark(0, -1, 0, gr, color)) {
    cout << 1LL * N * (N - 1) / 2 - M << '\n';
    return 0;
  }

  int left = count(color.begin(), color.end(), 0);
  cout << 1LL * left * (N - left) - M << '\n';

  return 0;
}


Measured memory_bytes: 6784
import java.util.Scanner;

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

    char[] s = scanner.next().toCharArray();
    int numZeros = 0;
    for (char c : s) if (c == '0') numZeros++;
    System.out.println(Math.min(numZeros, s.length - numZeros) * 2);
  }
}


Measured memory_bytes: 27860
s = input()
a, b = int(s[:2]), int(s[2:])
yymm = 1 <= b <= 12
mmyy = 1 <= a <= 12
if yymm and mmyy:
  print('AMBIGUOUS')
elif yymm:
  print('YYMM')
elif mmyy:
  print('MMYY')
else:
  print('NA')

Measured memory_bytes: 38256
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    ll N, W;   cin >> N >> W;
    ll *w = new ll[N], *v = new ll[N];
    for (ll i = 0; i < N; i++)
        cin >> w[i] >> v[i];

    ll **dp = new ll *[N+1];
    for (ll i = 0; i <= N; i++)
        dp[i] = new ll[W+1];

    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j <= W; j++) {
            if (w[i] <= j)
                dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i][j]);
            else 
                dp[i+1][j] = dp[i][j];
        }
    }

    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 78592
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N = int(readline())
a = list(map(int,readline().split()))

s = 0
for ai in a:
    s = s^ai
ans = []
for ai in a:
    ans.append(s^ai)
print(' '.join(map(str,ans)))


Measured memory_bytes: 41700
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long int n,m;
    cin>>n>>m;
    long long int man[n][2],po[m][2];
    for(int i=0;i<n;i++){
      cin>>man[i][0]>>man[i][1];
    }
    for(int i=0;i<m;i++){
      cin>>po[i][0]>>po[i][1];
    }
    long long int ans[n],count;
    count=100000000000;
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
      if(count>abs(man[i][0]-po[j][0])+abs(man[i][1]-po[j][1])){
        count=abs(man[i][0]-po[j][0])+abs(man[i][1]-po[j][1]);
        ans[i]=j+1;
      }
      }
      count=100000000000;
    }
    for(int i=0;i<n;i++){
      cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,K=pin()
    a=[0]*N
    for k in range(K):
        d=int(input())
        A=list(pin())
        #print(A)
        for n in range(d):
            a[A[n]-1]+=1
    cnt=0
    for aa in a:
        if aa==0:cnt+=1
    print(cnt)
#%%submit!
resolve()

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

using namespace std;

int main() {
  int cnt=0;
  vector<int> vec(5);
  rep(i,5){
    cin>>vec[i];
    int a=(vec[i]+9)/10*10;
  cnt+=a;
  }
  int ans=cnt;
  rep(i,5){
    int b=vec[i];
    b%=10;
    if(b!=0)ans=min(ans,cnt+b-10);
  }
  cout<<ans<<endl;
}

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

#define ll long long

// GCD, LCM
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main()
{
    int K;
    ll ans=0;

    cin>>K;

    for(int i=1;i<=K;i++){
        for(int j=1;j<=K;j++){
            for(int k=1;k<=K;k++){
                    ans+=gcd(gcd(i,j),k);
            }
        }
    }

    cout<<ans<<endl;    

    return 0;
}

Measured memory_bytes: 3636
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005
ll n;
ll h[N];
ll dp[N];

ll solve(ll pos){
	if(dp[pos]!=-1)return dp[pos];
	if(pos==1){
		return dp[pos]=solve(0)+abs(h[1]-h[0]);
	}
	if(pos==0){
		return dp[pos]=0;
	}
	return dp[pos]=min(solve(pos-1)+abs(h[pos]-h[pos-1]),solve(pos-2)+abs(h[pos]-h[pos-2]));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	rep(i,0,N)dp[i]=-1;
	while(TESTS--)
	{
			cin>>n;
			rep(i,0,n)cin>>h[i];
			cout<<solve(n-1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    vector<int> L(3);
    rep(i,3)cin >> L[i];
    sort(all(L));
    int A = L[0];
    int B = L[1];
    int C = L[2];
    


    if(abs(A-C) % 2 == 0 && abs(B-C) % 2 == 0){     // abs がどっちも偶数
        cout << (abs(A-C)+abs(B-C))/2 << endl;      // 2++ の動作だけでいいので
    }
    else if(abs(A-C) % 2 != 0 && abs(B-C) % 2 != 0){    // abs がどっちも奇数
        cout << (abs(A+1-C)+abs(B+1-C))/2 +1 << endl;   // 1回A,Bそれぞれ1足して、以降は2++だけ
    }
    else{   //abs が　偶数　と　奇数
        if(abs(A-C) % 2 == 0){  // A-C が偶数、B-Cが奇数のとき
            cout << (abs(A-C)+abs(B-C-1))/2 + 1 << endl;
        }
        else{   // A-C が奇数、B-Cが偶数のとき
            cout << (abs(A-C-1)+abs(B-C))/2 + 1 << endl;
        }
    }
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

bool e[51][51];
bool dfs(int i, int j, bool *visited, int N) {
    if(i == j)
        return true;
    if(visited[i])
        return false;
    visited[i] = true;
    bool p = false;
    FOR(x, 1, N + 1) {
        p = p || (e[i][x] && dfs(x, j, visited, N));
    }
    return p;
}

int main() {
    int N, M;
    cin >> N >> M;
    REP(i, N + 1) {
        fill(e[i], e[i] + N + 1, false);
    }
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        e[a][b] = e[b][a] = true;
    }
    int count = 0;
    bool visited[N + 1];
    FOR(i, 1, N + 1) {
        FOR(j, i + 1, N + 1) {
            fill(visited, visited + N + 1, false);
            if(!e[i][j])continue;
            e[i][j] = e[j][i] = false;
            if(!dfs(i, j, visited, N)) {
                count++;
            }
            e[i][j] = e[j][i] = true;
        }
    }
    cout << count << endl;
    return 0;
}


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const int N = 55;
string s;
int n, d[N];
ll b, c;
vector<P> p;
int g[N];

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  rep(i,n) cin >> d[i];
  ll result = 0;
  rep(i,n) for(int j= i+1; j < n; j++) {
    result += d[i]*d[j];
  }
  pl(result);
  br();
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
typedef long long ll;

int fastDigit(int n){
  if(n <= 9) return n;
  else fastDigit(n / 10);
}

int lastDigit(int n){
  return n % 10;
}

int getDigitCount(int n){
  if(n <= 9) return 1;
  else return getDigitCount(n / 10) * 10;
}

void push(int *p, int n){
  int i;
  for(i=0;p[i]!=0;i++);
  p[i] = n;
}

int length(int *p){
  int i;
  for(i=0;p[i]!=0;i++);
  return i;
}

int changeDigit(int n){
  int a,b,l;
  a = lastDigit(n);
  b = fastDigit(n);
  l = getDigitCount(n);
  
  n %= l;//最上位を消す
  n -= a;//最下位を消す
  
  n += a * l;
  n += b;
  
  return n;
}

int main(){
  int n,i,j,count=0,dabu=0;
  ll result=0;
  scanf("%d", &n);
  int c[10][10]={0};
  
  for(i=1;i<=n;i++){
    if(i%10==0) continue;
    c[fastDigit(i)][i%10]++;
  }
  for(i=1;i<=9;i++){
    for(j=1;j<=9;j++){
      result += (ll)c[i][j]*c[j][i];
    }
  }
  printf("%d", result);
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string.h>
#include<set>
#include<vector>
using namespace std;

int main(){
    int N;
    int A;
    long long sum=0;
    long long ans=0;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>A;
        if(A){
            sum+=A;
        }
        else{
            ans+=sum/2;
            sum=0;
        }
    }
    ans+=sum/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
const int N = 200050;
int n, nn[N], v[26][N];
int b[N];
char s[N];
int S[N];
void add(int i, int x) {
  while (i <= n) {
    S[i] += x;
    i += i & -i;
  }
}
int query(int i) {
  int x = 0;
  while (i) {
    x += S[i];
    i -= i & -i;
  }
  return x;
}
int main() {
  scanf("%s", s);
  for (n = 0; s[n]; ++n)
    v[s[n] - 'a'][nn[s[n] - 'a']++] = n;
  int l = 0;
  for (int i = 0; i < 26; ++i) if (nn[i] & 1) ++l;
  if (l > 1) return puts("-1") & 0;
  for (int i = 0; i < 26; ++i)
    for (int j = 0; j < nn[i]; ++j)
      b[v[i][nn[i] - j - 1]] = v[i][j] + 1;
  long long ans = 0;
  for (int i = n - 1; ~i; --i) {
    ans += (n - i - 1) - query(b[i]);
    add(b[i], 1);
  }
  printf("%lld\n", ans / 2);
  return 0;
}


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

// If this structure is used for two-dimensional surface,
// it assumes that the face id[0] faces the positive direction of the Y axis,
// the face id[1] faces the positive direction of the X axis
// and id[2] is top of the dice.
struct Dice {
  int id[6], cnt;
  const static int f[3][3];

  Dice() { init(); }

  void init() {
    for(int i = 0; i < 6; ++i) {
      id[i] = i;
    }
    cnt = 0;
  }

  // type (0:spin, 1:rollX, 2:rollY)
  // dir 1( ccw     neg      pos   )
  //    -1( cw      pos      neg   )
  void rotate(int type, int dir = 1) {
    const int *v = f[type];
    int a,b,c,t; a=v[0]; b=v[1]; c=v[2]; t=id[type];
    if(dir < 0) swap(a,c);
    id[type]=id[a]; id[a]=id[b]; id[b]=id[c]; id[c]=t;
  }

  bool next() {
    ++cnt;
    if(cnt == 24) {
      rotate(0,-1);
      rotate(1,-1);
      cnt = 0;
      return false;
    }
    if(cnt == 4*3) {
      rotate(2,-1);
      rotate(0,-1);
    } else if(cnt%4 == 0) {
      rotate(2);
    } else {
      rotate(0);
    }
    return true;
  }

  void roll(int dir) {
    //const static int dx[] = {1,0,-1,0};
    //const static int dy[] = {0,1,0,-1};
    switch(dir) {
      case 0: rotate(1,-1); break;
      case 1: rotate(2, 1); break;
      case 2: rotate(1, 1); break;
      case 3: rotate(2,-1); break;
    }
  }

  bool operator < (const Dice &d) const {
    for(int i = 0; i < 3; ++i)
      if(id[i] != d.id[i]) return id[i] < d.id[i];
    return false;
  }

  void show() {
    cout << id[4] << " / \\ " << id[5] << endl;
    cout << " /   \\" << endl;
    cout << "|\\ " << id[2] << " /|" << endl;
    cout << "|" << id[0] << "\\ /" << id[1] << "|" << endl;
    cout << " \\ | /" << endl;
    cout << "  \\|/" << endl;
    cout << "   " << id[3] << endl;
  }
};
const int Dice::f[3][3] = {{4,5,1},{3,4,2},{5,3,0}};


int main() {
  map<string,int> id;
  for(int n; cin >> n && n;) {
    set<vector<int> > st;
    for(int i = 0; i < n; ++i) {
      vector<int> v;
      for(int j = 0; j < 6; ++j) {
        string s;
        cin >> s;
        if(!id.count(s)) id[s] = id.size()-1;
        v.push_back(id[s]);
      }
      Dice d;

      do {
        vector<int> u;
        for(int j = 0; j < 6; ++j) {
          u.push_back(v[d.id[j]]);
        }
        st.insert(u);
      } while(d.next());
    }
    cout << n - (int)st.size()/24 << endl;
  }
  return 0;
}

Measured memory_bytes: 1292
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii; 
typedef pair < ll, ll > pll;
 
const int N = int(2e5) + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e18; 
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int a;
string s;
int main (){
    cin >> a >> s;
    if (a < 3200) return cout << "red\n", 0;
    return cout << s << "\n", 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9 + 7;
pair<ll, ll>s4[4] = {{ -1, 0}, {1, 0}, {0, -1}, {0, 1}};
pair<ll, ll>s8[8] = {{ -1, -1}, { -1, 0}, { -1, 1}, {0, -1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}};

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

void solve() {
	int n;
	cin >> n;
	cout << n*n*n << nl;
}

signed main() {
	judge();
	boost;
	solve();
}


Measured memory_bytes: 3628
n = int(input())
b = list(map(int, input().split()))
ans = []
while n > 0:
    k = n
    for i in range(n):
        if b[i] == i + 1:
            k = i
    if k == n:
        print(-1)
        exit()
    ans.append(b.pop(k))
    n -= 1
for i in ans[::-1]:
    print(i)

Measured memory_bytes: 3060
from fractions import gcd
import sys
a,b,k=map(int,input().split())
n=gcd(a,b)
#find the kth divisor of n
cnt=0
for i in range(n,0,-1):
    if n%i==0:
        cnt+=1
        if cnt==k:
            print(i)
            sys.exit()


Measured memory_bytes: 5048
#include<iostream>
#include<iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

#define R 1000000007

using namespace std;

int main()
{
    long double a, b, x, h, angle;
    cin >> a >> b >> x;
    h = x / (a * a);
    if(h * a <= (a * b) / 2)
    {
        angle = atan((b * b) / (2 * a * h));
    }
    else
    {
        angle = atan((2 * (b - h)) / a);
    }
    cout << setprecision(20) << angle * 180 / M_PI << '\n';
    
}


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

using namespace std;

int main()
{
	int n,q;
	string s;

	cin >> n >> q >> s;

	vector<int> v(n+1,0);

	int count = 0;

	for (int i = 1; i < s.length(); i++) {
		if (s[i - 1] == 'A' && s[i] == 'C') {
			count++;
		}
		v[i] = count;
	}

	vector<int> l(q + 1, 0);
	vector<int> r(q + 1, 0);

	for (int i = 0; i < q; i++) {
		cin >> l[i] >> r[i];
	}

	for (int i = 0; i < q; i++) {


		cout << v[r[i] - 1] - v[l[i] - 1] << endl;
	}
}


Measured memory_bytes: 2176
import sys

lines = [line.strip().split() for line in sys.stdin.readlines() if line != "\n"]

for line in lines:
    c = int(line[0])
    d = int(line[2])
    op = line[1]

    if op == "+":
        print(c + d)
    elif op == "-":
        print(c - d)
    elif op == "*":
        print(c * d)
    elif op == "/":
        print(c // d)
    else:
        pass



Measured memory_bytes: 5612
from itertools import product
N = int(input())
s = input()
s += s[0]

def isOK(x, y):
    lst = [-1] * (N+2)
    lst[0] = x
    lst[1] = y
    for i in range(1, N+1):
        if (s[i] == 'o') ^ (lst[i]):    # 両隣は違う
            lst[i+1] = 1 - lst[i-1]
        else:                       # 両隣は同じ
            lst[i+1] = lst[i-1]
    if lst[0] == lst[-2] and lst[1] == lst[-1]:     # 1周回って同じ
        return lst[:-2]
    else:
        return []

for x, y in product([1,0], repeat=2):
    chk = isOK(x, y)
    if len(chk) > 0:
        break

if len(chk) == 0:
    ans = -1
else:
    ans = ''
    for x in chk:
        if x:
            ans += 'S'
        else:
            ans += 'W'
print(ans)


Measured memory_bytes: 4836
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main(void)
{
	char A[11] = {}, B[11] = {};
	int numA = 0, numB = 0;
	char Getstr[11] = {};

	scanf("%s %s", A, B);
	scanf("%d %d", &numA, &numB);
	scanf("%s", Getstr);
	
	for (int i = 0; Getstr[i] == A[i]; i++)
	{
		if (Getstr[i] != A[i])
		{
			break;
		}
		else if (Getstr[i] == A[i] && Getstr[i] == '\0'&& A[i] == '\0')
		{
			printf("%d %d\n", numA - 1, numB);
			return 0;
		}
	}

	for (int i = 0; Getstr[i] == B[i]; i++)
	{
		if (Getstr[i] != B[i])
		{
			break;
		}
		else if (Getstr[i] == B[i] && Getstr[i] == '\0'&& B[i] == '\0')
		{
			printf("%d %d\n", numA, numB - 1);
			return 0;
		}
	}

	return 0;
}

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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int n;
    cin>>n;
    int d,x;
    cin>>d>>x;
    int ans=x;
    for(int i=0;i<n;i++){
        int tmp;
        cin>>tmp;
        int j=0,cho=1;
        while(cho<=d){
            ans++;
            j++;
            cho=tmp*j+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
# Union-Findデータ構造
class UnionFind:
    def __init__(self, numV):
        self.pars = list(range(numV))
        self.ranks = [0] * numV
    def find(self, x):
        if self.pars[x] == x: return x
        else:
            self.pars[x] = self.find(self.pars[x])
            return self.pars[x]
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return
        if self.ranks[x] < self.ranks[y]:
            self.pars[x] = y
        else:
            self.pars[y] = x
            if self.ranks[x] == self.ranks[y]:
                self.ranks[x] += 1
    def same(self, x, y):
        return self.find(x) == self.find(y)


N, M = map(int, input().split())

UF = UnionFind(N)
for _ in range(M):
    X, Y, Z = map(int, input().split())
    UF.union(X-1, Y-1)

for i in range(N):
    UF.find(i)

parents = UF.pars
print(len(set(parents)))


Measured memory_bytes: 13932
def main():
    while True:
        stdin = input()
        a, op, b = int(stdin.split()[0]), stdin.split()[
            1], int(stdin.split()[2])
        if op == "?":
            break
        elif op == "+":
            print(a + b)
        elif op == "-":
            print(a - b)
        elif op == "*":
            print(a * b)
        elif op == "/":
            print(a // b)


if __name__ == "__main__":
    main()



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

int main() {
  
  int N;
  int X;
  
  cin >> N >> X;
  
  vector<int> S(N);
  
  int num = 0;
  int num2 = 0;  
  
  for(int i = 0;i < N;++i){
    cin >> S[i];
  }
  
  for(int i = 0;i < N + 1;++i){
    if(num <= X){
       num2++;
      num = num + S[i];
    }
    else{
      break;
    }
}
  
  cout << num2 << endl;
}



Measured memory_bytes: 256
// Author: Tyler Wang

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.precision(12);
  std::cerr.precision(12);
  std::mt19937 rng((std::uint_fast32_t)std::chrono::high_resolution_clock::now()
                       .time_since_epoch()
                       .count());
  int n, W;
  cin >> n >> W;
  vector<int> w(n), v(n);
  for (int i = 0; i < n; ++i) {
    cin >> w[i] >> v[i];
  }
  constexpr int N = 123456;
  constexpr long long INF = 1e18;
  vector<long long> dp(N + 1, INF);
  dp[0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = N - v[i]; j >= 0; --j) {
      dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
    }
  }
  for (int i = N; i >= 0; --i) {
    if (dp[i] <= W) {
      cout << i << '\n';
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
 
int main () {
  vector<int>n(32);
  n={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  int k;
  cin >>k;

  cout <<n[k-1]<<endl;
return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> d = new ArrayList<Integer>();
        d.add(sc.nextInt());
        d.add(sc.nextInt());
        d.add(sc.nextInt());
        List<Integer> s = d.stream().sorted().collect(Collectors.toList());
        for(int i = 0; i < 3; i++) {
            if (i == 2) {
                System.out.println(s.get(i));
            }else {
                System.out.print(s.get(i) + " ");
            }
        }
    }
}


Measured memory_bytes: 32384
#include <stdio.h>

int main()
{
    signed short count[9]={0};
    signed short temp;
    signed short max_count= 0;
    for(char x = 0;x<3;x++)
    {
        scanf("%hd",&temp);
        count[temp-1]++;
        if(max_count <= count[temp-1])
        {
            max_count = count[temp-1];
        }

    }

    if(max_count == 2)
     printf("Yes\n");
    else
     printf("No\n");

    return 0;
}

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


int main() {
	
	int time=1000;
	vector<int> a(5);
	for(auto &i:a) cin >> i;
	for(int i=0; i<5; i++){
		for(int j=0; j<5; j++){
			if(j==i) continue;
			for(int k=0; k<5; k++){
				if(k==i||k==j) continue;
				for(int l=0; l<5;l++){
					if(l==i||l==j||l==k) continue;
					for(int m=0; m<5; m++){
						if(m==i||m==j||m==k||m==l) continue;
						int t;
						t = (a.at(i)+9)/10*10;
						t = (t+a.at(j)+9)/10*10;
						t = (t+a.at(k)+9)/10*10;
						t = (t+a.at(l)+9)/10*10;
						t = t+a.at(m);
						time = min(time, t);
					}
				}
			}
		}
	}
	cout << time << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;

ll ans , n , s;

void work1(){
	ll cur = n - s , p = sqrt(n);
	if(p * p == n) p ++;
	if(n == s) ans = n + 1;
	for(int i = 1 ; 1ll * i * i <= cur ; ++ i)
		if(cur % i == 0){
			ll b = i + 1;
			if(b >= p && n / b == cur / i)
				ans = min(ans , b);
			b = cur / i + 1;
			if(b >= p && n / b == i)
				ans = min(ans , b);
		}
}
void force(){
	for(ll b = 2 ; b * b <= n ; ++ b){
		ll tmp = n , cur = 0;
		while(tmp){
			cur += tmp % b;
			tmp /= b;
		}
		if(cur == s){
			ans = min(ans , b);
			break;
		}
	}
}
int main(){
	cin >> n >> s;
	ans = n + 2;
	work1();
	force();
	if(ans == n + 2)
		cout << -1 << endl;
	else
		cout << ans << endl;
	return 0;
}

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

using namespace std;

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

    if(*(--a.end()) == *(b.begin()) && *(--b.end()) == *(c.begin())){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

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

int main(){
  int H,W,h,w;cin >> H >> W >> h >> w;
  cout << (H*W) - (h*W + w*H-h*w) << endl;
  return 0;
}

Measured memory_bytes: 256
MOD = 10**9 + 7

s = input().strip()
ss = s[::-1]
rs = [10**i % 13 for i in range(6)]

n = len(s)
dp = [[0] * 13 for _ in range(n)]
for i, c in enumerate(ss):
    if i == 0:
        if c == '?':
            for j in range(10):
                dp[i][j] = 1
        else:
            dp[i][int(c)] = 1
    else:
        r = rs[i % 6]
        if c == '?':
            for j in range(13):
                for k in range(10):
                    dp[i][(j + r * k) % 13] += dp[i - 1][j]
        else:
            for j in range(13):
                dp[i][(j + r * int(c)) % 13] += dp[i - 1][j]
        for j in range(13):
            dp[i][j] %= MOD
print(dp[n - 1][5] % MOD)

Measured memory_bytes: 62300
n = int(input())
mat = [[0] * n for _ in range(n)]
for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    for j in adj[2:]:
        mat[i - 1][j - 1] = 1
for m in mat:
    print(' '.join(map(str, m)))

Measured memory_bytes: 7816
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
ans=int(N**.5)
print(ans*ans)

Measured memory_bytes: 2940
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

typedef pair < int , int > pii ;
typedef pair < long long  , long long > pll ;

const int N = 2e5 + 1 , K = 501;
int n , m , k;
int a[60];
bool bad(){
	return *max_element(a + 1 , a + 1 + n) > n - 1;
}
bool check(int x){ 
	//a[i] + 2 + x <= (N + 1) * (x[i] - 1)
	//a[i] - k * n + (x - k) <= n - 1
	int tot = 0;
	for(int i = 1 ; i <= n; i++){
	  	int l = 0 , r = min<ll>(x , 1e16 + 1000) , add = 1e16;
	  	while(l <= r){
	  		int m = (l + r) >> 1;
	  		if(a[i] - m * n + (x - m) <= n - 1)
	  			add = m , r = m - 1;
	  		else l = m + 1;
	  	}
	  	tot += add;
	  	if(tot > x)return false;
	}
	return 1;
}
main(){
	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	cin >> n ;
	int sum = 0;
	for(int i = 1; i <= n ; i++){
//		a[i] = rnd(100 * n) + 1;
//		a[i] = k;
		sum += a[i];
		cin >> a[i];
	}
	int cnt = 0;
	//a[i] + 2 + k  <=  (N + 1) * (x[i] - 1)  ;
	int l = 0 , r = 1e18 , res = 1e18 ;
	//1e13
//	ret(check(475457939086683502ll));
	while(l <= r){
		int m = (l + r) >> 1;
		int pos = -1;
		for(int i = max(m - 50* 50, 0ll) ; i <= m  ; i++)
			if(check(i))
				pos = i, i = m + 1;
							
		if(pos != -1){
			r = pos - 1 ;
			res = pos;
		}
		else l = m + 1;
	}

 	int ans = res;	
 	cerr << res << '\n';

/*	for(int i = res - 1 ; i >= 0 ; i--){
		if(check(i))
			ans = i;
		if(clock()/CLOCKS_PER_SEC > 1.9)break;
	}*/
//	cerr << ' ';
    ret(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

inline int read () {
    int ret = 0, t = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') t = -1, c = getchar();
    while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
    return ret * t;
}

int main () {
    int n = read();
    bool f = false;
    while (n--) {
        int x = read();
        if (x % 2 == 0) 
        {
            if (x % 3 != 0 && x % 5 != 0) { puts("DENIED"); return 0; }
        }
    }
    puts("APPROVED");
    return 0;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c&&c==a)cout<<1<<endl;
    else if(a!=b&&b!=c&&c!=a)cout<<3<<endl;
    else cout<<2<<endl;
    return 0;
}

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


int main(){
   int n,m;

   pair<int,int> data[100005];
   cin>>n>>m;
   for(int i=0;i<m;i++){
       int a,b;
       cin>>a>>b;
       data[i]=make_pair(b,a);
   }
   sort(data,data+m);
   int before=-1;
   int ans=0;
   for(int i=0;i<m;i++){
       if(before>=data[i].second) continue;
       ans++;
       before=data[i].first-1;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 1404
n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
i=0
num=0

if a[0] > x:
        ans=a[0]-x
        a[0]=a[0]-ans
        num=num+ans
while i<n-1:
        if a[i] + a[i+1] > x:
                ans=a[i] + a[i+1] - x
                a[i+1]=a[i+1]-ans
                num=num+ans
        else:
                i=i+1

print num

Measured memory_bytes: 11340
#include <queue>
#include <vector>
#include <string>
#include <iostream>

using namespace std;


int main() {
    int H {}, W {};
    cin >> H >> W;
    string A[H];
    for (int h=0; h<H; h++) {
        cin >> A[h];
    }

    // initialize first black positions
    queue<vector<int>*> black_list {};
    int **f = new int*[H];
    for (int h=0; h<H; h++) {
        f[h] = new int[W];
        for (int w=0; w<W; w++) {
            if (A[h][w] == '#') {
                f[h][w] = true;
                black_list.push(new vector<int> {h, w, 0});
            } else {
                f[h][w] = false;
            }
        }
    }
  
    int ans = 0;
    // expand black positions until all positions fill
    while (!black_list.empty()) {
        vector<int> *pos = black_list.front();
        int h = (*pos)[0];
        int w = (*pos)[1];
        int d = (*pos)[2];
        // up
        if (h-1 >= 0 && f[h-1][w] == false) {
            f[h-1][w] = true;
            black_list.push(new vector<int> {h-1, w, d+1});
        }
        // down
        if (h+1 < H && f[h+1][w] == false) {
            f[h+1][w] = true;
            black_list.push(new vector<int> {h+1, w, d+1});
        }
        // left
        if (w-1 >= 0 && f[h][w-1] == false) {
            f[h][w-1] = true;
            black_list.push(new vector<int> {h, w-1, d+1});
        }
        // right
        if (w+1 < W && f[h][w+1] == false) {
            f[h][w+1] = true;
            black_list.push(new vector<int> {h, w+1, d+1});
        }
        ans = d;
        black_list.pop();
        delete pos;
    }

    cout << ans << endl;
}


Measured memory_bytes: 75920
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include<iomanip>
#include<tuple>
#include<cmath>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int N,K;
    int h[100010];
    int dp[100010];
    cin>>N>>K;
    for(int i=0;i<10010;i++){
        h[i]=0;
    }
    for (int i=0;i<N;i++){
        cin>>h[i];
    }
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    
    for(int n=2;n<N;n++){
        dp[n]=INF;
        for (int k=1;k<=K;k++){
            if(n-k>=0)dp[n]=min(dp[n],dp[n-k]+abs(h[n]-h[n-k]));
        }
        //cout<<"dp["<<n<<"]"<<dp[n]<<endl;
    }
    cout<<dp[N-1]<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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 (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    int N; cin >> N;
    ve_vel p(N, vel(2));
    rep(i,N) {
        ll a, b; cin >> a >> b;
        p[i][0] = b, p[i][1] = a;
    }
    sort(all(p));
    ll time = 0LL;
    rep(i,N) {
        time += p[i][1];
        if(time > p[i][0]) {cout << "No" << endl; return 0;}
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 11264