akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    var answer = ""
    val rules = mutableSetOf<Pair<Int,Int>>()
    repeat(m) {
        rules.add(readLine()!!.split(" ").map { it.toInt() }.let { Pair(it.first(),it.last()) })
    }
    if (rules.groupBy { it.first }.filter { it.value.size > 1 }.isNotEmpty()) return println(-1)
    if (rules.any { it.first == 1 && it.second == 0 } && n != 1) return println(-1)
    if (!rules.any { it.first == 1 && it.second != 0 } && n == 1) return println(0)
    for (i in 1..n) {
        if (rules.any { it.first == i }) answer += rules.first { it.first == i }.second.toString()
        else if (i == 1) answer += "1"
        else answer += "0"
    }
    println(answer)
}


Measured memory_bytes: 36284
N = int(input())
W_list = list(map(int, input().split()))

left, right = 0, 0
ans = 100000000

for idx,w in enumerate(W_list):
    if idx == 0:
        left = w
        right = sum(W_list) - w
    else:
        left += w
        right -= w
        
    if ans > abs(left - right):
        ans = abs(left - right)
print(ans)
    

Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct BOOK
{
    char name[11];
    int num;
}book[101];
int main()
{
    int n;
    scanf("%d",&n);getchar();
    int i,arr[100],j;
    for(i=0;i<n;i++)
    {
        scanf("%s %d",book[i].name,&book[i].num);getchar();
    }
    char a[11];int t;
    for(i=0;i<n;i++)
    { int num1=0,num2=0;
        for(j=0;j<n;j++)
      {
          if(i!=j)
        {if(strcmp(book[i].name,book[j].name)<0||(strcmp(book[i].name,book[j].name)==0&&book[i].num>book[j].num))
            num1++;
        else
            num2++;
        }
      }
      arr[num2+1]=i+1;
    }
    for(i=1;i<=n;i++) printf("%d\n",arr[i]);
    return 0;
}


Measured memory_bytes: 128
n, y = map(int, input().split())
for i in range(n+1) :
    for j in range(n+1) :
        k = n - i - j
        if k < 0 : break
        if i*10000 + j*5000 + k*1000 == y :
            print(i,j,k)
            exit(0)

print('-1 -1 -1')


Measured memory_bytes: 3060
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
constexpr int MAX_V = 1000;
 
class twoMatching {
private:
  vector<int> G[MAX_V];
  int match[MAX_V];
  bool used[MAX_V];
  int V;
public:
  twoMatching(int v) {
    V = v;
  }
  void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
  }
 
  bool dfs(int v) {
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
      int u = G[v][i], w = match[u];
      if (w < 0 || !used[w] && dfs(w)) {
    match[v] = u;
    match[u] = v;
    return true;
      }
    }
    return false;
  }
 
  int bipartite_matching() {
    int res = 0;
    memset(match, -1, sizeof(match));
    for (int v = 0; v < V; v++) {
      if (match[v] < 0) {
    memset(used, 0, sizeof(used));
    if (dfs(v)) res++;
      }
    }
    return res;
  }
};
 
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

int main() {
  int m, n;
  int b[500], r[500];
 
  while (1) {
    scanf("%d%d", &m, &n);
    if (m == 0) break;
    for (int i = 0; i < m; i++) scanf("%d", &b[i]);
    for (int i = 0; i < n; i++) scanf("%d", &r[i]);
    twoMatching t(m + n);
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        if (gcd(b[i], r[j]) == 1) continue;
        t.add_edge(i, j + m);
      }
    }
    printf("%d\n", t.bipartite_matching());
  }
}



Measured memory_bytes: 3956
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;
const int INF=1e9;

