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

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

  int t = N, c = 0;
  // // 148
  // c += t % 10; // 8
  // t = t / 10; // 14
  // // 14
  // c += t % 10; // 4
  // t = t / 10; // 1
  // // 1
  // c += t % 10; // 1
  // t = t / 10; // 0
  while (t > 0) {
    c += t % 10;
    t = t / 10;
  }
  cout << ((N % c == 0) ? "Yes" : "No") << endl;
}

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

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

//重複順列
vector<ll> buf;
void permutation(ll i, const ll size, const ll range_start, const ll range_end)
{
    if (i == size) {
      // ここで所望の作業を行う
      for(ll itr:buf){
        cout << itr;
      }
    }
    else{
        for(ll j = range_start; j <= range_end; ++j){
            buf[i] = j;
            permutation(i + 1, size, range_start, range_end);
        }
    }
}
vector<ll> C;
vector<vector<ll>> A;
ll inf = 1000000000;
ll n, m, x, a, ans = inf;
bool flag = true;
void check(ll index, vector<ll> X, ll cost){
  if(index == n){
    flag = true;
    RAP(i, m){
      if(X[i]<x){
        flag = false;
      }
      //cout << X[i] << " ";
    }
    //cout << endl;
    if(flag){
      ans = min(ans, cost);
    }
  }else{
    check(index+1, X, cost);
    RAP(i, m){
      X[i] += A[index][i]; 
    }
    check(index+1, X, cost+C[index]);
  }
}
int main(void)
{
 cin >> n >> m >> x;
 C.resize(n);
 A.resize(n);
 RAP(i, n){
   cin >> C[i];
   RAP(j, m){
     cin >> a;
     A[i].push_back(a);
   }
 }
 vector<ll> X(m, 0);
 check(0, X, 0);
 if(ans == inf){
   cout << -1 << endl;
 }else{
   cout << ans << endl;
 }
 
 return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define double long double
using namespace std;
struct node{
	double x,y;
}a[105];
int n;
double ansx,ansy,sy=0,sx=0;
double ans=2000,t;
double del=0.9995; 
inline double dis(node aa,node bb){
	return sqrt((aa.x-bb.x)*(aa.x-bb.x)+(aa.y-bb.y)*(aa.y-bb.y));
}
double calc(double x,double y){
	double ans=0;
	for(int i=1;i<=n;i++){
		ans=max(ans,dis((node){x,y},a[i]));
	}
	return ans;
}
void SA(){
	double x=ansx,y=ansy;
	t=2000;
	while(t>1e-14){
		double X=x+((rand()<<1)-RAND_MAX)*t;
		double Y=y+((rand()<<1)-RAND_MAX)*t;
		double now=calc(X,Y);
    	double Delta=now-ans;
    	if(Delta<0){
    		x=X,y=Y;
    		ans=now;
		}
		else if (exp(-Delta/t)*RAND_MAX>rand()) x=X,y=Y; 
        t*=del;
	}
}
int main(){
	//freopen("a.in","r",stdin);
	int cnt=0;
	srand(1000211237);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		cin>>a[i].x>>a[i].y;
		sx+=a[i].x,sy+=a[i].y;
	}
	ansx=(double)sx/n,ansy=(double)sy/n;
	while((double)clock()/CLOCKS_PER_SEC<0.93) SA(),cnt++;
	printf("%.14Lf",ans);
	//cout<<" "<<cnt;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	int N,C; cin >> N >> C;
	vector<tuple<int,int,int>> S(N);
	rep(i,N){
		int s,t,c; cin >> s >> t >> c;
		S[i] = tie(s,t,c);
	}
	sort(S.begin(),S.end());
	vector<bool> used(N,false);
	int ans = 0;
	while(true){
		int time = 0;
		int channel = -1;
		bool ok = false;
		rep(i,N){
			if(get<0>(S[i]) >= time && used[i] == false){
				if(get<2>(S[i]) == channel){
					time = get<1>(S[i]);
					used[i] = true;
					ok = true;
				}
				else if(get<0>(S[i]) > time){
					time = get<1>(S[i]);
					channel = get<2>(S[i]);
					used[i] = true;
					ok = true;
				}
			}
		}
		if(ok) ans++;
		else break;
	}
	cout << ans << endl;
	
}
   


Measured memory_bytes: 1408
#include <stdio.h>
int main(void)
{
  long n, a, b, divid, remain, ans;

  // 標準入力からの値取得
  scanf("%ld %ld %ld", &n, &a, &b);

  // 計算
  divid = n / (a + b);
  remain = n % (a + b);
  ans = a * divid + ((remain < a) ? remain : a);

  // 出力
  printf("%ld\n", ans);
  return 0;
}

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

#define m(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(int i=1;i<=n;i++)
typedef long long ll;
const int MAXN=1e5+10;

int main(){
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	cout<<s1[0]<<s2[1]<<s3[2]<<endl;
	return 0;
}

Measured memory_bytes: 764
#include<stdio.h>
int m,n;
bool d[90][90];
bool cr[90][90];
int i,j;
int dx[4]={-1,0,0,1};
int dy[4]={0,1,-1,0};

int max(int a,int b){
	if(a>b)return a;
	else return b;
}

