akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace::std;
#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 : (int)1E18)

template<class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}



void _main() {
        int a; cin >> a;
        cout << a + a * a + a * a * a;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
#define N 10000
#define NIL -1

struct Node{
  int p,l,r;
};

struct Node data[N];
int n;

void preP(int a)
{
  if(a == NIL)
    return;

  printf(" %d",a);

  preP(data[a].l);
  preP(data[a].r);
}

void inP(int a)
{
  if(a == NIL)
    return;

  inP(data[a].l);
  printf(" %d",a);
  inP(data[a].r);
}

void postP(int a)
{
  if(a == NIL)
    return;

  postP(data[a].l);
  postP(data[a].r);
  printf(" %d",a);
}

int main()
{
  int l,r,i,v,way;

  scanf("%d",&n);
  for(i=0; i<n; i++)
    data[i].p = NIL;

  for(i=0; i<n; i++){
    scanf("%d %d %d",&v,&l,&r);
    data[v].l = l;
    data[v].r = r;
    if(l != NIL)
      data[l].p = v;
    if(r != NIL)
      data[r].p = v;
  }

  for(i=0; i<n; i++){
    if(data[i].p == NIL)
      way = i;
  }

  printf("Preorder");
  printf("\n");
  preP(way);
  printf("\n");
  printf("Inorder");
  printf("\n");
  inP(way);
  printf("\n");
  printf("Postorder");
  printf("\n");
  postP(way);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2108
main = do
    k <- readLn :: IO Int
    [a,b] <- map read <$> (words <$> getLine) :: IO [Int]
    if (a `mod` k) == 0
        then putStrLn "OK"
        else if (a `div` k) /= (b `div` k)
            then putStrLn $ "OK"
            else putStrLn $ "NG"

Measured memory_bytes: 3924
N,A = map(int,input().split())
x = list(map(int,input().split()))
X = max(max(x),A)
x = [0]+x
dp = [[0 for i in range(2*N*X+1)] for i in range(N+1)]
for j in range(N+1):
    y = x[j]-A
    for t in range(2*N*X+1):
        if j==0 and t==N*X:
            dp[j][t] = 1
        elif j>=1 and ((t-y)<0 or (t-y>2*N*X)):
            dp[j][t] = dp[j-1][t]
        elif j>=1 and 0<=t-y and t-y<=2*N*X:
            dp[j][t] = dp[j-1][t]+dp[j-1][t-y]
        else:
            dp[j][t] = 0

print(dp[N][N*X]-1)


Measured memory_bytes: 42588
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>

using namespace std;

int main()
{
    int K, T;
    if (scanf("%d%d", &K, &T) < 2) return 0;

    int mxa = 0;
    for (int i = 0; i < T; i++)
    {
        int tmp;
        if (scanf("%d", &tmp) < 1) return 0;
        if (mxa < tmp) mxa = tmp;
    }

    printf("%d\n", max(mxa - 1 - (K - mxa), 0));
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int64_t i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int64_t L,R; cin>>L>>R;

    int64_t ans=INT64_MAX;
    rep(l,L,min(R+1,L+2019)){
        rep(r,l+1,min(R+1,L+2019)) ans=min(ans,(l*r)%2019);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
typedef long long ll;
#define mod 1000000007
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF 1e15

					
int main()
{
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		ll h,w;
		cin>>h>>w;
		ll res=INT_MAX;
		for(ll i=1;i<w;i++)
		{
			ll a[3];
			a[0]=floor(h*1.0/2)*i;
			a[1]=ceil(h*1.0/2)*i;
			a[2]=h*(w-i);
			if( a[0] && a[1] && a[2])
			{
				sort(a,a+3);
				res=min(res,a[2]-a[0]);
				//cout<<a[0]<<" "<<a[1]<<" "<<res<<endl;
			}
		}
		swap(h,w);
		for(ll i=1;i<w;i++)
		{
			ll a[3];
			a[0]=floor(h*1.0/2)*i;
			a[1]=ceil(h*1.0/2)*i;
			a[2]=h*(w-i);
			if( a[0] && a[1] && a[2])
			{
				sort(a,a+3);
				res=min(res,a[2]-a[0]);
				//cout<<a[0]<<" "<<a[1]<<" "<<res<<endl;
			}
		}
		if(h%3==0 || w%3==0)
			res=0;
		else
			res=min(min(h,w),res);
		cout<<res;
}


Measured memory_bytes: 256
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    P_1 = list(map(int, input().split()))
    logging.info("Hello!")

    min_num = 2 * 10 ** 6
    counter_i = 0
    
    for p in P_1:
        if p <= min_num:
            counter_i += 1
            min_num = p

    print(counter_i)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 26012
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max = 1;
    int min = 1000000000;
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      max = Math.max(a, max);
      min = Math.min(a, min);
    }
    System.out.println(max - min);
  }
}

Measured memory_bytes: 21972
n,m = map(int,input().split())
a = [0]*m
b = [0]*m
for i in range(m):
  a[i], b[i] = map(int,input().split())

d = list(range(n+1))
g = [[i] for i in range(n+1)]

c = n*(n-1)//2
ans = [c]

for i in range(1,m)[::-1]:
  x = d[a[i]]
  y = d[b[i]]
  x,y = max(x,y),min(x,y)
  if x > y:
    c -= len(g[x])*len(g[y])
    for i in g[y]:
      d[i] = x
    g[x] += g[y]
  ans.append(c)

for t in ans[::-1]:
  print(t)


Measured memory_bytes: 43832
#include<cstdio>
#include<algorithm>
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define rep(i,s,t) for(register int i=s;i<=t;++i)
using namespace std;
const int N=8011,M=2e5+11,mod=1e9+7,half=N/2;
int n;
int f[N][N],ans,fac[N],ifac[N],a[M],b[M];
inline void inc(int &x,int y){
	x+=y;
	if(x>=mod)
		x-=mod;
}
inline int fp(int a,int b){
	int res=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1)
			res=1ll*res*a%mod;
	return res;
}
inline int C(int n,int m){
	return 1ll*fac[n]*ifac[n-m]%mod*ifac[m]%mod;
}
int main(){
	scanf("%d",&n);
	rep(i,1,n){
		scanf("%d%d",a+i,b+i);
		++f[half-a[i]][half-b[i]];
	}
	rep(i,0,N-1)
		rep(j,0,N-1)
			inc(f[i][j],(i?f[i-1][j]:0)+(j?f[i][j-1]:0));
	fac[0]=1;
	rep(i,1,N-1)
		fac[i]=1ll*i*fac[i-1]%mod;
	ifac[N-1]=fp(fac[N-1],mod-2);
	_rep(i,N-1,1)
		ifac[i-1]=1ll*i*ifac[i]%mod;
	rep(i,1,n){
		inc(ans,f[half+a[i]][half+b[i]]);
		ans=(ans-C(a[i]+a[i]+b[i]+b[i],a[i]+a[i])+mod)%mod;
	}
	ans=1ll*ans*(mod+1)/2%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 252416
#include <bits/stdc++.h>
#define SIZE(x) ((x).size())
#define PB push_back
#define FI first
#define SE second
#define _ << " " <<

using namespace std;

typedef pair<int, int> iint;

const int H = 501;
const int W = 501;
const int dx[] = { 0, 0, 1, -1 };
const int dy[] = { -1, 1, 0, 0 };

struct Move {
    int y, x, y_, x_;
    Move() = default;
    Move(int y, int x, int y_, int x_): y(y), x(x), y_(y_), x_(x_) {}
};

ostream& operator<<(ostream& oo, const Move& m) {
    oo << (m.y + 1) _ (m.x + 1) _ (m.y_ + 1) _ (m.x_ + 1);
    return oo;
}

int h, w, Opts;
int a[H][W];
vector<Move> Moves;

bool read() {
    if (!(cin >> h >> w)) {
        return false;
    }
    Opts = 0;
    Moves.clear();
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    return true;
}

void solve() {
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w - 1; j++) {
            if (a[i][j] & 1) {
                --a[i][j];
                ++a[i][j + 1];
                Moves.PB(Move(i, j, i, j + 1));
            }
        }
    }
    for (int i = 0; i < h - 1; i++) {
        if (a[i][w - 1] & 1) {
            --a[i][w - 1];
            ++a[i + 1][w - 1];
            Moves.PB(Move(i, w - 1, i + 1, w - 1));
        }
    }
