akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {


		public static void main(String[] args) {
	      
	      Scanner sc = new Scanner(System.in);
	      
	      int a = sc.nextInt();
		 int b =sc.nextInt();
           int c =sc.nextInt();
          
          if(a+b+c>=22){
            System.out.println("bust");
          }else if(a+b+c<=21){
            System.out.println("win");
          }
          
	      

	     }
	  }

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

# スペース区切りの整数の入力
n, k = map(int, input().split())
# 文字列のlist化
s = list(input())

#対象箇所
a = s[k-1:k]
#文字列変換
a = ','.join(a)
#対象箇所を小文字に変換
a = a.lower()
#置換
s[k-1:k] = a

s = ''.join(s)
#print(s)
print("{}".format(s))


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
    int N1,N2,N3, N4;
    cin >> N1 >> N2>>N3>>N4;
    if((N1==1 ||N1==9 || N1==7 || N1==4)&& ((N2==1 && N2!=N1) ||(N2==7 && N2!=N1) ||(N2==9 && N2!=N1) || (N2==4 && N2!=N1))
    && ((N3==1 ||N3==9 || N3==7 || N3==4) && N3!=N2 && N3!=N1 )&&((N4==1 ||N4==9 || N4==7 || N4==4) && N4!=N2 && N4!=N1 && N4!=N3))
cout<<"YES";
else
cout<<"NO";

    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[][] isHonest = new int[15][15];
            int[] nb = new int[15];

            for (int i = 0; i < n; i++) {
                int a = in.nextInt();
                nb[i] = a;
                for (int j = 0; j < a; j++) {
                    isHonest[i][in.nextInt() - 1] = in.nextInt() == 1 ? 1 : -1;
                }
            }

            long allOptions = 1L << (long) n;
            int best = 0;
            for (int option = 0; option < allOptions; option++) {
                boolean ok = true;
                int ans = 0;
                for (int i = 0; i < n; i++) {
                    boolean isHonestI = ((option & (1L << i)) == (1L << i));
                    if (isHonestI) {
                        ans++;
                        for (int j = 0; j < nb.length; j++) {
                            boolean isHonestJ = ((option & (1L << j)) == (1L << j));

                            if (isHonest[i][j] != 0 && (isHonest[i][j] == 1) != isHonestJ) {
                                ok = false;
                                continue;
                            }
                        }
                    }
                }
                if (ok)
                    best = Math.max(best, ans);
            }

            out.println(best);
        }

    }
}



Measured memory_bytes: 24148
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int lim,num,sum;
    vector<int>v1;
    while(cin>>num>>lim)
    {
        sum=0;
        for(int i=0;i<lim;i++)
        {
            int temp;
            cin>>temp;
            v1.push_back(temp);
            sum+=v1[i];
        }
        if(num>=sum)
        {
        cout<<(num-sum)<<endl;
        }
        else 
        {
        cout<<"-1"<<endl;
        }
        break;
    }
    
}


Measured memory_bytes: 3700
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int T = sc.nextInt();
    int A = sc.nextInt();
    int[] H = new int[N];
    for (int i = 0; i < N; i++) {
      H[i] = sc.nextInt();
    }
    int ans_index = 0;
    int df = Integer.MAX_VALUE;
    for (int i = 0; i < N; i++) {
      int temp = T * 1000 - (H[i] * 6);
      int df_tmp = Math.abs(temp - 1000 * A);
      if (df > df_tmp) {
        df = df_tmp;
        ans_index = i + 1;
      }
    }
    System.out.println(ans_index);
  }
}

Measured memory_bytes: 21716
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um =unordered_map<pair<string,string>,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

#define debug(v) cout<<#v<<": ";prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S;
    cin >> S;
    reverse(S.begin()+N, S.end());
    unordered_map<string,unordered_map<string,ll>> M;
    for(ll i=0;i<(1LL<<N);++i){
        string s="";
        string t="";
        for(ll j=0;j<N;++j){
            if(i&(1LL<<j))s+=S[j];
            else t+=S[j];
        }
        M[s][t]++;
    }
    S=S.substr(N,N);
    ll ans=0;
    for(ll i=0;i<(1LL<<N);++i){
        string s="";
        string t="";
        for(ll j=0;j<N;++j){
            if(i&(1LL<<j))s+=S[j];
            else t+=S[j];
        }
        if(M[s][t]){ans+=M[s][t];}
    }
    prt(ans);

    return 0;
}



Measured memory_bytes: 97664
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,k;
	cin>>a>>b>>k;
	for(int i=0;i<k;i++){
		if(b>=i+a){
			cout<<i+a<<endl;
		}
	}
	for(int i=b-k+1;i<=b;i++){
		if(a+k<=i){
			cout<<i<<endl;
		}
	}
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	s := next()

	n := len(s)
	for i := 0; i < n-1; i++ {
		if i < n-2 && s[i] == s[i+2] {
			puts(i+1, i+3)
			return
		} else if s[i] == s[i+1] {
			puts(i+1, i+2)
			return
		}
	}

	puts(-1, -1)
}


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

