akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
	int a;
	cin >> a;
	vector<int> deg(4);
	rep(i, 4) {
		deg[i] = a % 10;
		a /= 10;
	}
	reverse(deg.begin(), deg.end());
	if (deg[0] + deg[1] + deg[2] + deg[3] == 7) {
		cout << deg[0] << '+' << deg[1] << '+' << deg[2] << '+' << deg[3] << '=' << 7 << endl;
		return 0;
	}
	if (deg[0] + deg[1] + deg[2] - deg[3] == 7) {
		cout << deg[0] << '+' << deg[1] << '+' << deg[2] << '-' << deg[3] << '=' << 7 << endl;
		return 0;
	}
	if (deg[0] + deg[1] - deg[2] + deg[3] == 7) {
		cout << deg[0] << '+' << deg[1] << '-' << deg[2] << '+' << deg[3] << '=' << 7 << endl;
		return 0;
	}
	if (deg[0] - deg[1] + deg[2] + deg[3] == 7) {
		cout << deg[0] << '-' << deg[1] << '+' << deg[2] << '+' << deg[3] << '=' << 7 << endl;
		return 0;
	}
	if (deg[0] - deg[1] - deg[2] + deg[3] == 7) {
		cout << deg[0] << '-' << deg[1] << '-' << deg[2] << '+' << deg[3] << '=' << 7 << endl;
		return 0;
	}
	if (deg[0] - deg[1] + deg[2] - deg[3] == 7) {
		cout << deg[0] << '-' << deg[1] << '+' << deg[2] << '-' << deg[3] << '=' << 7 << endl;
		return 0;
	}
	if (deg[0] + deg[1] - deg[2] - deg[3] == 7) {
		cout << deg[0] << '+' << deg[1] << '-' << deg[2] << '-' << deg[3] << '=' << 7 << endl;
		return 0;
	}
	if (deg[0] - deg[1] - deg[2] - deg[3] == 7) {
		cout << deg[0] << '-' << deg[1] << '-' << deg[2] << '-' << deg[3] << '=' << 7 << endl;
		return 0;
	}
	return 0;
}


Measured memory_bytes: 256
const inf = Number.MAX_SAFE_INTEGER;
function Main(input){
	input = input.split("\n");
	var mem = input[0].split(" ").map(Number);
	input.shift();
	input = input.sort(function(a,b){return a-b}); 
	var min = inf;
	for(var i=mem[1]-1;i<input.length;i++){
		if(min>input[i]-input[i-mem[1]+1]) min = input[i]-input[i-mem[1]+1];
	}
	console.log(min)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 19404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long double PI = 3.14159265358979323846;

int a[51], b[51], c[51], d[51];
int n, m, q;
vector<ll> A;
ll maxScore = 0;
ll score = 0;

void completeSearch(int pos) {
    if ((int)A.size() == n) {
        for (int i = 0; i < q; ++i) {
            if (a[i] < A.size() && b[i] < A.size()) {
                if (A[b[i]] - A[a[i]] == c[i]) {
                    score += d[i];
                }
            }
        }
        maxScore = max(maxScore, score);
        score = 0;
        return;
    }
    for (int i = pos; i < m; ++i) {
        A.push_back(i);
        completeSearch(i);
        A.pop_back();
    }
    return;
}

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

    cin >> n >> m >> q;
    for (int i = 0; i < q; ++i) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i];
        --b[i];
    }
    completeSearch(0);
    cout << maxScore << '\n';

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t;
  cin >> s;
  cin >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<int>());
  if( s < t ) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d",&a);
	scanf("%d",&b);
	if(a < b)	{
			printf("a < b\n");
	}
	else if(a > b) {
			printf("a > b\n");
	}
	else if(a == b) {
			printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 2680
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    if(a.charAt(a.length()-1) == b.charAt(0) && b.charAt(b.length()-1) == c.charAt(0)){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] V = new int[N];
		int[] C = new int[N];

		for (int i=0; i<N; i++){
			V[i] = sc.nextInt();
		}
		for (int i=0; i<N; i++){
			C[i] = sc.nextInt();
		}
		int total=0;
		for (int i=0; i<N; i++){
			if (V[i] - C[i] > 0) {
				total += V[i] - C[i];
			}
		}
		System.out.println(total);
	}
}

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

int main(){
    int n, a, b, x = 0, ans = 0;
    cin >> n >> a;

    for(int i = 1; i < n; i++){
        cin >> b;

        if(b == a) continue;
        if(x){
            if((x == 1 && b < a) || (x == -1 && b > a)){
                x = 0;
                ans++;
            }
        }else{
            x = b > a ? 1 : -1;
        }
        a = b;
    }
    cout << ans + 1 << endl;
}

Measured memory_bytes: 256
from collections import deque
from itertools import chain
h, w = (int(x) for x in input().split())
s = []
for _ in range(h):
    s.append(list(input()))
dx = [[1, 0], [0, 1], [-1, 0], [0, -1]]
ans = []
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            continue
        d = [[0] * w for i in range(h)]
        for k, sh in enumerate(s):
            for l, sw in enumerate(sh):
                if sw == '#':
                    d[k][l] = -1
                else:
                    d[k][l] = float('inf')
        que = deque()
        que.append([i, j])
        d[i][j] = 0
        while len(que) > 0:
            qx, qy = que.popleft()
            for x, y in dx:
                nx, ny = qx + x, qy + y
                if 0 <= nx and nx < h and 0 <= ny and ny < w and d[nx][ny] == float('inf'):
                    que.append([nx, ny]) 
                    d[nx][ny] = d[qx][qy] + 1
        ans.append(max(chain.from_iterable(d)))
