akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
//#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }



int main() {
	
	int n;
	cin >> n;
	n = n % 10;

	if (n==3) {
		cout << "bon" << endl;
	}
	else if(n == 0 || n == 1 || n == 6 || n == 8 ){
		cout << "pon" << endl;
	}
	else {
		cout << "hon" << endl;

	}

}




Measured memory_bytes: 3676
#include<stdio.h>
int main()
{
	char s[4];
	while(scanf("%s",s)!=EOF)
	{
		int c=0;
		if(s[0]!='0') c++;
		if(s[1]!='0') c++;
		if(s[2]!='0') c++;
		printf("%d\n",c);
	}
}

Measured memory_bytes: 128
#include<cstdio>
namespace QiFeng233{
	const int maxn=110;
	int a[maxn],n;
	void solve(){
		scanf("%d",&n);
		for(int i=1;i<=n;++i)scanf("%d",a+i);
		for(int i=1;i<=n;++i){
			if(a[i]%2==1)continue;
			if(a[i]%3!=0&&a[i]%5!=0){
				printf("DENIED\n");
				return;
			}
		}
		printf("APPROVED\n");
	}
}
signed main(){
	QiFeng233::solve();
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
using namespace std;

long long int N, M;
string S;

int main(){
	int A, B, C, D;

    cin >> A >> B >> C >> D;

    while(true){
        C = C - B;
        if(C <= 0){
            cout << "Yes";
            break;
        }
        A = A - D;
        if(A <= 0){
            cout << "No";
            break;
        }
    }


}   

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 123;
int n, c[N], par[N], sz[N], ex[N];
vector <int> g[N], col[N];

ll f(ll x) {
	return x * (x + 1) / 2;
}
ll res, ans[N];

void make_set(int x) {
	par[x] = x;
	sz[x] = 1;
}

int find_set(int x) {
	if (x == par[x]) return x;
	return find_set(par[x]);
}

stack <array <ll, 5>> st;
int last;

void union_set(int x, int y) {
	x = find_set(x), y = find_set(y);
	if (x != y) {
		ll d = f(sz[x] + sz[y]) - f(sz[x]) - f(sz[y]);
		res += d;
		st.push({x, sz[x], y, sz[y], d});
		last++;
		if (sz[x] < sz[y]) swap(x, y);
		par[y] = x;
		sz[x] += sz[y];
	}
}

void add(int l, int r) {
	for (int i = l; i <= r; i++) {
		for (int j : col[i]) {
			ex[j] = 1, res += f(1);
			for (int k : g[j])
				if (ex[k]) union_set(k, j);
		}
	}
}

array <ll, 5> cur;

void undo(int x) {
	while (last > x) {
		cur = st.top(), st.pop();
		sz[cur[0]] = cur[1];
		par[cur[0]] = cur[0];
		sz[cur[2]] = cur[3];
		par[cur[2]] = cur[2];
		res -= cur[4];
		last--;
	}
}

void del(int l, int r) {
	for (int i = l; i <= r; i++)
		for (int j : col[i])
			ex[j] = 0, res -= f(1);
}

void solve(int l, int r) {
	if (l == r) {
		ans[l] = res;
		return;
	}
	int was = last;
	int m = l + r >> 1;
	add(m + 1, r);
	solve(l, m);
	undo(was);
	del(m + 1, r);
	add(l, m);
	solve(m + 1, r);
	undo(was);
	del(l, m);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> c[i];
		col[c[i]].pb(i);
		make_set(i);
	}
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		g[x].pb(y), g[y].pb(x);
	}
	solve(1, n);
	for (int i = 1; i <= n; i++)
		cout << (ll)n * (n + 1) / 2 - ans[i] << '\n';
}


Measured memory_bytes: 36232
#include <iostream>
#include <math.h>
using namespace std;

bool isPrime(int x) {
  if (x < 2) return false;
  if (x == 2) return true;
  if (x % 2 == 0) return false;
  double s = sqrt(x);
  for (int i = 3; i <= s; i+=2) {
    if (x % i == 0) return false;
  }
  return true;
}

