akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.Arrays;

class Main {
    public static void main(String[] args) throws IOException {
        int i, n, m; 
        String line, chr;
        String str;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        for(;;) {
            str = br.readLine();
            if("-".equals(str)) {
                break;
            }
            n = Integer.parseInt(br.readLine());
            for(i = 0; i < n; i++) {
                m = Integer.parseInt(br.readLine());
                chr = str.substring(0, m);
                line = str.substring(m, str.length());
                str = line + chr;
            }
            System.out.println(str);
        }
        System.out.flush();
    }
}

Measured memory_bytes: 24288
#include<stdio.h>
int main(){
  int i,j,A[101],minj,swap=0,a,N;
  
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<=N-1;i++){
    minj=i;
    for(j=i;j<=N-1;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
    }
    if(i!=minj){
    a=A[i];
    A[i]=A[minj];
    A[minj]=a;
    swap++;
    }
  }
  
  for(i=0;i<N;i++){
    if(i>0){
      printf(" ");
    }
    printf("%d",A[i]);
  }
  printf("\n%d\n",swap);
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  vector<int> dp(n);
  dp.at(0)=0;
  for(int i=1;i<n;i++){
    if(i==1)
    dp[i]=abs(a[i]-a[i-1]);
    else
    dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
  }
  cout << dp[n-1] << endl;
}

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

int main(){
    int x;
    int y;
    int z;
    
    while(1){
        cin >> x >> y;
        if (x == 0 && y == 0) break;
        if (x > y) {
            z = x;
            x = y;
            y = z;
        }
        cout << x << " " << y << endl;
    }
}


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

int main(){
    int n, i, count;
    string str;
    i = 0;
    count = 0;
    
    cin >> n;
    cin >> str;
    
    while(1){
        if(i >= str.size() - 1) break;
        if((str[i] == 'O' && str[i+1] == 'X') || (str[i] == 'X' && str[i+1] == 'O')){
            count++;
            i += 2;
            continue;
        } 
        else{
            i++;
        }
    }
    
    cout << count << endl;
    
    return 0;
}


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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

// Binary Indexed Tree
// 0-indexed
template <typename T>
class BIT {
private:
  // データ
  vector<T> bit;
  // 単位元, 要素数
  int neutral = 0;
  // 更新クエリ, 区間クエリ
  function<T(T,T)> f = [](const T l, const T r) -> T { return l+r; },
                   g = [](const T l, const T r) -> T { return l+r; };
public:
  // 初期化
  BIT(int n_ = 1e5) { init(n_); }
  void init(int n_ = 1e5) { bit.assign(n_+1, neutral); }
  // iに対する点更新クエリ
  void update(int i, T w) {
    for(int x = i+1; x < bit.size(); x += x&-x) bit[x] = f(bit[x], w);
  }
  // [0,i)に対する区間クエリ
  T query(int i) {
    T ret = neutral;
    for(int x = i+1; x > 0; x -= x & -x) ret = g(ret, bit[x]);
    return ret;
  }
};

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

  int n, m, q;
  cin >> n >> m >> q;
  vector<PII> v(m);
  REP(i, m) {
    cin >> v[i].second >> v[i].first;
    v[i].second--, v[i].first--;
  }
  VVI a(q, VI(3));
  REP(i, q) {
    cin >> a[i][1] >> a[i][0], a[i][2] = i;
    a[i][1]--, a[i][0]--;
  }

  sort(ALL(v));
  sort(ALL(a));

  VI ans(q);
  BIT<int> bit(n);
  int idx = 0;
  REP(i, q) {
    while(idx < m && v[idx].first <= a[i][0]) {
      bit.update(v[idx].second, 1);
      idx++;
    }

    int p = a[i][1]==0?0:bit.query(a[i][1]-1);
    ans[a[i][2]] = bit.query(n-1) - p;
  }

  REP(i, q) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 10368
#include <stdio.h>
	
	int main(void)
{
	long long int a,b,x;
	scanf("%lld %lld %lld",&a,&b,&x);
	
	if(a==0){
	printf("%lld\n",b/x+1);
	} else{
		printf("%lld\n",b/x-(a-1)/x);
	}
	return 0;
}

Measured memory_bytes: 128
T = list(input())
for i in range(len(T)):
    if i == 0:
        if T[i] == "?":
            if len(T) == 1:
                T[i] = "D"
                break
            if T[i+1] == "D":
                T[i] = "P"
            else:
                T[i] = "D"
    else:
        if T[i] == "?":
            T[i] = "D"
print("".join(T))


Measured memory_bytes: 10900
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;
int n, k;
llong T[MAX];

//最大積載量 p の k 台のトラックで何個の荷物を積めるか？
int check(llong P){
  int i = 0;
  for (int j = 0; j < k; j++){
    llong s = 0;
    while(s+T[i] <= P){
      s += T[i];
      i++;
      if(i == n)return n;
    }
  }
  return i;
}

