akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
//  配列の最大の大きさ
#define MAX_LENGTH  200010

typedef struct{
    int array[MAX_LENGTH];
    int first;
    int last;
}QUEUE;

void init(QUEUE*);
int enqueue(QUEUE*,int);
int dequeue(QUEUE*,int*);
struct touple { int a; int b; };
int cmp_touple(const void*n1, const void*n2);
int bisect_left(int x,struct touple a[],int left,int right);
int bisect_right(int x,struct touple a[],int left,int right);

int main(void){
    int N,M;
    scanf("%d%d", &N,&M);
    struct touple *ts = (struct touple *)malloc((M*2)*sizeof(struct touple));
    for (int i = 0; i < M; i++) {
        int x,y;
        scanf("%d%d", &x,&y);
        ts[i].a = x;ts[i].b = y;
        //逆辺も入れとく
        ts[i+M].a = y;ts[i+M].b = x;
    }
    qsort(ts,2*M,sizeof (ts), cmp_touple);
    // その部屋が指し示してる方向
    int *direction = (int *)malloc((N+1) * sizeof(int));
    memset(direction,0xFF,sizeof(int)*(N+1));
    //以下bfs やる
    //queueには処理する部屋の順(頂点)が詰まってる
    QUEUE q;
    init(&q);
    enqueue(&q,1);
    direction[1] = 0;
    while (q.first != q.last){
        //queueの頭から一個取り出す
        int v;
        dequeue(&q,&v);
        //printf("%d\n",v);
        int index1 = bisect_left(v,ts,0,(2*M)-1); //<- 引数上手く書く
        int index2 = bisect_left(v+1,ts,0,(2*M)-1); //<-引数上手く書く
        //printf("%d %d index\n",index1,index2);
        // 計算量は一番深いのがこの一個したのネストでO(Mlog(M)+N)
        for (int index = index1; index < index2; index++) {
            int nv = ts[index].b;
            // nvは新しい頂点(行ける頂点)
            if (direction[nv] != -1) continue;//到達しているのでいらん
            direction[nv] = v;//普通 direction[nv] = direction[v] + 1で距離見る
            enqueue(&q,nv);
        }
    }
    // direction をうまいこと出力
    printf("Yes\n");
    for (int i = 2; i <= N; i++) {
        printf("%d\n",direction[i]);
    }
}

int bisect_left(int x,struct touple a[],int left,int right){
    int mid; right++;
    while (left < right) {
        mid = (left + right) / 2;
        if (a[mid].a < x) {
            left = mid + 1;
        } else {
            right = mid;
        }
    }
    return left;
}


int cmp_touple(const void*n1, const void*n2){
    return ((struct touple*)n1)->a - ((struct touple*)n2)->a;
}

//  スタックの初期化
void init(QUEUE* pQueue)
{
    int i;
    for(i = 0; i < MAX_LENGTH; i++){
        pQueue->array[i] = 0;
    }
    //  最初と最後の位置を先頭に。
    pQueue->first = 0;
    pQueue->last = 0;
}
//  値のプッシュ
int enqueue(QUEUE* pQueue,int value)
{
    pQueue->array[pQueue->last] = value;          // キューに新しい値を入れる
    pQueue->last = (pQueue->last + 1) % MAX_LENGTH;   // lastの更新
    //  データを格納しきれなかった
    return 1;
}
//  値のポップ
int dequeue(QUEUE* pQueue,int* pValue)
{
    *pValue = pQueue->array[pQueue->first];           // いちばん先頭のキューを返す準備
    pQueue->first = (pQueue->first+1) % MAX_LENGTH;   // キューの先頭を次に移動する
    return 1;
}



Measured memory_bytes: 7812
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct aaa{
	ll x,y;
}a[200010];
ll n,i,sum,la,b[200010];
bool cmp(aaa a,aaa b){
	return a.x>b.x;
}
int main(){
	scanf("%lld",&n);
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i].x);
		a[i].y=i;
	}
	sort(a+1,a+n+1,cmp);
	a[n+1].x=0;
	la=a[1].y;sum=1;
	for(i=2;i<=n+1;i++){
		if(a[i].x==a[i-1].x)sum++;
		 else b[la]+=sum*(a[i-1].x-a[i].x),sum++;
		la=min(la,a[i].y);
	}
	for(i=1;i<=n;i++)printf("%lld\n",b[i]);
}

Measured memory_bytes: 4352
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdint.h>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

// index が条件を満たすかどうか
template <typename T> bool isOK(const vector<T> &a, ll index, T key) {
  // TODO
  if (a[index] > key)
    return true;
  else
    return false;
}