#ifdef DBG
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << a[i][j] << ' ';
        }
        cout << '\n';
    }
    cout << "---------\n";
#endif
    cout << SIZE(Moves) << endl;
    for (const auto& m: Moves) {
        cout << m << endl;
    }
}

int main(void) {
    while (read())
        solve();
    return 0;
}


Measured memory_bytes: 5232
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Numerics;
using System.Runtime.CompilerServices;

namespace AtCoder
{
    class Program
    {

        const int BiggestMod = 1000000007;

        public static void Main()
        {

            var args = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            Console.WriteLine(((args[1] & 1) == 0 && (args[0] << 1) <= args[1] && (args[0] << 2) >= args[1] ? "Yes" : "No"));

        }

    }

}


Measured memory_bytes: 28292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
vector<ll> V;
int pre[maxn];
int main() {
    ll a,b,n;
    cin>>a>>b>>n;
    ll ans=(a*n)/b-a*(n/b);
    if(n>=b) ans=max(ans,a-ll(ceil(1.0*a/b)));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<int,int>
 
char grid[55][55];
int dist[55][55];
const int INF = INT_MAX;
int di[]={0,1,0,-1};
int dj[]={1,0,-1,0};
 
int main(){
  int h,w;
  cin>>h>>w;
  int black = 0;
  rep(i,h)rep(j,w){
    cin>>grid[i][j];
    dist[i][j]=INF;
    if(grid[i][j]=='#') black++;
  }
  dist[0][0]=0;
  queue<P> q;
  q.push(make_pair(0,0));
  while(!q.empty()){
    int pi,pj;
    tie(pi,pj)=q.front(); q.pop();
    int past = dist[pi][pj];
    rep(tmp,4){
      int ni=pi+di[tmp],nj=pj+dj[tmp];
      int now=past+1;
      if(ni<0 || ni>=h || nj<0 || nj>=w) continue;
      if(grid[ni][nj]=='#') continue;
      if(dist[ni][nj]<=now) continue;
      dist[ni][nj]=now;
      q.push(make_pair(ni,nj));
    }
  }
  if(dist[h-1][w-1]!=INF) cout<<h*w - black - dist[h-1][w-1] -1<<endl;
  else cout<<-1<<endl;
}
 

Measured memory_bytes: 3644
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;

typedef int64_t i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

// 多重vectorを可変引数テンプレートで http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}
//

#pragma endregion

class UnionFind {
public:
	vector<i64> par;
	void init(i64 n) {
		par.assign(n, -1);
	}
	i64 root(i64 x) {
		if (par[x] <= -1) return x;
		else return par[x] = root(par[x]);
	}
	i64 size(i64 x) {
		return -1 * par[root(x)];
	}
	bool unite(i64 x, i64 y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (size(x) < size(y)) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	};
};

int main() {
	i64 n, m;
	cin >> n >> m;
	vector<i64> a(m), b(m);
	for (i64 i = 0; i < m; ++i) {
		cin >> a[i] >> b[i];
		--a[i]; --b[i];
	}
	i64 v = n * (n - 1) / 2;
	vector<i64> ans(m);
	ans[m - 1] = v;
	UnionFind uf;
	uf.init(n);
	for (i64 i = m - 1; i >= 1; --i) {
		i64 sa = uf.size(a[i]), sb = uf.size(b[i]);
		if (uf.unite(a[i], b[i])) {
			v -= sa * sb;
		}
		ans[i - 1] = v;
	}
	for (i64 i = 0; i < m; ++i) cout << ans[i] << endl;
}

Measured memory_bytes: 4480
import sys
from itertools import accumulate

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


def prime_numbers(n):
    if n < 2:
        return []

    m = (n + 1) // 2
    p = [1] * m
    for i in range(1, int((n ** 0.5 - 1) / 2) + 1):
        if p[i]:
            p[2 * i * (i + 1) :: 2 * i + 1] = [0] * (((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1)

    return {2} | {2 * i + 1 for i in range(1, m) if p[i]}


def main():
    primes = prime_numbers(10 ** 5)
    A = [1 if n in primes and (n + 1) // 2 in primes else 0 for n in range(10 ** 5 + 1)]
    A = tuple(accumulate(A))

    Q, *LR = map(int, open(0).read().split())
    ans = []
    for l, r in zip(LR[::2], LR[1::2]):
        ans.append(A[r] - A[l - 1])

    print(*ans, sep='\n')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 29000
#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define s(x) #x<<" "<<x<<" | "<<
#define f(i,j,k) for(int i = j;i<=k;i++)
#define fr(i,j,k) for(int i = j;i>=k;i--)
#define ll long long
#define all(A)  A.begin(),A.end()  
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);  
#define endl "\n"
const int MSIZE = 5e4+5;;
const int MOD = 1e9+7;




int main(){

    FIO
    
    ll a, b, v , w, t; cin>>a>>v>>b>>w>>t;
    if(a>b) swap(a,b);
    if(a==b)    cout<<"YES"<<endl;
    else if(v<w) cout<<"NO"<<endl;
    else if(b-a<=(v-w)*t)   cout<<"YES"<<endl;
    else cout<<"NO"<<endl;


} 


Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<string>
using namespace std;


int main(){
    int s;
    cin >> s;
    int a = s/100;
    int b = s%100;
    if(1 <= a && a<=12){
        if(1 <= b && b <= 12)cout << "AMBIGUOUS"<<endl;
        else cout << "MMYY" << endl;

    }else{
        if(1<=b&&b<=12)cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
}


Measured memory_bytes: 256
a,b,c=map(int,input().split())
ans=0
atmp=a
if a%2==0:
    if b%2==0:
        tmp1=b
        tmp2=c
    elif c%2==0:
        tmp1=c
        tmp2=b
    else:
        atmp=b
        tmp1=c
        tmp2=a
else:
    if b%2==1:
        tmp1=b
        tmp2=c
    elif c%2==1:
        tmp1=c
        tmp2=b
    else:
        atmp,tmp1,tmp2=b,c,a
maxtmp,mintmp=max(atmp,tmp1),min(atmp,tmp1)
while mintmp<maxtmp:
    mintmp+=2
    ans+=1
if tmp2<mintmp:
    while tmp2<mintmp:
        tmp2+=2
        ans+=1
else:
    while mintmp<tmp2:
        mintmp+=1
        ans+=1
if tmp2!=mintmp:
    ans+=1
print(ans)

            


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

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

int main() {
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i=0;i<N;i++) cin >> A[i];

    ll res = 0;
    ll ans = 0;
    for(int i=0;i<N;i++){
        res = 0;
        for(int j=0;j<N;j++){
            if(A[i]>A[j]) res++;
        }
        ans += ((res%MOD)*(((K-1)*K)%MOD)%MOD)*modinv(2,MOD)%MOD;
        //ans = (ans+((((res*(K-1)+1)%MOD)*((res*(K-1))%MOD))%MOD*(modinv(2,MOD)))%MOD)%MOD;
        ans %= MOD;
    }
    ll tmp = 0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(A[i]>A[j]) tmp++;
        }
    }
    cout << (ans+(tmp*K)%MOD)%MOD << endl;

    return 0;
}

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

using namespace std;

int main()
{
  string ar;
  
  cin>>ar;
  
  int A=0,B=0;
  
  for(int i=0 ; i<3 ; i++)
  {
    if(ar[i]=='A')	A++;
    else B++;
  }
  if(A==0 || B==0) cout<<"No\n";
  else	cout<<"Yes\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define int long long

int32_t main()
{
    int n; cin>>n;
    int temp;
    int q=0;
    for(int i=1;i<=n;i++)
    {
        cin>>temp;
        if(temp!=i) q++;
    }
    if(q==0||q==2) cout<<"YES";
    else cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

class Main {
    public static void main (String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int q = Integer.parseInt(br.readLine());

        StringBuilder sb = new StringBuilder("");

        for (int i = 0; i < q; i++) {
            char[] X = br.readLine().toCharArray();
            char[] Y = br.readLine().toCharArray();
            sb.append(LCS(X, Y));
            sb.append('\n');
        }

        System.out.print(sb);
    }

    private static int LCS(char[] X, char[] Y) {
        int m = X.length;
        int n = Y.length;
        int i, j;
        int[][] len = new int[m+1][n+1];

        for (i = 0; i < m; i++) {
            len[i][0] = 0;
        }
        for (j = 0; j < n; j++) {
            len[0][j] = 0;
        }

        for (i = 1; i <= m; i++) {
            for (j = 1; j <= n; j++) {
                if (X[i-1] == Y[j-1]) {
                    len[i][j] = len[i-1][j-1] + 1;
                } else {
                    len[i][j] = Math.max(len[i][j-1], len[i-1][j]);
                }
            }
        }

        return len[m][n];
    }
}

Measured memory_bytes: 63792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500009],br[500009];
map<ll,ll>mp;
vector<ll>v;
int main()
{
    ll a,b,c,i,j,k=0;
    string s,d,e;
    cin>>a;
    for(i=1;i<=a;i++)
    {
        cin>>b;
        mp[b]++;
        if(mp[b]>1)
        {
            k=1;
        }
    }
    if(k==1)
    {
        cout<<"NO"<<endl;
    }
    else
    {
        cout<<"YES"<<endl;
    }
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define maxn 586

using namespace std;

int n, m;
int a[maxn][maxn];
vector<pair<int, int> > v;

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) scanf("%d", &a[i][j]);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j < m;j++){
			if(a[i][j] & 1){
				a[i][j]--, a[i][j + 1]++;
				v.push_back({i, j});
			}
		}
	}
	for(int i = 1;i < n;i++){
		if(a[i][m] & 1){
			a[i][m]--, a[i + 1][m]++;
			v.push_back({i, m});
		}
	}
	printf("%d\n", v.size());
	for(int i = 0;i < v.size();i++){
		if(v[i].second == m) printf("%d %d %d %d\n", v[i].first, v[i].second, v[i].first + 1, v[i].second);
		else printf("%d %d %d %d\n", v[i].first, v[i].second, v[i].first, v[i].second + 1);
	}
}


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