//#define DEBUG

using namespace std;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void solve(){
    uint32_t N, X ;
    cin >> N >> X ;
    std::vector<uint32_t> L;
    L.reserve(N);
    for(uint32_t i = 0 ; i < N ; ++i){
        uint32_t l ;
        cin >> l;
        L.push_back(l);
    }
    uint32_t D = 0;
    for(uint32_t i = 0 ; i < N ; ++i){
       D = D + L[i];
       if( D > X) 
       {
           cout << i + 1 << endl;
           return;
       }
    }
    cout << N + 1 << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main(){
  int n,sum=0,k;
  cin >> n;
  k=n;
  while(k>0){
    sum+=k%10;
    k=k/10;
  }
  if(n%sum==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let k = get!(usize);
    
    let s = get().as_bytes();
    
    for i in 0..n {
        if i+1 == k {
            print!("{}", (s[i] + (b'a' - b'A')) as char);
        } else {
            print!("{}", s[i] as char);
        }
    }
    println!();
    
}


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

int dp[5005][5005]; //グローバルだと0初期化される

int main(void){
    int n;
    string s;
    cin >> n >> s;
    for(int i=n-1;i>=0;--i){
        for(int j = n-1;j>=0;--j){
            if(s[i] != s[j]){
                dp[i][j] = 0;
            }
            else{
                dp[i][j] = dp[i+1][j+1] + 1;
            }
        }
    }
    int ans = 0;
    rep(i,n){
        rep(j,n){
            if(i>=j)continue;
            int  now = min(dp[i][j],j-i);
            ans = max(ans,now);
        }
    }
    cout << ans <<endl;
    
    return 0;
}











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

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

  int H[N];
  bool gh[N];
  for (int i = 0; i < N; i++) {
    cin >> H[i];
    gh[i] = true;
  }

  for (int i = 0; i < M; i++) {
    int t, t2;
    cin >> t >> t2;
    t--;
    t2--;
    if (H[t] > H[t2]) {
      gh[t2] = false;
    } else if (H[t2] > H[t]) {
      gh[t] = false;
    } else {
      gh[t] = false;
      gh[t2] = false;
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (gh[i] == true) ans++;
  }

  cout << ans << endl;

  return 0;
}


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

int used[10];

void solve() {
    int n, k, v;
    cin >> n >> k;
    for (int i = 0; i < k; i++) {
        cin >> v;
        used[v] = 1;
    }
    for (; ; n++) {
        int isok = 1;
        int nn = n;
        while (nn > 0) {
            if (used[nn % 10] == 1) {
                isok = 0;
                break;
            } else {
                nn /= 10;
            }
        }
        if (isok) {
            cout << n;
            return;
        }
    }
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
    return 0;
}


Measured memory_bytes: 256
while True:
	str = input();
	if (str == '0'):
		break;
	
	scorea = 0;
	scoreb = 0;
	for i in range(1, len(str)):
		if (str[i] == 'A'):
			scorea += 1;
		else:
			scoreb += 1;
	
	if (scorea > scoreb):
		scorea += 1;
	else:
		scoreb += 1;
	
	print(scorea, scoreb);

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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	string S;
	cin >> N >> S;
	int res = 0;
	for (int i = 1; i < N; i++) {
		auto s = S.substr(0, i);
		auto t = S.substr(i, N - i);
		sort(s.begin(), s.end());
		s.erase(unique(s.begin(), s.end()), s.end());
		sort(t.begin(), t.end());
		t.erase(unique(t.begin(), t.end()), t.end());
		string u;
		set_intersection(s.begin(), s.end(), t.begin(), t.end(), back_inserter(u));
		res = max(res, (int)u.size());
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD3 1000000000
#define MOD2 998244353 
float PHI = 1.6180339;
const float  PI_F=3.14159265358979f;
#define MAX 1000 m
#define endl "\n"    
#define manhunt 32 
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define pi 3.1415926535897932384626433
//typedef long long float;
#define int long long
//#define double long double
typedef pair<int, int> pii;
//#define float unsigned long long
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define CHAR_SIZE 26 

int modpow(int x, int n, int m) { if (n == 0) return 1%m; long long u = modpow(x,n/2,m); u = (u*u)%m; if (n%2 == 1) u = (u*x)%m; return u; } 


int add(int x, int y,int m) 
{
	x += y;
	if (x >= m) return x - m;
	return x;
}
int sub(int x, int y) 
{
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
int inv(int a, int m = MOD2)
{
	return modpow(a, m - 2, m);
}
int mul(int a, int b,int m) 
{
	return (long long) a * b % m;
}


int nCrModp(int n, int r, int p) 
{ 
    int C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (int i = 1; i <= n; i++) 
    { 
        for (int j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 

bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
    if(a.first==b.first)
    return a.second<b.second;
      return (a.first > b.first); 
       //return (a.first-a.second)>(b.first-b.second);
}

vector<int> z_function(string &s)
{
	int n=s.size();
	vector<int> z(n);
	for(int i=1,l=0,r=0;i<n;i++)
	{
		if(i<=r)
			z[i]=min(r-i+1, z[i-l]);
		while(i+z[i]<n && s[z[i]]==s[i+z[i]])
			z[i]++;
		if(i+z[i]-1>r)
			l=i, r=i+z[i]-1;
	}
	return z;
}

bool isprime(int n) 
{ 
    if (n <= 1)  return false; 
  
    for (int i=2; i*i<=n; i++) 
        if (n%i == 0) 
            return false; 
  
    return true; 
}

void SieveOfEratosthenes(int n, bool isPrime[]) 
{ 
    isPrime[0] = isPrime[1] = false; 
    for (int i=2; i<=n; i++) 
        isPrime[i] = true; 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (isPrime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                isPrime[i] = false; 
        } 
    } 
}


int32_t main()
{
    /* freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout); */
    FAST
    cout << fixed << setprecision(16);

    string s;
    cin>>s;
    if(s[s.length()-1]=='s')
    s+="es";
    else
    s+="s";
    cout<<s<<endl;
    
    
    
    
    return 0;
}

Measured memory_bytes: 3664
use proconio::input;

fn main() {
    input! {
        n: u64,
    }

    let mut ans = 0;
    for i in 1..=n {
        if i % 3 != 0 && i % 5 != 0 {
            ans += i;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2176
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>

#define MOD 998244353

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))

typedef long long int64;

int main(void){

    int N;
    scanf("%d",&N);
    
    char S[N];

    
    scanf("%s",S);
    

    int K;

    scanf("%d",&K);
    
    
    char s=S[K-1];

    for(int i = 0; i < N; i++)
    {
        if(S[i]!=s){
            S[i]='*';
        }
    }

    for(int i = 0; i < N; i++)
    {
        printf("%c",S[i]);
        
    }

    
    
    
    return 0;
}

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

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

  long int balls = A + B;
  long int set = N / balls;
  long int amari = N % balls;
  long int blue;


  if(amari <= A){
    blue = amari;
  }else{
    blue = A;
  }

  cout << A * set + blue << endl;
}

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

ll mod = 1000000007;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    bool ok = false;
    int cnt = 0;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        if(x == y){
            cnt++;
            if(cnt == 3){
                ok = true;
            }
        }
        else{
            cnt = 0;
        }
        
    }
    if(ok)cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 3692
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Throwable {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int N = Integer.parseInt(br.readLine());
        int[] a = readArray(br, N);
        int[] b = readArray(br, N);

        System.out.println(solve(a, b));

        br.close();
    }

    static int[] readArray(BufferedReader br, int size) throws Throwable {
        int[] result = new int[size];
        StringTokenizer st = new StringTokenizer(br.readLine());
        for (int i = 0; i < result.length; ++i) {
            result[i] = Integer.parseInt(st.nextToken());
        }

        return result;
    }

    static int solve(int[] a, int[] b) {
        int result = 0;
        for (int i = 0; i <= 28; ++i) {
            int T = 1 << i;
            if (isXORBitOne(mod2T(a, T), mod2T(b, T), T)) {
                result += T;
            }
        }

        return result;
    }

    static int[] mod2T(int[] values, int T) {
        int[] result = new int[values.length];
        for (int i = 0; i < result.length; ++i) {
            result[i] = values[i] % (2 * T);
        }

        return result;
    }

    static boolean isXORBitOne(int[] a, int[] b, int T) {
        Arrays.sort(b);

        long oneCount = 0;
        for (int ai : a) {
            oneCount += findNum(b, T - ai, 2 * T - 1 - ai) + findNum(b, 3 * T - ai, 4 * T - 1 - ai);
        }

        return oneCount % 2 != 0;
    }

    static int findNum(int[] b, int minTarget, int maxTarget) {
        return findMaxIndex(b, maxTarget) - findMinIndex(b, minTarget) + 1;
    }

    static int findMaxIndex(int[] b, int maxTarget) {
        int result = -1;
        int lower = 0;
        int upper = b.length - 1;
        while (lower <= upper) {
            int middle = (lower + upper) / 2;
            if (b[middle] <= maxTarget) {
                result = middle;
                lower = middle + 1;
            } else {
                upper = middle - 1;
            }
        }

        return result;
    }

    static int findMinIndex(int[] b, int minTarget) {
        int result = b.length;
        int lower = 0;
        int upper = b.length - 1;
        while (lower <= upper) {
            int middle = (lower + upper) / 2;
            if (b[middle] >= minTarget) {
                result = middle;
                upper = middle - 1;
            } else {
                lower = middle + 1;
            }
        }

        return result;
    }
}

Measured memory_bytes: 73772
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int a[5];
	for(int i=0;i<5;i++)cin>>a[i];
	sort(a,a+5);
	for(int i=4;i>=0;i--){
		cout<<a[i];
		i==0?cout<<endl:cout<<" ";
	}
    return 0;
}

Measured memory_bytes: 1176
#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;
  string s = to_string(n);
  bool ok = false;
  for (char c : s) {
    if (c == '7') {
      ok = true;
    }
  }
  cout << (ok ? "Yes" : "No") << endl;

  return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  ll A, B, C, K;
  cin >> A >> B >> C >> K;

  ll ans = 0;
  ans += min(A, K);
  K -= A;
  if (K <= 0) {
    cout << ans << endl;
    return 0;
  }

  K -= B;
  if (K <= 0) {
    cout << ans << endl;
    return 0;
  }

  ans -= min(K, C);
  cout << ans << endl;

  return 0;
}


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

vector<vector<int>> c;
vector<int> pre, in;

void recon(vector<int> pre, vector<int> in) {
	if (pre.size() < 2)
		return;
	int j = 0;
	while (in[j] != pre[0])
		j++;
	if (j == pre.size() - 1) {
		c[pre[0] - 1][0] = pre[1] - 1;
		pre.erase(pre.begin());
		in.pop_back();
		recon(pre, in);
	}
	else if (j == 0) {
		c[pre[0] - 1][1] = pre[1] - 1;
		pre.erase(pre.begin());
		in.erase(in.begin());
		recon(pre, in);
	}
	else {
		c[pre[0] - 1][0] = pre[1] - 1;
		c[pre[0] - 1][1] = pre[j + 1] - 1;

		vector<int> pre1, in1;

		pre1.assign(pre.begin() + 1, pre.begin() + j + 1);
		in1.assign(in.begin(), in.begin() + j + 1);
		pre.erase(pre.begin(), pre.begin() + j + 1);
		in.erase(in.begin(), in.begin() + j + 1);
		recon(pre1, in1);
		recon(pre, in);
	}
}

void post(int id) {
	if (id == -1)
		return;
	post(c[id][0]);
	post(c[id][1]);
	cout << id + 1;
	if (id == pre[0] - 1)
		cout << endl;
	else
		cout << " ";
}

int main()
{
	int n = 0, t = 0;

	cin >> n;

	c.assign(n, { -1, -1 });

	for (int i = 0; i < n; i++) {
		cin >> t;
		pre.push_back(t);
	}

	for (int i = 0; i < n; i++) {
		cin >> t;
		in.push_back(t);
	}

	recon(pre, in);

	post(pre[0] - 1);

	return 0;
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
int n,s1[300010][2],s2[300010][2],ans=2e9;
char c[300010];
int main(){
	scanf("%d",&n);
	scanf("%s",c+1);
	for(int i=1;i<=n;i++){
		s1[i][0]=s1[i-1][0]+(c[i]=='W'?1:0);
		s2[i][0]=s2[i-1][0]+(c[i]=='E'?1:0);
	}
	for(int i=n;i>=1;i--){
		s1[i][1]=s1[i+1][1]+(c[i]=='W'?1:0);
		s2[i][1]=s2[i+1][1]+(c[i]=='E'?1:0);
	}
	for(int i=1;i<=n;i++){
		if(c[i]=='E')
			ans=min(ans,s1[i-1][0]+s2[i+1][1]);
		else
			ans=min(ans,s1[i-1][0]+s2[i+1][1]);
	}
	printf("%d",ans);
}

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

using namespace std;

const int N = (int) 5e5 + 7;
const int M = 777;

int n, q, v[N], sol[N], magic, bucket[N], last[N], first[N], f[N];

struct T {
  int l;
  int r;
  int i;
};

vector<T> lol[M];

bool operator < (T a, T b) {
  return a.r < b.r;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  magic = sqrt(n);
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    bucket[i] = (i - 1) / magic + 1;
    last[bucket[i]] = i;
  }
  for (int i = n; i >= 1; i--) {
    first[bucket[i]] = i;
  }
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    lol[bucket[l]].push_back({l, r, i});
  }
  for (int b = bucket[1]; b <= bucket[n]; b++) {
    for (int i = 1; i <= n; i++) {
      f[v[i]] = 0;
    }
    sort(lol[b].begin(), lol[b].end());
    int until = last[b], jmek = 0;
    for (auto &it : lol[b]) {
      if (it.r <= last[b]) {
        int element = 0;
        for (int j = it.l; j <= it.r; j++) {
          f[v[j]]++;
          element += (f[v[j]] == 1);
        }
        for (int j = it.l; j <= it.r; j++) {
          f[v[j]] = 0;
        }
        sol[it.i] = element;
      } else {
        while (until < it.r) {
          until++;
          f[v[until]]++;
          jmek += (f[v[until]] == 1);
        }
        int element = jmek;
        for (int j = it.l; j <= last[b]; j++) {
          f[v[j]]++;
          element += (f[v[j]] == 1);
        }
        for (int j = it.l; j <= last[b]; j++) {
          f[v[j]]--;
        }
        sol[it.i] = element;
      }
    }
  }
  for (int i = 1; i <= q; i++) {
    cout << sol[i] << "\n";
  }
  return 0;
}


