akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
	int w, h, n;
	int min_x, max_x;
	int min_y, max_y;
	int res;
	int i, j;

	scanf("%d", &w);
	scanf("%d", &h);
	scanf("%d", &n);

	min_x = 0;
	max_x = w;
	min_y = 0;
	max_y = h;

	int xya[n][3];

	for(i = 0; i < n; i++) {
		for (j = 0; j < 3; j++) {
			scanf("%d", &xya[i][j]);
		}
	}

	for (i = 0; i < n; i++) {
		switch (xya[i][2]) {
		case 1:
			if (min_x < xya[i][0]) {
				min_x = xya[i][0];
			}
			break;
		case 2:
			if (max_x > xya[i][0]) {
				max_x = xya[i][0];
			}
			break;
		case 3:
			if (min_y < xya[i][1]) {
				min_y = xya[i][1];
			}
			break;
		case 4:
			if (max_y > xya[i][1]) {
				max_y = xya[i][1];
			}
			break;
		}
	}

	if (max_x <= min_x) {
		res = 0;
	} else if (max_y <= min_y) {
		res = 0;
	} else {
		res = (max_x - min_x) * (max_y - min_y);
	}

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

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
	
		int n;
		cin>>n;
		int p =n;
		int temp = 0 ,r =0;
		while(p!=0){
			temp = p%10;
			r = r*10 + temp;
			p = p/10;
		}
		if(r==n){
			cout<<"Yes\n";
		}
		else
			cout<<"No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int maxs=-1;
	int mins;
	int num=0;
	for(int i=1;i<=n;i++)
	{
		int temp;
		scanf("%d",&temp);
		if(i==1)
		{
			mins=temp;
		}
		if(temp<mins)
		{
			mins=temp;
		}
		if(temp-mins>maxs)
		{
			maxs=temp-mins;
			num=1;
		}
		else if(temp-mins==maxs)
		{
			num++;
		}
	//	printf("%d\n",num);
	}
	printf("%d\n",num);
	return 0;
}

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

int H, W, rlen, clen, psum[102][102];
char G[102][102];

int calc(int r1, int c1, int r2, int c2) {
    int ret = psum[r2][c2];
    if(r1) ret -= psum[r1 - 1][c2];
    if(c1) ret -= psum[r2][c1 - 1];
    if(r1 && c1) ret += psum[r1 - 1][c1 - 1];
    return ret;
}

int re, ce;
int cc[102][102];
int dp(int r, int c) {
    int &ret = cc[r][c];
    if(ret != -1) return ret;

    ret = 0;
    if(r + rlen - 1 != re) {
        ret = max(ret, calc(r + rlen, c, r + rlen, c + clen - 1) + dp(r + 1, c));
    }
    if(c + clen - 1 != ce) {
        ret = max(ret, calc(r, c + clen, r + rlen - 1, c + clen) + dp(r, c + 1));
    }
    return ret;
}

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

    int r, c;
    for(int i = 0; i < H; i++) {
        scanf("\n");
        for(int j = 0; j < W; j++) {
            scanf("%c", &G[i][j]);

            if(G[i][j] == 'E') r = i, c = j;
        }
    }

    if(r + 1 > H - r) {
        for(int i = 0; i < H - 1 - i; i++) for(int j = 0; j < W; j++) swap(G[i][j], G[H - 1 - i][j]);
        r = H - 1 - r;
    }
    if(c + 1 > W - c) {
        for(int i = 0; i < H; i++) for(int j = 0; j < W - 1 - j; j++) swap(G[i][j], G[i][W - 1 - j]);
        c = W - 1 - c;
    }
    rlen = r + 1;
    clen = c + 1;

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            psum[i][j] = G[i][j] == 'o'? 1 : 0;
            if(i) psum[i][j] += psum[i - 1][j];
            if(j) psum[i][j] += psum[i][j - 1];
            if(i && j) psum[i][j] -= psum[i - 1][j - 1];
        }
    }

    int ans = 0;
    for(int i = 0; i <= r; i++) {
        for(int j = 0; j <= c; j++) {
            re = H - 1 - r + i;
            ce = W - 1 - c + j;

            memset(cc, -1, sizeof(cc));
            ans = max(ans, calc(i, j, i + rlen - 1, j + clen - 1) + dp(i, j));
        }
    }

    cout << ans;
}


