akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <list>
#include <random>

#define llong long long
#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i++))

using namespace std;

int D;

llong change(int,int,int*,int*,int*,list<int>*);

int main(){
	cin >> D;
	int c[26],s[D*26],t[D];
	rep(i,0,26) cin >> c[i];
	rep(i,0,D) rep(j,0,26) cin >> s[i*26+j];
	rep(i,0,D) t[i] = i%26;
	
	list<int> day[26];
	rep(i,0,26) day[i].push_front(0);
	rep(i,0,D) day[t[i]].push_back(i+1);
	rep(i,0,26) day[i].push_back(D+1);
	
	random_device rd;
	mt19937 mt(rd());
	uniform_int_distribution<int> type(0,25);
	uniform_int_distribution<int> days(1,D);
	
	int M=50000;
	rep(i,0,M){
		int d,q;
		d = days(mt);
		q = type(mt);
		if( change(d,q,t,c,s,day) > 0 ){
			t[d-1] = q;
		}
	}
	
	rep(i,0,D) cout << t[i]+1 << endl;
	
	return 0;
}

// d���ڂɊJ�Â����R���e�X�g��q�ɕς���
llong change(int d,int q,int *t,int *c,int *s,std::list<int> *day){
	int p = t[d-1],delta=0;
	// �R���e�X�g p ���J�Â���Ȃ����Ƃɂ��e��
	for(list<int>::iterator itr=day[p].begin();itr!=day[p].end();itr++){
		if( *itr == d ){	// �K���ǂ����Ɋ܂܂��
			list<int>::iterator back=itr,next=itr; back--; next++;
			// �K��0���擪�Ɋ܂܂�Ă���̂�itr!=begin
			// �K��D+1���I�[�Ɋ܂܂�Ă���̂�next!=end
			delta -= c[p]*(d-*back)*(*next-d)+s[(d-1)*26+p];
			day[p].erase(itr);
			break;
		}
	}
	// �R���e�X�g q ���J�Â���邱�Ƃɂ��e��
	for(list<int>::iterator itr=day[q].begin();;itr++){
		if( *itr > d ){
			// �I�[��D+1�ŕK�������|���邱�Ƃ��ۏ؂����
			list<int>::iterator back=itr; back--;
			day[q].insert(itr,d);
			delta += c[q]*(d-*back)*(*itr-d)+s[(d-1)*26+q];
			break;
		}
	}
	return delta;
}


