akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

void Yes(bool Yes){cout << (Yes ? "Yes" : "No") << endl;};
void YES(bool YES){cout << (YES ? "YES" : "NO") << endl;};

int main(){

    ll A, B; cin >> A >> B;

    ll ans = max(ll(0), A - B * 2);

    cout << ans << endl;


}

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



int main() {
    int n;
    cin >> n;
    
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
    }
    
    //vector<int> bp, sp;
    long int ans = 1000;
    long int kabu = 0;
    for(int i = 0; i < n-1; i++) {
        if(a[i+1] - a[i] > 0) {
            for(int j = i; j >= 1; j--) {
                if(a[j] - a[j-1] > 0)
                    break;
                else if(a[j] - a[j-1] < 0) {
                    kabu = ans / a[j];
                    ans %= a[j];
                    //cout << "buy" << i << endl;
                    break;
                }
            }
        }
        else if(a[i+1] - a[i] < 0) {
            for(int j = i; j >= 1; j--) {
                if(a[j] - a[j-1] < 0)
                    break;
                else if(a[j] - a[j-1] > 0) {
                    if(kabu == 0) {
                        kabu = ans / a[0];
                        ans %= a[0];
                        //cout << "buy" << 0 << endl;
                    }
                    ans += kabu * a[j];
                    kabu = 0;
                    //cout << "sold" << i << endl;
                    break;
                }
            }
        }
    }
    
    if(kabu != 0) {
        ans += kabu * a[n-1];
        //cout << "sold" << n-1 << endl;
    }
    
    if(ans == 1000 && a[n-1] > a[0]) {
        ans = (ans / a[0]) * a[n-1] + (ans % a[0]);
        //cout << "all up" << endl;
    }
    
    cout << ans << endl;
    
    return 0;
}




Measured memory_bytes: 3616
import java.util.*;
public class Main
{
	public static void main(String[] arguments) throws Exception
	{
		Scanner sc = new Scanner(System.in);
        Integer number = Integer.valueOf(sc.next());
        Integer rating = Integer.valueOf(sc.next());
        Integer result;
        if(number >= 10) {
			result = 0;
		} else {
			result = 100 * (10-number);
		}
		System.out.println(rating+result);
		return;
      }
}

Measured memory_bytes: 21716
S = raw_input()
X = [str(S[0])]
NX = []
for s in S[1:]:
    for x in X:
        NX.append(x + s)
        NX.append(x + "+" + s)
    X = NX[:]
    NX = []
ret = 0
for x in X:
    ret += eval(x)
print ret


Measured memory_bytes: 2692
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int[] v = new int[16384];
        for(int i = 0;i < 16384;i++){
            v[i] = 1;
        }
        int p = 3;
        while(true){
            if(p*p > 32768){
                break;
            }else{
                if(v[(p-1)/2] == 0){
                    p += 2;
                }else{
                    int t = p*p;
                    while(t < 32768){
                        v[(t-1)/2] = 0;
                        t += 2*p;
                    }
                    p += 2;
                }
            }
        }
        while(scan.hasNext()){
            int n = scan.nextInt();
            if(n == 0){
                break;
            }else if(n == 4){
                System.out.println(1);
                continue;
            }else if(n%2 != 0){
                if(v[(n-3)/2] == 1){
                    System.out.println(1);
                }else{
                    System.out.println(0);
                }
                continue;
            }
            int count = 0;
            for(int i = 1;i <= (n/2-1)/2;i++){
                if(v[i] == 1 && v[n/2-i-1] == 1){
                    count++;
                }
            }
            System.out.println(count);
        }
	}
}

Measured memory_bytes: 20592
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

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

    vector<bool> dp(X+1000, false);
    dp[0] = true;
    rep(i, 0, X+1)
    if (dp[i])
    {
        rep(j, 0, 6)
            dp[i+100+j] = true;
    }
    if (dp[X]) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <string>
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];
  }
  int ans = -1;
  int total=0;
  for(int i=0;i<m;i++){
    total += a[i];
  }
  if(total<=n){
    ans = n-total;
  }
  cout << ans;
}


Measured memory_bytes: 3660
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn is_ok(a: u32, b: u32, c: u32) -> bool {
    a < (b + c) && b < (c + a) && c < (a + b)
}

fn solve2(sticks: &[u32], a: u32, b: u32) -> u32 {
    let mut ans: u32 = 0;
    
    for i in 0..sticks.len() {
        if is_ok(a, b, sticks[i]) {
            ans += 1;
        }
    }

    ans
}

fn solve1(sticks: &[u32], a: u32) -> u32 {
    let mut ans: u32 = 0;
    
    for i in 0..sticks.len() - 1 {
        ans += solve2(&sticks[i + 1..], a, sticks[i]);
    }

    ans
}