int dfs(int r,int c){
	int ma=1;
	for(int k=0;k<4;k++){
		if(r+dx[k]>=0&&r+dx[k]<n&&c+dy[k]>=0&&c+dy[k]<m&&cr[r+dx[k]][c+dy[k]]){
			cr[r+dx[k]][c+dy[k]]=false;
			ma=max(ma,dfs(r+dx[k],c+dy[k])+1);
			cr[r+dx[k]][c+dy[k]]=true;
		}
	}
	return ma;
}

int main(){
	while(1){
		scanf("%d %d",&m,&n);
		if(m==0&&n==0)return 0;
		int a;
		for(i=0;i<n;i++)for(j=0;j<m;j++){
			scanf("%d",&a);
			if(a==1)d[i][j]=true;
			else d[i][j]=false;
		}
		int ans=0;
		for(i=0;i<n;i++)for(j=0;j<m;j++)cr[i][j]=d[i][j];
		for(i=0;i<n;i++)for(j=0;j<m;j++){
			if(cr[i][j]){
				cr[i][j]=false;
				ans=max(ans,dfs(i,j));
				cr[i][j]=true;
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1048
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var S = ReadLine();
            WriteLine(Regex.Match(S, "^[A]?KIH[A]?B[A]?R[A]?$",RegexOptions.None).Success?"YES":"NO");
        }
    }
}

Measured memory_bytes: 21636
#include <stdio.h>
#include <string.h>
#include <ctype.h>

struct words{
	char str[33];
	int cnt,length;
};

struct max{
	char str[33];
	int cnt;
};

struct longs{
	char str[33];
	int length;
};

int main(){
	int i,k,tmp,flag;
	char str[1024],word[33];
	char *ptr;
	struct words words[50];
	struct max max;
	struct longs longs;

	gets(str);

	ptr = str;
	max.cnt = 0;
	longs.length = 0;

	tmp = 1;
	while(*ptr != '\0'){
		i = 0;
		word[0] = '\0';
		while(1){
			if(isspace(*ptr)){
				*ptr++;
				break;
			}else if(*ptr == '\0'){
				break;
			}
			word[i] = *ptr;
			word[i+1] = '\0';
			*ptr++;
			i++;
		}
		flag = 0;
		for(k = 0;k < tmp;k++){
			if(strcmp(words[k].str,word) == 0){
				words[k].cnt++;
				if(max.cnt < words[k].cnt){
					max.cnt = words[k].cnt;
					strcpy(max.str,words[k].str);
				}
				flag = 1;
				break;
			}
		}
		if(!flag){
			strcpy(words[tmp-1].str,word);
			words[tmp-1].cnt = 1;
			words[tmp-1].length = strlen(word);
			if(max.cnt < words[tmp-1].cnt){
				max.cnt = words[tmp-1].cnt;
				strcpy(max.str,words[tmp-1].str);
			}
			if(longs.length < words[tmp-1].length){
				longs.length = words[tmp-1].length;
				strcpy(longs.str,words[tmp-1].str);
			}
			tmp++;
		}
	}

	printf("%s %s\n",max.str,longs.str);

	return 0;
}

Measured memory_bytes: 540
#include<cstdio>
int main()
{
	int a,b,c,flag=0;
	scanf("%d %d %d",&a, &b, &c);
	if(a+b+c==17 && a*b*c==175) flag=1;
	if(flag==1)
		printf("YES\n");
		else printf("NO\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define cbuf(buf, init) memset(buf, init, sizeof(buf))

template <class T>
constexpr T modp(T x, T y)
{
    return (y + x % y) % y;
}
template <class T>
constexpr T sq(T x)
{
    return x * x;
}
template <class T>
constexpr double divd(T x, T y)
{
    static_cast<double>(x) / static_cast<double>(y);
}

template <class T>
T nextInput()
{
    T t;
    cin >> t;
    return t;
}

#define netint nextInput<ll>()
#define netstr nextInput<string>()

template <class T>
void print(T&& t)
{
    cout << forward<T&&>(t) << endl;
}

void print(double t) { cout << fixed << setprecision(14) << t << endl; }

//

int main()
{
    //
    ll N = netint, A = netint, B = netint;
    cout << (abs(A - B) % 2 == 0 ? "Alice" : "Borys") << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAXI 1000000
// DP(????????????????????????)
int main(void){
  int dp[MAXI+1], dp2[MAXI+1];
  int i, j, t, n;
  for(i=0; i<=MAXI; i++) dp[i] = dp2[i] = i;
  i = 2;
  while(1){
    if((t = (int) i * (i+1) * (i+2) / 6) > MAXI) break;
    if(t % 2)
      for(j=t; j<=MAXI; j++)
        if(dp2[j] > dp2[j-t] + 1) dp2[j] = dp2[j-t] + 1;
    for(j=t; j<=MAXI; j++){
      if(dp[j] > dp[j-t] + 1) dp[j] = dp[j-t] + 1;
    }
    i++;
  }
  while(1){
    scanf("%d", &n);
    if(n == 0) break;
    printf("%d %d\n", dp[n], dp2[n]);
  }
} 

Measured memory_bytes: 8412
import sys
input = sys.stdin.readline
def main():
  N = int(input())
  al = []
  for _ in range(N):
    al.append(int(input())-1)
  bl = [False]*N
  i = 0
  nb = 0
  while bl[i] == False:
    bl[i] = True
    i = al[i]
    nb += 1
    if i == 1:
      print(nb)
      break
  else:
    print(-1)

main()

Measured memory_bytes: 7852
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int K = scanner.nextInt();
    char[] s = scanner.next().toCharArray();

    s[K - 1] = Character.toLowerCase(s[K - 1]);
    System.out.println(new String(s));
  }
}


Measured memory_bytes: 21204
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	int c1 = 0, c2 = 0, c3 = 0;
	for (int i = 0; i < N; ++i) {
		if (A[i] == 1) ++c1;
		if (A[i] == 2) ++c2;
		if (A[i] == 3) ++c3;
	}
	vector<vector<vector<double> > > dp(c3 + 1, vector<vector<double> >(c2 + c3 + 1, vector<double>(c1 + c2 + c3 + 1)));
	for (int i = 0; i <= c3; ++i) {
		for (int j = 0; i + j <= c2 + c3; ++j) {
			for (int k = 0; i + j + k <= c1 + c2 + c3; ++k) {
				if (i + j + k == 0) continue;
				if (k >= 1) dp[i][j][k] += dp[i][j][k - 1] * k;
				if (j >= 1) dp[i][j][k] += dp[i][j - 1][k + 1] * j;
				if (i >= 1) dp[i][j][k] += dp[i - 1][j + 1][k] * i;
				dp[i][j][k] = (dp[i][j][k] + N) / (i + j + k);
			}
		}
	}
	cout.precision(10);
	cout << dp[c3][c2][c1] << '\n';
	return 0;
}

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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int N;
    cin >> N;
    int H[N];
    rep(i, N) cin >> H[i];
    int count = 0;
    int max_cnt = 0;
    int cnt = 0;
    rep(i, N-1){
        if(H[i] >= H[i + 1]){
            cnt++;
            max_cnt = max(max_cnt, cnt);
        }else{
            cnt = 0;
        }
    }
    cout << max_cnt << endl;
    return 0;
}

