akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
//    ifstream in("input.txt");
//    cin.rdbuf(in.rdbuf());

    unordered_map <ll,ll> num_match;
    num_match[1] = 2;
    num_match[2] = 5;
    num_match[3] = 5;
    num_match[4] = 4;
    num_match[5] = 5;
    num_match[6] = 6;
    num_match[7] = 3;
    num_match[8] = 7;
    num_match[9] = 6;
    ll dp_dig[10001] = {};

    ll n,m;
    cin >> n >> m;
    set <ll> cost_num_lis;
    vector <ll> num_lis;
    for (ll i=0;i<m;i++){
        ll p;
        cin >> p;
        num_lis.push_back(p);
        cost_num_lis.insert(num_match[p]);
    }
    for (auto itr = cost_num_lis.begin(); itr != cost_num_lis.end(); itr++){
        dp_dig[*itr] = 1;
    }
    for (ll i=1;i<=n;i++){
        ll cnt = 0;
        for (auto itr = cost_num_lis.begin(); itr != cost_num_lis.end(); itr++) {
            if(i-*itr >= 0){
                dp_dig[i] = max(dp_dig[i], dp_dig[i - *itr] + 1);
                cnt++;
            }
        }
        if(cnt == 0 and dp_dig[i] == 0){
            dp_dig[i] = INT32_MIN;
        }
    }
    sort(num_lis.begin(), num_lis.end());
    reverse(num_lis.begin(), num_lis.end());
    for (ll i=0;i<m;i++){
        ll u = num_match[num_lis[i]];
        while(n-u >= 0 and dp_dig[n-u] == dp_dig[n] - 1){// and dp_dig[n] > 1){
            cout << num_lis[i];
            n -= u;
        }
//        if(dp_dig[n] == 1 and u == n){
//            cout << num_lis[i];
//        }
    }
    cout << endl;


}




Measured memory_bytes: 384
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;


int n, m,k;
string s,t;

int main() {
	cin>>n>>k>>s;
	int ans = 0;
	for (int i = 0; i < n-1; i++)
	{
		if (s[i] == s[i + 1])ans++;
	}
	cout << min(n - 1, ans + 2 * k)<<endl;
}

Measured memory_bytes: 512
n = int(input())
keta = 1
end = 0
while True:
    order = n - end
    end += 26**keta
    if n <= end:
        break
    keta += 1
order -= 1
ans = []
for i in range(keta):
    ans.append(chr(order%26 + 97))
    order //= 26
ans.reverse()
print("".join(ans))