fn solve(sticks: &Vec<u32>) -> u32 {
    let mut ans: u32 = 0;
    
    for i in 0..sticks.len() - 2 {
        ans += solve1(&sticks[i + 1..], sticks[i]);
    }

    ans
}

fn main(){
    let n: i32 = read();
    let mut sticks: Vec<u32> = (0..n).map(|_| read()).collect();
    sticks.sort();

    println!("{}", solve(&sticks));

    
}


Measured memory_bytes: 4352
a = input()
c1 = 0
c2 = 0
c3 = 0
c4 = 0
for i in range(int(a)):
  b = input()
  if "AC" == str(b):
    c1 += 1
  elif "TLE" == str(b):
    c2 += 1
  elif "WA" == str(b):
    c3 += 1
  elif "RE" == str(b):
    c4 += 1
print("AC" , "x" , str(c1))
print("WA" , "x" ,str(c3))
print("TLE" , "x" , str(c2))
print("RE" , "x" ,str(c4))

Measured memory_bytes: 9232
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;


const LL INF=1<<30;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
    if(b==0)return a;

    return gcd(b,a%b);
}
LL lcm(LL a,LL b){
    LL g=gcd(a,b);
    return a/g*b;
}

LL kaijo(LL n){
    LL ans=1;
    for(LL i=1;i<=n;++i){
        (ans*=i)%=MOD;
    }
    return ans;
}


int main(){
    LL x,t;
    cin>>x>>t;
    cout<<max(0LL,x-t)<<endl;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())printf("%d ",v[_]);cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

int dp[10010][110][2];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	string s;
	int d;
	cin>>s>>d;
	int MOD=1000000007;
	rep(i,10010)rep(j,110)rep(k,2)dp[i][j][k]=0;
	dp[0][0][0]=1;
	rep(i,s.size())rep(j,d)rep(k,2)rep(x,10){
		int I=i+1,J=(j+x)%d,K=k|(s[i]-'0'>x);
		if(!k&&s[i]-'0'<x)continue;
		(dp[I][J][K]+=dp[i][j][k])%=MOD;
	}
	cout<<(MOD-1+dp[s.size()][0][0]+dp[s.size()][0][1])%MOD<<endl;
}


Measured memory_bytes: 17536
import scala.annotation.tailrec
import scala.io.StdIn._
object Main extends App {
  val mod = 1000000007L
  val Array(a, b, c) = readLine.trim.split(' ')
  val power = Array.fill(10001){1L}
  for (i ← power.indices.tail) power(i) = power(i - 1) * 10 % mod
  println(
    ((countBelow(b, c) - countBelow(a, c) + a.indices.dropRight(c.length - 1).count(a.startsWith(c, _))) % mod + mod) % mod
  )


  def countBelow(limit: String, target: String): Long = {
    val rights = limit.foldRight((List(0L), 1L)){case (v, (l, d)) ⇒ ((v.asDigit * d + l.head) % mod :: l, d * 10 % mod)}._1.drop(target.length)
    countBelow(limit, target, limit.length, 0, rights, 0)
  }
  @tailrec def countBelow(limit: String, target: String, length: Int, left: Long, rights: List[Long], result: Long = 0): Long = {
    rights match {
      case Nil ⇒ (result % mod + mod) % mod
      case r::rr ⇒
        limit.prefixCompare(target, limit.length - length) match {
          case 0 ⇒ countBelow(limit, target, length - 1, (left * 10 + limit(limit.length - length).asDigit) % mod, rr, (result + (if (target.head != '0') left else (left - 1))  * power(length - target.length) + (r + 1)) % mod)
          case 1 ⇒ countBelow(limit, target, length - 1, (left * 10 + limit(limit.length - length).asDigit) % mod, rr, (result + (if (target.head != '0') (left + 1) else left) * power(length - target.length)) % mod)
          case -1 ⇒ countBelow(limit, target, length - 1, (left * 10 + limit(limit.length - length).asDigit) % mod, rr, (result + (if (target.head != '0') left else (left - 1))  * power(length - target.length)) % mod)
          case o ⇒ ???
        }
    }
  }
  implicit class Wrap(val str: String){
    def prefixCompare(that: String, toIndex: Int): Int = {
      prefixCompare(str, that, toIndex, 0)
    }
    @tailrec private[this] def prefixCompare(a: String, b: String, aPosition: Int, bPosition: Int ): Int = {
      if (a.indices.contains(aPosition) && b.indices.contains(bPosition)) {
        a(aPosition).compareTo(b(bPosition)) match {
          case 0 ⇒ prefixCompare(a, b, aPosition + 1, bPosition + 1)
          case o ⇒ if (o > 0) 1 else -1
        }
      }else 0
    }
  }
}


