akhauriyash/Code-Regression huggingface dataset:
n = int( raw_input( ) )
dic = {}
output = []
for i in range( n ):
	cmd, word = raw_input( ).split( " " )
	if "insert" == cmd:
		dic[ word ] = True
	elif "find" == cmd:
		if not dic.get( word ):
			output.append( "no" )
		else:
			output.append( "yes" )

print( "\n".join( output ) )

Measured memory_bytes: 69692
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }
  private static boolean isAllowed(String key) {
    String[][] ps = {{"A", "GC"}, {"AG", "C"}, {"ACG", ""}, {"GAC", ""}};
    for (String[] p : ps) {
      int i = key.indexOf(p[0]);
      if (i < 0) continue;
      if (key.indexOf(p[1], i + p[0].length()) >= 0) return false;
    }
    return true;
  }
  private static final int mod = 1_000_000_007;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    Map<String, Integer> counter = new HashMap<>();
    Map<String, Integer> counter2 = new HashMap<>();
    String[] chars = new String[] {"A", "C", "G", "T"};
    for (String c1 : chars) for (String c2 : chars) counter.put(c1 + c2, 1);
    for (int i = 3; i <= n; i++) {
      counter2.clear();
      for (String c : chars) {
        for (String prefix : counter.keySet()) {
          String s = prefix + c;
          if (!isAllowed(s)) continue;
          String key = s.substring(Math.max(0, s.length() - 3), s.length());
          int val = (counter2.getOrDefault(key, 0) + counter.get(prefix)) % mod;
          counter2.put(key, val);
        }
      }
      counter.clear();
      counter.putAll(counter2);
    }
    int sum = 0;
    for (int val : counter.values()) sum = (sum + val) % mod;
    System.out.println(sum);
  }
}

Measured memory_bytes: 30412
#include <bits/stdc++.h>
using namespace std;
 
typedef vector<int> veci;
typedef pair<int,int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9+7)
#define INF int(1e9+7)
#define fi first
#define se second
 