Measured memory_bytes: 20428
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int r, D, x; cin >> r >> D >> x;
  int k=x;
  for (int i=0;i<10;i++){
    cout << r*k-D << endl;
    k=r*k-D;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int k;
  cin>>k;
  int a,b;
  cin>>a>>b;
  for(int i=a;i<=b;i++){
  	if(i%k==0){
  		cout<<"OK";
  		return 0;
  	}
  }
  cout<<"NG";
  return 0;

}

Measured memory_bytes: 3652
package main

import (
	"fmt"
)

func main() {
	const ABC string = "ABC"
	var N int
	var S string
	fmt.Scan(&N)
	fmt.Scan(&S)

	abc_count := 0
	for i := 0; i <= N-len(ABC); i++ {
		for j := 0; j < len(ABC); j++ {
			if S[i+j] != ABC[j] {
				break
			}
			if j == 2 {
				abc_count += 1
			}
		}
	}

	fmt.Printf("%d\n", abc_count)
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<long long>T(N);
	vector<long long>A(N);
	for (int i = 0; i < N; ++i) {
		cin >> T[i] >> A[i];
	}
	long long x = 1;
	long long y = 1;
	for (int i = 0; i < N; ++i) {
		long long xsub = (x + T[i] - 1) / T[i];
		long long ysub = (y + A[i] - 1) / A[i];
		x = max(xsub, ysub)*T[i];
		y = max(xsub, ysub)*A[i];
	}
	cout << (long long)(x + y) << endl;
	return 0;
}


