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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;

struct edge { int to,cost; };

int main() {
  ll X,Y,Z,K;cin>>X>>Y>>Z>>K;
  vector<ll> AS(X),BS(Y),CS(Z);
  // 組み合わせ
  REP(i,X) cin>>AS[i];
  REP(i,Y) cin>>BS[i];
  REP(i,Z) cin>>CS[i];

  // X*Y*ZがKと同じなら全部
  if (X*Y*Z==K) {
    vector<ll> res;
    REP(x,X)REP(y,Y)REP(z,Z) {
      res.push_back(AS[x]+BS[y]+CS[z]);
    }
    sort(ALL(res),greater<ll>());
    REP(i,K) {
      OUT(res[i]);
    }
    return 0;
  }

  // 以下はX*Y*Z>K
  sort(ALL(AS),greater<ll>());
  sort(ALL(BS),greater<ll>());
  sort(ALL(CS),greater<ll>());

  // 二分探索
  // 上からKのボーダーライン
  ll left=0,right=AS[0]+BS[0]+CS[0];
  auto solve = [&](ll P) {
    ll cnt = 0;
    REP(x,X)REP(y,Y)REP(z,Z) {
      if (AS[x]+BS[y]+CS[z]<P) break;
      cnt++;
      if (cnt==K) return true;
    }
    return false;
  };
  // rightがfalse側
  while (left<right) {
    ll mid = (right+left)/2;
    if (mid==left) break;
    solve(mid) ? left = mid : right=mid-1;
  }

  vector<ll> res;
  REP(x,X)REP(y,Y)REP(z,Z) {
    if (AS[x]+BS[y]+CS[z]<left) break;
    res.push_back(AS[x]+BS[y]+CS[z]);
  }
  sort(ALL(res),greater<ll>());
  REP(i,K) {
    OUT(res[i]);
  }

  return 0;
}

Measured memory_bytes: 263772
#include <bits/stdc++.h>
typedef long long lli;

using namespace std;

const int MAXN = 104;
const lli INF = 1LL<<60;

int n;
lli a[MAXN], b[MAXN];
lli dp[MAXN][MAXN];

lli rec(int s, int t) {
  lli &res = dp[s][t];
  if(res != INF) return res;
  if(t-s == 1) return res = 0;
  for(int i = s+1; i < t; ++i) {
    res = min(res, rec(s,i) + rec(i,t) + a[s]*b[i-1]*a[i]*b[t-1]);
  }
  return res;
}

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  fill(dp[0], dp[MAXN], INF);
  cout << rec(0,n) << endl;
  return 0;
}

Measured memory_bytes: 1252
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  	int n;
  	cin >> n;
  	vector<int> a(n);
  	for(int i = 0; i < n; i++)cin >> a[i];
  	int ans = 0;
  	for(int i = 0; i < n; i++)for(int j = i+1; j < n; j++){
      	ans = max(ans, abs(a[i]-a[j]));
    }
  	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ENDL '\n'
using namespace std;
typedef long long ll;
int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, m, k, fin1, fin2;
  bool aux=true;
  cin>>n>>m>>k;
  ll sumone[n+1], sumtwo[m+1];
  sumone[0]=0;
  sumtwo[0]=0;

  for( int i = 1 ; i <= n ; ++i )
  {
    cin>>sumone[ i ];
    sumone[ i ] = sumone[ i - 1 ] + sumone[ i ];
  }

  for(int i=1; i<=m; ++i)
  {
    cin>>sumtwo[ i ];
    sumtwo[ i ]= sumtwo[ i - 1 ] + sumtwo[ i ];
  }
  ll resp=0,  antecesor=m;
  for(int i=0; i<=n; ++i)
  {
    aux=true;
    if( k -sumone[ i ] >= 0)
    {
      ll cont = i, mem = k;
      mem -= sumone[ i ];
        while(aux)
        {
          if(mem - sumtwo[ antecesor ] < 0 )
          {
            antecesor--;
          }
          else
          {
            aux=false;
            cont+=antecesor;
          }
        }

        if(cont>resp)
        {
          resp=cont;
        }
    }
    else
    {
      break;
    }
  }
  cout<<resp<<ENDL;
  return 0;
}


