akhauriyash/Code-Regression huggingface dataset:
const check = (word, used) => {
  if (used.length === 0) {
    return true
  }

  if (used[used.length - 1][used[used.length - 1].length - 1] !== word[0]) {
    return false
  }

  if (used.includes(word)) {
    return false
  }

  return true
}

const main = stdin => {
  const input = stdin.trim().split('\n')
  const N = parseInt(input[0])

  const used = []
  let ans = true
  for (let i = 0; i < N; i++) {
    const word = input[i + 1]
    if (!check(word, used)) {
      ans = false
      break
    }

    used.push(word)
  }

  console.log(ans ? 'Yes' : 'No')
}


// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(N);
  for(int i=0;i<N;++i) cin >> A[i];
  sort(A.begin(),A.end(),greater<int>());
  int sum = 0;
  for(int i=0;i<N;++i) sum += A[i];
  if(4*M*A[M-1]>=sum) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
from __future__ import print_function
import sys,heapq
n,q=map(int,sys.stdin.readline().split())
a=[[] for _ in range(n)]
for _ in range(q):
  g=list(map(int,sys.stdin.readline().split()))
  if g[0]==0:
    heapq.heappush(a[g[1]],-g[2])
  elif g[0]==1:
    a[g[1]] and print(-a[g[1]][0])
  else:
    a[g[1]] and heapq.heappop(a[g[1]])


Measured memory_bytes: 13456
<?php

$n = str_split(trim(fgets(STDIN)));

switch ($n[count($n)-1]) {
  case 2:
  case 4:
  case 5:
  case 7:
  case 9:
    echo 'hon';
    break;
  case 0:
  case 1:
  case 6:
  case 8:
    echo 'pon';
    break;
  case 3:
    echo 'bon';
    break;
}


Measured memory_bytes: 16108
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
	char S[1010];
	int C[4]={0}, i;
	scanf("%s", &S);
	for (i=0;i<strlen(S);i++) {
		if (S[i] == 'N') C[0]++;
		else if (S[i] == 'S') C[1]++;
		else if (S[i] == 'E') C[2]++;
		else if (S[i] == 'W') C[3]++;
	}
	if (((C[0]>0 && C[1]>0) || (C[0]==0 && C[1]==0)) && ((C[2]>0 && C[3]>0) || (C[2]==0 && C[3]==0))) printf("Yes\n");
	else printf("No\n");

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb(x) (x&-(x))
const int N = 101010;
char a[3];
int cnt=0;
int main(){
	scanf("%s",a);
	rep(i,0,3) if(a[i]=='o') cnt++; 
	printf("%d\n",700+100*cnt);
    return 0;
}


Measured memory_bytes: 256
import sys

def main():
    arg = raw_input().split(" ")
    a = int(arg[0])
    b = int(arg[2])
    op = arg[1]
    if a < 1 or b > 10 **9:
        return 0

    if op == "+":
        return a + b
    elif op == "-":
        return a - b
    else:
        return 0

print main()


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

ll n, m, q, ans = 0;
ll a[50], b[50], c[50], d[50];
ll A[10];

void dfs(int dep, int num) {
  if (dep == n) {
    ll t = 0;
    rep(i, q) if (A[b[i]] - A[a[i]] == c[i]) t += d[i];
    ans = max(ans, t);
    return;
  }

  for (int i = num; i <= m; ++i) A[dep] = i, dfs(dep + 1, i);
}