signed main(){
  int a;
  cin>>a;
  set<int> st;

  for(int i=1;i<1e8;i++){
    st.insert(a);
    if(a%2==0)a/=2;
    else a=a*3+1;
    if(st.count(a)){
      cout<<i+1<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    double r;cin>>r;
    //cout.precision(10);
    //cout<<r*r*M_PI<<" "<<2*r*M_PI<<endl;
    printf("%.7f %.7f\n",r*r*M_PI,2*r*M_PI);
}

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



Measured memory_bytes: 3208
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <cctype>
using namespace std;

#define ALL(c) (c).begin(), (c).end()

typedef pair<int, vector<int> > Result;
vector<int> universal;
vector<int> sets[100];

void print_vector(const vector<int>& v)
{
  for (int i = 0; i < (int)v.size(); ++i) {
    if (i != 0) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

Result parse_atom(const string& str, int k);

Result parse_expr(const string& str, int k)
{
  Result lhs = parse_atom(str, k);
  while (islower(str[lhs.first])) {
    Result rhs = parse_atom(str, lhs.first + 1);
    vector<int> result;
    switch (str[lhs.first]) {
    case 'u':
      set_union(ALL(lhs.second), ALL(rhs.second), back_inserter(result));
      break;
    case 'i':
      set_intersection(ALL(lhs.second), ALL(rhs.second), back_inserter(result));
      break;
    case 'd':
      set_difference(ALL(lhs.second), ALL(rhs.second), back_inserter(result));
      break;
    case 's':
      set_symmetric_difference(ALL(lhs.second), ALL(rhs.second), back_inserter(result));
      break;
    }
    lhs = make_pair(rhs.first, result);
  }
  return lhs;
}

Result parse_atom(const string& str, int k)
{
  if (str[k] == 'c') {
    Result ret = parse_atom(str, k+1);
    vector<int> result;
    set_difference(ALL(universal), ALL(ret.second), back_inserter(result));
    return make_pair(ret.first, result);
  } else if (str[k] == '(') {
    Result ret = parse_expr(str, k+1);
    return make_pair(ret.first+1, ret.second);
  } else {
    return make_pair(k+1, sets[str[k]-'A']);
  }
}

int main()
{
  for (;;) {
    char name;
    int n;
    universal.clear();
    for (int i = 0; i < 100; ++i) {
      sets[i].clear();
    }
    for (;;) {
      if (!(cin >> name >> n)) { return 0; }
      if (name == 'R') { break; }
      for (int i = 0; i < n; ++i) {
        int v; cin >> v;
        sets[name-'A'].push_back(v);
        universal.push_back(v);
      }
      sort(ALL(sets[name-'A']));
    }
    sort(ALL(universal));
    universal.erase(unique(ALL(universal)), universal.end());
    string str; cin >> str;
    vector<int> ret = parse_expr(str + ".", 0).second;
    if (ret.empty()) {
      cout << "NULL" << endl;
    } else {
      print_vector(ret);
    }
  }
}

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

int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i) {
    if (i < k) {
      printf("%c", s[i]);
    } else {
      printf("...\n");
      return 0;
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 3628
package main

import (
        "fmt"
)

func solution(s string) int {
        max := func(x, y int) int {
                if x > y {
                        return x
                }
                return y
        }

        isACGT := func(s string) bool {
                for i := range s {
                        t := s[i]
                        if !(t == 'A' || t == 'C' || t == 'G' || t == 'T') {
                                return false
                        }
                }
                return true
        }

        l := len(s)
        out := 0
        for i := 0; i <= l; i++ {
                for j := i + 1; j <= l; j++ {
                        t := s[i:j]
                        if isACGT(t) {
                                out = max(out, len(t))
                        }
                }
        }
        return out
}

func main() {
        var s string
        fmt.Scan(&s)
        fmt.Println(solution(s))
}

Measured memory_bytes: 1772
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN      
const ll mod=1e9+7;
const int N=1e5+4;

int main()                  
{
	int n,m,x; scn(n); scn(m); scn(x);

	set<pair<int,int>> st;

	map<int,int> ml,mr;

	rep(i,0,x)
	{
		int l,r; scn(l); scn(r);

		ml[l]++; mr[r]++;

		// cout<<l<<" "<<r<<endl;
		
		st.emplace(l,r);
	}

	if(ml.size()==1 or mr.size()==1)
	{
		pri(x); return 0;
	}

	vector<int> vl,vr;

	int mxl=0,mxr=0;

	for(auto it: ml)
	mxl=max(mxl,it.S);

	for(auto it: mr)
	mxr=max(mxr,it.S);

	for(auto it: ml)
	if(it.S==mxl)
	vl.pb(it.F);

	for(auto it: mr)
	if(it.S==mxr)
	vr.pb(it.F);

	int ans=mxl + mxr;

	// cout<<ml.begin()->S<<" "<<mr.begin()->S<<endl;

	int flag=1;

	// cout<<ans<<endl;

	for(int itl: vl)
	{
		for(int itr: vr)
		{
			if(st.find(mp(itl,itr))==st.end())
			{
				flag=0; break;
			}
		}
	}

	// cout<<flag<<endl;

	ans-=flag;

	pri(ans);

    return 0;
}

Measured memory_bytes: 49640
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0; i<N; i++) cin >> d[i];
  int cnt=0;
  for(int i=0; i+2<N; i++){
    if(max(d[i], d[i+2])>d[i+1] && min(d[i], d[i+2])<d[i+1]) cnt++;
  }
  cout << cnt <<endl;
  
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define INF 100000000
int main(){
  int N,pen,kati;
  cin >> N ;
  int ans = INF;
  for(int i=0;i<2;i++){
    cin >> pen >> kati;
    int a = N / pen;
    if(N%pen>=1) a++;
    ans = min(ans,a*kati);
  }
  cout << ans << endl;
}



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

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

  vector<bool> n1(10,false);
  vector<bool> n2(100,false);
  vector<bool> n3(1000,false);
  for(int i=0;i<N;i++){
    int a=S.at(i)-'0';
    for(int j=0;j<100;j++)  if(n2.at(j))  n3.at(10*j+a)=true;
    for(int j=0;j<10;j++) if(n1.at(j))  n2.at(10*j+a)=true;
    n1.at(a)=true;
  }
  int ans=0;
  for(int i=0;i<1000;i++) if(n3.at(i))  ans++;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n, k; cin >> n >> k;
	if (n * 500 >= k) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    t = str(input().rstrip('\n'))
    cnt = 0
    while True:
        if s == t:
            print("Yes")
            exit()
        elif cnt > len(s):
            print("No")
            exit()
        else:
            s = s[-1] + s[:-1]
            cnt += 1


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
// Quoted by @snuke
// https://atcoder.jp/contests/agc037/submissions/6957166

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

int main() {
    string s;
    cin >> s;

    int ans = 0;
    string t, u = "";
    for (int i = 0; i < s.size(); i++) {
        t += s[i];
        if (t == u) continue;
        u = t;
        t = "";
        ++ans;
    }
    cout << ans << endl;
    return 0;
}

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

#define NMAX 100000
#define INF 2000000000

#define MOD 1000000007

using namespace std;

struct Node{
    int label;
    int level;
};

int n, k;
long long ways;
vector<int> tree[NMAX];
queue<int> Q;
bool vis[NMAX];

int main()
{
    cin >> n >> k;
    for(int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    ways = k;
    int currK = k - 1;

    for(int i = 0; i < tree[0].size(); i++)
    {
        ways = (ways * currK) % MOD;
        currK--;
        Q.push(tree[0][i]);
    }
    vis[0] = 1;
    while(!Q.empty())
    {
        int node = Q.front();
        Q.pop();
        currK = k - 2;
        for(int i = 0; i < tree[node].size() && !vis[node]; i++)
        {
            if(!vis[tree[node][i]])
            {
                ways = (ways * currK) % MOD;
                currK--;
                Q.push(tree[node][i]);
            }
        }
        vis[node] = 1;
    }
    cout << ways % MOD << '\n';
    return 0;
}


Measured memory_bytes: 6648
/// Kazuki Hoshino


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define endl '\n'

int a, b;


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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);


cin >> a >> b;

cout << a*b - a - b +1 << endl;










return 0;}
///....


Measured memory_bytes: 256
from string import ascii_lowercase as abc
from itertools import product
def inpl(): return list(map(int, input().split()))

N = int(input())
ans = []
searched = set()
trans = str.maketrans({k: v for k, v in zip(list("0123456789"), list(abc[:10]))})
for X in product(*[range(x) for x in range(1, N+1)]):
    checked = [-1]*10
    res = 0
    i = 0
    for x in X:
        res *= 10
        if checked[x] == -1:
            checked[x] = i
            i+= 1
        res += checked[x]
    if not res in searched:
        searched.add(res)
        ans.append(res)
    
for a in sorted(ans):
    print(str(a).zfill(N).translate(trans))

Measured memory_bytes: 63196
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC omodtimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
typedef complex<long double> com;
 
const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll h,w;
	cin >> h >> w;
	if (h == 1 || w == 1){
		cout << 1 << endl;
	}
	else if ((h * w) & 1) cout << (h*w)/ll(2)+1 << endl;
	else cout << h*w/ll(2) << endl;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;

    int max_len = 0;
    for (int i = 0, l = 0; i < static_cast<int>(s.size()); i++) {
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
            if (max_len < i - l + 1) {
                max_len = i - l + 1;
            }
        } else {
            l = i + 1;
        }
    }

    cout << max_len << endl;
}


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

using namespace std;

typedef long long int ll;
 
template<class T> inline bool chmax(T& a,T b){ if(a<b){ a=b; return true;} return false; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){ a=b; return true;} return false; }
 