int solve(){
  llong left = 0;
  llong right = 100000 * 10000;
  llong mid;
  while (right - left > 1){
    mid = (left + right)/2;
    int v = check(mid);
    if(v>=n)right=mid;
    else left = mid;
  }

  return right;
}

main(){
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >>T[i];
  llong ans = solve();
  cout << ans <<endl;
}



Measured memory_bytes: 3880
#include <stdio.h>

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

   int L = A;
   int R = A+N-1;

   int eat;
   if (R <= 0)
      eat = R;
   else if (L >= 0)
      eat = L;
   else 
      eat = 0;

   int answer = (R+L) * (R-L+1)/2 - eat;

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


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

using namespace std;

int main(){

    int num, a, b, c, stat = 0, temp;

    cin >> num;

    while(1){
        temp = num;
        a = temp % 10;
        temp /= 10;
        b = temp % 10;
        if(a == b){
            c = temp / 10;
            if(b == c){
                break;
            }
            else{
                num++;
            }
        }
        else{
            num++;
        }
    }

    cout << num << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<ll, ll>P;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
string a[114514];
map<string,ll>mp;
signed main(){
	ll n,ans=0;
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)sort(a[i].begin(),a[i].end());
	rep(i,n)mp[a[i]]++;
	for(auto x:mp)ans+=(x.second)*(x.second-1)/2;
	cout<<ans<<endl;
}



Measured memory_bytes: 18304
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>

using namespace std;

const long long INF = 1LL << 50;

void solve(int n, int m, vector< vector<int> > gr) {
    vector<long long> dist(n, INF);
    dist[0] = 0;
    for (int loop = 0; loop < n-1; loop++) {
        for (int i = 0; i < m; i++) {
            if (dist[gr[i][0]-1] == INF) {
                continue;
            }
            if (dist[gr[i][1]-1] > dist[gr[i][0]-1] + gr[i][2]) {
                dist[gr[i][1]-1] = dist[gr[i][0]-1] + gr[i][2];
            }
        }
    }
    long long ans = dist[n-1];
    vector<bool> flag(n, false);
    for (int loop = 0; loop < n; loop++) {
        for (int i = 0; i < m; i++) {
            if (dist[gr[i][0]-1] == INF) {
                continue;
            }
            if (dist[gr[i][1]-1] > dist[gr[i][0]-1] + gr[i][2]) {
                dist[gr[i][1]-1] = dist[gr[i][0]-1] + gr[i][2];
                flag[gr[i][1]-1] = true;
            }
            if (flag[gr[i][0]-1]) {
                flag[gr[i][1]-1] = true;
            }
        }
    }
    if (flag[n-1]) {
        std::cout << "inf" << std::endl;
    } else {
        std::cout << -ans << std::endl;
    }
}

int main() {
    struct timeval start,end;
    long long span;
    int n,m;

    gettimeofday(&start,NULL);

    std::cin >> n >> m;
    vector< vector<int> > gr(m, vector<int>(3));
    for (int i = 0; i < m; i++) {
        std::cin >> gr[i][0] >> gr[i][1] >> gr[i][2];
        gr[i][2] = -gr[i][2];
    }
    solve(n,m,gr);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

void solve() {
    int N, X;
    cin >> N >> X;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    A.push_back(X);
    sort(all(A));
    int g = A[1] - A[0];
    for (int i = 1; i < A.size() - 1; i++) {
        g = __gcd(g, A[i + 1] - A[i]);
    }
    cout << g << endl;

}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

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

const double pi = std::acos(-1);
int main(){
  int A,B,H,M;
  cin >> A >> B >> H >> M;
  double angleM = 360.0 * M / 60;
  double angleH = 360.0 * H / 12 + angleM / 12;
  double angle = abs(angleH - angleM);
  angle = min(angle, 360-angle);
  double rad = 2 * pi * angle / 360;
  double ans = sqrt(A*A + B*B - 2.0*A*B*cos(rad));
  cout << fixed << setprecision(15);
  cout << ans << endl;
}
  

Measured memory_bytes: 4196
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(),x.end()
#define pri 1000000007
#define nonod 1000001
#define pr pair <ll,ll>
#define mnx  1000001
#define inf 100000000000000001
#define prin(x) cout<<setprecision(9)<<fixed<<x<<endl;
using namespace std;





void masterstroke(ll ta){
ll n,m;
cin>>n>>m;
ll a[n+1]={0};
for(ll i=0;i<m;i++){
	ll x;
	cin>>x;
	a[x]=1;
}
ll dp[n+1]={0};
if(a[n]==0)dp[n]=1;
//cout<<dp[n]<<endl;
for(ll i=n-1;i>=0;i--){
	if(a[i+1]==0)dp[i]=(dp[i]+dp[i+1])%pri;
	if(i+2<=n&&a[i+2]==0)dp[i]=(dp[i]+dp[i+2])%pri;
}
cout<<dp[0]<<endl;}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++)masterstroke(i);
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

