akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <atcoder/all>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;
static const ll mod = 1e9 + 7;

template<typename T>
static inline void chmin(T & ref, const T  value) {
	if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T & ref, const T value) {
	if (ref < value) ref = value;
}

struct UnionFind {
public:
	vector <ll> par; // 
	vector <ll> siz; // 

	UnionFind() {}

	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}

	ll root(ll x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

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

	ll size(ll x) {
		return siz[root(x)];
	}
};
int main() {
	ll n, m;
	cin >> n >> m;
	UnionFind uf(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		uf.merge(a, b);
	}
	set<int> nodes;
	rep(i, n) {
		nodes.insert(uf.root(i));
	}
	cout << nodes.size() - 1 << endl;
	return 0;
}


Measured memory_bytes: 8352
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt int Q[100005]={0}
#define mp make_pair
#define test() int t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<int>()) 
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(int i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(int i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int,int> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=mpowe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
 
int main()
{                       
    fastio();
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++) //0から
#define REP(i,n) for(int j=i;j<n;j++) //iから
#define in(a) cin>>a
#define out(a) cout<<a<<endl

long long int kaijo(long long int n){
    if(n == 0) return 1;
    return n * kaijo(n-1);
}


vector<bool> is_prime;
void Eratosthenes(long long int n){
    is_prime.resize(n+1,true);
    is_prime[0]=false;
    is_prime[1]=false;
    for(long long int i = 2; i <= n; i++){
        if(is_prime[i]){
            for(long long int j = i*i; j <= n; j++){
                is_prime[j] = false;
            }
        }
    }
}

//素数列挙
vector<long long int> Prime;
void Prime_Enumeration(long long int n){
    Eratosthenes(n);
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            Prime.push_back(i);
        }
    }
}

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

long long int lcm(long long int a, long long int b){
    long long int g = gcd(a,b);
    long long int l = (a * b) / g;

    return l;
}

//aが負の時でも余りを非負にしたいとき
long long  mod(long long a, long long m){
    return (a % m + m) % m;
}

//拡張ユークリッド ap + bq = gcd(a,b)
long long extGCD(long long a, long long b, long long &p, long long &q){
    if(b == 0){ p = 1; q = 0; return a;}
    long long d = extGCD(b, a % b, q, p);
    q -= a /b * p;
    
    return d;
}

//中国剰余定理
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2){
    long long p, q;
    long long d = extGCD(m1, m2, p, q);

    if((b2-b1) % d != 0) return make_pair(0, -1); //解なし

    long long m = m1 * (m2 / d);
    long long tmp = (b2 - b1) / d * p % (m2 / d);
    long long r =mod(b1 + m1 * tmp, m);

    return make_pair(r, m);
}