typedef pair<int,int> pair;

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

  ll max[]={a*c,a*d,b*c,b*d};
  ll ans=max[0];
  for(int i=1;i<4;i++){
    if(ans<max[i]) ans=max[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
using namespace std;
main(){
  long long K;
  scanf("%lld",&K);
  int L[10][10];
  int a,b;
  for(b=0;b<10;b++)L[0][b]=1;
  for(a=1;a<10;a++){
    L[a][0]=L[a-1][0]+L[a-1][1];
    for(b=1;b<9;b++)L[a][b]=L[a-1][b-1]+L[a-1][b]+L[a-1][b+1];
    L[a][9]=L[a-1][8]+L[a-1][9];
  }
  
  int brk=0;
  long long T=1;
  long long X=0;
  for(a=0;a<10;a++){
    for(b=1;b<10;b++){
      if(K>L[a][b])K-=L[a][b];
      else brk=1;
      if(brk)break;
    }
    if(brk)break;
    T*=10;
  }
  X+=T*b;
  int nb;
  brk=0;
  for(a--;a>=0;a--){
    T/=10;
    for(nb=b-1;nb<b+2;nb++){
      if(nb==-1)continue;
      if(nb==10)continue;
      if(K>L[a][nb])K-=L[a][nb];
      else break;
    }
    b=nb;
    X+=T*b;
  }
  printf("%lld",X);
}

Measured memory_bytes: 256
using System;
class abc122a{
  static void Main(){
    var b = Console.ReadLine();
    var result = "";
    if(b.Equals("A"))result="T";
    if(b.Equals("C"))result="G";
    if(b.Equals("G"))result="C";
    if(b.Equals("T"))result="A";
    
    Console.WriteLine(result);
    return;
  }
}      

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
struct UnionFind
{
  vector<int> Parent;
  UnionFind(int n):Parent(n,-1){}
  int Root(int y){return Parent.at(y)<0?y:Parent.at(y)=Root(Parent.at(y));}
  bool Unite(int x,int y)
  {
    if((x=Root(x))==(y=Root(y)))return true;
    else
    {
      if(-Parent.at(x)<-Parent.at(y))swap(x,y);
      Parent.at(x)+=Parent.at(y);
      Parent.at(y)=x;
      return false;
    }
  }
  int Size(int y){return -Parent.at(Root(y));}
};
int main()
{
  int a,b,c,d,N,M,K;
  cin>>N>>M>>K;
  UnionFind uf(N);
  vector<int> known(N);
  while(M--)
  {
    cin>>a>>b;
    a--,b--;
    uf.Unite(a,b);
    known.at(a)++,known.at(b)++;
  }
  while(K--) 
  {
    cin>>c>>d;
    c--,d--;
    if(uf.Root(c)==uf.Root(d))known.at(c)++,known.at(d)++;
  }
  for(int i=0;i<N;i++)cout<<(uf.Size(i)-known.at(i)-1)<<" ";
  return cout<<endl,0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int n, k, a[N];
ll sum[N];
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> k;
 	for(int i=1; i<=n; i++) 
 	{
 		cin >> a[i];
 		sum[i] = sum[i-1] + a[i];
 	}
 	int l = 1, r = k;
 	ll maxn = 0;
 	while(r<=n)
 	{
 		maxn = max(maxn, sum[r]-sum[l-1]);
 		l++; r++;
 	}
 	double ans = (k+maxn)*0.5;
 	cout << fixed << setprecision(12) << ans;
	return 0;
}


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

vector<int> dp;

int q(int x) {
	if (dp[x]) return dp[x];
	cout << x << endl;
	string s; cin >> s;
	if (s == "Vacant") exit(0);
	if (s == "Male") return dp[x] = -1;
	return dp[x] = 1;
}

bool f(int s, int t) {
	int o = (s - t) & 1;
	if (o) return q(s) == q(t);
	return q(s) != q(t);
}

int main() {
	int N;cin >> N;
	dp.resize(N);
	int s = 0, t = N / 2;
	if (!f(s, t)) swap(s, t);
	for (;;) {
		int m = s > t ? (s+t+N)/2 : (s+t)/2;
		if (m >= N) m -= N;
		if (f(s, m)) t = m;
		else s = m;
	}
}

Measured memory_bytes: 1236
#include "bits/stdc++.h"
using namespace std;

class Cube{
public:
	int f[6];
	Cube(){}
		void roll_z(){roll(1,2,4,3);}
		void roll_y(){roll(0,2,5,3);}//to W
		void roll_x(){roll(0,1,5,4);}//to N
		void roll(int i,int j,int k, int l){
			int t=f[i];f[i]=f[j];f[j]=f[k];f[k]=f[l];f[l]=t;
		}
		void move(char ch){
			if(ch=='E')for (int i = 0; i < 3; ++i) {roll_y();}
			if(ch=='W')roll_y();
			if(ch=='N')roll_x();
			if(ch=='S')for (int i = 0; i < 3; ++i) {roll_x();}
		}
};
bool eq(Cube c1,Cube c2){
	for (int i = 0; i < 6; ++i) {
		if (c1.f[i] != c2.f[i]) {return false;}
	}return true;
}

bool equal(Cube c1,Cube c2){
	for (int i = 0; i < 6; ++i) {
		for (int j = 0; j < 4; ++j) {
			if (eq(c1,c2)) return true;
						c1.roll_z();
		}
		if (i%2==0) {c1.roll_y();}
		else{c1.roll_x();}
	}
	return false;
}


int main() {
	int n;
	cin>>n;
	Cube c[n];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 6; ++j){
			cin>>c[i].f[j];
		}
	}
	for (int i = 0; i < n-1; ++i) {
		for (int j = i+1; j < n; ++j) {
			if (equal(c[i],c[j])){cout<<"No"<<endl;return 0;}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}



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

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;

	vector<int> cards;
	int card;
	for (int i = 0; i < N; i++) {
		cin >> card;
		cards.push_back(card);
	}

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

	int alice = 0;
	int bob = 0;
	for (int j = 0; j < cards.size(); j++) {
		int score = *(cards.end() - j - 1);
		if (j % 2 == 0) {
			alice += score;
		} else {
			bob += score;
		}
	}

	cout << alice - bob << endl;
	return 0;
}


Measured memory_bytes: 384
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef DEBUG_MODE

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 100005
#define MAX_M 5005
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
int boss[MAX_N];
int counts[MAX_N];
void init() {
	for (int i = 0; i < MAX_N; i++) boss[i] = i, counts[i] = 1;
}
int find(int x) {
	return boss[x] = (boss[x] == x ? x : find(boss[x]));
}
int64_t unite(int x, int y) {
	int bx = find(x);
	int by = find(y);
	if (bx == by) return 0LL;
	int64_t res = counts[bx] * counts[by];
	counts[bx] += counts[by];
	boss[by] = bx;
	return res;
}
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");

	init();
	int N, M;
	scanf("%d %d", &N, &M);
	int A[MAX_N], B[MAX_N];
	for (int i = 0; i < M; i++) scanf("%d %d", A + i, B + i);
	vector <int64_t> res;
	int64_t total = 1LL * N * (N - 1LL) >> 1;
	res.push_back(total);
	for (int i = M - 1; i > 0; i--) {
		int64_t remain = unite(A[i], B[i]);
		total -= remain;
		res.push_back(total);
	}
	reverse(res.begin(), res.end());
	for (int64_t num : res) {
		printf("%lld\n", num);
	}
	return 0;
}

