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




























int main() {
    int S;
    cin >> S;
    vector<long long> dp(2001, 0); //第i成分は和がiになる数列の総数
    dp[0] = 1;
    for (int i = 3; i <= S; i++) {
        long long count = 0;
        for (int j = 3; i - j >= 0; j++) {
            count = (count + dp[i - j]) % 1000000007;
        }
        dp[i] = count;
    }
    cout << dp[S] << endl;
}

Measured memory_bytes: 3636
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $a = explode(" ", trim(fgets(STDIN)));

  $ans = 1;

  $max = $a[0];
  for ($i=1; $i<$n; $i++) {
    if($max <= $a[$i]){
      $ans++;
      $max = $a[$i];
    }
  }
  echo $ans;

Measured memory_bytes: 15936
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    vector<vector<int>> vec(N);
    for(int i=0;i<N;i++){
        vec[i].resize(2);
        vec[i][0] = i+1;
        cin >> vec[i][1];
        if(vec[i][0] > vec[i][1])
            swap(vec[i][0], vec[i][1]);
    }
    
    sort(vec.begin(), vec.end());
    int ans = 0;
    for(int i=1;i<N;i++){
        if(vec[i][0] == vec[i-1][0] && vec[i][1] == vec[i-1][1])
            ans++;
    }

    cout << ans << endl;

}

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

typedef long long int lli;
const int MOD = 1e9 + 7;

int dp[5001][5001];
int n;
string s;

lli powe(int a, int b) {
	if(b == 0) return 1;
	else if(b == 1) return a;
	else {
		lli base = powe(a, b/2);
		lli ans = base*base;
		ans %= MOD;
		if(b&1) {
			ans *= a;
			ans %= MOD;
		}
		return ans;
	}
}

int main() {
	ios_base::sync_with_stdio(false);

	for(int i = 0; i < 5001; i++) for(int j = 0; j < 5001; j++) dp[i][j] = 0;
	dp[0][0] = 1;

	cin >> n;
	cin >> s;

	//i - number of keys pressed
	for(int i = 1; i <= n; i++) {
		// length of existing string
		for(int j = 0; j <= n; j++) {
			//append b
			if(j == 0) {
				dp[i][j] += dp[i-1][j];
				dp[i][j] %= MOD;
			} else {
				dp[i][j-1] += dp[i-1][j];
				dp[i][j-1] %= MOD;
			}

			//append a digit
			if(j != n) {
				dp[i][j+1] += 2*dp[i-1][j];
				dp[i][j+1] %= MOD;
			}
		}
	}

	cout << ((dp[n][s.length()]*powe(2, MOD-1-s.length())) % MOD) << endl;

	return 0;
}

Measured memory_bytes: 97920
import sys,queue,math,copy,itertools,bisect,collections,heapq
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]

H,W,K = LI()

dp = [[0] * W for _ in range(H+1)]
dp[0][0] = 1

good = []
for ami in range(2**(W-1)):
    b = 1
    m = -2
    for i in range(W-1):
        if b & ami:
            if i <= m + 1:
                break
            m = i
        b <<= 1
    else:
        s = []
        b = 1
        for i in range(W):
            s.append(ami & b > 0)
            b <<= 1
        good.append([0] + s + [0])

for i in range(H):
    for ami in good:
        for j in range(W):
            if ami[j] == 0 and ami[j+1] == 0:
                dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD
            elif ami[j] == 1:
                dp[i+1][j-1] = (dp[i+1][j-1] + dp[i][j]) % MOD
            else:
                dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % MOD

print(dp[-1][K-1])

Measured memory_bytes: 41328
#include <stdio.h>
#pragma warning (disable:4996)
//FILE *in = fopen("input.txt", "r"), *out = fopen("output.txt", "w");
FILE *in = stdin, *out = stdout;
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 1e9
#define NM 200005
#define MOD 1000000007
#define FOR(i,n,m) for (int i=(n);i<=(m);i++)
#define si(n) fscanf(in,"%d",&n)
#define sd(n) fscanf(in,"%lld",&n)
typedef long long int ll;