int main(){
    int n,m,p;
    while(cin >> n >> m >> p,n&&m&&p){
        vector<vector<bool>> s(n,vector<bool>(m,false));
        vector<vector<int>> pe(n,vector<int>(m,0));
        vector<pair<pair<int,int>,int>> v;
        vector<int> num(n,0);
        vector<int> t(n,0);
        for(int i=0;i<p;i++){
            int a,b,c; string r; cin >> a >> b >> c >> r;
            a--; b--;
            if(s[a][b])continue;
            if(r[0]=='W'){
                pe[a][b]++;
            }
            else{
                num[a]++;
                t[a]+=c+pe[a][b]*1200;
            }
        }
        for(int i=0;i<n;i++){
            v.push_back(make_pair(make_pair(num[i],-t[i]),-(i+1)));
        }
        sort(v.rbegin(),v.rend());
        for(int i=0;i<n;i++){
            printf("%d %d %d\n",-v[i].second,v[i].first.first,-v[i].first.second );
        }
    }
}



Measured memory_bytes: 3176
import java.util.*;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
 
        int N = sc.nextInt();
        int K = sc.nextInt();
        long ans = 0;
        long[] sum = new long[N + 1];
        sum[0] = 0;

        for(int i=1; i<=N; i++){
            sum[i] = sum[i - 1] + i;
        }

        for(int i=K; i<=N; i++){
            long min = sum[i - 1];
            long max = sum[N] - sum[N - i];
            ans += max - min + 1;
            ans = ans % 1000000007;
        }
        System.out.println(ans + 1);
    }
}

Measured memory_bytes: 37232
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string S[5]={"dream", "dreamer", "erase", "eraser"},str;
    cin >> str;
    int flag=0,i=0;
    for(int i=0;i<4;++i) reverse(S[i].begin(), S[i].end());
    reverse(str.begin(), str.end());
    
    for(int i=0;i<str.size();){
        flag=0;
        for(int j=0;j<4;j++){
            if(str.substr(i,S[j].size()) == S[j]){
                i += S[j].size();
                flag =1;
            }
        }
        if(!flag){
            cout<<"NO"; return 0;
        };
    }
    cout << "YES";
    return 0;
}


Measured memory_bytes: 512
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto M = RD;
	auto cnt = new long[](N);
	auto red = new bool[](N);
	cnt[] = 1;
	red[0] = true;
	foreach (i; 0..M)
	{
		auto x = RD-1;
		auto y = RD-1;
		red[y] |= red[x];
		--cnt[x];
		++cnt[y];
		if (cnt[x] == 0)
			red[x] = false;
	}

	long ans;
	foreach (i; 0..N)
	{
		if (red[i])
			++ans;
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 3964
#include<iostream>

using namespace std;

int main() {

	int n, l;

	cin >> n >> l;

	int sum=0;

	for (int i = 0; i < n; i++) {
		sum += l + i;
	}
	if (l + n - 1 < 0) {
		cout << sum - (l + n - 1) << endl;
	}
	else if (l <= 0 && l + n - 1 >= 0) {
		cout << sum << endl;

	}
	else {
		cout << sum - l << endl;
	}

	return 0;
}

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

#define ms(a,v)        memset(a,v,sizeof a)
#define lll            long long
#define FOR(i,a,b)     for(int i=a;i<=b;i++)
#define fast           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Read           freopen("READ.txt", "r", stdin)
#define Write          freopen("OUTPUT.txt", "w", stdout)
#define INF            99999
#define Co(x)          cout<<x<<endl;
#define Cos(x)         cout<<x<<" ";

typedef vector<long long>vii;
typedef pair<long long,long long>Pair;
typedef map<long long,long long>Map;

int dr[]={1,0,-1, 0 };
int dc[]={0,1, 0,-1 };

//int dr[]={1,1,0,-1,-1,-1, 0, 1};
//int dc[]={0,1,1, 1, 0,-1,-1,-1};

/*while(1) {
    if(!getline(cin,s)||s.empty()) break;
}*/

const int RT = 10000000;
vector<int>prime;
bitset<10000003> status;

void sieve()
{
    int rt = sqrt(RT);
    //for(int i = 4; i <= rt; i+=2) status[i]=true;
    for(int i = 3; i <= rt; i+=2)
        if(!status[i])
            for(int j = i*i; j < RT; j+=(i<<1))
                status[j] = true;
    prime.push_back(2);
    for(int i = 3; i <= RT; i+=2)
        if(!status[i])
            prime.push_back(i);
}

void Binary_Con(int n)
{
    int binaryNum[70];
    int i = 0;
    while (n > 0) {
        binaryNum[i] = n % 2;
        n = n / 2;
        i++;
    }
    // printing binary array in reverse order
    for (int j = i - 1; j >= 0; j--)
        cout << binaryNum[j];
}


void solve()
{
    int n,a,b,cnt=0;
    cin>>n;
    bool f=false;
    for(int i=1;i<=n;i++)
    {
        cin>>a>>b;
        if(a==b) cnt++;
        else cnt=0;
        if(cnt==3) f=true;
    }
    if(f) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

void kick_ass()
{
    fast
    #ifndef ONLINE_JUDGE
    //Read;
    //Write;
    #endif
    solve();
}

int main()
{
   kick_ass();
}


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

int main(){
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i, n){
      cin >> s[i];
  }
  sort(s.begin(), s.end());
  rep(i, n){
      cout << s[i];
  }
  cout << endl;
}

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

int main() {
  int t;
  cin >> t;
  vector<int> S(2, 0);
  while (t--) {
    string a, b;
    cin >> a >> b;
    if (a > b)
      S[0] += 3;
    else if (a < b)
      S[1] += 3;
    else
      S[0]++, S[1]++;
  }
  cout << S[0] << " " << S[1] << endl;

  return 0;
}


Measured memory_bytes: 3192
N,K=map(int,input().split())
x=list(map(int,input().split()))
y=[]
for i in range(N-1):
    y.append(x[i+1]-x[i])
z=[]
z.append(0)
for i in range(N-1):
    z.append(z[i]+y[i])
M=10**10
for i in range(N-K+1):
    M=min(M,min(abs(x[i]),abs(x[i+K-1]))+z[i+K-1]-z[i])
if N-K==0:
  M=min(abs(x[0]),abs(x[-1]))+z[-1]
print(M)


Measured memory_bytes: 64152
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<list>
using namespace std;

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b)cout<<c<<endl;
	else if(b==c)cout<<a<<endl;
	else if(c==a)cout<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    C = list(map(int, readline().split()))
    C.sort()

    if C[0] + C[1] == C[2]:
        print('Yes')
    else:
        print('No')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