Measured memory_bytes: 61888
#include<iostream>
using namespace std;
int n,cnt,h[105],minf;
main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>h[i];
    minf=h[0];
    for(int i=0;i<n;i++){
        if(minf<=h[i])cnt++;
        if(minf<h[i])minf=h[i];
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vector<ll> a(n);
	unordered_map<ll, int> cnt;
	rep(i, n) cin >> a[i], cnt[a[i]]++;
	vector<ll> b;
	for(pair<ll, int> x : cnt){
		rep(i, x.se - (x.se & 1)) b.pb(x.fi);
	}
	if(b.size() < 4){
		cout << 0 << endl;
		return 0;
	}
	sort(all(b));
	reverse(all(b));
	cout << (ll)(b[0] * b[2]) << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main(void)
{
    long long int a,b,c,i,j,k,n;
    string s;
    cin >> s;

    if(s <= "2019/04/30") cout << "Heisei";
    else cout << "TBD";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;

    for (int a = 1; a <= 9; ++a) {
        for (int b = a; b <= 9; ++b) {
            if (n == a*b) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
fun main(args:Array<String>?): Unit {
    readLine()!!.trim().toInt()
    val num = readLine()!!.trim().split(' ').map(String::toInt).toIntArray()
    println(solve(num))
}
fun solve(num: IntArray): Int {
    val range = RangeSum(num)
    val memo = Array(num.size){i -> IntArray(num.size - i){j -> if (j == 0) 0 else -1}}
    fun sub(from: Int, to: Int): Int {
        if (memo[from][to - from] == -1){
            memo[from][to - from] = (from until to).map{mid -> sub(from, mid) + sub(mid + 1, to) + time(range[from .. mid], range[mid + 1 .. to])}.min()!!
        }
        return memo[from][to - from]
    }
    return sub(0, num.lastIndex)
}
fun time(a: Int, b: Int): Int {
    tailrec fun sub(a: Int, b: Int, increment: Int = 0, result: Int = 0): Int {
        return if (a + b + increment == 0) result else sub(a / 10, b / 10, (a % 10 + b % 10 + increment) / 10, result + (a % 10) * (b % 10) + increment)
    }
    return sub(a, b)
}
class RangeSum(num: IntArray) {
    private val sum = num.clone()
    init {
        for (i in 1 until sum.size) sum[i] += sum[i - 1]
    }
    operator fun get(range: IntRange): Int {
        return get(range.last) - get(range.first - 1)
    }
    private fun get(index: Int): Int {
        return if (index in sum.indices) sum[index] else 0
    }
}


Measured memory_bytes: 107560
#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++)
ll mod=1e9+7;

int main(){
  int h,w;
  cin>>h>>w;
  char c[h][w];
  rep(i,0,h){
    rep(j,0,w){
      cin>>c[i][j];
    }
  }
  ll dp[h+1][w+1];
  rep(i,0,w+1) dp[0][i]=0;
  rep(i,0,h+1) dp[i][0]=0;
  dp[0][1]=1;
  rep(i,0,h){
    rep(j,0,w){
      if(c[i][j]=='.'){
        dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1];
        dp[i+1][j+1]%=mod;
      }
      else{
        dp[i+1][j+1]=0;
      }
    }
  }
  cout<<dp[h][w];
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define forn for(int i=0;i<n;i++)
#define form for(int j=0;j<m;j++)
#define pb push_back
#define mp make_pair
#define sc second
#define f first
#define kek cout<<"\n"
#define all(v)        ((v).begin()), ((v).end())
#define pob pop_back()
const ll MOD=1e9+7;
const int INF=1e8;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int a,b;
  cin>>a>>b;
  if(a==b) puts("Yes");
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		boolean in = false;
		
		long t1,t2,a1,a2,b1,b2, f1, f2;
		if(!in)
		{
			t1 = sc.nextLong();
			t2 = sc.nextLong();
			a1 = sc.nextLong();
			b1 = sc.nextLong();
			a2 = sc.nextLong();
			b2 = sc.nextLong();
			f1 = (a1-a2)*t1;
			f2 = (b2-b1)*t2;
//			System.out.println(a1 + " " + a2);
		}
		else
		{
			long sf1 = sc.nextLong();
			long sf2 = sc.nextLong();
			f1 = sf1;
			f2 = sf2;
		}
		
		if(f1 < 0)
		{
			f1 *= -1;
			f2 *= -1;
		}
		
		long dis = f1;
		long bf = f2-f1;
//		System.out.println(f1 + " " + f2 + " " + bf);
		
		if(f1 == f2)
		{
			System.out.println("infinity");
			return;
		}
		
		long score = 0;
		if(dis > bf && bf > 0)
		{
			score += (dis/bf)*2;
			dis = dis%bf;
		}
		if(dis > 0 && bf > 0)
			score++;
		
		System.out.println(score);

	}

}


Measured memory_bytes: 25044
import sys

sys.setrecursionlimit(1000000)

import bisect
import math
import collections
import heapq


def solve(N, As):
    As.sort()
    ans = []
    while len(ans) < N - 1:
        k = As.pop()
        if len(ans) == 0:
            ans.append(k)
        else:
            ans.append(k)
            ans.append(k)

    while len(ans) > N - 1:
        ans.pop()
    return sum(ans)

# solve(4, [2,2,1,3])
# solve(6, [1,2,3,4,5,6])
# solve(5, [1,2,3,4,5])

if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))


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

int dp[110][10010];

int main(){
    int n,W;
    int weight[110],value[110];

    cin >>n>>W;
    for(int i=0;i<n;i++) cin >>value[i]>>weight[i];
    for(int i=0;i<=W;i++) dp[0][i]=0;

    for(int i=0;i<n;i++){
        for(int w=0;w<=W;w++){
            if(w>=weight[i]) dp[i+1][w] = max(dp[i][w], dp[i][w-weight[i]]+value[i]);
            else dp[i+1][w] = dp[i][w];
        }
    }
    cout <<dp[n][W]<<endl;
    
    return 0;
}


Measured memory_bytes: 7024
#include<stdio.h>

int selectionSort(int [], int);

int main(){
  int n,a[100],i,c;

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

  c = selectionSort(a, n);

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

int selectionSort(int a[], int n){
  int i,j,minj,temp,c=0;

  for(i = 0; i <= n-1; i++){
    minj = i;
    for(j = i; j <= n-1; j++){
      if(a[j] < a[minj]) minj = j;
    }
    if(i != minj) c++;
    temp = a[i];
    a[i] = a[minj];
    a[minj] = temp;
  }
  return c;
}



Measured memory_bytes: 2144
def solve(A, B, C, X):
    r = 0
    for i in range(0, A + 1):
        for j in range(0, B + 1):
            for k in range(0, C + 1):
                t = i * 500 + j * 100 + k * 50
                if t == X:
                    r += 1
    return r

A = int(input())
B = int(input())
C = int(input())
X = int(input())

if __name__ == '__main__':
    print(solve(A, B, C, X))


Measured memory_bytes: 3060
//(0,0)->(4000,4000)
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

const int N=2e5+5;
const int M=4005;
const int MOD=1e9+7;
int a[N],b[N];
int f[M][M];
int c[M*2][M];

int ksm()
{
	int a=1;
	int t=2;
	int n=MOD-2;
	while(n>0)
	{
		if(n%2==1){
			a=(1ll*a*t)%MOD;
		}
		t=(1ll*t*t)%MOD;
		n/=2;
	}
	return a;
}
void init()
{
	memset(c,0,sizeof(c));
	c[0][0]=1;
	for(int i=1;i<=8000;i++){
		c[i][0]=1;
		for(int j=1;j<=min(4000,i);j++){
			c[i][j]=(c[i][j]+c[i-1][j-1])%MOD;
			c[i][j]=(c[i][j]+c[i-1][j])%MOD;
		}
	}
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
	}
	init();
	memset(f,0,sizeof(f));
	for(int i=1;i<=n;i++){
		f[2000-a[i]][2000-b[i]]++;
	}
	for(int i=0;i<=4000;i++){
		for(int j=0;j<=4000;j++){
			if(i-1>=0){
				f[i][j]=(f[i][j]+f[i-1][j])%MOD;
			}
			if(j-1>=0){
				f[i][j]=(f[i][j]+f[i][j-1])%MOD;
			}
		}
	}
//	printf("qwq");
	int ans=0;
	for(int i=1;i<=n;i++){
		ans=(ans+f[2000+a[i]][2000+b[i]])%MOD;
	}
	for(int i=1;i<=n;i++){
		ans=(ans+MOD-c[a[i]+a[i]+b[i]+b[i]][a[i]+a[i]])%MOD;
	}
	int p=ksm();
	printf("%d",(1ll*ans*p)%MOD);
	return 0;
}