int n, K, tree[NM * 2], B;
ll a[NM];
vector<ll> X;
void input(){
	si(n), si(K); B = n;
	X.push_back(0);
	FOR(i, 1, n){
		sd(a[i]);
		a[i] -= K;
		a[i] += a[i - 1];
		X.push_back(a[i]);
	}
	sort(X.begin(), X.end());
	FOR(i, 0, n) a[i] = lower_bound(X.begin(), X.end(), a[i]) - X.begin() + 1;
}
void Update(int idx, int cnt){
	idx += B;
	tree[idx] += cnt; idx >>= 1;
	while (idx){
		tree[idx] = tree[idx << 1] + tree[(idx << 1) + 1];
		idx >>= 1;
	}
}
int Get(int l, int r){
	l += B, r += B;
	int res = 0;
	while (l <= r){
		if (l & 1) res += tree[l++];
		if (!(r & 1)) res += tree[r--];
		l >>= 1, r >>= 1;
	}
	return res;
}
void pro(){
	ll ans = 0;
	FOR(i, 0, n){
		ans += Get(1, a[i]);
		Update(a[i], 1);
	}
	fprintf(out, "%lld", ans);
}
int main(){
	input();
	pro();
	return 0;
}

Measured memory_bytes: 5104
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string S;

	cin >> S;
	cout << (S == "AAA" || S == "BBB" ? "No" : "Yes") << endl;

	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

// order statistics tree
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> indexed_set;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

const int N = 301;
const ll INF = 1e18;

int n;
ll graph[N][N];
int used[N][N];

ll dist[N][N]; // shortest distance between verts i, j
ll ans;
int main() {
  cin.tie(0); cin.exceptions(cin.failbit);

  bool possible = true;
  scanf("%d", &n);

  rep(i, 0, n){
    rep(j, 0, n){
      scanf("%lld", &graph[i][j]);
    }
  }

  // dijkstra's for each vertex
  rep(source, 0, n){
    priority_queue<pll, vector<pll>, greater<pll>> q;

    ll len[N], // keep track of current minimum length from source other vertices
      prev[N]; // keep track of previous vertex in path back to source

    rep(v, 0, n){
      len[v] = INF;
      prev[v] = -1;
    }
    len[source] = 0;

    // get the ball rolling
    // push the source vertex into queue
    q.push({0, source}); // distance, vertex

    while(!q.empty()){
      auto p = q.top();
      q.pop();

      ll l = p.F; // length
      ll v = p.S; // vertex #

      // ignore outdated objects pushed into queue
      // a vertex can acquire a better length before we reach it in q
      if(l > len[v]) continue;

      // iterate through all neighbors of v
      rep(neighbor, 0, n){

        // I am not my own neighbor
        if(neighbor == v) continue;

        // distance to v + distance from v to neighbor
        ll new_dist = l + graph[v][neighbor];

        if(new_dist < len[neighbor]){
          len[neighbor] = new_dist;
          prev[neighbor] = v;
          q.push({new_dist, neighbor});
        } else if(new_dist == len[neighbor] &&
                  graph[v][neighbor] < graph[prev[neighbor]][neighbor]){
          // try to get only the smallest neighbors
          // is this correct?
          prev[neighbor] = v;
        }
      }
    }

    rep(i, 0, n){
      // printf("%lld ", len[i]);
      if(len[i] != graph[source][i]){
        possible = false;
        break;
      }

      if(prev[i] != -1){
        used[i][prev[i]]++;
        used[prev[i]][i]++;
      }

      // printf("%d ", prev[i]);
    }
    // puts("");

    if(!possible) break;
  }


  if(possible){
    // rep(i, 0, n){
    //   rep(j, 0, n){
    //     printf("%lld ", used[i][j]);
    //   }
    //   puts("");
    // }

    rep(i, 0, n){
      rep(j, i+1, n){
        if(used[i][j]){
          ans += graph[i][j];
        }
      }
    }
    cout << ans << endl;
  } else{
    puts("-1");
  }
}


Measured memory_bytes: 1280
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
const ll N=1100,M=1001001;
ll n,m,T,cnt,f[N][N],p[M],col[N][N],a[N],x,y,z,ans,k;
string s;
int main() 
{
	scanf("%lld%lld",&k,&n);
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	ll mx=0;
	for (int i=1;i<n;i++) mx=max(a[i+1]-a[i],mx);
	mx=max(mx,a[1]+k-a[n]);
	printf("%lld",k-mx);
}

Measured memory_bytes: 5396
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <unordered_map>
#include <utility>
#include <map>
#include <set>
#include <numeric>
using namespace std;

long long int gcd_euclid(long long int u, long long int v) {
    long long int r;
    while (0 != v) {
        r = u % v; u = v; v = r; /* swap */
    }
    
    return u;
}

