akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define all(c) (c).begin(), (c).end()

template <class T, class U>
inline bool chmin(T& t, const U& f) { return t > f ? t = f, true : false; }

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << p.first << ' ' << p.second; }

const int inf = 1 << 28;

pair<char const*, int> solve(int n, const vector<int>& p, const vector<int>& t) {
    vector<vector<int>> dp(n + 1, vector<int>(4, inf)); dp[0][0] = 0;
    for (int i = 0, cur = 0; i < n; cur = p[i++]) {
        int lim = t[i] - (i? t[i - 1]: 0);
        rep(k, 4) {
            if (k < 3 && abs(p[i] - cur) * (k + 1) <= lim) {
                chmin(dp[i + 1][k + 1], dp[i][k] + abs(p[i] - cur));
            }
            if (0 < k && cur * (k + 1) + p[i] <= lim) {
                chmin(dp[i + 1][1], dp[i][k] + cur + p[i]);
            }
        }
        if (all_of(all(dp[i + 1]), [](int x){ return x == inf; })) return make_pair("NG", i + 1);
    }
    return make_pair("OK", *min_element(all(dp.back())) + p.back());
}

int main() {
    for (int n; cin >> n, n;) {
        vector<int> p(n), t(n);
        rep(i, n) cin >> p[i] >> t[i];
        cout << solve(n, p, t) << endl;
    }
}

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

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