def solve(n, a, b):
    ans = 0
    for i in range(n):
        d = min(b[i], a[i])
        ans += d
        d = min(b[i]-d, a[i+1])
        ans += d
        a[i+1] -= d
    return ans

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(n, a, b))

Measured memory_bytes: 18624
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {          
                int n = int.Parse(Console.ReadLine());
                int[] output = new int[n];//n????????????????????£?¨?
                string input = Console.ReadLine();
                string[] array = input.Split(' ');

                for (int t = 0; t < n; t++)
                {
                    output[t] = int.Parse(array[t]);//??°?????????????????£??\
                }

                for (int i = n-1; 0 <= i; i--)
                {
                    Console.Write(string.Format("{0}",output[i]));
                    if (i == 0)
                        break;
                    Console.Write(" ");
                }
                Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9164
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN (1 << 21)

int n, q;
string s;

char a[MAXN];	

ll solve(int k) {
	ll ret = 0;
	int pos = k - 1;
	int nd = 0;
	int nm = 0;
	ll sum = 0;
	for (int i = k; i < n; i++) {
		char drop = a[i - k];
		if (drop == 'D') {
			nd--;
			sum -= nm;
		} else if (drop == 'M') {
			nm--;
		}
		if (a[i] == 'D') {
			nd++;
		} else if (a[i] == 'M') {
			nm++;
			sum += nd;
		} else if (a[i] == 'C') {
			ret += sum;
		}
	}
	return ret;
}

int main() {
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++) {
		a[i] = 'A';
	}
	for (int i = n; i < n + n; i++) {
		a[i] = s[i - n];
	}
	n *= 2;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		cout << solve(t) << endl;
	}
	return 0;
}