int main() {
  ll mod=1e9+7;
  ll n,k;
  cin>>n>>k;
  ll ans=0;
  for(ll i=k;i<=n+1;i++){
    ans+=((2*n-i+1)*i)/2;
    ans%=mod;
    ans-=(i*(i-1))/2;
    ans%=mod;
    ans++;
    ans%=mod;
  }
  if(ans<0){
    ans+=mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	     Scanner scan = new Scanner(System.in);
             int x;
	     for(int count = 1; ;count++){
	    	 x  = scan.nextInt();
	    	 if(x == 0)break;
	    	 System.out.println("Case " + count + ": " + x);
	     }


	}

}

Measured memory_bytes: 42544
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i = 0; i < (n); i++)
 
int main() {
	string S;
	cin >> S;
  	if (S[2]==S[3]&&S[4]==S[5]){
    cout << "Yes";
    }
  	else{
    cout << "No" << endl;
    }
}


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

int main(void) {
	char *s, *t, *u;
	int n;
	cin >> n;
	s = new char[n + 1];
	t = new char[n+ 1];
	u = new char[2*n + 1];
	cin >> s >> t;
	for(int i = 0; i < n; i++) {
		u[2*i] = s[i];
		u[2*i+1] = t[i];
	}
	u[2*n] = '\0';
	cout << u;
	delete[] s;
	delete[] t;
	delete[] u;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int a[10],b[10],i,s,ss;
	for(i=0;i<10;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<10;i++){
		scanf("%d",&b[i]);
	}
	sort(a,a+10,greater<int>());
	sort(b,b+10,greater<int>());
	s=a[0]+a[1]+a[2];
	ss=b[0]+b[1]+b[2];
	printf("%d %d\n",s,ss);
	return 0;
}

