akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#define cin (type == 0?cin:fin)
//#define cout (type == 0?cout:fout)
#define tcn cin.tie(0);
#define tct cout.tie(0);
#define r_0 return 0
#define ll long long
#define TIME ios_base::sync_with_stdio(0);
using namespace std;

const long long N = 2e3 + 7;
const long long MrBeast = 1e9;

ll T = 1, n, m, ans, x, cnt, a[N];
vector < ll > v, t;
int type = 0;
set< ll > st;
pair< ll ,ll > p[N];
int main()
{
    TIME
    //ifstream  fin("swap.in");
    //ofstream  fout("swap.out");
    cin >> n >> m;
    if ( n > m ){
        if ( n % m == 0 ){
            cout << n % m;
        }
        else{
            cout << abs( (n % m) - m );
        }
    }
    else{
        cnt = abs(n - m);
        cout << min(cnt , m - cnt);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
const int MOD=100000;
int dp[100][100][4];
int main(){
      int h,w;
      while(cin>>h>>w&&(h||w)){
            memset(dp,0,sizeof(dp));
            REP(i,w)dp[i][0][0]=1;
            REP(i,h)dp[0][i][1]=1;
            REP(i,w)REP(j,h){
                  if(i==0||j==0)continue;
                  dp[i][j][0]=(dp[i-1][j][0]+dp[i-1][j][2])%MOD;
                  dp[i][j][1]=(dp[i][j-1][1]+dp[i][j-1][3])%MOD;
                  dp[i][j][2]=(dp[i-1][j][1])%MOD;
                  dp[i][j][3]=(dp[i][j-1][0])%MOD;
            }
            cout<<(dp[w-1][h-1][0]+dp[w-1][h-1][1]+dp[w-1][h-1][2]+dp[w-1][h-1][3])%MOD<<endl;
      }
}

Measured memory_bytes: 1324
# your code goes here
n=int(input())
while n!=0:
    s=int(input())
    x=s
    m=s
    for i in range (n-1):#n-2?:?
        p=int(input ())
        if m>p:
      #      s+=m
            m=p
        elif x<p:
        #    s+=x
            x=p
    #    else:
        s+=p
   #     print (s)
    s-=x
    s-=m
    s/=n-2
    print(int(s))
    n=int(input())


Measured memory_bytes: 5588
#include<stdio.h>
#include<stdlib.h>

int main(){
  int n, u, k, temp;
  int i, j;
  int Adj[101][101]={};

  scanf("%d", &n);
  if(n < 1 || 100 < n)
    exit(1);

  for(i = 0; i < n; i++){
    scanf("%d %d", &u, &k);
    for(j = 1; j <= k; j++){
      scanf("%d", &temp);
      Adj[u][temp] = 1;
    }
  }

  for(i = 1; i <= n; i++){
    for(j = 1; j <= n; j++){
      if(j == n)
	printf("%d\n", Adj[i][j]);
      else
	printf("%d ", Adj[i][j]);
    }
  }

  return 0;
}

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

namespace ABC147B
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var count = 0;
            for (int i = 0; i < S.Length/2; i++)
            {
                if (S.Substring(i,1) != S.Substring(S.Length-i-1,1))
                {
                    ++count;
                }
            }
            Console.WriteLine(count);
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 11092
D = input()
A = [int(D[0]),int(D[1]),int(D[2]),int(D[3])]
for i in range(2**3):
    B = A[::1]
    C = ["+"]*3
    for j in range(3):
        if (i >> j) & 1:
            B[j+1] *= -1
            C[j] = "-"
    if sum(B) == 7:
        print(f"{A[0]}{C[0]}{A[1]}{C[1]}{A[2]}{C[2]}{A[3]}=7")
        exit()

Measured memory_bytes: 9196
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int x, y; cin >> x >> y;
	if (x == 2 && y == 2)cout << "Yes\n";
	else if (x == 2 || y == 2)cout << "No\n";
	else if (x == 4 || x == 6 || x == 9 || x == 11) {
		if (y == 4 || y == 6 || y == 9 || y == 11)cout << "Yes\n";
		else cout << "No\n";
	}
	else if (y == 4 || y == 6 || y == 9 || y == 11)cout << "No\n";
	else cout << "Yes\n";
	return 0;
}

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

int main(){
    long long a,b,k;
    cin >> a >> b >> k;
    for(int i = 0; i < k; i++){
        if(i % 2 == 0){
            if(a % 2 == 1){
                a--;
            }
            b += a/2;
            a /= 2;
        }else{
            if(b % 2 == 1){
                b--;
            }
            a += b/2;
            b /= 2;
        }
    }
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h> 

int main(void){
    int a,b,c;
	scanf("%d %d %d", &a,&b,&c);
	
	if(0<=a<=100 && 0<=b<=100 && 0<=c<=100){
	    if(a<b && b<c){
	    printf("Yes\n");
    	}else{
    	printf("No\n");
	}
	}
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;
const ll INF=10000000000000000;

int main() {
    ll n,w;
    cin>>n>>w;
    ll num=n*1000+1;
    vvll dp(n+1,vll(num,INF));
    
    ll W[n+1],V[n+1];
    rep(i,n){
        cin>>W[i+1];
        cin>>V[i+1];
    }
    dp[0][0]=0;
    for (int i=1;i<n+1;i++){
        for (int j=0;j<num;j++){
            //cout<<dp[i][j]<<" "<<i<<" "<<j<<endl;
            if (j==0){
                dp[i][j]=0;
            }
            else{
                if (j>=V[i]){
                    dp[i][j]=min(dp[i-1][j],dp[i-1][j-V[i]]+W[i]);
                }
                else{
                    dp[i][j]=dp[i-1][j];
                }
            }
        }
    }
    ll ans=0;
    for (int i=0;i<num;i++){
        if (dp[n][i]<=w){
            ans=i;
        }
    }
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 80256
#include <stdio.h>
int main(){
  int N,D,X;
  scanf("%d",&N);
  int A[N],ans=0;
  scanf("%d %d",&D,&X);
  for(int i=0;i<N;i++){
  scanf("%d",&A[i]);
  ans+=1;
  for(int j=1;j<D;j++){
    int aa=j*A[i]+1;
    if(aa>D)break;
    ans+=1;
  }
  }
  printf("%d\n",ans+X);
}


Measured memory_bytes: 128
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          (x).begin(),(x).end()
#define     rz(x)           resize(x)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    string s;
    cin>>s;

    if(s=="ARC")
        cout<<"ABC";
    else
        cout<<"ARC";
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
    int n,m,memx,memy,cou;
    while(scanf(("%d"),&n),n)
    {
        int sample[2][300] = {0},str[2][1100] = {0};
        for(int i = 0; i < n; i++)
        {
            scanf("%d%d",&sample[0][i],&sample[1][i]);
        }
        scanf("%d",&m);
        for(int i = 0; i < m; i++)
        {
            scanf("%d%d",&str[0][i],&str[1][i]);
        }
        for(int i = 0; i < m; i++)
        {
            memx = str[0][i] - sample[0][0];
            memy = str[1][i] - sample[1][0];
            cou = 0;
            for(int j = 1; j < n; j++)
            {
                for(int k = 0; k < m; k++)
                {
                    if(sample[0][j] == str[0][k] - memx && sample[1][j] == str[1][k] - memy)
                    {
                        cou++;
                        break;
                    }
                }
            }
            if(cou == n - 1)
            {
                printf("%d %d\n",memx,memy);
                break;
            }
        }
    }
}

Measured memory_bytes: 2684
import java.io.*;
import java.util.*;

public class Main {

    static double[]prob;
    static double[][]memo;
    static int n;
    static double dp(int idx,int taken){
        if (idx==n){
            return taken>n/2?1:0;
        }
        if (memo[idx][taken]!=-1)return memo[idx][taken];
        return memo[idx][taken]=prob[idx]*dp(idx+1,taken+1)+(1-prob[idx])*dp(idx+1,taken);
    }
    public static void main(String[] args) throws IOException, InterruptedException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        n = sc.nextInt();
        prob= new double[n];
        memo= new double[n+1][n+1];
        for (int i =0;i<n;i++)prob[i]=sc.nextDouble();
        for (double[]x:memo)Arrays.fill(x,-1);
        pw.println(dp(0,0));
        pw.flush();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }

}

Measured memory_bytes: 128976
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;

const int MOD = 1000000007;
const int INF = 1000000000;

template<class T>bool chmax(T &a, const T &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T>bool chmin(T &a, const T &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}

int main(){
    int n, a, b; cin >> n >> a >> b;
    cout << min(a*n, b) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000000000000;
//input



//processing



//dpTable
//int dp[100050];

int main(){
    int N;
    cin >> N;
    int A = (N + 999) / 1000;
    cout << 1000 * A - N << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define INF 1000

int main() {
  int h, w; cin >> h >> w;
  VVI c(10, VI(10));
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) cin >> c[i][j];
  }

  VI d(10, INF);
  d[1] = 0;
  auto comp = [&](int a, int b) { return d[a] > d[b]; };
  priority_queue<int, VI, decltype(comp)> que(comp);
  que.push(1);
  while (!que.empty()) {
    int v = que.top(); que.pop();
    for (int u = 0; u < 10; u++) {
      if (d[u] > d[v] + c[u][v]) {
        d[u] = d[v] + c[u][v];
        que.push(u);
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int a; cin >> a;
      if (a >= 0) ans += d[a];
    }
  }
  cout << ans << endl;
}

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

int main (void)
{
    int x1,y1,x2,y2,x3,y3,x4,y4, a, b;
    scanf("%d%d%d%d", &x1,&y1,&x2,&y2);
    a = y1 - y2;
    b = x2 - x1;
    x3 = x2 + a;
    y3 = y2 + b;
    x4 = x3 - (x2 - x1);
    y4 = y3 - (y2 - y1);
    printf("%d %d %d %d", x3, y3, x4, y4);
    return 0;
}

Measured memory_bytes: 128
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container;

long P = 10^^9+7;
long[10^^5+50] F, RF;

void init()
{
    F[0] = F[1] = 1;
    foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;

    {
        RF[$-1] = 1;
        auto x = F[$-1];
        auto k = P-2;
        while (k) {
            if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
            x = x^^2 % P;
            k /= 2;
        }
    }
    foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}

long pow(long x, long n) {
    long y = 1;
    while (n) {
        if (n%2 == 1) y = (y * x) % P;
        x = x^^2 % P;
        n /= 2;
    }
    return y;
}

long inv(long x)
{
    return pow(x, P-2);
}

void main()
{
    init();
    auto N = readln.chomp.to!long;
    auto r = F[N];
    long d = 1, p = 1, c = 1;
    foreach (i, x; readln.split.to!(long[])) {
        if (x < d) {
            r = (r - p * (N-i-1) % P * F[N-c] % P + P) % P;
            d -= 2;
            p = p * (i+2-c) % P;
            ++c;
        }
        d += 2;
    }
    writeln(r);
}

Measured memory_bytes: 7604
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            String S = in.next();
            int[] ec = new int[N + 1];
            int[] wc = new int[N + 1];
            for (int i = 0; i < N; i++) {
                ec[i + 1] = ec[i] + (S.charAt(i) == 'E' ? 1 : 0);
                wc[N - 1 - i] = wc[N - i] + (S.charAt(N - 1 - i) == 'W' ? 1 : 0);
            }
            int min = Integer.MAX_VALUE;
            for (int i = 0; i <= N; i++) {
                int temp;
//            if (i == 0) {
//                temp = ec[N] - ec[i + 1];
//            } else if (i == N) {
//                temp = wc[0] - wc[i - 1];
//            } else {
//                temp = wc[0] - wc[i - 1] + ec[N] - ec[i + 1];
//            }
                temp = wc[0] - wc[i] + ec[N] - ec[i];
                min = Math.min(min, temp);
            }
            out.println(min);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

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

    }
}



Measured memory_bytes: 28596
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>


#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int s, t; cin >> s >> t;
	string ss;
	string ts;

	FOR_LT(i, 0, t) {
		ss += '0' + s;
	}
	FOR_LT(i, 0, s) {
		ts += '0' + t;
	}

	if (ss < ts) {
		cout << ss << endl;
	}
	else {
		cout << ts << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long double n, m, d, ans;
	long long i, j, k;

	cin >> n >> m >> d;
	if (d == 0) ans = 1.0 / n;
	else {
		ans = (n - d) * 2.0 / (n * n);
	}

	ans *= (m - 1);

	cout << setprecision(10) << fixed << ans << "\n";


	return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int num,N,K;
  num = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    if (num * 2 < num + K || num * 2 == num + K) {
      num *= 2;
    }
    else if (num * 2 > num + K) {
      num += K;
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
priority_queue<int> que; 
int main(){
	int n, m; cin >> n >> m;
	for(int i = 1, x; i <= n; ++i)
		scanf("%d", &x), que.push(x);
	for(;m--;){
		int x = que.top();
		que.pop();
		x /= 2;
		que.push(x); 
	}
	long long ans = 0;
	for(;!que.empty();){
		ans += que.top();
		que.pop();
	}
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 892
import sys
sys.setrecursionlimit(10 ** 6)

N, X = map(int, input().split())

h = [1]
p = [1]

for _ in range(50):
    h.append(h[-1] * 2 + 3)
    p.append(p[-1] * 2 + 1)

def bug(l, y):
    if l == 0:
        return 0 if y <= 0 else 1
    
    mid = (h[l] + 1) // 2
    if y < mid:
        return bug(l - 1, y - 1)
    elif y == mid:
        return p[l - 1] + 1
    elif y > mid:
        return p[l - 1] + 1 + bug(l - 1, y - mid)
    
print(bug(N, X))


Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  for (int i = 1; i < 3; i++) {
    if (s[i] == s[i-1] && s[i] == s[i+1]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,q;
vector<vector<int>> a(200005,vector<int>(0));
int score[200005],p[200005];
int t[200005];
int solve(int l){
    if(l==0)return p[0];
    int ans = 0;
    int y;
    
    for(int i=0;i<a.at(l).size();i++){
        y=a.at(l).at(i);
        ans+=t[y];
        //cout<<ans<<endl;
    }
    
    return ans + p[l];
}

int main(){
    cin>>n>>q;
    int j,k;
    for(int i=0;i<n-1;i++){
        cin>>j>>k;
        a.at(k-1).push_back(j-1);
    }
    
    for(int i=0;i<q;i++){
        cin>>j>>k;
        p[j-1]+=k;
    }
    for(int i=0;i<n;i++){
        t[i]=solve(i);
        cout<<t[i]<<" ";
    }
    cout <<endl;
}

Measured memory_bytes: 14720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

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

  set<int> S;
  rep(i, N) {
    int A;
    cin >> A;
    S.insert(A);
  }

  int M = S.size();

  cout << ((N - M) % 2 == 0 ? M : M - 1) << endl;
  return 0;
}


Measured memory_bytes: 4992
n=int(input())
A=[]
B=[]
for i in range(n):
  a,b=map(int,input().split())
  A.append([a,b])
  
for i in range(n):
  for j in range(i):
    B.append([A[i][0]-A[j][0],A[i][1]-A[j][1]])
  for j in range(i+1,n):
    B.append([A[i][0]-A[j][0],A[i][1]-A[j][1]])
    

l=0
for i in B:
  l=max(l,B.count(i))
print(n-l)

Measured memory_bytes: 3316
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main {

    public static void main(String[] args) throws IOException {
        Scanner Input = new Scanner(System.in);
        int N = Input.nextInt();
        int K = Input.nextInt();
        ArrayList<Integer> Li = new ArrayList();
        for (int I = 0; I < N; I++) {
            Li.add(Input.nextInt());
        }
        Collections.sort(Li);
        long Sum = 0;
        for (int I = Li.size()-1; I >= Li.size()-K; I--) {
        Sum+=Li.get(I);
        }
        System.out.println(Sum);
    }

}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	int n, k, ans, i, j, x;
	cin >> n >> k;
	ans = 0;
	for (i = 0; i < n; i++) {
		cin >> x;
		ans += min(x, k - x);
	}
	cout << ans * 2 << "\n";

	return 0;
}



Measured memory_bytes: 888
##141
##A
s = input()
if s == "SUN":
    print(int(7))
elif s == "MON":
    print(int(6))
elif s == "TUE":
    print(int(5))
elif s == "WED":
    print(int(4))
elif s == "THU":
    print(int(3))
elif s == "FRI":
    print(int(2))
elif s == "SAT":
    print(int(1))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std ;
#define int long long int
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define pb push_back
#define all(c) (c).begin(), (c).end()

void startup()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

int32_t main()
{
    startup();

    int n,k;
    cin>>n>>k;
    vi v(n,0);
    for(int i=0 ; i<n ; ++i)
    	cin>>v[i];

    vi dp(n,0);
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    for(int i=2 ; i<n ; ++i)
    {
    	int nr=0;
    	dp[i]=INT_MAX ;
    	for(int j=1 ; j<=k && nr<(i); ++j,++nr)
    	{
    		dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
    	}
    }
    cout<<dp[n-1];
    
    
    return 0;
}

Measured memory_bytes: 4728
fun main(args: Array<String>) {
    readLine()
    val A = readLine()!!.split(" ").map(String::toInt)

    var a = 0
    var b = 0

    A.sortedDescending().forEachIndexed { i, e ->
        if (i % 2 == 0) {
            a += e
        } else {
            b += e
        }
    }
    println(a - b)
}



Measured memory_bytes: 37944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct qu
{
    int a,b,c,d;
}x[25];
bool cmp(qu u,qu v)
{
    return u.d>v.d;
}
int A[15];
int n,m,q,ans;
void dfs(int cur,int now)  // 最大能取的数,当前为第 now 个数
{
    if(cur==0) return;
    if(now==n)   // 计算一次符合的数
    {
        int sum=0;
        for(int i=0;i<q;i++)
        {
            if(A[x[i].a]-A[x[i].b]==x[i].c)
                sum+=x[i].d;
        }
        ans=max(ans,sum);
        return;
    }
    for(int i=cur;i>=1;i--)
    {
        A[now+1]=i;
        dfs(i,now+1);
    }
}
int main()
{
    cin>>n>>m>>q;
    for(int i=0;i<q;i++)
    {
        scanf("%d%d%d%d",&x[i].a,&x[i].b,&x[i].c,&x[i].d);
    }
    for(int i=m;i>=1;i--)
    {
        A[1]=i;
        dfs(i,1);
    }
    cout<<ans;
}


Measured memory_bytes: 3676
n = int(input())
words = dict()
for _ in range(n):
    s = input()
    words.setdefault(s, 0)
    words[s] += 1

m = int(input())
for _ in range(m):
    s = input()
    words.setdefault(s, 0)
    words[s] -= 1

mc = 0
for k, c in words.items():
    mc = max(mc, c)

if mc < 0:
    print(0)
else:
    print(mc)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
const int N=2e5+5;
int n,k,a[N],t1[N<<2],t2[N<<2];
void build(int l,int r,int k)
{
    if(l==r)
    {
        t1[k]=t2[k]=a[l];return;
    }
    int m=l+r>>1;
    build(l,m,k<<1);build(m+1,r,k<<1|1);
    t1[k]=min(t1[k<<1],t1[k<<1|1]);
    t2[k]=max(t2[k<<1],t2[k<<1|1]);
}
int qmn(int l,int r,int k,int x,int y)
{
    if(r<x||l>y) return inf;
    if(l>=x&&r<=y) return t1[k];
    int m=l+r>>1;
    return min(qmn(l,m,k<<1,x,y),qmn(m+1,r,k<<1|1,x,y));
}
int qmx(int l,int r,int k,int x,int y)
{
    if(r<x||l>y) return -inf;
    if(l>=x&&r<=y) return t2[k];
    int m=l+r>>1;
    return max(qmx(l,m,k<<1,x,y),qmx(m+1,r,k<<1|1,x,y));
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    build(1,n,1);
    int ans=1;
    for(int i=k+1;i<=n;i++)
        if(!(a[i-k]==qmn(1,n,1,i-k,i-1)&&a[i]==qmx(1,n,1,i-k+1,i))) ans++;
    int res=0,t=1;
    for(int i=2;i<=n;i++)
        if(a[i]>a[i-1]) t++;
    else
    {
        if(t>=k) res++;
        t=1;
    }
    res+=t>=k;
    ans-=max(0,res-1);
    printf("%d\n",ans);
}


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

int main(){
  string s;

  while(cin >> s){
    int n = s.length();
    string ans = "";

    for(int i = 0; i < n; ){
      if(s[i] == '@'){
        for(int j = 0; j < s[i + 1] - '0'; j++){
          ans += s[i + 2];
        }
        i += 3;
      }
      else{
        ans += s[i];
        i++;
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int64 gcd(int64 a, int64 b) {
    return b != 0 ? gcd(b, a % b) : a;
}

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

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};
typedef pair<int, int> P;

void solve() {
		int h, w; cin >> h >> w;
		vector<string> maze(h);
		rep (i, h) {
			cin >> maze[i];
		}
		int ans = -1;
		rep (si, h) {
			rep (sj, w) {
				queue<P> q;
				vector<vector<int>> dist(h, vector<int>(w, INF));
				auto update = [&](int i, int j, int x) {
					if (dist[i][j] != INF) return;
						dist[i][j] = x;
						q.push(P(i, j));
				};
				if (maze[si][sj] == '#') continue;
				update(si, sj, 0);
				while(!q.empty()) {
					int i = q.front().first;
					int j = q.front().second;
					q.pop();
					rep (dir, 4) {
						int ni = i + dx[dir];
						int nj = j + dy[dir];
						if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
						if (maze[ni][nj] == '#') continue;
						update(ni, nj, dist[i][j] + 1);
					}
				}
				rep (p, h) {
					rep (q, w) {
						if (dist[p][q] != INF) ans = max(ans, dist[p][q]);
					}
				}
			}
		}
		cout << ans << endl;
    return;
}

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x[500005],y[500005],z[500005];

ll t,i,j;
ll sum;
ll p,q;
ll n,m,a,b,c,d,e,h,w;

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

}

int main (){
	cin >> n;
	for(i=0;i<n;i++){
		cin >> x[i];
	}
	y[0] = x[0];
	for(i=1;i<n;i++){
		y[i] = gcd(x[i],y[i-1]);
	}
	z[n-1] = x[n-1];
	for(i=n-2;i>=0;i--){
		z[i] = gcd(x[i],z[i+1]);
	}
	ll ans = 1;
	for(i=1;i<n-1;i++){
		ans = max(ans,gcd(y[i-1],z[i+1]));
	}
	ans = max(ans,z[1]);
	ans = max(ans,y[n-2]);
	cout << ans << endl;
	return 0;
	


}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll N;
    cin >> N;
    ll sum = 0;
    FOR(i, N + 1, 1)
    {
        sum += i;
        if (sum > N)
        {
            cout << "No" << endl;
            return 0;
        }
        if (sum < N)
            continue;

        cout << "Yes" << endl;
        int k = 2 * N / i;
        cout << k << endl;
        vector<vector<int>> S(k);
        int index = 0;
        int h = 1;
        FOR(j, N + 1, 1)
        {
            S[index].push_back(j);
            S[index + h++].push_back(j);
            if (S[index].size() == i)
            {
                ++index;
                h = 1;
            }
        }

        REP(j, k)
        {
            cout << i;
            REP(n, i)
            {
                cout << " " << S[j][n];
            }
            cout << endl;
        }
        break;
    }
    return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
vector<ll> dp[5050][2];
int sz[5050];
vector<int> v[5050];
ll calc[5050];


void dfs(int x,int p=-1){
    sz[x]=1;
    for(auto to:v[x]){
        if(to==p)continue;
        dfs(to,x);
    }
    rep(i,2)dp[x][i].resize(sz[x]+1);
    dp[x][0][1]=1;
    int s=1;
    for(auto to:v[x]){
        if(to==p)continue;
        vector<ll> dpp[2];
        rep(i,2)dpp[i].resize(s+sz[to]+1);
        rep(i,sz[to]+1)rep(j,s+1){
            dpp[0][i+j]+=(dp[x][0][j]*dp[to][0][i]+dp[x][1][j]*dp[to][1][i])%mod;
            dpp[1][i+j]+=(dp[x][0][j]*dp[to][1][i]+dp[x][1][j]*dp[to][0][i])%mod;
        }
        s+=sz[to];
        rep(i,s+1){
            dp[x][0][i]=dpp[0][i]%mod;
            dp[x][1][i]=dpp[1][i]%mod;
        }
    }
    rep(i,s){
        dp[x][0][0]+=dp[x][1][i+1]*calc[i+1]%mod;
        dp[x][1][0]+=dp[x][0][i+1]*calc[i+1]%mod;
    }
    dp[x][0][0]%=mod;
    dp[x][1][0]%=mod;
    if(p!=-1)sz[p]+=sz[x];
}


int main(){
    int n;cin>>n;
    rep(i,n-1){
        int x,y;cin>>x>>y;
        --x;--y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    calc[0]=1;
    rep(i,n)calc[i+2]=calc[i]*(i+1)%mod;
    dfs(0);
    ll ans=(mod+dp[0][1][0]-dp[0][0][0])%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 138496
let levenshtein_distance s t =
  let m = String.length s in
  let n = String.length t in
  let d = Array.make_matrix (m + 1) (n + 1) 0 in
  let rec dudu i =
    if i <= m then begin
      d.(i).(0) <- i;
      dudu (i + 1)
    end in
  let rec wa i =
    if i <= n then begin
      d.(0).(i) <- i;
      wa (i + 1)
    end in
  let rec doit = function
    | (i, _) when i > m -> d.(m).(n)
    | (i, j) when j > n -> doit (i + 1, 1)
    | (i, j) ->
      let c = if s.[i-1] = t.[j-1] then 0 else 1 in
      d.(i).(j) <- if d.(i-1).(j) + 1 < d.(i).(j-1) + 1 then d.(i-1).(j) + 1 else d.(i).(j-1) + 1;
      d.(i).(j) <- if d.(i-1).(j-1) + c < d.(i).(j) then d.(i-1).(j-1) + c else d.(i).(j);
      doit (i, j + 1) in
  dudu 1; wa 1; doit (1, 1)

let () =
  let s1 = read_line () in
  let s2 = read_line () in
  Printf.printf "%d\n" (levenshtein_distance s1 s2)

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

//O(|V||E|)
template<typename ctype, ctype INF>
class BellmanFord{
public:
  double EPS = 1e-8;
  using T = tuple<int, int, ctype>;
  int V;
  vector<vector<int> > G, rG;
  vector<T> edge;
  BellmanFord():V(-1){}
  BellmanFord(int V):V(V), G(V), rG(V){}

  void add_edge(int from, int to,ctype cost){
    assert(0 <= from && from < V);
    assert(0 <= to && to < V);
    edge.push_back(T(from, to, cost));
    G[from].push_back(to);
    rG[to].push_back(from);
  }

  void add_bidirectional_edge(int a,int b,ctype cost){
    add_edge(a, b, cost);
    add_edge(b, a, cost);
  }

  //s番目の頂点から各頂点への最短距離を求める。
  //グラフに負閉路があれば{}を返す。
  vector<ctype> calcDistance(int start){
    assert(0 <= start && start < V);
    vector<ctype> D(V, INF);   //最短距離
    D[start] = 0;

    int cnt = 0;
    bool update = true;
    while(update){
      if(++cnt > V) return {}; //負の閉路
      update = false;
      for(auto e:edge){
        int from, to;
        ctype cost;
        tie(from, to, cost) = e;
        ctype ncost = D[from] + cost;
        if(abs(D[from] - INF) < EPS || ncost - D[to] > -EPS) continue;
        //if(D[from] == INF || ncost >= D[to]) continue;
        D[to] = ncost;
        update = true;
      }
    }
    return D;
  }


  //startからgoalへの最短距離を求める。
  //startからgoalの経路上に負閉路があるか判定する。
  ctype calcDistance(int start, int goal){
    assert(0 <= start && start < V);
    assert(0 <= goal && goal < V);

    vector<int> visited(V, 0); //goalから到達可能なノード
    function<void(int pos)> calcVisited = [&](int pos){
      if(visited[pos]) return;
      visited[pos] = 1;
      for(int to:rG[pos]) calcVisited(to);
    };
    calcVisited(goal);

    vector<ctype> D(V, INF);   //最短距離
    D[start] = 0;
    int cnt = 0;
    bool update = true;
    while(update){
      if(++cnt > V) return -INF; //負の閉路
      update = false;
      for(auto e:edge){
        int from, to;
        ctype cost;
        tie(from, to, cost) = e;
        ctype ncost = D[from] + cost;
        if(abs(D[from] - INF) < EPS || ncost - D[to] > -EPS || visited[to] == 0) continue;
        //if(D[from] == INF || ncost >= D[to] || visited[to] == 0) continue;
        D[to] = ncost;
        update = true;
      }
    }
    return D[goal];
  }
};

void ABC_137_E(){
  using Int = long long;
  const Int INF = 1LL<<55;
  int N, M, P;
  cin>>N>>M>>P;

  BellmanFord<Int, INF> bf(N);
  for(int i=0;i<M;i++){
    int a, b, c;
    cin>>a>>b>>c; a--, b--;
    bf.add_edge(a, b, -c + P);
  }
  Int ans = bf.calcDistance(0, N-1);
  if(ans == -INF) cout<<-1<<endl;
  else cout<<max(0LL, -ans)<<endl;

}

void AOJ_GRL_1_B(){
  int N, M, start;
  cin>>N>>M>>start;

  typedef long long ll;
  const ll INF = 1e18;
  BellmanFord <ll, INF> bf(N);
  for(int i=0;i<M;i++){
    int from, to, cost;
    cin>>from>>to>>cost;
    bf.add_edge(from, to, cost);
  }

  vector<ll> D = bf.calcDistance(start);
  if(D.empty()) cout<<"NEGATIVE CYCLE"<<endl;
  else {
    for(int i=0;i<N;i++)
      if(D[i] != INF) cout<<D[i]<<endl;
      else cout<<"INF"<<endl;
  }
}


signed main(){
  //ABC_137_E();
  AOJ_GRL_1_B();
  return 0;
}



Measured memory_bytes: 3220
n,x,y=map(int,input().split())
ans=[0]*(n-1)

for i in range(1,n):
    for j in range(i+1,n+1):
        #print(min(j-i,abs(y-j)+1+abs(x-i)))
        ans[min(j-i,abs(y-j)+1+abs(x-i))-1]+=1
for i in ans:
    print(i)

Measured memory_bytes: 46556
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())
print(a[k - 1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int iti, juu, hyaku, sen;
  iti = N % 10;
  juu = (N / 10) % 10;
  hyaku = (N / 100) % 10;
  sen = N / 1000;
  if ((sen == hyaku && hyaku == juu) || (hyaku == juu && juu == iti)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3612
#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(){
    int n, m, k;
    cin >> n>>m>>k;
    ll ans=0;
    if(n%m==0){
        ans=n/m;
    }else{
        ans=n/m+1;
    }
    cout << ans*k << endl;
}

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

const char NL = '\n';
const char SP = ' ';
#define loop(i, a, b) for (long long i = a; i < b; i++)

void buy (long long &st, long long &mo, long long price) {
    long long number = mo / price;
    st += number;
    mo = mo - price * number;
    //cout << "BUY " << st << SP << mo << SP << price << NL;
}

void sell (long long &st, long long &mo, long long price) {
    mo += price * st;
    st = 0;
    //cout << "SELL " << st << SP << mo << SP << price << NL;
}

int main () {
    ios_base::sync_with_stdio(false);
    long long n, mo = 1000, st = 0;// max_pr = 99, min_pr = 201;
    cin >> n;
    long long a[n];
    bool growing;
    loop (i, 0, n) {
        cin >> a[i];
    }
    if (a[0] > a[1]) {
        growing = true;
    }
    else {
        growing = false;
    }
    loop (i, 1, n) {
        if (a[i] > a[i - 1] && !growing) {
            buy (st, mo, a[i - 1]);
            growing = true;
        }
        else if (a[i] < a[i - 1] && growing) {
            sell (st, mo, a[i - 1]);
            growing = false;
        }
        if (growing && i == n - 1) {
            sell (st, mo, a[i]);
        }
        /*else if (a[i] < a[i - 1] && !growing) {
            if (min_pr > a[i]) {
                min_pr = a[i]
            }
        }*/
        //cout << a[i] << SP << st << SP << mo << NL;
    }
    cout << mo << NL;
    return 0;
}

Measured memory_bytes: 3640
program ABC144E_answer
    implicit none
    integer(8)::i,N,K
    integer(8)::C_min=-1
    integer(8)::C_max=0
    integer(8)::C_mid,K_sim
    integer(8),allocatable,dimension(:)::A,F,C

    read(5,*) N,K
    allocate(A(N))
    allocate(F(N))
    allocate(C(N))
    read(5,*) (A(i),i=1,N)
    read(5,*) (F(i),i=1,N)
    A=iqsort(A)
    F=iqsort(F)

    do i=1,N
        C(i)=A(i)*F(N+1-i)

        if(C(i)>C_max)then
            C_max=C(i)
        end if
    end do

    C_max=C_max+1

    do
        K_sim=0
        C_mid=(C_max+C_min)/2
        do i=1,N
            if(mod(max(0,C(i)-C_mid),F(N+1-i))==0)then
                K_sim=K_sim+max(0,C(i)-C_mid)/F(N+1-i)
            else
                K_sim=K_sim+max(0,C(i)-C_mid)/F(N+1-i)+1
            end if
        end do

        if(K_sim>K)then
            C_min=C_mid
        else
            C_max=C_mid
        end if

        if(C_max-C_min<=1) then
            exit
        end if
    end do

    print'(i0)',C_max

contains
    recursive function iqsort(ix) result(ires)
      integer(8), allocatable :: ires(:)
      integer(8), intent(in)  :: ix(:)
      integer :: k
      if (size(ix) <= 1) then 
        ires = ix
      else  
        k = ix(size(ix) / 2)
        ires = [iqsort(pack(ix, ix < k)), pack(ix, ix == k), iqsort(pack(ix, ix > k))] 
      end if
    end function iqsort    
end program ABC144E_answer

Measured memory_bytes: 14756
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

	string alphabets;
	{
		string lowers, uppers;
		REP( i, 0, 26 )
		{
			lowers += 'a' + i;
			uppers += 'A' + i;
		}
		alphabets = lowers + uppers;
	}

	for ( int n; cin >> n, n; )
	{
		VI ks( n );
		FOR( k, ks )
		{
			cin >> k;
		}

		string str;
		cin >> str;

		REP( i, 0, str.size() )
		{
			const int p = alphabets.find( str[i] );
			cout << alphabets[ ( p - ks[ i % ks.size() ] + 52 ) % 52 ];
		}
		cout << endl;
	}

	return 0;
}

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

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

    string s;
    cin >> s;

    if(s[0] != 'A'){
        cout << "WA" << endl;
        return 0;
    }

    int c_cnt = 0, idx;
    for(int i = 2; i <= s.size() -2; i++){
        if(s[i] == 'C'){
            c_cnt++;
            idx = i;
        }
        if(c_cnt > 1){
            cout << "WA" << endl;
            return 0;
        }
    }

    if(c_cnt == 0){
        cout << "WA" << endl;
        return 0;
    }

    for(int i = 1; i < s.size(); i++){
        if(i == idx) continue;
        if('A' < s[i] and s[i] <= 'Z'){
            cout << "WA" << endl;
            return 0;
        }
    }

    cout << "AC" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename x>
using ordered_set = tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update>;
#define sorta(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n,greater<__typeof(a[0])>())
#define all(x) (x).begin(),(x).end()
#define ms0(x) memset((x),0,sizeof((x)))
#define ms1(x) memset((x),-1,sizeof((x)))
typedef pair<int,int> pi;
#define inarr(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define prinarr(arr) {for(int x:arr)cout<<x<<" ";} cout<<"\n";
#define cout1(a) cout<<a<<"\n";
#define cout2(a,b) cout<<a<<" "<<b<<"\n";
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define setpre(n) cout<<fixed<<setprecision(8)<<n<<"\n";
#define filldp(arr,n,m,k) for(int i=0;i<n;i++){for(int j=0;j<m;j++) arr[i][j]=k;}

#define mod 1000000007
#define mod1 998244353


vector<vector<int>> adj;
vector<int> dis;
vector<int> parent;
vector<bool> visited;

void newgr(int n){
    n+=10;
    adj=vector<vector<int>>(n);
    dis=vector<int>(n,0);
    //parent=vector<int>(n,-1);
    visited=vector<bool>(n,false);
}

void dfs(int s){
    visited[s]=true;
    for(auto u:adj[s]){
        if(!visited[u]){
            //parent[u]=s;
            dis[u]=dis[s]+1;
            dfs(u);
        }
    }
}

void bfs(int s){
    queue<int> q;
    q.push(s);
    visited[s]=true;
    dis[s]=0;
    while(!q.empty()){
        auto u=q.front();
        q.pop();
        for(auto x:adj[u]){
            if(!visited[x]){
                //parent[x]=u;
                visited[x]=true;
                dis[x]=dis[u]+1;
                q.push(x);
            }
        }
    }
}

long long power(long long x,long long y){  
    long long ans=1;
    x%=mod;
    while(y>0){
        if(y&1) ans=(ans*x)%mod;
        y>>=1;
        x=(x*x)%mod;
    }
    return ans;
}

long long modinv(long long b){ 
    return power(b,mod-2);
}



int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    map<string,int> mp;
	int n;
	cin>>n;
	string s;
	
	for(int i=0;i<n;i++){
		cin>>s;
		mp[s]++;
	}
	cout2("AC x",mp["AC"]);
	cout2("WA x",mp["WA"]);
	cout2("TLE x",mp["TLE"]);
	cout2("RE x",mp["RE"]);
    return 0;
}

Measured memory_bytes: 3648