akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
char s[500000];
int a[100][30];
char s2[500000];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s);
        int len=strlen(s);
        if(i==1)
        {
            for(int j=0;j<len;j++)
            {
                int x=s[j]-'a';
                a[i][x]++;
            }
        }
        if(i>1)
        {
           for(int j=0;j<len;j++)
            {
                int x=s[j]-'a';
                a[i][x]++;
                a[i][x]=min(a[i-1][x],a[i][x]);
            }
        }
    }
    int k=0;
    for(int i=0;i<=25;i++)
    {
        if(a[n][i]>0)
        {
            for(int j=1;j<=a[n][i];j++)
            {
                s2[k++]='a'+i;
            }
        }
    }
    sort(s2,s2+k);
    printf("%s",s2);
}


Measured memory_bytes: 256
from fractions import gcd
from functools import reduce

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
a = list(map(int,input().split()))
m = lcm(*a) - 1
ans = 0
for i in range(N):
  ans += m%a[i]
print(ans)

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

int main(){
    int h,w;
    cin >> h >> w;
 //   int ma[][];
    vector<string> s(h,"");
    for(int i=0;i<h;i++){
        cin >> s[i];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int cou=0;
            if(s[i][j]=='.'){
                 for(int a=0;a<3;a++){
                     if(i-1+a<0 || i-1+a>=h)continue;
                    for(int b=0;b<3;b++){
                        if(j-1+b<0 || j-1+b>w-1)continue;
                        if(s[i-1+a][j-1+b]=='#')cou++;
                    }
                }
                cout << cou;
            }else cout << s[i][j];
        }
        cout << endl;
    }


}


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

using namespace std;