Measured memory_bytes: 6260
#include <stdio.h>
int main()
{
    int a,b,c,x,i,j,k,cnt=0;
    scanf("%d%d%d%d",&a,&b,&c,&x);
    for(i=0;i<=a;i++)
        for(j=0;j<=b;j++)
        for(k=0;k<=c;k++)
        if((i*500+j*100+k*50)==x)
        cnt++;
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 128
import bisect
S,T = input(),input()
lenS = len(S)
alp = [[]for i in range(26)]

for i in range(len(S)):
    alp[ord(S[i])-97].append(i)

if alp[ord(T[0])-97] == []:
    print(-1)
    exit()

l = [alp[ord(T[0])-97][0]]
for c in T[1:]:
    A = alp[ord(c)-97]
    if A == []:
        print(-1)
        exit()
    l.append(A[bisect.bisect_left(A,l[-1]+1)%len(A)])

ans = 0
for i in range(len(l)-1):
    if l[i] >= l[i+1]:
        ans += 1
print(ans*lenS+l[-1]+1)

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const ll mod = 1000000007LL;

long long extgcd(long long a,long long b,long long& x,long long& y)
{
  long long d = a;
  if(b != 0){
    d = extgcd(b,a%b,y,x);
    y -= (a/b)*x;
  }
  else
    x = 1,y = 0;
  return d;
}

long long mod_inv(long long a,long long m)
{
  long long x,y;
  extgcd(a,m,x,y);
  return (m+x%m)%m;
}


const int MAXnCk = 400001;
ll fact[MAXnCk+1], fact_inv[MAXnCk+1];
void init_nCk(){
  fact[0] = fact_inv[0] = 1;
  REP(i,1,MAXnCk+1) {
    fact[i] = fact[i-1] * (ll)i % mod;
    fact_inv[i] = mod_inv(fact[i],mod);
  }
}

ll nCk(ll n,ll k){
  if( n < 0 || k < 0 || k > n ) return 0LL;
  if( n-k < k ) k = n-k;
  return fact_inv[k] * fact[n] % mod * fact_inv[n-k] % mod;
}


#define MAX 100010
int n, a[MAX];


void solve() {
  if( n == 1 ) {
    cout << 1 << endl;
    cout << 1 << endl;
    return;
  }
  init_nCk();
  map<int,int> mp;
  int L = -1;
  rep(i,n+1) {
    if( mp.count(a[i]) ) { L = i; break; }
    mp[a[i]] = i;
  }
  int R = mp[a[L]];
  assert( L != -1 );
  int rL = n - L;
  int rR = R;
  swap(rL,rR);
  REP(k,1,n+2) {
    ll ans = nCk(n+1,k);
    ll c = 0;
    cout << "* k = " << k << endl;
    REP(b,0,rL+1) {
      cout << "  (" << rL << "," << b << ")  (" << rR << "," << k-1-b << ")" << endl;
      c = ( c + nCk(rL,b) * nCk(rR,k-1-b) ) % mod;
    }
    cout << "  ans = " << ans << " - c = " << c << endl;
    ans = ans - c;
    while( ans < 0 ) ( ans += mod ) %= mod;
    cout << ans << endl;
  }
}

void compute() {
  /*
  puts("Answer:");
  solve();
  puts("");
  */
  if( n == 1 ) {
    cout << 1 << endl;
    cout << 1 << endl;
    return;
  }
  init_nCk();
  map<int,int> mp;
  int L = -1;
  rep(i,n+1) {
    if( mp.count(a[i]) ) { L = i; break; }
    mp[a[i]] = i;
  }
  int R = mp[a[L]];
  assert( L != -1 );
  int rL = n - L;
  int rR = R;
  swap(rL,rR);
  REP(k,1,n+2) {
    ll ans = ( nCk(n+1,k) - nCk(rL+rR,k-1) ) % mod;
    while( ans < 0 ) ( ans += mod ) %= mod;
    cout << ans << endl;
  }
}

int main() {
  if( 0 ) {
    srand((unsigned int)time(NULL));
    cout << 100000 << endl;
    vector<int> vec;
    #define pb push_back
    REP(i,1,100001) vec.pb(i);
    vec.pb(1);
    random_shuffle(ALL(vec));
    rep(i,(int)vec.size()) cout << vec[i] << " ";
    return 0;
  }
  cin >> n;
  rep(i,n+1) cin >> a[i];
  compute();
  return 0;
}


Measured memory_bytes: 14892
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
#define MOD (ll)(1e9+7)
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;


signed main(){
    ll n;
    cin >> n;
    ll cnt[9] = {};
    rep(i,0,n){
        ll a;
        cin >> a;
        cnt[min(a/400,8LL)]++;  
    }

    ll ans = 0;
    rep(i,0,9){
        if(i < 8 && cnt[i] >0) ans++;
    }
    cout << max(1LL,ans) << " " << ans + cnt[8] << endl; 
    return 0;
}


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

int main(){
    int a[5];
    for(int i = 0; i < 5; i++){
        cin >> a[i];
    }
    for(int i = 0; i < 5; i++){
        if(a[i] == 0){
            cout << i+1 << endl;
            return 0;
        }
    }
    return 0;
}

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


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

string s[110];

int main() {
	li n, l;
	cin >> n >> l;
	rin{cin >> s[i];}
	sort(s, s + n);
	rin{cout << s[i];}
	cout << endl;



	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    char in[1001];
    int i,out;
    while(1)
    {
        for(i=0;i<1001;i++)
        {
            in[i]=0;
        }
        out=0;
       scanf("%s",in);
       if(in[0]=='0') break;
       for(i=0;i<1000;i++)
       {
           if(in[i]==0) break;
           out += in[i]-'0';
       }
       printf("%d\n",out);
    }
    return 0;
}

Measured memory_bytes: 536
from collections import deque

def dfs(stage , visited , start_x,start_y,goal_x,goal_y):
    queue = deque([[start_x,start_y]])
    visited[start_x][start_y] = 1
    while queue:
        x , y = queue.popleft()
        if [x , y] == [goal_x,goal_y]:
            return visited[x][y]

        for dx , dy in ([1,0],[-1,0],[0,1],[0,-1]):
            new_x , new_y = x + dx , dy + y
            #print(new_x,new_y)
            if 0 <= new_x <= goal_x and 0 <= new_y <= goal_y  and stage[new_x][new_y] == "." and visited[new_x][new_y] == -1:
                #print(new_x , new_y)
                visited[new_x][new_y] = visited[x][y] + 1
                queue.append([new_x,new_y])
    print("-1")
    exit(0)
if __name__ == "__main__":
    H , W = map(int , input().split())
    stage = []
    for _ in range(H):
        stage.append(list(input()))
    start_x,start_y ,goal_x,goal_y = 0,0,H-1,W-1
    visited = [[-1] * W for _ in range(H)]
    #print(visited)
    #print(stage)
    #print(visited[0][1])
    sum = 0
    for value in stage:
        sum += value.count('.')
    #print(sum)
    print(sum - dfs(stage,visited,start_x,start_y,goal_x,goal_y))


Measured memory_bytes: 3316
#![allow(non_snake_case)]
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let a:usize = sc.read();
    let b:usize = sc.read();
    let c:usize = sc.read();
    if a+b+c >= 22 {
        println!("bust");
    }else{
        println!("win");
    }
}

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

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