Measured memory_bytes: 3616
n, m = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)

bc = sorted([list(map(int, input().split()))
             for _ in range(m)], key=lambda x: x[1], reverse=True)

ans = 0
for b, c in bc:
    for _ in range(b):
        if not A:
            break
        a = A.pop()
        ans += max(a, c)
else:
    ans += sum(A)

print(ans)

Measured memory_bytes: 33736
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	double A, B, H, M; 
	cin >> A >> B >> H >> M;
	double pi = acos(-1);  
	double angle = abs(H / 6.0 - 11.0 / 360.0 * M) * pi; 
	double dist = pow(A * A + B * B - 2 * A * B * cos(angle), 0.5);
	cout.precision(15); 
	cout << dist << "\n";  
}

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

#define mem(f, v) memset(f,v,sizeof(f))
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);

typedef long long ll;
const int maxn = 100010;
const int inf = ~(1u << 31u);
const ll linf = ~(1llu << 63u);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int m;
    cin >> m;
    ll res = 0, sum = 0;
    for(int i = 1; i <= m; i ++){
        ll d, c;
        cin >> d >> c;
        res += c;
        sum += d * c;
    }
    cout << res - 1 + (sum - 1) / 9 << endl;
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //freopen("data.in", "r", stdin);
  int a, b, c;
  cin >> a >> b >> c;
  puts(a+b+c >= 22 ? "bust" : "win");
  return 0;
}

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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(int size) {
        prime.resize(size + 1, 1);
        prime[0] = 0;
        prime[1] = 0;
        FOR(i, 2, size) {
            if (prime[i]) {
                for (int j = 2 * i; j <= size; j += i) {
                    prime[j] = 0;
                }
            }
        }
    }

};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};


ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll N, M;
int d[100];
int g[100][100];