int main()
{
    ios::sync_with_stdio(false);
#ifdef LOCAL_TEST    
    int tcs;
    cin >> tcs;
    while (tcs-->0)
#endif        
{
    int n, k;
    cin >> n >> k;
 
    int wgcd;
    int maxi;
    veci va(n);
    for (int i=0; i<n; ++i) {
        cin >> va[i];
        if (i==0) {
            wgcd = va[i];
            maxi = va[i];
        } else {
            wgcd = __gcd(wgcd,va[i]);
            maxi = max(maxi,va[i]);
        }
    }

    string res;
    if (k%wgcd==0 && k<=maxi) {
        res = "POSSIBLE";
    } else {
        res = "IMPOSSIBLE";
    }
 
    cout << res << endl;
}}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv){
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	ll a,b; cin >> a >> b;
	ll c = gcd(a,b);
	ll ans = a*b/c;
	out(ans);
}




Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	char a[21];
	int i,nagasa;
	cin>>a;
	nagasa=strlen(a);
	for(i=nagasa-1;i>=0;i--)
		cout<<a[i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1132
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define rep2(x,from,to) for(long long x=from;x<to;x++)
#define rep(x,to) rep2(x,0,to)
#define INF 1000000000
typedef long long ll;
typedef pair<long long,long long> P;
typedef pair<long long,P>  PP;
typedef pair<long long,PP> PPP;
long long n;
long long m;
long long a[1006];
long long b[1006];
long long c[1006][19];
long long cc[1006];
long long before[1<<12];
long long after[1<<12];
int main()
{
    cin>>n>>m;
    rep(i,m)
    {
        cin>>a[i]>>b[i];
        rep(j,b[i])
        {
            cin>>c[i][j];
            c[i][j]--;
            cc[i]+=(1<<c[i][j]);
        }
    }
    rep(i,1<<12)
    {
        before[i]=INF;
        after[i]=INF;
    }
    before[0]=0;
    after[0]=0;
    for(long long i=0;i<m;i++)
    {
        //cout<<"i"<<i<<endl;
        for(long long j=0;j<(1<<n);j++)
        {
            after[j]=before[j];
        }
        for(long long j=0;j<(1<<n);j++)
        {
            if(before[j]==INF)continue;
            //cout<<" used"<<j<<endl;
            long long ne=j|cc[i];
            if(after[ne]>before[j]+a[i])
            { 
                //cout<<  "after[ne]"<<after[ne]<<endl;
                after[ne]=before[j]+a[i];
                //cout<<  "~after[ne]"<<after[ne]<<endl;
            }
            //after[ne]=min(after[ne],before[j]+a[i]);
          //  cout<<"  ne"<<ne<<endl;           
        }
        for(long long j=0;j<(1<<n);j++)
        {
            before[j]=after[j];
        }
    }
    if(before[(1<<n)-1]==INF)
    {
        cout<<-1<<endl;
    }
    else cout<<before[(1<<n)-1]<<endl;
    return 0;
}

Measured memory_bytes: 512
/****************************
*  Developer : joshi08
*  Date  :  27-06-2020
*  Year  :  2020
****************************/

#include <bits/stdc++.h>

#define lli long long int
#define mod 1000000007
#define fi first
#define se second
#define ii pair<lli, lli>
#define mp make_pair
#define endl '\n'
const double PI = 3.141592653589793238460;
lli gcd(lli a, lli b) { if (a == 0) return b; return gcd(b % a, a);}
lli max(lli a, lli b) {if (a > b) return a; else return b;}
lli min(lli a, lli b) {if (a < b) return a; else return b;}
lli power(lli a, lli n){ lli res = 1; while(n){ if(n%2==0){ a *= a; n /= 2; } else{ res *= a; n--; } } return res; }

using namespace std;
unsigned lli mk=0;



int main()
{
    ios::sync_with_stdio(false);
    
	unsigned lli n,i,m=0;
	cin>>n;
	
	for(i=1;i<=n;i++)
	{
		m += i*((n/i)*((n/i)+1)/2);
	}
	
	cout<<m;
    return 0;
}



Measured memory_bytes: 3652
Public Class Program
  Shared Sub Main()
    Dim ab As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
    Dim a As Integer = ab(0)
    Dim b As Integer = ab(1)
    Dim ans As Integer = a - 2 * b
    If ans < 0 Then ans = 0
    Console.WriteLine(ans.ToString())
  End Sub
End Class

Measured memory_bytes: 13140
K = int(input())
 
sevens = 7 % K
count = 1
 
while(sevens % K !=0):
  sevens = sevens * (10 % K) + (7 % K)
  sevens = sevens % K
  count += 1
  if count > K:
    count = -1
    break
    
print(count)

Measured memory_bytes: 9108
//#i#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <fstream>
#include <stdio.h>
#include<unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) vdeb(da[i]);
    std::cout << std::endl;
}

using namespace std;

int n;
ll a, b;

bool ch(vector<ll> &da, ll now){
    ll co = 0;
    rip(i,n,0){
        ll me = max((ll)0, da[i]-now*b);
        //cout << me << endl;
        co += (me+a-b-1)/(a-b);
    }
    return co <= now;
}

int main(){
    cin >> n >> a >> b;
    vector<ll> da(n);
    rip(i,n,0) cin >> da[i];
    ll le = 0, ri = INT_MAX;
    while(ri-le > 1){
        ll now  = (le+ri)/2;
        if(ch(da, now)){
            ri = now;
        }
        else{
            le = now;
        }
    }
    cout << ri << endl;
}

Measured memory_bytes: 1024
def resolve():
    N, K = map(int, input().split())

    if K == 0:
        print(N ** 2)
        return

    ans = 0
    for b in range(1, N + 1):
        ans += N // b * max(0, b - K)
        ans += max(0, N % b + 1 - K)

    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9072
N,M = map(int, input().split())
A_list = [int(e) for e in input().split()]

OK_count = 0
for i in range(N):
  if A_list[i]>=sum(A_list)/(4*M):
  	OK_count+=1
    
if OK_count >= M:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 int main() {
   string S, T; cin >> S >> T;
   if (S == T.substr(0, S.length())) cout << "Yes" << endl;
   else cout << "No" << endl;
 }


Measured memory_bytes: 3600
n = int(input())
a = list(int(input()) for _ in range(n))