Measured memory_bytes: 1040
root=lambda x:x if par[x]==x else root(par[x])
same=lambda x,y:root(x)==root(y)
def unite(*z):
  x,y=map(root,z)
  if x!=y:
    if rank[x]<rank[y]:
      par[x]=y
      size[y]+=size[x]
    else:
      par[y]=x
      size[x]+=size[y]
      if rank[x]==rank[y]:rank[x]+=1
n,*a=map(int,open(0).read().split())
*par,=range(n)
rank=[1]*n
size=[1]*n
b=[0]*n
for i,t in enumerate(a):b[t-1]=i
c=0
for k in b[::-1]:
  l=r=1
  if k>0 and a[k-1]>a[k]:
    l+=size[root(k-1)]
    unite(k-1,k)
  if k+1<n and a[k+1]>a[k]:
    r+=size[root(k+1)]
    unite(k+1,k)
  c+=l*r*a[k]
print(c)

Measured memory_bytes: 32540
#include <iostream>
#include <cmath>
#include <cstdio>
#define DEFAULT 100000
#define EPS 1e-10
using namespace std;

typedef long long ll;

double ceiler(double start) {
    //cout << start << endl;
    start /= 1000;
   // start += EPS;
    //cout << "start:" << start << endl;
    start = ceil(start);
    start *= 1000;
    return(start);
}