int main(){
    long long int n, m;
    long long int i;
    string s, t;
    cin >> n >> m >> s >> t;
    
    long long int g = gcd_euclid(n, m);
    long long int lcm = n * m / gcd_euclid(n, m);
    
    long long int flag = 1;
    
    long long int n_ , m_;
    n_ = n / g;
    m_ = m / g;
    
    for(i = 0; i <= max(n, m); i++){
        if(i * n_ >= n || i * m_ >= m){
            break;
        }
        if(s[i * n_] != t[i * m_]){
            flag = 0;
            break;
        }
    }
    
    if(flag){
        cout << lcm << endl;
    }else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 512
from collections import defaultdict


def read_input():
    n, m = map(int, input().split())

    d = defaultdict(lambda : True)
    for i in range(m):
        d[int(input())] = False

    return n, m, d


def submit():
    n, m, d = read_input()

    prev = 1
    prev_prev = 0
    curr = 1
    for i in range(1, n + 1):
        curr = 0
        if d[i - 1]:
            curr += prev
        if d[i - 2]:
            curr += prev_prev

        curr %= 1000000007

        prev_prev = prev
        prev = curr

    print(curr)


if __name__ == '__main__':
    submit()


Measured memory_bytes: 15444
#include<stdio.h>
int main(void){
    int c1,c5,c10,c50,c100,c500,bra;
    scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
    bra=c1*1+c5*5+c10*10+c50*50+c100*100+c500*500;
    if((bra/1000)>=1){
        printf("1\n");
    }else{
        printf("0\n") ;
    }
    return 0;
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9;
const int MOD=1e9+7;
typedef long long ll;
template<typename A,size_t N,typename T>
void Fill(A (&array)[N],const T &val)
{
    std::fill( (T*)array,(T*)(array+N),val );
}
int main(void)
{
    ll N,A,B,ans=0;
    cin >> N >> A >> B;
    ll div=N/(A+B);
    ll mod=N%(A+B);
    ans+=div*A;
    ans+=min(A,mod);
    cout << ans << endl;
}

Measured memory_bytes: 256
#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 pi (double) acos(-1)
#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;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> mp;
    rep(i, n){
        cin >> a.at(i);
        mp[a.at(i)-1]++;
        mp[a.at(i)]++;
        mp[a.at(i)+1]++;
    }
    ll ans = -1;
    for(auto x = mp.begin(); x != mp.end(); x++){
        ans = max(ans, x->second);
    }
    cout << ans;
}

Measured memory_bytes: 6912
#include <cstdio>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;

const ll MOD = 1e9 + 7;
const int N = 5e4 + 10;
ll S[110][N], B[110][N];

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

int main() {
    int n = read(), k = read();
    int r = sqrt(n) + 1;
    S[0][1] = 1;
    for (int i = 0; i < k; i++) {
        for (int j = 1; j < r; j++) S[i][j] = (S[i][j] + S[i][j - 1]) % MOD;
        for (int j = r - 2; j > 0; j--) B[i][j] = (B[i][j] + B[i][j + 1]) % MOD;
        for (int j = 1; j < r; j++) {
            B[i + 1][j] = S[i][j] * (n / j - n / (j + 1));
            if (j == n / j) B[i + 1][j] = 0; //已被包含在S里
            B[i + 1][j] %= MOD;
        }
        for (int j = 1; j < r; j++) {
            S[i + 1][j] = B[i][j] + S[i][r - 1];
            S[i + 1][j] %= MOD;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= r; i++) ans = (ans + B[k][i] + S[k][i]) % MOD;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 83456
#include<iostream>
#include <cstdio>
#include<cstring>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
int main()
{
	string S;
	cin >> S;
	int count=0;
	int N;
	int t=0;
	N = S.size();
	for (int j = 0;j < N;j++) {
		if (S.at(j)<='Z') {
			t++;
		}
	}if (t == 2) {
		if (S.at(0) == 'A') {
			for (int i = 2;i < N - 1;i++) {
				if (S.at(i) == 'C') { count++; }

			}
			if (count == 1) { cout << "AC" << endl; }
			else { cout << "WA" << endl; }
		}
		else { cout << "WA" << endl; }
	}
	else { cout << "WA" << endl; }
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String s=sc.next();
        int w=0;
        int b=0;
        int a=0;
        for(int i=0;i<n;i++)
        {
            if(s.charAt(i)=='.')
                w++;
        }
        a=w;
        for(int i=0;i<n;i++)
        {
            if(s.charAt(i)=='#')
                b++;
            else
                w--;
            a=Math.min(a, (w+b));
        }
        
        System.out.println(a);
    }
}

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

int digitSum(int num){
	int sum = 0;
	while(num != 0){
		sum += num % 10;
		num /= 10;
	}
	return sum;
}

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	int sum = 0;
	for(int i=0; i<=n; ++i){
		if( a<=digitSum(i) && digitSum(i)<=b ) sum += i;
	}
	cout << sum << endl;
	return 0;
}

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

using namespace std;

int main()
{
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	double length;
	length = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));

	printf("%.8lf\n", length);

	return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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



