akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std ;
int main () {
    int n,t,cost[1010],time_i[1010];
    int hoge = 10000;
    cin >> n >> t;
    
    for(int i = 0; i < n; i++)
    {
        cin >> cost[i];
        cin >> time_i[i];
    }
    
    for(int i = 0; i < n; i++)
    {
        
        if (time_i[i] <= t) {
            if(hoge >= cost[i])hoge = cost[i];
        }
        
    }
    
    if (hoge == 10000) {
        cout << "TLE" << endl;
    }else{
        cout << hoge << endl;
    }
    
    
} 

Measured memory_bytes: 256
/*input
15
13 76 46 15 50 98 93 77 31 43 84 90 6 24 14

*/
#include <bits/stdc++.h>

using namespace std;

inline int f(int x, int m) {
  return x / m;
}

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

  int cnt = 0;
  int n; cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x; cin >> x;
    cnt += (x & 1) & (i & 1);
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
/*
int func(long long A, long long B){
    int N_A = to_string(A).length();
    int N_B = to_string(B).length();

    return max(N_A, N_B);
}*/

int digit_count(long long N){
    int digit = 0;
    while (N > 0)
    {
        N /= 10;
        digit++;
    }
    return digit;
}

int main(){
    long long N;
    cin >> N;
    int num = digit_count(N);
    
    for (long long i = 1LL; i * i <= N; i++)
    {   
        if (N % i != 0) continue;
        long long j = N / i;
        int f = max(digit_count(i), digit_count(j));
        //cout << f << endl;
        num = min(num, f);
    }

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

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

#define MAX_N 30
#define MAX_M 30

int main() {
  int n, m, k[MAX_N], a[MAX_N][MAX_M];

  std::cin >> n >> m;
  for(int i = 0; i < n; ++i) {
    std::cin >> k[i];
    for(int j = 0; j < k[i]; ++j) {
      std::cin >> a[i][j];
    }
  }

  int ans = 0;
  for(int j = 0; j < m; ++j) {
    int count = 0;
    for(int i = 0; i < n; ++i) {
      for(int h = 0; h < k[i]; ++h) {
        if(a[i][h] == j + 1) count++;
      }
    if(count == n) ans++;
    }
  }

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

Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WORNINGS
#include<iostream>
#include<string>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<map>
#include<stdio.h>


#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZ(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define REV(x) reverse((x).begin(),(x).end())
#define endl  ("\n")
#define ll long long

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

const  double PI = 3.142857142857;
struct point{
	ll PP, PPP;
};

using namespace std;
ll arr[1000000];
int main()
{
	FAST

		int n;
	cin >> n;
	if (n == 25)cout << "Christmas\n";
	else if (n == 24)cout << "Christmas Eve\n";
	else if (n==23)cout << "Christmas Eve Eve\n";
	else cout << "Christmas Eve Eve Eve\n";
	return 0;
}

Measured memory_bytes: 256
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial

sys.setrecursionlimit(10**7)
N, M = map(int, input().split())

if N<M:
    print(str(N)*M)
else:
    print(str(M)*N)




Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 1; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (min(b, d) - max(a, c) < 0) P(0);
  else P(min(b, d) - max(a, c));
  return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        // 入力
        long[] nk = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();

        long[] x = new long[200000];
        for (int i = 0; i < n; i++)
        {
            x[a[i]]++;
        }

        long ans = 0;
        if (x.Where(value => value > 0).Count() > k)
        {
            long count = x.Where(value => value > 0).Count() - k;
            Array.Sort(x);
            for (int i = 0; i < 200000; i++)
            {
                if (x[i] != 0)
                {
                    ans += x[i];
                    count--;
                }

                if (count == 0)
                {
                    break;
                }
            }
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 38340
use proconio::*;
use proconio::marker::Usize1;

fn dfs(n: usize, m: usize, a: &mut [usize], g: &[Vec<(usize, usize, u32)>], score: u32) -> u32 {
    if n == 0 {
        return score;
    }
    let mut ans = 0;
    for i in 0..m {
        a[n - 1] = i;
        let mut s = score;
        for &(b, c, d) in g[n - 1].iter() {
            if a[b] - a[n - 1] == c {
                s += d;
            }
        }
        ans = std::cmp::max(ans, dfs(n - 1, i + 1, a, g, s));
    }
    ans
}

fn run() {
    input! {
        n: usize,
        m: usize,
        q: usize,
        e: [(Usize1, Usize1, usize, u32); q],
    }
    let mut g = vec![vec![]; n];
    for (a, b, c, d) in e {
        g[a].push((b, c, d));
    }
    let mut val = vec![0; n];
    val[n - 1] = m - 1;
    let ans = dfs(n - 1, m, &mut val, &g, 0);
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 2180
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) < *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

static struct {
	size_t num;
	struct {
		char c;
		size_t count;
	} info[3];
} aCount;

int main(void) {
	size_t N;
	char ABC[3][101];

	scanf("%zu\n%s\n%s\n%s", &N, ABC[0], ABC[1], ABC[2]);

	size_t swapCount = 0;

	for (size_t i = 0; i < N; i++) {
		aCount.num = 0;

		for (size_t j = 0; j < 3; j++) {
			bool found = false;

			for (size_t infoIdx = 0; infoIdx < aCount.num; infoIdx++) {
				if (aCount.info[infoIdx].c == ABC[j][i]) {
					aCount.info[infoIdx].count++;

					found = true;
				}
			}

			if (!found) {
				aCount.info[aCount.num].c = ABC[j][i];
				aCount.info[aCount.num].count = 1;
				aCount.num++;
			}
		}

		if (aCount.num == 3) {
			swapCount += 2;
		}
		else if (aCount.num == 2) {
			swapCount += 1;
		}
	}

	printf("%zu\n", swapCount);

	return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.lang.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        //one person: 0
        if(K==1) System.out.println(0);
        // 1, 1, ..., 1, (N-K+1)
        else System.out.println(N-K);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define ll long long
#define N 1000005
#define MOD 1000000007

using namespace std;

int n;
ll fact[N] , invfact[N];

ll Pow(ll n , ll p)
{
    ll npow = n , ans = 1;

    for(; p ; p >>= 1)
    {
        if(p & 1)
            ans = ans * npow % MOD;

        npow = npow * npow % MOD;
    }

    return ans;
}

void Prepare()
{
    int i;

    fact[0] = invfact[0] = 1;

    for(i = 1 ; i <= n ; i++)
    {
        fact[i] = fact[i - 1] * i % MOD;
        invfact[i] = Pow(fact[i] , MOD - 2);
    }
}

ll Comb(ll n , ll k)
{
    return fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
}

int main()
{
    ll x , ans = 0 , y = 0;
    int k;

    cin >> n;

    Prepare();

    for(k = n / 2 ; k < n ; k++)
    {
        x = Comb(k - 1 , n - k - 1) * fact[k] % MOD * fact[n - k - 1] % MOD;
        x = (x - y + MOD) % MOD;
        y = (y + x) % MOD;
        x = x * k % MOD;
        ans = (ans + x) % MOD;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 15872
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}


//#define int ll

int G[2020][2020];
int GG[2020][2020];
class DLamp {
public:

void solve(std::istream& cin, std::ostream& cout) {
    int H, W;
    cin >> H >> W;
    string s;
    memset(G,0,sizeof(G));
    memset(GG,0,sizeof(GG));
    _for(h,H){
        cin >> s;
        _for(w,W)G[h][w] = s[w] == '#';
        G[h][W] = 1;
    }
    _for(w,W+1)G[H][w] = 1;
    _for(h,H){
        int left = -1, right = 0, w = 0;
        while(w < W){
            while(!G[h][w] && w < W){
                w++;
                if(w == W)break;
            }
            rep(i,left+1, w)GG[h][i] = w - left - 1;
            left = w;
            w++;
        }
    }
    _for(w,W){
        int left = -1, right = 0, h = 0;
        while(h < H){
            while(!G[h][w] && h < H){
                h++;
            }
            rep(i,left+1, h)GG[i][w] += h - left - 1;
            left = h;
            h++;
        }
    }

    int mx = -1;
    _for(h,H)_for(w,W)mx = max(mx, GG[h][w]-1);
    cout << mx << endl;

}
};


#undef int
int main() {
	DLamp solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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


int main() {
int64_t A,B,N;
  cin >>A>>B>>N;
  if(N<B){
   cout <<(A*N)/B - A*(N/B)<<endl;
  }else{
   cout <<(A*(B-1))/B - A*((B-1)/B)<<endl;
  }
}

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

int main()
{
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int sum = 0;
  if ( A <= B) {
    sum += A;
  } else {
    sum += B;
  }

  if ( C <= D) {
    sum += C;
  } else {
    sum += D;
  }
  cout << sum << endl;
}

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

namespace atocoder1
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] A = Console.ReadLine().ToArray();
            int w = A.Aggregate(0, (x, y) => x + (y == 'o' ? 1 : 0));
            if(w >= 8 || 15 - A.Length >= 8 - w)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }
}


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

signed main(){
  int a,b,p=1;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b;
    if(b%2 == 0){
      if(b%3 != 0 && b%5!=0){
        p=0;
      }
    }
  }
  if(p==1){
    cout<<"APPROVED\n";
  } else {
    cout<<"DENIED\n";
  }
  return(0);
}

Measured memory_bytes: 256
use std::io;

fn main(){

    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let mut input:u32 = input.trim().parse().unwrap();

    let h:u32 = input/3600;
    input = input - h * 3600;
    let m:u32 = input/60;
    input = input - m*60;
    println!("{}:{}:{}",h,m,input);


}



Measured memory_bytes: 5032
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if b-a<=k and c-a<=k and d-a<=k and e-a<=k and c-b<=k and d-b<=k and e-b<=k and d-c<=k and e-c<=k and e-d<=k:
  print('Yay!')
else:
  print(':(')

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
using namespace std;
using ll =long long;
void out(ll X1, ll X2, ll num) {
	if (num <= X1) {
		cout << X2 << endl;

	}
	else {
		cout << X1 << endl;
	}

};

int main() {
	ll N;
	ll c;
	vector<ll>X;
	vector<ll>Xcopy;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> c;
		X.push_back(c);
		Xcopy.push_back(c);
	}
	sort(Xcopy.begin(), Xcopy.end());
	for (int i = 0; i < N; i++) {
		out(Xcopy[N / 2 - 1], Xcopy[N / 2], X[i]);
		
	}

}

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

using namespace std;
int n,k;
vector<int>v;
vector<int>dp(100002,-1);
bool slv(int ttl=0){
    int f=0;
    if(dp[ttl]!=-1)
        return dp[ttl];
    ///cout <<ttl << endl;
    for(int i=0;i<n;i++){
        if(ttl+v[i]<=k)
            f=max((bool)f,slv(ttl+v[i]));
    }
    return dp[ttl]=!f;
}

int main()
{
    cin>>n>>k;
    v=vector<int>(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    for(int i=k;i>=0;i--)
        slv(i);
    cout <<((slv()==0)?"First":"Second") << endl;
/**
5
0.42 0.01 0.42 0.99 0.42
*/
    return 0;
}


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

int main()
{
  int A,B;
  cin >> A >> B;
  int num;
  for(int i=10*B;i<10*(B+1);i++){
    num=i*0.08;
    if(num == A){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
      



Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define ll long long
int main(){
    int n;
    cin >> n;
    ll ans=0;
    int hi=0,lo=1999999999;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if (hi<a)hi=a;
        if (lo>a)lo=a;
    }
    cout <<abs(hi-lo)<<endl;
    return 0;
}

Measured memory_bytes: 256
d = list(map(int, input().split()))
order = input()
class Dice():
    def __init__(self, d):
        self.dice = d

    def InsSN(self, one, two, five, six):
        self.dice[0] = one
        self.dice[1] = two
        self.dice[4] = five
        self.dice[5] = six
        
    def InsWE(self, one, three, four, six):
        self.dice[0] = one
        self.dice[2] = three
        self.dice[3] = four
        self.dice[5] = six

    def S(self):
        one = self.dice[4]
        two = self.dice[0]
        five = self.dice[5]
        six = self.dice[1]
        self.InsSN(one, two, five, six)

    def N(self):
        one = self.dice[1]
        two = self.dice[5]
        five = self.dice[0]
        six = self.dice[4]
        self.InsSN(one, two, five, six)
 
    def W(self):
        one = self.dice[2]
        three = self.dice[5]
        four = self.dice[0]
        six = self.dice[3]
        self.InsWE(one, three, four, six)
        
    def E(self):
        one = self.dice[3]
        three = self.dice[0]
        four = self.dice[5]
        six = self.dice[2]
        self.InsWE(one, three, four, six)
        
    def roll(self, order):
        if order == 'S':
            self.S()
        elif order == 'N':
            self.N()
        elif order == 'E':
            self.E()
        elif order == 'W':
            self.W()
d = Dice(d)
for o in order:
    d.roll(o)
print(d.dice[0])

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

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

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll N, M;
  cin >> N >> M;

  ll p;
  string s;
  ll score = 0, penalty = 0;
  bool solved[N+1] = {};
  ll was[N+1] = {};
  rep(i, M){
    cin >> p >> s;
    if(solved[p]) continue;
    if(s == "AC"){
      solved[p] = true;
      score++;
      penalty += was[p];
    }
    else{
      was[p]++;
    }
  }
  printf("%lld %lld\n", score, penalty);
  return 0;
}


Measured memory_bytes: 1152
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
A=list(map(int,input().split()))
ans=0
tmp=sum(A)
for x in A:
    tmp-=x
    ans+=x*tmp
    ans%=MOD
print(ans)

Measured memory_bytes: 93828
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	int i,x=-1,y=-1,l;
	cin>>a;
	l=a.size();
	for(i=0;i<l;i++)
	{
		if(a[i]=='C')
		{
			x=i;
			break;
		}
	}
	if(x==-1)
	{
		cout<<"No"<<endl;
		return 0;
	}
	for(i=0;i<l;i++)
	{
		if(a[i]=='F')
		{
			y=i;
		}
	}
	if(y==-1)
	{
		cout<<"No"<<endl;
		return 0;
	}
	if(x<y)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#define all(x) (x).begin(),(x).end()
#define size(x) ((int)(x).size()) 
using namespace std;
typedef pair<int,int> pii;

const int inf = 1e8;
const int maxn = 2e4;
struct edge
{
	int v, r, w, c;
};
vector<edge> G[maxn];
int h[maxn], dist[maxn];
int pv[maxn], pe[maxn];
int V;
int n, m, k;

void init(){
	for(int i = 0; i < V; i++){
		G[i].clear();
	}
}

void add(int u, int v, int w, int cost){
	G[u].push_back((edge){v, size(G[v]), w, cost});
	G[v].push_back((edge){u, size(G[u])-1, 0, -cost});
} 

void bellman(int s){
	int update = 1;
	fill(dist, dist+V, inf);
	dist[s] = 0;
	while(update){
		update = 0;
		for(int u = 0; u < V; u++){
			for(int j = 0; j < size(G[u]); j++){
				edge &e = G[u][j];
				if(e.w > 0 && dist[e.v] > dist[u] + e.c){
					dist[e.v] = dist[u] + e.c;
					update = 1;
				}
			}
		}
	}
}

int min_cost_flow(int s, int t, int flow){
	int res = 0;
	fill(h, h+V, 0);
	bellman(s);
	for(int i = 0; i < V; i++){
		h[i] += dist[i];
	}
	while(flow > 0){
		fill(dist, dist+V, inf);
		dist[s] = 0;
		priority_queue<pii, std::vector<pii>, greater<pii> > q;
		q.push(pii(0, s));
		while(!q.empty()){
			pii x = q.top(); q.pop();
			int u = x.second;
			if(dist[u] < x.first) continue;
			for(int i = 0; i < size(G[u]); i++){
				edge &e = G[u][i];
				int k = h[u] + dist[u] + e.c - h[e.v];
				if(k < dist[e.v] && e.w > 0){
					dist[e.v] = k;
					q.push(pii(k, e.v));
					pv[e.v] = u;
					pe[e.v] = i;
				}
			}
		}
		if(dist[t] == inf) {
			return -1;	//不能再增广
		}
		for(int i = 0; i < V; i++){
			h[i] += dist[i];
		}   
		int tf = flow;
		for(int v = t; v != s; v = pv[v]){
			tf = min(tf, G[pv[v]][pe[v]].w);
		}	
		if(tf){
			for(int v = t; v != s; v = pv[v]){
				edge &e = G[pv[v]][pe[v]];
				e.w -= tf;
				G[v][e.r].w += tf;
			}
			res += tf * h[t];
			flow -= tf;
		}
	}
	return res;	
}

int a[maxn], w[maxn], vis[maxn];

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> m >> n >> k;
	int res = 0;
	for(int i = 1; i <= n; i++){
		cin >> w[i];
	} 
	for(int i = 0; i < k; i++){
		cin >> a[i];
	}
	k = unique(a, a+k) - a;
	int s = 0, t = k - 1;
	for(int i = 0; i < k-1; i++){
		add(i, i+1, inf, 0);
	}
	V = k;
	for(int i = 0; i < k; i++){
		res += w[a[i]];
		if(vis[a[i]]){
			add(vis[a[i]], i, 1, -w[a[i]]);
		}
		vis[a[i]] = i+1;
	}
	cout << res + min_cost_flow(s, t, m-1) << endl;
	return 0;
}


Measured memory_bytes: 4816
#include <bits/stdc++.h>
using namespace std;
#define v1 (2 * v + 1)
#define v2 (2 * v + 2)
#define size(a) ((ll)a.size())
typedef long long ll;

int main() {
#ifdef RUZAL
    freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#else
    //freopen("sum0.in", "r", stdin); freopen("sum0.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0); //cin.tie(NULL); cout.tie(NULL);

    ll a, b;
    cin >> a >> b;

    ll ans = min(a, b / 2);
    a -= ans;
    b -= 2 * ans;
    ans += b / 4;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  llong n, k;
  cin >> n >> k;
  vector<llong> a(n), b(n);

  set<int> v;
  map<int, llong> mp;

  REP(i,n){
    cin >> a[i] >> b[i];
    v.insert(a[i]);
    mp[a[i]] += b[i];
  }
  
  llong cnt = 0;
  REPI(itr, v){
    cnt += mp[*itr];
    if(cnt >= k){
      cout << *itr << endl;
      break;
    }
  }

  return 0;
}



Measured memory_bytes: 8704
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    private static final int[] pc = createPrimeChecker();
    private static final int MAX = 1000000;
    
    public static void main(String[] args) {
        while(scn.hasNextInt()) {
            System.out.println(pc[scn.nextInt()]);
        }
    }
    
    private static int[] createPrimeChecker() {
        int[] ary = new int[MAX];
        ary[2] = 1;
        for(int i = 3; i < MAX; i += 2) {
            ary[i] = 1;
        }
        int lim = (int)Math.sqrt(MAX) + 1;
        for(int i = 3; i < lim; i += 2) {
            if(ary[i] > 0) {
                for(int j = i * 2; j < MAX; j += i) {
                    ary[j] = 0;
                }
            }
        }
        for(int i = 3, j = 1; i < MAX; i++) {
            if(ary[i] > 0) {
                ary[i] += j;
                j++;
            } else {
                ary[i] += j;
            }
        }
        return ary;
    }
}

Measured memory_bytes: 30244
import sys #追加
sys.setrecursionlimit(10**6) 
input = sys.stdin.readline

n,q = map(int,input().split())
from collections import defaultdict
dic = defaultdict(list)
for _ in range(n-1):
    a,b = map(int,input().split())
    dic[a-1].append(b-1)
    dic[b-1].append(a-1)

from collections import defaultdict
dicp = defaultdict(int)

for _ in range(q):
    p,x = map(int,input().split())
    dicp[p-1] += x


ansl = [0 for i in range(n)]
used = [0 for i in range(n)]
def dfs(pos, point):
    point += dicp[pos]
    used[pos] = 1
    ansl[pos] = point
    for p in dic[pos]:
        if used[p] == 0:
            dfs(p, point)

dfs(0, 0)

for a in ansl:
    print(a)


Measured memory_bytes: 269844
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


// 2 ^ 27
int ans[1 << 18];
int n;
int a[1 << 18];


int x[1 << 18][4];


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


	cin >> n;
	rep(i, 1 << n)cin >> a[i];


	rep(i, 1 << n) {
		int s = i >> n / 2;
		for (int j = s; j<(1 << (n+1)/2); j = (j + 1) | s) {
			x[j<<n/2 | i][0] = a[i];
			sort(x[j<<n/2 | i], x[j<<n/2 | i] + 4);
		}
	}

	rep(i, 1 << n) {
		int arr[4] = {};
		int m = i >> n / 2 << n / 2;
		int s = i & ((1 << n / 2) - 1);
		for (int j = s;; j = (j - 1)&s) {
			arr[0] = x[m | j][2];
			arr[1] = x[m | j][3];
			sort(arr, arr + 4);
			if (j == 0)break;
		}

		ans[i] = arr[2] + arr[3];
	}

	rep(i, (1 << n) - 1) {
		ans[i + 1] = max(ans[i + 1], ans[i]);
	}
	for (int k = 1; k < (1 << n); k++) {
		cout << ans[k] << endl;
	}


	return 0;
}