void check(int num) {
    cout << ceiler(num) << endl;
}

int main(void) {
    double start = DEFAULT;
    int num; cin >> num;
    for(int r = 0; r < num; r++) {
        start *= 1.05;
        start = ceiler(start);
        //cout << start << endl;
    }
    printf("%d\n", (int)start);
    return(0);
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint& a) { if ((x += a.x) >= mod) x -= mod; return *this;}
    mint& operator++() { return *this += mint(1); }
    mint& operator-=(const mint& a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator--() { return *this -= mint(1); }
    mint& operator*=(const mint& a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint& a) const { mint res(*this); return res+=a; }
    mint operator-(const mint& a) const { mint res(*this); return res-=a; }
    mint operator*(const mint& a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const {
        mint res = mint(1),a(*this);
        while(t > 0) {
            if(t&1) res *= a;
            t >>= 1;
            a *= a;
        }
        return res;
    }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint& a) { return *this *= a.inv(); }
    mint operator/(const mint& a) const { mint res(*this); return res/=a; }
};
ostream& operator<<(ostream& os,const mint& m) { return os << m.x; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    string s,t;
    cin >> n >> s >> t;
    map<char,mint> mp;
    mp[s[0]] += 1;
    rep2(i,1,n) {
        mint now = mp[t[i]];
        if(i == n-1) {
            cout << now << endl;
            return 0;
        }
        mp[s[i]] += now;
    }
}



Measured memory_bytes: 3312
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n';

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	double h, a;
	cin >> h >> a;
	cout << ceil(h / a);
}



Measured memory_bytes: 512
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

vvecllong dp;

int ctoi(char c) {
    switch (c) {
        case '0': return 0;
        case '1': return 1;
        case '2': return 2;
        case '3': return 3;
        case '4': return 4;
        case '5': return 5;
        case '6': return 6;
        case '7': return 7;
        case '8': return 8;
        case '9': return 9;
        default: return 0;
    }
};