maximum = max(a)
if a.count(maximum):
    num = a.index(maximum)
    x = max(a[:num]+a[num+1:])
    for _ in range(num):
        print(maximum)

    print(x)

    for _ in range(num+1, n):
        print(maximum)

else:
    for _ in range(n):
        print(maximum)


Measured memory_bytes: 14112
#include <bits/stdc++.h>
int main() {
    std::cin.tie(nullptr); std::ios::sync_with_stdio(false);

    int N;
    std::cin >> N;
    std::deque<int> b(N);
    std::deque<int> ans;
    for(auto&i:b)std::cin>>i;
    
    for(int i = 0;i<N;++i){
    	for(int j = b.size()-1;j>=0;--j){
    		if(b[j]==j+1){
    			ans.push_front(b[j]);
    			b.erase(b.begin()+j);
    			break;
    		}
    	}
    }
   	if(b.empty()){
   		for(auto&i:ans){
   			std::cout << i << std::endl;
   		}
   	}
   	else std::cout << -1 << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define IT iterator 
#define vi vector<int>
#define TP template<class o>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20,mod=998244353,inf=2e9;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
    char c=gc; x=0; int f=1;
    while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
    while(isdigit(c)) x=x*10+c-'0',c=gc;
    x*=f;
}
template<class o> void qw(o x) {
    if(x/10) qw(x/10);
    putchar(x%10+'0');
}
template<class o> void pr1(o x) {
    if(x<0)x=-x,putchar('-');
    qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
    if(x<0)x=-x,putchar('-');
    qw(x); putchar('\n');
}

ll p[N],np[N],n,k,s,cnt,ans;
int c[N],a[N];

TP void upd(o &x,int y) {x += y; if(x>=mod) x -= mod;}
void add(int x,int y) {upd(s,y); for( ;x<=n;x += x&-x) upd(c[x],y); }
int ask(int x) {ll y=0; for( ; x;x -= x&-x) y += c[x]; return y%mod; }
void clear() {memset(c+1,0,sizeof(int)*n); s=0;}

ll mult(ll a,ll b,ll p) {
    a=(a%p+p)%p; b=(b%p+p)%p;
    ll c=(ld)a*b/p;
    return a*b-c*p;
}
ll gcd(ll a,ll b) {return !a?b:gcd(b%a,a);}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
ll power(ll a,ll b=mod-2) {
    ll c=1;
    while(b) {
        if(b&1) c=c*a%mod;
        b /= 2; a=a*a%mod;
    }
    return c;
}
ll Power(ll a,ll b=mod-2) {
    ll c=1;
    while(b) {
        if(b&1) c=mult(c,a,mod);
        b /= 2; a=mult(a,a,mod);
    }
    return c;
}

int main() {
    qr(n); qr(k);
    for(int i=1;i<=n;i++) 
		qr(a[i]),add(a[i],1),cnt += i-ask(a[i]);
    p[0]=np[0]=1; p[1]=(k-1)*power(k)%mod; np[1]=power(p[1]); clear();
    for(int i=2;i<=n;i++) p[i]=p[i-1]*p[1]%mod,np[i]=np[i-1]*np[1]%mod;
    for(int i=1;i<=n;i++) {
        int f=max(i-k,0LL);
        ans += p[f]*(2*ask(a[i])-s+mod)%mod;
        add(a[i],np[f]);
    }
    pr2((cnt+ans%mod*(mod+1)/2%mod)%mod); return 0;
}

Measured memory_bytes: 8264
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

