akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define mp make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF (1<<30)
#define LLINF (1LL<<60)
//#define MOD 998244353
#define MOD 1000000007
#define PI 3.14159265358979
using ll = long long;
using namespace std;

int main(){
    ll digit[40]={};//i=0:1桁目,...,i=20:21桁目
    ll n;
    ll maxdig=-1;
    cin>>n;
    ll num[200005];
    rep(i,n){
        ll t;
        cin>>t;
        num[i]=t;
        ll dig=0;
        while(t!=0){
            ll m=t%2;
            if(m==1) digit[dig]++;
            t-=m;
            t/=2;
            dig++;
        }
        maxdig=max(maxdig,dig);
    }

    bool digitisodd[40]={};//odd:true, even:false
    rep(i,40){
        if(digit[i]%2==1)digitisodd[i]=true;
    }

    rep(i,n){
        ll dig=0;
        //vector<ll>ans;
        ll ansnum=0;
        while(dig!=maxdig){
            ll m=num[i]%2;
            if(digitisodd[dig]){
                if(m==0){
                    //ans.push_back(1);
                    ansnum+=pow(2,dig);
                }
                else{
                    //ans.push_back(0);
                }
            }
            else{
                //ans.push_back(m);
                if(m==1) ansnum+=pow(2,dig);
            }
            num[i]-=m;
            num[i]/=2;
            dig++;
        }
        //for(ll j=ans.size()-1;j>=0;j--)cout<<ans[j];
        //cout<<' ';
        cout<<ansnum;
        if(i!=n-1) cout<<' ';
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<ll>> dp(M + 1, vector<ll>(1 << N, INF));

    vector<int> a(M), b(M);
    vector<vector<int>> c(M);
    rep(i, M) {
        cin >> a[i] >> b[i];
        rep(j, b[i]) {
            int t;
            cin >> t;
            c[i].push_back(t);
        }
    }

    dp[0][0] = 0;
    rep(i, M) {
        rep(j, 1 << N) {
            if (dp[i][j] == INF) continue;
            int bit = j;
            rep(k, b[i]) {
                bit |= (1 << (c[i][k] - 1));
            }
            chmin(dp[i + 1][bit], dp[i][j] + a[i]);
            chmin(dp[i + 1][j], dp[i][j]);
        }
    }

    ll ans = dp[M][(1 << N) - 1];
    if (ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35712
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

string binary(long long int n){
    string s="";
    while(n>0){
      if(n%2==1)s="1"+s;
      else s="0"+s;
      n/=2;
    }
    return s;
}

long long int calc(long long int x, string s){
  int n=s.length();
  long long int a=2, ans=0;
  for(int i=1;i<s.length();i++){
    if(s[n-1-i]=='1'&&s[n-1]=='0')ans+=a;
    a*=2;
  }
  if(x%4==1||x%4==2)ans+=1;
  return ans;
}

int main(){
  long long int a, b, ans;
  cin >> a >> b;
  long long int x=calc(a-1, binary(a-1));
  long long int y=calc(b, binary(b));
  ans=x^y;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
a,b,c = [int(num) for num in input().split()]
k = int(input())

operation = 0

while operation < k and b <= a:
    b *= 2
    operation += 1

while operation < k and c <= b:
    c *= 2
    operation += 1

if a < b < c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9136
require 'prime'

class Solver
  def main
    n, p = gets.split.map(&:to_i)

    pds = Prime.prime_division(p)  #=> [[5, 1], [197, 1], [461, 1]]

    ans = 1
    pds.each do |(base, exp)|
      e = exp / n
      ans *= base**e
    end

    puts ans
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2300
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
	ll i,n,m,l,r,lma=0,rmi=100000,z=0;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>l>>r;
		lma=max(l,lma);
		rmi=min(rmi,r);
	}
	cout<<max(z,rmi-lma+1)<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
int x[100005],w=1,n,m,a,i;
long s=0;
main(){
scanf("%d %d",&n,&m);
for(i=1;i<n;i++){
scanf("%d",&x[i]);
}
for(i=0;i<m;i++){
scanf("%d",&a);
if(a>0){
for(int j=0;j<a;j++){
s+=x[w+j];
}
}else{
for(int j=a;j<0;j++){
s+=x[w+j];
}
}
w+=a;
}
printf("%ld\n",s%100000);
return 0;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ld a[3333];
ld dp[3333][3333];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			dp[i][j]=dp[i-1][j]*(1.00000-a[i]);
			if(j>0) dp[i][j]+=dp[i-1][j-1]*a[i];
		}
	}
	ld ans=0;
	for(int i=0;i<=n;i++)
	{
		if(i>n-i)
		{
			ans+=dp[n][i];
		}
	}
	cout<<fixed<<setprecision(15)<<ans<<'\n';
}


Measured memory_bytes: 156160
# include<bits/stdc++.h>
# define LL long long
using namespace std;
const int MAX=2e5+5;
int n;
char s[MAX];
int main()
{
	scanf("%s",s+1),n=strlen(s+1);
	LL ans=0;
	for(int i=1,L=1;i<=n;++i)
	  if(s[n-i+1]=='B') ans+=i-L,++L;
	return printf("%lld",ans),0;
}


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


int main() {
    int n, n2;
    cin >> n;
    n2 = n;
    int sum = 0;
    while (true) {
        if (n == 0) break;
        sum += n%10;
        n /= 10;
    }
    if (n2%sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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; }

template <int mod>
struct ModInt {
    int val;
    ModInt() : val(0) {}
    ModInt(long long x) : val(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    int getmod() { return mod; }
    ModInt &operator+=(const ModInt &p) {
        if ((val += p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if ((val += mod - p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        val = (int)(1LL * val * p.val % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
    ModInt operator-() const { return ModInt(-val); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return val == p.val; }
    bool operator!=(const ModInt &p) const { return val != p.val; }
    ModInt inverse() const {
        int a = val, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(long long n) const {
        ModInt ret(1), mul(val);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.val; }
    friend istream &operator>>(istream &is, ModInt &a) {
        long long t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
    static int get_mod() { return mod; }
};
const int MOD = 1000000007;  // if inv is needed, this shold be prime.
using modint = ModInt<MOD>;

int main(){
	int h, w;
	cin >> h >> w;
	vector<vector<char> > a(w+1, vector<char>(h+1));
	vector<vector<modint> > dp(w+10, vector<modint> (h+10));
	dp[0][0] = 1;
	rep(y, h){
		rep(x, w){
			cin >> a[x][y];
		}
	}
	rep(y, h){
		rep(x, w){
			if(a[x][y] != '#'){
				if(x != 0 && y != 0) {
					dp[x][y] = dp[x-1][y] + dp[x][y-1];
				}
				else if(x == 0 && y != 0) {
					dp[x][y] = dp[x][y-1];
				}
				else if(x != 0 && y == 0) {
					dp[x][y] = dp[x-1][y];
				}
			}
		}
	}
	cout << dp[w-1][h-1] << endl;
}

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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int K;
    cin >> K;
    string S;
    cin >> S;
    int len = (int)S.size();
    if(len <= K) cout << S << endl;
    else{
        string s = S.substr(0, K);
        cout << s << "..." << endl;
    }
    return 0;
}

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

int main(){
  string i;
  cin >> i;
  bool ans = true;
  if(i[2]!=i[3])ans =false;
  if(i[4]!=i[5])ans =false;
  cout << (ans?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
// B - Ringo's Favorite Numbers
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int D,N; cin>>D>>N;
	int n = 0, s = 1; rp(i, 0, D) s*=100;
	for(int i=s; i<=s*100+s; i+=s)
		if(i%(s*100))
			if(++n==N){cout<< i <<endl; return 0; }
}

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

typedef long double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long> vl;
typedef vector<double> vd;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

#define pi 3.14159265358979
#define eps 1e-9
#define inf 1<<30

int main()
{
	int N, Q;
	cin >> N >> Q;
	string s;
	cin >> s;
	vi v(N);

	v[0] = 0;
	for( int i=1; i<N; i++ ){
		if( s[i-1] == 'A' && s[i] == 'C' ){
			v[i] = v[i-1] + 1;
		} else {
			v[i] = v[i-1];
		}
	}

	int l, r;
	for( int i=0; i<Q; i++ ){
		cin >> l >> r;
		cout << v[r-1] - v[l-1] << endl;
	}

	return 0;
}


Measured memory_bytes: 1408
import math
a,b,x = map(int,input().split( ))

if x >=b*a**2/2:###
    h = b*2 - (2*x/a**2)
    tan = h/a
    ans = math.atan(tan)/math.pi *180
    print(ans)


else:
    w = 2*x/(a*b)
    tan = b/w
    ans = math.atan(tan)/math.pi *180
    print(ans)


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 50005

int main()
{
    _FastIO;

    char c[10][10];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> c[i][j];
        }
    }
    for(int i = 0; i < 3; i++){
        cout << c[i][i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3624
while 1:	
	n,k,m = map(int,raw_input().split())
	if (n, k, m) == (0,0,0):
		break
	stone = range(n+1)
	here = m
	stone.pop(here)
	rest = n - 1
	while rest >= 2:
		if here - 1 + k <= rest:
			tmp = here - 1 + k
		else:
			rem = (k - (rest-here+1)) % rest
			tmp = rest if rem == 0 else rem
		stone.pop(tmp)
		rest -= 1
		here = 1 if tmp > rest else tmp
	print stone[1]

Measured memory_bytes: 4604
# -*- coding: utf-8 -*-
import sys
point = '.'
sharp = '#'

while True:
	H, W = map(int, raw_input().split())
	if H == W == 0:
		break
	for h in xrange(H):
		for w in xrange(W):
			if h % 2 == 0:
				if w % 2 == 0:
					sys.stdout.write(sharp),
				else:
					sys.stdout.write(point),
			else:
				if w % 2 == 0:
					sys.stdout.write(point)
				else:
					sys.stdout.write(sharp)
		print
	print

Measured memory_bytes: 4220
#include<stdio.h>


int main(void)
{
	int a,b,check;
	scanf("%d %d",&a,&b);
	check = (a - b);
	if(check>0){
		printf("a > b\n");
	}else{
		if(check<0){
			printf("a < b\n");
		}else{
				printf("a == b\n");
			}
	}
	return 0;
}

Measured memory_bytes: 580
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

K = getN()
if K == 1 or K == 7:
    print(1)
    exit()

prev1 = 7

cnt = 1
for i in range(10 ** 6 + 2):
    cnt += 1
    mi = (prev1 * 10 + 7) % K
    if mi == 0:
        print(cnt)
        exit()
    prev1 = mi
print(-1)

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

using namespace std;

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

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(15);
	cout << fixed;

	int n = 0;
	cin >> n;

	map<multiset<char>, lld> mp;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		multiset<char> mt(s.begin(), s.end());

		mp[mt]++;
	}
	lld ans = 0;
	for (auto p : mp) {
		ans += p.second * (p.second - 1) / 2;
	}
	cout << ans << endl;

}

Measured memory_bytes: 56576
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pb push_back
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll x, y, z;
  cin >> x >> y >> z;
  cout << z << ' ' << x << ' ' << y << "\n";
}


Measured memory_bytes: 3668
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct Edge {
    ll rev, from, to;
    ll cap, original_cap;
    Edge(ll r, ll f, ll t, ll c) : rev(r), from(f), to(t), cap(c), original_cap(c) {};
};

struct Graph {
    vector<vector<Edge>> g;
    Graph(ll n) { g = vector<vector<Edge>>(n); };
    vector<Edge>& operator[](ll i) { return g[i]; }
    size_t size() {return g.size(); }
    Edge& redge(Edge e) {
        return g[e.to][e.rev];
    }
    void add_edge(ll from, ll to, ll cap) {
        g[from].push_back(Edge(g[to].size(), from, to, cap));
        g[to].push_back(Edge(g[from].size() - 1, to, from, 0));
    }
};

struct FordFulkerson {
    vector<bool> used;
    Graph& G;
    FordFulkerson(Graph& g) : G(g) {};
    ll dfs(ll v, ll t, ll f) {
        if(v == t) return f;
        used[v] = true;
        for(auto& e : G[v]) {
            if(used[e.to] || e.cap <= 0) continue;
            ll d = dfs(e.to, t, min(f, e.cap));
            if(d <= 0) continue;
            e.cap -= d;
            G.redge(e).cap += d;
            return d;
        }
        return 0;
    }
    ll max_flow(ll s, ll t) {
        ll flow = 0;
        while(true) {
            used.assign(G.size(), false);
            ll f = dfs(s, t, INFL);
            if(f == 0) return flow;
            else flow += f;
        }
        return 0;
    }
};

void solve() {
    ll x, y, e;
    cin >> x >> y >> e;
    Graph g(x + y + 2);
    for(ll i = 0; i < e; i++) {
        ll _x, _y;
        cin >> _x >> _y;
        g.add_edge(_x + 1, _y + x + 1, 1);
    }
    for(ll i = 0; i < x; i++) {
        g.add_edge(0, i + 1, 1);
    }
    for(ll i = 0; i < y; i++) {
        g.add_edge(i + x + 1, x + y + 1, 1);
    }
    FordFulkerson f(g);
    cout << f.max_flow(0, x + y + 1) << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3800
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
using namespace std;
#define MOD 1000000007
#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()

int main(){
  int H, N, sum = 0;
  cin >> H >> N;
  int A[N];
  for (int i = 0; i < N; i++){
    cin >> A[i];
    sum += A[i];
  }
  if (sum >= H)
  cout << "Yes" << endl;
  else 
    cout << "No" << endl;
  
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;


int main() {
    int N; cin >> N;
    vector<pii> ans;
    int x = N;
    if (N & 1) x--;

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            if (j <= i || j == x) continue;
            ans.pb(mp(i, j));
        }
        x--;
    }

    cout << ans.size() << endl;
    for (auto p : ans) {
        cout << p.F << " " << p.S << endl;
    }
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	int X;
	cin >> X;
	int a = X / 100;
	int b = X % 100;
	if (a * 5 >= b) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}



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

import sys
sys.setrecursionlimit(300000)

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int):
    s = str(N)
    ret = NO
    for c in s:
        if c == '7':
            ret = YES
            break
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61696
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		
		char []strtochar = str.toCharArray();
		int count = 0;
		
		for(char c: strtochar) {
		    
		    if (Character.isLetter(c)){
		        
		        if (Character.isUpperCase(c)){
    		        System.out.print(Character.toLowerCase(c));
    		    }else {
    		        System.out.print(Character.toUpperCase(c));
    		    }
    		    
		    }else {
		        System.out.print(c);
		    }
		}
		
		System.out.println();
	}

}


Measured memory_bytes: 26816
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,k,s,t;cin >> n >> k >> s >> t;
    vector<ll> b(n);REP(i,n)cin >> b[i];
    vector<ll> a;
    REP(i,n){
        bool f=true;
        REP(j,18){
            if((s>>j)&1 and !((b[i]>>j)&1)){
                f=false;break;
            }
            if(!((t>>j)&1) and (b[i]>>j)&1){
                f=false;break;
            }
        }
        if(f)a.PB(b[i]);
    }
    n=SIZE(a);
    k=min(n,k);
    //cout << n << endl;
    //cout << n << endl;
    //unordered_mapはpairをキーにできない
    //dp_subを用意すると遅い
    vector<map<pair<ll,ll>,ll>> dp(k);
    REP(i,n){
        FORD(j,k-2,0){
            for(auto l=dp[j].begin();l!=dp[j].end();l++){
                dp[j+1][MP((l->F.F)&a[i],(l->F.S)|a[i])]+=(l->S);
            }
        }
        dp[0][MP(a[i],a[i])]=1;
    }
    ll ans=0;
    REP(i,k)ans+=(dp[i][MP(s,t)]);
    cout << ans << endl;
}


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

int big (int a, int b ){
	if(a>b){
		return a;
	}
	return b;
}

int small (int a,int b){
	return a+b-big(a,b);
}


int main (){
	int a,b,c,x,y;
	int ans=0;


	cin >> a >> b >> c >> x >>y;
/*	
	if((a+b)> c * 2 ){
		ans = ans + small(x,y)*c;
		if(x>y){
			ans = ans + (x-y) * a;
		}
		else ans = ans + (y-x) * b;
	}
	else if(big(a,b)>=c*2){
		if(a>=b){
			if(x>=y){
				ans = c * 2 * x;
			}
			else ans = c*2*x+b*(y-x);
		}
	}
	else ans = a*x+b*y;
*/
	if((a+b)>=2*c){
		if(x>=y){
			ans = ans + c * y * 2;
			if(a>=2*c){
				ans = ans + 2*c*(x-y);
			}
			else ans = ans + a*(x-y);
		}
		else if(y>x){
			ans = ans + c * x * 2;
			if(b>=2*c){
				ans = ans + 2 * c * (y-x);
			}
			else ans = ans + b * (y-x);
		}
	}
	else ans = a*x+b*y;



	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    while(1) {
        int n, p, i, num, temoto[50] = {};
        scanf("%d %d", &n, &p);
        if (n == 0) break;
        num = p;
        for (i=0; ; i++) {
            if (temoto[i] == p) {
                printf("%d\n", i);
                break;
            }
            if (num) {
                num--;
                temoto[i]++;
            } else {
                num = temoto[i];
                temoto[i] = 0;
            }
            if (i == n-1) i = -1;
        }
    }
}

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

int main() {
    int N, A[1000];

    cin >> N;

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

    for (int i = 1; i < N; i++) {
        cout << A[0];
        for (int i = 1; i < N; i++) {
            cout << " " << A[i];
        }
        cout << endl;

        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
    }

    cout << A[0];
    for (int i = 1; i < N; i++) {
        cout << " " << A[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3128
from collections import deque
H, W = map(int, input().split())
grid = [["#"] * (W + 2)] + [list("#" + input() + "#")
                            for i in range(H)] + [["#"]*(W+2)]
# print(grid)
stack = deque()
for h in range(1, H+1):
    for w in range(1, W+1):
        # 黒ならスタックにpush
        if grid[h][w] == "#":
            stack.append([h, w])

for i in range(h + w + 3):
    tmp = deque()
    while stack:
        h, w = stack.pop()
        for dh, dw in ([0, 1], [0, -1], [1, 0], [-1, 0]):
            if grid[h + dh][w + dw] == ".":
                grid[h + dh][w + dw] = "#"
                tmp.append([h + dh, w + dw])
    stack = tmp
    if not stack:
        print(i)
        break

Measured memory_bytes: 168668
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	string S;
	cin >> S;
	int N = S.length();
	for(int i=0;i<N;i++){
		if(i+1 < N && S[i] == S[i+1]){
			cout << (i + 1) << " " << (i + 2) << endl;
			return 0;
		}
		if(i+2 < N && S[i+1] == S[i+2]){
			cout << (i + 2) << " " << (i + 3) << endl;
			return 0;
		}
		if(i+2 < N && S[i] == S[i+2]){
			cout << (i + 1) << " " << (i + 3) << endl;
			return 0;
		}
	}
	
	cout << "-1 -1" << endl;
	
	
	
    return 0;
}

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

class abc125d
{
    static void Main()
    {
        var N = long.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().ToList().ConvertAll(long.Parse);
        var Bdash = A.Select(y => Math.Abs(y));
        var answer = Bdash.Sum();
        if(A.Where(x => x < 0).Count() % 2 == 1) {
            answer -= Bdash.Min() * 2;
        }

        Console.WriteLine(answer);
    }
}


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

int main()
{
    int x, res = 1;
    cin >> x;

    for(int i = 2; i <= x; ++i)
    {
        int power = i * i;
        while(power <= x)
        {
            res = max(res, power);
            power *= i;
        }

    }

    cout << res << "\n";
    return 0;
}

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

ll choose2(ll n) {
    return n*(n-1)/2;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> cnt(n, 0);
    rep(i,n) cnt[a[i]-1] += 1;
    // 全体を求める
    ll all = 0;
    rep(i,n) {
        if (cnt[i] < 2) continue;
        all += choose2(cnt[i]);
    }
    // 全体からk番目と同じボールの選び方を引いて、k番目以外から同じ2個のボールを選ぶ選び方
    vector<ll> ans(n,all);
    rep(k,n) {
        ans[k] -= cnt[a[k]-1] - 1;
        cout << ans[k] << endl;
    }
    return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Node{
	int location;
	int p,left,right;
};

struct Point{
	Point(){
		id = x = y = 0;
	}

	Point(int arg_id,int arg_x,int arg_y){
		id = arg_id;
		x = arg_x;
		y = arg_y;
	}
	bool operator < (const Point & arg)const{
		return id < arg.id;
	}
	void print(){
		printf("%d\n",id);
	}
	int id,x,y;
};

static const int MAX = 1000000;
static const int NIL = -1;

int N;
Point P[MAX];
Node T[MAX];
int number;

bool lessX(const Point &p1, const Point &p2) {return p1.x < p2.x; }
bool lessY(const Point &p1, const Point &p2) {return p1.y < p2.y; }

int makeKDTree(int left,int right, int depth){

	if(!(left < right))return NIL;

	int mid = (left+right)/2;

	int node_id = number++;

	if(depth%2 == 0){
		sort(P+left,P+right,lessX);
	}else{
		sort(P+left,P+right,lessY);
	}

	T[node_id].location = mid;
	T[node_id].left = makeKDTree(left,mid,depth+1);
	T[node_id].right = makeKDTree(mid+1,right,depth+1);

	return node_id;
}

void find(int node_id,int sx,int tx,int sy,int ty, int depth, vector<Point> &ans){

	int x = P[T[node_id].location].x;
	int y = P[T[node_id].location].y;

	if(sx <= x && x <= tx && sy <= y && y <= ty){
		ans.push_back(P[T[node_id].location]);
	}

	if(depth%2 == 0){
		if(T[node_id].left != NIL){
			if(sx <= x)find(T[node_id].left,sx,tx,sy,ty,depth+1,ans);
		}
		if(T[node_id].right != NIL){
			if( x <= tx)find(T[node_id].right,sx,tx,sy,ty,depth+1,ans);
		}
	}else{
		if(T[node_id].left != NIL){
			if(sy <= y)find(T[node_id].left,sx,tx,sy,ty,depth+1,ans);
		}
		if(T[node_id].right != NIL){
			if(y <= ty)find(T[node_id].right,sx,tx,sy,ty,depth+1,ans);
		}
	}
}


int main(){

	int x,y;
	//scanf("%d",&N);
	cin>>N;
	for(int i = 0; i < N; i++){
		//scanf("%d %d",&x,&y);
		cin>>x>>y;
		P[i] = Point(i,x,y);
		T[i].left = T[i].right = T[i].p = NIL;
	}

	number = 0;

	int root = makeKDTree(0,N,0);

	int q;
	//scanf("%d",&q);
	cin>>q;
	int sx,tx,sy,ty;
	vector<Point> ans;
	for(int i = 0; i < q; i++){
		//scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
		cin>>sx>>tx>>sy>>ty;
		ans.clear();
		find(root,sx,tx,sy,ty,0,ans);
		sort(ans.begin(),ans.end());
		for(int j = 0; j < ans.size(); j++){
			ans[j].print();
		}
		//printf("\n");
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 22392
import System.IO (isEOF)

main = do
    quit <- isEOF
    if quit then return () else do
        input >>= output . solve
        main

type Point = (Double,Double)

input :: IO (Point,Point,Point,Point)
input = do
    line <- getLine
    let
        [ox,oy,ax,ay,bx,by,px,py] = map read $ words line
    return ((ox,oy),(ax,ay),(bx,by),(px,py))

output :: Bool -> IO ()
output x = putStrLn (if x then "YES" else "NO")

solve :: (Point,Point,Point,Point) -> Bool
solve ((ox,oy),(ax,ay),(bx,by),(px,py)) = and [s > 0.0, t > 0.0, s+t < 1.0]
    where
        s = (oby * opx - obx * opy) / (oax * oby - obx * oay)
        t = (oax * opy - oay * opx) / (oax * oby - obx * oay)
        oax = ax - ox
        oay = ay - oy
        obx = bx - ox
        oby = by - oy
        opx = px - ox
        opy = py - oy

Measured memory_bytes: 4284
import java.util.Scanner;

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

    while (true) {
      a = scanner.nextInt();
      b = scanner.nextInt();
      if (a == 0 && b == 0) break;
      for (int i = 0; i < a; ++i) {
        for (int j = 0; j < b; ++j) System.out.printf("#");
        System.out.println();
      }
      System.out.println();
    }
  }
}


Measured memory_bytes: 58656
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] p = new int[n];
		for(int i = 0; i < n; i++){
		    p[i] = sc.nextInt();
		}

		// 計算
	    int result = 0;
	    int max = 0;
	    int index = 0;
	    for(int i = 0; i < n; i++){
		    max = max(max, p[i]);
		    if(max == p[i]) index = i;
		}
	    for(int i = 0; i < n; i++){
	        if(i == index){
	            result += max/2;
	        }else{
	            result += p[i];
	        }
		}
	    
		// 出力
		System.out.println(result);
        
	}
}


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

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int R, G, B, N, ans = 0;
    cin >> R >> G >> B >> N;
    rep(r, N / R + 1) {
        rep(g, N / G + 1) {
            int b = (N - R * r - G * g) / B;
            //cout << r << g << b <<"\n";
            if (b >= 0 && N == R * r + G * g + B * b) ans++;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
n,m=STDIN.gets.chomp.split(/ +/).map(&:to_i)
prefs = {}
m.times do |i|
  p,y=STDIN.gets.chomp.split(/ +/).map(&:to_i)
  if prefs[p] == nil
    prefs[p] = []
  end
  prefs[p] << [i,y]
end

prefs.each_value do  |pref|
  pref.sort!{ |a,b| a[1] <=> b[1] }
  pref.each_with_index{ |x,i| x[1]=i + 1 }
end

cities= []

prefs.each do |pref,value|
  value.each do |v|
    cities << [ v[0], pref, v[1] ]
  end
end

cities.sort!{|a,b| a[0]<=>b[0]}

cities.each do |city|
  puts "%06d%06d" % [city[1],city[2]]
end 
    



Measured memory_bytes: 37228
import sys
sys.setrecursionlimit(10000100)

t = int(input())
for _ in range(t):
    n, a, b, c, d = map(int, input().split())

    used = {}

    def solve(t):
        if t in used:
            return used[t]
        if t <= 1:
            return t * d

        res = d * t
        for x, y in zip([2, 3, 5], [a, b, c]):
            if t % x == 0:
                res = min(res, solve(t // x) + y)
            else:
                res = min(res, solve(t // x) + y + (t - t // x * x) * d)
                res = min(res, solve(t // x + 1) + y + ((t // x + 1) * x - t) * d)

        used[t] = res
        return res

    print(solve(n))


Measured memory_bytes: 10804
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    if(b-a == c-b){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}
    

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

int main(){
    int n,x;cin >> n >> x;
    vector <int> L(n);
    for(int i=0;i<n;++i) cin >> L[i];
    vector <int> sum(n);
    sum[0] = L[0];
    for(int i=1;i<n;++i){
        sum[i] = sum[i-1] + L[i];
    }
    for(int i=n-1;i>=0;--i){
        if(sum[i] <= x){
            cout << (i+2) << endl;
            break;
        }
    }
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 30;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int ans = INF;

  for(int x = -100; x <= 100; ++x) {
    int tmp = 0;
    rep(i, n) tmp += (int)pow(abs(a[i]-x), 2);
    chmin(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
int deg[26] = {};
vector<int> e[26];
bool v[26] = {};
void init() {
	rep(i,26) {
		deg[i] = 0;
		e[i].clear();
		v[i] = false;
	}
}
void dfs(int c) {
	v[c] = false;
	rep(i,e[c].size()) {
		if(v[e[c][i]]) dfs(e[c][i]);
	}
}
//bool bfs(int c) {
//	queue<int> q;
//	q.push(c);
//	while(!q.empty()) {
//		int x = q.front; q.pop();
//		if(!v[x]) continue;
//		v[x] = false;
//		rep(i,e[c].size()) {
//			if(e[c][i]) q.push(e[c][i]);
//		}
//	}
//	rep(i,26) if(deg[i]&&v[i]) return false;
//	return true;
//}
int main(){
	int n;
	string s;
	while(cin >> n, n) {	
		init();
		int a;
		rep(i,n) {
			cin >> s;
			a = s[0] - 'a';
			int b = s[s.size()-1] - 'a';
			e[a].push_back(b);
			deg[a]++, deg[b]--;
			v[a] = v[b] = true;
		}
		dfs(a);
		int i;
		for(i=0;i<26;++i) {
			if(v[i] || deg[i]!=0) {
				cout << "NG" << endl;
				break;
			}
		}
		if(i==26) cout << "OK" << endl;
		// if(bfs(a)) cout << "OK" << endl;
		// else cout << "NG" << endl;
	}
}

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

int main() {
  int n, m, r;
  cin >> n >> m >> r;
  vector<int> t(r);
  for (int i = 0; i < r; i++) {
    cin >> t.at(i);
    t.at(i)--;
  }
  sort(t.begin(), t.end());
  vector<vector<int>> d(n, vector<int>(n, 1e9));
  for (int i = 0; i < n; i++) {
    d.at(i).at(i) = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    d.at(a).at(b) = c;
    d.at(b).at(a) = c;
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d.at(i).at(j) = min(d.at(i).at(j), d.at(i).at(k) + d.at(k).at(j));
      }
    }
  }
  int ans = 1e9;
  do {
    int s = 0;
    for (int i = 0; i < r - 1; i++) {
      s += d.at(t.at(i)).at(t.at(i + 1));
    }
    ans = min(ans, s);
  } while (next_permutation(t.begin(), t.end()));
  cout << ans << endl;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

int dp[100010];

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

	vector<int> num(1, 1);

	for (int i = 6; i <= N; i*= 6)
	{
		num.push_back(i);
	}
	for (int i = 9; i <= N; i *= 9)
	{
		num.push_back(i);
	}

	sort(ASC(num));

	dp[0] = 0;

	for (int i = 1; i <= N; i++) dp[i] = inf;

	for (int i = 1; i <= N; i++)
	{
		for (int j = 0; j < num.size(); j++)
		{
			if (i - num[j] < 0) break;

			chmin(dp[i], dp[i - num[j]] + 1);
		}
	}

	cout << dp[N] << endl;
}


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

auto solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b) {
    std::vector<int> ns(N, 0);
    for(int i = 0;i < M; ++i){
        ns[a[i]-1]++;
        ns[b[i]-1]++;
    }

    stringstream ss;
    for(const auto& n : ns){
        ss << n << endl;
    }
    return ss.str();
}

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


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	n <- readInt
	ps <- readInts
	print $ length $ filter f $ map ( take 3 ) $ take ( n - 2 ) $ tails ps

f [ a, b, c ]
	| a < b && b < c = True
	| c < b && b < a = True
	| otherwise = False

Measured memory_bytes: 508
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int c = Integer.parseInt(str[2]);
    System.out.println(Math.min(Math.min(a+b,c+a),b+c));
  }
}

Measured memory_bytes: 32600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=16,mo=1e9+7;
ll f[1<<N],jc[1<<N+1],ny[1<<N+1],lim=1e5;
int a[20],n,m,cnt[1<<N];
ll power(ll a,ll b=mo-2){
	ll ans=1;
	while (b){
		if (b&1)ans=ans*a%mo;
		a=a*a%mo;
		b>>=1;
	}return ans;
}
void move(ll &a,ll b){
	a=(a+b)%mo;
}
ll calc(ll n,ll m){
	if (n<m)return 0;
	return jc[n]*ny[n-m]%mo;
}
int main(){
	cin>>n>>m;
	for (int i=1;i<=m;i++)scanf("%d",&a[i]);
	jc[0]=1;
	for (int i=1;i<=lim;i++)jc[i]=jc[i-1]*i%mo;
	ny[lim]=power(jc[lim]);
	for (int i=lim;i>=1;i--)ny[i-1]=ny[i]*i%mo;
	f[0]=1;
	for (int i=m;i>=1;i--){
		for (int s=(1<<n)-1;s>=0;s--){
			for (int k=0;k<n;k++){
				if (s&(1<<k))continue;
				move(f[s|(1<<k)],f[s]*calc((1<<n)-s-a[i],(1<<k)-1)%mo<<k);
			}
		}
	}
	ll ans=0;cnt[0]=1;
	for (int i=0;i<1<<n;i++){
		cnt[i]=cnt[i>>1]*(i&1?-1:1);
		move(ans,(cnt[i]*f[i]*jc[(1<<n)-1-i]%mo+mo)<<n);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N =  2e+5+5;

int n,V;
int a[N];
int lef[N][20],rig[N][20];
int val[20],k;
int f[N*2],g[N*2];
struct point{
	int x,y,id;
	point(const int x_=0,const int y_=0,const int id_=0){x=x_;y=y_;id=id_;}
	friend bool operator < (point a,point b){
		if (a.x!=b.x)return a.x>b.x;
		if (a.y!=b.y)return a.y<b.y;
		return a.id<b.id;
	}
}p[N*4];
int m;
bool ans[N];

int main(){
	n=get();V=get();
	fo(i,1,n)a[i]=get();
	val[0]=V;
	k=0;
	for(;val[k];k++)val[k+1]=val[k]/2;
	fo(i,1,n)
		fo(j,0,k){
			lef[i][j]=i;
			if (i>1&&a[i]-a[i-1]<=val[j])lef[i][j]=lef[i-1][j];
		}
	fd(i,n,1)
		fo(j,0,k){
			rig[i][j]=i;
			if (i<n&&a[i+1]-a[i]<=val[j])rig[i][j]=rig[i+1][j];
		}
	fo(i,0,(1<<k)-1)g[i]=1e+9;
	f[0]=0;g[0]=n+1;
	fo(i,1,k){
		f[1<<(i-1)]=rig[1][i];
		g[1<<(i-1)]=lef[n][i];
	}
	fo(i,1,(1<<k)-1){
		fo(x,1,k)
		if (((1<<(x-1))&i)==0){
			if (f[i]==n)f[i|(1<<(x-1))]=n;
			else f[i|(1<<(x-1))]=max(f[i|(1<<(x-1))],rig[f[i]+1][x]);
			if (g[i]==1)g[i|(1<<(x-1))]=1;
			else g[i|(1<<(x-1))]=min(g[i|(1<<(x-1))],lef[g[i]-1][x]);
		}
	}
	fo(i,1,n)p[++m]=point(lef[i][0],rig[i][0],i);
	fo(i,0,(1<<k)-1)p[++m]=point(f[i]+1,g[((1<<k)-1)^i]-1,0);
	sort(p+1,p+1+m);
	int lim=1e+9;
	fo(i,1,m)
	if (p[i].id==0)lim=min(lim,p[i].y);
	else ans[p[i].id]=(lim<=p[i].y);
	fo(i,1,n)
	if (ans[i])printf("Possible\n");else printf("Impossible\n");
	return 0;
}

Measured memory_bytes: 47104