Measured memory_bytes: 6744
#include<bits/stdc++.h>
#define pb push_back
#define rep(a,b,c) for(int a=(int)b;a<(int)c;a++)
#define repk(a,b,c,k) for(int a=(int)b;a<(int)c;a+=(int)k)
#define comeback std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define int long long int
#define pii pair<int,int>
#define ful(a) a.begin(),a.end()
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
using namespace std;
int em(int x,int n)
{
    if(n==0)
    return 1;
    else if(n%2==0)
    return em((x%mod*x%mod)%mod,n/2);
    else
    return (x%mod*em((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
int dp[102][100009];
signed main()
{
	comeback
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output1.txt","w",stdout);
	#endif*/
         int n,W,i,j,k,l;
         cin>>n>>W;
         int w[n+1],va[n+1];
         for(i=1;i<=n;i++){
         	cin>>w[i]>>va[i];
         }
         for(i=0;i<=n;i++)
         	for(j=0;j<=100000;j++)
         		dp[i][j]=1e15;
         dp[0][0]=0;
         for(i=1;i<=n;i++){
         	for(j=0;j<=100000;j++){
         			if(va[i]<=j)
         			dp[i][j]=min(dp[i-1][j],w[i]+dp[i-1][j-va[i]]);
         			else
         			dp[i][j]=dp[i-1][j];		
         	}
         }
         for(i=100000;i>=0;i--)
         	if(dp[n][i]<=W){
         		cout<<i;
         		return 0;
         	}
         	cout<<0;

}

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

using namespace std;

int main(void) {
  int a, b;
  cin >> a >> b;

  int count = 0;
  for(int i = a; i <= b; i++) {
    string s = to_string(i);
    count++;
    for(int j = 0; j < s.length(); j++) {
      if(s[j] != s[s.length() - j - 1]) {
	count--;
	break;
      }
    }
  }

  cout << count << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int>num(n);vector<char>alpha(n);
    vector<int>num2(n);vector<char>alpha2(n);
    for(int i = 0;i < n;i++){
        cin >> alpha.at(i) >> num.at(i);
    }
    num2 = num;alpha2 = alpha;
    for(int i = 0;i < n;i++){
        for(int j = n-1;j > i;j--){
            if(num.at(j) < num.at(j-1)){
                int t = num.at(j);char d = alpha.at(j);
                num.at(j) = num.at(j-1);alpha.at(j) = alpha.at(j-1);
                num.at(j-1) = t;alpha.at(j-1) = d;
            }
        }
    }
    for(int i = 0;i < n;i++){
        int minj = i;
        for(int j = i;j < n;j++){
            if(num2.at(j) < num2.at(minj)){
                minj = j;
            }
        }
        int t = num2.at(minj);char d = alpha2.at(minj);
        num2.at(minj) = num2.at(i);alpha2.at(minj) = alpha2.at(i);
        num2.at(i) = t;alpha2.at(i) = d;
    }
    for(int i =  0;i < n;i++){
        if(i != n-1){
            cout << alpha.at(i) << num.at(i) << " ";
        }
        else{
            cout << alpha.at(i) << num.at(i) << endl;
        }
    }
    cout << "Stable" << endl;
    for(int i = 0;i < n;i++){
        if(i != n-1){
            cout << alpha2.at(i) << num2.at(i) << " ";
        }
        else{
            cout << alpha2.at(i) << num2.at(i) << endl;
        }
    }
    if(alpha == alpha2){
        cout << "Stable" << endl;
    }
    else{
        cout << "Not stable" << endl;
    }
}



Measured memory_bytes: 3164
n, k = STDIN.gets.split.map(&:to_i)
h = STDIN.gets.split.map(&:to_i)

tiles = Array.new(n)
tiles[0] = 0

for i in 1...n do
  tiles[i] = tiles[i - 1] + (h[i] - h[i - 1]).abs

  for j in 1..k do
    break if i - j < 0

    if tiles[i] > tiles[i - j] + (h[i] - h[i - j]).abs
      tiles[i] = tiles[i - j] + (h[i] - h[i - j]).abs
    end
  end
end

puts tiles[-1]


Measured memory_bytes: 11404
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b>=c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N = i_i()
S = i_s()

print(S.count('ABC'))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int N = 102;
int main() {
	int A,B,k,a[N],b=0,i;
	scanf("%d%d%d",&A,&B,&k);
	for(i=min(A,B);i>=1;i--){
        if(A%i==0&&B%i==0)
            b+=1;
        if(b==k)
            break;
	}

	printf("%d",i);
}


Measured memory_bytes: 256
class Node
  attr_accessor :parent, :size
  def initialize(n)
    @parent = n
    @size = 1
  end
end

class UnionFindTree
  def initialize(n)
    @nodes = (0..n).map { |i| Node.new(i) }
  end

  def find(x)
    return x if @nodes[x].parent == x
    @nodes[x].parent = find(@nodes[x].parent)
  end

  def unite(a, b)
    pa = find(a)
    pb = find(b)
    return if pa == pb

    if @nodes[pa].size < @nodes[pb].size
      @nodes[pa].parent = pb
      @nodes[pb].size += @nodes[pa].size
    else
      @nodes[pb].parent = pa
      @nodes[pa].size += @nodes[pb].size
    end
  end

  def same?(a, b)
    find(a) == find(b)
  end

  def size(x)
    @nodes[find(x)].size
  end

  def num_of_connected_component
    res = 0
    1.upto(@nodes.length-1) do |i|
      res += 1 if find(i) == i
    end
    res
  end
end

n, m = gets.split.map(&:to_i)
uft = UnionFindTree.new(n)

m.times do |i|
  x, y, z = gets.split.map(&:to_i)
  uft.unite(x,y)
end

puts uft.num_of_connected_component


Measured memory_bytes: 9340
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<int> a(n),x(n);
    for (int i=0;i<n;i++){
        cin >> a[i];
        x[i] = a[i];
    }
    sort(x.begin(),x.end());
    for (int i=0;i<n;i++){
        if (a[i]==x[n-1]){
            cout << x[n-2] << endl;
        } else {
            cout << x[n-1] << endl;
        }
    }
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,M,X,costA = 0,costB = 0;
    cin >> N >> M >> X;
    vector<int> spot(M);
    for(int i = 0; i < M; i++){
        cin >> spot[i];
    }
    for(int i = 0; i < M; i++){
        if(X < spot[i])
            costA++;
        if(spot[i] < X)
        costB++;
    }
cout << min(costA,costB) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#include<cmath>
#include<set>
using namespace std;
typedef long long int LL;
const int inf=1e9+10;
int main()
{
    LL N;
    scanf("%lld",&N);
    LL x=N%10;
    if(x==2||x==4||x==5||x==7||x==9)
    {
        printf("hon\n");
        return 0;
    }
    else if(x==0||x==1||x==6||x==8)
    {
        printf("pon\n");
        return 0;
    }
    else
        printf("bon\n");
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <string>



using namespace std;

int main() {

    int a[10000];
    long n;
    long long max, min,sum;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    max = a[0];
    min = a[0];
    sum = 0;

    for (int i = 0; i < n; i++) {
        if (max < a[i]) {
            max = a[i];
        }
    }
    for (int i = 0; i < n; i++) {
        if (min > a[i]) {
            min = a[i];
        }
    }
    for (int i = 0; i < n; i++) {
        sum += a[i];
    }

    cout << min << " " << max << " " << sum << endl;
    
}


Measured memory_bytes: 3120
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
typedef unsigned long long ll;

int main() {
	ll N, K;
	std::cin >> N >> K;

	if (2 * K - 1 <= N)
	{
		std::cout << "YES" << std::endl;
	}
	else
	{
		std::cout << "NO" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <string>
#include <map>
#include <queue>
#include <list>


#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long  ll;

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

//    ll pre_score = 1;
//    REP(i, 0, k){
//        pre_score *= a[i];
//    }

//    p(pre_score);

    int top_idx, end_idx;
    top_idx = 0;
    end_idx = k - 1;

    REP(i, k, n){
        end_idx += 1;
//        ll score = pre_score * a[end_idx] / a[top_idx];
//        p(score);


        if(a[end_idx] > a[top_idx]){
            p("Yes");
        } else {
            p("No");
        }

        top_idx += 1;
//        pre_score = score;
    }
}

Measured memory_bytes: 4468
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long int ll;
ll N;
int main(int argc, char const *argv[]) {
  cin >> N;
  ll x = 1;
  for(int i=1;i<=N;i++){
    x=(i*x)%1000000007;
  }
  cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 256
from collections import Counter
_ = input()
c = {k: x for k, x in Counter(map(int, input().split())).items() if x>=2}
d = sorted(list(c.keys()), reverse=True)
if len(c) < 1:
    print(0)
elif c[d[0]] >= 4:
    print(d[0] ** 2)
elif len(c) < 2:
    print(0)
else:
    print(d[0] * d[1])

Measured memory_bytes: 24224
import sys
for e in sys.stdin:
 e=sorted(map(int,e.split(',')))
 print([['null','straight'][e[0]*9<e[1]or e[4]-e[0]<5],'one pair','two pair','three card','full house',0,'four card'][sum(e.count(s)for s in e)//2-2])


Measured memory_bytes: 5612
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

pair<int,int> A[300000];

int main(){
  ll h,w,m;
  cin>>h>>w>>m;
  
  map<ll,ll> a,b;
  ll c,d;
  rep(i,m){
    cin>>c>>d;
    A[i]={c,d};
    a[c]++;
    b[d]++;
  }
  
  ll m1=0,m2=0;
  for(auto x:a){
    m1=max(m1,x.second);
  }
  for(auto x:b){
    m2=max(m2,x.second);
  }
  
  ll p=0,q=0;
  for(auto x:a){
    if(x.second==m1) p++;
  }
  for(auto x:b){
    if(x.second==m2) q++;
  }
  
  ll r=0;
  rep(i,m){
    if(a[A[i].first]==m1 && b[A[i].second]==m2) r++;
  }
  
  if(p*q==r) cout<<m1+m2-1<<endl;
  else cout<<m1+m2<<endl;

  return 0;
}

Measured memory_bytes: 43420
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
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;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}




int N;
int h[110000];
int dp[110000];

int main () {
  cin >> N;

  rep(i, N) cin >> h[i];

  dp[1] = 0;
  dp[2] = abs(h[2] - h[1]);

  for (int k=3;k<=N;++k) {
    dp[k] = min(dp[k-2] + abs(h[k]-h[k-2]), dp[k-1] + abs(h[k]-h[k-1])); 
  }

  cout << dp[N] << "\n";
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    static final int INF = (int)Math.pow(10, 9) + 7;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] x = new int[N];
        for (int i = 0; i < x.length; i++) {
            x[i] = sc.nextInt();
        }
        int res = INF;
        for (int i = 0; i < N - K + 1; i++) {
            int l = i;
            int r = i + K - 1;
            int pattern1 = Math.abs(x[l]) + Math.abs(x[r] - x[l]);
            int pattern2 = Math.abs(x[r]) + Math.abs(x[r] - x[l]);
            int time = Math.min(pattern1, pattern2);
            res = Math.min(res, time);
        }
        System.out.println(res);
        sc.close();
    }
}

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

//n
int main() {
    int n;
    cin >> n;
    vector<long long>a(n + 1);
    vector<long long>b(n);
    for(int i = 0;i < n + 1;i++){
        cin >> a[i];
    }
    for(int i = 0;i < n;i++){
        cin >> b[i];
    }
    long long count = 0;
    for(int i = 0;i < n;i++){
        count += min(a[i],b[i]);
        b[i] -= min(a[i],b[i]);
        count += min(a[i + 1],b[i]);
        a[i + 1] -= min(a[i + 1],b[i]);
    }
    cout << count << endl;
}

Measured memory_bytes: 4784
use proconio::*;
pub struct Dsu {
    n: usize,
    parent_or_size: Vec<i32>,
}

impl Dsu {
    pub fn new(n: usize) -> Self {
        Self {
            n: n,
            parent_or_size: vec![-1; n],
        }
    }
    pub fn merge(&mut self, a: usize, b: usize) -> usize {
        assert!(a < self.n);
        assert!(b < self.n);
        let (mut x, mut y) = (self.leader(a), self.leader(b));
        if x == y {
            return x;
        }
        if -self.parent_or_size[x] < -self.parent_or_size[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.parent_or_size[x] += self.parent_or_size[y];
        self.parent_or_size[y] = x as i32;
        return x;
    }

    pub fn same(&mut self, a: usize, b: usize) -> bool {
        assert!(a < self.n);
        assert!(b < self.n);
        return self.leader(a) == self.leader(b);
    }
    pub fn leader(&mut self, a: usize) -> usize {
        assert!(a < self.n);
        if self.parent_or_size[a] < 0 {
            return a;
        }
        self.parent_or_size[a] = self.leader(self.parent_or_size[a] as usize) as i32;
        self.parent_or_size[a] as usize
    }
    pub fn size(&mut self, a: usize) -> usize {
        assert!(a < self.n);
        let x = self.leader(a);
        -self.parent_or_size[x] as usize
    }
}

fn main(){
    input!{
        n:usize,q:usize,
        que:[(usize,usize,usize);q],
    }
    let mut d=Dsu::new(n);
    for (c,s,t) in que{
        if c==0{
            d.merge(s, t);
        }else{
            println!("{}",if d.same(s,t){1}else{0});
        }
    }
}

Measured memory_bytes: 9524
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
lli fac[2000005];

lli power(lli x, lli y, lli m)
{
	lli a = 1;
	x %= m;
	while (y > 0)
	{
		if (y & 1)
		{
			a *= x;
			a %= m;
		}
		y /= 2;
		x *= x;
		x %= m;
	}
	return a;
	//log y
}
lli modInverse(lli b, lli m)
{
	return power(b, m - 2, m);
}
lli modDivide(lli a, lli b, lli m)
{
	a %= m;
	lli inv = modInverse(b, m);
	a *= inv;
	a %= m;
	return a;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	lli k, mod = 1000000007;
	cin >> k;
	string s;
	cin >> s;
	fac[0] = 1;
	for1(i, 1, 2000005)
	{
		fac[i] = fac[i - 1] * i;
		fac[i] %= mod;
	}
	lli n = s.length();
	lli y = n + k;
	lli x = 0;
	for1(i, 0, k + 1)
	{
		lli u = fac[n + k];
		u = modDivide(u, fac[n + i], mod);
		u = modDivide(u, fac[k - i], mod);
		lli t = power(25, k - i, mod);
		t *= u;
		t %= mod;
		x += t;
		x %= mod;
	}
	cout << x << endl;
}

Measured memory_bytes: 19808
ciar = input().split()
W = int(ciar[0])
H = int(ciar[1])
x = int(ciar[2])
y = int(ciar[3])
r = int(ciar[4])
if (x + r) <= W and (x - r) >= 0 :
    if (y + r) <= H and (y - r) >= 0 :
        print("Yes")
    else :
        print("No")
else :
    print("No")

Measured memory_bytes: 7692
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int A,B;
    while(scanf("%d%d",&A,&B)!=EOF){
        int p=max(A+B,A-B);
        int o=max(p,A*B);
        printf("%d\n",o);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll int i,n,m,j,k,l,o,p;
    cin>>n;
    ll int a[n];
    unordered_map<ll int,ll int>M;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        M[a[i]]+=1;
    }
    ll int H = 0;
    for(auto it=M.begin();it!=M.end();it++)
    {
        H+=((((*it).second)*((*it).second - 1))/2);
    }
    //cout<<H<<endl;
    for(i=0;i<n;i++)
    {
        //cout<<M[a[i]]<<endl;
        cout<<H-(M[a[i]]-1)<<endl;
    }
}

Measured memory_bytes: 9160
import sys
sys.setrecursionlimit(10000000)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

n = int(input())
s=[]
m={}
sum=0
for i in range(0,n):
    # print((list(input()))
    tmp = "".join(sorted(input()))
    if tmp in m:
        m[tmp]+=1
    else:
        m[tmp] = 1
for k in m:
    if m[k]>1:
        # print(m[k])
        # print("["+k)
        sum+=cmb(m[k],2)
print(sum)



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

int main()
{
    int iNumA = 0;
    int iNumB = 0;
    int iNumC = 0;
    
    cin >> iNumA >> iNumB >> iNumC;
    
    if ((iNumA < iNumB) && (iNumB < iNumC))
    {
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <stack>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 
int cal(){
  stack<int> st;
  int ope=0;
  int num;
  while(true){
    char c = getchar();
    if(c == '(' || ('0'<=c && c<= '9') ) {
      if(c == '(') num = cal();
      else{
        int dig=0;
        int numd[10]={0};
        numd[0] = (c - '0');
        while(true){
          c = getchar();
          if(!('0'<=c&&c<='9')) break;
          dig++;
          numd[dig] = (c - '0');
        }
        num = 0;
        for(int i=dig; i>=0; i--)
          num+=numd[dig-i] * pow(10,(double)i);
      }
      if(ope==0){
        st.push(num);
      }else if(ope == 1){
        st.push(-num);
        ope = 0;
      }else if(ope == 2){
        int tmp = st.top();
        st.pop();
        st.push(tmp * num);
        ope = 0;
      }else if(ope == 3){
        int tmp = st.top();
        st.pop();
        st.push(tmp / num);
        ope = 0;
      }
    }
    if(c == ')' ) break;
    if(c == '=' ){
      getchar();
      break;
    }
    if(c == '+') ope = 0;
    if(c == '-') ope = 1;
    if(c == '*') ope = 2;
    if(c == '/') ope = 3;
  }
  int sum=0;
  while(!st.empty()){
    sum += st.top();
    st.pop();
  }
  return sum;
}

int main(void){  
  int n;
  cin >> n;
  getchar();
  REP(i,n)
    cout << cal() << endl;
  return 0;
}

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

int main() {
	int n;
	cin>>n;
	if(n<1200){
		cout<<"ABC"<<endl;
	}
	else if(n<2800){
		cout<<"ARC"<<endl;
	}else{
		cout<<"AGC"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
N,Q = map(int,input().split())

S = input()

T = S.replace("AC","!?")

csum = [0]*N

s = 0

for i in range(N):
    if T[i] == "?":
        s += 1
    csum[i] = s

for i in range(Q):
    l,r = map(int,input().split())
    print(csum[r-1]-csum[l-1])

Measured memory_bytes: 6108
n = int(input())
lst = [list(map(int, input().split())) for i in range(n)]

t = 0
for i in range(n - 1):
    for j in range(i, n):
        t += ((lst[i][0] - lst[j][0]) ** 2 + (lst[i][1] - lst[j][1]) ** 2) ** 0.5

print(2 * t / n)


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

int main(){
  int data[1400000],i,j;
  for(i = 2; i*i < 1400000; i++){
    if(data[i]==0){
      for(j = i*2; j < 1400000; j+=i){
	data[j]=1;
      }
    }
  }
  data[0]=1;
  data[1]=2;
  int n,down,up;
  while(1){
    cin >> n;
    if(n==0)break;
  
    for(i = n; i >=2; i--){
      if(data[i]==0){
	down = i;
	break;
      }
    }
    
    for(i = n; i < 1400000; i++){
      if(data[i]==0){
	up = i;
	break;
      }
    }
    
    if(data[n]==0)cout << "0" << endl;
    else cout << up - down << endl;
  }
  return 0;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(10, 0); int tmp;
    for (int i = 0; i < M; i++) {
        cin >> tmp;
        A[tmp] = 1;
    }
    if(A[5] == 1){
        A[2] = 0; A[3] = 0;
    }
    if(A[3] == 1){
        A[2] = 0;
    }
    if(A[9] == 1){
        A[6] = 0;
    }
    
    vector<int> a, AA;
    vector<int> match(10);
    match[1] = 2;
    match[2] = 5;
    match[3] = 5;
    match[4] = 4;
    match[5] = 5;
    match[6] = 6;
    match[7] = 3;
    match[8] = 7;
    match[9] = 6;

    for (int i = 1; i < 10; i++) {
        if(A[i] == 1){
            a.push_back(match[i]);
            AA.push_back(i);
        }
    }

    sort(ALL(AA), greater<int> ());    

    vector<int> dp(N+1, -inINF);
    dp[0] = 0; 
    for (int i = 1; i < N+1; i++) {
        tmp = -inINF;
        for (int j : a){
            if(i - j >= 0){
                tmp = max(tmp, dp[i-j] + 1);
            }
        }
        dp[i] = tmp;
    }

    tmp = N;
    for (int i = 0; i < dp[N]; i++) {
        for (int v : AA) {
            if(tmp - match[v] >= 0 && dp[tmp]-1 == dp[tmp - match[v]]){
                printf("%d", v);
                tmp -= match[v];
                break;
            }
        }
    }

    cout << endl;

    


}

Measured memory_bytes: 3764
#include <iostream>
using i64 = long long;

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

    i64 s = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 && i % 5) s += i;
    }

    std::cout << s << std::endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
const int N = 1e5+5;
const ll oo = 1e18;
const ll mod = 1e9+7;
const int INF = 1 << 30;



int main()
{
    ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
    
    int n;
    cin >> n;
    if (n % 3 == 0) {
        double ans = (double) (n/3) * (n/3) * (n/3);
        cout << fixed << setprecision(12) << ans << endl;
    } else {
        double part = n/3.0;
        cout << fixed << setprecision(12) << part * part * part << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
h = gets.split.map(&:to_i)
INF = Float::INFINITY
cost = Array.new(n+10, INF)
cost[0] = 0
 
0.upto(n-1) do |i|
  cost[i] = [cost[i], cost[i-1]+(h[i]-h[i-1]).abs].min if i - 1 >= 0
  cost[i] = [cost[i], cost[i-2]+(h[i]-h[i-2]).abs].min if i - 2 >= 0
end
 
#p cost
puts cost[n-1]

Measured memory_bytes: 11404
#include<bits/stdc++.h>
using namespace std;
int main(){
   int a,b;
   cin>>a>>b;
   if(a>=13){

    cout<<b<<endl;
   }
   else if(a>=6&&a <=12){

    cout<<b/2<<endl;
   }
   else
   cout<<"0"<<endl;




}

Measured memory_bytes: 256
import itertools
n = input()
x, pm, a = [], [1,-1], 7-int(n[0])
for i in range(1,4):
	x.append(int(n[i]))
for j in itertools.product(pm,repeat=3):
	if x[0]*j[0]+x[1]*j[1]+x[2]*j[2]==a:
		y = list(j)
		break
for k in range(3):
	if y[k]==1:
		y[k] = "+"
	else:
		y[k] = "-"
print(n[0]+y[0]+n[1]+y[1]+n[2]+y[2]+n[3]+"=7")

Measured memory_bytes: 3064
import java.util.*
fun main(args: Array<String>) {

    val (N, M) = readLine()!!.split(" ").map(String::toInt)

    var map = LinkedHashMap<String,Problem>()

    for(i in 0 until M){

        val submit = readLine()!!.split(" ")
        val problemNum = submit[0]
        val accept = submit[1]=="AC"

        if(!map.containsKey(problemNum)){
            if(accept){
                map[problemNum] = Problem(0,accept)
            }else{
                map[problemNum] = Problem()
            }
        }else{
            if(!map[problemNum]!!.accept){
                if(accept){
                    map[problemNum]!!.accept = true
                }else{
                    map[problemNum]!!.wrong+=1
                }
            }
        }
    }

    var ac = 0
    var wc = 0
    for(problem in map.values){
        if(problem.accept){
            ac++
            wc+=problem.wrong
        }
    }

    println("$ac $wc")
}

class Problem(var wrong : Int = 1,var accept : Boolean = false)

Measured memory_bytes: 66652
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
int n,m,sum=0;
int p[100005];
ll fuc[101105],inv[101105];
ll ans=1;
ll pow2(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b%2) ans=ans*a%mod;
		b/=2; a=a*a%mod;
	}
	return ans;
}
void divide(int x)
{
    sum=0;
	for(int i=2;i<=sqrt(x);i++)
	{
		if(x%i==0)
		{
			sum++;
			while(x%i==0)
			{
				x/=i;
				p[sum]++;
			}
		}
	}
	if(x>1)
	{
		p[++sum]++;
	}
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
  scanf("%d%d",&n,&m);
  divide(m); 
  fuc[1]=1;
  for(int i=2;i<=101000+100;i++)
    fuc[i]=(ll)(fuc[i-1]*i)%mod;
  inv[101000+100]=pow2(fuc[101000+100],mod-2);
  inv[0]=1;
  for(int i=101000+99;i>=1;i--)
    inv[i]=(ll)(inv[i+1]*(i+1))%mod;
  for(int i=1;i<=sum;i++)
  {
  	ans=(ll)ans*(ll)(fuc[p[i]-1+n]%mod*inv[n-1]%mod*inv[p[i]]%mod)%mod;
  	ans=ans%mod;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
/*#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <numeric>
*/
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define rrep()
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int gcd(int a,int b){
    if(a<b)swap(a,b);
    int k=a%b;
    while(k!=0){
        a=b;
        b=k;
        k=a%b;
    }
}

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

int main(){
    char c;
    int v[10];
    while(cin>>v[0]>>c){
    double sum=0;
    rep(i,1,10){
        cin>>v[i]>>c;
        if(i)v[i]+=v[i-1];
    }
    
    double a,b;
    sum=v[9];
    cin>>a; cin>>c; cin>>b;
    sum*=a/(a+b);
    rep(i,0,10){
        if(sum<=v[i]){
            cout<<i+1<<endl;
            break; 
        }
    }
    }
    return 0;
}



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

int main()
{
  int n = 0;
  cin >> n;
  int counter = 0;

if(n >= 105){
  for(int i = 105;i <= n;i++){
    if(i % 2 == 1){
      int sqrt = 0;
      for(int j = 1; j <= pow(i,0.5); j++){
        if(i % j == 0){
          sqrt ++ ;
        }
      }
      if(sqrt == 4){
        counter ++;
      }
    }
  }
}

  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 4064
x1, y1, x2, y2 = map(float, raw_input().split())
num = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)
if num == 0:
    print 0
else:
    xi = num
    for _ in range(100):
        xi = (xi + (num / xi)) / 2.0
    print xi

Measured memory_bytes: 6404
def Collatz(x):
  if x%2:
    return 3*x+1
  return x//2
A = [int(input())]
for i in range(2,10**6):
  a = Collatz(A[-1])
  if a in A:
    print(i)
    exit()
  else:
    A.append(a)

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

typedef long long ll;
const int N = 1e5 + 7;
ll a[N], b[N];

int main()
{
	int n;
	cin >> n;
	for (int i=0; i<n; i++)
		cin >> a[i] >> b[i];
	ll cnt = 0;
	for (int i=n-1; i>=0; i--)
	{
		a[i] += cnt;
		ll add = 0;
		if (a[i] % b[i])
			add = b[i] - a[i] % b[i];
		cnt += add;
	}
	cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 1792
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    int N, K;
    readf("%d %d\n", &N, &K);
    auto g = sort(sort(readln.split.to!(int[])).group.map!(g => g[1]).array);
    g[0..max(0,cast(long)g.length-K)].sum.writeln;
}



Measured memory_bytes: 11056
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;



void solve()
{
    int n, m, K;
    scanf("%d%d%d", &n, &m, &K);
    vector<int> a(n), b(m);
    int i;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (i = 0; i < m; i++) {
        scanf("%d", &b[i]);
    }

    vector<ll> sb(m + 1);
    for (i = 0; i < m; i++) {
        sb[i + 1] = sb[i] + b[i];
    }
    int ans = -INF;
    ll s = 0;
    for (i = 0; i <= n; i++) {
        if (i > 0) s += a[i-1];

        int k=lower_bound(sb.begin(), sb.end(), K - s + 1)-sb.begin();
        if (k > 0) {
            k--;
            ans = MAX(ans, i + k);
        }
    }
    printf("%d\n", ans);
    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 5948
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int main(){
	string s;
	cin >> s;
	reverse(all(s));

	string del[4] = {
		"dream",
		"dreamer",
		"erase",
		"eraser"
	};
	rep(i,4) reverse(all(del[i]));

	int i = 0;
	while(i < s.size()){
		int f = i;
		if(i + 5 > s.size()){
			break;
		}
		if(s.substr(i,5) == del[0]) i += 5;
		else if(s.substr(i,5) == del[2]) i += 5;
		else if(s.substr(i,6) == del[3]) i += 6;
		else if(s.substr(i,7) == del[1]) i += 7;
		if(f == i) break;
	}

	bool f = i == s.size();
	cout << (f ? "YES" : "NO") << endl;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int M = sc.nextInt();
		int[] h = new int[H+1];
		int[] w = new int[W+1];
		HashSet<Long> set = new HashSet<>();
		int maxh = 0;
		int maxw = 0;
		for (int i = 0; i < M; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			h[x]++;
			w[y]++;
			maxh = Math.max(maxh, h[x]);
			maxw = Math.max(maxw, w[y]);
			set.add(x * (W + 1L) + y);
		}
		int[] mh = new int[H];
		int[] mw = new int[W];
		int nh = 0;
		int nw = 0;
		for (int i = 1; i <= H; i++) {
			if (h[i] == maxh) {
				mh[nh++] = i;
			}
		}
		for (int i = 1; i <= W; i++) {
			if (w[i] == maxw) {
				mw[nw++] = i;
			}
		}
		if (nw * nh > M) {
			System.out.println(maxh + maxw);
			return;
		}
		for (int i = 0; i < nh; i++) {
			for (int j = 0; j < nw; j++) {
				if (!set.contains(mh[i] * (W + 1L) + mw[j])) {
					System.out.println(maxh + maxw);
					return;
				}
			}
		}
		System.out.println(maxh + maxw - 1);
		
	}

}


Measured memory_bytes: 83372
#include <iostream>

using namespace std;

int main()
{

		int N;
		cin >> N;
		if (N > 9)
		{
			int tmp = N / 10;
			N -= tmp * 10;
		}
		if (N == 3)
		{
			cout << "bon" << endl;
		}
		else if (N == 0 || N == 1 || N == 6 || N == 8)
		{
			cout << "pon" << endl;
		}
		else
		{
			cout << "hon" << endl;
		}
}

Measured memory_bytes: 3616
def main():
    import sys
    from collections import defaultdict
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    D = defaultdict(int)
    for a in A:
        D[a] += 1
    
    for n in range(1, N+1):
        print(D[n])

if __name__ == '__main__':
    main()

Measured memory_bytes: 37688
#include<iostream>
using namespace std;
int cnt = 0;
int n;
int a[1000000];
int w[500000];
int G[500000];
int m;
int shellsort();
int aho(int g);




int shellsort()
{
	m = n / 2;
	if (m == 0)
	{
		m = 1;
	}
	//cout << m << endl;
	for (int i = 0; i < m; i++)
	{
		if (i == 0)
		{
			G[0] = m;
		}
		else
			G[i] = G[i - 1] / 2;
		if (G[i] == 0)
		{
			m = i;
			break;
		}
		//cout << G[i];
		//if (i != m - 1)cout << " ";
	}
	cout << m << endl;
	for (int i = 0; i < m; i++)
	{
		cout << G[i];
		if (i != m - 1)
		{
			cout << " ";
		}
	}
	cout << endl;
	for (int i = 0; i < m; i++)
	{
		aho(G[i]);
	}
	return 0;
}
int aho(int g)
{
	for (int i = g; i < n; i++)
	{
		int v = a[i];
		int j = i - g;
		while (j>=0 && a[j] > v)
		{
			a[j + g] = a[j];
			j = j - g;
			cnt++;
		}
		a[j + g] = v;
	}
	return 0;
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	shellsort();
	cout << cnt << endl;
	for (int i = 0; i < n; i++)
	{
	 cout << a[i] << endl;
	}

	




}

Measured memory_bytes: 6932
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.function.BiFunction;
import java.util.function.Function;

public class Main {
  void run() {
    String str = sc.next();
    int c = str.indexOf('C');
    int f = str.lastIndexOf('F');
    System.out.println((c >= 0 && f >= 0 && c < f) ? "Yes" : "No");
  }

  Scanner sc = new Scanner(System.in);

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

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }

  class BIT<T> {
    int n;
    ArrayList<T> bit;
    BiFunction<T, T, T> bif;

    BIT(int n, BiFunction<T, T, T> bif, T defaultValue) {
      this.n = n;
      bit = new ArrayList<>(n + 1);
      for (int i = 0; i < n + 1; ++i) {
        bit.add(defaultValue);
      }
      this.bif = bif;
    }

    void update(int i, T v) {
      for (int x = i; x <= n; x += x & -x) {
        bit.set(x, bif.apply(bit.get(x), v));
      }
    }

    T reduce(int i, T defaultValue) {
      T ret = defaultValue;
      for (int x = i; x > 0; x -= x & -x) {
        ret = bif.apply(ret, bit.get(x));
      }
      return ret;
    }
  }

  long MOD = 1_000_000_007;

  long pow(long a, long r) {
    long sum = 1;
    while (r > 0) {
      if ((r & 1) == 1) {
        sum *= a;
        sum %= MOD;
      }
      a *= a;
      a %= MOD;
      r >>= 1;
    }
    return sum;
  }

  long C(int n, int r) {
    long sum = 1;
    for (int i = n; 0 < i; --i) {
      sum *= i;
      sum %= MOD;
    }
    long s = 1;
    for (int i = r; 0 < i; --i) {
      s *= i;
      s %= MOD;
    }
    sum *= pow(s, MOD - 2);
    sum %= MOD;

    long t = 1;
    for (int i = n - r; 0 < i; --i) {
      t *= i;
      t %= MOD;
    }
    sum *= pow(t, MOD - 2);
    sum %= MOD;

    return sum;
  }

  double GOLDEN_RATIO = (1.0 + Math.sqrt(5)) / 2.0;

  /**
   * 黄金分割探索
   *
   * @param left  下限
   * @param right 上限
   * @param f     探索する関数
   * @param comp  上に凸な関数を探索するときは、Comparator.comparingDouble(Double::doubleValue)
   *              下に凸な関数を探索するときは、Comparator.comparingDouble(Double::doubleValue).reversed()
   * @return 極値の座標x
   */
  double goldenSectionSearch(double left, double right, Function<Double, Double> f, Comparator<Double> comp) {
    double c1 = divideInternally(left, right, 1, GOLDEN_RATIO);
    double c2 = divideInternally(left, right, GOLDEN_RATIO, 1);
    double d1 = f.apply(c1);
    double d2 = f.apply(c2);
    while (right - left > 1e-9) {
      if (comp.compare(d1, d2) > 0) {
        right = c2;
        c2 = c1;
        d2 = d1;
        c1 = divideInternally(left, right, 1, GOLDEN_RATIO);
        d1 = f.apply(c1);
      } else {
        left = c1;
        c1 = c2;
        d1 = d2;
        c2 = divideInternally(left, right, GOLDEN_RATIO, 1);
        d2 = f.apply(c2);
      }
    }
    return right;
  }

  /**
   * [a,b]をm:nに内分する点を返す
   */
  double divideInternally(double a, double b, double m, double n) {
    return (n * a + m * b) / (m + n);
  }
}


Measured memory_bytes: 9680
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;

int main(void) {
    ll N; cin >> N;
    ll N_bina = 0;
    string ans;
    string alphabet = "abcdefghijklmnopqrstuvwxyz";
    for (int i = 0; N>0; i++) {
            N--;
            N_bina = N_bina+(N%26)*pow(10,i);
            ans += alphabet[N%26];
            //cout << N%26 << endl;
            N/=26;
        }
    reverse(ans.begin(),ans.end());
    cout << ans << endl; 
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
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; }
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,D;
    int X[14][14];
    cin >> N >> D;
    REP(i,N){
        REP(j,D){
            cin >> X[i][j];
        }
    }
    int Ans=0;
    REP(j,N){
        REP(i,j){
            int sum=0;
            REP(k,D){
                int num;
                num=abs(X[i][k]-X[j][k]);
                sum+=num*num;
            }
            if(((int)sqrt(sum))*((int)sqrt(sum))==sum){
                Ans++;
            }
        }
    }
    cout << Ans << endl;
    return 0;
}




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

#define INF 1e18
#define int long long

signed main() {
    int a, b; cin >> a >> b;

    if((a + b) % 2 == 0) {
        cout << (a + b) / 2 << endl;
        return 0;
    }

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


Measured memory_bytes: 256
<?php
  $input = trim(fgets(STDIN));
  $input = str_replace(array("\r\n","\r","\n"), '', $input);
  $array = str_split($input);
  
  $cnt = 0;
  for( $i = 0; $i < count($array); $i++) {
    if( $array[$i] == 1) {
      $cnt++;
    }
  }
  echo $cnt;
?>
  

Measured memory_bytes: 3576
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var H, W int

func main() {
	fsc := NewFastScanner()
	H, W := fsc.NextInt(), fsc.NextInt()
	costs := make([][]int, 11)
	for i := 0; i < 10; i++ {
		costs[i] = make([]int, 10)
	}
	for i := 0; i < 10; i++ {
		for j := 0; j < 10; j++ {
			costs[i][j] = fsc.NextInt()
		}
	}
	for k := 0; k < 10; k++ {
		for i := 0; i < 10; i++ {
			for j := 0; j < 10; j++ {
				costs[i][j] = IntMin(costs[i][j], costs[i][k]+costs[k][j])
			}
		}
	}
	result := 0
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			val := fsc.NextInt()
			if val == -1 {
				continue
			} else {
				result += costs[val][1]
			}
		}
	}
	fmt.Println(result)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}


Measured memory_bytes: 768
"""
fast way to compute a combination using inverse factorials
O(N) to construct tables -> O(1) to compute each combination
"""


def get_fact_and_inv(limit: int, MOD: int) -> tuple:
    """Compute mod tables of factorials and inverse factorials (1-indexed)."""
    factorials = [0] * (limit + 1)
    factorials[0] = 1
    x = 1
    for i in range(1, limit + 1):
        x = x * i % MOD
        factorials[i] = x

    inverse_factorials = [1] * (limit + 1)
    inverse_factorials[-1] = pow(factorials[-1], MOD - 2, MOD)
    x = inverse_factorials[-1]
    for i in range(limit - 1, 0, -1):
        x = x * (i + 1) % MOD
        inverse_factorials[i] = x
    return factorials, inverse_factorials


def mod_comb(n: int, r: int, MOD: int) -> int:
    """Compute nCr % MOD using a mod table of inverse factorials."""
    return fact[n] * inv[r] * inv[n - r] % MOD


# e.g. ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D)
def main():
    global fact, inv
    H, W, A, B = map(int, input().split())
    MOD = 10 ** 9 + 7
    fact, inv = get_fact_and_inv(H + W, MOD)
    x, y, a = H - A - 1, W + A - 2, A - 1  # fixed variables
    f = lambda i: mod_comb(x + i, i, MOD) * mod_comb(y - i, a, MOD)
    ans = sum(f(i) for i in range(B, W)) % MOD
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 18804