akhauriyash/Code-Regression huggingface dataset:
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-16 07:22:13
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int n; cin >> n;
  int64 T; cin >> T;
  vector<int64> t(n); cin >> t;

  vector<int64> dp(n + 5, 0LL);
  dp[0] = T;

  for (int i = 1; i < n; ++i) {
    if (t[i] > t[i - 1] + T) {
      dp[i] = dp[i - 1] + T;
    } else {
      dp[i] = dp[i - 1] + (t[i] - t[i - 1]);
    }
  }

  cout << dp[n - 1] << endl;

  return 0;
}

Measured memory_bytes: 3456
#include<stdio.h>

int F[44];

void fibonacci(n)
{
  int i;
  
  F[0] = 1;
  F[1] = 1;

  for(i = 2;i <= n;i++)
    F[i] = F[i - 2] + F[i - 1];
}

int main()
{
  int n;

  scanf("%d",&n);
  fibonacci(n);
  printf("%d\n",F[n]);

  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll INF = 1LL << 58;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
 
	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
 
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
 
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}
 
	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}
 
		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);
 
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;
 
		return true;
	}
};
//x以下の要素への最小index
template <class T> int former(const vector<T> &v, T x) {
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> int latter(const vector<T> &v, T x) {
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T1>
void cout_vec(const int n, vector<T1> &vec1){
  rep(i, n){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
ll comb(ll n,ll k){
    ll ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
ll gcd(ll a,ll b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,d,x;
    cin>>n>>d>>x;
    vector<int> a(n);
    vector<int> sum(n,0);
    rep(i,n){
        cin>>a[i];
        int count=1;
        while(count<=d){
            sum[i]++;
            count+=a[i];
        }
    }
    cout<<x+accumulate(sum.begin(),sum.end(),0)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, n, m) for(ll i = n; i < (int)m; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w, d, n;
    cin >> w >> d >> n;
    vector<vector<P>> cons(w, vector<P>(d, {-inf, inf}));
    vector<ll> x(n), y(n), z(n);
    REP(i, n) cin >> x[i] >> y[i] >> z[i];
    REP(i, n) {
        x[i]--; y[i]--;
        cons[x[i]][y[i]].first = max(cons[x[i]][y[i]].first, z[i]);
        cons[x[i]][y[i]].second = min(cons[x[i]][y[i]].second, z[i]);
        REP(j, w) REP(k, d) {
            ll diff = abs(j - x[i]) + abs(k - y[i]);
            cons[j][k].first = max(cons[j][k].first, z[i] - diff);
            cons[j][k].second = min(cons[j][k].second, z[i] + diff);
        }
    }
    ll ans = 0;
    REP(i, w) REP(j, d) {
        if(cons[i][j].first > cons[i][j].second) {
            cout << "No" << endl;
            return 0;
        }
        ans += cons[i][j].first;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(),a.end()
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forr(i,n) for(int i=int(n-1);i>=0;i--)
#define fora(i,a,b) for(int i=int(a);i<=int(b);i++)
#define forb(i,a,b) for(int i=int(a);i>=int(b);i--)
#define mod 1000000007
using namespace std;
using ll=long long int;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vii;
typedef pair<ll ,ll> pii;
template<typename T>
string ts(T v)
{
	string res="{";
	bool r=true;
	for(const auto &x:v)
	{
		if(!r)res+=",";
		r=false;
		res+=to_string(x);
	}
	res+="}";
	return res;
}
void solve()
{
	int n,k;
	cin>>n>>k;
	int arr[n];
	forn(i,n)cin>>arr[i];
	sort(arr,arr+n);
	int ans=0;
	forn(i,k)ans+=arr[i];
	cout<<ans<<endl;
}
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
	solve();
    return 0;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        System.out.println( solve(N, A) );
    }

    private static long solve(int N, int[] A) {
        long sum = 0;
        for (int i = 0; i < N; i++) {
            sum += A[i];
        }

        long ans = Long.MAX_VALUE;
        long x = 0;
        for (int i = 0; i < N-1; i++) {
            x += A[i];
            long y = sum - x;
            long abs = Math.abs(x - y);

            if( abs < ans ) {
                ans = abs;
            }
        }
        return ans;
    }
}


Measured memory_bytes: 65092
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>

int main()
{
    std::string str;
    std::getline(std::cin, str, '\n');
    std::getline(std::cin, str, '\n');
    
    std::stringstream ss(str);
    std::vector<int> vec;
    while (std::getline(ss, str, ' '))
    {
        vec.push_back(std::stoi(str));
    }
    
    for (int n = vec.size() - 1; n >= 0; --n)
    {
        std::string s = (n == 0 ? "" : " ");
        std::cout << vec[n] << s;
    }
    
    std::cout << std::endl;
    
    return 0;
}


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

const int MAX = 20;

int main(){
    int x, a;
    cin >> x >> a;
    if(x < a){
        cout << 0 << endl;
    }else{
        cout << 10 << endl;
    }
}

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

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

    if (a % 2 != b % 2){
        cout << "IMPOSSIBLE" << endl;
    }
    else{
        cout << (a + b) / 2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        int cnt = 0;
        x -= z;
        while (x >= y + z) {
            x -= (y + z);
            cnt++;
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define o_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
#define trav(it, v) for(auto &it : v)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
 	return r;
}


void solve()
{
	int n, x;
	cin >> n >> x;
	int a[n + 1];
	a[n] = 0;
	rep(i, n){
		cin >> a[i];
	}
	ll res = 0;
	rep(i, n){
		int sum = a[i] + a[i + 1];
		int del = max(0, sum - x);
		a[i + 1] = max(0, a[i + 1] - del); 
		res += 1ll * del;
	}
	cout << res;
}
int main()
{
    Red;
    // freopen("black.in", "r", stdin);
	// freopen("black.out", "w", stdout);
    int T = 1;
    // cin >> T;
    for(int i = 1; i <= T; ++i) {
    	// cout << "Case #" << i << ": ";
    	solve();
  	}
  	return 0;

}


Measured memory_bytes: 4052
from sys import stdin
from string import ascii_uppercase


def main():
    S = stdin.readline().rstrip()
    if S[0] == 'A':
        if len([x for x in S[2:-1] if x == 'C']) == 1:
            if len(set([x for x in S[1:]]) & set(ascii_uppercase)) == 1:
                print('AC')
                return
    print('WA')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3892
#include<bits/stdc++.h>
using namespace std;
#define N 200003
#define LL long long
#define mod 998244353

int n;
double ans;

inline int read(){
	int X=0,w=0;
	char ch=0;
	while (ch<'0' || ch>'9')
	  w|=ch=='-',ch=getchar();
	while (ch>='0' && ch<='9')
	  X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
	return w ? -X : X;
}

int main(){
	n=read();
	for (int i=1;i<=n;i++){
		double x=read();
		ans+=(double)1.0/x;	
	}
	ans=(double)1.0/ans;
	printf("%.6lf\n",ans);
	return 0;
}

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

N = int(input())
S = input()

z_ascii = ord('Z')
S_ascii = map(ord, S)
S_ascii_new = []

for i in S_ascii:
    new = i+N
    S_ascii_new.append(new - 26 if new > z_ascii else new)

print(''.join(map(chr, S_ascii_new)))

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rrep1(i, n) for (int i = ((int)(n)); i > 0; --i)
#define sz(x) ((int)(x).size())
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define pb push_back

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<double>    vd;
typedef vector<long long> vl;

// template<class T>bool maxc(T &a, const T &b) { if (a<b) { a=b; return 1; } }
// template<class T>bool minc(T &a, const T &b) { if (b<a) { a=b; return 1; } }

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

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int n, d;
    cin >> n >> d;

    // 処理
    int    cnt = 0;
    double x   = 1 + d * 2;
    int    ans = ceil(n / x);

    // 出力
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
ll n,m;
cin >> n >> m;
if (n > m) swap(n, m);
if(n==1){
    if(m==1){
        cout << 1 << endl;
    }
    else{
        cout << m - 2 << endl;
    }
}
else
    cout << (n - 2) * (m - 2) << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	N := readInt()

	Count, Keys, Max, Index := map[string]int{}, make([]string, N), 1, 0
	for i := 0; i < N; i++ {
		s := readString()

		v, exists := Count[s]
		if exists {
			Count[s] = v + 1
			if Max < v+1 {
				Max = v + 1
			}
		} else {
			Count[s] = 1
			Keys[Index] = s
			Index++
		}
	}

	sort.Strings(Keys)

	for _, k := range Keys {
		v := Count[k]
		if v == Max {
			fmt.Println(k)
		}
	}
}

func readInt() int {
	var v int
	fmt.Scan(&v)
	return v
}

func readString() string {
	var v string
	fmt.Scanln(&v)
	return v
}

Measured memory_bytes: 24448
a = str(input())
if len(a) >= 6 and any(chr.isdigit() for chr in a) == True: 
    if any(chr.islower() for chr in a) == True and any(str.isupper() for str in a) == True:
        print("VALID")
    else:
        print("INVALID")
else:
    print("INVALID")


Measured memory_bytes: 5568
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

bool isprime(int);

int main(int argc, char const *argv[])
{
	int size, count = 0, num;
	cin >> size;

	for (int i = 0; i < size; ++i)
	{
		cin >> num;
		if (isprime(num)) count++;
	}
	printf("%d\n", count);
	return 0;
}


bool isprime(int x)
{
	for (int i = 2; i <= (int)sqrt(x); ++i)
	{
		if (x % i == 0) return false;
	}
	return true;
}

Measured memory_bytes: 1144
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

typedef pair<int, int> P;
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int upper = (N - 1) * (N - 2) / 2;
    if(upper < K) {
        cout << "-1" << endl;
        return 0;
    }
    vector<P> v;
    rep(i, N - 1) {
        v.push_back({1, i + 2});
    }
    int diff = upper - K;
    int l = 2, r = 3;
    rep(i, diff) {
        v.push_back({l, r});
        r++;
        if(r > N) {
            l++;
            r = l + 1;
        }
    }
    cout << v.size() << endl;
    rep(i, v.size()) {
        cout << v[i].first << " " << v[i].second << endl;
    }

    return 0;
}


Measured memory_bytes: 384
/*
Author: Rishabh Agarwal
Nationality: Indian
*/
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define MOD 1000000007
#define vpi vector<pair<int, int>>
#define ll long long int
#define inf 1000000000
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Cases int testCases; cin>>testCases; while(testCases--) 
#define MOD 1000000007
#define pb push_back
//---------------------------------------------------
int main() {
    FIO
    ll N; cin>>N;
    int array[N];
    for(int i=1; i<N; ++i){
        cin>>array[i];
    }
    ll counter[N] = {0};
    for(int i=1; i<N; ++i){
        int current = array[i];
        counter[current-1]++;
    }
    for(int i=0; i<N; ++i){
        cout<<counter[i]<<endl;
    }
}



Measured memory_bytes: 5992
#include <cstdio>
int main() {
	char c;
	int p = 0, d = 0;
	for(int i = 0; i < 4; i++) {
		c = getchar();
		if(c == '+') p ++;
		else d --;
	}
	printf("%d\n", p + d);
	return 0;
}

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

int main() {
    string name;
    char type;
    string UP;
    for (int i = 0; i < 26; i++) {
        UP += 'A' + i;
    }

    while (cin >> name >> type) {
        if (type == 'U') {
            stringstream ss;
            for (auto& i : name) if (i == '_') i = ' ';
            ss << name;
            string str;
            while (ss >> str) {
                str[0] = toupper(str[0]);
                cout << str;
            }
            cout << endl;
        } else if (type == 'L') {
            stringstream ss;
            for (auto& i : name) if (i == '_') i = ' ';
            ss << name;
            string str;
            ss >> str;
            str[0] = tolower(str[0]);
            cout << str;
            while (ss >> str) {
                str[0] = toupper(str[0]);
                cout << str;
            }
            cout << endl;
        } else if (type == 'D'){
            for (int i = 0; i < name.size(); i++) {
                if (UP.find(name[i]) != string::npos) {
                    name[i] = name[i] - 'A' + 'a';
                    name.insert(i, " ");
                }
            }
            stringstream ss;
            ss << name;
            string str;
            ss >> str;
            cout << str;
            while (ss >> str) {
                cout << "_" << str;
            }
            cout << endl;
        } else {
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3104
/*
 * Created by Dipta Das on 29-06-2019
 * Title: 
 * Problem Link: 
 * Editorial: 
 * Source Code: 
 * Comments: 
*/

#include <bits/stdc++.h>
#include <stdio.h>
#define fin freopen("input", "r", stdin)
#define whatis(x) cerr << #x << ": " << x << endl;

using namespace std;
using ll = long long;

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

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

    if (n % 2 == 1) {
        cout << "0" << endl;
        return 0;
    }

    sort(ar.begin(), ar.end());

    int mid = n/2;

    int ans = ar[mid] - ar[mid-1];

    cout << ans << endl;

    


    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
		tree_order_statistics_node_update> ordered_set;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 1e5 + 9, M = 20 + 9, OO = (int) 1e9 + 1;
const long long MOD = 1e9 + 7, INF = 1e18 + 9;

typedef long long ll;

void OUTPUT() {
	cout << fixed << setprecision(0);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

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

int n, m, u, v, nodes[N], vis[N], cnt;
vector<vector<int>> edges(N);
map<int, int> mp;

void DFS(int node) {
	vis[node] = 1;
	mp[node]++;
	mp[nodes[node]]++;
	for (auto child : edges[node]) {
//		mp[nodes[child]]++;
//		mp[child]++;
		if (!vis[child]) {
			DFS(child);
		}
	}
}

int main() {
//	INPUT();
	OUTPUT();
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> nodes[i];
	}

	for (int i = 0; i < m; i++) {
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}

	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			mp.clear();
			DFS(i);
			for (auto x : mp) {
				if (x.second == 2)
					cnt++;
			}
		}
	}
	cout << cnt;

	return 0;

}



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

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

        int ans = -1;
        double rate = -1;
        rep(i, n) {
            int b, r, t;
            cin >> b >> r >> t;
            if (t == 1) {
                double nrate = 1+(double)(y*r)/100;
                if (nrate > rate) {
                    ans = b; rate = nrate;
                }
                //cout << nrate << endl;
            } else {
                double nrate = 1;
                rep(j, y) nrate *= 1+(double)r/100;
                if (nrate > rate) {
                    ans = b; rate = nrate;
                }
                //cout << nrate << endl;
            }
        }

        cout << ans << endl;
    }

    return 0;
}


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

int main() {
    int n,ans=10000000,sum1=0,sum2=0;
    cin>>n;
    vector<int> w(n);
    rep(i,n) {
        cin>>w.at(i);
        sum2+=w.at(i);
    }
    rep(i,n-1) {
        sum1+=w.at(i);
        sum2-=w.at(i);
        ans=min(ans,abs(sum1-sum2));
    }
    cout<<ans<<endl;
}   

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<utility>
#define mp make_pair
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0; i<n; i++)
typedef long long int64;
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}

string bin(int n){
    string s = "";
    while(n>0){
        string b = to_string(n%2);
        s = b+s;
        n>>=1;
    }
    return s;
}

vector<vector<tuple<int,int,int>>> build_edge(int mask, vector<tuple<int,int,int,int,int>> const& in, int N){
    vector<vector<tuple<int,int,int>>> edge(N);
    for(auto z:in){
        int a,b,c,d,e; tie(a,b,c,d,e) = z;
        if(mask>>e&1) c=0;
        edge[a].emplace_back(b,c,d);
        edge[b].emplace_back(a,c,d);
    }
    return move(edge);
}


void solve(int N,int M,int H,int K){
    vector<tuple<int,int,int,int,int>> in;
    REP(i,M){
        int a,b,c,d,e; cin >> a >> b >> c >> d >> e;
        in.emplace_back(--a,--b,c,d,--e);
    }
    int S,T; cin >> S >> T; S--; T--;
    int P; cin >> P;
    vector<pair<int,int>>  one_day;
    REP(i,P){
        int l,d; cin >> l >> d;
        int tmp = 0;
        REP(_,l){
            int k; cin >> k;
            tmp += 1<<--k;
        }
        one_day.emplace_back(d,tmp);
    }

    int64 INF = 1LL<<60;
    vector<int64> DP(1<<K, INF);
    DP[0] = 0;
    REP(mask,1<<K){
        for(auto e:one_day){
            int d,k; tie(d,k) = e;
            chmin(DP[mask | k], DP[mask] + d);
        }
    }

    int64 ans = INF;
    REP(mask, 1<<K){
        auto edge = build_edge(mask, in, N);
        vector<vector<int64>> DP2(N, vector<int64>(H+1, INF));
        DP2[S][0] = 0;
        REP(j,H+1){
            REP(i,N){
                for(auto e:edge[i]){
                    int to,c,d; tie(to,c,d) = e;
                    if(j+d > H) continue;
                    if(j) chmin(DP2[i][j], DP2[i][j-1]);
                    chmin(DP2[to][j+d], DP2[i][j] + c);
                }
            }
        }
        // cerr << bin(mask) << " ans:" << ans << endl;
        chmin(ans, DP2[T][H] + DP[mask]);
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

int main(){
    while(true){
        int N,M,H,K; cin >> N >> M >> H >> K;
        if(N==0) break;
        solve(N,M,H,K);
    }
    
}


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

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

    string s;
    cin>>s;
    int n = s.length();
    if(s[n-1]=='s')
    {
        s+='e';
        s+='s';
    }
    else{
        s+='s';
    }
    cout<<s;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

constexpr int m = 1145141;
int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<ll> a(n);
    map<ll, int> x;
    rep(i,n) cin>>a[i], x[a[i]]++;
    sort(a.begin(), a.end());
    vector<bool> b(2001001, false);
    set<ll> st;
    map<ll, int> mp;
    int ans = 0;
    rep(i,n) {
        if (!b[a[i]]) mp[a[i]]++;
        if (st.count(a[i])) continue;
        for (ll j = a[i]; j < m; j+=a[i]) b[j] = true;
        st.insert(a[i]);
    }

    for (auto &&e: mp) {
        if (x[e.first] == 1) ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 39308
// inputに入力データ全体が入る
function Main(input) {
	
	input = input.split(" ");
	
	//文字列から10進数に変換するときはparseIntを使います
	var N= parseInt(input[0], 10);
	
	var n = 0;
	
	if (N <= 9){var n = N;}
	   else if ( N >=10 && N <= 99){n = 9;}
	         else if ( N >= 100 && N<= 999 ){n = N-99+9;}
	          else if (N >= 1000 && N<=9999){n = 909;}
	                                             
	               else if (N >=10000 && N <=99999){ n = N-9999  + 909;}
	               else{var n = 90909;}

   console.log(n);               
               
     }
    
	
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define ll long long 
#define pll pair<ll,ll> 
#define ppll pair<ll, pll> 

const ll N=1e3+5;
ll V[N][N];

ll ans=-1;
char s[N][N];
ll n, m;
bool check (ll x, ll y){
	if(x>=0 && x<n && y>=0 && y< m )
		return 1;
	return 0;
}
void bfs(ll x,ll y, ll a, ll b){
	priority_queue<ppll, vector<ppll> , greater<ppll> > q;
	q.push({0,{x,y}});
	while(!q.empty()){
		ll w=q.top().first;
		x=q.top().second.first;
		y=q.top().second.second;
		q.pop();
		if(x==a && y==b){
			ans=w;
			return ;
		}

		if(V[x][y])
			continue;
		V[x][y]=1;

		for(ll i=-2;i<=2;i++){
			for(ll j=-2;j<=2;j++){
				if(!i && !j)
					continue;
				ll az=abs(i)+abs(j);
				ll u=x+i, v=y+j;
				if(check(u,v)  && s[u][v]=='.' )
					q.push({w+(az>1),{u,v}});
			}
		}
	}
}

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin>>n>>m;
	ll x,y,a, b;
	cin>>x>>y>>a>>b;
	x--,y--,a--,b--;
	for(ll i=0;i<n;i++)
		for(ll j=0;j<m;j++)
			cin>>s[i][j];


	bfs(x,y, a, b);

	cout<<ans<<endl;
}


Measured memory_bytes: 14644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    ll n, m;
    cin >> n >> m;
    ll num = n*2 + m;
    ll ans = num/4;
    chmin(ans, m/2);
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin>>str;
  if(str.compare("AAA") == 0
   || str.compare("BBB") == 0) {
    cout<<"No"<<"\n";
  }
  else {
    cout<<"Yes"<<"\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
	int a1,a2,a3,a4,b1,b2,b3,b4,A=0,B=0;
	scanf("%d %d %d %d",&a1,&a2,&a3,&a4);
	scanf("%d %d %d %d",&b1,&b2,&b3,&b4);
	A = a1 + a2 + a3 + a4;
	B = b1 + b2 + b3 + b4;
	if(A > B){
		printf("%d\n",A);
	}else{
		printf("%d\n",B);
	}

    return 0;
}

Measured memory_bytes: 2672
// RAM RAM

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair
#define arrayin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define N 55
const int MOD=1000000007;
using namespace std;
unordered_map<int,bool> done;

int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	

    int k,s;cin>>k>>s;
    int res=0;
    for(int i=0;i<=k;i++){
    	for(int j=0;j<=k;j++){
    		int temp=s-i-j;
    		if(temp>=0 && temp<=k)
    			res++;
    	}
    }

    cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>
#include <iomanip>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int x;
	cin >> x;
	
	if( x == 0 ) cout << 1 << endl;
	else cout << 0 << endl;
	
	return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>

#define NMAX 100000

long long int W[NMAX];
int n,k;

int check(long long int mid){
	int i = 0;
	for(int j = 0; j < k; j++){
		long long int s = 0;
		while(s + W[i] <= mid){
			s += W[i];
			i++;
			if(i == n){
				return n;
			}
		}
	}
	return i;
}
int solve(){
	long long int left = 0;
	long long int right = 100000 * 10000;
	long long int mid;
	while((right - left) > 1){
		mid = (left + right) / 2;
		int v = check(mid);
		if(v >= n){
			right = mid;
		}
		else{
			left = mid;
		}
	}
	return right;
}

int main(void){
	int i;
	long long int c = 0;
	scanf("%d%d" ,&n,&k);
	for(i = 0; i < n; i++){
		scanf("%d",&W[i]);
	}
	c = solve();
	printf("%d\n" ,c);
	return 0;
}


Measured memory_bytes: 2560
# D - Lunlun Number
from collections import deque
K = int(input())
lun = deque([1,2,3,4,5,6,7,8,9])
for i in range(K-1):
    x = lun.popleft()
    if x%10>0:
        lun.append(10*x+x%10-1)
    lun.append(10*x+x%10)
    if x%10<9:
        lun.append(10*x+x%10+1)
print(lun.popleft())

Measured memory_bytes: 18832
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
int main(){
  ll N,M;
  cin>>N>>M;
  for(ll i=0;i<M;i++){
    if(N%2==1){cout<<i+1<<" "<<N-i<<endl;}
  }
  if(N%2==0){
    for(ll i=0;i<(M/2+M%2);++i){
      cout<<i+1<<" "<<N/2-i<<endl;
    }
    for(ll i=0;i<M/2;i++){
      cout<<N/2+i+1<<" "<<N-i-1<<endl;
    }
  }
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c) {
    cout << "No\n";
  } else if (a == b || a == c || b == c) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

int main() {
int count;
int cum = 0;
cin >> count;
int array[count] = {};
while (cum < count) {
cin>> array[count - cum-1];
cum++;
} for (int i= 0; i < count; i++) {
cout << array[i];
if (i != count - 1) {
cout << " ";
}
} cout << endl;
}


Measured memory_bytes: 3044
#include<cstdio>
int a[100001],b[100000];
int main(){
    int n;
    long long sum=0;
    scanf("%d",&n);
    for(int i=0;i<=n;i++)scanf("%d",&a[i]);
    for(int i=0;i<n;i++)scanf("%d",&b[i]);
    for(int i=n-1;i>=0;i--){
        if(a[i+1]<=b[i]){
            sum+=a[i+1];
            b[i]-=a[i+1];
            if(a[i]<=b[i]){
                sum+=a[i];
                a[i]=0;
            }else{
                a[i]-=b[i];
                sum+=b[i];
            }
        }else{
            sum+=b[i];
        }
    }
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define db double
#define ll long long
#define reg register
#define pb(x) push_back(x)
#define fup(i,x,y) for(reg int i=x;i<=y;++i)
#define fdw(i,x,y) for(reg int i=x;i>=y;--i)
using namespace std;
const int N=2e5+10;
ll a[N],ans=-1e18,n,f[N][2];
inline int read()
{
	int x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}
int main()
{
//	freopen("1.in","r",stdin);
	n=read();
	for(int i=1;i<=n;++i) a[i]=read();
	memset(f,0xef,sizeof(f));
	f[1][1]=a[1];f[1][0]=0;
	f[2][1]=max(a[1],a[2]);
	for(int i=3;i<=n;++i)
	{
		if(i%2!=0)
		{
			f[i][0]=max(f[i-2][0]+a[i],max(f[i-2][1],f[i-1][1]));
			f[i][1]=f[i-2][1]+a[i];	
		}
		else f[i][1]=max(f[i-1][1],f[i-2][1]+a[i]);
	}
	if(n%2==0) cout<<f[n][1]<<endl;
	else       cout<<f[n][0]<<endl;
	return 0;
}



Measured memory_bytes: 8320
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        h: usize,
        w: usize,
        s: [chars; h],
    }

    let mut ans = vec!["".to_string(); h];
    for i in 0..h as i64 {
        for j in 0..w as i64 {
            if s[i as usize][j as usize] == '#' {
                print!("#");
                continue;
            }
            print!(
                "{}",
                [
                    (-1, -1),
                    (-1, 0),
                    (-1, 1),
                    (0, -1),
                    (0, 1),
                    (1, -1),
                    (1, 0),
                    (1, 1)
                ]
                    .iter()
                    .filter(|&&(x, y)| (i + x) >= 0
                        && (i + x) < h as i64
                        && (j + y) >= 0
                        && (j + y) < w as i64
                        && s[(i + x) as usize][(j + y) as usize] == '#').count()
            );
        }
        println!();
    }
}


Measured memory_bytes: 4352
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<int, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 1000010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22) cout << "bust";
    else cout << "win";
    return 0;
}