LL n;
int a[101010], d[101010];
LL sum, sa_sum;
int main(){
    cin >> n;
    REP(i, n)cin >> a[i];
    REP(i, n)sum += a[i];
    LL tr = n * (n + 1)/2;
    if(sum % tr){
        cout << "NO" << endl;
        return 0;
    }
    LL k = sum / tr;
    REP(i, n){
        d[i] = a[(i + 1)%n] - a[i];
        d[i] -= k;
        if(d[i] > 0){
            cout << "NO" << endl;
            return 0;
        }
        if((-d[i])%n){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

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

const int MAX = 2100000;

int main() {
  int N;
  cin >> N;
  vector<long long> v(MAX, 0);
  for (int i = 0; i < N; ++i) {
    long long a;
    cin >> a;
    v[a]++;
  }
  for (int d = 1; d < MAX; ++d) {
    if (v[d] == 0) continue;
    if (v[d] > 1) v[d] = 0;
    for (int e = d * 2; e < MAX; e += d) {
      v[e] = 0;
    }
  }
  long long res = 0;
  for (int d = 1; d < MAX; ++d) res += v[d];
  cout << res << endl;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  vector<P> p(n);
  REP(i, n) cin >> p[i].fi >> p[i].se;

  sort(ALL(p));


  int sz = SZ(p);
  cout << p[sz-1].fi + p[sz-1].se << endl;
}


Measured memory_bytes: 1024
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter
    import networkx as nx
    h, w = map(int, readline().split())
    G = nx.DiGraph()

    for i in range(10):
        costs = list(map(int, readline().split()))
        for j, cost in enumerate(costs):
            if i != j:
                G.add_edge(i, j, weight=cost)

    d = nx.algorithms.floyd_warshall(G)

    counter = Counter()
    for _ in range(h):
        nums = list(map(int, readline().split()))
        counter.update(nums)
    ans = 0
    for num in range(10):
        ans += counter[num] * d[num][1]

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
    int n,x;
    set<int>ar;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        ar.insert(x);
    }
    if(ar.size()==n)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<cstring>
typedef long long ll;
using namespace std;
int n;
int a[3005];
ll memo[3005][3005];

ll dp(int l,int r){
  if(l==r)return a[l];
  if(memo[l][r]!=-1)return memo[l][r];

  return memo[l][r]=max(a[l]-dp(l+1,r),-dp(l,r-1)+a[r]);
}
  
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  memset(memo,-1,sizeof(memo));
  
  cout<<dp(0,n-1)<<"\n";
  
  return 0;
}
  


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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

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

    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    int dx = tx - sx;
    int dy = ty - sy;

    cout << string(dx, 'R');
    cout << string(dy, 'U');

    cout << string(dx, 'L');
    cout << string(dy, 'D');

    cout << 'D';
    cout << string(dx+1, 'R');
    cout << string(dy+1, 'U');
    cout << 'L';

    cout << 'U';
    cout << string(dx+1, 'L');
    cout << string(dy+1, 'D');
    cout << 'R';
    
    cout << endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static class Reader {

		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public Reader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

	}

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Reader sn = new Reader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		int n = sn.nextInt();
		int k = sn.nextInt();
		int a[] = new int[n];
		
		for (int i = 0; i < a.length; i++) {
			a[i] = sn.nextInt();
			
		}
	/*	int res=0;
		for(int i=0; i<=n-k; i++){
			int aux=0;
			int j=i;
			int cont=0;
			while(true){
				if(cont==k){
					break;
				}
				aux = aux+a[j];
				j++;
				cont++;
			}
			res = Math.max(res, aux);
		}
		**/
		int res=0;
		Arrays.sort(a);
		for(int i=n-k; i<n; i++){
			res+=a[i];
		}
		
		out.println(res);
		out.close();
	}

}

Measured memory_bytes: 21332
#高橋君は 3桁のパスワードを設定しようとしています。
#使える文字が 1 以上 N 以下の数字のみであるとき、設定できるパスワードが全部で何種類であるかを答えてください。

num=gets.to_i
pattern=1
parm=1
for i in  1..num do
  pattern=pattern*i
end
for i in  1..(num-1) do
  parm=parm*i