void dfs(int x) {
    if (d[x])return;
    d[x] = 1;
    REP(i, N) {
        if (g[x][i])dfs(i);
    }
}

int main() {

    cin >> N >> M;
    set<pair<int, int>> s;

    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        s.insert(make_pair(a, b));
        g[b][a] = g[a][b] = 1;
    }

    int res = 0;

    for (auto k: s) {
        int a = k.first, b = k.second;
        memset(d, 0, sizeof(d));
        g[b][a] = g[a][b] = 0;
        dfs(0);
        g[b][a] = g[a][b] = 1;
        REP(i, N)if (!d[i]) {
                res++;
                break;
            }
    }

    cout << res << endl;
    return 0;
}



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

using namespace std;

int n;
int arr[3000];
long long memo[2][3000][3000];
bool done[2][3000][3000];

long long dp(bool player, int a, int b)
{
    if (a > b)
        return 0;
    if (done[player][a][b])
        return memo[player][a][b];
    long long res;
    if (!player)
        res = max(arr[a] + dp(!player, a + 1, b), arr[b] + dp(!player, a, b - 1));
    else
        res =  min(dp(!player, a + 1, b) - arr[a], dp(!player, a, b - 1) - arr[b]);

    done[player][a][b] = true;
    memo[player][a][b] = res;
    return res;
}



int main(void)
{
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &arr[i]);
    }
    long long result;
    result = dp(0, 0, n - 1);
    cout << result << endl;
    
}