int main() {
  cin >> n >> m >> q;
  rep(i, q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--, b[i]--;
  }

  dfs(0, 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

// const int SZ = 1000000;
// vector<ll> BIT(SZ+1);
ll sum(vector<ll>& BIT, int a) {
  ll ans=0;
  while(a) {
    ans+=BIT[a];
    a-=a&-a;
  }
  return ans;
}

ll sum(vector<ll>& BIT, int a,int b) {
  return sum(BIT, b)-sum(BIT, a-1);
}

void add(vector<ll>& BIT, int a,ll x) {
  while(a<BIT.size()) {
    BIT[a]+=x;
    a+=a&-a;
  }
}

void reset(vector<ll>& BIT) {
  fill(BIT.begin(),BIT.end(),0);
}


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int n,q;
  string s;
  cin>>n>>s>>q;
  unordered_map<char, vector<ll>> m;
  rep(i,26) {
    m[(char)(i+'a')]=vector<ll>(n+1);
    reset(m[(char)(i+'a')]);
  }
  rep(i,s.size()) {
    add(m[s[i]],i+1,1);
  }
  rep(_i, q) {
    int t;
    cin>>t;
    if(t==1) {
      int i;
      char c;
      cin>>i>>c;
      add(m[s[i-1]],i,-1);
      add(m[c],i,1);
      s[i-1]=c;
    } else {
      int l,r;
      cin>>l>>r;
      ll a=0;
      rep(i,26) {
	char c = 'a'+i;
	if(sum(m[c], l, r)>0) {
	  a++;
	}
      }
      cout << a << endl;
    }
  }
  return 0;
}


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

double v;
const double g = 9.8;
const double c_y = 4.9;
const int c_n = 5;
const double err = 0.0001;

double t(double v)
{
	return v / g;
}

double y(double t)
{
	return c_y * t * t;
}

int n(double y)
{
	double r = (y + c_n) / c_n;
	int r2 = (int)r;
	//if (r - r2 < err && r - r2 > -err)
	//	return r2;
	//else
		return r2 + 1;
}

int main()
{
	while (cin >> v)
	{
		cout << n(y(t(v))) << endl;
	}
	return 0;
}

Measured memory_bytes: 3052
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
using namespace std;
typedef long long ll;
ll dx[] = { 1,1,0,-1,-1,-1,0,1 };
ll dy[] = { 0,1,1,1,0,-1,-1,-1 };
ll prime(ll x) {
	ll i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}
ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}

ll MOD = 1000000007;
int main() {
	ll N;
	cin >> N;
	ll a[10000];
	ll cnt=0;
	ll sum = 0;
	for (ll i = 0; i < N; i++) {
		cin >> a[i];
    }
  	for(ll i=0; i<N; i++){
		if (a[i] == a[i + 1]) {
			++cnt;
        }
        else if(a[i]!=a[i+1]){
          sum+=(cnt+1)/2;
          cnt=0;
        }
    }
		cout << sum << endl;
}

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

bool isPrime(int n) {
  for (int i = 2; i <= std::sqrt(n); ++i) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {
  int n;
  std::cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    std::cin >> a;
    if(isPrime(a))
      ++cnt;
  }
  std::cout << cnt << std::endl;
}

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

using namespace std;

typedef long double ldb;
typedef long long ll;

const ldb PI=acos(-1.0);

int num[3005];

int main() {
  int n,L;
  scanf("%d%d",&n,&L);
  for(int i=1;i<=n;i++) scanf("%d",&num[i]);
  ldb s1=0,s2=0;
  for(int i=1;i<n;i++)
    for(int j=i+1;j<=n;j++) {
	  s1+=(n-2*(j-i))*cos(PI*(num[i]+num[j])/L);
	  s2+=(n-2*(j-i))*sin(PI*(num[i]+num[j])/L);
    }
  ll c=(ll)n*(n-1)*(n-2)/6;
  printf("%.15f %.15f\n",(double)(s1/c),(double)(s2/c));
  return 0;
}

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

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;

	int n = s.size(), m = t.size();
	vector<string> dp(m + 1, "");
	for (int i = 0; i < n; ++i) {
		vector<string> nxt(m + 1, "");
		for (int j = 0; j < m; ++j) {
			if (s[i] == t[j]) {
				nxt[j + 1] = dp[j];
				nxt[j + 1].push_back(s[i]);
			} else {
				if (dp[j + 1].size() > nxt[j].size()) {
					nxt[j + 1] = dp[j + 1];
				} else {
					nxt[j + 1] = nxt[j];
				}
			}
		}
		dp = nxt;
	}
	cout << dp[m] << endl;

	return 0;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

