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

int main() {
  int N,K,R,S,P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;
  
  long long ans=0;
  for(int i=0;i<N;i++){
    if(i>=K){
      if(T[i]==T[i-K]){
        T[i] = 'x';
        continue;
      }
    }
    if(T[i]=='r') ans += P;
    if(T[i]=='s') ans += R;
    if(T[i]=='p') ans += S;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){
  int i, j, k;
  for(i = 1; i <= 9; i++){
    for(j = 1; j <= 9; j++){
      k = i * j;
      printf("%dx%d=%d\n", i, j, k);
	}
  }
  return 0;
}

Measured memory_bytes: 924
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
#include <omp.h>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
int gogo[200][200] = {};
int bobo[200] = {};
int main(){
	int n;
	cin >> n;
	if (n % 2 == 0) {
		for (int i = 1; i <= n; ++i) {
			gogo[i][n - i + 1] = 1;
		}
	}
	else {
		for (int i = 1; i <= n - 1; ++i) {
			gogo[i][n - i] = 1;
		}
	}
	vector<pair<int, int>> nya;
	for (int i = 1; i <= n; ++i) {
		for (int q = i + 1; q <= n; ++q) {
			if (gogo[i][q] == 0) {
				nya.push_back(make_pair(i, q));
			}
		}
	}
	cout << nya.size() << endl;
	for (int i = 0; i < nya.size(); ++i) {
		cout << nya[i].first << " " << nya[i].second << endl;
	}
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(){
    ll k;
    cin >> k;
    string s;
    cin >> s;
    if(s.length()<=k)
        cout << s << endl;
    else {
        string a = s.substr(0, k);
        a += "...";
        cout << a << endl;
    }
    return 0;
}


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

const int MAX_N = 105;
const int MAX_W = 1e5 + 5;

int n_test;
int n, W, w, v;

long long solve() {
    scanf("%d %d", &n, &W);
    long long res[MAX_N][MAX_W] = {{0L}};

    for(int i = 1; i <= n; ++i) {
        scanf("%d %d", &w, &v);
        for(int j = 0; j <= W; ++j)
            res[i][j] = res[i - 1][j];
        for(int j = w; j <= W; ++j) {
            res[i][j] = max(res[i][j], res[i - 1][j - w] + v);
        }
    }
    return res[n][W];
}


int main() {
    n_test = 1;
    //scanf("%d", &n_test);
    for(int i = 0; i < n_test; ++i) printf("%lld\n", solve());
}


Measured memory_bytes: 82304
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------

int main(void){
    ll a;
    string s;
    cin >> a >> s;
    int idx = s.find('.');
    s.erase(s.begin() + idx);
    ll b = stoi(s);
    cout << a * b / 100 << endl;
}


Measured memory_bytes: 3624
import java.util.*

fun main(args: Array<String?>) {
    val scanner = Scanner(System.`in`)

    val s = scanner.next()

    val head = Integer.parseInt(s.substring(0,2))
    val tail = Integer.parseInt(s.substring(2,4))
    
    if (head in 1..12) {
        if (tail in 1..12) {
            println("AMBIGUOUS")
        } else {
            println("MMYY")
        }
    } else {
        if (tail in 1..12) {
            println("YYMM")
        } else {
            println("NA")
        }
    }
}

Measured memory_bytes: 29360
#include<bits/stdc++.h>
const int M = 100005 ;
using namespace std ;
inline int read(){
	char c = getchar() ; int x = 0 , w = 1 ;
	while(c>'9'||c<'0'){ if(c=='-') w = -1 ; c = getchar() ; }
	while(c>='0'&&c<='9'){ x = x*10+c-'0' ; c = getchar() ; }
	return x*w ;
}
int n , m ;
struct E{
	int st , ed ;
}p[M];
inline bool Cmpr(E a , E b){return a.ed < b.ed ;}
inline bool Cmpl(E a , E b){return a.st < b.st ;}
int Ans ;
int r[M] ;
int vis[M] ;
int main(){
	n = read() ; m = read() ;  
	for(int i = 1 ; i <= m ; i ++ ){
		p[i].st = read() ; p[i].ed = read() ; 
	}
	if(m == 0 ){
		cout << 0 << endl ;
		return 0 ;
	}
	if(m == 1){
		cout << 1 << endl ;
		return 0 ;
	}
	sort(p + 1 , p + m + 1 , Cmpr) ;
	for(int i = 1 ; i <= m ; i ++ ) r[i] = p[i].ed , ++ vis[r[i]];
	int upp = 1 ;
	sort(p + 1 , p + m + 1 , Cmpl) ;
	for(int i = 1 ; i <= m ; i++){
		if(p[i].st >= r[upp]){
			++Ans ;
			while((r[upp] <= p[i].st || vis[r[upp]] == 0 ) && upp < m) upp++ ;
		}
		vis[p[i].ed] -- ; 
	}
	cout << Ans + 1  << endl ;
	return 0 ;
}

Measured memory_bytes: 1792
import sys

def S(): return sys.stdin.readline().rstrip()

A,B,C,D = map(int,S().split())

from math import gcd

def f(n):  # 1からnまでCでもDでも割り切れない自然数の個数
    return n-n//C-n//D+n//(C*D//gcd(C,D))

print(f(B)-f(A-1))

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

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

  if (a[0] != 0) {
    cout << -1 << endl;
    return 0;
  }

  long long ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] > a[i-1] + 1) {
      cout << -1 << endl;
      return 0;
    }
    if (a[i] == a[i-1] + 1) {
      ans += 1;
    } else {
      ans += a[i];
    }
  }
  cout << ans << endl;

  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll find_min(vector<ll> & x, ll exclude){
	ll idx;
	ll mi = (1ll << 60);
	REP(i, x.size()){
		if(i == exclude) continue;
		if(mi >= x[i]){
			mi = x[i];
			idx = i;
		}
	}
	return idx;
}

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

    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    ll mi = (1ll << 60);
    REP(i, n) mi = min(mi, a[i]);

    vector<ll> res;
    ll mdx = find_min(a, -1);
    REP(i, n){
    	a[i]--;
    	if(i != mdx) res.push_back(i);
    }
    res.push_back(mdx);
    k--;

    bool flag = true;
    while(1){
    	ll tdx = find_min(a, mdx);
    	REP(i, n){
    		if(i == mdx) continue;
    		a[i]--;
    		if(a[i]<0){
    			flag = false;
    			break;
    		}
    		if(i != tdx) res.push_back(i);
    	}
    	if(!flag) break;
    	res.push_back(tdx);
    	//cout << res << endl;

    	k--;
    	if(k < 0){
    		flag = true;
    		break;
    	}
    	mdx = tdx;
    }
    if(flag){
    	cout << res.size() << endl;
    	REP(i, res.size()){
    		cout << res[i]+1 << " ";
    	}
    	cout << endl;
    }else{
    	cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true){
            int n = sc.nextInt();
            if (n==0) break;
            String[] formula = new String[n];

            for (int i = 0; i < n; i++) {
                formula[i] = sc.next();
            }

            System.out.println(((n==1)?Integer.parseInt(formula[0]):dfs(formula, 0, n)));
        }
    }

    static int dfs(String[] formula, int s, int e) {
        int num = (formula[s].charAt(formula[s].length()-1)=='+')?0:1;
        int j = 0, ans = 1;
        for (int i = s+1; i < e; i++) {
            if(formula[i].charAt(formula[i].length()-1)!='*'&&formula[i].charAt(formula[i].length()-1)!='+'){
                ans = ((num==0)?ans+(formula[i].charAt(formula[i].length()-1) - '0'):ans*(formula[i].charAt(formula[i].length()-1) - '0'));
            }else {
                for (j = i+1; j < e; j++) {
                    if (formula[j].length()==formula[i].length()) break;
                }
                ans = ((num==0)?ans+dfs(formula, i, j):ans*dfs(formula, i, j));
                i = j-1;
            }
        }
        return (num==0)?ans-1:ans;
    }
}

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