Measured memory_bytes: 189696
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  ll n, c = 0, ans = 0, num[100002];
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);
  rep(i, n) sort(all(s.at(i)));
  sort(all(s));
  for(int i = 1; i < 100000; i++) num[i] = num [i-1] + i;
  for(int i = 1; i < n; i++) {
    if(s.at(i) == s.at(i-1))c++; 
    else {
      ans += num[c];
      c = 0;
    }
  }
  ans += num[c];
  cout << ans;
}

Measured memory_bytes: 8064
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/arc064/editorial.pdf
・最終的には両端にある2種類の文字か、両端が同じ文字ならそれとそれ以外のもう1文字以外は残らない。
・なので残った文字数の偶奇は分かる。
・そこから総ターン数が分かるので、その偶奇で勝敗が分かる。
"""

import sys
from collections import deque, Counter, defaultdict
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, product, combinations, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial

def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
N = len(S)

if S[0] == S[-1]:
    if N % 2 == 0:
        print('First')
    else:
        print('Second')
else:
    if N % 2 == 0:
        print('Second')
    else:
        print('First')


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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  string O,E;
  cin >> O;
  cin >> E;
  
  string ans = "";
  for(int i = 0; i < O.size(); i++){
    ans += O[i];
    if(i < E.size()) ans += E[i];
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	int		para[100][100] = {0}, line[100] = {0}, num, x, y, i, j, ans, product;
	char	pattern;

	scanf("%d %d" , &y, &x);
	
	for(i=0; i<y; i++){
		for(j=0; j<x; j++){
			scanf("%d" , &num);
			para[i][j] = num;
		}
	}
	for(i=0; i<x; i++){
		scanf("%d" , &num);
		line[i] = num;
	}
	for(i=0; i<y; i++){
		ans = 0;
		for(j=0; j<x; j++){
			product = (para[i][j] * line[j]);
			ans += product;
		}
		printf("%d\r\n", ans);
	}
		return 0;	 
}

Measured memory_bytes: 648
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string s1,s2;
    cin>>s1>>s2;
    ll ans=0;
    for (int i = 0; i < 3; ++i)
    {
        if(s1[i]==s2[i])
        {
            ans++;
        }
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 384
n,m = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(m)]
a = sorted(a,key=lambda x:x[1])
ans = [0]
for a_ in a:
    for i,k in enumerate(ans):
        if a_[0]<k and a_[1]>=k:
            break
        elif i==len(ans)-1:
            ans.append(a_[1])
            break
print(len(ans)-1)

Measured memory_bytes: 65752
#include <bits/stdc++.h>
using namespace std;
// がっつり解こうとするとかなり時間がかかる。
// ロジックも正しいか怪しい・・・。
// DP法で解く。
// Dp[i][j][k]

int main(){

  int H,W;
  int A[100][100], B[100][100], D[100][100];
  bool DP[100][100][10000]={false};

  cin >> H >> W;
  for(int i = 0;i<H;i++){
    for(int j = 0;j<W;j++){
      cin >> A[i][j];
    }
  }
  for(int i = 0;i<H;i++){
    for(int j = 0;j<W;j++){
      cin >> B[i][j];
      D[i][j] = abs(A[i][j]-B[i][j]);
    }
  }

  int ans;
  DP[0][0][D[0][0]] = true;

  for(int diagnal=0;diagnal<(H+W);diagnal++){
    for(int i=0;i<=min(diagnal,H-1);i++){
      int j = diagnal-i;
      if(i==0 and j==0) continue;
      if(i>=H or j>=W) continue;
      for(int k=0;k<10000;k++){
        if(i==0){
          DP[i][j][k+D[i][j]] |= (DP[i][j-1][k]);
          DP[i][j][abs(k-D[i][j])] |= (DP[i][j-1][k]);
        } else if (j==0) {
          DP[i][j][k+D[i][j]] |= (DP[i-1][j][k]);
          DP[i][j][abs(k-D[i][j])] |= (DP[i-1][j][k]);
        } else {
          DP[i][j][k+D[i][j]] |= (DP[i-1][j][k] or DP[i][j-1][k]); 
          DP[i][j][abs(k-D[i][j])] |= (DP[i-1][j][k] or DP[i][j-1][k]);
        }        
      }
    }
  }
  for(int k=0;k<10000;k++){
    if(DP[H-1][W-1][k]){
      ans = k;
      break;
      }
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 98048
#include<iostream>
#include<vector>
#include<string>

enum InkSize
{
	small=0,
	middle,
	large
};

InkSize Next(int x)
{
	if(x<0 || 2<x)
	{
		std::cout << "Input Error.\n";

		return small;
	}

	const InkSize ink[3]=
	{
	small,
	middle,
	large
	};

	return ink[x];
}

struct Board
{
	Board(int a)
	{
		for(size_t i=0; i<m_element; ++i)
		{
			for(size_t j=0; j<m_element; ++j)
			{
				m_map[j][i] = a;
			}
		}
	}
	
	void DropInk(int x, int y, InkSize ink)
	{
		const int inkSet[3][5][5]=
		{
			{//small
				{0,0,0,0,0},
				{0,0,1,0,0},
				{0,1,1,1,0},
				{0,0,1,0,0},
				{0,0,0,0,0},
			},
			{//middle
				{0,0,0,0,0},
				{0,1,1,1,0},
				{0,1,1,1,0},
				{0,1,1,1,0},
				{0,0,0,0,0},
			},
			{//large
				{0,0,1,0,0},
				{0,1,1,1,0},
				{1,1,1,1,1},
				{0,1,1,1,0},
				{0,0,1,0,0},
			}
		};

		for(size_t i=0; i<5; ++i)
		{
			for(size_t j=0; j<5; ++j)
			{
				if( y-2+i<0 || x-2+j<0 || y-2+i>9 || x-2+j>9 )
				{
					continue;
				}

				m_map[y-2+i][x-2+j] += inkSet[ink][i][j];
			}
		}
	}

	int CountNonInkedCell()
	{
		int count=0;

		for(size_t i=0; i<m_element; ++i)
		{
			for(size_t j=0; j<m_element; ++j)
			{
				if(m_map[i][j]==0)
				{
					++count;
				}
			}
		}

		return count;
	}

	int MostInkedCell()
	{
		int max=0;

		for(size_t i=0; i<m_element; ++i)
		{
			for(size_t j=0; j<m_element; ++j)
			{
				if(m_map[i][j]>max)
				{
					max=m_map[i][j];
				}
			}
		}

		return max;
	}

	enum { m_element = 10 };

	int m_map[m_element][m_element];
};

int main()
{
	Board boad1(0);

	int x=0, y=0, inkSize=0;

	char c;

	while(std::cin >> x >> c >> y >> c >> inkSize)
	{
		boad1.DropInk(x,y,Next(inkSize-1));
	}

	std::cout << boad1.CountNonInkedCell() << '\n' << boad1.MostInkedCell() << '\n';

}

Measured memory_bytes: 1156
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

l = 0
r = 10**9

while (r-l > 1)
    x = (r+l)/2

    cnt = 0 
    for i in 0...n
        cnt += (a[i]-1) / x
        break if cnt > k
    end

    if(cnt <= k)
        r = x
    else
        l = x
    end
end

puts r


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

int main()
{
    int K,S;
    int ans=0;
    cin>>K>>S;
    for(int X = 0;X<=K; X++){
        for(int Y=0; X+Y<=S; Y++){
            int Z = S-(X+Y);
            if(Y<=K&&Z<=K)ans++;
        }
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define p pair<int, int>
using namespace std;

int par[100];
int _rank[100];
int _size;

int init(int n){
  _size = n;
  for(int i = 0; i < n; i++){
    par[i] = i;
    _rank[i] = 1;
  }
}

int find(int x){
  if(par[x] == x) return x;
  return par[x] = find(par[x]);
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) return;
  if(_rank[x] > _rank[y]) swap(x, y);
  par[y] = x;
  _rank[x] += _rank[y];
  _size--;
}

bool same(int x, int y){
  return find(x) == find(y);
}

int main(){

  int n, m;
  cin >> n >> m;
  vector<p> v;
  for(int i = 0; i < m; i++){
    int s, t;
    cin >> s >> t;
    s--; t--;
    v.push_back(p(s, t));
  }
  int sum = 0;
  for(int i = 0; i < m; i++){
    init(n);
    for(int j = 0; j < m; j++){
      if(i == j) continue;
      if(!same(v[j].first, v[j].second)){
        unite(v[j].first, v[j].second);
      }
    }
    if(_size != 1) sum++;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
int dpp[100010],dpc[100010];
int32_t main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n,k,x;
    cin>>n>>k;
    dpc[0] = 1;
    for(int i=1;i<=n;i++)
    {
        int sm = 0;
        swap(dpp,dpc);
        cin>>x;
        for(int j=0;j<=k;j++)
        {
            sm+=dpp[j];
            sm%=mod;
            dpc[j] = sm;
            if(j>=x)
            {
                sm-=dpp[j-x];
                sm+=mod;
                sm%=mod;
            }
        }
    }
    cout<<dpc[k];
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, a, b;
    cin >> x >> a >> b;
    x -= a;
    int ans = x % b;
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
typedef  long long ll;
using namespace std;

int main(void) {
	ll N, K;
    cin >> N >> K;
    int ans = 0;
    while (N > 0)
    {
        ans++;
        N = N / K;
    }
    
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ab_list = []

for _ in range(M):
  a, b = map(int, input().split())
  ab_list.append((a, b))

ab_list.sort(key=lambda x:x[1])

b = -1
ans = 0
for tupl in ab_list:
  if b == -1:
    ans += 1
    b = tupl[1]
  elif b == tupl[1]:
    continue
  elif b != tupl[1]:
    if tupl[0] <= b-1:
      continue
    else:
      ans += 1
      b = tupl[1]
print(ans)

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

int main() {
  int H, W, A = 0, B;
  cin >> H >> W;
  vector<vector<char>> S(H,vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S.at(i).at(j);     
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S.at(i).at(j) == '#') {
        break;
      }
      else if (j == W - 1) {
        for (int k = 0; k < W; k++) {
          S.at(i).at(k) = 'a';
        }
      }
    }
  }
  for (int i = 0; i < W; i++) {
    for (int j = 0; j < H; j++) {
      if (S.at(j).at(i) == '#') {
        break;
      }
      else if (j == H - 1) {
        for (int k = 0; k < H; k++) {
          S.at(k).at(i) = 'a';
        }
         A += 1;
      }
    }
  }
  B = A;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S.at(i).at(j) == 'a') {
        continue;
      }
      cout << S.at(i).at(j);
      B += 1;
      if (B == W) {
        cout << endl;
        B = A;
      }
    }
  }
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#include<string>
#include<set>

using namespace std;

#define pb push_back
#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    int l = 0, r = 1e18;
    while(r - l > 1){
        int mid = (r + l) / 2, ans = 0;
        for (int i = 0; i < n; i++){
            ans += (v[i] - 1) / mid;
        }
        if (ans <= k) r = mid;
        else l = mid;
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 4752
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
count = 0
0.upto(n-1) do |i|
  if a[i]>b[i]
    count+=b[i]
    a[i]-=b[i]
    b[i]=0
  else
    count+=a[i]
    b[i]-=a[i]
    a[i]=0
    if a[i+1] > b[i]
      count+=b[i]
      a[i+1]-=b[i]
      b[i]=0
    else
      count+=a[i+1]
      b[i]-=a[i+1]
      a[i+1]=0
    end
  end
end
puts count


Measured memory_bytes: 24704
N, M = map(int,input().split())
a = set()
for _ in range(M):
    A = int(input())
    a.add(A)
dp = [0 for _ in range(N + 2)]
dp[0] = 1
for i in range(N):
    if i in a:
        continue
    dp[i + 1] += dp[i]
    dp[i + 2] += dp[i]
    if dp[i + 1] > 1000000007:
        dp[i + 1] %= 1000000007
        dp[i + 2] %= 1000000007
print(dp[N] % 1000000007)

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

using lli = long long int;
template <typename T>
bool chmax(T& a, T b) {
    if (b > a) {
        a = b;
        return true;
    }
    return false;
}

lli n, w;
std::vector<std::pair<lli, lli>> vec;
std::vector<std::vector<lli>> dp;


int main() {
    std::cin >> n >> w;
    vec.assign(n+1, {0, 0});
    for (lli i = 0; i < n; i++) {
        //std::cin >> vec[i].first >> vec[i].second;
        std::cin >> vec[i+1].first >> vec[i+1].second;
    }
    dp.assign(n+1, std::vector<lli>(w+1, 0));

    for (lli i = 1; i <= n; i++) {
        for (lli p = 0; p <= w; p++) {
            if (p >= vec[i].first) {
                chmax(dp[i][p], dp[i-1][p]);
                chmax(dp[i][p], dp[i-1][p-vec[i].first] + vec[i].second);
            }
            else {
                chmax(dp[i][p], dp[i-1][p]);
            }
        }
    }
    std::cout << dp[n][w] << std::endl;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pri pair<int,int>
#define mpi map<int,int>
#define prl pair<ll,ll>
#define mp make_pair
#define mpl map<ll,ll>
#define umpl unordered_map<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 2e18
#define EPS 1e-3
#define PI 3.1415926535897932385
const double h = 1e-6;
const int MAX_  = 100005;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////

int main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,w;  cin>>n>>w;
    ll wg[n],val[n];
    f(n)cin>>wg[i]>>val[i];
    ll dp[n+1][w+1];  memset(dp,0,sizeof(dp));
    for(int i =1;i<=n;i++)
    {
        for(int j =1;j<=w;j++)
        {
            if(wg[i-1] > j)
            {
                dp[i][j] = dp[i-1][j];
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],val[i-1]+dp[i-1][j-wg[i-1]]);
            }
            
        }
    }
    cout << dp[n][w] << "\n";
    return 0;
 }

Measured memory_bytes: 79232
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long k = sc.nextLong();

        long sum = 0;
        if (k <= a) {
            sum += 1 * k;
        } else if (k > a && k <= a + b) {
            sum += 1 * a;
        } else if (k > a + b) {
            sum += 1 * a - 1 * (k - a - b);
        }

        System.out.println(sum);
    }
}

Measured memory_bytes: 35732
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int gcd(int x, int y) {
	if (!y)return x;
	return gcd(y, x % y);
}
int a, b;
signed main() {
	cin >> a >> b;
	int c = gcd(a, b);
	int ans = 0;
	for (int i = 2; i * i <= c; i++) {
		if (c % i == 0)ans++;
		while (c % i == 0)c /= i;
	}
	if (c != 1)ans++;
	cout << ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n,p;
    while(cin >> n >> p && n){
        int const P = p;
        int ans = -1;
        int k = 0;
        int have[55] = {};
        int cup = p;
        while(1){
            if(cup){
                have[k]++;
                cup--;
                if(cup == 0){
                    if(have[k] == P){
                        ans = k;
                        goto END;
                    }
                }
            } else {
                cup += have[k];
                have[k] = 0;
            }
            k++;
            k %= n;
        }
    END:;
        cout << ans << endl;
    }
}

Measured memory_bytes: 1156
#include <cstdio>
#include <algorithm>

using namespace std;

#define INF 100000

int d[10][10];

int main(){
    while(true){
        for(int i = 0; i < 10; i++){
            for(int j =0; j < 10; j++){
                if(i == j) d[i][j] = 0;
                else d[i][j] = INF;
            }
        }
        int n;
        scanf("%d",&n);
        if(n==0)break;
        for(int i = 0; i < n; i++){
            int a,b,c;
            scanf("%d %d %d",&a, &b, &c);
            d[a][b] = d[b][a] = c;
        }
        for(int k = 0; k < 10; k++){
            for(int i =0; i < 10; i++){
                for(int j = 0; j < 10; j++){
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        int ans = 1000000;
        int city = 100;
        for(int i =0; i < 10; i++){
            int tmp = 0;
            for(int j = 0; j < 10; j++){
                if(d[i][j] != INF)tmp += d[i][j];    
            }
            // 問題に記述されていない都市番号のtmpが0と最小になるため除外
            if(ans > tmp && tmp != 0){
                ans = tmp;
                city = i;
            }
        }
        printf("%d %d\n", city, ans);
        // for(int i =0; i < 10; i++){
        //     for(int j = 0; j < 10; j++){
        //         printf("%d ", d[i][j]);
        //     }
        //     printf("\n");
        // }
    }
    return 0;
} 


Measured memory_bytes: 2748
#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>;

void Main()
{
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> l(Q);
  vector<int> r(Q);
  rep(i,Q) {
    cin >> l[i] >> r[i];
    l[i]--; r[i]--;
  }
  //vector<int> acPoints;
  vector<int> cumulativeSum;
  //string S_new = "";
  int cnt = 0;
  for (int j = 0; j < S.size()-1; j++) {
    if (S[j] == 'A' && S[j+1] == 'C') {
      //S_new += "ZZ";
      cumulativeSum.push_back(++cnt);
      cumulativeSum.push_back(++cnt);
      ++j;
    } else {
      //S_new += S[j];
      cumulativeSum.push_back(cnt);
    }
  }
  cumulativeSum.push_back(cnt);
  //if (j == S.size()-2) S_new += S[S.size()-1];

  rep(i,Q) {
    cout << cumulativeSum[r[i]]/2 - cumulativeSum[l[i]]/2 << endl;
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

Measured memory_bytes: 2248
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int q = a / b;
		int r = a % b;
		double f = 1.0 * a / b;
		
		System.out.print(q + " " + r + " ");
		System.out.printf("%.5f", f);
	}
}


Measured memory_bytes: 26440
#include<iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

#define LOCAL  1
#define UPLOAD 2

using namespace std;
typedef long long ll;

template <class T = ll>
T input(){T x;cin >> x;return x;}

template <class T>
void output(T x){cout << x << endl;}

//#define int long log

#define debug(x) cerr << #x<< ": " << x<< '\n';

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

  int N = input();
  int D = input();

  output(ceil((float)N / (D*2+1)));


  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <limits>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 100005
using namespace std;

int main() {
  ull n;
  cin >> n;
  if(n%2 == 0) {
    cout << n << endl;
  }else {
    cout << n*2 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
#include <chrono>
#include<unordered_map>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 1e5 + 10;
const int MS = 1 << 18;
const int LH = 10;

LL dp[1024][MR];

PII t[MS];
int h[MS];

int main()
{
	int N;
	scanf("%d", &N);
	FORQ(i, 1, N)
		scanf("%d%d", &t[i].first, &t[i].second);
	// wylicz dp dla roota, h[root] == 0
	FOR(i, t[1].second, MR)
		dp[1][i] = t[1].first;
	FORQ(v, 2, N)
	{
		// wylicz h
		int par = v / 2;
		h[v] = h[par] + 1;
		if (h[v] < LH)
		{
			// wylicz dp do meet in the middle
			FOR(i, 1, t[v].second)
				dp[v][i] = dp[par][i];
			FOR(i, t[v].second, MR)
				dp[v][i] = max(dp[par][i], dp[par][i - t[v].second] + t[v].first);
		}
	}

	// jedz query
	int Q;
	scanf("%d", &Q);
	REP(xxx, Q)
	{
		int v, L;
		scanf("%d%d", &v, &L);

		// zobacz, czy od razu mamy wynik
		if (h[v] < LH)
		{
			printf("%lld\n", dp[v][L]);
			continue;
		}

		// wez kazdy podzbior rodzicow o glebokosci >= LH
		vector<int> par;
		while (h[v] >= LH)
		{
			par.push_back(v);
			v >>= 1;
		}

		// teraz w v mamy rodzica o h[v] < LH i tam mamy wyliczone dp
		LL res = 0;
		REP(mask, 1 << par.size())
		{
			int W = 0;
			LL V = 0;
			REP(i,par.size())
				if (mask&(1 << i))
				{
					V += t[par[i]].first;
					W += t[par[i]].second;
					if (W > L)
						break;
				}

			if (W <= L)
				res = max(res, V + dp[v][L - W]);
		}

		printf("%lld\n", res);
	}

	return 0;
}

// FOR GNU C++ use the following pattern:
// Uncomment the code below and change your main into main2
// It does not build in MS C++
// But it does increase the stack size from 256 MB on CF and uses GNU C++

//#include <Processthreadsapi.h>
//#include <iostream>
//#include <Synchapi.h>
//#include <windows.h>
//#include <process.h>
//
//DWORD WINAPI MyThreadFunction(LPVOID lpParam) {
//    main2(nullptr);
//    return 0;
//}
//int main() {
//    auto h = CreateThread(nullptr, 1024 << 20, MyThreadFunction, nullptr, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr);
//    WaitForSingleObject(h, INFINITE);
//}

Measured memory_bytes: 805552
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {

  int N, K;
  cin >> N >> K;

  vector<int> A(N + 1);
  map<int, int> m;

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

  int town = 1;
  int s, e;
  int tmp;

  m[1] = 0;
  town = A[1];

  for(int i = 1; i <= N; i++){
    if(m.find(town) == m.end()){
      m[town] = i;
      town = A[town];
    }else{
      s = m.find(town)->second;
      e = i;
      tmp = town;
      break;
    }
  }

  int loop;
  if(K <= s){
    town = 1;
    for(int i = 1; i <= K; i++){
      town = A[town];
    }
  }else if(K <= e){
    town = tmp;
    for(int i = 1; i <= K - s; i++){
      town = A[town];
    }
  }else{
    town = tmp;
    for(int i = 1; i <= (K - s) % (e - s); i++){
      town = A[town];
    }
  }  
  cout << town << endl;
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n,m;
    while (cin >> n >> m) {
        vvi v(m, vi());
        for (int i = 0; i < m; i++) {
            int k; cin >> k;
            v[i] = vi(k);
            for (int j = 0; j < k; j++) {
                cin >> v[i][j]; v[i][j]--;
            }
        } 
        vi p(m);
        for (int i = 0; i < m; i++) {
            cin >> p[i];
        }
        int ans = 0;
        for (int mask = 0; mask < (1<<n); mask++) {
            int ok = 1;
            for (int i = 0; i < m; i++) {
                int on = 0;
                for (auto x : v[i]) {
                    if (mask & (1<<x)) {
                        on++;
                    }
                }
                if (on%2 != p[i]) {
                    ok = 0;
                }
            }
            ans += ok;
        }
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
dic = {}
for _ in range(n):
    s = list(input())
    k = ''.join(sorted(s))
    if k in dic:
       dic[k] += 1
    else:
       dic[k] = 1
ans = sum([v * (v - 1) // 2 for v in dic.values()])
print(ans)

Measured memory_bytes: 66648
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	
	if(a>=b&&a>=c)
	printf("%d",b+c);
	
	else if(b>=a&&b>=c)
	printf("%d",a+c);
	
	else
	printf("%d",a+b);
	
	return 0;
}



Measured memory_bytes: 1700
import sys
S = input()
A = ''
input()
key = 1

for i in sys.stdin:
    if i[0] == '0':
        break

    if i[0] == '1':
        key = -key
    
    elif key == 1:
        if i[2] == '1':
            A = A + i[4]
        else:
            S = S + i[4]

    else:
        if i[2] == '2':
            A = A + i[4]
        else:
            S = S + i[4]

ans = A[::-1] + S
print(ans[::key])


Measured memory_bytes: 9852
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

int main(){
    map<ll,int> M;
    ll N;
    cin>>N;
    vector <ll> A(N);
    rep(i,0,N)cin>>A[i];
    bool ans=true;

    rep(i,0,N){
        if(M[A[i]]==1){
            ans=false;
        }
        else{
            M[A[i]]=1;
        }
    }
    if(ans){
        cout<<"YES";
    }
    else cout<<"NO";
    return 0;
}

Measured memory_bytes: 14820
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb(t) push_back(t)
#define pt(num) cout << num << "\n"
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;

ll N, M;

int main(void) {
    cin >> N >> M;
    ll i;
    set<ll> st;
    ll ba[MAX];
    
    
    for(i=0; i<N; i++) ba[i]=1;
    
    st.insert(0);
    for(i=0; i<M; i++) {
        ll x, y;
        cin >> x >> y;
        x--; y--;
        
        ba[x]--;
        ba[y]++;
        
        auto it=st.find(x);
        if(it!=st.end()) st.insert(y);
        
        if(ba[x]==0) st.erase(x);
    }
    
    pt(st.size());
    
}


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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;

    rep(i, 10) rep(j, 10) if (i * j == n) {
        cout << "Yes" << endl;
        return 0;
    } 

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
a,b = map(int,input().split())
s = str(input())

if len(s)== a+b+1 \
    and s[a:a+1] =='-' \
    and str.isdecimal(s[0:a]) \
    and str.isdecimal(s[a+1:a+1+b]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <iomanip>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin>>n;
    cout<<(n%2==0?n/2:n/2+1)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long

struct ab {
    ll A;
    ll B;
};

bool compareDiff(ab a, ab b) {
    return (a.A + a.B) > (b.A + b.B);
}

using namespace std;
int main(int argc, const char * argv[]) {
    ll N;
    vector<ab> AB;
    
    cin>>N;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll a, b;
        cin>>a>>b;
        ab x;
        x.A = a;
        x.B = b;
        AB.push_back(x);
    }
    sort(AB.begin(), AB.end(), compareDiff);
    for (int i = 0; i < N; i++) {
        if ((i & 1) == 0) {
            ans += AB[i].A;
        } else {
            ans -= AB[i].B;
        }
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define fi first
#define se second
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define MOD 1000000007
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 200009
#define M 2000009
#define mid(l, r) l + (r - l) / 2
#define vec vector
#define vecl vector<ll>
#define umap unordered_map<ll, ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
#define int long long
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}







void test_case()
{
    

    ll n,k;
    cin >> n >> k;
    vector<ll> a(n),s(n+1);
    map<ll,ll> m;


    rep(i,n){
        cin >> a[i];
        s[i+1]=s[i]+a[i];
    }


    for(ll i=1;i<=n;i++){
        s[i]-=i;
        s[i]%=k;
    }


    ll ans=0;

    
    for(ll i=0;i<=n;i++){
        ans+=m[s[i]];
        if(i>=k-1) m[s[i-k+1]]--;
        m[s[i]]++;
    }
    cout << ans << endl;




    
    
    



}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(20);

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

    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

Measured memory_bytes: 18776
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val Array(h, w) = sc.nextLine.split(" ").map(_.toInt)
  val seqs = Seq.fill(h)(sc.nextLine.split("").toSeq.filter(_.nonEmpty).zipWithIndex).zipWithIndex
  
  def findOpt[T](index: Int, seq: Seq[(T, Int)]): Option[T] = {
    import scala.util.Try
    Try(seq.map{case (t, index) => t}.apply(index)).toOption
  }
  
  val results = seqs.map{ case (seq, seqIndex) =>
    val preSeq = findOpt(seqIndex - 1, seqs)
    val curSeq = findOpt(seqIndex, seqs)
    val nextSeq = findOpt(seqIndex + 1, seqs)

    seq.map { case (e, eIndex) =>
      if (e == "." ) true
      else Seq(preSeq.flatMap(findOpt(eIndex, _)),
              curSeq.flatMap(findOpt(eIndex - 1, _)),
              curSeq.flatMap(findOpt(eIndex + 1, _)),
              nextSeq.flatMap(findOpt(eIndex, _))
              ).exists(_.contains("#"))
    }
  }.flatten
  
  println(if (results.forall(_ == true)) "Yes" else "No")
}

Measured memory_bytes: 32844
import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;


class Main {
	static Map<Integer, Integer> values = new HashMap<> ();
	
	static int Fibonacci (int n) {
		
		if (n == 0 || n == 1) return 1;
		
		Integer m = values.get(n);
		if (m != null ) return m;
		
		m = Fibonacci(n - 1) + Fibonacci(n - 2);
		values.put(n, m);
		return m;
		
	}
	
	public static void main (String[] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		n = Fibonacci (n);
		scan.close();	
		System.out.println(n);
	}
}



Measured memory_bytes: 26236