Measured memory_bytes: 4352
n,k=map(int,input().split())
A=list(map(int,input().split()))

for i in range(n):
    A[i]-=1

ans=0
hub_city=0
visited=[-1]*n
now=0
cnt_warp=0
loop_cnt=0
first_visit_hub_city=0

for i in range(n):
    if visited[now]>-1:
        hub_city=now
        first_visit_hub_city=visited[now]
        loop_cnt=cnt_warp-first_visit_hub_city
        break
    else:
        visited[now]=cnt_warp
    
    now=A[now]
    cnt_warp+=1

idoukaizu=min(first_visit_hub_city+(k-first_visit_hub_city)%loop_cnt,k)

now=0
for i in range(idoukaizu):
    now=A[now]

print(now+1)

Measured memory_bytes: 99896
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(isize);
    
    for a1 in 1..3501 {
        for a2 in 1..3501 {
            let up = 4*a1*a2 - n*a1 - n*a2;
            if up <= 0 {
                continue;
            }
            let down = n*a1*a2;
            if down % up == 0 {
                println!("{} {} {}", a1,a2,down/up);
                return;
            }
        }
    }
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

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

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000010;
const int MAXK = 100010;
const int MAXQ = 200010;

int n, a[MAXN], k;
ll dp[MAXN][MAXK], s[MAXK];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> k;
    FOR(i,1,n) cin >> a[i];
    dp[0][0] = 1;
    s[0] = dp[0][0];
    FOR(i,1,100000) s[i] = (s[i-1] + dp[0][i]) % MODBASE;
    FOR(i,1,n) {
        FOR(j,0,100000) {
            int r = j;
            int l = max(0, r - a[i]);
            if (l == 0) dp[i][j] = s[r];
            else dp[i][j] = (s[r] - s[l-1] + MODBASE) % MODBASE;
        }
        s[0] = dp[i][0];
        FOR(j,1,100000) s[j] = (s[j-1] + dp[i][j]) % MODBASE;
    }
    cout << dp[n][k];
    return 0;
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int B[N-1];
    REP(i, N-1){
        cin >> B[i];
    }

    int A[N];
    A[0] = B[0];
    A[N-1] = B[N-2];
    FOR(i, 1, N-2){
        A[i] = min(B[i-1], B[i]);
    }

    int ans = 0;
    REP(i, N){
        ans += A[i];
    }

    cout << ans << endl;
}


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

