akhauriyash/Code-Regression huggingface dataset:
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}


#define int long long
ll dp[3000][3000];
ll val[200000];
int n, m, border;
int calc(int l, int r) {
    if (l >= r) swap(l, r);
    return (val[r] - val[l - 1]) / border;
}
void solve(){
    cin >> n >> m >> border;
    vector<int> vertexs;
    REP(i, n) {
        int a;
        cin >> a;
        vertexs.push_back(a);
    }
    vector<int> gogo;
    REP(i, m) {
        int a;
        cin >> a;
        val[i + 1] = val[i] + a;
    }
    sort(ALL(vertexs));
    REP(i, n + 1) {
        REP(q, n + 1) {
            dp[i][q] = 1e18;
        }
    }
    int hoge = 0;
    for (int q = 1; q < vertexs.size();++q) {
        hoge += calc(vertexs[q], vertexs[q - 1]);
        dp[q - 1][q] = calc(vertexs[q], vertexs[0]) + hoge;
        dp[q][q-1] = dp[q-1][q];
    }
    for (int i = 1; i < vertexs.size()-1; ++i) {
        REP(q, i) {
            dp[i + 1][i] = min(dp[i + 1][i], dp[q][i] - calc(vertexs[q], vertexs[i]) + calc(vertexs[q], vertexs[i + 1]) + calc(vertexs[i], vertexs[i + 1]));
            dp[q][i + 1] = min(dp[q][i + 1], dp[q][i] - calc(vertexs[q], vertexs[i]) + calc(vertexs[q], vertexs[i + 1]) + calc(vertexs[i], vertexs[i + 1]));
            dp[i][i + 1] = min(dp[i][i + 1], dp[i][q] - calc(vertexs[q], vertexs[i]) + calc(vertexs[q], vertexs[i + 1]) + calc(vertexs[i], vertexs[i + 1]));
            dp[i+1][q] = min(dp[i+1][q], dp[i][q] - calc(vertexs[q], vertexs[i]) + calc(vertexs[q], vertexs[i + 1]) + calc(vertexs[i], vertexs[i + 1]));
        }
    }
    int ans = 1e18;
    REP(q, vertexs.size()) {
        ans = min({ ans,dp[vertexs.size() - 1][q],dp[q][vertexs.size() - 1] });
    }
    cout << ans << endl;
}

#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 43308
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size() 
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)


/****************************** CODE IS HERE ***********************************/
const ll INF = 5e18;
map<ll, ll> dp;
vector <pair<ll, ll>> action(3);
ll a, b, c, d; 

ll go(ll n) {
    if (n == 0) return 0;
    if (n == 1) return d;

    if (dp.count(n)) return dp[n];

    ll ans = INF;
    if (ans / n > d)
        ans = min(ans, n * d);

    for (auto i: action) {
        ll mul = i.first;
        ll cost = i.second;
        if (n % mul == 0) {
            ans = min(ans, cost + go(n / mul));
        } else {
            ll down = n / mul * mul;
            ans = min(ans, cost + d*(n - down) + go(n / mul)); // or ans = ... + go(down / mul) result is same 
            ll up = down + mul;
            ans = min(ans, cost + d*(up - n) + go(n / mul + 1)); //or ans = ... + go(up / mul) result is same
        }
    }

    dp[n] = ans;
    return ans;
}

void solve() {
    ll n;
    cin >> n >> a >> b >> c >> d;
    action[0] = {2, a};
    action[1] = {3, b};
    action[2] = {5, c};

    dp.clear();
    ll ans = go(n);
    cout << ans << endl;

}


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

    int t; cin >> t;
    while (t--) 
        solve();

    return 0;
}

//there is trick used to safely use the +1, -1 operation
//you can also use unordered_map with safe hashing techinique


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

public class Main{
	static void main() throws Exception{
		char[]in=sc.nextLine().toCharArray();
		for(int i=0;i<in.length;i++) {
			if(in[i]=='?')in[i]='D';
			pw.print(in[i]);
		}
		
	}
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
//		int tc=sc.nextInt();
//		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}

Measured memory_bytes: 36564
import numpy as np
 
N, W = map(int, input().split())
dp = np.ones(int(1e5+1)) * np.inf
dp[0] = 0
total = 0
for i in range(N):
    w, v = map(int, input().split())
    dp[v:total+v+1] = np.minimum(dp[v:total+v+1], dp[:total+1] + w)
    total += v
 
print(int(np.where(dp<=W)[0][-1]))

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

const int N = 1010;

int n;
int indegree[N * N];
vector<int> g[N * N];

int toint(int x, int y) {
  if (x > y)
    swap(x, y);
  return n * x + y;
}

pair<int, int> demap(int x) {
  return {x / n, x % n};
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int last;
    scanf("%d", &last);
    last--;
    for (int j = 0; j < n - 2; j++) {
      int cur;
      scanf("%d", &cur);
      cur--;
      g[toint(i, last)].push_back(toint(i, cur));
      indegree[toint(i, cur)]++;
      last = cur;
    }
  }