Measured memory_bytes: 113564
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 100100;
int n;
int a[N];
vector<int> g[N];

void solve(int v, int par)
{
    if ((int)g[v].size() == 1) return;
    ll sum = 0;
    int mx = 0;
    for (int u : g[v])
    {
        if (u == par) continue;
        solve(u, v);
        sum += a[u];
        mx = max(mx, a[u]);
    }
    if (a[v] > sum || sum > 2 * a[v])
    {
        printf("NO\n");
        exit(0);
    }
    int k = sum - a[v];
    if (k > sum - mx)
    {
        printf("NO\n");
        exit(0);
    }
    a[v] -= k;
    return;
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    for (int i = 1; i < n; i++)
    {
        int v, u;
        scanf("%d%d", &v, &u);
        v--;u--;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    if (n == 2)
    {
        if (a[0] == a[1])
            printf("YES\n");
        else
            printf("NO\n");
        return 0;
    }
    int v = 0;
    while((int)g[v].size() == 1) v++;
    solve(v, -1);
    if (a[v] == 0)
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}

Measured memory_bytes: 12800
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<string>
 
#define ll unsigned long long
using namespace std;
int solve()
{
	ll a;
	float b;
	cin >> a;
	cin >> b;
 	ll c = b*100+0.5;
	
	ll d = a*c;
  	ll res = d/100;
	cout << res << endl;
 
	return 0;
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 3744
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.insert(0,0)
a.append(0)

cn = 0
if(a[1]>x):
    cn = a[1]-x
    a[1] = x
for i in range(1,n):
    if(a[i]+a[i+1]>x):
        cn+=a[i]+a[i+1]-x
        a[i+1]=x - a[i]
        #print(cn,i)
        
print(cn)
        

Measured memory_bytes: 63984
#include<stdio.h>
int main(){
   int x;
   scanf("%d",&x);
   if(x%10==2||x%10==4||x%10==5||x%10==7||x%10==9){
      printf("hon");
   }
   if(x%10==0||x%10==1||x%10==6||x%10==8){
      printf("pon");
   }
   if(x%10==3){
      printf("bon");
   }
   return 0;
}

Measured memory_bytes: 1696
from collections import defaultdict as dd

def ri():
    return int(input())

def rl():
    return map(int, input().split())

def rl2():
    return list(rl())

s = input()
if s[-1] in '24579':
    print ('hon')
elif s[-1] in '0168':
    print ('pon')
else:
    print ('bon')


Measured memory_bytes: 64956
#include<bits/stdc++.h>
using namespace std;
int n,a[100010],id[100010];
bool cmp(int x,int y)
{
	return a[x]<a[y];
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		id[i]=i;
	}
	sort(id+1,id+n+1,cmp);
	int ans=0;
	for (int i=2;i<=n;i+=2)
	{
		if (id[i]&1)
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
n,m = map(int, input().split())

line = [[0 for i in range(n)] for j in range(n)]


for i in range(m):
    a,b = map(int, input().split())
    line[a-1][b-1] = 1
    line[b-1][a-1] = 1

stack = [0]
visited = [[0]]
ans = 0

while stack:
    p = stack.pop()
    v = visited.pop()
    for i in range(n):
        if line[p][i]:
            if i not in v:
                if len(v) == n-1:
                    ans += 1
                else:
                    stack.append(i)
                    v.append(i)
                    visited.append([x for x in v])
                    v.pop()

print(ans)


Measured memory_bytes: 3064
//https://atcoder.jp/contests/abc165/tasks/abc165_a
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
  ll K; cin>>K;
  ll A,B; cin>>A>>B;
  ll a=A/K;
  ll b=A/K+1;
  bool ans=false;
  FOR(i,a,b+1){
    ll tmp=i*K;
    if(tmp>=A&& tmp<=B){
      ans=true;
      break;
    }
  }
  cout<<(ans?"OK":"NG")<<endl;
  return 0;
}

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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e6;
const ld pi = acos(-1);
const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 0, (int)A.size()) out << A[i] << " ";
    return out;
}


int32_t main() {
    IOS int n,r=0,ans=0;
    cin>>n;
    string s;   cin>>s;
    fr(i,0,n){
        if(s[i] == 'R') r++;
    }
    fr(i,0,r)
        if(s[i] == 'W') ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3764
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean ok = true;
        for(int i = 0;i < n;i++){
            int num = sc.nextInt();
            if(num%2 == 0){
                if(num%3==0||num%5==0){
                    ok = true;
                }else{
                    ok = false;
                    break;
                }
            }
            
        }
        System.out.println(ok?"APPROVED":"DENIED");
    }
}

