akhauriyash/Code-Regression huggingface dataset:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c, k = map(int, readline().split())
if a + b >= k:
    print(min(a, k))
else:
    print(a - (k - a - b))


Measured memory_bytes: 61816
import Control.Monad
import Data.List

main = do
    [n, m] <- fmap read <$> words <$> getLine
    ab <- forM [1..n] $ \i -> do
        [ai, bi] <- fmap read <$> words <$> getLine
        return (ai, bi)
    putStrLn $ show $ solve n m ab

solve :: Int -> Int -> [(Integer, Integer)] -> Integer
solve n m ab = doit (fromIntegral m) (sort ab)
  where
    doit m ((a, b) : ab) | m <= b    = m * a
                         | otherwise = b * a + doit (m - b) ab

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

int main() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    vector<string> ans;
    for(int i = 1; i <= k; i++) {
        int limit = n - i + 1;
        rep(j,limit) {
            string a = s.substr(j,i);
            ans.push_back(a);
        }
    }
    sort(ans.begin(),ans.end());
    ans.erase(unique(ans.begin(),ans.end()),ans.end());
    cout << ans[k-1] << "\n";
    return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

long long gcd(long long a, long long b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
    return (a * b) / gcd(a, b);
}

int main() {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> zerobit(61);
    vector<int> onebit(61);
    for (int i = 0; i < n; i++) {
        for (long long bit = 0; bit <= 60; bit++) {
            if (a[i] & (1ll << bit)) onebit[bit]++;
            else zerobit[bit]++;
        }
    }
    long long ans = 0;
    for (long long bit = 0; bit <= 60; bit++) {
        ans = ((ans % MOD) + (((zerobit[bit] % MOD * onebit[bit] % MOD) % MOD) * ((1ll << bit) % MOD)) % MOD) % MOD;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 5592
#include<iostream>
#include<iomanip>

using namespace std;

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

void Main(){
  int a,b,c;
  cin>>a>>b>>c;
  a!=b && b!=c && a!=c? cout<<3<<endl : a==b && b==c && a==c ? cout<<1<<endl : cout<<2<<endl;
}

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  Main();
}

Measured memory_bytes: 256
a, b, ab, x, y = map(int, input().split())
ave = (a + b) / 2
minxy = min(x, y)
amt = 0

if ave > ab:
    amt += ab * minxy * 2
else:
    amt += (a + b) * minxy
    
if x == minxy:
    if b / 2 > ab:
        amt += ab * (y - minxy) * 2
    else:
        amt += b * (y - minxy)
else:
    if a / 2 > ab:
        amt += ab * (x - minxy) * 2
    else:
        amt += a * (x - minxy)
        
print(amt)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
	return *(int*)a-*(int*)b;
}
int main()
{
	int n,m,s,t[20005]={0},r;
	for(;scanf("%d%d",&n,&m),n+m;)
	{
		for(s=1;s<=n+m;s++)
			scanf("%d",&t[s]);
		qsort(t,n+m+1,4,cmp);
		for(s=r=0;s<n+m;r=r<t[s+1]-t[s]?t[s+1]-t[s]:r,s++);
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 804
###AGC,GAC,ACG,A*GC,AG*Cが存在しない

###k-1個の組み合わせの後に'AGCT'を付け足し、ダメな組み合わせを引いた数がk個の組み合わせ
###k-1がl個のとき、kはl*4-ダメな数

import sys

n = int(input())

if n <= 2:
  print(4**n)
  sys.exit()

end = {}
for i in ['A','G','C','T']:
  for j in ['A','G','C','T']:
    for k in ['A','G','C','T']:
      if i+j+k in ['AGC','GAC','ACG']:
        end[i+j+k] = 0
      else:
        end[i+j+k] = 1
        
num = 61
if n == 3:
  print(num)
  sys.exit()

###*AG+C
notend = ['AAG','GAG','CAG','TAG']
notpattarn = ['AAGC','GAGC','CAGC','TAGC']
###*GA+C
notend += ['AGA','GGA','CGA','TGA']
notpattarn += ['AGAC','GGAC','CGAC','TGAC']
###*AC+G
notend += ['AAC','CAC','TAC']
notpattarn += ['AACG','CACG','TACG']
###AG*+C
notend += ['AGG','AGT']
notpattarn += ['AGGC','AGTC']
###A*G+C
notend += ['ATG']
notpattarn += ['ATGC']

for i in range(4,n+1):
  
  num *= 4
  for j in end.keys():
    if j in notend:
      num -= end[j]
      
  end_tmp = {}
  for j in end.keys():
    end_tmp[j] = 0
  
  for j in end.keys():
    for k in ['A','G','C','T']:
      if k+j in notpattarn:
        pass
      else:
        end_tmp[j] += end[k+j[0:2]]
        
  end = end_tmp
  
#print(num)
print(num%(10**9+7))
  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

void solve() {
    int n, m;
    std::cin >> n >> m;
    std::vector<std::pair<int, bool>> result(m);
    rep(i, m) {
        std::string s;
        std::cin >> result[i].first >> s;
        result[i].first--;
        if(s == "AC") {
            result[i].second = true;
        } else {
            result[i].second = false;
        }
    }
    std::vector<int> mp(n, -1);
    for(int i = m - 1; i >= 0; i--) {
        if(result[i].second)
            mp[result[i].first] = 0;
        else if(mp[result[i].first] != -1) {
            mp[result[i].first]++;
        }
    }
    int cnt_ac = 0, cnt = 0;
    rep(i, n) {
        if(mp[i] >= 0) {
            cnt_ac++;
            cnt += mp[i];
        }
    }
    std::cout << cnt_ac << " " << cnt << std::endl;
}

int main() {
    // std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 1408
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s; cin >> s;
    
    for(uint i=0; i<s.size(); ++i){
        if(s[i]=='1'){ cout << '9';
        }    else    { cout << '1'; }
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
  int N;
  scanf("%d", &N);

  int res = 0;
  for (int i = 0; i < N; ++i) {
    int a;
    scanf("%d", &a);

    res += __builtin_ctz(a);
  }
  printf("%d\n", res);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int maxn = 100100;
struct edges
{
	int to, next;
}edge[maxn * 2];
int point[maxn] = {0}, te = 1;
void add(int a, int b)
{
	te ++;
	edge[te].to = b;
	edge[te].next = point[a];
	point[a] = te;
}
bool flag[maxn * 2] = {0};
int du[maxn] = {0};
bool dfs(int now, int ed, int p)
{
	if(p && now == ed)
		return 1;
	du[now] --;
	//cout << now << " " << ed << " " << p << endl;
	for(int e = point[now]; e; e = edge[e].next)
		if(!flag[e])
		{
			//cout << edge[e].to << endl;
			du[edge[e].to] --;
			flag[e] = flag[e ^ 1] = 1;
			return dfs(edge[e].to, ed, now);
		}
	return 0;
}
int n, m;
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 1; i <= m; i ++)
	{
		int a, b;
		cin >> a >> b;
		du[a] ++;
		du[b] ++;
		add(a, b);
		add(b, a);
	}
	int st[3], cnt = 0;
	bool asd = 0;
	for(int i = 1; i <= n; i ++)
	{
		if(du[i] % 2 == 1)
		{
			cout << "No" << endl;
			return 0;
		}
		if(du[i] >= 6)
		{
			asd = 1;
			continue;
		}
		if(du[i] > 2)
		{
			cnt ++;
			if(cnt > 2)
			{
				asd = 1;
				continue;
			}
			st[cnt] = i;
		}
	}
	if(asd)
	{
		cout << "Yes" << endl;
		return 0;
	}
	if(cnt < 2)
	{
		cout << "No" << endl;
		return 0;
	}
	dfs(st[1], st[2], 0);
	dfs(st[1], st[2], 0);
	if(dfs(st[1], st[2], 0))
	{
		cout << "No" << endl;
		return 0;
	}
	/*
	for(int i = 1; i <= n; i ++)
		cout << du[i] << " " ;
	cout << endl;
	*/
	cout << "Yes" << endl;
	//cerr << "Yes" << endl;
	return 0;
}
/*
4 6
1 2
2 3
1 3
1 3
1 4
4 3
*/
/*
10 14
7 1
1 3
3 9
9 1
1 4
4 6
6 2
4 8
8 10
10 8
8 5
5 6
6 1
1 2
*/

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

typedef long long ll;

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout << i << endl;
#define AS(i) cout << i << " ";

const int INF = 1001001001;
const double PI = 3.14159;

using namespace std;


int main() {

    int l, r, d;
    cin >> l >> r >> d;

    int ans = 0;

    for (int i = l; i <= r; i++) {
        if (i % d == 0)
            ans++;
    }

    AA(ans);
}

Measured memory_bytes: 3592
s = input()

ans=0
slist= [int(i) for i in s]

for i in range(len(s)-1):
    if slist[i] == slist[i+1]:
        ans += 1
        if slist[i+1] == 1:
            slist[i+1] = 0
        else:
            slist[i+1] = 1

print(ans)

Measured memory_bytes: 45020
C(int*a,int*b){return*a-*b;}
p['~~'];a[9];i,j,M;c[]={0,2,5,5,4,5,6,3,7,6};
main(n,m){
	for(scanf("%d%d",&n,&m);~scanf("%d",a+j++););
	for(qsort(a,m,4,C);i++<n;p[i]=M)
		for(M=-9,j=m;j--;)M=fmax(M,c[a[j]]>i?M:p[i-c[a[j]]]+1);
	for(i=n;p[i];putchar(a[j]+48),i-=c[a[j]])
		for(j=m;j--&&(i<c[a[j]]||p[i-c[a[j]]]+1-p[i]););
}

Measured memory_bytes: 256
function Main(input) {
    var a = Number(getLineAndSplit(input, 0)[0]);
    var b = Number(getLineAndSplit(input, 0)[1]);
    console.log((a * b) % 2 === 0? 'Even': 'Odd')
}

function getLine(input, rowNum) {
    var inputs = input.split("\n");
    return inputs[rowNum];
}

function getLineAndSplit(input, rowNum) {
    return getLine(input, rowNum).split(" ");
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require("fs").readFileSync("./input", "utf8"));

Measured memory_bytes: 11468
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N, M; std::cin >> N >> M;
  std::string s; std::cin >> s;
  std::vector<std::vector<int>> G(N);
  std::vector<int> dA(N,0), dB(N,0);
  std::set<std::pair<int,int>> ps;
  for(int i = 0; i < M; ++i) {
    int a, b; std::cin >> a >> b; --a; --b;
    if(a > b) std::swap(a,b);
    if(ps.count(std::make_pair(a,b))) continue;
    ps.insert({a,b});
    G[a].push_back(b);
    G[b].push_back(a);
    if(s[a]=='A') ++dA[b]; else ++dB[b];
    if(a < b) {
      if(s[b]=='A') ++dA[a]; else ++dB[a];
    }
  }
  std::queue<int> q;
  for(int i = 0; i < N; ++i) if(dA[i] == 0 || dB[i] == 0) q.push(i);
  while(!q.empty()) {
    int i = q.front(); q.pop();
    if(s[i] == ' ') continue;
    auto& deg = (s[i] == 'A'? dA: dB);
    s[i] = ' ';
    for(int j: G[i]) if(--deg[j] == 0) q.push(j);
  }
  for(char c: s) if(c!=' ') fin("Yes");
  fin("No");
  return 0;
}


Measured memory_bytes: 21072
#include<iostream>
#include<string>
using namespace std;
int main() {
  string O,E; cin >> O >> E;
  if(O.size()==E.size()){
    for(int i=0;i<O.size();i++) cout << O[i] << E[i];
  }else if(O.size()>E.size()){
    for(int i=0;i<E.size();i++) cout << O[i] << E[i];
    cout << O[E.size()];
  }else if(O.size()<E.size()){
    for(int i=0;i<O.size();i++) cout << O[i] << E[i];
    cout << E[O.size()];
  }
  return 0;
}

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

int main(void){
    int passwordStartedby[100];
    for(int i = 0; i < 100; ++i) passwordStartedby[i] = 0;
    int N;
    std::cin >> N;
    std::string S;
    std::cin >> S;

    // finalPosition[i] => i poistion in S (final)
    int finalPosition[10];

    for(int i = 0; i < 10; ++i){
        finalPosition[i] = -1;
    }

    for(int i = 0; i < N; ++i){
        finalPosition[S[i]-'0'] = i;
    }

    for(int i = 0; i < N-1; ++i){
        for(int j = i+1; j < N; ++j){
            int firstTwoWords = (S[i]-'0')*10 + (S[j]-'0');
            if(passwordStartedby[firstTwoWords] > 0) continue;

            int ct = 0;
            for(int p = 0; p < 10; ++p){
                if(finalPosition[p] > j) ++ct;
            }

            passwordStartedby[firstTwoWords] = ct;
        }
    }

    int ret = 0;
    for(int i = 0; i < 100; ++i) ret += passwordStartedby[i];

    std::cout << ret;
    return 0;
}




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

int CoinChoice(vector<int> coin, int target)
{
    int i, j;
    int result[50001];

    for (i = 1; i < 50001; i++) {
        result[i] = 50001;
    }
    result[0] = 0;

    for (i = 0; i < coin.size(); i++) {
        for (j = 0; j + coin[i] <= target; j++) {
            result[j + coin[i]] = min(result[j + coin[i]], result[j] + 1);
        }
    }

    return result[target];
}

int main(void)
{
    int i, tmp;
    int target;
    int cnum;
    int ret;
    vector<int> cointype;

    scanf("%d %d", &target, &cnum);
    for (i = 0; i < cnum; i++) {
        scanf("%d", &tmp);
        cointype.push_back(tmp);
    }

    ret = CoinChoice(cointype, target);

    printf("%d\n", ret);

    return 0;
}

Measured memory_bytes: 1404
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    var total = 1
    var odd = 1
    for (i in 0 until n) {
        total *= 3
        if (a[i] % 2 == 0) {
            odd *= 2
        }
    }
    println(total - odd)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

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


bool check(string a,string b,int d){
  if(a.size()<b.size())swap(a,b);
  if(a==b) return 1;
  int A = a.size(),B=b.size();
  if(d==0||A-B>d)return 0;


  //erase
  for(int i=0;i<A;i++){
    char ch = a[i];
    
    a.erase(a.begin()+i);
    if(check(a,b,d-1))return 1;
    a.insert(a.begin()+i,ch);
  }

  if(A!=B) return 0;

  //swap
  for(int i=0;i<A-1;i++){
    if(a[i]==a[i+1]||a[i+1]!=b[i]||a[i]!=b[i+1])continue;
    swap(a[i],a[i+1]);
    if(check(a,b,d-1))return 1;
    swap(a[i],a[i+1]);
  }
  
  //change
  int cnt=0;
  for(int i=0;i<A;i++) cnt+=a[i]!=b[i];
  return cnt<=d;
}

int main(){
  int n,d;
  while(cin>>n,n){
    cin>>d;
    string str[201];
    for(int i=0;i<n;i++)cin>>str[i];
    sort(str,str+n);

    int cnt=0;    
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++)
	if(check(str[i],str[j],d)) cout<<str[i]<<","<<str[j]<<endl,cnt++;
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
           int n,m;
           cin>>n>>m;
           cout<<n*(n-1)/2 + m*(m-1)/2;
           
         
}

        


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

int main(){
  string s;
  cin>>s;
  int er=0;
  int ans=s.size();
  rep(i,s.size()){
    if(s[i]=='S') er++;
    if(s[i]=='T' && er!=0){
      er--; ans-=2;
    } 
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3684
#pragma GCC optimize("Ofast")
#include<stdio.h>
int main(void)
{
    int n = 0, a = 0, b;
    int d[200000];
    char c=getchar_unlocked();
    while(c<='9'&&c>='0') {n=(n<<1)+(n<<3)+c-'0'; c=getchar_unlocked();}
    int* e = d + n;
    do
    {
        d[n] = 0;
        c=getchar_unlocked();
        while(c<='9'&&c>='0') {d[n]=(d[n]<<1)+(d[n]<<3)+c-'0'; c=getchar_unlocked();}
        a ^= d[n];
    } while(--n);
    while(d != e)
    {
        printf("%d ", a ^ *e);
        --e;
    }
    return 0;
}


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

using namespace std;

#define ll long long int 


int main(){
    string s; cin >> s;
    ll l = s.size();
    ll l1 = (l-1)/2 , l2 = (l+3)/2  - 1;
    bool flag = true;

    for(int i=0; i< l/2; i++){
        if(s[i] != s[l - i -1 ]){
            flag = false;
            break;
        }
    }
    if(flag){
        for(int i=0; i< l1/2; i++){
            if(s[i] != s[l1 - i - 1]){
                flag = false;
                break;
            }


        }

        if(flag){
            for(int i=l2; i< l2+ (l -1 - l2)/2; i++){
                if(s[i] != s[l - 1 -i ]){
                    flag = false;
                    break;
                }
            }
            if(flag)cout<<"Yes" << endl;
            else cout << "No" << endl;

        }
        else
            cout<<"No"<<endl;


    }
    else
        cout<<"No"<<endl;

    // ll ans; 

    return 0;
}

Measured memory_bytes: 256
from collections import Counter
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = Counter([e+i+1 for i,e in enumerate(a)])
    c = Counter([i+1-e for i,e in enumerate(a) if i+1-e > 1])
    ans = 0
    for i in c:
        ans += b[i] * c[i]
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 138276
# coding: utf8

import sys

for line in sys.stdin:
    a, b, c, d, e, f = map(float, line.split())

    if (c * e - b * f) == 0:
        x = 0.0
    else:
        x = round((c*e-b*f)/(a*e-b*d), 3)

    if (c * d - a * f) == 0:
        y = 0.0
    else:
        y = round((c*d-a*f)/(b*d-a*e), 3)

    print '%.3f %.3f' % (x, y)

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

using namespace std;

int main()
{
    std::string input;
    cin >> input;

    int len=input.length();

    // 文字列を1文字ずつ読み込んで、int に変換して加算する。
    int sum = 0;
    for (int i=0;i<len;i++){
        //cout<< input[i]<<endl;
        sum += input[i] - '0';  // char -> int
    }

    if (sum % 9 == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define all(x) (x).begin(), (x).end()
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const int MOD = 998244353; //1e9+7;
const int MAXN = 1e7+1;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int x; cin >> x;
    cout << x/500*1000 + (x%500)/5*5 << endl;
    return 0;
}


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

using namespace std;

int main()
{

    int N, T;
    int c, t;
    vector<int> cost;
    cin >> N >>T;
    for(int i=0; i<N; ++i)
    {
        cin >> c >>t;
        if(t<=T)
        {
            cost.push_back(c);
        }
    }

    if(cost.empty())
    {
        cout<<"TLE"<<endl;
    }
    else
    {
        int min = *min_element(cost.begin(), cost.end());
        cout<<min<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
<?php
// Your code here!
fscanf(STDIN,"%d",$n);
$line = explode(" ", trim(fgets(STDIN)));

$a = $line[0];
$b = $line[1];

$line = '';
for($i=0; $i<$n; $i++){
    $line .= $a[$i].$b[$i];
}
echo $line;


Measured memory_bytes: 4728
#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
    int n, m;
    int data[30];
    int nowdata[30];
    for (int i = 0; i < 30; i++)
    {
        data[i] = 1;
        nowdata[i] = 0;
    }
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int a;
            cin >> a;
            nowdata[a - 1] = 1;
        }
        for (int j = 0; j < 30; j++)
        {
            if (data[j])
            {
                if (!nowdata[j])
                    data[j] = 0;
            }
            nowdata[j] = 0;
        }
    }

    int res = 0;

    for (int i = 0; i < 30; i++)
    {
        if (data[i])
            res++;
    }

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

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

using namespace std ;

const int mod = 1e9 + 7 ;
const int N = 900010 ;
#define ll long long 

int n , m , k ;
ll fac[ N ] , ifac[ N ] , p[ N ] ; 

ll mul( ll x , ll  y ) {
	return ( 1ll * x * y ) % mod ;
}

ll add( ll x , ll y ) {
	return ( x + y ) % mod ;
}

ll power( ll a , ll b ) {
	int ans = 1 , base = a ;
	while( b ) {
		if( b&1 ) ans = mul( ans , base ) ;
		base = mul( base , base ) ; 
		b >>= 1 ;
	}
	return ans ;
}

ll inv( ll x ) {
	return power( x , mod - 2 ) % mod ;
}

ll C( ll x , ll y ) {
	return ( fac[ x ] * ifac[ y ] % mod * ifac[ x - y ] % mod ) % mod ;
}

int main() {
	scanf( "%d%d%d" , &n , &m , &k ) ;
	fac[ 0 ] = 1ll ;
	p[ 0 ] = 1ll ;
	for( int i = 1 ; i < N ; i ++ ) {
		fac[ i ] = fac[ i - 1 ] * i % mod ;
		p[ i ] = p[ i - 1 ] * 3ll % mod ;
	}
	for( int i = 0 ; i < N ; i ++ ) {
		ifac[ i ] = inv( fac[ i ] ) ;
	}
	ll ans = 0 , x = 1ll ;
	n -- ;
	if( m < k ) swap( m , k ) ;
	for( int i = 0 ; i <= m + k ; i ++ ) {
		ans = ( ans + C( n + i , n ) * p[ m + k - i ] % mod * x )  % mod  ;
		/*
		for( int j = 0 ; j < m ; j ++ ) {
			if( j > i || i - j >= k ) break ;
			x = add( x , C( i , j ) ) ;
		}
		*/
		if( i < k ) x = ( x * 2ll ) % mod ;
		else if( i < m ) x = ( x * 2ll - C( i , k ) ) % mod ;
		else  x = ( x * 2ll - C( i , k ) - C( i , m ) ) % mod ;
	}
	printf( "%lld\n" , add( ans , mod ) ) ;
	return 0 ;
} 

Measured memory_bytes: 21376
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9 + 5;
constexpr long long INFLL = 1LL << 62;
constexpr double eps = (1e-9);

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

  ll k;
  cin >> k;

  int n = 50;
  vector<ll> a(50);
  rep(i, n) a[i] = i;

  rep(i, n) {
    a[i] += k / n;
  }

  rep(i, k % n) {
    a[i] += n;
    for (int j = 0; j < n; j++) {
      if (j == i) continue;
      a[j] -= 1;
    }
  }

  printf("%d\n", n);
  for (int i = 0; i < n; i++) {
    printf("%lld%s", a[i], i == n - 1 ? "\n" : " ");
  }

  return 0;
}


Measured memory_bytes: 3748
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int a, b, c, k, x = 0;
    cin >> a >> b >> c >> k;
    while (b <= a) {
        b *= 2;
        x++;
    }
    while (c <= b) {
        c *= 2;
        x++;
    }
    if (x <= k) cout << "Yes";
    else cout << "No";
    return 0;
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

typedef pair<int, int> P;

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( a > b ) { a = b; return 1; } return 0; }

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

signed main(){
    string s1, s2; cin >> s1 >> s2;
    reverse( ALL( s2 ) );
    cout << ( s1 == s2 ? "YES" : "NO" ) << endl;
}


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

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

//Write From this Line

int main()
{
	ll x ,y ;
	cin >>  x >>y ;
	ll ans = 0 ;
	while(x<=y){
		x *= 2;
		ans ++ ;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

using namespace std;
const int inf = 1e9 +5;
int main()
{
    fast;
    ll n,w;
    cin>>n>>w;
    ll wt[n],val[n];
    for(ll i=0;i<n;i++)
    {
        cin>>wt[i]>>val[i];
    }

    ll dp[n+1][w+1];
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=w;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if (wt[i-1] <= j)
            {
                dp[i][j] = max(val[i-1] + dp[i-1][j-wt[i-1]],dp[i-1][j]);
            }
            else
            {
                dp[i][j]= dp[i-1][j];
            }
        }
    }
    cout<<dp[n][w];

    return 0;
}


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

dp = [float("inf")] * ((1<<n) + 1)
dp[0] = 0

for i in range(m):
    a, b = map(int, input().split())
    c_list = list(map(int, input().split()))
    c = 0
    for j in range(b):
        c += 1 << (c_list[j]-1)

    for j in range(1<<n):
        dp[j | c] = min(dp[j] + a, dp[j | c])

if dp[(1<<n) - 1] == float("inf"):
    ans = -1
else:
    ans = dp[(1<<n) - 1]

print(ans)


Measured memory_bytes: 50776
#include <bits/stdc++.h>
#define rep(i, z, n) for(int64_t i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
//const int INF = 1 << 29;
//const int MODINF = 1000000007;
//const int64_t INF = 998244353;
using namespace std;
typedef pair<int64_t, int64_t> P;

int main(){
    int N, R;
    cin >> N >> R;
    cout << R + 100 * max((10 - N), 0) << endl;
}

Measured memory_bytes: 256
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-12 15:24:43
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  long double w, h; cin >> w >> h;
  long double x, y; cin >> x >> y;

  if (x == w / 2 && y == h / 2) {
    cout << setprecision(17) << w * h / 2 << " " << 1 << endl;
  } else {
    cout << setprecision(17) << w * h / 2 << " " << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
const int inf = 233333333;

struct Node{
	int x, l, r;
	Node(){}
	Node(int a, int b, int c) {x = a, l = b, r = c;}
	bool operator < (const Node & a) const{
		return x > a.x;
	}
};

int n, nn, M;
int T1[N << 3], T2[N << 3], seq[N]; 
priority_queue<Node> q;

int Min(int x, int y){if(seq[x] > seq[y]) return y; return x;}

int Query(int x, int y, int * T){
	if(x > y) return 0;
	int res = 0;
	for(x = x + M - 1, y = y + M + 1; x ^ y ^ 1; x >>= 1, y >>= 1){
		if(~ x & 1) res = Min(res, T[x ^ 1]);
		if(  y & 1) res = Min(res, T[y ^ 1]);
	}
	return res;
}

int Query(int x, int y, int f){
	if(f & 1) return Query(x, y, T1);
	return Query(x, y, T2);
}

void Change(int x, int t, int * T){
	x += M;
	T[x] = t;
	for(x >>= 1; x; x >>= 1) T[x] = Min(T[x << 1], T[x << 1 | 1]);
	return;
}

int main(){
	seq[0] = inf;
	scanf("%d", & n);
	for(int i = 1; i <= n; i ++)
		scanf("%d", &seq[i]);
	for(M = 1; M <= n + 1; M <<= 1);
	for(int i = 1; i <= n; i += 2) T1[i + M] = i;
	for(int i = 2; i <= n; i += 2) T2[i + M] = i;
	for(int i = M - 1; i; i --) T1[i] = Min(T1[i << 1], T1[i << 1| 1]), T2[i] = Min(T2[i << 1], T2[i << 1 | 1]);
	q.push(Node(seq[Query(1, n, 1)], 1, n));
	Node k;
	int x, y;
	while(!q.empty()){
		k = q.top();
		q.pop();
		x = Query(k.l, k.r, k.l & 1);
		y = Query(x, k.r, !(k.l & 1));
		printf("%d %d ", seq[x], seq[y]);
		if(k.l < x) q.push(Node(seq[Query(k.l, x - 1, k.l & 1)], k.l, x - 1));
		if(y - x >= 2) q.push(Node(seq[Query(x + 1 , y - 1, (x + 1) & 1)], x + 1, y - 1));
		if(y < k.r) q.push(Node(seq[Query(y + 1, k.r, (y + 1) & 1)], y + 1, k.r));
	}
	
	return 0;
}

Measured memory_bytes: 10236
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	dd={'A':'a', 'B':'b', 'C':'c'}
	n, k = IN()
	s = input()
	
	ret=s[:k-1]+dd[s[k-1]]+s[k:]
	return ret
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
#include<iostream>
#include<complex>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define NEXT(i,n) ((i+1)%(n))

typedef complex<double> P;
typedef vector<P> vp;


const double eps = 1e-10;
P ori[4];

double cross(P a,P b){
  return a.real()*b.imag() - a.imag()*b.real();
}

P intersection_point(P a1,P a2,P b1,P b2){
  P b = b2-b1;
  double d1 = abs(cross(b,a1 - b1));
  double d2 = abs(cross(b,a2 - b1));
  double t = d1 / (d1 + d2);
  return a1 + (a2 - a1) * t;
}

vp construct_vertical_line(P a,P b,vp &c,vp &d){
  vp ret;
  ret.pb(a);
  rep(i,c.size()){
    ret.pb(intersection_point(a,b,c[i],d[i]));
  }
  ret.pb(b);
  return ret;
}


double polygon_area(vp &a){
  double sum = 0;
  int n = a.size();
  rep(i,a.size()){
    sum += (a[i].real() - a[NEXT(i,n)].real()) * (a[i].imag() + a[NEXT(i,n)].imag());
  }
  if (sum < 0)sum*=-1;
  return sum/2.;
}

double calc_vertic(vp a,vp b){
  double ret = 0;
  rep(i,(int)a.size() - 1){
    vp arg;
    arg.pb(a[i]);
    arg.pb(a[i+1]);
    arg.pb(b[i+1]);
    arg.pb(b[i]);
    ret = max(ret,polygon_area(arg));
  }
  return ret;
}

double solve(int n,vp a,vp b,vp c,vp d){
  vp vertic[n+2];
  
  vertic[0].pb(ori[0]);
  rep(i,n)vertic[0].pb(c[i]);
  vertic[0].pb(ori[1]);
  
  rep(i,n)vertic[i+1] = construct_vertical_line(a[i],b[i],c,d);
  
  vertic[n+1].pb(ori[2]);
  rep(i,n)vertic[n+1].pb(d[i]);
  vertic[n+1].pb(ori[3]);

  double ans = 0;
  rep(i,n+1){
    ans = max(ans,calc_vertic(vertic[i],vertic[i+1]));
  }

  return ans;
}

main(){
  ori[0].real() = 0;ori[0].imag() = 0;
  ori[1].real() = 0;ori[1].imag() = 1;
  ori[2].real() = 1;ori[2].imag() = 0;
  ori[3].real() = 1;ori[3].imag() = 1;
  int n;
  while(cin>>n && n){
    vp in[4];//bottom,top,left,right
    P tmp;

    tmp.imag() = 0;
    rep(i,n)cin>>tmp.real(),in[0].pb(tmp);

    tmp.imag() = 1;
    rep(i,n)cin>>tmp.real(),in[1].pb(tmp);

    tmp.real() = 0;
    rep(i,n)cin>>tmp.imag(),in[2].pb(tmp);

    tmp.real() = 1;
    rep(i,n)cin>>tmp.imag(),in[3].pb(tmp);

    
    printf("%.6lf\n",solve(n,in[0],in[1],in[2],in[3]));
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<(int)(r); i++)
#define rep_eq(i,l,r) for(int i=l; i<=(int)(r); i++)
#define all(vec) vec.begin(),vec.end()
using namespace std;

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

using ll=long long;

using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;
using vs=vector<string>;

const ll INF=LLONG_MAX;
const ll mod=1e9+7;

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

  int N,M; cin >>N >>M;
  vi oks(N+1,true);
  rep(i,0,M) {
    int a; cin >>a;
    oks[a]=false;
  }
  vll dp(N+1);
  dp[0]=1;
  rep(now,0,N) {
    rep_eq(next,now+1,min(N,now+2)) {
      if (oks[next]) {
        dp[next]+=dp[now];
        dp[next]%=mod;
      }
    }
  }
  cout <<dp.back() <<'\n';
  return 0;
}


Measured memory_bytes: 4492
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(int t=1; ; ++t){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<vector<int> > a(n, vector<int>(n));
        int b = 0;
        for(int i=0; i<2*n-1; ++i){
            for(int j=0; j<=i; ++j){
                int y = i - j;
                int x = j;
                if(i % 2 == 1)
                    swap(y, x);

                if(0 <= y && y < n && 0 <= x && x < n)
                    a[y][x] = ++ b;
            }
        }

        cout << "Case " << t << ':' << endl;
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j)
                cout << setw(3) << a[i][j];
            cout << endl;
        }
    }
}

