akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a[5] = {}, k;
    for (int i = 0; i < 5; i++) cin >> a[i];
    cin >> k;
    if (a[4] - a[0] > k) cout << ":(";
    else cout << "Yay!";
    return 0;
    int T;
    cin >> T;
    for (int U = 1; U <= T; U++) {
        cout << "Case #" << U << ": ";
        
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int cplc(int p0[2],int p1[2],int p2[2],int r,double s[2],double t[2]){
  int x1=p1[0]-p0[0],y1=p1[1]-p0[1],x2=p2[0]-p0[0],y2=p2[1]-p0[1];
  long long a=x1*x1+y1*y1,b=x1*x2+y1*y2,c=x2*x2+y2*y2-r*r;
  if(b*b<a*c)return 0;
  s[0]=p0[0]+x1*(b+sqrt(b*b-a*c))/a;
  s[1]=p0[1]+y1*(b+sqrt(b*b-a*c))/a;
  t[0]=p0[0]+x1*(b-sqrt(b*b-a*c))/a;
  t[1]=p0[1]+y1*(b-sqrt(b*b-a*c))/a;
  return 1;
}
int main(){
  int p[4][2],n,i,r,j=0;
  double a[2][2],e=0.000005;
  scanf("%d %d %d %d",&p[2][0],&p[2][1],&r,&n);
  while(n--){
    for(i=0;i<4;i++)scanf("%d",&p[i/2][i%2]);
    cplc(p[0],p[1],p[2],r,a[0],a[1]);
    if(fabs(a[0][0]-a[1][0])<e)j=a[0][1]+e<a[1][1]?0:1;
    else                       j=a[0][0]+e<a[1][0]?0:1;
    printf("%.9f %.9f %.9f %.9f\n",a[j][0],a[j][1],a[1-j][0],a[1-j][1]);
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
using namespace std;
typedef pair<int,int>pii;
int n;
char a[110],b[110],c[110];
int ans;
int main(){
	cin>>n;
	scanf("%s%s%s",a+1,b+1,c+1);
	for(int i=1;i<=n;i++){
		char c1=a[i],c2=b[i],c3=c[i];
		if(c1==c2&&c2==c3)continue;
		if((c1==c2&&c1!=c3)||(c2==c3&&c2!=c1)||(c3==c1&&c3!=c2))ans++;
		else ans+=2;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	int a;
	int b;
	int c;
	scanf("%d %d %d",&a,&b,&c);
	
	if(a+b+c>=22){
		printf("bust");
	}
	else if(a+b+c<22){
		printf("win");
	}
	
	
	
	
	return 0;
}

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

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

    ll n; cin >> n;
    vector<ll> a(n,0); for(ll i=0;i<n;i++) { cin >> a[i]; }
    
    sort(a.rbegin(), a.rend());

    ll ans = 0;
    int t = n - 1;

    for (int i=0; i<n; i++) {
        int lim = 2;
        if (i == 0) lim = 1;
        for (int j=0; j<lim; j++) {
            if (t > 0) {
                ans += a[i];
                t--;
            }
        }
    }

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

Measured memory_bytes: 4756
import java.util.*;
class Main {
  public static void main (String[] args) throws Exception {
    
    Scanner sc = new Scanner(System.in);
    
    int A = sc.nextInt();
    int B = sc.nextInt();
    
    if((A*B)%2==1){
      System.out.println("Yes");
     }else{
      System.out.println("No");
      }

  }
}

Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		
		Scanner scan  = new Scanner(System.in);
		
		String S = scan.next();
		
		
		StringBuilder edit = new StringBuilder();
		
		for(int i = 0;i<S.length();i++){
			switch(S.substring(i, i+1)){
			case "B":
				if(edit.toString().equals("")){
					break;
				}else{
					edit.delete(edit.toString().length()-1, edit.toString().length());
					break;
				}
			case "0":
				edit.append("0");
				break;
				
			case "1":
				edit.append("1");
				break;
			
			}
		}
		
		System.out.println(edit.toString());
		
		
	}
	

}


Measured memory_bytes: 21844
#testB
if __name__=="__main__":
  r, g, b = map(int, input().split())
  k = int(input())


  for _ in range(k):
      if not r < g:
        g = g*2
        continue
      if not g < b:
        b = b*2
        use = False
  if r < g and g < b:
    print("Yes")
  else:
    print("No")


Measured memory_bytes: 9060
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	ll N; cin>>N;
	vector<lp> dot(N);
	set<lp> check;
	rep(i,N){
		cin>>dot[i].first>>dot[i].second;
		check.insert(make_pair(dot[i].first, dot[i].second));
	}
	if(N == 1){cout<<1<<endl; return 0;}
	ll ans = inf;
	for(ll i = 0; i<N; ++i){
		for(ll j = 0; j<N; ++j){
			if(i == j)continue;
			ll dx = dot[i].first-dot[j].first;
			ll dy = dot[i].second-dot[j].second;
			vector<bool> dis(N,true);
			rep(k,N){
				if(check.count(make_pair(dx + dot[k].first, dy + dot[k].second))){
					dis[k] = false;
				}
			}
			ll e_ans = 0;
			rep(k,N)if(dis[k]) ++e_ans;
			ans = min(ans, e_ans);
		}
	}
	cout<<ans<<endl;
}

// int main(){
// 	int N; cin>>N;
// 	vector<lp> input(N);
// 	rep(i,N)cin>>input[i].first>>input[i].second;
// 	map<long double, map<pair<long double,long double>,set<int>>> slope;
// 	rep(i,N){
// 		for(int j = i+1; j<N; ++j){
// 			long double sl = (long double)(input[i].second-input[j].second)/(input[i].first-input[j].first);
// 			long double y = input[j].second - input[j].first * sl;
// 			long double x = (sl*input[i].first - input[i].second)/sl;
// 			if(input[i].first == input[j].first )x = input[i].first;
// 			if(input[i].second == input[j].second)y = input[i].second;
// 			slope[sl][make_pair(x,y)].insert(i);
// 			slope[sl][make_pair(x,y)].insert(j);
// 		}
// 	}
// 	int n_cost = 0;
// 	for(auto x: slope){
// 		int cnt = x.second.size();
// 		printf("[same_slope_cnt = %d, slope = %Lf]\n", cnt, x.first);
// 		int uni = 0;
// 		for(auto p:x.second){
// 			printf("     [x, y] = [%Lf, %Lf]\n", p.first.first, p.first.second);
// 			uni += p.second.size();
// 		}
// 		cout<<endl;
// 		n_cost = max(n_cost, uni-cnt);
// 	}
// 	cout<<N-n_cost<<endl;
// 	return 0;
// }

Measured memory_bytes: 256
// Problem : A - Takoyaki
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("O2")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
int main()
{
	fast;
	ll t = 1;
	// cin >> t;
	while (t--)
	{
		ll n,x,tt;
		cin >> n >> x >> tt;
		ll r = n/x;
		if(n%x)
			r++;
		cout<<r*tt<<"\n";
	}
	return 0;
}


Measured memory_bytes: 3644
// Author : Nachiket Kanore
// Institute : PICT, Pune

/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */

#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <memory>
#include <random>
#include <cmath>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>

using namespace std;

#define int long long
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
 
 
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
 
const int mod = 1e9+7;
const int inf = 1e18;
const int N = 2e5+20;
int ans = 1;
int anscnt = 0;

int32_t main(){
    FAST;
    
    int n;  cin >> n;
    rep(i,1,n){
        int cnt =0;
        int num = i;
        while(num % 2 == 0) num /=2 , cnt++;

        if(anscnt < cnt){
            ans = i;
            anscnt = cnt;
        }


    }

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

Measured memory_bytes: 256
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.Arrays;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

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

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int X = in.nextInt();
			int[] x = new int[N + 1];
			x[0] = X;
			int ans;
			for(int i = 1; i < x.length; i++) {
				x[i] = in.nextInt();
			}
			Arrays.sort(x);
			ans = Math.abs(x[1] - x[0]);
			for(int i = 2; i < x.length; i++) {
				ans = test(Math.abs(x[i] - x[i - 1]), ans);
			}
			out.println(ans);
		}
	}
	
	static int test(int a, int b) {
		int c;
		int ans;
		if(a >= b) {
			while(a % b != 0) {
				c = a % b;
				a = b;
				b = c;
			}
			ans = b;
		}else {
			while(b % a != 0) {
				c = b % a;
				b = a;
				a = c;
			}
			ans = a;
		}
		return ans;
	}
	
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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

	}
}