// 汎用的な二分探索のテンプレ
template <typename T> ll binary_search(const vector<T> &a, T key) {
  ll ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
  ll ok = (ll)a.size(); // 「index = a.size()-1」
                        // が条件を満たさないこともあるので、初期値は a.size()

  /* ok と ng のどちらが大きいかわからないことを考慮 */
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;

    if (isOK(a, mid, key)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}

void solve(long long N, std::vector<long long> A, std::vector<long long> B,
           std::vector<long long> C) {
  sort(ALL(A));
  sort(ALL(B));
  sort(ALL(C));
  vector<ll> lower_count(N);
  REP(i, B.size()) {
    ll c_index = binary_search<ll>(C, B[i]);
    lower_count[i] = C.size() - c_index;
  }
  for (ll i = B.size() - 1; i >= 1; i--) {
    lower_count[i - 1] += lower_count[i];
  }
  ll count = 0;
  REP(i, A.size()) {
    ll b_index = binary_search<ll>(B, A[i]);
    if (b_index < (ll)B.size()) {
      count += lower_count[b_index];
    }
  }
  std::cout << count << std::endl;
}

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


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

typedef long long ll;

int N;
int s[100];

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> s[i];
  }
  sort(s, s + N);
  int cum[N];
  cum[0] = s[0];
  for (int i = 1; i < N; i++) {
    cum[i] = cum[i - 1] + s[i];
  }
  int ans = cum[N - 1];
  for (int i = 0; i < N; i++) {
    if (ans % 10 == 0) {
      if (s[i] % 10 != 0) {
        cout << ans - s[i] << endl;
        ;
        return 0;
      }
    } else {
      cout << ans << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}


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

using ll = long long;
int MOD  = 1e9 + 7;

template <class T> void Add(T& a, const T& b, const T& mod = MOD) {
  auto value = ((a % mod) + (b % mod)) % mod;
  if(value < 0)
    value += mod;
  a = value;
}

int dp[10010][2][110];

int main() {
  string K;
  int D;
  cin >> K >> D;

  dp[0][0][0] = 1;

  for(int k = 0; k < K.size(); ++k) {
    for(int smaller : {0, 1}) {
      int limit = smaller ? 9 : (K[k] - '0');
      for(int i = 0; i <= limit; ++i) {
        for(int d = 0; d < D; ++d) {
          Add(dp[k + 1][smaller || (i < limit)][(d + i) % D], dp[k][smaller][d]);
        }
      }
    }
  }
  int ans = 0;
  for(int smaller : {0, 1}) {
    Add(ans, dp[K.size()][smaller][0]);
  }
  Add(ans, -1);
  cout << ans << endl;

  return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<vector<ll>> C(N,vector<ll>(N));
    for (int i=0;i<N;++i)
        for (int j=0;j<N;++j)
            cin >> C[i][j];
    ll ans=0;
    for (int i=0;i<N;++i)
        for (int j=i+1;j<N;++j)
            ans+=min(C[i][j],C[j][i]);
    cout << ans << '\n';
}


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

int main()
{
    int X, Y, N, OX = 0, OY = 0;
    cin >> X >> Y >> N;
    vector<vector<bool>> v(X, vector<bool>(Y, false));
    for (int i = 0; i < N; i++)
    {
        int x, y, a;
        cin >> x >> y >> a;
        switch (a)
        {
        case 1:
            OX = max(x, OX);
            break;

        case 2:
            X = min(x, X);
            break;

        case 3:
            OY = max(y, OY);
            break;

        case 4:
            Y = min(y, Y);
            break;
        }
    }

    int ans = 0;
    for (int i = OX; i < X; i++)
    {
        for (int j = OY; j < Y; j++)
        {

            ans++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000000;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string s, t; cin >> s >> t;
	int a, b; cin >> a >> b;
	map<string, int>mp;
	mp[s] = a;
	mp[t] = b;
	string u; cin >> u;
	mp[u]--;
	cout << mp[s] << " " << mp[t] << "\n";

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log
from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from decimal import Decimal
inf = float('inf')
MOD = 1000000007
def INT_(n): return int(n) - 1
def MI(): return map(int, input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n: int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')

n, m, q = MI()
abcd = LLIN(q)

ans = 0
num = [0 for _ in range(10)]
for i0 in range(1, m+1):
    num[0] = i0
    for i1 in range(i0, m+1):
        num[1] = i1
        for i2 in range(i1, m+1):
            num[2] = i2
            for i3 in range(i2, m+1):
                num[3] = i3
                for i4 in range(i3, m+1):
                    num[4] = i4
                    for i5 in range(i4, m+1):
                        num[5] = i5
                        for i6 in range(i5, m+1):
                            num[6] = i6
                            for i7 in range(i6, m+1):
                                num[7] = i7
                                for i8 in range(i7, m+1):
                                    num[8] = i8
                                    for i9 in range(i8, m+1):
                                        num[9] = i9
                                        tmp = 0
                                        for a,b,c,d in abcd:
                                            if num[b-1] - num[a-1] == c:
                                                tmp += d
                                        ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 78276
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N, M;
        N = in.nextInt();
        M = in.nextInt();
        int[] k = new int[M];
        int[] p = new int[M];
        ArrayList<Integer>[] s = new ArrayList[M];
        for (int i = 0; i < M; i++) {
            s[i] = new ArrayList<>();
            k[i] = in.nextInt();
            for (int j = 0; j < k[i]; j++) {
                s[i].add(in.nextInt() - 1);
            }
        }
        for (int i = 0; i < M; i++) {
            p[i] = in.nextInt();
        }
        int[] sw = new int[N];
        int ans = solve(s, sw, p, 0);
        System.out.println(ans);
    }

    static int solve(ArrayList<Integer>[] s, int[] sw, int[] p, int index) {
        //index番目までのスイッチのon/offを列挙してしらべる
        if (index >= sw.length) {//最後のスイッチまで列挙したら判定
            return isLightenAll(s, sw, p) ? 1 : 0;
        }
        int ret = 0;
        //まだ列挙し終わっていないならindex番目を列挙して次へ
        for (int i = 0; i <= 1; i++) {//off=0, on=1
            int[] nextSw = Arrays.copyOf(sw, sw.length);
            nextSw[index] = i;
            ret += solve(s, nextSw, p, index + 1);
        }
        return ret;
    }

    static boolean isLightenAll(ArrayList<Integer>[] s, int[] sw, int[] p) {
        for (int i = 0; i < s.length; i++) {
            if (!isLighten(s[i], sw, p[i])) {
                return false;
            }
        }
        return true;
    }

    static boolean isLighten(ArrayList<Integer> s, int[] sw, int p) {
        //swの
        //s.get(0) ~ s.get(s.size()-1)番目の値の和 % 2 == p
        //ならばtrue
        int sum = 0;
        for (int si : s) {
            sum += sw[si];
        }
        return sum % 2 == p;
    }
}


Measured memory_bytes: 22996
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,x;
    x=0;
    cin >> a >> b >> c;
    while (1<2)
    {
        if (c%a==0) x++;
        a++;
        if (a>b) break;}

cout << x << endl;
return 0;
}
    


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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 5e8 // cf. INT_MAX ≒ 2x10^9
#define ALL(a) a.begin(), a.end()
#define MAXEL max_element
#define MINEL min_element
#define POW (long long)pow
#define BIT(i) (long long)pow(2, i)
typedef long long Lint;
#define LINF 2e18 // cf. LLONG_MAX ≒ 9x10^18

//最大公約数:gcd(n, m)
int gcd(const long long n, const long long m) {
  long long nDivided, nDividing;
  nDivided = max(n, m);
  nDividing = min(n, m);
  while (nDivided % nDividing) {
    nDivided = nDivided % nDividing;
    swap(nDivided, nDividing);
  }
  return nDividing;
}

int main() {
  int n, x0;
  cin >> n >> x0;
  vector<int> d;
  int xPrev = x0;
  REP(i, n) {
    int x;
    cin >> x;
    d.push_back(abs(xPrev - x));
    xPrev = x;
  }

  int ans = d[0];
  for (int dist : d) {
    ans = gcd(ans, dist);
  }

  cout << ans << endl;
}


Measured memory_bytes: 892
def inpl(): return map(int, input().split())
from itertools import accumulate
from bisect import bisect, bisect_left
from collections import Counter
from functools import reduce
from itertools import accumulate
from operator import itemgetter, xor

from sys import setrecursionlimit
setrecursionlimit(10**9)
 
import sys
input = sys.stdin.readline
from collections import Counter
def inpl(): return list(map(int, input().split()))

L, R = inpl()
if R - L > 2019:
    print(0)

else:
    ans = 2019
    for l in range(L, R+1):
        for r in range(l+1, R+1):
            ans = min(ans, l*r%2019)
    print(ans)

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

int main(){
    int n;
    cin >> n;
    vector<int> v;
    v.push_back(0);
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        v.push_back(a);
    }
    v.push_back(0);
    int sum = 0;
    for(int i=0; i<=n; i++){
        sum += abs(v[i+1] - v[i]);
    }
    
    for(int i=1; i<=n; i++){
        int df = abs(v[i] - v[i-1]) + abs(v[i+1] - v[i]) - abs(v[i+1] - v[i-1]);
        cout << sum - df << endl;
    }
    return 0;
}

Measured memory_bytes: 1784
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
inf = 10 **9 + 5
def main():
    s = str(input())
    s = s[::-1]
    dp1 = [inf] *(10 ** 6 +3)
    dp2 = [inf] *(10 ** 6 +3)
    dp1[0] = int(s[0])
    dp2[0] =  10 -int(s[0])
    for i in range(1,len(s)):
        dp1[i] = min(dp2[i-1] + int(s[i]) + 1,dp1[i-1] + int(s[i]))
        dp2[i] = min(dp2[i-1] + 9 - int(s[i]),dp1[i-1] + 10 - int(s[i]))
    print(min(dp1[len(s)-1],dp2[len(s)-1] + 1))

main()


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

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Solver solver = new Solver();
		solver.solve(1, in, out);
		out.close();
	}
}