Measured memory_bytes: 0
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")
           
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
           
using namespace std;
using namespace __gnu_pbds;
           
//#define int long long
  
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
           
using matrix = vector<vector<ll>>;
template<typename T>
using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
           
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
  
void FAST_IO() {
    //ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.setf(ios::fixed);
    //cout.precision(20);
    #ifndef _offline
    //freopen("mincost.in", "r", stdin);
    //freopen("mincost.out", "w", stdout);
    #endif
}

bool is_pal(string s) {
    string t = s;
    reverse(all(t));
    return (s == t);
}

signed main() {
    FAST_IO();
    string s;
    cin >> s;
    int n = s.length();
    if (!is_pal(s) || !is_pal(s.substr(0, (n - 1) / 2)) || !is_pal(s.substr((n + 3) / 2 - 1))) {
        cout << "No\n";
    }
    else {
        cout << "Yes\n";
    }
}   

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

int main(){

  int N;
  cin >> N;
  int d[N];
  for(int i=0;i<N;++i){
    cin >> d[i];
  }
  sort(d,d+N);
  int res=0;
  int num_ABC=d[N/2-1];
  int num_ARC=d[N/2];
  res =num_ARC-num_ABC;
    cout << res;
}

Measured memory_bytes: 640
N = int(input())
X = list(map(int, input().split()))
MOD = 10 ** 9 + 7