Measured memory_bytes: 55032
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
#define pf push_front
#define TIME ios_base::sync_with_stdio(0);
using namespace std;

const long long N = 3e3 + 1;

ll n, m, h, x, y, cnt, a[N], b[N], r[N];
string s;
int main()
{
    TIME;
    cin >> n >> s;
    if ( n < 3200 )
        cout << "red";
    else cout << s;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b;
    cin >> a >> b;
    cout << a*b-a-b+1 << endl;
    return 0;
}

Measured memory_bytes: 256
import Data.List
import Data.IntMap (singleton, (!), keys, elems, unionWith, filterWithKey, mapKeys)
import qualified Data.IntMap.Strict as M

splitOn c xs
 | null xs = []
 | head xs == c = splitOn c (tail xs)
 | otherwise = (takeWhile (/= c)) xs : splitOn c (dropWhile (/= c) xs)
 
main = interact $ unlines . numbering . map (show' . thief) . read' . lines
 where
  read' ("0":_) = []
  read' (w:n:xs) = (read w, parse_vw $ take (read n) xs) : read' (drop (read n) xs)
   where parse_vw = map (map read . splitOn ',')
  show' (v,w) = show v ++ "\n" ++ show w
  numbering = zipWith (++) ["Case " ++ show n ++ ":\n" | n<-[1..]] 
 
thief (max_weight, treasures) = dp (singleton 0 0) (sort treasures)
 where
  dp im [] = (im!k, k)
   where k = minimum $ keys $ M.filter (== (maximum $ elems im)) im
  dp im ([v,w]:vws) = dp (unionWith max im (filterWithKey (\k _-> k<=max_weight) im')) vws
   where im' = M.map (+v) $ mapKeys (+w) im

Measured memory_bytes: 6552
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll a,b,n;
    cin >> n >> a >> b;
    if(b<a){
        cout << 0 << endl;
        return 0;
    }
    if(n==1&&b!=a){
        cout << 0 << endl;
        return 0;
    }

    ll min = a*(n-1)+b;
    ll max = b*(n-1)+a;
    cout << max+1-min << endl;
    return 0;
}

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

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

struct cmp{
  bool operator () (const pair<double,string> &a, const pair<double,string> &b){
    if(abs(a.f - b.f) > 1e-10)
      return a.f > b.f;
    return a.s < b.s;
  }
};

int main(){
  int n;
  while(cin>>n, n){
    vector<pair<double,string> > v(n);
    REP(i,n){
      int p,a,b,c,d,e,f,s,m;
      cin>>v[i].s>>p>>a>>b>>c>>d>>e>>f>>s>>m;
      v[i].f = (double)(f*m*s-p) / (double)((a+b+c+d+e) + (m-1)*(d+e));
    }
    sort(v.begin(), v.end(), cmp());
    REP(i,n) cout << v[i].s << endl;
    cout << "#" << endl;
  }
  return 0;
}

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

int main()
{
  string s, p;
  string::iterator s_p, p_p;
  bool result;

  cin >> s >> p;

  result = false;
  for (string::iterator s_head = s.begin(); s_head != s.end(); s_head++) {
    s_p = s_head;
    p_p = p.begin();
    for (;;) {
      if (*s_p++ != *p_p++) break;
      else if (p_p == p.end()) { result = true; goto end; }
      if (s_p == s.end()) s_p = s.begin();
    }
  }
end:
  if (result) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}
      


Measured memory_bytes: 3196
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void)
{
    string S;

    cin >> S;

    if(S[5]=='0'&&(S[6]=='1'||S[6]=='2'||S[6]=='3'||S[6]=='4')){
        cout << "Heisei" << endl;
    }

    else{
        cout << "TBD" << endl;
    }

    return 0;
}

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

long long a;
long long sum=1;
int h;

int main(){
	cin>>a;
	if(a==1){
		cout<<1;
		return 0;
	}
	for(int i=1;i<=50;i++){
		if(a<sum){
			break;
		}
		if(a==sum){
			cout<<sum*2-1<<endl;
			return 0;
		}
		sum*=2;
	}
	cout<<sum-1<<endl;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR :kamesh_11 *
* INSTITUTION : GVPCOE *
******************************************/

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

#define ll long long
#define MOD 1000000007
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bs binary_search
#define endl '\n'
#define start_clock clock_t beginn=clock()
#define end_clock clock_t endd=clock()
#define cal_exec_time double time_spent=(double)(endd-beginn)/CLOCKS_PER_SEC
#define print_exec_time cout<<endl<<time_spent<<" secs"

int find(int arr[], int ind, int n, int dp[], int k){
	if(ind == n) return 0;
	if(dp[ind] != -1) return dp[ind];

	int ans = INT_MAX;
	for(int i=k;i>=1;i--){
		if(ind+i <= n)
			ans = min(ans, abs(arr[ind+i]-arr[ind]) + find(arr, ind+i, n, dp, k));
	}

	return dp[ind] = ans;
}

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

	int n, k;
	cin>>n>>k;
	int arr[n+1];
	for(int i=1;i<=n;i++)
		cin>>arr[i];

	int dp[n+1];
	memset(dp, -1, sizeof(dp));
	cout<<find(arr, 1, n, dp, k);

	return 0;
}

Measured memory_bytes: 10368
import string
def dfs(w, d):
    if len(w) == N:
        print(w)
        return
    for i in range(d + 1):
        if i == d:
            dfs(w + wordlst[i], d + 1)
        else:
            dfs(w + wordlst[i], d)

N = int(input())
anslst = []
nlst = [0] * N
wordlst = string.ascii_lowercase
dfs('a', 1)


Measured memory_bytes: 4976
#include <iostream>
#include <string>
using namespace std;
int ans;
string s;
int main(){
    cin >> s;
    int i;
    for(i = 0; i < 3; i++)
    {
        if(s[i] == '1')
        {
            ans++;
        }
    }
    cout << ans << endl;
}

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


int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}