class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
 
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }
 
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
 
    public int nextInt() {
        return Integer.parseInt(next());
    }
 
}


class Solver{
	public void solve(int testNumber, InputReader in, PrintWriter out){
		int N = in.nextInt();
		int K = in.nextInt();
		int arr [] = new int [N];
		for(int i =0 ; i < N; i++){
			arr[i] = in.nextInt();
		}

		int dp [] = new int [N];
		Arrays.fill(dp,Integer.MAX_VALUE);

		dp[0] = 0;

		for(int i = 1; i < N; i++){
				for(int j=1; j <= K && j <= i; j++ ){
					dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(arr[i] - arr[i-j]));
				}
		} 


		out.println(dp[N-1]);

	}
}

Measured memory_bytes: 33452
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int arr[26]={0};
	for(int i=0;i<s.length();i++)
	{
		arr[s[i]-'a']++;
	}
	char c='/';
	for(int j=0;j<26;j++)
	{
		if(arr[j]==0)
		{
			c=(char)(j+97);
			break;
		}
	}
	if(c!='/')
	cout<<c<<"\n";
	else
	cout<<"None"<<"\n";
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(void){
    int a,b,c = 0;
    cin >> a >> b >> c;
    if(b-a < 2 * c){
        for (size_t x = a; x <= b; x++)
        {
            cout << x << endl;
        }
        
    }else
    {
        for (int i = a; i < a+c; i++)
        {
            cout << i << endl;
        }
        for (int q = b-c+1; q <= b; q++)
        {
            cout << q << endl;
        }
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e-a > k){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
object Main extends App {
	val Array(x, y) = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	val a1 = Set(1,3,5,7,8,10,12)
	val a2 = Set(4,6,9,11)
	val a3 = Set(2)

	if(a1.contains(x) && a1.contains(y)){
		println("Yes")
	}else if(a2.contains(x) && a2.contains(y)){
		println("Yes")
	}else if(a3.contains(x) && a3.contains(y)){
		println("Yes")
	}else{
		println("No")
	}


} 


Measured memory_bytes: 27320
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	val, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return val
}

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()
	M := nextInt()
	K := nextInt()
	ar := make([]int, N)
	for i := 0; i < N; i++ {
		ar[i] = nextInt()
	}
	br := make([]int, M)
	for i := 0; i < M; i++ {
		br[i] = nextInt()
	}
	A := new(ar)
	B := new(br)
	ans := 0
	prev := N
	for i := 0; i <= M; i++ {
		tb := B.read(i)
		buf := 0
		for j := prev; j >= 0; j-- {
			ta := A.read(j)
			if tb+ta <= K {
				buf = i + j
				prev = j
				break
			}
		}
		if buf > ans {
			ans = buf
		}
	}
	fmt.Println(ans)
}