int main(void) {
    string S;
    cin >> S;

    llong lenS = S.length();
    dp = vvecllong(S.length() + 1, vecllong(13, 0));
    dp[0][0] = 1;

    llong digitMask = 1;
    FORS(digit, 1, lenS + 1) {
        if(S[lenS - digit] == '?') {
            FOR(d, 13) {
                FOR(k, 10) {
                    llong m = (d - k * digitMask) % 13;
                    if(m < 0) {
                        m += 13;
                    }
                    dp[digit][d] += dp[digit - 1][m] % MOD;
                    dp[digit][d] %= MOD;
                }
            }
        } else {
            llong a = ctoi(S[lenS - digit]);

            FOR(d, 13) {
                llong m = (d - a * digitMask) % 13;
                if(m < 0) {
                    m += 13;
                }
                dp[digit][d] += dp[digit - 1][m] % MOD;
                dp[digit][d] %= MOD;
            }
        }
        digitMask *= 10;
        digitMask %= 13;
    }

    llong ans = (dp[lenS][5]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13696
#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, M;
vector<vector<int>> G;

int main() {
  cin >> N >> M;
  G.resize(N, vector<int>(N, 0));

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a][b] = 1;
    G[b][a] = 1;
  }

  vector<int> path(N - 1);
  rep(i, N - 1) path[i] = i + 1;

  int ans = 0;
  do {
    int u = 0;
    for (int v : path) {
      if (!G[u][v]) {
        --ans;
        break;
      }
      u = v;
    }
    ++ans;
  } while (next_permutation(path.begin(), path.end()));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n,k;cin >> n >> k;
    vl v(n);rep(i,n)cin >> v[i];
    sort(all(v));
    vector<ll> min,pls;
    ll a=0,b=0,c=0;
    rep(i,n){
        if(v[i]<0)min.pb(-v[i]),a++;
        else if(!v[i])b++;
        else pls.pb(v[i]),c++;
    }
    rev(all(min));
    ll mc=a*c,zc=b*(a+c)+b*(b-1)/2;//pc=c*(c-1)/2+a*(a-1)/2;
    if(k>mc+zc){
        k-=mc+zc;
        ll ok=INF,ng=-1;
        //rev(all(min));
        while(abs(ok-ng)>1){
            ll mid=(ok+ng)/2;
            ll res=0;
            rep(i,pls.size()){
                ll key=mid/pls[i];
                res+=upper_bound(all(pls),key)-pls.begin();
                if(key>=pls[i])res--;
            }
            rep(i,min.size()){
                ll key=mid/min[i];
                res+=upper_bound(all(min),key)-min.begin();
                if(key>=min[i])res--;
            }
            //cout << mid <<" " << res/2 <<endl;
            if(res/2>=k)ok=mid;
            else ng=mid;
        }
        cout << ok <<endl;
    }
    else if(k>mc)cout << 0 <<endl;
    else{
        k=mc-k+1;
        ll ok=INF,ng=-1;
        //rev(all(min));
        while(abs(ok-ng)>1){
            ll mid=(ok+ng)/2;
            ll res=0;
            rep(i,pls.size()){
                ll key=mid/pls[i];
                res+=upper_bound(all(min),key)-min.begin();
                //if(key>=pls[i])res--;
            }
            /*rep(i,min.size()){
                ll key=mid/min[i];
                res+=upper_bound(all(min),key)-min.begin();
                if(key>=min[i])res--;
            }*/
            //cout << mid <<" " << res/2 <<endl;
            if(res>=k)ok=mid;
            else ng=mid;
        }
        cout << -ok <<endl;
    }
}


Measured memory_bytes: 7032
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long int
#define tc int t; cin>>t; while(t--)
#define inn ll arr[n]; for(int i=0;i<n;i++) cin>>arr[i];
#define fora(i,n)for(ll i=0;i<n;i++)
#define forb(i,a,n) for(int i=a;i<n;i++)
#define MOD 1000000007
template<class T> T power(T N,T P){ return (P==0)?  1: N*power(N,P-1);}

int main()
{
 //THIS CODE IS CREATED BY ANSHJAIN18
 ll n;
 cin>>n;
 string s;
 cin>>s;
 if(n&1)
     cout<<"No";
 else
 {
     ll flag=0;
     ll a=n/2;
     for(ll i=0;i<n/2;i++)
     {
         if(s[i]!=s[i+a])
         {
             flag=1;
             break;
         }

     }
     if(flag)
         cout<<"No";
     else cout<<"Yes";

 }




return 0;


}

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

int main() {
  int a,b,x;
  cin >> a >> b ;
  x = a*b;
  
  if ( x % 2 == 0 ){
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl ;
  }
  
  
}


Measured memory_bytes: 256
N=int(input())
hlist=list(map(int,input().split()))
ans=min(hlist)
if len(hlist)==1:
    print(ans)
else:
    if max(hlist)==min(hlist):
        print(ans)
    else:
        for i in range(min(hlist)+1,max(hlist)+1):
            for j in range(len(hlist)-1):
                if hlist[j]>=i and hlist[j+1]<i:
                    ans+=1
            if hlist[len(hlist)-1]>=i:
                ans+=1
        print(ans)  