  int proc = 0, ans = 0;
  vector<int> cur_set;
  for (int i = 0; i < N * N; i++)
    if (!indegree[i] && demap(i).first < demap(i).second && max(demap(i).first, demap(i).second) < n)
      cur_set.push_back(i);

  while ((int) cur_set.size() > 0) {
    ans++;
    proc += (int) cur_set.size();
    vector<int> nxt;
    for (int u : cur_set)
      for (int v : g[u]) {
        indegree[v]--;
        if (!indegree[v])
          nxt.push_back(v);
      }
    cur_set = nxt;
  }

  printf("%d\n", (proc == n * (n - 1) / 2 ? ans : -1));
  return 0;
}

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

int n;
typedef complex<double> Point;
typedef Point Vector;
Point X(0.0, 0.0), Y(100.0, 0.0);
Point z(1.0/2, sqrt(3)/2);

void func(Point x, Point y, int m){
	if(m == 0){
		cout << real(x) << " " << imag(x) << "\n";
		return;
	}
	Point s = (2.0*x + y) / 3.0;
	Point t = (x + 2.0*y) / 3.0;
	Point u = s + (t - s) * z;
	func(x, s, m-1);
	func(s, u, m-1);
	func(u, t, m-1);
	func(t, y, m-1);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	cin >> n;
	func(X, Y, n);
	cout << real(Y) << " " << imag(Y) << "\n";
}


Measured memory_bytes: 3288
import sys
sys.setrecursionlimit(1000000)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import defaultdict
n = I()
def primes(n):
    cnt = defaultdict(int)
    for i in range(2,int(n**0.5)+1): # range(3)だと、0,1,2が出てくる。
        while n % i == 0:
            cnt[i] += 1 # 同じ素数で何回割れるか辞書型で登録しておく
            n //= i # iで割り切った商で更新しておく
    if n > 1: # nの平方根より大きい値があった場合、追加
        cnt[n] += 1
    return cnt
prs = primes(n) #　素数の辞書
ans = 0
for key in prs.keys(): #辞書から素数を抽出して、その素数の指数値をvとして格納する。
    v = prs[key]
    for i in range(100):
        # if (i * (i+1)) // 2 <= v:　これだと何度も足し算してしまう。
        if (i * (i + 1)) // 2 > v: # 指数eを超えた一つ前が目的の計数である。
            ans += (i-1)
            break
print(ans)


Measured memory_bytes: 66544
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M, c = 0, ans = 0; cin >> N >> M;
  vector<int> A(N, 0);
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    c += A[i];
  }
  for(int i = 0; i < N; i++) {
    if(double(A[i]) / double(c) < 1 / (4 * double(M))) continue;
    ans++;
  }
  if(ans >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

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

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
		String first = new Scanner(System.in).nextLine();
		String Array[] = first.split(" ");
		int Num0 = Integer.parseInt(Array[0]);
		int Num1 = Integer.parseInt(Array[1]);
		System.out.println(Num0 * Num1);
		
    }
}

Measured memory_bytes: 35816
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

const int N = 3000;
ll dp[N][N];
ll vals[N];

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

	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> vals[i];

	for (int len = 1; len <= n; ++len) {
		for (int a = 0; a+len <= n; ++a) {
			int b = a + len - 1;
			if (a == b) dp[a][b] = vals[a];
			else dp[a][b] = max(vals[b] - dp[a][b-1], vals[a] - dp[a+1][b]);
		}
	}
	cout << dp[0][n-1] << '\n';
}