Measured memory_bytes: 384
/// * BISMILLAH * ///
#include<bits/stdc++.h>
/// Try to solve it, even though you may not solve it  ----- Aspot ///
using namespace std;
int main()
{
int N, M, H;
int c = 0, cc = 0;
cin >> N >> M >> H;
int a[M];
for (int i = 0; i < M; i++)
cin >> a[i];
for (int i = 0; i < M; i++)
if (a[i] > H)
c++;
else
cc++;
cout << min (c, cc);
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) {
        try {
            InputReader in;
            PrintWriter out;
            boolean useOutput = false;
            // if (System.getProperty("ONLINE_JUDGE") == null) useOutput = true;
            if (useOutput) {
                FileInputStream fin = new FileInputStream(new File("src/testdata.in"));
                in = new InputReader(fin);
                FileOutputStream fout = new FileOutputStream(new File("src/testData.out"));
                out = new PrintWriter(fout);
            } else {
                InputStream inputStream = System.in;
                in = new InputReader(inputStream);
                OutputStream outputStream = System.out;
                out = new PrintWriter(outputStream);
            }
            Solver solver = new Solver();
            solver.solve(in, out);
            out.close();
            // fin.close();
            // fout.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static class Solver
    {

        public void solve (InputReader cin, PrintWriter cout)
        {
            try {
                int n = cin.nextInt();
                int k = cin.nextInt();
                if (n < k) {
                    cout.println(1);
                } else {
                    if (n % k == 0) cout.println(0);
                    else cout.println(1);
                }
            } catch (RuntimeException e) {
                e.printStackTrace();
                return;
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }

        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong () {
            return Long.parseLong(next());
        }

        public double nextDouble () {
            return Double.parseDouble(next());
        }

    }

}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll ans=0,c[3];
  mem(c);
  string s[n];
  rep(i,n) {
    R s[i];
    if(s[i].back()=='A'&&s[i][0]=='B') c[1]++;
    else if(s[i].back()=='A') c[0]++;
    else if(s[i][0]=='B') c[2]++;
    rep(j,s[i].size()-1) {
      if(s[i][j]=='A'&&s[i][j+1]=='B') ans++;
    }
  }
  if(c[1]) {
    if(c[0]) {
      ans++;
      c[0]--;
    }
    if(c[2]) {
      ans++;
      c[2]--;
    }
    ans+=c[1]-1;
  }
  ans+=min(c[0],c[2]);
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 768
#include<stdlib.h>
#include<stdio.h>
#include<math.h>

int main(void){
    
    int n,d;
    scanf("%d %d", &n, &d);
    int x[n][d];
    int c = 0;
    int i,j,k;
    int a;
    double di;

    for(i=0;i<n;i++){
        for(j=0;j<d;j++){
            scanf("%d" ,&x[i][j]);
        }
    }
    
    for(i=0;i<n-1;i++){
       
        for(j = i+1;j<n;j++){
             di = 0;
            for(k=0;k<d;k++){
                
                di += (double)(abs(x[i][k]-x[j][k])*abs(x[i][k]-x[j][k]));
            }
            
            di = sqrt(di);
            //printf("%le\n", di);
            if(floor(di)==di ) c++;
        }

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

}

Measured memory_bytes: 128
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

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

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        ans += (ll)i;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3688
using namespace std;

#include <cstdio>
#include <cstdint>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>


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

    int     N = 0;
    int     n = 0;
    cin >> N;
    string     S[N];
    int     num_AC = 0;
    int     num_WA = 0;
    int     num_TLE = 0;
    int     num_RE = 0;
    for(n = 0; n<N; n++){
        cin >> S[n];

        if(S[n] == "AC"){
            num_AC++;
        }else if(S[n] == "WA"){
            num_WA++;
        }else if(S[n] == "TLE"){
            num_TLE++;
        }else if(S[n] == "RE"){
            num_RE++;
        }
    }
    cout << "AC x " << num_AC << "\n";
    cout << "WA x " << num_WA << "\n";
    cout << "TLE x " << num_TLE << "\n";
    cout << "RE x " << num_RE << "\n";
    return 0;
    
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = 0x3c3c3c3c;
const ll INFL = 0x3c3c3c3c3c3c3c3c;
const int MAX_N = 1e5 + 9;

int P[MAX_N];

int main(){
	cin.sync_with_stdio(false);
	cin.tie(NULL);
	int N;
	cin >> N;
	for(int i = 1; i <= N; i++) cin >> P[i];
	int ans = 0;
	for(int i = 1; i <= N - 1; i++){
		if(i == P[i]){
			swap(P[i], P[i + 1]);
			ans++;
		}
	}
	if(P[N] == N) ans++;
	printf("%d", ans);
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N=50005;
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    int sum=0;
    sum+=(n)*(n-1)/2;
    sum+=m*(m-1)/2;
    printf("%d\n",sum);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rgi register int
#define pii pair<int,int>
#define mkp make_pair
#define fi first
#define se second
#define pb push_back
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
using namespace std;
int a,b,c;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>a>>b>>c;
	int t=a+b+c;
	if(t>=22)
		cout<<"bust"<<endl;
	else
		cout<<"win"<<endl;
	return 0;
}


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

typedef long long ll;

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

    ll a, ans = 0, accum = 0;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a == 0){
            ans += accum/2;
            accum = 0;
        }
        accum += a;
    }
    ans += accum/2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

int main(void) {

	char s[101][101], tmp[101];
	int i, j, n, l;

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

	for (i = 0; i < n; i++) {
		scanf("%s", s[i]);
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < n - i - 1; j++) {
			if (strcmp(s[j], s[j + 1]) > 0) {
				
				strcpy(tmp, s[j]);
				strcpy(s[j], s[j+1]);
				strcpy(s[j+1], tmp);
				
			}
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			printf("%c", s[i][j]);
		}
	}
	return 0;
}

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

void solve(ll N){
    bool ok=false;
    REP(i,1,3501){
        REP(j,1,3501){
            if (ok) break;
            ll a = N*i*j;
            ll b=4*i*j-N*i-N*j;
            if(0<b && a%b==0){
                cout<<i<<" "<<j<<" "<<a/b<<endl;
                ok=true;
            }
        }
    }

}