Measured memory_bytes: 3064
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
            var v = line[0];
            var e = line[1];
            var edges = new List<int[]>();
            for (var i = 0; i < e; i++)
            {
                line = ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
                edges.Add(line);
            }
            edges = edges.OrderBy(array => array[2]).ToList();
            var parents = new int[v];
            for(var i = 0; i < v; i++)
            {
                parents[i] = i;
            }

            var cost = 0;
            foreach(var edge in edges)
            {
                if(GetRoot(parents, edge[0]) != GetRoot(parents, edge[1]))
                {
                    cost += edge[2];
                    Unite(parents, edge[0], edge[1]);
                }
            }

            WriteLine(cost);
        }

        private static int GetRoot(int[] parents, int node)
        {
            if (parents[node] == node)
            {
                return node;
            }
            return parents[node] = GetRoot(parents, parents[node]);
        }

        private static void Unite(int[] parents, int x, int y)
        {
            x = GetRoot(parents, x);
            y = GetRoot(parents, y);

            if (x == y)
            {
                return;
            }
            parents[x] = y;
        }
    }
}



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

int main(){
    int n,dif;
    while(cin>>n){
if(n==0)break;
        dif=1000000;
        int a[1000];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
     sort(a,a+n);
for(int i=0;i<n-1;i++)
        if(max(a[i]-a[i+1], a[i+1]-a[i])<dif)dif=max(a[i]-a[i+1], a[i+1]-a[i]);

cout<<dif<<endl;
    }
    return 0;
}

Measured memory_bytes: 3008
n = int(input())
d, x = map(int, input().split())
a = []
for i in range(n):
    a.append(int(input()))

k = []
for i in range(n):
    count = 0
    day = d
    while True:
        day -= (count * a[i]) + 1
        if day >= 0:
            count += 1
            day = d
        else:
            k.append(count)
            break
total = sum(k) + x
print(total)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
typedef struct _alpha{
	char w[32];
	int n;
}_alpha;
struct _alpha a[300];
int main(){
	char str[40],maxLengthA[40],maxA[40];
	int maxLengthH=-1,h;
	int max=-1,i;
	int c=0,f=0;
	while(scanf("%s",str)!=EOF){
		h=strlen(str);
		if(h>maxLengthH){
			maxLengthH=h;
			strcpy(maxLengthA,str);
		}
		for(i=0;i<c;i++){
			if(!strcmp(a[i].w,str)){
				a[i].n++;f=1;
				if(max<a[i].n){
					strcpy(maxA,str);
					max=a[i].n;
				}
			}
		}
		if(!f){
			a[++c].n=1;
			strcpy(a[c].w,str);
		}
		f=0;
	}
	printf("%s ",maxA);
	printf("%s\n",maxLengthA);
	exit(0);
}

Measured memory_bytes: 0
#include<stdio.h>

