akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <vector>
#include <cstdlib>
using namespace std;
int main(){
  int N;
  cin >> N;

  vector<int> alphabets(26,50);
  string all = "abcdefghijklmnopqrstuvwxyz";
  for(int i = 0;i < N;i++){
    string s;
    cin >> s;

    map<char,int> mp;

    for(int j = 0;j < s.size();j++)mp[s[j]]++;

    for(int j = 0;j < 26;j++)alphabets[j] = min(alphabets[j],mp[all[j]]);
  }

  string ans = "";

  for(int i = 0;i < 26;i++)
    for(int j = 0;j < alphabets[i];j++)ans += all[i];

  cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll; 
#define endl "\n"
#define pb push_back
int main(){
  ll n; 
  cin>>n; 
  ll a[n];
  for(ll i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  ll ans=0;
  for(ll i=0;i<(n-1);i++){
    for(ll j=(i+1);j<(n-1);j++){
      for(ll k=(j+1);k<n;k++){
        if(a[i]==a[j] or a[j]==a[k] or a[i]==a[k]){
          continue; 
        }
        if((a[i]+a[j])>a[k]){
          ans++;
        }
      }
    }
  }
  cout<<ans; 
  return 0;
}

Measured memory_bytes: 3600
import java.util.*;

// ARC 81-D
// https://beta.atcoder.jp/contests/arc081/tasks/arc081_b

public class Main {
	
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		char[][] map = new char[2][52];
		
		map[0] = in.next().toCharArray();
		map[1] = in.next().toCharArray();
		
		long answer = 1;
		long MOD = 1000000007;
		int i = 0;
		
		// Placed vertically
		if (map[0][0] == map[1][0]) {
			answer = 3;
			i = 1;
		}
		// Placed horizontally
		else {
			answer = 6;
			i = 2;
		}
		
		for (; i < N; i++) {
			// Placed vertically
			if (map[0][i] == map[1][i]) {
				// Previous domino placed vertically
				if (map[0][i - 1] == map[1][i - 1]) {
					answer *= 2;
				}
				// Previous domino placed horizontally
				else {
					answer *= 1;
				}
			}
			// Placed horizontally
			else {
				// Previous domino placed vertically
				if (map[0][i - 1] == map[1][i - 1]) {
					answer *= 2;
				}
				// Previous domino placed horizontally
				else {
					answer *= 3;
				}
				i++;
			}
			answer %= MOD;
		}
		
		System.out.println(answer);
	}
}


Measured memory_bytes: 23124
#include<stdio.h>
int main(void)
{
	int N,a;
	int i,j=0;
	int put=0,ans=0;
	scanf("%d",&N);
	for(i=0;i<=N;i++)
	{
		if(i==N){a=0;}
		else
		scanf("%d",&a);
		if(put==a)
		j++;
		if(put!=a && j>0)
		{
			ans+=(j+1)/2;
			j=0;
		}
		put=a;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define BUFSIZE 10000000
typedef long long ll;
#define WDSIZE 10000

char S[BUFSIZE];
char T[BUFSIZE];

int main(void){
      scanf("%s",S);
      scanf("%s",T);
      for(int i = 0;i < BUFSIZE;i++){
        if(S[i] != '\0'){
          if(S[i] != T[i]){
            printf("No");
            exit(0);
          }
        }
        else{
        printf("Yes");
        exit(0);
        }
      }
}


Measured memory_bytes: 1740
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
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> 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; }

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

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

  ll n, m;
  string s, t;
  cin >> n >> m >> s >> t;

  ll g = gcd(n, m), l = n * m / g;
  set<ll> st;
  rep(i, n) st.insert(m * i / g);
  rep(i, m) {
    if (st.find(n * i / g) != st.end()) {
      int j = n * i / m;
      if (s[j] != t[i]) {
        cout << -1 << '\n';
        return 0;
      }
    }
  }
  cout << l << '\n';







  
  return 0;
}

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

int main() 
{
  int N;
  cin >> N;
  int d[55];
  for (int i = 0; i < N; i++) cin >> d[i];
  int total = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++){
      if (i == j) break;
      total += d[i] * d[j];
    }
  }
  cout << total << endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>

 int main(){
 	char character;
	char char1[102];
    scanf("%s",char1 );
    
    char character2;
 	char char2[102]; 
	scanf("%s",char2 ); 
	
	printf("%s%s", char2,char1 );	

	return 0;
}

Measured memory_bytes: 1736
# coding: utf-8
# Here your code !
case = 1
while True:
    N = int(raw_input())
    if N == 0: break
    mat = [[0 for i in xrange(N)] for j in xrange(N)]
    n = 1
    for i in xrange(N): # upper half
        for j in reversed(xrange(i+1)):
            if i%2==0:
                mat[j][i-j] = n
                n += 1
            elif i%2==1:
                mat[i-j][j] = n
                n += 1
                 
    for i in xrange(N,2*N-1): # lower half
        for j in reversed(xrange(i-N+1,N)):
            if i%2==0:
                mat[j][i-j] = n
                n += 1
            elif i%2==1:
                mat[i-j][j] = n
                n += 1
    print 'Case %d:'%(case); case += 1
    for s in mat:
        print ''.join(map(str,[str(st).rjust(3) for st in s]))
    