func new(a []int) *table {
	return &table{
		arr: a,
		m:   map[int]int{},
	}
}

type table struct {
	arr []int
	m   map[int]int
}

func (t *table) read(n int) int {
	if val, ok := t.m[n]; ok {
		return val
	}
	if val, ok := t.m[n-1]; ok {
		t.m[n] = val + t.arr[n-1]
		return t.m[n]
	}
	if val, ok := t.m[n+1]; ok {
		t.m[n] = val - t.arr[n]
		return t.m[n]
	}
	var val int
	for i := 0; i < n; i++ {
		val += t.arr[i]
	}
	t.m[n] = val
	return val
}


Measured memory_bytes: 26884
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int dy8[] = {0,1,1,1,0,-1,-1,-1};
int dx8[] = {1,1,0,-1,-1,-1,0,1};

/*==================================================*/
/*variable*/
set<int> g[3] = {{1,3,5,7,8,10,12}, {4,6,9,11}, {2}};
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    int x, y;
    cin>>x>>y;
    REP(i,0,3){
        if(g[i].find(x) != g[i].end() && g[i].find(y) != g[i].end()){
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    cout<<"No"<<endl;

    return 0;
}


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

int main()
{
  int X,A,B,C ;
  cin>>A>>B>>C>>X ;
  int count=0 ;
  int max=X/50 ;
  for(int i=0;i<=max&&i<=A;i++){
    for(int j=0;j<=max&&j<=B;j++){
      for(int k=0;k<=max&&k<=C;k++){
        if(500*i+100*j+50*k==X) count++ ;
      }
    }
  }
  
  cout<<count<<endl ;
  
  return 0 ;
}








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

vector<ll> v;

int main(){
  ll n,k;
  cin >> n >> k;
  
  for(int i=0; i<k; i++){
    ll a; cin >> a;
    v.push_back(a);
  }
  
  ll p = 1;
  ll ans;
  
  for(ll i=n; i<100000; i++){
    ll tmp = i;
    int flag = 1;
    while(tmp > 0){
      if(find(v.begin(), v.end(), tmp % 10) == v.end())
        tmp /= 10;
      else{
        flag = 0;
        break;
      }
    }
    if(flag == 1){
      cout << i << endl;
      return 0;
    }
  }
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int &x : arr)
        cin >> x;
    map<vector<int>, int> mmap;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            for (int k = j + 1; k < n; k++)
            {
                if (arr[i] == arr[j] || arr[i] == arr[k] || arr[j] == arr[k])
                    continue;
                vector<int> tmp{arr[i], arr[j], arr[k]};
                sort(tmp.begin(), tmp.end());
                if (tmp[0] + tmp[1] > tmp[2])
                    mmap[tmp]++;
            }
        }
    }
    int sum = 0;
    for (auto pp : mmap)
        sum += pp.second;
    cout << sum << "\n";

    return 0;
}

