akhauriyash/Code-Regression huggingface dataset:
//
// Created by hide on 2020/05/15.
//

//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード(アルファベット順,bits/stdc++.hは使わない派閥)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define PRINT(message) cout<<message<<endl //10^5:配列の最大のrange(素数列挙などで使用)

//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
//#define PB push_back //vectorヘの挿入
//#define MP make_pair //pairのコンストラクタ
//#define F first //pairの一つ目の要素
//#define S second //pairの二つ目の要素
int D, G;
int answer = std::numeric_limits<int>::max();
vector<int> p, c;

unordered_map<int, int> mp;

#include <iostream>
#include <vector>
using namespace std;

// 1 つの証言を表す構造体
using pint = pair<int,int>; // 「人」と「0 or 1」

// 入力
int N;
vector<vector<pint>> v;

// 整数 bit に対応する「決め打ち」が整合しているかを判定
bool judge(int bit) {

    // i 人目の証言を検証する
    for (int i = 0; i < N; ++i) {

        // i 人目が「不親切」だったら、証言はすべて無意味
        if ( !(bit & (1 << i)) ) continue;

        // それぞれ確認
        for (pint xy : v[i]) {
            int x = xy.first; // x が
            int y = xy.second; // y = 1: 正直、y = 0: 不親切

            // y = 1 なのに「不親切」だったらダメ
            if (y == 1 && !(bit & (1 << x))) return false;

            // y = 0 なのに「正直者」だったらダメ
            if (y == 0 && (bit & (1 << x))) return false;
        }
    }
    return true;
}