Measured memory_bytes: 4268
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ctos(c) string(1,c)
#define all(c) (c).begin(), (c).end()
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll d1[26];
ll d2[26];

int main() {
  clr(d1,-1);
  clr(d2,-1);
  string s1,s2;
  cin>>s1;
  cin>>s2;
  rep(i,0,s1.sz){
    if(d1[s1[i]-'a']==-1){
      d1[s1[i]-'a'] = s2[i]-'a';
    }
    else{
      if(d1[s1[i]-'a'] != s2[i]-'a'){
        cout << "No" << endl;
        return 0;
      } 
    }
  }
  rep(i,0,s1.sz){
    if(d2[s2[i]-'a']==-1){
      d2[s2[i]-'a'] = s1[i]-'a';
    }
    else{
      if(d2[s2[i]-'a'] != s1[i]-'a'){
        cout << "No" << endl;
        return 0;
      } 
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((a<=c && c<=b) || (b<=c && c<=a))
        cout<<"Yes"<<'\n';
    else
        cout<<"No"<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin >>s;
    cin>>t;
    bool flag=true;
    if (s.length()+1==t.length())
    {
        for (int i = 0; i < s.length(); ++i)
        {
            if (s[i]!=t[i])
            {
               flag=false;
               break;
            }
        }
        if(flag)
            cout <<"Yes";
        else
            cout <<"No";
    }
    else
        cout <<"No";
    
    
    return 0;
}

Measured memory_bytes: 3628
using System;

class Program
{
    static void Main()
    {
        int i = 0;
        int n = 0;

        while (true)
        {
            n = int.Parse(Console.ReadLine());
            if (n == 0) break;

            Console.WriteLine(string.Format("Case {0}: {1}", ++i, n));
        }
    }
}


Measured memory_bytes: 9308
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    X, N = MI()
    P = LI()

    ans = 0
    d = INF
    for i in range(0, 102):
        if i in P: continue
        if d > abs(i - X):
            ans = i
            d = abs(i - X)
    print(ans)

if __name__ == '__main__':
    solve()


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

int main() {
    int H, W;
    char s[60][60];
    cin >> H >> W;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> s[i][j];
            if (s[i][j] == '.') s[i][j] = '0';
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (s[i][j] == '#') {
                if (i > 0) {
                    if (j > 0) {
                        if (s[i - 1][j - 1] != '#') s[i - 1][j - 1] += 1;
                    }
                    if (j < W) {
                        if (s[i - 1][j + 1] != '#') s[i - 1][j + 1] += 1;
                    }
                    if (s[i - 1][j] != '#') s[i - 1][j] += 1;
                }
                if (i < H) {
                    if (j > 0) {
                        if (s[i + 1][j - 1] != '#') s[i + 1][j - 1] += 1;
                    }
                    if (j < W) {
                        if (s[i + 1][j + 1] != '#') s[i + 1][j + 1] += 1;
                    }
                    if (s[i + 1][j] != '#') s[i + 1][j] += 1;
                }
                if (j > 0) {
                    if (s[i][j - 1] != '#') s[i][j - 1] += 1;
                }
                if (j < W) {
                    if (s[i][j + 1] != '#') s[i][j + 1] += 1;
                }
            }
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cout << s[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
int hen(int h, int m) {
	return h * 60 + m;
}
void input(int &num, vector<int> &line) {
	cin >> num;
	for (int i = 0; i < num; ++i) {
		int h, m;
		cin >> h >> m;
		line.push_back(hen(h, m));
	}
	sort(line.begin(), line.end());
	line.push_back(hen(24, 0));
}


void kan(int num) {
	printf("%d:%02d", num / 60, num % 60);
}

void output(int &N, int &M, vector<int> &nline, vector<int> &mline) {
	int i, j;
	i = j = 0;
	for (int k = 0; k < N + M; ++k) {
		if (nline[i] == mline[j]) {
			kan(nline[i]);
			++k;
			++i;
			++j;
		}
		else if(nline[i]<mline[j]) {
			kan(nline[i]);
		++i;
		}
		else {
			kan(mline[j]);
			++j;
		}
		cout << (k + 1 == N + M ? '\n' : ' ');
	}
}

int main() {
	int N, M;
	vector<int> nline, mline;
	input(N, nline);
	input(M, mline);
	output(N, M, nline, mline);
}

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

using namespace std;
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int q,a,b,c,d;
inline int getdiv(int K)
{
	int L=0,R=a,border=0;
	while(L<=R)
	{
		int mid=(L+R)>>1;
		int A=a-mid,B=b-mid/K;
		if(1ll*(A+1)*K-1>=B)border=mid,L=mid+1;
		else R=mid-1;
	}
	border+=border/K; return border;
}
inline int getps(int xx,int p,int K)
{
	if(p<=xx) return p%(K+1)==0;
	else return (a+b-p+1)%(K+1)!=0;
}
int main()
{
	q=read(); while(q--)
	{
		a=read(); b=read(); c=read(); d=read();
		int K=(max(a,b)-1)/(min(a,b)+1)+1;
		int gg=getdiv(K);
		for(int i=c;i<=d;i++)
			putchar('A'+getps(gg,i,K));
		puts("");
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
 
int main(){
    string s;
    ostringstream oss;
    int m, h;
    while (cin >> s, s != "-"){
        cin >> m;
        for (int i = 0; i < m; i++){
            cin >> h;
            s = s.substr(h) + s.substr(0, h);
        }
        oss << s << endl;
    }
    cout << oss.str() << flush;
}


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

int main() {
  // ここにプログラムを追記
  int N;
  int *c;
  int *s, *f;
  int t;
  int i;
  int j;
  
  cin >> N;
  c = new int[N];
  s = new int[N];
  f = new int[N];
  
  for(i=0;i<N;i++){
    cin >> c[i] >> s[i] >> f[i];
  }
  for(i=0;i<N;i++){
    t = 0;
    for(j=i;j<N-1;j++){
      if(t <= s[j]) t = s[j];
      else if(t%f[j]==0); 
      else t = t + f[j] - t % f[j];
      t += c[j];
    }
    cout << t << endl;
  }

  delete[] c;
  delete[] s;
  delete[] f;
  
}

Measured memory_bytes: 256
from bisect import bisect_left
import sys
n, Q = [int(x) for x in sys.stdin.readline().split()]
stx = [[int(x) for x in sys.stdin.readline().split()] for i in range(n)]
q = [int(sys.stdin.readline()) for i in range(Q)]
stx.sort(key=lambda x: x[2])
ans = [-1 for i in range(Q)]
skip = [-1 for i in range(Q)]

for (s, t, x) in stx:
  begin = bisect_left(q, s-x)
  end = bisect_left(q, t-x)
  while begin<end:
    if skip[begin]==-1:
      ans[begin] = x
      skip[begin] = end
      begin += 1
    else:
      begin = skip[begin]
for e in ans:
  print(e)

Measured memory_bytes: 110764
#include<stdio.h>
int a[1000100],g[100000]={1},cnt=0,m=0;

void shell(int A[],int g,int n){
	for(int i=g;i<n;i++){
		int v=a[i];
		int j=i-g;
		while(j>=0&&A[j]>v){
			A[j+g]=A[j];
			j-=g;
			cnt++;
		}
		A[j+g]=v;
	}
}

void shellSort(int A[],int n){
	while(3*g[m]+1<n){
		m++;
		g[m]=3*g[m-1]+1;
	}
	for(int i=m;i>=0;i--){
		shell(A,g[i],n);
	}
}
int main(){
	int i,n,j,k;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&a[i]);
	shellSort(a,n);
	printf("%d\n",m+1);
	for(i=m;i>=0;i--){
		printf("%d",g[i]);
		if(i!=0) printf(" ");
		else printf("\n");
	}
	printf("%d\n",cnt);
	for(i=0;i<n;i++)	printf("%d\n",a[i]);
} 


Measured memory_bytes: 6588
n=int(input())
c,m=[],[]
d={}
t={}
for i in range(n):
    s,p=map(str,input().split())
    m.append((s,int(p)))
    if s not in c:
        c.append(s)
        d[s]=[int(p)]
    else:
        d[s].append(int(p))
    t[(s,int(p))]=i+1
c.sort()
ans={}
cnt=1
for i in c:
    d[i].sort(reverse=True)
    for j in d[i]:
        ans[cnt]=(i,j)
        cnt+=1
for i in range(1,n+1):
    print(t[ans[i]])


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define int long long
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define F first
#define S second
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int dp[100009];
bool used[100009];

signed main(){
	dp[0]=1;
	int n,m;
	cin>>n>>m;
	r(i,m){
		int x;
		cin>>x;
		used[x]=1;
	}

	for(int i=0;i<=n;i++){
		if(used[i])continue;
		dp[i+1]+=dp[i];
		dp[i+2]+=dp[i];
		dp[i+1] %= 1000000007;
		dp[i+2] %= 1000000007;
	}
	cout<<dp[n]<<endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000123456LL

template<class T>
void dijkstra(const vector<vector<pair<int,T>>> &vec, vector<T> &d, int from=0){
  using P = pair<T,int>;
  fill(all(d), INF);
  priority_queue<P, vector<P>, greater<P>> pq;
  d[from] = 0;
  pq.push(mp(0,from));
  while(!pq.empty()){
    auto p = pq.top(); pq.pop();
    int v = p.second;
    T dd = p.first;
    if(d[v] < dd) continue;
    for(auto to : vec[v]){
      T nd = dd + to.second;
      int ni = to.first;
      if(d[ni] > nd){
        d[ni] = nd;
        pq.push(mp(nd, ni));
      }
    }
  }
}


int main(){
  int n;
  cin>>n;
  vector<vector<pair<int,long>>> vec(n);
  rep(i,n-1){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    vec[a].pb(mp(b,c));
    vec[b].pb(mp(a,c));
  }

  int q,k;
  cin>>q>>k;
  k--;

  vector<long> d(n);
  dijkstra(vec, d, k);

  rep(_,q){
    int x,y;
    cin>>x>>y;
    x--;y--;
    cout << d[x]+d[y] << endl;
  }


  return 0;
}


Measured memory_bytes: 11120
#include <iostream>
#include <queue>
#include <string>

using namespace std;

int main()	{
  	string s;
  	string result;
	cin >> s;
  	for (int i = 0; s[i] != '\0'; i++)	{
    	if (s[i] == '1' || s[i] == '0')
          	result.push_back(s[i]);
      	else if (s[i] == 'B' && !(result.empty()))
          	result.pop_back();
    }
  	cout << result << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define bp  __builtin_popcount
#define pb push_back
#define sz(s) (int)(s.size())

using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e6+5;
const  double EPS = 1e-14;
const int MOD = 1e9+7;

ll GCD(ll a,ll b){return (a)?GCD(b%a,a):b;}
ll LCM(ll a, ll b){return a*b/GCD(a,b);}
ll fastpow(ll b, ll p){if(!p)return 1;ll ret = fastpow(b, p >> 1);ret *= ret;if(p&1)ret*= b;return ret;}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
  //  freopen("in.txt", "r", stdin);
#endif
    int n;
    cin>>n;
    int arr[n+5];
    for(int i=0; i<n; i++)
        cin>>arr[i];
    for(int i=1; i<n; i++)
        if(arr[i]==arr[i-1])
        {
            for(int j=i; j<n-1; j++)
                arr[j]=arr[j+1];
            n--;
        }
    int idx=1;
    for(int i=1; i<n-1; i++)
    {
        if(arr[i]>arr[i-1]&&arr[i]>arr[i+1]||arr[i]<arr[i-1]&&arr[i]<arr[i+1])
        {
            idx++;
            arr[i]=arr[i+1];
        }
    }
    cout<<idx;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  string s;
  cin>>s;
  int n=s.size();
  string ans="";
  rep(i,0,n){
    if(i%2==0)ans+=s[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3692
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

string s="aaaaaaaaaa";

void fun(ll i,ll n,ll u) {
    if(i==n) {
        cout<<s.substr(0,n)<<endl;
        return;
    }
    int sum=0;
    ifr(j,0,u+1) {
        s[i] = j+'a';
        bool f[26]={0}; sum = 0;
        ifr(k,0,i+1) f[s[k]-'a']=1;
        ifr(k,0,26) sum += f[k];
        fun(i+1,n,sum);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // int T;cin>>T;while(T--) 
    {
        ll n;
        cin>>n;
        fun(0,n,0);
    }
    return 0;
}

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

using namespace std;

int main(){
    string s,ans = "Good";
    cin >> s;

    for(int i = 0;i < s.size()-1;i++){
        if(s[i] == s[i+1])ans = "Bad";
    }


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

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

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] lr = new int[n][2];
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			int l = sc.nextInt();
			lr[i][0] = x - l;
			lr[i][1] = x + l;
		}

		Arrays.sort(lr, (a, b) -> Integer.compare(a[1], b[1]));
		int a = 1;
		int current = lr[0][1];
		for (int i = 1; i < n; i++) {
			if (lr[i][0] >= current) {
				a++;
				current = lr[i][1];
			}
		}

		System.out.println(a);
	}
}


Measured memory_bytes: 94776
//Bi-smi llāh

#include<bits/stdc++.h>
using namespace std;
#define ll long long



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

	bool ok = false;

	for(int i = a; i <= b; ++i){
			if(i % k == 0){
					ok = true;
					break;
				}
		}

	ok ? cout << "OK\n" : cout << "NG\n";

	return 0;
	}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define count2way(v, x) high2way(v, x) - low2way(v, x)
#define lower(v, x) low2way(v, x) - v.begin()       //1番左が0、もし見つから無いならｎを出力
#define higher(v, x) high2way(v, x) - v.begin() - 1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout << a << endl
#define putout2(a, b) \
  putout(a);          \
  putout(b)
#define putout3(a, b, c) \
  putout(a);             \
  putout(b);             \
  putout(c)
#define putout4(a, b, c, d) \
  putout(a);                \
  putout(b);                \
  putout(c);                \
  putout(d)
#define putout5(a, b, c, d, e) \
  putout(a);                   \
  putout(b);                   \
  putout(c);                   \
  putout(d);                   \
  putout(e)
#define Gput(a, b) G[a].push_back(b)
#define cin1(a) cin >> a
#define cin2(a, b) cin >> a >> b
#define cin3(a, b, c) cin >> a >> b >> c
#define cin4(a, b, c, d) cin >> a >> b >> c >> d
#define cin5(a, b, c, d, e) cin >> a >> b >> c >> d >> e
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}
template <typename T>
T lcm(T x, T y)
{
  T z = gcd(x, y);
  return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
  if (n < 2)
    return false;
  else if (n == 2)
    return true;
  else if (n % 2 == 0)
    return false;
  double sqrtn = sqrt(n);
  for (T i = 3; i < sqrtn + 1; i++)
  {
    if (n % i == 0)
    {
      return false;
    }
    i++;
  }
  return true;
}
template <typename T>
T modinv(T a, T m)
{
  T b = m, u = 1, v = 0;
  while (b)
  {
    T t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//多次元配列の宣言法
//vector<vector<ll>> field(h, vector<ll>(w));
template <class T>
inline void chmax(T &a, T b)
{
  if (a < b)
    a = b;
}
template <class T>
inline void chmin(T &a, T b)
{
  if (a > b)
    a = b;
}
/*
ライブラリをここに置いてコメントを削除
*/

int main()
{
  cout << fixed << setprecision(30);
  string s;
  cin >> s;
  loop(i, 3) if (s[i] == '7')
  {
    putout("Yes");
    return 0;
  }
  putout("No");
  return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

class BIT {
    int n;
    vector<int> dat;

public:
    BIT(int _n) : n(_n), dat(vector<int>(_n+1)) {}

    void add(int i, int x)
    {
        while (i <= n) {
            dat[i] += x;
            i += i & -i;
        }
    }

    int sum(int i)
    {
        int res = 0;
        while (i > 0) {
            res += dat[i];
            i -= i & -i;
        }
        return res;
    }

    // [l, r]
    int sum(int l, int r)
    {
        return sum(r) - sum(l-1);
    }
};

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M; 

    map<int, vector<PII>> range;

    rep(i, N) {
        int L, R;
        cin >> L >> R;
        range[R - L + 1].emplace_back(L, R);
    }

    BIT bit(M);
    int num = N;

    for (int d=1; d<=M; d++) {
        int ans = 0;

        num -= range[d].size();
        for (auto r : range[d]) {
            bit.add(r.first, 1);
            bit.add(r.second+1, -1);
        }

        for (int i=d; i<=M; i+=d) {
            ans += bit.sum(i);
        }

        cout << ans + num << endl;
    }
}



Measured memory_bytes: 13440
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
using namespace std;
long double ans,a,b,h,m;
int main()
{
	cin>>a>>b>>h>>m;
	printf("%.10Lf",sqrt(a*a+b*b-2.0*a*b*cos((30.0*h-5.5*m)/180.0*M_PI)));
	return 0;
}

Measured memory_bytes: 4152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

template <ll Mod>
struct ModInt {
  ll n;
  ModInt(const ll x = 0) : n(x) { while (n < 0) n += Mod; n %= Mod; }
  ModInt operator+(const ModInt r) const { return ModInt(*this) += r; }
  ModInt operator-(const ModInt r) const { return ModInt(*this) -= r; }
  ModInt operator*(const ModInt r) const { return ModInt(*this) *= r; }
  ModInt operator/(const ModInt r) const { return ModInt(*this) /= r; }
  ModInt &operator+=(const ModInt r) { n += r.n; if (n >= Mod) n -= Mod; return *this; }
  ModInt &operator-=(const ModInt r) { if (n < r.n) n += Mod; n -= r.n; return *this; }
  ModInt &operator*=(const ModInt r) { n = n * r.n % Mod; return *this; }
  ModInt &operator/=(const ModInt r) { return *this *= r.inv(); }
  ModInt pow(ll x) const { ModInt<Mod> ret(1), tmp(*this); while (x) { if (x&1) ret *= tmp; tmp *= tmp; x >>= 1; } return ret; }
  ModInt inv() const { return pow(Mod-2); }
  friend ostream& operator<<(ostream& os, const ModInt& obj) { return os << obj.n; }
  friend istream& operator>>(istream& is, ModInt& obj) { ll t; is >> t; obj = ModInt(t); return is; }
};
constexpr ll mod = 1000000007;
using mint = ModInt<mod>;
mint operator"" _mi(unsigned long long n) { return mint(n); }

// T modint
template<class T>
struct Combination {
  vector<T> fact, inv_fact;
  Combination(ll n) : fact(n+1), inv_fact(n+1) {
    fact[0] = T(1);
    for (ll i = 1; i <= n; i++) fact[i] = fact[i-1] * static_cast<T>(i);
    inv_fact[n] = fact[n].inv();
    for (ll i = n; i > 0; i--) inv_fact[i-1] = inv_fact[i] * static_cast<T>(i);
  }

  T P(ll n, ll k) const {
    if (n < k or k < 0) return T(0);
    return fact[n] * inv_fact[n-k];
  }

  T C(ll n, ll k) const {
    if (n < k or k < 0) return T(0);
    return fact[n] * inv_fact[n-k] * inv_fact[k];
  }

  T H(ll n, ll k) const {
    if (n < 0 or k < 0) return T(0);
    if (n == 0 and k == 0) return T(1);
    return C(n+k-1, n-1);
  }
};

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

  vl r(2), c(2);
  rep(i, 2) {
    cin >> r[i] >> c[i];
  }
  r[0]--, c[0]--;

  constexpr ll limit = 2'000'000;
  Combination<mint> comb(limit);

  auto f = [&comb](ll y, ll x) -> mint {
    mint ret = (2_mi).pow(y+x+1)-1;
    rep(i, x) {
      ret -= comb.C(y+i, i) * ((2_mi).pow(x-i)-1_mi);
    }
    rep(i, y) {
      ret -= comb.C(x+i, i) * ((2_mi).pow(y-i)-1_mi);
    }
    return ret;
  };

  mint ans;
  rep(i, 2) {
    rep(j, 2) {
      ans += mint(i^j ? -1 : 1) * f(r[i], c[j]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 31488
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };
static const int mod = 1000000007;
static const int MAX_N = 100000;

int N;
int A[305][305];
vector<P2> G;
vector<P1> E[305];
int ans;
int dist[305];
int used[305][305]={false};

int dijkstra(int s,int e){
    for(int i=0;i<305;++i)dist[i] = INF;
    priority_queue< P1, vector<P1>, greater<P1> > pq;
    dist[s] = 0;
    pq.push(P1(0,s));
    while(!pq.empty()){
        P1 p = pq.top();
        pq.pop();
        int v = p.second;
        if(dist[v]<p.first)continue;
        for(auto e : E[v]){
            if(dist[e.first]>dist[v]+e.second){
                dist[e.first] = dist[v]+e.second;
                pq.push(P1(dist[e.first],e.first));
            }
        }
    }
    return dist[e];
}

signed main(){
    cin>>N;
    for(int i=0;i<N;++i){
        for(int j=0;j<N;++j){
            int a;
            int u = min(i,j);
            int v = max(i,j);
            cin>>a;
            A[u][v] = a;
            G.PB(P2(a,P1(u,v)));
        }
    }

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

    for(auto u : G){
        int from = u.second.first, to = u.second.second;
        if(used[from][to])continue;
        used[from][to]=true;
        //cout<<"////////////////////"<<endl;
        //cout<<from<<" "<<to<<endl;
        int cost = dijkstra(from,to);
        //cout<<cost<<" "<<u.first<<endl;
        if(cost==INF||cost>u.first){
            E[from].PB(P1(to,u.first));
            E[to].PB(P1(from,u.first));
            ans+=u.first;
            /*int tmp = INF;
            int p;
            for(int i=0;i<N;++i){
                if(u.first<=dist[i])continue;
                if(u.first-dist[i]<tmp){
                    tmp = u.first-dist[i];
                    p = i;
                }
            }
            //cout<<p<<endl;
            E[p].PB(P1(to,u.first-dist[p]));
            E[to].PB(P1(p,u.first-dist[p]));
            ans+=u.first-dist[p];
            cout<<p<<" "<<to<<endl;
            */
        }
        else {
            if(cost!=u.first){
                cout<<-1<<endl;
                return 0;
            }
        }
        //cout<<"////////////////////"<<endl;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 5492
#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);
    string s; cin >> s;
    ll k; cin >> k;
    char ans;
    rep(i, min(k, (ll)s.size())) {
        if (s[i]>='2') { cout << s[i] << endl; return 0; }
    }
    cout << '1' << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

	int a = scan.nextInt();
	int b = scan.nextInt();

	if(a == 1 && b == 1){
	    System.out.println("Draw");
	}else if(a == 1){
	    System.out.println("Alice");
	}else if(b == 1){
	    System.out.println("Bob");
	}else{
	    if(a > b){
		System.out.println("Alice");
	    }else if(b > a){
		System.out.println("Bob");
	    }else{
		System.out.println("Draw");
	    }
	}
    }
}



Measured memory_bytes: 23764
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 4010

struct BIT{

  int data[SIZE];
  int size;
  
  void init(int n){
    for(int i=1;i<=n;i++) data[i] = 0;
    size = n;
  }

  void add(int k,int x){

    while(k<=size){
      data[k] += x;
      k += k&(-k);
    }

  }

  int sum(int k){
    int ret = 0;

    while(k>0){
      ret += data[k];
      k -= k&(-k);
    }

    return ret;
  }
};

int ul_max[SIZE][SIZE],dr_max[SIZE][SIZE];
bool castle[SIZE][SIZE];
BIT bit;
priority_queue<pair<int,int> > pq;

int h,w,l,p;

int calc(int t){
  int ret = 0,s;

  bit.init(h);

  while(pq.size()) pq.pop();
  
  for(int i=1;i<=h;i++){
    if(t+i <= 0 || t+i>w) continue;
    pq.push({-(i-ul_max[i][t+i]+1),i});
  }

  for(int i=1;i<=h;i++){

    while(pq.size() && -pq.top().first <= i){
      bit.add(pq.top().second,1);
      pq.pop();
    }

    if(t+i <= 0 || t+i > w ) continue;

    s = dr_max[i][t+i];
    
    if(s >= l && i+(l-1) <= h){
      
      int add = bit.sum(i+(s-1))-bit.sum(i+(l-2));
      
      ret += add;
    }
  }    

  return ret;
}

int main(){
  int a,b;
  int dp[SIZE];
  
  scanf("%d%d%d%d",&h,&w,&l,&p);
  
  for(int i=0;i<p;i++){
    scanf("%d%d",&a,&b);
    castle[a][b] = true;
  }
  
  for(int i=h;i>=1;i--){
    dp[w+1] = 0;
    for(int j=w;j>=1;j--){
      if(castle[i][j]){
	dp[j] = 0;
      }else{
	dp[j] = dp[j+1]+1;
      }
      dr_max[i][j] = dp[j];
    }
  }

  for(int i=w;i>=1;i--){
    dp[h+1] = 0;
    for(int j=h;j>=1;j--){
      if(castle[j][i]){
	dp[j] = 0;
      }else{
	dp[j] = dp[j+1]+1;
      }
      dr_max[j][i] = min(dr_max[j][i],dp[j]);
    }
  }

  
  for(int i=1;i<=h;i++){
    dp[0] = 0;
    for(int j=1;j<=w;j++){
      if(castle[i][j]){
	dp[j] = 0;
      }else{
	dp[j] = dp[j-1]+1;
      }
      ul_max[i][j] = dp[j];
    }
  }

  for(int i=1;i<=w;i++){
    dp[0] = 0;
    for(int j=1;j<=h;j++){
      if(castle[j][i]){
	dp[j] = 0;
      }else{
	dp[j] = dp[j-1]+1;
      }
      ul_max[j][i] = min(ul_max[j][i],dp[j]);
    }
  }

  ll ans = 0;
  
  for(int i=-h;i<=w-1;i++){
    ans += calc(i);
  }

  printf("%lld\n",ans);
  
  return 0;
}

Measured memory_bytes: 143032
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
a.sort()
I,A=min(a),max(a)
c=Counter(a)
p=print
e=exit
if c[A]==1or c[I]>A%2+1or I*2<A:e(p("Impossible"))
for i in range(I+1,A+1):
 if not(i in c and c[i]>=2):e(p("Impossible"))
p("Possible")

Measured memory_bytes: 9356
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
from collections import defaultdict

n = II()
tasks = [0 for i in range(n)]
for i in range(n):
    tasks[i] = LI()
tasks = sorted(tasks, key=lambda x: x[1])
load = 0
for i in range(n):
    load += tasks[i][0]
    if load > tasks[i][1]:
        print("No")
        break
else:
    print("Yes")

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

int n;
long long l;
int trie[100005][2];
int tn;

long long grundy;

long long get_grundy(long long x) {
  long long answer = 1;
  while (answer <= x) {
    if (answer * 2 > x || x % (answer * 2) > 0) {
      return answer;
    }
    answer *= 2;
  }
}

void insert(string s) {
  int idx = 0;
  for (int i = 0; i < s.size(); i++) {
    int next = s[i] - '0';
    if (trie[idx][next] == -1) {
      trie[idx][next] = tn++;
    }
    idx = trie[idx][next];
  }
}

int main() {
  memset(trie, -1, sizeof(trie));
  tn = 1;
  cin >> n >> l;
  for (int ni = 0; ni < n; ni++) {
    string s;
    cin >> s;
    insert(s);
  }
  grundy = 0;
  queue<pair<int, int>> q;
  q.push(make_pair(0, 0));
  while (!q.empty()) {
    auto top = q.front();
    int idx = top.first;
    int depth = top.second;
    q.pop();
    if (trie[idx][0] == -1 && trie[idx][1] != -1 || trie[idx][0] != -1 && trie[idx][1] == -1) {
      grundy ^= get_grundy(l - depth);
    }
    if (trie[idx][0] != -1) {
      q.push(make_pair(trie[idx][0], depth + 1));
    }
    if (trie[idx][1] != -1) {
      q.push(make_pair(trie[idx][1], depth + 1));
    }
  }
  if (grundy == 0) {
    cout << "Bob" << endl;
  } else {
    cout << "Alice" << endl;
  }
  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
//const int INF=1e9+5; 
long long int dp[101][100001];
int main()
{
	fastio;
	int n,w;
	cin>>n>>w;
	vector<pair<int,int>>a(n+1);
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].first>>a[i].second;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=w;j++)
		{
			if(a[i].first>j)dp[i][j]=dp[i-1][j];
			else
			{
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i].first]+a[i].second);
			}
		}
	}
	cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 78336
import itertools
from math import factorial
from scipy.misc import comb

N = int(input())
s = {}
for _ in range(N):
    b = list(input())
    b.sort()
    c = ''.join(b)
    if not c in s:
        s[c] = 1
    else:
        s[c] += 1

a = [comb(v, 2, exact=True) for v in s.values()]
print(sum(a))

Measured memory_bytes: 28008
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::min;

const MOD: i64 = 1000000007;

fn main() {
    input! {
        s: i64
    };
    if s < 6 {
        println!("{}", [0, 1][(s > 2) as usize]);
        return;
    }
    let n = s / 3 + ((s % 3 != 0) as i64);
    // サイズnの数列を右側（最右は {3 or 1 or 2}）から崩していって
    // それより左に割り当てていく
    // 10の場合
    // [3, 3, 3, 1]
    // 0~0 に 10-3*1 を割り当て
    // 0~1 に 10-3*2 を割り当て
    // 0~2 に 10-3*3 を割り当て

    // 3の倍数の場合数列全部が3の1パターン、他は最右が不完全な {1 or 2}なので0
    let mut rs = (s % 3 == 0) as i64;

    // seq_size: 数列のサイズ
    for seq_size in 1..n {
        // 割り当てる数字の合計
        let resource = s - 3 * seq_size;
        // a_{1..=seq_size}にresouceを割り当てる == 区別しない玉を区別する箱に分配
        // http://www.ee.em-net.ne.jp/~takeji/kousiki/kumiwake.pdf
        rs = (rs + combination(seq_size + resource - 1, resource)) % MOD;
    }

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

// https://qiita.com/Cassin01/items/d94fc89a97f21af8ac8d
fn extended_euclidean(u: i64, v: i64) -> i64 {
    let mut r0 = u;
    let mut r1 = v;
    let mut s0 = 1;
    let mut s1 = 0;
    let mut t0 = 0;
    let mut t1 = 1;
    while r1 != 0 {
        let q = r0 / r1;
        let r = r0 - q * r1;
        let s = s0 - q * s1;
        let t = t0 - q * t1;
        r0 = r1;
        s0 = s1;
        t0 = t1;
        r1 = r;
        s1 = s;
        t1 = t;
    }
    if t0 < 0 {
        t0 + u
    } else {
        t0
    }
}

// https://qiita.com/Cassin01/items/d94fc89a97f21af8ac8d
// nCc mod m を計算します。
fn combination(mut n: i64, c: i64) -> i64 {
    let mut upe = 1;
    let mut dow = 1;
    for i in 1..=c {
        upe = upe * n % MOD;
        dow = dow * i % MOD;
        n -= 1;
    }
    upe * extended_euclidean(MOD, dow) % MOD
}


Measured memory_bytes: 2140
x, n = map(int, input().split())
try:
    in_li = set(map(int, input().split()))
    num_li = list({i for i in range(min(list(in_li))-1,max(list(in_li))+2)} - in_li)
except:
    in_li = set()
    num_li = []

num_li.sort()
res = 0

if n == 0:
    print(x)
elif x not in in_li:
    print(x)
else:
    for i in num_li:
        if abs(x-i) < abs(x-res):
            res = i
    print(res)


Measured memory_bytes: 62012
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=110;
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
char s[maxn];

bool check(int left,int right)
{
    bool flag=true;
    while(left<right)
    {
        if(s[left]!=s[right])
        {
            flag=false;
            break;
        }
        left++;
        right--;
    }
    return flag;
}

int main()
{
    #ifdef __LOCAL__
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
    scanf("%s",s+1);
    int len=strlen(s+1);
    if(check(1,len)&&check(1,(len-1)/2)&&check((len+3)/2,len))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"kyoto
tokyo"# => r#"Yes"#,
}


fn solve(src: &str) -> String {
    input! {
        source = src,
        s: String,
        t: String,
    }
    let mut ans = "No";

    for i in 0..s.len() {
        // println!("{} <=> {}", s[0..s.len() - i].chars().collect::<String>(), s[s.len() - i..].chars().collect::<String>());
        let mut ns = s[s.len() - i..].chars().collect::<String>();
        ns.push_str(&s[0..s.len() - i].chars().collect::<String>());
        if ns == t {
            ans = "Yes";
            break;
        }
    }

    ans.to_string()
}

Measured memory_bytes: 4352