akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int mod = 1e9+7;

int main() {
    ll H, W, N;
    cin >> H >> W >> N;
    map<pair<int, int>, int> mp;

    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        for (int j = -1; j <= 1; j++) {
            for (int k = -1; k <= 1; k++) {
                mp[make_pair(a+j, b+k)]++;
            }
        }
    }

    vector<ll> ans(10);
    for (const auto &e : mp) {
        if ( (1 <= e.first.first) && (e.first.first < H-1) && (1 <= e.first.second) && (e.first.second < W-1) ) {
            ans[e.second]++;
        }
    }

    // おそらくHが入っていたレジスタに演算結果が入れられてからans[0]に入ると
    // 考えられるのでH, Wもllにしないといけない
    ans[0] = (H-2)*(W-2);
    for (size_t i = 1; i < 10; i++) {
        ans[0] -= ans[i];
    }

    for (size_t i = 0; i < 10; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


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

int main(void) {
    double r, S, l;
    
    scanf("%lf", &r);
    
    S = (double)r * r * M_PI;
    l = (double)r * 2 * M_PI;
    
    printf("%f %f\n", S, l);
    
    return 0;
}


Measured memory_bytes: 2100
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: usize = read();
    let k: usize = read();
    let mut p: Vec<u64> = (0..n).map(|_| read()).collect();
    p.sort();

    let mut ret = 0;
    for i in 0..k {
        ret += p[i];
    }
    println!("{}", ret);
}


Measured memory_bytes: 2140
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0;
	cin >> n;
	vector<lli> a(n);
	for (auto &i : a)
		cin >> i;
	lli sum = accumulate(a.begin(), a.end(), 0ll);
	vector<lli> pre(n, 0ll);
	pre[0] = a[0];
	for (int i = 1; i < n; ++i)
		pre[i] = pre[i - 1] + a[i];
	lli res = 0ll;
	for (int i = 0; i + 1 < n; ++i)
		res = (res + (1ll * a[i] * ((sum - pre[i]) % MOD))) % MOD;
	if (res < 0ll)
		res += MOD;
	cout << res << endl;
}

Measured memory_bytes: 6324
N,M,X = map(int,input().split())
B = []
for i in range(N):
	a = list(map(int,input().split()))
	B.append(a)

def int2bit(n, l):
	ret = [0 for i in range(l)]
	i = 0
	while n > 0:
		ret[i] = n % 2
		i += 1
		n = n // 2
	return ret

MAX = 10**7
ans = MAX
for i in range(1, 2**N):
	b = int2bit(i, N)
	rikai = [0 for j in range(M)]
	for p in range(N):
		if b[p] == 1:
			for j in range(M):
				rikai[j] += B[p][j+1]
	if len([r for r in rikai if r < X]) == 0:
		ans = min(ans, sum([B[p][0] for p in range(N) if b[p] == 1]))
if ans == MAX:
	print(-1)
else:
	print(ans)