void solve() {
  int n, m;
  cin >> n >> m;
  vector<ii> a(n), b(m);
  for (auto &i : a) {
    cin >> i.fi >> i.sc;
  }
  for (auto &j : b) {
    cin >> j.fi >> j.sc;
  }
  auto f = [](ii a, ii b) {
    return abs(a.fi - b.fi) + abs(a.sc - b.sc);
  };
  for (auto &i : a) {
    int ans = 0;
    for (int j = 1; j < m; j++) {
      if (f(i, b[j]) < f(i, b[ans])) {
        ans = j;
      }
    }
    cout << ans + 1 << '\n';
  }
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;

typedef vector<vector<int>> Graph;

Graph G;
vector<ll> d;

void dfs(int node, int parent, ll v) {
    d[node] += v;
    for (int to: G[node]) {
        if (to == parent) continue;
        dfs(to, node, d[node]);
    }
}

void Main()
{
    ll n, Q;
    cin >> n >> Q;

    vector<ll> a(n - 1), b(n - 1);
    rep(i, n - 1) cin >> a[i] >> b[i];

    vector<ll> p(Q), x(Q);
    rep(i, Q) cin >> p[i] >> x[i];
    
    G.assign(n, vector<int>());
    d.assign(n, 0);
    rep(i, n - 1) {
        G[a[i] - 1].push_back(b[i] - 1);
        G[b[i] - 1].push_back(a[i] - 1);
    }

    rep(i, Q) {
        d[p[i]-1] += x[i];
    }

    dfs(0, -1, 0);

    rep(i, n) {
        cout << d[i] << (i == n - 1? "": " ");
    }
    cout <<endl;
}
signed main(){ Main();return 0;}

Measured memory_bytes: 31484
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int H[N];
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        H[i] = a;
    }
    bool flag = true;
    for(int i = N-1; i > 0; i--){
        if(H[i] == H[i-1]-1){
            H[i-1]--;
        }else if(H[i] < H[i-1]-1){
            cout << "No" << endl;
            flag = false;
            break;
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 640
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N;
	int[] A;

	public void solve() {
		N = nextInt();
		A = new int[N];

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

		long max = 1L;
		long ans = (A[0] - 1);//最初の要素を1にし、A[0] - 1をカウント

		for(int i = 1;i < N;i++){
			if(A[i] > max + 1){
				//A[i] - 1は1は残さないといけないため
				//1以上を残してmax+1ずつ減らしていく
				ans += (A[i] - 1) / (max + 1);
			}else if(A[i] == max + 1){
				//A[i]はmax+1で減らすと0になってしまうので、スルー
				//次の要素からはmax = A[i] + 1にしないといけない
				max++;
			}
		}
		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

Measured memory_bytes: 23356
#include<bits/stdc++.h>
#define M 1000000007

using namespace std;
typedef long long int ll;


int main()
{

 double a,b,c;
 cin>>a>>b>>c;
 ll d = min(b-1,c);
 ll ans = floor((a*d)/b) - a*(floor(d/b));
cout<<ans<<endl;
}


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

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		int N =nextInt();

		long sum=1;
		long n=1;
		while(sum<N){
			n++;
			sum=(n*(n+1)/2);
		}
		long except=sum-N;
		for(int i=1;i<=n;i++){
			if(i!=except){
				System.out.println(i);
			}
		}
	}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}

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

int main(){
    ll res = 0, N;cin >> N;
    for (ll i = 1; i <= N; i++)
    {
        if (i % 3 != 0 and i % 5 != 0)res += i;
    }
    
    cout << res << endl;
}

Measured memory_bytes: 3636
/*
No matter how long a night, dawn will always break.

Simular saying ... The darkest hour is just before the dawn.
 ***************************************   ************************8   **********************************
*/
#include <bits/stdc++.h>
using namespace std;

 
#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define sz(x)	    (int)(x).size()
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007
#define hell        998244353
#define output(x) cout << (x ? "YES" : "NO")<<endl;
 
 
 
 
 
int gcd(int a, int b) {if(a>b)swap(a,b) ;  if (a == 0)  return b; return gcd(b % a, a); }  
bool mod(double a,double b) {return a/b - floor(a/b);}
 

 
 
 
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int i,j,x,k,a,b;
   cin>>x;
   a=100;
   b=0;
   while(a<x){
   	a+=a/100;
   	b++;
   }
   cout<<b;
   
   
   
   
    return 0;
}

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

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

int main(){
  int a, b, c;cin>>a>>b>>c;
  if(a>b)swap(a, b);
  if(a>c)swap(a, c);
  if(b>c)swap(b, c);
  if((b-a)&1){
  	cout<<(b-a)/2+(c-b)+2<<endl;
  }else{
  	cout<<(b-a)/2+(c-b)<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  char c ;
  cin >> c ;
  if (c== 'a' || c== 'e' || c== 'u' || c=='i' || c=='o'){
    cout<<"vowel";
  }
  else {
    cout <<"consonant" ;
  }
    return 0;
}


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

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;

    vector<int> p(N);
    for (int i = 0; i < N; i++)
    {
        cin >> p.at(i);
    }

    vector<int> cmp_p(N);
    cmp_p = p;

    sort(cmp_p.begin(), cmp_p.end());
    int counter = 0;
    for (int i = 0; i < N; i++)
    {
        if (p.at(i) != cmp_p.at(i))
            counter++;
    }

    if (counter <= 2)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}


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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent = false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);
// lambda: [](T1 x)->T2{return y;}
// simple lambda: [](T x){return x;}