print(max(ans))

Measured memory_bytes: 3316
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int gcd(int x, int y) {
    if (x > y) {
        swap(x, y);
    }
    if (x <= 0) {
        return y;
    }
    return gcd(y % x, x);
}

vector<int> as;

// ls[i] is gcd of as in [0, i)
vector<int> ls;
// rs[i] is gcd of as in [i, N)
vector<int> rs;

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

    as.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> as[i];
    }

    ls.resize(N + 1);
    ls[0] = 0;
    for (int i = 0; i < N; i++) {
        ls[i + 1] = gcd(ls[i], as[i]);
    }
#ifdef DEBUG
    printf("ls: \n");
    for (int i = 0; i <= N; i++) {
        cout << ls[i] << " ";
    }
    cout << endl;
#endif

    rs.resize(N + 1);
    rs[N] = 0;
    for (int i = N - 1; i >= 0; i--) {
        rs[i] = gcd(rs[i + 1], as[i]);
    }
#ifdef DEBUG
    printf("rs: \n");
    for (int i = 0; i <= N; i++) {
        cout << rs[i] << " ";
    }
    cout << endl;
#endif

    int ans = 0;
    for (int i = 0; i < N; i++) {
        chmax(ans, gcd(ls[i], rs[i + 1]));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4492
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int n1 = n + 1;
		String[] sa = br.readLine().split(" ");
		int[] c = new int[n1];
		int d = 0;
		for (int i = 0; i < n1; i++) {
			int a = Integer.parseInt(sa[i]);
			if (c[a] > 0) {
				d = n - i + c[a] - 1;
				break;
			}
			c[a] = i + 1;
		}
		br.close();

		int mod = 1000000007;
		long[] p = new long[n1 + 1];
		long[] pi = new long[n1 + 1];
		p[0] = 1;
		pi[0] = 1;
		for (int i = 1; i < p.length; i++) {
			p[i] = p[i - 1] * i % mod;
			pi[i] = modinv(p[i], mod);
		}

		PrintWriter pw = new PrintWriter(System.out);
		pw.println(n);
		for (int i = 2; i <= n1; i++) {
			long v1 = nCr(n1, i, mod, p, pi);
			if (i - 1 <= d) {
				long v2 = nCr(d, i - 1, mod, p, pi);
				v1 -= v2;
				if (v1 < 0) {
					v1 += mod;
				}
			}
			pw.println(v1);
		}
		pw.flush();
	}

	static long nCr(int n, int r, int m, long[] p, long[] pi) {
		return p[n] * pi[r] % m * pi[n - r] % m;
	}

	static long modinv(long a, long m) {
		long b = m;
		long u = 1;
		long v = 0;
		long tmp = 0;

		while (b > 0) {
			long t = a / b;
			a -= t * b;
			tmp = a;
			a = b;
			b = tmp;

			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}

		u %= m;
		if (u < 0) u += m;
		return u;
	}
}


Measured memory_bytes: 42640
a, b, c, d = map(int, input().split())

if abs(c-a) <= d:
  print("Yes")
  exit(0)
elif abs(a-b) <= d and abs(c-b) <= d:
  print("Yes")
  exit(0)
else:
  print("No")
  exit(0)

exit(0)

Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
int main(void){
  int counter=0;
  int counterb=0;
  int yaku[10000];
  int yakub[10000];
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  for(int i=1;i<=a;i++){
    if(a%i==0){
      yaku[counter]=i;
      counter++;
    }
  } 
   for(int ite=0;ite<counter;ite++){
    if(b%yaku[ite]==0){
      yakub[counterb]=yaku[ite];
      counterb++;
} 
}
  printf("%d",yakub[counterb-c]);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
#include<deque>
#include<chrono>
using namespace std;
#define pi 3.141592653589793238


#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>
typedef vector<ll> vi;
typedef vector<vi> vvi;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    
    //cin >> T;
    while (T--) {
        double n, k;
        cin >> n >> k;
        double ans = 0;
        for(i = 1; i <= n ;i++){
            double s = i;
            double cnt = 0;
            while(s < k){
                s *= 2;
                cnt++;
            }
            ans += 1 /((pow(2, cnt) * n));
        }
        cout <<fixed << setprecision(10) <<  ans;
    }

    return 0;
}


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


ll N, M, V, P;
vector<ll> A;


void input() {
    cin >> N >> M >> V >> P;
    A = vector<ll>(N);
    rep(i, N) cin >> A[i];
}