Measured memory_bytes: 3828
import sys
from heapq import nlargest

sys.setrecursionlimit(10000)


def first_dfs(v, p, stones, dists, costs):
    stone = s[v]
    dist = 0
    cost = 0
    children_dists = []
    for u in links[v]:
        if u == p:
            continue
        us, ud, uc = first_dfs(u, v, stones, dists, costs)
        stone += us
        dist += us + ud
        cost += uc
        children_dists.append((us + ud, uc))
    # print(v, p, stone, dist, cost, children_dists)
    if len(children_dists) > 1:
        md, mc = max(children_dists)
        if dist - md < md - mc * 2:
            cost = dist - md + mc
        else:
            cost = dist // 2
        # print(v, p, md, hd, dist, cost)
    stones[v] = stone
    dists[v] = dist
    costs[v] = cost
    return stone, dist, cost


def second_dfs(v, p, pd, pc):
    children_dists = []
    dist = 0

    for u in links[v]:
        if u == p:
            dist += pd
            children_dists.append((pd, pc))
            continue
        ud = stones[u] + dists[u]
        uc = costs[u]
        dist += ud
        children_dists.append((ud, uc))
    # print(v, p, pd, pc, dist, children_dists)

    # only when source and leaf node
    if len(children_dists) == 1:
        u = next(iter(links[v]))
        return second_dfs(u, v, s[v], 0)

    (md1, mc1), (md2, mc2) = nlargest(2, children_dists)
    ret = INF

    hd, m = divmod(dist, 2)
    # print(' ', hd, m, md1, mc1, dist - md1, md1 - mc1 * 2)
    if m == 0 and dist - md1 >= md1 - mc1 * 2:
        ret = min(ret, hd)

    for u in links[v]:
        if u == p:
            continue
        us = stones[u]
        ud = dists[u]
        uc = costs[u]

        # dist=0 node cannot be a center
        if ud == 0:
            continue
        usd = us + ud
        if usd == md1 and uc == mc1:
            md, mc = md2, mc2
        else:
            md, mc = md1, mc1
        td = dist - usd
        if td - md < md - mc * 2:
            vc = td - md + mc
        else:
            vc = td // 2
        result = second_dfs(u, v, td + (all_stones - us), vc)
        ret = min(ret, result)

    return ret