int main() {
    cin >> N;
    v.resize(N);
    for (int i = 0; i < N; ++i) {
        int A; cin >> A;
        v[i].resize(A);
        for (int j = 0; j < A; ++j) {
            cin >> v[i][j].first >> v[i][j].second;
            --v[i][j].first; // 0-indexed に
        }
    }

    int res = 0;
    for (int bit = 0; bit < (1 << N); ++bit) {

        // 矛盾 check
        if (judge(bit)) {

            // bit に含まれる人数を数える
            int count = 0;
            for (int i = 0; i < N; ++i) {
                if (bit & (1 << i)) ++count;
            }
            res = max(res, count);
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main()
{
    ll n, m;
    cin >> n >> m;
    priority_queue<ll> a;
    vector<ll> uk(n);
    ll sum = 0;
    rep(i, n)
    {
        cin >> uk[i];
        a.push(uk[i]);
    }
    rep(i, m)
    {
        ll s = a.top();
        a.pop();
        a.push(s / 2);
    }
    rep(i, n)
    {
        sum += a.top();
        a.pop();
    }
    cout << sum << endl;
}

Measured memory_bytes: 2168
n,k=map(int, input().split( ))
w = []
for _ in range(n):
    w.append(int(input()))
mx=sum(w)
mn=max(w)##mx//k<max(w)が抜けてる
mid = (mx+mn)//2
w.append(1000000000000000)

while mn < mid:#このループ条件が不自然みたいだが
    cnt = 1
    sm = 0
    for i in range(n):#ここがwhileだったのを修正して減らした
        if sm <= mid-w[i]:
            sm +=  w[i]
        else:
            cnt+=1
            sm = w[i]

    if cnt>k:
        mn = mid
        mid = (mid+mx)//2
    else:
        mx = mid
        mid = (mid+mn)//2
#最終的な実行可能解が不明、結局最後mn,mid,mx全部チェックしてる
ans=[]
for a in [mn,mid,mx]:
    cnt = 1
    sm = 0
    for i in range(n):
        if sm <= a - w[i]:
            sm +=  w[i]
        else:
            cnt+=1
            sm = w[i]

    if cnt<=k:
        ans.append(a)
    else:
        pass

print(min(ans))
#最終的な実行可能解は(直前までmidだった)mx



Measured memory_bytes: 9512
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,a[2010][2010],t;
int main(){
	cin>>n;
	FOR(i,1,100000)
		if (1ll*i*(i-1)/2==n){
			puts("Yes");
			cout<<i<<endl;
			FOR(j,1,i)
				FOR(k,1,j-1)
					a[j][k]=a[k][j]=++t;
			FOR(j,1,i){
				printf("%d",i-1);
				FOR(k,1,i) if (j!=k) printf(" %d",a[j][k]);
				puts("");
			}
			return 0;
		}
	puts("No");
	return 0;
}

Measured memory_bytes: 4992
def main():
    class UnionFind:
        def __init__(self, N):
            """
            N:要素数
            root:各要素の親要素の番号を格納するリスト.
                ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.
            rank:ランク
            """
            self.N = N
            self.root = [-1] * N
            self.rank = [0] * N

        def find(self, x):
            """頂点xの根を見つける"""
            if self.root[x] < 0:
                return x
            else:
                while self.root[x] >= 0:
                    x = self.root[x]
                return x

        def union(self, x, y):
            """x,yが属する木をunion"""
            # 根を比較する
            # すでに同じ木に属していた場合は何もしない.
            # 違う木に属していた場合はrankを見てくっつける方を決める.
            # rankが同じ時はrankを1増やす
            x = self.find(x)
            y = self.find(y)
            if x == y:
                return
            elif self.rank[x] > self.rank[y]:
                self.root[x] += self.root[y]
                self.root[y] = x
            else:
                self.root[y] += self.root[x]
                self.root[x] = y
                if self.rank[x] == self.rank[y]:
                    self.rank[y] += 1

        def same(self, x, y):
            """xとyが同じグループに属するかどうか"""
            return self.find(x) == self.find(y)

    import sys
    n, q = map(int, sys.stdin.buffer.readline().split())
    uf = UnionFind(n)
    for _ in range(q):
        t, u, v = map(int, input().split())
        if t:
            print(int(uf.same(u, v)))
        else:
            uf.union(u, v)


main()


Measured memory_bytes: 76696
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		int ans = 0;
		for(int x = 1; x * x <= i; x++){
			for(int y = 1  ; y * y  + x * x + x * y <= i; y++){
				for(int z = 1; z * z + x * x + y * y + x * y + y* z + x * z  <=i ; z++){
					if(x * x + y * y + z * z + x * y + z * x + y * z == i) ans++;
				}
			}
		}
		cout << ans <<"\n";
	}
}

Measured memory_bytes: 3632
#include <stdio.h>
  
int main(int argc, char *argv[]) {
    int k, s; 
    int cnt = 0;
    
    scanf("%d%d", &k, &s);
        
    for (int y = 0; y <= k; y++) {
        for (int x = 0; x <= k; x++) {
            int z = s - x - y;
            if (z >= 0 && z <= k ) cnt++;
        }
    }

    printf("%d\n", cnt);

    return 0;
}

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

int main()
{
  int N;
  while (cin >> N) {
    if (N == 0)
      break;

    vector<vector<int> > p(N);
    for (int i = 0; i < N; ++i) {
      int M;
      cin >> M;
      for (int j = 0; j < M; ++j) {
	int pij;
	cin >> pij;
	p[i].push_back(pij);
      }
    }

    int K;
    cin >> K;
    vector<int> l(K);
    for (int i = 0; i < K; ++i)
      cin >> l[i];

    int ans = 0;
    for (int i = 0; i < N; ++i) {
      int cnt = 0;
      for (int j = 0; j < K; ++j) {
	for (unsigned int k = 0; k < p[i].size(); ++k) {
	  if (l[j] == p[i][k])
	    ++cnt;
	}
      }
      if (cnt == K) {
	if (ans == 0)
	  ans = i+1;
	else
	  ans = -1;
      }
    }

    if (ans == 0)
      ans = -1;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 952
program snuke
	implicit none
	!character(len=3) :: Masu
    integer ::i,j,Masu
    j=0
    read(*,*) Masu
  	do i=1,3
    	!write(*,*) mod(Masu/(10**(i-1)),10)
    	if(mod(Masu/(10**(i-1)),10)==1) then
     		j=j+1
        else
        endif
	end do   
    write(*,'(i0)') j
end program snuke

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

int main()
{
  long maxMod = 2019;
  
  long L, R;
  cin >> L >> R;
  
  if (L == 0) maxMod = 0;
  else if (R - 1 == L) maxMod = (L * R) % 2019;
  else
  {
    for (long i = L; i < R; i++)
    {
      for (long j = i + 1; j <= R; j++)
      {
        long mod = (i * j) % 2019;
        if (mod == 0) {
          maxMod = 0;
          goto result;
        }
        else if (mod < maxMod) maxMod = mod;
      }
    }
  }

result:
  cout << maxMod << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
   long long a,b,k; cin>>a>>b>>k;
   if(a>=k) cout<<a-k<<' '<<b<<endl;
   else if((a+b)>=k) cout<<0<<' '<<a+b-k<<endl;
   else cout<<0<<' '<<0<<endl;
   return 0;
}

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

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

    int k, x;
    cin >> k >> x;
    
    if(500 * k >= x){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python


def main():
    s = input()
    al, ar = ([0] * (len(s) + 1), [0] * (len(s) + 1))
    for i in range(0, len(s)):
        al[i + 1] = al[i] + 1 if s[i] == '<' else 0

    for i in range(len(s) - 1, -1, -1):
        ar[i] = ar[i + 1] + 1 if s[i] == '>' else 0

    sum_a = sum([max(aln, arn) for aln, arn in zip(al, ar)])
    print(sum_a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 32412
#include <iostream>

using namespace std;

int main(void) {

	int A, B, C, D;
	cin >> A >> B >> C >> D;

	string s;
	int cmp = (A + B) - (C + D);
	if (cmp > 0) {
		s = "Left";
	} else if (cmp < 0) {
		s = "Right";
	} else {
		// cmp == 0
		s = "Balanced";
		;
	}

	cout << s << endl;

	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 1000000100

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
static const int MOD = 1000000007;
int dp[51][2];

int main(){
  char numbers[3][55];
  while(~scanf("%s",numbers[0])){
    if(numbers[0][0] == '0') break;
    
    memset(dp,0,sizeof(dp));
    for(int i=1;i<3;i++){
      scanf("%s",numbers[i]);
    }

    int N=strlen(numbers[0]);
    reverse(numbers[0],numbers[0]+N);
    reverse(numbers[1],numbers[1]+N);
    reverse(numbers[2],numbers[2]+N);

    dp[0][0] = 1;
    for(int x=0;x<N;x++){
      int left = 0;
      int right = -1;
      int q_count = 0;

      for(int y=0;y<2;y++){
        if(numbers[y][x] != '?'){
          left += numbers[y][x] - '0';
        }
        else{
          q_count++;
        }
      }

      if(numbers[2][x] != '?'){
        right = numbers[2][x] - '0';
      }

      for(int carry = 0; carry < 2; carry++){
        //num of ? eq 2
        if(q_count == 2){
          for(int i=0; i<10;i++){
            for(int j=0; j<10;j++){
              if(x == N - 1 && (i==0 || j==0)) continue;
              //C is not known
              if(right == -1){
                dp[x+1][(i+j+carry) / 10] += dp[x][carry] % MOD;
                dp[x+1][(i+j+carry) / 10] %= MOD;
              }
              //C is known
              else if((i+j+carry) % 10 == right){
                dp[x+1][(i+j+carry) / 10] += dp[x][carry] % MOD;
                dp[x+1][(i+j+carry) / 10] %= MOD;
              }
            }
          }
        }
        
        //num of ? eq 1
        if(q_count == 1){
          for(int i=0; i<10;i++){
            if(x == N - 1 && i==0) continue;
            //C is not known
            if(right == -1){
              dp[x+1][(i+left+carry) / 10] += dp[x][carry] % MOD;
              dp[x+1][(i+left+carry) / 10] %= MOD;
            }
            //C is known
            else if((i+left+carry) % 10 == right){
              dp[x+1][(i+left+carry) / 10] += dp[x][carry] % MOD;
              dp[x+1][(i+left+carry) / 10] %= MOD;
            }
          }
        }
        
        //num of ? eq 0
        if(q_count == 0){
          if(right != -1 && (left + carry) % 10 == right){
            dp[x+1][(left+carry) / 10] += dp[x][carry] % MOD;
            dp[x+1][(left+carry) / 10] %= MOD;
          }
          if(right == -1){
            if(x == N - 1 && (left+carry) % 10 == 0) continue;
            dp[x+1][(left+carry) / 10] += dp[x][carry] % MOD;
            dp[x+1][(left+carry) / 10] %= MOD;
          }
        }
      }
      
    }

    printf("%d\n",(dp[strlen(numbers[0])][0] % MOD));
  }
}

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

using namespace std;

int main(){
	int n; cin >> n;
	int a, b; cin >> a >> b;
	int ans = 0;
	for(int i = 1; i <=n; i++){
		stringstream s;
		s << i;
		string str = s.str();
		int sum = 0;
		for(int j = 0; j < str.size(); j++){
			sum += str[j] - '0';
		}
		if(sum >= a && sum <= b){
			ans += i;
		}
	}
	cout << ans << endl;
		

	return 0;
}



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


int main(){
	int N;cin>>N;
	vector<int> nos(N);
	for(int i=0;i<N;i++) cin>>nos[i];
	long long int ans = 0;
	int cz = N-1;
	for(int i=N-1;i>=0;i--){
		int x = nos[i];
		if(x > i){
			cout<<-1<<endl;
			return 0;
		}
		int ez = i-x;
		if(ez == cz) continue;
		else if(ez < cz){
			ans += x;
			cz = ez;
		}else{
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(){
    int n,artnum[4][14],y,i,j;
    char x;
    scanf("%d",&n);

    for(i=0; i<4; i++){
        for(j=0; j<13; j++){
            artnum[i][j] = 0;
        }
    }
    for(j=0; j<n; j++){
        scanf(" %c %d",&x,&y);
        if(x == 'S'){
            artnum[0][y] = 1;
        }else if(x == 'H'){
            artnum[1][y] = 1;
        }else if(x == 'C'){
            artnum[2][y] = 1;
        }else if(x == 'D'){
            artnum[3][y] = 1;
        }
    }
    for(i=0; i<4; i++){
        for(j=1; j<14; j++){
            if(artnum[i][j] != 1){
                if(i ==0){
                    x ='S';
                }else if(i==1){
                    x ='H';
                }else if(i==2){
                    x ='C';
                }else if(i==3){
                    x ='D';
                }
                printf("%c %d\n",x,j);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 596
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	if(n==3){
		cout<<"2 5 63\n";
		return 0;
	}
	vector<int> v={2,4,3,9};
	n-=4;
	for(int i=8;i<=30000 && n>=2;i+=6){
		v.emplace_back(i);
		v.emplace_back(i+2);
		n-=2;
	}
	for(int i=15;i<=30000 && n>=2;i+=12){
		v.emplace_back(i);
		v.emplace_back(i+6);
		n-=2;
	}
	for(int i=6;i<=30000 && n>0;i+=6){
		v.emplace_back(i);
		n--;
	}
	n=sz(v);
	For(i,0,n-1) cout<<v[i]<<" \n"[i==n-1];
	return 0;
}





























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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

string s;

int main(){
	cin.sync_with_stdio(false);
  cin>>s;
  if(s.length()<4){
    cout<<"No"<<endl;
    return 0;
  }
  if(s.substr(0,4)=="YAKI")cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<climits> //INT_MIN/MAX
using namespace std;

#define FOR(i,s,e) for(ll (i)=(s);(i)<(e);(i)++)
#define FORR(i,s,e) for(ll (i)=(s);(i)>(e);(i)--)
#define MOD 1000000007
#define llong long long
#define debug(x) cout<<#x<<": "<<x<<endl
typedef long long ll;

/* 2017/01/25 問題 ----- ABC042 D /Link http://abc042.contest.atcoder.jp/tasks/arc058_b */
/* -----解説等-----
問題: 縦 H マス、横 W マスのマス目があります。
いろはちゃんは、今一番左上のマス目にいます。
そして、右か下に1マス移動することを繰り返し、一番右下のマス目へと移動します。
ただし、下から A 個以内、かつ左から B 個以内のマス目へは移動することは出来ません。

移動する方法は何通りあるか求めてください。

なお、答えは非常に大きくなることがあるので、答えは 10^9+7 で割ったあまりを出力してください。


*/
#define MAX 230000
int H, W, A, B;
ll fact[MAX], rfact[MAX];

ll mod_pow(ll x, ll p, ll mod) {
    ll a = 1;
    while (p) {
        if (p % 2) a = a * x % mod;
        x = x * x % mod;
        p /= 2;
    }
    return a;
}

//逆元
ll mod_inverse(ll a, ll m) {
    return mod_pow(a, m - 2, m);
}


ll nCr(int n, int r) {
    return fact[n] * rfact[r] % MOD * rfact[n - r] % MOD;
}

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

    int H, W, A, B;
    cin >> H >> W >> A >> B;
    ll ans = 0;


    fact[0] = rfact[0] = 1;

    for (int i = 1; i < MAX; i++) {
        fact[i] = (fact[i - 1] * i) % MOD;
        rfact[i] = mod_inverse(fact[i], MOD);
    }

    for (int i = B + 1; i <= W; i++) {
        int h = H - A - 1, w = i - 1;
        ll tmp = nCr(h + w, h);
        h = A - 1, w = W - i;
        tmp *= nCr(h + w, w);
        ans += tmp%MOD;
    }

    cout << ans%MOD << endl;

    return 0;
}

Measured memory_bytes: 3840
a, b ,c ,d = input()

operator = ['+', '-']

for i in range(2 ** 3):
    result = a + operator[int(format(i, 'b').zfill(3)[0])] \
        + b + operator[int(format(i, 'b').zfill(3)[1])] \
        + c + operator[int(format(i, 'b').zfill(3)[2])] \
        + d

    if eval(result) == 7:
        print(result + "=7")
        break

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

int foo(char c) {
	switch(c) {
		case 'N' : return 0;
		case 'E' : return 1;
		case 'S' : return 2;
		case 'W' : return 3;
	}
	return -1;
}

char bar(int n) {
	switch(n) {
		case 0 : return 'N';
		case 1 : return 'E';
		case 2 : return 'S';
		case 3 : return 'W';
	}
	return '@';
}

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

int W, H;
bool valid(int i, int j) {
	return 0 <= i && i < H && 0 <= j && j < W;
}

int main() {
	while(cin >> W >> H, W || H) {
		vector<string> sq;
		for(int i = 0; i < H; i++) {
			string s;
			cin >> s; sq.push_back(s);
		}

		int ret = -1;
		for(int t = 0; t < 180; t++) {
			vector<string> nex;

			/* turn */
			for(int i = 0; i < sq.size(); i++) {
				for(int j = 0; j  < sq[i].size(); j++) {
					if(foo(sq[i][j]) != -1) {
						for(int k = 0; k < 4; k++) {
							int x,y;
							int dir = (k + 4 - foo(sq[i][j])) % 4;
							y = i + dy[dir];
							x = j + dx[dir];
							if(!valid(y, x))
								continue;
							if(sq[y][x] == '.' || sq[y][x] == 'X') {
								sq[i][j] = bar((5 - dir)%4);
								break;
							}
						}
					}
				}
			}

			/* debug 
			if(t < 20) {
				for(int i = 0; i < sq.size(); i++) {
					for(int j = 0; j < sq[i].size(); j++) {
						cout << sq[i][j];
					} cout << endl;
				}
				cout << endl;
			}
			// */

			/* move */
			for(int i = 0; i < 4; i++) {
				/*
				if(t < 20)
					cout << bar((3-i)%4) << endl;
				// */
				for(int j = 0; j < sq.size(); j++) {
					for(int k = 0; k < sq[j].size(); k++) {
						if(sq[j][k] == bar((3-i)%4)) {
							int x, y;
							x = k + dx[(i+2)%4];
							y = j + dy[(i+2)%4];
							if(valid(y,x) && sq[y][x] == '.') {
								sq[y][x] = (int)sq[j][k] - ('A' - 'a');
								sq[j][k] = '@';
							}
							else if(valid(y,x) && sq[y][x] == 'X') {
								sq[y][x] = 'x';
								sq[j][k] = '@';
								ret = t;
							}
						}
					}
				}
			}
			/* debug 
			if(t < 20) {
				for(int i = 0; i < sq.size(); i++) {
					for(int j = 0; j < sq[i].size(); j++) {
						cout << sq[i][j];
					} cout << endl;
				}
				cout << endl;
			}
			// */

			for(int i = 0; i < sq.size(); i++) {
				for(int j = 0; j < sq[i].size(); j++) {
					if(sq[i][j] == '@')
						sq[i][j] = '.';
					else if(sq[i][j] == 'x')
						sq[i][j] = 'X';
					if(sq[i][j] == 'n' || sq[i][j] == 'e' || sq[i][j] == 'w' || sq[i][j] == 's')
						sq[i][j] = (int)sq[i][j] + 'A' - 'a';
				}
			}
		}

		for(int i = 0; i < sq.size(); i++) {
			for(int j = 0; j < sq.size(); j++) {
				if(foo(sq[i][j]) != -1) {
					ret = -1;
				}
			}
		}

		if(ret == -1)
			cout << "NA" << endl;
		else
			cout << ret + 1 << endl;
	}
}

Measured memory_bytes: 1220
n = int(input())
l = [int(input()) for _ in range(n)]
l = sorted(l)
sum_l = sum(l)
ans = 0
if not (sum_l % 10 == 0):
    print(sum_l)
else:
    for i in range(n):
        tmp = sum_l - l[i]
        if not (tmp % 10 == 0):
            ans = max(ans, tmp)
    for i in range(n):
        for j in range(i, n):
            tmp = sum_l - l[i] - l[j]
            if not (tmp % 10 == 0):
                ans = max(ans, tmp)
    print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

//int main(){
//	int N;
//	cin >> N;
//	vector<ll> dp(max(N+1, 5), 0);
//	dp[0] = 1; dp[1] = 4; dp[2] = 16; dp[3] = 61;
//	for(int i = 4; i <= N; ++i){
//		dp[i] += dp[i-1]*4; dp[i] %= MOD;
//		dp[i] -= dp[i-3]*2; dp[i] %= MOD;
//		dp[i] -= dp[i-4]*6; dp[i] %= MOD;
//		if(i >= 5){dp[i] += dp[i-5]; dp[i] %= MOD;}
//		if(i >= 6){dp[i] += dp[i-6]*2; dp[i] %= MOD;}
//	}
//	if(dp[N] < 0)dp[N] += MOD;
//	cout << dp[N] << endl;
//	return 0;
//}
int N;
map<pair<string, int>, ll> memo;
char tail[4] = {'A', 'C', 'G', 'T'};

bool check(string k){
	string t1 = k.substr(1,3);
	if(t1 == "AGC" || t1 == "ACG" || t1 == "GAC" || (k[0] == 'A' && (k[1] == 'G' || k[2] == 'G') && k[3] == 'C'))return false;
	return true;
}

ll dfs(string distn, int pos){
	if(memo.count(make_pair(distn, pos)) == 1)return memo[make_pair(distn, pos)];
	if(pos == N)return 1;
	ll res = 0;
	rep(i,4){
		string now = distn + tail[i];
		if(check(now)){
			res += dfs(now.substr(1, 3), pos + 1);
			res %= MOD;
		}
	}
	return memo[make_pair(distn, pos)] = res;
}

int main(){
	cin >> N;
	cout << dfs("TTT", 0) << endl;
}


Measured memory_bytes: 4144
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<list>
#include<stack>
#define lli long long int
#define h 10000
#define pf push_front
#define pb push_back
#define ub upper_bound
#define lb lower_bound
using namespace std;
int main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL) ;
  lli a, b, c, d;
  cin>>a>>b>>c>>d;
  if(b<=0 && d<=0)cout<<a*c<<endl;
  else if(b<=0)
  {
  	if(c<=0)cout<<a*c<<endl;
  	else cout<<c*b<<endl;
  } 
  else if(d<=0)
  {
  	if(a<=0)cout<<a*c<<endl;
  	else cout<<a*d<<endl;
  } 
  else
  cout<<max(a*c,b*d)<<endl;
  return 0;
} 


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <vector>

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

using namespace std;

int n;
bool g[7][7];
int t;

bool dfs(int i){
	rep(j, 7){
		if(!g[i][j]){
			g[i][j] = g[j][i] = true;
			++t;
			bool r = dfs(j);
			g[i][j] = g[j][i] = false;
			--t;
			if(r){
				return true;
			}
		}
	}
	return t == n;
}

int main(){
	while(cin >> n){
		rep(i, 7){
			fill(g[i], g[i] + 7, true);
		}

		rep(i, n){
			int p;
			cin >> p;
			int a = p / 10;
			int b = p % 10;
			g[a][b] = g[b][a] = false;
		}

		bool a = false;
		rep(i, 7){
			if(dfs(i)){
				a = true;
				break;
			}
		}
		cout << (a ? "Yes" : "No") << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
n = int(input())
l = list(map(int, input().split()))
cnt = 2
l.sort(reverse = True)
ans = l[0]
for i in l[1: ]:
    if cnt == n: break
    ans += i
    cnt -= -1
    if cnt == n: break
    ans += i
    cnt -= -1
print(ans)

Measured memory_bytes: 94312
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W, m;
    cin >> H >> W >> m;
    vector<ll> h(m), w(m), countx(H, 0), county(W, 0);
    rep(i, m) cin >> h[i] >> w[i];
    ll xm = 0;
    ll ym = 0;
    rep(i, m)
    {
        h[i]--;
        w[i]--;
        countx[h[i]]++;
        county[w[i]]++;
    }
    rep(i, H)
    {
        chmax(xm, countx[i]);
    }
    rep(i, W)
    {
        chmax(ym, county[i]);
    }
    vector<int> x, y;
    rep(i, H)
    {
        if (xm == countx[i])
        {
            x.push_back(i);
        }
    }
    rep(i, W)
    {
        if (ym == county[i])
            y.push_back(i);
    }
    map<pair<ll, ll>, bool> M;
    rep(i, m)
    {
        M[make_pair(h[i], w[i])] = true;
    }
    //debug(x);
    //debug(y);
    //cout<<xm<<" "<<ym<<"\n";
    rep(i, x.size())
    {
        rep(j, y.size())
        {
            pair<ll, ll> temp = make_pair(x[i], y[j]);
            if (M[temp] == false)
            {
                return cout << xm + ym << "\n", 0;
            }
        }
    }
    cout << xm + ym - 1 << "\n";
}


Measured memory_bytes: 33756
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = n - 1; i >= 0; --i)
#define pb push_back

typedef long long ll;

int main() {
	int n; cin >> n;
	int h[n+1];
	REP(i, n){
		cin >> h[i];
	}
	
	int ans = 1;
	int d = h[0];

	FOR(i, 1, n){
		d = max(d, h[i-1]);
		if (d <= h[i]){
			++ans;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

long long n, tab[101], pocz, kon, s, v, j, i, ans, dp[110][110]; 

long long newt( int n, int m )
{
	if( dp[n][m] == 0 )
	{
		if( n == m )dp[n][m] = 1;
		else if( m == 1 )dp[n][m] = n;
		else dp[n][m] = newt( n - 1, m ) + newt( n - 1, m - 1 );
	}
	return dp[n][m];
}
int main()
{
	ios_base::sync_with_stdio( 0 );
	cin.tie( 0 );
	cin>>n>>pocz>>kon;
	for( int a = 1; a <= n; a++ )cin>>tab[a];
	sort( tab + 1, tab + n + 1 );
	reverse( tab + 1, tab + n + 1 );
	for( int a = 1; a <= pocz; a++ )s += tab[a];
	v = tab[pocz];
	for( int a = 1; a <= n; a++ )if( tab[a] == tab[pocz] )i++;
	for( int a = 1; a <= pocz; a++ )if( tab[a] == tab[pocz] )j++;
//	cout<<"ok"<<endl;
	if( v == tab[1] )
	{
		for( int a = pocz; a <= kon; a++ )
		{
			if( tab[a] != v )break;
			ans += newt( i, a ); 	
		}	
	}
	else
	{
		ans = newt( i, j );
	}	
//	cout<<s<<" "<<pocz<<endl;
	cout<<setprecision( 6 );
	cout<<fixed;
	cout<<(double)s/pocz<<endl;
	cout<<ans<<endl;
	return 0;
}
 


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
c=0
for i in range(n-1):
    if(l[i]==i+1):
        l[i],l[i+1]=l[i+1],l[i]
        c+=1
if(l[-1]==n):
    c=c+1
print(c)


Measured memory_bytes: 83632
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve(ll N) {
  ll ans(0);
  FOR(i, 1, N) {
    ans += (N - 1) / i;
    // printf("i=%lld += %lld", i, N / i);
  }
  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;

  solve(N);

  return 0;
}


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

using namespace std;

typedef long long int ll;

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

  string s, t;
  cin >> s >> t;
  int ans = INT_MAX;
  for (int i = 0; i < (int)s.length(); i++) {
    int sum = 0;
    for (int j = 0; j < (int)t.length(); j++) {
      if (i + j >= (int)s.length()) {
        sum = INT_MAX;
        break;
      }
      sum += (s[i + j] != t[j]);
    }
    ans = min (ans, sum);
  }

  cout << ans << '\n';
}


Measured memory_bytes: 3656
let make_no =
  let rec one n f =
    let i = (4 * n) + 1 in
    if i < 21 then i :: one (n + 1) f else f
  in
  let rec two n f =
    let i = (4 * n) + 2 in
    if i < 14 then i :: two (n + 1) f else f
  in
  let rec three n f =
    let i = (4 * n) + 3 in
    if i < 7 then i :: three (n + 1) f else f
  in
  one 0 (two 0 (three 0 []))

let () =
  let n = read_int () in
  let l = make_no in
  (match List.mem n l with true -> "No" | false -> "Yes") |> print_endline


Measured memory_bytes: 2432
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;

int cnt_digits(ll n) {
    int digits = 0;

    while(n > 0) {
        n /= 10;
        digits++;
    }
    return digits;
}
int main() {
    ll n;
    cin >> n;
    int ans = cnt_digits(n);
    for(ll a = 1LL;a <= sqrt(n);a++) {
        if(n%a != 0) continue;
        ll b = n/a;
        int cur = max(cnt_digits(a),cnt_digits(b));
        ans = min(ans,cur);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,K;
	ll A[100001],B[100001];
	int ichi[31]={};
	rep1(i,30){
		ichi[i]=(ichi[i-1]<<1)+1;
	}
	scan(N);scan(K);
	rep(i,N){
		scan(A[i]);scan(B[i]);
	}
	vint Kr;
	Kr.push_back(K);
	int Kketa,tmp=K;
	for(Kketa=0;tmp;Kketa++){
		tmp>>=1;
	}
	rep1(keta,Kketa){
		if(((K>>keta)&1)==1){
			Kr.push_back((K-(1<<keta))|(ichi[keta]));
		}
	}
	ll ans=0;
	rep(k,Kr.size()){
		ll sum=0;
		rep(i,N){
			if((A[i]|Kr[k])==Kr[k]){
				sum+=B[i];
			}
		}
		ans=max(ans,sum);
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <string>

using namespace std;


int main() {
	string str;
	cin >> str;

	string odd_string = "";
	for (int i = 0; i < str.size(); i++) {
		if (i % 2 == 0) {
			odd_string.push_back(str[i]);
		}
	}

	cout << odd_string << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define pb push_back

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;
}

int MOD = 1e9 + 7;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> field(h);
    rep(i, h)
    {
        cin >> field[i];
    }
    vector<int> dx(4);
    vector<int> dy(4);
    dx = {-1, 0, 1, 0};
    dy = {0, -1, 0, 1};
    queue<pair<int, int>> que;
    vector<vector<int>> d(h, vector<int>(w, -1));
    d[0][0] = 1;
    que.push(make_pair(0, 0));
    while (!que.empty())
    {
        pair<int, int> yx = que.front();
        int y = yx.first;
        int x = yx.second;
        que.pop();
        rep(i, 4)
        {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (ny >= 0 && ny < h && nx >= 0 && nx < w && d[ny][nx] < 0 && field[ny][nx] != '#')
            {
                que.push(make_pair(ny, nx));
                d[ny][nx] = d[y][x] + 1;
            }
            else
                continue;
        }
    }
    int c = 0;
    rep(i, h)
    {
        rep(j, w)
        {
            if (field[i][j] == '.')
                ++c;
        }
    }
    if (d[h - 1][w - 1] < 0)
        cout << -1 << endl;
    else
        cout << c - d[h - 1][w - 1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[100010];
ll b[100010];
ll pro[100010];
int main() {
	ll n,t;
	cin>>n>>t;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	ll ma=0;
	for(int i=n-1;i>=0;i--){
		ll now=a[i];
		ma=max(now,ma);
		b[i]=ma;
	}
	ma=0;
	for(int i=0;i<n;i++){
		pro[i]=b[i]-a[i];
		ma=max(ma,pro[i]);
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		if(ma==pro[i]){
			ans++;
		}
	}
	cout << ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
typedef long long ll;

using namespace std;
void fastio() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main() {
    fastio();
    int s;
    ll g=0;
    string a;
    cin>>s>>a;
    ll c[90]={0},k,l;
    for(int i=0; i<s; i++) {
        c[a[i]]++;
        for(int j=0; j<s; j++) {
            k=2*j+i;
            l=j+i;
            if(k>=s) break;
            if(a[i]!=a[l] && a[i]!=a[k] && a[l]!=a[k])
                g++;
        }
    }
    ll ans=c['R']*c['G']*c['B']-g;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3192
/*
    Ujjawal Pabreja
*/
#include <bits/stdc++.h> 
#include <functional> 
using namespace std;
using ll = long long;
using ld = long double;
#define speed_cubing    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define mp              make_pair
#define in              insert
#define ff              first
#define ss              second
#define vv              vector
#define vll             vector <ll>
#define pll             pair <ll,ll>
#define vpll            vector <pll>
#define umap            unordered_map
#define uset            unordered_set
#define mset            multiset
#define pqueue          priority_queue
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define gcd(a,b)        __gcd(a,b)
#define nl              "\n"
#define debug(x)        cout << #x << " : " << x << nl;
const ll inf = 1e18;  
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;

// ====== int_1024t begins ======
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// ====== int_1024t ends ======

// ====== pbds begins ======
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, 
//         tree_order_statistics_node_update> 
//         pbds; 
// ====== pbds ends ======

// ====== Useful functions begin ======
inline ll add(ll a,ll b) {return ((a%mod)+(b%mod))%mod;}
inline ll sub(ll a,ll b) {return ((a%mod)-(b%mod)+mod)%mod;}
inline ll mul(ll a,ll b) {return ((a%mod)*(b%mod))%mod;}
ll pwr(ll x,ll n){
    if(!n) return 1;
    if(n&1) return mul(x, pwr(mul(x,x),(n-1)/2));
    else return pwr(mul(x,x),n/2);
}
ll modinv(ll n){ 
    return pwr(n,mod - 2); 
}
// ====== Useful functions end ======
 
// ====== Variables begin ======

// ====== Variables end ======
void speed_solve(){
    ll n;
    cin >> n;
    ll a[n];
    map <ll, ll> m;
    rep(i,n){
        cin >> a[i];
        m[a[i]]++;
    }
    ll tot = 0;
    for(auto it : m){
        tot += (it.ss*(it.ss - 1))/2;
    }
    rep(i,n){
        cout << tot - (m[a[i]]*(m[a[i]] - 1))/2 + ((m[a[i]] - 1)*(m[a[i]] - 2))/2 << nl;
        
    }
}
int main()
{
    speed_cubing;
    ll test_cases = 1;
    // cin >> test_cases;
    rep(i,test_cases){
        // cout << "Case #" << i + 1 << ": ";
        speed_solve();
    }
    return 0;
}

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

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

  bool ans = true;

  string S1;
  S1=S;
  reverse(S1.begin(), S1.end());

  if (S!=S1) ans=false;

  int N=S.size();
  int strN=(N-1)/2;
  string S2=S.substr(0,strN);

  S1=S2;
  reverse(S1.begin(), S1.end());
  if (S2!=S1) ans=false;
 
  reverse(S.begin(), S.end());
  S2=S.substr(0,strN);

  S1=S2;
  reverse(S1.begin(), S1.end());
  if (S2!=S1) ans=false;

  if (ans) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}  

Measured memory_bytes: 256
import scala.io.StdIn.readInt

object Main {
  def fib(a:Int, b:Int, c:Int, n:Int):Int = {
    if (n ==  0)
      a
    else
      fib(a+b, a, b, n-1)
  }

  def main(args: Array[String]) = {
    val n = readInt()
    println(fib(1, 0, 0, n))
  }
}

Measured memory_bytes: 43740
/*
   19-3-30 Atcoder2019
   */
#include <iostream>

using namespace std;

int main()
{
    int n; cin>>n;
    string s;
    cin>>s;
    int len = s.length();
    int r=0,b=0;
    for(int i=0;i<len;i++)
    {
        if(s[i]=='R')++r;
        else ++b;
    }
    if(r>b)puts("Yes");
    else puts("No");
   // cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 256
from math import atan2,radians,sqrt,sin,cos
import sys

t = 0
result = []
for i in range(1,1000):
    t += atan2(1, sqrt(i))
    result.append((cos(t)*sqrt(i+1), sin(t)*sqrt(i+1)))
    
for n in map(int, sys.stdin):
    if n == -1:
        break
    print(result[n-2][0])
    print(result[n-2][1])


Measured memory_bytes: 5792
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};

int N, K;
int pasta[110];

int dp[110][5][5];
const int MOD = 1e4;

void modAdd(int& dpi, int& val) {
	dpi += val;
	dpi %= MOD;
}

void solve() {
	minit(dp, 0);
	
	if (pasta[0] != -1) dp[1][pasta[0]][1] = 1;
	else for_(j,0,3) dp[1][j][1] = 1;
	
	for_(i,1,N) for_(j,0,3) for_(k,1,3) {
		if (pasta[i] == -1) {
			for_(jj,0,3) {
				if (jj == j) modAdd(dp[i + 1][jj][k + 1], dp[i][j][k]);
				else modAdd(dp[i + 1][jj][1], dp[i][j][k]);
			}
		} else {
			if (j == pasta[i]) modAdd(dp[i + 1][pasta[i]][k + 1], dp[i][j][k]);
			else modAdd(dp[i + 1][pasta[i]][1], dp[i][j][k]);
		}
	}
	
	int ans = 0;
	for_(j,0,3) for_(k,0,3) modAdd(ans, dp[N][j][k]);
	
	cout << ans << endl;
}

int main() {
	cin >> N >> K;
	
	minit(pasta, -1);
	for_(i,0,K) {
		int a, b; cin >> a >> b;
		--a; --b;
		pasta[a] = b;
	}
	
	solve();
	return 0;
}

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

int main(void)
{
  int l = 0;
  int n;
  int a[100001] = {0};
  int p;
  int i;
  cin >> n;
  for ( i=0; i<n; i++ ) {
    cin >> a[i];
    a[i]--;
  }
  for ( i=0; i<n; i++ ) {
    p = a[i];
    if ( a[p] == i ) {
      l++;
    }
  }
  cout << l/2 << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int maxn=1e5+1;

char s[101];
int main() {
	scanf("%s",s);
	int z=0;
	for (int i=0;s[i];i++)
		if (z==0&&s[i]=='C') z=1;
		else if (z==1&&s[i]=='F') z=2;
	puts(z==2?"Yes":"No");
	return 0;
}



Measured memory_bytes: 256
import math
import sys
import queue
from collections import Counter
from itertools import accumulate
from fractions import gcd
from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

mod = 1000000007

"""
# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

def count(X):
    cnt  = 0
    for i in range(1, X + 1):
        if X % i == 0:
            cnt += 1
    return cnt


if __name__ == "__main__":
    N = int(sys.stdin.readline())
    ans = 0
    print(sum(count(x) == 8 for x in range(1, N + 1, 2)))

Measured memory_bytes: 5076
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int a,b;
	cin >> a >> b;
	if(a + b >= 10) cout << "error" << endl;
	else cout  << a + b << endl;
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    ll ans = 0;
    for (int i = 1; i < N; i++) {
        if (A[i-1] % 2 == 1 && A[i] > 0) {
            ans++;
            A[i-1]--;
            A[i]--;
        }
    }
    for (int i = 0; i < N; i++) {
        ans += A[i]/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define modp 1000000007
using namespace std;
int n,m;
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	if (abs(n-m)>=2) printf("%d\n",0);
	else
	{
		ans=1;
		for (int i=1;i<=n;i++) ans=(1LL*ans*i)%modp;
		for (int i=1;i<=m;i++) ans=(1LL*ans*i)%modp;
		if (n==m) ans=(2LL*ans)%modp;
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 256