akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
const int mod = 1000000007;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
};
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n=1):n(n), f(n+1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i]) continue;
primes.push_back(i);
f[i] = i;
for (ll j = i*i; j <= n; j += i) {
if (!f[j]) f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x;}
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0) return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
int main(){
    Sieve s(1000010);
    int n;cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    map<ll,ll> mp;
    for(int i=0; i<n; i++){
        vector<P> v=s.factor(a[i]);
        for(auto p: v){
            if(mp[p.first]<p.second) mp[p.first]=p.second;
        }
    }
    mint ans=0;
    mint sum=1;
    for(auto p: mp){
        for(int i=0; i<p.second; i++){
            sum*=p.first;
        }
    }
    for(int i=0; i<n; i++){
        mint b=sum/a[i];
        ans+=b;
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 5112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[100010];
int main() {
	ll n;
	cin>>n;
	ll cnt=1;
	ll ans=0;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		if(a[i]==cnt){
			cnt++;
		}
		else if(a[i]>cnt){
			if(a[i]%cnt==0){
				ans+=a[i]/cnt-1;
			}
			else{
				ans+=a[i]/cnt;
			}
		}
		if(cnt==1){
			cnt++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1024
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
using namespace std;

int main() {
	int32_t n;
	cin>>n;
	double ans=0;
	for(int32_t i=0;i<n;i++){
		double value=0;
		cin>>value;
		string s;
		cin>>s;
		if(s=="BTC"){
			ans+=380000.0*value;
		}else{
			ans+=value;
		}
	}
	cout << fixed << setprecision(8) << ans;


}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>
#include <set>

using namespace std;


int main() {

    int K;
    cin >> K;


    int numOfEven = K / 2;
    int numOfOdd = (K % 2 == 0) ? K / 2 : K / 2 + 1;

    cout << (numOfEven * numOfOdd) << "\n";

    return 0;
}

Measured memory_bytes: 256
use std::cmp;
use std::collections::BTreeSet;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n = sc.read();
    let s: Vec<i64> = sc.vec(n);

    let mut ans = 0;
    for i in 1..n {
        let mut left_sum = 0;
        let mut right_sum = 0;
        let mut left_cur = 0;
        let mut right_cur = n - 1;
        while left_cur + i < n {
            left_cur += i;
            right_cur -= i;

            if (n - 1) % i == 0 && left_cur >= right_cur {
                break;
            }

            if right_cur <= i {
                break;
            }

            // let a = right_cur;
            // let b = a - i;

            left_sum += s[left_cur];
            right_sum += s[right_cur];
            ans = cmp::max(ans, left_sum + right_sum);
        }
    }

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

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
#define ll long long
#define debug(x) {cerr<<#x<<" = "<<(x)<<endl;}
#define M(x) memset(x,0,sizeof(x))
#define dalao main
using namespace std;
int dalao()
{
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<s.size();i++)
    {
        ans+=s[i]-'0';
        ans%=9;
    }
    if(ans==0) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 3784
N, M = map(int, input().split())
S = []
C = []
for m in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
cnt = -1
man = False
for n in range(1000):
    num = str(n)
    res = True
    if len(num) != N:
        res = False
        continue
    for m in range(M):
        if num[S[m]-1] != str(C[m]):
            res = False
    if res:
        cnt = int(num)
        man = True
        break
if man:
    print(cnt)
else:
    print(cnt)

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

int main() {
	int a,b;
	char op;
	while(true){
		cin>>a>>op>>b;
		if(op=='+'){
			cout<<a+b<<"\n";
		}
		else if(op=='-'){
			cout<<a-b<<"\n";
		}
		else if(op=='*'){
			cout<<a*b<<"\n";
		}
		else if(op=='/'){
			cout<<a/b<<"\n";
		}
		else{
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int H, W;
    cin >> H >> W;
    vector<string> A(H);
    rep(i, H) cin >> A[i];
    int cnt = 0;
    rep(i, H) rep(j, W){
        if(A[i][j] == '#') cnt++;
    }
    
    if(cnt == H + W - 1){
        output("Possible");
    }
    else{
        output("Impossible");
    }
    
    
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int D = stdIn.nextInt();
		double X[] = new double[N];
		double Y[] = new double[N];
		double ans = 0;
		int a = 0;
		for(int i = 0; i < N; i++){
			X[i] = stdIn.nextDouble();
			Y[i] = stdIn.nextDouble();
			ans = X[i] * X[i] + Y[i] * Y[i];
			if(Math.sqrt(ans) <= D ){
				a++;
			}
		}
		System.out.println(a);

		stdIn.close();
	}
}

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

int arr[102],dp[2][100002],n;

int win(int p,int K)
{
  
  if(K==0)
    return dp[p][K]=0;

  if(dp[p][K]!=-1)
    return dp[p][K];

  int opp=1;

  for(int i=1;i<=n;i++)
  {
    if(arr[i]<=K)
      opp=min(opp,win(p^1,K-arr[i]));
  }

  return dp[p][K]=(opp?0:1);
}

int32_t main()
{
  int K;
  cin>>n>>K;

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

  memset(dp,-1,sizeof(dp));

  int winner=win(1,K);
  
  cout<<(winner?"First":"Second");

  return 0;  
}   

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

int main(){
long long A, B, K;
cin >> A >> B >> K;
 if(K <= A){
  cout << A - K <<  " "  << B << endl;
}
 else if(K <= A + B){
   cout << 0 <<  " " << A + B - K << endl;
 } 
  else{
    cout << 0 <<  " "  << 0 << endl;
  }
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    X, Y = map(int, readline().split())
    if X % Y == 0:
        print('-1')
    else:
        print(X)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9140
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
  double pi=3.14159265358979;
  double x=0, y=0, r=-pi/2;

  while(1) {
    int z,nr;
    scanf("%d%*c%d",&z,&nr);
    if(z==0 && nr==0) break;

    x += z*cos(r);
    y += z*sin(r);
    r -= nr*pi/180;
  }
  cout << -(int)x << endl << -(int)y << endl;
  return 0;
}


Measured memory_bytes: 1212
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  if (n < 1200) {
    cout << "ABC" << endl;
  } else if (n < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
  return 0;
}


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

int main()
{
    int n;
    std::cin>>n;
    std::vector<int> d(n);
    for(int i=0;i<n;i++)std::cin>>d[i];
    long long ans = 0;

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans += d[i]*d[j];
        }
    }
    std::cout<<ans<<std::endl;

}

Measured memory_bytes: 256
#include <iostream>                                           
using namespace std;
 
int main(){
  long long n, a, b;
  long long ans = 0;
  long long* array;
  cin >> n >> a >> b;
  array = new long long[n];
  for(int i = 0; i < n; i++) cin >> array[i];
  for(int i = 0; i < n-1; i++)
    ans += min((array[i+1]-array[i])*a, b); 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<int>d(N);
  for(int i=0;i<N;i++)cin>>d[i];
  sort(ALL(d));
  cout<<d[N/2]-d[N/2-1]<<endl;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int maxpos = 0;
        int max = 0;
        int sum = 0;
        for(int i=0; i<n; i++){
            p[i] = sc.nextInt();
            sum += p[i];
            if(p[i] > max){
                max = p[i];
                maxpos = i;
            }
        }
        sc.close();

        sum -= p[maxpos] / 2;

        System.out.println(sum);
    }
}

Measured memory_bytes: 21588
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		
		int n  =sc.nextInt();
		int[] a = new int[n];
		
		int[] b = new int[n];
		int[] c = new int[n];
		
		for(int i =0 ;i <n;i++) {
			a[i] = sc.nextInt()-1;
		}
		for(int i =0 ; i < n ;i++) {
			b[i] = sc.nextInt();
		}
		for(int i = 0; i < n-1; i++) {
			c[i] = sc.nextInt();
		}
		c[n-1] = 0;
		int prev = -100;
		
		int sum = 0;
		for(int i = 0 ;i < n ;i++) {
			int cur = a[i];
			sum += b[cur];
			if(cur == prev+1) {
				sum += c[prev];
			}
			prev = cur;
		}
		System.out.println(sum);
 	}
}