Measured memory_bytes: 640
N = int(input())
H = list(map(int,input().split()))
ans = []
count = 0
if len(H) == 1:
  print(0)
  exit()
for i in range(1,N):
  if H[i-1] < H[i]:
    ans.append(count)
    count = 0
  elif H[i-1] >= H[i]:
    count += 1
  if i == N-1:
    ans.append(count)

print(max(ans))

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long m,long long n)
{
	if(n==0)
		return m;
	return gcd(n,m%n);
}
int main()
{
	long long n;
	scanf("%lld",&n);
	//printf("%lld\n",gcd(2,n));
	printf("%lld",2*n/gcd(2,n));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int            int64_t
#define double         long double
#define nitro          ios_base::sync_with_stdio(false);cin.tie(0);
#define vi             vector<int64_t>
#define pub            push_back
#define puf            push_front
#define pob            pop_back
#define pof            pop_front
#define PI             3.1415926535897932384626433832795
#define read(a)        for(auto& x : a) cin>> x
#define endl           '\n'
#define gap            ' '
#define min3(a,b,c)    min(a, min(b, c))
#define max3(a,b,c)    max(a, max(b, c))
#define MOD            1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    nitro
    string s1,s2;cin>>s1>>s2;
    if(s1.size()>s2.size()) return puts("GREATER")*0;
    else if(s1.size()<s2.size()) return puts("LESS")*0;
    else
    {
    	for(int i=0;i<s1.size();++i)
    	{
    		if(s1[i]>s2[i]) return puts("GREATER")*0;
    		else if(s1[i]<s2[i]) return puts("LESS")*0;
    	}
    }
    cout<<"EQUAL";
    return 0;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=1;i<=n;i++)
#define fi first
#define se second
using namespace std;
typedef pair<ll,ll> P;