// 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)
int main(){
    ll N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
H,W = gets.split.map(&:to_i)
S = readlines.map(&:chomp)

ans = 0
H.times do |y|
  W.times do |x|
    next if S[y][x] == '#'
    s = Array.new(H) { [] }
    s[y][x] = 0
    q = [[y,x]]
    while !q.empty?
      y,x = q.shift
      n = s[y][x]
      ans = n if ans < n
      [y-1,x, y+1,x, y,x-1, y,x+1].each_slice(2) do |y,x|
        next if x < 0 || y < 0 || x >= W || y >= H
        next if s[y][x] != nil
        next if S[y][x] == '#'
        s[y][x] = n + 1
        q << [y,x]
      end
    end
  end
end
puts ans


Measured memory_bytes: 1916
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,pair<int,int>> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
int main(){
    int n;cin>>n;
    bool f=false;
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            if(4*i+7*j==n)f=true;
        }
    }
    if(f){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 768
program main
    implicit none
    integer:: i,j
    integer:: n, k, q
    integer,allocatable:: a(:), p(:)
    read*, n,k,q
    allocate(a(q), p(n))
    p(1:n) = k-q
    read*, a(1:q)

    ! print*, n,k,q
    ! print*, p
    do i = 1, q
        p(a(i)) = p(a(i)) + 1 
    end do
    ! print*, p
    do i = 1, n
        if(p(i) > 0)then
            print*, 'Yes'
        else
            print*, 'No'
        end if
    end do

    
end program

Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<deque>
#include<numeric>
#include<algorithm>
#include<unordered_map>
#include<cmath>

using namespace std;
using ll = long long int;
constexpr int INF = 1 << 29;
constexpr ll MOD = ll(1e9 + 7);

int n, m;
map<ll, int> card;
vector<ll> h;

int main(void) {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		ll ai;
		cin >> ai;
		if (card[ai] == 0)
			h.push_back(ai);
		card[ai]++;
	}

	int bi;
	ll ci;
	for (int i = 0; i < m; i++) {
		cin >> bi >> ci;
		if (card[ci] == 0)
			h.push_back(ci);
		card[ci] += bi;

	}
	sort(h.begin(), h.end(), std::greater<ll>());
	ll ret = 0;
	for (int i = 0; i < h.size() && n>0; i++) {
		int card_num = min(card[h[i]], n);
		ret += h[i] * card_num;
		n -= card_num;
	}

	cout << ret << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  string s;
  cin >> s;
  int m = 0;
  int v = 0;
  rep(i, s.size()) {
    if (s[i] == 'R') {
      m++;
      v = max(v, m);
    } else {
      m = 0;
    }
  }
  cout << v << endl;
  return 0;
}

Measured memory_bytes: 3620
def main():
    import sys
    input = sys.stdin.readline
    n, m, x, y = list(map(int, input().rstrip('\n').split()))
    X = list(map(int, input().rstrip('\n').split()))
    Y = list(map(int, input().rstrip('\n').split()))
    mx = max(X)
    my = min(Y)
    for z in range(x + 1, y + 1):
        if mx < z <= my:
            print("No War")
            exit()
    print("War")


if __name__ == '__main__':
    main()


Measured memory_bytes: 39856
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")
#include"bits/stdc++.h"
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb emplace_back
#define x first
#define y second
#define pii pair<int, int>
#define sz(x) (int)(x).size()

const int prime = 1e9+7;

int mod(int a, int p = prime) {
	return (a%p + p) % p;
}

int xpo(int a, int b) {
	if(!b)
		return 1;
	int temp = xpo(mod(a*a), b/2);
	if(b&1)
		temp = mod(temp*a);
	return temp;
}

int solve() {
    int n;
    cin >> n;
    if(n == 1)
    	return 0;
    int ans = mod(xpo(10, n) - 2*xpo(9, n) + xpo(8, n));
    return ans;
}

int32_t main() {

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

    int t = 1;
    while(t--) {
        cout << solve();
    }
		
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
long long L[100];
int main() {
    int n;
    scanf("%d", &n);
    L[0] = 2;
    L[1] = 1;
    for (int i = 2; i <= n; i++) L[i] = L[i - 1] + L[i - 2];
    printf("%lld\n", L[n]);
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int w=sc.nextInt();
			int h=sc.nextInt();
			String gomi = sc.nextLine();
			if(w==0&&h==0) break;
			int[][] map = new int[h][w];
			int start_w=0,start_h=0;
			for(int i=0;i<h;++i){
				String line = sc.nextLine();
				String[] line2=line.split("");
				for(int j=0;j<w;++j){
					if(line2[j].equals("#")){
						map[i][j]=-1;
					} else if(line2[j].equals("@")){
						map[i][j]=1;
						start_w=j; start_h=i;
					}
				}
			}
			int count=1;
			Queue<Node> queue = new LinkedList<Node>();
			queue.add(new Node(start_h, start_w));
			while(!queue.isEmpty()){
				Node cur = queue.remove();
				if(cur.h!=0){
					if(map[cur.h-1][cur.w]==0){
						count++; map[cur.h-1][cur.w]=1;
						queue.add(new Node(cur.h-1,cur.w));
					}
				}
				if(cur.h!=h-1){
					if(map[cur.h+1][cur.w]==0){
						count++; map[cur.h+1][cur.w]=1;
						queue.add(new Node(cur.h+1,cur.w));
					}
				}
				if(cur.w!=0){
					if(map[cur.h][cur.w-1]==0){
						count++; map[cur.h][cur.w-1]=1;
						queue.add(new Node(cur.h,cur.w-1));
					}
				}
				if(cur.w!=w-1){
					if(map[cur.h][cur.w+1]==0){
						count++; map[cur.h][cur.w+1]=1;
						queue.add(new Node(cur.h,cur.w+1));
					}
				}
			}
			System.out.println(count);
		}
	}
}
class Node{
	int h,w;
	Node(int w,int h){
		this.h=w;
		this.w=h;
	}
}


Measured memory_bytes: 58056
#include <iostream>

using namespace std;