end
result=pattern/parm
result=result*result*result
puts(result)

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
template<class Type> void line(const Type &a){int cnt=0;for(auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n;
	cin>>n;
	
	REP(i,50001){
		int tmp=i;
		if(int(tmp*1.08)==n){
			cout<<tmp<<endl;
			return 0;
		}
	}
	
	cout<<":("<<endl;
}


Measured memory_bytes: 256
n = int(input())
ab,xa,bx,bxa = 0,0,0,0
for i in range(n):
  s = input()
  if s[-1] == 'A' and s[0] == 'B':
    bxa += 1
  if s[-1] == 'A':
    xa += 1
  if s[0] == 'B':
    bx += 1
  for j in range(len(s)-1):
    if s[j]+s[j+1] == 'AB':
      ab += 1
if bxa == xa == bx:
  print(ab+bxa-bool(bxa))
else:
  print(ab+min(xa,bx))

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

int main(){
  int n, h;
  cin >> n >> h;
  vector<int> an(n), bn(n);
  for(int i=0; i<n; ++i) cin >> an[i] >> bn[i];
  int mxan = 0;
  for(int i=0; i<n; ++i) mxan = max(mxan, an[i]);
  sort(bn.begin(),bn.end());
  reverse(bn.begin(),bn.end());
  int ans = 0;
  for(int i=0; i<n; ++i){
    if(bn[i] < mxan || h <= 0) break;
    h -= bn[i];
    ++ans;
  }
  if(h>0) ans += (h-1)/mxan +1;
  cout << ans << endl;
}

Measured memory_bytes: 4016
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int n;
  cin >> n;
  map<ll, ll, greater<ll>> m;
  rep(i, n) {
    ll a;
    cin >> a;
    if (m.find(a) == m.end())
      m[a] = 1;
    else
      m[a]++;
  }
  ll len1 = 0;
  for (auto& x : m) {
    if (x.second >= 4) {
      if (len1 == 0) {
        cout << x.first * x.first << endl;
        return 0;
      } else {
        cout << len1 * x.first << endl;
        return 0;
      }
    } else if (x.second >= 2) {
      if (len1 == 0) {
        len1 = x.first;
      } else {
        cout << len1 * x.first << endl;
        return 0;
      }
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <algorithm>


using namespace std;

int main(void) {
	int N;

	cin >> N;

	if (N % 2 == 0) {
		printf("%lf", 1 / 2.0);
	}
	else {
		printf("%lf", (N + 1) / (2.0 * N));
	}
	   
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    char str[5];
    int i, j=0;
    scanf("%s",str);
    for(i=0;i<3;i++){
        if(str[i] == str[i+1]){
            j++;
        }
    }
    if(j == 0){
        printf("Good\n");
    }
    else{
        printf("Bad\n");
    }
    return 0;
    
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
typedef unsigned long long ll;

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

    ll dp[3][N];
    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for(int i = 1; i < N; i++)
    {
        dp[0][i] = max(dp[1][i-1], dp[2][i-1]) + a[i];
        dp[1][i] = max(dp[0][i-1], dp[2][i-1]) + b[i];
        dp[2][i] = max(dp[0][i-1], dp[1][i-1]) + c[i];
    }

    cout << max({dp[0][N-1], dp[1][N-1], dp[2][N-1]}) << endl;

    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> po(n,0);
    rep(i,q) {
        int a;
        cin >> a;
        a--;
        po[a]++;
    }
    rep(i,n) {
        if(k-q+po[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

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

int dp[100000];
vector<int> pillar;

int jump(int now, int cost){
    if(dp[now] != -1){
        return cost + dp[now];
    }
    if(pillar.size() == now + 1){
        dp[now] = 0;
    }else if(pillar.size() == now + 2){
        dp[now] = abs(pillar[now] - pillar[now + 1]);
    }else{
        dp[now] = min(jump(now + 1, abs(pillar[now] - pillar[now + 1])), jump(now + 2, abs(pillar[now] - pillar[now + 2])));
    }
    return cost + dp[now];
}

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        int input;
        cin >> input;
        pillar.push_back(input);
    }
    for(int i = 0; i < 100000; i++){
        dp[i] = -1;
    }
    cout << jump(0, 0) << endl;
}


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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n;
	cin >> n;
	vector<int> ans(n + 1);
	for (int x = 1; x*x <= n; x++) {
		for (int y = 1; y*y <= n; y++) {
			for (int z = 1; z*z <= n; z++) {
				int v = x*x + y*y + z*z + x*z + y*x + y*z;
				if (v <= n) ans[v]++;
			}
		}
	}
	for (int i = 1; i <= n; i++) cout << ans[i] << '\n';
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
      ll t;
      cin >> t;
      //int value = 1;
      //int count = 0;
      if(t >= 400 && t <= 599){
            printf("8\n");
      }
      else if(t >= 600 && t <= 799){
            printf("7\n");
      }
      else if(t >=800 && t <= 999){
            printf("6\n");
      }
      else if(t >= 1000 && t <= 1199){
            cout << 5 << endl;
      }
      else if(t >= 1200 && t <= 1399){
            printf("4\n");

      }
      else if (t >= 1400 && t <= 1599){
            printf("3\n");

      }
      else if(t >= 1600 && t<= 1799){
            printf("2\n");
      }
      else if(t >= 1800 && t <= 1999){
            printf("1\n");
      }
          



          
}

Measured memory_bytes: 3616
using System;
namespace MyConsoleAppContests
{

  //
  // Contests
  //
    class Program
    {
        static void Main(string[] args)
        {
            //
            // 入力
            //
            // 整数の入力
            int n = int.Parse(Console.ReadLine());// 問題の数

            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]); //第１問の配点　ａ以下
                                         //第２問の配点　ａ＋１以上ｂ以下
            int b = int.Parse(input[1]); //第３問の配点　ｂ＋１以上

            int[] point = new int[n];// 入力された配点を記録する
         // スペース区切りの整数の入力
         //string[] input = Console.ReadLine().Split(' ');
         //int b = int.Parse(input[0]);
         //int c = int.Parse(input[1]);
            string[] inputPoint = Console.ReadLine().Split(' ');// 入力された配点
            for (int i = 0; i < point.Length; i++)
            {                
                point[i] = int.Parse(inputPoint[i]);
            }
            //
            int counter1 = 0;
            int counter2 = 0;
            int counter3 = 0;

            for(int j = 0; j < point.Length; j++)
            {
                if (point[j] <= a)
                {
                    counter1++;
                }
                if ((point[j] >= (a + 1)) && (point[j] <= b))
                {
                    counter2++;
                }
                if(point[j] >= (b + 1))
                {
                    counter3++;
                }
            }
            //
            int min = counter1;
            if (counter2 < min)
            {
                min = counter2;
            }
            if (counter3 < min)
            {
                min = counter3;
            }

            //
            // 出力
            //
            Console.WriteLine(min);
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int dfs(int v, vector<vector<int>> &g, vector<int> &dp, vector<bool> &seen)
{
    if (seen[v])
    {
        return dp[v];
    }
    seen[v] = true;
    dp[v] = 0;
    for (int u : g[v])
    {
        int res = dfs(u, g, dp, seen);
        chmax(dp[v], res + 1);
    }
    return dp[v];
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    vector<int> h(n, 0);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        h[b]++;
    }
    vector<int> dp(n, 0);
    vector<bool> seen(n, false);
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        chmax(ans, dfs(i, g, dp, seen));
    }
    cout << ans << endl;
}

Measured memory_bytes: 9216
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>


long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){
int N;
cin>>N;
map<int,int>v;//Aにん、番号i
int a;
for(int i=0;i<N;i++){
    cin>>a;
    v.insert(make_pair(a,i+1));
}
auto iter=v.begin();

while(iter!=v.end()){
    cout<<iter->second<<" ";
    iter++;
}
 return 0;
}
/*
3
2 3 1

3 1 2


5
1 2 3 4 5

1 2 3 4 5

8
8 2 7 3 4 5 6 1

8 2 4 5 6 7 3 1
*/

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

const int M = 1e9 + 7;

int main()
{
 int n;
 cin>>n;
 int arr[n];
 for(int i=0; i<n; i++)
    cin>>arr[i];
 ll sum = 0, ans = 0;
 for(int i=0; i<n; i++){
    ans = (ans + (sum*arr[i])%M)%M;
    sum = (sum + arr[i])%M;
 }
 cout<<ans;
 return 0;
}



Measured memory_bytes: 4412
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int N;
int b[205];
void plot() {
    rep(i,104) cout<<b[i]<<" ";
    cout<<endl;
}
void move() {
    //plot();
    int h = 0;
    rep(i,204) if(b[i]!=0) h++;
    rep(i,204) if(b[i]!=0) b[i]--;
    b[202]=h;
    //plot();
    rep(i,204) {
        if(!i) continue;
        if(b[i]!=0) {
            int j;
            for(j=i-1;j>=0;j--) {
                if(b[j]!=0) break;
            }
            swap(b[i],b[j+1]);
        }
    }

}
bool ok() {
    bool f=true;
    rep(i,204) {
        if(b[i]==0) break;
        f&=(i+1)==b[i];
    }
    return f;

}
void solve() {
    rep(i,205) b[i]=0;
    rep(i,N) cin>>b[i];
    int cnt=0;
    if(ok()) {
        cout<<"0"<<endl;
        return;
    }
    while(1) {
        cnt++;
        move();
        if(ok()) {
            cout<<cnt<<endl;
            return;
        }
        if(cnt == 10000) break;

    }
    cout<<"-1"<<endl;
}

int main() {
    while(cin>>N) {
        if(N==0) break;
        solve();

    }
    return 0;
}

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

int main(){
    ll n, q;
    cin >> n >> q;
    vector< vector<ll> > G(n);
    rep(i, 0, n-1) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<ll> imos(n, 0), ans(n, 0);
    rep(i, 0, q) {
        ll p, x;
        cin >> p >> x;
        p--;
        imos[p] += x;
    }
    queue<pair<ll,ll>> que;
    que.push({0, 0});
    while(!que.empty()){
        auto q = que.front();
        que.pop();
        ans[q.first] = ans[q.second] + imos[q.first];
        for(auto g : G[q.first]) {
            if(g == q.second) continue;
            que.push({g, q.first});
        }
    }
    rep(i, 0, n) cout << ans[i] << (i == n-1 ? "\n" : " ");
    return 0;
}

Measured memory_bytes: 22092
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)10e9+7;
const int INF = 0x3f3f3f3f;

int a[100001];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, x;
    cin >> n >> x;
    for(int i=0; i<n; i++) cin >> a[i];
    if(n==2)
    {
        cout << max(0, a[0]+a[1]-x);
        return 0;
    }
    ll ans=0;
    for(int lb=1; lb<n; lb++)
    {
        int aa=a[lb]+a[lb-1]-x;
        if(aa>0)
        {
            a[lb]-=aa;
            if(a[lb]<0)
            {
                a[lb-1]+=a[lb];
                a[lb]-=a[lb];
            }
            ans += aa;
        }
    }
    cout << ans;
}

