akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define maxn 16
#define maxbm (1<<maxn)
#define pb push_back
using namespace std;
typedef long long LL;

int n;
LL dp[maxbm];
LL sum[maxbm];
int a[maxn][maxn];
vector<int> nextGroups[maxbm];

void input() {
	scanf("%d",&n);
	for( int i = 0 ; i < n ; i++ )
		for( int j = 0 ; j < n ; j++ )
			scanf("%d",&a[i][j]);
}

void findNextGroups(int bmask, int id, int curr, vector<int>& v) {
	if(id == (int) v.size()) {
		if(curr != 0)
			nextGroups[bmask].pb(curr);
		return;
	}
	findNextGroups(bmask, id+1, curr, v);
	findNextGroups(bmask, id+1, curr | (1 << v[id]), v);
}

void calcGroups() {
	for( int bm = 0 ; bm < (1<<n) ; bm++ ) {
		vector<int> v1, v0;
		for( int i = 0 ; i < n ; i++ )
			if( bm & (1<<i) )
				v1.pb(i);
			else
				v0.pb(i);
		for( int i = 0 ; i < (int) v1.size() ; i++ )
			for( int j = i+1 ; j < (int) v1.size() ; j++ )
				sum[bm] += a[v1[i]][v1[j]];
		findNextGroups(bm, 0, 0, v0);
	}
}

LL f(int bmask) {
	if(bmask == (1<<n)-1)
		return 0;
	if(dp[bmask] != -1)
		return dp[bmask];
	dp[bmask] = 0;
	for( int i = 0 ; i < (int) nextGroups[bmask].size() ; i++ ) {
		int nextGroup = nextGroups[bmask][i];
		dp[bmask] = max( dp[bmask] , f(bmask | nextGroup) + sum[nextGroup] );
	}
	return dp[bmask];
}

void solve() {
	memset(dp, -1, sizeof(dp));
	printf("%lld\n",f(0));
}

int main() {
	input();
	calcGroups();
	solve();
	return 0;
}


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

int main(){
	int n, q, query, x, t;
	
	cin>>n>>q;
	
	
	vector<vector<int>> vec(n);
	
	for(int i = 0; i < q; i++){
		cin>>query>>t;
		
		if(query == 0){
			cin>>x;
			vec[t].push_back(x);
		} else if(query == 1){
			bool flag = false;
			for(int y : vec[t]) cout<<(flag++?" ":"")<<y;cout<<endl;
		} else {
			vec[t].clear();
		}
	}
	
	
	return 0;
}


Measured memory_bytes: 5828
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw				"\n"
int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	cin>>n;
	while(m<=n)
		m*=2;
	cout<<m-1;
}


Measured memory_bytes: 3628
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

int main() {
    int N;
    cin >> N;
    N *= -1;
    while (N < 0) N += 1000;
    cout << N << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
// HFUU-QerM  
// 00:09:24
ll CEIL(ll a,ll b)
{
    // 返回a/b并向上取整。
    ll res=a/b;
    if(a%b)
    {
        res++;
    }
    return res;
}
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    gbtb;
    ll a,b;
    ll n;
    cin>>n;
    cin>>a>>b;
    n--;
    ll x,y;
    repd(i,1,n)
    {
        cin>>x>>y;
        ll num=max(CEIL(a,x),CEIL(b,y));
        a=num*x;
        b=num*y;
    }
    cout<<a+b<<endl;
    
    
    
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}

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

int main(){
    cin >> n;
    vector<ll> v;
    for (int i = 1; i <= n; i++){
        ll x;
        cin >> x;
        if (x%2 == 0) v.push_back(x);
    }
    if (v.size() == 0) cout << 0; 
    else{
        ll ans = 0;
        for (int i = 0; i <v.size(); i++){
            while (v[i]%2 == 0){
                ans++;
                v[i] /= 2;
            }
        }
        cout << ans;
    }
}

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

char in[120];
pair<pair<string, int>, int> p[110];
int main(){
  int a; cin >> a;
  for(int i=0; i<a; i++){
	int t; cin >> in >> t;
    string tmp=in;
	p[i] = make_pair(make_pair(in, -t),i);
  }
  sort(p,p+a);
  for(int i=0; i<a; i++) cout << p[i].second+1 << endl;

  return 0;

}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, k = LI()
p = LI()
c = LI()
C = []
S = []
for i in range(n):
    lst = [-1]*n
    cnt = 0
    idx = i
    s = 0
    while lst[idx] == -1:
        lst[idx] = cnt
        s += c[idx]
        cnt += 1
        idx = p[idx] - 1
    C.append(cnt)
    S.append(s)