int main(void){
	int i,num,t,cnt;
	scanf("%d",&num);
	//最初に1桁目をtに入力
	t = num % 10;
	num /= 10;
	cnt = 1;
	while(1){
		//tに2~桁目を入力
		if(t == (num%10)){
			cnt++;
			if(cnt==3)break;
		}else {
			t = num%10;
			cnt=1;
			
		}
		if(num/10==0)break;
		num /= 10;
		
	}
	
	if(cnt == 3)printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<int,int> P;
typedef struct pair<int,P> P2;

vector<ll> v[28];
vector<ll> v2;

int d[100001]={};
int num[100001]={};
const ll INF=1000000000000000001;
int main() {

	int n,l;
	cin>>n>>l;
	int p=0;
	for(int i=1;i<n+1;++i){
		cin>>d[i];
		int k=d[i]+d[i-1];
		if(k>=l)p=i;
	}
	if(p==0){
		cout<<"Impossible"<<endl;
	}else{
		cout<<"Possible"<<endl;
		for(int i=1;i<p-1;++i){
			cout<<i<<endl;
		}
		for(int i=n-1;i>p-1;--i){
			cout<<i<<endl;
		}
		cout<<p-1<<endl;
	}
	return 0;
}


Measured memory_bytes: 1152
a, b, m = input().split()
a, b, m = int(a), int(b), int(m)
a_values = input().split()
b_values = input().split()
m_values = {}
for i in range(m):
    m_values[i] = input().split()

min_num = int(a_values[int(m_values[0][0]) - 1]) + int(b_values[int(m_values[0][1]) - 1]) - int(m_values[0][2])
for i in range(1, m):
    now = int(a_values[int(m_values[i][0]) - 1]) + int(b_values[int(m_values[i][1]) - 1]) - int(m_values[i][2])
    if min_num > now:
        min_num = now
now = int(min(a_values)) + int(min(b_values))
if min_num > now:
    print(now)
else:
    print(min_num)

Measured memory_bytes: 58984
import java.util.*;
class Main
{
  public static void main(String []args)
  {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    String s=sc.next();
    if(a<3200)
      System.out.println("red");
    else
      System.out.println(s);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int n,m; cin >> n >> m;
    int A[m];
    rep(i,m) cin >> A[i];
    int dp[n+1];
    rep(i,n+1){
        dp[i]=INF;
    }
    dp[0]=0;
    rep(i,m+1){
        rep(j,n+1){
            if(j-A[i]>=0){
                dp[j]=min(dp[j-A[i]]+1,dp[j]);
            }
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=998244353;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
vector<int>kaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    //if(!kaijo[0])init_fact(2000010);
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
signed main(){
    string s;
    cin>>s;
    int a=stoi(s.substr(0,2));
    int b=stoi(s.substr(2,2));
    if(1<=b&&b<=12){
        if(1<=a&&a<=12)puts("AMBIGUOUS");
        else puts("YYMM");
    }
    else{
        if(1<=a&&a<=12)puts("MMYY");
        else puts("NA");
    }
    return 0;
}

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

typedef long long ll;
#define re(n) cin >> n
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define ff(i,x,n) for(ll i=(int)x;i<(int)n;i++)
#define f(i,n) ff(i,0,n)
#define fast std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define te(t) ll t; re(t); while(t--)
#define MOD 1000000007

int main(){
	fast;
	ll n;
	re(n);
	ll a=0, b=0, c=0;
	f(i, n){
		ll x, y, z;
		re(x >> y >> z);
		ll ta, tb, tc;
		ta = max(b+x, c+x);
		tb = max(a+y, c+y);
		tc = max(b+z, a+z);
		a = ta; b = tb; c = tc;
	}
	cout << max(a, max(b, c)) << "\n";
	return 0;
}


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

int main(){
	
	int n;
	cin>>n;
	vector<int>a(n);
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(n==1){
		cout<<0<<endl;
		return 0;
	}
	sum=(sum)/n;
	int ans1=0,ans2=0,ans3=0;
	for(int i=0;i<n;i++){
		int temp=abs(a[i]-sum);
		ans1+=temp*temp;
	}
	sum+=1;
	for(int i=0;i<n;i++){
		int temp=abs(a[i]-sum);
		ans2+=temp*temp;
	}
	/*sum-=2;
	for(int i=0;i<n;i++){
		int temp=abs(a[i]-sum);
		ans3+=temp*temp;
	}*/
	cout<<min({ans1,ans2})<<endl;
	
	return 0;
}


Measured memory_bytes: 3548
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <iomanip>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

int X[55], Y[55];

int main() {
    int N, K;
    ll minv=5e18;
    cin >> N >> K;
    
    rep(i,N) cin >> X[i] >> Y[i];
    
    rep(i,N){
        rep(j,N){
            rep(k,N){
                rep(l,N){
                    int left = X[i], right = X[j], upper = Y[k], lower = Y[l];
                    if( left > right || upper < lower ) continue;
                    
                    int cnt=0;
                    rep(t,N){
                        if ( X[t] >= left && X[t] <= right && Y[t] >= lower && Y[t] <= upper ) cnt++;
                    }
                    
                    if( cnt>=K && (ll)(upper-lower)*(right-left) < minv ) minv = (ll)(upper-lower)*(right-left);
                }
            }
        }
    }
    cout1(minv);
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v) cerr << #v << ":"; rep(i, v.size()) cerr << " " << v[i]; cerr << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

bool table[1010101];
int cnt[1010101];

void table_init(vector<int> &P) {
    sort(all(P));
    P.erase(unique(all(P)), P.end());
    for(auto p : P) {
        if (table[p]) continue;
        for(int i = 2 * p; i < 1010101; i += p) {
            table[i] = 1;
        }
    }
}

void solve() {
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i, n) {
        cin >> A[i];
        cnt[A[i]]++;
    }
    table_init(A);
    int ans = 0;
    for(auto a : A) {
        if (cnt[a] == 1 && !table[a]) {
            ans++;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 8976
#include <iostream>
#include <utility>
#include <algorithm>
typedef long long ll;
using namespace std;

ll H[5010], P[5010], dp[5010], lmax=1e12;
pair<pair<ll, ll>, int> pr[5010];

int main() {
	int N;
	cin >> N;
	for(int i=0; i<N; ++i){
		cin >> H[i] >> P[i];
		pr[i]=make_pair(make_pair(H[i]+P[i], P[i]), i);
	}
	sort(pr, pr+N);
	dp[0]=0;
	for(int i=1; i<=N+1; ++i) dp[i]=lmax;
	for(int i=0; i<N; ++i){
		int t=pr[i].second;
		for(int j=i; j>=0; --j){
			if(dp[j]<=H[t]){
				dp[j+1]=min(dp[j+1], dp[j]+P[t]);
			}
		}
	}
	int ans=0;
	while(dp[ans+1]<lmax) ++ans;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512