def prepare(n, MOD):
 
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs

fact, rfact = prepare(N, MOD)

ret = 0
inv = 0
for i in range(N-1):
    diff = X[i+1] - X[i]
    # rfact[i]はiの階乗の逆元なので、fact[i-1]をかけて、iの逆元を求める
    # 普通にpow(i, MOD-2, MOD)と計算結果は一致する
    inv += fact[i] * rfact[i+1]
    ret += diff * inv
    ret %= MOD

print(ret*fact[N-1]%MOD)



Measured memory_bytes: 15248
void main()
{
    long[] tmp = readln.split.to!(long[]);
    long k = tmp[0], a = tmp[1], b = tmp[2];

    long op = k - a + 1;
    long cal = a + (b - a) * (op / 2) + op % 2;
    max(k + 1, cal).writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

int main() {
  char b;
  cin >> b;
  
  if (b == 'A') cout << 'T' << endl;
  if (b == 'C') cout << 'G' << endl;
  if (b == 'G') cout << 'C' << endl;
  if (b == 'T') cout << 'A' << endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: u64,
    }
    let mut res = 1;
    for i in 1..n + 1 {
        res = (i * res) % 1_000_000_007;

        //dbg!(res);
    }
    println!("{}", res);
}


Measured memory_bytes: 4352
const main = stdin => {
    const input = stdin.trim().split('\n')
    //ここにかく
    //文字列S
const N = input[0].split(" ")[0];
let S; 

 if (N == 0){
     S = 1;
 } else {
     S = 0;
 };

 console.log(S);
    
};
    // 標準入力
    main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 29656