int x[10], y[10];

double dis(int i, int j){
  double dx = x[i] - x[j];
  double dy = y[i] - y[j];
  return sqrt(dx*dx + dy*dy);
}

int main(){
  int n;
  cin >> n;
  rep(i, n) cin >> x[i] >> y[i];

  vector<int> v(n);
  rep(i, n) v[i] = i;
  double sum = 0;
  int cnt = 0;

  do{
    rep(i, n-1){
      sum += dis(v[i], v[i+1]);
    }
    cnt++;
  }while(np(v.begin(), v.end()));

  double ans = sum / cnt;
  printf("%.10f\n", ans);
}


/*





















*/


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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  cout << vec.at(N - 1) - vec.at(0) << endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
n,q = [int(i) for i in readline().split()]

g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = [int(i) for i in readline().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)

add = [0]*n
for _ in range(q):
    p,x = [int(i) for i in readline().split()]
    add[p-1] += x

ans = [0]*n
#ans[0] = add[0]

def dfs(v,p,value): #p: parent of v
    value += add[v]
    ans[v] = value
    for c in g[v]:
        if c == p: continue
        dfs(c,v,value)

dfs(0,-1,0)

#print(add)

print(*ans)

Measured memory_bytes: 236920
#include <algorithm>
#include <cstdio>
#include <list>

using namespace std;

int main() {
    int q, x;
    scanf("%d", &q);
    char com[20];
    list<int> v;

    for(int i = 0; i < q; i++) {
        scanf("%s", com);
        if(com[0] == 'i') {
            scanf("%d", &x);
            v.push_front(x);
        } else if(com[6] == 'F') {
            v.pop_front();
        } else if(com[6] == 'L') {
            v.pop_back();

        } else if(com[0] == 'd') {
            scanf("%d", &x);
            for(list<int>::iterator it = v.begin(); it != v.end(); it++) {
                if(*it==x){
                    v.erase(it);
                    break;
                }
            }
        }
    }
    int i = 0;
    for(list<int>::iterator it = v.begin(); it != v.end(); it++) {
        if(i++)
            printf(" ");
        printf("%d", *it);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 33916
#include <stdio.h>
int main(){
    int n,i,b,c;
    scanf("%d",&n);
    int a[n];
    b =0,c=0;
    for(i =0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i] %2 ==0){
            if(a[i]%3 ==0 || a[i]%5 ==0){
                c++;
            }
            b++;
        }
    }
    
    if(b==c){
        printf("APPROVED");
    }else{
        printf("DENIED");
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    long long a,b,x;
    cin >> a>>b>>x;
    long long ans=0;
    if(a==0){
        ans=((b/x)+1);
    }else{
        ans=(b/x)-((a-1)/x);
    }

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

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	for(;;){
		int h, w;
		int n;
		
		int ban[100][100] = {0};
		int cant_xy[100][2];
		bool flg = false;
			
		cin >> w >> h;
		if(w == 0){
			break;
		}
		
		
		cin >> n;
		
		ban[0][0] = 1;
		
		for(int i = 0; i < n; i++){
			cin >> cant_xy[i][0] >> cant_xy[i][1];
		}
		
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				for(int k = 0; k < n; k++){
					if(i == cant_xy[k][1]-1 && j == cant_xy[k][0]-1){
						flg = true;
						break;
					}
				}
				if(flg != true){
					ban[i+1][j] += ban[i][j];
					ban[i][j+1] += ban[i][j];
				}
				flg = false;
			}
		}
		
		/*
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				printf("%d ",ban[i][j]);
			}
			cout << endl;
		}
		*/
		
		cout << ban[h-1][w-1] << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    int a,b;
    int cnt = 0;
    rep(i, n) {
        if(cnt >= 3) continue;
        cin >> a >> b;
        if(a == b) cnt++;
        else cnt = 0;
    }
    if(cnt >= 3) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)
