akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
#define fi first
#define se second
#define lc T[p].l
#define rc T[p].r
#define mid (l+r>>1)
#define lson lc,l,mid
#define rson rc,mid+1,r
#define sum T[p].val
#define pii pair<int,int>
const int MX=1e6+7;
const int mod=998244353;
const double pi=3.1415926535897932384;
double isp=1e-13;
using namespace std;
ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}
ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}//要求MOD为质数
ll exgcd(ll a,ll b,ll &x,ll &y){if(b==0){x=1,y=0;return a;}ll ret=exgcd(b,a%b,y,x);y-=a/b*x;return ret;}
ll getInv(int a,int mod){ll x,y;ll d=exgcd(a,mod,x,y);return d==1?(x%mod+mod)%mod:-1;}//求a在mod下的逆元，不存在逆元返回-1，不要求MOD为质数
ll mx[MX],a[10];
ll dis(ll a,ll b)
{
    return a*a+b*b;
}
void solve()
{
    ll n,d;
    cin>>n>>d;
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(dis(x,y)<=d*d)ans++;
    }
    cout<<ans<<endl;
}
int main()
{
  ios::sync_with_stdio(0),cin.tie(0);
  int t;
 // cin>>t;
  t=1;
  while(t--)
  {
      solve();
  }
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

vvi G(10000); // グラフ(リスト)

// トポロジカルソート
void rec(int v, vector<bool> &seen, vector<int> &order) {
    seen[v] = true;
    for (int i= 0; i < G[v].size(); i++) {
        int next = G[v][i];
        if (seen[next]) continue; // 既に訪問済みなら探索しない
        rec(next, seen, order);
    }
    order.push_back(v);
}

vector<int> topo(int N) { // Nはノード数
    // 探索
    vector<bool> seen(N, 0); // 初期状態では全ノードが未訪問
    vector<int> order; // トポロジカルソート順
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue; // 既に訪問済みなら探索しない
        rec(v, seen, order);
    }
    reverse(order.begin(), order.end());
    return order;
}

int main() {
    
    int n,m;
    cin>>n>>m;
    rep(i,m){
        int s,t;
        cin>>s>>t;
        G[s].pb(t);
    }
    vi v=topo(n);
    rep(i,v.size())fin(v[i]);
}




Measured memory_bytes: 3688
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System .in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        long max1 = a>b?a:b;
        long min1 = a<=b?a:b;
        int c = sc.nextInt();
        int d = sc.nextInt();
        long max2 = c>d?c:d;
        long min2 = c<=d?c:d;
        long max = Math.max(Math.max(Math.max(max1*max2,min1*min2),max1*min2),min1*max2);
        System.out.println(max);
    }
}

Measured memory_bytes: 35664
#include <stdio.h>
int main(){
    int i;
    int n,a;
    long long min, max, sum;
    sum = 0;
    scanf("%d", &n);
    scanf("%d", &a);
    max = a;
    min = a;
    sum += a;
    for (i = 1; i < n; i++){
        scanf("%d", &a);
        sum += a;
        if (max < a){
            max = a;
        }
        if (min > a){
            min = a;
        }
    }
    printf("%lld %lld %lld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 2100
import java.util.Scanner;
class Main{
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    
    int n = stdIn.nextInt();
    
    if (n % 2 == 0) {
      System.out.println(n / 2);
    } else {
      System.out.println((n+1) / 2);
    }
  }
}


Measured memory_bytes: 21972
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

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

  int n;
  cin >> n;
  deque<ll> ans;
  REP(i, n) {
    ll tmp;
    cin >> tmp;
    if(i%2 == n%2) {
      ans.push_back(tmp);
    } else {
      ans.push_front(tmp);
    }
  }

  REP(i, n-1) {
    cout << ans[i] << " ";
  }
  cout << ans[n-1] << endl;

  return 0;
}


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

int main()
{
    string S;
    int l = 0;
    cin >> S;

    l = S.length();
    if (S[l - 1] != 's')
        cout << S << 's' << endl;
    else
        cout << S << "es" << endl;
}

Measured memory_bytes: 3136
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var a = int.Parse(_[0]);
            var b = int.Parse(_[1]);

            if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0){
                Console.WriteLine("Possible");
            }else{
                Console.WriteLine("Impossible");
            }
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>

int dp[50];

int fib(int n){
  if(n==0 || n==1) return dp[n]=1;
  if(dp[n]!=-1) return dp[n];
  return dp[n]=fib(n-1)+fib(n-2);
}

