akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

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

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

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,x,y;
	map<ll,ll> m;
	cin >> n >> x >> y;
	for(ll i=1;i<n;i++){
		for(ll j=i+1;j<=n;j++){
			ll dis=min(j-i,abs(x-i)+abs(y-j)+1);
			m[dis]++;
		}
	}
	for(ll i=1;i<n;i++) cout << m[i] << endl;
	return 0;
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	max1, max2 := 0, 0
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		if a[i] > max1 {
			max1, max2 = a[i], max1
			continue
		}
		if a[i] > max2 {
			max2 = a[i]
		}
	}

	for _, v := range a {
		if v == max1 {
			fmt.Println(max2)
			continue
		}
		fmt.Println(max1)
	}
}


Measured memory_bytes: 8244
def test():
    n,m,x,y = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    flag = 0
    for i in range(x+1,y+1):
        c = i
        if all(k<c for k in a) and all(c<=m for m in b):
            flag = 1
            break

    if flag == 0:
        print("War")
    elif flag == 1:
        print("No War")


if __name__ == "__main__":
    test()


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

int main() {
  int s, i, j, ans = 0;
  cin >> s;
  vector<int> a(1000000);
  a.at(0) = s;
  
  for(i = 0; i < 1000000; i++){
    if(ans != 0) break;
    if(a.at(i) % 2 == 0) a.at(i + 1) = a.at(i) / 2;
    else a.at(i + 1) = 3 * a.at(i) + 1;

    if(i != 0){
      for(j = 0; j < i + 1; j++){
        if(a.at(i + 1) == a.at(j)) {
          ans = i + 2;
          break;
        }
      }
    }
    
  }
  cout << ans << endl;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> >v(100001);
 long long dp[100005];
 long long dfs(int node)
 {
     int i;
     long long x=0,c;
     for(i=0;i<v[node].size();i++)
     {
         if(dp[v[node][i]]!=-1)
         {
             x=max(x,1+dp[v[node][i]]);
         }
         else
         {
             c=1+dfs(v[node][i]);
             x=max(x,c);
         }
     }
     dp[node]=x;
     return dp[node];
 }
 int main()
 {
     int a,b,n,m,i;
     long long c=0;
     cin>>n>>m;
     memset(dp,-1,sizeof(dp));
     while(m--)
     {
         cin>>a>>b;
         v[a].push_back(b);
     }
     for(i=1;i<=n;i++)
     {
         c=max(c,dfs(i));
     }
     cout<<c;
     return 0;
 }

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int a, b;
  cin >> a >> b;
  cout << (b % a != 0 ? b - a : a + b) << endl;
}


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

int main(){
    int A,B,C,D;

    cin >> A >> B >> C >> D;

    while(true){
        C -= B;
        if(C<=0){
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if(A<=0){
            cout << "No" << endl;
            break;
        }
    }

    return 0;
}

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

int n;
long long int a, b, x[101010];

int main(){
  cin >> n >> a >> b;
  rep(i, n){
    cin >> x[i];
  }
  long long int res = 0;
  rep(i, n - 1){
    res += min(a* (x[i + 1] - x[i]), b);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	int x = sc.nextInt();
      	int t = sc.nextInt();
      	int time;
      	if(n%x==0) time = (n/x)*t;
      	else time = ((n/x)+1)*t;
      	System.out.println(time);
    }
}

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4.0;
// const int MOD = 998244353;
const ll LINF = 9e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

ll N, K;

const ll NMAX = 1e6;
ll fac[NMAX + 1], inv[NMAX + 1], finv[NMAX + 1];

void cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    FOR(i, 2, NMAX + 1) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll comb(ll n, ll k) {
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main() {
    cin >> N >> K;
    cominit();
    ll ans = 0;
    FOR(i, 1, K + 1) {
        ll tmp = 0;
        tmp = comb(N - K + 1, i);
        (tmp *= comb(K - 1, K - i)) %= MOD;
        cout << tmp << "\n";
    }
}


Measured memory_bytes: 23808
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>
#include <regex>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define P pair<int, int>

using namespace std;
//using ll = long long;
using ll = int64_t;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

double divide(double x, double y){
    double A, B[2], C[2];

    A = round(x/3)*y;
    x = x - round(x/3);
    double divH = round(x/2);
    double divW = round(y/2);
    B[0] = divH * y;
    C[0] = (x-divH) * y;
    B[1] = divW * x;
    C[1] = (y-divW) * x;
    int temp1, temp2;
    temp1 = max(max(A, B[0]), C[0]) - min(min(A, B[0]), C[0]);
    temp2 = max(max(A, B[1]), C[1]) - min(min(A, B[1]), C[1]);

    return min(temp1, temp2);
}

void solve(){
    int h, w;
    cin >> h >> w;
    int temp1 = divide(h, w);
    int temp2 = divide(w, h);
    cout << min(temp1, temp2) << endl;
}

int main(){
    solve();
    return 0;
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void answer1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void answer2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void answer3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void answer(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i, j;
  //ll n;
  //cin >> n;
  ll a, b, c;
  cin >> a >> b >> c;
  //string s; cin >> s;
  ll result = 0;
  bool judge = true;
  if((c-b)%2==0)
  cout<<"Alice"<<endl;
  else
  {
      cout<<"Borys"<<endl;
  }
  

  /*
  vector<ll> a(n);
  for(i = 0; i < n; i++)
    cin >> a[i];
  //for(i = 0; i < n; i++)
  */

  return 0;
}

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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Question();
			Instance.Exec();
		}
	}

	public class Question
	{
		void NonGoto(int n)
		{
			int i = 1;
			do {
				int x = i;
				if (i % 3 == 0) {
					Console.Write($" {i}");
				} else {
					do {
						if (x % 10 == 3) {
							Console.Write($" {i}");
							break;
						} else {
							x /= 10;
						}

					} while (x != 0) ;
				}

				++i;
			} while (i <= n);

			Console.WriteLine("");
		}

		public void Exec()
		{
			int n = int.Parse(Console.ReadLine());
			NonGoto(n);

			Console.ReadKey();
		}
	}
}