long f1(long n, int p) {
  if (n == 0) return 0;
  return n / p + f1(n / p, p);
}

long f2(long n, int p) {
  if (n % 2 == 1) {
    return f1(n, p) - f2(n - 1, p);
  }
  long res = f1(n / 2, p);
  if (p == 2) res += n / 2;
  return res;
}

int main() {
  long N;
  cin >> N;
  if (N & 1) return cout << 0 << "\n", 0;
  cout << f2(N, 5) << "\n";
}

Measured memory_bytes: 256
n_str = input()
n = int(n_str)
digit = len(n_str)
top = int(n_str[0])

def calc_add(digit):
    return (3 ** (digit) - ((2 ** (digit)) * 2) + 1) if digit >= 2 else 0 
# 前項
answer = 0
if(digit > 3):
    for(pre_digit) in range(3, digit):
        answer += calc_add(pre_digit - 1) * 3
# 最大桁に3,5,7が含まれる場合
add = calc_add(digit - 1)
if(top > 3):
    # 1パターン追加
    answer += add
if(top > 5):
    # 2パターン追加
    answer += add
if(top > 7):
    # 3パターン追加
    answer += add

if (top == 3 or top == 5 or top == 7):
    # ややこなのでforチェックする.
    # チェックするリストを作成
    chk_list = []
    char_list = ["3", "5", "7"]
    counter = 0
    while True:
        string = str(top)
        cp_counter = counter
        for index in reversed(range(0, (digit - 1))):
            string += char_list[(cp_counter // (3 ** (index)))]
            cp_counter -=  (3 ** (index)) * (cp_counter // (3 ** (index)))
        if int(string) <= n:
           chk_list.append(tuple(string))
        counter += 1
        if counter >= 3 ** (digit - 1):
            break
    # チェック
    for string_number in chk_list:
        count3 = 0
        count5 = 0
        count7 = 0
        for num in string_number:
            if(int(num) == 3):
                count3 += 1
            elif(int(num) == 5):
                count5 += 1
            elif(int(num) == 7):
                count7 += 1 
            else:
                break
        else:
            if(count3 != 0 and count5 != 0 and count7 != 0):
                answer += 1
print (answer)

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
#define INF 1e18
#define NINF INT_MIN

#define nax 200005


void solve(){
	
	int n,k;
	cin>>n>>k;
	int arr[n];
	rep(i,0,n)
		cin>>arr[i];
	sort(arr,arr+n);

	int sum=0;
	rep(i,0,k){
		sum+=arr[i];
	}
	cout<<sum<<endl;
	
}	

signed main(){
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand (static_cast <unsigned> (time(0)));
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3664
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1 == 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

bool isPrime(int x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)
            return false;
    }
    if (x == 1)
        return false;
    return true;
}

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}
int maxl = 1e18;
int a[100005];
int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int n;
        cin >> n;
        //int a[n];
        int c = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            if (a[i] == 0) {
                cout << 0;
                exit(0);
            }
        }
        if (c > 0) {
            cout << 0 << endl;
            continue;
        }
        int sum = 1;
        for (int i = 0; i < n; i++) {
            if (a[i] > maxl / sum) {
                sum = -1;
                cout << -1;
                exit(0);
            }
            else {
                sum *= a[i];
            }
        }
        cout << sum;
    }
    return 0;
}


Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std; void solve(); int main(){cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); solve();}
using ll=int_fast64_t; using ld=long double; using pll=pair<ll,ll>; using pld=pair<ld,ld>;
#define fi first
#define se second
#define SELECTOR(_1,_2,_3,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
template<class T> void vecout(const T &v){for(auto it=v.begin();it!=v.end();++it,cout<<(it!=v.end()?" ":"\n"))cout<<*it;}