int main()
{
  int n,i;
  for(i=0;i<50;i++) dp[i]=-1;
  scanf("%d",&n);
  printf("%d\n",fib(n));
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
  
   int main(void)
   {
       int n;
       int i;
  
       scanf("%d", &n);
 
      for (i = n; i % 2 !=  0 || i % n != 0; i += n);
 
      printf("%d\n", i);
 
      return (0);
 
 }
 

Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long [] A = new long [N];
        for(int i=0;i<N;i++){A[i] = sc.nextLong();}
        Arrays.sort(A);
		long ans = 1;
        String str = "1000000000000000000";
        long limit = Long.parseLong(str);
        for(int i=0;i<N;i++){
          if(A[i]==0){ans=0;break;}
          if(A[i]<=limit/ans){ans*=A[i];}
          else{ans=-1;break;}
        }
		System.out.println(ans);
	}
}

Measured memory_bytes: 61468
#include<stdio.h>
#define MAX 100000
#define NIL -1

typedef struct{
  int parent,left,right;
}Node;
Node T[MAX];
int n,D[MAX],H[MAX];

void print(int u){
  int i,c,deg=0;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  if(T[u].left!=NIL)deg++;
  if(T[u].right!=NIL)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent == NIL)printf("root\n");
  else if(T[u].left == NIL && T[u].right == NIL)printf("leaf\n");
  else printf("internal node\n");

}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].left!=NIL)
    h1=setHeight(T[u].left) + 1;
  if(T[u].right!=NIL)
    h2=setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u){
  if(T[u].parent == NIL)return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
    return T[T[u].parent].right;
  return NIL;
}

void setDepth(int u,int d){
  if(u==NIL)return;
  D[u] = d;
  setDepth(T[u].right, d+1);
  setDepth(T[u].left, d+1);
}

int main(){
  int i,v,l,r,root=0;
  scanf("%d",&n);

  for(i=0;i<n;i++)T[i].parent=NIL;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left=l;
  T[v].right=r;
  if(l!=NIL)T[l].parent=v;
 if(r!=NIL)T[r].parent=v;
  }
  for(i=0;i<n;i++)if(T[i].parent==NIL)root=i;

  setDepth(root,0);
  setHeight(root);

  for(i=0;i<n;i++)print(i);

  return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    rep(i,n){
        int a;
        cin>>a;
    }
    
    
    cout<< (n+k-3)/(k-1)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
xp = sum(a[::2]) - sum(a) // 2
ans = [xp * 2]
for i in range(N - 1):
    ans.append((a[i] - xp) * 2)
    xp = a[i] - xp
print(' '.join(list(map(str, ans))))

Measured memory_bytes: 19148
import java.util.*;

class Main {

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

  private Scanner sc = new Scanner(System.in);