int N, M, r, q;

const int MAX_T = 1270;

void solve() {
    cin >> r;

    VVI ts(M, VI(MAX_T));

    rep(i, r) {
        int t, n, m, s;
        cin >> t >> n >> m >> s;
        --m;
        ts[m][t] += s ? 1 : -1;
    }

    rep(i, M) {
        partial_sum(ALL(ts[i]), ts[i].begin());
    }

    cin >> q;
    rep(i, q) {
        int s, e, m;
        cin >> s >> e >> m;
        --m;
        int cnt = count_if(ts[m].begin() + s, ts[m].begin() + e, [](int x){return x>0;});
        cout << cnt << endl;
    }
}

int main(void) {
    while (cin >> N >> M, N) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 51180
s = input()
N = len(s)

win = lose = 0
g = p = 0

for i in range(N):
    if s[i]=="g":
        if p < g:
            p += 1
            win += 1
        else:
            g += 1
    else: # s[i]=="p"
        if p < g:
            p += 1
        else:
            g += 1
            lose += 1
print(win-lose)


Measured memory_bytes: 3316
yyyy, mm, dd = input().split('/')
year = int(yyyy)
month = int(mm)
day = int(dd)
if year <= 2018:
  print('Heisei')
elif year == 2019:
  if month <= 3:
    print('Heisei')
  elif month == 4:
    print('Heisei')
  else:
    print('TBD')
else:
  print('TBD')

Measured memory_bytes: 3060
a = input()
b = input()
c = input()
d = input()
e = input()
k = input()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
e = int(e)
k = int(k)
if(abs(a-b)>k or abs(a-c)>k or abs(a-d)>k or abs(a-e)>k or abs(b-c)>k or abs(b-d)>k or abs(b-e)>k or abs(c-d)>k or abs(c-e)>k or abs(d-e)>k):
	print(":(")
else:
	print("Yay!")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  int N;
  scanf("%d", &N);
  
  cout << 3*N*N << endl;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
#define pb push_back
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; }

/*
 string -> int : stoi(S);
 int -> string : to_string(N);
 Sのn文字以降をm文字取り出す : S.substr(n,m)
cout << fixed << setprecision(2) << 3.14 << endl; //3.1

 int: -2,147,483,648 ～ 2,147,483,647 (2×10^9)
 ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (9×10^18)

*/

int main() {

  ll n, m, count=0, ans=0;
  string s;
 int k,a,b;
 bool aa=false;
  cin >> k>>a>>b;
  rep(i,10000){
    int l =k*(i+1);
    if(a<=l&&l<=b) aa=true;
  }

  if( aa ){ cout << "OK" << endl; }
  else { cout << "NG" << endl; }

}

Measured memory_bytes: 3596
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
good = [True] * (N+1)  # 1-indexed
H = [0] + lr()  # 1-indexed
for _ in range(M):
    a, b = lr()
    if H[a] >= H[b]:
        good[b] = False
    if H[a] <= H[b]:
        good[a] = False

answer = sum(good) - 1
print(answer)


Measured memory_bytes: 20752
from collections import Counter
    
n = int(input())
v = list(map(int, input().split()))

a = Counter(v[0::2]).most_common()
b = Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0] != b[0][0]:
    print(n - (a[0][1] + b[0][1]))
else:
    print(min(n-(a[1][1]+b[0][1]), n-(a[0][1]+b[1][1])))

Measured memory_bytes: 20572
#!/usr/bin/env python

a, b = map(int, input().split())
# print(a, b)

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# lcm(a, b) = a * b / gcd(a, b)
lcm = int(a * b / gcd(a, b))
print(lcm)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n, m;
int a[maxn];
int b[maxn];
int p[maxn];
ll cnt[maxn];
ll res[maxn];