Measured memory_bytes: 25044
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int ans = 0;
  int n;
  string s;
  cin >> n >> s;
  for(int i=0;i<n-2;i++){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (auto i=(a); i<(b); ++i)
#define iter(it,c) for (auto it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
const int INF = 2147483647;

map<pair<int,bool>, int> mem;
    ll mod = 1000000007;

string s;
int dp(int at, bool same) {
    if (at == s.size()) {
        return 1;
    }

    pair<int,bool> st(at,same);
    if (mem.find(st) != mem.end()) {
        return mem[st];
    }

    int res = 0;
    rep(d1,0,2) {
        rep(d2,0,2) {
            if ((d1+d2) == (d1^d2)) {
                int t = d1+d2,
                    u = s[at] - '0';
                if (same && t > u) continue;
                res += dp(at+1, same && t == u);
                res %= mod;
            }
        }
    }
    return mem[st] = res;
}

int main() {
    cin >> s;

    cout << dp(0,true) << endl;
    return 0;
}



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

using namespace std;

int N, A[112345][3];
long long dp[112345][3];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i][0] >> A[i][1] >> A[i][2];
	}

	dp[0][0] = A[0][0];
	dp[0][1] = A[0][1];
	dp[0][2] = A[0][2];

	for (int i = 1; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			dp[i][j] = A[i][j] + max(dp[i - 1][(j + 1)%3], dp[i - 1][(j + 2)%3]);
		}
	}

	cout << max(max(dp[N - 1][0], dp[N - 1][1]), dp[N - 1][2]) << endl;
}


Measured memory_bytes: 3840
#include <iostream>
#include <string>

int main() {
	std::string S;
	std::cin >> S;
	if ((std::atoi(S.substr(5, 2).c_str())) > 4)
		std::cout << "TBD" << std::endl;
	else
		std::cout << "Heisei" << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
int main(){
  int N, M;
  while (cin >> N >> M, N){
    int r, t, n, m, s;
    cin >> r;
    vector< vector<pii> > V(M);
    map<pii,int> L;
    for (int i = 0; i < r; ++i){
      cin >> t >> n >> m >> s;
      --m;
      if(s) L[pii(n,m)] = t;
      else V[m].push_back(pii(L[pii(n,m)],t));
    }
    int q, ts, te;
    cin >> q;
    for(int i = 0; i < q; ++i){
      cin >> ts >> te >> m;
      --m;
      sort(V[m].begin(),V[m].end());
      int ans = te-ts;
      for(int j = 0; j < V[m].size(); ++j){
	if(ts >= V[m][j].first) ts = max(ts,V[m][j].second);
	else if(V[m][j].first > te) break;
	else{
	  ans += ts-V[m][j].first;
	  ts = V[m][j].second;
	}
	if(ts >= te) break;
      }
      if(ts < te) ans += ts-te;
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()

{
long long a,b,c,d,e,f,g,h,i,j,k,l,m,n;

cin>>n;

a=n/100;

if(a==4 || a==5) cout<<8<<endl;

if(a==6 || a==7) cout<<7<<endl;

if(a==8 || a==9) cout<<6<<endl;

if(a==10|| a==11) cout<<5<<endl;

if(a==12 || a==13) cout<<4<<endl;

if(a==14 || a==15) cout<<3<<endl;

if(a==16 || a==17) cout<<2<<endl;

if(a==18 || a==19) cout<<1<<endl;
















}


Measured memory_bytes: 3632
//   Rishabh Agarwal
#include <bits/stdc++.h>
#define F first
#define S second
#define MAX 10000003
using namespace std;

typedef long long int ll;
const ll mod = 1e9+7;
const ll INF= 1e18;
long double PI=3.1415926;

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    ll temp=power(a,b/2)%mod;
    if(b%2==0){
        return (temp*temp)%mod;
    }
    else{
        return ((a*temp)%mod*temp)%mod;
    }
}

ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

vector<pair<ll,ll>>v;
vector<ll>::iterator it;
map<ll,ll>mp;

void primeFactors(ll n)  
{  
    while (n % 2 == 0)  
    {  
        mp[2]++;
        n = n/2;  
    }  
    for (ll i = 3; i <= sqrt(n); i = i + 2)  
    {  
        while (n % i == 0)  
        {  
            mp[i]++;
            n = n/i;  
        }  
    }  
    if (n > 2){ 
        mp[n]++; 
    } 
}  

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    //cin>>t;
    t=1;
    //ll c=1;
    while(t--){
        ll n,k;
        cin>>n>>k;
        ll a[n];
        for(ll x=0; x<n; x++){
            cin>>a[x];
        }
        ll dp[n+1][k+1];
        memset(dp,-1,sizeof(dp));
        for(ll y=1; y<=k; y++){
            ll flag=-1;
            for(ll x=0; x<n; x++){
                ll t=y-a[x];
                if(t<0){
                    dp[x][y]=-1;
                    //flag=-1;
                }
                else{
                    if(dp[n][t]==1){
                        dp[x][y]=2;
                        if(flag==-1){
                            flag=0;
                        }
                    }
                    else{
                        dp[x][y]=1;
                        flag=1;
                    }
                }
                //cout<<dp[x][y]<<" ";
            }
            //cout<<"\n";
            if(flag==1){
                dp[n][y]=1;
            }
            else if(flag==0){
                dp[n][y]=2;
            }
            else{
                dp[n][y]=-1;
            }
            //cout<<dp[n][y]<<"\n";
        }
        if(dp[n][k]==1||dp[n][k]==-1){
            cout<<"First\n";
        }
        else{
            cout<<"Second\n";
        }
        mp.clear();  
        v.clear();
        //cout<<"Case #"<<c<<": "<<ans<<"\n";
        //c++;
    }
    return 0;
}

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

int main(){
    int h, w;
    cin >> h >> w;

    vector<vector<int>> a(h, vector<int>(w, 0));

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }
    vector<int> ans;
    int cnt = 0;
    for(int i = 0; i < h; i++){
        if(i % 2 == 0){
            for(int j = 0; j < w; j++){
                if(i == h-1 && j == w-1) break;
                if(a[i][j]%2 != 0){
                    ans.push_back(i+1);
                    ans.push_back(j+1);
                    a[i][j]--;
                    if(j == w-1){
                        ans.push_back(i+2);
                        ans.push_back(w);
                        a[i+1][w-1]++;
                    }
                    else{
                        ans.push_back(i+1);
                        ans.push_back(j+2);
                        a[i][j+1]++;
                    }
                    cnt++;
                }
            }
        }
        else{
            for(int j = w-1; j >= 0; j--){
                if(i == h-1 && j == 0) break;
                if(a[i][j]%2 != 0){
                    ans.push_back(i+1);
                    ans.push_back(j+1);
                    a[i][j]--;
                    if(j == 0){
                        ans.push_back(i+2);
                        ans.push_back(1);
                        a[i+1][0]++;
                    }
                    else{
                        ans.push_back(i+1);
                        ans.push_back(j);
                        a[i][j-1]++;
                    }
                    cnt++;
                }
            }
        }
    }

    cout << cnt << endl;

    for(int i = 0; i < cnt; i++){
        cout << ans[4*i] << ' ' << ans[4*i+1] << ' ' << ans[4*i+2] << ' ' << ans[4*i+3];
        cout << endl;
    }
}

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

constexpr long mod = 998244353;
// constexpr long mod = 1000000007;
vector<long> fact, inv;

long mpow(long a, long b) {
  long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b /= 2;
  }
  return res;
}