int main() {
    input();
    sort(A.rbegin(), A.rend());
    ll sum = A[P-1];
    ll pre = A[P-1];
    int k = 1;
    int ans = P;
    int x;
    for (int i = P; i < N; i++) {
        if (pre - A[i] > M) break;
        if (A[i] == A[i-1]) goto con;
        x = V - (N - i);
        if (x < P) goto con;
        x -= P - 1;
        if (sum + x * M > (A[i] + M) * k) break;
con:
        ans++;
        sum += A[i];
        k++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
// 2011/10/02 Tazoe

#include <iostream>
#include <string>
using namespace std;

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

	for(int i=0; i<n; i++){
		string str;
		cin >> str;

		if(str[0]!='>'){
			cout << "NA" << endl;
			continue;
		}

		if(str[1]=='\''){
			int N = 0;
			int I = 2;
			while(str[I]=='='){
				N++;
				I++;
			}
			if(N==0){
				cout << "NA" << endl;
				continue;
			}

			if(str[I]!='#'){
				cout << "NA" << endl;
				continue;
			}
			I++;

			int M = 0;
			while(str[I]=='='){
				M++;
				I++;
			}
			if(N!=M){
				cout << "NA" << endl;
				continue;
			}

			if(!(str[I]=='~'&&I+1==str.size())){
				cout << "NA" << endl;
				continue;
			}

			cout << "A" << endl;
		}
		else if(str[1]=='^'){
			int N = 0;
			int I = 2;
			while(str[I]=='Q'&&str[I+1]=='='){
				N++;
				I += 2;
			}
			if(N==0){
				cout << "NA" << endl;
				continue;
			}

			if(!(str[I]=='~'&&str[I+1]=='~'&&I+2==str.size())){
				cout << "NA" << endl;
				continue;
			}

			cout << "B" << endl;
		}
		else
			cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
	int n, x, i;
	int l = 0;
	int d = 0;
	int count = 1;
	scanf("%d %d", &n, &x);
	
	for (i = 0; i < n; i++) {
		scanf("%d", &l);
		d += l;//跳ねる座標
		if (d <= x) {//跳ねる座標がX以下の領域か判定
			count++;
		}
	}

	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
    int a, b;

    cin >> a >> b;

    if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main(){
    
 string a;
 int b;
    cin>>a;
rep(i,a.size()){
    if(a[i]=='A'){
    b=i;
    break;
    }
}
for(int i=a.size()-1;i>=0;i--){
if(a[i]=='Z'){
    b=i-b;
    break;
}
}
cout<<b+1;
}


Measured memory_bytes: 640
n = int(input())
list_abc = ['a','b','c','d','e','f','g','h','i','j']

list_old0 = [0]
list_old1 = [[0,0],[0,1]]
list_old = [[0,0],[0,1]]
if n>2:
    m = n
else:
    m = 3

for i in range(2,m):
    list_new=[]
    for k in list_old:
        #print('b')
        for j in range(i+1):
            #print('c')
            b=k.copy()
            #print(b)
            #print(f'j{j}')
            if max(k)+1<j:
                continue
            b.append(j)
            list_new.append(b)
    #print(list_new)
    list_old = list_new

if n==1:
    print('a')
elif n==2:
    print('aa')
    print('ab')
else:
    for l in list_old:
        for y in l:
            print(list_abc[y],end='')
        print()

    


Measured memory_bytes: 32076
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	char s[100005];
	scanf("%s", s);
	int i, ans = 1;
	for (i = 1; i < n; i++)
		if (s[i] != s[i - 1])
			ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=[0]*m
for i in range(m):
    x,y,c=map(int,input().split())
    ans[i]=a[x-1]+b[y-1]-c
ans.append(min(a)+min(b))
print(min(ans))

Measured memory_bytes: 66620
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
const int N=100005;
int n,C,K,ans,sum,t,T[N];
int main()
{
	n=read(),C=read(),K=read();
	for(RI i=1;i<=n;++i) T[i]=read();
	sort(T+1,T+1+n);sum=C;
	for(RI i=1;i<=n;++i) {
		if(sum==C) ++ans,sum=1,t=T[i];
		else {
			if(T[i]-t<=K) ++sum;
			else ++ans,sum=1,t=T[i];
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<ii> vii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr(be, en) for(int i = be; i <= en; i++) 
ll mod = 1e9 + 7;
ll power(ll a, ll b)
{
	if(b == 0) return 1;
	ll ans = power(a, b/2);
	ans = (ans*ans)%mod;
	if(b%2) ans*=a;
	return ans%mod;
}
ll mul(ll a,ll n, ll mod)
{
	ll ret;
	if(n==0) return 0;
	ret = mul(a,n/2, mod);
	ret = (ret+ret)%mod;
	if(n%2)	ret=(ret+a)%mod;
	return ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);
	cin.tie(NULL);
	ll n, k;
	cin >> n >> k;
	vi ways(1e5 + 1, 0);
	ll ans = 0;
	for(int i = k; i >= 1; i--)
	{
		ll poss = k/i;
		ll poss_sub  = power(poss, n);
		for(int j = i; j <= k; j+= i) 
		{
			poss_sub -= ways[j];
			if(poss_sub < 0) poss_sub += mod;
		}
		ways[i] = poss_sub;
		ans = (ans + ways[i]*i)%mod;
	}
	cout << ans;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0;i < n;i++) cin >> h[i];
    sort(h.begin(),h.end());
    set<int> g;
    for(int i;i < n - k + 1;i++){
        g.insert(h[i + k - 1] - h[i]);
    }
    cout << *begin(g) << endl;
    return 0;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<pair<int,int> >g;
vector<int>v;
priority_queue<int>pq;
int main()
{
	scanf("%d%d",&n,&m);
	g.clear();
	for(int i=0;i<n;i++)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		g.push_back(make_pair(l,r));
	}
	sort(g.begin(),g.end());
	int num=0;
	for(int i=0;i<n;i++)
	{
		pq.push(-g[i].second);
		int x=g[i].first;
		if(x>num)num++;
		else
		{
			v.push_back(pq.top());
			pq.pop();
		}
	}
	sort(v.begin(),v.end());
	int pos=num,ans=0;
	num=0;
	for(int i=0;i<v.size();i++)
	{
		if(m-num<(-v[i]))ans++;
		else if(pos+num==m)ans++;
		else num++;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
string s;
int n;
int c[500001][26];

inline int lowbit(int x){
	return x&(-x);
}

inline void add(int p,int k){
	while(p<=n){
		++c[p][k];
		p+=lowbit(p);
	}
}
inline void amend(int p,int k,int f){
	while(p<=n){
		++c[p][k];
		--c[p][f];
		p+=lowbit(p);
	}
}

inline int sum(int p,int k){
	int ans=0;
	while(p){
		ans+=c[p][k];
		p-=lowbit(p);
	}
	return ans;
} 
inline int ask(int l,int r){
	int ss=0;
	for(int i=0;i<26;++i)if(sum(r,i)-sum(l-1,i))++ss;
	return ss;
}

int main(){
	memset(c,0,sizeof(c));
	register int m,f,a,b;
	register char c;
	cin>>n>>s>>m;
	s=' '+s;
	int i;
	for(i=1;i<=n;++i)add(i,s[i]-'a');
	while(m--){
		cin>>f>>a;
		if(f==1){
			cin>>c;
			amend(a,c-'a',s[a]-'a');
			s[a]=c;
		}
		else{
			cin>>b;
			cout<<ask(a,b)<<endl;
		}
	}
}

Measured memory_bytes: 52228
from heapq import *
import sys

q = []
while True:
  # commands = list(map(str, input().split()))
  commands=sys.stdin.readline().split()

  if commands[0] == "end":
    break

  if commands[0] == "insert":
    heappush(q, -int(commands[1]))
  else:
    print(-heappop(q))


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

int main()
{

    cin >> N >> a >> b;
    ll ans;
    if ((b - a) % 2 == 0)
    {
        ans = (b - a) / 2;
    }
    else
    { //近い方の端に行く
        ans = min(a - 1, N - b) + 1 + (b - a - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n+1];
int cnt=0;
for(int i=1;i<=n;i++){
    cin>>a[i];
    if(a[i]!=i){
        cnt++;
    }
}
if(cnt<=2){
    cout<<"YES"<<endl;
}
else{
    cout<<"NO"<<endl;
}
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
int H,W;
int ans=100000;
vector<string> field;
bool seen[110][110];
void dfs(int h,int w){
    string s;
    seen[h][w]=true;
    if(field[0][0]=='#') s+='a';
    for(int dir=0; dir<4;dir++){
        int nh=h+dx[dir];
        int nw=w+dy[dir];

        if(nh<0 || nh>=H ||nw<0 || nw>=W) continue;
        if(field[nh][nw]=='#'){
            s+='a';
           
        }
        if(seen[nh][nw]) continue;

        dfs(nh,nw);
       
    } 
    
    if(s.size()<ans) ans=s.size(); 
}


int main(){
    string s;
    cin>>s;
    string h=s;
    reverse(h.begin(),h.end());
    int n=s.size();
    string a,b,c,d;
    rep(i,(n-1)/2){
        a+=s[i];
        c+=s[i];
    }
    for(int i=(n+3)/2-1;i<n;i++){
        b+=s[i];
        d+=s[i];
    }
    reverse(c.begin(),c.end());
    reverse(d.begin(),d.end());
    (h==s && a==c && b==d)? cout<<"Yes":cout<<"No";

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#define pb push_back
#define INF 1000000000
#define mp make_pair
#define ll long long
#define tc int t; cin>>t; while(t--)
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define pi pair<int,int>
#define pii vector<pair<int,int>>

using namespace std;

#define nl '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: ", cout << to_string(__VA_ARGS__) << endl
/*compact version*/
template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template<typename T> int SIZE(const T &t) { return t.size(); } string to_string(string &s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char* s) { string tmp(s); return to_string(tmp); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(char c) { return string({c}); } template<size_t N> string to_string(bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ((x1 < b.size()) ? (b.to_string()).substr(x1, x2 - x1 + 1) : ""); reverse(begin(t), end(t)); return '"' + t + '"'; } template <typename A, typename... C> string to_string(A (&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += nl; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += nl; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += nl; return res; }
/*end of compact version*/

void prl(int x) {cout << x << endl;}
void pr(int x) { cout << x << " ";}

void init() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
}
const int sz = 10001000;
const int size = 1e6 + 1;


int main() {
    init();
    // tc
    {
        int n; cin >> n;
        int a, b; cin >> a >> b;

        bool flag = 0;
        for (int i = n; i <= b; i += n ) {
            if (i >= a && i <= b) flag = 1;
        }
        if (flag == 1) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3672
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        int l = S.length();
        int minval = 1000;
        for(int i=0; i+3<=l; i++) {
            String sub = S.substring(i, i+3);
            Integer val = Integer.parseInt(sub);
            Integer tmp = Math.abs(val - 753);
            if(tmp < minval) minval=tmp;
//            System.out.println(sub);
        }
        System.out.println(minval);
    }
}


Measured memory_bytes: 23764
//xenowitz -- Jai Shree Ram
#include<bits/stdc++.h>
using namespace std;

#define fori(i,a,b) for (long int i = a; i <= b ; ++i)
#define ford(i,a,b) for(long int i = a;i >= b ; --i)
#define mk make_pair
#define mod 1000000007
#define pb push_back
#define eb emplace_back
#define vec vector<long long int>
#define ll long long
#define rnd mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count())
#define pi pair<long long int,long long int>
#define sc second
#define fs first
#define stf shrink_to_fit

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t;
  cin >> t;

  if (t == 0) {
      cout << 1 << endl;
  } else {
      cout << 0 << endl;
  }
  return 0;
}


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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

signed main(){
	int n; cin >> n;
	vector<vector<int> > a(3,vector<int>(n));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 3; j++)cin >> a[j][i];
	}

	vector<int> ans(n,0);
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < n; j++){
			bool flag = true;
			for(int k = 0; k < n; k++){
				if(j == k)continue;
				if(a[i][j] == a[i][k]){
					flag = false;
					break;
				}
			}
			if(flag)ans[j]+=a[i][j];
		}
	}
	for(auto e : ans)cout << e << endl;

	return 0;
}




Measured memory_bytes: 3084
/**So..a**/
#include<bits/stdc++.h>

using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define PB(x, v) x.push_back(v);
#define M_P(a, b) make_pair(a, b)
#define pll pair<ll, ll>
#define ll long long
#define mll map<ll, ll>
#define vl vector<ll>
#define fa(x, v) for(auto x: v)
#define fr(i, a, b) for(int i= a;i <=b; i++)
#define TEST  ll Test; cin >> Test; while(Test--)

#define B_ begin()
#define E_ end()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define NL_ "\n"
#define F first
#define S second
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second

#define mod(a) a%1000000007

#define  ull unsigned long long
#define MAX  1000010

ll prime[MAX];
ll arr[MAX];

bool div(ll n)
{
    bool ans = true;
    ll r= n;
    if(n%2==0)
    {
        if(prime[2])
            ans = false;
        prime[2] = 1;
        while(n%2==0)
            n/=2;
    }
    ll i=3;
    while(i*i<=r)
    {
        if(n%i==0)
        {
            if(prime[i])
                ans = false;
            prime[i] = 1;
            while(n%i==0)
                n/=i;

        }
        i+=2;
    }
    if(n>1)
    {
       if(prime[n])
            ans = false;
        prime[n] = 1;

    }
    return ans;


}


int main()
{

    FAST;
    fr(i, 1, MAX-1) prime[i] = 0;
    ll n;
    cin >> n;
    fr(i, 1, n) cin>> arr[i];
    ll ans = true;
    fr(i, 1, n)
    {
        ans = (ans && div(arr[i])) ;
    }
    if(ans)
    {
        cout <<"pairwise coprime";
    }
    else
    {
        ll gcd  = 0;
        fr(i, 1, n) gcd = __gcd(gcd, arr[i]);
        if(gcd==1)
            cout << "setwise coprime";
        else
            cout <<"not coprime";
    }


    return 0;
}


Measured memory_bytes: 19260
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define int long long

int N, Q;
vector<int> G[200200];
int cnt[200200];

void dfs(int v, int pa) {
    int res = cnt[v];
    for(auto u : G[v]) {
        if(u == pa) continue;
        cnt[u] += res;
        dfs(u, v);
    }
}

void solve() {
    cin >> N >> Q;
    rep(i, N - 1) {
        int a, b; cin >> a >> b; a --; b --;
        G[a].pb(b); G[b].pb(a);
    }
    rep(i, N) {
        cnt[i] = 0;
    }
    rep(i, Q) {
        int p, x; cin >> p >> x;
        p --; cnt[p] += x;
    }
    dfs(0, -1);
    rep(i, N) {
        cout << cnt[i] << " ";
    }
    cout << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 24320
//InTheNameOfGod
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,j,k) for(int i=j;i<k;++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define pb push_back
#define lb(i) i&(-i);
const int maxn = 1e5+5;
string s;
ll n,mx,mx2,h,y[maxn],re;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n>>h;
    rep(i,0,n)
    {
        ll x;
        cin>>x>>y[i];
        mx=max(mx,x);
    }
    sort(y,y+n);
    reverse(y,y+n);
    mx2=0;
    rep(i,0,n)
    {
        if(y[i]>=mx)
        {
            h-=y[i];
            re++;
        }
        if(h<=0)break;
    }
    if(h>0)
    {
        re+=(h+mx-1)/mx;
    }
    cout<<re;
    return 0;
}


Measured memory_bytes: 1024
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vll         vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  1005
ll n,m;
string s[N];
ll dp[N][N];
int main()
{
	ios
	ll i,j;
	cin>>n>>m;
	for(i=1;i<=n;i++){
		cin>>s[i];
		s[i]=" "+s[i];
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(i==1&&j==1)dp[i][j]=1;else
			if(s[i][j]=='#');
			else
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%hell;
		}
	}
	cout<<dp[n][m];
}


/*

8
1 1 1 2 2 5 5 
1 -1 -1 -1 1 2 -1 -1 


*/

Measured memory_bytes: 9088
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> n = new ArrayList<Integer>();
		String s = sc.next();
		String t = sc.next();

		boolean flag = false;
		for (int i = 0; i < s.length(); i++) {
			s = s.substring(1, s.length()) + s.substring(0, 1);
			if (s.equals(t)) {
				flag = true;
				break;
			}
		}

		if (flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

void reset(int board[8][8]){
    for(int i=0;i<8;i++){
        for(int j=0;j<8;j++){
            board[i][j]=0;
        }
    }
}

bool isOK(int board[8][8], int x, int y){
    if(y==7) return true;
    for(int i=1;i<8-y;i++){
        if(x-i<0)break;
        if(board[x-i][y+i]==1){
            return false;
        }
    }
    for(int i=1;i<8-y;i++){
        if(x+i>7)break;
        if(board[x+i][y+i]==1){
            return false;
        }
    }
    return true;
}

int main(){
    int board[8][8];
    int k;
    cin >> k;
    int x[8],y[8];
    rep(i,k){
        cin >> y[i] >> x[i];
    }
    int perm[] = {0,1,2,3,4,5,6,7};
    do{
        reset(board);
        bool flg= false;
        rep(j,k){
            board[x[j]][y[j]] = 1;
            if(perm[y[j]]!=x[j]){
                flg =true;
                break;
            }
        }
        if(flg) continue;
        for(int i=0;i<8;i++){
            board[perm[i]][i]=1;
        }
        
        for(int i=0;i<8;i++){
            if(!isOK(board,perm[i],i)) break;
            if(i==7&&isOK(board,perm[7],7)){
                rep(h,8){
                    rep(w,8){
                    if(board[w][h]==0)cout << ".";
                    else cout << "Q";
                    }
                    cout << endl;
                }
                return 0;
            }
        }
    }while(next_permutation(perm,perm+8));
    return 0;
}


Measured memory_bytes: 3112
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int n;
    cin>>n;
    FOR(i,0,n){
        cout<<"ACL";
    }
}


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

int main(){
  int n,a[110],alice=0,bob=0;
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n,greater<int>());
  for(int i=0;i<n;i++){
    if(i%2==0) alice+=a[i];
    else bob+=a[i];
  }
  cout<<alice-bob;
}


Measured memory_bytes: 3644
# AtCoder Beginner Contest 046 - A
# -*- encoding: UTF-8 -*-
a,b,c = map(int, input().split())

colors = {}

colors[a] = 1

if b in colors :
  colors[b] = 2
else :
  colors[b] = 1

if c in colors :
  colors[c] = colors[c] + 1
else :
  colors[c] = 1

print(len(colors))



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


int N;
string S;

ll solve(){
    N=S.size();
    vector<int> whsum(N+1,0);
    vector<int> blsum(N+1,0);
    for(int i=0;i<N;i++){
        whsum[i+1]=whsum[i]+(S[i]=='.' ? 1 : 0);
        blsum[i+1]=blsum[i]+(S[i]=='#' ? 1 : 0);
    }
    
    ll res=1LL<<60;
    for(int left=0;left<=N;left++){
        ll tmp=0;
        tmp+=blsum[left]-blsum[0];
        tmp+=whsum[N]-whsum[left];
        
        res=min(res,tmp);
    }
    return res;
}

int main(){
    cin>>N>>S;
    cout<<solve()<<endl;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K,S,a=0;
  cin>>K>>S;
  for(int x=0;x<=K;x++){
    for(int y=0;y<=K;y++){
       if(S-x-y>=0&&S-x-y<=K) a++;
    }
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        for (int i = 0; i < 5; i++) {
            int n = scan.nextInt();
            if (n == 0) {
                System.out.println(i + 1);
                break;
            }
        }
    }
}

Measured memory_bytes: 35672
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

const int kMaxDepth = 19;

class TreeNode {
public:
  TreeNode(int d, int th) {
    depth = d;
    thresh = th;
    left = nullptr;
    right = nullptr;
  };
public:
  int depth;
  int thresh;
  TreeNode *left;
  TreeNode *right;
  map<char, int> counts;
};

void AddChar(TreeNode *root, int i, int ch) {
  TreeNode *node = root;
  for (int d = 0; d <= kMaxDepth; ++d) {
    node->counts[ch]++;
    if (i < node->thresh) {
      node = node->left;
    } else {
      node = node->right;
    }
  }
}

void SubChar(TreeNode *root, int i, int ch) {
  TreeNode *node = root;
  for (int d = 0; d <= kMaxDepth; ++d) {
    node->counts[ch]--;
    if (i < node->thresh) {
      node = node->left;
    } else {
      node = node->right;
    }
  }
}

map<char, int> GetCounts(TreeNode *root, int i) {
  if (i == 1<<(kMaxDepth)) {
    return root->counts;
  }
  
  map<char, int> counts;
  TreeNode *node = root;
  for (int d = 0; d < kMaxDepth; ++d) {
    if (i < node->thresh) {
      node = node->left;
    } else {
      for (char ch = 'a'; ch <= 'z'; ++ch) {
	counts[ch] += node->left->counts[ch];
      }	
      node = node->right;
    }
  }
  return counts;
}

int main() {
  TreeNode *root = new TreeNode(0, 1<<(kMaxDepth - 1));

  // Construct
  queue<TreeNode*> q;
  q.push(root);
  while (not q.empty()) {
    TreeNode *node = q.front();
    q.pop();
    int delta = 1<<(kMaxDepth - 2 - node->depth);
    node->left = new TreeNode(node->depth + 1, node->thresh - delta);
    node->right = new TreeNode(node->depth + 1, node->thresh + delta);
    if (node->depth < kMaxDepth) {
      q.push(node->left);
      q.push(node->right);
    }
  }

  int N;
  cin >> N;
  string S;
  cin >> S;

  for (int i = 0; i < N; ++i) {
    AddChar(root, i, S[i]);
  }

  int Q;
  cin >> Q;
  
  for (int query = 0; query < Q; ++query) {
    int cmd;
    cin >> cmd;
    if (cmd == 1) {
      int i;
      char ch;
      cin >> i >> ch;
      --i;
      SubChar(root, i, S[i]);
      S[i] = ch;
      AddChar(root, i, S[i]);
    } else {
      int l, r;
      cin >> l >> r;
      --l; --r;
      map<char, int> c1 = GetCounts(root, l);
      map<char, int> c2 = GetCounts(root, r + 1);
      int ans = 0;
      for (char ch = 'a'; ch <= 'z'; ++ch) {
	if (c2[ch] - c1[ch] > 0) {
	  ++ans;
	}
      }
      cout << ans << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 387716
#include <stdio.h>
#include <math.h>
#include <iostream>
#define MAXN 100005
using namespace std;


int main()
{
    int n;
    cin>>n;
    int flag = 1;
    int t[MAXN], x[MAXN], y[MAXN];
    for(int i = 0; i < n; i++)
    {
        cin>>t[i]>>x[i]>>y[i];
        if(t[i] % 2)
        {
            if((x[i] + y[i]) % 2 == 0)
                flag = 0;
        }
        if((x[i] + y[i]) > t[i])
            flag = 0;
        if(fabs(x[i]) > t[i] || fabs(y[i]) > t[i])
            flag = 0;
    }
    if(flag == 0)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 1408
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        mut a: [usize;n],
    }

    a.sort();
    a.push(0);
    debug!(a);
    let mut b: Vec<usize> = Vec::new();
    let mut cnt = 0;
    for i in 0..n {
        let now = a[i];
        let next= a[i+1];
        if now==next {
            cnt += 1;
        } else {
            cnt += 1;
            b.push(cnt);
            cnt = 0;
        }
    }
    debug!(b);
    let mut ans = 0;
    for i in b {
        if i%2!=0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

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

    string s;
    for(int i=0; i<n; i++){
        cin >> s[i];
    }

    int p_counter=0;
    int w_counter=0;
    int g_counter=0;
    int y_counter=0;

    for(int i=0; i<n; i++){
        if(s[i]=='P'){
            p_counter++;
        }else if(s[i]=='W') {
            w_counter++;
        }else if(s[i]=='G') {
            g_counter++;
        }else{
            y_counter++;
        }
    }

    if(p_counter==0 || w_counter==0 || g_counter==0 || y_counter==0){
        cout << "Three";
    }else{
        cout << "Four";
    }

    return 0;
}

Measured memory_bytes: 256
import bisect
import numpy


N,K=[ int(x) for x in raw_input().split() ]
X=[ int(x) for x in raw_input().split() ]
zl=bisect.bisect(X, 0)

XL=[0]+sorted([ -x for x in X[:zl] ])
XR=[0]+X[zl:]

SL= XL
SR= XR
ans=1e20

for m in range(K+1):
    try:
        anstmp = SL[m]+SR[K-m] + min(SL[m], SR[K-m] )
        ans=min(ans, anstmp)
    except:
        pass
print int(ans)


Measured memory_bytes: 19924
#include <bits/stdc++.h>
using namespace std;
#define M 210
#define N 5100
#define ll long long
int n,m;
int a[N],b[M][N],mx[M][N][16],bir[N];
ll sum[N],ans;
int query(int x,int l,int r)
{
	int t=bir[r-l+1];
	return max(mx[x][l][t],mx[x][r-(1<<t)+1][t]);
}
void solve(int l1,int r1,int l2,int r2)
{
	if(l1>r1)return;
	int mid=(l1+r1)>>1;
	ll v=0,p=max(l2,mid);
	for(int i=max(l2,mid);i<=r2;i++)
	{
		ll t=0;
		for(int j=1;j<=m;j++)
			t+=query(j,mid,i);
		t-=sum[i-1]-sum[mid-1];
		if(t>v)v=t,p=i;
	}
	ans=max(ans,v);
	solve(l1,mid-1,l2,p);
	solve(mid+1,r1,p,r2);
}
int main()
{
	//freopen("tt.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<n;i++)
		sum[i]=sum[i-1]+a[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&b[j][i]);
	bir[1]=0;
	for(int i=2;i<=n;i++)
		bir[i]=bir[i>>1]+1;
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)mx[i][j][0]=b[i][j];
		for(int j=1;j<=bir[n];j++)
			for(int k=1;k+(1<<j)-1<=n;k++)
				mx[i][k][j]=max(mx[i][k][j-1],mx[i][k+(1<<j-1)][j-1]);
	}
	solve(1,n,1,n);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 70912
#include <stdio.h>

typedef struct List {
	struct List *next;
	int v;
	long long sum;
} list;

int main()
{
	int i, n, m, u, w;
	long long c;
	list *adj[100001] = {}, e[200001], *p;
	scanf("%d %d", &n, &m);
	for (i = 0; i < m; i++) {
		scanf("%d %d %lld", &u, &w, &c);
		e[i*2].v = w;
		e[i*2+1].v = u;
		e[i*2].sum = c;
		e[i*2+1].sum = c;
		e[i*2].next = adj[u];
		e[i*2+1].next = adj[w];
		adj[u] = &(e[i*2]);
		adj[w] = &(e[i*2+1]);
	}
	
	int flag[100001] = {}, q[100001] = {}, head, tail;
	long long x[100001];
	q[0] = 1;
	flag[1] = 1;
	x[1] = 0;
	for (head = 0, tail = 1; head < tail; head++) {
		u = q[head];
		for (p = adj[u]; p != NULL; p = p->next) {
			w = p->v;
			if (flag[w] == 0) {
				flag[w] = -flag[u];
				x[w] = p->sum - x[u];
				q[tail++] = w;
			}
		}
	}
	
	for (i = 0; i < m; i++) {
		u = e[i*2].v;
		w = e[i*2+1].v;
		c = e[i*2].sum;
		if (flag[u] == flag[w]) {
			if ((x[u] + x[w] + c) % 2 != 0) {
				printf("0\n");
				fflush(stdout);
				return 0;
			} else {
				q[0] = u;
				q[1] = w;
				x[u] += (c - x[u] - x[w]) / 2;
				x[w] = c - x[u];
				flag[u] = 0;
				flag[w] = 0;
				for (head = 0, tail = 2; head < tail; head++) {
					u = q[head];
					for (p = adj[u]; p != NULL; p = p->next) {
						w = p->v;
						if (flag[w] != 0) {
							flag[w] = 0;
							x[w] = p->sum - x[u];
							q[tail++] = w;
						} else if (x[u] + x[w] != p->sum) {
							printf("0\n");
							fflush(stdout);
							return 0;
						}
					}
				}
				
				for (u = 1; u <= n; u++) if (x[u] <= 0) break;
				if (u <= n) printf("0\n");
				else printf("1\n");
				fflush(stdout);
				return 0;
			}
		} else if (x[u] + x[w] != c) {
			printf("0\n");
			fflush(stdout);
			return 0;
		}
	}
	
	long long min[2] = {(long long)1 << 60, (long long)1 << 60};
	for (u = 1; u <= n; u++) if (x[u] < min[(flag[u]+1)/2]) min[(flag[u]+1)/2] = x[u];
	if (min[0] + min[1] < 2) printf("0\n");
	else printf("%lld\n", min[0] + min[1] - 1);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 8752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF=1e18,MOD=1e9+7;
int main(){
	ll n,a,ans=0;
	cin>>n;
	map<ll,ll>arr,cmp;
	for(int i=0;i<n;i++){
		cin>>a;
		if(!arr[a])arr[a]++;
		else arr[a]=0;
	}
	for(auto itr:arr){
		if(itr.second>0)ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 6528
use std::io;

fn main() {
    let n: i32 = read::<i32>();
    let a_vec = read_vec::<i32>();

    let mut list: Vec<i32> = Vec::new();

    for _num in 0..n {
        list.push(0);
    }

    for jyoshi in a_vec {
        list[jyoshi as usize - 1] += 1;
    }
    for i in &list {
        println!("{}", i);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut line = String::new();
    io::stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    io::stdin().read_line(&mut line)
        .ok()
        .expect("Faild to read Vec");
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4176
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] B = new int[N - 1];
    for (int i = 0; i < B.length; i++) {
      B[i] = sc.nextInt();
    }

    int next = B[0];
    int ans = B[0];
    for (int i = 1; i < B.length; i++) {
      int cur = Math.min(next, B[i]);
      ans += cur;
      next = B[i];
    }
    ans += next;
    System.out.println(ans);
  }
}


Measured memory_bytes: 22996
if __name__ == '__main__':
    N = int(raw_input())
    A = map(int, raw_input().split())
    head = 0
    tail = 0
    num_2 = 0
    num_10 = 0
    ans = 0
    now_len = 0
    while(head < N):
        num_2 = num_2 ^ A[head]
        num_10 += A[head]
        if num_2 == num_10:
            head += 1
            now_len += 1
            ans += now_len
        else:
            num_2 ^= A[tail]
            num_10 -= A[tail]
            num_2 ^= A[head]
            num_10 -= A[head]
            tail += 1
            now_len -= 1

    print(ans)

Measured memory_bytes: 20020
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		String[] s = new String[n];
		Map<String, Integer> map = new HashMap<String, Integer>();
		for (int i = 0; i < n; i++) {
			s[i] = scanner.next();
			if(map.containsKey(s[i])) {
				map.put(s[i], map.get(s[i]) + 1);
			}else {
				map.put(s[i], 1);
			}
		}
		
		int m = scanner.nextInt();
		String[] t = new String[m];
		for (int i = 0; i < m; i++) {
			t[i] = scanner.next();
			if(map.containsKey(t[i])) {
				map.put(t[i], map.get(t[i]) - 1);
			}
		}
		
		
		int max = 0;
		for(Map.Entry<String, Integer> ans: map.entrySet()) {
			max = Math.max(max, ans.getValue());
		}
		System.out.println(max);
		scanner.close();

	}

}


Measured memory_bytes: 21332
#include <iostream>
using namespace std;
int main(void){
        int N,K,P;
        cin >> N;
        while(N--){
            cin >> K >> P;
            if(K%P == 0){
                cout << P << endl;  
            }else{
                cout << K%P << endl;
            }
        }
        
    return 0;
    }


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

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

int main() {
  string s;
  cin >> s;
  int ans = 100000000;
  int K = s.size();
  for (int i = 0; i <= K - 3; i++) {
    int a = ctoi(s.at(i));
    int b = ctoi(s.at(i + 1));
    int c = ctoi(s.at(i + 2));
    ans = min(ans, abs(a * 100 + b * 10 + c - 753));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3584