  private void run() {
    int N = Integer.parseInt(sc.next());
    int M = Integer.parseInt(sc.next());

    int[] a = new int[N];
    for (int i = 0; i < M; i++) {
      int k = Integer.parseInt(sc.next());
      for (int j = 0; j < k; j++) {
        int s = Integer.parseInt(sc.next());
        s--;
        a[s] |= 1 << i;
      }
    }

    int P = 0;
    for (int i = 0; i < M; i++) {
      int x = Integer.parseInt(sc.next());
      P |= x << i;
    }

    int ans = 0;

    for (int i = 0; i < (1 << N); i++) {
      int t = 0;
      for (int j = 0; j < N; j++) {
        if ((i >> j & 1) == 1) {
          t ^= a[j];
        }
      }
      if (t == P) {
        ans++;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int n,a[105],s=0,mi=1e9;
	cin>>n;
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(int i=-100;i<=100;i++)
	{
		s=0;
		for(int j=0;j<n;j++)
			s+=(a[j]-i)*(a[j]-i);
		mi=min(mi,s);
	}
	cout<<mi<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007


int main(){
	long int a,b,k;
	scanf("%ld%ld%ld", &a, &b, &k);
	
	//a = a-k;
	if(a>=k){
		a = a-k;
		//printf("%d %d\n", a, b);
	}
	else{
		k = k-a;
		a = 0;
		//k = k-a; printf("%d\n", k);
		if(b>=k) b = b-k;
		else b = 0;
	}
	printf("%ld %ld\n", a, b);
	/*
	if(a<0){
		b = b+a;
		if(b<0) printf("0 0\n");
		else printf("0 %d\n", b);
	}
	else{
		printf("%d %d\n", a, b);
	}
	*/
	//printf("%s\n", t);

	return 0;
}

Measured memory_bytes: 128
<?php
$d=trim(fgets(STDIN));//365
$c=explode(" ",trim(fgets(STDIN)));
$i=0;
while($i<$d){
  $s[$i]=explode(" ",trim(fgets(STDIN)));
  $v=max($s[$i]);
  $k=array_keys($s[$i],$v);
  echo $k[0]+1 . "\n";
  ++$i;
}

Measured memory_bytes: 17060
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
ll n,k,d;
int main()
{
    cin>>n>>k>>d;
    n=abs(n);
    ll sum=n/d;
    ll t=n%d;
    if(sum>k)
    {
        cout<<n-k*d<<endl;
    }
    else
    {
        int x=k-sum;
        if(x%2==0)
        {
            cout<<n%d<<endl;
        }
        else
        {
            cout<<d-n%d<<endl;
        }
    }
    return 0;
}


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

int main() {
   int a, b, c;
  char c1, c2;
  cin >> a >> c1 >> b >> c2 >> c;
  if (b <= 4) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
   
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a=[i for i in a if i%2==0]
a.sort()
ans=0
temp=0
while a:
    temp=a[0]//2
    if temp%2==1:
        del a[0]
    else:
        a[0]=temp
    ans=ans+1
print(ans)

Measured memory_bytes: 4148
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int n; cin>>n;
    vector<ll> a(n); 
    rep(i,0,n) cin>>a[i];
    ll m1=0;
    rep(i,0,n) {
        if(i%2==0) m1+=a[i];
        else m1-=a[i];
    }
    cout<<m1<<endl;
    ll temp=m1;
    for(int i=0; i<=n-2; i++){
        temp=2*a[i]-temp;
        cout<<temp<<endl;
    }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define int long long
using namespace std;
int x;
int gcd(int a,int b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}
int lcm(int a,int b)
{
	return a*b/gcd(a,b);
}
signed main()
{
	scanf("%lld",&x);
	int sum=lcm(x,360);
	printf("%lld\n",sum/x);
}

Measured memory_bytes: 3664
from fractions import gcd


def main():
    A, B = [int(i) for i in input().split()]
    G = gcd(A, B)
    factor = set()
    i = 2
    while i * i < G:
        while True:
            if G % i == 0:
                factor.add(i)
                G = G // i
            else:
                break
        i += 1

    if G != 1:
        factor.add(G)
    print(len(list(factor))+1)


if __name__ == "__main__":
    main()


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

int main(){
  int w, n;

  cin >> w >> n;

  int t[w];

  for(int i = 0; i < w; i++){
    t[i] = i + 1;
  }

  //ツ禿シツ療債つウツづェツつスツ渉?氾板づ可スツδ渉ッツプツ堕?催ャツづーツ行ツつヲツづ篠つ「ツつ「
  for(int i = 0; i < n; i++){
    int a, b;
    char ch;

    cin >> a >> ch >> b;
    swap(t[a - 1], t[b - 1]); //swapツ甘鳴青板づーツ使ツつヲツづ篠配ツ療アツ禿?づ個要ツ素ツづーツ甘按単ツづ可禿シツづェツ妥鳴つヲツづ?つォツづゥ
  }

  for(int i = 0; i < w; i++){
    cout << t[i] << endl;
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

int main() {
	int n, x, i, j;
	vector<int>a;
	bool flag;

	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> x;
		a.push_back(x);
	}

	sort(a.begin(), a.end());

	x = 0;
	j = a[0];
	flag = true;
	for (i = 1; i < n; i++) {
		if (j == a[i]) {
			flag = !flag;
		}
		else {
			if (flag)
				x++;
			j = a[i];
			flag = true;
		}
	}
	if (flag) {
		x++;
	}

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 892
X,N = map(int, input().split())
P = list(map(int, input().split()))

result = 100
AAA = result

if N == 0:
    result = X
else:
    for pi in range(-2,102):
        if pi in P:
            continue

        if pi > X:

            if abs(X - AAA) <= abs(X - pi):
                result = AAA
            else:
                result = pi

            break

        AAA = pi

print(result)

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

template <class T>
map<T,T> prime_factor(T x){
	map<T,T> ans;
	for(T i=2;i*i<=x;i++){
		while(x%i==0){
			x/=i;
			ans[i]++;
		}
	}
	if (x!=1){
		ans[x]=1;
	}
	return ans;
}

template <class T>
T mult(T n,T m){
	if(m==0) return 1;
	if(m==1){
		return n%mod;
	}else if(m%2==0){
		T t=mult(n,m/2);
		return (t*t)%mod;
	}else{
		T t=mult(n,m-1);
		return (t*n)%mod;
	}
}

vector<ll> d1(200010),d2(200010);
template <class T>
void make_table(T N){
	for(ll i=0;i<=N;i++){
		if(i==0){
			d1[i]=1;
			d2[i]=1;
		}else{
			d1[i]=(i*d1[i-1])%mod;
			d2[i]=mult(d1[i],mod-2);
		}
	}
}

 //階乗, 階乗の逆げんテーブル作ってから,d1[n]:n! mod ,d2[n]:(n!)^(-1) mod
template <class T>
T comb_mod_2(T n,T k){
	if(n<k) return 0;
	return (((d1[n]*d2[n-k])%mod)*d2[k])%mod;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  cin>>n>>m;
  map<ll,ll> ret=prime_factor(m);
  ll ans=1;
  make_table(n+100);
  for(auto itr:ret){
    ans*=comb_mod_2(itr.se+n-1,n-1);
    ans%=mod;
  }
  cout<<ans<<endl;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N,K,A[202020],As[202020];
vector<ll> mk[202020];
map<ll, ll> mmp;
ll mk2[202020];
ll i, j, ans;
int main(){
    scanf("%lld%lld", &N,&K);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
        A[i] = (A[i] - 1 + K) % K;
    }
    mmp[0] = 0;
    mk[0].push_back(0);
    
    fornum(i,0,N){
        As[i + 1] = (A[i] + As[i]) % K;
        if(mmp.find(As[i + 1])==mmp.end()){
            ll a = mmp.size();
            mmp[As[i + 1]] = a;
        }
        mk[mmp[As[i + 1]]].push_back(i + 1);
    }

    ans = 0;
    for(auto a:mmp){
        if(mk[a.second].size()<=1)
            continue;
        queue<ll> q;
        q.push(mk[a.second][0]);
        fornum(j,1,mk[a.second].size()){
            ll b = mk[a.second][j];
            while(q.size()&&b-q.front()>=K){
                q.pop();
            }
            ans += q.size();
            q.push(b);
        }
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 26880
import math
import numpy as np
Q = int(input())
LR = []
for _ in range(Q):
    LR.append(list(map(int, input().split())))

rmax = max(r for l, r in LR)
# primes
primes = np.ones(1 + rmax, int)
primes[4::2] = 0
for i in range(3, 1 + int(math.sqrt(rmax)), 2):
    if primes[i]:
        primes[2*i::i] = 0
# like 2017
for i in range(rmax, 0, -2):
    if primes[i] and not primes[(i + 1) // 2]:
        primes[i] = 0
primes[:3] = 0
acc = np.cumsum(primes)
for l, r in LR:
    ans = acc[r] - acc[l - 1]
    print(ans)

Measured memory_bytes: 39588
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  string a,b;
  cin >> a >> b;
  string c = b;
  c.at(0) = b.at(2);
  c.at(2) = b.at(0);
  
  if(a == c) cout << "YES" << endl;
  else cout << "NO" << endl;
 
 
}

Measured memory_bytes: 256
#include <cstdio>

char s[10];
int a,b;

int main()
{
    scanf("%s",s+1);
    a=(s[1]-'0')*10+(s[2]-'0');
    b=(s[3]-'0')*10+(s[4]-'0');
    if (a>=1 && a<=12 && b>=1 && b<=12)
    {
        printf("AMBIGUOUS");
    }
    else if (a>=1 && a<=12)
    {
        printf("MMYY");
    }
    else if (b>=1 && b<=12)
    {
        printf("YYMM");
    }
    else
    {
        printf("NA");
    }
    getchar(); getchar();
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define MAX 128
#define fst first
#define sec second
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
#define int long long
const double PI = 3.141593;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double EPS = 1e-9;
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 (b < a){a = b;return 1;}return 0;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }     //最小公倍数
ll combination(ll n, ll r){if (r * 2 > n)r = n - r;ll dividend = 1;ll divisor = 1;for (ll i = 1; i <= r; ++i){dividend *= (n - i + 1);divisor *= i;}return dividend / divisor;}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    int ans = 0;

    map<int, int> mp;
    rep(i,N){
        int a;
        cin >> a;
        if(mp.find(a)==mp.end()){
            mp[a] = 1;
            ans++;
        }
        else{
            if(mp[a]==1){
                mp[a] = 0;
                ans--;
            }
            else{
                mp[a] = 1;
                ans++;
            }
        }
    }
    /*
    for (auto e:mp){
        cout << e.first << " " << e.second << endl;
    }
    */
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

bool comparg(const P& p1, const P& p2){
    if(p1.first >= 0 && p2.first < 0) return true;
    if(p1.first < 0 && p2.first >= 0) return false;
    if(p1.first == 0 && p2.first == 0){
        if(p1.second < 0 && p2.second > 0) return true;
        if(p1.second > 0 && p2.second < 0) return false;
    }
    if(p1.second * p2.first == p1.first * p2.second) return p1.first + p1.second < p2.first + p2.second;
    return p1.second * p2.first < p1.first * p2.second;
}

int main()
{
    int n;
    cin >> n;
    ll x[103], y[103];
    P p[103];
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
        p[i] = P(x[i], y[i]);
    }
    ll ans = 0;
    sort(p, p + n, comparg);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            ll xsum = 0, ysum = 0;
            for(int k = 0; k <= j; k++){
                xsum += p[(i + k) % n].first;
                ysum += p[(i + k) % n].second;
            }
            ans = max(ans, xsum * xsum + ysum * ysum);
        }
    }
    cout << fixed << setprecision(15) << sqrt(ans) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
const ld pi = 3.14159265358979323846;
//ll MOD = 1e9 + 7;
ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}
void solve(){
    ll x,n;
    cin>>x>>n;
    if(n==0){
        cout<<x<<nl;
        return;
    }
    
    vll cnt(104);
    fo(i,n){
        ll y;
        cin>>y;
        cnt[y]++;
    }
    if(cnt[x] == 0 ){
        cout<<x<<nl;
        return;
    }
    ll ans1 = -inf;
    for(ll i = x-1;i>=0;i--){
        if(cnt[i] == 0){
            ans1 = i;
            break;
        }
    }
    ll ans2 = inf;
    for(ll i =x+1;i<=103;i++){
        if(cnt[i]==0){
            ans2 = i;
            break;
        }
    }
    if(x - ans1<=ans2-x){
        cout<<ans1<<nl;
    }
    else{
        cout<<ans2<<nl;
    }

}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    ll t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";


}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll l, r, d;
    cin >> l >> r >> d;
    ll cnt = 0;
    for (ll i = l; i <= r; i++)
    {
        if (i % d == 0)
            cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int cnt = 0;
  while(a>=b){
    b *= 2;
    cnt++;
  }
  while(b>=c){
    c *= 2;
    cnt++;
  }
  cout << (cnt<=k ? "Yes\n" : "No\n");

  return 0;
}


Measured memory_bytes: 3644
def main():
    N, K = map(int, input().split())
    cnt = []

    for j in range(N):
        cnt.append(0)
    
    for i in range(K):
        d = int(input())
        A = list(map(int, input().split()))
        for k in range(len(A)):
            num = A[k]
            cnt[num - 1] = cnt[num - 1] + 1
    
    print(cnt.count(0))
main()

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(;;){
        int n;
        cin>>n;
        if(!n) return 0;
        char s[n];
        rep(i,0,n) cin>>s[i];
        unordered_map<char, int> m;
        bool X=false;
        rep(j,0,n){
            m[s[j]]++;
            int M=0;
            rep(i,0,26){
                M=max(M,m['A'+i]);
            }
            int cnt=0;
            char win;
            rep(i,0,26){
                if(M==m['A'+i]){
                    cnt++;
                    win='A'+i;
                }
            }
            if(cnt>1){
                if(j==n-1) cout << "TIE"<<"\n";
                continue;
            }
            rep(i,0,26){
                if(M!=m['A'+i]&&M<=m['A'+i]+n-j-1) break;
                if(i==25){
                    X=true;
                    cout << win<<" "<<j+1<<"\n";
                }
            }
            if(X) break;
        }
    }
}


Measured memory_bytes: 3032
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<iomanip>
#include<fstream>
#include<ctime>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;

int n, a, b;

int main() {
scanf("%d %d %d", &n, &a, &b);
if ((a - b) % 2 == 0) printf("Alice\n"); else printf("Borys\n");
return 0;
}



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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int P,Q,R;
    cin >> P >> Q >> R;

    cout << P + Q + R - max(P,max(Q,R)) << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
using namespace std;
//using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX (1000*1000*1000+7)
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >
//#define endl "\n"
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int mod=1e10+7;
int power(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return ans;
}

int32_t main()
{
    fast;

    int n,k,val,val1,ans=0;
    cin>>n>>k;
    map<int,int> mpp;
    rep(i,k)
    {
        cin>>val;
        rep(j,val)
        {
            cin>>val1;
            mpp[val1]++;
        }
    }

    repa(i,1,n)
    {
        if(mpp[i]==0) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <assert.h>
#include <cstdio>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main()
{
    string s;
    cin >> s;
    for (ll i = 0; i < s.size(); i++)
    {
        if (char(s[i] - 3) < 'A')
        {
            cout << (char)(s[i] + 'Z' - 'A' - 2);
        }
        else
        {
            cout << (char)(s[i] - 3);
        }
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3200
#include<stdio.h>
int main(void){
	int N,M,i,j,Aj,Bj,a=0;
	scanf("%d %d",&N,&M);
	int H[N],P[N];
	for(i=0;i<N;i++){
		scanf("%d",&H[i]);
		P[i]=0;
	}
	for(j=0;j<M;j++){
		scanf("%d %d",&Aj,&Bj);
		if(H[Aj-1]>=H[Bj-1]){
			P[Bj-1]=P[Bj-1]+1;
		}
		if(H[Aj-1]<=H[Bj-1]){
			P[Aj-1]=P[Aj-1]+1;
		}
	}
	for(i=0;i<N;i++){
		if(P[i]==0){
			a=a+1;
		}
	}
	printf("%d\n",a);
	return 0;
}


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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(2e5) + 17;

ll I, O, T, J, L, S, Z;

bool read() {
    if (!(cin >> I >> O >> T >> J >> L >> S >> Z))
        return false;

    return true;
}

void solve() {
    ll res1 = (J / 2) * 2 + (L / 2) * 2 + (I / 2) * 2;
    ll res2 = 0;
    --L, --J, --I;

    if (L >= 0 && J >= 0 && I >= 0)
        res2 = 3 + (J / 2) * 2 + (L / 2) * 2 + (I / 2) * 2;

    cout << O + max(res1, res2) << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char c=getchar();int x=0,f=1;
	while(c<'0'||c>'9'){ if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}
int n,a[1000006],k;
int main(){
	n=read();
	for(int i=1;i<=n;++i) a[i]=read();
	sort(a+1,a+n+1);
	if(a[1]==a[n]){
		if(n-1==a[n]||(n/a[n])>=2) printf("Yes\n");
		else printf("No\n");	
	}
	else if(a[n]-a[1]==1){
		for(int i=1;i<=n;++i){
			if(a[i]==a[1]) ++k;
		}
		if(a[n]-k==0) printf("No\n");
		else if((n-k)/(a[n]-k)>=2) printf("Yes\n");
		else printf("No\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


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

int n;
vector<int> a;

int main() {
    cin >> n;
    a.resize(n + 2);
    for (int i = 0; i < n; i++) {
        cin >> a[i + 1];
    }
    // left[i]:[0,i]を訪れるときの合計
    vector<int> left(n + 2, 0);
    for (int i = 0; i < n + 1; i++) {
        left[i + 1] = left[i] + abs(a[i + 1] - a[i]);
    }
    // right[i]:[i,n+1]を訪れるときの合計
    vector<int> right(n + 2, 0);
    for (int i = n + 1; i > 0; i--) {
        right[i - 1] = right[i] + abs(a[i] - a[i - 1]);
    }
    for (int i = 1; i <= n; i++) {
        cout << left[i - 1] + right[i + 1] + abs(a[i - 1] - a[i + 1]) << endl;
    }
}

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

int main() {
    char ch;
    int count[26] = {};
    
    while(cin >> ch) {
        ch = tolower(ch);
        if (isalpha(ch)) {
            count[ch - 'a']++;
        }
    }
    for (int i = 0; i < 26; i++) {
        printf("%c : %d\n", i + 'a' ,count[i]);
    }
    return 0;
}


Measured memory_bytes: 3212
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
//b以下-a未満
int main(){
    ll a,b,x,ans;
    cin>>a>>b>>x;
    ans = b/x;
    if(a>0) ans -= (a-1)/x;
    else ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int l=0,i,c=0;
    string s;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
        if(islower(s[i]))
            l++;
        if(i>1&&i<s.size()-1&&s[i]=='C')
            c++;
    }
    if(s[0]=='A'&&c==1&&l==s.size()-2)
        cout<<"AC"<<endl;
    else
        cout<<"WA"<<endl;
}


Measured memory_bytes: 3600
from functools import reduce
MOD = 10**9+7
n = int(input())
A = list(map(int, input().split()))


def factorization(n):
    retval = []
    tmp = n
    for i in range(2, int(-(-n**.5//1))+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            retval.append((i, cnt))
    if tmp != 1:
        retval.append((tmp, 1))
    return retval


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return (a*b)//gcd(a, b)


x = reduce(lcm, A) % MOD
print(sum(x*pow(a, MOD-2, MOD) for a in A) % MOD)


Measured memory_bytes: 4708
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    if(a < b && b < c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T> constexpr void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

string s;
void solve() {
    cin >> s;

    bool ok = true;
    rep(i, s.size()) {
        auto val = s[i];
        if (i % 2 == 0) {
            if (!(val == 'R' || val == 'U' || val == 'D'))ok = false;
        }
        else {
            if (!(val == 'L' || val == 'U' || val == 'D'))ok = false;
        }
    }

    if (ok) cout << "Yes" << endn;
    else cout << "No" << endn;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    solve();

    cout << flush;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <assert.h>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
const ll MOD = 998244353;
 
ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) { res *= a; res %= MOD; }
        a *= a;
        a %= MOD;
        n >>= 1;
    }
    return res % MOD;
}
 
ll inv(ll x) { return binpow(x, MOD - 2); }
 
void add(ll& x, ll y) { x += y; if (x >= MOD) x -= MOD; }
void take(ll& x, ll y) { x -= y; if (x < 0) x += MOD; }
 
ll sum(ll a, ll b) { add(a, b); return a; }
ll sub(ll a, ll b) { take(a, b); return a; }
ll mul(ll x, ll y) { return (x * y) % MOD; }
ll rat(ll x, ll y) { assert(y); return mul(x, inv(y)); }
 
ll fact(ll a) {
    ll ans = 1;
    for (ll i = 2; i <= a; ++i) {
        ans *= i;
        ans %= MOD;
    }
    ans %= MOD;
    return ans;
}
 
const ll MAXN = 1e5 + 228;
ll ans = 1;
ll kek[3];
ll lol[3];
 
void foo(ll x) {
    ans = mul(ans, x);
}
 
const string CHARS = "RGB";
int ch2i(char ch) {
    return (int)CHARS.find(ch);
}
 
int other(int i, int j) {
    for (int k = 0; k < 3; ++k) {
        if (k != i && k != j) return k;
    }
    assert(false);
}
 
int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
 
    ll n;
    string s;
    cin >> n >> s;
 
    for (int i = 0; i < 3 * n; ++i) {
        ll idx = ch2i(s[i]);
        if (lol[idx]) {
            foo(lol[idx]--);
            continue;
        }
        bool bad = true;
        for (int j = 0; j < 3; ++j) {
            if (j == idx) continue;
            if (!kek[j]) continue;
            bad = false;
            foo(kek[j]--);
            ++lol[other(idx, j)];
            break;
        }
        if (bad) {
            ++kek[idx];
        }
    }
 
    foo(fact(n));
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 720
import sys,bisect
input = sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))

ans = [1]*n

edge = [[] for i in range(n)]
for i in range(n-1):
    u,v = map(int,input().split())
    edge[u-1].append(v-1)
    edge[v-1].append(u-1)

root = 0
chi = [[] for i in range(n)]
par = [-1]*n
used = [False]*n
tank = [0]

while tank:
    q = tank.pop()
    used[q] = True
    for e in edge[q]:
        if not used[e]:
            chi[q].append(e)
            tank.append(e)
            par[e] = q

tank = [root]

idx = dict()
val = dict()
dp = [10**10]*n

eulerNum = -1

while tank:
    q = tank.pop()
    if q >= 0:
        #first time
        num = a[q]
        kk = bisect.bisect_left(dp,num)
        
        val[q] = dp[kk]
        idx[q] = kk
        dp[kk] = num
        ans[q] = bisect.bisect_left(dp,10**10)

        eulerNum += 1
        tank.append(~q)
        for ch in chi[q]:
            tank.append(ch)
    else:
        if ~q != root:
            if dp[idx[~q]] == a[~q]:
                dp[idx[~q]] = val[~q]
                eulerNum += 1

print(*ans,sep = "\n")

Measured memory_bytes: 177968
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string tmp; cin >> tmp;
        mp[tmp]++;
    }
    int cnt = 0;
    for (auto itr=mp.begin(); itr != mp.end(); ++itr) {
        if (cnt < itr->second) cnt = itr->second;
    }
    vector<string> anss;
    for (auto itr=mp.begin(); itr != mp.end(); ++itr) {
        if (cnt == itr->second) anss.push_back(itr->first);
    }
    sort(ALL(anss));
    for (auto s : anss) cout << s << endl;
    return 0;
}

Measured memory_bytes: 25584
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = [LIST() for _ in range(N)]

match_id = [[0]*N for _ in range(N)]

def toid(i, j):
	i, j = sorted([i, j])
	return match_id[i][j]

cnt = 0
for i in range(N):
	for j in range(N):
		if i < j:
			match_id[i][j] = cnt
			cnt += 1

V = N*(N-1)//2

gout = [[] for _ in range(V)]
deg = [0]*V
for i in range(N):
	for j in range(N-2):
		gout[toid(i, A[i][j]-1)].append(toid(i, A[i][j+1]-1))
		deg[toid(i, A[i][j+1]-1)] += 1

topo = [v for v in range(V) if deg[v] == 0 ]
day = [0]*V
deq = deque(topo)
ans = 0
while deq:
	v = deq.popleft()
	for t in gout[v]:
		deg[t] -= 1
		if deg[t] == 0:
			deq.append(t)
			day[t] = day[v] + 1
			ans = day[t]
if any(deg):
	print(-1)
	exit()
print(ans+1)

Measured memory_bytes: 158976
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		int[][][] array = new int [4][3][10];
		Scanner scan = new Scanner(System.in);
		int number = scan.nextInt();
		for(int i = 0; i<number; i++){
			int building = scan.nextInt();
			int floor = scan.nextInt();
			int room_number = scan.nextInt();
			int change = scan.nextInt();

			array[building-1][floor-1][room_number-1] += change;

		}
		for(int j = 0; j<4; j++){
			for(int k = 0; k<3; k++){
				for(int l = 0; l<10; l++){
					System.out.print(" "+array[j][k][l]);
				}
				System.out.println();
			}
			if(j!=3){
				System.out.println("####################");
			}
		}
	}
}


Measured memory_bytes: 29716
def calc(N, s):
    s_sorted = []
    for w in s:
        w_list = list(w)
        w_list.sort()
        s_sorted += [''.join(w_list)]
    s_sorted.sort()
    result = 0
    count = 1
    i = 1
    a = s_sorted[0]
    while (i < N):
        if (a == s_sorted[i]):
            count += 1
        else:
            result += count * (count - 1) // 2
            count = 1
            a = s_sorted[i]
        i += 1
    return result + count * (count - 1) // 2

N = int(input())
s = [input() for _ in range(N)]
print(calc(N, s))

Measured memory_bytes: 17752
import sys
sys.setrecursionlimit(10**7)
def is_ok(m, n):
    return m*(m+1)//2>=n
def meguru_bisect(ng, ok, n):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid, n):
            ok = mid
        else:
            ng = mid
    return ok
def f(n):
    if n>0:
        m = meguru_bisect(0,10**7, n)
        print(m)
        f(n-m)
N = int(input())
f(N)


Measured memory_bytes: 76828
//
//  main.cpp
//  codeforces
//
//  Created by cfhaiteeh on 29/5/2018.
//  Copyright © 2018 cfhaiteeh. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define  LL long long

using namespace  std;
const int maxn=123456;

void init(){
   
   
}





void play(){
   
   
}
void pri(){
   // printf("%lld\n",ans);
}
char ch[5];
int n;
int main() {
    while(scanf("%d",&n)!=EOF){
        int sum=0;
        int t=n;
        while(t>0){
            sum=sum+(t%10);
            t/=10;
        }
        if(n%sum==0)printf("Yes\n");
        else printf("No\n");
        //init();
       // play();
       // pri();
    }
    return 0;
}


Measured memory_bytes: 256