vi fact;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z;
    cin>>n;
    x = n-1;
    fact.pb(x);
    if(n==2){
        cout<<1;
        return 0;
    }
    for(ll i=2;i*i<=x;i++){
        if(x%i==0){
            fact.pb(i);
            if(i!=(x/i))
                fact.pb(x/i);
        }
    }
    ll ans = 0;
    ans+=fact.size();
    fact.clear();
    fact.pb(n);
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            fact.pb(i);
            if(i!=(n/i))
                fact.pb(n/i);
        }
    }
    for(int i=0;i<fact.size();i++){
        y = n;
        while(y%fact[i]==0){
            y/=fact[i];
        }
        if(y%fact[i]==1){
            ans++;
        }
    }
    cout<<ans;
    
    


    return 0;
}               

Measured memory_bytes: 3668
#include <iostream>
using namespace std;
#define MAX 500000
#define H 2000000000

int c(0);
int L[MAX/2+2], R[MAX/2+2];
void Merge(int A[], int start, int middle, int end) 
{   
    int n1 = middle - start;
    int n2 = end - middle;
    for (int i = 0; i < n1; ++i) L[i] = A[start+i];  
    for (int i = 0; i < n2; ++i) R[i] = A[middle+i];
    L[n1] = R[n2] = H;
    int j = 0, k = 0;
    for (int i = start; i < end; ++i) 
    {
        if (L[j] > R[k]) A[i] = R[k++];
        else A[i] = L[j++];
        c++;
    }
}
void MergeSort(int A[], int start, int end) 
{
    if (end-start<=1) return; // 要素2個になった時点でreturn
    int middle = (start+end)/2; // 小数点以下切り捨て
    MergeSort(A, start, middle);
    MergeSort(A, middle, end);
    Merge(A, start, middle, end);
}
int main() 
{
    int n, S[MAX];
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &S[i]);
    MergeSort(S, 0, n);
    for (int i = 0; i < n; ++i) 
    {
        printf("%d", S[i]);
        if (i == n-1) printf("\n%d\n", c);
        else printf(" ");
    }
}