int find(int x){
  return p[x] != x ? p[x] = find(p[x]) : p[x];
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i ++){
      p[i] = i;
      cnt[i] = 1;
    }
    for(int i = 1; i <= m; i ++)
      scanf("%d%d",&a[i],&b[i]);

    ll ans = 1ll * n * (n - 1) / 2;
    for(int i = m; i >= 1; i --){
        res[i] = ans;
        int px = find(a[i]);
        int py = find(b[i]);
        if(px != py){
          ans -= cnt[px] * cnt[py];
          cnt[py] += cnt[px];
          p[px] = py;
        }
    }
    for(int i = 1; i <= m; i ++)
      printf("%lld\n", res[i]);
    return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
int main(){
  //input
  int n;cin>>n;
  int a,b;a=n/100;b=n%100;
  //caricurate
  if((a<13)&&(b<13)&&(a!=0)&&(b!=0)){
  cout<<"AMBIGUOUS"<<endl;
  }else if((a<13)&&((12<b)||(b==0))&&(a!=0)){
    cout<<"MMYY"<<endl;
  }else if(((12<a)||(a==0))&&(b<13)&&(b!=0)){
    cout<<"YYMM"<<endl;
  }else{
    cout<<"NA"<<endl;
  }
  //output
}

Measured memory_bytes: 256
import math
#from scipy.special import comb
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

N,A,B=map(int,input().split())
v=[int(i) for i in input().split()]
v.sort(reverse=True)
v=groupby(v)

if A<=v[0][1]:
    #こっちが間違ってる
    m=min(v[0][1],B)
    co=0
    for i in range(A,m+1):
        co+=combinations_count(v[0][1],i)
    print(v[0][0])
    print(co)
else:
    al=0
    l=len(v)
    C=0
    for i in range(l):
        C+=v[i][1]
        if C<=A:
            al+=(v[i][0]*v[i][1])
        else:
            C-=v[i][1]
            al+=(v[i][0]*(A-C))
            k=combinations_count(v[i][1],A-C)
            break
    print(al/A)
    print(k)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long int
#define MOD 1000000007
#define pb push_back
using namespace std;
void solve() {
        int a[3];
        for(int i=0;i<3;i++)
                cin >> a[i];
        sort(a, a+3);
        if(a[0] == 5 && a[1] == 5 && a[2] == 7)
                cout << "YES" << endl;
        else
                cout << "NO" << endl;
        return ;
}

int32_t main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        solve();
        return 0;
}


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

typedef long long LL;

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

int main() {
    int N;
    string s;
    cin >> N;
    cin >> s;
    for(int i = 0;i < s.size();i++) {
        s[i] = (s[i] - 'A' + N)%26 + 'A';
    }
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define ll long long
#define INF (ll)(1e9)
using namespace std;

ll dp[100011];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,k,temp;
	cin>>n>>k;
	ll arr[n];
	for(ll i=0;i<n;i++)cin>>arr[i];
	for(ll i=1;i<n;i++){
		temp=INF;
		for(ll j=1;j<=k;j++){
			if(i-j<0)break;
			temp=min(temp,abs(arr[i]-arr[i-j])+dp[i-j]);
			if(i-j==0 || j==k)dp[i]=temp;
		}
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, k;
    cin >> n >> k;

    int ans = k;
    rep(i, n-1) {
        ans *= k-1;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
  "strconv"
)
func main() {
	var year,judge string
    fmt.Scan(&year)
	first, _ := strconv.Atoi(year[:2])
	latter, _ := strconv.Atoi(year[2:])

	if first >= 1 &&  first <= 12 && latter >= 1 && latter <= 12 {
		judge = "AMBIGUOUS "
	} else if (first == 00 || first >= 13 ) && (latter == 00 || latter >= 13) {
		judge = "NA"
	} else if (first >= 13 || first == 0) {
		judge = "YYMM"
	} else {
		judge = "MMYY"
	}
	fmt.Println(judge)
}

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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
int n ;
string s ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	int ans = 0 ;
	int cnt1 = 0 , cnt2 = 0 , cnt3 = 0 ;
	for(int i = 0 ; i < n ; ++i)
	{
		cin>>s ;
		for(int j = 0 ; j < s.size() - 1 ; ++j)
		{
			if(s[j] == 'A' && s[j+1] == 'B')
				ans++ ;
		}
		if(s.back() == 'A' && s[0] == 'B')
			cnt3++ ;
		else if(s[0] == 'B')
			cnt2++ ;
		else if(s.back() == 'A')
			cnt1++ ;
	}
	if(cnt3 > 0 && cnt1 == 0 && cnt2 == 0)
		cnt3-- ;
	ans += min(cnt1 , cnt2) ;
	int x = max(cnt1 , cnt2) - min(cnt1 , cnt2) ;
	ans += min(x , cnt3) ;
	cnt3 -= min(x , cnt3) ;
	return cout<<ans + cnt3<<"\n" , 0 ;
}		

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>

using namespace std;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    long n;
    cin >> n;
    int ans = 0;
    for (long a = 1; a < n; a++) {
        for (long b = 1; b < n; b++) {
            if (a * b < n) {
                ans += 1;
            } else {
                break;
            }
        }
    }
    cout << ans << endl;
}


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

