akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素


int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    map<int,ll> ma;
    rep(i,N){
        cin>>A[i];
        ma[A[i]]++;
    }
    ll sum=0;
    for(pair<int,ll> p : ma){
        sum+=p.S*(p.S-1)/2;
    }
    rep(i,N){
        ll ans=sum-(ma[A[i]]-1);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 11864
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

H,W,A,B = map(int, input().split())

for h in range(H):
    if h>=B:
        temp = "1"*A
        temp += "0"*(W-A)
    else:
        temp = "0"*A
        temp += "1"*(W-A)
    print(temp)

Measured memory_bytes: 3956
#include <iostream>
using namespace std;
int main(void)
{
	int A, B; cin >> A >> B;
	if (A == B)cout << "Draw" << endl;
	else {
		if (A == 1)cout << "Alice" << endl;
		else if (B == 1)cout << "Bob" << endl;
		else {
			if(A>B)cout << "Alice" << endl;
			else cout << "Bob" << 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 pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll n, m, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m >> k;
    erep(i, 0, n) {
      erep(j, 0, m) {
        if (i * (m - j) + j * (n - i) == k) {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fill(x,c) memset(x,c,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int SIZE = 1e6+10;
ll a[SIZE];
int main() {
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll m,n;
	cin>>n>>m;
	if(m>n)swap(m,n); 
	
	string res;
	rep(i,0,n)res+=('0'+m);
	cout<<res;
  	return 0;
}


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

int main() {
	double a, b, c, d, e, f, x, y;
	while (cin >> a >> b >> c >> d >> e >> f) {
		double w = 1.0 / (a*e - b*d);
		double x = w*(e*c - b*f);
		double y = w*(-d*c + a*f);
		if (x == 0) x = 0;
		if (y == 0) y = 0;
		printf("%.3f %.3f\n", x, y);
	}
	return 0;
}

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

int main(){
    int N, X, L, i, dist = 0, times = 1;

    cin >> N >> X;
    for(i = 0; i < N; i++){
        cin >> L;
        dist += L;
        if(dist <= X)times++;
        if(dist > X)break;
    }
    cout << times << endl;
}

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

int main(){
	int N;
	cin >> N;
	
	vector<ll> A(N);
	rep(i,N){
		cin >> A[i];
	}
	
	ll sum = 0;
	
	vector<ll> ans(N);
	
	rep(i,N){
		sum += A[i];
	}
	
	ans[0] = sum;
	
	rep(i,N/2){
		ans[0] -= 2*A[2*i+1];
	}
	
	rep(i,N-1){
		ans[i+1] = 2*A[i] - ans[i];
	}
	
	rep(i,N){
		cout << ans[i] << endl;
	}
	
	
	
}



Measured memory_bytes: 2944
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}
			int m = scan.nextInt() - 2*n;
			char[] ch = (scan.next()).toCharArray();
			int count = 0;
			for(int i = 0;i < m;i++){
				if(ch[i] == 'I'){
					for(int j = 0;j < n;j++){
						if(ch[i+1+2*j] != 'O' || ch[i+2*(j+1)] != 'I'){
							break;
						}else if(j == n-1){
							count++;
							i += 1;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int a, b, c, d, e, n, m, k;
string s, t, r;
char c1, c2, c3;

int A[200005];
int B[200005];
int C[200005];

int main() {
	cin >>a;
  cout <<a+a*a+a*a*a<<endl;
	return 0;
}

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

int main()
{
	long long n,m,sum=0;
	cin>>n>>m;
	if(n<m)
	{
		sum+=n;
		sum+=(m-n*2)/4;
	}
	else
		sum+=m/2;
	cout<<sum;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cfloat>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <iomanip>

using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
// #define req(j, n) for (ll j = 1; j < (n+1); j++)
// #define rer(k, n) for (ll k = 1; k < (n+1); k++)



vector<string> BubbleSort(vector<string> card, int N) {
    for (int i = 0; i < N; i++) {
        for (int j = N-1; j > i; j--) {
            if (card[j][1] < card[j-1][1]) {
                swap(card[j], card[j-1]);
            }
        }
    }
    return card;
}


vector<string> SelectionSort(vector<string> card, int N) {
    int minj;
    int j;
    for (int i = 0; i < N; i++) {
        minj = i;
        for (int j = i; j < N; j++) {
            if (card[j][1] < card[minj][1]) {
                minj = j;
            }
        }
        swap(card[i], card[minj]);
    }
    return card;
}


bool isStable(vector<string> in, vector<string> out, int N) {
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            for (int a = 0; a < N; a++) {
                for (int b = a+1; b < N; b++) {
                    if (in[i][1] == in[j][1] && in[i] == out[b] && in[j] == out[a]) {
                        return false;
                    } else {
                        continue;
                    }
                }
            }
        }
    }
    return true;
}


int main()
{
    int N;
    cin >> N;
    vector<string> card(N);
    vector<string> bubble_card(N);
    vector<string> select_card(N);
    rep(i,N) {
        cin >> card[i];
    }
    bubble_card = BubbleSort(card, N);
    rep(i,N) {
        if (i<N-1) {
            cout << bubble_card[i] << " ";
        } else {
            cout << bubble_card[i] << endl;
        }
    }
    bool judge;
    judge = isStable(card, bubble_card, N);
    if (judge == true) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
    select_card = SelectionSort(card, N);
    rep(i,N) {
        if (i<N-1) {
            cout << select_card[i] << " ";
        } else {
            cout << select_card[i] << endl;
        }
    }
    judge = isStable(card, select_card, N);
    if (judge == true) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
#define lg 18
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    cin>>n;
    int arr[n];
    rep(i,0,n)cin>>arr[i];
    ll pre[n+1];pre[0]=0;
    rep(i,1,n+1)pre[i]=pre[i-1]+arr[i-1];
    ll dp[n][n];

    int len,k;
    rep(len,1,n+1)
    {
        rep(i,0,n-len+1)
        {
            j=i+len-1;
            if(len==1) dp[i][j]=0;
            else if(len==2) dp[i][j]=arr[i]+arr[j];
            else
            {   
                dp[i][j]=LONG_MAX;
                rep(k,i,j)
                {
                    dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]);
                }
                dp[i][j]+=pre[j+1]-pre[i];
            }
        }
    }
    cout<<dp[0][n-1];

    return 0;
}



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

int time_count(int x) {
  if (x == 0) return 1;
  int mod = __builtin_popcount(x);
  x %= mod;
  return time_count(x) + 1;
}

int MOD(int base, int mod) {
  if (base < 0) {
    for (int i = 1; ; i++) {
      base += i * mod;
      if (base >= 0) {
        break;
      }
    }
  }
  return base % mod;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  assert((int) s.size() == n);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') cnt++;
  }
  if (cnt == 0) {
    for (int i = 0; i < n; i++) {
      cout << 1 << '\n';
    }
    return 0;
  }
  if (cnt == 1) {
    if (s[n - 1] == '1') {
      for (int i = 0; i < n - 1; i++) {
        cout << 2 << '\n';
      }
      cout << 0 << '\n';
    } else {
      for (int i = 0; i < n - 1; i++) {
        if (s[i] == '1') {
          cout << 0 << '\n';
        } else  {
          cout << 1 << '\n';
        }
      }
      cout << 2 << '\n';
    }
    return 0;
  }
  int ans1 = 0;
  for (int i = 0; i < n; i++) {
    ans1 *= 2;
    ans1 += s[i] - '0';
    ans1 %= cnt - 1;
  }
  int ans2 = 0;
  for (int i = 0; i < n; i++) {
    ans2 *= 2;
    ans2 += s[i] - '0';
    ans2 %= cnt + 1;
  }
  vector<int> va(n, 0);
  va[n - 1] = 1 % (cnt - 1);
  for (int i = n - 1; i >= 1; i--) {
    va[i - 1] = va[i] * 2 % (cnt - 1);
  } 
  vector<int> vb(n, 0);
  vb[n - 1] = 1 % (cnt + 1);
  for (int i = n - 1; i >= 1; i--) {
    vb[i - 1] = vb[i] * 2 % (cnt + 1);
  }
  vector<int> ans(n, 0);
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      ans[i] = time_count(MOD(ans1 - va[i], cnt - 1));
    } else {
      ans[i] = time_count(MOD(ans2 + vb[i], cnt + 1));
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 5976
"use strict"

let inputs = ``

const reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
})
reader.on('line', function(input) {
  inputs += input+` `
})
reader.on('close', function() {
  let items = inputs.trim().split(' ')
  for (let i = 0 ; i <items.lenght ; i++){
    items[i] = parseInt(items[i])
  }
  let damage = parseInt(0)
  for(let i = 2 ; i < items.length ; i++){
    damage += parseInt(items[i])
  }

  if(damage >= items[0]){
    console.log("Yes")
  }else{
    console.log("No")
  }
})

Measured memory_bytes: 16844
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int X,A,B;
	cin>>X>>A>>B;
	int c,n;
	c=X-A;
	n=c/B;
	printf("%d\n",c-n*B);
}


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

const int N = 1e5 + 5;

vector<int> g[N];

int ant, n, k;

static int dfs(int u) {
	if (g[u].empty()) return 0;

	int t, mx(0);
	for (auto v: g[u]) {	
		t = dfs(v) + 1;
		mx = max(mx, t % k);
		if (t == k && u != 1)
			ant+= 1; }

	return mx; }

int main() {
#ifdef HOME
	freopen("agc4d.in", "r", stdin);
	freopen("agc4d.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int t;

	cin >> n >> k >> t;
	if (t != 1)
		ant+= 1;
	for (int i = 2; i <= n; ++i) {
		cin >> t;
		g[t].push_back(i); }

	dfs(1);

	cout << ant << endl;

	return 0; }


Measured memory_bytes: 10496
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          pb push_back
#define          N (int)2e5+5
#define          PI acos(-1.0)
#define          int long long 
#define          vi vector<int>
#define          mod 1000000007
#define          ld long double
#define          eb emplace_back
#define          mii map<int,int>
#define          vpii vector<pii>
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) x.rbegin(),x.rend()
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define            bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
set<int> adj[N];
int vis[N],par[N],h[N];

void go()
{
     cin >> n >> m;

     fo(i,1,n+1) cin >> h[i];
     int ans = 0;

     fo(i,1,m+1)
     {
          int u , v;
          cin >> u >> v;
          adj[u].insert(v);
          adj[v].insert(u);
     }

     fo(i,1,n+1)
     {
          if( adj[i].size() == 0 )
          {
               ans++;
               continue;
          }

          int hh = h[i];
          bool ok = 0;

          for( auto j: adj[i] )
          {
               if( h[j] >= hh )
               {
                    ok = 1;
                    break;
               }
          }

          ans += ( !ok );
     }

     cout << ans << endl;


}

int32_t main()
{
     FAST;     
     int t=1; 
     // cin>>t;
     test(t) go();
}

 

Measured memory_bytes: 23148
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

struct List
{
    List* next;
    List* prev;
    long deta;

    this(long deta)
    {
        this.deta = deta;
    }
}

void initList(List* head)
{
    head.next = head.prev = head;
}

void addbefore(List* head, List* add)
{
    add.next = head;
    add.prev = head.prev;
    head.prev.next = add;
    head.prev = add;
}

void addafter(List* tail, List* add)
{
    add.next = tail.next;
    add.prev = tail;
    tail.next.prev = add;
    tail.next = add;
}

void printfirst(List* head, List* tail)
{
    while (head != tail)
    {
        head.deta.write(" ");
        head = head.next;
    }
    head.deta.writeln();
}

void printlast(List* tail, List* head)
{
    while (tail != head)
    {
        tail.deta.write(" ");
        tail = tail.prev;
    }
    tail.deta.writeln();
}

void main()
{
    auto n = readln.chomp.to!(long);
    auto a = readln.split.to!(long[]);
    auto head = new List;
    auto tail = new List;
    bool flag;
    foreach (i, e; a)
    {
        if(i == 0)
        {
            auto elem = new List(e);
            initList(elem);
            head = tail = elem;
            continue;
        }
        if(flag)
        {
            auto add = new List(e);
            addbefore(head, add);
            head = head.prev;
        }
        else
        {
            auto add = new List(e);
            addafter(tail, add);
            tail = tail.next;
        }
        flag = !flag;
    }
    if(flag)
        printlast(tail, head);
    else
        printfirst(head, tail);
}


Measured memory_bytes: 20336
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

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

    int ans=0;
    rep2(i,2,n+1)
    {
        if(i%2==0)continue;

        int cnt=0;
        rep2(j,1,i+1)
        {
            if(i%j==0)cnt++;
        }
        if(cnt==8)ans++;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 500000
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
	int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int ans=0;
    REP(i,n-1){
        if(s[i]==s[i+1])ans++;
    }
    int tmp=n-ans;
    if(tmp/2>k){
        ans+=2*k;
    }else{
        ans=n-1;
    }
    OUT(ans);
	return 0;
}

Measured memory_bytes: 512
n = int(input())
size = [int(i) for i in input().split()]
for _ in range(n - 1):
    _, a = map(int, input().split())
    size.append(a)
dp = [[0] * (n) for _ in range(n)]
# init
for i in range(n):
    dp[i][i] = 0
# solve
for l in range(1, n):
    for i in range(n - l):
        j = i + l
        min = 10 ** 9
        for k in range(i, j):
            tmp = dp[i][k] + dp[k + 1][j] + size[i] * size[k + 1] * size[j + 1]
            if tmp < min:
                min = tmp
        dp[i][j] = min
print(dp[0][-1])


Measured memory_bytes: 5716
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <climits>

using namespace std;

//BEGIN
template <typename T>
struct SegmentTree {
        using F = function<T(T, T)>;
        
        int n;
        vector<T> tree;
        const F f;
        const T ti;

        SegmentTree() {}
        SegmentTree(F f, T ti) :f(f), ti(ti) {}

        void init(int n_) {
                n = 1;
                while (n < n_) n *= 2;
                tree.assign(2 * n, ti);
        }

        void build(const vector<T>& v) {
                int n_ = v.size();
                init(n_);
                for (int i = 0; i < n_; ++i) tree[n + i] = v[i];
                for (int i = n - 1; i > 0; --i) tree[i] = f(tree[2 * i], tree[2 * i + 1]);
        }

        void update(int i, const T& x) {
                i += n;
                tree[i] = x;
                while (i >>= 1) tree[i] = f(tree[2 * i], tree[2 * i + 1]);
        }

        T find(int l, int r) { // [l, r)
                l += n, r += n;
                T ll = ti, rr = ti;
                while (l < r) {
                        if (l & 1) ll = f(ll, tree[l++]);
                        if (r & 1) rr = f(rr, tree[--r]);
                        l >>= 1, r >>= 1;
                }
                return f(ll, rr);
        }

        T at(int i) { return tree[i + n]; }
};
//END

void DSL_2_A() {
        int n, q; cin >> n >> q;
        SegmentTree<int> seg([](int a, int b) { return min(a, b); }, INT_MAX);
        seg.init(n);
        while (q--) {
                int com, x, y; cin >> com >> x >> y;
                if (com) cout << seg.find(x, y + 1) << endl;
                else seg.update(x, y);
        }
}
/*
        created: 2019-11-30
        https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_A
*/
void DSL_2_B() {
        int n, q; cin >> n >> q;
        SegmentTree<long long> seg([](long long a, long long b) { return a + b; }, 0LL);
        seg.init(n);
        while (q--) {
                int com, x, y; cin >> com >> x >> y;
                --x;
                if (com) --y, cout << seg.find(x, y + 1) << endl;
                else seg.update(x, seg.at(x) + y);
        }
}
/*
        created: 2019-11-30
        https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_B
*/

int main() {
        //DSL_2_A();
        DSL_2_B();

        return 0;
}


Measured memory_bytes: 4864
/*
--> WHEN IT'S OBVIOUS THAT THE GOAL CANNOT BE REACHED,
	DON'T ADJUST THE GOALS,
	ADJUST THE ACTION STEPS.

--> THE WAY YOU CONQUER SELF-DOUBT IS BY DOING THINGS THAT MAKE YOU UNCOMFORTABLE.

--> IT IS DURING OUR DARKEST MOMENTS WE MUST FOCUS TO SEE LIGHT.
*/

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <climits>
using namespace std;
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortAll(x) sort(all(x))
#define sz(x) (int)x.size()
#define clr(x) memset(x, 0, sizeof(x))
#define PI 3.1415926535897932384626
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef pair< int, int >	pii;
typedef pair< ll, ll >		pl;
typedef vector< int >		vi;
typedef vector< ll >		vl;
typedef vector< pii >		vpii;
typedef vector< pl >		vpl;
typedef vector< vi >		vvi;
typedef vector< vl >		vvl;

const int MOD = 1e9 + 7;

ll power(ll a, ll b)
{
	ll ans = 1;

	while (b > 0)
	{
		if (b & 1)
			ans *= a;
		a = a * a;
		b >>= 1;
	}
	return ans;
}

ll powm(ll a, ll b)
{
	a %= MOD;
	ll ans = 1;

	while (b > 0)
	{
		if (b & 1)
			ans = (ans * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return ans;
}

//================================

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

	ll ans = (n / 500) * 1000;
	// cout << ans << " " << n << " " << n / 500 << "\n";
	n %= 500;
	ans += (n / 5) * 5;

	cout << ans << "\n";
	return 0;
}

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

long long euc(long long x,long long y){
    long long gcd;
    while(y>=1){
        if(y==1){
            gcd = 1;
            break;
        }
        if(y>x){
            swap(x,y);
        }
        if(x%y == 0){
            gcd =y;
            break;
        }
        else{
            x = x%y;
        }
    }
    return gcd;
}

int main(){
    long long A,B,C,D;
    cin >> A >> B >> C >>D;
    long long E = C*D/euc(C,D);
    long long Cmin;
    A%C == 0 ? Cmin = A/C : Cmin = A/C+1;
    long long Cmax = B/C;
    long long Dmin;
    A%D == 0 ? Dmin = A/D : Dmin = A/D+1;
    long long Dmax = B/D;
    long long Emin;
    A%E == 0 ? Emin = A/E : Emin = A/E+1;
    long long Emax = B/E;
    long long ans = B-A+1-(Cmax-Cmin+1)-(Dmax-Dmin+1)+(Emax-Emin+1);
    cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

long long ncr(int n, int r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod(ll a,ll b,ll m){
    if(b==0)return 1;
    if(b%2==0){
        ll y =  mod(a,b/2,m);
        return (y*y)%m;
    }
    else{
        return ((a%m)*mod(a,b-1,m))%m;
    }
}

ll modinv(ll a,ll m){
return mod(a,m-2,m);
//works only for prime m.
//else calculate phi(m)-1.
}



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

//dp states->what is important so far
//pos of first and second string
int f= s.length(),g=t.length();
ll dp[f+1][g+1];
pair<int,int> rem[f+1][g+1];
for(int i=0;i<=f;i++)
for(int j=0;j<=g;j++)
    dp[i][j]=0;

for(int i=1;i<=f;i++){
    for(int j=1;j<=g;j++){
        if(s[i-1]==t[j-1]){
            //max of include or not include

            if(dp[i-1][j-1]+1>dp[i][j]){
                dp[i][j]=dp[i-1][j-1]+1;

            }

        }
        else{
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
}
    string ans="";
    ll p=dp[f][g];
    int x=f,y=g;
    while(p!=0){
        if(dp[x][y]>dp[x-1][y]&&dp[x][y]>dp[x][y-1]){
            p--;
            ans+=s[x-1];
            x--;y--;
        }
        else if(dp[x][y]>dp[x][y-1]){
            x--;

        }
        else y--;
    }


reverse(all(ans));
cout<<ans;
    return 0;
}


Measured memory_bytes: 144308
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		a[i] -= i + 1;
	}
	sort(a.begin(), a.end());
	int x = a[n / 2];
	long long ret = 0;
	for (int i = 0; i < n; ++i) {
		ret += (a[i] > x ? a[i] - x : x - a[i]);
	}
	cout << ret << '\n';
	return 0;
}

Measured memory_bytes: 1024
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys
import numpy as np
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *P = map(int, read().split())
print(sum(x<y<z or x>y>z for x,y,z in zip(P,P[1:],P[2:])))


Measured memory_bytes: 21656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()


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

  vector<int> a(M);
  vector<int> b(M);

  rep(i,M) cin >> a.at(i) >> b.at(i) ;

  vector<vector<bool>> path(N,vector<bool>(N,false));//パスがあるか

  rep(i,M){
    int X=a.at(i)-1,Y=b.at(i)-1;//パスの指定を1~N→0~N-1に変換
    path.at(X).at(Y)=true;
    path.at(Y).at(X)=true;
  }

  vector<int> order(N);//初期順列の作成
  rep(i,N) order.at(i)=i;//iとすることで、0~N-1で初期化

  int ans=0;

  do{
    if(order.at(0)!=0) continue;//頂点1(ここでは1-1=0)が順列の初めでない場合は飛ばす。
    bool can=true;
    rep(i,N-1){
      int X=order.at(i+1),Y=order.at(i);
      if(!path.at(X).at(Y)) can=false;
    }
    if(can) ans++;

  }while(next_permutation(all(order)));

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
 int a[100][100], b[100], c[100], n, m, i, j;
 cin >> n >> m;
 for(i = 0; i < n; i++){
   for(j = 0; j < m; j++){
     cin >> a[i][j];
   }
 }
 for(i = 0; i < m; i++){
   cin >> b[i];
 }
 for(i = 0; i < n; i++){
   for(j = 0; j < m; j++){
     c[i] += a[i][j] * b[j];
   }
 }
 for(i = 0; i < n; i++){
   cout << c[i] << endl;
 }
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

#define mod 1e9+7

int main(){
  string s;
  cin >> s;
  int a, z;
  REP(i, s.length()){
    if(s[i] == 'A'){
      a = i;
      break;
    }
  }
  REPR(i, s.length()-1){
    if(s[i] == 'Z'){
      z = i;
      break;
    }
  }
  cout << z - a + 1 << endl;
  return 0;
}


Measured memory_bytes: 640
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


# 解説
N, M = list(map(int, sys.stdin.buffer.readline().split()))
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]
LR = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
AB = np.array(AB, dtype=int)
LR = np.array(LR, dtype=int)

AB = AB[np.argsort(AB[:, 0])]
A, B = AB[:, 0], AB[:, 1]
L, R = LR[:, 0], LR[:, 1]

L = np.searchsorted(A, L, side='left').tolist()
R = np.searchsorted(A, R, side='right').tolist()

# L か R の数が奇数になる場所が True
is_odd = np.diff(np.concatenate(([0], B, [0]))) != 0

graph = [[] for _ in range(N + 1)]
for i, (l, r) in enumerate(list(zip(L, R))):
    graph[l].append((r, i))
    graph[r].append((l, i))

seen_graph = [False] * (N + 1)
seen_v = [False] * (N + 1)
parents = [None] * (N + 1)


def dfs(v):
    # 子の is_odd の数が奇数ならその辺を切る。葉からやってけば root で辻褄が合う
    ret = int(is_odd[v])
    for u, j in graph[v]:
        if seen_v[u]:
            continue
        seen_v[u] = True
        children_odds = dfs(u)
        if children_odds % 2 == 1:
            ans.append(j)
        ret += children_odds
    return ret


ans = []
for v in range(N + 1):
    if seen_v[v]:
        continue
    seen_v[v] = True
    if dfs(v) % 2 != 0:
        print(-1)
        exit()

ans = np.array(ans, dtype=int)
ans.sort()
print(len(ans))
print(*(ans + 1))


Measured memory_bytes: 149352
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const int N=2e5;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int a[N],b[N],c[N];
int suf[N],d[N],f[N];
pair<int,int>p[N];
int head[N],nxt[N];
bool side[N];
#define x first
#define y second
int main()
{
	int n=gi(),m,i,j,s,l,r,all=0,cur=0;
	priority_queue< pair<int,int> >q;
	for (i=1;i<=n;i++) a[i]=gi(),b[i]=gi();
	for (i=1;i<=n+1;i++) c[i]=gi();
	sort(c+1,c+1+n+1);
	for (i=1;i<=n;i++) {
		a[i]=lower_bound(c+1,c+1+n+1,a[i])-c;
		b[i]=lower_bound(c+1,c+1+n+1,b[i])-c;
		d[a[i]-1]--;
		if (b[i]<a[i])
			nxt[i]=head[a[i]-1],head[a[i]-1]=i;
		side[i]=true;
	}
	for (s=-1,i=n+1;i;i--,s++) {//一开始多了一个,每一轮可以抵消一个
		s+=d[i];
		for (j=head[i];j;j=nxt[j]) q.push(make_pair(-b[j],j));
		while (s<-1) //如果<-1则必须把某一个变小
			if (q.empty()||-q.top().x>i) { for (m=gi();m--;) puts("-1"); return 0; }
			else side[q.top().y]=false,s++,d[i]++,d[-q.top().x-1]--,all++,q.pop();
	}
	m=gi();
	for (i=n+1;i>=0;i--) d[i]=0;
	for (i=1;i<=n;i++) d[side[i]?a[i]:b[i]]++;
	for (i=2;i<=n+1;i++) d[i]+=d[i-1];
	while (!q.empty()) q.pop();
	for (i=n+1;i;i--) head[i]=0;
	for (i=1;i<=n;i++) if (side[i]) nxt[i]=head[b[i]],head[b[i]]=i;
	for (i=1;i<=n+1;i++) {
		for (j=head[i];j;j=nxt[j]) q.push(make_pair(a[j]-1,j));
		f[i]=f[i-1];
		if (d[i]-i==-1&&cur<i) {
			if (q.empty()||q.top().x<i) f[i]=1<<30;
			else cur=q.top().x,f[i]++,q.pop();
		}
	}
	while (m--) {
		l=lower_bound(c+1,c+1+n+1,gi())-c;
		r=lower_bound(c+1,c+1+n+1,gi())-c;
		l=f[l-1]+all;
		r=f[r-1]+all;
		l=min(l,r+1);
		if (l>n+1) puts("-1");
		else printf("%d\n",n+1-l);
	}
	return 0;
}

Measured memory_bytes: 7540
#include <iostream>
#include <string>
using namespace std;
string s;
bool isall(char c, int p, int d) {
	for (int i = 0; i < 3; i++) {
		if (s[p + d * i] != c) return false;
	}
	return true;
}
bool win(char c) {
	for (int i = 0; i < 9; i += 3) {
		if (isall(c, i, 1)) return true;
	}
	for (int i = 0; i < 3; i++) {
		if (isall(c, i, 3)) return true;
	}
	if (isall(c, 0, 4)) return true;
	if (isall(c, 2, 2)) return true;
	return false;
}

int main() {
	while (cin >> s) {
		if(win('o')) cout << 'o' << endl;
		else if (win('x')) cout << 'x' << endl;
		else cout << 'd' << endl;
	}
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define r(i, n) for (int i=0;i<n;i++)
using namespace std;
int main() {
  int n=0,x=0;
  cin >> n;
  int a[n],b[n],c[n];
  r(i, n) cin >> a[i];
  r(i, n) cin >> b[i];
  r(i, n-1) cin >> c[i];
  for(int i=1; i<n+1; i++) {
    x+=b[a[i-1]-1];
    if(a[i-1]+1==a[i]) x+=c[a[i-1]-1];
  }
  cout << x <<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=2e5+10;
const int mod=1e9+7;
main(){
    int n,k;
    cin>>n>>k;
    vector<int>a;
    for(int i=1;i<=n;++i){
        int x;
        cin>>x;
        a.push_back(x);
    }
    sort(a.begin(),a.end());
    int ans=0;
    for(int i=0;i<k;++i)ans+=a[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int m = sc.NextInt();
        var dic = new Dictionary<int, int>();
        
        for (int i = 0; i < n; i++)
        {
        	int p = sc.NextInt();
        	if (!dic.ContainsKey(p)) dic.Add(p, 0);
        	dic[p] += sc.NextInt();
        }
        
        var prices = dic.Keys.OrderBy(p => p).ToList();
        long ans = 0;
        long bought = 0;
        foreach (int p in prices)
        {
        	long c = Math.Min(m - bought, dic[p]);
        	if (c == 0) break;
        	ans += p * c;
        	bought += c;
        }
        Console.WriteLine(ans);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }
        
    public long NextLong()
    {
    	CheckNext();
    	return long.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}

Measured memory_bytes: 25544
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    string s1, s2;
    
    cin >> s1;
    cin >> s2;
    
    if ( s1.length() > s2.length() ) {
        cout << "GREATER" << endl;
        return 0;
    }
    else if (s1.length() < s2.length()) {
        cout << "LESS" << endl;
        return 0;
    }
    else {
        
        for ( int i = 0; i < s1.length(); i++ ) {
            
            if ( s1[i] > s2[i] ) {
                cout << "GREATER" << endl;
                return 0;
            }
            else if ( s1[i] < s2[i] ) {
                cout << "LESS" << endl;
                return 0;
            }
        }
        
        cout << "EQUAL" << endl;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 256
import numpy

k, n = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

diff = []
for i in range(len(a) - 1):
    diff.append(a[i + 1] - a[i])
diff.append(k - a[-1] + a[0])

max_diff = max(diff)
print(k - max_diff)


Measured memory_bytes: 42460
def main():
    N = int( input())
    S = list( input())
    dp = [[0]*7 for _ in range(N)]
    if S[0] == "R":
        dp[0][0] = 1
    elif S[0] == "G":
        dp[0][1] = 1
    else:
        dp[0][2] = 1
    for i in range(1,N):
        s = S[i]
        for j in range(7):
            dp[i][j] = dp[i-1][j]
        if s == "R":
            dp[i][0] += 1
            dp[i][3] += dp[i-1][1]
            dp[i][5] += dp[i-1][2]
            dp[i][6] += dp[i-1][4]
        elif s == "G":
            dp[i][1] += 1
            dp[i][3] += dp[i-1][0]
            dp[i][4] += dp[i-1][2]
            dp[i][6] += dp[i-1][5]
        else:
            dp[i][2] += 1
            dp[i][4] += dp[i-1][1]
            dp[i][5] += dp[i-1][0]
            dp[i][6] += dp[i-1][3]
    # print(dp)
    ans = dp[N-1][6]
    # for i in range(N):
    #     ans += dp[i][6]
    # print(ans)
    for d in range(1,N//2+1):
        for i in range(N-d*2):
            # print(d,i,i+2*d)
            if S[i] != S[i+d] and S[i] != S[i+2*d] and S[i+d] != S[i+2*d]:
                ans -= 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9948
#include <iostream>

using namespace std;

int main()
{
	double x[5];
	cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
	for (int i = 0; i < 5; i++) {
		if (x[i] == 0) {
			cout << i+1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3788
n, m = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
ans = 0
for i in range(n):
    if a[i][1] < m:
        ans += a[i][0] * a[i][1]
        m -= a[i][1]
    else:
        ans += a[i][0] * m
        break
print(ans)

Measured memory_bytes: 27756
/*================================================================
Love China, Love YALI, Love OI!
*   
*   File Name：C.cpp
*   Author：YaliKiWi
*   Date：2019年08月18日
*   Discribe：
*
================================================================*/


#include<bits/stdc++.h>
using namespace std;
#define fo(i,s,e) for(register int i=s;i<=e;i++)
#define max_(x,y) ((x)>(y)?(x):(y))
#define min_(x,y) ((x)<(y)?(x):(y))
#define dd double
#define ull unsigned long long
#define ll long long
#define maxn 55
#define inf 10000
dd a[maxn];
int n;
dd ans;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	fo(i,1,n){
		cin>>a[i];
	}
	fo(i,1,n-1){
		sort(a+1,a+n+1);
		a[1]=(a[1]+a[2])/2;
		a[2]=inf;
	}
	cout<<a[1];
	return 0;
}

Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

a,b,x = map(int, input().split())


def function(n,x):
    if (n>=0):
        return n//x+1
    else:
        return 0

ans = function(b,x) - function(a-1,x)

print(ans)


Measured memory_bytes: 9184
h, w, m = gets.split.map(&:to_i)
bomb_memo = Array.new(h) { Array.new }
h_memo = Hash.new(0)
w_memo = Hash.new(0)
m.times do
  hi, wi = gets.split.map(&:to_i).map(&:pred)
  h_memo[hi] += 1
  w_memo[wi] += 1
  bomb_memo[hi] << wi
end

h_max = 0
h_memo.values.each do |v|
  h_max = v if h_max < v
end
h_maxes = []
h_memo.each do |k, v|
  next if v < h_max
  h_maxes << k
end

w_max = 0
w_memo.values.each do |v|
  w_max = v if w_max < v
end
w_maxes = []
w_memo.each do |k, v|
  next if v < w_max
  w_maxes << k
end

existing_empty = false
h_maxes.each do |h_m|
  if !(w_maxes - bomb_memo[h_m]).empty?
    existing_empty = true
    break
  end
end
ans = h_max + w_max
ans -= 1 unless existing_empty
puts ans


Measured memory_bytes: 75224
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()
T = input()

ans = "Yes"
if S != T[:-1]:
    ans = "No"
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


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

int main() {
  string s;
  cin >> s;
  int r = 0;
  for (int i = 0; i < s.size() / 2; i++) r += s[i] != s[s.size() - 1 - i];
  cout << r << endl;
}


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


char name[100000][27];
int main(void){
  int N;
  char input[12];

  std::cin>>N;
  
  for(int i=0;i<N;i++){
    std::cin>>input;
    for(int j=0;input[j]!=0;j++){
      name[i][input[j]-'a']++;
    }
  }

  std::qsort(name, N, sizeof *name, [](const void* a, const void* b)
	     {
	       const char *arg1=(const char*)a;
	       const char *arg2=(const char*)b;
	       for(int i=0;i<27;i++){
		 //		 std::cout<<"a1:"<<arg1[i]+0<<",a2:"<<arg2[i]+0<<"N";
		 if(arg1[i]-arg2[i]<0)return 1;
		 else if(arg1[i]-arg2[i]>0)return -1;
	       }
	       return 0;
 
	       //  return (arg1 > arg2) - (arg1 < arg2); // possible shortcut
	       //  return arg1 - arg2; // erroneous shortcut (fails if INT_MIN is present)
	     });
  uint64_t s=0;
  int n;
  for(int i=0;i<N-1;i++){
    n=0;
    for(int j=i+1;j<N;j++){
      int k;
      for(k=0;k<27&&name[i][k]==name[j][k];k++);
      if(k==27)n++;
      else break;
    }
    s+=((uint64_t)n)*(n+1)/2;
    i+=n;
  }

  std::cout<<s;
  
  return 0;
}


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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(A) A.begin(), A.end()
#define SZ(A) (ll)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 1e6;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, k, res = 0;
    cin >> n >> k;
    ll h[n];
    for (ll i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort (h, h + n);
    for (ll i = 0; i < n - k; i++) {
        res += h[i];
    }
    cout << res << "\n";
 	return 0;
}

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

using namespace std;

int v[2048], mi[2048];
int n, x;

int mod (int i)
{
    if (i <= 0) i += n;
    return i;
}

int main ()
{
   // freopen ("file.in", "r", stdin);

    scanf ("%d %d", &n, &x);

    for (int i = 1; i <= n; ++i)
        scanf ("%d", &v[i]), mi[i] = v[i];

    long long ans = 4000000000000000000LL;
    for (int k = 0; k < n; ++k)
    {
        long long rez = 1LL * k * x;

        for (int i = 1; i <= n; ++i)
        {
            mi[i] = min (mi[i], v[mod (i - k)]);
            rez += 1LL * mi[i];
        }

        ans = min (ans, rez);
    }

    printf ("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;

int n, x, a[100];

int main() {
  scanf("%d%d", &n, &x);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i == n - 1) {
      if (x == a[i]) ans++;
      break;
    }
    if (a[i] <= x) x -= a[i], ans++;
    else break;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 128
n,m=map(int,input().split())
a=[list(input()) for _ in range(n)]
b=[list(input()) for _ in range(m)]
r=n-m+1
for x in range(r**2):
  for y in range(m**2):
    if a[x//r+y//m][x%r+y%m]!=b[y//m][y%m]:
      break
  else:
    print('Yes')
    break
else:
  print('No')



Measured memory_bytes: 9096
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	string S;
	int alph[26] = {};
	cin >> S;
	for (int i = 0; i < S.size(); i++)
	{
		alph[S[i] - 'A']++;
	}
	int numChar = 0;
	int prod = 1;
	for (int i = 0; i < 26; i++)
	{
		if (alph[i]!=0)
		{
			numChar++;
			prod *= alph[i];
		}
	}
	if (numChar==2 && prod==4)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
program prob4
    implicit none
    integer :: N, cnt, i, ans
    integer, allocatable :: a(:)

    read(*,*) N
    allocate(a(N))
    read(*,*) a
    
    cnt = 0
    do i = 1, N
        if(mod(a(i), 2) == 0) then
            cnt = cnt + 1
        end if
    end do

    ans = 3**N - 2**cnt

    write(*,*) ans

    stop
contains
end program prob4   

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int tyouhoukei = 0;
		int hishigata = 0;

		while (sc.hasNext()) {
			String[] s = sc.nextLine().split(",");

			int a = Integer.parseInt(s[0]);
			int b = Integer.parseInt(s[1]);
			int c = Integer.parseInt(s[2]);
			if (c * c == a * a + b * b) {
				tyouhoukei++;
			}
			if (a == b) {
				hishigata++;
			}
		}
		System.out.println(tyouhoukei);
		System.out.println(hishigata);
	}
}

Measured memory_bytes: 26236
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
const int INF = 1e9+7;

int main() {
  int n, k; cin >> n >> k;
  vec v(n);
  rep(i,n) {
    cin >> v[i];
  }

  int m = 0;

  vec o;
  int sum_a = 0;
  rep(a, min(n,k)+1) {
    int sum_b = 0;
    vec o1 = o;
    rep(b, min(n,k)-a+1) {
      sort(all(o1));

      int sum_c = 0;
      rep(i, min(k-a-b, a+b)+1) {
        m = max(m, sum_a + sum_b - sum_c);
        if (i < a+b) sum_c += o1[i];
      }
      if (n-b-1 >= 0) {
        o1.push_back(v[n-b-1]);
        sum_b += v[n-b-1];
      }
    }
    if (a < n) {
      o.push_back(v[a]);
      sum_a += v[a];
    }
  }

  cout << m << endl;
}


Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String S = br.readLine();

		if(S.charAt(0) != 0x41){
			System.out.println("WA");
			return;
		}
		if(!(S.charAt(1)>0x60 && S.charAt(1)<0x7B)){
			System.out.println("WA");
			return;
		}
		int cnt = 0;
		for(int i=2;i<S.length()-1;i++){
			if(S.charAt(i) == 'C'){
				cnt++;
			}else if(!(S.charAt(i)>0x60 && S.charAt(i)<0x7B)){
				System.out.println("WA");
				return;
			}
		}
		if(cnt  != 1){
			System.out.println("WA");
			return;
		}
		if(!(S.charAt(S.length()-1)>0x60 && S.charAt(S.length()-1)<0x7B)){
			System.out.println("WA");
			return;
		}
		System.out.println("AC");
	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

int main() {
    ll n;
    ll k;
    cin >> k >> n;
    vector<ll> a(n);
    rep(i, n){
        cin >> a[i];
    }

    ll temp = a[0] + (k - a[n-1]);
    arep(i, 1, n){
        ll temp2 = a[i] - a[i - 1];

        if(temp < temp2){
            temp = temp2;
        }
    }

    ll dist = k - temp;
    cout << dist << endl;
}

Measured memory_bytes: 4788
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String s = sc.next();
    int p = 0;
    int m = 0;
    int[] sum = new int[N + 1];
    for(int i = 0; i < N; i++) {
      if(s.charAt(i) == '(') {
        sum[i + 1] = sum[i] + 1;
      } else {
        sum[i + 1] = sum[i] - 1;
        if(sum[i + 1] < 0) {
          p++;
          sum[i + 1] = 0;
        }
      }
    }
    m = sum[N];
    String first = "";
    String last = "";
    for(int i = 0; i < p; i++) {
      first += "(";
    }
    for(int i = 0; i < m; i++) {
      last += ")";
    }    
    System.out.println(first + s + last);
  }
}

Measured memory_bytes: 21972