if n >= k:
    ans = -10**10
    for i in range(n):
        cnt = 0
        ret = 0
        idx = p[i]
        while cnt < k:
            ret += c[idx-1]
            idx = p[idx-1]
            cnt += 1
            ans = max(ans, ret)
    print(ans)
else:
    ans = -10**10
    for i in range(n):
        if S[i] > 0:
            tmp = S[i] * (k // C[i])
            r = k % C[i]
            cnt = 0
            ret = 0
            idx = p[i]
            if r == 0:
                tmp -= S[i]
                r = C[i]
            while cnt < r:
                ret += c[idx-1]
                idx = p[idx-1]
                cnt += 1
                ans = max(ans, tmp + ret)
        else:
            cnt = 0
            ret = 0
            idx = p[i]
            while cnt < n:
                ret += c[idx-1]
                idx = p[idx-1]
                cnt += 1
                ans = max(ans, ret)
    print(ans)

Measured memory_bytes: 70680
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int>> g(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    g.at(a).push_back(b);
    g.at(b).push_back(a);
  }
  for(int i=0;i<n;i++)
    cout<<g.at(i).size()<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;
//abc168

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int k;
    cin>>k;
    string s;
    cin>>s;
    if(s.size()<=k) cout<<s<<endl;
    else{
        rep(i,k) cout<<s[i];
        cout<<"..."<<endl;
    }
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

Measured memory_bytes: 3648
#include <stdio.h>
int n,A[50];

int solve(int i,int m){
  if(m == 0)
    return 1;
  if(i >= n)
    return 0;
  int res = solve(i + 1,m) || solve(i + 1,m - A[i]);
  return res;
}

int main(){
  int q,M,i;
  scanf("%d",&n);
  for(i = 0;i < n;i++)
    scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&M);
    if(solve(0,M))
      printf("yes\n");
    else printf("no\n");
  }

  return 0;
}