void init(int n) {
  fact.push_back(1);
  inv.push_back(1);
  for (int i = 0; i < n; i++) {
    fact.push_back(fact.at(i) * (i + 1) % mod);
    inv.push_back(mpow(fact.at(i + 1), mod - 2));
  }
}

long qcom(long n, long r) {
  return fact.at(n) * inv.at(r) % mod * inv.at(n - r) % mod;
}

long com(long n, long r) {
  long x = 1, y = 1;
  for (int i = 1; i <= r; i++) {
    x = x * (n - i + 1) % mod;
    y = y * i % mod;
  }
  return x * mpow(y, mod - 2) % mod;
}

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  init(N);
  long ans = 0;
  for (int i = 0; i <= K; i++) {
    (ans += M * mpow(M - 1, N - i - 1) % mod * qcom(N - 1, i) % mod) %= mod;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 6620
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
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(){

  while(1){
  int m,t,p,r ;cin>>m>>t>>p>>r ;
  if(m==0) break ;
  int d[r][4] ;
  rep(i,r){
      rep(j,4){
          cin>> d[i][j] ;
      }
  }
  vector<pair<pair<int,int>,int>> A(t) ;
  rep(i,t){
   A[i].se = i+1 ;
  }
  int pe[t][p] ;
  rep(i,t){
      rep(j,p) pe[i][j]= 0 ;
  }
  rep(i,r){
  
  if(d[i][3]==0){
      A[d[i][1]-1].fi.fi ++ ;
      A[d[i][1]-1].fi.se = (A[d[i][1]-1].fi.se+d[i][0])
      +pe[d[i][1]-1][d[i][2]-1]*20 ;

  }
  else pe[d[i][1]-1][d[i][2]-1]++ ;
  }
  rep(i,t) A[i].fi.se *= -1 ;
  sort(A.rbegin(),A.rend()) ;
  rep(i,t){
      auto x= A[i] ;
      int w= A[i].se ;
      if(t==1){
          cout<<1<<endl ;
          break ;
      }
  if(i==0) cout<<w ;
  else if(i==t-1){
     auto y= A[i-1] ;

      if(x.fi.fi==y.fi.fi && x.fi.se==y.fi.se){
          cout<<"="<< w <<endl;
      }
      else{
          cout<<","<< w <<endl;
      } 
  }
  else{
      auto y= A[i-1] ;

      if(x.fi.fi==y.fi.fi && x.fi.se==y.fi.se){
          cout<<"="<< w ;
      }
      else{
          cout<<","<< w ;
      }
  }
  }

  }
  return 0 ; 
}




Measured memory_bytes: 3092