Measured memory_bytes: 7052
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main()
{
	ll N;
	cin >> N;
	vector<ll> A(N);
	int flag = 0;
	vector<int> flags(N, 0);
	// 1 : buy
	// 0 : stay
	// -1 : sell
	REP(i, N){
		cin >> A[i];
	}
	ll money = 1000;
	ll stock = 0;
	REP(i, N-1){
		if(A[i]<A[i+1]){
			flag=1;
		}else if(A[i]>A[i+1]){
			flag=-1;
		}else{
			flag=0;
		}
		flags[i] = flag;
	}
	if(flag == 0 or flag == 1){
		flags[N-1] = -1;
	}else{
		flags[N-1] = 0;
	}

	REP(i, N){
//		cout << "money:" << money;
//		cout << " stock:" << stock << endl;
		if(flags[i]==-1){
			money += stock*A[i];
			stock = 0;
		}else if(flags[i]==1){
			ll tmp = money/A[i];
			stock += tmp;
			money -= tmp*A[i];
		}
	}
	cout << money << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void){
    ll X, Y, Z;
    cin>>X>>Y>>Z;
    swap(X, Y);
    swap(X, Z);
    cout<<X<<sp<<Y<<sp<<Z<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;


ll MAX = 1000000000;


int main()
{
	int A, B;
	cin >> A >> B;

	A += B;

	if (A % 2 == 0)
	{
		cout << A / 2 << endl;
	}
	else
	{
		cout << "IMPOSSIBLE" << endl;
	}


	return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  int n, m;
  while (cin >> n >> m) {
    double p = 1.0;
    for (int i = 0; i < m; ++i) {
      p /= 2.0;
    }
    const double q = p;
    double x = 0;
    const double a = (n - m) * 100.0;
    const double b = m * 1900.0;
    for (int i = 1; i <= 10000; ++i) {
      x += i * p * (a + b);
      // cout << p << ' ' << i * (a + b) << ' ' << i * p * (a + b) << endl;
      p = p * (1.0 - q);
    }
    printf("%.0lf\n", x);
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define ll int64_t
#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
ll modex(ll a,int b,ll p){ll res=1;a%=p;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b>>=1;}return res;}

int n;
int a[102];
int dp[2][100005];

int win(int t,int k){
	
	if(dp[t][k]!=-1) return dp[t][k];

	int w=1-t;

	for(int i=0;i<n;i++)
		if(a[i]<=k && win(1-t,k-a[i])==t)
			w=t;

	return dp[t][k]=w;	
}

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

	memset(dp,-1,sizeof dp);

	int k;
	cin>>n>>k;

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

	int ans=win(0,k);
	
	if(ans==0) cout<<"First\n";
	else cout<<"Second\n";

	return 0;
}


Measured memory_bytes: 7296
from collections import deque

# 命令数入力
n = int(input())
# 命令入力
# order_list = [input().split() for i in range(n)]


# 双方向連結リスト
doubly_linked_list = deque()

for i in range(n):
    
    order = input().split()
    
    if order[0] == "insert":
        doubly_linked_list.appendleft(order[1])
    
    elif order[0] == "delete":
        if order[1] in doubly_linked_list:
            doubly_linked_list.remove(order[1])
    
    elif order[0] =="deleteFirst":
        doubly_linked_list.popleft()
    
    elif order[0] == "deleteLast":
        doubly_linked_list.pop()
        
# 最終結果出力
print(*doubly_linked_list)


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

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

	ios::sync_with_stdio( false );
	cin.tie( 0 );

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

	if( A == B && A == C )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
h, w, k = map(int, input().split())
c = []
for _ in range(h):
  c.append(input())
  
cols = ['{:06b}'.format(i)[6-w:] for i in range(2**w)]
rows = ['{:06b}'.format(i)[6-h:] for i in range(2**h)]

ans = 0
for row in rows:
  for col in cols:
    cnt = 0
    for i in range(h):
      for j in range(w):
        if row[i] == '0' and col[j] == '0':
          if c[i][j] == '#':
            cnt += 1
          if cnt > k:
            break
      if cnt > k:
        break
    else:
      if cnt == k:
        ans += 1
print(ans)

Measured memory_bytes: 9240
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define vin(v,n) rep(i,n)cin>>v[i];
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define sz size()
#define fi first
#define se second
#define pb push_back
#define prqueue priority_queue<ll,vector<ll>,greater<ll>>
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll n,ct, v[200010];
int main() {
	cin >> n;
	rep(i, n)cin>>v[i];
	rep(i, n) {
		if (i == 0) { if (v[i] != 0) { ct = -1; break; } else continue; }
		if (v[i] - v[i-1] == 1)++ct;
		else if (v[i - 1] >= v[i])ct += v[i];
		else { ct = -1; break; }
	}
	cout << ct << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>

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

using namespace std;

bool judge2(const char rule[51],const char packet[51]){
	rep(i,8) if(rule[i]!='?' && rule[i]!=packet[i]) return false;
	return true;
}

bool judge(const char rule[3][51],const char packet[3][51]){
	return judge2(rule[1],packet[0]) && judge2(rule[2],packet[1]);
}

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n||m;){
		static char rule[1024][3][51];
		rep(i,n) rep(j,3) scanf("%s",rule[i][j]);

		int n_pass=0,pass[1024];
		static char packet[1024][3][51];
		rep(k,m){
			rep(j,3) scanf("%s",packet[k][j]);

			bool ok=false;
			for(int i=n-1;i>=0;i--) if(judge(rule[i],packet[k])) {
				ok=(rule[i][0][0]=='p');
				break;
			}

			if(ok) pass[n_pass++]=k;
		}

		printf("%d\n",n_pass);
		rep(i,n_pass) printf("%s %s %s\n",packet[pass[i]][0],packet[pass[i]][1],packet[pass[i]][2]);
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,l;
    cin >> n >> l;
    int r=n+l-1;
    int ans;
    ans=(l+r)*n/2;
    if (r<0) ans-=r;
    else if (l>0) ans-=l;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}// char to int
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}//MAX
int lcm(ll a,ll b){return a*b/gcd(a,b);}//MIN
 