void solve(){
  ll n; cin>>n;
  vector<ll> p(n);
  vector<ll> idx(n+1);
  rep(i,n){
    cin>>p[i];
    idx[p[i]]=i;
  }
  set<ll> s;
  ll ans=0;
  for(ll x=n;x>0;--x){
    ll i=idx[x];
    auto it1=s.insert(i).fi;
    auto it2=it1;
    vector<ll> l(2,-1), r(2,n);
    rep(j,2){
      if(it1--==s.begin()) break;
      l[j]=*it1;
    }
    rep(j,2){
      if(++it2==s.end()) break;
      r[j]=*it2;
    }
    ans+=x*((i-l[0])*(r[1]-r[0])+(l[0]-l[1])*(r[0]-i));
  }
  cout<<ans<<"\n";
}


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

int main() {
  int n;cin>>n;
  map<string,int> mp;
  rep(i,n){
    string s;cin>>s;
    mp[s]++;
  }
  int ans=0;
  for(auto p:mp)ans=max(ans,p.second);
  for(auto p:mp){
    if(p.second!=ans)continue;
    cout<<p.first<<endl;
  }
}

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

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(){
  ll n;
  cin >> n;
  ll sum =0;
  map<ll,ll> mp;
  rep(i,n){
    ll a;
    cin >> a;
    sum += a;
    mp[a]++;
  }

  ll q;
  cin >> q;
  rep(i,q){
    ll b,c;
    cin >> b >> c;
    sum -= mp[b]*b;
    sum += mp[b]*c;
    mp[c] += mp[b];
    mp.erase(b);
    cout << sum << endl;
  }


  return 0;
} 