int main(){
  string s;
  long long a,b;
  stack<long long> st;
  while (cin>>s){
    if(s.at(0)=='+'){
      a=st.top();st.pop();
      b=st.top();st.pop();
      st.push(a+b);
      //cout<<a+b<<endl;
    }
    else if(s.at(0)=='-'){
      a=st.top();st.pop();
      b=st.top();st.pop();
      st.push(b-a);
      //cout<<a-b<<endl;
    }
    else if(s.at(0)=='*'){
      a=st.top();st.pop();
      b=st.top();st.pop();
      st.push(a*b);
      //cout<<a*b<<endl;
    }
    else {
      int n=s.at(0)-'0';
      for(int i=1;i<s.length();i++){
        n=n*10+s.at(i)-'0';
      }
      st.push(n);
      //cout<<n<<endl;
    }
    
  }
  cout<<st.top()<<endl;
  return 0;
}


      


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

def main(X, k):
    flag = True
    for i in range(5):
        for j in range(5):
            if(abs(X[i]-X[j]>k)):
                flag = False
                break
    print("Yay!" if flag else ":(")
    

if __name__ == '__main__':
    X = []
    for i in range(5):
        X.append(int(input()))
    k = int(input())
    
    main(X, k)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main(){
  char	s[200000+1]={0};
  char	t[200000+1]={0};
  scanf("%s",s);
  scanf("%s",t);

  long	cnt=0;
  for(long i=0; i<strlen(s); i++){
    if( s[i] != t[i] ){ cnt++; }
  }
  printf("%ld", cnt);
  return 0;
}

Measured memory_bytes: 2076
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
vector< vector<ll> >dp(1e3+1,vector<ll>(4097,-1));
ll fun(ll n,ll m,vector<p>&cost,ll i,ll num,ll x)
{
    if(num==x)
    {
        return 0;
    }
    if(i==m)
    {
        return INT_MAX;
    }
    if(dp[i][num]!=-1)
    {
        return dp[i][num];
    }
    ll ans1=0,ans2=0;
    ans1=cost[i].se+fun(n,m,cost,i+1,num|cost[i].fi,x);
    ans2=fun(n,m,cost,i+1,num,x);
    return dp[i][num]=min(ans1,ans2);

}
int main()
{
fast;
ll n,m;
cin>>n>>m;
vector<p>cost;
for(ll i=0;i<m;i++)
{
    ll a,b;
    cin>>a>>b;
    vector<ll>cnt(n,0);
    for(ll j=0;j<b;j++)
    {
        ll x;
        cin>>x;
        cnt[x-1]++;
    }ll num=0;
    for(ll i=n-1;i>=0;i--)
    {

            num=num<<1;
            num+=cnt[i];

    }
    cost.pb({num,a});
}
ll x=1<<n;
x--;
ll ans=fun(n,m,cost,0,0,x);
if(ans>=INT_MAX)
{
    ans=-1;
}
cout<<ans<<endl;


return 0;
}


Measured memory_bytes: 32512
from itertools import accumulate

n = int(input())
As = list(map(int, input().split()))
As.sort()
acc = [0] + list(accumulate(As))
# print(As, acc)
"""
それまでの累積和が次のやつを食うかどうか
食えない⇨それ以前はいくら頑張ってもダメ
1 2 7 20 30 40
1 3 10 30 60 100 
"""
for i in range(1,n+1):
    if i == 0:continue
    if As[-i] > acc[-i-1]*2:
        break
print(i)