vector<pair<ll,ll>> p(1000000);
int N, M;
int main(){
  cin >> N >> M;
  rep(i,N){
    int a,b;
    cin >> a >> b;
    p[i] = make_pair(a,b);
  }
  p.resize(N);
  sort(p.begin(), p.end());
  // rep(i,N){
  //   cout << p[i].first << endl;
  // }
  
  int pos = 0;
  ll ans = 0;
  while(1){
    if(p[pos].second < M){
      
      M -= p[pos].second;
      ans+=(p[pos].second*p[pos].first);
      // cout << M << endl << endl;
      pos++;
    }
    else{
      ans += (M*p[pos].first);
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 15872
n=int(input())
d={'AC':0,"WA":0,'TLE':0,'RE':0}
for i in range(n):
    s=str(input())
    if(s=='AC'):
        d['AC']=d['AC']+1
    elif(s=='WA'):
        d['WA']=d['WA']+1
    elif(s=='RE'):
        d['RE']=d['RE']+1
    elif(s=='TLE'):
        d['TLE']=d['TLE']+1
print("AC x"+' '+str(d['AC']))
print('WA x'+' '+str(d['WA']))
print('TLE x'+' '+str(d['TLE']))
print('RE x'+' '+str(d['RE']))

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		String[] str = new String[n];
		for(int i=0; i<n; i++){
			str[i] = sc.next();
		}
		Arrays.sort(str);
		String res = "";
		for(int i=0; i<n; i++){
			res += str[i];
		}
		sc.close();
		System.out.println(res);
	}
}

Measured memory_bytes: 24148
a, b, k = map(int, input().split())
# = int(input())
# = input()
# = list(map(int, input().split()))

cnt = 1
for i in reversed(range(1, min(a, b)+1)):
	if a%i == 0 and b%i == 0:
		if cnt == k:
			print(i)
			exit(0)
		else:
			cnt += 1


Measured memory_bytes: 2940
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

n = int(arr_data[0][0])
a = int(arr_data[1][0])


print(n * n-a)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	LL n;
	LL a,b;
	cin>>n;
	cin>>a>>b;
	if((b-a)%2==0){
		cout<<(b-a)/2<<endl;
		return 0;
	}
	LL s=0;
	if(a-1<n-b)s+=a;
	else s+=n-b+1;
	s+=(b-a)/2;
	cout<<s<<endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)

signed main(){
    int n;
    cin>>n;
    vector<double>a(n);
    rep(i,0,n)cin>>a[i];
    double ave=accumulate(a.begin(),a.end(),double(0))/n; //合計 accumulate(始め,終わり,初期値)
    rep(i,0,n)a[i]=abs(a[i]-ave);
  	cout<<min_element(a.begin(),a.end())-a.begin();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,t,cc,tt,ans=99999999;
int main() {
	cin>>n>>t;
	for(int i=0;i<n;i++) {
		cin>>cc>>tt;
		if(tt<=t) ans=min(ans,cc);
	}
	if(ans==99999999) cout<<"TLE"<<endl;
	else cout<<ans<<endl;
	return 0;
}


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

using namespace std;

int main()
{
    int n, m;

    while (cin >> n >> m, n || m) {
        vector<int> p(n);
        int sum = 0;

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

        sort(p.begin(), p.end(), greater<int>());
        
        for (int i = 0; i < n; i += m) {
            for (int j = 0; j < m - 1; j++) {
                if (i + j > n - 1)
                    break;
                sum += p[i + j];
            }
        }
        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 1216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.OptionalInt;
import java.util.regex.Pattern;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) throws IOException {
        Pattern space = Pattern.compile(" ");
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        int[] first = space.splitAsStream(stdin.readLine()).mapToInt(Integer::parseInt).toArray();
        int n = first[0];
        int l = first[1];
        int[] a = space.splitAsStream(stdin.readLine()).mapToInt(Integer::parseInt).toArray();

        OptionalInt knot = IntStream.range(0, n - 1).filter(i -> a[i] + a[i + 1] >= l).findFirst();
        if (!knot.isPresent()) {
            System.out.println("Impossible");
            System.exit(0);
        }

        System.out.println("Possible");
        for (int i = 0; i < knot.getAsInt(); i++) System.out.println(i + 1);
        for (int i = n - 2; i > knot.getAsInt(); i--) System.out.println(i + 1);
        System.out.println(knot.getAsInt() + 1);
    }

}


Measured memory_bytes: 47748
r,c=map(int,input().split())
box=[list(map(int,input().split())) for i in range(r)]
box.append([])
for i in range(r):box[i] +=[sum(box[i])]
for i in range(c+1):
   count=0
   for j in range(r):
      count +=box[j][i]
   box[r] +=[count]

for i in range(r+1):print(*box[i])


Measured memory_bytes: 6236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=203,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    if(N==1){
        cout<<")("<<endl;
        return 0;
    }
    int sum=0;
    for(int i=1;;i++){
        sum+=i;
        if(sum+(i+1)>=N){
            string S="()";
            for(int j=0;j<i;j++){
                S+=')';
            }
            for(int j=0;j<i;j++){
                S+='(';
            }
            int j=0;
            while(sum<N){
                swap(S[j],S[j+1]);
                j++;
                sum++;
            }
            
            cout<<S<<endl;
            return 0;
        }
    }
}