Measured memory_bytes: 21236
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
const int INF = 1001001001;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> p(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
	}
	int ans = 0;
	int i, j;
	int  small = INF;
	for (i = 1; i <= n; i++) {
		small = min(small, p[i]);
			if (p[i] == small) ans++ ;
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 1024
n = int(input())
k = int(input())

dp = [[[0]*(2) for i in range(k+1)] for j in range(len(str(n))+1)]

dp[0][0][0] = 1

for i in range(len(str(n))):
    for j in range(k+1):
        for m in range(2):
            nd = int(str(n)[i])
            for l in range(10):
                ni = i+1
                nj = j
                nm = m
                if l != 0:
                    nj += 1
                if nj > k:
                    continue
                if nm == 0:
                    if  l > nd:
                        continue
                    elif l < nd:
                        nm = 1
                dp[ni][nj][nm] += dp[i][j][m]
print(dp[len(str(n))][k][0]+dp[len(str(n))][k][1])

Measured memory_bytes: 3064
import sys
from math import ceil

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    
    ans = [0] * (N + 1)
    for x in range(1, ceil(N ** 0.5) + 1):
        for y in range(1, ceil(N ** 0.5) + 1):
            for z in range(1, ceil(N ** 0.5) + 1):
                n = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
                if n <= N:
                    ans[n] += 1
    print(*ans[1:], sep='\n')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 92164
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc  = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();

        System.out.println((A+B)%2 == 0 ? (A+B)/2 : "IMPOSSIBLE");
    }
}


Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	char c;
	string ans = "";

	for (int i = 0; i < 9; i++)
	{
		cin >> c;
		if (i == 0 || i == 4 || i == 8) {
			ans += c;
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

const int MAX=100;

class edge
{
public:
	int src,tar,w;
	edge(int src=0,int tar=0,int w=0):src(src),tar(tar),w(w){}
};

int n;
vector<edge> G[MAX];

int cost;
vector<edge> GG[MAX];//reverse edge
int num[MAX],pre[MAX],mcost[MAX];//number, prev of vertex, edges min cost
bool mark[MAX];//vertex used flag
vector<int> comp[MAX];//compressed vertex
vector<int> nex[MAX];//next of vertex

void cycle(int v,int s,int r,bool &found)
{
	if(mark[v])
	{
		int temp[MAX];
		for(int i=0;i<n;i++)temp[i]=num[i];
		found=true;
		do
		{
			cost+=mcost[v];
			v=pre[v];
			if(v!=s)
			{
				while(!comp[v].empty())
				{
					num[comp[v].back()]=s;
					comp[s].push_back(comp[v].back());
					comp[v].pop_back();
				}
			}
		}while(v!=s);
		
		for(int i=0;i<comp[s].size();i++)
		{
			int j=comp[s][i];
			if(j!=r)
			{
				for(int k=0;k<GG[j].size();k++)
				{
					if(num[GG[j][k].src]!=s)
					{
						GG[j][k].w-=mcost[temp[j]];
					}
				}
			}
		}
	}
	
	mark[v]=true;
	for(int k=0;k<nex[v].size();k++)
	{
		int i=nex[v][k];
		if(num[i]!=num[v]&&pre[num[i]]==v)
		{
			if(!mark[num[i]]||i==s)
			{
				cycle(i,s,r,found);
			}
		}
	}
	return;
}

int mincosttree(int r)
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<G[i].size();j++)
		{
			GG[G[i][j].tar].push_back(G[i][j]);
		}
	}
	
	for(int i=0;i<n;i++)
	{
		num[i]=i;
		comp[i].push_back(i);
	}
	cost=0;
	
	while(1)
	{
		for(int i=0;i<n;i++)
		{
			pre[i]=-1;
			mcost[i]=1<<28;
		}
		
		for(int j=0;j<n;j++)
		{
			if(j==r)continue;
			for(int k=0;k<GG[j].size();k++)
			{
				int i=GG[j][k].src;
				if(num[i]!=num[j])
				{
					if(GG[j][k].w<mcost[num[j]])
					{
						mcost[num[j]]=GG[j][k].w;
						pre[num[j]]=num[i];
					}
				}
			}
		}
		
		for(int i=0;i<n;i++)
		{
			if(pre[i]>=0)
			{
				nex[pre[i]].push_back(i);
			}
		}
		
		bool stop=true;
		for(int i=0;i<n;i++)mark[i]=false;
		
		for(int i=0;i<n;i++)
		{
			if(i==r||mark[i]||comp[i].empty())continue;
			bool found=false;
			cycle(i,i,r,found);
			if(found)stop=false;
		}
		if(stop)
		{
			for(int i=0;i<n;i++)
			{
				if(pre[i]>=0)
				{
					cost+=mcost[i];
				}
			}
			return cost;
		}
	}
}

int main()
{
	int e,r;cin>>n>>e>>r;
	int s,t,w;
	for(int i=0;i<e;i++)
	{
		cin>>s>>t>>w;
		G[s].push_back(edge(s,t,w));
	}
	cout<<mincosttree(r)<<endl;
	return 0;
}

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

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

if (d<=(t*s))
{
	cout<<"Yes"<<endl;
	return 0;
}
cout<<"No"<<endl;
return 0;





}

Measured memory_bytes: 3624
N, Y = map(int, input().split())
a = 10000
b = 5000
c = 1000
for i in range(N+1):
    for j in range(N-i+1):
        k = N-i-j
        if a*i+b*j+c*k==Y:
            print(i, j, k)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#define MAXVALUE 10000
#define rep(i,a) for(i=0;i<a;i++)
using namespace std;

void CountingSort(vector<int> &A, vector<int> &B, int k){
    int i,j;
    vector<int> C(k+1,0);

    for(j=0; j<A.size(); j++) {
        C[A[j]]++;
    }
    for(i=1; i<=k; i++) {
        C[i] = C[i] + C[i-1];
    }
    for(j=A.size()-1; j>=0; j--){
        B[C[A[j]]-1] = A[j];
        C[A[j]]--;
    }
}