int  main(){
int w,h,n;
cin>> w >> h >> n;
bool che [h][w];
for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
        che [i][j]=false;
    }
}
for(int i=0;i<n;i++){
    int x,y,a;
    cin >> x >> y >> a;
    if(a==1){
        for(int j=0;j<h;j++){
            for(int k=0;k<x;k++){
                che [j][k]=true;//
            }
        }
    }
    if(a==2){
            for(int j=0;j<h;j++){
            for(int k=x;k<w;k++){
                che [j][k]=true;
            }
        }
    }
    if(a==3){
                for(int j=0;j<y;j++){
            for(int k=0;k<w;k++){
                che [j][k]=true;
            }
        }
    }
    if(a==4){
                for(int j=y;j<h;j++){
            for(int k=0;k<w;k++){
                che [j][k]=true;
            }
        }
    }
}
int ans = 0;
        for(int j=0;j<h;j++){
            for(int k=0;k<w;k++){
                if(!che[j][k])ans++;

        }
        }
        cout << ans << endl;
}
 


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#pragma warning(disable : 4996)
struct Node {
	int key;
	Node *p, *l, *r;
};
Node *root;
void insert(int key_) {
	Node *x = root, *y = 0, *z;
	z = (Node*)malloc(sizeof(Node));
	z->key = key_, z->l = 0, z->r = 0;
	while (x) y = x, x = (z->key < x->key) ? x->l : x->r;
	z->p = y;
	if (!y) root = z;
	else if (z->key < y->key) y->l = z;
	else y->r = z;
}
bool find(int key_) {
	Node *x = root;
	while (x) {
		if (key_ < x->key) x = x->l;
		else if (key_ > x->key) x = x->r;
		else return true;
	}
	return false;
}
void walk1(Node *x) { if (!x) return; walk1(x->l); printf(" %d", x->key); walk1(x->r); }
void walk2(Node *x) { if (!x) return; printf(" %d", x->key); walk2(x->l); walk2(x->r); }
int n, v; char c[8];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", &c);
		if (c[0] == 'i') scanf("%d", &v), insert(v);
		else if (c[0] == 'f') scanf("%d", &v), printf("%s\n", find(v) ? "yes" : "no");
		else walk1(root), printf("\n"), walk2(root), printf("\n");
	}
	return 0;
}

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

using namespace std;
typedef long long ll ;
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define pb push_back

int main()
{
	int T=1;
	// cin >> T ;

	while(T--)
	{
		int n ;
		cin>>n ;
		ll a[n] ;
		rep(i,0,n) cin>>a[i] ;

		ll dp[n][n] ;

		rep(i,0,n) dp[0][i]=a[i] ;

		rep(i,1,n)
		{
			int l=i+1 ;
			rep(j,0,n-l+1)
				dp[i][j] = max(a[j]-dp[i-1][j+1] , a[j+l-1]-dp[i-1][j]) ;
		} 
		cout<<dp[n-1][0]<<endl ;
	}
	return 0;
}