n = int(input())
s = list(map(int, input()))
links = [set() for _ in [0] * n]
for line in sys.stdin:
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)
all_stones = sum(s)
if all_stones == 1:
    print(0)
    exit()
stones = [0] * n  # 1を根とした木の、頂点vの部分木以下（自身含む）にある石の数
dists = [0] * n  # 頂点vの部分木以下にある石 x それぞれのvとの距離 の和
costs = [0] * n  # 頂点v以下の石同士で、最大限頂点vに近づけておくためにできる操作の数
first_dfs(0, -1, stones, dists, costs)
# print(stones)
# print(dists)
# print(costs)
INF = 10 ** 10
ret = second_dfs(0, -1, 0, 0)
print(-1 if ret == INF else ret)


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


int main(){
    string s;cin>>s;
    ll bc = 0;
    ll ans = 0;
    int n = s.size();
    rep(i,s.size()){
        if(s[i]=='B') bc++;
        else ans+=bc;


    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3724
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
m = 10**19
idx = 0
for i in range(n):
    d = t - h[i]*0.006
    if abs(a-d) < m:
        m = abs(a-d)
        idx = i+1
print(idx)


Measured memory_bytes: 9180
#include<bits/stdc++.h>
#define rint register int 
#define ll long long 
using namespace std;
int N,vis[1010000],gg[1010000];
ll prime[1010010],cnt,A[1000010],rev[1010000],cur[1000100];
unordered_map<ll,int> mp,iscube;
inline ll ksm(ll x,ll y){
	ll res=1;
	for(rint i=1;i<=y;++i) res=res*x;
	return res;
} 
inline void Init(){
	vis[1]=1;
	for(rint i=2;i<=4000;++i) {
		if(!vis[i]) prime[++cnt]=i;
		for(rint j=1;j<=cnt&&i*prime[j]<=4000;++j) {
			vis[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
	for(rint i=1;i<=4000;++i)  {
		ll tmp=1ll*i*i*i;
		iscube[tmp]=1;
	}
}

int main(){
	cin>>N;
	for(rint i=1;i<=N;++i) cin>>A[i];
	Init();
	int ans=0;
	for(rint i=1;i<=N;++i) {
		ll tmp=A[i];
		if(iscube[tmp]) {ans=1;continue;}
		rev[i]=1,cur[i]=1;
		for(rint j=1;j<=cnt;++j) {
			int tot=0;
			while(tmp%prime[j]==0) tmp/=prime[j],++tot;
			tot%=3;
			cur[i]=cur[i]*ksm(prime[j],tot);
			rev[i]=rev[i]*ksm(prime[j],(3-tot)%3);
		}
		if(tmp==1) {
			gg[i]=1;
			mp[cur[i]]++;
			continue;
		}
		else {
			ll t=sqrt(tmp);
			if(t*t==tmp) {
				gg[i]=1;
				cur[i]*=tmp;
				rev[i]*=t;
				mp[cur[i]]++;
			}
			else {
				cur[i]*=tmp;
				mp[cur[i]]++;
			}
		}
		//cout<<A[i]<<" "<<cur[i]<<" "<<rev[i]<<endl;
	}
	for(rint i=1;i<=N;++i) {
		if(iscube[A[i]]) {continue;}
		if(gg[i]) {
			ans+=max(mp[rev[i]],mp[cur[i]]);
			mp[rev[i]]=mp[cur[i]]=0;
		}
	}
	for(rint i=1;i<=N;++i) {
		if(!gg[i]) {
			ans+=mp[cur[i]];
			mp[cur[i]]=0;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 17204
// Problem :
// 			B - Making Triangle
//
//
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define tos(x) string(1, x)
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testc   \
    int tcc;    \
    cin >> tcc; \
    for (int tc = 1; tc <= tcc; tc++)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//#define int ll

signed main() {
    fast_io;
    int n;
    cin >> n;
    vi v(n);
    in(v);
    int cnt=0;
    sort(all(v));
    lp(i, 0, n) {
        lp(j, i+1, n) {
            lp(k, j+1, n) {
                if (v[i] + v[j] > v[k] && v[i] + v[k] > v[j] &&
                    v[j] + v[k] > v[i]) {
                    	if(v[i]!=v[j] && v[j]!=v[k] && v[k]!=v[i]){
                    		cnt++;
                    	}
                }
            }
        }
    }
    cout << cnt;
}
// code!=think
// least efficient code to get ac


Measured memory_bytes: 3656
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    string t,p;cin>>t>>p;
    for(int i=0;i<t.length();i++){
        if(i+p.length()>t.length())break;
        string tmp=t.substr(i,p.length());
        if(tmp==p)cout<<i<<endl;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------















































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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

struct Item {
    int value, weight;
};

int main() {

    int n, w;
    cin >> n >> w;

    vector<Item> items(n);
    rep(i, n)cin >> items[i].value >> items[i].weight;

    vector<vector<int>> dp(n + 1, vector<int>(w + 1, INT_MIN));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= w; j++) {
            if (dp[i][j] == INT_MIN) continue;
            {
                // 入れない
                cmax(dp[i + 1][j], dp[i][j]);
            }
            {
                // 入れる
                int next = j + items[i].weight;
                int now = dp[i][j];
                int next_value = now + items[i].value;
                if (next <= w) {
                    cmax(dp[i + 1][next], next_value);
                }
            }
        }
    }

    int ans = 0;
    for (int v : dp[n]) cmax(ans, v);
    cout << ans << endl;

}




Measured memory_bytes: 6832
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

int ssum[2][101010], tsum[2][101010];
int main() {
	string s, t;
	cin >> s >> t;
	rep(i, 0, s.size()) {
		ssum[s[i] - 'A'][i + 1] += ssum[s[i] - 'A'][i] + 1;
		ssum[!(s[i] - 'A')][i + 1] = ssum[!(s[i] - 'A')][i];
	}
	rep(i, 0, t.size()) {
		tsum[t[i] - 'A'][i + 1] += tsum[t[i] - 'A'][i] + 1;
		tsum[!(t[i] - 'A')][i + 1] = tsum[!(t[i] - 'A')][i];
	}
	int q;
	cin >> q;
	rep(i, 0, q) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--, b--, c--, d--;
		string s1, s2;
		int diff1 = (ssum[1][b + 1] - ssum[1][a]) - (ssum[0][b + 1] - ssum[0][a]);
		if(diff1 > 0) {
			if (diff1 % 3 == 0)s1 = "";
			else if (diff1 % 3 == 1)s1 = "B";
			else s1 = "A";
		}
		else if (diff1 == 0) {
			s1 = "";
		}
		else {
			if (-diff1 % 3 == 0)s1 = "";
			else if (-diff1 % 3 == 1)s1 = "A";
			else s1 = "B";
		}
		int diff2 = (tsum[1][d + 1] - tsum[1][c]) - (tsum[0][d + 1] - tsum[0][c]);
		if (diff2 > 0) {
			if (diff2 % 3 == 0)s2 = "";
			else if (diff2 % 3 == 1)s2 = "B";
			else s2 = "A";
		}
		else if (diff2 == 0) {
			s2 = "";
		}
		else {
			if (-diff2 % 3 == 0)s2 = "";
			else if (-diff2 % 3 == 1)s2 = "A";
			else s2 = "B";
		}
		if (s1 == s2)puts("YES");
		else puts("NO");
	}
	return 0;
}


Measured memory_bytes: 2432
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<map>

template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }
#include <cstdint>
#include <iostream>

template <std::uint_fast64_t Modulus = 1000000007ULL> class Modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr Modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr Modint operator+(const Modint rhs) const noexcept { return Modint(*this) += rhs; }
  constexpr Modint operator-(const Modint rhs) const noexcept { return Modint(*this) -= rhs; }
  constexpr Modint operator*(const Modint rhs) const noexcept { return Modint(*this) *= rhs; }
  constexpr Modint operator/(const Modint rhs) const noexcept { return Modint(*this) /= rhs; }
  constexpr Modint &operator+=(const Modint rhs) noexcept {
    a += rhs.a; if (a >= Modulus) a -= Modulus;
    return *this;
  }
  constexpr Modint &operator-=(const Modint rhs) noexcept {
    if (a < rhs.a) { a += Modulus; } a -= rhs.a;
    return *this;
  }
  constexpr Modint &operator*=(const Modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr Modint &operator/=(Modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) *this *= rhs;
      rhs *= rhs; exp /= 2;
    }
    return *this;
  }
  Modint pow(u64 exp) {
    Modint<> ret = 1, x = this->a;
    while(exp > 0) {
        if (exp & 1) ret *= x;
        x *= x; exp >>= 1;
    }
    return ret;
  }
};

template <std::uint_fast64_t Modulus> std::ostream& operator<<(std::ostream& os, const Modint<Modulus>& obj) { os << obj.value(); return os; }
template <std::uint_fast64_t Modulus> std::istream& operator>>(std::istream& is, Modint<Modulus>& obj) { std::uint_fast64_t a; is >> a; obj = Modint<Modulus>(a); return is; }

using namespace std;
using ll = long long;
int n;
ll k;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    Modint<> ans = 0;
    // D(k);
    REP(i, n) {
        Modint<> total = 0;
        Modint<> back = 0;
        REP(j, n) {
            if (a[j] < a[i]) total += 1;
            if (a[j] < a[i] && j > i) back += 1;
        }
        // DDD(i, total, back);
        ans += back * k + total * k * (k - 1) / 2;
    }
    cout << ans << endl;

}


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

int main(){
    ll A,B,C; cin >> A >> B >> C;
    ll ans;
    if((A*B*C)%2==0) ans=0;
    else{
        ans=min({A*B,B*C,C*A});
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

set<ll> ans;

void fact(ll n) {
  for (ll x = 1; x * x <= n; x++) {
    if (n % x == 0) {
      ans.insert(x);
      ans.insert(n / x);
    }
  }
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  ll n; cin >> n;
  fact(n - 1);
  ans.insert(n);
  for (ll x = 2; x * x <= n; x++) {
    ll y = n;
    while (y % x == 0) y /= x;
    y %= x;
    if (y % x == 1) {
      ans.insert(x);
    }
  }
  ans.erase(1);
  cout << ans.size() << endl;

  return 0;
}


Measured memory_bytes: 256
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = gets.chomp.to_i
puts a[k-1]

Measured memory_bytes: 1788
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

fn main() {
    input! {
        n:usize,k:usize,
        a:[usize;n]
    }
    let mut ok = 9999999999_usize;
    let mut ng = 0;

    while ok - ng > 1 {
        let mid = (ok + ng) / 2;
        let mut l = 0;
        for &i in &a {
            l += (i - 1) / mid;
        }
        if l <= k {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    println!("{}", ok);
}


Measured memory_bytes: 5408
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=2e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();	
 	
 	int n;

 	cin>>n;
 	map<string,int>occ;
 	for(int i=0;i<n;i++){
 		string a;
 		cin>>a;
 		occ[a]++;
 	}
 	int mx = 0;
 	set<string>s;
 	for(auto a : occ){
 		if(a.second > mx){
 			s.clear();
 			s.insert(a.first);
 			mx = a.second;
 		}
 		else if(a.second == mx){
 			s.insert(a.first);
 		}
 	}

 	for(auto a : s)cout<<a<<endl;
}		


Measured memory_bytes: 33280
from collections import deque

N, M = map(int, input().split())
g = [[int(i) for i in input().split()] for j in range(M)]

G = [[] for i in range(N)]
for i in range(M):
    a, b = g[i]
    G[a-1].append(b-1)
    G[b-1].append(a-1)

marks = [-1 for i in range(N)]
node = deque([[0, 0]])
while len(node) > 0:
    v = node.popleft()
    if marks[v[0]] == -1:
        marks[v[0]] = v[1]
        for i in G[v[0]]:
            if marks[i] == -1:
                node.append([i, v[0]])

if -1 not in marks:
    print("Yes")
    for i in range(1, N):
        print(marks[i]+1)
else:
    print("No")

Measured memory_bytes: 71916
N,K,C = map(int,input().split())
S = input()
def solve():
    l = []
    y = 0
    for i,c in enumerate(S):
        if y:
            y -= 1
            continue
        if c=='o':
            y = C
            l.append(i+1)
            if len(l) == K:
                break
    r = []
    y = 0
    for i,c in enumerate(S[::-1]):
        if y:
            y -= 1
            continue
        if c=='o':
            y = C
            r.append(N-i)
            if len(r) == K:
                break
    r.reverse()
    ans = [a for a,b in zip(l,r) if a==b]
    print(*ans, sep='\n')
solve()

Measured memory_bytes: 25564
n = int(input())
c = [int(input())]
last = [-1 for _ in range(2 * (10 ** 5) + 1)]
for i in range(1, n):
    _c = int(input())
    if _c != c[-1]:  # 連続同数字は1つに連結
        c.append(_c)
# print(c)
out = [0 for _ in range(len(c))]
out[0] = 1
last[c[0]] = 0
for i in range(1, len(c)):
    out[i] = out[i-1]
    if last[c[i]] >= 0:
        # print(out[last[c[i]]])
        out[i] += out[last[c[i]]]
        out[i] %= 10 ** 9 + 7
    last[c[i]] = i
    # print("out:{}".format(out))
    # print("last:{}\n".format(last[:10]))
print(out[-1] % (10 ** 9 + 7))

Measured memory_bytes: 20532
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll i, j, k, l, n, m;
    string s;
    cin >> s;
    ll sz = s.size();
    if(s[sz-1]=='s')
        cout << s << "es\n";
    else
        cout << s << "s\n";
    return 0;
}

Measured memory_bytes: 3616