//TODO: 48


Measured memory_bytes: 640
#include <stdio.h>

int main(){
    int i, s;
    char x[1001];
    
    while(scanf("%s", x), x[0] != '0'){
        s = 0;
        
        for(i = 0; x[i] != '\0'; ++i){
            s += x[i] - '0';
        }
        
        printf("%d\n", s);
    }
    
    return 0;
}

Measured memory_bytes: 536
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()

void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}

bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
	if(a.ff!=b.ff)
		return a.ff<b.ff;
	else
	{
		if(a.ss>b.ss)
			return b.ss<a.ss;
		else if(a.ss<b.ss)
			return a.ss<b.ss;
	}
	return a.ff>b.ff;
}

ll powe(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}

int main()
{
	checkpoint1();
	string s;
	cin>>s;
	ll n=0;
	for(ll i=0;i<s.length();i++)
		n+=(s[i]-'0');
	if(n%9==0)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3752
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

template<typename T> bool chmin(T& a, const T& b) {
    if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
    if (a < b) return a = b, true; else return false;
}

// End of template.

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

    int x[5];
    rep(i, 5) cin >> x[i];
    rep(i, 5) if (x[i] == 0) {
        print(i + 1);
        return 0;
    }

    return 0;
}



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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    vector<int> A(5);
    for (int i = 0; i < 5; i++) {
        cin >> A[i];
    }
    int k;
    cin >> k;

    sort(all(A));
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            if (abs(A[i] - A[j]) > k) {
                cout << ":(" << endl;
                return;
            }
        }
    }
    cout << "Yay!" << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

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