int main(){
    int r,l,d;
    cin >> r>>l>>d;
    int ans = 0;
    for(int i = r; i<= l; i++)
    {
        if(i % d == 0)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;


class TEST{
	static void Main(){
		Debug.Listeners.Add(new TextWriterTraceListener(System.Console.Out));
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int ans = N;
		
		switch(K%2){
			
			case 0:
			// there exists the center vertex when diam%2 == 0
			
			for(int i=0;i<N;i++){
				
				int[] depth = new int[N];
				int[] parent = new int[N];
				int root = i;
				depth[root] = 0;
				parent[root] = -1;
				
				var Q = new Queue<int>();
				Q.Enqueue(root);
				while(Q.Count>0){
					var now = Q.Dequeue();
					foreach(var nxt in E[now]){
						if(nxt != parent[now]){
							parent[nxt] = now;
							depth[nxt] = depth[now] + 1;
							Q.Enqueue(nxt);
						}
					}
				}
				int mustRemove = depth.Count(e => e > K/2);
				ans = Math.Min(ans,mustRemove);
			}
			break;
			
			
			
			case 1:
			// there exists the center edge when diam%2 == 1
			
			for(int i=0;i<N;i++){
				
				int[] depth = new int[N];
				int[] parent = new int[N];
				int root = i;
				foreach(var adj in E[root]){
					if(adj < root)continue;
					
					depth[root] = 0;
					parent[root] = adj;
					depth[adj] = 0;
					parent[adj] = root;
					
					var Q = new Queue<int>();
					Q.Enqueue(root);
					Q.Enqueue(adj);
					
					while(Q.Count>0){
						var now = Q.Dequeue();
						foreach(var nxt in E[now]){
							if(nxt != parent[now]){
								parent[nxt] = now;
								depth[nxt] = depth[now] + 1;
								Q.Enqueue(nxt);
							}
						}
					}
Debug.WriteLine(String.Join(" ",depth));					
					int mustRemove = depth.Count(e => e > K/2);
					ans = Math.Min(ans,mustRemove);
				}
			}
			break;
			
		}
		
		Console.WriteLine(ans);
	}
	
	int N,K;
	List<int>[] E;
	public Sol(){
		var d = ria();
		N = d[0];
		K = d[1];
		E = new List<int>[N];
		for(int i=0;i<N;i++){
			E[i] = new List<int>();
		}
		for(int i=0;i<N-1;i++){
			d = ria();
			E[d[0]-1].Add(d[1]-1);
			E[d[1]-1].Add(d[0]-1);
		}
		
	}
	
	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define m_p make_pair

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int A, B, M;
	cin >> A >> B >> M;
	
	int a[A];
	for(int i=0 ; i<A ; ++i)cin >> a[i];
	
	int b[B];
	for(int i=0 ; i<B ; ++i)cin >> b[i];
	
	int minA = *min_element(a, a+A);
	int minB = *min_element(b, b+B);
	
	int x, y, c;
	int minP = minA + minB;
	for(int i=0 ; i<M ; ++i){
		cin >> x >> y >> c;
		int price = a[x-1] + b[y-1] - c;
		minP = min(minP, price);
	}
	
	cout << minP;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(void)
{
  int a,b,c,d; cin>>a>>b>>c>>d;
  int d1,d2,d3;
  d1=abs(b-a);
  d2=abs(c-b);
  d3=abs(c-a);
  if(d1<=d){
    if(d2<=d){
      puts("Yes"); return 0;
    }
  }
  if(d3<=d){puts("Yes"); return 0;}
  puts("No");
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeForce
{



    class CF
    {

        static void Main(string[] args)
        {
            List<int> firstnumbers = new List<int>(from x in Console.ReadLine().Split(' ') select Convert.ToInt32(x));
            var votes = new List<int>(from x in Console.ReadLine().Split(' ') select Convert.ToInt32(x));
            int counter = 0;
            double threshold = 1.0 / (4 * firstnumbers[1]) * votes.Sum();
            foreach (int i in votes)
            {
                if (i >= threshold)
                    counter++;
                
            }
            if (counter >= firstnumbers[1])
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


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

using ll = long long;

int main(){
	ll a, b, c;cin >> a >> b >> c;
	if(c - b - a <= 0){
		cout<<"No"<<endl;
		return 0;
	}
	if(4 * a * b < (c - b - a) * (c - a - b)){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int chmax(int *,int);
int main()
{
    char s[3001];
    char t[3001];
    scanf("%s",s);
    scanf("%s",t);
    int lens=strlen(s);
    int lent=strlen(t);
    int dp[lens][lent];
    //initialize dp[i][0]
    if(s[0]==t[0]) dp[0][0]=1;
    else dp[0][0]=0;
    for (int i = 1; i < lens; i++)
    {
        if(s[i]==t[0])dp[i][0]=1;
        else dp[i][0]=0;
        chmax(&dp[i][0],dp[i-1][0]);
    }
    //initialize dp[0][j]
    for (int j = 1; j < lent; j++)
    {
        if(s[0]==t[j])dp[0][j]=1;
        else dp[0][j]=0;
        chmax(&dp[0][j],dp[0][j-1]);
    }
    //loop for i and j
    for (int i = 1; i < lens; i++)
    {
        for (int j = 1; j < lent; j++)
        {
            dp[i][j]=0;
            if(s[i]==t[j])dp[i][j]=dp[i-1][j-1]+1;
            chmax(&dp[i][j],dp[i-1][j]);
            chmax(&dp[i][j],dp[i][j-1]);
        }
        
    }
    int i=lens-1;
    int j=lent-1;
    int now=dp[lens-1][lent-1];
    char lcs[now+1];
    lcs[now]='\0';
    while(now>0)
    {
        while (dp[i-1][j]==dp[i][j])
        {   
            if(i==0)break;
            i--;
        }
        while (dp[i][j-1]==dp[i][j])
        {
            if(j==0)break;
            j--;
        }
        lcs[now-1]=s[i];
        i--;
        j--;
        now--;
    }
    printf("%s\n",lcs);
    return 0;
}

int chmax(int *a,int b)
{
    if(*a<b)*a=b;
}

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


ll powr(ll a,ll b, ll mod)
{
	if(b<=0)
		return 1;
	else if(b%2==0)
		return (powr(a,b/2,mod)*powr(a,b/2,mod))%mod;
	else
		return (a*powr(a,b-1,mod))%mod;
}

void solve()
{
	ll n, mod =1e9 +7;
	cin>>n;
	if(n==1)
	{
		cout<<0<<endl;
		return ;
	}
	else if(n==2)
	{
		cout<<2<<endl;
		return;
	}
	ll ans = powr(10,n,mod)-2*powr(9,n,mod)+powr(8,n,mod);
	ans = ans%mod;
	cout<<(ans+mod)%mod<<endl;
}

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

Measured memory_bytes: 3636
import java.lang.Math.max

fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }
    var lcs = Array(n + 2) { 0 }
    for (i in 1..n) {
        lcs[i] = gcd(lcs[i - 1], a[i - 1])
    }
    var rcs = Array(n + 2) { 0 }
    for (i in n downTo 1) {
        rcs[i] = gcd(rcs[i + 1], a[i - 1])
    }
    var ans = 0
    for (i in 1..n) {
        ans = max(ans, gcd(lcs[i - 1], rcs[i + 1]))
    }
    println(ans)
}

Measured memory_bytes: 58248
// I make this just for fun because i'm done
// Aimi Haraguni >> Konomi Suzuki >> Yui >>  Ikimono Gakari >> Garnidelia >> Kalafina >> Eir Aoi.   .. dude? 
// problems that involves any kind of persistent data structures are the best of the best, are not them?
 
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
 
#define pb push_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) ll(x.size())
#define all(v) (v).begin(), (v).end()
// #define fill(x, v) memset(x, v, sizeof(x))
#define FER(i,a,b) for(int i=int(a); i< int(b); ++i)
#define IFR(i,a,b) for(int i=int(a); i>=int(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
 
// #define N 21000000
// #define M 19
// #define mod 
#define mod  998244353
#define mod1 1000000007
#define mod2 1000000009
#define bas 987625403
#define sqr(x) (x)*(x)  
#define INF 3000000000000000000
 
using namespace std;
using namespace __gnu_pbds;
 
typedef int ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<vi> vv;
typedef vector<ii> vii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> S_t;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define trace(...) fff(#__VA_ARGS__, __VA_ARGS__)
template<typename t> void fff(const char* x, t&& val1) { cout<<x<< " : "<<val1<<"\n";}
template<typename t1, typename... t2> void fff(const char* x, t1&& val1, t2&&... val2){
    const char* xd=strchr(x+1, ',');
    cout.write(x, xd-x)<<" : "<<val1<<" | ";
    fff(xd+1, val2...);
}
 
inline ll add(ll a, ll b, ll m) { return a+b < m? a+b : a+b-m;}
inline ll rem(ll a, ll b, ll m) { return a >= b? a - b: a- b + m;}
inline ll mul(ll a, ll b, ll m) { return (long long) a*b%m;}
inline void Mul(ll &a, ll b, ll m) { a = (long long) a*b%m;}
inline ll bp(ll a, ll p, ll m){
	ll ret;
	for(ret = 1; p; p>>=1, Mul(a, a, m)) (p & 1) && (Mul(ret, a, m), 1);
	return ret;
}
 
static inline void read(ll &x) { cin>>x;}

long double dp[1<<19];
inline long double Que(ll l, ll r){
	if(l) return dp[r-1] - dp[l-1];
	return dp[r-1];
}
int main(){
	fastio;
	ll r, g, b, k; read(r), read(g), read(b), read(k);
	while(g <= r and k > 0) g<<=1, k--;
	while(b <= g and k > 0) b<<=1, k--;
	if(g > r and b > g){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main(){
  int a, b, m, d;
  
  scanf("%d %d", &a, &b);
  
  m = a * b;
  
  d = m % 2;
  
  if(d == 0){
    printf("Even\n");
  }
  else{
    printf("Odd\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#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;
    string s;
    cin >> n >> s;

    vvl dp(n+1, vl(n+1));  // dp[i][j] : s[i]とs[j]から始めたとき一致する長さの最大値
    for(ll i = n-1; i >= 0; i--) {
        for(ll j = n-1; j >= 0; j--) {
            if(s[i] == s[j]) {
                dp[i][j] = min(j-i, dp[i+1][j+1] + 1);
            }
        }
    }

    ll ans = 0;
    rep(i, n-1) {
        exrep(j, i+1, n-1) {
            chmax(ans, dp[i][j]);
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 197888