Measured memory_bytes: 49812
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define PI 3.14159265
#define ll long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 300000000000000001
#define infx 9223372036854775806
#define all(c) c.begin(),c.end()
#define mk(x,yy) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define ff first
#define ss second
#define re return
// #define endl "\n"
#define max2(x,y)           (x>y)?x:y
#define min2(x,y)           (x<y)?x:y
#define mid(s,e)               (s+(e-s)/2)
#define mini                   INT_MIN
#define maxo                   INT_MAX
#define rep(i,a,b) for(int i=a;i<(int)(b);++i)
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define show(a,n) for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl
#define ene cout<<"\n";

ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
ll power(ll x,  ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
 
bool compr(std::vector<ll> a, std::vector<ll> b)
{
    if(a[0]==b[0])
        return a[1]<b[1];
    else
        return a[0]<b[0];
}

bool comp(std::vector<ll> a, std::vector<ll> b)
{
    if(a[1]==b[1]&&a[2]==b[2])
        return a[0]<b[0];
    else if(a[1]==b[1])
        return a[2]>b[2];
    else
        return a[1]<b[1];
}

int main()
{
    #ifdef SHIVANSH 
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    ll dp[k+1];
    dp[0] = 0;
    for(ll i=1;i<a[0];i++)
        dp[i] = 0;
    for(ll i=a[0];i<=k;i++)
    {
        ll b[101] = {};
        for(ll j=0;j<n;j++)
        {
            if(a[j]>i)
                break;
            
            b[dp[i-a[j]]]++;
        }
        for(ll j=0;j<=100;j++)
        {
            if(b[j]==0)
            {
                dp[i] = j;
                break;
            }
        }
    }
    // for(ll i=0;i<=k;i++)
    //     cout<<dp[i]<<endl;
    if(dp[k]==0)
        cout<<"Second"<<endl;
    else
        cout<<"First"<<endl;
}

Measured memory_bytes: 4388
#include<bits/stdc++.h>
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod=1e9+7;         
const int N=1e5+4;
typedef pair<int,int> pii;
int main()                  
{
    int n,m;
    scn(n);scn(m); 
    vector<pii> v;
    rep(i,0,n)
    {
        pii p;
        scn(p.S);scn(p.F);
        v.pb(p);
    }
    set<int> s;
    rep(i,0,m+1)
    s.insert(i);
    sort(v.rbegin(),v.rend());
    ll total=0;
    for(auto it:v)
    {
        if(it.S>m)
        continue;
        if(s.find(m-it.S)!=s.end())
        {
            s.erase(m-it.S);
            total+=(ll)it.F;
        }
        else
        {
            auto iter=s.upper_bound(m-it.S);
            if(iter==s.begin())
            continue;
            iter--;
            s.erase(*iter);
            total+=(ll)it.F;
        }
    }
    lpri(total);
}

Measured memory_bytes: 5748
#include <iostream>
#include <algorithm>
using namespace std;
#define F for(i=0;i<N;i++)
int main(){
int i,N,a[100],r=0;
 cin>>N;
 F cin>>a[i];
 sort(a,a+N);
 F r+=(i%2)?-a[N-i-1]:a[N-i-1];
 cout<<r<<endl;
}

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

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define INF (1<<28)
#define pb(i) push_back(i)
#define fs first
#define sc second

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

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


Measured memory_bytes: 896
char m[98],v[98],c;C(i){return m[i]==c&!v[i]?v[i]=1,1+C(i+1)+C(i-1)+C(i+7)+C(i-7):0;}E(i){m[i]==79?m[i]=0:m[i]==c?m[i]=0,E(i+1),E(i-1),E(i+7),E(i-7):0;}main(i,e,n){for(read(0,m+7,3);read(0,m+7,84);printf("%d\n",n))for(e=n=-1;e;n++){for(i=924;i--;m[7+e]<47?m[7+e]=m[e],m[e]=0:0)v[7+(e=i%84)]=0;for(i=6;++i<91;c&&strchr("RGBYP",c)&&C(i)>3&&E(e=i))c=m[i];}}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */

/* function */

/* main */
int main() {

    string T;
    while (1) {

        cin >> T;
        if (T[0] == '-') {
            break;
        }
        else{
            int num;
            cin >> num;
            while (num--) {
                int h; cin >> h;
                T = T.substr(h) + T.substr(0, h);
            }
            cout << T << '\n';
        }

    }



}



Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    cout << (a[0] == 5 && a[1] == 5 && a[2] == 7 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
int a,b;
string s1,s2,s3;
cin>>s1>>s2;
cin>>a>>b;
cin>>s3;	
if(s1==s3)
a=a-1;
else
b=b-1;
cout<<a<<" "<<b<<endl;
	
	
	
}


Measured memory_bytes: 256
n = int(input())
t,a = map(int,input().split())
H = list(map(int,input().split()))
def get_temp(x):
  return t - x * 0.006
best = a + 10000
ans = 0
for i in range(n):
  cur_dif = abs(get_temp(H[i]) - a)
  if cur_dif < best:
    best = cur_dif
    ans = i + 1
print(ans)

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

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

const int INF = 1e9;
const int mod = 1e9+7;

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

    vector<int> flag(n+10,0);
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        if(a == 1 || a == n) flag[b]++;
        if(b == 1 || b == n) flag[a]++;
    }
    for(int i = 1; i <= n; i++){
        if(flag[i] == 2){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;
 
int main(){
 
    int a,b ;
    cin >> a>>b;
	if(b!=100){
    if(a==0)cout << b;
    if(a==1)cout << b*100;
    if(a==2)cout << b*10000;
    }else{
        if(a==0)cout << b+1;
    if(a==1)cout << (b+1)*100;
    if(a==2)cout <<(b+1)*10000;
    }
 
}

Measured memory_bytes: 256
S = input()
T = input()

for i in range(len(S) - len(T)+1):
    target = S[len(S) - len(T) - i:len(S) - i]

    can_search = True
    for key in range(len(T)):
        if target[key] != '?':
            if target[key] != T[key]:
                can_search = False
                break

    if can_search:
        new_key = S[:len(S) - len(T) - i]
        new_key += T
        new_key += S[len(new_key):]
        print(new_key.replace('?', 'a'))
        exit()

print('UNRESTORABLE')


Measured memory_bytes: 9076
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD=1000000007;
int main(){
    int N,K; cin>>N>>K;
    int ans=0;
    vector<int> A(N,1);
    for(int i=0;i<K;i++){
        int d; cin>>d;
        for(int j=0;j<d;j++){
            int a; cin>>a;
            A[a-1]=0;
        }
    }
    for(int i=0;i<N;i++){
        if(A[i]==1)ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	int ans = 1000000007;
	for (int i = 0; i <= s.size() - t.size(); i++) {
		string s1 = s.substr(i, t.size());
		int co = 0;
		for (int j = 0; j < t.size(); j++) {
			if (s1[j] != t[j]) {
				co++;
			}
		}
		if (ans > co) {
			ans = co;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3632