int n,m;
vector<pair<int, int>> id[100004];
string ans[100004];

string toString(int x){
	string ret = "000000";
	for(int i = 5;i>=0;i--){
		ret[i] = char(x%10)+'0';
		x /= 10;
	}
	return ret;
}

int main() {
	cin>>n>>m;
	for (int i=0; i<m; i++){
		int p, y;
		cin>>p>>y;
		id[p].push_back({y, i});
	}
	for(int i = 1;i<=n;i++){
		sort(id[i].begin(), id[i].end());
		for(int j = 0; j<id[i].size(); j++)
			ans[id[i][j].second] = toString(i) + toString(j + 1);
	}
	for(int i = 0;i<m;i++)	cout<<ans[i]<<'\n';
	return 0;
}

Measured memory_bytes: 12416
#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>
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;

int main() {
    int n, y, com[3] = { -1,-1,-1 };
    cin >> n >> y;
    for (int i = 0; i <= n; i++) {//10000
        for (int j = 0; j <= n; j++) {//5000
            if ((y - 10000 * i - 5000 * j == 1000 * (n - i - j)) && (n-i-j)>=0) {
                com[0] = i;
                com[1] = j;
                com[2] = n - i - j;
                break;
            }
        }
    }
    for (int i = 0; i < 3; i++)cout << com[i] << ' ';
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
vector<int> vis(N,0);
vector<int> par(N,0);
vector<int> adj[N];
#define pb push_back
int u,v,n,m;
void solve(){
        queue<int>q;
        q.push(1);
        vis[1]=1;
        while(!q.empty()){
                int u=q.front(); q.pop();
                for(int i: adj[u]){
                        if(!vis[i]){vis[i]=1; par[i]=u; q.push(i); }
                }
        }
        for(int i=1;i<=n;i++){
                if(!vis[i]) { cout<<"No"<<endl; return ; }
        }
        cout<<"Yes"<<endl;
        for(int i=2;i<=n;i++) cout<<par[i]<<endl;
}

int main(){
        cin>>n>>m;
        for(int i=1;i<=m;i++) { cin>>u>>v; adj[u].pb(v); adj[v].pb(u); }
        solve();
}


Measured memory_bytes: 10636
#include <bits/stdc++.h>
using namespace std;
int x, a, b;
int main() {
    cin >> x >> a >> b;
    int xa = abs(x-a);
    int xb = abs(x-b);

    if(xa > xb) {
        cout << 'B' << endl;
    }else {
        cout << 'A' << endl;
    }
}

Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <numeric>
#include <vector>

int main()
{
    int n, m;
    std::cin >> n;
    std::vector<int> t(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> t[i];
    }
    std::cin >> m;
    std::vector<int> p(m), x(m);
    for (int j = 0; j < m; ++j) {
        std::cin >> p[j] >> x[j];
    }

    const std::int64_t total = std::accumulate(t.cbegin(), t.cend(), 0);
    for (int j = 0; j < m; ++j) {
        std::int64_t this_total = total - t[p[j] - 1] + x[j];
        std::cout << this_total << "\n";
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <utility>
#define int long long
#define F first
#define S second
using namespace std;
typedef pair<long long, int> edge;
typedef pair<long long, long long> ll;
typedef pair<ll, int> prior;
const long long INF = 1000000000000000000LL;
int32_t main() {
	int N, M, L, Q, A, B;
	scanf("%lld %lld %lld", &N, &M, &L);
	long long C;
	ll sp[N][N];
	vector<edge> adjlist[N];
	for (int i = 0; i < M; ++i) {
		scanf("%lld %lld %lld", &A, &B, &C);
		if (C > L) continue;
		adjlist[A - 1].push_back(edge(C, B - 1));
		adjlist[B - 1].push_back(edge(C, A - 1));
	}
	for (int i = 0; i < N; ++i) {
		fill_n(sp[i], N, ll(INF, INF));
		sp[i][i] = ll(0, 0);
		priority_queue< prior, vector<prior>, greater<prior> > pq;
		pq.push(prior(sp[i][i], i));
		while (!pq.empty()) {
			prior k = pq.top();
			pq.pop();
			if (sp[i][k.S] != k.F) continue;
			for (edge a: adjlist[k.S]) {
				ll q;
				q.F = k.F.F;
				q.S = k.F.S;
				if (k.F.S + a.F > L) {
					q.F += 1;
					q.S = a.F;
				} else q.S += a.F;
				if (sp[i][a.S] > q) {
					sp[i][a.S] = q;
					pq.push(prior(q, a.S));
				}
			}
		}
	}
	scanf("%lld", &Q);
	for (int i = 0; i < Q; ++i) {
		scanf("%lld %lld", &A, &B);
		if (sp[A - 1][B - 1].F >= INF) printf("-1\n");
		else printf("%lld\n", sp[A - 1][B - 1].F);
	}
	return 0;
}

Measured memory_bytes: 4352