Measured memory_bytes: 3356
import bisect

N = int(input())
S = input()
Q = int(input())
alphabet_dic = {}
alphabet_array = []
for i,s in enumerate(S):
    alphabet_array.append(s)
    if s in alphabet_dic:
        alphabet_dic[s].append(i)
    else:
        alphabet_dic[s] = [i]
# print(alphabet_dic)

for _ in range(Q):
    a, b, c = map(str,input().split())
    if int(a) == 1:
        b = int(b)
        now_str = alphabet_array[b-1]
        if now_str != c:
            alphabet_array[b-1] = c
            alphabet_dic[now_str].remove(b-1)
            if c in alphabet_dic:
                bisect.insort_left(alphabet_dic[c],b-1)
            else:
                alphabet_dic[c] = [b-1]
    else:
        ans = 0
        b = int(b)
        c = int(c)
        for index_array in alphabet_dic.values():
            if not len(index_array) or index_array[-1] < b-1:
                continue
            i = bisect.bisect_left(index_array,b-1)
            if index_array[i] <= c-1:
                ans += 1
        print(ans)


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

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

    double sum=0;
    double x;
    string u;
    for(int i=0;i<n;i++){
        cin >> x >> u;
        if(u=="JPY"){
            sum += x;
        }else{
            sum += x*380000;
        }
    }
    printf("%.7f\n",sum);

    return 0;
}


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