S = input()
A = []
ans = 0
for i in range(len(S)):
    if i % 2 == 0:
        A.append(1)
    else:
        A.append(0)
for i in range(len(S)):
    if int(S[i]) != int(A[i]):
        ans += 1
print(min(ans, len(S) - ans))

Measured memory_bytes: 3956
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s

int main(){
    int n,m;
    cin >> n >> m;
    cout << (n*m) << "\n";
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		        Scanner sc=new Scanner(System.in);
		        int n=sc.nextInt();
		        StringBuilder stc_out = new StringBuilder();
		        
		        for(int i=1;i<=n;i++){
		        	if(i%3==0){
		        		stc_out.append(" "+i);
		        		continue;
		        	}
		        	int num=i;
		        	while(num!=0){
		        		if(num%10==3){
		        			stc_out.append(" "+i);
		        			break;
		        		}else{
		        			num=num/10;
		        		}
		        	}
		        }
		        System.out.println(stc_out);
	}

}

Measured memory_bytes: 24408
n,a,b=map(int,input().split())

sho=min(a,b)
dai=max(a,b)

if((dai-sho)%2==0):
    print((dai-sho)//2)
else:
    sa=[0]*2
    sa[0]=sho+dai-2
    sa[1]=2*n-sho-dai
    if(sa[0]<sa[1]):
        print((sa[0]+1)//2)
    else:
        print((sa[1]+1)//2)

Measured memory_bytes: 3064
//                _                                      
//  ___ _ __ ___ (_) __ ___      ___   _ _ __ ___  _ __  
// / __| '_ ` _ \| |/ _` \ \ /\ / / | | | '_ ` _ \| '_ \ 
// \__ \ | | | | | | (_| |\ V  V /| |_| | | | | | | |_) |
// |___/_| |_| |_|_|\__, | \_/\_/  \__,_|_| |_| |_| .__/ 
//                  |___/                         |_|  
//code by smigwump
//https://codeforces.com/blog/entry/62393
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long ll;
#define REP(i,a,b) for(ll i = a; i <= b; i++)
#define PER(i,a,b) for(ll i = a; i >= b; i--)


using namespace std;

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll ans = 0;
    REP(i,1,n) {
        ll temp = n/i;
        ans += (i*temp*(temp+1))/2;
    }

    cout<<ans<<"\n";
	return 0;
}


 


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    for(int i = 1; i < n; i++){
        if (a[i-1] + a[i] < x) continue;
        int eat = min(a[i], a[i]+a[i-1]-x);
        a[i] -= eat;
        ans += eat;
    }

    if (a[0] > x){
        ans += a[0] - x;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4024