/*
int ans[1 << 18];
int n;
int a[1 << 18];


int x[1 << 18][4];


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


	cin >> n;
	rep(i, 1<<n)cin >> a[i];


	rep(i,1<<n) {
		x[i][0] = a[i];
		sort(x[i], x[i] + 4);
	}
	rep(i, n) rep(b, 1 << n) if (0 != (b & (1 << i))) {
		int src = b ^ 1 << i;
		x[b][0] = x[src][2];
		x[b][1] = x[src][3];
		sort(x[b], x[b] + 4);
	}


	rep(i,1<<n) {
		ans[i] = x[i][2] + x[i][3];
	}

	rep(i, (1<<n)-1) {
		ans[i + 1] = max(ans[i + 1], ans[i]);
	}
	for (int k = 1; k < (1 << n); k++) {
		cout << ans[k] << endl;
	}


	return 0;
}
*/


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

int main(){
  int n;
  cin >> n;
  int h[n+1];
  for (int i = 0; i < n; i++){
  	cin >> h[i];
  }
  h[n] = 1000000001;
  
  int res = 0;
  int count = 0;
  for (int j = 0; j < n; j++){
  	if (h[j] >= h[j+1]){
      count += 1;
    }else{
      res = max(res, count);
      count = 0;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
using namespace std;

int main(void){
	long long ans=0,n,f;
	cin>>n;
  	long long a[n],s[n+1]={0},tmp,tc=1;
  	for(int i=0;i<n;i++){
    	cin>>a[i];
      	s[i+1]=s[i]+a[i];
    }
  	sort(s,s+n+1);
  tmp=s[0];
  	for(int i=1;i<=n;i++){
      //cout<<s[i]<<endl;
      	if(s[i]==tmp){
          	tc++;
          f=1;
        }else{
          tmp=s[i];
          //cout<<(tc*(tc-1))/2;
          ans+=(tc*(tc-1))/2;
          tc=1;
          f=0;
        }
    }
  	if(f)ans+=(tc*(tc-1))/2;
	cout << ans << endl;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 3e2 + 5;

int n,c[5];
double dp[N][N][N];

double f(int c1,int c2,int c3) {
  if (c1 == 0 && c2 == 0 && c3 == 0)
    return 0;
  double &res = dp[c1][c2][c3];
  if (res != -1)
    return res;
  res = (double) n / (c1 + c2 + c3);
  if (c1)
    res += f(c1 - 1,c2,c3) * (double)c1 / (c1 + c2 + c3);
  if (c2)
    res += f(c1 + 1,c2 - 1,c3) * (double)c2 / (c1 + c2 + c3);
  if (c3)
    res += f(c1,c2 + 1,c3 - 1) * (double)c3 / (c1 + c2 + c3);
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n;
  for (int i = 1 ; i <= n ; i++) {
    int x;
    cin >> x;
    c[x]++;
  }
  for (int i = 0 ; i <= n ; i++)
    for (int j = 0 ; j <= n ; j++)
      for (int k = 0 ; k <= n ; k++)
        dp[i][j][k] = -1;
  cout << setprecision(10) << fixed << f(c[1],c[2],c[3]);
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  string s;
  cin >> n >> q >> s;
  vector<int> res(n);
  for (int i = 0; i < n - 1; i++) {
    res[i+1] = s.substr(i, 2) == "AC";
  }
  for (int i = 0; i < n - 1; i++) {
    res[i+1] += res[i];
  }
  for (int i = 0; i < q; i++) {
    int l, r; cin >> l >> r;
    cout << res[r-1] - res[l-1] << '\n';
  }
  return 0;
}

Measured memory_bytes: 1488
from math import floor
from math import ceil

N, K = map(int, input().split())
ans = 0
for i in range(1, N+1):
    if (i*2) % K == 0:
        m = floor((N+i)/K) - ceil((1+i)/K) + 1
        n = floor((N-i)/K) - ceil((1-i)/K) + 1
        ans += m*n
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */


/* main */

signed main(){
    ll N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    S += 'p';
    vl v;
    for(int i = 0;i < N;){
        ll l = i;
        while(i < N && S[i] == S[l]){
            i++;
        }
        ll r = i;
        v.push_back(r-l);
    }
    FOR(i,0,v.size()-1)v[i+1] += v[i];
    ll ans = 0;
    if(S[0] == '0'){
        FOR(i,0,v.size()){
            ll tmp = v[max(min(v.size()-1,i + 2*K - (i%2 ? 0 : 1)),0)] - (i ? v[i-1] : 0);
            chmax(ans,tmp);
        }
    }
    else{
        FOR(i,0,v.size()){
            ll tmp = v[max(min(v.size()-1,i + 2*K - (i%2 ? 1 : 0)),0)] - (i ? v[i-1] : 0);
            chmax(ans,tmp);
        }
    }
    cout << ans << endl;
}

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

int main() {
  int N,K;
  cin>>N>>K;
  string S;
  cin>>S;
  int Z=0;
  for(int i=0;i<N-1;i++){
    if(S[i]==S[i+1]){
      Z++;
    }
  }
  cout<<min(N-1,Z+2*K)<<endl;
}

Measured memory_bytes: 3756
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
const int maxn=200005;
int d1[maxn];
int c1, c2, n, m;

map<int, int> go;

int main()
{
    while(~scanf("%d%d", &n, &m)){
        c1=0;
        go.clear();
        int u, v;
        for(int i=0;i<m;i++){
            scanf("%d%d", &u, &v);
            if(u==1||v==1){
                if(u==1)d1[c1++]=v;
                else d1[c2++]=u;
            }
            if(u==n||v==n){
                if(u==n)go[v]=1;
                else go[u]=1;
            }
        }
        int ans=0;
        for(int i=0;i<c1;i++){
            int t=d1[i];
            if(go[t]){
                ans=1;break;
            }
        }
        if(ans)printf("POSSIBLE\n");
        else printf("IMPOSSIBLE\n");
    }
    return 0;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 998244353;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
  ll a,b;
  ll v,w;
  ll t;
  cin >> a >> v;
  cin >> b >> w;
  cin >> t;
  bool can = true;
  if(v - w <= 0){
    can = false;
  }else{
    if(abs(a - b) <= (v - w) * t){
      can = true;
    }else{
      can = false;
    }
  }
  if(can){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main() {

    int N; cin >> N;
    vector<int> ans;
    while(N != 0) {
        for (int i = 1; ; ++i) {
            if (i*(i-1)/2 < N && N <= (i+1)*i/2) {
                ans.push_back(i);
                N -= i;
                break;
            }
        }
    }

    Sort(ans);
    rep(i,ans.size()) {
        out(ans[i]);
    }

    return 0;
}









Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int max = -1;
        int c = 0;
        while (n-- > 0) {
            int m = sc.nextInt();
            int w = sc.nextInt();
            if (max < w || max == w && c > m) {
                max = w;
                c = m;
            }
        }
        System.out.println(c + " " + max);
    }
}






Measured memory_bytes: 26168
#include <iostream>
using namespace std;
void ABC90(void);
void ABC91(void);
void ABC92(void);
void ABC93(void);
void ABC94(void);
void ABC95(void);
void ABC96(void);
void ABC97(void);
void ABC98(void);
void ABC99(void);

int main(void){
    ABC91();
}

void ABC91(){
    int a,b,c;
    cin>>a>>b>>c;
    if((a+b)>=c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int i,j,N,A[100],flag,b,c=0;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	flag=1;
	while(flag){
		flag=0;
		for(j=N-1;j>=1;j--){
			if(A[j]<A[j-1]){
				b=A[j];
				A[j]=A[j-1];
				A[j-1]=b;
				flag=1;
				c++;
			}
		}
	}
	for(i=0;i<N;i++){
		if(i>0){
			printf(" ");
		}
		printf("%d",A[i]);
	}
	printf("\n");
	printf("%d\n",c);
	return 0;
}


Measured memory_bytes: 2132
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e3+50;
const int mod=1e9+7;
using namespace std;
int n,i,j,mid,l,r,ans,rs,a[nmax],t;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	//for(i=1;i<=n;i++)cout<<a[i]<<" ";
	//cout<<endl;
	for(i=1;i<=n;i++)
	{
		t=0;
		for(j=i+1;j<=n;j++)
		{
			for(t=max(t,j+1);t<=n;t++)
			{
				if(a[t]>=a[i]+a[j])break;
			}
			//cout<<i<<" "<<j<<" "<<t<<endl;
			ans+=t-j-1;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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


int main(){
  int k; // kこ入力受付
  int x; // xは確実に黒
  int i,count=0;
  char moji[10],tmp[10],j;

  if (scanf("%d", &k) == 1) {
      } else {
          printf("Failed to read integer.\n");
      }


      if (scanf("%s", moji) == 1) {
    } else {
        printf("Failed to read integer.\n");
    }


if(k<3200) printf("red" );
if (k>=3200) printf("%s", moji);

return 0;
}


Measured memory_bytes: 128
N = int(input())
S = input()

# numは1からn-1まで
def mozisu(text, num):
    ans = 0
    wc = {}
    for i in text[:num]:
        wc[i] = True
    for i in text[num:]:
        if i in wc:
            if wc[i]:
                wc[i] = False
                ans += 1
    return ans

max = 0
for i in range(len(S)-1):
    x = mozisu(S, i+1)
    if x > max:
        max = x
print(max)


Measured memory_bytes: 3060
class Dice:
    def __init__(self, lst):
        self.a = lst[0]
        self.b = lst[1]
        self.c = lst[2]
        self.d = lst[3]
        self.e = lst[4]
        self.f = lst[5]
        
    def roll(self, orders):
        for order in orders:
            if order=='W':
                tmp = self.a
                self.a = self.c
                self.c = self.f
                self.f = self.d
                self.d = tmp
            elif order=='E':
                tmp = self.a
                self.a = self.d
                self.d = self.f
                self.f = self.c
                self.c = tmp
            elif order=='S':
                tmp = self.a
                self.a = self.e
                self.e = self.f
                self.f = self.b
                self.b = tmp
            elif order=='N':
                tmp = self.a
                self.a = self.b
                self.b = self.f
                self.f = self.e
                self.e = tmp
#             print(self.a, self.b, self.c, self.d, self.e, self.f)
        print(self.a)
                

if __name__ == '__main__':
    lst = [int(x) for x in input().split()]
    orders = input()
    
    dice = Dice(lst)
    dice.roll(orders)


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 4e5 + 10;
#define fi first
#define se second
#define pb push_back
int n,a[N],b[N];
vector<int>v[N];
int t[N<<2];
#define mid (l+r>>1)
#define ls o<<1
#define rs o<<1|1
void up(int o,int l,int r,int p,int d){
  if(l==r){
    t[o]=d;
    return ;
  }
  if(p<=mid)up(ls,l,mid,p,d);
  else up(rs,mid+1,r,p,d);
  t[o]=max(t[ls],t[rs]);
}
int get(int o,int l,int r,int x,int y){
  if(x<=l&&r<=y)return t[o];
  int z=0;
  if(x<=mid)z=max(z,get(ls,l,mid,x,y));
  if(y>mid)z=max(z,get(rs,mid+1,r,x,y));
  return z;
}
int get(int o,int l,int r,int x){
  if(l==r)return t[o];
  int z=0;
  if(x<=mid)return get(ls,l,mid,x);
  else return get(rs,mid+1,r,x);
}
int len,cnt,c[N],ans[N];
void dfs(int x,int y){
  int pre=get(1,1,len,a[x]);
  int nx=get(1,1,len,1,c[x])+1;
  ans[x]=max(ans[y],nx);
  up(1,1,len,a[x],nx);
  for(auto k:v[x]){
    if(k==y)
      continue;
    dfs(k,x);
  }
  up(1,1,len,a[x],pre);
}
int main() {
  ios::sync_with_stdio(false);
  cin>>n;
  for(int i=1;i<=n;i++)cin>>a[i],b[++cnt]=a[i],b[++cnt]=a[i]-1;
  sort(b+1,b+1+cnt);
  len=unique(b+1,b+1+cnt)-b-1;
  for(int i=1;i<=n;i++){
    c[i]=lower_bound(b+1,b+1+len,a[i]-1)-b;
    a[i]=lower_bound(b+1,b+1+len,a[i])-b;
  }
  for(int i=1;i<n;i++){
    int s,t;
    cin>>s>>t;
    v[s].pb(t);
    v[t].pb(s);
  }
  dfs(1,0);
  for(int i=1;i<=n;i++)cout<<ans[i]<<'\n';
  return 0;
}


Measured memory_bytes: 37536
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <cmath>
#include <iomanip>

using namespace std;

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

    vector<int> a(M);

    for(int i=0; i<M; i++)
        cin>>a[i];

    vector<long long> dp(N+1, 0);

    int a_idx=0;
    dp[0]=1;

    for(int i=1; i<=N; i++){
        if(a_idx<M and a[a_idx]==i){
            dp[i]=0;
            a_idx++;
            continue;
        }

        if(i==1) {
            dp[i] = 1;
            continue;
        }

        dp[i] = (dp[i-1]+dp[i-2])%1000000007;
    }

    cout<<dp[N]<<endl;

    return 0;
}

Measured memory_bytes: 1408
#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;

    if (n % 1000 ==0) cout << 0 << endl;
    else cout << 1000 - (n % 1000) << endl;

    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

string S,T;

int main(){
  ll H,W,N,cu,cd,cl,cr;
  ll X,Y;
  cin >> H >> W >> N;
  cin >> X >> Y ;
  cin >> S >> T;
  cu=X-1;cl=Y-1;cd=H-X;cr=W-Y;
  rep(i,N){
    if(S[i]=='U'){
      cu--;
      if(cu<0){
        cNO;
        return 0;
      }
    }
    if(S[i]=='D'){
      cd--;
      if(cd<0){
        cNO;
        return 0;
      }
    }
    if(S[i]=='R'){
      cr--;
      if(cr<0){
        cNO;
        return 0;
      }
    }
    if(S[i]=='L'){
      cl--;
      if(cl<0){
        cNO;
        return 0;
      }
    }
    if(T[i]=='U'){
      cd=min(H-1,cd+1);
    }
    if(T[i]=='D'){
      cu=min(H-1,cu+1);
    }
    if(T[i]=='R'){
      cl=min(W-1,cl+1);
    }
    if(T[i]=='L'){
      cr=min(W-1,cr+1);
    }
  }
  cYES;
}

Measured memory_bytes: 776
#!/usr/bin/env python3
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62



def solve(x: "List[int]"):
    print(x.index(0)+1)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = [int(next(tokens)) for _ in range(5)]  # type: "List[int]"
    solve(x)

if __name__ == '__main__':
    main()


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

int main(){
    int A,B,C,K;
    long long sum;
    scanf("%d%d%d%d",&A,&B,&C,&K);

    if(A>=K)
        printf("%d\n",K);
    else if((B+A)>=K)
        printf("%d\n",A);
    else
        printf("%d\n",A-(K-B-A));

    return 0;
}

Measured memory_bytes: 2144