int main() {
  int n, e;
  int count = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> e;
    if (isPrime(e)) count++;
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
char s[105][105];
int a[105][105]={0};
int main()
{
    int h,w;
    cin >> h >> w;
    for(int i=1;i<=h;i++){
        cin >> s[i]+1;
    }
    for(int i=0;i<=h;i++)
        for(int j=0;j<=w;j++)
            a[i][j]=100005;
    if(s[1][1]=='#')
        a[1][1]=1;
    else
        a[1][1]=0;
    //a[0][0]=0;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(i==j&&i==1){
                continue;
            }
            if(s[i][j]=='.')
                a[i][j]=min(a[i-1][j],a[i][j-1]);
            else{
                if(s[i][j]!=s[i-1][j]){
                    a[i][j]=min(a[i-1][j]+1,a[i][j]);
                }
                else
                    a[i][j]=min(a[i-1][j],a[i][j]);
                if(s[i][j]!=s[i][j-1])
                    a[i][j]=min(a[i][j-1]+1,a[i][j]);
                else
                    a[i][j]=min(a[i][j-1],a[i][j]);
            }
        }
    }
//    for(int i=1;i<=h;i++)
//        for(int j=1;j<=w;j++)
//            cout << a[i][j] << " \n"[j==w];
    cout << a[h][w] <<endl;
    return 0;
}


Measured memory_bytes: 3660
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

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

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            int K = in.nextInt();
            int F[] = CPUtils.readIntArray(N, in);
            Arrays.sort(F);
            int sum = 0;
            for (int i = 0; i < K; i++)
            {
                sum += F[i];
            }
            out.println(sum);
        }

    }

    static class CPUtils
    {
        public static int[] readIntArray(int size, Scanner in)
        {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
            {
                array[i] = in.nextInt();
            }
            return array;
        }

    }
}



Measured memory_bytes: 30132
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		string str;
		cin >> str;
		vector<int> point(n);
		int field = 0;
		int pos = 0;
		for(int i = 0; i < str.size(); ++i)
		{
			if(str[i] == 'S')
			{
				field += point[pos] + 1;
				point[pos] = 0;
			}
			else if(str[i] == 'L')
			{
				point[pos] += field + 1;
				field = 0;
			}
			else if(str[i] == 'M')
			{
				++point[pos];
			}
			pos = (pos + 1) % n;
		}
		sort(point.begin(), point.end());
		for(int i = 0; i < n; ++i)
		{
			cout << point[i] << " ";
		}
		cout << field << endl;
	}
}

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

Measured memory_bytes: 1228
H,W = map(int,input().split())
if H == 1 or W == 1:
    print(1)