Measured memory_bytes: 17984
#include <stdio.h>
#include <algorithm>

int L, A, B, C, D;

int main(void) {
	scanf("%d%d%d%d%d", &L, &A, &B, &C, &D);

	if (A%C == 0) { A /= C; }
	else { A = A / C + 1; }
	if (B%D == 0) { B /= D; }
	else { B = B / D + 1; }

	printf("%d\n", L - std::max(A, B));
	return 0;
}

Measured memory_bytes: 2760
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
typedef pair<int, int> P;
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    P p[100010];
    rep(i, N) {
        cin >> p[i].first >> p[i].second;
    }
    sort(p, p + N);
    rep(i, N) {
        K -= p[i].second;
        if(K <= 0) {
            cout << p[i].first << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 4424
#include<cstdio>
#include<algorithm>
using namespace std;
#define INF 2000000000
#define MAXN 1000000
int a[MAXN],sum[MAXN],n,k;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		sum[i]=a[i]-a[1];
	int ans=INF;
	for(int i=1;i<=n-k+1;i++)
	{
		int tmp=sum[i+k-1]-sum[i];
		if(a[i]<0)
		{
			int k1=abs(a[i]),k2=abs(a[i+k-1]);
			tmp+=min(k1,k2);
		}
		else tmp+=a[i];
		ans=min(ans,tmp);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
const int INF=2E9;
typedef pair<int,int> Pair;

int main(){
    int N,C;
    int D[34][34]={};
    int c[520][520]={};
    int s[34][3]={0};
    cin >> N >> C;
    for(int i=0;i<C;i++){
        for(int j=0;j<C;j++){
            cin >> D[i][j];
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin >> c[i][j];
        }
    }
    for(int k=0;k<C;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                s[k][(i+j)%3]+=D[c[i][j]-1][k];
            }
        }
    }

    int ans=INF;
    for(int i=0;i<C;i++){
        for(int j=0;j<C;j++){
            for(int k=0;k<C;k++){
                if(i!=j && j!=k && k!=i){
                    ans=min(ans,s[i][0]+s[j][1]+s[k][2]);
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1280
def need(a):
    if a=="a":
        return 0
    else:
        return 123-ord(a)

s=list(input())
x=int(input())
i=0
while x>0:
    count=need(s[i])
    if x>=count:
        s[i]="a"
        x-=count
    
    if i==len(s)-1:
        s[i]=chr(ord(s[i])+(x%26))
        x=0
    i+=1
print("".join(s))

Measured memory_bytes: 4156
#include <cstdio>
#include <queue>

const int N = 500000 + 10;

int n, m;

struct Point {
  double x, y;
  explicit Point(double _x = 0., double _y = 0.): x(_x), y(_y) {}
};

inline Point operator+ (const Point &lhs, const Point &rhs) {
  return Point(lhs.x + rhs.x, lhs.y + rhs.y);
}

inline Point operator- (const Point &lhs, const Point &rhs) {
  return Point(lhs.x - rhs.x, lhs.y - rhs.y);
}

std::deque<Point> q;

int main() {
  scanf("%d%d", &n, &m);
  Point sum(0, 0);
  for (int i = n; i--;) {
    int t, v;
    scanf("%d%d", &t, &v);
    Point p(v, (double)t * v);
    sum = sum + p;
    while (!q.empty()) {
      if (sum.x <= m) break;
      Point cur = q.back();
      q.pop_back();
      sum = sum - cur;
      if (sum.x - cur.x >= m) continue;
      Point temp(m - sum.x, cur.y / cur.x * (m - sum.x));
      q.push_back(temp);
      sum = sum + temp;
      break;
    }
    for (; !q.empty() && q.front().y / q.front().x >= p.y / p.x; q.pop_front()) p = p + q.front();
    q.push_front(p);
    printf("%.12f\n", sum.y / sum.x);
  }
  return 0;
}


Measured memory_bytes: 19604
a=int(input())
x=[input()]
flag=0
for i in range(1,a):
    s=input()
    if s in x or x[i-1][len(x[i-1])-1]!=s[0] :
        x.append("1")
        flag=1
    else:
        x.append(s)
if flag == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int n, k, sum[216000];
Int a[216000], alt[216000];
Int q, x;

Int solve(Int x){
  if(abs(x - a[n-1]) < abs(x - a[n-2]))return alt[n-1];
  Int k = lower_bound(a, a+n, x) - a;
  if(k > 0 && abs(x-a[k]) >= abs(x-a[k-1]))k--;
  Int bottom = k, top = n-1;
  while(top - bottom > 1){
    Int mid = (top + bottom) / 2;
    Int d = n - mid - 1;
    Int l = mid-d;
    if(l < 0 || abs(x-a[l]) > abs(x-a[mid]))bottom = mid;
    else top = mid;
  }
  Int d = n - bottom-1;
  Int l = bottom - d;
  Int res = sum[n-1] - sum[bottom];
  //  cout << bottom << endl;
  if(l >= 0)res += alt[l];
  return res;
}

int main(){
  cin >> n;
  cin >> q;
  for(Int i = 0;i < n;i++)cin >> a[i];
  sum[0] = a[0];
  alt[0] = a[0];
  if(n >= 2)alt[1] = a[1];
  for(Int i = 1;i < n;i++){
    if(i > 0)sum[i] = sum[i-1] + a[i];
    if(i > 1)alt[i] = alt[i-2] + a[i];
  }
  for(Int i = 0;i < q;i++){
    cin >> x;
    cout << solve(x) << endl;
  }
  return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
  int N, A, B;
  cin >> N >> A >> B;
  int num = A + B;
  int count = 0;
  int forgni = 1;
  rep(i, N)
  {
    char c;
    cin >> c;
    if (c == 'a')
    {
      if (count < A + B)
      {
        cout << "Yes" << endl;
        count++;
      }
      else
      {
        cout << "No" << endl;
      }
    }
    else if (c == 'b')
    {
      if (count < A + B)
      {
        if (forgni <= B)
        {
          cout << "Yes" << endl;
          forgni++;
          count++;
        }
        else
        {
          cout << "No" << endl;
        }
      }
      else
      {
        cout << "No" << endl;
      }
    }
    else if (c == 'c')
    {
      cout << "No" << endl;
    }
  }
}

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

const int N = 1e5 + 5;
const long long maxV = 1e18;

int n;
long long a[N] = {1};

int main() {
	std::cin >> n;
	for(int i = 1; i <= n; ++i) std::cin >> a[i];
	std::sort(a + 1, a + n + 1);
	if(a[1] == 0) {
		puts("0");
		return 0;
	}
	long long res = 1LL;
	for(int i = 1; i <= n; ++i) {
		if(res > maxV / a[i]) {
			puts("-1");
			return 0;
		}
		res *= a[i];
		if(res > maxV) {
			puts("-1");
			return 0;
		}
	}
	std::cout << res;
	return 0;
}

Measured memory_bytes: 4420
from collections import Counter
N=int(input())
A=list(map(int, input().split()))
C=Counter(A)
# print(C)
ans=0
for k in C:
    n=C.get(k)
    ans+=n*(n-1)//2
# print(ans)

for i in range(N):
    k=A[i]
    n=C.get(k)
    print(ans-n+1)

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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var N = int.Parse(input[0]);
        var M = int.Parse(input[1]);

        var dict = new Dictionary<int, List<int>>();
        for(var i = 1; i < N + 1; i++)
        {
            dict.Add(i, new List<int>());
        }

        for(var i = 0; i < M; i++)
        {
            var input2 = Console.ReadLine().Split(' ');
            var A = int.Parse(input2[0]);
            var B = int.Parse(input2[1]);

            dict[A].Add(B);
            dict[B].Add(A);
        }

        var visited = new bool[N];
        var mark = new int[N];
        var count = new int[N];
        for (var i = 0; i < N; i++)
        {
            visited[i] = false;
            count[i] = int.MaxValue;
        }

        var list = new List<int>();
        visited[0] = true;
        count[0] = 0;
        var cnt = 0;
        var visitedCount = 1;
        foreach(var road in dict[1])
        {
            mark[road - 1] = 1;
            if(visited[road - 1] == false)
            {
                visitedCount += 1;
            }
            visited[road - 1] = true;
            count[road - 1] = 1;
            foreach(var r in dict[road])
            {
                list.Add(r);

            }
        }


        while (true)
        {
            var minRoad = 0;
            var minNum = int.MaxValue;

            if (visited[list[cnt] - 1] != true)
            {
                foreach (var n in dict[list[cnt]])
                {


                    if (visited[n - 1] == true)
                    {
                        if (count[n - 1] < minNum)
                        {
                            minRoad = n;
                            minNum = count[n - 1] + 1 ;
                        }
                    }
                }

                mark[list[cnt] - 1] = minRoad;
                count[list[cnt] - 1] = minNum;
                visited[list[cnt] - 1] = true;
                visitedCount += 1;
                foreach(var l in dict[list[cnt]])
                {
                    list.Add(l);

                }
            }
            cnt++;
            var flag = true;
            if(visitedCount == N)
            {
                break;
            }
        }

        Console.WriteLine("Yes");
        var roadN = 0;
        foreach(var room in mark)
        {
            if(roadN != 0)
            {
                Console.WriteLine(room);
            }
            roadN++;
        }

        Console.Read();
    }


}



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

int N, M;
int WA[105000];
bool AC[105000];

void solve() {
    cin >> N >> M;
    int WAnum = 0;
    int ACnum = 0;
    for(int i = 1; i <= N; i++) {
        WA[i] = 0;
        AC[i] = false;
    }
    while(M--) {
        int p;
        string S;
        cin >> p >> S;
        // if(AC[p]) continue;
        if(S == "AC" && AC[p] == false) {
            AC[p] = true;
            ACnum++;
            WAnum += WA[p];
        } else if(S == "WA" && AC[p] == false) {
            WA[p]++;
        }
    }
    cout << ACnum << " " << WAnum << endl;
    return;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 768
n = int(input())
nums = [int(input()) for i in range(n)]

minNum = nums[0]
maxDiff = False
for i in nums[1:]:
    diff = i - minNum
    if maxDiff == False or diff > maxDiff:
        maxDiff = diff
    if minNum > i:
        minNum = i

print(maxDiff)

Measured memory_bytes: 17012
n,c,k=gets.split.map &:to_i
a=[]
n.times{
	a << gets.to_i
}
a.sort!
bus = 1
cnt = 1
f = 0
a.map{|x|
	f = x if f == 0
	if x - f <= k
		if cnt < c
			cnt += 1
		else
			bus += 1
			cnt = 1
			f = x
		end
	else
		bus += 1
		cnt = 1
		f = x
	end
	
}
p c == 1 ? n : bus

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e6+3; // prime number
ll getPow(ll a,ll p){
  ll ret = 1,cp = a;
  while(p){
    if(p&1) ret = (ret*cp)%MOD;
    p >>= 1;
    cp = (cp*cp)%MOD;
  }
  return ret;
}
ll getInverse(ll a){
  return getPow(a,MOD-2)%MOD;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  vector<ll> inv(MOD,1),fact(MOD,1);
  for(ll i = 2; i < MOD; ++i){
    inv[i] = getInverse(i);
    fact[i] = (i*fact[i-1])%MOD;
  }
  ll q,x,d,n;
  cin >> q;
  while(q--){
    cin >> x >> d >> n;
    if(d == 0) cout << getPow(x,n);
    else if(x == 0) cout << 0;
    else{
      ll X = (x*inv[d])%MOD;
      if(X+n-1 >= MOD) cout << 0;
      else{
        ll ret = (fact[X+n-1]*inv[fact[X-1]])%MOD;
        cout << (ret*getPow(d,n))%MOD;
      }
    }
    cout << '\n';
  }
  return 0;
}

Measured memory_bytes: 16512
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int a, b;
int main()
{
	cin >> a >> b;
	if((a + b) % 2 == 0){
		cout << (a + b) / 2;
	}else{
		cout << "IMPOSSIBLE";
	}
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            List<int> lstInp = new List<int>();            
            for (int i = 0; i < 6; i++)
            {
                string sS = System.Console.ReadLine().Trim();
                lstInp.Add(int.Parse(sS));
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "Yay!";
            if (lstInp[4] - lstInp[0] > lstInp[5]) { sOut = ":("; }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


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

string S;


int solve(){
  int s_count = 0;
  int n_count = 0;
  int e_count = 0;
  int w_count = 0;
  int len = S.length();
  for(int i = 0; i < len; i++){
    if(S[i] == 'S') s_count++;
    else if(S[i] == 'N') n_count++;
    else if(S[i] == 'E') e_count++;
    else w_count++;
  }
  if(n_count > 0 and s_count == 0) return false;
  if(s_count > 0 and n_count == 0) return false;
  if(e_count > 0 and w_count == 0) return false;
  if(w_count > 0 and e_count == 0) return false;
  return true;
}


int main(){
  cin >> S;
  int ans = solve();
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

long lcs(string x, string y) {
    long m = x.size();
    long n = y.size();
    x = ' ' + x;
    y = ' ' + y;
    long dp[m + 1][n + 1];
    for (long i = 0; i <= m; i++) {
        dp[i][0] = 0;
    }
    for (long i = 0; i <= n; i++) {
        dp[0][i] = 0;
    }

    long lcs_max = 0;
    for (long i = 1; i <= m; i++) {
        for (long j = 1; j <= n; j++) {
            if (x[i] == y[j]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
            lcs_max = max(lcs_max, dp[i][j]);
        }
    }
    return lcs_max;
}

int main() {
    long q;
    string x, y;
    cin >> q;
    for (long i = 0; i < q; i++) {
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }
    return 0;
}



Measured memory_bytes: 11040
import numpy as np

N, K = map(int, input().split())
H = np.array(list(map(int, input().split())) + [0] * (K + 2), dtype = np.int64) 

INF = 10 ** 9
cost = np.array([INF] * (N + K + 2), dtype = np.int64)
cost[0] = 0
for i in range(N):
    cost[i + 1: i + K + 1] = np.minimum(cost[i + 1: i + K + 1], cost[i] + abs(H[i + 1: i + K + 1] - H[i]))


# print (cost)
print (cost[N - 1])

Measured memory_bytes: 22756
package main

import (
	"fmt"
)

func main() {
	var N, T, c, t int
	fmt.Scan(&N, &T)
	mc := 9999
	for i := 0; i < N; i++ {
		fmt.Scan(&c, &t)
		if t <= T && c < mc {
			mc = c
		}
	}
	if mc == 9999 {
		fmt.Println("TLE")
	} else {
		fmt.Println(mc)
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long A, long long B, long long C){
  if (A == B && A == C) {
    std::cout << "No" << std::endl;
  } else if (A == B || B == C || A == C) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
}

int main(){
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  long long C;
  scanf("%lld",&C);
  solve(A, B, C);
  return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >>n;
  string s;
  cin >> s;
  int r=0,b=0;
  for(int i=0;i<n;i++){
    if(s[i]=='R')r++;
    else b++;
  }
  if(r>b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
n, m = gets.chomp.split(" ").map(&:to_i)
a = Array.new(n, Array.new(3))
for i in 0..(n-1) do
  a[i] = gets.chomp.split(" ").map(&:to_i)
end
b = Array.new(8) { Array.new(n) }
for i in 0..(n-1) do
  b[0][i] = a[i][0] + a[i][1] + a[i][2]
  b[1][i] = a[i][0] + a[i][1] - a[i][2]
  b[2][i] = a[i][0] - a[i][1] + a[i][2]
  b[3][i] = a[i][0] - a[i][1] - a[i][2]
  b[4][i] = - a[i][0] + a[i][1] + a[i][2]
  b[5][i] = - a[i][0] + a[i][1] - a[i][2]
  b[6][i] = - a[i][0] - a[i][1] + a[i][2]
  b[7][i] = - a[i][0] - a[i][1] - a[i][2]
end

for i in 0..7 do
  b[i] = b[i].sort{|a, b| b <=> a }
end

c = Array.new(8, 0)
for i in 0..7 do
  for j in 0..(m-1) do
    c[i] += b[i][j]
  end
end

p c.max


Measured memory_bytes: 2044
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int p, q, r;
  cin >> p >> q >> r;

  cout << p + q + r - max({p, q, r}) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#include<cmath>
using namespace std;
 
int32_t main(){
  int a,b,n;
  cin>>a>>b>>n;
   int x=min(b-1,n);
   int r=((a*x)/b);
    cout<<r<<endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int n; cin >> n;
    ll a[3001];
    ll sum = 0;
    rep(i, n){
        cin >> a[i];
        sum += a[i];
    }
    ll ans = sum - n;
    cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        int a = (4 * x - y) / 2;
        int b = (y - 2 * x) / 2;
        if (a >= 0 && b >= 0 && a + b == x) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    string ans="NO";
    
    rep(i,n)
        if(b-a<=d*i-c*(n-1-i)&&c*i-d*(n-1-i)<=b-a)ans="YES";
     cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        String s = sc.next();
        
        int happy = 0;
        int lr = 0;
        int rl = 0;
        for(int i = 0; i < n-1; i++){
            if(s.charAt(i) == 'L'){
                if(s.charAt(i+1) == 'R'){
                    lr++;
                }else{
                    happy++;
                }
            }else{
                if(s.charAt(i+1) == 'L'){
                    rl++;
                }else{
                    happy++;
                }
            }
        }
        
        happy += Math.min(k, Math.min(lr, rl)) *2;
        if(k > Math.min(lr, rl)){
            happy += Math.min(k - Math.min(lr, rl), Math.abs(lr - rl));
        }
        System.out.println(happy);
    }
}

Measured memory_bytes: 24868
N,n=map(int,input().split())
L=[]
for i in range(N):
    a=list(input())
    L.append(a)

l=[]
for i in range(n):
    a=list(input())
    l.append(a)
#print(L)
#print(l)

for H in range(N-n+1):
    for W in range(N-n+1):
        F=0
        if F!=1:
            for h in range(n):
                if F!=1:
                    for w in range(n):
                        if L[h+H][w+W]!=l[h][w]:
                            F=1
        if F==0:
            print("Yes")
            #print(H,W)
            exit()
print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <stack>
#include <typeinfo>
#include <string>
using namespace std;

int main(){
    stack<int> st;
    int temp1,temp2 = 0;
    string Buf;
    
    while(cin >> Buf){
        if(Buf == "+"){
            temp1 = st.top();
            st.pop();
            temp2 = st.top();
            st.pop();
            st.push(temp1 + temp2);
        }else if(Buf == "-"){
            temp2 = st.top();
            st.pop();
            temp1 = st.top();
            st.pop();
            st.push(temp1 - temp2);
        }else if(Buf == "*"){
            temp1 = st.top();
            st.pop();
            temp2 = st.top();
            st.pop();
            st.push(temp1 * temp2);
        }else{
            st.push(stoi(Buf));
        }
    }
    
    cout << st.top() << endl;
    
    return 0;
}

Measured memory_bytes: 3144
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

int main() {
    ll N;
    cin >> N;
    vector<ll> cnt(3);
    for (ll i = 0; i < N; i++) {
        ll ai;
        cin >> ai;
        cnt[ai-1]++;
    }
    auto dp = make_vec_nd((double)0.0, N+1, N+1, N+1);
    for (ll three_cnt = 0; three_cnt <= N; three_cnt++) {
        for (ll two_cnt = 0; two_cnt <= N; two_cnt++) {
            for (ll one_cnt = 0; one_cnt <= N; one_cnt++) {
                ll zero_cnt = N - one_cnt - two_cnt - three_cnt;
                if (zero_cnt < 0) {
                    continue;
                } else if (zero_cnt == N) {
                    continue;
                }
                if (one_cnt > 0) {
                    dp[one_cnt][two_cnt][three_cnt] += one_cnt / (double)N * (dp[one_cnt-1][two_cnt][three_cnt] + 1);
                }
                if (two_cnt > 0) {
                    dp[one_cnt][two_cnt][three_cnt] += two_cnt / (double)N * (dp[one_cnt+1][two_cnt-1][three_cnt] + 1);
                }
                if (three_cnt > 0) {
                    dp[one_cnt][two_cnt][three_cnt] += three_cnt / (double)N * (dp[one_cnt][two_cnt+1][three_cnt-1] + 1);
                }
                dp[one_cnt][two_cnt][three_cnt] += zero_cnt / (double)N;
                dp[one_cnt][two_cnt][three_cnt] /= (1.0 - zero_cnt / (double)N);
            }
        }
    }
    cout << fixed << setprecision(10) << dp[cnt[0]][cnt[1]][cnt[2]] << endl;
}



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

int main(){
    int n, a, b;
    cin >> n;
    if(n == 1)  cout << "Hello World" << endl;
    if(n==2){
        cin >> a >> b;
        cout << a+b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin >> n;
	int a[n]; rep(i,n) cin >> a[i];
	int r[3] = {};
	int64_t ans = 1;
	for(int i = 0; i < n; ++i) {
		int64_t cnt = 0;
		for(int j = 0; j < 3; ++j) {
			if(r[j] == a[i]) {
				if(cnt == 0) r[j]++;
				cnt++;
			}
		}
		ans *= cnt;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){
  
  int n;
  cin >> n;
  
  int v[n];
  REP(i,n){
    cin >> v[i];
  }
  
  sort(v,v+n);
  
  cout << v[n-1] - v[0] << endl;



 return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

int main(){
    fastIO;
    int n;
    cin >> n;
    vector<int> t;
    int a;
    for(int i = 0 ; i < n; i ++ ){
        cin >> a;
        -- a;
        t.push_back(a);
    }
    vector<int> res;
    int mx = 0;
    for(int i = 0 ; i < n ; i ++ ){
        mx = -1;
        for(int i = 0 ; i < t.size(); i ++ ){
            if(t[i] == i){
                mx = max(mx, t[i]);
            }
        }
        if(mx == -1){
            cout << -1;
            exit(0);
        }
        res.push_back(mx);
        t.erase(t.begin() + mx);
    }
    reverse(res.begin(), res.end());
    for(auto x : res)
        cout << x + 1<< "\n";
    return 0;
}

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

using namespace std;

int main(){
    int N;
    int A[100000];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    sort(A, A+N);
    if(N%2 == 0){
        long sum1 = 0, sum2 = 0;
        for(int i = 0; i < N/2; i++){
            sum1 += A[i];
            sum2 += A[N-1-i];
        }
        cout << 2*(sum2-sum1) + A[N/2-1] - A[N/2] << endl;
    }else{
        long sum1 = 0, sum2 = 0;
        for(int i = 0; i < (N-1)/2; i++){
            sum1 += A[i];
            sum2 += A[N-1-i];
        }
        cout << 2*(sum2 - sum1) + max(A[(N-1)/2] - A[(N+1)/2], -A[(N-1)/2] + A[(N-3)/2]) << endl;;
    }
}

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

const ll mod = ll(1e9) + 7;
const int INF = 1<<29;
const ll lINF = 1l<<40;

int main(){
    int n;
    cin >> n;
    int a = 0,b = 0,c = 0;
    rep(i,n){
        int t,x,y;
        cin >> t >> x >> y;
        if ((x-b)+(y-c)<=(t-a) && ((t-a)-(x-b)+(y-c))%2==0) continue;
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

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

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

  set<int> s;
  rep(i, n) {
    int a;
    cin >> a;
    s.insert(a);
  }

  if (s.size() == n)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<cstring>

#define ll long long
#define ull unsigned long long
#define ld long double
#define fo2(i,start,end,diff) for(int i=start;i<end;i=i+diff)
#define fo(i,start,end) for(int i=start;start<end?i<end:i>end;start<end?i+=1:i-=1)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define vll vector<ll>
#define vc vector<char>
#define pll pair<ll,ll>
#define vop vector<pll>
#define vov vector<vector<ll>>
using namespace std;
const ld pi=3.14159265358979323;

const long long mod1=1e9+7;
const long long mod2=1e18;
const ll mod3=9e18;
const ll N=1e7;

long long power(ll  x, ll n){if(n==0)return 1;ll temp=power(x,n/2);if(n%2==0)return temp*temp;else return x*temp*temp;}

ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return (a*b)/(gcd(a,b));}
void swap(int* a, int* b){int t = *a;*a = *b;*b = t;}
bool f(ll x,ll y){return x>y;}
bool cmp(ll x ,ll y){
    return abs(x)<abs(y);
}
ll MAX(ll a,ll b){return a>b?a:b;}
ll MIN(ll x,ll  y){return x>y?y:x;}

ll ow(ll a, ll b, ll mod)//a^b%mod
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b/=2;
        a=(a*a)%mod;
    }
    return ans;
}
ll sum(vll v){
    ll sm=0;
    fo(i,0,v.size())sm=sm+v[i];
    return sm;
}
int main(){
    ll x1,x2,x3,x4,x5;
    cin>>x1>>x2>>x3>>x4>>x5;
    if(x1==0)cout<<"1"<<endl;
    else if(x2==0)cout<<"2"<<endl;
    else if(x3==0)cout<<"3"<<endl;
    else if(x4==0)cout<<"4"<<endl;
    else if(x5==0)cout<<"5"<<endl;
    return 0;
}

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

class Cube{
    public:
    int f[6];
    Cube(){}
    void roll_z(){ roll(1, 2, 3, 4);}
    void roll_y(){ roll(0, 2, 5, 3);}
    void roll_x(){ roll(0, 1, 5, 4);}
    void roll(int i, int j, int k, int l){
        int t=f[i]; f[i]=f[j]; f[j]=f[k]; f[k]=f[l]; f[l]=t; 
    }
    void move(char ch){
        if(ch=='E') for(int i=0;i<3;i++) roll_y();
        if(ch=='W') roll_y();
        if(ch=='N') roll_x();
        if(ch=='S') for(int i=0;i<3;i++) roll_x();
    }
};

int main(){
    Cube c;
    string com;
    int i;

    for(i=0;i<6;i++) cin>>c.f[i];
    cin>>com;

    for(i=0;i<com.size();i++) c.move(com[i]);

    cout<<c.f[0]<<endl;

    return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
using namespace std;

const int MAXN = 501;

char A[5][MAXN];
int pos;
string line;

vector<char> exp();
vector<char> fact();

vector<char> exp() {
  vector<char> res = fact();
  while(1) {
    if(line[pos] == 'u') {
      ++pos;
      vector<char> x = fact();
      for(int i = 0; i< x.size(); ++i) {
	res[i] = (res[i] || x[i]);
      }
    } else if(line[pos] == 'i') {
      ++pos;
      vector<char> x = fact();
      for(int i = 0; i< x.size(); ++i) {
	res[i] = (res[i] && x[i]);
      }
    } else if(line[pos] == 'd') {
      ++pos;
      vector<char> x = fact();
      for(int i = 0; i< x.size(); ++i) {
	res[i] = (res[i] && !x[i]);
      }
    } else if(line[pos] == 's') {
      ++pos;
      vector<char> x = fact();
      for(int i = 0; i< x.size(); ++i) {
	res[i] = ((res[i] && !x[i]) || (x[i] && !res[i]));
      }
    } else {
      break;
    }
  }
  return res;
}

vector<char> fact() {
  vector<char> res;
  if(line[pos] == 'c') {
    ++pos;
    res = fact();
    for(int i = 0; i < res.size(); ++i) {
      res[i] = 1-res[i];
    }
  } else if(isupper(line[pos])) {
    char c = line[pos];
    ++pos;
    res = vector<char>(A[c-'A'], A[c-'A']+MAXN);
  } else if(line[pos] == '(') {
    ++pos;
    res = exp();
    ++pos;
  }
  return res;
}

map<int,int> id, rid;
int getId(int n) {
  if(!id.count(n)) {
    id[n] = id.size()-1;
    rid[id[n]] = n;
  }
  return id[n];
}

int main() {
  while(1) {
    bool run = true;
    fill(A[0], A[5], false);
    id.clear();
    rid.clear();
    while(1) {
      char c;
      int n;
      if(!(cin >> c >> n)) {
	run = false;
	break;
      }
      if(c == 'R' && n == 0) break;
      for(int i = 0; i < n; ++i) {
	int a;
	cin >> a;
	a = getId(a);
	A[c-'A'][a] = true;
      }
    }
    if(!run) break;
    string s;
    cin >> s;
    line = s;
    pos = 0;
    vector<char> res = exp();
    vector<int> ans;
    for(int i = 0, cnt = 0; i < res.size(); ++i) {
      if(rid.count(i) && res[i]) {
	ans.push_back(rid[i]);
      }
    }
    sort(ans.begin(), ans.end());
    if(ans.size() == 0) {
      cout << "NULL" << endl;
    } else {
      for(int i = 0; i < ans.size(); ++i) {
	if(i) cout << " ";
	cout << ans[i];
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    ll n, k;
    cin >> n >> k;
    vector<int> G(n);
    rep(i, n){
        int a;
        cin >> a;
        G[i] = a-1;
    }

    vector<int> dist(n, INF);
    dist[0] = 0;
    int now = 0;
    int v, x, y;
    rep(i, n){
        if(dist[G[now]] != INF){
            v = G[now];
            x = dist[G[now]];
            y = dist[now]+1 - x;
            break;
        }
        dist[G[now]] = dist[now]+1;
        now = G[now];
    }

    if(k <= x){
        now = 0;
        rep(i, k) now = G[now];
    }
    else{
        now = v;
        rep(i, (k-x)%y) now = G[now];
    }

    cout << now+1 << endl;
}

Measured memory_bytes: 4848