Measured memory_bytes: 256
line = input().split()
H = int(line[0])
W = int(line[1])

array = []

def get_ij(index):
    i = index // W
    if (i % 2 == 0):
        j = index % W
    else:
        j = W - index % W - 1
    return i+1, j+1


for i in range(H):
    if i % 2 == 0:
        array.extend([int(a) for a in input().split()])
    else:
        array.extend(reversed([int(a) for a in input().split()]))

move_index = []
previous_move = False
for i, a in enumerate(array[:-1]):
    even = a % 2 == 0

    if previous_move and even:
        # print(i, a, 1, previous_move, even)
        move_index.append(i)
        previous_move = True
    elif not previous_move and not even:
        # print(i, a, 2, previous_move, even)
        move_index.append(i)
        previous_move = True
    else:
        previous_move = False

print(len(move_index))

for i in move_index:
    ind_from = get_ij(i)
    ind_to = get_ij(i+1)
    print("{} {} {} {}".format(ind_from[0], ind_from[1], ind_to[0], ind_to[1]))



Measured memory_bytes: 12012
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll n;
    cin >> n;
    cout << n / 3 << endl;
}

Measured memory_bytes: 256
import collections
import heapq

h, w = map(int, input().split())
cs = [list(map(int, input().split())) for _ in range(10)]
counter = collections.Counter()
for _ in range(h):
    for x in map(int, input().split()):
        if x != -1:
            counter[x] += 1