Measured memory_bytes: 70016
#include<iostream>
using namespace std;
int main(){
    int n, v, j;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        if(i == n-1){
            cout << a[i] << endl;
        }else{
            cout << a[i] << " ";
        }
    }
    for(int i = 1; i <= n-1; i++){
        v = a[i];
        j = i - 1;
        while(j >= 0 && a[j] > v){
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        for(int j = 0; j < n; j++){
            if(j == n-1){
                cout << a[j] << endl;
            }else{
                cout << a[j] << " ";
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    if(a > b){
        if(b != 1){
            cout << "Alice" << endl;
        }else{
            cout << "Bob" << endl;
        }
    }else if(a < b){
        if(a != 1){
            cout << "Bob" << endl;
        }else{
            cout << "Alice" << endl;
        }
    }else if(a == b){
        cout << "Draw" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

ll n, X, x[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> X;
    rep(i, 0, n) cin >> x[i];
    x[n] = X;
    ll ans = 0;
    rep(i, 0, n) ans = gcd(abs(x[i+1] - x[i]), ans);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;
typedef pair<int,int> P;
int main(){
  ll n,m;
  string s,t;
  cin>>n>>m>>s>>t;
  ll l=n/__gcd(n,m)*m;
  ll b=l/n;
  ll a=l/m;
  bool ans=true;
  int j=0;
  for(int i=0;i<n;i+=a){
    if(s[i]!=t[j]){
      ans=false;
    }
      j+=b;
    
  }
  if(ans)cout<<l<<endl;
  else cout<<-1<<endl;
}
      

Measured memory_bytes: 512
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    ################
    class UnionFind():
        """
        parents : 親要素(findしない場合は根ではないことの注意)，根の場合は"-(要素数）"
        find(x):要素xの属するグループの根を返す
        size(x):要素xの属するグループの要素数を返す
        same(x,y):x,yが同じグループに属しているか返す
        重いかも！　　members(x):要素xが属するグループに属する要素をリストで返す
        roots:全ての根の要素を返す
        group_count():グループの数を返す
        重いかも！　all_group_members():{根要素：[そのグループに含まれる要素のリスト]}の辞書を返す
        """
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, x):
            #根を探す&つなぎかえる
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.parents[x] > self.parents[y]:
                x, y = y, x

            self.parents[x] += self.parents[y]
            self.parents[y] = x

        def size(self, x):
            return -self.parents[self.find(x)]

        def same(self, x, y):
            return self.find(x) == self.find(y)

        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]

        def group_count(self):
            return len(self.roots())

        def all_group_members(self):
            return {r: self.members(r) for r in self.roots()}

        def __str__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
        
    ################

    """
    解説放送のように，グラフを考える．
    X座標を表す点を10**5個
    Y座標を表す点を10**5個用意．
    座標を点，点をグラフの辺として表す
    """

    N=I()
    M=10**5
    XY=[0]*(2*M)
    uf=UnionFind(2*M)
    for i in range(N):
        x,y=MI()
        x-=1
        y-=1
        y+=M
        XY[x]+=1
        XY[y]+=1
        uf.union(x,y)
    
    #　各根要素に対して，xの要素数，yの要素数，入出する辺の本数をメモ
    from collections import defaultdict
    ddx = defaultdict(int)
    ddy = defaultdict(int)
    dde = defaultdict(int)
    
    for i in range(2*M):
        root=uf.find(i)
        if i<M:
            ddx[root]+=1
        else:
            ddy[root]+=1
        dde[root]+=XY[i]
        
    ans=0
    
    for k,v in dde.items():
        temp=ddx[k]*ddy[k]-v//2
        ans+=temp
        
    print(ans)
    
    
    

main()


Measured memory_bytes: 166944
/*
AtCoder Beginner Contest 100 A - Happy Birthday!
結果:
*/

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

#define max(x,y)(x<y?y:x)
#define int long long

//尺取法
//scanf("%d", &N);
//for (i; i < N; ++i) {
//	scanf("%d", &A[i]);
//	if (b[A[i]] == 1) {
//		ans = max(ans, i - j);
//		while (b[A[i]] == 1) {
//			b[A[j++]] = 0;
//		}
//	}
//	b[A[i]] = 1;
//}
//ans = max(ans, i - j);
//printf("%d\n", ans);

//文字列の最大出現
//static int N, i, j, ans;
//static int A, B;
//static char A[50][51];
//static int cnt, max;
//char *max_name;
//
//scanf("%d", &N);
//for (i = 0; i < N; i++) {
//	scanf("%s", A[i]);
//}
//max_name = A[0];
//for (i = 0; i < N; i++) {
//	cnt = 0;
//	for (j = 0; j < N; j++) {
//		if (strcmp(A[i], A[j]) == 0) {
//			cnt++;
//		}
//		if (cnt > max) {
//			max = cnt;
//			max_name = A[i];
//		}
//	}
//}
//printf("%s\n", max_name);

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF

int main() {
	static int N, i, j, ans;
	static int A, B;
	//static char A[50][51];
	static int cnt, max;
	char *max_name;

	//scanf("%d", &N);
	scanf("%d %d", &A, &B);
	//for (i = 0; i < N; i++) {
	//	scanf("%s", A[i]);
	//}

	if ((A + B) <= 16 && (A <= 8 && B <= 8)) {
		printf("%s\n", "Yay!");
	}
	else
	{
		printf("%s\n", ":(");
	}

	//ans = ;
	//printf("%d\n", ans);
	//printf("%s\n", max_name);


#ifdef DEBUGF
	getch();
#endif
	return 0;
}


Measured memory_bytes: 128
a=list(map(int,input().split()))
sumy=0
for i in range(int(a[0]+1)):
    b=[]
    b+=str(i)
    c=0
    for t in range(len(b)):
        c+=int(b[t])
    if c>=a[1] and c<=a[2]:
        sumy+=i
print(sumy)

Measured memory_bytes: 3060
//2019.12.21
//s1270188 xxxmk2
//alds1_03d

#include<stdio.h>

#define N 20000

//prototype
void push(int);
int pop(void);

//global
int left[N], left_n=0;

int main(){
  int data, i=0, j;
  int S[N/2][2], S_n=0, SUM=0;

  //input
  while((data=getchar())!='\n'){
    if(data=='\\') push(i); 
    else if(data=='/' && (data=pop())!=-1){
      S[S_n][0]=i-data;
      SUM+=i-data;
      S[S_n][1]=data;
      S_n++;
    }

    i++;
  }


  for(i=S_n-1;i>0;i--){
    if(S[i][1]<S[i-1][1]){
      S[i-1][0]+=S[i][0];
      S[i-1][1]=S[i][1];

      for(j=i;j<S_n;j++){
	S[j][0]=S[j+1][0];
	S[j][1]=S[j+1][1];
      }
      S_n--;
    }
  }
  
  //output
  printf("%d\n%d",SUM,S_n);
  if(S_n==0) printf("\n");
  else{
    for(i=0;i<S_n;i++) printf(" %d",S[i][0]);
    printf("\n");
  }
  
  return 0;
}


void push(int data){
  left[left_n++]=data;
}


int pop(void){
  if(left_n==0) return -1;
  else return left[--left_n];
}



Measured memory_bytes: 2108
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n < 2) {
            System.out.println(n);
        } else if (n < 4) {
            System.out.println(2);
        } else if (n < 8) {
            System.out.println(4);
        } else if (n < 16) {
            System.out.println(8);
        } else if (n < 32) {
            System.out.println(16);
        } else if (n < 64) {
            System.out.println(32);
        } else {
            System.out.println(64);
        }
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define int long long 
typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=500005;
const int MOD=1000000007;
const int BLOCK=700;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())


int N,Q;
int C[MAXN], freq[MAXN], ans[MAXN], numcol;

void add(int col){
	if (freq[col] == 0) numcol++;
	freq[col]++;
}

void remove(int col){
	if (freq[col] == 1) numcol--;
	freq[col]--;
}

struct Query{
	int l, r, idx;
	Query(int _l=0, int _r=0, int _idx=0): l(_l), r(_r), idx(_idx) {}
};

bool cmp(Query a, Query b){
	return mp(a.l/BLOCK, a.r) < mp(b.l/BLOCK, b.r);
}

vector<Query> vec;

void moalgo(){
	sort(all(vec), cmp);
	int cur_l = 1, cur_r = 0;
	for (Query q:vec){
		while (cur_l > q.l){
			cur_l--;
			add(C[cur_l]);
		}
		while (cur_l < q.l){
			remove(C[cur_l]);
			cur_l++;
		}
		while (cur_r < q.r){
			cur_r++;
			add(C[cur_r]);
		}
		while (cur_r > q.r){
			remove(C[cur_r]);
			cur_r--;
		}
		ans[q.idx] = numcol;
	}
}
main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>Q;
	FOR(i,1,N) cin>>C[i];
	FOR(i,1,Q){
		int l,r; cin>>l>>r;
		vec.pb(Query(l,r,i));
	}
	moalgo();
	FOR(i,1,Q) cout<<ans[i]<<"\n";
}




Measured memory_bytes: 27324
class Node:
    def __init__(self, p, l, r):
        self.p, self.l, self.r = p, l, r

N = int(input())
T = [Node(None, None, None) for _ in range(N)]

def get_depth(i):
    depth = 0
    while T[i].p != None:
        depth += 1
        i = T[i].p
    return depth

def get_children(i):
    children = []
    child = T[i].l
    while child != None:
        children.append(child)
        child = T[child].r
    return children

for _ in range(N):
    node, num, *children = map(int, input().split())
    if len(children) > 0:
        T[node].l = children[0]
        for i, child in enumerate(children):
            if len(children) - 1 < i + 1:
                break
            T[child].r = children[i + 1]
        for child in children:
            T[child].p = node

for i, t in enumerate(T):
    parent = t.p if t.p != None else -1
    depth = get_depth(i)
    if t.p == None:
        node = 'root'
    elif t.l == None:
        node = 'leaf'
    else:
        node = 'internal node'
    children = get_children(i)
    print('node {}:'.format(i), end=' ')
    print('parent = {},'.format(parent), end=' ')
    print('depth = {},'.format(depth), end=' ')
    print('{},'.format(node), end=' ')
    print(children)


Measured memory_bytes: 33648
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
lis = [0] * (max(D)+1)
if D[0] != 0:
    print(0)
    exit()
for i in D:
    lis[i] += 1
if lis[0] == 0 or lis[0] > 1:
    print(0)
    exit()


ans = 1
for i in range(1,len(lis)):
    ans *= pow(lis[i-1],lis[i], MOD)
    ans %= MOD
print(ans)


Measured memory_bytes: 84492
import fractions

N = int(input())
A = list(map(int, input().split()))

a = 1
for i in range(N):
    g = a * A[i] // fractions.gcd(a, A[i])
    a = g
    
b = 0
for i in range(N):
    b = b + g // A[i]

c = b % (1000000007)
print(c)

Measured memory_bytes: 6072
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main ()
{
	string a;
	while ((a = readln.strip) != "")
	{
		auto n = a.length.to !(int);
		int [char] w;
		foreach (c; a)
		{
			w[c] += 1;
		}
		auto res = 1 + (n * (n - 1L)) / 2;
		foreach (k, v; w)
		{
			res -= (v * (v - 1L)) / 2;
		}
		writeln (res);
	}
}


Measured memory_bytes: 2684
#include<stdio.h>

int main() {
  int a, b;
  int i;
  int ans;
  scanf("%d %d", &a, &b);
  for(i=0; i<2; i++){
    if(a > b) ans += a--;
    else ans += b--;
  }
  printf("%d", ans);
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int main() {
  int N,a;
  cin >> N;
  
  a = N % 10;
  if(a==2 || a==4 || a==5 || a==7 || a==9){
    cout << "hon" << endl;
  } 
  else if(a==3){
    cout << "bon" << endl;
  }
  else{
    cout << "pon" << endl;
  }
}

Measured memory_bytes: 3672
#include <stdio.h>

int main(void)
{
    char input;
    int count['z' + 1] = {0};

    while(scanf("%c", &input) != EOF)
    {
        if(input >= 'a' && input <= 'z')
        {
            count[input]++;
        }

        if(input >= 'A' && input <= 'Z')
        {
            count[input - 'A' + 'a']++;
        }
    }

    char i;
    for(i = 'a'; i != 'z' + 1; ++i)
    {
        printf("%c : %d\n", i, count[i]);
    }

    return 0;
}

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

template<typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n=0){
        initialize(n);
    }

    void initialize(int nin){
        n = nin;
        dat.resize(n, 0);
    }

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

    T sum_between(int i, int j){
        return sum(j) - sum(i-1);
    }

    void plus(int i, T x){
        while(i < n){
            dat[i] += x;
            i |= i+1;
        }
    }

    // a[0]+...+a[ret] >= x
    int lower_bound(T x){
        int ret = -1;
        int k = 1;
        while(2*k <= n) k <<= 1;
        for( ;k>0; k>>=1){
            if(ret+k < n && dat[ret+k] < x){
                x -= dat[ret+k];
                ret += k;
            }
        }
        return ret + 1;
    }
};