Measured memory_bytes: 23892
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
          int sum=0;
                String s = sc.next();
                if(s.equals("-"))
                break;
                int m = sc.nextInt();
                for(int i=0;i<m;i++){
                  int h=sc.nextInt();
                  sum+=h;
                }
                String[] d=s.split("");
                int l=sum%d.length;
                for(int i=l;i<d.length;i++){
                  System.out.printf("%s",d[i]);
                }
                for(int i=0;i<l;i++){
                  System.out.printf("%s",d[i]);
                }
                System.out.println("");
              }
              sc.close();
    }
}


Measured memory_bytes: 26616
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int main()
    {
        LL a,b,c;
        LL abc;
        LL k;
        scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
        if(k%2==1) printf("%lld",b-a);
        else printf("%lld",a-b);
        return 0;
    }

Measured memory_bytes: 256
#include <iostream>

#define u unsigned
#define s short
#define ll long long
#define REP(i, a, b) for (auto i = (a); i < (b); i++)
#define REPR(i, a, b) for (auto i = (a-1); i >= (b); i--)

using namespace std;

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

    cout << (N % 1000 == 0 ? 0 : (1000 - (N % 1000))) << "\n";

    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	LL N;
	cin >> N;
	VL a(N);
	FOR(i, 0, N) {
		cin >> a[i];
		a[i] -= (i + 1);
	}
	SORT(a);
	FOR(i, 0, N) {
		ans += abs(a[i] - a[N / 2]);
	}



	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PA;