Measured memory_bytes: 7548
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  string ans = "No";
  if (N >= 4) {
    if (S.at(0) == 'Y' && S.at(1) == 'A' && S.at(2) == 'K' && S.at(3) == 'I') {
      ans = "Yes";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2019/06/02
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	char S[16] = {0};
	int i = 0, win = 0, k = 0;
	scanf("%s", S);
	k = strlen(S);
	for(i = 0; i < k; i++) {
		if(S[i] == 'o') {
			win++;
		}
	}
	if((win + (15-k)) >= 8) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxn=500010;
long long a,b,c,d;
int n;
int main(){
    cin>>n>>a>>b>>c>>d;
    long long lb,rb;
    for(register int i=0;i<n;i++){
        lb=a+i*c-(n-i-1)*d;
        rb=a+i*d-(n-i-1)*c;
        if((b>=lb)&&(b<=rb)){
            printf("YES\n");return 0;
        }
    }
    printf("NO\n");
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func getNext(x int) (y int) {
	if x%2 == 0 {
		y = x / 2
	} else {
		y = 3*x + 1
	}
	return
}

func main() {
	var s int
	fmt.Scan(&s)
	ls := []int{s}
L:
	for {
		next := getNext(ls[len(ls)-1])
		ls = append(ls, next)
		for i := 0; i < len(ls)-1; i++ {
			if ls[i] == next {
				break L
			}
		}
	}
	fmt.Println(len(ls))
}


Measured memory_bytes: 512
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1])
jikoku=0
for i in range(n):
  jikoku+=ab[i][0]
  if jikoku>ab[i][1]:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 53600
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

x, y = list(map(int, input().split()))
if x in a:
  if y in a:
    ans = 'Yes'
  else:
    ans = 'No'
elif x in b:
  if y in b:
    ans = 'Yes'
  else:
    ans = 'No'
else:
  ans = 'No'
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll h, w;
  cin >> h >> w;
  vector <vector <char>> v(h, vector <char> (w));
  rep(i, h) {
    rep(j, w) {
      cin >> v.at(i).at(j);
    }
  }
  rep(i, 2*h) {
    rep(j, w) {
      cout << v.at((i+2)/2-1).at(j);
      if (j == w-1) cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void){
	int n,m,x,count=0;
	int *a;
	scanf("%d %d %d",&n,&m,&x);
	a = (int*)malloc(sizeof(int)*m);
	for(int i=0;i<m;i++) scanf("%d",&a[i]);
	for(int i=0;i<m-1;i++) if(a[i] < x) count++;
	printf("%d\n",count < m/2 ? count : m-count);
	return 0;
}


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

int main(){
    ll n;
    cin >> n;
    vector<ll> c(n);
    vector<ll> s(n);
    vector<ll> f(n);
    rep(i,n-1){
        cin >> c[i] >> s[i] >> f[i];
    }

    rep(i,n-1){
        ll x = 0;
        for(ll j = i; j < n-1; j++){
            if(x < s[j]){
                x = s[j] + c[j];
            }else{
                if(x%f[j]==0){
                    x += c[j];
                }else{
                    x = (x/f[j]+1)*f[j]+c[j];
                }
            }
        }
        cout << x << endl;
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int n,a;cin>>n;
    lint ans1=0,ans2=0;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin>>a;vec[i]=a;
    }
    int tmp=0;
    for(int i=0;i<n;i++){
        tmp+=vec[i];
        if(i%2==0){
            if(tmp<=0){
                ans1+=(1-tmp);
                tmp=1;
            }
        }
        else{
            if(tmp>=0){
                ans1+=(1+tmp);
                tmp=-1;
            }
        }
    }
    tmp=0;
    for(int i=0;i<n;i++){
        tmp+=vec[i];
        if(i%2==1){
            if(tmp<=0){
                ans2+=(1-tmp);
                tmp=1;
            }
        }
        else{
            if(tmp>=0){
                ans2+=(1+tmp);
                tmp=-1;
            }
        }
    }
    cout<<min(ans1,ans2)<<endl;
}


Measured memory_bytes: 3748
from collections import Counter
N,K=map(int,input().split())
A=list(map(int,input().split()))
c=Counter(A)
count=0
if len(c)<=K:
    print(0)
else:
    x=c.most_common()[K:]
    for a in x:
        count+=a[1]
    print(count)

Measured memory_bytes: 39352
h, w = map(int, input().split())
f = [input() for _ in range(h)]
for i in range(h):
  for j in range(w):
    if f[i][j] == '#':
      print('#', end = "")
      continue
    cnt = 0
    for k in range(i-1, i+2):
      if k < 0 or h <= k:
        continue
      for l in range(j-1, j+2):
        if l < 0 or w <= l:
          continue
        if f[k][l] == '#':
          cnt += 1
    print(cnt, end = "")
  print()

Measured memory_bytes: 3444
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::ops::Add;

fn main() {
    let (_n, k) = get!(usize, usize);
    let mut ll = get!(String).split_whitespace().map(|i| i.parse::<i32>().unwrap()).collect::<Vec<_>>();
    ll.sort();
    ll.reverse();
    println!("{}", ll.into_iter().take(k).fold(0, Add::add));
}

Measured memory_bytes: 4352
n = int(input())

a = list(map(int, input().split()))
a.sort()

c = [0] * (10**6+1)
for i in a:
    c[i] += 1

uni = []
a = list(set(a))

for i in a:
    if c[i] == 1:
        uni.append(i)

b = [0 for _ in range(10**6+1)]

for i in a:
    for j in range(i*2, 10**6+1, i):
        b[j] = 1

cnt = 0
for i in uni:
    if b[i] == 0:
        cnt += 1

print(cnt)

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

#define BUF_SIZE 1500000
#define min(a, b) ((a) < (b) ? (a) : (b))

int main(void) {
  char buf[BUF_SIZE];
  FILE *fp = stdin;

  if(!fgets(buf, BUF_SIZE, fp)) return 0;

  int num;
  sscanf(buf, "%d", &num);

  if(!fgets(buf, BUF_SIZE, fp)) return 0;

  char *tmpbuf = buf;
  int i;
  long sum_plus = 0;
  long sum_minus = 0;

  long res_plus = 0;
  long res_minus = 0;
  for(i = 0; i < num; i++) {
    char *tmp = strtok(tmpbuf, " ");
    long n = strtol(tmp, NULL, 10);
    sum_plus += n;
    sum_minus += n;
    if (i%2) { // odd
      // start_plus requires sum of minus
      if(sum_plus >= 0) {
        res_plus += sum_plus + 1;
        sum_plus = -1;
      }
      if(sum_minus <= 0) {
        res_minus += 1 - sum_minus; // -1 - n
        sum_minus = 1;
      }
    } else { // even
      if(sum_plus <= 0) {
        res_plus += 1 - sum_plus; // -1 - n
        sum_plus = 1;
      }
      if(sum_minus >= 0) {
        res_minus += sum_minus + 1;
        sum_minus = -1;
      }
    }
    tmpbuf = NULL;
  }

  long res = min(res_plus, res_minus);
  printf("%ld\n", res);

  return 0;
}

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

int main(){
  int a,b;
  cin>>a>>b;
  if(a*b%2==0) cout<<"Even"<<endl;
  else cout<<"Odd"<<endl;
}

Measured memory_bytes: 256
N=int(input())
A=[int(x) for x in input().split()]

ans=0
s=0
for i in range(N):
  s+=A[i]
  if i % 2 ==0:
    if s<=0:
      ans+=(abs(s)+1)
      s=1
  else:
    if s>=0:
      ans+=(abs(s)+1)
      s=-1

ans2=0
s2=0
for i in range(N):
  s2+=A[i]
  if i % 2 ==0:
    if s2>=0:
      ans2+=(abs(s2)+1)
      s2=-1
  else:
    if s2<=0:
      ans2+=(abs(s2)+1)
      s2=1
print(min(ans,ans2))


Measured memory_bytes: 14468
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define last Last
#define int long long
const int N=1e6+5;
int n,m,k,cnt,gs,fa[N];
struct node{
	int x,y,opt;
}q[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
int find(int x)
{
	if(fa[x]==x)return x;
	fa[x]=find(fa[x]);
	return fa[x];
}
signed main()
{
	n=read();m=read();k=read();cnt=n;
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=k;i++)
	{
		q[i].x=read()+1,q[i].y=read()+1,q[i].opt=read();
		if(q[i].opt==0)
		{
			if(find(q[i].x)==find(q[i].y))continue;
			fa[find(q[i].x)]=find(q[i].y);
			cnt--;
		}
		else gs++;
	}
	if(m==n-1)
	{
		if(gs)puts("No");
		else puts("Yes");
		return 0;
	}
	for(int i=1;i<=k;i++)
	{
		if(q[i].opt==1)
		{
			if(find(q[i].x)==find(q[i].y)){puts("No");return 0;}
		}
	}
	if(m-(n-cnt)<=cnt*(cnt-1)/2)puts("Yes");
	else puts("No");
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define all(x, r) (x), (x)+(r)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define exst(x, data) (data).find(x) != (data).end()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define np next_permutation
#define b32 bitset<32>

using ll = long long;
using Pii = pair<int,int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;

const long long MOD = 1000000000 +7;

ll fact[200000];

long long pow_mod(long long a, long long b) {
    if(b == 0) return 1;

    long long p = pow_mod(a, b/2);
    if(b%2 == 0) {
        return p * p % MOD;
    } else {
        return (p * p) % MOD * a % MOD;
    }
}

long long solve_sprob(int h, int w) {
    return fact[h+w-2] * pow_mod(fact[h-1],MOD-2) % MOD * pow_mod(fact[w-1],MOD-2) % MOD;
}

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

    int H, W, A, B; cin >> H >> W >> A >> B;

    // (H+W-2)! / ( (H-1)! (W-1)! ) mod 1000000007
    fact[0] = 1;
    REP(i,1,H+W-1) fact[i] = (ll)fact[i-1] * i % MOD;

    ll ans = 0;
    REP(h,1,H-A+1) {
        ans = (ans + solve_sprob(h, B) % MOD * solve_sprob(H-h+1, W-B) % MOD) % MOD;
        // cout << solve_sprob(h, B) << " " << solve_sprob(H-h+1, W-B) << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;
inline LL read(){
	LL ret=0,p=1;
	char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') p=-1;ch=getchar();}
	while (ch>='0' && ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return ret*p;
}
int n;
LL C;
LL a[100000+3];
LL x1[100000+3],x2[100000+3];
LL l1[100000+3],l2[100000+3];
LL t1[100000+3],t2[100000+3],t3[100000+3],t4[100000+3];
LL ans=0;
inline LL max(LL a,LL b){
	if (a<b) return b;
	return a;
}
int main(){
	n=read();C=read();
	for (int i=1;i<=n;i++){
		l1[i]=read();a[i]=read();
		l2[i]=C-l1[i];
	}
	memset(x1,0,sizeof(x1));
	memset(x2,0,sizeof(x2));
	memset(t1,0,sizeof(t1));
	memset(t2,0,sizeof(t2));
	memset(t3,0,sizeof(t3));
	memset(t4,0,sizeof(t4));
	for (int i=1;i<=n;i++){
		x1[i]=x1[i-1]+a[i];x2[i]=x2[i-1]+a[n-i+1];
	}
	for (int i=1;i<=n;i++){
		t1[i]=max(t1[i-1],x1[i]-l1[i]);
		t2[i]=max(t2[i-1],x2[i]-l2[n-i+1]);
		t3[i]=max(t3[i-1],x1[i]-l1[i]*2);
		t4[i]=max(t4[i-1],x2[i]-l2[n-i+1]*2);
	}
	for (int i=1;i<=n;i++){
		 ans=max(ans,t1[i]+t4[n-i]);
		 ans=max(ans,t2[i]+t3[n-i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  string A,B,C;cin>>A>>B>>C;
  reverse(ALL(A));reverse(ALL(B));reverse(ALL(C));
  int turn=0;
  while(true){
    char hand;
    if(turn==0){
      if(A.size()==0){
        print("A");
        re 0;
      }
      hand = A.at(A.size()-1);
      A.pop_back();
      // if(B.size()>0&&B.at(B.size()-1)==hand)B.pop_back();
      // if(C.size()>0&&C.at(C.size()-1)==hand)C.pop_back();
      turn=(int)hand-'a';
    }
    if(turn==1){
      if(B.size()==0){
        print("B");
        re 0;
      }
      hand = B.at(B.size()-1);
      B.pop_back();
      // if(A.size()>0&&A.at(A.size()-1)==hand)A.pop_back();
      // if(C.size()>0&&C.at(C.size()-1)==hand)C.pop_back();
      turn=(int)hand-'a';
    }
    if(turn==2){
      if(C.size()==0){
        print("C");
        re 0;
      }
      hand = C.at(C.size()-1);
      C.pop_back();
      // if(A.size()>0&&A.at(A.size()-1)==hand)A.pop_back();
      // if(B.size()>0&&B.at(B.size()-1)==hand)B.pop_back();
      turn=(int)hand-'a';
    }
  }
}


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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define SORT(v) sort(ALL(v))
//#define scanf scanf_s
typedef pair<int, int> P;

string rev(string s)
{
	reverse(ALL(s));
	return s;
}

int main()
{
	int m;
	cin >> m;
	REP(q, m)
	{
		string s;
		cin >> s;
		set<string> ari;
		ari.insert(s);
		FOR(i, 1, s.size())
		{
			string a = s.substr(0, i);
			string b = s.substr(i, s.size());
			string reva = rev(a);
			string revb = rev(b);
			ari.insert(a + revb);
			ari.insert(reva + b);
			ari.insert(reva + revb);
			ari.insert(b + a);
			ari.insert(b + reva);
			ari.insert(revb + a);
			ari.insert(revb + reva);
		}
		cout << ari.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1292
#include<stdio.h>
int main(void){
    long long int a=0,b=0,c=0,i=0,d=0;
    long long int x,y;
    long long int e = 0;
    while(scanf("%lld%lld",&i,&a) != EOF){
        e=i*a;
        x = 0,y = 0;
        for(b=0;;b++){
            if(a > i){
                c = a;
                a = i;
                i = c;
            }
            if(i%a==0){
                printf("%lld %lld\n",a,e/a);
                break;
            }
            x = i%a;
            y = a;
            a = x;
            i = y;
        }
    }
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include "unistd.h"
using namespace std;
#define WA cout<<"char134217728";exit(0)
#define RE throw
#define TLE sleep(1000)
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, m, c, B[20];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m >> c;
  FOR(i, 0, m) cin >> B[i];
  int ans = 0;
  FOR(j, 0, n){
    int s = c, a;
    FOR(i, 0, m){
      cin >> a;
      s += a * B[i];
    }
    if(s > 0) 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++)

int main(){
  int M, D;
  cin >> M >> D;
    int ans = 0;
    for(int i = 1; i <= M; i++){
      for(int j = 1; j <= D; j++){
        int d10 = j / 10;
        int d1 = j % 10;
        if(d10 >= 2 && d1 >= 2 && d10 * d1 == i) ans++;
      }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int BinarySearch(int*,int,int);
int main(){
  int n,qtw,i,keytw,ans=0;
  scanf("%d",&n);
  int S[n];
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&qtw);
  for(i=0;i<qtw;i++){
    scanf("%d",&keytw);
    if(BinarySearch(S,n,keytw)==1)ans++;
  }
  printf("%d\n",ans);
  return 0;
}

int BinarySearch(int *S,int n,int key){
  int left=0,right=n;
  while(left<right){
    int mid=(left+right)/2;
    if(S[mid]==key)return 1;
    else if(key<S[mid])right=mid;
    else left=mid+1;
  }
  return 0;
}
      




Measured memory_bytes: 2104
import           Control.Applicative
import           Control.Monad
import           Data.List           ((\\))

data Suit
    = Spade
    | Heart
    | Club
    | Dia
    deriving (Eq, Ord)

instance Show Suit where
    show Spade = "S"
    show Heart = "H"
    show Club  = "C"
    show Dia   = "D"

instance Read Suit where
    readsPrec _ "S" = [(Spade, "")]
    readsPrec _ "H" = [(Heart, "")]
    readsPrec _ "C" = [(Club, "")]
    readsPrec _ "D" = [(Dia, "")]

toPair :: String -> (Suit, Int)
toPair xs = (read s, read t)
  where
    [s, t] = words xs

deck :: [(Suit, Int)]
deck = [(s, t) | s <- [Spade, Heart, Club, Dia], t <- [1..13]]

main :: IO ()
main = do
    getLine
    cards <- fmap toPair . lines <$> getContents
    forM_ (deck \\ cards) $ \(s, t) -> do
        putStrLn $ show s ++ " " ++ show t



Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s; cin>>s;
  deque<int>dq;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0') dq.push_back(0);
    if(s[i]=='1') dq.push_back(1);
    if(s[i]=='B'){
      if(dq.empty()) continue;
      else dq.pop_back();
    } 
  }
  for(int i=0; i<dq.size();i++){
    cout<<dq[i];
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ins insert
#define sz(x) (long long)x.size()
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 5;
const ld pi = 3.141592653;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ll INF = __LONG_LONG_MAX__;

using namespace std;

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

vector<bool> vis(N);

void dfs (vector<int> g[], int t){
        vis[t] = true;
        for(int i = 0; i<sz(g[t]); i++){
                if(!vis[g[t][i]]) dfs(g, g[t][i]);
        }
}

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int T = 1;
        //cin>>T;
        while(T--)
        {
                int n, m, i;
                cin>>n>>m;
                vector<int> g[N];
                for(i = 0; i<m; i++){
                        int u, v; cin>>u>>v;
                        g[u].pb(v); g[v].pb(u);
                }
                int cnt = 0;
                for(i = 0; i<N; i++) vis[i] = false;
                for(i = 1; i<=n; i++){
                        if(vis[i] == false){
                                dfs(g, i); cnt++;
                        }
                }
                cout<<cnt - 1;
        }
        return 0;
}

Measured memory_bytes: 9984
X,K,D=map(int,input().split())
x=abs(X)
a=x//D
b=x%D
c=abs(b-D)
if a%2==0:
    even=b
    odd=c
else:
    odd=b
    even=c
if a>K:
    print(abs(X)-K*D)
elif K%2==0:
    print(even)
else:
    print(odd)

Measured memory_bytes: 9124
#include <cstdio>

int n,a[50];

int make_up(int i,int v){
    if (v==0)
        return 1;
    if (i>=n)
        return 0;
    int res=make_up(i+1,v)||make_up(i+1,v-a[i]);
    return res;
}

int main() {
    int i,q,value;
    scanf("%d",&n);
    for (i = 0; i < n; ++i) {
        scanf("%d",&a[i]);
    }
    scanf("%d",&q);
    for (i = 0; i < q; ++i) {
        scanf("%d",&value);
        if (make_up(0,value))
            printf("yes\n");
        else
            printf("no\n");

    }
    return 0;
}

Measured memory_bytes: 2688
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return int64(a)
}

func scanFloat() float64 {
	sc.Scan()
	a, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func scanTextSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = scanText()
	}
	return a
}

func scanSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanFloatSlice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = scanFloat()
	}
	return a
}

func scanInt64Slice(n int64) []int64 {
	a := make([]int64, n)
	for i := int64(0); i < n; i++ {
		a[i] = scanInt64()
	}
	return a
}

// var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	input := scanSlice(2)
	n := input[0]
	m := input[1]

	// maze := make([]string, 0)

	// for i := 0; i < n; i++ {
	// 	maze[i] = make([]string, m)
	// }

	if n <= m {
		fmt.Println("Yes")

	} else {
		fmt.Println("No")

	}

}

type position struct {
	x        int
	y        int
	distanse int
}

func binarySearch(arr []int, number int) int {

	l := -1
	r := len(arr)
	index := 0
	for {
		mid := l + (r-l)/2
		tmp := arr[mid]

		if r-l <= 1 || tmp == number {
			index = mid
			break
		} else if tmp < number {
			l = mid
		} else {
			r = mid
		}
	}
	return index
}

func factorial(n int) int64 {
	sum := int64(1)
	for i := 2; i <= n; i++ {
		sum *= int64(i)
	}
	return sum
}

func deleteNumOfArray(arr []int, position int) []int {
	left := arr[:position]
	r := arr[position+1:]
	appendArr := append(left, r...)
	return appendArr
}


Measured memory_bytes: 640
#include <chrono>
#include <iostream>

using namespace std;
using namespace std::chrono;

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int a, b, c;
  cin >> a >> b >> c;
  cout << (a == b ? c : (a == c ? b : a)) << endl;

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


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

using namespace std;


string f(long long n) {
    if(n == 0) {
        return "";
    }
    n--;
    return f(n / 26) + string(1, 'a' + n % 26);
}

int main() {
    long long n;
    cin >> n;
    cout << f(n) << "\n";
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll q,h,s,d,n,m;
struct node {
	ll v,id;
} e[5];
bool cmp(node a,node b) {
	return a.v<b.v;
}
int main() {
	scanf("%lld %lld %lld %lld %lld",&q,&h,&s,&d,&n);
	if (n==1)
		printf("%lld\n",min(s,min(h*2,q*4)));
	else {
		e[1].id=1; e[1].v=q*8;
		e[2].id=2; e[2].v=h*4;
		e[3].id=3; e[3].v=s*2;
		e[4].id=4; e[4].v=d;
		sort(e+1,e+5,cmp);
		m=0;
		for (int i=1;i<=4&&n>0;i++) {
			int t=e[i].id;
			if (t==4) {
				m+=(n/2)*d;
				n%=2;
				continue;
			}
			if (t==3)
				m+=n*s;
			else if (t==2)
				m+=n*2*h;
			else m+=n*4*q;
			break;
		}
		printf("%lld\n",m);
	}
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input!{
        n: usize,
        k: usize,
    }

    let m = 1_000_000_007;
    let n = n + 1;
    let mut f = vec![0; n + 1];

    for i in 1..n + 1 {
        f[i] = f[i - 1] + i;
    }

    let mut sum = 0;
    for i in k..n + 1 {
        let min = f[i] % m;
        let max = (f[n] - f[n - i]) % m;
        sum += (if max < min { m + max - min + 1 } else { max - min + 1 }) % m;
    }
    println!("{}", sum % m);
}


Measured memory_bytes: 3584
#include <stdio.h>
#include <stdlib.h>
int main() {
  int i,j,N,minj,tmp,count=0;
  int *A;
  scanf("%d",&N);
  if(N<1 || N>100) exit(1);
  A = (int *)malloc(N*sizeof(int));
  for(j=0;j<N;j++)
    {
      scanf("%d",&A[j]);
      if(A[j]<0 || A[j]>100) exit(1);
    }
  for(i=0;i<N;i++)
    {
      minj = i;
      for(j=i;j<N;j++)
	{
	  if(A[j]<A[minj])
	    {
	      minj = j;
	    }
	}
      if(A[minj]<A[i])
	{
	  tmp = A[i];
	  A[i] = A[minj];
	  A[minj] = tmp;
	  count++;
	}
	
    }
  for(j=0;j<N-1;j++)
    {
      printf("%d ",A[j]);
    }
  printf("%d\n",A[j]);
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2084
#include <iostream>

using namespace std;

int main() {
	int K, S;
	cin >> K >> S;

	int count = 0;

	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			if (S - i - j >= 0 && S - i - j <= K) {
				count++;
			}
		}
	}

	cout << count << endl;
	return 0;
}

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

int main(){
    int n;
    while(cin>>n && n!=0){
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        bool ok[n][n]={};
        map<int,vector<int>> mp;
        for(int i=0;i<n;i++) ok[i][i]=true;
        for(int i=0;i<n-1;i++){
            if(abs(a[i]-a[i+1])<=1) ok[i][i+1]=true;
        }

        for(int len=1;len<n;len+=2){
            for(int i=0;i<n-len;i++){
                for(int k=1;k<i+len;k++){
                    if(ok[i][i+k] && ok[i+k+1][i+len]) ok[i][i+len]=true;
                }
                if(abs(a[i]-a[i+len])<=1 && ok[i+1][i+len-1]) ok[i][i+len]=true;
                
                if(ok[i][i+len]) mp[i+len].push_back(len+1);
            }
        }
        
        int dp[n]={};
        for(int i=1;i<n;i++){
            dp[i]=dp[i-1];
            for(auto j:mp[i]){
                if(i-j>=0) dp[i]=max(dp[i],dp[i-j]+j);
                if(i-j==-1) dp[i]=max(dp[i],j);
            }
        }
        cout<<dp[n-1]<<endl;
    }
}


Measured memory_bytes: 3424
#include <stdio.h>
int main(void){
    char s[100];
    int i,j;
    scanf("%s",s);
    for(i=0;s[i]!='\0';i++){
        if(s[i]=='C'){
            for(j=i+1;s[j]!='\0';j++){
                if(s[j]=='F'){
                    printf("Yes\n");
                    return 0;
                }
            }
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128