int main() {
	string s;
	cin >> s;
	if ((s.front() == s.back()) ^ (s.size() % 2 == 0)) {
		cout << "Second" << endl;
	}
	else cout << "First" << endl;
	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define int long long
typedef pair<char,int>P;
int uni[100009],r[100009];
int find(int a){
    if(a!=uni[a])a=find(uni[a]);
    return a;
}
bool same(int a,int b){
    return find(a)==find(b);
}
void unit(int a,int b){
    int c=find(a),d=find(b);
    if(c==0||d==0)exit(1);
    uni[d]=c;
}
 
int M[100007];
vector<int>v[100007];
 
void dfs(int x,int col){
  if(M[x]!=-1)col=x;
  uni[x]=col;
  r(i,v[x].size()){
    dfs(v[x][i],col);
  }
}
int n,m,x,sum;
vector<P>query;
int xx[100009];


main(){
  while(cin>>n>>m,n){
    sum=0;
    memset(uni,0,sizeof(uni));
    memset(r,0,sizeof(r));
    memset(M,-1,sizeof(M));
    query.clear();
    r(i,100007)v[i].clear();
    r(i,n-1){
      cin>>xx[i+2];
      v[xx[i+2]].push_back(i+2);
    }
    xx[1]=1;
    set<P>s;
    r(i,m){
      char c;
      cin>>c>>x;
      if(c=='M'&&s.count(P(c,x)))continue;
      if(c=='M')M[x]=x;
      s.insert(P(c,x));
      query.push_back(P(c,x));
    }
    dfs(1,1);
    reverse(query.begin(),query.end());
    r(i,query.size()){
      if(query[i].first=='Q') sum += find(query[i].second);
      else{
        unit(xx[query[i].second],query[i].second);
      }
    }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 22264
from math import ceil

line = input().split(" ")
N = int(line[0])
H = int(line[1])

a = []
b = []

for _ in range(N):
    line = input().split(" ")
    a.append(int(line[0]))
    b.append(int(line[1]))

a.sort(reverse=True)
b.sort(reverse=True)

ret = 0
for x in b:
    if x<a[0]:
        break
    H -= x
    ret += 1
    if H<=0:
        break

if H>0:
    ret += ceil(H/a[0])

print(ret)

Measured memory_bytes: 11264
#from editorial
N = int(input()) 
ans = ''
for i in range(1, 99):
    if N <= 26 ** i: 
        N -= 1
        for j in range(i):
            ans += chr(ord('a') + N % 26) 
            N //= 26
        break 
    else:
        N -= 26 ** i
print(ans[::-1]) # reversed

Measured memory_bytes: 9116
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=5e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const double PI = acos(-1);

void solve(){
    int n;
    cin>>n;
    int arr[n];
    int sum=0;
    loop(n,i,0)
        cin>>arr[i],sum+=arr[i];
    sum/=n;
    int res=1e9;
    loop(sum+5,i,max(sum-5,0)){
        int x=0;
        loop(n,j,0)
            x+=(abs(arr[j]-i)*abs(arr[j]-i));
        min_self(res,x);
    }
    cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


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


namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var countOne = S.Count(val => val  == '1');
            var countZero = S.Count(val => val == '0');
            Console.WriteLine(S.Length - Math.Abs(countOne - countZero));
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=305,p=998244353,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,C,a[10],b[10];
ll f[1<<5][N];
ll calc(){
	memset(f,0,sizeof(f));
	f[0][a[n]*n-1]=1;
	for (int i=0;i<n*C;i++){
		int x=i%n,r=min(n*C,i+a[b[x]]*n);
		for (int j=0;j<(1<<n);j++)
		if (!(j&(1<<x))) for (int k=i;k<=n*C;k++)
		f[j+(1<<x)][max(r,k)]+=f[j][k];
	}
	return f[(1<<n)-1][n*C];
}
int main(){
	n=read()-1;C=read();
	for (int i=0;i<=n;i++) a[i]=read(),b[i]=i;
	sort(a,a+n+1);
	ll ans=0;
	do{ans+=calc();}
	while (next_permutation(b,b+n));
	ll t=1;
	for (int i=1;i<=n;i++) t*=i*C;
	printf("%.16lf\n",1.0*ans/t);
	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);

		Long N = sc.nextLong();
		Long M = sc.nextLong();

		Long ans = 0L;

		Long s_num = N;
		Long c_num = M / 2;

		Long scc_num = s_num < c_num ? s_num : c_num;

		ans += scc_num;

		N -= scc_num;
		M -= scc_num * 2;

		ans += M / 4;

		System.out.println(ans);

		sc.close();
	}

}


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

int main() {
	// your code goes here
	int N = 0;
	cin>>N;
	vector<int> dp[3];
	N--;
	int a,b,c;
	cin>>a>>b>>c;
	dp[0].push_back(a);
	dp[1].push_back(b);
	dp[2].push_back(c);
	while(N--){
		cin>>a>>b>>c;
		int val1 = a + max(dp[1].back(),dp[2].back());
		int val2 = b + max(dp[0].back(),dp[2].back());
		int val3 = c + max(dp[0].back(),dp[1].back());
		dp[0].push_back(val1);
		dp[1].push_back(val2);
		dp[2].push_back(val3);
	}
	int ans = dp[0].back();
	for(int i=1;i<3;i++)ans = max(dp[i].back(),ans);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4292
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
struct edge { int to, cost; };

int x[114], y[114], h[114],ha[114];
int xy[114][114];
int imos[114][114];
signed main() {
	int n; cin >> n;
	rep(i, n) {
		cin >> x[i] >> y[i] >> h[i];
	}

	for(int i=0;i<=100;i++){
		for (int j = 0; j <= 100; j++) {
			vector<int>V;
			rep(k, n) {
				V.push_back(h[k] + abs(i - x[k]) + abs(j - y[k]));
			}
			sort(V.begin(), V.end());
			V.erase(unique(V.begin(), V.end()), V.end());
			rep(l, V.size()) {
				int VT = V[l];
				rep(k, n) {
					ha[k] = max(0ll, VT - abs(i - x[k]) - abs(j - y[k]));
				}
				rep(k, n) {
					if (h[k] != ha[k])goto A;
				}
				cout << i << ' ' << j << ' ' << VT << endl;
			A:;
			}
		}
	}
}

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

public class prog
{
    public static void Main()
    {
       int N = int.Parse(Console.ReadLine());
       
       int[] nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
       
       bool can = true;
       
       for(int i = N-1 ; i > 0 ; i--){
           if(nums[i] < nums[i-1]) nums[i-1]--;
       }
       
       for(int i = 1 ; i < N ; i++){
           if(nums[i] < nums[i-1]) can = false;
       }
       
       if(can) Console.WriteLine("Yes");
       else Console.WriteLine("No");
    }
}

Measured memory_bytes: 30300
<?php

$s_str = trim(fgets(STDIN));
$s_int = (int)$s_str;

$length = strlen($s_str);
$keta_max = strlen($s_str) - 1;
if ($keta_max === 0) {
	echo $s_str;
	exit();
}
$keta = 0;
$kumiawase = [];
$pattern = ['-', '+'];
$tmp = [''];
while ($keta < $keta_max) {
	$new = [];
	foreach ($tmp as $v) {
		for ($i=0; $i < 2; $i++) { 
			$new[] = $v . $pattern[$i];
		}
	}
	$tmp = $new;
	++$keta;
}
$kumiawase = $new;
$k_length = count($kumiawase);

$int_array = [];
for ($i=0; $i < $k_length; $i++) { 
	$str = $s_str[0];
	$tmp_k = $kumiawase[$i];
	$tmp_k_length = strlen($tmp_k);
	for ($j=0; $j < $tmp_k_length; $j++) { 
		if ($tmp_k[$j] === '+') {
			$int_array[] = (int)$str;
			$str = $s_str[$j+1];
		}else{
			$str .= $s_str[$j+1];
		}
	}
	if ($str !== '') {
		$int_array[] = (int)$str;
	}
}

$sum = 0;
foreach ($int_array as $v) {
	// echo $v . PHP_EOL;
	$sum += $v;
}
echo $sum;

Measured memory_bytes: 4604
#include<stdio.h>
#include<math.h>

int main(void)
{
	long long i, k, N;

	scanf("%lld", &N);

	k = N;

	for (i = 1; i <= sqrt(N); i++) {
		if (N % i == 0) {
			if (k > i + (N / i) - 2) {
				k = i + (N / i) - 2;
			}
		}
	}
	printf("%lld\n", k);

	return 0;
}

Measured memory_bytes: 128
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll a(1LL << n); REP(i, 1LL << n) cin >> a[i];
    V< P<ll, ll> > dp(1LL << n, make_pair(0, 0));
    REP(i, 1LL << n) dp[i].first = a[i];
    
    REP(i, n) {
        REP(j, 1LL << n) {
            if (!((j >> i) & 1)) {
                P<ll, ll> tmp1 = dp[j | (1LL << i)], tmp2 = dp[j];
                if (tmp1.first < tmp2.first) {
                    dp[j | (1LL << i)] = make_pair(tmp2.first, max(tmp1.first, tmp2.second));
                } else {
                    dp[j | (1LL << i)] = make_pair(tmp1.first, max(tmp2.first, tmp1.second));
                }
            }
        }
    }

    ll ans = 0;
    rep(i, 1, 1LL << n) {
        chmax(ans, dp[i].first + dp[i].second);
        cout << ans << '\n';
    }
    return 0;
}



Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define fori(i,n) for(int i =0;i<n;i++)
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
#define mp make_pair
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout.precision(15);
 
 
int mod = 1e9+7;
 
int pow(int a, int b) {
    int ans = 1;
    a %= mod;
    while(b) {
        if(b%2) {
            ans *= a;
            ans %= mod;
        }
        b /= 2;
        a *= a;
        a %= mod;
    }
    return ans;
}

int inv(int a) {
    return pow(a,mod-2);
}

int mul (int a,int b) {
    return ((a%mod)*(b%mod))% mod;
}

struct cmp {
    bool operator() (pair<int,int> a, pair<int,int> b) const {
        int x = a.F;
        int y = b.F;
        return x>=y;
    }
};


int32_t main() {
    FAST;
    int t;
    cin>>t;
    // t = 1;
    map<string,int> m;
    string s;
    while(t--) {
        cin>>s;
        m[s]++;

    }
    cout<<"AC x "<<m["AC"]<<endl;
    cout<<"WA x "<<m["WA"]<<endl;
    cout<<"TLE x "<<m["TLE"]<<"\n";
    cout<<"RE x "<<m["RE"]<<"\n";
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <set>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
    if (a < b) {
        ll tmp = a;
        a = b;  b = tmp;
    }
    ll r = a % b;
    while (r != 0) {
        a = b;  b = r;
        r = a % b;
    }
    return b;
}


int main(void){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    
    ll ans = b - a + 1;
    ans -= b / c - max(0ll, (a - 1) / c);
    ans -= b / d - max(0ll, (a - 1) / d);
    ans += b / (c * d / gcd(c, d))- max(0ll, (a - 1) / (c * d / gcd(c, d)));
    cout << ans << endl;
    
}


Measured memory_bytes: 256
data IRect = IRect Int Int deriving Eq

instance Ord IRect where
 (<=)  (IRect h1 w1) (IRect h2 w2) = h1^2+w1^2 < h2^2+w2^2 || (h1^2+w1^2 == h2^2+w2^2 && h1<=h2)

instance Show IRect where
 show (IRect h w) = show h ++ " " ++ show w 

main = interact $ unlines . map (show . integral_rectangles . map read . words) . init . lines

integral_rectangles [h,w] = minimum [IRect h' w'| h'<-[1..150], w'<-[1..150], h'<w', IRect h' w' > IRect h w]

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

using namespace std;
#define sd(x) scanf("%d", &x);
#define sdl(x) scanf("%lld", &x);
#define pr(x) printf("%d\n", x);
#define prl(x) printf("%lld\n", x);

long long int mod = 1000000007;

long long int gcd(long long int a, long long int b)
{
    if (b < a)
        return gcd(b, a);
    else if (b % a == 0)
        return a;
    else
        return gcd(b % a, a);
}

long long fast_exp(long long a, long long n, long long mod1)
{

    if (n == 0)
        return 1;
    else if (n == 1)
        return a;
    if (n % 2 == 0)
        return fast_exp((a * a) % mod1, n / 2, mod1);
    else
        return (a * fast_exp((a * a) % mod1, n / 2, mod1)) % mod1;
}
bool is_square(long long a)
{
    long long int b = sqrt(a);
    if (b * b == a)
        return true;
    else
        return false;
}
long long n_fact[1000001];
void calc_fact(int n) // calculates the factorial % mod and stores in n_fact upto n
{
    n_fact[0] = 1;
    for (int c(1); c <= n; c++)
        n_fact[c] = (c * n_fact[c - 1]) % mod;
    return;
}
long long calc_inverse_mod(long long x, long long mod)
{
    return fast_exp(x, mod - 2, mod);
}
bool n_primes[100001] = {false};
void calc_primes(int n)
{
    for (int c(2); c <= 100000; c++)
    {
        if (n_primes[c] == true)
            continue;
        for (int c1(c + c); c1 <= 100000; c1 = c1 + c)
            n_primes[c1] = true;
    }
    return;
}
bool is_palindrome(string a)
{
    string b = a;
    reverse(b.begin(), b.end());
    if (b == a)
        return true;
    else
        return false;
}


double dp[100000];
int done[100000];
unordered_map<int,vector<int>>graph;

void dfs(int i,int prev)
{
   
    if (done[i]!=0)
        return;
    double e=0;
    done[i]=1;
    int siz=0;
    for (int c=0;c<graph[i].size();c++)
        {
            if (graph[i][c]==prev)
                continue;
            dfs(graph[i][c],i);
            e+=1+dp[graph[i][c]];
            siz++;
        }
      
      
        dp[i]=e/max(1,siz);
    return ;

}
int main()
{

    ios_base::sync_with_stdio(false);
    int t;
    t = 1;

    for (int tt = 0; tt < t; tt++)
    {
       string a;
       cin >> a;
       if (a[2]==a[3]&& a[4]==a[5])
        cout << "Yes" << endl;
        
        else cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	
	if(a <= c && c <= b) printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int map[9][9];
char c_map[9][9];

void scan(int x, int y, int h, int w){
  int counter[9];
  int i,j,k;

  for(i = 0; i < 9; i++){
    counter[i] = 0;
  }

  for(i = 0; i < h; i++){
    for(j = 0; j < w; j++){
      counter[map[y+i][x+j] - 1]++;
    }
  } 
  
  for(i = 0; i < 9; i++){
    if(counter[i] > 1){
      for(j = 0; j < h; j++){
	for(k = 0; k < w; k++){
	  if(i == (map[y+j][x+k] - 1)){
	    c_map[y+j][x+k] = '*';
	  }
	}
      }
    }
  }
}

int main(int argc,char* argv[]){
  int n,i;
  int first = 0;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    int j,k;

    if(first != 0){
      printf("\n");
    }
    
    for(j = 0; j < 9; j++){
      for(k = 0; k < 9; k++){
	scanf("%d",&map[j][k]);
      }
    }

    for(j = 0; j < 9; j++){
      for(k = 0; k < 9; k++){
	c_map[j][k] = ' ';
      }
    }

    for(j = 0; j < 9; j++){
      scan(j,0,9,1);
    }
    
    for(j = 0; j < 9; j++){
      scan(0,j,1,9);
    }

    for(j = 0; j < 9; j++){
      scan((j / 3) * 3, (j % 3) * 3,3,3);
    }

    for(j = 0; j < 9; j++){
      for(k = 0; k < 9; k++){
	printf("%c%d",c_map[j][k],map[j][k]);
      }
      printf("\n");
    }

    if(first == 0){
      first = 1;
    }
    
  }
  return 0;
}

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

#define LEN 100000

typedef struct pp{
  char name[10];
  int time;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue(){
  P x=Q[head];
  head=(head+1)%LEN;
  return x;
}

int min(int x,int y){
  return x<y ? x:y;
}

int main(){
  int elaps=0,c,i,q;
  P u;

  scanf("%d %d",&n,&q);

  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].time);
  }
  head=1;
  tail=n+1;

  while(head!=tail){
    u=dequeue();
    c=min(q,u.time);
    u.time=u.time-c;
    elaps=elaps+c;
    if(u.time>0)enqueue(u);
    else printf("%s %d\n",u.name,elaps);
  }

  return 0;
}



Measured memory_bytes: 3288
import decimal
import math
a,b,x=map(int,input().split())
num1=a*a*b-x
if (a*a*b)/2<x:
    num2=decimal.Decimal((num1*2)/(a*a))
    num3=decimal.Decimal(math.sqrt(decimal.Decimal((a*a)+decimal.Decimal(num2*num2))))
    num4=decimal.Decimal((a*a+decimal.Decimal(num3*num3)-decimal.Decimal(num2*num2))/decimal.Decimal(2*decimal.Decimal(a*num3)))
    ans=math.degrees(math.acos(num4))
else:
    num2=decimal.Decimal((x*2)/(a*b))
    num3=decimal.Decimal(math.sqrt(decimal.Decimal((b*b)+decimal.Decimal(num2*num2))))
    num4=decimal.Decimal((num2*num2+decimal.Decimal(num3*num3)-decimal.Decimal(b*b))/decimal.Decimal(2*decimal.Decimal(num2*num3)))
    ans=math.degrees(math.acos(num4))
print(ans)


Measured memory_bytes: 10064
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll LL_MAX=LLONG_MAX;

struct In{
    template<typename T>
    operator T(){
        T x;
        cin >> x;
        return x;
    }
};
In in;

template <typename T,typename U>
void forin(T* x,U n){
    for (U i=0;i<n;i++) cin >> x[i];
}

template <typename T>
int div1(T x) {
    return x%1000000007;
}

template <typename T>
void out(T x){
    cout << x << endl;
}

template <typename T>
T gcd(T x,T y){
    if (y == 0) return x;
    return gcd(y,x%y);
}

template <typename T>
T lcm(T x,T y){
    return x*y/gcd(x,y);
}

int main(){
    double r=in,pi=3.1415926;
    out(r*2.0*pi);
}


Measured memory_bytes: 3784
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;

namespace zyt
{
	template<typename T>
	inline bool read(T &x)
	{
		char c;
		bool f = false;
		x = 0;
		do
			c = getchar();
		while (c != EOF && c != '-' && !isdigit(c));
		if (c == EOF)
			return false;
		if (c == '-')
			f = true, c = getchar();
		do
			x = x * 10 + c - '0', c = getchar();
		while (isdigit(c));
		if (f)
			x = -x;
		return true;
	}
	template<typename T>
	inline void write(T x)
	{
		static char buf[20];
		char *pos = buf;
		if (x < 0)
			putchar('-'), x = -x;
		do
			*pos++ = x % 10 + '0';
		while (x /= 10);
		while (pos > buf)
			putchar(*--pos);
	}
	typedef long long ll;
	typedef pair<int, int> pii;
	const int N = 3e3 + 10, P = 1e9 + 7, INV2 = (P + 1) / 2;
	int n, q, arr[N], f[N][N], tmp[N][N];
	int power(int a, int b)
	{
		int ans = 1;
		while (b)
		{
			if (b & 1)
				ans = (ll)ans * a % P;
			a = (ll)a * a % P;
			b >>= 1;
		}
		return ans;
	}
	int inv(const int a)
	{
		return power(a, P - 2);
	}
	int work()
	{
		read(n), read(q);
		for (int i = 1; i <= n; i++)
			read(arr[i]);
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				f[i][j] = (arr[i] > arr[j] ? 1 : 0);
		for (int i = 1; i <= q; i++)
		{
			int x, y;
			read(x), read(y);
			for (int j = 1; j <= n; j++)
				tmp[x][j] = f[x][j], tmp[y][j] = f[y][j], tmp[j][x] = f[j][x], tmp[j][y] = f[j][y];
			for (int j = 1; j <= n; j++)
				if (j != x && j != y)
				{
					f[x][j] = ll(f[x][j] + tmp[y][j]) * INV2 % P;
					f[j][x] = ll(f[j][x] + tmp[j][y]) * INV2 % P;
					f[y][j] = ll(f[y][j] + tmp[x][j]) * INV2 % P;
					f[j][y] = ll(f[j][y] + tmp[j][x]) * INV2 % P;
				}
			f[x][y] = ll(f[x][y] + tmp[y][x]) * INV2 % P;
			f[y][x] = ll(f[y][x] + tmp[x][y]) * INV2 % P;
		}
		int ans = 0;
		for (int i = 1; i <= n; i++)
			for (int j = i + 1; j <= n; j++)
				ans = (ans + f[i][j]) % P;
		write((ll)ans * power(2, q) % P);
		return 0;
	}
}
int main()
{
	return zyt::work();
}

Measured memory_bytes: 70912
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
pair<ll,ll>p[200005];
int main()
{
    ll n,m,i,ans,j;
    while(cin>>n>>m)
    {
        map<ll,ll>mp;

        for(i=1; i<=m; i++)
        {
            cin>>p[i].first>>p[i].second;
            if(p[i].second==n)
            {
                mp[p[i].first]=p[i].second;
            }


        }
         sort(p+1,p+m+1);

        ll f=1;
        for(i=1; i<=m; i++)
        {
            if(p[i].first==1&&mp[p[i].second]==n)
            {
                printf("POSSIBLE\n");
                f=0;
                break;


            }


        }
        if(f)
            printf("IMPOSSIBLE\n");
    }


    return 0;

}


Measured memory_bytes: 15872
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

X = I()
X -= X % 5
X //= 5
print(1000*(X//100) + 5*(X % 100))


Measured memory_bytes: 61964
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
int course[16][17][2];
int main()
{
  for(;;){
    int H,W;
    cin >> W >> H;
    if(H==0||W==0) break;
    memset(course,0,sizeof(course));
    for(int h=1; h<=H; h++){
      for(int w=1; w<=W; w++){
        cin >> course[h][w][0];
      }
    }
    for(int w=1; w<=W; w++){
      if(course[1][w][0] == 1) course[1][w][1] = 0;
      else course[1][w][1] = 1;
    }
    for(int h=2; h<=H; h++){
      for(int w=1; w<=W; w++){
        if(course[h][w][0] == 1){
          course[h][w][1] = 0;
        }else if(course[h][w][0] == 2){
          if(course[h-1][w][0] != 2){
            course[h][w][1] = course[h-1][w][1];
          }
          if(course[h-2][w][0] == 2){
            course[h][w][1] += course[h-2][w][1];
          }
        }else {
          for(int i=-1; i<=1; i++){
            if(course[h-1][w+i][0] != 2){
              course[h][w][1] += course[h-1][w+i][1];
            }
          }
          if(course[h-2][w][0] == 2){
            course[h][w][1] += course[h-2][w][1];
          }
        }
      }
    }
    long long sum = 0;
    for(int w=1; w<=W; w++){
      sum += course[H][w][1];
      if(course[H-1][w][0] == 2){
        sum += course[H-1][w][1];
      }
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N, K = map(int, input().split())

if K > (N-1)*(N-2)//2:
    print(-1)
    exit()

print(N - 1 + (N - 1) * (N - 2) // 2 - K)
for i in range(2, N + 1):
    print(1, i, sep=" ")

c = 0
for i in range(2, N):
    for j in range(i + 1, N + 1):
        if (N - 1) * (N - 2) // 2 - K == c:
            exit()
        print(i, j, sep=" ")
        c += 1


Measured memory_bytes: 3608
#include <stdio.h>
int main(void){
  int a,b,c,i,j=0 ;
  scanf("%d %d %d",&a,&b,&c);
  for( i = a ; i <= b ; i++ ){
    if( c % i == 0)
    j=j+1;
    else
    ;

  }
  printf("%d\n",j);
  return 0 ;


}



Measured memory_bytes: 2108
import java.lang.Math
import java.util.ArrayDeque

val INF = 1000000000

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val S = Array(N) { readInputLine().toCharArray() }
    val edges = Array(N) { mutableListOf<Int>() }

    for (i in 0 until N) {
        for (j in 0 until N) {
            if (S[i][j] == '1') {
                edges[i].add(j)
            }
        }
    }

    val (ok, color) = isBipartite(N, edges)

    if (!ok) {
        println(-1)
        return
    }

    val d = warshallFloyd(N, edges)

    var maxDist = 0

    for (i in 0 until N) {
        for (j in 0 until N) {
            if (d[i][j] < INF) {
                maxDist = Math.max(d[i][j], maxDist)
            }
        }
    }

    for (i in 0 until N) {
        val nextNodes = mutableSetOf<Int>()
        for (j in 0 until N) {
            if (d[i][j] == 1) {
                nextNodes.add(j)
            }
        }
        for (k in nextNodes) {
            for (l in nextNodes) {
                if (k == l) {
                    continue
                }
                if (d[k][l] == 1) {
                    println(-1)
                    return
                }
            }
        }
    }

    println(maxDist + 1)
}

fun readInputLine(): String {
    return readLine()!!
}

// ワーシャル-フロイド法
// O(V^3)のグラフ全ノード間の距離を求めるアルゴリズム
fun warshallFloyd(n: Int, edges: Array<MutableList<Int>>): Array<IntArray> {
    val d = Array(n) { IntArray(n) { INF } }

    for (i in 0 until n) {
        d[i][i] = 0
    }

    for ((i, es) in edges.withIndex()) {
        for (e in es) {
            d[i][e] = 1
        }
    }

    for (k in 0 until n) {
        for (i in 0 until n) {
            for (j in 0 until n) {
                d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j])
            }
        }
    }

    return d
}

// 2部グラフ判定
// グラフを2つの頂点集合に分割し、集合内の頂点同士では辺が存在しないグラフが存在するか判定する
// 分割できる場合は分割の方法も返す
fun isBipartite(n: Int, edges: Array<MutableList<Int>>): Pair<Boolean, IntArray> {
    val color = IntArray(n) { -1 }
    color[0] = 0

    val queue = ArrayDeque<Int>(n)
    queue.add(0)

    while (queue.isNotEmpty()) {
        val node = queue.poll()!!
        val nodeColor = color[node]
        for (e in edges[node]) {
            if (color[e] == -1) {
                color[e] = (nodeColor + 1) % 2
                queue.add(e)
            } else if (color[e] == nodeColor) {
                return Pair(false, color)
            }
        }
    }

    return Pair(true, color)
}


Measured memory_bytes: 43288
//36
#include<iostream>
#include<cstring>

using namespace std;

int main(){
  int n;
  cin>>n;
  int c[200];
  for(int i=0;i<2*n;i++){
    c[i]=i+1;
  }
  int m;
  cin>>m;
  while(m--){
    int k;
    cin>>k;
    if(k){
      int t[200];
      memcpy(t,c,sizeof(c[0])*k);
      memmove(c,c+k,sizeof(c[0])*(2*n-k));
      memcpy(c+2*n-k,t,sizeof(c[0])*k);
    }else{
      int t[200];
      memcpy(t,c,sizeof(c[0])*2*n);
      for(int i=0;i<n;i++){
	c[2*i]=t[i];
	c[2*i+1]=t[i+n];
      }
    }
  }
  for(int i=0;i<2*n;i++){
    cout<<c[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;



int main() {
ll add=0;
int N;
cin>>N;
ll A[N],B[N];
rep(i,N){
    cin>>A[i]>>B[i];
}
repr(i,N){
    if((A[i]+add)%B[i]!=0){
    add+=B[i]-(A[i]+add)%B[i];
    }
}
cout<<add<<endl;
return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
void PDF(int B[],int o,int k)
{
    int c,y,s=0,t=0,i;
    float l,r;
    l = (float) 1/(4*k);
    for(i=0;i<o;i++)
    {
        s = s+B[i];
    }
    r = s*l;
    for(i=0;i<o;i++)
    {
        if(B[i]>=r)
        {
            t++;
        }
    }
    if(t>=k)
    {
        cout << "Yes" <<endl;
    }
    else
    {
        cout << "No" <<endl;
    }
}
int main()
{
    int A[10000];
    int n,m,i,j,l;
    cin >> n >> m;
    for(i=0;i<n;i++)
    {
        cin >> A[i];
    }
    PDF(A,n,m);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n" 
#define p pair<int, int>
#define arrinp(i, a, start, end); for(ll i = start; i <= end; i++) cin >> a[i];
#define arrout(i, a, start, end); for(ll i = start; i <= end; i++) cout << a[i] << " ";
#define swap(a, b) {a = a + b; b = a - b; a = a - b;
#define forfront(i, start, end) for(ll i = start; i <= end; i++)
#define forback(i, start, end) for(ll i = start; i >= end; i--)
#define out(x) cout << x << " ";
#define outline(x) cout << x << endl;
const int N = 3e5 + 1;
vector<int> graph[N];
int visited[N];
int returnSize(int node)
{
    visited[node] = 1;
    int count = 1;
    for(int x : graph[node])
    {
        if(visited[x] == 0)
        {
            count += returnSize(x);
        }
    }
    return count;
}
// Returns no of connected components.
int noOfComponents(int n)
{
    int maxComponent = 0;
    for(int i = 1; i < n + 1; i++)
    {
        if(visited[i] == 0)
        {
            int ans = returnSize(i);
            // out(i)
            // outline(ans)
            maxComponent = max(maxComponent, ans);
        }
    }
    return maxComponent;
}
int main()
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int m;
    cin >> m;
    forfront(i, 1, m)
    {
        int u, v;
        cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    int count = noOfComponents(n);
    outline(count);
    return 0;
}

Measured memory_bytes: 27052
#include <iostream>

using namespace std;

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

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

    int count = 1;
    int max = h[0];
    for (int i = 1; i < n; i++)
    {
        if (h[i] >= max)
        {
            count++;
            max = h[i];
        }
    }

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

Measured memory_bytes: 256
N = int(input())

ans = 0
for n1 in ['0','3','5','7']:
	for n2 in ['0','3','5','7']:
		for n3 in ['0','3','5','7']:
			for n4 in ['0','3','5','7']:
				for n5 in ['0','3','5','7']:
					for n6 in ['0','3','5','7']:
						for n7 in ['0','3','5','7']:
							for n8 in ['0','3','5','7']:
								for n9 in ['0','3','5','7']:
									target = int(n1+n2+n3+n4+n5+n6+n7+n8+n9)
									if N <target:
										continue
										
									if 0 <str(target).count('0'):
										continue
										
									if str(target).count('3')==0:
										continue
										
									if str(target).count('5')==0:
										continue
										
									if str(target).count('7')==0:
										continue
									#print(target)
									ans +=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 1e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
inline ll kissme(ll x,ll y)
{
	ll res=1;
	if(x==0)return 1;
	if(x==1)return y;
	res=kissme(x/2,y);
	res=res*res%mod;
	if(x%2==1)res=res*y%mod;
	return res;
}
void read(int &x)
{
    int f=1;
    x=0;
    char s=getchar();
    while(s<'0'||s>'9')
    {
        if(s=='-')
            f=-1;
        s=getchar();
    }
    while(s>='0'&&s<='9')
    {
        x=x*10+s-'0';
        s=getchar();
    }
    x*=f;
}
void print(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
int n,m,k,ans;
char c[10][10],h[10][10];
bool check(int x,int y)
{
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			h[i][j]=c[i][j];
	for(int i=0;i<n;i++)
	{
		if((x>>i)&1)
		{
			for(int j=0;j<m;j++)
			{
				h[i][j]='.';
			}
		}
	}
	for(int j=0;j<m;j++)
	{
		if((y>>j)&1)
		{
			for(int i=0;i<n;i++)
			{
				h[i][j]='.';
			}
		}
	}
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(h[i][j]=='#')cnt++;
		}
	}
	return cnt==k;
}
signed main()
{
	Very_fast;
	cin>>n>>m>>k;
	for(int i=0;i<n;i++)cin>>c[i];
	for(int i=0;i<(1<<n);i++)
	{
		for(int j=0;j<(1<<m);j++)
		{
			if(check(i,j))
			{
				ans++;
			}
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define nl "\n"
#define pb push_back
#define sp " "
typedef long long ll;

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n , m;
    cin >> n>> m;
    double sum=0;
    double arr[n];
    for(int i=0;i<n;i++)cin >>arr[i], sum+=arr[i];
    int cnt=0;
   // cout<<sum<<nl;
    double temp=sum/(4*m);
   // cout<<temp<<nl;
    for(int i=0;i<n;i++){
        if(arr[i]>=temp)cnt++;



    }
  //  cout<<cnt<<nl;
    if(cnt>=m)cout<<"Yes"<<nl;
    else cout<<"No"<<nl;
}


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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve() 
{
	int n , L;
	
	cin >> n >> L;
	
	int mx = inf;
	int sm1 = 0;
	
	for(int i = 1; i <= n; ++i) {
		sm1 += L + i -1;
	}
	
	int ans;
	
	for(int i = 1 ; i <= n; ++i) {
		int sm = 0;
		
		for(int j = 1; j <= n; ++j) {
			if(i != j) {
				sm += L + j - 1;
			}
		}
		
		//cout << abs(sm - sm1) << " " << sm << endl;
		
		if(abs(sm - sm1) < mx) {
			mx = abs(sm - sm1);
			ans = sm;
		}
	}
	
	cout << ans;
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3632
S = gets.chomp.split("")
ans = 0
Mod = 10**9 + 7
rcs = S[2..-1].count{ |s| s == "C" }
rqs = S[2..-1].count{ |s| s == "?" }
las = S[0] == "A" ? 1 : 0
lqs = S[0] == "?" ? 1 : 0
powers_of_3 = [1]
(S.size).times{ powers_of_3 << powers_of_3[-1] * 3 % Mod }
(1...S.size-1).each{ |i|
  if S[i] == "B" || S[i] == "?" 
    va = [las * powers_of_3[lqs], lqs > 0 ? lqs * powers_of_3[lqs-1] : 0]
    vc = [rcs * powers_of_3[rqs], rqs > 0 ? rqs * powers_of_3[rqs-1] : 0]
    ans += (va[0] + va[1]) * (vc[0] + vc[1])
    ans %= Mod
  end
  las += 1 if S[i] == "A"
  lqs += 1 if S[i] == "?"
  rcs -= 1 if S[i+1] == "C"
  rqs -= 1 if S[i+1] == "?"
}
p ans

Measured memory_bytes: 12668
#!/usr/bin python3
# -*- coding: utf-8 -*-

#import sys
#input = sys.stdin.readline

def main():
    S = input()
    Q = int(input())
    H = True
    A = ''
    B = ''
    for i in range(Q):
        q = list(input().split())
        if q[0] == '1':
            H = not H
        elif q[1]=='1' and H:
            A = q[2] + A
        elif q[1]=='2' and not H:
            A = q[2] + A
        elif q[1]=='1' and not H:
            B = B + q[2]
        elif q[1]=='2' and H:
            B = B + q[2]
    ret = A + S + B
    if H:
        print(ret)
    else:
        print(ret[::-1])

if __name__ == '__main__':
    main()

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

int main(){
  long long n;
  cin >> n;
  vector<long long> d(n);
  for(int i = 0; i < n; i++) cin >> d[i];
  
  if(d[0] != 0) cout << 0 << endl;
  
  else{
  
  	map<long long, long long> mp;
  	for(int i = 0; i < n; i++) mp[d[i]]++;
  
  	long long ans = 1;
  
  	for(int i = 1; i < n; i++){
    	ans *= mp[d[i] - 1];
    	ans %= 998244353;
    }
  
  	cout << ans << endl;
  }
}

Measured memory_bytes: 7296
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a = sc.next();
        String b[] = a.split("");
		int pay = 700;
        
      	for(int i = 0;i < 3;i++){
          if(b[i].equals("o")){
            pay += 100;
          }
        }
          System.out.println(pay);

 
      	
 
    }
}

Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 */
int main()
{
    int N, M;
    cin >> N >> M;
    priority_queue<int> que;
    REP(i, N) {
        ll A;
        cin >> A;
        que.push(A);
    }
    while(!que.empty() && M--) {
        ll price = que.top();
        que.pop();
        price /= 2;
        if(price) que.push(price);
    }
    ll total = 0;
    while(!que.empty()) {
        total += que.top();
        que.pop();
    }
    cout << total << endl;
    return 0;
}

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

int main() {
    int n, k;
    int h[100000];
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> h[i];

    sort(h, h + n);

    int ans = 1000000000;
    for (int i = k - 1; i < n; i++) {
        ans = min(ans, h[i] - h[i - k + 1]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3940
#include<iostream>
#include<vector>
using namespace std;
const int INF = 1e9+7;

int main(){
	int n;
	cin >> n;
	vector<int> h(n);
	for(int &x:h){
		cin >> x;
	}
	
	vector<int> dp(n, INF);
	dp[0] = 0;
	for(int i = 0; i<n; i++){
		for(int j : {i+1,i+2}){
			if(j < n){
				dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
			}
		} 
	}
	cout << dp[n-1] <<"\n";
	return 0; 
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
    string n; cin >> n;
    int tot = 0;
    for(int i=0; i<n.size(); i++){
        int k = n[i] - '0';
        tot += k;
    }
    if(tot % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nax=3005;
ll dp[nax][nax];
int main(){
		ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
	    int n;
	    cin>>n;
	    int a[n];
	    for(int i=0;i<n;i++){
	      cin>>a[i];
	    }
	    for(int l=n-1;l>=0;--l){
			for( int r=0;r<n;++r){
				if(l==r)
				dp[l][r]=a[l];
				else
				dp[l][r]=max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
			}
		}
	cout<<dp[0][n-1]<<endl;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string C;
  cin >> C;
  
  string str = "abcdefghijklmnopqrstuvwxyz";
  
   int i = 0;
   string D;
   D = str.at(i);
  while (D != C) {
  i++;
  D = str.at(i);
  } 
  
  cout << str.at(i+1) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  V<ll> x(n);
  rep(i, n) cin >> x[i];

  ll ans = 0;
  for (int i = 1; i < n; i++) {
    ll d = x[i] - x[i - 1];
    ll c = d * a;
    if (c > b) {
      ans += b;
    } else {
      ans += c;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3992
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
const ll INF = 1LL << 60;
const ll MOD = 1'000'000'007;

int main(void){
    int n,m;
    cin >> n >> m;
    bool a[100010];
    REP(i,n+1) a[i]=true;
    REP(i,m) {
        int tmp;
        cin >> tmp;
        a[tmp]=false;
    }
    ll dp[100010]={0};
    dp[0]=1;
    if(a[1])dp[1]=1;
    for(int i=2;i<=n;i++){
        if(a[i])
            dp[i]=(dp[i-1]+dp[i-2])%MOD;
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 4476
while True:

    N = int(raw_input())
    if N == 0:
        break

    gems = []
    x, y = 10, 10
    direc = {
        "N": (0, 1),
        "E": (1, 0),
        "S": (0, -1),
        "W": (-1, 0)
    }

    for _ in range(N):
        xi, yi = map(int, raw_input().split())
        gems.append((xi, yi))
    M = int(raw_input())
    for _ in range(M):
        dat = raw_input().split()
        d, l = dat[0], int(dat[1])
        for _ in range(l):
            x += direc[d][0]
            y += direc[d][1]
            #print "check", x, y
            if (x, y) in gems:
                gems.remove((x, y))
    if gems == []:
        print "Yes"
    else:
        print "No"


Measured memory_bytes: 4256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a,b) for(int i=int(a);i>int(b);--i)
using namespace std;
using ll = long long;

int main()
{
  string s;
  cin >> s;
  cout << ((regex_match(s,regex("(dream|dreamer|erase|eraser)*")))?"YES":"NO") << "\n";
}


Measured memory_bytes: 39808
var
	N,i,j:Longint;
	A:Array[1..100,1..99]of Longint;
begin
	read(N);
	if N=2 then begin
		writeln(-1);
		exit;
	end;
	if N mod 2=1 then begin
		for i:=1 to N-1 do A[N,i]:=i;
		i:=1;
		while i<=N-1 do begin
			for j:=1 to i-1 do begin
				A[i,j]:=j;
				A[i+1,j]:=j;
			end;
			A[i,i]:=i+1;
			A[i+1,i+1]:=i;
			A[i,i+1]:=i+2;
			A[i+1,i]:=i+2;
			for j:=i+2 to N-1 do begin
				A[i,j]:=j+1;
				A[i+1,j]:=j+1;
			end;
			inc(i,2);
		end;
	end else begin
		i:=1;
		while i<=N-2 do begin
			for j:=1 to i-1 do begin
				A[i,j]:=j;
				A[i+1,j]:=j;
			end;
			A[i,i]:=i+1;
			A[i+1,i+1]:=i;
			A[i,i+1]:=i+2;
			A[i+1,i]:=i+2;
			for j:=i+2 to N-1 do begin
				A[i,j]:=j+1;
				A[i+1,j]:=j+1;
			end;
			inc(i,2);
		end;
		for j:=1 to N-3 do begin
			A[N-1,j]:=j;
			A[N,j]:=j;
		end;
		A[N-1,N-2]:=N;
		A[N,N-1]:=N-1;
		A[N-1,N-1]:=N-2;
		A[N,N-2]:=N-2;
	end;
	for i:=1 to N do begin
		for j:=1 to N-1 do begin
			writeln(A[i,j]);
		end;
	end;
end.


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n, m;
    cin >> n >> m;
    vector< pair<int , ll> > V(n, make_pair(0,0));
    REP(i, n) cin >> V[i].first >> V[i].second;
    sort(ALL(V));
    // REP(i,n) cout <<i << " "<< V[i].first << " " << V[i].second << endl;

    int now_at=0;
    ll cost = 0;
    while(m>=1){
        if(V[now_at].second >= m){
            cost += V[now_at].first * m;
            m -= m;
        }
        else{
            m -= V[now_at].second;
            cost += V[now_at].first * V[now_at].second;
            now_at++;
        }
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 1792