else:
    if H % 2 == 0:
        print(H//2 * W)
    else:
        if W % 2 == 0:
            print(H * W//2)
        else:
            print(W * (H//2) + W//2 + 1)

Measured memory_bytes: 38384
def BFS(G):
    ans = [0] + [[i+1,-1] for i in range(len(G))]
    def main(G,i,d):
        if -1 < ans[i][1] <= d: return
        ans[i] = [i, d]
        for j in G[i-1][2:]: main(G,j,d+1)
    main(G,1,0)
    return ans[1:]


if __name__=='__main__':
    n = int(input())
    G = [list(map(int,input().split())) for _ in range(n)]
    for out in BFS(G): print(*out)

Measured memory_bytes: 7748
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int maxDiff = 13000;
const int origin = maxDiff / 2;
bool dp[80][80][maxDiff];

int main() {
    // dp、最大で80^3まで見れば良い
    int H, W;
    cin >> H >> W;
    vector<vector<int>> A(H, vector<int> (W));
    rep(i, H) rep(j, W) cin >> A[i][j];
    vector<vector<int>> B(H, vector<int> (W));
    rep(i, H) rep(j, W) cin >> B[i][j];
    rep(i, H) rep(j, W) A[i][j] = abs(A[i][j] - B[i][j]);
    dp[0][0][origin+A[0][0]] = 1;
    dp[0][0][origin-A[0][0]] = 1;
    rep(i, H) rep(j, W) {
        int cur = A[i][j];
        if (i >= 1) {
            // 上から
            for (int k = 0; k < maxDiff; k++) {
                if (dp[i-1][j][k] && k + cur < maxDiff) {
                    dp[i][j][k+cur] = 1;
                }
                if (dp[i-1][j][k] && k - cur >= 0) {
                    dp[i][j][k-cur] = 1;
                }                
            }
        }
        if (j >= 1) {
            for (int k = 0; k < maxDiff; k++) {
                if (dp[i][j-1][k] && k + cur < maxDiff) {
                    dp[i][j][k+cur] = 1;
                }
                if (dp[i][j-1][k] && k - cur >= 0) {
                    dp[i][j][k-cur] = 1;
                }                
            }
        }
    }
    int ans = maxDiff;
    for (int i = 0; i < maxDiff; i++) {
        if (dp[H-1][W-1][i]) {
            ans = min(ans, abs(origin-i));
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 80468
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n = int(readline())
s = readline().decode("utf-8")

cnt = 0
for i in range(n-2):
    if s[i:i+3] == "ABC":
        cnt += 1
print(cnt)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}


void solve(long long K, long long X){
    for(int i = X-K+1;i <= X+K-1;i++){
        if(i == X-K+1) {
            cout << i;
        }else{
        cout << " " << i;

        }
    }
    cout << endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    long long X;
    scanf("%lld",&X);
    solve(K, X);
    return 0;
}


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

int main(){
    string s;
    int nc[26]={};

    while(getline(cin, s)){
        for(int i=0; i<(int)s.length(); i++){
            if('a' <= s[i] && s[i] <= 'z') nc[s[i]-'a']++;
            if('A' <= s[i] && s[i] <= 'Z') nc[s[i]-'A']++;
        }
    }
    for(int i=0; i<26; i++){
        cout << (char)('a'+i) << " : " << nc[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3188
from sys import stdin


def main():
    s = dict()

    for i in range(3):
        s[ord('A') + i] = next_str()

    turn = ord('A')

    while s[turn] != "":
        pre = turn
        turn = ord(s[turn][0].upper())

        s[pre] = s[pre][1:]

    print(chr(turn))

def next_str():
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    cin >> n;
    vector<int> t(n),x(n),y(n);
    rep(i,n){
        cin >> t[i] >> x[i] >> y[i];
    }
    int nowx = 0, nowy = 0;
    int dist = 0;
    int nowt = 0;
    rep(i,n){
        dist = abs(x[i] + y[i] - (nowx + nowy));
        if(dist > t[i]-nowt){
            cout << "No" << endl;
            return 0;
        }
        if(dist%2 == (t[i]-nowt)%2){
            nowt = t[i];
            nowx = x[i];
            nowy = y[i];
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 4624
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
int main(){
    int n;
    cin >> n;
    int ans=10000;
    rep(i,11){
        if(i*1000>=n){
            ans=min(ans,1000*i-n);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

namespace alfabetto
{
    class Program
    {
        static void Main(string[] args)
        {
            var moji = Console.ReadLine();
            char charmoji = moji[0];
            int mojicode = (int)charmoji;
            int nextmojicode = mojicode + 1;
            char nextmoji = (char)nextmojicode;
            Console.WriteLine(nextmoji);
        }
    }
}


Measured memory_bytes: 11092
# -*- coding: utf-8 -*-
"""
Created on Sun Oct  7 22:06:12 2018
ABC073D
@author: maezawa
"""
import itertools as itr
import sys
input = sys.stdin.readline

def wf(graph):
    """ Warshall-Floyd Algorithm """
    for k in range(len(adjmatrix)):
        for i in range(len(adjmatrix)):
            for j in range(len(adjmatrix[i])):
                if adjmatrix[i][j] > adjmatrix[i][k] + adjmatrix[k][j]:
                    adjmatrix[i][j] = adjmatrix[i][k] + adjmatrix[k][j]
                    adjmatrix[j][i] = adjmatrix[i][k] + adjmatrix[k][j]				
    #return graph

n, m, r = list(map(int, input().split()))
rarray = list(map(int, input().split()))
adjmatrix = [[float("inf")]*n for _ in range(n)]
#for i in range(n):
#    adjmatrix[i][i] = 0

for i in range(m):
    a, b, c = list(map(int, input().split()))
    adjmatrix[a-1][b-1] = c
    adjmatrix[b-1][a-1] = c

#print(abc)

#costmatrix = wf(adjmatrix)
wf(adjmatrix)
        
#print(*adjmatrix, sep='\n')
    
# search for ri to rj
mincnt = float("inf")
for route in itr.permutations(rarray):
    cnt = 0
    for i in range(len(route)-1):
        cnt += adjmatrix[route[i]-1][route[i+1]-1]
    if cnt < mincnt:
        mincnt = cnt

print(mincnt)
        
        

Measured memory_bytes: 4724
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	int n, c; cin >> n >> c;
	int l[10],d[10];
	rep(i, 0, n) {
		cin >> l[i];
		d[i] = i;
	}
	sort(l, l + n);
	double dp[310][32],ans=0;
	//dp[x][mask]={座標xまで覆っていて集合maskの弧を使っている場合の数
	do
	{
		rep(i, 0, n * c + 1)rep(j, 0, 1 << n)dp[i][j] = 0;
		dp[l[n - 1]*n][0] = 1;
		rep(i, 0, n * c + 1)if (i % n) {
			int now = d[(i - 1) % n];
			rep(mask, 0, 1 << (n - 1))if(!((mask>>now)&1)){
				rep(j, i, n* c + 1) {
					dp[min(n * c, max(j, l[now] * n + i))][mask | (1 << now)] += dp[j][mask];
				}
			}
		}
		ans += dp[n*c][(1 << (n - 1)) - 1];
	} while (next_permutation(d,d+(n-1)));
	rep(i, 1, n) ans /= i;
	printf("%.15f", ans/pow(c,n-1));
	return 0;
}


Measured memory_bytes: 384
import sys
input = sys.stdin.readline

n = int(input())
li = [0]*n
for i in range(n):
    li[i] = int(input())
a = 0
b = 0

for i in li:
    if i > a:
        b = a
        a = i
    elif i > b:
        b = i

for i in li:
    if i == a:
        print(b)
    else:
        print(a)


Measured memory_bytes: 12508
#!/usr/bin/env ruby
require 'set'

n = gets.chomp.to_i

dict = Set.new
n.times do
  action, str = gets.chomp.split
  str = str.tr('ACTG', '1234').to_i
  case action
  when 'insert'
    dict << str
  when 'find'
    puts dict.include?(str) ? 'yes' : 'no'
  end
end

Measured memory_bytes: 26476
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e16
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */

ll n,k;
vector<ll> xp,xm;

/* add your algorithm here */

int main() {
  cin >> n >> k;
  rep(i,n) {
    ll a;
    cin >> a;
    if (a >= 0) {
      xp.pb(a);
    } else {
      xm.pb(a);
    }
  }

  ll ans = INF + 1;
  sort(xm.begin(), xm.end(), greater<ll>());

  for (int i = 0; i <= k; ++i) {
    ll tmpp = 0;
    ll tmpm = 0;
    ll ta = 0;
    ll tp = k - i;
    ll tm = i;
    ll c = 0;

    if (tp != 0 && xp.size() >= tp) {
      tmpp += xp[tp-1];
      c += tp;
    }

    if (tm != 0 && xm.size() >= tm) {
      tmpm += xm[tm-1];
      c += tm;
    }

    tmpm = abs(tmpm);
    if (tmpm < tmpp) {
      ta = tmpm * 2 + tmpp;
    } else {
      ta = tmpp * 2 + tmpm;
    }

    if (c == k && ta < ans) ans = ta;
  }

  cout << ans << endl;
}


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

int main() {
	int N,M;
	cin>>N>>M;
	int r[N+1];
	int num[N+1];
	fill_n(r, N+1, 0);
	fill_n(num, N+1, 1);
	r[1]=1;
	
	num[1]=1;
	for(int i=0;i<M;i++)
	{
		int a,b;
		cin>>a>>b;
		if(r[a]==1 && num[a]==1){
			num[b]++;
			r[b]=1;
			r[a]=0;
			num[a]--;
		}
		else if(r[a]==1 && num[a]>1)
		{
			num[b]++;
			r[b]=1;
			num[a]--;
		}
		else if(r[a]!=1){
			num[b]++;
			num[a]--;
		}
	}
	int ans=0;
	for(int i=1;i<N+1;i++)
	{
		if(r[i]==1)ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
    public static void main(String arg[]){
        Scanner sc=new Scanner(System.in);
        int i;
        int n=sc.nextInt();
        int[] data=new int[n];
        for(i=0;i<n;i++)data[i]=sc.nextInt();
        for(i=n-1;i>=0;i--){
            System.out.printf("%d",data[i]);
            if(i!=0)System.out.printf(" ");
        }
        System.out.println();
    }
}


Measured memory_bytes: 26512
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;
using ll = long long;
class BIT {
public:
    ll n; //データの長さ
    vector<ll> bit; //データの格納先
    BIT(ll n):n(n),bit(n+1,0){} //コンストラクタ

    //k & -kはLSB

    //bit_iにxをO(log(n))で加算する
    void add(ll i,ll x){
        if(i==0) return;
        for(ll k=i;k<=n;k+=(k & -k)){
            // cout<<k<<endl;
            bit[k]+=x;
        }
    }

    //bit_1 + bit_2 + …  + bit_n をO(log(n))で求める
    ll sum(ll i){
        ll s=0;
        if(i==0) return s;
        for(ll k=i;k>0;k-=(k & -k)){
            s+=bit[k];
        }
        return s;
    }
};
int main(){
    int N,Q;cin>>N>>Q;
    vector<int> c;
    c.push_back(0);
    for(int i = 0;i < N;i++){
        int _a;cin>>_a;
        c.push_back(_a);
    }
    vector<tuple<int,int,int,int>> queries;
    for(int i = 0;i < Q;i++){
        int _a,_b;cin>>_a>>_b;
        queries.push_back(make_tuple(i, _a, _b, 0));
    }
    auto fn = [](const tuple<int,int,int,int>& l, const tuple<int,int,int,int>& r){
        return get<2>(l) < get<2>(r);
    };
    sort(queries.begin(), queries.end(), fn);
    vector<int> lastapp(N+1,0);
    BIT bit(N);
    int lastr = 0;
    for(int q = 0;q < Q;q++){
        tuple<int,int,int,int> query = queries[q];
        int l = get<1>(query);
        int r = get<2>(query);
        // cout<<l<<r<<endl;
        // bit.add(10,1);
        if(lastr < r){
            for(int i = lastr + 1;i <= r;i++){
                // cout<<i<<endl;
                // cout<<i<<endl;
                if(lastapp[c[i]] != 0){
                    bit.add(lastapp[c[i]], -1);
                }
                // cout<<i<<endl;
                lastapp[c[i]] = i;
                // cout<<lastapp[c[i]]<<endl;
                bit.add(lastapp[c[i]], 1);
                // cout<<i<<endl;
            }
        }
        // cout<<"A"<<endl;
        lastr = r;
        if(l != 1){
            get<3>(queries[q]) = bit.sum(r) - bit.sum(l-1);
        }
        else
            get<3>(queries[q]) = bit.sum(r);

    }
    // cout<<"!"<<endl;
    auto fn2 = [](const tuple<int,int,int,int>& l, const tuple<int,int,int,int>& r){
        return get<0>(l) < get<0>(r);
    };
    sort(queries.begin(), queries.end(), fn2);
    for(int q = 0;q < Q;q++){
        cout<<get<3>(queries[q])<<endl;
    }
}

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

int isPrime(int x){
    int i;
    if(x==1)return 0;
    else if(x==2)return 1;
    if(x%2==0)return 0;
    for(i=3;(i*i)<=x;i+=2){
        if(x%i==0)return 0;
    }
    return 1;
}

int main(void){
    int n,m,cnt=0;
    int i;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&m);
        if(isPrime(m)==1){
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 2056
M = 10001; p = [1]*M;
p[0],p[1] = 0,0
for i in xrange(2,101):
    if p[i]:
        for j in xrange(i*i,M,i):
            p[j] = 0
while 1:
    try:
        n = int(raw_input()); ans = 0;
        for i in xrange(1,n+1):
            if p[i] and p[n+1-i]:
                ans += 1
        print ans
    except EOFError:
        break

Measured memory_bytes: 4284
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
#define INF 2147483647
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;



int main(){
	 
	 int n,k,a[111111];
	 cin>>n>>k;
	 for(int i=0;i<n;i++)cin>>a[i];
	 sort(a,a+n);
	 int min=INF;
	 for(int i=k-1;i<n;i++){
	 	min=std::min(min,a[i]-a[i-k+1]);
	 }
	 cout<<min<<endl;


}

Measured memory_bytes: 768
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 9000000000000000000 //9e18:極めて大きい値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define LOGMAXR 18 // floor(log2(10^5)) + 1: 配列の最大のrangeのlog
//略記
//#define PB push_back //vectorヘの挿入
//#define MP make_pair //pairのコンストラクタ
//#define F first //pairの一つ目の要素
//#define S second //pairの二つ目の要素

int main(){
  ll N, M, X;
  cin >> N >> M >> X;
  ll C[N], A[N][M];
  REP(n, N){
    cin >> C[n];
    REP(m, M){
      cin >> A[n][m];
    }
  }
  ll ret = INF;
  REP(s, (1 << (N))){
    ll price, check[M];
    price = 0;
    REP(m, M) check[m] = 0;
    REP(n, N){
      if((s >> n) & 1){
	price += C[n];
	REP(m, M) check[m] += A[n][m];
      }
    }
    //cout << "===" << endl;
    //cout << s << " " << price << endl;
    REP(m, M){
      //cout << check[m] << endl;
      if(check[m] < X){
	price = INF;
      }
    }
    if(ret > price) ret = price;
  }
  if(ret == INF){
    cout << -1 << endl;
  }else{
    cout << ret << endl;
  }
  return 0;
}


Measured memory_bytes: 3180
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------
V<int>ans;
void Rabin_Karp(string a,string b){
    int al=a.length(),bl=b.length();
    if(al>bl)return;
    ll t=1;
    for(int i=0;i<al;i++)t*=MOD;
    ll ah=0,bh=0;
    for(int i=0;i<al;i++) ah=ah*MOD+a[i];
    for(int i=0;i<al;i++) bh=bh*MOD+b[i];
    for(int i=0;i+al<=bl;i++){
        if(ah==bh)ans.pb(i);
        if(i+al<bl)bh=bh*MOD+b[i+al]-b[i]*t;
    }
}
//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    string t,p;cin>>t>>p;
    Rabin_Karp(p,t);
    for(int i=0;i<ans.size();i++)cout<<ans[i]<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------















































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

int main() {
	int N;
	cin >> N;
	vector<int> A(N, 0);
	string result = "YES";

	repeat(i, N) {
		cin >> A[i];
	}

	sort(A.begin(), A.end());
	repeat(i, N) {
		if(A[i] == A[i+1]) {
			result = "NO";
			break;
		}
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#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 FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();
    sort(ALL(a));
    int ans = 0;
    REP(i,n) REP(j,i) REP(k,j){
        if (a[i] == a[j]) continue;
        if (a[j] == a[k]) continue;
        if (a[j] + a[k] > a[i]) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3696
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
 int a,b;
  cin>>a>>b;
  if(13<=a)
    cout<<b<<endl;
  else if(6<=a&&a<13)
    cout<<b/2<<endl;
  else
    cout<<0<<endl;
}


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


int main(){
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    int max = 1, len = 1;
    for(int i = 1; i < n; i++)
    {
        if(a[i] <= a[i-1])
            len++;
        else
        {
            if(max < len)
                max = len;
            len = 1;
        }
    }
    if(max < len)
        max = len;
    cout << max - 1<< endl;
    return 0;
}


Measured memory_bytes: 640
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll x, a, b;
    cin >> x >> a >> b;
    char ans = (abs(x - a) < abs(x - b)) ? 'A' : 'B';
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>

using namespace std;

typedef pair<int, int> P;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int N;
int s[200][200];
vector<int> v[200];
vector<int> H[200];
bool used[200];
bool used_[200]; //in all
int dist[200];

int depth;
int cnt;
int ed;
int es;
bool flg;

int calc ;

void bfs(int v){
    queue<int> que;
    que.push(v);
    dist[v] = 0;
    used[v] = true;
    while(!que.empty()){
        int top = que.front();
        que.pop();
        for(int i = 0; i < H[top].size(); i++){
            if(!used[H[top][i]]) {
                que.push(H[top][i]);
                depth = dist[top]+1;
                dist[H[top][i]] = dist[top]+1;
                ed = H[top][i];
                used[H[top][i]] = true;
                used_[H[top][i]] = true;
            }
        }
    }
}

void clear(){
    for(int i = 0; i < N; i++) {
        used[i] = false;
    }
}

int main(){
    cin >> N;
    UnionFind uf(N);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            char c;
            cin >> c;
            if(c == '0') s[i][j] = 0;
            if(c == '1') s[i][j] = 1;
            if(s[i][j] == 1){
                H[i].push_back(j);
                uf.unionSet(i, j);
            }
        }
    }
    
    int ans = 0;
    for(int i = 0; i < N; i++){
        v[uf.root(i)].push_back(i);
        //cout << H[i].size() << endl;
    }
    for(int i = 0; i < N; i++){
        if(v[i].size() <= 1){
            ans += v[i].size();
        }else{
            int tmp = 0;
            for(int m = 0; m < v[i].size(); m++){
                clear();
                depth = 0;
                bfs(v[i][m]);
                bool flg = true;
                for(int j = 0; j < v[i].size(); j++){
                    for(int k = 0; k < j; k++){
                        if(s[v[i][j]][v[i][k]] == 1){
                           // cout << v[i][j] << ' ' << v[i][k] << ' ' << dist[v[i][j]] << ' ' << dist[v[i][k]] << endl;
                            if((abs(dist[v[i][j]]-dist[v[i][k]])) != 1){
                                flg = false;
                                //calc++;
                                //break;
                            }
                        }
                    }
                    //if(!flg) break;
                }
                if(flg) {
                    tmp = max(depth, tmp);
                }
            }
            if(tmp == 0){
                cout << -1 << endl;
                return 0;
            }else{
                ans += tmp+1;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  cout << b / x - a / x + (a % x == 0 ? 1 : 0) << endl;
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include<cstdio>
#include <vector>
#include<queue>
#include<limits.h>
#include<string.h>
#include<functional>
using namespace std;

int a[100];
signed main() {
	int b; cin >> b;
	for (int c = 0; c < b; c++) {
		cin >> a[c];
	}
	reverse(a, a + b);
	for (int c = 0; c < b; c++) {
		if (c)cout << " ";
		cout << a[c];
	}
	cout << endl;
}

Measured memory_bytes: 3080
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD (998244353ULL);

//u64 C[100001][100001];
int D[100000];

/*void init(int N)
{
    C[0][0] = 1;
    for (int i = 0; i <= N; ++i)
    {
        for (int j = 0; j <= i; ++j)
        {
            if (C[i][j]) continue;
            else if (i == 0 || j == 0) C[i][j] = 1;
            else
            {
                C[i][j] += C[i - 1][j] + C[i - 1][j - 1];
                C[i][j] %= MOD;
            }
        }
    }
}*/

u64 mypow(u64 x, u64 n)
{
    u64 ret = 1;
    for (; n>0; n >>= 1, x = x * x)
    {
        x %= MOD;
        if (n % 2 == 1)
        {
            ret *= x;
            ret %= MOD;
        }
    }
    return ret;
}

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

    int N;
    cin >> N;
    //init(N);

    int d;
    cin >> d;
    if (d != 0)
    {
        cout << "0\n";
        return 0;
    }

    int md = 0;
    rep (i, N - 1)
    {
        cin >> d;
        ++D[d];
        md = MAX(md, d);
    }

    if (D[0] > 0)
    {
        cout << "0\n";
        return 0;
    }

    u64 ans = 1;
    for (int i = 1; i < md; ++i)
    {
        //ans *= C[D[i] + D[i + 1] - 1][D[i + 1]]
        u64 a = D[i] % MOD;
        u64 b = D[i + 1] % MOD;
        ans *= mypow(a, b);
        ans %= MOD;
    }

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



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

int main() {
    int n;
    cin>>n;
    int num[n];
    for(int i=0; i<n; i++) cin>>num[i];

    sort(num, num+n);

    bool flag = true;
    int tmp;
    for(int i=0; i<n-1; i++) {
        if(num[i+1]==num[i]) flag=false;
    }

    if(flag) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		String a = sc.next().toUpperCase();
		String b = sc.next().toUpperCase();
		String c = sc.next().toUpperCase();


		System.out.println(a.charAt(0) +"" + b.charAt(0) + c.charAt(0));
	}
}

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


int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long test=1;
// 	cin>>test;	
	while(test--)
	{
	    long long a,b=0,c=0,k,i,n,j,mini,maxi,ans,q,sum,x,y,count=0,next,prev,n1,n2,temp;
	   
	   // string s1,s2,s3;
	    cin>>n>>c;
	    int arr[n];
	    cin>>arr[0];
	    if(arr[0]>c)
	    {
	        count+=arr[0]-c;
	        arr[0]=c;
	    }
	    for(i=1;i<n;i++)
	    {
	        cin>>arr[i];
	        if(arr[i]+arr[i-1]>c)
	        {
	            count+=arr[i]+arr[i-1]-c;
	            arr[i]-=arr[i]+arr[i-1]-c;
	        }
	    }
	    cout<<count;
	    
    }
    
}


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

const int INF = (int)1e5;

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

    int N, C;
    cin >> N >> C;

    int p[C][INF];
    memset(p, 0, sizeof(p));
    int tmp_s, tmp_t, tmp_c;
    for (int i = 0; i < N; ++i) {
        cin >> tmp_s >> tmp_t >> tmp_c;
        for (int j = tmp_s - 1; j < tmp_t; ++j) {
            p[tmp_c - 1][j] = 1;
        }
    }

    int max_count = 0;
    for (int j = 0; j < INF; ++j) {
        int count = 0;
        for (int i = 0; i < C; ++i) {
            count += p[i][j];
        }
        max_count = max(max_count, count);
    }

    cout << max_count << '\n';

    return 0;
}


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

using ll = long long;

bool bipartite(vector<vector<pair<int, ll>>> &G, int u, vector<ll> &bipart) {
  bipart[u] = 0;
  queue<int> q;
  q.push(u);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < G[v].size(); i++) {
      if (bipart[G[v][i].first] == -1) {
        bipart[G[v][i].first] = (bipart[v] ^ 1);
        q.push(G[v][i].first);
      }
      else {
        if (bipart[G[v][i].first] == bipart[v]) return false;
      }
    }
  }
  return true;
}

bool bfs(vector<vector<pair<int, ll>>> &G, int u, vector<ll> &d) {
  d[u] = 1;
  queue<int> q;
  q.push(u);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < G[v].size(); i++) {
      if (d[G[v][i].first] == 1e18) {
        d[G[v][i].first] = G[v][i].second - d[v];
        q.push(G[v][i].first);
      }
      else {
        if (d[G[v][i].first] != G[v][i].second - d[v]) return false;
      }
    }
  }
  return true;
}

ll bfs2(vector<vector<pair<int, ll>>> &G, int u, int x, vector<ll> &d) {
  d[u] = x;
  queue<int> q;
  q.push(u);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < G[v].size(); i++) {
      if (d[G[v][i].first] == 1e18) {
        d[G[v][i].first] = G[v][i].second - d[v];
        q.push(G[v][i].first);
      }
      else {
        if (d[G[v][i].first] != G[v][i].second - d[v]) return abs(d[G[v][i].first] - (G[v][i].second - d[v]));
      }
    }
  }
  return 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 重み付き無向(有向)グラフの隣接リスト
  int n, m; // n:頂点数 m:辺数
  cin >> n >> m;
  
  vector<vector<pair<int, ll>>> G(n); // G:頂点数nのグラフの隣接リスト
  
  for (int i = 0; i < m; i++) {
    int u, v;
    ll w;
    cin >> u >> v >> w;
    u--;
    v--;
    G[u].emplace_back(make_pair(v, w));
    G[v].emplace_back(make_pair(u, w)); // 有向グラフではコメントアウト
  }
  
  vector<ll> bipart(n, -1);
  if (bipartite(G, 0, bipart)) {
    vector<ll> d(n, 1e18);
    if (bfs(G, 0, d)) {
      ll left = 1e18, right = 1e18;
      for (int i = 0; i < n; i++) {
        if (bipart[i] == 0) left = min(left, d[i]);
        else right = min(right, d[i]);
      }
      cout << max(left + right - 1, 0LL) << '\n';
    }
    else {
      cout << 0 << '\n';
    }
  }
  else {
    vector<ll> d(n, 1e18);
    ll keep = bfs2(G, 0, 1, d);
    if (keep % 2 == 1) {
      cout << 0 << '\n';
      return 0;
    }
    d.assign(n, 1e18);
    keep = bfs2(G, 0, 1 + keep / 2, d);
    if (keep != 0) {
      cout << 0 << '\n';
      return 0;
    }
    for (int i = 0; i < n; i++) {
      if (d[i] <= 0) {
        cout << 0 << '\n';
        return 0;
      }
    }
    cout << 1 << '\n';
  }
}

Measured memory_bytes: 12660
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vll vector<ll>
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
    fast;
    vector<ll> a;
    ll i,ans=0,k,n;
    cin>>n;
    a.resize(n);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=1;i<n;i++)
    {
        if(a[i]<a[i-1])
        {
            ans+=(a[i-1]-a[i]);
            a[i]=a[i-1];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4764
import java.io._
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, K = sc.nextInt()

    val ans = if (N % K == 0) 0 else 1
    out.println(ans)
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int)(f: Int => Unit): Unit = {
    var i = 0
    while(i < n) { f(i); i += 1 }
  }
  def rep_r(n: Int)(f: Int => Unit): Unit = {
    var i = n - 1
    while(i >= 0) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}


Measured memory_bytes: 25412
N = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
al = 0
bo = 0
while a.size != 0
  sa = a.max
  a.each_with_index do |val,i|
    if val == sa
      a.delete_at(i)
      break
    end
  end
  sb = a.max
  a.each_with_index do |val,i|
    if val == sb
      a.delete_at(i)
      break
    end
  end
  al += sa if sa; bo += sb if sb
end
puts al - bo

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


int main()
{
	string s, p, ss;
	cin >> s;
	cin >> p;

	ss = s + s;

	if (ss.find(p) == -1){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3216