Measured memory_bytes: 20424
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll m; cin >> m;
    priority_queue <ll> as;
    REP(i, n){
        ll a; cin >> a;
        as.push(a);
    }
    REP(i, m){
        ll t = as.top();
        as.pop();
        as.push(t/2);
    }
    ll ans = 0;
    REP(i, n){
        ll t = as.top();
        as.pop();
        ans += t;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
def resolve():
    N = int(input())
    ans = 0
    for i in range(1, N+1):
        if i%3==0 and i%5==0:
            continue
        elif i%3==0:
            continue
        elif i%5==0:
            continue
        else:
            ans += i
    return print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9172
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
	int N;	cin >> N;
	long long power = 1;
	long long num = 1000000007;
	for (int i = 1; i <= N; ++i) {
		power = (power*i) % num;
	}
	cout << power << endl;
	cin >> N;
}

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

#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define fo(i,s,t) for(int i = s; i <= t; ++ i)
const int maxn = 5005;

int n, k, a[maxn];
bool f[maxn];

bool dp(int x)
{
	fo(i,1,k) f[i] = false;
	f[0] = true;
	fo(i,1,n) if(i!=x) fd(j,k,a[i]) f[j]|=f[j-a[i]];
	fo(j,max(0,k-a[x]),k-1) if(f[j]) return true;
	return false;
}

int main()
{
	scanf("%d%d",&n,&k);
	fo(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int l = 1, r = n, mid, ans = 0;
	while(l<=r)
	{
		mid = l+r >> 1;
		if(!dp(mid)) ans = mid, l = mid + 1;
		else r = mid - 1;
	}
	printf("%d",ans);
	return 0;
}

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

cnt = 0

for i in range(1, N - 1) :
    #print(p[i], max(p[i-1:i+2]), min(p[i-1:i+2]))
    if p[i] != max(p[i-1:i+2]) and p[i] != min(p[i-1:i+2]) :
        cnt += 1


print(cnt)


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

//配列の要素を順番に出力
void trace(int A[], int N) {
  for (int i = 0; i < N; i++) {
    if (i > 0) cout << " "; //隣接する要素の間に1つの空白を出力
    cout << A[i];
  }
  cout << endl;
}

//挿入ソート
void insertionSort(int A[], int N) {
  int i, j, v;
  for(i = 1; i < N; i++) {
    v = A[i];
    j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    trace(A, N);
  }
}

int main() {
  int N;
  int A[100];

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

  trace(A, N);
  insertionSort(A, N);

  return 0;
}



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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

void pl(set<int>& s, int i, int& lb){
  while(true){
	if(!s.count(i)){
	  s.insert(i);
	  break;
	}
	s.erase(i);
	--i;
  }
  if(SZ(s) == 1 && s.count(0))
	lb = 1e9+10;
  else
	while(s.count(lb)) ++lb;
}

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

  int N; cin >> N;
  int lb = 1;
  set<int> xs;
  REP(i,N){
	int x; cin >> x;
	if(x < lb-1 || (x == lb-1 && SZ(xs) != lb-1))
	  cout << "No" << endl;
	else{
	  cout << "Yes" << endl;
	  pl(xs,x,lb);
	}
  }
  
  return 0;
}

Measured memory_bytes: 14940
#include <bits/stdc++.h>
using namespace std;
int n;
int A[20];
int q;
int m;

bool rec(int i, int m, int acc){
    if(m == acc)
        return true;
    if(i == n)
        return false;
    else
        return rec(i+1, m, acc) || rec(i+1, m, acc + A[i]);
}

int main() {
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> A[i];
    cin >> q;
    while(q--){
        cin >> m;
        cout << (rec(0, m, 0) ? "yes" : "no") << endl;
    }
}

Measured memory_bytes: 3092
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    long long n,m,ans,sum,tem;
    while(~scanf("%lld%lld",&n,&m))
    {
        tem=n/m;
        sum=fabs(n-m*tem);
        ans=fabs(n-m*(tem+1));
//        printf("%lld %lld %lld\n",,tem,ans,sum);
        if(ans>sum)
            printf("%lld\n",sum);
        else
            printf("%lld\n",ans);
    }
}


Measured memory_bytes: 256
import sys

def tree_path():
    def walk(i,c):
        if d[i] == -1:
            d[i] = c
            for node, dist in path[i]:
                walk(node, c+dist)
    sys.setrecursionlimit(100007)
    n = int(input())
    path = [[] for _ in range(n+1)]
    for _ in range(n-1):
        u , v , w = map(int,input().split())
        path[u].append([v,w])
        path[v].append([u,w])
    
    d = [-1] * (n+1)
    walk(1,0)
    for item in d[1:]:
        print(item % 2)