dists = [float('inf') for i in range(10)]
dists[1] = 0
q = []
for i in range(10):
    heapq.heappush(q, (dists[i], i))

while q:
    d0, i = heapq.heappop(q)
    for j in range(10):
        if j == i:
            continue
        d = d0 + cs[j][i]
        if dists[j] > d:
            dists[j] = d
            heapq.heappush(q, (dists[j], j))

res = 0
for k, v in counter.items():
    res += dists[k] * v
print(res)

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

int main() {
  ll N; cin >> N;
  if (N == 3) {cout << 2 << " " << 3 << " " << 205 << endl; return 0;}
  
  vector<ll> a;
  for (ll i = 1; i <= 30000; i++) {
    if (i%2==0 || i%3==0 || i%5==0 || i%7==0) {
      a.push_back(i);
    }
  }
  ll sum = 0;
  for (ll i = 0; i < N; i++) {
    sum += a[i];
  }
  ll mod = sum%210;
  if (mod%2 == 0) {
    if (a[N-1]%2 == 0) {a[N-1]+=(210-mod);}
    else if (N-2 >= 0 && a[N-2]%2 == 0) {a[N-2]+=(210-mod);}
  } else {
    if (a[N-1]%2 == 1) {a[N-1]+=(210-mod);}
    else if (N-2 >= 0 && a[N-2]%2 == 1) {a[N-2]+=(210-mod);}
    else if (N-3 >= 0 && a[N-3]%2 == 1) {a[N-3]+=(210-mod);}
    else if (N-4 >= 0 && a[N-4]%2 == 1) {a[N-4]+=(210-mod);}
  }
  for (ll i = 0; i < N; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}

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


void solve(long long N, std::vector<long long> A, long long Q, std::vector<long long> B, std::vector<long long> C){
  map<long long, long long> m;
  for (long long a : A) {
    if (m.count(a)) m[a] += 1;
    else m[a] = 1;
  }

  long long prev = -1;
  for (long long q=0; q<Q; q++) {
    long long minus = B[q] * m[B[q]];
    long long plus = C[q] * m[B[q]];
    m[C[q]] += m[B[q]];
    m[B[q]] = 0;
    if (prev != -1) {
      cout << prev - minus + plus << endl;
      prev = prev - minus + plus;
    } else {
      long long sum = 0;
      for (auto p : m) sum += p.first * p.second;
      cout << sum << endl;
      prev = sum;
    }
  }
}

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]);
    }
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> B(Q);
    std::vector<long long> C(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(A), Q, std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 11620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 60;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


// 入力
int N;
ll a[100010][3];

// DP テーブル
ll dp[100010][3];

int main() {
    int N; cin >> N;
    rep1(i, N) rep1(j, 3) cin >> a[i][j];

    // ループ
    rep1(i, N) {
        rep1(j, 3) {
            rep1(k, 3) {
                if (j == k) continue;
                chmax(dp[i+1][k], dp[i][j]+a[i][k]);
            }
        }
    }
    ll ans = 0;
    rep1(i,3) chmax(ans, dp[N][i]);
    // 答え
    cout << ans << endl;
}

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

int main(){
	long long a, b, c;
	cin >> a >> b >> c;
	if(((((a * b) % 2) * c) % 2) == 0){
		cout << "0" << endl;
	}else{
		long long ans = min((a * b), min((b * c), (a * c)));
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		doIt();
	}
	
	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		//double x = 1;
		//double y = 0;
		while(n != -1){
			double rad = 0;
			double hyp = 1;
			for(int i = 1; i < n; i++){
				rad += Math.atan(1 / hyp);
				hyp = Math.sqrt(hyp*hyp + 1);
				//x = hyp * Math.cos(rad);
				//y = hyp * Math.sin(rad);
			}
			System.out.println(hyp * Math.cos(rad));
			System.out.println(hyp * Math.sin(rad));
			n = sc.nextInt();
		}
	}
}

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