Measured memory_bytes: 9268
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+50;
int n,ans,pos,l,r,bpos;
int sum[N];
char s[N],t[N];
int main()
{
	int i;
	bool pd=1;
	scanf("%d",&n);
	scanf("%s",s+1);
	
	scanf("%s",t+1);
	/*
	for(i=248300;i<=248500;i++) putchar(s[i]);
	putchar('\n');
	for(i=248300;i<=248500;i++) putchar(t[i]);
	putchar('\n');
	exit(0);
	*/
	for(i=1;i<=n;i++)
	{
		if(s[i]!=t[i]) pd=0;
	}
	if(pd==1)
	{
		puts("0");
		return 0;
	}
	pos=n+1;ans=0;
	l=1;r=0;bpos=n+2;
	for(i=n;i>=1;i--)
	{
		if(t[i]==t[i-1]) continue;
		if(pos>i&&s[i]==t[i])
		{
			l=1;r=0;bpos=i+1;
			continue;
		}
		pos=min(pos,i);
		while(pos>0&&s[pos]!=t[i]) pos--;
		if(pos==0)
		{
			puts("-1");
			return 0;
		}
		r++;sum[r]=sum[r-1]+bpos-pos-1;
		while(l<r&&pos+(sum[r]-sum[l])>=i) l++;
		//printf("P %d->%d   %d %d   S%d %d\n",pos,i,l,r,sum[r],sum[r-1]);
		ans=max(ans,r-l+1);
		bpos=pos;
		/*
		if(pos==2)
		{
			for(i=1;i<=r;i++) printf("#%d %d\n",i,sum[i]-sum[i-1]);
			exit(0);
		}
		*/
	}
	
	ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6144
'''
Created on 2020/08/29

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  A=list(map(int,pin().split()))
  S=abs(A[0])+abs(A[N-1])
  for i in range(N-1):
    S+=abs(A[i]-A[i+1])
  c=0
  for j in range(N-1):
    print(S-abs(c-A[j])-abs(A[j]-A[j+1])+abs(c-A[j+1]))
    c=A[j]
  print(S-abs(c-A[N-1])-abs(A[N-1])+abs(c))
  return 
main()

Measured memory_bytes: 19912
#include<iostream>
using namespace std;
int main(){
    int x,y;
    for(;;){
        cin >> x >> y ;
        if(x==0 && y==0) break;
        if(x<y) cout << x << " " << y << endl;
        else cout << y << " " << x << endl;
    }
    return 0;
}


Measured memory_bytes: 3004
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */

#include <bits/stdc++.h>
//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class FIntervalRunning {
public:
    void solve(std::istream &in, std::ostream &out) {
        int t1, t2;
        in >> t1 >> t2;
        long long a1, a2;
        in >> a1 >> a2;
        long long b1, b2;
        in >> b1 >> b2;
        if (a1 > b1) {
            swap(a1, b1);
            swap(a2, b2);
        }
        a1 *= t1;
        a2 *= t2;
        b1 *= t1;
        b2 *= t2;
        if (a1 + a2 == b1 + b2) {
            out << "infinity" << "\n";
        } else if (a1 + a2 < b1 + b2) {
            out << 0 << "\n";
        } else {
            long long d = a1 + a2 - b1 - b2, D = b1 - a1, res = D / d * 2;
            D %= d;
            if (D) {
                ++res;
            }
            out << res << "\n";
        }
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    FIntervalRunning solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
#include<algorithm>
#include<set>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)

const int mod=1000000007;


int main(){

int a,b,c,k;
cin>>a>>b>>c>>k;
if(a>=k) cout<<k;
else if(k<=a+b)cout<<a<<endl;
else if(k<=a+b+c) cout<<a-(k-a-b)<<endl;
return 0;
}

Measured memory_bytes: 3160
using System;

namespace atcoderA
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[2]);
            Console.WriteLine(input[1] == "+" ? A + B : A - B);
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin >> N;
    vector<int> x(N), y(N);
    vector<pair<int, int>> coord(N);
    REP(i, N) {
        cin >> x[i] >> y[i];
        coord[i].first = x[i];
        coord[i].second = y[i];
    }
    map<pair<int, int>, int> cnt;
    sort(ALL(coord));
    REP(i, N) {
        for(int j = i + 1; j < N; j++) {
            int p = coord[j].first - coord[i].first;
            int q = coord[j].second - coord[i].second;
            cnt[make_pair(p, q)]++;
        }
    }
    int currentMax = 0;
    pair<int, int> arg_max;
    for(auto it = cnt.cbegin(); it != cnt.cend(); ++it) {
        if(it->second > currentMax) {
            arg_max = it->first;
            currentMax = it->second;
        }
    }
    cout << N - currentMax << endl;
    return 0;
}

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

int main() {
  int N, M, L; cin >> N >> M >> L;
  long long matA[N][M], matB[M][L], matC[N][L];
  memset(matC, 0, sizeof matC);
  for(int i=0; i<N; i++)
    for(int j=0; j<M; j++)
      cin >> matA[i][j];
  for(int i=0; i<M; i++)
    for(int j=0; j<L; j++)
      cin >> matB[i][j];
  for(int i=0; i<N; i++)
    for(int j=0; j<M; j++)
      for(int k=0; k<L; k++)
        matC[i][k] += matA[i][j]*matB[j][k];
  for(int i=0; i<N; i++) {
    for(int j=0; j<L; j++) {
      if(j) cout << " ";
      cout << matC[i][j];
    }
    cout << endl;
  }
  return 0;
}

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

int main() {
  int X,Y;
  cin >> X >> Y;
  
  if((X+Y)%2 == 0){
   cout << (X+Y)/2 << endl;
  }else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
# ABC045B - 3人でカードゲームイージー / Card Game for Three (ABC Edit)
from collections import deque

lst = [deque(list(input().rstrip())) for _ in range(3)]
abc = ["a", "b", "c"]
turn = lst[0].popleft()

while True:
    if not lst[abc.index(turn)]:
        print(turn.upper())
        break
    turn = lst[abc.index(turn)].popleft()

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

int main() {
    ll n;
    cin>>n;
    if(n%2==0)cout<<0.5<<endl;
    else cout<<fixed<<setprecision(10)<<((double)n+1)/(2*(double)n)<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
 
int main(){
    int  a,b;
    while(1){
        scanf("%d%d",&a,&b);
        if(!(a|b))return 0;
        printf("%lf\n",2*sqrt(((double)a/2)*((double)a/2)+b*b)*a+a*a);
    }
}

Measured memory_bytes: 1060
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

bool equiv(
    const vector<string> &A, const vector<string> &B, size_t a, size_t b
) {
    static size_t N=A.size(), M=B.size();
    for (size_t i=0; i<M; ++i) {
        if (i+a >= N) return false;
        if (A[i+a].substr(b, M) != B[i]) return false;
    }

    return true;
}

int main() {
    size_t N, M;
    scanf("%zu %zu", &N, &M);

    vector<string> A(N), B(M);
    for (size_t i=0; i<N; ++i) {
        char buf[64];
        scanf("%s", buf);
        A[i] = buf;
    }

    for (size_t i=0; i<M; ++i) {
        char buf[64];
        scanf("%s", buf);
        B[i] = buf;
    }

    for (size_t i=0; i<N; ++i)
        for (size_t j=0; j<N; ++j)
            if (equiv(A, B, i, j))
                return !printf("Yes\n");

    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

template <typename T> T mod_pow(T n, T r, T m) {
	T ret = 1;
	T tmp = n;
	while (r != 0) {
		if (r % 2) {
			ret *= tmp;
		}
		tmp *= tmp;
		tmp %= m;
		ret %= m;
		r /= 2;
	}
	return ret;
}

template <typename T> T mod_inv (T a, T m) {
	return mod_pow(a, m - 2, m);
}

 template <typename T> T mod_div (T a, T b, T m) {
	return a * mod_inv(b, m) % m;
}

int main() {
	ull mod = 998244353;
	
	uint N;
	cin >> N;
	
	ull a_comb = 1;
	ull bc_comb = 1;
	ull major = 1;
	
	for(uint i=1; i<N/2; i++) {
		a_comb = mod_div(a_comb * (N - i + 1) % mod, (ull)i, mod);
		//a_comb = a_comb * (N - i + 1) / i;
		//cout << N << "C" << i << ":" << a_comb << endl;
		bc_comb = bc_comb * 2 % mod;
		ull comb = a_comb * bc_comb % mod;
		major = (major + comb) % mod;
	}
	
	major = major * 2 % mod;
	ull whole = mod_pow((ull)3, (ull)N, mod);
	
	ull ans = (whole > major) ? (whole - major) % mod : mod + whole - major;
	
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int x,a,b; cin >> x >> a >> b;
    cout <<(x-a)%b << endl; return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main (void)
{
    int a, b;
    cin >> a >> b;

    if (a == 1) {
        a = 14;
    }
    if (b == 1) {
        b = 14;
    }

    if (a > b) {
        cout << "Alice" << endl;
    } else if (a < b) {
        cout << "Bob" << endl;
    } else {
        cout << "Draw" << endl;
    }

    return 0;
}

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

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

    static class ABC109A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            if (A % 2 == 1 && B % 2 == 1) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }

    }
}



Measured memory_bytes: 21076
fun main(args: Array<String>) {
    val s = readLine()!!.toString()
    val n = s.length
    val a = mutableListOf<Int>()
    var b = 'L'
    var cnt = 1
    var li = 0
    for (i in 0 until n - 1) {
        if (s[i] == 'R') {
            if (b == 'L') {
                b = 'R'
                if (s[i + 1] == 'R') {
                    a.add(0)
                    cnt++
                } else {
                    a.add(cnt)
                    cnt = 1
                }
            } else {
                if (s[i + 1] == 'R') {
                    a.add(0)
                    cnt++
                } else {
                    a.add(cnt)
                    cnt = 1
                }
            }
        } else {
            if (b == 'R') {
                li = i
                b = 'L'
                if (s[i + 1] == 'L') {
                    a.add(0)
                    cnt++
                } else {
                    a.add(0)
                    a[li] = cnt
                    cnt = 1
                }
            } else {
                if (s[i + 1] == 'L') {
                    a.add(0)
                    cnt++
                } else {
                    a.add(0)
                    a[li] = cnt
                    cnt = 1
                }
            }
        }
    }
    if (s[n - 2] == 'L') {
        a.add(0)
        a[li] = cnt
    } else a.add(1)

    val an = mutableListOf<Int>()
    var ne = false
    for (i in 0 until n) {
        if (ne) {
            ne = false
            continue
        }
        if (a[i] == 0) an.add(0)
        else {
            if ((a[i] + a[i + 1]) % 2 == 0) {
                an.add((a[i] + a[i + 1]) / 2)
                an.add((a[i] + a[i + 1]) / 2)
            } else {
                if (a[i] % 2 == 1) {
                    an.add((a[i] + a[i + 1]) / 2 + 1)
                    an.add((a[i] + a[i + 1]) / 2)
                } else {
                    an.add((a[i] + a[i + 1]) / 2)
                    an.add((a[i] + a[i + 1]) / 2 + 1)
                }
            }
            ne = true
        }
    }
    for (i in 0..n-2) {
        print("${an[i]} ")
    }
    println(an.last())
}

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

int main(){
  int n,c=0;
  cin >> n;
  int a[n],b[100009]={};
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[a[i]]++;
  }
  for(int i=0;i<100007;i++){
    int ans = b[i+2]+b[i+1]+b[i];
    if(ans > c)
      c = ans;
  }
  cout << c << endl;
}

Measured memory_bytes: 1024
#include <iostream>

#define rep(i, first, to) for(ll i = first; i < to; ++i)
#define REP(i, first, to) for(ll i = first; i <= to; ++i)

using namespace std;
typedef long long ll;

int cnt = 0;
int a[1000001];
int n;
int g[1000001];

void show(int *p) {
	rep(i, 0, n - 1) {
		cout << p[i] << " ";
	}
	cout << p[n - 1] << endl;
}

void insertSort(int g) {
	//cout << "now" << g << endl;
	for (int i = g; i < n; ++i) {
		int v = a[i];
		int j = i - g;
		for (;j >= 0 && a[j] > v; j -= g) {
			a[j + g] = a[j];
			++cnt;
		}
		a[j + g] = v;
		//show(a);
	}
}

void shellSort() {
	int m = 0;
	for(int i = 0; 3 * g[m - 1] + 1 <= n; m++) {
		g[m] = 3 * g[m - 1] + 1;
	}
	for (int i = m - 1; i >= 0; --i) {
		insertSort(g[i]);
		//show(a);
	}
	//show(a);
	cout << m << endl;
	for (int i = m - 1; i > 0; --i) {
		cout << g[i] << " ";
	}
	cout << g[0] << endl;
	cout << cnt << endl;
	rep(i, 0, n) {
		cout << a[i] << endl;
	}
}

void solve() {
	cin >> n;
	rep(i, 0, n) {
		cin >> a[i];
	}
	shellSort();
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 6992
import sys
sys.setrecursionlimit(10**7)
N = int(input())
ts = [int(input()) for _ in range(N)]

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

def lcm(a,b):
    g = gcd(a,b)
    return a * b // g

l = 1
for t in ts:
    l = lcm(l,t)
    
print(l)

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

using ll=long long;



void solve(){
    string s;
    cin>>s;
    int cnt=0;
    for(auto c:s){
        if(c=='o')cnt++;
    }
    cout<<700+100*cnt<<endl;
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	map<int, int> D;
	for (auto i = 0; i < N; ++i)
	{
		int d;
		cin >> d;
		++D[d];
	}

	vector<int> list;
	list.push_back(0);
	bool flag = true;
	for (auto d : D)
	{
		for (auto i = 0; i < d.second; ++i)
		{
			if (flag)
			{
				list.push_back(d.first);
			}
			else
			{
				list.push_back(24 - d.first);
			}
			flag = !flag;
		}
	}

	sort(list.begin(), list.end());
	auto result = 24;
	for (auto i = 0; i < list.size() - 1; ++i)
	{
		result = min(result, list[i + 1] - list[i]);
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int &a, int &b){
  if (a == 0 || b == 0){
    return max(a, b);
  } else {
    int c = min(a, b);
    int d = max(a, b) % min(a, b);
    return gcd(c, d);
  }
}
int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  int ans;
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
    ans = gcd(ans, A.at(i));
  }
  cout << ans << endl;
  return 0;
}

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

int main(void){
    int A, B;
    cin >> A >> B;

    // implements
    if((A+B)%3 == 0 || A%3 == 0 || B%3 == 0){
        printf("Possible\n");
    }
    else{
        printf("Impossible\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int in(){int x; scanf("%d",&x); return x;}
static const int MAX = 100;


int main(){
  int N = in();
  double sum = 0, x;
  string u;

  rep(i, N){
    cin >> x >> u;
    if(u == "BTC") sum += x * 380000.0;
    else sum += x;
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
  int a, b, ans;
  scanf("%d", &a);
  scanf("%d", &b);

  if (a+b > a-b){
    ans = a + b;
  }else{
    ans = a-b;
  }
  if (ans < a*b) {
    printf("%d\n", a*b);
  }else{
    printf("%d\n", ans);
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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 namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n;
    cin >> n;
    
    vector<int> p(n);
    REP(i, n) {
        cin >> p[i];
        p[i]--;
    }
    int res = 0;
    for(int i = 0; i < n; i++) {
        if (p[i] == i) {
            res++;
            if (i == n-1) iter_swap(p.begin()+i, p.begin()+i-1);
            else iter_swap(p.begin()+i, p.begin()+i+1);
        }
    }


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

Measured memory_bytes: 640
import sys
#結局よくわからず解法見てしもた
#通ったし今度はリファクタリングや

def 解():
    iN = int(input())
    aP = [[int(_) for _ in sLine.rstrip("\n").split()] for sLine in sys.stdin.readlines()]

    iMod = sum(aP[0]) % 2
    for i in range(1,iN):
        if sum(aP[i]) % 2 != iMod :
            print("-1")
            exit()

    i最遠 = max([ abs(iX)+abs(iY) for iX , iY in aP])

    a腕 = [1]
    if iMod == 0 :
        a腕 = [1,1]

    for i in range(32):
        a腕.append(a腕[-1] * 2)
        if i最遠 // 2 < a腕[-1]:
            break

    a腕.reverse()
    iLen腕 = len(a腕)
    aRet = []
    for iX,iY in aP:
        aCommand=[]
        for i in range(iLen腕):
            if abs(iX) > abs(iY):
                if iX < 0 :
                    iX += a腕[i]
                    aCommand.append("L")
                else:
                    iX -= a腕[i]
                    aCommand.append("R")
            else:
                if iY < 0 :
                    iY += a腕[i]
                    aCommand.append("D")
                else:
                    iY -= a腕[i]
                    aCommand.append("U")
        aRet.append("".join(aCommand))

    print(iLen腕)
    print(" ".join([str(_) for _ in a腕]))
    sys.stdout.write("\n".join(aRet) + "\n")

if __name__ == '__main__':
    解()


Measured memory_bytes: 3444
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int a[13], b[13];
 
signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    string s;   cin >> s;
    a[0] = 1;
    int c = 1;
    for(int i = s.length()-1; i >= 0; i--){
        if(s[i] == '?'){
            for(int k = 0; k <= 9; k++){
                for(int j = 0; j < 13; j++){
                    b[(j+k*c)%13] += a[j];
                    b[(j+k*c)%13] %= mod;
                }
            }
        }
        else{
            int k = s[i] - '0';
            for(int j = 0; j < 13; j++){
                b[(j+k*c)%13] += a[j];
                b[(j+k*c)%13] %= mod;
            }
        }
        for(int j = 0; j < 13; j++){
            a[j] = b[j];
            b[j] = 0;
        }
        c = (c*10) % 13;
    }   
    cout << a[5];
    return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
int N;
	cin >> N;
	vec(A);
	vec(B);
	vec(C);
	ll sumA = 0, sumB = 0;
	fx(N) {
		vecp(A);
		sumA += A[x];
	}
	fx(N) {
		vecp(B);
		sumB += B[x];
	}

	if (sumA<sumB) {
		ce(-1)
	}
	else {
		ll sum = sumA - sumB;
		fx(N) {
			pb(C, A[x] - B[x]);
		}
		sorts(C);
		int ans = 0;
		fx(N) {
			if (C[x] < 0) { continue; }
			if (sum>=C[x]) {
				sum -= C[x];
				ans++ ;
			}
			//doublece(sum,ans)
		}
		ce(N-ans)
	}
    return 0;
}



Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    int a[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    if (m1 != m2) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
    
    return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

typedef long long ll;

void solve(std::string S, std::string T)
{
    cout << T << S << endl;
}

int main()
{
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 256
def f(i):
    if i%2 == 0:
        return int(i/2)
    else:
        return 3*i+1


s = int(input())
a = [s]
ans = 0
for i in range(1,1000000):
    ai = f(a[i -1])
    if a.count(ai) == 1:
        ans = i + 1
        break
    a.append(ai)
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	int n;
	long long sum = 0;
	cin >> n;
	vector<long long> A(n);
	int count = 0;
	for (int i = 0; i < n; ++i) {
		cin >> A[i];
		if (A[i] < 0) {
			++count;
			A[i] = -A[i];
		}
	}
	sort(A.begin(), A.end());

	if (count % 2 == 0) {
		for (int i = 0; i < n; ++i) {
			sum += abs(A[i]);
		}
	}
	else {
		sum = -abs(A[0]);
		for (int i = 1; i < n; ++i) {
			sum += abs(A[i]);
		}
	}

	cout << sum << endl;

	return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
struct Edge {
    int to;
    int weight;
    Edge(int t, int w)
        : to(t)
        , weight(w)
    {
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;
typedef long long ll;
typedef pair<int, int> P;
vector<int> dx = { 1, 0, -1, 0 };
vector<int> dy = { 0, 1, 0, -1 };

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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;
}

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank;

    UnionFind(int n = 1)
    {
        init(n);
    }

    void init(int n = 1)
    {
        par.resize(n);
        rank.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int root(int x)
    {
        if (par[x] == x) {
            return x;
        } else {
            int r = root(par[x]);
            return par[x] = r; // 辺の縮約（一度根をたどったら辺を直接根に向かって貼り直す）
        }
    }

    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (rank[x] < rank[y])
            swap(x, y);
        if (rank[x] == rank[y])
            ++rank[x];
        par[y] = x; // xよりyのほうが高さが小さい木
        return true;
    }
};

// 最大公約数
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

// 最小公倍数
int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y)
{
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

// 負の数にも対応した % 演算
long long mod(long long val, long long m)
{
    long long res = val % m;
    if (res < 0)
        res += m;
    return res;
}

// a^n modを計算する
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    // nを2進数表示して1が埋まっている桁に関してはa^mをかけていく
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod)
{
    return modpow(a, mod - 2, mod);
}

int main()
{
    ll H;
    cin >> H;
    ll i = 0;
    ll ans = 1;
    while (H > 0) {
        H /= 2;
        ans *= 2;
    }

    cout << ans - 1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
using namespace std;
const int MAX = 10000000;
long N,M,K;
long fact[MAX];

long pow(long a,long n,long p){
	if(n == 0) return 1;
	if(n == 1) return a%p;
	if(n%2 == 0) {
		long t=pow(a,n/2,p);
		return (t*t)%p;
	}
	else {
		long t=pow(a,n-1,p);
		return (a*t)%p;
	}
}

long fact_nondiv(long n, long p){
	if(n == 0 || n == 1) return 1;
	long a = fact_nondiv(n/p, p);
	long b = fact[n%p];

	if(n/p%2) return a*(p-b)%p;
	else return a*b%p;
}

long fact_numdiv(long n, long p){
	long x = 0;
	while(n > 0){
		x += n/p;
		n /= p;
	}
	return x;
}

long mod_inv(long a, long m){
	int p=m,q=a%m;
	stack<int> s;
	s.push(p);
	s.push(q);
	while(q>0){
		int r = p%q;
		s.push(r);
		p = q;
		q = r;
	}
	s.pop();s.pop();
	int x=1,y=0;
	while(!s.empty()){
		q = p;
		p = s.top();
		s.pop();
		int z = x-(p/q)*y;
		x = y;
		y = z;
	}
	return (y+m)%m;
}


long comb(long n, long k, long p){
	if(n == 0 || k == 0 || n < k) return 1;
	if(fact_numdiv(n,p) > fact_numdiv(k,p) + fact_numdiv(n-k,p)){
		return 0;
	}
	else{
		return fact_nondiv(n,p)*mod_inv(fact_nondiv(k,p)*fact_nondiv(n-k,p)%p,p)%p;
	}
}

int main(){
	long p = 1000000007;
	fact[0] = 1;
	for(int i=1; i<MAX; i++){
		fact[i] = fact[i-1]*i%p;
	}
	cin >> N >> M >> K;
	long res = 0;
	long s = 1;
	for(int i=N; i<=N+M+K; i++){
		long x = comb(i-1,N-1,p);
		long y = pow(3,N+M+K-i,p);
		long z = s;
		//cout << x << " " << y << " " << z << endl;
		res = (res + (x*y%p)*z%p)%p;
		long l=0,r=0;
		if(i-N >= K) l = comb(i-N, i-N-K, p);
		if(i-N >= M) r = comb(i-N, M, p);
		//cout << l << " " <<  r << endl;
		s = (s*2-l-r+p*2)%p;
	}
	cout << res << endl;
	/*
	cin >> N >> M;
	cout << comb(N,M,p) << endl;
	*/

	return 0;
}


Measured memory_bytes: 78336
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int main(void){
  int x1,x2,x3,x4,y1,y2,y3,y4;
  scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
  int x=x2-x1,y=y2-y1;
  x3=x2-y,y3=y2+x,x4=x1-y,y4=y1+x;
  printf("%d %d %d %d\n",x3,y3,x4,y4);
  return 0;
}

Measured memory_bytes: 128
x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
lisc.sort(reverse=True)
an = []
ans = []
for num in lisb:
    for nu in lisa:
        an.append(num+nu)
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:
        ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])


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

#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int f[50][50];

int dfs(vector<vector<int>> &m, int h, int w, vector<vector<char>> as) {
    if (h < 0 || w < 0 || h >= m.size() || w >= m[h].size()) {
        return 0;
    }
    if (as[h][w] == 'B') return 1;
    if (as[h][w] == 'W') return 2;
    if (f[h][w]) return m[h][w];
    f[h][w] = 1;
    int t=0;
    t |= dfs(m, h-1, w, as);
    t |= dfs(m, h+1, w, as);
    t |= dfs(m, h, w+1, as);
    t |= dfs(m, h, w-1, as);
    m[h][w] = t;
    return t;
}

int siage(vector<vector<int>> &m, int h, int w, vector<vector<char>> as, int max_num) {
    if (h < 0 || w < 0 || h >= m.size() || w >= m[h].size()) {
        return 0;
    }
    if (as[h][w] == 'B') return 0;
    if (as[h][w] == 'W') return 0;
    if (f[h][w]) return m[h][w];
    f[h][w] = 1;
    int t=0;
    max_num = max(max_num, m[h][w]);
    max_num = max(max_num, siage(m, h-1, w, as, max_num));
    max_num = max(max_num, siage(m, h+1, w, as, max_num));
    max_num = max(max_num, siage(m, h, w-1, as, max_num));
    max_num = max(max_num, siage(m, h, w+1, as, max_num));
    m[h][w] = max_num;
    return max_num;
}

int main()
{
    int w, h;
    while (cin >> w >> h, w) {
        loop(50,i) loop(50,j) f[i][j] = 0;
        vector<vector<char>> as;
        as.resize(h);
        loop(h,i) {
            string s;
            cin >> s;
            for (char c:s) as[i].push_back(c);
        }
       // for(auto mm:as) {
       //     for (auto m:mm) cout << m << ' ';
       //     cout << endl;
       // }

        vector<vector<int>> mat(h, vector<int>(w,0));
        loop(h,i){
            loop(w,j){
                if (as[i][j] == '.') {
                    dfs(mat, i, j, as);
                }
            }
        }
        loop(50,i) loop(50,j) f[i][j] = 0;

        loop(h,i){
            loop(w,j){
                if (as[i][j] == '.') {
                    siage(mat, i, j, as, 0);
                }
            }
        }
        int ans_w = 0, ans_b = 0;
        for(auto mm:mat) {
            for (auto m:mm) {
                if (m == 1) ans_b++;
                if (m == 2) ans_w++;
                //cout << m << ' ';
            }
            //cout << endl;
        }
        cout << ans_b << ' ' << ans_w << endl;

    }
}

Measured memory_bytes: 14224
/*
ID: usaco.t3
TASK: test
LANG: C++14
*/

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _CRT_SECURE_NO_WARNINGS
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define pii pair<intt,intt>
#define vi vector<intt>
#define vii vector<pii>

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define IO ios_base::sync_with_stdio(false);cin.tie();
#define endl '\n'

#define wtfis(x) cerr << "at line " << __LINE__ << ": " << #x << " = " << (x) << endl

const intt max3 = 1003;
const intt max4 = 10004;
const intt maxx = 100005;
const intt max6 = 1000006;
const intt max7 = 10000007;

const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;

const intt INF = 2LL * 1000000001;
const intt INFLL = 9LL * 1000000000 * 1000000000;
/***************/

intt powmod (intt a, intt b, intt mod) {
    intt res = 1;
    a %= mod;
    for (; b; b >>= 1) {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

intt gcd (intt a, intt b) {
    while (b > 0) {
        intt t = a % b;
        a = b, b = t;
    }
    return a;
}

intt lcm (intt a, intt b) {
    return (a / gcd (a, b)) * b;
}

intt is_prime (intt n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (intt i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/**************************/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    IO;
    string s; int n;
    cin >> s >> n;
    int i = 0;
    while (i < s.size()) {
        cout << s[i];
        i += n;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 整数の入力
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		int X = sc.nextInt();

		int count=0;

		for(int x=0;x<=A&&x*500<=X;x++){
			for(int y=0;y<=B&&(x*500+y*100)<=X;y++){
				if(X-(x*500+y*100+C*50)<=0){
					count++;
				}
			}
		}

		// 出力
		System.out.println(count);
	}
}

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

int d[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
int main(void){
    // Your code here!
    int x,y;
    cin>>x>>y;
    if(d[x]==d[y]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define N 1000005 
#define LL long long 
using namespace std;
char s[N];
int L[N],R[N];
int mark[N]; 
int main(){
	int n,k,c,p=0;
	cin>>n>>k>>c;
	scanf("%s",s+1);  
	for(int i=1;i<=n;i++){
		if(s[i]=='o'){
			mark[i]=++p; 
			i+=c; 
		}
	}
	if(p<k)return 0;
	for(int i=n;i>=1;i--){
		if(s[i]=='o')R[i]=R[i+c+1]+1;
		else R[i]=R[i+1]; 
	}
	for(int i=1;i<=n;i++){
		if(mark[i]&&mark[i]-1+R[i+1]<k)printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <algorithm> 
#include <cmath>
#include <numeric>
using namespace std;


int main(void){
    // Your code here!
    string s;
    cin >> s;
    if(s.length() == 2) cout << s << endl;
    else {
        reverse(s.begin(), s.end());
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// {{{ by unolight
#pragma region
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
#pragma endregion
// }}}

void main() {
    LL n, x, m;
    R(n,x,m);
    map<LL,int> seen;
    vector<LL> a;
    LL me=x;
    int time=0,prv=-1;
    while (1) {
        if ( time>=n ) break;
        if ( seen.count(me) ) {
            prv=seen[me];
            break;
        }
        if ( prv==-1 ) {
            seen[me]=time++;
            a.PB(me);
            me=me*me%m;
        }
    }
    LL sum=0;
    if ( time>=n ) {
        for ( auto it:seen ) {
            sum+=it.first;
        }
        W(sum);
    } else {
        int cycle = time - prv;
        for ( int i=prv; i<time; i++ ) sum+=a[i];
        n -= prv;
        LL k = n/cycle;
        sum*=k;
        k=n%cycle;
        for ( int i=0; i<k; i++ ) sum+=a[prv+i];
        for ( int i=0; i<prv; i++ ) sum+=a[i];
        W(sum);
    }
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}


Measured memory_bytes: 6892
#define SUBMIT

#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef SUBMIT
    auto& in = cin;
#else
    stringstream in(R"(1 2 + 3 4 - *
)");
#endif
    stack<int> s;
    string str;
    while (in >> str) {
        if (str == "+" || str == "-" || str == "*") {
            auto rhs = s.top(); s.pop();
            auto lhs = s.top(); s.pop();
            if (str == "+") s.push(lhs + rhs);
            else if (str == "-") s.push(lhs - rhs);
            else if (str == "*") s.push(lhs * rhs);
        } else {
            s.push(stoi(str));
        }
    }
    cout << s.top() << endl;
    return 0;
}


Measured memory_bytes: 3196
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 10000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll fac[maxn],inv[maxn],n,k,ans,nw,q,b[maxn];
const ll mod=998244353;

inline ll pw(ll a,ll b)
{
	ll ans=1,base=a;
	while(b)
	{
		if(b&1) ans=(ans*base)%mod;
		base=(base*base)%mod; b>>=1;
	}
	return ans;
}

inline ll C(int N,int M){return (fac[N]*inv[M]%mod)*inv[N-M]%mod;}

int main()
{
	fac[0]=1; inv[0]=1; n=read(); b[0]=1;
	rep(i,1,(maxn-5)) fac[i]=(fac[i-1]*i)%mod,b[i]=(b[i-1]*2)%mod;
	rep(i,1,(maxn-5)) inv[i]=pw(fac[i],mod-2); q=pw(3,n); nw=-1;
	for(int i=n/2+1;i<=n;i++)
	{
		ll tmp=C(n,i)*b[n-i]; tmp%=mod;
		ans=(ans+tmp+mod)%mod;
	}
	cout<<(q-(2*ans%mod)+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 238012
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = 0;
		if(a==1 && b==2) { ans = 3; } else
		if(a==1 && b==3) { ans = 2; } else
		if(a==2 && b==1) { ans = 3; } else
		if(a==2 && b==3) { ans = 1; } else
		if(a==3 && b==1) { ans = 2; } else
		if(a==3 && b==2) { ans = 1; }
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
struct edge{int next,to;}a[6005];
int n,cnt,h[3005],v[3005];
bool vis[3005],f[3005];
void Addedge(int x,int y)
{a[++cnt].to=y;a[cnt].next=h[x];h[x]=cnt;}
bool DFS(int x)
{if(vis[x])return f[x];
 vis[x]=1;
 bool flag=0;
 for(int i=h[x];i;i=a[i].next)
 {int y=a[i].to;
  if(v[y]<v[x])if(!DFS(y)){flag=1;break;}
 }
 return f[x]=flag;
}
int main()
{scanf("%d",&n);
 for(int i=1;i<=n;i++)scanf("%d",&v[i]);
 for(int i=1,x,y;i<n;i++)
 {scanf("%d%d",&x,&y);
  Addedge(x,y);
  Addedge(y,x);
 }
 for(int i=1;i<=n;i++)
 if(!vis[i])f[i]=DFS(i);
 for(int i=1;i<=n;i++)if(f[i])printf("%d ",i);
 return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k;
  cin >> s >> k;

  set<string> sub;
  for (int i=0; i<s.size(); i++) {
    for (int j=1; j<=k; j++) {
      sub.insert(s.substr(i, j));
    }
  }

  // for (auto& e : sub) {
  //   cout << e << endl;
  // }

  auto iter = sub.begin();
  for (int i=0; i<k-1; i++) {
    iter++;
  }
  cout << *iter << endl;

  return 0;
}


Measured memory_bytes: 1664
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
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)*}
    };
}
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")
    };
}

#[allow(dead_code)]
const MOD: u64 = 1000000007;


fn main() {
    input!{
        a: f64, b: f64, h: f64,
    }
    println!("{}", (a+b)*h/2.0);
}

Measured memory_bytes: 4352