int main()
{
	// 入力
	int N;
	cin >> N;
	string S;
	cin >> S;
	
	bool isYes = false;
	// 偶数個の場合のみ判定を行う。奇数個の場合はNoになるため
	if (N % 2 == 0) {
		// N / 2で半分
		int halfN = N / 2;
		string first = S.substr(0, halfN);
		string after = S.substr(halfN, halfN);
			
		// S の 0 文字目から始まる N/2 文字分の部分文字列と
		// S の N/2 文字目から始まる N/2 文字分の部分文字列が等しい場合のみ
		if (first == after) {
			isYes = true;
		}
	}
	
	// 出力
	if (isYes == true)
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;
 
 int main() {
  int n,a;
  while(cin >> n) {
    a=n % 39;
	cout << "3C";
	if (a==0) a=39;
	if (a<10) cout << '0';
	cout << a << endl;
  }
  return 0;
 }

Measured memory_bytes: 1160
s = input()

YYMM=False
MMYY=False

if 1 <= int(s[:2]) <= 12:
  MMYY=True
if 1 <= int(s[2:]) <= 12:
  YYMM=True

if YYMM and MMYY:
  print("AMBIGUOUS")
elif YYMM:
  print("YYMM")
elif MMYY:
  print("MMYY")
else:
  print("NA")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>
#include <functional>
#include <array>
#include <cmath>
#include <set>

using namespace std;

int N, H;

int a[100000]{}, b[100000]{};

int main(){
	
	cin >> N >> H;
	for (int i = 0; i < N; ++i) {
		cin >> a[i] >> b[i];
	}

	sort(b, end(b), greater<decltype(b[0])>());
	int x = *max_element(a, end(a));

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		if (b[i] >= x) {
			H -= b[i];
			++ans;
			if (H <= 0) {
				break;
			}
		}
		else break;
	}

	if (H > 0) {
		ans += (H + x - 1) / x;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#define EPS 1e-10
#define INF (-(1<<21))
using namespace std;
typedef long long llong;
int main() {
	int n;
	while (1) {
		cin >> n;
		if (!n)break;
		vector<int>a(n);
		for (int i = 0; i < n; i++)cin >> a[i];
		int tmp;
		int m = INF;
		for (int i = 0; i < n; i++) {
			tmp = 0;
			for (int j = i; j < n; j++) {
				tmp += a[j];
				m = max(m, tmp);

			}
		}
		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<double>   vd;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define mii map<int,int>
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define log2(x) (31 - __builtin_clz(x))
#define lcm(x,y) (x*y) / __gcd(x,y)
int inf = (1e9) + 7;
int mod = 998244353;

int main(){
	

	int x,y;
	sf2(x,y);

	if(!(x%y)){
		printf("-1\n");
	}
	else
		printf("%d\n",x);

}


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

const double pi=3.1415926535897932384626434;
int n;
#define maxn 200011
struct Point
{
	int x,y;
	bool operator < (const Point &b) const {return x<b.x;}
}s,t,p[maxn];
int yy[maxn],ly=0;
int g[maxn];
int up()
{
	int ans=0;
	g[0]=-1;
	for (int i=1;i<=ly;i++)
	{
		int L=0,R=ans;
		while (L<R)
		{
			int mid=(L+R+1)>>1;
			if (g[mid]<yy[i]) L=mid;
			else R=mid-1;
		}
		g[L+1]=yy[i];
		if (L==ans) ans++;
	}
	return ans;
}
int down()
{
	for (int i=1;i<=ly/2;i++) {int t=yy[i];yy[i]=yy[ly-i+1];yy[ly-i+1]=t;}
//	for (int i=1;i<=ly;i++) cout<<yy[i]<<' ';cout<<endl;
	return up();
}
int abs(int x) {return x>0?x:-x;}
int main()
{
	scanf("%d%d%d%d",&s.x,&s.y,&t.x,&t.y);
	if (s.x>t.x) swap(s,t);
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y);
	sort(p+1,p+1+n);p[0].x=-1;p[n+1].x=1e9;
	int L=0,R=n+1;
	while (L<R)
	{
		int mid=(L+R)>>1;
		if (p[mid].x<s.x) L=mid+1;
		else R=mid;
	}
	int left=L;
	L=0,R=n+1;
	while (L<R)
	{
		int mid=(L+R+1)>>1;
		if (p[mid].x>t.x) R=mid-1;
		else L=mid;
	}
	int right=L;
	for (int i=left;i<=right;i++)
		if (p[i].y>=min(s.y,t.y) && p[i].y<=max(s.y,t.y)) yy[++ly]=p[i].y;
//	for (int i=1;i<=ly;i++) cout<<yy[i]<<' ';cout<<endl;
	if (s.y>t.y) L=down();
	else L=up();//cout<<L<<endl;
	double ans=(abs(t.y-s.y)+(t.x-s.x))*1ll*100-L*(20-5*pi);
	if (abs(t.y-s.y)+1==L || t.x-s.x+1==L) ans=ans+5*pi;
	printf("%.15lf\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    
    if (B < C) {
        if (A < C - B) cout << B * 2 + A + 1 << endl;
        else cout << B + C << endl;
    } else {
        cout << B + C << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn

object Main {

  def bubbleSort(A: Array[Int]){
    def swap(i: Int, j: Int) {
      val t = A(i); A(i) = A(j); A(j) = t
      ()
    }

    var count = 0
    for(i <- 0 to A.length - 1){
      for(j <- A.length - 1 to i + 1 by -1){
        if(A(j) < A(j-1)){
          swap(j,j-1)
          count += 1
        }
      }
    }

    println(A.mkString(" "))
    println(count)
  }

  def main(args: Array[String]){
    val N = StdIn.readInt()
    val input = StdIn.readLine().split(" ").map(_.toInt)
    bubbleSort(input)
  }
}

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

int main () {
	vector<long long> v;
	v.push_back(0);
	int N;
	cin >> N;
	for(int i = 0; i < N; i++)
	{
		long long a;
		cin >> a;
		v.push_back(a + v[i]);
	}
	vector<long long> ctr;
	long long c = 1, prev = -1e18;
	sort(v.begin(), v.end());
	
	for(auto &i: v)
	{
		if(i == prev) {
			c++;
		}else{
			ctr.push_back(c);
			c = 1;
		}
		prev = i;
	}
	ctr.push_back(c);
	long long ans = 0;
	for(auto &i: ctr) {
		ans += i * (i - 1) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4848
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
//----//
#define MX 10
int n, d;
 
 
int main(){
  int i, j, k, data, count;
  int X[MX][MX];
  scanf("%d%d", &n, &d);
  for(i=0;i<n;i++){
    for(j=0;j<d;j++){
		scanf("%d", &X[i][j]);
    }
  }
 //--//
  count = 0;
  data = 0;
  for(i=0;i<n;++i){
    for(j=i+1;j<n;++j){
      	data = 0;
		for(k=0;k<d;++k){
          data += pow(fabs(X[i][k] - X[j][k]), 2);
        }
    	for(k=0;k<=data;k++){
          if(pow(k,2) == data){
            count++;
 		  }
		}
	}
  }
    printf("%d",count);
	return 0;
}

Measured memory_bytes: 128
L = [int(input()) for i in range(len("abcde"))]
k = int(input())

for i in range(4):
    for j in range(i+1, 5):
        if abs(L[i] - L[j]) > k:
            print(":(")
            break
    else:
        continue
    break
else:
    print("Yay!")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	int k;
	cin >> n >> k;
	int a, b;
	set <int> s;
	for(int i=0; i<k; i++){
		cin >> a;
		for(int j=0; j<a; j++){
			cin >> b;
			s.insert(b);
		} 
	}
	cout << n-s.size();
    return 0;
}

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

#define pb push_back
#define fr first
#define sc second
#define ll long long

using namespace std;

const int N = 1e4 + 7;
const int mod = 1e9 + 7;

int dp[N][107][2];

int ad(int x)
{
	return ((x + mod) % mod);
}

main()
{
	string s;
	int m, n;
	
	cin >> s >> m;
	
	n = s.size();
	
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
		{
			for (int j = 0; j < int(s[0] - '0'); j++)
			{
				dp[i][j % m][1] += 1;
			}
			dp[0][int(s[0] - '0') % m][0] = 1;
			continue;
		}
		for (int j = 0; j < m; j++)
		{
			for (int k = 0; k < 10; k++)
			{
				dp[i][(j + k) % m][1] += dp[i - 1][j][1];
				dp[i][(j + k) % m][1] %= mod;
			}
			for (int k = 0; k < int(s[i] - '0'); k++)
			{
				dp[i][(j + k) % m][1] += dp[i - 1][j][0];
				dp[i][(j + k) % m][1] %= mod;
			}
			dp[i][((j + int(s[i] - '0')) % m)][0] += dp[i - 1][j][0];
			dp[i][((j + int(s[i] - '0')) % m)][0] %= mod;
		}
	}
	cout << ad((dp[n - 1][0][0] + dp[n - 1][0][1]) - 1) << endl;
}
/*
 * I will solve it in two way
	/					\
   /					 \
 Memory optimization    Time optimization
*/


Measured memory_bytes: 8576
/******************************************
* AUTHOR : AMAN SAXENA *
* Nick : blue-meth *
* "There's some good in this world, and it's worth fighting for." *
* INSTITUTION : KIET Group of Institutions *
******************************************/
#include <bits/stdc++.h>
 
const long long MODULO=1000000007;
const long long N = 1e5 + 7;
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FOR1(i,a,n) for(int i=a;i<=n;i++)
#define FOR2(i,a,n) for(int i=a;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pi 3.14159265359
 
using namespace std;
 
ll amanpower(ll a, ll b) {
    ll r = 1;
    while (b > 0) 
    {
        if (b & 1) r = r * a;
        a = a * a;
        b >>= 1;
    }
    return r;
}
 
ll amanlcm(ll a, ll b)
{
     return a*(b/__gcd(a,b));
}
//Prime Numbers
 
vector<bool>prime(N+1,true);
void sieve()
{
    ll i,j,k;
    prime[0]=prime[1]=false;
    for(i=2;i*i<=N;i++)
    {
        if(prime[i])
        {
            for(j=i*i;j<=N;j+=i)
            {
                prime[j]=false;
            }
        }
    }
}
 
//Exponentiation
 
ll power(ll a,ll b)
{
    ll r=1;
    while(b)
    {
        if(b%2==1)
            r=r*a;
        b/=2;
        a*=a;
    }
    return r;
}
ll power(ll a,ll b,ll m)
{
    a=a%m;
    ll r=1;
    while(b)
    {
        if(b%2==1)
            r=(r*a)%m;
        b/=2;
        a=(a*a)%m;
    }
    return r;
}
 
//Prime Factors
 
vector<ll> factors(ll n)
{
    vector<ll>r;
    ll i,j;
    for(i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            r.push_back(i);
            if(n/i!=i)
                r.push_back(n/i);
        }
    }
    return r;
}
 
 
//********* CODE START *********
 
 int minimumChar(string S1, string S2) 
{ 
    int n = S1.size(), m = S2.size(); 
  
    int ans = INT_MAX; 
  
    for (int i = 0; i < m - n + 1; i++) { 
        int minRemovedChar = 0; 
        for (int j = 0; j < n; j++) { 
            if (S1[j] != S2[i + j]) { 
                minRemovedChar++; 
            } 
        } 
        ans = min(minRemovedChar, ans); 
    } 
    return ans; 
} 
 
void solve()
{
    string a, b;
    cin >>  a >> b;
    cout << minimumChar(b, a) ;
}
 
void test()
{
    int t;
    cin>>t;
    while(t--) //for(int j=1;j<=t;j++) cout << "Case #" << j << ": ";
    {
        solve();
    }
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif
    
    // test();
    solve();
 
    
    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define ll long long
#define db double
#define iosks std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int N=2e5+10,M=3e4+10;
const ll inf=INT_MAX,mod=1e9+7;
const db pi=atan(1)*4;
ll pow2(ll a,ll b) {ll s=1; while(b) {if(b&1) s=(s*a)%mod; a=(a*a)%mod; b/=2; } return s;}
ll lcm(ll a,ll b) {return a/__gcd(a,b)*b; }
int read()
{
    int s=0,f=1; char ch=getchar();
    while(ch<'0'&&ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {s=s*10+ch-'0'; ch=getchar();} return s*f;
}

ll a[5005][2],p[5005],c[5005],n,k,ans=-1e17,m,as,t,mm,x;

int main()
{
    iosks;
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>p[i];
    for(int i=1;i<=n;i++) cin>>c[i];
    for(int i=1;i<=n;i++){
        as=0,t=p[i];
        memset(a,0,sizeof(a));
        for(int j=1;j<=k;j++){
            if(a[t][1]){
                x=j-a[t][1];
                as=as*(k/x-1);mm=k%x+x;ans=max(ans,as);
                for(int j=1;j<=mm;j++) as+=c[t],t=p[t],ans=max(ans,as);
                memset(a,0,sizeof(a));
                break;
            }
            as+=c[t];ans=max(ans,as);
            a[t][0]=as;a[t][1]=j;
            t=p[t];

        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3708
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(){
    int i, j;
    char str[8][8];
    for(i = 0;i < 8;i++){
        for(j = 0;j < 8;j++){
            scanf("%c",&str[i][j]);
            if(str[i][j] == '\n'){
                j--;
            }
        }
    }
    printf("90\n");
    for(i = 0;i < 8;i++){
        for(j = 7;j >= 0;j--){
            printf("%c",str[j][i]);
        }
        printf("\n");
    }
    printf("180\n");
    for(j = 7;j >= 0;j--){
        for(i = 7;i >= 0;i--){
            printf("%c",str[j][i]);
        }
        printf("\n");
    }
    printf("270\n");
    for(i = 7;i >= 0;i--){
        for(j = 0;j < 8;j++){
            printf("%c",str[j][i]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 520
a, b, c, d = map(int, input().split())

oc = c
od = d

for i in range(d):
    c, d = d, c%d
    if d == 0:
        gcd = c
        break
    else:
        pass
c = oc
d = od

lcm = c * d // gcd


b_c = b // c
b_d = b // d
b_l = b // lcm

a_c = (a-1) // c
a_d = (a-1) // d
a_l = (a-1) // lcm

sum = (b_c + b_d - b_l) - (a_c + a_d - a_l)
print(b - a + 1 - sum)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int m, k;
    cin >> m >> k;
    if(m == 0){
        if(k == 0){
            cout << 0 << " " << 0 << "\n";
        }
        else{
            cout << -1 << "\n";
        }
        return 0;
    }
    if(m == 1){
        if(k == 0){
            cout << 0 << " " << 0 << " " << 1 << " " << 1 << "\n";
        }
        else{
            cout << -1 << "\n";
        }
        return 0;
    }

    int sz = 1 << (m + 1);
    int hoge = 1 << m;
    if(k > hoge - 1){
        cout << -1 << "\n";
        return 0;
    }
    deque<int> res;
    res.push_front(k);
    for(int i = 0; i < hoge; ++i){
        if(i == k)  continue;
        res.push_front(i);
        res.push_back(i);
    }
    res.push_back(k);

    vector<int> sum(sz+1, 0);
    int pos = 0;
    while(!res.empty()){
        sum[pos + 1] = sum[pos] ^ res.front();
        ++pos;
        cout << res.front();
        res.pop_front();
        if(!res.empty())    cout << " ";
        else    cout << "\n";
    }

    // for(int i = 0; i < hoge; ++i){
    //     cerr << (sum[hoge+i] ^ sum[hoge-i-1]) << " ";
    // }
    // cerr << "\n";
}

Measured memory_bytes: 3968
import java.util.*;

import java.lang.*;

import java.io.*;



class Main {

    private static long inversions = 0;



    public static void main(String[] args) throws java.lang.Exception {

        

        Scanner s = new Scanner(System.in);

        int arraySize = s.nextInt();

        int[] A = new int[arraySize];

        for (int i = 0; i < arraySize; i++) {

            A[i] = s.nextInt();

        }



        mergeSort(A, 0, A.length);

        System.out.println(inversions);

    }



    public static void mergeSort(int[] A, int left, int right) {

        if (left + 1 >= right) {

            return;

        }

        int mid = (right + left) / 2;

        mergeSort(A, left, mid);

        mergeSort(A, mid, right);

        merge(A, left, mid, right);

    }



    public static void merge(int[] A, int left, int mid, int right) {



        int n1 = mid - left;

        int n2 = right - mid;



        int[] L = new int[n1];

        int[] R = new int[n2];



        for (int i = 0; i < n1; i++) {

            L[i] = A[left + i];

        }

        for (int i = 0; i < n2; i++) {

            R[i] = A[mid + i];

        }



        int i = 0;

        int j = 0;



        for (int k = left; k < right; k++) {

            if (j >= n2) {

                A[k] = L[i];

                i = i + 1;

                continue;

            }

            if (i >= n1) {

                A[k] = R[j];

                inversions += L.length - i;

                j = j + 1;

                continue;

            }

            if (L[i] <= R[j]) {

                A[k] = L[i];

                i = i + 1;

            } else {

                A[k] = R[j];

                inversions += L.length - i;

                j = j + 1;

            }

        }

    }

}


Measured memory_bytes: 101464
#include <iostream>
#include <stdio.h>
const double M_PI = 3.14159265359;
using namespace std;

int main()
{
	double r;
	double S,L;
	cin>>r;
	S = r*r*M_PI;
	L = 2.0*M_PI*r;
	printf("%12lf %12lf\n", S,L);
	return 0;
}

Measured memory_bytes: 3196
// ITP1_5_B
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

void write(int h,int w){
    for(int i=0;i<h;i++){
        if(i==0 or i==h-1){
            for(int j=0;j<w;j++){
                cout<<"#";
            }
            cout<<endl;
        }else{
            cout<<"#";
            for(int j=0;j<w-2;j++){
                cout<<".";
            }
            cout<<"#"<<endl;
        }
    }
    cout<<endl;
    return;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int h,w;
    cin>>h>>w;
    while(h!=0 or w!=0){
        write(h,w);
        cin>>h>>w;
    }
    return 0;
}


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

int MAX_N=262144;
vector<int64_t> seg(MAX_N*2-1);
int64_t qu(int a,int b,int k,int l, int r){
  if(r<=a||b<=l){
    return 0;
  }
  else if(a<=l&&r<=b){
    return seg[k];
  }
  else{
    int64_t X=qu(a,b,k*2+1,l,(l+r)/2);
    int64_t Y=qu(a,b,k*2+2,(l+r)/2,r);
    return X+Y;
  }
}
void pu(int64_t a,int b){
  int D=MAX_N-1+b;
  while(D>0){
    seg[D]+=a;
    D--;
    D/=2;
  }
  seg[0]+=a;
}

int main() {
  int N;
  cin>>N;
  int64_t Q=998244353;
  vector<int64_t> ni(N,1);
  for(int i=1;i<N;i++){
    ni[i]=(ni[i-1]*2)%Q;
  }
  priority_queue<pair<int,int>> pqx;
  priority_queue<pair<int,int>> pqy;
  for(int i=0;i<N;i++){
    int x,y;
    cin>>x>>y;
    pqx.push(make_pair(x,i));
    pqy.push(make_pair(y,i));
  }
  vector<int> p(N);
  vector<int> q(N);
  for(int i=N-1;i>=0;i--){
    int a=pqx.top().second;
    int b=pqy.top().second;
    pqx.pop();
    pqy.pop();
    p[a]=i;
    q[b]=i;
  }
  vector<int> r(N);
  for(int i=0;i<N;i++){
    r[p[i]]=q[i];
  }
  
  int64_t Z=(ni[N-1]*N*2)%Q;
  for(int i=0;i<N;i++){
    pu(1,r[i]);
    int B=qu(0,r[i],0,0,MAX_N);
    int A=i-B;
    int C=r[i]-B;
    int D=N-1-A-B-C;
    Z-=(((ni[A]+ni[C]-1)%Q)*((ni[B]+ni[D]-1)%Q))%Q;
    Z+=Q;
    Z%=Q;
  }
  cout<<Z<<endl;

  
}

Measured memory_bytes: 14384
import Data.Array.IO

main :: IO ()
main = do
  [n, x] <- (map read . words) <$> getLine :: IO [Int]
  as <- (map read . words) <$> getLine :: IO [Int]
  asArr <- newListArray (0, n - 1) as :: IO (IOArray Int Int)
  print =<< solve asArr 1 n x 0

solve :: IOArray Int Int -> Int -> Int -> Int -> Int -> IO Int
solve asArr ptr n x cnt
  | ptr == n = return cnt
  | otherwise = do
      a0 <- readArray asArr (ptr - 1)
      a1 <- readArray asArr ptr
      cnt' <-
        if a0 + a1 <= x
          then return cnt
          else do
            let toEat = (a0 + a1 - x)
            if a1 >= toEat
              then writeArray asArr ptr (a1 - toEat)
              else do
                writeArray asArr ptr 0
                writeArray asArr (ptr - 1) (a0 - (toEat - a1))
                
            return (cnt + toEat)

      solve asArr (ptr + 1) n x cnt'


Measured memory_bytes: 61820
import java.util.Scanner;
 
public class Main {
 
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
 
		int N = sc.nextInt();
		String answer;
 
		int n = N;
 
		int sum = 0;
        while (n != 0) {
            sum += n % 10;
            n /= 10;
        }
 
        if((N%sum)==0) answer = "Yes";
        else answer = "No";
 
		sc.close();
 
	    System.out.println(answer);
    }
}

Measured memory_bytes: 21972
from collections import deque
S = list(input())
Q = int(input())

S = deque(S)

rev = False
for i in range(Q):
  query = list(input())
  if query[0] == '1':
    rev = not rev
  else:
    c = query[4]
    if query[2] == '1' and not rev or (rev and query[2] == '2'):
      S.appendleft(c)
    else:
      S.append(c)
      
if rev:
  S.reverse()


print(''.join(S))

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

#define fastIO ios_base::sync_with_stdio(false)
#define forI0N(i, a, b) for(int i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

    vector<int> h(N);
    forI0N(i, 0, N) cin >> h[i];

    vector<ull> jump1(N), jump2(N);
    jump1[1] = abs(h[1]-  h[0]);
    jump2[1] = ULLONG_MAX;

    forI0N(i, 2, N) {
        jump1[i] = min(jump1[i - 1], jump2[i - 1]) + abs(h[i] - h[i - 1]);
        jump2[i] = min(jump1[i - 2], jump2[i - 2]) + abs(h[i] - h[i - 2]);
    }

    cout << min(jump1[N - 1], jump2[N - 1]);
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int N;
int X[55], Y[55];

long double dist(long double x, long double y, int i) {
    return sqrtl((X[i] - x) * (X[i] - x) + (Y[i] - y) * (Y[i] - y));
}

long double calc_y(long double x, long double y) {
    long double res = -LLINF;
    REP(i, N) {
        chmax(res, dist(x, y, i));
    }
    return res;
}

long double calc_x(long double x) {
    long double low = 0, high = 1001;
    REP(i, 200) {
        const auto mid1 = (low + low + high) / 3;
        const auto mid2 = (low + high + high) / 3;

        if (calc_y(x, mid1) <= calc_y(x, mid2)) {
            high = mid2;
        } else {
            low = mid1;
        }
    }

    return calc_y(x, low);
}

int main(void) {
    cin >> N;
    REP(i, N) {
        cin >> X[i] >> Y[i];
    }

    long double low = 0, high = 1001;
    REP(i, 200) {
        const auto mid1 = (high + low + low) / 3;
        const auto mid2 = (high + high + low) / 3;
        // cerr << mid1 << " " << mid2 << endl;
        // cerr << calc_x(mid1) << " " << calc_x(mid2) << endl;
        if (calc_x(mid1) <= calc_x(mid2)) {
            high = mid2;
        } else {
            low = mid1;
        }
    }

    cout << fixed << setprecision(20) << calc_x(low) << endl;
}


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

signed main() {
  int n;
  while ( cin >> n, n ) {
    int pre = 0;
    int asi = 0;
    int cnt = 0;
    for ( int i = 0; i < n; i++ ) {
      string f;
      cin >> f;
      if ( f == "lu" ) asi |= 1;
      if ( f == "ru" ) asi |= 2;
      if ( f == "ld" ) asi ^= 1;
      if ( f == "rd" ) asi ^= 2;
      if ( !pre && asi == 3 ) {
	cnt++;
	pre = 1;
      } else if ( pre && asi == 0 ) {
	cnt++;
	pre = 0;
      }
    }

    cout << cnt << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3112
//
//  main.cpp
//  AOJ-2000
//
//  Created by Kenta Kodera on 2017/06/18.
//  Copyright ?? 2017??´ Kenta Kodera. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
#include <ctype.h> // isdigit
#include <cassert>
using namespace std;



int main(){
  map<string, pair<int, int>> dxy;
  dxy["N"] = {0, 1};
  dxy["E"] = {1, 0};
  dxy["S"] = {0, -1};
  dxy["W"] = {-1, 0};
  
  int N;
  while(cin >> N, N){
    vector<pair<int, int>> jewely;
    for(int i=0; i<N; i++){
      int x, y; cin >> x >> y;
      jewely.push_back({x,y});
    }
    
    int M; cin >> M;
    int nx = 10, ny = 10;
    for(int i=0; i<M; i++){
      string D; cin >> D;
      int L; cin >> L;
      for(int j=0; j<L; j++){
        nx += dxy[D].first;
        ny += dxy[D].second;
        pair<int, int> np = {nx, ny};
        auto itr = find(jewely.begin(), jewely.end(), np);
        if(itr != jewely.end()){
          jewely.erase(itr);
        }
      }
    }
    if(jewely.empty()){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(void){
    ll n, a, b;
    cin >> n >> a >> b;
    if(a == 0) cout << 0 << endl;
    else cout << (n/(a+b))*a + min(a, n - (n/(a+b))*(a+b)) << endl;
    return 0;
}


Measured memory_bytes: 3616
from math import factorial
n,k = map(int,input().split())
for i in range(k):
  if i <= n-k:
    blue = factorial(k-1)//(factorial(k-i-1)*factorial(i))
    red = factorial(n-k+1)//(factorial(n-k-i)*factorial(i+1))
    print((blue*red)%1000000007)
  else:
    print(0)

Measured memory_bytes: 3316
#include <stdio.h>

int main()
{
  int N,i,j,v,x;


  scanf("%d\n",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

   for(i=0;i<N;i++){
     if(i)printf(" ");
    printf("%d",A[i]);
  }
   printf("\n");
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(x=0;x<N;x++){
      if(x)printf(" ");
      printf("%d",A[x]);
    }
    printf("\n");
  }

  
  return 0;
}





Measured memory_bytes: 2084
n=int(input())
A=[int(input()) for i in range(n)]
minv = A[0]
maxv = A[1]-A[0]
for j in range(1,n):
	if(maxv < A[j] - minv):
		maxv = A[j] - minv
	if(A[j] < minv):
		minv = A[j]
print(maxv)


Measured memory_bytes: 13592