//mod.mでのa^{-1}
long long modinv(long long a, long long m){
    long long b = m, u = 1, v = 0;
    while(b){
        long long t = a /b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if(u < 0)u += m;
    return u;

}
const long long MOD = 1000000007;

//key以上のうち最小の要素のindex
int binary_search(long long int *a, long long int n, long long int key){
    long long int right = n, left = -1;
    long long int md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}


int main(){
    long long int n,k;
    string s;

    cin>>n>>k;

    long long int ans = 1,m;
    m=k;
    while(n>=m){
        ans++;
        m*=k;
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

typedef pair<pll,ll> ppll;

int main() {
  ll n,m,s;
  cin >> n >> m >> s;
  vector<vector<ppll>> G(n);
  for(ll i=0;i<m;i++) {
    ll u,v,a,b;
    cin >> u >> v >> a >> b;
    u--,v--;
    G[u].push_back({{v,a},b});
    G[v].push_back({{u,a},b});
  }
  vec c(n),d(n);
  for(ll i=0;i<n;i++) cin >> c[i] >> d[i];
  priority_queue<ppll,vector<ppll>,greater<ppll>> q;
  q.push({{0,0},min(5000LL,s)});
  mat dp(n,vec(5001,-1));
  vec ans(n);
  while(q.size()) {
    auto p=q.top();
    q.pop();
    ll f=p.first.second;
    ll dis=p.first.first;
    ll re=p.second;
    if(dp[f][re]>-1) continue;
    dp[f][re]=dis;
    if(!ans[f]) ans[f]=dis;
    for(auto pp:G[f]) {
      ll co=pp.first.second;
      ll t=pp.first.first;
      ll nd=pp.second;
      if(re>=co&&dp[t][re-co]==-1) {
        q.push({{dis+nd,t},re-co});
      }
    }
    if(re+c[f]<=5000) q.push({{dis+d[f],f},re+c[f]});
  }
  for(ll i=1;i<n;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 17524
import java.util.Scanner;

	public class Main {

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

			int n = sc.nextInt();
			int i,j,k;


			for(i=3;i<=n;i++){
				if(i%3==0) System.out.print(" "+i);
				else {
					for(j=i;j>0;j/=10){
						if(j%10==3){
							System.out.print(" "+i);
							break;
						}

					}
						
			}
		}

			System.out.print("\n");		
	}
}

Measured memory_bytes: 28832
def judge(t, x1, y1, x2, y2):
    if abs(x2 - x1) + abs(y2 - y1) > t:
        return False
    else:
        t -= abs(x2 - x1) + abs(y2 - y1)
        if 0 == t % 2:
            return True
        else:
            return False


n = int(input())
ans = "Yes"
now_x, now_y = 0, 0
t0 = 0
for _ in range(n):
    t, x, y = map(int, input().split())
    if judge(t-t0, now_x, now_y, x, y):
        now_x, now_y = x, y
        t0 = t
    else:
        ans = "No"
        break
print(ans)

Measured memory_bytes: 3064
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - ABC Swap
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int x, y, z;
  scanf("%d%d%d", &x, &y, &z);

  printf("%d %d %d\n", z, x, y);
  return 0;
}


Measured memory_bytes: 256
a, b, q = gets.split.map(&:to_i)
s = [1000000000000]
t = [1000000000000]
x = []
a.times do
  s.push gets.chomp.to_i
end
b.times do
  t.push gets.chomp.to_i
end
q.times do
  x.push gets.chomp.to_i
end

sorted_s = s.sort
sorted_t = t.sort
x.each do |j|
  ind_s_p = sorted_s.bsearch_index { |e| e >= j }
  if ind_s_p > 0
    ind_s_n = ind_s_p - 1
  else
    ind_s_n = 0
  end
  ind_t_p = sorted_t.bsearch_index { |e| e >= j }
  if ind_t_p > 0
    ind_t_n = ind_t_p - 1
  else
    ind_t_n = 0
  end
  candidate = []
  [ind_s_p, ind_s_n].each do |is|
    [ind_t_p, ind_t_n].each do |it|
      ss = sorted_s[is] - j
      tt = sorted_t[it] - j
      if ss * tt >= 0
        candidate.push [ss.abs, tt.abs].max
      else
        candidate.push [ss.abs, tt.abs].min * 2 + [ss.abs, tt.abs].max
      end
    end
  end
  puts candidate.min
end


Measured memory_bytes: 7528
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    r,s,p=map(int,input().split())
    T=input()
    T_lis=[False]*n
    ans=0
    for i,t in enumerate(T):
        if i-k>=0:
            if T[i-k]==t and T_lis[i-k]:
                continue
        if t=='r':
            ans+=p
        elif t=='s':
            ans+=r
        else:
            ans+=s
        T_lis[i]=True
    print(ans)


if __name__=='__main__':
    main()

Measured memory_bytes: 4084
#include "bits/stdc++.h"

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll N, M;

int main(){
	cin >> N >> M;
	M = max<ll>(1, M);
	N = max<ll>(1, N);
	p(N*(N-1)/2 + M*(M-1)/2);
	return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int n;
int ans;//合計点
int top,dow,rig;//上の面、下の面、右の面の出目
string sousa;
int main(){
  while(true){
  scanf("%d",&n);//操作回数の入力
  if(n ==0)
    break;
  top = 1;
  dow = 2;
  rig = 3;
  ans = 1;
  int temp1,temp2,temp3;
  for(int i= 0;i < n;i++){
    cin >> sousa;
    temp1 = top;
    temp2 = dow;
    temp3 = rig;

    if(sousa == "North"){
      top = temp2;
      dow = 7-temp1;
      rig = temp3;
      ans +=top;
    }else if(sousa =="East"){
      top = 7-temp3;
      dow = temp2;
      rig = temp1;
      ans +=top;
    }else if(sousa =="West"){
      top = temp3;
      dow = temp2;
      rig = 7-temp1;
      ans +=top;
    }else if(sousa =="South"){
      top = 7-temp2;
      dow = temp1;
      rig = temp3;
      ans +=top;
    }else if(sousa =="Right"){
      top = temp1;
      dow = temp3;
      rig = 7-temp2;
      ans += top;
    }else if(sousa =="Left"){
      top = temp1;
      dow = 7-temp3;
      rig = temp2;
      ans += top;
    }
}
  printf("%d\n",ans);
  }
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int arr[] = {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<<arr[K-1]<<endl;
}

Measured memory_bytes: 256
n, p = map(int, input().split())

if n==1:
    print(p)
else:
    out=1
    tm = int(pow(p, 1/n))
    for i in range(2,tm+1):
        while p%(i**n)==0:
            p = p//(i**n)
            out *= i
        if p < i**n:
            break
    print(out)

Measured memory_bytes: 3060
N = gets.to_i
array = gets.split(" ").map{|item| item.to_i}
gaps = []

for i in 1...N
  s1 = 0
  s2 = 0
  subarray1 = array.slice(0, i)
  subarray2 = array.slice(i, N-1)
  for i in 0...subarray1.length
    s1 += subarray1[i]
  end
  for i in 0...subarray2.length
    s2 += subarray2[i]
  end
  gaps.push((s1-s2).abs)
end

p gaps.min

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

//.define
// #define FILE_IN_OUT
#define RET(_x)                       return cout << (_x) << '\n', 0;
#define all(_obj)                     (_obj).begin(), (_obj).end()
#define loop(_n)                      for (int i = 0; i < (_n); ++i)
#define CeilDiv(_dividend, _divider)  (((_dividend) - 1LL + (_divider)) / (_divider))
#define sz(_obj)                      static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)                     std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)                     {}
#endif
#define endl "\n"
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int n, m, k;
    cin >> n >> m >> k;
    vector<int> arr(n + 1, 0);
    loop(n) {
        cin >> arr[i + 1];
    }
    vector<ll> brr(m + 1, 0);
    loop(m) {
        cin >> brr[i + 1];
        brr[i + 1] += brr[i];
    }
    ll sum = 0;
    int ans = 0;
    loop(n + 1) {
        sum += arr[i];
        if (sum > k) {
            break;
        }
        int j = distance(begin(brr), upper_bound(all(brr), k - sum)) - 1;
        ans = max(i + j, ans);
    }
    cout << ans << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

Measured memory_bytes: 5568
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod = 1000000007;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
	int n;
	cin >> n;
	int t[101] = { 0 };
	int tt[101] = { 0 };
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		t[i+1] = x;
		tt[i+1] = x;
	}
	int m;
	cin >> m;
	for(int i = 1; i <= m; i++) {
		int p, x;
		cin >> p >> x;
		t[p] = x;
		cout << accumulate(t, t + 101, 0) << endl;
		for(int i = 0; i < 101; i++)
			t[i] = tt[i];
	}
    return 0;
}



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

using namespace std;

using ll = long long;

const int MX = 3007;

vector<int> g[MX];
int a[MX];

bool dfs(int v, int p = -1) {
    for (int to : g[v]) {
        if (to != p && a[to] < a[v] && !dfs(to, v)) {
            return true;
        }
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
        if (dfs(i)) {
            cout << i << " ";
        }
    }
    cout << "\n";
    return 0;
}




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

multiset<int> a;
int n, x;

int main()
{
	scanf("%d", &n);
	while (n--)
	{
		scanf("%d", &x);
		a.insert(x);
	}
	scanf("%d", &n);
	while (n--)
	{
		scanf("%d", &x);
		auto it = a.find(x);
		if (it == a.end() || *it != x)
		{
			printf("NO\n");
			return 0;
		}
		a.erase(it);
	}
	printf("YES\n");
	return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll a[99];
int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	rep(i,0,m){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		a[x]++;
		a[y]++;
	}
	rep(i,0,n)printf("%lld\n",a[i+1]);
}

Measured memory_bytes: 128
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


N = int(sys.stdin.readline())

print(N // 3)

Measured memory_bytes: 63852
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,ans=0;
    string s;
    cin>>n>>s;
    ll dp[5010][5010];
    rep(i,5010)rep(j,5010) dp[i][j]=0;
    for(ll i=n-1;i>=0;i--){
        for(ll j=n-1;j>=0;j--){
            if(s[i]==s[j]){
                dp[i][j]=max(dp[i][j],dp[i+1][j+1]+1);
            }
            ans = max(ans,min(dp[i][j],j-i));
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
    long long k;
    long long a,b;

    cin >> k >> a >> b;

    long long bis = 1;

    if(b-a <= 2){
        cout << k+1 << endl;
    }
    else{
        bis = a; //add bis
        k -= a-1; // use k til bis == a
        bis += k/2 * (b-a);
        cout << bis+k%2 << endl;
    }
    return 0;
}

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

int main() {

	int k, s;
	cin >> k >> s;

	int ans = 0;
	int tmp = 0;

	for (int i = 0; i <= k; i++) {
		if (i > s) break;
		if (3 * k < s)break;
		tmp = s - i;

		if ( k >= tmp) {
			ans += tmp + 1;
		}
		else if (2 * k >= tmp) {
			for (int j = 0; j <= k; j++) {
				if (tmp - j > k)continue;
				ans++;
			}
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
vector<int> w[200000];
int n,m,c[200000],vis[200000];
bool dfs(int u)
{
	if(vis[u])return 1;
	vis[u]=1;
	for(int i:w[u])
		if(c[i]==c[u])return 0;
		else
		{
			c[i]=!c[u];
			if(!dfs(i))return 0;
		}
	return 1;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		w[u].push_back(v);
		w[v].push_back(u);
	}
	memset(c,-1,sizeof c);
	c[1]=1;
	if(!dfs(1))printf("%lld\n",n*(n-1ll)/2-m);
	else
	{
		long long b=0,w=0;
		for(int i=1;i<=n;i++)
			if(c[i])w++;
			else b++;
		printf("%lld\n",b*w-m);
	}
	return 0;
}


Measured memory_bytes: 9984
import java.util.*;
import java.io.*;

public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args) throws IOException{
		NScanner sc = new NScanner(System.in);
		int[] a = new int[6];
		for(int i = 0; i < 6; ++i)
			a[i] = sc.nextInt();
		Dice d = new Dice(a);
		String com = sc.next();
		for(int i = 0; i < com.length(); ++i){
			if(com.charAt(i) == 'N') d.turnN();
			else if(com.charAt(i) == 'S') d.turnS();
			else if(com.charAt(i) == 'E') d.turnE();
			else if(com.charAt(i) == 'W') d.turnW();
		}
		System.out.println(d.Top);
	}

}

class Dice{
	int Top, Front, Right, Left, Back, Bottom;
	Dice(int[] a){
		Top = a[0]; Front = a[1]; Right = a[2];
		Left = a[3]; Back = a[4]; Bottom = a[5];
	}
	void turnN(){
		int tmp = Top; Top = Front; Front = Bottom;
		Bottom = Back; Back = tmp;
	}
	void turnS(){
		int tmp = Top; Top = Back; Back = Bottom;
		Bottom = Front; Front = tmp;
	}
	void turnE(){
		int tmp = Top; Top = Left; Left = Bottom;
		Bottom = Right; Right = tmp;
	}
	void turnW(){
		int tmp = Top; Top = Right; Right = Bottom;
		Bottom = Left; Left = tmp;
	}
}

class NScanner{

	private BufferedReader br;
	private StringTokenizer tok;

	public NScanner(InputStream is) throws IOException{
		br = new BufferedReader(new InputStreamReader(is));
		getLine();
	}

	private void getLine() throws IOException{
		while(tok == null || !hasNext()){
			tok = new StringTokenizer(br.readLine());
		}
	}

	public boolean hasNext(){
		return tok.hasMoreTokens();
	}

	public String next() throws IOException{
		if(hasNext()){
			return tok.nextToken();
		}else{
			getLine();
			return tok.nextToken();
		}
	}

	public int nextInt() throws IOException{
		if(hasNext()){
			return Integer.parseInt(tok.nextToken());
		}else{
			getLine();
			return Integer.parseInt(tok.nextToken());
		}
	}

	public long nextLong() throws IOException{
		if(hasNext()){
			return Long.parseLong(tok.nextToken());
		}else{
			getLine();
			return Long.parseLong(tok.nextToken());
		}
	}

	public double nextDouble() throws IOException{
		if(hasNext()){
			return Double.parseDouble(tok.nextToken());
		}else{
			getLine();
			return Double.parseDouble(tok.nextToken());
		}
	}
}


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

int main() {
	int N;
	cin >> N;
	vector<int> L(N);
	int sum = 0, max_num = 0;
	for (int i = 0; i < N; i++) {
		cin >> L[i];
		sum += L[i];
		if (L[i] > max_num) 
			max_num = L[i];
	}
	cout << (((sum - max_num) > max_num) ? "Yes" : "No");

}

Measured memory_bytes: 256
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    n = ii()
    a = li()
    a.insert(0, 0)
    cnt = 0
    for i in range(1, n + 1):
        if i % 2 and a[i] % 2:
            cnt += 1
    print(cnt)


main()


Measured memory_bytes: 10016
N = input()

a = N.count('1')
b = N.count('2')
c = N.count('3')
d = N.count('4')
e = N.count('5')
f = N.count('6')
g = N.count('7')
h = N.count('8')
i = N.count('9')

total = 1 * a + 2 * b + 3 * c + 4 * d + 5 * e + 6 * f + 7 * g + 8 * h + 9 * i

N_int = int(N)

if N_int % total == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
X,Y,A,B,C=list(map(int,input().split()))
A_l=list(map(int,input().split()))
B_l=list(map(int,input().split()))
C_l=list(map(int,input().split()))
A_l.sort(reverse=True)
B_l.sort(reverse=True)
C_l.sort()
A_after_l=A_l[:X]
B_after_l=B_l[:Y]
ans=[A_after_l,B_after_l]
ans=sum(ans,[])
ans.sort()
import heapq
heapq.heapify(ans)
for i in C_l:
   N=heapq.heappop(ans)
   if N < i:
      heapq.heappush(ans,i)
   else:
      heapq.heappush(ans,N)
print(sum(ans))

Measured memory_bytes: 29500
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double n,d,x,y,i,r,c=0;
    cin>>n>>d;
    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        r=sqrt(x*x+y*y);
        if(r<=d)
            c++;
    }
    cout<<c<<endl;
}


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

int main()
{
    int n; cin>>n;
    vector<int> p(n);
    for(e: p) { cin>>e; --e; }

    vector<long> a(n), b(n);
    for(int i=0; i<n; ++i) a[i]=20000*(i+1);

    int x=p[n-1];
    b[x]=20000*n;
    auto m=a[x]+b[x];
    for(int i=n-2; i>=0; --i) {
        x=p[i];
        b[x]=m-a[x]-1;
        m=a[x]+b[x];
    }
    for(int i=0; i<n; ++i) cout<<a[i]<<(i+1<n ? ' ': '\n');
    for(int i=0; i<n; ++i) cout<<b[i]<<(i+1<n ? ' ': '\n');
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> a){
    map<ll, ll> rec;
    REP(i, N){
        rec[a[i]] ++;
    }
    if(rec.size()==1 && rec.count(0)){
        cout << YES<<endl; return;
    }
    if(N %3 == 0 && rec.count(0)){
        if(rec[0]==N/3 && rec.size()==2){
            cout<< YES<<endl; return;}
    }
    //cout<< rec.size()<<endl;
    if(N %3 == 0 && rec.size()==3){
        ll tmp = 0;
        for(auto it:rec){
            tmp = tmp^it.first;
            //cout<<it.second<<endl;
            if(it.second != N/3){
                cout<<NO<<endl;
                return;
            }
        }
        if(tmp == 0)
            cout<<YES<<endl;
        else
            cout<< NO<<endl;
        return;
    }
    cout<<NO<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 5632
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var N = input[0];
        var K = input[1];

        var s = new HashSet<int>();
        for (int i = 0; i < K; i++)
        {
            var _ = Console.ReadLine();
            input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int j = 0; j < input.Length; j++)
            {
                s.Add(input[j]);
            }
        }

        var snuke = Enumerable.Range(1, N).ToHashSet();
        Console.WriteLine(snuke.Except(s).Count());
    }
}


Measured memory_bytes: 28532
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int max = a.back();
  int j = 0;
  vector<bool>dup(1000010,false);
  while(j+1 < n) {
    if(a[j] == a[j+1]) {
      int tmp = a[j];
      dup[j] = true;
      while(tmp == a[j+1]) {
        dup[j+1] = true;
        j++;
      }
    }
    j++;
  }
  int count = 0;
  vector<bool>dp(max, true);
  rep(i, n) {
    int tmp = a[i];
    if(dp[tmp] && !dup[i]) {count++;}
    int j = tmp;
    while(j <= max) {
      dp[j] = false;
      j += tmp;
    }
  }
  cout << count << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()

int N, K;
string S;

vi make() {
    vi v;
    if (S[0] == '0') v.PB(0);
    int c0 = 0, c1 = 0;
    REP (i, N) {
        if (S[i] == '0') {
            if (c1 != 0) {
                v.PB(c1);
                c1 = 0;
            }
            c0++;
        } else {
            if (c0 != 0) {
                v.PB(c0);
                c0 = 0;
            }
            c1++;
        }
    }
    if (c0 != 0) {
        v.PB(c0);
        v.PB(0);
    } else v.PB(c1);
    return v;
}

int solve() {
    vi v = make(), s;
    assert(v.size()&1);
    if (2*(K+1) >= v.size()) return N;
    s.PB(0);
    ll sum = 0, ans = 0;
    FORE (x, v) {
        sum += x;
        s.PB(sum);
    }
    REP (i, s.size()-2*K-1) if (!(i&1)) {
        ans = max(ans, s[2*K+i+1] - s[i]);
    }
    return ans;
}

int main() {
    cin >> N >> K >> S;
    cout << solve() << endl;
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n, k;
  cin >> n >> k;
  vi sn(n);
  rep(i, k) {
    int d;
    cin >> d;
    rep(j, d) {
      int a;
      cin >> a;
      a--;
      sn[a]++;
    }
  }
  int ans = 0;
  rep(i, n) {
    if (sn[i]) ans++;
  }
  cout << n - ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 3660
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    ll N; cin >> N;
    if(N % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }

    ll lim = N / 2;
    ll cnt2 = lim, cnt5 = 0;

    {
        ll tot = 0;
        for(int two=60; two>=0; two--) {
            ll num = lim / (1LL << two);
            num -= tot;
            cnt2 += two * num;
            tot += num;
        }
    }

    ll c = 0, f = 1;
    while(f < lim) c++, f *= 5;
    {
        ll tot = 0;
        for(int five=c; five>=0; five--, f/=5) {
            ll num = lim / f;
            num -= tot;
            cnt5 += five * num;
            tot += num;
        }
    }

    cout << min(cnt2, cnt5) << endl;
    return 0;
}


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

long long int MOD = 1000000007;

long long int dp[10006][105][2];

string S;

int D;

int A[10008];

int main(void) {


	cin >> S;
	cin >> D;

	int M = S.size();

	int q = 1;
	for (int j = M - 1; j >= 0; j--) {
		A[q++] = S[j] - '0';\
	}
	q--;

	dp[q][A[q] % D][0] = 1;
	for (int i = 0; i < A[q]; i++) {
		dp[q][i%D][1] += 1;
	}

	/*for (int i = 1; i <= 12; i++) {
		cout << "A[" << i << "]= " << A[i] << endl;
	}*/

	for (int i = q-1; i >= 1; i--) {
		//===========
		for (int k = 0; k < D; k++) {
			for (int a = 0; a <= 9; a++) {
				dp[i][(k + a) % D][1] += dp[i+1][k][1];
				dp[i][(k + a) % D][1] %= MOD;
			}
		}
		//==============
		for (int k = 0; k < D; k++) {
			dp[i][(k + A[i]) % D][0] += dp[i+1][k][0]; 
			dp[i][(k + A[i]) % D][0] %= MOD;
			for (int a = 0; a < A[i]; a++) {
				dp[i][(k + a) % D][1] += dp[i+1][k][0];
				dp[i][(k + a) % D][1] %= MOD;
			}
		}
	}

	long long int ans = (dp[1][0][1]+dp[1][0][0]-1+MOD)%MOD;

	//cout << "dp[1][0][1]= " << dp[1][0][1] << endl;
	//cout << "dp[1][0][0]= " << dp[1][0][0] << endl;

	cout << ans << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 16768
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long N[100005]={0};
    long long n, d, maxd=0;
    long long count = 1;
    cin >> n;
    cin >> d;
    if(d != 0){
        cout << 0 << endl;
        return 0;
    }
    N[0]++;
    for(int i=1;i<n;i++){
        cin >> d;
        N[d]++;
        if(d>=maxd){
            maxd = d;
        }
    }
    for(int i=0;i<maxd;i++){
        if(N[i]==0 || N[0] != 1){
            cout << 0 <<endl;
            return 0;
        }
        /*
        for(int j=0;j<N[i+1];j++){
            count = count*N[i]%998244353;
        }
        */
        long long x = 1,a = N[i],y= N[i+1];
        while(y > 0){//全てのbitが捨てられるまで。
                if(y&1){//1番右のbitが1のとき。
                x = x*a%998244353;
                }
                a = a*a%998244353;
                y >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
        }
        count = count*x%998244353;    
    }
    cout << count << endl;

    return 0;
}


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

typedef long long ll;

vector<ll> x(100010), v(100010);
vector<ll> sum1(100010), sum2(100010), sumN(100010);
vector<ll> sum_max1(100010), sum_max2(100010);
vector<ll> max_x1(100010), max_x2(100010); //sum_maxに対応する寿司の場所

int main() {
	int n;
	ll c;
	ll sum = 0;

	cin >> n >> c;

	for (int i = 1; i <= n; i++) { //原点から時計回り
		cin >> x[i] >> v[i];
		sum += v[i]; //累積和
		sum1[i] = sum - x[i]; //解説のf(a)、時計回りが往復でないとき
		sum2[i] = sum - x[i] * 2; //時計回りが往復のとき
		if (sum_max1[i - 1] > sum1[i]) {
			max_x1[i] = max_x1[i - 1];
			sum_max1[i] = sum_max1[i - 1];
		}
		else {
			max_x1[i] = x[i];
			sum_max1[i] = sum1[i];
		}

		if (sum_max2[i - 1] > sum2[i]) {
			max_x2[i] = max_x2[i - 1];
			sum_max2[i] = sum_max2[i - 1];
		}
		else {
			max_x2[i] = x[i];
			sum_max2[i] = sum2[i];
		}
	}
	x[n + 1] = c;

	for (int i = n; i > 0; i--) { //反時計回り
		sumN[n - i + 1] = sumN[n - i] + v[i];
	}

	ll ans = 0, MAX = 0;
	for (int i = 0; i <= n; i++) {
		ans = sum_max1[n - i] + sumN[i];
		ans -= (c - x[n + 1 - i])*2;
		MAX = max(MAX, ans);

		ans = sum_max2[n - i] + sumN[i];
		ans -= (c - x[n + 1 - i]);
		MAX = max(MAX, ans);
	}
	cout << MAX << endl;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> dp(n,0);
    dp[0] = 1000;
    for(i = 1;i < n;++i){
        dp[i] = dp[i - 1];
        for(j = 0;j <= i-1;++j){
            ll v = dp[j]/a[j];
            ll w = dp[j] + (a[i] - a[j])*v;
            dp[i] = max(dp[i], w);
        }
    }
    cout << dp[n-1] << endl;

    return 0;
}

Measured memory_bytes: 3592
import sys
S = input()

if S[0]==S[1] and S[2]==S[3] and S[0] != S[2]:
  print("Yes")
  sys.exit()
if S[0]==S[2] and S[1]==S[3] and S[0] != S[1]:
  print("Yes")
  sys.exit()
if S[0]==S[3] and S[2]==S[1] and S[0] != S[2]:
  print("Yes")
  sys.exit()
print("No")

Measured memory_bytes: 38256
#set
a,b,c,d = gets.chomp.split("").map(&:to_i)


#main
answer_1 = a + b + c + d
if answer_1 == 7 then
  print ("#{a}+#{b}+#{c}+#{d}=7\n")
  exit
end

answer_2 = a - b + c + d
if answer_2 == 7 then
  print ("#{a}-#{b}+#{c}+#{d}=7\n")
  exit
end

answer_3 = a + b - c + d
if answer_3 == 7 then
  print ("#{a}+#{b}-#{c}+#{d}=7\n")
  exit
end

answer_4 = a + b + c - d
if answer_4 == 7 then
  print ("#{a}+#{b}+#{c}-#{d}=7\n")
  exit
end

answer_5 = a - b - c + d
if answer_5 == 7 then
  print ("#{a}-#{b}-#{c}+#{d}=7\n")
  exit
end

answer_6 = a - b + c - d
if answer_6 == 7 then
  print ("#{a}-#{b}+#{c}-#{d}=7\n")
  exit
end

answer_7 = a + b - c - d
if answer_7 == 7 then
  print ("#{a}+#{b}-#{c}-#{d}=7\n")
  exit
end

answer_8 = a - b - c - d
if answer_8 == 7 then
  print ("#{a}-#{b}-#{c}-#{d}=7\n")
  exit
end

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

int main() {
  int A , B , C , D;
  cin >> A >> B >> C >> D;
  
  if (A+B == C+D)
    cout << "Balanced" << endl;
  else if (A+B > C+D)
    cout << "Left" << endl;
  else
    cout << "Right" << endl;
  
}



Measured memory_bytes: 256
defmodule Main do
  use Bitwise
  def main do
    _ = IO.gets("")
    a = IO.gets("")
        |> String.trim()
        |> String.split(" ")
        |> Enum.map(&String.to_integer/1)

    mask = a |> xor()

    a
    |> calc(mask, [])
    |> Enum.join(" ")
    |> IO.puts()
  end

  def xor(a) do
    a |> Enum.reduce(fn x, acc -> x ^^^ acc end)
  end

  def calc([], _, acc), do: acc |> Enum.reverse()
  def calc([x | tail], mask, acc) do
    calc(tail, mask, [x^^^mask | acc])
  end
end


Measured memory_bytes: 91064
#include <stdio.h>

int W;

inline void next(int &i, int &j, bool &rtl)
{
	if (rtl) {
		if (++j == W)
			++i, --j, rtl = 0;
	}
	else {
		if (--j == -1)
			++i, ++j, rtl = 1;
	}
}

int main()
{
	int H, N = 0, a, i, j, k, m = 0, count = 0;
	bool odd[500][500], rtl;
	scanf("%d %d", &H, &W);
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			scanf("%d", &a);
			if (odd[i][j] = a & 1)
				count++;
		}
	}

	i = 0, j = 0, rtl = 1;
	for (k = 0; k < count / 2; k++) {
		while (!odd[i][j])
			next(i, j, rtl);
		N++, next(i, j, rtl);

		while (!odd[i][j])
			N++, next(i, j, rtl);

		next(i, j, rtl);
	}

	printf("%d\n", N);
	i = 0, j = 0, rtl = 1;
	for (k = 0; k < count / 2; k++) {
		while (!odd[i][j])
			next(i, j, rtl);
		printf("%d %d ", i+1, j+1);
		next(i, j, rtl);

		while (!odd[i][j]) {
			printf("%d %d\n", i+1, j+1);
			printf("%d %d ", i+1, j+1);
			next(i, j, rtl);
		}

		printf("%d %d\n", i+1, j+1);
		next(i, j, rtl);
	}

	return 0;
}