Measured memory_bytes: 4132
#include <iostream>
#include <algorithm>
int arr[200007];
using namespace std;
int main() {
  
int n;cin >> n;
for(int i = 1; i <= n; i++){
  cin >> arr[i];
  arr[i] -= i;
}
sort(arr + 1, arr + 1 + n);
int b = arr[n / 2 + 1];
long long res = 0;
for(int i =1; i <= n; i++){
  res += abs(arr[i]-b);
}
cout << res << endl;
  return 0; 
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long int
using namespace std;
void solve() {
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    int count=0;
    for(int i=1;i<n-1;i++) {
        if(a[i] > a[i-1] && a[i] < a[i+1] || a[i] < a[i-1] && a[i] > a[i+1])
            count++;
    }
    cout << count << '\n';
    return ;
} 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    N, M = [int(n) for n in input().split()]
    A = []
    for n in range(N):
        A.append([int(n) for n in input().split()])

    vals = sorted(A, key=lambda x: x[0])
    ret = 0
    for v in vals:
        if v[1] < M:
            M -= v[1]
            ret += v[0] * v[1]
        else:
            print(ret + v[0] * M)
            exit()

Measured memory_bytes: 23524
#include<stdio.h>

int a=1,b=0,c=0;
int xa,xb,xc;

void change(){
  if(a){
    if(xa){
      if(xb){
	a=0;
	b=1;
      }
      else if(xc){
	a=0;
	c=1;
      }
    }
  }
  else if(b){
    if(xb){
      if(xa){
	b=0;
	a=1;
      }
      else if(xc){
	b=0;
	c=1;
      }
    }
  }
  else if(c){
    if(xc){
      if(xa){
	c=0;
	a=1;
      }
      else if(xb){
	c=0;
	b=1;
      }
    }
  }
} 

int main(void){
  char x,y;
  
  while(scanf("%c,%c",&x,&y)!=EOF){
    xa=(xb=(xc=0));
    if(x=='A')
      xa=1;
    else if(x=='B')
      xb=1;
    else if(x=='C')
      xc=1;
    if(y=='A')
      xa=1;
    else if(y=='B')
      xb=1;
    else if(y=='C')
      xc=1;
    //    printf("{%d %d %d} (%d %d %d)",xa,xb,xc,a,b,c);
    change();
    //    printf("-(%d %d %d)\n",a,b,c);
  }
  if(a)
    puts("A");
  else if(b)
    puts("B");
  else
    puts("C");
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  int a[n];
  int sum_all = 0;
  rep(i, n) {
    cin >> a[i];
    sum_all += a[i];
  }
  if (sum_all % 10 != 0) {
    cout << sum_all << endl;
  } else {
    int sum = 0;
    rep(i, n) {
      if (a[i] % 10 != 0) {
        sum = max(sum, sum_all - a[i]);
      }
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative

readDigits = map read <$> words <$> getLine :: IO [Int]

solve :: [Int] -> String
solve [-1, _, _] = "F"
solve [_, -1, _] = "F"
solve [a, b, c]
    | 80 <= (a+b) = "A"
    | 65 <= (a+b) = "B"
    | 50 <= (a+b) = "C"
    | 30 <= (a+b) && 50 <= c = "C"
    | 30 <= (a+b) = "D"
    | otherwise = "F"


main :: IO ()
main =
    loop
    where
    loop = do
        abc <- readDigits
        unless (all (== -1) abc) $ do
            putStrLn $ solve abc
            loop

Measured memory_bytes: 3984
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <utility>
#include <tuple>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<vector<int> > vvi;
#define rep(i,n) for (int i=0;i<n;i++)

ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    char color = s[0];
    for (int i=1;i<n;i++){
        if (color!=s[i]){
            ans++;
            color = s[i];
        }
    }
    ans++;
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=300;
    class Cell{
    public:
        int x,y,a;
        Cell(){}
        Cell(int i,int j,int v):x(i),y(j),a(v){}
        bool operator<(Cell &c){
            return a<c.a;
        }
    };
    vector<Cell>vctCell;
    vector<int>cost[MAXN*MAXN];
    void solve(){
        int h,w,d;
        cin>>h>>w>>d;
        for(int u=0;u<h;u++){
            for(int v=0;v<w;v++){
                int t;
                cin>>t;
                vctCell.push_back(Cell(u,v,t));
            }
        }
        sort(vctCell.begin(),vctCell.end());
        for(int m=1;m<=d;m++){
            cost[m].push_back(0);
            for(int t=m+d;t<=h*w;t+=d){
                int dist=abs(vctCell[t-d-1].x-vctCell[t-1].x)
                +abs(vctCell[t-d-1].y-vctCell[t-1].y);
                cost[m].push_back(cost[m].back()+dist);
            }
        }
        int q;
        cin>>q;
        while(q--){
            int l,r;
            cin>>l>>r;
            if(r%d)
            cout<<cost[r%d?r%d:d][r/d]-cost[l%d?l%d:d][l/d]<<"\n";
            else 
            cout<<cost[r%d?r%d:d][r/d-1]-cost[l%d?l%d:d][l/d-1]<<"\n";
        }
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

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


int main() {
    Int N;
    cin >> N;
    vector<Int> a(N);
    rep(i,N) cin >> a[i];


    Int ans = 0;

    while(true) {
        bool flag = true;
        rep(i,N) {
            if (a[i] >= N) {
                Int b = a[i] / N;
                a[i] -= b * N;
                rep(j,N) {
                    if (i != j) a[j] += b;
                }
                ans += b;
                flag = false;
            }
        }
        if (flag) break;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
use v5.18; # strict say state

chomp (my $s = <STDIN>);
my ($f, $c) = (0, 0);
my @p;
for my $i (0..length($s)-1) {
  if (substr($s, $i, 1) eq 'R') {
    if ($f == 1) {
      push @p, $c;
      $f = 0;
      $c = 0;
    }
  } else {
    if ($f == 0) {
      push @p, $c;
      $f = 1;
      $c = 0;
    }
  }
  $c++;
  push @p, $c if $i == length($s) - 1;
}
my @ans;
for my $i (0..length($s)-1) {
  $ans[$i] = 0;
}
my $pos = 0;
while (@p) {
  my $x = shift @p;
  my $y = shift @p;
  if (($x + $y) % 2 == 0) {
    $pos += $x;
    $ans[$pos-1] = ($x + $y) / 2;
    $ans[$pos] = ($x + $y) / 2;
    $pos += $y;
  } elsif ($x % 2 == 0) {
    $pos += $x;
    $ans[$pos-1] = int(($x + $y) / 2);
    $ans[$pos] = int(($x + $y) / 2) + 1;
    $pos += $y;
  } else {
    $pos += $x;
    $ans[$pos-1] = int(($x + $y) / 2) + 1;
    $ans[$pos] = int(($x + $y) / 2);
    $pos += $y;
  }
}
say join(' ', @ans);

Measured memory_bytes: 16000
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

size_t gcd(size_t m, size_t n) {
  if (n == 0) return m;
  else return gcd(n, m % n);
}

int main() {
  size_t N, X;
  std::cin >> N >> X;

  std::vector<size_t> Xs(N+1);

  for (size_t i=0; i<N; i++) {
    std::cin >> Xs[i];
  }
  Xs[N] = X;

  std::sort(Xs.begin(), Xs.end());

  for (size_t i=1; i<N+1; i++) {
    Xs[i] -= Xs[0];
  }

  if (N>1)
    std::cout <<
      std::accumulate(Xs.begin()+3, Xs.end(),
                      gcd(Xs[1], Xs[2]),
                      [](size_t init, size_t i) {
                        // std::cout << init << ','
                        //           << i << std::endl;
                        if (init < i)
                          return gcd(init, i);
                        else
                          return gcd(i, init);
                      })
              << std::endl;
  else
    std::cout << Xs[1] << std::endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, q, l, r, a[100100];
string s;

signed main() {
	cin >> n >> q >> s;
	reps(i,1,n) {
		if (s[i]=='C' && s[i-1]=='A') a[i]++;
		a[i] += a[i-1];
	}
	while (q--) {
		cin >> l >> r;
		l--, r--;
		cout << a[r]-a[l] << endl;
	}
}

Measured memory_bytes: 1488
#include<stdio.h>
long long gcd(long a,long b)
{
    return b?gcd(b,a%b):a;
}
long long lcm(long long a,long long b)
{

	return a/gcd(a,b)*b;
}
int main()
{
	int n,i;
	long long a[101];
	long long m;
	while(~scanf("%d",&n))
	{
		for (i=0;i<n;i++)
		{
			scanf("%lld",&a[i]);
		}
		m=a[0];
		for (i=1;i<n;i++)
		{
		    if (a[i]%m==0)
		    {
		    	m=a[i];
			}
			else
			{
				m=lcm(m,a[i]);
			}
		}
		printf("%lld\n",m);
	}
	return 0;
}


Measured memory_bytes: 128
#include <cstring>
#include <cstdlib>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)<0?(-(a)):(a))
#define CS while(cases())
#define I(n) int n = gi()
#define II(n) n = gi()
#define L(n) ll n = gli()
#define LL(n) n = gli()
#define F0(i, n) for (int i = 0; i < n; i++)
#define F1(i, n) for (int i = 1; i < n; i++)
#define Fi(n, a) for (int i = 0; i < n; i++) a[i] = gi()
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

template<class T>
T gcd(T a, T b) {
    return (b == 0 ? a : gcd(b, a%b));
}

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int cases() {
    static int t = gi();
    return t--;
}

#define MD 1000000007
char a[200004];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    scanf("%s", a);
    int n = strlen(a);
    for (int i = 0; i < n; i++)
        if (a[i] == '?')
            a[i] = 'D';
    cout << a << endl;

    return 0;
}


Measured memory_bytes: 3844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map> 
using namespace std;

#define LL long long


class LLPair
{
public:
	LLPair() {}
	LLPair(LL a, LL b) : a(a), b(b) {}
public:
	LL a = 0;
	LL b = 0;
};

int main(){

	char c;
	stack<LLPair> result;
	stack<LL> temp;
	LL index = 0;

	while (scanf("%c", &c) != EOF) {
		if (c == '\\') {
			temp.push(index); //-1は下り
		}
		else if (c == '/') {
			if (temp.size() > 0) {
				LL prev_temp = temp.top();
				temp.pop();

				LLPair water_block(prev_temp, index - prev_temp);

				while (result.size() > 0) {
					LLPair result_top = result.top();

					if (water_block.a < result_top.a) {
						//統合
						result.pop();
						water_block.b += result_top.b;
					}
					else {
						break;
					}
				}

				result.push(water_block);
			}
		}
		else if (c == '_') {

		}
		else {
			break;
		}

		index++;
	}


	LL total = 0;
	stack<LL> result_for_print;

	while (result.size() > 0) {
		LLPair result_top = result.top();
		result.pop();

		total += result_top.b;
		result_for_print.push(result_top.b);
	}

	printf("%lld\n", total);
	printf("%lld", result_for_print.size());
	while (result_for_print.size() > 0) {
		printf(" %lld", result_for_print.top());
		result_for_print.pop();
	}
	printf("\n");

	return 0;
}



Measured memory_bytes: 3296
n = int(input())
ans = 0
s = list(map(int,input().split()))
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            a,b,c = s[i],s[j],s[k]
            if a != b!= c!= a and a+b >c and a+c >b and c+b >a:ans +=1
print(ans)


Measured memory_bytes: 9084
#include<stdio.h>

int main(){
  int x[6]={0};
  scanf("%d %d %d %d %d",&x[0],&x[1],&x[2],&x[3],&x[4]);

  int i;
  for(i=0;i<5;i++){
    if(x[i]==0){
      printf("%d",i+1);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 1672
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define v vector
#define len length()
#define mt make_tuple
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9+7;
int ll_max=1e6;
v<ll> fact;
//factorial

void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <=n; i++)
    {
        fact[i] = i * fact[i - 1];
        fact[i] %= M;
    }
}

// modular exponentiation 
ll binpow(ll val, ll deg)
{
    if (!deg)
        return 1 % M;
    if (deg & 1)
        return binpow(val, deg - 1) * val % M;
    ll res = binpow(val, deg >> 1);
    return (res * res) % M;
}
//combination
ll combination(ll n, ll i)
{
    ll res = fact[n]; 
    ll div = fact[n - i] * fact[i];
    div %= M;
    // using fermat little theorum
    div = binpow(div, M - 2); // modular inverse  
    return (res * div) % M; 
}
int main() {
	// your code goes here
	IOS;
	ll n,m,i;
	ll j,t,x,y,k;
      cin>>k;
      
      string s;
      cin>>s;
      n=s.len;
      fact.assign(n+k+1,1);
      factorial(n+k);
      ll sum=0;
      for(i=n;i<=n+k;i++){
            sum+=combination(n+k,i)*binpow(25,n+k-i);
            sum%=M;
      }
      cout<<sum;
	return 0;
}

Measured memory_bytes: 19748
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAX 100100
using namespace std;

int main()
{
	int N; 
	scanf("%d", &N);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int x; scanf("%d", &x);
		if (x == ans + 1) ans++;
	}
	if (ans == 0) ans = N + 1;
	printf("%d\n", N - ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
using namespace std;
int n, I[1 << 10], R[1 << 10], O[1 << 10], V[1 << 10];
int main() {
	while (true) {
		cin >> n; if (n == 0)break;
		for (int i = 1; i <= n; i++) { cin >> I[i]; }
		long double minx = 100.0; int T = 0;
		for (int S = 0; S < 16; S++) {
			for (int A = 0; A < 16; A++) {
				for (int C = 0; C < 16; C++) {
					R[0] = S; long double sum = 0.0;
					for (int i = 1; i <= n; i++) R[i] = (A*R[i - 1] + C) % 256;
					for (int i = 1; i <= n; i++) O[i] = (I[i] + R[i]) % 256;
					for (int i = 0; i < 256; i++) V[i] = 0;
					for (int i = 1; i <= n; i++) V[O[i]]++;
					for (int i = 0; i < 256;i++){
						if (V[i] >= 1) {
							long double F = 1.0*V[i] / n;
							sum -= F*log(F);
						}
					}
					if (sum < minx) {
						minx = sum; T = S * 256 + A * 16 + C;
					}
				}
			}
		}
		cout << T / 256 << ' ' << (T / 16) % 16 << ' ' << T % 16 << endl;
	}
	return 0;
}

Measured memory_bytes: 3136
def main():
    N, A, B = map(int, input().split())

    if abs(A-B) % 2 == 0:
        print(abs(A-B)//2)
    else:
        print(min([A-1, N-B])+1+(B-A-1)//2)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
 int x,y,sum=0;
  cin>>s;
x=s.find("A");
y=s.rfind("Z");
for(int i=x;i<=y;i++)
{
	sum++;
}
cout<<sum;
 return 0;
}


Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
template<class T> inline int add(T& a, T b, T M = MOD){a=(a+M)%M;b=(b+M)%M;a=(a+b)%M;return a;};
template<class T> inline int mul(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
////////////////////////////////////////////////////////////////////

signed main(){
  string s;cin>>s;
  int cnt = 0, n = s.length();
  rep(i,s.length())if(s[i] == '0')cnt++;
  cout << 2LL*min(cnt, n-cnt) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n, m;
	cin >> n >> m;
	
	if(n == m)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++) cin >> d.at(i);

	int ans = 0;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			ans += d.at(i) * d.at(j);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let v:Vec<i64> = buf.split_whitespace().into_iter().map(|el| el.parse().unwrap()).collect();
    let (w, h, x, y, r) = (v[0], v[1], v[2], v[3], v[4]);

    if x - r < 0 || x + r > w || y - r < 0 || y + r > h {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 5028
n=1
i=[]
try:
    while n<=3000:
        a,b=map(int,input().split())
        if a==0 and b==0:
            break
        else:
            if a<b:
                i.append(str(a)+" "+str(b))
            else:
                i.append(str(b)+" "+str(a))
        n+=1
except EOFError:
    pass
i_n="\n".join(i)
print(i_n)


Measured memory_bytes: 5668
#include <stdio.h>

int main()
{
  int time, times[5], i, isEnd = 0, isSwap, a, b, tmp;

  for (i = 0; i < 5; i++) {
    if (scanf("%d", &time) == EOF) {
      return -1;
    }
    times[i] = time;
  }

  while (!isEnd) {
    isSwap = 0;
    for (i = 0; i < 4; i++) {
      a = times[i] % 10;
      if (a == 0) a = 10;

      b = times[i + 1] % 10;
      if (b == 0) b = 10;

      if (a < b) {
        tmp = times[i];
        times[i] = times[i + 1];
        times[i + 1] = tmp;
        isSwap = 1;
      }
    }
    if (!isSwap) {
      isEnd = 1;
    }
  }

  time = 0;
  for (i = 0; i < 4; i++){
    time += ((times[i] / 10) * 10);
    if (times[i] % 10)
      time += 10;
  }
  time += times[i];
  printf("%d\n", time);

  return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();

        int ans = 0;

        if (a >= k) {
            ans = k;
            k = 0;
        } else {
            ans = a;
            k -= a;
        }

        k -= b;

        if (k > 0) {
            ans -= k;
        }

        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

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

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

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

Measured memory_bytes: 25396
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import deque

h, w = map(int, readline().split())
a = [input() for i in range(h)]
q = []
dist = [[True] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            q.append((i, j))
            dist[i][j] = False
cnt = -1
while q:
    cnt += 1
    qq = deque()
    for y, x in q:
        if x + 1 < w and dist[y][x + 1]:
            dist[y][x + 1] = False
            qq.append((y, x + 1))
        if x - 1 >= 0 and dist[y][x - 1]:
            dist[y][x - 1] = False
            qq.append((y, x - 1))
        if y + 1 < h and dist[y + 1][x]:
            dist[y + 1][x] = False
            qq.append((y + 1, x))
        if y - 1 >= 0 and dist[y - 1][x]:
            dist[y - 1][x] = False
            qq.append((y - 1, x))
    q = qq
print(cnt)


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

int main() {
    int N; cin >> N;
    int T, A; cin >> T >> A; T *= 1000; A *= 1000;
    int ans = -1, x = 100000000;
    rep(i, N) {
        int h; cin >> h;
        int t = T - h * 6;
        if (abs(t - A) < x) { x = abs(t - A); ans = i + 1; }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
n = int(input())
x = list(map(int,input().split()))
c = 0

change = 1
for i in range(n):
    if not change:
        break
    change = 0
    for j in range(n-i-1):
        if x[j] > x[j+1]:
            x[j],x[j+1] = x[j+1],x[j]
            change = 1
            c += 1

print(*x)
print(c)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll powmod(ll a, ll b, const ll mod = MOD) {
    a %= mod;
    ll res = 1;
    while (b > 0) {
        if (b % 2 == 1)res = res * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return res;
}

vector<ll> f, inv, finv;
const ll mod = MOD;
void cominit(ll n = 210000) {
    f.resize(n + 1);
    inv.resize(n + 1);
    finv.resize(n + 1);
    f[0] = f[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    FOR(i, 2, n + 1) {
        f[i] = f[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

ll nCr(ll n, ll r) {
    if (n < r)return 0;
    if (n < 0 or r < 0)return 0;
    return f[n] * (finv[r] * finv[n - r] % mod) % mod;
}

ll nPr(ll n, ll r) {
    if (n < r)return 0;
    if (n < 0 or r < 0)return 0;
    return f[n] * finv[n - r] % mod;
}

ll nHr(ll n, ll r) {
    if (n < r)return 0;
    if (n < 0 or r < 0)return 0;
    return nCr(n + r - 1, r);
}

ll k, ans;
string s;
int main() {
    cominit(2100000);
    cin >> k >> s;
    ll sz = s.size();   
    ll n = k + sz;
    ans = powmod(26, n);
    REP(i, sz){
        ans -= nCr(n, i) * powmod(25, n - i) % MOD;
        ans = (ans + MOD * 2) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 54548
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
using namespace std;

//自然数nの約数列挙 O(root(N))
//使い方
//自然数nを渡すとvector<long long>を返す
//ソート含めると O(root(N) + N log N)
vl divisor(ll n){
	vl ret;
	for (ll i = 1; i*i <= n; ++i){
		if (n%i == 0){
			ret.push_back(i);
			if (i*i != n) ret.push_back(n / i);
		}
	}

	//これ入れたらオーダーちょい上がる
	sort(ret.begin(), ret.end());

	return ret;
}

//ユークリッドの互除法 ラメの定理よりO(log N)
//使い方
//整数a,bを渡すと最小公倍数を返す
ll gcd(ll a, ll b){
	ll q = max(a, b);
	ll r = min(a, b);
	while (r){
		ll t = q;
		q = r;
		r = t % r;
	} return q;
}

int main(){
	ll a, b, k; cin >> a >> b >> k;
	ll d = gcd(a, b);
	vl ngo = divisor(d);
	cout << ngo[ngo.size() - 1 - (k - 1)] << endl;
}

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

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

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

	int x;
	cin >> x;

	cout << 360 / mygcd(360, x) << endl;
}


Measured memory_bytes: 3556
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define FILE_NAME "a"

const int A = 26;

int n, m;
vi cnt;

bool read() {
	if  (scanf("%d%d\n", &n, &m) < 2) {
		return 0;
	}
	cnt.assign(A, 0);
	forn(i, n) {
		static char buf[1000];
		scanf("%s\n", buf);
		forn(j, m) {
			++cnt[buf[j] - 'a'];
		}
	}
	return 1;
}

bool solve2(vi cnt, int times2) {
	forn(c, A) {
		if  (cnt[c] % 2 != 0) {
			return 0;
		}
	}

	forn(c, A) {
		if  (cnt[c] % 4 != 0) {
			assert(cnt[c] % 4 == 2);
			cnt[c] -= 2;
			--times2;
		}
	}

	if (times2 < 0) {
		return 0;
	}

	if  (times2 % 2 == 0) {
		return 1;
	}
	return 0;
}

bool solve(vi cnt) {
	if  (n % 2 == 0 && m % 2 == 0) {
		forn(c, A) {
			if  (cnt[c] % 4 != 0) {
				return 0;
			}
		}
		return 1;
	}

	if  (m % 2 == 0) {
		swap(n, m);
	}

	if  (n % 2 == 0) {
		forn(c, A) {
			if  (cnt[c] % 2 != 0) {
				return 0;
			}
		}

		forn(c, A) {
			cnt[c] /= 2;
		}

		int times = n / 2;
		int odd = 0;
		forn(c, A) {
			if  (cnt[c] & 1) {
				++odd;
			}
		}

		if (odd > times) {
			return 0;
		}

		times -= odd;

		if  (times & 1) {
			return 0;
		}
		return 1;
	}

	assert(n % 2 == 1 && m % 2 == 1);

	forn(c, A) {
		if  (!cnt[c]) {
			continue;
		}
		--cnt[c];
		if  (solve2(cnt, m / 2 + n / 2)) {
			return 1;
		}
		++cnt[c];
	}

	return 0;
}

bool solve() {
	return solve(cnt);
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		puts(solve() ? "Yes" : "No");
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


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


int mm[500005];
int ind[500005];
int seg[2000005];
void upd(int ver,int tl,int tr,int pos,int val)
{
    if(tl>tr)
        return ;
    else if(tl==tr)
    {
        seg[ver]=val;
    }
    else
    {
        int tm=(tl+tr)/2;
        if(tm>=pos)
        upd(2*ver,tl,tm,pos,val);
        else
            upd(2*ver+1,tm+1,tr,pos,val);
        seg[ver]=seg[2*ver]+seg[2*ver+1];
    }    
}

int get(int ver,int tl,int tr,int l,int r)
{
    if(tl>tr||l>r||tr<l||r<tl)
        return 0;
    else if(tl==l&&tr==r)
        return seg[ver];
    else
    {
        int tm=(tl+tr)/2;
        return get(2*ver,tl,tm,l,min(tm,r))+get(2*ver+1,tm+1,tr,max(tm+1,l),r);
    }    
}
int ans[500005];

signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int n,q;
    cin>>n>>q;
    int col[n+1];
    for(int i=1;i<=n;i++)
    {
        ind[i]=n+1;
        cin>>col[i];
    }   

    for(int i=n;i>=1;i--)
    {
        mm[i]=ind[col[i]];
        ind[col[i]]=i;
    }
    vector<pair<pair<int,int>,int>> pp;
    int x,y;
    for(int i=0;i<q;i++)
    {
        cin>>x>>y;
        pp.push_back({{x,y},i});
    }
    sort(pp.begin(),pp.end());
    for(int i=1;i<=n;i++)
    {
        if(ind[i]<=n)
        {
            upd(1,1,n,ind[i],1);
        }
    }

    for(int i=1;i<pp[0].first.first;i++)
    {
        int z=mm[i];
        upd(1,1,n,i,0);
        if(z<n+1)
        upd(1,1,n,z,1);
    }
    for(int i=0;i<q;i++)
    {
        ans[pp[i].second]=get(1,1,n,pp[i].first.first,pp[i].first.second);
        if(i<q-1)
        {
            for(int j=pp[i].first.first;j<pp[i+1].first.first;j++)
            {
                int z=mm[j];
                upd(1,1,n,j,0);
                if(z<n+1)
                    upd(1,1,n,z,1);
            }
        }
    }

    for(int i=0;i<q;i++)
        cout<<ans[i]<<'\n';

}


Measured memory_bytes: 39488
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n,k;
  cin >> n >> k;
  int ans=0;
  rep(i,n){
    int h; cin >> h;
    if(h>=k)ans++;
  }

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

	    int a =sc.nextInt();
	    String op = sc.next();
	    int b =sc.nextInt();

	    if(op.equals("?"))break;




	    switch(op) {
	    case "+" :
	    	System.out.println(a + b);
	    	break;
	    case "-" :
	    	System.out.println(a - b);
	    	break;
	    case "*" :
	    	System.out.println(a * b);
	    	break;
	    case "/" :
	    	System.out.println(a / b);
	    	break;
	    }



		}





	}
}




Measured memory_bytes: 26248
E, Y = map(int, input().split())
if E == 0 :
    if 1868 <= Y <= 1911 :
        print('M', Y-1867, sep='')
    elif 1912 <= Y <= 1925 :
        print('T', Y-1911, sep='')
    elif 1926 <= Y <= 1988 :
        print('S', Y-1925, sep='')
    else :
        print('H', Y-1988, sep='')

elif E == 1 :
    print(Y+1867)
elif E == 2 :
    print(Y+1911)
elif E == 3 :
    print(Y+1925)
else :
    print(Y+1988)
    


Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

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

    vector<ll> a(n, 0);
    for(int i = 0; i < n; i++) cin >> a[i];

    sort(a.begin(), a.end());
    
    int right = a[n-1];
    int left = 0;
    int target = (right + 1) / 2;

    auto index = lower_bound(a.begin(), a.end(), target);
    if(distance(a.begin(), index) == 0) left = *index;
    else if(*index - target >= target - *(index-1)) left = *(index-1);
    else left = *index;

    cout << right << " " << left << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
int main(){
  std::string s[3];
  long long k,a[3]={};
  std::cin>>s[0]>>k;
  for(size_t i=0;i<2;++i) s[i+1]=s[i]+s[0];
  for(size_t i=0;i<3;++i) for(size_t j=0;j<s[i].length()-1;++j) if(s[i][j]==s[i][j+1]) ++a[i],s[i][j+1]='.';
  std::cout<<(k&1?a[0]:a[1])+(k-1)/2*(a[2]-a[0])<<std::endl;
}


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

int main() {
  long long X,Y;
  cin >> X;
  int ans=0;
  Y = 100;
  while(true) {
    Y = Y * 1.01;
    ans++;
    if(Y >= X) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 3636
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 200005;
const ll mm = 1e+18;
void solve()
{
    int x;
    cin>>x;
    char c;
    cin>>c;
    int y;
    cin>>y;
    if(c=='+') cout<<x+y;
    else cout<<x-y;
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int a, b;
    map<int, int> mii;
    REP(i, 3) {
        cin >> a >> b;
        mii[a - 1]++;
        mii[b - 1]++;
    }
    REP(i, 4) {
        if (mii[i] > 2) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;

void main() {
    int n;
    scan(n);

    int ans;
    int ls, rs;

    ans = query(0);
    if (ans == 2) return;
    ls = ans;

    ans = query(n-1);
    if (ans == 2) return;
    rs = ans;

    int left = 0, right = n - 1;

    while (true) {
        int mid = (left + right) / 2;
        ans = query(mid);

        if (ans == 2) return;

        int b = ((mid - left + 1) & 1) ^ (ls ^ ans);

        if (!b) {
            right = mid;
            rs = ans;
        }
        else {
            left = mid;
            ls = ans;
        }
    }
}

int query(int i) {
    writeln(i);
    stdout.flush();
    string s = readln.chomp;
    if (s == "Male") {
        return 0;
    }
    else if (s == "Female") {
        return 1;
    }
    else {
        return 2;
    }
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 852
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    Int ans = min(a[n], b[n - 1]);
    b[n - 1] = max((Int)(b[n - 1] - a[n]), (Int)0);
    for (int i = n - 1; i >= 1; i--) {
        Int killed1 = min(a[i], b[i]);
        b[i] = max((Int)(b[i] - killed1), (Int)0);
        a[i] = max((Int)(a[i] - killed1), (Int)0);

        Int killed2 = min(a[i], b[i - 1]);
        b[i - 1] = max((Int)(b[i - 1] - killed2), (Int)0);
        a[i] = max((Int)(a[i] - killed2), (Int)0);

        ans += killed1 + killed2;
    }
    ans += min(a[0], b[0]);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
# coding: utf-8
# Your code here!
while True:
    H,W=map(int,input().split())
    
    if H+W==0:
        break
    for i in range(H):
        for j in range(W):
            if (i+j)%2==0:
                print('#',end='')
            else:
                print('.',end='')
        print()
    print()


Measured memory_bytes: 7004
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
    
        int N = sc.nextInt();
        String S = sc.next();
        char[] A = S.toCharArray();

        
        int sum[];
        sum = new int[N];
        
        int sumW[];
        sumW = new int[N];
        int sumE[];
        sumE = new int[N];

        for(int m = 0;m < N;m++){
            int countE = 0;
            int countW = 0;
            if(A[m] == 'W'){
                countW++;
                
            }else{
                countE++;
            }
            if(m < 1){
                sumW[m] = countW;
                sumE[m] = countE;
            }else{
            sumW[m] = countW + sumW[m-1];
            sumE[m] = countE + sumE[m-1];
            }
        
        } 
        

        for(int i = 0;i < N;i++){
            if(i < 1){
                sum[i] = sumE[N-1] - sumE[i];
            }else if(i == N - 1){
                sum[i] = sumW[i];
            }else{
            sum[i] = sumW[i-1] + (sumE[N-1] - sumE[i]);
            }
        }

        //for(int i = 0; i < N;i++){
          //  int count = 0;
            //for(int n = 0;n < i;n++){
              //  if(A[n] == 'W'){
                //    count++;
                //}
           // }
            //for(int reader = i + 1; reader < N; reader++){
              //  if(A[reader] == 'E'){
                //    count++;
                //}
            //}
            //sum[i] = count;
            
       // }

        int min = sum[0];
            for(int i = 1;i < N;i++){
                int n = sum[i];
                if(n < min){
                min = n;
                }
            }
            System.out.println(min);
            
    }
}


Measured memory_bytes: 32800
from collections import defaultdict
n=int(input())

d=defaultdict(int)
for i in range(n):
    s=input()
    sorted_list=sorted(s)
    s="".join(sorted_list)
    d[s]+=1
count=0
for i,j in d.items():
    count+=j*(j-1)//2

print(count)

Measured memory_bytes: 22644
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(2e5)+10;
int n,m1,m2,fa[maxn],sz[maxn];
ll ans;
struct node {
	int x,y,z;
} d[maxn];
bool cmp(node a,node b) {
	return a.z>b.z;
}
int find(int x) {
	if (fa[x]==x) return x;
	return fa[x]=find(fa[x]);
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(m1); read(m2);
	int x,y,z;
	for (int i=1;i<=n;i++) {
		read(x); read(y); read(z);
		d[i]=(node){x,y+m1,z};
	}
	sort(d+1,d+n+1,cmp);
	for (int i=1;i<=m1+m2;i++) fa[i]=i;
	for (int i=1;i<=n;i++) {
		x=d[i].x; y=d[i].y; z=d[i].z;
		x=find(x); y=find(y);
		if (x==y) {
			if (sz[x]) continue;
			sz[x]=1;
		} else {
			if (sz[x]&&sz[y]) continue;
			fa[x]=y; sz[y]|=sz[x];
		}
		ans+=z;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2816