using namespace std;
int main() {
	int n;
	cin >> n;
	int ans = 0;
	if (n % 10 == 0) cout << 10 << endl;
	else {
		while(n > 0) {
			ans += n % 10;
			n /= 10;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    
    map<vector<int>,int> cnt;
    for(int i=0; i<N; i++){
        double a;
        cin >> a;
        ll la=llround(a*1e9);

        int two=0;
        while(two<18&&la%2==0){
            two++;
            la/=2LL;
        }

        int five=0;
        while(five<18&&la%5==0){
            five++;
            la/=5LL;
        }
        cnt[{two,five}]++;
    }

    ll ans=0;
    for(auto &c1:cnt){
        for(auto &c2:cnt){
            if(c1.first[0]+c2.first[0]>=18&&c1.first[1]+c2.first[1]>=18){
                if(c1==c2){
                    ans+=(ll)c1.second*(c1.second-1)/2;
                }else if(c1>c2){
                    ans+=(ll)c1.second*c2.second;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3712
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	long long  n;
	cin >> n;
	long long sum = n * (n + 1) / 2;
	for (long long  int i = 1; 3 * i <= n; i++) {
		if((3*i)%15!=0)
		sum -= 3 * i;

	}
	for (long long int i = 1; 5 * i <= n; i++) {
		if ((5* i) % 15 != 0)
		sum -= 5 * i;
	}
	for (long long int i = 1; 15 * i <= n; i++) {
		sum -= 15 * i;
	}
	cout << sum << endl;
}

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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

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

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {

    int n;
    cin >> n;

    vector<ll> numbers(n);
    rep(i, n) cin >> numbers[i];

    multiset<ll> s;
    map<ll, int> m;
    rep(i, n) s.insert(numbers[i] - i);
    rep(i, n) m[numbers[i] - i]++;
    ll ans = 0;
    rep(i, n) {

        ll t = -(numbers[i] + i);
        ll now = m[t];
        ans += now;

        auto it = s.find(numbers[i] - i);
        s.erase(it);

    }

    cout << ans << endl;

}

Measured memory_bytes: 27496
// g++ -std=gnu++1y -O2 xxx.cpp

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

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

    int cnt=0;
    size_t lastPos=0;
    while ((lastPos = S.find("ABC", lastPos)) != string::npos) {
        cnt++;
        lastPos += 3;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set> 
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector <ll> v(n);
        for(int i=0;i<n;i++)cin>>v[i];
        string s;
        cin>>s;
        int status=0;
        vector <ll> xors;
        for(int i=n-1;i>=0;i--){
            ll x=v[i];
            for(auto it:xors){
                x=min(x,x^it);
            }
            if(x==0)continue;
            if(s[i]=='0'){
                xors.push_back(x);
            }
            else {
                cout<<1<<endl;
                status=1;
                break;
            }
        }
        if(status==0)cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
const int inf=1e18;
int32_t main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0),cin.tie(0);
    int x,y,z;
    cin >> x >> y >> z;
    swap(x,y);
    swap(x,z);
    cout << x << " " << y << " " << z;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1ll << 60

using namespace std;
typedef long long ll;

int Binary_search(ll n, vector<ll> &d, int l, int r) {
	if (l == r)
		return l;
	int p = (r + l) >> 1;
	if (n <= d[p])
		return Binary_search(n, d, l, p);
	else
		return Binary_search(n, d, p + 1, r);
}

int main(void) {
	int snum, tnum, q, i, a, b;
	ll ans, x;
	cin >> snum >> tnum >> q;
	vector<ll> s(snum + 2), t(tnum + 2);
	s[0] = -INF;
	t[0] = -INF;
	s[snum + 1] = INF;
	t[tnum + 1] = INF;
	for (i = 1; i <= snum; i++)
		cin >> s[i];
	for (i = 1; i <= tnum; i++)
		cin >> t[i];
	for (i = 0; i < q; i++) {
		cin >> x;
		a = Binary_search(x, s, 0, snum + 1);
		b = Binary_search(x, t, 0, tnum + 1);
		ans = min(max(s[a], t[b]) - x, x - min(s[a - 1], t[b - 1]));
		ans = min(ans, s[a] - t[b - 1] + min(s[a] - x, x - t[b - 1]));
		ans = min(ans, t[b] - s[a - 1] + min(t[b] - x, x - s[a - 1]));
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 2944
import sys

A, B, M = map(int, sys.stdin.readline().split())
*a, = map(int, sys.stdin.readline().split())
*b, = map(int, sys.stdin.readline().split())
xyc = zip(*[map(int, sys.stdin.read().split())] * 3)

def main():
    res = min(a) + min(b)

    for x, y, c in xyc:
        res = min(res, a[x-1] + b[y-1] - c)
    return res
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 35124
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll tmp;

int main(){
	ll n;
	cin >> n;
	ll sum[n];//sum[i]は山の上1枚目からi+1枚目までの総和
	rep(i,n){
		cin >> tmp;
		if(i==0)
			sum[i]=tmp;
		else
			sum[i]=sum[i-1]+tmp;
	}
	ll min = abs(sum[n-1]-sum[0]-sum[0]);
	arep(1,i,n-1){
		tmp=abs(sum[n-1]-2*sum[i]);
		if(tmp<min)
			min=tmp;
	}
	cout << min << endl;
}

Measured memory_bytes: 5188
#include <iostream>
using namespace std;
#include <cmath>
int main(void){
    // Your code here!
    double a,b,c;
    cin >>a>>b>>c;
    cout << min(min((abs(a-b) + abs(b-c)),min(abs(a-c) + abs(c-b),abs(b-a) + abs(a-c))),min((abs(b-a) + abs(a-c)),min(abs(c-a) + abs(a-b),abs(c-b) + abs(b-a)))) << endl;
}


Measured memory_bytes: 256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int a,b;

main(){
	cin>>a>>b;
	if(a<b)dump(0);
	else dump(10);
}

Measured memory_bytes: 256
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

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

  int ans = 0;

  int P = 1;
  rep(i, N) {
    if (P == A[i])
      P++;

    int sell = (A[i] - 1) / P;
    ans += sell;
    A[i] -= sell * P;
    if (A[i] == 1 && P == 1)
      P++;
  }
  cout << ans << endl;
}

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

#define int long long

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

  int N;
  cin >> N;
  
  for ( int i = 0; i < 100000; i++ ) {
    if ( (int)(i*1.08) == N ) {
      cout << i << endl;
      return 0;
    }
  }

  cout << ":(" << endl;
  
  return 0;
}


Measured memory_bytes: 256
// Contest: AtCoder Beginner Contest 159 (https://atcoder.jp/contests/abc159)
// Problem: B: String Palindrome (https://atcoder.jp/contests/abc159/tasks/abc159_b)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion }}}

using It = string::iterator;

bool is_pal(It it, It it_end) {
    It itb = it_end - 1;
    while (it < itb)
        if (*it++ != *itb--)
            return false;
    return true;
}

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

    string s; cin >> s;
    int n = sz(s);
    cout << (is_pal(all(s)) && is_pal(begin(s), begin(s) + n / 2) && is_pal(end(s) - n / 2, end(s)) ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <bitset>
#include <ctime>
#include <cstdio>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

typedef pair<int, int> P;

int normalize(int s) {	//正整数n, mで「n * m^3 = s」と表すときの最大のmをMとおき、s/M^3を返す。
	int n, m;
	double eps1 = 1e-10;
	double eps2 = 1e-9;
	
	for (n = 1; n <= 316; n++) {
		if (s % n == 0) {
			double md = pow(s / n, 1.0 / 3) + eps1;
			int m = (int)md;
			if (md - m <= eps2) {
				return s / (m * m * m);
			}
		}
	}
	for (m = 316; m >= 1; m--) {
		if (s % (m * m * m) == 0) {
			return s / (m * m * m);
		}
	}
	return -1;
}

bitset<400000001> bset;
int primeCnt, primes[1000];
void prepare() {
	int i, j;
	
	for (i = 1; i <= 20000; i++) {
		bset[i * i] = 1;
	}
	
	bool isPrime[2201] = {false};
	for (i = 2; i <= 2200; i++) {
		isPrime[i] = true;
	}
	
	primeCnt = 0;
	for (i = 2; i <= 2200; i++) {
		if (isPrime[i]) {
			primes[primeCnt++] = i;
			for (j = i * 2; j <= 2200; j += i) {
				isPrime[j] = false;
			}
		}
	}
}

int findPair(int s) {	//正整数n, mで「n * m^2 = s」と表すときの最大のmをMとおき、(s / M^2)^2 * Mを返す。
	int n, m;
	double eps1 = 1e-10;
	double eps2 = 1e-9;
	
	for (n = 1; n <= 2200; n++) {
		if (s % n == 0) {
			if (n >= 50) {
				if (bset[s / n]) {
					m = (int)(sqrt((double)s / n) + eps1);
					return n * n * m;
				}
			}
			else {
				double md = sqrt((double)s / n) + eps1;
				int m = (int)md;
				if (md - m <= eps2) {
					return n * n * m;
				}
			}
		}
	}
	
	m = 1;
	for (int i = 0; i < primeCnt; i++) {
		int p = primes[i];
		if (s % (p * p) == 0) {
			m *= p;
		}
	}
	
	n = s / (m * m);
	if (n > 100000) return -1;
	return n * n * m;
}

int n;
int s[100000];
map<int, int> cntMp;
vector<P> pairs;

signed main() {
	int i;
	
	prepare();
	scanf("%lld", &n);
	rep(i, n) { scanf("%lld", s + i); s[i] = normalize(s[i]); cntMp[s[i]]++; }
	rep(i, n) {
		int t = findPair(s[i]);
		if (s[i] <= t) pairs.push_back(P(s[i], t));
		else pairs.push_back(P(t, s[i]));
	}
	sort(pairs.begin(), pairs.end());
	pairs.erase(unique(pairs.begin(), pairs.end()), pairs.end());
	
	int ans = 0;
	rep(i, pairs.size()) {
		int u = pairs[i].first;
		int v = pairs[i].second;
		if (u == 1) { ans++; continue; }
		ans += max(cntMp[u], cntMp[v]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 61684
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int cmp(const void *a,const void *b)
{
    return (*(char*)a-*(char*)b);
}
int main()
{
    int n,i;
    scanf("%d",&n);
    char s[n][11];
    for(i=0; i<n; i++)
    {
        scanf("%s",s[i]);
        qsort(s[i],10,sizeof(char),cmp);
    }
    qsort(s,n,sizeof(char)*11,strcmp);
    long long ans=0,c=0;
    for(i=1; i<n; i++)
        if(strcmp(s[i],s[i-1])==0)
        {
            c++;
            ans+=c;
        }
        else
            c=0;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2300
while True :
    H, W = map(int, input().split())
    if H == 0 and W == 0 :
        break
    
    for i in range(H) :
        for j in range(W) :
            if i == 0 or i == H-1 :
                print("#", end="")
            elif j == 0 or j == W-1 :
                print("#", end="")
            else :
                print(".", end="")
        print()
    print()



Measured memory_bytes: 7004
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------

//動的計画法で役に立つ関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

int main(void) {
int N;
cin >> N;

ll ans = 1LL;

for (int i = 0; i < N; ++i) {
ll T;
cin >> T;
ans = lcm(ans, T);
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll n, m;
    cin >> n >> m;

    ll num[n];
    bool check[n];

    rep(i, 0, n){
        num[i] = 1;
        check[i] = false;
    }

    check[0] = true;

    rep(i, 0, m){
        ll t1, t2;
        cin >> t1 >> t2;
        t1--;
        t2--;

        if(check[t1]){
            if(num[t1] == 1){
                check[t1] = false;
                num[t1]--;
                check[t2] = true;
                num[t2]++;
            }else{
                num[t1]--;
                check[t2] = true;
                num[t2]++;
            }
        }else{
            num[t1]--;
            num[t2]++;
        }
    }

    ll count = 0;
    rep(i, 0, n){
        if(check[i]){
            count++;
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 1152
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>

using namespace std;

#define N_MAX 100001
#define M_MAX 100001

int par[N_MAX];

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

void unite(int a, int b)
{
	if (find(a) == find(b)){
		return;
	}
	par[find(a)] = find(b);

	return;
}

void solv()
{
	int N, M; scanf("%d%d", &N, &M);

	for (int i = 0; i < N; i++){
		par[i] = i;
	}

	for (int i = 0; i < M; i++){
		int x, y, z; scanf("%d%d%d", &x, &y, &z);
		unite(x - 1, y - 1);
	}

	int count[N_MAX];
	fill(count, count + N, 0);
	for (int i = 0; i < N; i++){
		count[find(i)]++;
	}

	int ret = 0;
	for (int i = 0; i < N; i++){
		if (0 != count[i]){
			ret++;
		}
	}

	printf("%d", ret);

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 1408
import java.io.InputStreamReader
import java.io.BufferedReader
import java.io.PrintWriter

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))
  val out = PrintWriter(PrintWriter(System.`out`))

  val (n, q) = br.readLine().split(" ").map { it.toInt() }
  val s = br.readLine().toCharArray()

  val table = IntArray(n)
  for(i in 0 until n-1) {
    table[i+1] =
      if(s[i] == 'A' && s[i+1] == 'C') table[i] + 1
      else table[i]
  }

  for(i in 1..q) {
    val (l, r) = br.readLine().split(" ").map { it.toInt() - 1 }
    out.println(table[r] - table[l])
  }

  out.flush()
}

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

using namespace std;
using ll = long long;


int main()
{
	int n; cin >> n;
	vector<int> a(n); for(int i = 0; i < n; i++)cin >> a[i];
	vector<int> ans;

	for(int i = 0; i < n; i++) {
		bool res = false;
		for(int j = (int)a.size() - 1; j >= 0; j--) {
			if(a[j] == j + 1) {
				ans.push_back(j + 1);
				a.erase(a.begin() + j);
				res = true;
				break;
			}
		}
		if(!res) {
			cout << -1 << endl;
			return 0;
		}
	}
	reverse(ans.begin(), ans.end());
	for(int i = 0; i < n; i++)cout << ans[i] << endl;
}

Measured memory_bytes: 256
// ABC 75 C
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
#define NMAX 55
#define BLACK 0
#define WHITE 1
#define GRAY 2
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int M[NMAX][NMAX], color[NMAX];
int n;
vector<pair<int, int> > hen;

void solve(int v);
int ans = 0;

int main(){
    int m; cin >> n >> m;
    for(int i = 0; i < n; i++){
        color[i] = WHITE;
        for(int j = 0; j < n; j++){
            M[i][j] = 0;
        }
    }
    for(int i = 0; i < m; i++){
        int a,b; cin >> a >> b;
        a--; b--;
        hen.push_back(make_pair(a,b));
        M[a][b] = M[b][a] = 1;
    }

    for(int i = 0; i < m; i++){
        int wa = hen[i].first, wb = hen[i].second;
        M[wa][wb] = M[wb][wa] = 0;
        for(int j = 0; j < n; j++){
            color[j] = WHITE;
        }
        solve(0);
        bool f = true;
        for(int j = 0; j < n; j++){
            if(color[j] == WHITE) {f = false; break;}
        }
        if(!f) ans++;
        M[wa][wb] = M[wb][wa] = 1;
    }
    cout << ans << endl;
    return 0;
}

void solve(int v){
    color[v] = BLACK;
    for(int i = 0; i < n; i++){
        if(M[v][i] == 1 && color[i] != BLACK){
            solve(i);
        }
    }
}

Measured memory_bytes: 256