Measured memory_bytes: 2304
a = input().split()
j = 0
d = 0
for i in range(int(a[1])):
    j += 1
    s = int(a[0]) * j
    if s % int(a[1]) == int(a[2]):
        print('YES')
        d = 1
        break
if d == 0:
    print('NO')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
    int n;
    while(cin >> n && n) {
        map<int,int> m;
        rep(i,n) {
            int x;
            cin >> x;

            m[x]++;
        }

        bool flag = true;
        map<int,int>::iterator ite;
        for(ite = m.begin(); ite != m.end() ; ite++) {
            if(ite->second > n/2) {
                cout << ite->first << endl;
                flag = false;
                break;
            }
        }

        if(flag) {
            cout << "NO COLOR" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2732
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  string s,t,ss = "";
  cin >> s >> t;
  int n = s.size();
  bool ok = false;
  REP(i,n){
    REP(j,n){
      ss.push_back(s.at((i+j)%n));
    }
    if(t == ss) ok = true;
    ss = "";
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
  int R[MAX], n;

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

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; ++i)
  {
    maxv = max(maxv,R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0 ;


}

Measured memory_bytes: 1940
#include<stdio.h>

int main(void){
	int a, b, n, i, gcd;

	while (scanf("%d %d", &a, &b) != EOF){
		if (a > b){
			n = a;
		}
		else{
			n = b;
		}

		for (i = 1; i <= n; i++){
			if (a%i == 0){
				if (b%i == 0){
					gcd = i;
				}
			}
		}
		
		printf("%d\n", gcd);
	}

	return 0;
}

Measured memory_bytes: 592
#include<iostream>
char a[16], b[16] = {'C', 'O', 'D', 'E', 'F', 'E', 'S', 'T', 'I', 'V', 'A', 'L', '2', '0', '1', '6'};
int ans;
int main(void){
    std::cin >> a;
    for(int i = 0; i < 16; i ++){
        if(a[i] != b[i]) ans++;
    }
    std::cout << ans << "\r\n";  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

int main(){
    ll x,k,d;cin>>x>>k>>d;

    if(x<0){x=x*(-1);}//左右対称

    if(x/d<k&&(k-x/d)%2==1){cout<<abs(x%d-d)<<endl;}  //k-x%dとケアレス
    if(x/d<k&&(k-x/d)%2==0){cout<<x%d<<endl;}
    if(x/d>=k){cout<<x-d*k<<endl;}

}

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

int main(){
  ll a,b,n;cin>>a>>b>>n;
  
  if(n<b) cout<<(int)(a*(double)n/b)<<endl;
  else cout<<(int)(a*(double)(b-1)/b)<<endl;
}

Measured memory_bytes: 3624
using System;

namespace atcorder
{
    class Program
    {
        public static void Main()
        {
            string[] In = Console.ReadLine().Split(' ');
            int n = int.Parse(In[0]);
            //rは表示レーティング
            //r=(内部レート)-100*(10-n)
            int r = int.Parse(In[1]);
            int x = 0;
            if (n >= 10)
            {
                x = r;
            }
            else
            {
                x = r + (100 * (10 - n));
            }
            Console.WriteLine(x);
        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int a,b,c,n,i;
	cin>>n;
	b=0;
	c=2000000000;
	for(i=0;i<n;i++){
		cin>>a;
		if(a<0) a=a*(-1);
		if(a>b) b=a;
		if(a<c) c=a;
	}
	cout<<b-c<<endl;
}


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

using namespace std;


int main(){
    int n;
    cin >> n;
    vector<long long>h(n),a(n),d(n),s(n);
    long long h1,a1,d1,s1;
    long long ans=0;
    cin >> h1 >> a1 >> d1 >> s1;
    for(int i=0;i<n;i++){
        cin >> h[i] >> a[i] >> d[i] >> s[i];
        if(s1<s[i]){
            ans += max(a[i]-d1,0LL);
        }
    }
    if(h1<=ans){
        cout << -1 << endl;
        return 0;
    }
    vector<long long> c(n),dam(n);
    for(int i=0;i<n;i++){
        if(max(a1-d[i],0LL)!=0){
            c[i] = (h[i]-1)/(a1-d[i]) + 1;
        }else{
            c[i] = 0;
            if(max(a[i]-d1,0LL)!=0){
                cout << -1 << endl;
                return 0;
            }
        }
        dam[i] = max(a[i]-d1,0LL);
    }
    vector<pair<long double,pair<long long,long long > > > v;
    long long sm = 0;
    for(int i=0;i<n;i++){
        if(c[i]!=0){
            v.push_back(make_pair((long double)dam[i]/(long double)c[i],make_pair(c[i],dam[i])));
            sm += dam[i];
        }
    }
    sort(v.begin(),v.end(),greater<pair<long double,pair<long long,long long > > >());
    for(int i=0;i<v.size();i++){
        ans += sm*(v[i].second.first-1);
        sm -= v[i].second.second;
        ans += sm;
        if(h1<=ans){
            cout << -1 << endl;
            return 0;
        }
    }
    if(h1<=ans){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 6688
#include <stdio.h>          // printf(), scanf(), getc(), ungetc()
#include <ctype.h>          // isdigit()
#include <stdbool.h>

#define MAX_N 2000000
#define swap(a, b) { int t; t = a; a = b; b = t; }

const int INF = (1 << 30);
int a[MAX_N + 1];
int h;

void
max_heapify(int i)
{
	int largest;

	int l = 2 * i;
	int r = 2 * i + 1;

	/* ????????????????????????????????§???????????§???node????????¶ */
	if (l <= h && a[l] > a[i])
		largest = l;
	else
		largest = i;

	if (r <= h && a[r] > a[largest])
		largest = r;

	if (largest != i) /* ????????????????????§????????´?????? */
	{
		swap(a[i], a[largest]);
		max_heapify(largest);
	}
}

int
extract()
{
	if (h < 1)
		return -INF;

	int maxv = a[1];
	a[1] = a[h--];
	max_heapify(1);
	return maxv;
}

void
increase_key(int i, int key)
{
	if (key < a[i])
		return;

	a[i] = key;
	while (i > 1 && a[i / 2] < a[i])
	{
		swap(a[i], a[i / 2]);
		i /= 2;
	}
}

void
insert(int key)
{
	h++;
	a[h] = -INF;
	increase_key(h, key);
}

int
main(int argc, char** argv)
{
	char command[8];
	int key;
	int n;
	int c;

	h = 0;
	while (true)
	{
		scanf("%s", command);
		if (command[0] == 'e' && command[1] == 'n')
			break;

		else if (command[0] == 'e' && command[1] == 'x')
			printf("%d\n", extract());

		else if (command[0] == 'i')
		{
			n = 0;
			c = getc(stdin);
			while (c == ' ' || c == '\n')
				c = getc(stdin);
			
			while (isdigit(c))
			{
				n = 10 * n + c - '0';
				c = getc(stdin);
			}

			ungetc(c, stdin);
			key = n;
			insert(key);
		}
	}

	return 0;
}

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

#define INF  						1e15
#define EPS   						1e-9
#define MOD 						1000000007
#define Pi 							3.14159265358979323846264338327950288419716939937510

#define umap 						unordered_map
#define uset 						unordered_set
#define fi 							first
#define se 							second
#define ll 							long long 
#define vi 							vector<int>
#define pii 						pair<int,int>
#define vll 						vector<ll>
#define pll							pair<ll,ll>
#define pb 							push_back
#define pob 						pop_back
#define pf 							push_front
#define pof 						pop_front
#define maxE(a,n) 					*max_element(a,a+n);
#define minE(a,n) 					*min_element(a,a+n);
#define all(x) 						x.begin(), x.end()

#define fast 						ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fori(i,a,n) 				for (ll  i=a;i<n;i++)
#define ford(i,a,n) 				for (ll  i=n-1;i>=a;i--)

ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll power(ll x, ll b,ll m) {ll p = 1;while (b > 0) {if(b&1) {p = p * x; p %= m;} b >>= 1; x *= x; x %= m;} return p % m;}

using namespace std;


void solve(){

	ll n;
	cin>>n;

	ll height[n];
	fori(i,0,n){
		cin>>height[i];
	}

	ll op = 0;
	for(ll i=1;i<n;i++){
		if(height[i] < height[i-1]){
			ll diff = height[i-1] - height[i]; 
			op  = op + diff;
			height[i] = height[i-1];
		}
	}
	
	cout<<op<<endl;
}


int main(){

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

	fast;
	ll t = 1;
	// cin>>t;

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


Measured memory_bytes: 5208