const int MOD = 1000000007;
const ll INF=2e18;

ll N,M;
ll a,b,c;
string s;
int main(){
    cin>>a>>b>>c;
    cout<<max(0LL,c-(a-b))<<endl;
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp!.to_i
h = gets.chomp!.split(" ").map(&:to_i)

cnt = h.last

1.upto(n - 1) do |hh|
  cnt += (h[hh - 1] - h[hh]) if h[hh - 1] > h[hh]
end

puts cnt


Measured memory_bytes: 1788
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")



#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include <ext/rope>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define Find order_of_key
// #define at find_by_order
#define x first
#define y second
#define ll long long
#define lll __int128
#define ull unsigned long long
#define ulll unsigned __int128
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define gu getchar_unlocked()
#define pu putchar_unlocked()
#define all(x) x.begin(),x.end()
#define endl '\n'
const int mx=1000010;
int f[mx];

int main()
{
	for(int i=1;i<mx;i++){
		for(int j=i;j<mx;j+=i){
			f[j]++;
		}
	}
	int n;
	cin>>n;
	ll an=0;
	for(int i=n-1;i>=1;i--){
		an+=f[i];
	}cout<<an<<endl;
	return 0;
}

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

int main() {
	string S;
	cin >> S;
	char str[] = {'2', '0', '1', '8'};
	for (int i = 0; i < 4; i++) {
		S[i] = str[i];
	}
	cout << S << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ST first
#define ND second
#define ll long long
#define ld long double
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;

const ll  INF = 1e9 + 9;
const ll  MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;
 
// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)
 
//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<ll > gen(0,n-1);
//gen(gener); // generate random number

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

	int t; cin >> t;
	int ac = 0, wa = 0, tle = 0, re = 0;
	while(t--){
		string s; cin >> s;
		if(s == "AC") ac++;
		if(s == "WA") wa++;
		if(s == "TLE") tle++;
		if(s == "RE") re++;
	}
	
	cout << "AC x " << ac << "\n";
	cout << "WA x " << wa << "\n";
	cout << "TLE x " << tle << "\n";
	cout << "RE x " << re << "\n";
	
	
	
	
	
	
	
	
	
	
	
	

}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define ford(i, n) for (int i = int(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define de(x) cout<<#x<<" = "<<(x)<<endl
#define de2(x,y) cout<<#x<<" = "<<(x) <<' '<< #y<<" = "<<y<<endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
ll nxt(){ll x;cin>>x;return x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	string st;
    int q;
    cin>>st>>q;
    int flag=0;
    string pre,suf;
    while(q--){
        int x;
        cin>>x;
        if(x==1) flag^=1;
        else{
            int xx;
            char ch;
            cin>>xx>>ch;
            if(xx==1){
                if(flag==0) pre+=ch;
                else suf+=ch;
            }else{
                if(flag==0) suf+=ch;
                else pre+=ch;
            }
        }
    }
    if(flag) reverse(all(st));
    if(flag){
        reverse(all(suf));
        cout<<suf<<st<<pre;
    }else{
        reverse(all(pre));
        cout<<pre<<st<<suf;
    }
    return 0;
}



Measured memory_bytes: 1040
import sys
input = sys.stdin.readline
from collections import defaultdict


def read():
    R, C, K = map(int, input().strip().split())
    # アイテムの価値V[r][c]
    V = [defaultdict(int) for i in range(R+1)]
    for i in range(K):
        r, c, v = map(int, input().strip().split())
        V[r][c] = v
    return R, C, K, V


def solve(R, C, K, V, INF=10**9):
    # dp[c][s]: c列目までにs個のアイテムを拾った時の、価値の最大値
    dp = [[-INF for s in range(4)] for c in range(C+1)]
    # 次の行に移るときに使うキャッシュ
    before = [0 for c in range(C+1)]
    for r in range(1, R+1):
        # s=0, s=1, s>1で処理を分ける
        for c in range(1, C+1):
            dp[c][0] = max(dp[c-1][0], before[c])
            dp[c][1] = max(dp[c-1][1], dp[c-1][0] + V[r][c], before[c] + V[r][c])
            for s in range(2, 4):
                dp[c][s] = max(dp[c-1][s], dp[c-1][s-1] + V[r][c])
        # 次の行へ移る
        for c in range(1, C+1):
            before[c] = max(dp[c])
        # dpを初期化
        for c in range(C+1):  
            for s in range(4):
                dp[c][s] = 0
    ans = before[-1]
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

int main() {
    int N; cin >> N;
    vector<int> L(N);
    rep(i, N){
        cin >> L[i];
    }

    int ans = 0;
    for (int i = 0; i < N-2; i++){
        for (int j = i+1; j < N-1; j++){
            for (int k = j+1; k < N; k++){
                int l1 = L[i];
                int l2 = L[j];
                int l3 = L[k];
                if(l1 == l2 || l2 == l3 || l3 == l1)continue;
                if(l1 + l2 > l3 && l2 + l3 > l1 && l3 + l1 > l2)ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
fun main(args: Array<String>) {
    val word = readLine()!!
    var numCount = 0
    while (true) {
        val sentence = readLine()!!
        if (sentence == "END_OF_TEXT") break
        sentence.toLowerCase().split(" ").forEach { if (word == it) numCount++ }
    }
    println("$numCount")
}



Measured memory_bytes: 32020
#!/usr/bin/env python3
# Submit as pypy2

from __future__ import print_function


try:
    input = raw_input
    range = xrange
except NameError:
    pass


# Test code requires python3
# from hypothesis import given
# from hypothesis import strategies as st

N = int(input())
d = [int(x) for x in input().split()]
d.sort()
print(d[N//2] - d[N//2-1])


Measured memory_bytes: 42476
#include<stdio.h>
int main(void)
{
	int n,a,b,a2,b2,i;
	while(1){
	scanf("%d",&n);
	if(n==0) break;
	a=0;
	b=0;
	a2=0;
	b2=0;
	for(i=0;i<n;i++){
	scanf("%d %d",&a,&b);
		if(a<b){
			b2+=a+b;
		}
		if(a>b){
			a2+=a+b;
		}
		else if(a==b){
			a2+=a;
			b2+=b;
		}
	}
	printf("%d %d\n",a2,b2);
	}
}

Measured memory_bytes: 2572
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#define int long long
using namespace std;

int ans[50];
signed main() {
	int k; cin >> k;
	for (int i = 0; i < 50; i++) {
		ans[i] = 49 + k / 50;
	}
	for(int i=0;i<k%50;i++){
		ans[i] += 50;
		for (int j = 0; j < 50; j++) {
			if(i!=j)
			ans[j]--;
		}
	}
	cout << 50 << endl;
	for (int i = 0; i < 50; i++) {
		if (i)cout << " ";
		cout << ans[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int h,w;
  while(cin >> h >> w && h||w){
    for(int j=0;j<w;j++) cout << "#";
    cout << endl;
    for(int i=1;i<h-1;i++){
      cout << "#";
      for(int j=1;j<w-1;j++) cout << ".";
      cout << "#" << endl;
    }
    for(int j=0;j<w;j++) cout << "#";
    cout << endl << endl;
  }
}


Measured memory_bytes: 3092
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<typeinfo>

using namespace std;
#define REP(i,m,n) for(int i=m;i<n;++i)
#define REPll(i,m,n) for(ll i=m;i<n;++i)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()


int m, n;
vector<vector<int>>edge;
vector<pair<int, int>>tmp;
vector<int>dist;

int dijkstra(int s, int t) {
	dist.assign(n, 100000000);
	dist[s] = 0;
	queue<pair<int, int>>q;
	q.push(mp(s, 0));
	while (!q.empty()) {
		pair<int, int>hoge = q.front();
		q.pop();
		REP(i, 0, n) {
			if (dist[i] > dist[hoge.first] + edge[hoge.first][i]) {
				dist[i] = dist[hoge.first] + edge[hoge.first][i];
				q.push(mp(i, dist[i]));
			}
		}
	}
	return dist[t];
}

int main() {
	cin >> n >> m;
	edge.assign(n, vector<int>(n, 1000000000));
	REP(i, 0, m) {
		int a, b, c;
		cin >> a >> b >> c;
		edge[a - 1][b - 1] = c;
		edge[b - 1][a - 1] = c;
		tmp.push_back(mp(a - 1, b - 1));
	}
	int ans = 0;
	REP(i, 0, m) {
		if (edge[tmp[i].first][tmp[i].second] > dijkstra(tmp[i].first, tmp[i].second)) {
			edge[tmp[i].first][tmp[i].second] = 1000000000;
			edge[tmp[i].second][tmp[i].first] = 1000000000;
			ans++;
		}
	}
	cout << ans << endl;
}

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


int main()	
{
	int a[3],sum=0,d[2]={};
	for(int i=0;i<3;i++)
	{
		cin>>a[i];
		d[a[i]%2]++;
	}
	if(d[0]==3||d[1]==3)
	{
		sort(a,a+3);
		cout<<(a[2]-a[1]+a[2]-a[0])/2<<endl;
	}
	else
	{
		for(int i=0;i<3;i++)
		{
			if(d[0]==2&&a[i]%2==0)a[i]++;
			else if(d[1]==2&&a[i]%2==1)a[i]++;
		}
		sort(a,a+3);
		cout<<(a[2]-a[1]+a[2]-a[0])/2+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>

using namespace std;
#define REP(i,m,n) for(long long i=m;i<n;++i)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

int main() {
	string s;
	cin >> s;
	if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a,b,i,max;
    int s[3];
    max = -100000;
    scanf("%d %d",&a,&b);
    s[0] = a+b;
    s[1] = a-b;
    s[2] = a*b;
    for(i=0;i<3;i++){
        if (max<s[i]){
            max = s[i];
        }
    }
    printf("%d",max);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std ;
#define ll long long 
#define all(x) x.begin() , x.end()

string s ; 
multiset<char> mst ; 
set<char> st ; 

bool can(){ return mst.size() - st.size() > mst.size()/2; }

int main(){
    cin >> s;
  for(int l = s.size()-1; l >= 2 ; --l){
      if(s[l] == s[l-1] || s[l] == s[l-2]){
          printf("%d %d\n", l-1 , l+1);
          return 0 ; 
      }
  }
  if(s[0] == s[1])printf("1 2");
  else printf("-1 -1");
}

Measured memory_bytes: 512
use std::io;
use std::str::FromStr;

struct Edge {
    len: u64,
    to: usize
}

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_tuple() -> (usize, usize, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0] as usize, vec[1] as usize, vec[2])
}

fn dfs(i: usize, pre: usize, edge_map: &Vec<Vec<Edge>>, distance: &mut Vec<u64>) {
    // println!("{}", i);
    for edge in &edge_map[i] {
        if edge.to == pre {
            continue;
        }
        distance[edge.to] = distance[i] + edge.len;
        dfs(edge.to, i, edge_map, distance);
    }
}

fn main() {
    let n:u64 = input();
    let mut edge_map: Vec<Vec<Edge>> = Vec::new();
    for _ in 0..n {
        edge_map.push(Vec::new());
    }
    for _ in 0..(n-1) {
        let (u, v, w) = input_tuple();
        edge_map[u - 1].push(Edge{to: v - 1, len: w});
        edge_map[v - 1].push(Edge{to: u - 1, len: w});
    }
    let mut distance = vec![0u64; n as usize];
    dfs(0, 0, &edge_map, &mut distance);
    // println!("{:?}", distance);
    for dist in distance {
        println!("{}", dist % 2);
    }
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
    int n;
    cin >> n;
    
    cout << 10 - n/200 << endl;
	return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3700
#include<iostream>
#include<vector>    
#include<algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    int maxv = 0;
    vector<int> v(n);
    cin >> v[0];
    int cnt = 0;
    for (int i = 1; i < n; i++)
    {
        cin >> v[i];
        if(v[i-1]>=v[i])
        {
            cnt++;
            maxv = max(cnt, maxv);
        }
        else
        {
            cnt = 0;
        }
    }
    cout << maxv << endl;
    return 0;
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))
Asum = sum(A) % (10**9 + 7)
ans = 0

for i in range(N):
    Asum = Asum - A[i]
    ans += A[i]*Asum % (10**9 + 7)
    ans = ans % (10**9 + 7)

print (ans)

Measured memory_bytes: 31388
s = input().split()
n=int(s[0])
x=int(s[1])-1
y=int(s[2])-1
inf=float('inf')
map={}
for i in range(n):
    map[i]=0
for i in range(n):
    for j in range(i+1,n):
        map[min(abs(j-i),abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x))]+=1
for i in range(1,n):
    print(map[i])


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

using namespace std;

int Ans[20];

int main() {
	int w, size;
	string str;

	cin >> w;
	size = 0;
	while (w) {
		Ans[size++] = w % 3;
		w /= 3;
	}

	str = "";
	for (int i = 0; i < size; ++i) {
		if (Ans[i] == 0) {
			str += "0";
		}else if(Ans[i] == 1) {
			str += "+";
		}
		else if (Ans[i] == 2) {
			str += "-";
			++Ans[i + 1];
			if (i == size - 1) {
				++size;
			}
		}
		else if (Ans[i] == 3) {
			str += "0";
			++Ans[i + 1];
			if (i == size - 1) {
				++size;
			}
		}
	}
	reverse(str.begin(), str.end());
	cout << str << endl;

	return 0;
}



Measured memory_bytes: 3204
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>a>>b>>c;
	a=max(a,b);
	cout<<(c-1)/a+1<<endl;
}

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

int main(){
  int N, K, x;
  cin >> N >> K;
  int total = 0;
  for(int i = 0; i < N; i++){
    cin >> x;
    if(K - x > x){
      total += 2 * x;
    }
    else{
      total += (K - x)*2;
    }
  }
  cout << total << endl;
  
  return 0;
}

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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int H, W, h, w; cin >> H >> W >> h >> w;
    int ans = (H-h)*(W-w);
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 
#define nint int
using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> pii;
typedef pair<double,double> dop;
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 gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;



signed main()
{
int n,k;
std::cin >> n >> k;
int sum = 0;
sum++;
n--;
sum += n / 2;
if(sum >= k){
    std::cout << "YES" << std::endl;
} else {
    std::cout << "NO" << std::endl;
}

return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N, Q;
    cin >> N >> Q;
    vector<int> a(N), x(Q);
    for (int i=0; i<N; ++i) cin >> a[i];
    for (int i=0; i<Q; ++i) cin >> x[i];

    vector<ll> sum(N+1), sumtaka(N+1);
    for (int i=1; i<N+1; ++i) sum[i] = sum[i-1] + a[i-1];
    for (int i=1; i<N+1; ++i) {
        sumtaka[i] = sumtaka[i-1];
        if (N%2 == i%2) sumtaka[i] += a[i-1];
    }
    for (int i=0; i<Q; ++i) {
        int cur = x[i];
        int ok = N / 2, ng = -1;
        while (abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;
            if (abs(cur - a[N-mid-1]) < abs(cur - a[N-mid*2-1])) ok = mid;
            else ng = mid;
        }
        if (N%2 == 1 && ok == N / 2 && abs(cur - a[0]) <= abs(cur - a[N/2])) cout << sum[N] - sum[N/2] << '\n';
        else cout << sum[N] - sum[N-ok] + sumtaka[N-2*ok] << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 5548
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;

ll C[2005][2005];
ll dp[100005][13];


int main(){
    int N,M;
    cin >> N >> M;
    vector<int>A(M+5);
    for(int i=0; i<M; i++){
        cin >> A[i];
        N -= A[i];
    }
    if(N < 0){
        cout << -1 << endl; 
    }else{
        cout << N << endl;
    }
}

Measured memory_bytes: 3644
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


t = I()
for _ in range(t):
    n, a, b, c, d = LI()
    memo = {0: 0, 1: d}
    def dfs(x):
        if x in memo:
            return memo[x]
        ret = x * d
        ret = min(ret, min(dfs(x // 2), dfs((x - 1) // 2 + 1)) + a + d * (x % 2))
        ret = min(ret, min(dfs(x // 3) + b + d * (x % 3), dfs((x - 1) // 3 + 1) + b + d * (-x % 3)))
        ret = min(ret, min(dfs(x // 5) + c + d * (x % 5), dfs((x - 1) // 5 + 1) + c + d * (-x % 5)))
        memo[x] = ret
        return ret

    print(dfs(n))
    

Measured memory_bytes: 91164
// =====================================================
//   File    :   main.cpp
//   Author  :   eezyl
//   Synopsis:   codeforces/atcoder template
//   Address :
//   Date    :   2020/08/15
// =====================================================

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

//#define rep(i, a, b) for (int i = (a); i < int(b); ++i)
typedef long long LL;

const int MOD = 1e9+7;

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

void solve() {
    int n;
    LL K;
    cin >> n >> K;
    vector<int> P(n+1);
    for (int i = 1; i <= n; ++i)
        cin >> P[i];
    vector<LL> C(n+1);
    for (int i = 1; i <= n; ++i)
        cin >> C[i];


    LL ans = C[1];
    for (int i = 1; i <= n; ++i) {
        int start = P[i];
        int cur = P[start];
        LL score = C[start];
        ans = max(ans, score);
        LL count = 1;

        vector<LL> rem(1, 0);
        while (count < K && cur != start) {
            rem.push_back(score);
            ++count;
            score += C[cur];
            ans = max(ans, score);
            cur = P[cur];
        }
        if (count < K && cur == start) {

            LL rep = K / count;
            LL new_k = K % count;

            if (new_k == 0) {
                --rep;
                rem.push_back(score);
                new_k = count;
            }

            LL lar = rem[0];
            for (LL j = 1; j <= new_k; ++j)
                lar = max(lar, rem[j]);
            LL p = rep * score + lar;
            ans = max(ans, p);

        }
    }
    cout << ans << endl;
}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
//#define LOCAL
#ifdef LOCAL
freopen("data.in", "r", stdin);
while (!feof(stdin)) {
#endif // LOCAL

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

#ifdef LOCAL
}
printf("Time used = %.2lf\n", (double)clock() / CLOCKS_PER_SEC);
#endif // LOCAL
    return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h> 
#include <algorithm>  
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fr(i,a,b) for(long long int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;
vector<ll>g[1000001];
ll vis[1000005]={0};
map<ll,ll>mx;
/*queue<ll>q ;
void bfs(ll s)
{
       vis[s]=1;
       q.push(s);
       ll curr=q.front(); vis[curr]=1;
       while(!q.empty())
       {
              curr=q.front(); q.pop(); // vis[curr]=1;
              for(ll i=0;i<g[curr].size();i++)
              {
                     ll child=g[curr][i];
                     if(vis[child]==0) 
                     { 
                            q.push(child); 
                            vis[child]=1;
                     }
              }
       }
}*/
ll co=0;
ll dfs(ll curr)
{
       vis[curr]=1;
       for(ll i=0;i<g[curr].size();i++)
       {
              ll child=g[curr][i];
              if(vis[child]==0)
              {
                     co++;
                     dfs(child);
              }
       }
       return co;
}
signed main() 
{
    fast
    ll n,m;
    cin>>n>>m;
    while(m--)
    {
           ll u,v;
           cin>>u>>v;
         if(mx[u]!=v)  {g[u].pb(v);g[v].pb(u);mx[u]=v;}
    }
    ll c=0;
    vector<ll>v;
    for(ll i=1;i<=n;i++)
    {
           if(vis[i]==0)  {v.pb(dfs(i)+1); co=0; c++;}
    }
   // for(ll i=0;i<v.size();i++) cout<<v[i]<<" ";
    if(c==1) cout<<n<<" ";
    else
    {
           sort(v.begin(),v.end());
          cout<<v[0]+(v[v.size()-1]-v[0]);
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18

void solve_abc_b() {
	ll n, m;
	ll a, b, c, d;
	ll x, y;
	ll k;
	ll l;
	string s, t;
	ll l_ans = 0;
	float f_ans = 0;
	string s_ans;

	cin >> d >> n;

	if (d == 0) {
		l_ans = n;
		if (n == 100) {
			l_ans = 101;
		}
	}
	else if (d == 1) {
		l_ans = 100 * n;
		if (n == 100) {
			l_ans = 10100;
		}
	}
	else if (d == 2) {
		l_ans = 10000 * n;
		if (n == 100) {
			l_ans = 1010000;
		}
	}

	cout << l_ans << "\n";

	return;
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(7);

	solve_abc_b();

	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long 
#define v vector<int> 
using namespace std; 
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL); 
string s; 
cin>>s; 
int i,n=s.length(),c=0,j,ans=0; 
for(i=0;i<n;i++){
if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
    c++;
    for(j=i+1;j<n;j++){
        if(s[j]=='A'||s[j]=='C'||s[j]=='G'||s[j]=='T'){c++;}
        else{break;}
    }
    ans=max(ans,c);
    c=0;
}
else{ans=max(ans,c);}
}
cout<<ans <<"\n";
}

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

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

  int count = 0;
  int j = S - 1;
  int k = S - 2;

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

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

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

  int M = 0;
  vector<int> h(N, 0);
  rep(i, N) {
    cin >> h[i];
    M = max(h[i], M);
  }
  
  int ans = 0;
  for (int i = 1; i <= M ; i++) {
    bool flag = false;
    for (int j = 0; j < N; j++) {
      if (h[j] >= i) {
        flag = true;
      }
      if ((h[j] < i || j == N - 1) && flag == true) {
        ans++;
        flag = false;
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ll long long
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
using namespace std;
const int inf=1e9+10;
const int mod=1e9+7;
const int maxn=1e5+10;
int n,r;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n>>r;
	cout<<max(0,(10-n)*100)+r<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		sc.close();
		long ans = 0;

		int n = str.length() -1;
      
		for (int i=0; i<(Math.pow(2,n)); i++) {
			String str_first = String.valueOf(str.charAt(0));
			StringBuilder sb = new StringBuilder(str_first);
          
			for (int j=0; j<n; j++) {
				if ((1&i>>j) == 1) {
					sb.append("+");
                }
				sb.append(str.charAt(j + 1));
            }
			String[] subset = sb.toString().split("\\+");
			for (String s : subset) {
				ans += Long.parseLong(s);
            }
        }
		System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const LL MOD = 1000000007LL;
using namespace std;

int main() {
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;
	cout << max(N - K, 0)*Y + min(N, K)*X << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MP make_pair
#define F first
#define S second
using namespace std;
typedef pair<int, int> PII;
typedef pair<PII, PII> PPP;

int x, y;
bool visited[51][51][51][51];
bool flr[52][52];
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int main()
{
  while(true){
    cin >> x >> y;
    if(!x && !y){
      break;
    }

    int tx, ty, kx, ky;
    memset(visited, false, sizeof visited);
    memset(flr, false, sizeof flr);
    cin >> tx >> ty >> kx >> ky;

    for(int i = 1; i <= y; i++){
      for(int j = 1; j <= x; j++){
	int in;
	cin >> in;
	flr[i][j] = (bool)in;
      }
    }

    for(int i = 1; i <= y; i++){
      flr[i][0] = flr[i][x + 1] = true;
    }
    for(int i = 1; i <= x; i++){
      flr[0][i] = flr[y + 1][i] = true;
    }

    queue<PPP> q;
    q.push(MP(MP(ty, tx), MP(ky, kx)));

    for(int i = 0; i <= 100; i++){
      int sz = q.size();
      for(int j = 0; j < sz; j++){
	PPP now = q.front();
	q.pop();
	if(!visited[now.F.F][now.F.S][now.S.F][now.S.S]){
	  visited[now.F.F][now.F.S][now.S.F][now.S.S] = true;
	  
	  if(now.F.F == now.S.F && now.F.S == now.S.S){
	    cout << i << endl;
	    goto end;
	  }
	  
	  for(int k = 0; k < 4; k++){
	    int ntdx = dx[k], ntdy = dy[k], nkdx = -dx[k], nkdy = -dy[k];
	    PPP next = MP(MP(now.F.F + ntdy * !flr[now.F.F + ntdy][now.F.S + ntdx], now.F.S + ntdx * !flr[now.F.F + ntdy][now.F.S + ntdx]), MP(now.S.F + nkdy * !flr[now.S.F + nkdy][now.S.S + nkdx], now.S.S + nkdx * !flr[now.S.F + nkdy][now.S.S + nkdx]));
	    q.push(next);
	  }
	}
      }
    }
    cout << "NA" << endl;
  end:;
  }
  return 0;
}

Measured memory_bytes: 8748
n = gets.to_i

a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

h = Hash.new(0)
b.each {|e| h[e] += 1}

h = h.to_a
lim = h.size
i = l = 0
j = 1

ans = []
n.times do |k|
    if a[k] == h[i][0] && j == lim
        l += 1 while a[l] != a[k] && ans[l] == a[k]
        
        if a[l] == a[k]
            puts "No"
            exit
        end
        ans << ans[l]
        ans[l] = h[i][0]
        h[i][1] -= 1
    elsif a[k] == h[i][0]
        ans << h[j][0]
        h[j][1] -= 1
        j += 1 if h[j][1] == 0
    else
        ans << h[i][0]
        h[i][1] -= 1
        i += 1 while i < lim && h[i][1] == 0
        j = i + 1 if i == j
    end
end

puts "Yes"
puts ans * " "


Measured memory_bytes: 59124