int main(void) {
    vector<int> A;
    vector<int> B;
    int i,n,num;

    cin >> n;
    for(i = 0; i < n; i++) {
        cin >> num;
        A.push_back(num);
    }
    B.resize(n);
    CountingSort(A,B,*max_element(A.begin(),A.end()));

    rep(i,n){
        cout << B[i];
	if(i != n-1) {
	  cout << " ";
	} else {
	  continue;
	}
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 16884
def dist(p, X, Y):
    s = 0
    for x, y in zip(X, Y):
        s += abs(x - y)**p
    return s**(1/p)
N = int(input())
*X, = map(int, input().split())
*Y, = map(int, input().split())
print(dist(1, X, Y))
print(dist(2, X, Y))
print(dist(3, X, Y))
print(max(abs(x - y) for x, y in zip(X, Y)))



Measured memory_bytes: 5648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ff(i, c, n) for (ll i = c; i < n; i++)
#define fr(i, c, n) for (ll i = c; i >= n; --i)
#define INF 1e9 + 7

ll modpow(ll a, ll b, ll c)
{ //a^b%c in O(logb)
	ll res = 1;
	while (b > 0)
	{
		if (b & 1)
		{
			res = (res * a) % c;
		}
		a = (a * a) % c;
		b >>= 1;
	}
	return res;
}
ll modinv(ll m, ll n)
{ //modular inverse of n w.r.t m provided 1<=n<=(m-1) in O(logn) and m is prime
	ll inv[n + 1];
	inv[1] = 1;
	for (int i = 2; i < n + 1; ++i)
		inv[i] = (m - (m / i) * inv[m % i] % m) % m;
	return inv[n];
}

//a+b=a^b+2*(a&b)
int main()
{
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll h, w, a, b;
	cin >> h >> w >> a >> b;
	ff(i,0,h){
		if(i<b){
			ff(j,0,w){
				if(j<a) cout<<'1';
				else cout<<'0';
			}
		}
		else{
			ff(j,0,w){
				if(j<a) cout<<'0';
				else cout<<'1';
			}
		}
		cout<<endl;
	}
	


	return 0;
}


Measured memory_bytes: 1280
import numpy as np

H, N = map(int, input().split())
AB = np.array([list(map(int, input().split())) for i in range(N)])
A = AB[:, 0]
B = AB[:, 1]

# インデックスはライフ 値はそれを以下にする最小MP
dp = np.array([0]*(H+1))
# dp = np.array([0 for i in range(H+1)])

for i in range(1, H+1):
    dp[i] = min(dp[np.maximum(i - A, 0)] + B)

print(dp[-1])

Measured memory_bytes: 14688
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scanf("%d %d", &h, &w)
	if h == 1 || w == 1 {
		fmt.Println(1)
		return
	}
	sq := h * w
	if sq%2 == 1 {
		sq = sq/2 + 1
	} else {
		sq /= 2
	}
	fmt.Println(sq)
}


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

typedef long long int ll;
ll GCD(ll x,ll y){if(x%y==0)return y;else return GCD(y,x%y);}
ll LCM(ll x,ll y){return x*y/GCD(x,y);}

int main(){
	ll A;
	cin>>A;
	cout<<LCM(A,360)/A;
	return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<cmath>
#define Point Vector
using namespace std;
class Vector
{
public:
	double x;
	double y;
	Vector(double x = 0, double y = 0) :x(x), y(y) {}
	Vector operator +(Vector &p)
	{
		return Vector(x + p.x, y + p.y);
	}
	Vector operator -(Vector &p)
	{
		return Vector(x - p.x, y - p.y);
	}
	Vector operator *(double k)
	{
		return Vector(k*x, k*y);
	}
	double abs(Vector &p)
	{
		return sqrt(p.x*p.x + p.y*p.y);
	}
	double dot(Vector &p1, Vector &p2)
	{
		return p1.x*p2.x + p1.y*p2.y;
	}
	Point projection(Point p1, Point p2)
	{
		Vector p1p(x - p1.x, y - p1.y);
		Vector p1p2(p2.x - p1.x, p2.y - p1.y);
		double pj = dot(p1p, p1p2) / abs(p1p2);
		Vector p1x = p1p2 * (pj / abs(p1p2));
		Point x = p1x + p1;
		return x;
	}
	Point reflection(Point &p1, Point &p2)
	{
		Point x = this->projection(p1, p2);
		return (x - *this) * 2 + *this;
	}
};
int main()
{
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	Point p1(x1, y1);
	Point p2(x2, y2);
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		double x, y;
		cin >> x >> y;
		Point p(x, y);
		Point res = p.reflection(p1, p2);
		printf("%.10f %.10f\n", res.x, res.y);
	}
}


Measured memory_bytes: 3256
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
class Dice {
	private final int N = 6;
	private final int X = 4;
	int surface[] = new int[6];
	int recover[] = new int[6];
	int axis_north[] = {0,1,5,4};
	int axis_east[] = {0,3,5,2};
	int axis_right[] = {1,2,4,3};
	int count;

	Dice() {
		count = 1;
		surface[0] = 1; // ???
		surface[1] = 2; // ??????
		surface[2] = 3; // ???
		surface[3] = 4; // ???
		surface[4] = 5; // ?\\
		surface[5] = 6; // ???
		UpdateRecoverVal();
	}

	public void OpNorth() {
		for (int i=0;i<X;i++) {
			surface[axis_north[i]] = recover[axis_north[(i+1)%X]];
		}
		UpdateRecoverVal();
		count += surface[0];
	}

	public void OpSouth() {
		for (int i=0;i<X;i++) {
			surface[axis_north[i]] = recover[axis_north[(i-1+X)%X]];
		}
		UpdateRecoverVal();
		count += surface[0];
	}

	public void OpEast() {
		for (int i=0;i<X;i++) {
			surface[axis_east[i]] = recover[axis_east[(i+1)%X]];
		}
		UpdateRecoverVal();
		count += surface[0];
	}

	public void OpWest() {
		for (int i=0;i<X;i++) {
			surface[axis_east[i]] = recover[axis_east[(i-1+X)%X]];
		}
		UpdateRecoverVal();
		count += surface[0];
	}

	public void OpRight() {
		for (int i=0;i<X;i++) {
			surface[axis_right[i]] = recover[axis_right[(i+1)%X]];
		}
		UpdateRecoverVal();
		count += surface[0];
	}

	public void OpLeft() {
		for (int i=0;i<X;i++) {
			surface[axis_right[i]] = recover[axis_right[(i-1+X)%X]];
		}
		UpdateRecoverVal();
		count += surface[0];
	}

	private void UpdateRecoverVal() {
		for (int i=0;i<N;i++) {
			recover[i] = surface[i];
		}
	}

	public void printCount() {
		System.out.println(this.count);
	}
}

class Main {
    public static void main(String args[]) {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
 
        try {
            String buf = null;
            int n;
            while (!(buf = br.readLine()).equals("0")) {
				Dice d = new Dice();
                n = Integer.parseInt(buf);
				for (int i=0;i<n;i++) {
					String rot = br.readLine();
					if (rot.equals("North")) {
						d.OpNorth();
					} else if (rot.equals("South")) {
						d.OpSouth();
					} else if (rot.equals("West")) {
						d.OpWest();
					} else if (rot.equals("East")) {
						d.OpEast();
					} else if (rot.equals("Left")) {
						d.OpLeft();
					} else if (rot.equals("Right")) {
						d.OpRight();
					}
				}
				d.printCount();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

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

int main() {
    string S, T; cin >> S >> T;
    int ss = S.size();
    int tt = T.size();
    int ans = 1005;
    for (int i = 0; i <= ss-tt; i++){
        int now = 0;
        for (int j = 0; j < tt; j++){
            if(S[i+j] != T[j])now++;
        }
        ans = min(ans, now);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
x = int(input())

if 400<=x<600:
    print(8)
    
if 600<=x<800:
    print(7)
    
if 800<=x<1000:
    print(6)
    
if 1000<=x<1200:
    print(5)
    
if 1200<=x<1400:
    print(4)
    
if 1400<=x<1600:
    print(3)
    
if 1600<=x<1800:
    print(2)
    
if 1800<=x<2000:
    print(1)


Measured memory_bytes: 61840
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String[] s=new String[n];
		for(int i=0; i<n; i++){
			s[i]=sc.next();
		}
		Arrays.sort(s);
		ArrayList<State> c=new ArrayList<>();
		int count=1;
		for(int i=1; i<n; i++){
			if(!s[i-1].equals(s[i])){
				c.add(new State(s[i-1],count));
				count=1;
			}else{
				count++;
			}
		}
		c.add(new State(s[n-1],count));
		Collections.sort(c,(x,y)->(y.count-x.count));
			for(int i=0; i<c.size(); i++){
				System.out.println(c.get(i).s);
				if(!(i!=(c.size()-1) && c.get(i).count==c.get(i+1).count)){
					break;
				}
			}
	}
	static class State{
		String s;
		int count;
		State(String s,int count){
			this.s=s;
			this.count=count;
		}
	}
}


Measured memory_bytes: 84272
import java.io.*;
import java.util.*;
public class Main
{
    static String str;
    static long[][][] dp;
    static int mod = 1000000007;
    static int d;
    public static long solve(int pos, int sum, int tight){
        if(pos == str.length()){
            if(sum%d == 0)
                return 1;
            return 0;
        }
        if(dp[pos][sum][tight] != -1){
            return dp[pos][sum][tight];
        }
        long ans = 0;
        int len = 9;
        if(tight == 1){
            len = str.charAt(pos)-'0';
        }
        for(int i = 0; i <= len; i++){
            int newt = 0;
            if(tight == 1 && i == len){
                newt = 1;
            }
            ans += solve(pos+1, (sum + i)%d, newt)%mod;
        }
        return dp[pos][sum][tight] = ans%mod;
    }
	public static void main(String[] args) throws Exception{
		FastReader s = new FastReader();
		StringBuilder sb = new StringBuilder("");
	    str = s.nextLine();
	    d = s.nextInt();
	    dp = new long[str.length()+1][d+1][2];
	    for(int i = 0; i < dp.length; i++){
	        for(int j = 0; j < dp[i].length; j++){
	            Arrays.fill(dp[i][j], -1);
	        }
	    }
	    long ans = (solve(0, 0, 1)-1+mod)%mod;
	    sb.append(ans + "\n");
		System.out.print(sb);
	}
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}




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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n;
    cin >> n;
    map<string, priority_queue<Int, vector<Int>, greater<Int>>> mp;
    for (Int i = 0; i < n; i++) {
        string s;
        Int x;
        cin >> s >> x;
        mp[s].push(x);
    }
    Int m;
    cin >> m;
    vector<string> s(m);
    for (Int i = 0; i < m; i++) {
        cin >> s[i];
    }
    Int cur = 0;
    for (Int i = 0; i < m; i++) {
        while (not mp[s[i]].empty() and cur >= mp[s[i]].top()) {
            mp[s[i]].pop();
        }
        if (mp[s[i]].empty()) {
            print("No");
            return 0;
        } else {
            cur = mp[s[i]].top();
            mp[s[i]].pop();
        }
    }
    print("Yes");
    return 0;
}



Measured memory_bytes: 30416
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(),K = sc.nextInt(); 
		long[][] NK = new long[N][6]; 
		int[] dp = new int[N]; 
		for(int i = 0; i < N; i++) dp[i] = 0;
		for(int i = 0; i < K; i++){
			int scan = sc.nextInt();
			dp[scan-1] = sc.nextInt();
		} 
		for(int i = 0; i < N; i++){
			if(dp[i] == 1){
				if(i == 0)NK[i][1] = 1;
				else{
					NK[i][0] += NK[i-1][1];
					NK[i][1] += NK[i-1][2] + NK[i-1][3] + NK[i-1][4] + NK[i-1][5];
				}
			}
			else if(dp[i] == 2){
				if(i == 0)NK[i][3] = 1;
				else{
					NK[i][2] += NK[i-1][3];
					NK[i][3] += NK[i-1][0] + NK[i-1][1] + NK[i-1][4] + NK[i-1][5];
				}
			}
			else if(dp[i] == 3){
				if(i == 0)NK[i][5] = 1;
				else{
					NK[i][4] += NK[i-1][5];
					NK[i][5] += NK[i-1][0] + NK[i-1][1] + NK[i-1][2] + NK[i-1][3];
				}
			}
			else{
				if(i == 0){
					NK[i][1] = 1;NK[i][3] = 1;NK[i][5] = 1;
				}
				else{
					if(NK[i-1][1] > 0){
						NK[i][0] += NK[i-1][1] % 10000;
						NK[i][3] += NK[i-1][0] + NK[i-1][1] % 10000;
						NK[i][5] += NK[i-1][0] + NK[i-1][1] % 10000;
					}else{
						NK[i][3] += NK[i-1][0] + NK[i-1][1] % 10000;
						NK[i][5] += NK[i-1][0] + NK[i-1][1] % 10000;
					}
					if(NK[i-1][3] > 0){
						NK[i][1] += NK[i-1][2] + NK[i-1][3] % 10000;
						NK[i][2] += NK[i-1][3] % 10000;
						NK[i][5] += NK[i-1][2] + NK[i-1][3] % 10000;
					}else{
						NK[i][1] += NK[i-1][2] + NK[i-1][3] % 10000;
						NK[i][5] += NK[i-1][2] + NK[i-1][3] % 10000;
					}
					if(NK[i-1][5] > 0){
						NK[i][1] += NK[i-1][4] + NK[i-1][5] % 10000;
						NK[i][3] += NK[i-1][4] + NK[i-1][5] % 10000;
						NK[i][4] += NK[i-1][5] % 10000;
					}else{
						NK[i][1] += NK[i-1][4] + NK[i-1][5] % 10000;
						NK[i][3] += NK[i-1][4] + NK[i-1][5] % 10000;
					}
				}
			}
		}
		int total = 0;
		for(int j = 0; j < 6; j++){
			total += NK[N-1][j]; 
		}
		System.out.println(total % 10000);
	}

}

Measured memory_bytes: 19636
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};

int N,M;
vector<int>v[200010];
vector<int>sec;



signed main(){
  cin>>N>>M;
  for(int t=1;t<=M;t++){
    int a,b;cin>>a>>b;
    v[a].push_back(b);
    if(a==1)sec.push_back(b);
  }

  for(auto itr=sec.begin();itr!=sec.end();itr++){
    for(auto x:v[*itr]){
      if(x==N){
        cout<<"POSSIBLE"<<"\n";
        return 0;
      }
    }
  }

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


Measured memory_bytes: 9576
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>

using namespace std;

int main(){
    int w,n;
    cin >> w >> n;
    int a[w],b[2][n];
    for(int i=1;i<=w;i++){
        a[i-1]=i;
    }
    char x[n];
    for(int i=0;i<n;i++){
        cin >> b[0][i] >>x[n] >> b[1][i];
        swap(a[b[0][i]-1],a[b[1][i]-1]);
    }
    for(int i=1;i<=w;i++){
        cout << a[i-1]<< endl;
    }
}


Measured memory_bytes: 2964
mod = 10**9+7
N = int(input())
a = list(map(int, input().split()))
sum_a = 0
sum_a2 = 0
for x in a:
  sum_a += x
  sum_a2 += x**2

ans = ((sum_a**2 - sum_a2))//2
print(ans%mod)


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

using namespace std;
#define ll long long
ll num[100005];
ll sum;
int main()
{
    int n;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        ll t;
        scanf("%lld",&t);
        num[t]++;
        sum+=t;
    }
    int o;
    cin >> o;
    for(int i=0;i<o;i++)
    {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        sum-=num[a]*a;
        sum+=num[a]*b;
        num[b]+=num[a];
        num[a]=0;
        printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 4596
# coding: utf-8

def partition(A, p, r):
    r = r - 1
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    # A = list(map(str, A))
    # A[i + 1], A[r] = '[{}]'.format(A[r]), A[i + 1]
    A[i+1], A[r] = A[r], A[i+1]
    return i+1

if __name__ == "__main__":
    # n = 12
    # A = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11]

    n = int(input())
    A = list(map(int, input().split()))
    
    q = partition(A, 0, len(A))
    A = list(map(str, A))
    A[q] = '[{}]'.format(A[q])
    print(' '.join(A)) 



Measured memory_bytes: 16392
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|e| e.parse().unwrap());
    let n: usize = itr.next().unwrap();
    let m: usize = itr.next().unwrap();

    s.clear();
    stdin().read_line(&mut s).ok();
    let h: Vec<usize> = s
        .split_whitespace()
        .map(|e| e.parse::<usize>().unwrap())
        .collect();
    s.clear();
    let mut edge: Vec<Vec<usize>> = vec![vec![]; 100009];

    for _ in 0..m {
        s.clear();
        stdin().read_line(&mut s).ok();
        let mut itr = s.split_whitespace().map(|e| e.parse::<usize>().unwrap());
        let a = itr.next().unwrap();
        let b = itr.next().unwrap();
        edge[a].push(b);
        edge[b].push(a);
    }

    let mut ans = 0;

    'outer: for i in 1..=n {
        let now = h[i - 1];
        for &e in &edge[i] {
            if now <= h[e - 1] {
                continue 'outer;
            }
        }

        ans += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 9444
numberOfQuery=int(input())
count=0
listForStock=[]
listForPrint=[]

def popBack():
    lastIndex=len(listForStock)-1
    del listForStock[lastIndex]

def pushBack(x):
    listForStock.append(x)

def randomAccess(p):
    listForPrint.append(listForStock[p])

#-----------------main--------------------
while count<numberOfQuery:
    query=input()
    if query=="2":
        popBack()
    else:
        querys=query.split()
        if querys[0]=="0":
            pushBack(int(querys[1]))
        elif querys[0]=="1":
            randomAccess(int(querys[1]))
        else:
            print("入力が不正です")
            break
    count+=1

for chip in listForPrint:
    print(chip)
#-----------------main--------------------


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

int main() {
    int n;
    cin >> n;
    vector<P> jobs(n);
    rep(i,n) {
        cin >> jobs.at(i).second >> jobs.at(i).first;
    }
    sort(jobs.begin(), jobs.end());
    ll time = 0;
    rep(i,n) {
        time += jobs.at(i).second;
        if (jobs.at(i).first < time) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 4724
a=range(int(input())+1)
b=range(int(input())+1)
c=range(int(input())+1)
x=int(input())
res=0
import itertools
p=itertools.product(a,b,c)
for i in p:
    ans =500*i[0]+100*i[1]+50*i[2]
    if ans==x:res+=1
print(res)

Measured memory_bytes: 9032