Measured memory_bytes: 38956
#include <stdio.h>

int main()
{
	int i, j,H, W, flag = 1;
	char S[50][51] = {};
	char newS[52][52] = {};
	
	scanf("%d %d",&H,&W);
	for(i = 0; i< H; i++) scanf("%s",S[i]);
	for(i = 0; i <= W; i++)
	{
		newS[0][i] = '.';
		newS[H+1][i] = '.';
	}
	newS[0][W+1] = '\n'; newS[H+1][W+1] = '\n';
	
	for(i = 1; i <= H; i++)
	{
		sprintf(newS[i],".%s\n",S[i-1]);
	}
	
	for(i=1; i<=H; i++)
	{
		for(j=1;j<W;j++)
		{
			if(newS[i][j]=='#' && newS[i-1][j]!='#' && newS[i+1][j]!='#' && newS[i][j+1]!='#' && newS[i][j-1]!='#') flag = 0;
			if(flag == 0) break;
		}
		if(flag == 0) break;
	}
	
	printf("%s\n",(flag==0)? "No":"Yes");
	return 0;
}


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

int sum(int x){
  int h=0;
  while(x>0){
    h+=x%10;
    x/=10;
  }
  return h;
}

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  int answer=0;
  for(int i=1;i<=a;i++){
    if(b<=sum(i)&&sum(i)<=c){
      answer+=i;
    }
  }
  cout<<answer<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long X; cin >> X;
  long long cnt = 0;
  long long x = 100;
  while(true) {
    cnt++;
    x = (long long)(x * 1.01);
    if(x >= X) {
      cout << cnt << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;

int main(){
    string s;
    cin >> s;
    ll K;
    cin >> K;
    ll N = s.size();
    for(ll i = 0; i < N; i++){
        if(s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
        if(i == K - 1){
            puts("1");
            return 0;
        }
    }
}

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

int main(){
    int H, W;
    vector<int> col, row;
    cin >> H >> W;
    string map[H+1];
    bool flag;
    
    for(int i=0; i<H;i++){
	cin >> map[i];
    }

    for(int i=0; i<H;i++){
	flag=false;
	for(int j=0; j<W; j++){
	    if(map[i][j]=='#'){
		flag=true;
		break;
	    }
	}
	if(flag){
	    row.push_back(i);		    
	}
    }

    for(int i=0; i<W;i++){
	flag=false;
	for(int j=0; j<H; j++){
	    if(map[j][i]=='#'){
		flag=true;
		break;
	    }
	}
	if(flag){
	    col.push_back(i);
	}
    }

    for(int i=0; i<row.size(); i++){
	for(int j=0; j<col.size(); j++){
	    int left=row[i];
	    int right = col[j];
	    cout<<map[left][right];
	}
	cout<<endl;
    }
}


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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x) cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x) cout << ((x) ? "YES" : "NO") << endl

int main(int argc, const char* argv[]) {
	ll n, T;
	cin >> n >> T;

	ll ret = 0x7FFFFFFFFFFFFFFF;
	rep(i, n) {
		ll c, t;
		cin >> c >> t;
		if(t <= T && c < ret) ret = c; 
	}

	if(ret == 0x7FFFFFFFFFFFFFFF) {
		cout << "TLE" << endl;
	} else {
		cout << ret << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int seach(int n,int m){
	if(m==4){
		return (n==0);
	}
	else{
	int res=0;
	for(int i=0;i<10;i++){
		res+=seach(n-i,m+1);
	}
	return res;
}
}

int main() {
	int n;
	while(cin >> n)
	cout << seach(n,0) << endl;
	return 0;
}

Measured memory_bytes: 1160
//
//  main.cpp
//  B - Count ABC
//
//  Created by Hashizo on 2020/01/10.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
int main(int argc, const char * argv[]) {
	ll ans = 0;
	
	ll n;
	cin >> n;

	
	char s[n+1];
	cin >> s;


	REP(i, n) {
		if (s[i] == 'A') {
			if (s[i+1] == 'B') {
				if (s[i+2] == 'C') {
					ans++;
				}
			}
		}
	}

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


Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())
c = math.pi*(h+m/60)/6
d = math.pi*m/30
e = min(abs(c-d), 2*math.pi-abs(c-d))
print(math.sqrt(a**2+b**2-2*a*b*math.cos(e)))

Measured memory_bytes: 9444
a, b = gets.chomp.split
i=1
A = ""
B = ""
while i<=b.to_i do
  A += a
  i += 1
end
i = 1
while i<=a.to_i do
  B += b
  i += 1
end
if A > B 
  puts B
else
  puts A
end

Measured memory_bytes: 1788
N = input()
M = str(N)
K = len(M)
if N[K-1] == '2' or N[K-1] == '4' or N[K-1] == '5' or N[K-1] == '7' or N[K-1] == '9':
    print('hon')
elif N[K-1] == '0' or N[K-1] == '1' or N[K-1] == '6' or N[K-1] == '8':
    print('pon')
else:
    print('bon')


Measured memory_bytes: 9132
#include <iostream>
#include <string>
#include <atcoder/string>
using namespace std;
using namespace atcoder;
typedef long long ll;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    vector<int> sa = suffix_array(s);
    vector<int> la = lcp_array(s, sa);
    ll ans = n - sa[0];
    for(int i = 1; i < n; i++){
        ans += n - sa[i] - la[i - 1];
    }
    cout << ans << endl;
}


Measured memory_bytes: 15588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)

int main() {
  ll n, k; cin >> n >> k;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  sort(v.begin(), v.end());
  ll sum = 0;
  rep(i, k) sum += v.at(i);
  cout << sum << endl;
}

Measured memory_bytes: 3644
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    bool flag = false;
    for(int i = 0; i <= N/4; i++) {
        for(int j = 0; j <= N/7; j++) {
            if(N == i*4 + j*7) flag = true;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int h,w,n;

signed main() {
    cin >> h >> w >> n;
    cout << (n+max(h,w)-1)/max(h,w) << endl;
}



Measured memory_bytes: 256
import re,functools as f;d=f.lru_cache(None)(lambda n,b:n<1or sum(d(n-1,b[1:]+s)for s in'ACGT'if not re.match('.AGC|.ACG|.GAC|A.GC|AG.C',b+s))%(10**9+7));print(d(int(input()),'TTT'))

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

using namespace std;

int main(){
	int n;

	cin >> n;

	set< int > st;

	for(int i = 0 ; i < n ; i++){
		int xi;

		cin >> xi;

		if(st.find(xi) != st.end()){
			printf("NO\n");
			return 0;
		}

		st.insert(xi);
	}

	printf("YES\n");

	return 0;
}

Measured memory_bytes: 9600
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= 9; ++i) {
    if (n <= i * 111) {
      cout << i * 111 << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

const int MAXS = 20000 + 5;
const int INF = 1e9 + 5;

struct item {
	int w, s, v;
	item(int ww, int ss, int vv) : w(ww), s(ss), v(vv) {}
	bool operator <(item b) {
		return w + s < b.w + b.s;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<item> all;

	for (int i = 0; i < n; i++) {
		int w, s, v;
		cin >> w >> s >> v;
		all.push_back({ w, s, v });
	}

	sort(all.begin(), all.end());
	vector<long long> dp(MAXS, -INF);
	dp[0] = 0;

	for (int i = 0; i < n; i++) {
		for (int j = all[i].s; j >= 0; j--) {
			if (dp[j] >= 0) {
				dp[j + all[i].w] = max(dp[j + all[i].w], dp[j] + all[i].v);
			}
		}
	}

	cout << *max_element(dp.begin(), dp.end()) << "\n";
}

Measured memory_bytes: 3672
from collections import deque

input()
values = tuple(input().split(' '))

queue = deque()

for index, value in enumerate(values):
    if index % 2 == 0:
        queue.append(value)
    else:
        queue.appendleft(value)

if len(values) % 2 == 1:
    queue.reverse()

print(' '.join(queue))


Measured memory_bytes: 31512
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let mut str = String::new();
    for _ in 0..4 {
        str.push(read!());
    }

    let ans = if &str.chars().sorted().collect::<String>() == "1479" {
        "YES"
    } else {
        "NO"
    };

    println!("{}", ans);
}


Measured memory_bytes: 2172
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    # n進数
    n = int(input())
    k = -2
    if n==0:
        print(0)
    else:
        bi = ''
        while n != 0:
            bi += str(n % abs(k))
            if k < 0:
                n = -(-n // k)
            else:
                n = n // k
        print(bi[::-1])


resolve()

Measured memory_bytes: 3060
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int N,K;
vector< pair<ll,ll> > datas;
int main(){
	cin>>N;
	ll Lma=-1,Rmi=1e9+1;
	ll Lenma=0;
	rep(i,N){
		ll le;
		ll ri;
		cin>>le>>ri;
		datas.pb(mp(le,ri));
		Lma=max(Lma,le);
		Rmi=min(Rmi,ri);
		Lenma=max(Lenma,ri-le+1);
	}
	ll ans=Lenma+max((ll)0, Rmi-Lma+1);
	bool hoge=true;
	ll Ld=1,Rd=1e9;
	vector<pair<ll,ll> > rest;
	rep(i,N){
		ll le=datas[i].first,ri=datas[i].second;
		if(Rmi<le&&ri<Lma)hoge=false;
		// if(le<=Rmi&&ri<Lma){
		// 	Ld=max(Ld,le);

		// }else if(le>Rmi&&ri>=Lma){
		// 	Rd=min(Rd,ri);
		// }else{
		// 	rest.pb(mp(le,ri));
		// }
	}
	sort(all(datas));
	reverse(all(datas));
	//rep(i,N)cout<<datas[i].first<<" "<<datas[i].second<<endl;
	if(hoge){
		ll miri[114514];
		ll nori=1e9;

		rep(i,N-1){
			nori =min(nori,datas[i].second);
			ll lef=datas[i+1].first;
			ll ho=Rmi-lef+1;
			ll ho2=nori-Lma+1;
			if(lef<=Rmi)ans=max(ans,ho+ho2);
			//cout<<ans<<" "<<ho<<" "<<ho2<<" "<<lef<<" "<<nori<<endl;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pairs;

#define MOD 998244353


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

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}


const double PI = acos(-1);
const int M = 1000005;

int n,w;

vector<int> a;

bool rec(int i, int sum){
    
    if(i == n){
        if(sum == w)return true;
        else return false;
    }
    
    if(rec(i+1, sum + a[i])){
        return true;
    }
    if(rec(i, sum)){
        return true;
    }
    
    return false;
}

int main(){
    ll n;
    string s;
    cin>>n>>s;
    ll a = 0, b = 0;
    for(ll i = 0; i<n; i++){
        if(s[i] == 'R')a++;
    }
    
    ll ans  = max({a,b});
    
    for(ll i = 0; i<n; i++){
        if(s[i] == 'R')a--;
        else b++;
        ll curans = max({a,b});
        ans = min({ans, curans});
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3720
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int main(void){
	int N,a,ans=0;
	int sum[3][110];
	cin>>N;
	rep(i,N){
		cin>>a;
		sum[1][i]=a;
		if(i!=0)sum[1][i]+=sum[1][i-1];
	}
	rep(i,N){
		cin>>a;
		sum[2][i]=a;
	}
	irep(i,N){
		if(i!=N-1)sum[2][i]+=sum[2][i+1];
	}
	rep(i,N){
		ans = max(ans, sum[1][i]+sum[2][i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
    string str;
    cin >> str;
    int N=0;
    for(int n=0; n*2<str.size(); n++) {
        if(str[n]!=str[str.size()-1-n]) {
            N++;
        }
    }
    
    cout << N << endl;


    return 0;
    
}

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

int z(char c) {
  if(c=='^') return 1;
  if(c=='<') return 2;
  if(c=='v') return 3;
  if(c=='>') return 4;
  return 0;
}

int main() {
  int n,m;
  int dx[5]={0,-1,0,1,0},dy[5]={0,0,-1,0,1};
  while(cin >> n >> m && n && m) {
    int s[n][m];
    for(int i=0; i<n; i++) {
      string t;
      cin >> t;
      for(int j=0; j<m; j++) s[i][j]=z(t[j]);
    }
    int d[n][m];
    for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) d[i][j]=0;
    }
    d[0][0]=1;
    int ansx=-1,ansy=-1;
    int nx=0,ny=0;
    while(s[nx][ny]) {
      nx+=dx[s[nx][ny]];
      ny+=dy[s[nx][ny]];
      if(d[nx][ny]==0) d[nx][ny]=1;
      else break;
    }
    if(s[nx][ny]==0) {
      ansx=nx;
      ansy=ny;
    }
    if(ansx==-1 && ansy==-1) cout << "LOOP" << endl;
    else cout << ansy << " " << ansx << endl;
  }
  return 0;
}


Measured memory_bytes: 1288
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,c,d;
    cin>>n;
    a=n/1000%10; b=n/100%10; c=n/10%10; d=n%10;
    if (a+b+c+d==7) cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7";
    else if (a+b+c-d==7) cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7";
    else if (a+b-c+d==7) cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7";
    else if (a+b-c-d==7) cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7";
    else if (a-b-c-d==7) cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7";
    else if (a-b-c+d==7) cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7";
    else if (a-b+c-d==7) cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7";
    else if (a-b+c+d==7) cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7";
    cout<<endl;
    return 0;
}

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

int main() {
    int n,x,t;
    cin >> n >> x >> t;
    int hoge = n/x;
    if(n%x)hoge++;
    cout << hoge*t << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    set<int> st;
    for(int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if(st.find(a) == st.end())
            st.insert(a);
        else
            st.erase(a);
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 4864
#include <stdio.h>

int main(void) {
    
    int i;
    int n;
    int a[100];

    scanf("%d", &n);

    for(i = 0; i < n; i++) {
        scanf("%d", a+i);
    }

    for(i = n - 1; i >= 0; i--) {
        printf("%d", a[i]);
        if(i != 0) {
            putchar(' ');
        }
    }

    printf("\n");

    return 0;
}

Measured memory_bytes: 604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		long ans = 0;
		for (int i = 1; i < n; i++) {
			if (a[i] < a[i - 1]) {
				int d = a[i - 1] - a[i];
				ans += d;
				a[i] += d;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 60164
#include<algorithm>
#include<cstdio>
#include<iostream>
using namespace std;
int N=0,W=0;
int v[110]={0},w[110]={0};
int dp[110][10010]={0};
int main(void){
	
	cin>>N>>W;
	for(int i=0;i<N;i++){
		cin>>v[i]>>w[i];
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<=W;j++){
			if(w[i]<=j){
				dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
			}
			else{
				dp[i+1][j]=dp[i][j];
			}
		}
	}
	cout<<dp[N][W]<<endl;
	return 0;
}


Measured memory_bytes: 7024
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i=0;i<n;i++) {
    cin >> a[i];
    a[i] -= i+1;
  }

  sort(a.begin(), a.end());
  long long b;
  if(n % 2 == 0) {
    b = (a[n/2]+a[n/2-1]) / 2;
  }
  else {
    b = a[n/2];
  }

  long long ans = 0;

  for(int i=0;i<n;i++) {
    ans += abs(a[i]-b);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
long long fiboDP(int n){
    long long fibodp[200]={0};
    fibodp[1]=1;
    fibodp[2]=1;
    for(int i=3;i<=n;i++){
        fibodp[i]=fibodp[i-1]+fibodp[i-2];
    }
    return fibodp[n];
}
int main(void){
    int n;
    scanf("%d",&n);
    printf("%lld\n",fiboDP(n+1));
   return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<string>
using namespace std;
int main(){
	int h, w;
	cin >> h >> w;
	char A[50][50];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) cin >> A[i][j];
	}
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if(A[i][j]=='#'){
				int d = 0;
				if (A[i - 1][j] == '.' || i == 0) d++;
				if (A[i + 1][j] == '.' || i == h) d++;
				if (A[i][j - 1] == '.' || j == 0) d++;
				if (A[i][j + 1] == '.' || j == w) d++;
				if (d == 4) {
					ans = 1;
					break;
				}
			}
		}
	}
	if (ans == 1) cout << "No"<<endl;
	else cout << "Yes"<<endl;
}

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

    int n;
    cin>>n;

    long long sum=0;

    rep(i,n+1){
        if(i%3!=0&&i%5!=0){sum+=i;}
    }

cout<<sum<<endl;

}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
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); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

ll dp[105][100010];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, W;
  cin >> n >> W;
  vector<ll> w(n), v(n);
  REP(i, n) cin >> w[i] >> v[i];

  REP(i, n) REP(j, W+1) {
    if(j >= w[i]) {
      dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
    } else {
      dp[i+1][j] = dp[i][j];
    }
  }
  cout << dp[n][W] << endl;

  return 0;
}


Measured memory_bytes: 79360
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

vector<vector<int>> g;
vector<int> c;
int cnt;

void dfs(int v, int p, vector<int> &d){
	d[v] = c[cnt++];
	for(auto nv : g[v]){
		if(nv == p) continue;
		dfs(nv, v, d);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	g.resize(n);
	c.resize(n);
	rep(i,n-1){
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	ll sum = 0;
	int mx = 0;
	rep(i,n){
		cin >> c[i];
		sum += c[i];
		chmax(mx, c[i]);
	}
	sort(c.rbegin(), c.rend());
	cnt = 0;
	vector<int> d1(n, 0);
	dfs(0, -1, d1);
	ll ans = sum - mx;
	cout << ans << endl;
	rep(i,n) cout << d1[i] << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 1408
class UF:
    def __init__(self, N):
        self.uf = [-1]*N
        self.n = N

    def find(self, x):
        if self.uf[x]<0: return x
        self.uf[x] = self.find(self.uf[x])
        return self.uf[x]

    def size(self, x):
        return -self.uf[self.find(x)]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x==y: return
        if self.size(x) > self.size(y): x, y = y, x
        self.uf[y] += self.uf[x]
        self.uf[x] = y
        self.n -= 1

N, M = list(map(int, input().split()))
P = list(map(int, input().split()))
L = [None]*N
for l, p in enumerate(P):
    L[p-1] = l
uf = UF(N)
for _ in range(M):
    x, y = list(map(int, input().split()))
    uf.union(x-1, y-1)

ans = 0
for i in range(N):
    if uf.find(i)==uf.find(L[i]): ans+=1

print(ans)

Measured memory_bytes: 13880
n = int(input())
p = [int(i) for i in input().split()]
ans = 'YES'
k = 0
for i in range(n):
    if p[i] != i + 1:
        if k == 1:
            ans = 'NO'
            break
        else:
            if p[p[i] - 1] == i + 1:    
                p[p[i] - 1] = p[i]
                p[i] = i + 1
                k = 1
            else:
                ans = 'NO'
                break

print(ans)

Measured memory_bytes: 3064
N, M = map(int, input().split())
conns = [tuple(map(int, input().split())) for _ in range(M)]
cost = [[float("INF")]*N for _ in range(N)]

# make same node cost zeros
for i in range(N):
  cost[i][i] = 0

# update edge cost
for a,b,c in conns:
  cost[a-1][b-1] = c
  cost[b-1][a-1] = c

# find minimum cost across all pairs of nodes
for k in range(N):
  for i in range(N):
    for j in range(N):
      cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

# find edges without shortest path
cnt = 0
for a,b,c in conns:
  if c > cost[a-1][b-1]:
    cnt += 1

print(cnt)
  


Measured memory_bytes: 9336
N,K = map(int,input().split())
V = list(map(int,input().split()))

ans = 0

P = min(N,K)

for a in range(1,P+1) :
    for i in range(a+1) :
        cnt = 0
        calc = 0
        GET = V[:i] + V[N-(a-i):]
        GET = sorted(GET)
        
        for g in GET :
            if (g < 0) and (cnt < K-a) :
                cnt += 1
            else :
                calc += g
        
        ans = max(ans, calc)
print(ans)


Measured memory_bytes: 3064
#include <map>
#include <cstdio>
#include <cstring>

inline int Abs(const int x){return x>=0?x:-x;}

int n,a[205],b[205],Mat[205],Ans;
bool G[205][205],Vis[205];
std::map<int,int> M;

bool Prime(int x)
{
    if(x<2)return false;
    for(int i=2;i*i<=x;++i)
        if(x%i==0)return false;
    return true;
}

bool DFS(int x)
{
    for(int y=1;y<=n;++y)
        if(!Vis[y]&&G[x][y])
            if(Vis[y]=true,!Mat[y]||DFS(Mat[y]))
                return Mat[y]=x,true;
    return false;
}

int main()
{
    scanf("%d",&n);
    for(int i=1,x;i<=n;++i)scanf("%d",&x),M[x]^=1,M[x+1]^=1;
    for(auto i:M)if(i.second)(i.first&1?a[++*a]:b[++*b])=i.first;
    for(int i=1;i<=*a;++i)
        for(int j=1;j<=*b;++j)
            G[i][j]=Prime(Abs(a[i]-b[j]));
    for(int i=1;i<=*a;++i)memset(Vis,0,sizeof Vis),Ans+=DFS(i);
    printf("%d\n",Ans+(*a-Ans)/2*2+(*b-Ans)/2*2+(*a-Ans)%2*3);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iomanip>
// #define int long long
#define ll long long
#define FOR(P,Q) for(P=0;P<Q;P++)
#define FORR(P,Q) for(P=1;P<=Q;P++)
#define FORS(i,s) for(i=0;s[i]!='\0';i++)
#define pb push_back
using namespace std;

/*std::cout << std::fixed;
    std::cout << std::setprecision(14);
    std::cout << d;
*/
    
int main()
{
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  #ifndef ONLINE_JUDGE
	freopen("error.txt","w",stderr);
	#endif

	char s[4];
	cin>>s;
	int i,c1=0,c2=0;

		char a=s[0];
		FOR(i,4){
			if(a==s[i])
				c1++;
		}
	char b;
	FOR(i,4){
		if(s[i]!=a)
		{
			b=s[i];
			break;
		}	
	}

		FOR(i,4){
			if(b==s[i])
				c2++;
		}
		cerr<<s<<c1<<c2;
	if(c1==2&&c2==2)
		cout<<"Yes";
	else cout<<"No";
	  
 return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (u == s)
        a--;
    else if (u == t)
        b--;
    cout << a << " " << b << "\n";
    return 0;
}

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

#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

const int INF = INT_MAX;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

using PII = pair<int, int>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int N, M, C;
V<int> b;

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cin >> N;
    cin >> M;
    cin >> C;

    REP(i, M) {
        int x; cin >> x;
        b.push_back(x);
    }

    int ct = 0;
    REP(i, N) {
        int ans = C;
        REP(j, M) {
            int a; cin >> a;
            ans += (a * b[j]);
        }
        if(ans > 0) ct++;
    }
    cout << ct << "\n";
}

Measured memory_bytes: 256
namespace ABC143.A
{
    using System.Collections.Generic;
    using System.Linq;
    using static System.Console;

    public class Program
    {

        public static void Main(string[] args)
        {
            var l = ReadInputsAsInt().ToList();


            WriteLine(Solve(l[0], l[1]));
        }

        public static int Solve(int a, int b) => a - b * 2 >= 0 ? a - b * 2 : 0;


        static IEnumerable<int> ReadInputsAsInt() => ReadLine().Split(' ').Select(x => int.Parse(x));

    }
}


Measured memory_bytes: 13268
#include<stdio.h>

int main(){
  while(1){
    int parts[350], a, b, c, n, i;
    int check[1000][4];
    for(i = 0;i < 350;i++)parts[i] = 2;
    scanf("%d%d%d", &a, &b, &c);
    if(a == 0 && b == 0 && c == 0) return 0;
    scanf("%d", &n);
    for(i = 0;i < n;i++){
      scanf("%d%d%d%d", &check[i][0], &check[i][1], &check[i][2], &check[i][3]);
      if(check[i][3] == 1){
	parts[check[i][0]] = 1;
	parts[check[i][1]] = 1;
	parts[check[i][2]] = 1;
      }
    }
    for(i = 0;i < n;i++){
      if(check[i][3] == 0){
	if(parts[check[i][0]] * parts[check[i][1]] * parts[check[i][2]] == 2){
	  if(parts[check[i][0]] == 2)parts[check[i][0]] = 0;
	  if(parts[check[i][1]] == 2)parts[check[i][1]] = 0;
	  if(parts[check[i][2]] == 2)parts[check[i][2]] = 0;
	}
      }
    }
    for(i = 1; i <= a + b + c;i++){
      printf("%d\n", parts[i]);
    }
  }
}

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

int a(int x){
    int i;
    int y = (int)(sqrt(x)) + 1;

    for(i = 2; i < y;i++){
        if(x % i == 0){
            return 0;
        }
    }
    return 1;
}

int main(void){
    int n, i, x;
    int count = 0;
    int A[10000];
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d\n", &A[i]);
        x = a(A[i]);
        if(x == 1){
            count++;
        }
    }
    printf("%d\n", count);

    return 0;
}


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

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> v(h);
    for(int i=0;i<h;i++){cin >> v.at(i);}
    for(auto e:v){cout <<e<<endl; cout <<e<<endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    string t;
    getline(cin,s);
    getline(cin,t);
    int m=s.length();
    int n=t.length();
    int l[m+1][n+1];
    l[0][0]=0;
    for(int i=0;i<=m;i++){
    for( int j=0;j<=n;j++){
        if(i==0 || j==0) l[i][j]=0;
        else if(s[i-1]==t[j-1]) l[i][j]=1+l[i-1][j-1];
        else l[i][j]=max(l[i-1][j],l[i][j-1]);
           }
         }
         int index = l[m][n];
   char lcs[index+1]; 
        lcs[index] = '\0'; 
         int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      if (s[i-1] == t[j-1]) 
      { 
          lcs[index-1] = s[i-1]; 
          i--; j--; index--;     
      } 
      else if (l[i-1][j] > l[i][j-1]) 
         i--; 
      else
         j--; 
   } 
   cout<<lcs<<endl;
return 0;
    }

Measured memory_bytes: 35456
#include <iostream>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

int gcd(ll a, ll b) {
  ll c;
  if (a > b) swap(a, b);
  while (b % a > 0) {
    c = b % a;
    b = a;
    a = c;
  }
  return a;
}
int main() {
  int k, ans = 0;
  cin >> k;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int l = 1; l <= k; l++) {
        ans += gcd(gcd(i, j), l);
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

int main(){
	int n; cin >> n;
	string s;
	cin >> s;
	vector<int> l_W(n+1, 0), l_E(n+1, 0), r_W(n+1, 0), r_E(n+1, 0);
	
	for(int i = 0; i < n; i++){
		if(s[i] == 'W'){
		 	l_W[i+1] = l_W[i] + 1;
		 	l_E[i+1] = l_E[i];
		}else{
			l_E[i+1] = l_E[i] + 1;
			l_W[i+1] = l_W[i];
		}
	}

	for(int i = n-1; i >= 0; i--){
		if(s[i] == 'W'){
		 	r_W[i] = r_W[i+1] + 1;
		 	r_E[i] = r_E[i+1];
		}else{
			r_E[i] = r_E[i+1] + 1;
			r_W[i] = r_W[i+1];
		}		
	}

	int ans = 1001001001;

	for(int i = 0; i < n; i++){
		int sum;
		if(s[i] == 'W'){
			int l = l_W[i];
			int r = r_E[i+1];
//			cout << l << r << endl;
			sum = l + r;
		}else{
			int l = l_W[i];
			int r = r_E[i+1];
//			cout << l << r << endl;
			sum = l + r;
		}		
		ans = min(ans , sum);
	}

	cout << ans << endl;
}

Measured memory_bytes: 5380
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	boolean [][] visited;
	boolean ans;
	int count, w,h, sx,sy;
	int [] vx = {0,1,0,-1, 1,1,-1,-1};
	int [] vy = {-1,0,1,0, -1,1,1,-1};
	
	private void doit(){
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if((w|h) == 0) break;
			count = 0;
			visited = new boolean[h][w];
			sx = -1;
			sy = -1;
			boolean isworstpatt = (w == 7 && h == 7);
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					int now = sc.nextInt();
					if(now == 0){
						count++;
						if(sx == -1){
							sx = j;
							sy = i;
						}
					}
					else{
						isworstpatt = false;
						visited[i][j] = true;
					}
				}
			}
			if(isworstpatt){
				System.out.println("No");
				continue;
			}
			
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if(visited[i][j])continue;
					int count = 0;
					for(int k = 0; k < 4; k++){
						int x = j + vx[k], y = i + vy[k];
						if(! isOK(x,y))continue;
						if(visited[y][x] == false){
							count++;
						}
					}
					if(count <= 1){
						sx = -1;
						break;
					}
				}
				if(sx == -1){
					break;
				}
			}
			
			if(sx == -1){
				System.out.println("No");
				continue;
			}
			ans = false;
			dfs(sx, sy, 0);
			System.out.println(ans ? "Yes" : "No");
		}
	}

	private void dfs(int x, int y, int deep) {
		if(ans) return;
		
		//branch
		if(count - deep < Math.abs(x - sx) + Math.abs(y - sy)) return;
		
		for(int i = 0; i < 4; i++){
			int xx = x + vx[i];
			int yy = y + vy[i];
			if(! isOK(xx, yy))continue;
			if(yy == sy && xx == sx){
				if(deep + 1 == count){
					ans = true;
				}
				return;
			}
			if(visited[yy][xx]) continue;
			boolean res = check(xx, yy);
			if(! res)continue;

			visited[yy][xx] = true;
			dfs(xx, yy, deep + 1);
			visited[yy][xx] = false;
		}
	}

	private boolean check(int x, int y) {
		for(int i = 0; i < vx.length; i++){
			int xx = x + vx[i];
			int yy = y + vy[i];
			if(! isOK(xx, yy)) continue;
			if(xx == sx && yy == sy) continue;
			if(visited[yy][xx]) continue;
			int count = 0;
			for(int j = 0; j < 4; j++){
				int xxx = xx + vx[j];
				int yyy = yy + vy[j];
				if(! isOK(xxx, yyy)) continue;
				if(visited[yyy][xxx]) continue;
				count++;
			}
			if(count <= 1) return false;
		}
		return true;
	}

	private boolean isOK(int xx, int yy) {
		if(0<= xx && xx < w && 0<= yy && yy < h) return true;
		return false;
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 50024