Measured memory_bytes: 2108
n = int(input())
A = list(map(int,input().split()))
if n%2==0:
    ans1=A[0];ans2=A[1]
    for i in range((n-2)//2):
        ans2 = max(ans1,ans2)+A[(i+1)*2+1]
        ans1 = ans1++A[(i+1)*2]
    print(max([ans1,ans2]))

else:
    ans1,ans2,ans3,=A[0],A[1],A[2]
    for i in range((n-2)//2):
        ans3 = max(ans3,ans2) + A[(i+2)*2]
        ans2 = max(ans1,ans2) + A[(i+2)*2-1]
        ans1 = ans1 + A[(i+1)*2]
    print(max([ans1,ans2,ans3]))

Measured memory_bytes: 31168
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    ll a,b;
    cin>>a>>b;
    if(a<=0 && b>=0) cout<<"Zero"<<endl;
    else if(a>0) cout<<"Positive"<<endl;
    else if(b<0){
        if(abs(a-b)%2==0) cout<<"Negative"<<endl;
        else cout<<"Positive"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <numeric>
#include <utility>
#include <ctime>
#include <iomanip>
#include <cassert>

using namespace std;

const int S = 100005;
const long long MAX = 1000000000000000LL;

struct edge{
    int to;
    int a;
    int b;
    edge() {
        
    }
    edge(int to, int a, int b):
    to(to), a(a), b(b) { }
};

int N, M;
int f, s;
long long snuuk[S], yen[S];
long long result[S];
vector<edge> v[S];

void bfs1(int node) {
    for (int i = 1; i <= N; i ++) yen[i] = MAX;
    yen[node] = 0;
    queue<int> Q;
    Q.push(node);
    while (!Q.empty()) {
        int current = Q.front();
        Q.pop();
        for (auto e: v[current]) {
            if (yen[e.to] > yen[current] + e.a) {
                yen[e.to] = yen[current] + e.a;
                Q.push(e.to);
            }
        }
    }
}
void bfs2(int node) {
    for (int i = 1; i <= N; i ++) snuuk[i] = MAX;
    snuuk[node] = 0;
    queue<int> Q;
    Q.push(node);
    while (!Q.empty()) {
        int current = Q.front();
        Q.pop();
        for (auto e: v[current]) {
            if (snuuk[e.to] > snuuk[current] + e.b) {
                snuuk[e.to] = snuuk[current] + e.b;
                Q.push(e.to);
            }
        }
    }
}

int main() {
    cin >> N >> M;
    cin >> f >> s;
    for (int i = 1; i <= M; i ++) {
        int from, to, a, b;
        cin >> from >> to >> a >> b;
        v[from].push_back(edge(to, a, b));
        v[to].push_back(edge(from, a, b));
    }
    bfs1(f);
    bfs2(s);
    
//    cout << "using yens: " << endl;
//    for (int i = 1; i <= N; i ++) {
//        cout << i << " --> " << yen[i] << endl;
//    }
//    cout << endl;
//    cout << "using snuuks: " << endl;
//    for (int i = 1; i <= N; i ++) {
//        cout << i << " --> " << snuuk[i] << endl;
//    }
//    cout << endl;
    
    long long best = MAX;
    for (int i = N; i > 0; i --) {
        best = min(best, snuuk[i] + yen[i]);
        result[i] = best;
    }
    for (int i = 1; i <= N; i ++) {
        cout << MAX - result[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 10752
/* In the name of Allah */
#include <bits/stdc++.h>
using namespace std;

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define Size(x) ((int)(x).size())
#define Precision(i) cout << fixed << setprecision(i)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

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

	int n, a, b;
	cin >> n >> a >> b;
	if((a - b) % 2)
		cout << "Borys\n";
	else
		cout << "Alice\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int X; cin >> X;
    constexpr int S = 7;
    vector<bool> md(X); 
    int ans = 1;
    int cnt = 0;
    while(true) {
        cnt = cnt * 10 + S;
        cnt %= X;
        if (cnt == 0) {
            OUT(ans)
            break;
        }
        if (md[cnt]) {
            OUT(-1)
            break;
        }
        md[cnt] = true;
        ans++;
    }

    return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long N; cin >> N;
    vector<long long> div(10000001,1);

    for(long long i=2; i<10000001; i++){
        
        long long cnt = i;
        while(cnt < 10000001){
            div.at(cnt)++;
            cnt += i;
        }
        
    }

    long long ans = 0;
    for(long long i=1; i<=N; i++){
        ans += i*div.at(i);
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 81396
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)

while 1:
    try:
        a,b=map(int,raw_input().split())
        print gcd(a,b),lcm(a,b)
    except:
        break

Measured memory_bytes: 6256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
using namespace std;

int main(){
  long long n;
  cin >> n;
  long long sum = 0;
  for(long long i = 1; i <= n; i++){
    sum += i;
    if(sum >= n){
      cout << i << endl;
      return 0;
    }
  }

  return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<string> input(int n) {
    vector<string> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<string> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i];
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table.at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n, r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b) {
    if (a % b == 0) {
        return(b);
    }
    else {
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool isprime(int n) {
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}
void sayYes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
void sayYES(bool f) {
    if (f) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
    int n, l;
    cin >> n >> l;
    vector<string> s = input(n);
    sort(s.begin(), s.end());
    output(s);
}

Measured memory_bytes: 256
from collections import Counter


def main():
    n = int(input())
    a = input()
    b = input()
    c = input()

    cnt = 0
    for es in zip(a, b, c):
        ec = Counter(es)
        l = len(ec)
        if l == 3:
            cnt += 2
        elif l == 2:
            cnt += 1

    print(cnt)


if __name__ == "__main__":
    main()


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

typedef long long ll;

int main()
{
    string s;
    cin >> s;
    deque<char> deq;
    int i,q;
    cin >> q;
    for(i = 0;i < s.size();++i){
        deq.push_back(s.at(i));
    }
    bool flag = true;   
    for(i = 0;i < q;++i){
        int t;
        cin >> t;
        if(t == 1){
            if(flag){
                flag = false;
            }else{
                flag = true;
            }
            continue;
        }
        int f;
        char c;
        cin >> f >> c;
        if(flag){
            if(f == 1){
                deq.push_front(c);
            }else{
                deq.push_back(c);
            }
        }else{
            if(f == 2){
                deq.push_front(c);
            }else{
                deq.push_back(c);
            }
        }
    }
    if(flag){
        while(!deq.empty()){
            cout << deq.front();
            deq.pop_front();
        }
        cout << endl;
    }else{
        while(!deq.empty()){
            cout << deq.back();
            deq.pop_back();
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9+7;
const ll inf_l = 1e18;
const int MAX = 1e6;

int main() {
    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];
    map<ll,int> mp;
    vll sum(n+1,0);
    rep(i,n) sum[i+1] = sum[i] + a[i];
    rep(i,n+1) mp[sum[i]]++;
    ll ans = 0;
    for (P p : mp) {
        ans += (ll)p.second*(p.second-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15104
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// }}}
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;

/// --- math {{{ ///
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll d;
  return b == 0 ? (x = 1, y = 0, a)
    : (d = extgcd(b, a % b, y, x), y -= a / b * x, d);
}
ll modinv(ll a, ll mod = (ll) 1e9 + 7) {
  ll x, y;
  extgcd(a, mod, x, y);
  if(x < 0) x += mod;
  return x;
}
ll modpow(ll a, ll b, ll mod = (ll) 1e9 + 7) {
  ll r = 1;
  a %= mod;
  while(b) {
    if(b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}
/// }}}--- ///


int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, m;
  cin >> n >> m;
  string s, t; cin >> s >> t;
  ll ans = lcm(n, m);
  for(int i = 0; i < n; i++) { 
    ll j = i * (ans / n);
    if(j % (ans / m) == 0) {
      ll x = j / (ans / m);
      if(s[i] != t[x]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], t;

void dfs_visit(int i)
{
   int j;

   color[i] = GRAY;
   d[i] = ++t;
 for (j=0; j<n; j++){
      if (M[i][j]==0)
         continue;
      if (color[j]==WHITE)
         dfs_visit(j);
   }
color[i] = BLACK;
   f[i] = ++t;
}

void dfs()
{
   int i;

   for (i=0; i<n; i++)
      color[i] = WHITE;
   t = 0;
   for (i=0; i<n; i++){
      if (color[i]==WHITE)
         dfs_visit(i);
   }

   for (i=0; i<n; i++)
      printf("%d %d %d\n", i+1, d[i], f[i]);
}

int main()
{
   int u, v, k, i, j;

   scanf("%d", &n);
   for (i=0; i<n; i++){
      for (j=0; j<n; j++)
         M[i][j] = 0;
   }

   for(i=0; i<n; i++){
      scanf("%d %d",  &u, &k);
      u--;
for(j=0; j<k; j++){
         scanf("%d", &v);
         v--;
         M[u][v] = 1;
      }
   }

   dfs();
   return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  ll res = 0;
  ll tmp = 0;
  cin >> n;
  rep(i, n) {
    char c;
    cin >> c;
    if (c == 'I') {
      tmp++;
    } else {
      tmp--;
    }
    if (tmp > res) res = tmp;
  }
  cout << res << endl;
}

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

int main(){
	int a,b,c,d,e,t;
	t=0;
	cin>>a>>b>>c>>d>>e;
	if(a<=0) b++;
	while(a<b){
		if(a<0){
			t+=c;
			a++;
		}
		else if(a==0){
			t+=d;
			a++;
		}
		else if(a>0){
			t+=e;
			a++;
		}
	}
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 3068
import java.util.*;
class Main{
	public static void main(String ags[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		int[] count = new int[n];
		Map<String, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++){
			s[i] = sc.next();
			if (map.containsKey(s[i])){
				int value = map.get(s[i]);
				value++;
				map.put(s[i],value);
			} else {
				map.put(s[i], 1);
			}
		}
		int maxvalue = Collections.max(map.values()); 
		List<String> list = new ArrayList<>();
		for (Map.Entry<String, Integer> m : map.entrySet()){
			if (m.getValue() == maxvalue){
				list.add(m.getKey());
				//~ map.remove(s[i]);
			}
		}
		Collections.sort(list);
		for (int i = 0; i < list.size(); i++)
			System.out.println(list.get(i));
	}
}


Measured memory_bytes: 84536
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(ll i = 1;i <=  n; i++)
#define rreq(i,n) for(ll i = n;i >= 1;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MOD = 1000000007;
int main(void) {
    int n, m;
    while (cin >> n >> m, n, m) {
        vector<vector<int>> dp1(m, vector<int>(m,MOD)), dp2(m, vector<int>(m, MOD));
        rep(i, n) {
            int a, b, c, t; cin >> a >> b >> c >> t; a--; b--;
            dp1[a][b] = c; dp2[a][b] = t;
            dp1[b][a] = c; dp2[b][a] = t;
        }rep(i, m) rep(j, m) rep(k, m) dp1[j][k] = min(dp1[j][k], dp1[j][i] + dp1[i][k]);
        rep(i, m) rep(j, m) rep(k, m) dp2[j][k] = min(dp2[j][k], dp2[j][i] + dp2[i][k]);
        int k; cin >> k;
        rep(i, k) {
            int a, b, r; cin >> a >> b >> r; a--; b--;
            if (r == 0) {
                cout << dp1[a][b] << endl;
            }
            else {
                cout << dp2[a][b] << endl;
            }
        }
    }
}


Measured memory_bytes: 3176
N, T=map(int,input().strip().split(' '))

ct=[]
for i in range(N):
    ct.append(list(map(int, input().strip().split(' '))))
    
tle=True
c=100000000

for i in range(N):
    if ct[i][1]<=T:
        tle=False
        c=min(c,ct[i][0])
        
if tle:
    print('TLE')
else:
    print(c)

Measured memory_bytes: 3064
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
   



int main(){
   IOS

   char c; cin>>c;
   if(c >= 'a' && c <= 'z')cout<<"a\n";
   else cout<<"A\n";

   







}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
   if(b&1) res = res * a % mod;
        a = a * a % mod;
   b >>= 1;
    }

    return res;
}



Measured memory_bytes: 3616
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("parse error")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        xyz: [(usize1, usize1, usize); m]
    }
    let mut graph = vec![vec![]; n];
    for &(x, y, _) in &xyz {
        graph[x].push(y);
        graph[y].push(x);
    }
    let mut count = 0;
    let mut dist = vec![false; n];
    
    for i in 0..n {
        if dist[i] {continue; }
        dist[i] = true;
        count += 1;
        let mut queue = VecDeque::new();
        queue.push_back(i);
        while let Some(x) = queue.pop_front() {
            for &p in &graph[x] {
                if dist[p] {continue;}
                dist[p] = true;
                queue.push_back(p);
            }
        }
    }
    println!("{}", count);
}


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

using namespace std;

int main(void)
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int n,m;
    n =  C/B;
    m =  A/D;

    if( C % B != 0){
        n++;
    }
    if( A % D != 0) {
        m++;
    }

    if(n <= m) {
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N;
    cin >> N;
    int M = N + 10000;
    vector<bool> a(M, true);
    a[0] = false; a[1] = false;
    for (int i = 2; i*i <= M; i++) {
        if(a[i]){
            for (int j = i; i*j <= M; j++) {
                a[i*j] = false;
            }
        }
    }

    for (int i = N; i < M; i++) {
        if(a[i]){
            printf("%d\n", i);
            break;
        }
    }


}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
const ll mod=1e9+7;

int main(){
  int x;
  cin>>x;
  if(x<600) cout<<8<<endl;
  else if(x<800) cout<<7<<endl;
  else if(x<1000) cout<<6<<endl;
  else if(x<1200) cout<<5<<endl;
  else if(x<1400) cout<<4<<endl;
  else if(x<1600) cout<<3<<endl;
  else if(x<1800) cout<<2<<endl;
  else cout<<1<<endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
char str[1100][110];
vector<int>g[1100];
void dfs(int a,int b){
	for(int i=0;i<b;i++)printf(".");
	printf("%s\n",str[a]);
	for(int i=0;i<g[a].size();i++)dfs(g[a][i],b+1);
}
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		int t;scanf("%d%s",&t,str[i]);
		if(t){
			t--;
			g[t].push_back(i);
		}
	}
	dfs(0,0);
}

Measured memory_bytes: 1220
n, q = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp
ss = Array.new(n-1, 0)
(n-1).times do |i|
  if s[i..(i+1)] == "AC"
    ss[i] = 1
  end
end

sss = Array.new(n, 0)
(n - 1).times do |i|
  sss[i+1] = sss[i] + ss[i]
end

q.times do
  l, r = gets.chomp.split(" ").map(&:to_i)
  puts sss[r-1] - sss[l-1]
end

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

const int N(3009);
const int mod(1e9 + 7);

int n, m, ans;
char s[N];
int f[N][N], sum[N]; 
// f[i][j] - the total solution of first i elements end with j 
void add_self(int &a, int b)
{
	a += b;
	if (a >= mod) a -= mod;
}
int main()
{
	scanf("%d", &n);
	scanf("%s", s);
	f[1][1] = 1;
	for (int i = 2; i <= n; i++)
	{
		sum[0] = 0;
		for (int j = 1; j <= i - 1; j++)
		{
			sum[j] = sum[j - 1] + f[i - 1][j];
			sum[j] %= mod;
		}
		for (int b = 1; b <= i; b++)
		{
			int l, r;
			if (s[i - 2] == '<')
			{
				l = 1; r = b - 1;
			}
			else
			{
				l = b, r = i - 1;
			}
			add_self(f[i][b], (sum[r] - sum[l - 1] + mod ) % mod);
		}
	}
	for (int i = 1; i <= n; i++)
	{
		add_self(ans, f[n][i]);
	}
	printf("%d\n", ans);
	return 0;
}




Measured memory_bytes: 34304
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int calc(int a, int b)
{
    if(a == b) return 0;
    if(a == 1 || b == 1) return 1;
    return 2;
}

int count2(int n)
{
    int ret = 0;
    while(n>0 && n%2==0){
        n /= 2;
        ret++;
    }
    return ret;
}

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

    vector<int> a(N);
    bool one = false;
    for(int i=0; i<N; i++){
        a[i] = s[i] - '1';
        if(a[i]==1) one = true;
    }

    vector<int> c(N);
    c[0] = 1;
    c[N-1] = 1;
    int k = 0;
    for(int i=1; i<N-1; i++){
        k += count2(N-i) - count2(i);
        if(k==0) c[i] = 1;
    }

    int b = 0;
    for(int i=0; i<N; i++){
        b += a[i]*c[i];
    }
    if(b%2==1){
        cout << 1 << endl; return 0;
    }

    if(one){
        cout << 0 << endl; return 0;
    }
    
    b = 0;
    for(int i=0; i<N; i++){
        if(a[i]==2) b += c[i];
    }
    if(b%2==1){
        cout << 2 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 4e4 + 5;
const int inf = 2e9 + 7;
int a[maxn], b[maxn];

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

	string s;
	cin >> s;
	if (s[0] != s[1] || s[1] != s[2])cout << "Yes\n";
	else cout << "No\n";


	return 0;
}


Measured memory_bytes: 256
A,B,C,D = [int(i) for i in input().split()]

def calc_kill_num(hp, attack):
	if hp < attack:
		return 1
	attack_num, mod = divmod(hp, attack)
	if mod > 0:
		return attack_num + 1
	else:
		return attack_num

t_kill_a_num = calc_kill_num(C, B)
a_kill_t_num = calc_kill_num(A, D)


if t_kill_a_num <= a_kill_t_num:
	print("Yes")
else:
	print("No")
	

Measured memory_bytes: 9144
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		
		long res = 1;
		for(int i=1; i<=n; i++) {
			res = (res * i) % 1000000007L;
		}
		
		System.out.println(res);
	}
}


Measured memory_bytes: 23124
#ゆうたのやり方

n=int(input())
xy=[[] for i in range(n)]

for i in range(n):
    a=int(input())
    for j in range(a):
        xy[i].append(list(map(int, input().split())))
#print(xy)
bit=[]#1が正直0が嘘
ans=0
def bit_search(bit):
    global ans
    if len(bit)==n:#2**n文の組み合わせを調べる加圧10を交互に入れるためのif
        for i in range(n):
            jugh=bit[i]
            if jugh==1:
                for j in xy[i]:
                    x,y=j
                    if bit[x-1]==0:
                        if y==1:
                            return 
                    else:
                        if y==0:
                            return 
        ans=max(ans,sum(bit))
    else:
       #再起化することによって最初にbitの配列を作る必要性をなくした
        bit_search(bit+[0])
        bit_search(bit+[1])
bit_search(bit)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, w;
  cin >> n >> w;
  vector<int> weight(n), value(n);
  long long sum = 0;
  for (int i = 0; i < n; i++){
    cin >> weight[i] >> value[i];
    sum += value[i];
  }
  vector<long long> dp(sum + 1, 1e18L);
  dp[0] = 0;
  for (int i = 0; i < n; i++){
    for (int val = sum - value[i]; val >= 0; val--){
      dp[val + value[i]] = min(dp[val + value[i]], dp[val] + weight[i]);
    }
  }
  long long ans = 0;
  for (int i = 0; i <= sum; i++){
    if (dp[i] <= w)
      ans = max(ans, (long long)i);
  }
  cout << ans << '\n';

    
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    string s;
    ll k;
    cin >> s >> k;
    string t = s + s + "?";
    s += "?";
    int n = t.length();
    int m = s.length();
    ll num2 = 0;
    ll cnt = 1;
    rep(i, n-1) {
        if ( t[i] == t[i+1] ) ++cnt;
        else {
            num2 += cnt / 2LL;
            cnt = 1;
        }
    }
    cnt = 1;
    ll num1 = 0;
    bool flg = true;
    rep(i, m-1 ) {
        if ( s[i] == s[i+1] ) ++cnt;
        else {
            if ( i != m - 2 ) flg = false;
            num1 += cnt / 2LL;
            cnt = 1;
        }
    }
//    cout << flg << endl;
    if ( flg ) {
        ll len = 1LL * (ll)(s.size()-1) * k;
        cout << len / 2LL << endl;
    }
    else {
//        cout << "moge" << endl;
        cout << num1 + ( k - 1LL ) * ( num2 - num1 ) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <queue>
using namespace std;

using int64 = long long;

// (int64, sum)
struct M {
    using T = int64;
    static T op(const T& a, const T& b) { return a + b; }
    static constexpr T identity() { return 0; }
};

template <class Object>
class SegmentTree {
    const int N;
    using T = typename Object::T;
    std::vector<T> t;

    inline int lowest_pow_of_2(int n) {
        int res = 1;
        while (res < n) res <<= 1;
        return res;
    }

    inline void prop_to(int i) {
        t[i] = Object::op(t[2 * i], t[2 * i + 1]);
    }

    public:

    SegmentTree(int n) : N(lowest_pow_of_2(n)), t(2 * N, Object::identity()) { }

    template <class InputIt>
    SegmentTree(InputIt first, InputIt last)
        : N(lowest_pow_of_2(std::distance(first, last))),
          t(2 * N, Object::identity()) {
        std::copy(first, last, t.begin() + N);
        for (int i = N - 1; i > 0; i--) prop_to(i);
    }

    inline void modify(int i, T v) {
        t[(i += N)] = v;
        while (i >>= 1) prop_to(i);
    }

    T query(int l, int r) {
        return query(l, r, 1, 0, N);
    }

    T get(int i) {
        return t[i + N];
    }

    T query(int l, int r, int id, int nodel, int noder) {
        // 範囲外
        if (noder <= l or r <= nodel) return Object::identity();
        // 完全に含まれる
        if (l <= nodel and noder <= r) return t[id];

        T resl = query(l, r, 2 * id, nodel, (nodel + noder) / 2);
        T resr = query(l, r, 2 * id + 1, (nodel + noder) / 2, noder);
        
        return Object::op(resl, resr);
    }
};

int64 calc_inversion_number(vector<int>& x) {
    SegmentTree<M> segtree(x.size());
    int64 res = 0;
    for (int n : x) {
        res += segtree.query(n, x.size());
        segtree.modify(n, 1);
    }
    return res;
}

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

    map<char, int> counter;
    int N = S.size();
    static deque<int> indexes[26];
    for (int i = 0; i < N; i++) {
        counter[S[i]]++;
        indexes[S[i] - 'a'].push_back(i);
    }

    // check
    int odd_cnt = 0;
    for (auto& kv : counter) {
        if (kv.second % 2) odd_cnt++;
    }

    // cerr << odd_cnt << endl;

    if (N % 2 != odd_cnt) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> x(N, -1);
    int nxt = 0;
    for (int i = 0; i < N; i++) {
        if (x[i] != -1) continue;
        int offset = S[i] - 'a';
        auto& dq = indexes[offset];

        if (dq.size() == 1) {
            x[i] = N / 2;
            dq.pop_front();
        } else {
            x[i] = nxt;
            x[dq.back()] = N - 1 - nxt;
            nxt++;
            dq.pop_front();
            dq.pop_back();
        }
    }

    cout << calc_inversion_number(x) << endl;

    return 0;
}

Measured memory_bytes: 6148
#include <stdio.h>
int main()
{
    int n, ans = 0;
    scanf("%d", &n);
    int p = n;
    while (1)
    {
        ans++;
        n = (n * 10 + 7) % p;
        if (n == 0)
            break;
        if(ans > 1e8)
        {
            ans = -1;
            break;
        }
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 1728
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
int MOD = 1000000007;

int main() {
	for (;;) {
		string x; cin >> x;
		if (x == "0") break;
		int sum = 0;
		for (int i = 0; i < x.length(); i++)
			sum += x[i] - '0';
		cout << sum << endl;
	}
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   n--;
   int ans = (n*(n+1))/2;
   cout << ans << '\n';
   return 0;
}

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

using namespace std;

static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N];
int d[N];  //距離で訪問状態(color)を管理する

void bfs(int s){
  queue<int> q;  //標準ライブラリを使用する(テストでは使用×)
  q.push(s);
  for(int i = 0; i < n; i++) d[i] = INFTY;
  d[s] = 0;
  int u;
  while(!q.empty()){
    u = q.front();
    q.pop();
    for(int v = 0; v < n; v++){
      if(M[u][v] == 0) continue;
      if(d[v] != INFTY) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  for(int i = 0; i < n; i++){
    cout << i+1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
  }
}

int main(){
  int u,k,v;

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> u >> k;
    u--;
    for(int j = 0; j < k; j++){
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }
  bfs(0);

  return 0;
}



Measured memory_bytes: 3128
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll A, B;
    cin >> A >> B;

    ll ans = A / B;

    if(A % B > 0) ans++;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include <numeric>

#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for(int i = 0; i<n; ++i)
#define rep1(i, n) for(int i = 1; i<n; ++i)
#define rev_rep(i, n) for(int i = n - 1; i >= 0; --i)
#define dump(x) cout << #x << ":" << x << "\n";
#define all(v) v.begin(), v.end()

template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair){
  os << '(' << pair.first << ',' << pair.second << ')';
  return os;
}
template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(int i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}


#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  ll W, H;
  cin >> W >> H;
  if(W == 1 && H == 1){
    cout << 1;
    return 0;
  }
  if(W == 1){
    cout << H - 2;
    return 0;
  }
  if(H == 1){
    cout << W - 2;
    return 0;
  }

  cout << (W - 2) * (H - 2);
  
}
#endif


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      string s;
      cin >> s;
      int count[3]={};
      rep(i,3){
        rep(j,s.size()){
         if(s[j]=='a'+i)count[i]++; 
        }
      }
      if(count[0]*count[1]*count[2]==1)cout << "Yes" << endl;
      else cout << "No" << endl;
      return 0;}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF=1000000000;
const int dre_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dre_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int main(){
	static bool prim[1000010]; rep(i,1000010)prim[i]=true;
	static int ans[1000010];
	ans[1]=0;
	
	int i=2;
	for(;i*i<=1000000;i++){
		ans[i]=ans[i-1];
		if(prim[i]){
			ans[i]++;
			for(int j=i*i;j<=1000000;j+=i){
				prim[j]=false;
			}
		}
	}
	for(;i<=1000000;i++){
		ans[i]=ans[i-1];
		if(prim[i])ans[i]++;
	}
	
	int n;
	while(~scanf("%d",&n))printf("%d\n",ans[n]);
}

Measured memory_bytes: 6068
from heapq import heappush, heappop
from collections import deque
N = int(input())
G = [[] for i in range(N)]
for i in range(N - 1):
    a, b, c = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append((b, c))
    G[b].append((a, c))

Q, K = map(int, input().split())
K -= 1

INF = float("inf")
d = [INF] * N
d[K] = 0
que = [(0, K)]
while que:
    cost, v = heappop(que)
    if d[v] < cost:
        continue
    for w, c in G[v]:
        if d[v] + c < d[w]:
            d[w] = d[v] + c
            heappush(que, (d[w], w))

for i in range(Q):
    x, y = map(int, input().split())
    print(d[x - 1] + d[y - 1])


Measured memory_bytes: 46488