tree_path()

Measured memory_bytes: 98172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
#define sort(v) sort(v.begin(), v.end())
#define sortr(v) sort(v.rbegin(), v.rend())
void chmin(int &a, int b) {if(a > b) a = b;}
void chmax(int &a, int b) {if(a < b) a = b;}

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};


int main(){
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i,0,n){
        string s;
        cin >> s;
        mp[s]++;
    }
    int maxim = -1;
    for(auto itr = mp.begin() ; itr != mp.end() ; itr++){
        maxim = max(itr->second, maxim);
    }
    vector<string> vs;
    for(auto itr = mp.begin() ; itr != mp.end() ; itr++){
        if(itr->second == maxim) vs.push_back(itr->first);
    }
    sort(vs);
    for(auto e : vs){
        cout << e << endl;
    }
}

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


int main(){
    int n;
    string s;
    cin >> n >> s;
  	if(n%2 != 0){
      	cout << "No" << endl;
    }
  	else{
        string a = s.substr(0,n/2);
        string b = s.substr(n/2,n/2);
        if(a == b)cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  ll A, B; cin >> A >> B;
  ll C, K; cin >> C >> K;

  if (K >= A + B) {
    ll ans = A * 1;
    ans += -1 * (K - (A+B));
    cout << ans << CRLF;
  } else if (K >= A) {
    ll ans = A * 1;
    cout << ans << CRLF;
  } else {
    ll ans = K;
    cout << ans << CRLF;
  }
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 3648
#ABC133-E Virus Tree 2
"""
問題：
n頂点の木(辺の情報が与えられる)に対して、k色で頂点を塗り分ける時、距離が2以下の頂点に対して同じ色
を塗ってはいけないという制約下で、何通りの塗り分け方が存在するか。

解法：
ある頂点xに対して、その親が既に塗られている場合、xの子の数をcとして、xの子の塗り方の総数は
(k-2)Pc
なお、木の頂点の塗り方をk通りとした場合、それ以降は子の塗り方さえ考えれば良いので、x自体の塗り方の総数は
既に考慮されている。

また、根については、根と同時にその子について一気に決定する必要があり、
根の子の個数をcとして、kP(c+1)としなけらばならない。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7

#順列modあり
def factrial_memo(n=10**5+1,mod=10**9+7): # [1,n)までの階乗と逆元の階乗
    fact = [1, 1]  # fact[n] = (n! mod mod)
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod mod)
    inv = [0, 1]  # factinv 計算用
    for i in range(2, n + 1):
        fact.append((fact[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv.append((factinv[-1] * inv[-1]) % mod)
    return fact,factinv # warning:1-indexed list

#そのまま使う
fact,factinv = factrial_memo()

def permutation(n,m,mod=10**9+7): #nPm
    return fact[n]*factinv[n-m]%mod

n,k = map(int,readline().split())

g = [[] for _ in range(n)] #隣接リスト
for i in range(n-1):
    a,b = map(int,readline().split())
    a,b = a-1,b-1
    g[a].append(b)
    g[b].append(a)

#親のノードに子を入れてくdfs
root = 0 #根
stack = [0]
parent = [0]*n
order = []
while stack:
    x = stack.pop()
    order.append(x)
    for i in g[x]:
        if i == parent[x]:
            continue
        parent[i] = x
        stack.append(i)

ans = 1

for x in order: #親
    if len(g[x]) == 1 and x != root:
        continue
    if len(g[x]) >= k: #条件を満たす彩色ができない
        print(0)
        exit()
    if x == root:
        ans *= permutation(k,len(g[x])+1)
        ans %= mod
    else:
        ans *= permutation(k-2,len(g[x])-1)
        ans %= mod

print(ans)

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

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

    for(int i = 1;i<=1009;i++)
    {
        int na = i * 8/100;
        int nb = i * 10/100;
        if(a == na && b == nb)
        {
            cout<<i<<endl;
            return 0;
        }
    }

    cout<<-1<<endl;
    return 0;

}

Measured memory_bytes: 256
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>

using namespace std;
const int64_t INF=1e10;

int main(){
	int64_t x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y<<endl;
}


Measured memory_bytes: 256