int main(){
    int Q;
    cin >> Q;
    vector<int> T(Q), A(Q), B(Q);
    map<int, int> mp;
    for(int i=0; i<Q; i++){
        cin >> T[i];
        if(T[i] == 1){
            cin >> A[i] >> B[i];
            mp[A[i]] = 0;
        }
    }
    vector<int> cmp;
    int sz = 0;
    for(auto p : mp){
        mp[p.first] = sz++;
        cmp.push_back(p.first);
    }

    BIT<int64_t> bit_num(sz), bit_sum(sz);
    int64_t Bsum = 0;
    int s = 0;
    for(int i=0; i<Q; i++){
        if(T[i] == 1){
            int a = A[i], b = B[i];
            s++;
            Bsum += b;
            bit_num.plus(mp[a], 1);
            bit_sum.plus(mp[a], a);
        }else{
            int mi = bit_num.lower_bound((s+1)/2);
            int s1 = bit_num.sum_between(0, mi);
            int64_t med = cmp[mi];
            int64_t ans = s1 * med - bit_sum.sum_between(0, mi) + bit_sum.sum_between(mi+1, sz-1) - (s-s1) * med + Bsum;
            cout << med << " " << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 11768
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;
    int ans = 1;
    for (int i = 0; i < n; i++) {
        int l;
        cin >> l;
        x -= l;
        if (x >= 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
td = [[int(i) for i in input().split()] for _ in range(N)]
td.sort(key=lambda x:x[1],reverse=True)
ans = 0
ls = set()
dl = []
for i in range(K):
    ans += td[i][1]
    if not td[i][0] in ls:
        ls.add(td[i][0])
    else:
        dl.append(td[i][1])
ans = ans + len(ls)**2
res = ans
for i in range(K,N):
    if not dl:
        break
    if td[i][0] in ls:
        continue
    ans += len(ls)*2+1
    ans += td[i][1]
    ans -= dl[-1]
    del dl[-1]
    res = max(res,ans)
    ls.add(td[i][0])
print(res)

Measured memory_bytes: 68312
"""
    dp[h][w]: h番目のrow(h: 0~H(終着))で棒w(w: 0~W-1)にいる状態になるための横線(0~h)の組合せ数
    dp[h][w] = A*dp[h-1][w-1] + B*dp[h-1][w] + C*dp[h-1][w+1] O(100*8)
    A, B, Cはなんかうまいこと決めれそう。(全探索でもO(7*7*3))
    o(10**6)には入りそう
    """
def main():
    import sys
    input = sys.stdin.readline
    H, W, K = map(int, input().split())
    dp = [[0]*W for _ in range(H+1)]
    dp[0][0] = 1
    for h in range(1, H+1):
        for w in range(W):
            A, B, C = 0, 0, 0
            for i in range(2 ** (W-1)):
                lines = []
                for j in range(W-1):
                    if ((i >> j) & 1):
                        if lines and lines[-1]:
                            break
                        lines.append(True)
                    else:
                        lines.append(False)
                else:
                    if w-1 >= 0 and lines[w-1]:
                        A += 1
                    elif w <= W-2 and lines[w]:
                        C += 1
                    else:
                        B += 1
            if w-1 >= 0:
                dp[h][w] += dp[h-1][w-1] * A
            dp[h][w] += dp[h-1][w] * B
            if w+1 <= W-1:
                dp[h][w] += dp[h-1][w+1] * C
    print(dp[H][K-1] % (10**9+7))
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
N,Y=map(int,input().split())

for x in range(N+1):
    for y in range(N-x+1):
        z=(Y//1000)-10*x-5*y
        if N==x+y+z:
            print("{} {} {}".format(x,y,z))
            exit()

print("-1 -1 -1")

Measured memory_bytes: 9092
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn solve(mut n:i64) {
    if n == 0 {
        println!("0");
        return;
    }
    let mut st = Vec::<i32>::new();
    let mut bit = 1;
    while n != 0 {
        // println!(" : {} {}", n, bit);
        if n % (bit * 2) != 0 {
            st.push(1);
            n -= bit;
        } else {
            st.push(0);
        }
        bit *= -2;
    }
    while let Some(top) = st.pop() {
        print!("{}", top);
    }
    println!("");
}
fn main() {
    let n = read::<i64>();
    solve(n);
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

signed main(){
	int A,B;
	cin>>A>>B;
	if(B%A==0){
		cout<<B+A<<endl;
	}
	else{
		cout<<B-A<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define SORT(v) sort(v.begin(),v.end())
#define fori(i,a,b) for(ll i=a;i<b;i++)
#define M 1000000007
#define deb(x) cout<< #x << " " << x << endl;

double pi=3.14159265358979323846;

typedef pair<int,int> pii;
typedef pair<long long int, long long int>pll;
typedef vector<int>vi;
typedef vector<long long int>vl;
#define M 1000000007

 

int main ()
{
    ll T;
   T=1;
   //cin>>T;
    while(T--)
    {	
    ll h,w;
    cin>>h>>w;
    vector<string>v(h);
    fori(i,0,h){cin>>v[i];}
    vector<vector<ll>>dp(h,vector<ll>(w,0));
    int i;
    for( i=0;i<h;i++){
    	if(v[i][0]=='#'){break;}
    	else dp[i][0]=1;
    }
    for(;i<h;i++ ){dp[i][0]=0;}
    for( i=0;i<w;i++){
    	if(v[0][i]=='#'){break;}
    	else{dp[0][i]=1;}
    }
    for(;i<w;i++ ){dp[0][i]=0;}
    
    for(int i=1;i<h;i++){
    	for(int j=1;j<w;j++){
    		if(v[i][j]=='#')continue;
    		  dp[i][j] = (dp[i][j-1] + dp[i-1][j])%M;
               
    	}
    }
    cout<<dp[h-1][w-1]<<endl;
    
    }
    return 0;
}


Measured memory_bytes: 13000
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(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 main(){
    int n, k;
    cin >> n >> k;
    deque<ll> Que;
    rep(i, n){
        ll v; cin >> v;
        Que.push_back(v);
    }

    ll res = 0;
    rep(i, k+1){
        rep(j, k+1){
            if(i+j > n || i+j > k) continue;
            deque<ll> que = Que;
            vector<ll> jewel;
            ll val, sum = 0;
            rep(a, i){
                val = que.front(); que.pop_front();
                jewel.push_back(val); 
                sum += val;
            }
            rep(b, j){
                val = que.back(); que.pop_back();
                jewel.push_back(val);
                sum += val;
            }
            sort(all(jewel));
            rep(c, min((int)jewel.size(), k-(i+j))){
                ll num = jewel[c];
                if(num < 0)sum -= num;
            }
        chmax(res, sum);
        }
    }
    cout << res << ln;
}


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

int main() {
  int N; cin >> N;
  vector<int> A(N + 1); for (int i = 1; i <= N; i++) cin >> A[i];
  int sum = 0;
  for (int i = 1; i <= N; i++) sum += A[i];
  if (sum % 2 == 0) cout << "YES" << endl; else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 640
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

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

	ll cnt[N+1] = {};
	rep(i, N) cnt[A[i]]++;

	ll ans = 0;
	rep(i, N+1) ans += C(cnt[i]);

	ll tmp = ans;
	for (int k = 0; k <N; k++) {
		ans = tmp;
		ans -= C(cnt[A[k]]);
		ans += C(cnt[A[k]] - 1);
		cout << ans << endl;
	}
}

Measured memory_bytes: 5760
#include<stdio.h>
int main(){
  int x,y,z,p,q;
  int a,i;
  scanf("%d %d",&x,&y);

  if(x>=y)
    {
      p=x;
      q=y;
    }
  else if(x<=y){
    q=x;
    p=y;
  }
  z=p%q;
  a=1;
  if(z==0){
    printf("%d\n",x);
  }
  else if(z!=0){
    for(i=1;i<=z;i++){
    if(z%i==0 && q%i==0){
      if(i>=a){
        a=i;
    }
    }
    }
  printf("%d\n",a);
  }
  return 0;

}



Measured memory_bytes: 2036
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	double[][] p = new double[2][6];

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] w = new long[n];
		for (int i = 0; i < n; ++i) {
			w[i] = sc.nextLong();
		}
		@SuppressWarnings("unchecked")
		ArrayList<Integer>[] g = new ArrayList[n];
		for (int i = 0; i < n; ++i)
			g[i] = new ArrayList<>();
		int[] deg = new int[n];
		for (int i = 0; i < m; ++i) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			--u;
			--v;
			g[u].add(v);
			g[v].add(u);
			++deg[u];
			++deg[v];
		}

		long[] f = new long[n];

		ArrayDeque<Integer> dq = new ArrayDeque<>();
		for (int i = 0; i < n; ++i) {
			if (deg[i] == 1 && i != 0) {
				dq.add(i);
			}
		}

		while (!dq.isEmpty()) {
			int v = dq.pollFirst();
			if (deg[v] == 0)
				throw new AssertionError();
			for (int dst : g[v]) {
				if (deg[dst] == 0)
					continue;
				f[dst] = Math.max(f[dst], f[v] + w[v]);
				--deg[dst];
				--deg[v];
				if (dst != 0 && deg[dst] == 1) {
					dq.addLast(dst);
				}
			}
		}

		long ans = 0;
		for (int i = 0; i < n; ++i) {
			if (i == 0 || deg[i] > 0)
				ans += w[i];
		}
		Arrays.sort(f);
		ans += f[f.length - 1];
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

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


Measured memory_bytes: 119112
#include <stdio.h>
main()

{
    int a,b,c,num=0;
    scanf("%d%d%d",&a,&b,&c);
    if (a==b && a==c) num=1;
    else if (a==b && a!=c) num=2;
    else if (a!=b && a==c) num=2;
    else if  (a!=b && b==c) num=2;
    else if (a!=b && a!=c && b!=c) num=3;
    printf("%d",num);
}


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

using namespace std;

int main()
{
    int N, K;
    cin >> N;

    vector<pair<int, int>> As(N);

    for (int i = 0; i < N; ++i)
    {
        int A;
        cin >> A;
        As[i] = make_pair(i + 1, A);
    }

    sort(As.begin(), As.end(), [](auto lhs, auto rhs) {
        return lhs.second < rhs.second;
    });

    for (int i = 0; i < N; ++i)
    {
        cout << As[i].first;
        if (i != N - 1)
        {
            cout << " ";
        }
    }
}

Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	vector<int> A(N); rep(i, 0, N) { cin >> A[i]; }
	int ans = 0;
	int i = 0;
	while (true) {
		int mini = INF, maxi = 0;
		rep(j, 0, M) {
			chmin(mini, A[i]);
			chmax(maxi, A[i]);
			i++;
			i %= N;
		}
		ans += maxi - mini;
		if (i == 0)break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3212
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		long[] A=new long[N];
		for(long i=0L; i<N; i++) {
			long t=sc.nextLong()*100000000L+(i+1L);
			A[(int)i]=t;
		}
		Arrays.sort(A);
		for(int i=0; i<N-1; i++) {
			System.out.print(A[i]%100000000+" ");
		}
		System.out.println(A[N-1]%100000000);

	}
	public static void p(Object o) {
		System.out.println(o);
	}
}

Measured memory_bytes: 65428
fun main(args: Array<String>) {
    val (x1, y1, x2, y2) = readLine()!!.split(' ').map(String::toInt)
    val dx = x1 - x2
    val dy = y1 - y2
    val x3 = x2 + dy
    val y3 = y2 - dx
    val x4 = x1 + dy
    val y4 = y1 - dx
    println("$x3 $y3 $x4 $y4")
}


Measured memory_bytes: 36340
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n,k,mod=llpow(10,9)+7;
 sc(n);sc(k);
 ll a[n+10];
 rep(i,0,n)sc(a[i]);

 ll b,c;ans=0;ll mx,y;
 rep(i,0,n){
  b=0;
  rep(j,0,i){
   if(a[i]>a[j])b++;
  } 
  y=k;
  mx=(k*(k-1))/2;mx%=mod;
  ans+=mx*b;
  ans%=mod;
 // cout<<i<<" "<<y<<" "<<ans<<" "<<b<<" "<<(k-1)*b<<endl;
  c=0;
  rep(j,i,n){
   if(a[i]>a[j])c++;
  }
  mx=(k*(k+1))/2;mx%=mod;
  ans+=mx*c;ans%=mod;
 // cout<<i<<" "<<y<<" "<<ans<<" "<<c<<" "<<k*c<<endl;
 }
 ans%=mod;
 pr(ans);
return 0;}


Measured memory_bytes: 3680
#include<stdio.h>
int main()
{
    int i, 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};
    scanf("%d",&i);
    printf("%d\n",a[i-1]);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>

using namespace std;

vector<int> con[100005];

struct node
{
	int p;
	int d;
	int x;
};

node nodes[100005];

void dfs(int id,int p)
{
	nodes[id-1].x=1;
	nodes[id-1].p=p;
	if(p==-1)
		nodes[id-1].d=0;
	else
		nodes[id-1].d=nodes[p-1].d+1;
	for(int i=1;i<=con[id-1].size();i++)
		if(con[id-1][i-1]!=p)
		{
			dfs(con[id-1][i-1],id);
			nodes[id-1].x+=nodes[con[id-1][i-1]-1].x;
		}
}

int par(int id,int n)
{
	if(n==0)
		return id;
	else if(n==1)
		return nodes[id-1].p;
	else
		return par(nodes[id-1].p,n-1);
}

	 

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

	dfs(1,-1);
	
	int pid=par(n,(nodes[n-1].d-1)/2);
		
	if(nodes[n-1].d%2==0)
	{
		cout << (nodes[1-1].x-nodes[pid-1].x>nodes[pid-1].x ? "Fennec" : "Snuke") << endl;
	}
	else
	{
		cout << (nodes[1-1].x-nodes[pid-1].x>nodes[pid-1].x ? "Fennec" : "Snuke") << endl;
	}


}


Measured memory_bytes: 14720
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
dd = defaultdict(int)
ans = 0
for _ in range(N):
    s = ''.join(sorted(list(input())))
    ans += dd[s]
    dd[s] += 1

print(ans)


Measured memory_bytes: 18940
#include <stdio.h>
#include <string.h>
int selectionsort(int a[],int n)
{
    int i,j,minj,temp,ans=0;
    for(i=0; i<n; i++)
    {
        minj=i;
        for(j=i+1; j<n; j++)
        {
            if(a[minj]>a[j])
            {
                minj=j;
            }
        }
        temp=a[minj];
        a[minj]=a[i];
        a[i]=temp;
        if(i!=minj)
            ans++;
    }
    return ans;
}

int main()
{
    int i,n,ans;
    int a[110];
    scanf("%d",&n);

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

    ans=selectionsort(a,n);

    for(i=0; i<n; i++)
    {
        if(i!=0)   printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");
    printf("%d\n",ans);

    return 0;
}



Measured memory_bytes: 2724
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

/*DP使ったほうがよくない？？WOWWOW*/

int main(){
  string S,head,tail; cin>>S; head="", tail="";
  int Q,t,f; cin>>Q;
  char c;
  deque<string> a;
  bool rev=false;
  for(int i=0; i<Q; i++){
    cin>>t;
    if(t==1){
      rev = !rev;
    }
    else{
      cin>>f>>c;
      if((!rev && f==1) || (rev && f==2)){
        head+=c;
      }
      else{
        tail+=c;
      }
    }
  }
  reverse(head.begin(),head.end());
  S=head+S+tail;
  if(rev){
    reverse(S.begin(),S.end());
  }
  cout<<S<<endl;
}

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

const int mod = 2019;

int main() {
    int k;
    cin >> k;
    vector<ll> lunlun;
    queue<ll> q;
    for (int i = 1; i <= 9; i++) {
        lunlun.push_back(i);
        q.push(i);
    }
    while (lunlun.size() < k) {
        ll x = q.front(); q.pop();
        if (x%10 == 0) {
            lunlun.push_back(x*10);
            q.push(x*10);
            lunlun.push_back(x*10+1);
            q.push(x*10+1);
        }
        else if (x%10 == 9) {
            lunlun.push_back(x*10+8);
            q.push(x*10+8);
            lunlun.push_back(x*10+9);
            q.push(x*10+9);
        }
        else {
            lunlun.push_back(x*10+x%10-1);
            q.push(x*10+x%10-1);
            lunlun.push_back(x*10+x%10);
            q.push(x*10+x%10);
            lunlun.push_back(x*10+x%10+1);
            q.push(x*10+x%10+1);
        }
    }
    cout << lunlun[k-1] << endl;
    return 0;
}

Measured memory_bytes: 4600
#include<stdio.h>

int main(void) {
	int n,u,v,i,j,k,a[100][100];
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			a[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--;
			a[u][v] = 1;
		}
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (j) {
				printf(" ");
			}
			printf("%d", a[i][j]);
		}
		printf("\n");
	}
	return 0;
}


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

int main() {
  cout << fixed << setprecision(10);
  
  int N;
  cin >> N;
  double a;
  if (N%2 == 1) {
    cout << (double)(N/2+1)/N <<endl;
  }
  else {
    cout << (double)(N/2)/N <<endl;
  }
  
}


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

int  main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n)
	{
		cin >> a.at(i);
	}
	int cnt = 1;
	int i = 0;
	while(a[i] != 2)
	{
		if (a[i] != 2)
		{
			i = a[i] - 1;
			cnt++;
		}
		if (cnt > n)
		{
			cout << "-1\n"; return 0;
		}
	}
	cout << cnt << endl;
	return (0);
}


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

#define B

#ifdef B

int main(void)
{
	int sum;
		string str;
		vector<int> ans;
	while (true)
	{
		getline(cin, str);
		if (atoi(str.c_str()) == 0)
			break;
		sum = 0;
		for (size_t i = 0; i < str.size(); i++)
		{
			sum += str[i] - 0x30;
		}
		ans.push_back(sum);
	}
	for (auto a : ans) {
		cout << a << endl;
	}
	return 0;
}
#endif // B

Measured memory_bytes: 3164