ll in[500500];
ll de[500500];
int main(){
    string s; cin >> s;
    ll res=0;
    ll k=0,l=0;
    rep(i,s.size()){
        if(s[i]=='<'){
            in[k]++;
            if(de[l]!=0) l++;
        }
        else{
            de[l]++;
            if(in[k]!=0) k++;
        }
    }
    ll ans = 0;
    if(s[0]=='<'){
        rep(i,s.size()+1){
            if(in[i]>=de[i]) ans += in[i]*(in[i]+1)/2;
            else ans+=de[i]+in[i]*(in[i]-1)/2;
            ans+=de[i]*(de[i]-1)/2;
        }
    }
    else{
        ans+=de[0]*(de[0]+1)/2;
        rep(i,s.size()+1){
                if(in[i]>=de[i+1]) ans += in[i]*(in[i]+1)/2;
                else ans+=de[i+1]+in[i]*(in[i]-1)/2;
                ans+=de[i+1]*(de[i+1]-1)/2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5892
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
 
 int main(){
     ll N,cnt=0;
     map<string,int> mp;
     cin>>N;
     string s;
     for(ll i=0;i<N;i++) 
     {
         cin>>s;
         mp[s]++;
         if(mp[s]==1) cnt++;
     }
     
     p(cnt);
     }




 

Measured memory_bytes: 19220
N, x = map(int, input().split())
A = [int(x) for x in input().split()]
T = [0] * N
B = [a for a in A]
for k in range(N):
  for i in range(N):
    B[i] = min(B[i], A[(i - k) % N])
  T[k] = sum(B) + k * x
print(min(T))

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

int n, k, ans;
string str;
int main() {
	cin >> n >> k;
	cin >> str;

	for (int i = 1; i < n; ++i)
		if (str[i] == str[i - 1])
			ans++;

	cout << min(n - 1, ans + 2 * k);

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  sort(ALL(a));
  int last=a[0];
  bool flag=true;
  rep1(i,n-1){
    if(last==a[i])flag=false;
    last=a[i];
  }
  if(flag){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a1(n);
  vector<int> a2(n);

  int sum1 = 0;
  int sum2 = 0;
  rep (i, n) cin >> a1[i];
  sum1 += a1[0];
  rep (i, n){
    cin >> a2[i];
    sum2 += a2[i];
  }

  int ans = sum1 + sum2;
  rep (i, n - 1){
    sum1 += a1[i+1];
    sum2 -= a2[i];
    int temp = sum1 + sum2;
    if (ans < temp) ans = temp;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3524
import sys

sys.setrecursionlimit(1000000)


def f(x, y, z):
    return x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x

def p_solve(N):
    ans = [0 for _ in range(N)]
    for x in range(1, 100):
        for y in range(1, 100):
            for z in range(1, 100):
                k = f(x, y, z)
                k -= 1
                if 0 <= k < len(ans):
                    ans[k] += 1
    return ans

def solve(N):
    ans = p_solve(N)
    for a in ans:
        print(a)

if __name__ == "__main__":
    N = int(input())
    solve(N)


Measured memory_bytes: 9308
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
int32_t main()
{
	fast;
	int n;
	cin >> n;
	int a[n + 1];
	vector<int > v[n + 1];
	for (int i = 2; i <= n; i++)
	{
		cin >> a[i];
		v[a[i]].push_back(i);
	}
	for (int i = 1; i <= n; i++)
	{
		cout << v[i].size();
		cout << "\n";
	}








}

Measured memory_bytes: 16080
/*input
6
30 10 60 10 60 50
*/
#include<bits/stdc++.h>
using namespace std;
#define maxim 2048
#define fn(i,n) for(long long i=0;i<n;i++)
#define fn1(i,n) for(long long i=1;i<n;i++)
#define ram 60
int main()
{
	int n;
	cin>>n;
	int a[n];
	fn(i,n)cin>>a[i];
	int dp[n];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
    int n, a, b, i;
    scanf("%d", &n);
    scanf("%d %d", &a, &b);

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

    int first = 0, second = 0, third = 0, ans;
    for (i = 0; i < n; i++) {
        if(p[i] <= a)
            first++;
        else if(a < p[i] && p[i] <= b)
            second++;
        else
            third++;
    }

    if(first <= second && first <= third)
        ans = first;
    else if(second < first && second <= third)
        ans = second;
    else
        ans = third;

    printf("%d", ans);

    return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n;
	cin >> n;
	
	int ans = 0;
	REP(i, n) ans += i + 1;
	
	cout << ans << endl;
	
	return 0;
}

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

int main(){
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	
	if(a+b == c+d)	printf("Balanced\n");
	else if	(a+b > c+d) printf("Left\n");
	else	printf("Right\n");
	
}


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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++){
    int &a = vec.at(i);
    cin >> a;
  }
  
  int count = 0, check = 0;
  for (int j = 0; j < N; j++){
    if (j == N - 1){
      if (check < count)
        cout << count << endl;
      else
        cout << check << endl;
    }
    else if (vec.at(j) >= vec.at(j + 1))
      count++;
    else if (vec.at(j) < vec.at(j + 1)){
      if (check < count)
        check = count;
      count = 0;
    }
  }
}

Measured memory_bytes: 640
n,m = map(lambda x:int(x),input().split())
heights = list(map(lambda x:int(x),input().split()))
good = 0
obscon = {}
for i in range(n):
  obscon[i] = [-1]
for i in range(m):
  a,b = map(lambda x:int(x)-1,input().split())
  obscon[a].append(b)
  obscon[b].append(a)
for i in range(n):
  if obscon[i] == [-1]:
    good += 1
  else:
    obscon[i].remove(-1)
    tall = 1
    for j in obscon[i]:
      if heights[i]>heights[j]:
        tall = min(tall,1)
      else:
        tall = min(tall,0)
    if tall == 1:
      good += 1
print(good)

Measured memory_bytes: 41644
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1,0};
const int dy[]={0,1,0,-1,1,1,-1,-1,0};
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(ll i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()){
		out << v[i] <<", ";
	}
	return out << "}" << endl;
}
int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n){
        cin >> a[i];
    }
    int ret = -100000;
    rep(i,n){  
        reps(j,i+1,n){
            ret = max(ret, abs(a[i]-a[j]));
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	vector<char> c(4);
	for (int i = 0; i < 4; i++) {
		cin >> c.at(i);
	}
	for (int i = 0; i < 3; i++) {
		if (c.at(i) == c.at(i + 1)) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;

}


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

int main(const int args, const char* argv[])
{
    string line;
    getline(cin, line);
    for(auto& it:line)
    {
        if(static_cast<int>(it) >= 97 && static_cast<int>(it) <= 122)
        {
            int tmp = static_cast<int>(it) - 97;
            it = static_cast<char>(tmp + 65);
        }
        else
        {
            if(static_cast<int>(it) >= 65 && static_cast<int>(it) <= 90)
            {
                int tmp = static_cast<int>(it) - 65;
                it = static_cast<char>(tmp + 97);
            }
        }
    }
    cout << line << endl;
    
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, n;
  cin >> h >> w >> n;
  cout << min(ceil((double) n / w), ceil((double) n / h)) << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.io.*;

public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn = null;
		int[] hit = new int[10000];
		int[] blow = new int[10000];
		int index = 0;
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			while( stdIn.hasNext() ){
				int[] A = new int[4];
				int[] B = new int[4];
				int[] check = new int[10];
				int sum = 0;
				for(int i = 0; i < 4; i++){
					A[i] = stdIn.nextInt();
					check[A[i]] = 1;
				}
				for(int i = 0; i < 4; i++){
					B[i] = stdIn.nextInt();
					if( check[B[i]] == 1 ){
						sum++;
					}
				}
				int h = 0;
				for(int i = 0; i < 4; i++){
					if( A[i] == B[i] ){
						h++;
					}
				}
				hit[index] = h;
				blow[index] = sum-h;
				index++;
			}
			
			for(int i = 0; i < index; i++){
				System.out.println(hit[i] + " " + blow[i]);
			}
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

void dfs(vector<string>& m,int i,int j){
  int di[]={1,0,-1,0};
  int dj[]={0,1,0,-1};
  for(int k=0;k<4;++k){
    int ni=i+di[k];
    int nj=j+dj[k];
    if(ni<0||ni>=12||nj<0||nj>=12)continue;
    if(m[ni][nj]=='1'){
      m[ni][nj]='0';
      dfs(m,ni,nj);
    }
  }
}

int main() {
  while(1){
    vector<string> m(12);
    for(int i=0;i<12;++i){
      cin>>m[i];
    }
    if(m[11].size()!=12)break;
    int cnt=0;
    for(int i=0;i<12;++i)
      for(int j=0;j<12;++j)
        if(m[i][j]=='1'){
          cnt++;
          dfs(m,i,j);
        }
    cout<<cnt<<endl;
    string wl;
    //cin>>wl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
const int MAX=3000;

signed main(){
    string A,B,C;cin>>A>>B>>C;
    if(A[A.size()-1]==B[0]&&B[B.size()-1]==C[0])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import Text.Printf

main :: IO()
main = do
  [a, b, _, k] <- map read . words <$> getLine
  printf "%s" $ slv a b k

slv :: Integer -> Integer -> Integer -> String
slv a b k | abs val > 10^18 = "Unfair"
          | otherwise = show val
  where val | even k = a - b
            | otherwise = b - a

Measured memory_bytes: 508
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] w = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextInt();
            sum += w[i];
        }

        int ans = 10000;
        int tmp = 0;
        for (int i = 0; i < n-1; i++) {
            tmp += w[i];
            sum -= w[i];
            ans = Math.min(ans, Math.abs(tmp - sum));
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    vector<vector<int> > A(3);
    repp(i,0,3) {
        repp(j,0,3) {
            int a; cin >> a;
            A[i].push_back(a);
        }
    }
    vector<vector<int> > B(3);
    repp(i,0,3) {
        repp(j,0,3) {
            B[i].push_back(false);
        }
    }
    int N; cin >> N;
    repp(k,0,N) {
        int b; cin >> b;
        repp(i,0,3) {
            repp(j,0,3) {
                if (A[i][j] == b) B[i][j] = true;
            }
        }
    }
    bool res = false;
    res |= B[0][0] && B[0][1] && B[0][2];
    res |= B[1][0] && B[1][1] && B[1][2];
    res |= B[2][0] && B[2][1] && B[2][2];
    res |= B[0][0] && B[1][0] && B[2][0];
    res |= B[0][1] && B[1][1] && B[2][1];
    res |= B[0][2] && B[1][2] && B[2][2];
    res |= B[0][0] && B[1][1] && B[2][2];
    res |= B[0][2] && B[1][1] && B[2][0];

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


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

typedef pair<int,int>  pint;
typedef pair<ll,ll>    pll;
typedef vector<int>    vint;
typedef vector<ll>     vll;
typedef vector<string> vstr;
typedef vector<pint>   vpint;
typedef vector<pll>    vpll;

#define vint2(v,n,m,init) vector<vector<int>> v(n, vector<int>(m, init))
#define vll2(v,n,m,init)  vector<vector<ll>>  v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vint var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vstr var(n); rep(i,n){cin >> var[i];}
#define ALL(var)         (var).begin(), (var).end()
#define sortall(var)     sort(ALL(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());

#define prt(var)         cout << (var) << "\n"
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//-----------------------------------------------------------------------------
class UnionFind{

public:
  int vertexNumber;
  vector<int> parents;

  UnionFind(int n){
    vertexNumber = n;
    parents.assign(n, -1);
  }
  ~UnionFind(){}

  int find(int x){
    if(parents[x]<0){return x;}
    else {return find(parents[x]);}
  }

  void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x==y){return;}

    if(parents[x]>parents[y]){
      int tmp = x;
      x = y;
      y = tmp;
    }

    parents[x] += parents[y];
    parents[y] = x;
  }

  int size(int x){return -parents[find(x)];}

  bool is_same(int x, int y){return find(x) == find(y);}

  int count_roots(){
    int ct=0;
    for(int i=0; i<vertexNumber; i++){
      if(parents[i]<0){ct++;}
    }
    return ct;
  }
};

int main(void){
  int n, q;
  cin >> n >> q;

  UnionFind uf(n);
  vint ans;
  rep(i,q){
    int t, u, v;
    cin >> t >> u >> v;
    if(t) ans.push_back(uf.is_same(u, v));
    else uf.unite(u, v);
  }

  for(auto x : ans){
    prt(x);
  }
}


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

int main() {
int N;  
string S ;
    cin >> N >> S ;
int count=0;
  for (int i=0;i<N-2;i++){
   if (S.at(i)=='A'&&S.at(i+1)=='B'&&S.at(i+2)=='C')
     count ++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
// Wrongri-La Shower

#include <iostream>
#include <queue>
#include <stack>
#include <tuple>

typedef long long ll;
typedef std::tuple<int,ll> P;

template <int n>
class UnionFind{
public:
    UnionFind(){
        init();
    }
    void init(){
        for(int i=0;i<n;i++){
            par[i] = i;
            rank[i] = 0;
            weight[i] = 0ll;
        }
    }
    P find(int x){
        if(x == par[x])return std::make_tuple(x, weight[x]);
        P p = find(par[x]);
        int y, w;
        std::tie(y, w) = p;
        
        return std::make_tuple(par[x] = y, weight[x] += w);
    }
    bool same(int x, int y){
        return std::get<0>(find(x)) == std::get<0>(find(y));
    }
    void unite(int x, int y, int l){
        P xp = find(x), yp = find(y);
        ll wx, wy;
        std::tie(x, wx) = xp;
        std::tie(y, wy) = yp;
        
        if(x == y){return;}
        
        if(rank[x] > rank[y]){
            par[y] = x;
            weight[y] = wx - wy + l;
        }else{
            par[x] = y;
            weight[x] = wy - wx - l;
            if(rank[x] == rank[y]){rank[y]++;}
        }
    }
    int rank[n], par[n];
    ll weight[n];
};

UnionFind<100001> uf;

int main(){
    std::ios_base::sync_with_stdio(false);
    
    int N, M;
    while(std::cin >> N >> M, N || M){
        uf.init();

        for(int i=0;i<M;i++){
            char c;
            std::cin >> c;

            if(c == '!'){
                int a, b, c;
                std::cin >> a >> b >> c;

                uf.unite(a, b, c);
            }else{
                int a, b;
                std::cin >> a >> b;

                if(!uf.same(a, b)){
                    std::cout << "UNKNOWN" << std::endl;
                }else{
                    P ap = uf.find(a), bp = uf.find(b);
                    ll wa = std::get<1>(ap), wb = std::get<1>(bp);

                    std::cout << wb-wa << std::endl;
                }
            }
        }
    }
}

Measured memory_bytes: 2756
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

n,d = map(int,input().split())

x = [list(map(int,input().split())) for i in range(n)]

#print(x)

ans = 0

import math

for i in range(n):
	for j in range(n):
		if i!=j:
			check = 0
			for k in range(d):
				#print(x[i][k],x[j][k])
				check = (x[i][k]-x[j][k])**2 + check
			check =math.sqrt(check) 
			#print(i,j,check)
			if check.is_integer():
				ans = ans + 1

#ルートの計算
#import math
#math.sqrt(x)

print(int(ans/2))
	


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

using namespace std ;

int main ( )
{
	string x , y;
	cin >> x >> y ;
    bool flag=0;
	if  (x.size() > y.size())
	{
		cout << "GREATER\n" ;
	}
	else if (x.size()==y.size() )
	{
		for (int i =0;i<x.size();i++)
		{
			if (x[i]>y[i])
			{
				cout << "GREATER\n" ;
				flag=1;
				break ;

			}
			else if (x[i] <y[i])
			{
				cout <<"LESS\n" ;
				flag=1;
				break ;
			}
		}
		if(flag==0)
            cout << "EQUAL\n" ;

	}
	else if (x.size()<y.size() )
	cout << "LESS\n" ;
	else
			cout << "EQUAL\n" ;

		return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const long long mod = 1e9+7;
long long power(long long a, long long b, long long m = mod) {
    if(b < 0) {
        return power(power(a, -b), mod-2);
    }
    long long x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
const int N = 1000+9;
#define int ll
pair<int, int> a[N];
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    int n; cin >> n;
    int par = 0;
    for(int i = 1; i <= n; i++) {
        cin >> a[i].first >> a[i].second;
        if(i > 1) {
            if(((a[i].first+a[i].second)&1) != par) {
                cout << "-1\n";
                return 0;
            }
        } else {
            par = ((a[i].first+a[i].second) & 1);
        }
    }
    int dx[] = {0, 0, 1, -1};
    int dy[] = {1, -1, 0, 0};
    char dc[] = {'D', 'U', 'L', 'R'};
    vector<int> arm;

    if(par==0) arm.push_back(1);
    for(int i = 0; i < 31; i++) {
        arm.push_back(1<<i);
    }
    int m = arm.size();
    cout << m << "\n";
    for(int i: arm) cout << i << " ";
    cout << "\n";
    vector<int> sum(m+1);
    for(int i = 1; i <= m; i++) {
        sum[i] = sum[i-1] + arm[i-1];
    }
    for(int i = 1; i <= n; i++) {
        vector<char> ans;
        int x = a[i].first, y = a[i].second;
        // cout << x << " " << y << " ";
        for(int cur = m-1; cur >= 0; cur--) {
            for(int dd = 0; dd < 4; dd++) {
                int nx = x + dx[dd]*arm[cur], ny = y + dy[dd]*arm[cur];
                if(abs(nx) + abs(ny) <= sum[cur]) {
                    x = nx; y = ny;
                    ans.push_back(dc[dd]);
                    break;
                } 
            }
        }
        reverse(ans.begin(), ans.end());
        for(char c: ans) cout << c;
        cout << '\n';
    }
    
    return 0;
    
}

Measured memory_bytes: 256
def Get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def Get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def Get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def Get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end

a,b=Get()
if a=="H"
  puts b
else
  puts b=="D" ? "H" : "D"
end

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>
#include <string>

using namespace std;

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

  string s;
  cin >> s;

  int count0 = 0;
  int count1 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      count0++;
    }
    else {
      count1++;
    }
  }

  cout << 2 * min(count0, count1) << endl;
}

Measured memory_bytes: 512
n,a,b,c,d=gets.split.map(&:to_i)
s=gets.chomp.to_s

if c<d
    if /##/===s[a-1..d-1]
        puts "No"
    else
     puts "Yes"
     end
else
    if /##/===s[a-1..d-1]
       puts "No"
       #追い越すための区間
    elsif /[.]{3}/===s[b-2..d]
        puts "Yes"
    else
        puts "No"
    end
   
end

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

int main(){
	int N, i, count = 1;
	scanf("%d", &N);
	vector<string> S(N);
	for(i = 0; i < N; i++){
		cin >> S[i];
	}
	sort(S.begin(), S.end());
	for(i = 1; i < N; i++){
		if(S[i] != S[i - 1]){
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 9596
#include <bits/stdc++.h>
#define fi first
#define se second
#define For(i, a, b) for (int i = (a); i <= (b); ++i)
#define Ford(i, a, b) for (int i = (a); i >= (b); --i)
#define Rep(i, a, b) for (int i = (a); i < (b); ++i)
#define Repd(i, a, b) for(int i = (a); i > (b); --i)
#define endl '\n'
#define debug(a) cout << a << endl
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

const ll maxN = 1e18;
const ll minN = -1e18;
const ll MOD = 1e9 + 7;

const ll limit = 2e5 + 5;
const ll limit1 = 1e6 + 5;
const ll limit2 = 1e3 + 5;
const ll limit3 = 1e4 + 5;

ll test;
ll n;
ll a, b, c, k;
ll res = 0, sum = 0, ans = 0, kd, hkd;
bool ok = false;

void FastIn(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
void ReadIn(){
    cin >> a >> b >> c >> k;
    kd = min(a, k);
    res = 1 * kd;
    k -= kd;
    k -= b;
    if(k > 0){
        kd = min(c, k);
        res = res - kd;
    }
    cout << res;
}
int main(){
    FastIn();
    ReadIn();
}
/*
5
4 4 5 3 1

2 2 1 1 1
3 3 3 2 1
*/
/*
* Ctrl + Shift + K Delete Line
* Ctrl + / TOGGLE LINE COMMENT
Ctrl + F Find
* Ctrl + H  REPLACE
* shift + alt + f FORMAT CODE DOCUMENT
Shift + alt + uparrow/downarrow Copy line up/down
Ctrl + ]/[ INDENT/OUTDENT LINE
Quy Hoạch Động
2 kiểu
+ Đếm cách
+ Dùng ít nhất
*/


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

int main()
{
    int n;
    cin >> n;
    int p[100010];
    for(int i = 1; i <= n; i++){
        cin >> p[i];
    }
    int ans = 0;
    bool check = false;
    for(int i = 1; i <= n; i++){
        if(p[i] == i){
            if(check == false){
                ans++;
                check = true;
                continue;
            }
        }
        check = false;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
s = str(input())
t = s[::-1]
if(s != t):
    print("No")
    exit()
c = ""
for i in range((len(s)-1)//2):
    c += s[i]
e = c[::-1]
if(e != c):
    print("No")
    exit()
r = ""
for i in range(((len(s)+3)//2)-1,len(s),1):
    r += s[i]
y = r[::-1]
if(r != y):
    print("No")
    exit()
print("Yes")
"""
print(s,t)
print(e,c)
print(r,y)
"""

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T>
struct fix_point: private T {
  explicit constexpr fix_point(T &&func): T(std::forward<T>(func)) { }
  template <class... Args>
  constexpr decltype(auto) operator () (Args &&... args) const {
    return T::operator()(*this, std::forward<Args>(args)...);
  }
};

template <class T>
constexpr decltype(auto) make_fix_point(T &&func) {
  return fix_point<T>{std::forward<T>(func)};
}

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  for (int &x: A) {
    std::cin >> x;
  }
  std::vector<std::vector<int>> graph(N);
  for (int i = 1; i < N; ++i) {
    int a, b;
    std::cin >> a >> b;
    --a; --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  bool answer = true;
  if (N == 2) {
    std::cout << (A[0] == A[1] ? "YES" : "NO") << '\n';
    return 0;
  }
  int root = -1;
  for (int i = 0; i < N; ++i) {
    if (graph[i].size() > 1) {
      root = i;
    }
  }
  if (make_fix_point([&](auto dfs, int u, int p) -> int64_t {
    if (graph[u].size() == 1) {
      return A[u];
    }
    int64_t sum = 0, max = 0;
    for (int v: graph[u]) {
      if (v != p) {
        int64_t tmp = dfs(v, u);
        sum += tmp;
        chmax(max, tmp);
      }
    }
    int64_t pairs = sum - A[u];
    int64_t up = A[u] - pairs;
    if (pairs < 0 || std::min(sum / 2, sum - max) < pairs) {
      answer = false;
    }
    return up;
  })(root, -1) != 0) {
    answer = false;
  } 
  std::cout << (answer ? "YES" : "NO") << '\n';
  return 0;
}


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

using namespace std;
typedef long long ll;

int n;
ll ans, l[101];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> l[i];
    sort(l + 1, l + n + 1);
    for (int i = 1; i <= n - 2; i++)
        for (int j = i + 1; j <= n - 1; j++)
            for (int k = j + 1; k <= n; k++)
                if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i])
                    if (l[i] + l[j] > l[k]) ans++;
    cout << ans;
    return 0;
}


Measured memory_bytes: 3656
import sys,os,io
input = sys.stdin.readline
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
  a,b = list(map(int, input().split()))
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

def dfs(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  while stack:
    v = stack[-1]
    marker = 0
    for u in edge[v]:
      if u==parent[v]:
        continue
      if parent[u]==N: #子へ降ろす
        marker = 1
        parent[u]=v
        stack.append(u)
      else: #子から吸い上げる
        ans[v] *= ans[u]+1
        ans[v] %=M
    if marker==0:
      stack.pop()
  return

def dfs2(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  p_value = [0]*N
  while stack:
    v = stack.pop()
    cum1 = [1]*(len(edge[v])+1)
    cum2 = [1]*(len(edge[v])+1)
    for i,u in enumerate(edge[v]):
      if u==parent[v]:
        cum1[i+1] = cum1[i]*(p_value[v]+1)%M
      else:
        cum1[i+1] = cum1[i]*(ans[u]+1)%M
    for i,u in enumerate(edge[v][::-1]):
      if u==parent[v]:
        cum2[-i-2] = cum2[-i-1]*(p_value[v]+1)%M
      else:
        cum2[-i-2] = cum2[-i-1]*(ans[u]+1)%M
    for i,u in enumerate(edge[v]):
      if u==parent[v]:
        continue
      parent[u]=v
      p_value[u] = cum1[i]*cum2[i+1]%M
      ans[u] *= (p_value[u]+1)
      ans[u] %= M
      stack.append(u)
    ans[v] %= M
  return

ans = [1]*N
dfs(0)
dfs2(0)
print(*ans, sep='\n')

Measured memory_bytes: 43536
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n";
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

using namespace std;
typedef long long 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;}

ll n,a,b,d;
vector<ll> h;
bool pro(ll m){
    ll cnt = 0;
    REP(i,n){
        ll temp = h[i]-b*m;
        if(temp>0)cnt += (temp+d-1)/d;
    }
    return cnt<=m;
}

int main(){
    cin >> n >> a >> b;
    d = a-b;
    h.resize(n);
    REP(i,n){
        cin >> h[i];
    }
    ll ub = *(max_element(all(h)))+1;
    ll lb = -1;
    while(ub-lb>1){
        ll mid = (ub+lb)/2;
        if(pro(mid)){
            ub = mid;
        }else{
            lb = mid;
        }
    }
    put(ub);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll N,ans=0;
    cin>>N;
    vector<ll> L(N);
    rep(i,N) cin>>L.at(i);
    
    if(N<=2) {
        cout<<ans<<endl;
        return 0;
    }
    
    for(ll i=0;i<N-2;i++){
        for(ll j=i+1;j<N-1;j++){
            for(ll k=j+1;k<N;k++){
                ll a=L.at(i),b=L.at(j),c=L.at(k);
                if((a-b)*(b-c)*(c-a)==0) continue;
                if(ABS(a-b)<c && c<a+b) ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3564
n,m=map(int,input().split())
if n%2==1:
    for i in range(1,m+1):
        print(f"{i} {n+1-i}")
else:
    count = 0
    q = n//2
    if q%2==0:
        for j in range(1,q//2+1):
            print(f"{j} {q+1-j}")
            count += 1
            if count == m:
                exit(0)
        for j in range(1,q//2):
            print(f"{q+j} {q+j+(q-2*j)}")
            if count == m:
                exit(0)
    else:
        for j in range(1,q//2+1):
            print(f"{j} {q+1-j}")
            count += 1
            if count == m:
                exit(0)
        for j in range(1,q//2+1):
            print(f"{q+j} {q+j+(q-2*j)}")
            if count == m:
                exit(0)


Measured memory_bytes: 9128