int main(void) {
    int n, m, ret = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> m;
        if (isPrime(m)) ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <bitset>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define reps(i,s,n) for(int i=s; i<n; i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int INF = 1<<30;

int cost[10][10];
string dp[1<<10][10];

bool comp( string s1, string s2 ) {
	if( s1.length() == s2.length() )
		return s1 < s2;
	else
		return s1.length() < s2.length();
}

int cntTwice(string out, string w) {
	if( out.length() >= w.length() ) {
		for(int j=w.length()-1; j>0; j--) {
			string s1 = out.substr(out.length()-j, j);
			string s2 = w.substr(0, j);
			if( s1 == s2 ) {
				return j;
			}
		}
	} else {
		for(int j=0; j<out.length(); j++) {
			string s1 = out.substr(j, out.length()-j);
			string s2 = w.substr( 0, out.length()-j );
			if( s1 == s2 ) {
				return out.length()-j;
			}
		}
	}
	return 0;
}

int main() {
	int n;
	while(cin >> n, n) {
		vector<string> inw(n);
		rep(i, n) {
			cin >> inw[i];
		}
		bool inner[10] = {};
		rep(i,n) {
			if( inner[i] ) continue;
			rep(j,n) {
				if( i!=j && !inner[j] && inw[i].find(inw[j]) != string::npos ) {
					inner[j] = true;
				}
			}
		}
		vector<string> word;
		rep(i,n) {
			if(!inner[i]) word.push_back(inw[i]);
		}
		n = word.size();

		rep(i, n) rep(j, n) cost[i][j] = cntTwice( word[i], word[j] );
		rep(i, (1<<n)) rep(j, n) dp[i][j] = "";
		rep(i, n) dp[1<<i][i] = word[i];
		for(int i=0; i<(1<<n); i++) {
			for(int p=0; p<n; p++) {
				for(int j=0; j<n; j++) {
					if( !(i & (1<<j)) && p!=j && dp[i][p]!="" ) {
						if( dp[i|(1<<j)][j] == "" )
							dp[i|(1<<j)][j] = dp[i][p] + word[j].substr(cost[p][j]);
						else {
							if( comp(dp[i|(1<<j)][j], dp[i][p] + word[j].substr(cost[p][j])) )
								dp[i|(1<<j)][j] = dp[i|(1<<j)][j];
							else
								dp[i|(1<<j)][j] = dp[i][p] + word[j].substr(cost[p][j]);
						}
					}
				}
			}
		}
		vector<string> ans;
		rep(i,n) ans.push_back(dp[(1<<n)-1][i]);
		sort( ans.begin(), ans.end(), comp );
		cout << ans[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 1796
int main(){
    int n;
    int a[100];
    int i;
    scanf("%d",&n);

    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    
    for(i=n-1;i>=0;i--){
        if(i!=n-1)
            printf(" ");
            printf("%d",a[i]);
        }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;

int main(){
    string s;

    cin >> s;

    int cnt =0;

    s[3] = '8';

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int N=100005;
vector<int> vct[N];
int n,m,i,j,a[N],p[N],bl[N],cnt,id[N],s[N];
ll K,x[N],d[N],e[N];
void dfs(int x)
{
	if(bl[x])
		return;
	bl[x]=cnt;
	vct[cnt].push_back(x);
	id[x]=s[cnt]++;
	dfs(p[x]);
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
	{
		scanf("%lld",x+i);
		d[i]=x[i]-x[i-1];
		a[i]=i;
	}
	scanf("%d%lld",&m,&K);
	for(i=1;i<=m;++i)
	{
		scanf("%d",&j);
		swap(a[j],a[j+1]);
	}
	for(i=1;i<=n;++i)
		p[a[i]]=i;
	cnt=0;
	for(i=1;i<=n;++i)
		if(!bl[i])
		{
			++cnt;
			dfs(i);
		}
	for(i=1;i<=n;++i)
		e[vct[bl[i]][(id[i]+K)%s[bl[i]]]]=d[i];
	for(i=1;i<=n;++i)
	{
		e[i]+=e[i-1];
		printf("%lld.0\n",e[i]);
	}
	return 0;
}

Measured memory_bytes: 11768
#include <cstdio>
#include <algorithm>

using namespace std;
int N;
int a[100010];
int main() {
  scanf("%d", &N);
  for(int i=0;i<N;++i) {
    int t;
    scanf("%d", &t);
    a[t]++;
    a[t+1]++;
    if (t!=0) a[t-1]++;
  }
  int ans=0;
  for(int i=0;i<=100000;++i) {
    ans=max(ans, a[i]);
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 512
import java.util.Arrays;

public class Main {

  private static void solve() {
    int[] dp = new int[1 << 26];
    Arrays.fill(dp, Integer.MAX_VALUE / 2);
    dp[0] = 0;
    int bit = 0;
    for (char c : ns()) {
      bit ^= 1 << (c - 'a');
      for (int j = 0; j < 26; j ++) {
        dp[bit] = Math.min(dp[bit ^ (1 << j)] + 1, dp[bit]);
      }
    }
    System.out.println(Math.max(dp[bit], 1));
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = System.getProperty("debug");
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 291796
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

constexpr ll mod = 998244353;
constexpr ll modsize = 100010;
vector<ll> fac(modsize);
vector<ll> inv(modsize);
vector<ll> facinv(modsize);

void modcalc() {
	if (modsize == 0) abort();
	fac[0] = 1; fac[1] = 1; inv[1] = 1;
	facinv[0] = 1; facinv[1] = 1;
	for (ll i = 2; i < modsize; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		facinv[i] = facinv[i - 1] * inv[i] % mod;
	}
}

ll modinv(ll a) {
	if (a == 0) abort();
	ll b = mod, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}

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

ll modcomb(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[k] % mod * facinv[n - k] % mod;
}

ll modperm(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[n - k] % mod;
}

ll modhom(ll n, ll k) {
	if (n < 0 || k < 0 || n == 0 && k > 0) return 0;
	if (n == 0 && k == 0) return 1;
	return fac[n + k - 1] * facinv[k] % mod * facinv[n - 1] % mod;
}

ll dp[3010][6010];

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

	ll n, x;
	cin >> n >> x;
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, 6008) {
			rep(k, 3) {
				dp[i + 1][j + k] += dp[i][j];
				if (dp[i + 1][j + k] >= mod) dp[i + 1][j + k] -= mod;
			}
		}
	}
	ll ans = 0;
	rep(i, x) ans += dp[n][i];
	ans %= mod;
	if (x & 1) {
		for (int i = (x + 1) / 2; i <= n; i++) ans += modcomb(n, i);
		ans %= mod;
	}
	for (int i = 1; i <= (x - 2) / 2; i++) {
		int rem = x - 1 - 2 * i;
		for (int two = 0; two <= (rem - 1) / 2; two++) {
			int one = rem - 2 * two;
			ll cnt = modcomb(one + two, one);
			cnt *= modcomb(n, one + two + 2 * i);
			ans += cnt % mod;
		}
		ans %= mod;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 143872
#include <iostream>

using namespace std;

int main()
{
  	int a, b;
  	cin >> a >> b;
  	if(a <= 0 && b >= 0){
      	cout << "Zero";
    }else if(a > 0){
      	cout << "Positive";
    }else{
      	if((b-a) % 2 == 0){
          	cout << "Negative";
        }else{
          	cout << "Positive";
        }
    }
  	return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()
L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(L[K-1])

Measured memory_bytes: 6092
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9

int N, K;
int num[100000];
int array_max;

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

void input() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> num[i];
		array_max = max(array_max, num[i]);
	}
}

void solve() {
	int cd = gcd(num[0], num[1]);
	for (int i = 2; i < N && cd != 1; i++) cd = gcd(cd, num[i]);
	if (gcd(cd, K) == cd && K <= array_max) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
}

int main() {
	input();
	solve();

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <complex>
#include <vector>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
 
using namespace std;
 
int main(){
    int K,T;
    cin >> K >> T;
    vector<int> a(T);
    for(int i = 0 ; i < T ; i++) cin >> a[i];
    sort(a.rbegin(),a.rend());
    int R = a[0] - 1;
    for(int i = 1 ; i < T ; i++)
        R -= a[i];
    cout << max(R,0) << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, m;
    cin >> n >> m;

    vvl v(m);  // v[i][j] : 電球iのつながっているj番目のスイッチ
    rep(i, m) {
        ll k;
        cin >> k;
        rep(j, k) {
            ll s;
            cin >> s;
            s--;
            v[i].pb(s);
        }
    }

    vl p(m);
    rep(i, m) {
        cin >> p[i];
    }

    ll ans = 0;
    rep(b, 1<<n) {  // bのjビット目が1のときスイッチjはon
        bool ok = true;
        rep(i, m) {  // 電球iをチェックする
            ll cnt = 0;  // 電球iがつながっているスイッチでonのものの個数
            rep(j, v[i].size()) {
                if(b & 1<<v[i][j]) {
                    cnt++;
                }
            }
            if(cnt%2 != p[i]) {
                ok = false;
            }
        }  
        if(ok) {
            ans++;
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long  LL;
const int N = int(2e3) + 10;
LL a[N],b[N];
LL n,x;
int f(int i){
    if(i<=0) i+=n;
    return i;
}
int main(){
    scanf("%lld %lld",&n,&x);
    LL sum=0;
    for(int i=1;i<=n;i++) {cin>>a[i];sum+=a[i];b[i]=a[i];}
    for(int i=1;i<=n-1;i++){
        LL tmp=x*i;
        for(int j=1;j<=n;j++){
            b[j]=min(b[j],a[f(j-i)]);
            tmp+=b[j];
        }
        sum=min(sum,tmp);
    }
    cout<<sum<<endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int n;
    cin>>n;
    int ans=1;
    for(int i=1;i<=n;i++)ans=ans*i%1000000007;
    cout<<ans<<endl;
    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 all(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

int main() {
    using vi = vector<int>;
    
    int n,k;
    cin >> n >> k;
    vi d(k);
    vector<vi> a(k);
    rep(i,k){
        cin >> d[i];
        rep(j,d[i]){
            int x;
            cin >> x;
            a[i].push_back(x);
        }
    }
    int count = 0;
    rep(i,n){
        int f = 0;
        rep(j,k){
            rep(l,a[j].size()){
                if(a[j][l] == i+1){
                    f = 1;
                }
            }
        }
        if(f == 0){
            count++;
        }
    }
    cout << count << endl;
}

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

const int MAX = 105;
int A[MAX];
int main() {
    int N, a;
    scanf("%d", &N);
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    for (int i = 1; i < N; i++) {
        if (A[i] == A[i-1]) {
            A[i] = 0;
            cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    ll n, x, a1, a2;
    ll ans;
    cin >> n >> x;

    ans = 0;
    cin >> a1;
    FOR(i, 1, n)
    {
        cin >> a2;

        if (a1 + a2 > x)
        {
            ans += max((ll)0, (a1 + a2 - x));

            a2 = max((ll)0, a2 - (a1 + a2 - x));
        }

        a1 = a2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
use proconio::input;
 
fn main() {
  input! {
    a: f64,
    b: f64,
    x: f64
  }

  if a * a * b <= 2f64 * x {
    println!("{}", (2f64 * (a * b - (x / a)) / (a * a)).atan().to_degrees());
  } else {
    println!("{}", (b / (2f64 * x / (b * a))).atan().to_degrees());
  }
}

Measured memory_bytes: 2920
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
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; }
#define rep(i, n) REP(i, 0, n)
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;

//vector<vector<ll>> vec(100000,vector<ll>(3,0));
int main(){
  ll a;
  string s;
  cin >> a;
  cin >> s;
  if(a >= 3200){
    cout << s;
  }else{
    cout << "red";
  }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

string dp[2][3252];
// int dp2[2][3252];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, t;
	cin>>s>>t;
	int n=s.size(), m=t.size();
	REP(i, n){
		if(i&1){
			REP(j, m){
				if(s[i]==t[j]){
					dp[0][j+1]=dp[1][j]+s[i];
					// dp2[0][j+1]=dp2[1][j]+1;
				}
				else{
					if(dp[0][j].size()>dp[1][j+1].size()){
						dp[0][j+1]=dp[0][j];
						// dp2[0][j+1]=dp2[0][j];
					}
					else{
						dp[0][j+1]=dp[1][j+1];
						// dp2[0][j+1]=dp2[1][j+1];
					}
				}
			}
		}
		else{
			REP(j, m){
				if(s[i]==t[j]){
					dp[1][j+1]=dp[0][j]+s[i];
					// dp2[1][j+1]=dp2[0][j]+1;
				}
				else{
					if(dp[1][j].size()>dp[0][j+1].size()){
						dp[1][j+1]=dp[1][j];
						// dp2[1][j+1]=dp2[1][j];
					}
					else{
						dp[1][j+1]=dp[0][j+1];
						// dp2[1][j+1]=dp2[0][j+1];
					}
				}
			}
		}
	}
	cout<<dp[n&1][m]<<'\n';
	return 0;
}


Measured memory_bytes: 17016
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			int[] a = new int[n];
			for(int i=0;i<n;i++) a[i] = sc.nextInt();
			
			int p = 32;
			for(int i=0;;i++){
				p -= (p-1)%5;
				if(p<=0) break;
				System.out.println(p);
				p -= a[i%n];
				if(p<=0) break;
				System.out.println(p);
			}
			System.out.println(0);
		}	
	}	
}

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

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    long long N;
    cin >> N;
    const auto &res = prime_factorize(N);
    int ans = 0;
    for (auto p : res) {
        int num = 1;
        while(p.second >= 0){
          p.second -= num;
          num ++;
        }
        ans += num-2;
    }
    cout << ans << endl;
}


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

int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<int>>data(H,vector<int>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      char a;
      cin >> a;
      if(a=='.') data.at(i).at(j)=0;
      else data.at(i).at(j)=-1;
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(data.at(i).at(j)==-1){
        bool count=false;
        if(i!=0){
          if(data.at(i-1).at(j)==-1) count=true;
        }
        if(j!=0){
          if(data.at(i).at(j-1)==-1) count=true;
        }
        if(j!=W-1){
          if(data.at(i).at(j+1)==-1) count=true;
        }
        if(i!=H-1){
          if(data.at(i+1).at(j)==-1) count=true;
        }
        if(!count){
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	ll n, m;
	cin >> n >> m;
	if (n%m == 0)cout << -1 << endl;
	else {
		cout << n << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




int main() {
    ll n;
    string s;
    cin >> n >> s;
    
    map<pair<string, string>, ll> mp;
    
    string a = s.substr(0, n);
    REP(i, 1 << n){
        string t1, t2;
        REP(j, n){
            if(i & (((1 << (n - 1)) >> j))){
                t1 += a[j];
            }
            else{
                t2 += a[j];
            }
        }
        mp[{t1, t2}]++;
    }
    
    ll ans = 0;
    string b = s.substr(n, n);
    reverse(b.begin(), b.end());
    REP(i, 1 << n){
        string t1, t2;
        REP(j, n){
            if(i & (((1 << (n - 1)) >> j))){
                t1 += b[j];
            }
            else{
                t2 += b[j];
            }
        }
        ans += mp[{t1, t2}];
    }
    cout << ans << endl;
}


Measured memory_bytes: 91904
#define ENABLE_DEBUG 1
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#if ENABLE_DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                \
  do {                            \
    cerr << " \033[33m (L";       \
    cerr << __LINE__ << ") ";     \
    cerr << #__VA_ARGS__ << ": "; \
    cerr << "\033[0m";            \
    debug(__VA_ARGS__);           \
    cerr << endl;                 \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif
const i64 MOD = 1'000'000'007;

struct mint {
  long long x;
  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

vector<pair<i64, int>> factorize(i64 n) {
  vector<pair<i64, int>> res;
  for (i64 k = 2; k * k <= n; ++k) {
    int cnt = 0;
    while (n % k == 0) {
      n /= k;
      ++cnt;
    }
    if (cnt > 0) {
      res.emplace_back(k, cnt);
    }
  }
  if (n > 1) {
    res.emplace_back(n, 1);
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<i64> A(N);
  for (auto& x : A) cin >> x;
  map<i64, int> fs;
  auto merge_factors = [&](const vector<pair<i64, int>>& fx) -> void {
    for (auto [p, c] : fx) {
      fs[p] = max(fs[p], c);
    }
  };
  REP(i, N) { merge_factors(factorize(A[i])); }
  mint allp = 1;
  for (auto [p, c] : fs) {
    allp *= mint(p).pow(c);
  }
  mint ans = 0;
  REP(i, N) {
    mint b = allp * mint(A[i]).inv();
    ans += b;
  }
  cout << ans << endl;
}

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

int main(){
  int x,a,b,c;
  cin >> a >> b >> c >> x;
  
  int count = 0;
  
  rep(i,a+1){
    rep(j,b+1){
      rep(k,c+1){
        if(i*500 + j*100 + k*50 == x){
          count++;
        }
      }
    }
  }
  
  cout << count <<endl;
}

  
  
  

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int y = sc.nextInt();

		System.out.println(euclideanAlgorithm(x, y));
	}

	public static int euclideanAlgorithm(int x, int y) {
		int tmp;
		while (true) {
			tmp = x % y;
			if (tmp == 0) {
				return y;
			}
			x = y;
			y = tmp;
		}
	}
}



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

string str;

void solve(){
    stack<int>S;
    for(int i=0;i<str.size();i++){
        if(str[i]=='(')S.push(1);
        else if(str[i]=='[')S.push(0);
        else if(str[i]==')'){
            if(S.empty()||S.top()!=1){
                cout<<"no"<<endl;
                return;
            }
            S.pop();
        }
        else if(str[i]==']'){
            if(S.empty()||S.top()!=0){
                cout<<"no"<<endl;
                return;
            }
            S.pop();
        }
    }
    if(S.empty())cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}
int main(){
    while(getline(cin,str),str!=".")solve();
    return 0;
}

Measured memory_bytes: 1176
#include <stdio.h>

#define BOARD_WIDTH_MAX 5
#define BOARD_HEIGHT_MAX 10

#define DELETE_THRESHOLD 3

typedef struct {
	int W,H;
	int score;
	int board[BOARD_HEIGHT_MAX][BOARD_WIDTH_MAX];
} game_t;

int game_delete(game_t *game) {
	int deleted=0;
	int i,j,k;
	for(i=0;i<game->H;i++) {
		int cnt=1;
		for(j=1;j<=game->W;j++) {
			if(j>=game->W || game->board[i][j]!=game->board[i][j-1]) {
				if(cnt>=DELETE_THRESHOLD && game->board[i][j-1]>0) {
					game->score+=game->board[i][j-1]*cnt;
					for(k=j-cnt;k<j;k++)game->board[i][k]=0;
					deleted=1;
				}
				cnt=1;
			} else {
				cnt++;
			}
		}
	}
	return deleted;
}

void game_fall(game_t *game) {
	int i,j,k;
	for(i=game->H-1;i>0;i--) {
		for(j=0;j<game->W;j++) {
			if(game->board[i][j]==0) {
				for(k=i-1;k>=0 && game->board[k][j]==0;k--);
				if(k>=0) {
					game->board[i][j]=game->board[k][j];
					game->board[k][j]=0;
				}
			}
		}
	}
}

int main(void) {
	game_t game;
	game.W=5;
	while(scanf("%d",&game.H)==1 && game.H>0) {
		int i,j;
		for(i=0;i<game.H;i++) {
			for(j=0;j<game.W;j++) {
				if(scanf("%d",&game.board[i][j])!=1)return 1;
			}
		}
		game.score=0;
		while(game_delete(&game))game_fall(&game);
		printf("%d\n",game.score);
	}
	return 0;
}

Measured memory_bytes: 600
s = input()
for i1 in ["+","-"]:
  for i2 in ["+","-"]:
    for i3 in ["+","-"]:
      text = s[0] + i1 + s[1] + i2 + s[2] + i3 + s[3]
      if(eval(text) == 7):
        print(text+"=7")
        exit()

Measured memory_bytes: 3060
#include <cstdio>
using namespace std;

typedef long long LL;

char s[15];
int n;

LL calc(int i, const LL& r, const LL& v)
{
	if(i == n) return (v == 0)? r: 0;
	return
		calc(i + 1, r, v * 10LL + s[i] - '0') +
		calc(i + 1, r + v * 10LL + s[i] - '0', 0LL);
}

int main(int argc, char** argv)
{
	char c;
	while((c = getchar()) != '\n') s[n++] = c;
	printf("%lld\n", calc(0, 0LL, 0LL));
	return 0;
}

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

nums = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}

for i in range(n):
    s = input()
    nums[s] += 1

cnds = ['AC', 'WA', 'TLE', 'RE']

for cnd in cnds:
    print(cnd, 'x', nums[cnd])

Measured memory_bytes: 9152
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
void A()
{
    // 入力
    string N;
    cin >> N;
    
    // 出力
    if( N.find("7") != string::npos )
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
 
void B()
{
    // 入力
    int N;
    cin >> N;
    
    long long int ans = 0;
    
    // "Fizz", "Buzz", "FizzBuzz"のいずれでもない場合を合算する
    for( int i = 1; i < N+1; ++i )
        if( (i % 3 != 0) && (i % 5 != 0) )
            ans += i;
    
    // 出力
    cout << ans << endl;
}
 
long long int gcd(long long int a, long long int b)
{
    long long int ret;
     
    if( a < b ){
        long long int tmp = a;
        a = b;
        b = tmp;
    }
     
    if( b == 0 ) return a;
     
    ret = a % b;
    ret = gcd(b, ret);
     
    return ret;
}
 
void C()
{
    // 入力
    int K;
    cin >> K;
    
    int ans = 0;
    
    // 2重GCDで解ける
    for( int a = 1; a < K+1; ++a )
        for( int b = 1; b < K+1; ++b )
            for( int c = 1; c < K+1; ++c )
                ans += gcd(gcd(a, b), c);
    
    // 出力
    cout << ans << endl;
}
 
void D()
{
    // 入力
    int N;
    string S;
    cin >> N >> S;
    
    // SをR, G, Bに分割する
    unsigned long long int R = 0, G = 0, B = 0;
    for( int i = 0; i < N; ++i )
        switch( S[i] ){
            case 'R': ++R; break;
            case 'G': ++G; break;
            case 'B': ++B; break;
        }
    
    // {R, G, B}の組合せの数
    // 必ずR, G, Bそれぞれひとつずつの組合せになるが、i < j < k順に並びかえればいいので、それぞれの個数をかけた値になる
    unsigned long long int ans = R * G * B;
    
    // (j − i) == (k − j)の組合せの数を引く
    // i, jが決まればkを求められる
    /*
    for( int i = 1; i < N+1; ++i )
        for( int j = i+1; j < N+1; ++j ){
            int k = 2*j - i;
            if( k < j || N < k ) continue;
            if( S[i-1] != S[j-1] && S[j-1] != S[k-1] && S[k-1] != S[i-1] )
                --ans;
        }
    */
    // 拝借 https://atcoder.jp/contests/abc162/submissions/13747699
    for(int i = 0; i < N-2; i++){
        for(int j = i+1; j < N-1; j++){
            int k = 2*j - i;
            if(k < N && S[i] != S[j] && S[j] != S[k] && S[i] != S[k])
                ans--;
        }
    }
    
    // 出力
    cout << ans << endl;   
}
 
int main()
{
    //A();
    //B();
    //C();
    D();
    
    return 0;
}


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

int table[50][26];

int main()
{
    int n;
    cin >> n;
    string s;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        for (int j = 0; j < s.size(); j++)
        {
            int k = s[j] - 'a';
            table[i][k]++;
        }
    }
    for (int j = 0; j < 26; j++)
    {
        int k = INT_MAX;
        for (int i = 0; i < n; i++)
            k = min(k, table[i][j]);
        char c = j + 'a';
        for (int i = 0; i < k; i++)
        {
            cout << c;
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(K: int, N: int, A: "List[int]"):
    B = []
    for i in range(N-1):
        B.append(A[i+1]-A[i])
    B.append(A[0] + K - A[N-1])
    C = []
    for b in B:
        C.append(K-b)
    print(min(C))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(K, N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 35700
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2.0)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}
#define nof(T) [](T a){return a;}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	int ave = accumulate(all(a), 0) / n, ave2 = (accumulate(all(a), 0) + n) / n;
	ll ans1 = 0, ans2 = 0;
	rep(i, n) {
		ans1 += pow(ave - a[i], 2);
		ans2 += pow(ave2 - a[i], 2);
	}
	printf("%d\n", min(ans1, ans2));

	Please AC;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);

	int n =sc.nextInt();
	int i =1;
	while(true){
	    int x=i;
            if(x%3==0){
		System.out.printf(" %d",i);}
	     else{
		 while(true){
	        if(x%10==3){
		    System.out.printf(" %d",i);
		    break;}    
                x/=10;
		if(x!=0)continue;
		else break;}}
        if(++i<=n)continue;
	else break;
	}
	System.out.printf("\n");
  }
 }

Measured memory_bytes: 40168
#include <iostream>
#include <cstring>

using namespace std;

class Dice {

    int E[6]{3, 1, 0, 5, 4, 2};
    int N[6]{1, 5, 2, 3, 0, 4};
    int S[6]{4, 0, 2, 3, 5, 1};
    int W[6]{2, 1, 5, 0, 4, 3};
    int v[6];

public:
    inline Dice(int *values) { memcpy(v, values, sizeof(int) * 6); };

    void roll(char);

    inline int top() { return v[0]; };
};

void Dice::roll(char dir) {
    int *dir_;
    switch (dir) {
        case 'E':
            dir_ = E;
            break;
        case 'N':
            dir_ = N;
            break;
        case 'S':
            dir_ = S;
            break;
        case 'W':
            dir_ = W;
            break;
    }
    int v_[6];
    for (int i = 0; i < 6; i++) {
        v_[i] = v[dir_[i]];
    }
    memcpy(v, v_, sizeof(int) * 6);
}

int main() {
    int values[6];
    for (int i = 0; i < 6; i++) {
        cin >> values[i];
    }
    Dice dice(values);
    string command;
    cin >> command;
    for (char c:command) {
        dice.roll(c);
    }
    cout << dice.top() << endl;
}


Measured memory_bytes: 3188
#include <iostream>
#include <string>
using namespace std ;
int main() {
    int h, w;
    cin >> h >> w;
    string s, new_s;
    for (int i = 0; i < h; ++i) {
        cin >> s;
        new_s += s;
        new_s += s;
    }
    for (int j = 0; j < 2 * h * w; j += w) {
        for (int i = j; i < j + w; ++i) {
            cout << new_s[i];
        }
        cout << endl;
    }
    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 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;
typedef long long int lli;
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(){
    int n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    vector<tuple<char, int, bool>> point(n);
    rep(i, n){
        if (t[i] == 'r') {
            get<0>(point[i]) = 'p';
            get<1>(point[i]) = p;
            get<2>(point[i]) = false;
        }
        if (t[i] == 's'){
            get<0>(point[i]) = 'r';
            get<1>(point[i]) = r;
            get<2>(point[i]) = false;
        } 
        if (t[i] == 'p'){
            get<0>(point[i]) = 's';
            get<1>(point[i]) = s;
            get<2>(point[i]) = false;
        } 
    }
    ll ans = 0;
    rep(i, n){
        if (i - k < 0){
            ans += get<1>(point[i]);
            get<2>(point[i]) = true;
        } 
        else if(get<0>(point[i-k]) != get<0>(point[i])){
            ans += get<1>(point[i]);
            get<2>(point[i]) = true;
        }
        else if(!get<2>(point[i-k])){
            ans += get<1>(point[i]);
            get<2>(point[i]) = true;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  ll d = min(a + b+1, c);
  print(b + d);
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
    int R[MAX], n;
    cin >> n;
    for(int i=0;i<n;i++)cin >> R[i];
    int max_v = -2000000000;
    int min_v = R[0];

    for(int i=1;i<n;i++){
        max_v = max(max_v, R[i]-min_v);
        min_v = min(min_v, R[i]);
    }
    cout << max_v << endl;
    return 0;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
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;
}
int main() {
    ll N;
    cin >> N;
    vector<pair<ll, ll>> robots(N);
    for (ll i = 0; i < N; ++i) {
        ll a, b;
        cin >> a >> b;
        robots[i].second = a - b;
        robots[i].first  = a + b;
    }

    sort(robots.begin(), robots.end(), [](const auto& a, const auto& b) { return a.first < b.first; });

    ll next  = robots[0].first;
    ll count = 1;
    for (ll i = 1; i < robots.size(); ++i) {
        if (next <= robots[i].second) {
            count++;
            next = robots[i].first;
        }
    }
#ifdef SOURCE_TEST
    for (auto& r : robots) {
        cout << r.first << "," << r.second << endl;
    }

#endif

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


Measured memory_bytes: 4824
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<math.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define N (1000000000+7)
#define INF (ll)1e16
typedef long long ll;

ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

int main(void){
    ll n,m;
    string s,t;
    cin>>n>>m;
    cin>>s>>t;
    ll g=gcd(n,m);
    ll m1=m/g;
    ll n1=n/g;
    ll l=n*m/g;
    map<ll,char>ms,mt;
    for(ll i=0;i<n;i++){
        ms[i*m1+1]=s[i];
    }
    for(ll i=0;i<m;i++){
        mt[i*n1+1]=t[i];
    }
    for(ll i=0;m1*n1*i+1<=l;i++){
        if(ms[m1*n1*i+1]!=mt[m1*n1*i+1]){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<l<<endl;
    return 0;
}

Measured memory_bytes: 10880
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int A[1000000],n;
int main(int argc, char const *argv[])
{
	cin>>n;
	for(int i = 0;i < n;i++)
	{
		cin>>A[i];
	}
	int q,k,sum = 0;
	cin>>q;
	for(int j = 0; j < q;j++)
	{
		cin>>k;
		if(*lower_bound(A,A + n,k) == k) sum++;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3408
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	N := readInt()
	K := readInt()
	if K == 1 {
		println(0)
		return
	}
	println(N - K)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
int n,c[21],v[21],ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>v[i];
	for(int i=0;i<n;i++)cin>>c[i];
	for(int i=0;i<(1<<n);i++)
	{
		int v_sum=0,c_sum=0;
		for(int s=0;s<n;s++)
		{
			if((1<<s)&i)
			{
				v_sum+=v[s];
				c_sum+=c[s];
			}
		}
		ans=max(ans,v_sum-c_sum);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256