akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int a,b,c;
  int x,y,z;
  string s;
  string anss;
  int ans = 0;
  cin >> a >> b;
  cout << (a==b ? "Yes" : "No") << endl;
  // cout << ans << endl;
}


Measured memory_bytes: 764
#include <iostream>

using namespace std;

int main() {
	int a, b, c, d;
	
	cin >> a >> b >> c >> d;
	
	while (1) {
		c -= b;
		if (c <= 0) {
			cout << "Yes" << endl;
			return 0;
		}
		a -= d;
		if (a <= 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>

using namespace std;

class Stu{
public:
    int m;
    int f;
    int r;
    Stu(int _m, int _f, int _r) : m(_m), f(_f), r(_r) {}
};

int main(){
    int m, f, r;
    vector<Stu> data;
    while(1){
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r == -1) break;
        data.push_back(Stu(m, f, r));
    }

    for(vector<Stu>::size_type i = 0; i < data.size(); i++){
        if(data[i].m == -1 || data[i].f == -1){
            cout << "F" << endl;
            continue;
        }

        if(data[i].m + data[i].f >= 80)
            cout << "A" << endl;
        else if (data[i].m + data[i].f >= 65 && data[i].m + data[i].f < 80)
            cout << "B" << endl;
        else if (data[i].m + data[i].f >= 50 && data[i].m + data[i].f < 65)
            cout << "C" << endl;
        else if (data[i].m + data[i].f >= 30 && data[i].m + data[i].f < 50)
            if(data[i].r >= 50)
                cout << "C" << endl;
            else
                cout << "D" << endl;
        else
            cout << "F" << endl;
    }
    
    return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n>>d>>x;
      rep(i,n){
        cin>>a;
        cnt=1;
        while(1){
          ans++;
          cnt+=a;
          if(cnt>d)break;
        }
      }
      Cout(ans+x);
     

       
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    while(cin>>n)
    {
        int x[105];
        for(int i=1;i<=n;i++)
            cin>>x[i];
        ll sum=1e18;
        for(int i=1;i<=100;i++)
        {
            ll tmp=0;
            for(int j=1;j<=n;j++)
            {
                tmp+=(x[j]-i)*(x[j]-i);
            }
            if(tmp<sum)
                sum=tmp;
        }
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<ctype.h>
#include<stdlib.h>
int cmpfunc(const void *a,const void *b){
    return *(int*)a-*(int*)b;
}
int main()
{
    int n,k,sum=0;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
    qsort(a,n,sizeof(int),cmpfunc);
    for(int i=0;i<k;i++)
    sum+=a[i];
    printf("%d",sum);
}

Measured memory_bytes: 1744
import java.util.Scanner;

public class Main {
  private static Scanner sc;

  public static void main(String[] args) {
    sc = new Scanner(System.in);
    new Main().solve();
  }


  private void solve() {
    int A = sc.nextInt();
    int B = sc.nextInt();
    System.out.println((A - 1) * (B - 1));
  }
}



Measured memory_bytes: 20052
s=input()
n=int(len(s))
count=0
ans=0
for i in range(n):
  if s[i]=='A' or s[i]=='T' or s[i]=='G' or s[i]=='C':
    count+=1
    if ans<count:
      ans=count      
  else:
    count=0

else:
  print(max(count,ans))

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

int main(){
  int n;cin >> n;
  string s;cin >> s;
  if(n%2 == 0){
    rep(i,n/2){
      if(s[i] != s[i+n/2]){cout << "No" << endl;return 0;}
    }
  } else {
    cout << "No" << endl;return 0;
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

N, K = input_nums()
R, S, P = input_nums()
T = input()

hands = {'r':P, 's':R, 'p':S}
b = [1] * N
score = 0
for i in range(N):
    if i > K - 1 and T[i] == T[i-K]:
        b[i] = 1 - b[i-K]
    score += hands[T[i]] if b[i] == 1 else 0
print(score)


Measured memory_bytes: 40688
import java.util.*;


class Main{
	public static void main(String args[]){
		
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		String[] kinds = new String[n];
		
		int ans=1;
		
		for(int i=0;i<n;i++){
			kinds[i] = sc.next();
		}
		
		Arrays.sort(kinds);
		
		for(int i=1;i<n;i++){
		  		
		//System.out.print(kinds[i]);
			if(kinds[i].equals(kinds[i-1])==false)ans++;
		}
		
		System.out.print(ans);
	}
}
	




Measured memory_bytes: 70016
N = int(raw_input())
ts = map(int, raw_input().split())
vs = map(int, raw_input().split())

vs.append(0)

for i in xrange(N-1, -1, -1):
  vs[i] = min(vs[i], vs[i+1] + ts[i])

def dist(vstart, vend, time):
  return time * (min(vstart, vend) + (abs(vstart - vend) / 2.0))

v = 0
ans = 0.0
for i in xrange(N):
  a = min(ts[i], vs[i] - v)
  vs[i] = min(vs[i], v + a)
  b = max(0, vs[i] - vs[i+1]) # <= ts[i]
  c = ts[i] - a - b
  #print i, v, vs[i], ts[i], '   ', a, c, b

  if c >= 0:
    ans += dist(v, vs[i], a) + dist(vs[i], vs[i], c) + dist(vs[i], vs[i+1], b)
  else:
    a, b = (a-b+ts[i])/2.0, (b-a+ts[i])/2.0
    ans += dist(v, v+a, a) + dist(v+a, v+a-b, b)

  v = v + a - b

print ans

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

using namespace std;
using llint = long long;

#define LOG(x) cout << "# " << #x <<" => "<< (x) <<endl

int n, ans=0;
vector<int> h;

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

    h.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> h.at(i);
    }

    // Solve
    while(true){
        int l = 0;

        while(l<n && !h.at(l)){
            l++;
        }

        if (l == n) break;

        for (int i = l; i < n; ++i) {
            if (!h.at(i)) break;
            h.at(i)--;
        }

        ans++;
    }
    
    // Output
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	int f(int lAnimal, int cAnimal, char cAnswer) {
		if (cAnswer == 'o') {
			if (cAnimal == 0) {
				return (lAnimal + 1) % 2;
			} else {
				return lAnimal;
			}
		} else {
			if (cAnimal == 0) {
				return lAnimal;
			} else {
				return (lAnimal + 1) % 2;
			}
		}
	}

	void g(int[] ret) {
		int n = ret.length;
		for (int i = 0; i < n; i++) {
			if (ret[i] == 0) {
				System.out.print('W');
			} else {
				System.out.print('S');
			}
		}
		System.out.println();
	}

	boolean h(int n, char[] s, int a0, int a1) {
		int[] ret = new int[n];
		ret[0] = a0;
		ret[1] = a1;
		for (int i = 2; i < n; i++) {
			ret[i] = f(ret[i - 2], ret[i - 1], s[i - 1]);
		}
		if (f(ret[n - 2], ret[n - 1], s[n - 1]) == ret[0] && f(ret[n - 1], ret[0], s[0]) == ret[1]) {
			g(ret);
			return true;
		}
		return false;
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		if (h(n, s, 1, 1)) return;
		if (h(n, s, 1, 0)) return;
		if (h(n, s, 0, 1)) return;
		if (h(n, s, 0, 0)) return;
		System.out.println(-1);
}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 35076
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>

void make_hand(std::vector<int> &hand) {
    for (int i = 7; i <= 15; i++) {
        hand[i] = 1;
    }
    hand[20] = 1;
    hand[24] = 1;
}

int main(void) {
    std::string s;
    const char* c;
    int now_hand;
    int search_space;
    int change_count;
    std::vector<int> hand(26, 0);
    make_hand(hand);
    std::cin >> s;
    while(s != "#") {
        c = s.c_str();
        change_count = 0;

        search_space = (int) c[0] - 97;;
        now_hand = hand[search_space];

        for (int i = 1; i < s.size(); i++) {
            search_space = (int) c[i] - 97;;
            if (hand[search_space] != now_hand) {
                change_count++;
                now_hand = hand[search_space];
            }
        }
        std::cout << change_count << std::endl;
        
        std::cin >> s;
    }

    return EXIT_SUCCESS;
}

Measured memory_bytes: 3172
#include <stdio.h>
int main()
{
	int	A;	/* 入力される整数A */
	int	B;	/* 入力される整数B */
	int	C;	/* 入力される整数C */

	scanf("%d %d %d", &A, &B, &C);
	if(A == B){
		if(A != C)
			printf("Yes\n");
		else
			printf("No\n");
	}
	else if(A == C){
		if(A != B)
			printf("Yes\n");
		else
			printf("No\n");
	}
	else if(B == C){
		if(B != A)
			printf("Yes\n");
		else
			printf("No\n");
	}
	else
		printf("No\n");
	return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    string S;
    cin >> S;
    int res = 0;
    int l = 0;
    int cnt = 0;
    for(int r = 0;r < n; r++){
		if(S[r]=='0'){
			if(r==0 || S[r-1]=='1') cnt++;
		}
		if(cnt > k){
			while(l < S.size() && S[l]=='1') l++;
			while(l < S.size() && S[l]=='0') l++;
			cnt--;
		}
		res=max(res,r-l+1);
	}
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
//
//  abc168_a.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll INF = 1000000007;
#define PI 3.14159265

const int MAX = 110000;

ll fac[MAX], finv[MAX], inv[MAX];

std::vector<int> permutations;

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

int main() {
  ll n;
  std::cin >> n;

  if (n%10 == 2 || n%10 == 4 || n%10 == 5 || n%10 == 7 || n%10 == 9) {
    std::cout << "hon" << std::endl;
  }
  else if (n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8) {
    std::cout << "pon" << std::endl;
  }
  else if (n%10 == 3) {
    std::cout << "bon" << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	ll N, M;
	ll x[1010], y[1010], z[1010];
	ll maxn = -(1LL << 60);
	cin >> N >> M;
	for (int i = 0; i < N; ++i) {
		cin >> x[i] >> y[i] >> z[i];
	}
	ll ans = 0;
	for (int i = 0; i < 8; ++i) {
		vector<ll>vec;
		for (int j = 0; j < N; ++j) {
			ll S;
			ll A = x[j] * (i & 1 ? 1 : -1);
			ll B = y[j] * (i & 2 ? 1 : -1);
			ll C = z[j] * (i & 4 ? 1 : -1);
			S = A + B + C;
			vec.push_back(S);
		}
		sort(vec.begin(), vec.end(), greater<ll>());
		ll ans = 0;
		for (int j = 0; j < M; ++j) {
			ans += vec[j];
		}
		maxn = max(maxn, ans);
	}
	cout << maxn << endl;
	return 0;
}



Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    double t,a;
    cin>>t>>a;
    double temp=DBL_MAX;
    int idx;
    vector<double> x(n);
    forn(i,n){
        cin>>x[i];
        double res=t-x[i]*0.006;
        if(abs(a-res)<temp){
            temp = abs(a-res);
            idx = i;
        }
    }
    
    cout<<idx+1<<endl;
    return 0;
}



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

void dfs(int n, int a, int N, int M, int Q,
	int* arr,	const int (*abcd)[4], int* ans) {
	if(n == N) {
		int sum = 0;
		for(int i = 0; i < Q; ++i)
			if(arr[abcd[i][1]] - arr[abcd[i][0]] == abcd[i][2])
				sum += abcd[i][3];
		if(*ans < sum)*ans = sum;
		
		return;
	}
	for(; a <= M; ++a) {
		arr[n] = a;
		dfs(n + 1, a, N, M, Q, arr, abcd, ans);
	}
}

int main(void) {
	int N, M, Q;
	scanf("%d %d %d", &N, &M, &Q);
	int(*abcd)[4] = (int(*)[4])malloc(sizeof(int[4]) * Q);
	for(int i = 0; i < Q; ++i) {
		for(int j = 0; j < 4; ++j)
			scanf("%d", &abcd[i][j]);
		--abcd[i][0]; --abcd[i][1];
	}
	int ans = 0;
	int* arr = (int*)malloc(sizeof(int) * N);
	dfs(0, 1, N, M, Q, arr, abcd, &ans);
	printf("%d\n", ans);
	free(arr);
	free(abcd);
}


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

string arrows;
char prev;

int main() {
    int tc;
    cin>>tc;
    while(tc--) {
        cin>>arrows;

        bool flag = true,f = true;
        for(int i=1; i<arrows.length(); ++i)
            if(arrows[i] == arrows[i-1]) flag = false;

        //use left leg at first
        for(int i=1; i<arrows.length(); i+=2)
            if(arrows[i] == 'L' || arrows[i-1] == 'R') f = false;

        //use right leg at first
        for(int i=1; i<arrows.length(); i+=2)
            if(!f && (arrows[i] == 'R' || arrows[i-1] == 'L')) flag = false;

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

Measured memory_bytes: 1140
import java.util.Arrays;
import java.util.HashSet;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int x = scanner.nextInt();
			int y = scanner.nextInt();
			int z = scanner.nextInt();
			int k = scanner.nextInt();
			scanner.nextLine();
			long[] a = new long[x];
			for (int i = 0; i < x; i++) {
				a[i] = scanner.nextLong();
			}
			scanner.nextLine();
			Arrays.sort(a);

			long[] b = new long[y];
			for (int i = 0; i < y; i++) {
				b[i] = scanner.nextLong();
			}
			scanner.nextLine();
			Arrays.sort(b);

			long[] c = new long[z];
			for (int i = 0; i < z; i++) {
				c[i] = scanner.nextLong();
			}
			scanner.nextLine();
			Arrays.sort(c);

			long[] sum = new long[k];
			Queue<Sum> queue = new PriorityQueue<>((s1, s2) -> {
				if (s1.sum > s2.sum) {
					return -1;
				} else if (s1.sum == s2.sum) {
					return 0;
				} else {
					return 1;
				}
			});
			Set<Sum> set = new HashSet<>();
			Sum first = new Sum(a[x - 1] + b[y - 1] + c[z - 1], x - 1, y - 1, z - 1);
			queue.add(first);
			set.add(first);
			for (int j = 0; j < k; j++) {
				Sum now = queue.remove();
				sum[j] = now.sum;
				Sum sum1 = null, sum2 = null, sum3 = null;
				if (now.ia > 0) {
					sum1 = new Sum(a[now.ia - 1] + b[now.ib] + c[now.ic], now.ia - 1, now.ib, now.ic);
				}
				if (now.ib > 0) {
					sum2 = new Sum(a[now.ia] + b[now.ib - 1] + c[now.ic], now.ia, now.ib - 1, now.ic);
				}
				if (now.ic > 0) {
					sum3 = new Sum(a[now.ia] + b[now.ib] + c[now.ic - 1], now.ia, now.ib, now.ic - 1);
				}
				if ((null != sum1) && !set.contains(sum1)) {
					queue.add(sum1);
					set.add(sum1);
				}
				if ((null != sum2) && !set.contains(sum2)) {
					queue.add(sum2);
					set.add(sum2);
				}
				if ((null != sum3) && !set.contains(sum3)) {
					queue.add(sum3);
					set.add(sum3);
				}
			}
			Arrays.stream(sum).forEach(System.out::println);
		}
	}

	private static class Sum {
		long sum;
		int ia;
		int ib;
		int ic;

		Sum(long sum, int ia, int ib, int ic) {
			super();
			this.sum = sum;
			this.ia = ia;
			this.ib = ib;
			this.ic = ic;
		}

		@Override
		public int hashCode() {
			return Objects.hash(sum, ia, ib, ic);
		}

		@Override
		public boolean equals(Object obj) {
			if (null == obj) {
				return false;
			} else if (obj instanceof Sum) {
				return (sum == ((Sum) obj).sum) && (ia == ((Sum) obj).ia) && (ib == ((Sum) obj).ib)
						&& (ic == ((Sum) obj).ic);
			}
			return false;
		}

		@Override
		public String toString() {
			return "sum=" + sum + ",ia=" + ia + ",ib=" + ib + ",ic=" + ic;
		}
	}
}

Measured memory_bytes: 37188
N = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

ans = 0
N.times do |i|
  c = [a[i], b[i]].min
  ans += c
  a[i] -= c
  b[i] -= c

  c2 = [a[i+1], b[i]].min
  ans += c2
  a[i+1] -= c2
  b[i] -= c2
end

p ans


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

const int N = 101;
const int W = 10001;

int dp[N][W];
int weight[N];
int value[N];

int main()
{
    int n, w;
    cin >> n >> w;
    for (int i=0; i < n; ++i) {
        cin >> value[i] >> weight[i];
    }

    // i = ????????????????????§????????¨???
    // j = ??????????????§?????????????????§
    for (int j=0; j <= w; ++j) {
        for (int i=0; i <= n; ++i) {
            int a = (i-1 >= 0 ? dp[i-1][j] : 0);
            int b = (j-1 > 0 ? dp[i][j-1] : 0);
            int c = (i > 0 && j-weight[i-1] >= 0 ? dp[i-1][j-weight[i-1]]+value[i-1] : 0);
            dp[i][j] = max(max(a, b), c);
        }
    }

    cout << dp[n][w] << endl;

    return 0;
}

Measured memory_bytes: 7036
#include <math.h>
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>

#define nl                std::cout << "\n"
#define in(x)             std::cin  >> (x)
#define out(x)            std::cout << (x) << " "
#define err(x)            std::cerr << #x << " = " << (x) << " | "

#define inn(x)            int x; in(x)
#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)
#define rrep(i, n)        for (int i = (n) - 1; i > -1; --i)

#define no                puts("NO")
#define yes               puts("YES")

using ll  = long long int;
using vi  = std::vector<int>;
using ii  = std::pair<int, int>;
using iii = std::pair<ii, int>;
using vii = std::vector<ii>;

const int N = 1010101;
const int MD = 1e9 + 7;

void solve() {
    inn(n);
    int a[n]; rep(i, n) in(a[i]);
    int ans = 0;
    repr(i, 1, n - 1) {
        int min = *std::min_element(a + i - 1, a + i + 2);
        int max = *std::max_element(a + i - 1, a + i + 2);
        if (min != a[i] && max != a[i]) {
            ans++;
        }
    }
    out(ans);
}
int main() {
    std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

    //int t; in(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

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

struct UnionFind
{
	vector<ll> par, wei;

	UnionFind(ll n) {init(n);}
	
	void init(ll n)
	{
		par.assign(n, -1);
		wei.assign(n, 0);
	}

	ll root(ll x)
	{
		if (par[x] < 0) return x;
		else
		{
			ll r = root(par[x]);
			wei[x] += wei[par[x]];
			return par[x] = r;
		}
	}

	ll weight(ll x)
	{
		root(x);
		return wei[x];
	}

	bool merge(ll x, ll y, ll w)
	{
		w += weight(x);
		w -= weight(y);
		
		x = root(x);
		y = root(y);

		if (x == y) return false;

		if (rank(x) < rank(y)) swap(x, y), w *= -1;

		// rank(x) > rank(y)
		par[x] += par[y];
		par[y] = x;

		wei[y] = w;
		return true;
	}

	ll diff(ll x, ll y)
	{
		return weight(y) - weight(x);
	}

	bool issame(ll x, ll y)
	{
		return root(x) == root(y);
	}

	ll rank(ll x)
	{
		return -par[root(x)];
	}
};

int main(int argc, char **argv)
{
	ll N, M; cin >> N >> M;
	UnionFind uf(N);

	REP(i, M)
	{
		ll l, r, d; cin >> l >> r >> d;
		--l, --r;
		if (uf.issame(l, r))
		{
			if (uf.diff(l, r) != d)
			{
				std::cout << "No" << std::endl;
				return 0;
			}
		}
		else
		{
			uf.merge(l, r, d);
		}
	}

	std::cout << "Yes" << std::endl;
	
}


Measured memory_bytes: 1920
#include <stdio.h>
int max(int a, int b){return a>b?a:b;}
int main(void){
    int h,w,k;
    scanf("%d%d%d",&h,&w,&k);
    long long dp[h+1][w+2],mod=1000000007,n[8]={1,2,3,5,8,13,21,24};
    for (int i=0; i<h+1; i++){
        for (int j=0; j<=w; j++){
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    for (int i=1; i<h+1; i++){
        for (int j=0; j<w; j++){
            if (j==0){
                dp[i][j]=(dp[i][j]+dp[i-1][j]*n[max(0,w-2)])%mod;
                dp[i][j]=(dp[i][j]+dp[i-1][j+1]*n[max(0,w-3)])%mod;
            } else if (j==w-1){
                dp[i][j]=(dp[i][j]+dp[i-1][j]*n[max(0,w-2)])%mod;
                dp[i][j]=(dp[i][j]+dp[i-1][j-1]*n[max(0,w-3)])%mod;
            } else {
                dp[i][j]=(dp[i][j]+dp[i-1][j]*n[max(0,j-1)]*n[max(0,w-j-2)])%mod;
                dp[i][j]=(dp[i][j]+dp[i-1][j-1]*n[max(0,j-2)]*n[max(0,w-j-2)])%mod;
                dp[i][j]=(dp[i][j]+dp[i-1][j+1]*n[max(0,j-1)]*n[max(0,w-j-3)])%mod;
            }
        }
    }
    printf("%lld\n",dp[h][k-1]%mod);
	return 0 ;
}

Measured memory_bytes: 128
#include <stdio.h>

void trace(int A[], int N){
 int i;
 for (i = 0; i < N; i++) {
   /* code */
   if ( i > 0) printf(" ");
   printf("%d", A[i]);
 }
 printf("\n");
}

void insertionSort(int A[], int N){
  int j,i,v;
  for (i = 1; i < N; i++) {
    v = A[i];
    j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j + 1] = A[j];
      j--;
      /* code */
    }
    A[j + 1] = v;
    trace(A, N);
    /* code */
  }
}

int main(){
  int N, i, j;
  int A[100];

  scanf("%d", &N);
  for ( i = 0; i < N; i++) {
    /* code */
    scanf("%d",&A[i]);
  }
  trace(A,N);
  insertionSort(A,N);
}

Measured memory_bytes: 2604
def canput( list, n )
	return true if list.size == 0
	if list[ -1 ] < n
		return true
	else
		return false
	end
end

def put_try( listB, listC, left )

	return true if left.size == 0

	newleft = left.dup
	n = newleft.shift
	if canput( listB, n ) == true
		newlistB = listB.dup
		newlistC = listC.dup
		newlistB << n 
		b = put_try( newlistB, newlistC, newleft )
		return true if b
	end
	if canput( listC, n ) == true
		newlistB = listB.dup
		newlistC = listC.dup
		newlistC << n 
		b = put_try( newlistB, newlistC, newleft )
		return true if b
	end
	return false
end

def checkball( balls )
	listB = Array.new	
	listC = Array.new
	listB << balls.shift

	return put_try( listB, listC, balls )
end

answers = Array.new
num = $stdin.gets.chomp.to_i
num.times{
	list = $stdin.gets.chomp.split( /\s/ ).map{ |n| n.to_i}
	answers << checkball( list )
}
answers.each{ |a|
	if a
		puts "YES"
	else
		puts "NO"
	end
}


Measured memory_bytes: 6092
#pragma GCC optimize("O3", "unroll-loops")
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	long long w, h, x, y;
	cin >> w >> h >> x >> y;
	long double ww = w, hh = h;
	cout << setprecision(9) << fixed << ww * hh / 2 << ' ';
	if (2 * x == w && 2 * y == h)
		cout << "1\n";
	else
		cout << "0\n";
	return 0;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    vector<lint> a(n);
    REP(i, n) { cin >> a[i]; }
    lint ans=0;
    sort(ALL(a));
    int pre = 0, count = 0;
    int c = 0;

    REP(i,n){
        if(pre==a[i]){
            count++;
        }else{
            c+=count;
            count = 0;
        }
        pre = a[i];
    }
    c += count;
    //REP(i, n)//cout << a[i] << " ";

    ans =n- c - c% 2;
    cout << ans <<"\n";

    return 0;
}

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

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

  deque<char> d;
  for (int i = 0; i < S.size(); i++) d.push_back(S.at(i));
  bool dir = true;
  for (int i = 0; i < Q; i++) {
    int a, b;
    char c;
    cin >> a;
    if (a == 1) {
      dir = (dir == true) ? false : true;
      continue;
    }
    cin >> b >> c;
    if (dir == true && b == 1)
      d.push_front(c);
    else if (dir == true && b == 2)
      d.push_back(c);
    else if (dir == false && b == 1)
      d.push_back(c);
    else if (dir == false && b == 2)
      d.push_front(c);
  }

  if (!dir) reverse(d.begin(), d.end());
  for (int i = 0; i < d.size(); i++) cout << d.at(i);
  cout << endl;
}

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

#define ll long long int
#define inv(name,Type,size) vector<Type> name(size);for(int index=0;index<size;index++) cin>>name[index];
#define F(a,n,i) for(int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define mod 1000000007
#define modpro 99824435

const int d8i[8]={-1,0,1,0,-1,1,1,-1},d8j[8]={0,1,0,-1,1,1,-1,-1};


void solve(){
	int n,k;
	cin>>n>>k;
	inv(a,ll,n);
	F(0,n-k,i){
		if(a[i]>=a[i+k]){
			cout<<"No"<<endl;
		}
		else cout<<"Yes"<<endl;
	}
}

int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  //int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();
}



Measured memory_bytes: 4780
function Main(input) {
	const temps = input.split(' ');
	const product　= parseInt(temps[0],10) * parseInt(temps[1], 10);
	if(product % 2 === 0) {
		console.log('Even');
	}else {
		console.log('Odd');
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
N = int(input())
ls = []
for i in range(N):
  a = int(input())
  for _ in range(a):
    x,y = map(int, input().split())
    ls.append((i,x-1,y==1))
max = 0
for i in range(2**N):
  c = 0
  hon = set()
  unhon = set()
  
  for x in range(N):
    if (i>>x)&1 == 1:
      c += 1
      
  for x,y,z in ls:
    if (i>>x)&1 == 1:
      if z:
        hon.add(y)
      else:
        unhon.add(y)
        
  if len(hon & unhon) == 0:
    flag = True
    for n in range(N):
      if (i>>n)&1 == 1:
        if n in unhon:
          flag = False
          break
      else:
        if n in hon:
          flag = False
          break
    if flag and c >= max:
      max = c
      
print(max)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		String ans;
		if ((a + b + c) < 22) {
			ans = "win";
		} else {
			ans = "bust";
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cstdio>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007
#define MAXS(x,y) (x = max(x,y))
#define MINS(x,y) (x = min(x,y))

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;

vector<int> pre, in, post;

int N;
int pos = 0;

struct Node {
  int key;
  Node *parent, *left, *right;
};


void printIn(Node *p){
  if(p == NULL)return;
  printIn(p->left);
  cout << " " << p->key;
  printIn(p->right);
}

void printPre(Node *p){
  if(p == NULL)return;
  cout << " " << p->key;
  printPre(p->left);
  printPre(p->right);
}

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

  Node *root = NULL;

  REP(i,N){
    cin >> cmd;

    

    if(cmd == "insert"){
      Node *y = NULL;
      Node *x = root;
      Node *z = (Node *)malloc(sizeof(Node));

      int v;
      cin >> v;
      z->key = v;
      z->left = NULL;
      z->right = NULL;

      while(x != NULL){
        y = x;
        if(x->key > z->key){
          x = x->left;
        }else{
          x = x->right;
        }
      }

      z->parent = y;
      if(y == NULL){
        root = z;
      }else if(z->key < y->key){
        y->left = z;
      }else{
        y->right = z;
      }

    }else{
      printIn(root);
      cout << endl;
      printPre(root);
      cout << endl;
    }
    
  }


}



Measured memory_bytes: 26588
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define inf 0x3f3f3f3f 
#define MAXN 1019191130
int main(){
	ll  n , W; cin >> n >> W;
    ll w[101] , v[101] , dp[100001];
    for(int i = 0 ; i <= 100000; ++i) dp[i] = inf;
    for(int i = 0 ; i < n ; ++i)
        cin >> w[i] >> v[i];
        dp[0] = 0;
    for(int i = 0 ; i < n ; ++i){
        for(int j =  100000 ; j >= v[i] ; j--){
            dp[j] = min(dp[j] , dp[j - v[i]] + w[i]);
        }
    }
    int j = 100001;
    while(j-- && dp[j] > W);

    cout<< j <<endl;
}

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

int main(){
	int n,m,v1,v2;
	cin >> n >> m;
	int lx,rx;
	cin >> lx >> rx;
	while(--m){
		cin >> v1 >> v2;
		lx = max(lx,v1);
		rx = min(rx,v2);
	}
	if(lx>rx)
		cout << 0 << endl;
	else
		cout << min(n-lx+1,rx-lx+1) << endl;
 return 0; 
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,r=MI()
    if n>=10:ans=r
    else:ans=r+1000-100*n
    print(ans)
    
main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl; 
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF =0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a,LL b){LL s=1;while(b>0){if(b&1)s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
LL gcd(LL a,LL b) {return b?gcd(b,a%b):a;}
int dr[2][4] = {1,-1,0,0,0,0,-1,1};
typedef pair<int,int> P;
int main(void)
{
    int A,B,C;
    cin>>A>>B>>C;
    cout<<max(0,C-(A-B))<<endl;

   return 0;
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int32_t A, B, C;
  cin >> A >> B >> C;

  bool is_okay = false;
  for (int32_t i = 1; i <= B; ++i) {
    if ((i * A) % B == C) {
      is_okay = true;
    }
  }
  if (is_okay) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
portals = [0] + list(map(int, input().split()))

visitTowns = list()
visitTimes = [0 for _ in range(N + 1)]

curTown = 1
timeBackTo = 0

curTime = 0
while True:
    if visitTimes[curTown] > 0:
        timeBackTo = visitTimes[curTown]
        break

    visitTowns.append(curTown)
    visitTimes[curTown] = curTime

    # teleport
    curTown = portals[curTown]

    curTime += 1

nonLoopCount = timeBackTo
loopSpan = len(visitTowns) - nonLoopCount

if K <= nonLoopCount:
    print(visitTowns[K])
    exit()

rem = (K - nonLoopCount) % loopSpan
print(visitTowns[nonLoopCount + rem])


Measured memory_bytes: 115056
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define tr(i,c) for(auto i=(c).begin();i!=(c).end();i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())


bool search_rec(vi& array, int left, int right, int x) {
  if (right < left || left < 0 || right >= sz(array)) return false;
  int m = (left + right) / 2;

  if (array[m] < x) return search_rec(array, m+1, right, x);
  else if (x < array[m]) return search_rec(array, left, m-1, x);
  else return true; // array[m] == x
}

bool search(vi& array, int x) {
  return search_rec(array, 0, sz(array) - 1, x);
}

int main(int argc, char **argv)
{
  int n, q;
  cin >> n;
  vi S(n);
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  //sort(all(S));
  cin >> q;
  int C = 0;
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x;
    if (search(S, x)) C++;
  }
  cout << C << endl;

  return 0;
}

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

int main()
{
	char w[11],t[1000];
	cin >> w;
	for(int i = 0;i < strlen(w);i++){
		if('A' <= w[i] && w[i] <= 'Z') w[i] += 'a' - 'A';
	}
	
	int count = 0;
	while(1){
		cin >> t;
		if(!strcmp(t,"END_OF_TEXT")) break;
		for(int i = 0;i < strlen(t);i++){
			if('A' <= t[i] && t[i] <= 'Z') t[i] += 'a' - 'A';
		}
		if(strlen(t) == strlen(w) && strcmp(w,t) == 0) count++;
		}
		
		cout << count << endl;
		return 0;
		}

Measured memory_bytes: 3044
import math

n = int(input())
res = None
for i in range(1, int(math.sqrt(n))+2):
  if n % i == 0:
    if res is None:
      res = max(len(str(i)), len(str(n//i)))
    elif max(len(str(i)), len(str(n//i))) < res:
      res = max(len(str(i)), len(str(n//i)))
print(res)

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

int dice[6] = {1, 2, 3, 4, 5, 6};

void mv(string cmd)
{
    int d[6];
    
    for(int i=0;i < 6;++i) d[i] = dice[i];

    if (cmd == "North") {
        dice[0] = d[1];
        dice[1] = d[5];
        dice[4] = d[0];
        dice[5] = d[4];
    } else if (cmd == "East") {
        dice[0] = d[3];
        dice[2] = d[0];
        dice[3] = d[5];
        dice[5] = d[2];
    } else if (cmd == "West") {
        dice[0] = d[2];
        dice[2] = d[5];
        dice[3] = d[0];
        dice[5] = d[3];
    } else if (cmd == "South") {
        dice[0] = d[4];
        dice[1] = d[0];
        dice[4] = d[5];
        dice[5] = d[1];
    } else if (cmd == "Right") {
        dice[1] = d[2];
        dice[2] = d[4];
        dice[3] = d[1];
        dice[4] = d[3];
    } else if (cmd == "Left") {
        dice[1] = d[3];
        dice[2] = d[1];
        dice[3] = d[4];
        dice[4] = d[2];
    }
}

int main()
{
    int n;
    while (cin >> n && n) {
        int ans = 1; string cmd;
        
        for(int i=0; i < n; ++i) {
            cin >> cmd;
            mv(cmd);
            ans += dice[0];
        }

        cout << ans << endl;

        for(int i=0;i < 6;++i) dice[i] = i+1;
    }

    return 0;
}

Measured memory_bytes: 1216
import java.io.*;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {
    //Solution by Sathvik Kuthuru
    public static void main(String[] args) {
        FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        Task solver = new Task();
        int t = 1;
        for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);
        out.close();
    }

    static class Task {

        public void solve(int testNumber, FastReader scan, PrintWriter out) {
            int n = scan.nextInt(), a = scan.nextInt(), b = scan.nextInt();
            for(int i = a; i <= b; i++) {
                if(i % n == 0) {
                    out.println("OK");
                    return;
                }
            }
            out.println("NG");
        }
    }

    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 32812
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list> 
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
int S[1000] = { 0 };


int main() {
	ll N,Q;
	cin >>N>>Q;
	vector<ll>Y[N];
	rep(i,Q) {
		int a;
		cin >> a;
		if (a==0) {
			int b,c;
			cin >> b>>c;
			Y[b].push_back(c);
		}
		else if (a == 1) {
			int b;
			cin >> b;
			if (0<Y[b].size()) {
				rep(j, Y[b].size() - 1) {
					cout << Y[b][j] << " ";
				}
				cout << Y[b][Y[b].size() - 1] << endl;
			}
			else {
				cout << endl;
			}
		}
		else {
			int b;
			cin >> b;
			Y[b].clear();
		}
	}
	return 0;
}





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

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Solution sol = new Solution();
		sol.solve(in, out);
		out.close();
	}

	private static class Solution {
		private void solve(InputReader in, PrintWriter out) {
			int n=in.nextInt(), k=in.nextInt();
			int[] logsLength=in.readArray(n);
			int min = 1, max = (int) 1e9 + 1000;
			while (min < max) {
				int mid = (min + max) / 2;
				if (nei(mid, logsLength, k))
					max = mid;
				else
					min = mid + 1;
			}
			out.println(min);
		}

		private boolean nei(int mid, int[] logsLength, int k) {
			for (int log : logsLength)
				k -= (log + mid - 1) / mid - 1;
			return k >= 0;
		}
	}

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

		private InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

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

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

		private int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; ++i)
				a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 55704
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a+b<c+d) cout << "Right" << endl;
  else if(a+b==c+d) cout << "Balanced" << endl; else cout << "Left" << endl;
}

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

#define int long long

using namespace std;

const int maxn = 1e6 + 10;
bool g[maxn];
int a[maxn], n;

signed main()
{
    ios::sync_with_stdio(false);
    string s;
    cin >> s;

    n = s.size() + 1;
    for (int i = 0; i < n - 1; i++)
        g[i] = s[i] == '>';

    vector<int> st{ 0 };
    if (g[n - 2])
        st.push_back(n - 1);
    for (int i = 1; i < n - 1; i++) {
        if (g[i - 1] && (!g[i])) {
            st.push_back(i);
        }
    }

    for (int u : st) {
        for (int i = u + 1, x = 1; i < n && (!g[i - 1]); i++) {
            a[i] = x++;
        }
        for (int i = u - 1, x = 1; (~i) && ((!i) || g[i - 1]); i--) {
            a[i] = x++;
        }
    }

    for (int i = 0; i < n - 1; i++) {
        if (g[i]) {
            a[i] = max(a[i], a[i + 1] + 1);
        }
    }

    int S = 0;
    for (int i = 0; i < n; i++)
        S += a[i];
    
    cout << S;

    return 0;
}

Measured memory_bytes: 8472
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define req(i,n) for(ll i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = 1e18;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}ll n, S; vector<ll> a;
const ll mod = 998244353;
int main(void) {
	cin >> n >> S; a.resize(n);
	rep(i, n) cin >> a[i];
	vector<vector<ll>> dp(n+10, vector<ll>(S + 100, 0));
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, S+1) {
			if (j + a[i] <= S) dp[i + 1][j+a[i]] += dp[i][j];
			dp[i + 1][j] += 2 * dp[i][j];
			dp[i + 1][j] %= mod;
		}
	}cout << dp[n][S] << endl;
}

Measured memory_bytes: 76292
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 200000
void inarray(ll a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    int n; cin >> n;
    ll a[n];
    inarray(a,n);
    ll d[MAX+1];
    for(int i = 0; i < MAX+1; i++) d[i] = 0;
    for(int i = 0; i < n; i++){
        d[a[i]]++;
    }
    ll ans = 0;
    for(int i = 0; i < MAX+1; i++){
        ans += (d[i]*(d[i]-1))/2;
    }
    for(int i = 0; i < n; i++){
        cout << ans - (d[a[i]]*(d[a[i]]-1))/2 + ((d[a[i]]-1)*(d[a[i]]-2))/2 << endl;;
    }
    return 0;
}

Measured memory_bytes: 5760
n,m = map(int,input().split())
start = [0]*200001
goal = [0]*200001

for i in range(m):
  a,b = map(int,input().split())
  if a == 1:
    if goal[b] == 1:
      print("POSSIBLE")
      exit()
    start[b] = 1
    a
  elif b == n:
    if start[a] == 1:
      print("POSSIBLE")
      exit()
    goal[a] = 1
print("IMPOSSIBLE")

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    int K, T;
    cin >> K >> T;
    vi a(T);
    for (int i = 0; i < T; i++) {
        cin >> a[i];
    }
    sort(all(a));
    cout << max(a[T-1]-1-(K-a[T-1]), 0) << endl;



    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    String s = sc.next();

	    if (s.equals("a") || s.equals("i") || s.equals("u") || s.equals("e") || s.equals("o")){
	    	System.out.println("vowel");
	    }else {
	    	System.out.println("consonant");
	    }
	}
}

Measured memory_bytes: 20948
import java.util.Scanner;

//Aka-beko and 40 Thieves
public class Main{

	int[][] dfa = {
			{0, 0},
			{2, 3},
			{0, 4},
			{2, 0},
			{5, 6},
			{6, 3},
			{3, 2}
	};
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			char[] s = sc.next().toCharArray();
			if(s[0]=='#')break;
			int p = 1;
			for(char t:s){
				p = dfa[p][t-'0'];
			}
			System.out.println(p==6?"Yes":"No");
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 17336
#include <vector>
#include <cstdio>
using namespace std;
class union_find{
	int *parent,*rank,n;
public:
	int root(int a){return parent[a]==a?a:(parent[a]=root(parent[a]));}
	union_find(int _n){n=_n;parent=new int[n];rank=new int[n];for(int i=0;i<n;i++)parent[i]=i,rank[i]=0;}
	~union_find(){delete []parent;delete []rank;}
	int unite(int a,int b){
		int x=root(a),y=root(b);if(x==y)return 0;
		if(rank[x]<rank[y]){
			parent[x]=y;
		}else{
			parent[y]=x;
			if(rank[x]==rank[y])rank[x]++;
		}
		return 1;
	}
};
int main(){
	int N,K;
	scanf("%d%d%d",&N,&K,&K);
	union_find uf(N+1);
	vector<int>v(N+1);
	for(int i=1;i<=K;i++){
		int c,a,b;
		scanf("%d%d%d",&c,&a,&b);
		if(c==1){
			if(v[uf.root(a)]&&v[uf.root(b)]&&v[uf.root(a)]!=v[uf.root(b)]){
				printf("%d\n",i);return 0;
			}
			if(!v[uf.root(a)])v[uf.root(a)]=v[uf.root(b)];
			if(!v[uf.root(b)])v[uf.root(b)]=v[uf.root(a)];
			uf.unite(a,b);
		}else{
			if(v[uf.root(a)]&&v[uf.root(a)]!=b){
				printf("%d\n",i);return 0;
			}
			v[uf.root(a)]=b;
		}
	}
	puts("0");
}

Measured memory_bytes: 3416