using namespace std;

int main(){
  string s;

  cin >> s;

  if(s[0] != 'A' || isupper(s[1]) || isupper(s[s.length()-1])){
    cout << "WA" << endl;
    return 0;
  }

  int cnt = 0;
  for(int i = 2; i < s.length(); i++){
    if( s[i] == 'C' ) cnt++;
    else if( isupper(s[i])){
      cout << "WA" << endl;
      return 0;
    }
  }
  if( cnt == 1 ) cout << "AC" << endl;
  else cout << "WA" << endl;

  return 0;
}
 


Measured memory_bytes: 256
from collections import deque

s = deque(input())
q = int(input())
top = 0

for i in range(q):
  a = list(map(str, input().split()))
  if(a[0] == "1"):
    top = (top + 1) % 2
    continue
  # a[0] == "2"
  if(top + int(a[1]) - 1 == 1):
    s.append(a[2])
  else:
    s.appendleft(a[2])
if(top == 0):
  print(''.join(s))
else:
  print((''.join(s))[::-1])
    

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

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

signed main(){
	string S;cin>>S;
	int N=S.size()+1;
	vint inc(N),dec(N);
	for(int i=0;i<N-1;i++){
		if(S[i]=='<')inc[i+1]=inc[i]+1;
	}
	for(int i=N-2;i>=0;i--){
		if(S[i]=='>')dec[i]=dec[i+1]+1;
	}

	int ans=0;
	for(int i=0;i<N;i++){
		ans+=max(inc[i],dec[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8708
n=int (input())
card=list(map(int, input().strip().split()))
card.sort(reverse=True)
a=0
b=0
for i in range(n):
    if i%2==0:
        a=a+card[i]
    elif i%2==1:
        b=b+card[i]
print(a-b)

Measured memory_bytes: 9084
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9
#define MAX_N 200001

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int main() {
    vector<int> A;
    int N, K;
    cin >> N >> K;
    int num[MAX_N];
    fill(num, num + MAX_N, 0);
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        num[a - 1] += 1;
    }
    for (int i = 0; i < N; ++i) {
        if (num[i] != 0) {
            A.push_back(num[i]);
        }
    }
    int len = (int)A.size();
    sort(A.begin(), A.end());
    int ans = 0;
    for (int i = 0; i < len - K; ++i) {
        ans += A[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2168