akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC
{


    public static void Main()
    {
        var read = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = read[0];
        int K = read[1];

        int minus = N - K;

        if (K == 1)
        {
            Console.WriteLine(0);
        }
        else
        {
            Console.WriteLine(minus);
        }


    }



}

Measured memory_bytes: 13268
module piyoMod
      implicit none
      
      contains
      function digit( n )
        implicit none
        integer :: n,digit
        integer :: i,ten
        
        i = 1
        do while( .true. )
          ten = 10**i
          if( n/ten==0 )then
            digit = i
            return
          else
            i = i + 1
          end if
        end do
      end function
      
      end module
      
      
      program main
      use piyoMod
      implicit none
      integer :: n,i,ans=0
      read*,n
      
      do i = 1,n
        if(mod(digit(i),2)==1)then
          ans = ans + 1
        end if
      end do
      
      print*,ans
      
      end program

Measured memory_bytes: 2860
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define swap(type ,a ,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(i=0;i<n;i++)
#define forR(i,s,n) for(i=s;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

int main(){
    int n,i,tmpi;
    float tmpf;
    cin >> n;
    forN(i,9){
        if(n%(i+1) ==0){
            tmpf = (float)n/((float)i+1.);
            if(tmpf < 10.){
                cout << "Yes" << endl;;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int tri(int a, int b, int c)
{
	int y = 0;
	if (a < b + c) {
		if (b < a + c) {
			if (c < a + b) {
				y++;
			}
		}
	}

	return y;
}
int main(void)
{
	int N,count=0;
	int L[10010];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &L[i]);
	}
	sort(L, L + N);
	for (int i = 0; i < N - 2; i++) {
		for (int j = i + 1; j < N - 1; j++) {
			for (int k = j + 1; k < N; k++) {
				if (tri(L[i], L[j], L[k]) == 1) {
					count++;
				}
				else {
					break;
				}
			}
		}
	}
	printf("%d", count);

	return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int d[2][101][4];
int main(void){
	char s[103];
	int n, k, i, j;
	scanf("%s%d", s+1, &k);
	n=strlen(s+1);
	d[0][1][0]=1;
	if(s[1]!='0') d[0][1][1]=s[1]-'0'-1;
	d[1][1][1]=1;
	for(i=2; i<=n; i++){
		d[0][i][0]=1;
		for(j=1; j<=k; j++){
			d[0][i][j]=d[0][i-1][j]+d[0][i-1][j-1]*9;
			if(s[i]!='0') d[0][i][j]+=d[1][i-1][j-1]*(s[i]-'0'-1)+d[1][i-1][j];
			if(s[i]=='0'){
				d[1][i][j]=d[1][i-1][j];
			}else{
				d[1][i][j]=d[1][i-1][j-1];
			}
		}
	}
	printf("%d\n", d[0][n][k]+d[1][n][k]);
}


Measured memory_bytes: 128
#include "bits/stdc++.h"

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
//#define int ll
int INF = 1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
typedef pair<int, int> Vec2;
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template<class T> inline void chmax(T& a, T b) { if (a < b) a = b; }
template<class T> inline void chmin(T& a, T b) { if (a > b)  a = b; }

long long h[110000];
long long dp[110000];

signed main() {
	ios::sync_with_stdio(false);
	int N,K;
	cin >> N >> K;
	rep(i, N) cin >> h[i];
	rep(i, 110000) dp[i] = INF;
	dp[0] = 0;
	rep(i,N){
		for (int j = 1; j <= K;  j++) {
			chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}
	cout << dp[N - 1] << endl;
	return 0;
}


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


int main(){
    
    int n;
    cin>>n;
    int i=0;
    int pla[1000];
   // cout<<"aaa";
    

    if(n!=0){
    while(n!=1){
        
        if(n%(-2)==0){
        pla[i]=0;
        n=n/(-2);
        //cout<<'a'<<n<<pla[i]<<endl;
    }else{
       pla[i]=1;
        n=(n-1)/(-2);
       // cout<<'b'<<n<<pla[i]<<endl;;
    }
        i++;
    }
    
    pla[i]=1;
    for(int j=i;j>=0;--j){
        cout<<pla[j];
    }}
    else{cout<<0;}
    return 0;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;
const int MAX = 100005;

//modpow
template <class T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus; // llにしないとダメ
    exp >>= 1;
  }
  return result;
}

int main() {
    string s; cin >> s;
    int n = s.size();
    map<ll,ll> mt;
    ll now = s[n-1] - '0';
    mt[0]++;
    mt[now]++;
    for (int i = n-2; i >= 0; i--) {
        now += (s[i]-'0')*modpow(10,n-i-1,2019);
        now %= 2019;
        mt[now]++;
    }
    ll ans = 0;
    for (auto pt = mt.begin(); pt != mt.end(); pt++) {
        ll x = pt->second;
        ans += x*(x-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3764
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>

using namespace std;


int main(){
  string s;
  cin >> s;
  int one = 0, zero = 0;
  int ans;
  for(int i = 0; i < s.length(); ++i){
    if(s[i] == '1') ++one;
    else ++zero;
  }
  ans = min(one, zero) * 2;
  cout << ans << endl;
}


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

int main() {
  int n;
  string x;
  cin >> n >> x;
  vector<int> f(n + 1);
  for (int i = 1; i <= n; i++) {
    f.at(i) = f.at(i % __builtin_popcount(i)) + 1;
  }
  int s = count(x.begin(), x.end(), '1'), r0 = 0, r1 = 0;
  vector<int> p0, p1;
  p0.push_back(1);
  p1.push_back(1);
  for (int i = 0; i < n; i++) {
    r0 *= 2;
    r1 *= 2;
    if (x.at(i) == '1') {
      r0++;
      r1++;
    }
    if (s > 1) r0 %= s - 1;
    r1 %= s + 1;
    if (s > 1) p0.push_back(p0.at(i) * 2 % (s - 1));
    p1.push_back(p1.at(i) * 2 % (s + 1));
  }
  for (int i = 0; i < n; i++) {
    if (x.at(i) == '1') {
      if (s > 1) {
        cout << f.at((r0 + (s - 1) - p0.at(n - 1 - i)) % (s - 1)) + 1 << "\n";
      } else {
        cout << 0 << "\n";
      }
    } else {
      cout << f.at((r1 + p1.at(n - 1 - i)) % (s + 1)) + 1 << "\n";
    }
  }
}


Measured memory_bytes: 6100
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n; cin >> n;
    vector<ll> v;
    REP(i, n) {
        ll tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    vector<ll> sorted_v = v;
    sort(ALL(sorted_v));
    ll l = sorted_v[sorted_v.size() / 2 - 1];
    ll r = sorted_v[sorted_v.size() / 2];
    REP(i, n) {
        if (v[i] <= l) {
            cout << r << endl;
        } else {
            cout << l << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6328
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
int main(){
	int i,j,k,m,n;
	cin>>n;
	for(register int i=1;i<=n;i++)cin>>a[i];
	int zx=a[1]-1;
	for(register int i=2;i<=n;i++){
		if(a[i]<zx){cout<<"No"<<endl;return 0;}
		zx=max(a[i]-1,zx);
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int N = cin.nextInt();
        int L = cin.nextInt();
        String[] S = new String[N];
        for (int i = 0; i < N; i++) {
            S[i] = cin.next().substring(0, L);
        }

        Arrays.sort(S);

        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < N; i++) {
            sb.append(S[i]);
        }

        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 21844
n=int(input())
arr=[[0,0,0]]+[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
  t1,x1,y1=arr[i]
  t2,x2,y2=arr[i+1]
  if abs(x1-x2)+abs(y1-y2)>t2-t1:
    print('No')
    exit()
  if (abs(x1-x2)+abs(y1-y2))%2!=(t2-t1)%2:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 27800
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)

int main() {
    string s; cin >> s;
    int n = s.size();
    bool b = true;
    while(s.size() > 0){
        if(s.substr(0,2) == "hi") s = s.substr(2);
        else{
            b = false;
            s = "";
        }
    }
    if(b) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main() {
    string S;
    cin >> S;
    int a = S.size();
    int counter = 0; 
    for(int i = 0; i < a; i++) {
        if(S.at(i) != S.at(a-1-i)) {
            ++counter;
        }
    }
    cout << counter/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int number,AC=0,WA=0,TLE=0,RE=0;
    string temp;
    cin>>number;
    for (int i=0;i<number;++i)
    {
        cin>>temp;
        if(temp=="AC")
            ++AC;
        else if(temp=="WA")
            ++WA;
        else if(temp=="TLE")
            ++TLE;
        else if(temp=="RE")
            ++RE;
    }
    printf("AC x %d\n",AC);
    printf("WA x %d\n",WA);
    printf("TLE x %d\n",TLE);
    printf("RE x %d\n",RE);
    return 0;
}


Measured memory_bytes: 3680
#include <stdio.h>

#define black 1
#define white 0

int main(){
  int num,buf,a[110][110],all,in;
  int i,j;

  scanf("%d",&num);
  
  for(i=1;i<=num;i++){
    scanf("%d%d",&buf,&all);
    if(all==0) continue;
    for(j=1;j<=all;j++){
      scanf("%d",&in);
      a[i][in]=black;
    }
  }
  
  for(i=1;i<=num;i++){
    for(j=1;j<=num;j++){
      if(a[i][j]==black) printf("%d",a[i][j]);
      else printf("%d",a[i][j]);
      if(j!=num)printf(" ");
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2128
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(long.Parse).ToArray();
		Console.WriteLine(Factorize(Gcd(h[0], h[1])).Distinct().Count() + 1);
	}

	static long Gcd(long x, long y) { for (long r; (r = x % y) > 0; x = y, y = r) ; return y; }

	static long[] Factorize(long n)
	{
		long rn = (long)Math.Ceiling(Math.Sqrt(n)), x = 2;
		var r = new List<long>();
		while (n % x == 0) { r.Add(x); n /= x; }
		for (x++; x <= rn && n > 1; x += 2)
			while (n % x == 0) { r.Add(x); n /= x; }
		if (n > 1) r.Add(n);
		return r.ToArray();
	}
}


Measured memory_bytes: 13396
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll dp[41][401][401];

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

    // input
    ll N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    
    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N);
    FOR(i, 0, N){
        cin >> A.at(i);
        cin >> B.at(i);
        cin >> C.at(i);
    }
    
    FOR(i, 0, 41){
        FOR(j, 0, 401){
            FOR(k, 0, 401){
                dp[i][j][k] = inf;
            }
        }
    }
    dp[0][0][0] = 0;
    
    FOR(i, 1, N+1){
        // i番目の薬を使うかどうか
        ll a = A[i-1];
        ll b = B[i-1];
        ll c = C[i-1];

        FOR(j, 0, 401){
            FOR(k, 0, 401){
                dp[i][j][k] = dp[i-1][j][k];
                if(j-a>=0 && k-b>=0){
                    dp[i][j][k] = min(dp[i-1][j][k], dp[i-1][j-a][k-b] + c); 
                }
            }
        }
    }

    ll min_cost = inf;

    FOR(i, 1, 401){
        FOR(j, 1, 401){
            if(j * Ma == i * Mb){
                ll cost = dp[N][i][j];
                min_cost = min(min_cost, cost);
            }
        }
    }

    // p("確認");
    // FOR(i, 1, 5){
    //     FOR(j, 1, 5){
    //         cout << i << " " << j << " " << dp[N][i][j] << endl;
    //     }
    // }
    

    if(min_cost==inf){
        p(-1);
    }else{
        p(min_cost);
    }
    
    return 0;
}

Measured memory_bytes: 51712
#include <stdio.h>

int main(void){
    int i,j,N;
    int a[101];
    int cnt = 0;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&a[i]);
    }
    /*for(i=0;i<N;i++){
        printf("%d\n",a[i]);
    }*/
    for(i=1;i<N;i++){
        if(a[i-1]==a[i]){
            a[i] += 4;
            cnt++;
        }
    }
    /*for(i=0;i<N;i++){
        printf("%d\n",a[i]);
    }*/
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int N = 1000000;
		boolean[] primes = new boolean[N + 1];

		primes[0] = true;
		primes[1] = true;
		for (int i = 2; i <= N / 2; i++) {
			for (int j = 2; j <= N / i; j++) {
				primes[i * j] = true;
			}
		}

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line);
			if (n == 0) {
				break;
			}
			int count = 0;
			for (int i = n; i >= n / 2; i--) {
				if (!primes[i] && !primes[n - i]) {
					count++;
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 22056
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll N) {
  auto s = to_string(N);
  int ans = count_if(ALL(s), [](char c) { return c == '2'; });
  cout << ans << endl;
}

int main() {
  ll N;
  cin >> N;
  solve(N);
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int SURP = 1000000007;

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

	int N = s.length();
	int ret = N;
	FOR(i,0,N-1){
		if(s[i] != s[i+1]){
			ret = min(ret,max(i+1,N-i-1));
		}
	}

	cout << ret << endl;
	return 0;

}


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

void call(int n) {
  int i = 1;
CHECK_NUM:
  int x = i;
  if (x % 3 == 0) {
    cout << " " << i;
    goto END_CHECK_NUM;
  }
INCLUDE3:
  if (x % 10 == 3) {
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if (x) goto INCLUDE3;
END_CHECK_NUM:
  if (++i <= n) goto CHECK_NUM;

  cout << endl;
}

int main() {
  int N;
  cin >> N;
  call(N);
}


Measured memory_bytes: 3104
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1000006;
int f[N],A[N],B[N],i,j,k,n,m,d,an;
bool F=1;
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

int read(){ int z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }

int getC()
{
	do c=getc(); while (c<'a'||c>'z');
	return c-'a';
}

int solve()
{
	n=read();
	for (register int i=1;i<=n;++i) A[i]=getC();
	for (register int i=1;i<=n;++i) B[i]=getC(),F&=A[i]==B[i];
	B[0]=-1;
	if (F) return 0;
	an=1;
	for (register int i=n,j=n;i;--i)
		if (B[i]!=B[i-1])
		{
			for (j=min(i,j);j&&A[j]!=B[i];--j)  f[j+d]=-d;
			if (!j) return -1;
			++d;
			if (j<i) an=max(an,f[i-1+d]+d+1);
			--j;
		}
	return an;
}

int main()
{
	//freopen("1.in","r",stdin);
	printf("%d\n",solve());
	return 0;
}

Measured memory_bytes: 14464
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
 
using namespace std;
 
int main(void) {
	int a[3];
	for (int i = 0; i < 3; ++i)
	{
		cin >> a[i];
	}
	int five = 0;
	int seven = 0;
	for (int i = 0; i < 3; ++i)
	{
		if (a[i] == 5)
		{
			++five;
		}
		if (a[i] == 7)
		{
			++seven;
		}
	}
	cout << (five == 2 && seven == 1 ? "YES" : "NO") << endl;
	return 0;
}


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

int main(){
  int h,n;
  cin >> h >> n;
  vector<int>vec(n);
  int c=0;
  
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
    c += vec.at(i);
  }
  
  if(c>=h)
    cout <<"Yes"<< endl;
  else
    cout <<"No"<< endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    string A, B, C;
    cin >> A >> B >> C;
    
    int ans = 0;
    for(int i=0;i<N;i++){
        if(A[i] == B[i] && B[i] == C[i]){
            ans += 0;
        }else if(A[i] == B[i] || B[i] == C[i] || C[i] == A[i]){
            ans += 1;
        }else{
            ans += 2;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args)throws Exception{
    Scanner sc=new Scanner(System.in);
    String S=sc.next();
    if(S.endsWith("s")){
      System.out.println(S+"es");
    }else{
      System.out.println(S+"s");
    }
  }
}


Measured memory_bytes: 38452
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int64_t n;
  cin >> n;
  vector<int64_t> k(n+1,0);
  vector<int64_t> u(n,0);
  rep(i,n){
    int64_t a;
    cin >> a;
    u[i]=a;
    k[a]++;
  }
  int64_t ans=0;
  rep(i,n){
    ans+=k[i+1]*(k[i+1]-1)/2;
  }
  rep(i,n){
    int64_t y=u[i];
    int64_t fin=ans;
    fin=fin-k[y]*(k[y]-1)/2+(k[y]-1)*(k[y]-2)/2;
    cout << fin << endl;
  }
}


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

int main(void) {
  ll N;
  cin >> N;
  ll A[1LL << 18];
  REP(i, 0, 1LL << N) scanf("%lld", A + i);

  ll ans = 0;
  REP(k, 1, 1LL << N) {
    ll p = 0, q = 0;
    ll i = k;
    do {
      if(A[i] > p) {
        q = p;
        p = A[i];
      } else if(A[i] > q) {
        q = A[i];
      }
      i = (i - 1) & k;
    } while(i != k);
    ans = max(ans, p + q);
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 5120
def find_pair(n,y)
  if n*10000 < y
    return [-1,-1,-1]
  end

  (y/10000 + 1).times do |i|
    r_y = y-i*10000
    r_n = n-i
    next if r_n*5000 < r_y

    (r_y/5000 + 1).times do |j|
      if j*5000 + (r_n-j)*1000 == r_y
        return [i, j, r_n-j]
      end
    end
  end

  return [-1,-1,-1]
end

(n,y)=gets.chomp.split(' ').map(&:to_i)
puts find_pair(n,y).join(' ')


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

int main(){
    ll h, w; cin >> h >> w;
    ll c = h * w;
    if(h == 1 || w == 1){
        cout << 1 << endl;
        return 0;
    }
    if(c % 2 == 1){
        cout << c / 2 + 1;
        return 0;
    }else{
        cout << c / 2;
        return 0;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

//namespace _4_B

class Program
{
    static void Main(string[] args)
    {
        //??\??????????????°???????????????
        double r = double.Parse(Console.ReadLine());

        //??¢???????¨??????????
        double equivalent = 3.141592653589 * Math.Pow(r, 2);

        //string??????????????????????????????????????¨?????????
        string e = equivalent.ToString("F6");

        //??¨?????????????¨??????????
        double around = 2 * 3.141592653589 * r;

        //string??????????????????????????????????????¨?????????
        string a = around.ToString("F6");

        //?????????????????????
        Console.WriteLine(e + " " + a);

    }
}

Measured memory_bytes: 9436
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b

signed main(){
	int n; cin>>n;
	string s; cin>>s;
	int a=0,b=0;
	rep(i,0,s.size()){
		if(s[i]=='R')a++;
		else b++;
	}
	if(a>b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define pbb pair<bool,bool>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xmod (ll)(1e9+7) 
#define hmod 1286031825167LL
using namespace std;
string s;
int len,ct1,ct2;
int main(){	
    ios::sync_with_stdio(false);
	cin >> s; len=s.length();
	for (int i=1;i<len;i++){
		if (s[i] != s[i-1])
		ct1++;
	}
	for (int i=len-2;i>=0;i--){
		if (s[i] != s[i+1])
		ct2++;
	}
	cout << min(ct1,ct2) << "\n";
    return 0;
}	

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

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

    int c = stoi(a + b);

    for (int i = 1; i * i <= c; i++) {
        if (i * i == c) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
typedef long long ll;
using namespace std;

int dr[] = {0, 0, -1, +1, -1, -1, +1, +1};
int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1};

int main(){
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll moves = min(x/d, k);

    if((k-moves)&1) 
        cout << d - x%d << endl;
    else cout << x - moves * d << endl;
}



Measured memory_bytes: 3636
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

static inline uint32_t
decode(char *s)
{
	const int p = 4;
	int i;
	uint32_t res = 0;

	for (i = 0; i <= 12; i++)
		switch (*s++) {
		case 'A':
			break;
		case 'C':
			res |= 1 << (i * 2 + p);
			break;
		case 'G':
			res |= 2 << (i * 2 + p);
			break;
		case 'T':
			res |= 3 << (i * 2 + p);
			break;
		case '\0':
		default:
			goto end;
		}

end:
	return res | i;
}

int
main(int argc, char **argv)
{
	int i, j, n, m;
	uint32_t *d;
	char cmd[16];
	char name[16];
	const int dlen = (1<<28)/8;

	scanf("%d", &n);
	if (n <= 0)
		return 1;

	d = (uint32_t *)malloc(dlen);
	if (d == NULL)
		return 1;
	memset(d, 0, dlen);

	for (i = m = 0; i < n; i++) {
		scanf("%s", cmd);
		if (cmd[0] == 'i') {
			uint32_t v;
			scanf("%s", name);
			v = decode(name);
			d[v/32] |= 1 << (v%32);
		} else if (cmd[0] == 'f') {
			uint32_t v;
			scanf("%s", name);
			v = decode(name);
			printf("%s\n", (d[v/32] & (1 << (v%32))) ? "yes" : "no");
		}
	}

	return 0;
}



Measured memory_bytes: 34480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll l_inf=0x3f3f3f3f3f3f3f3f;
const int maxn=1010;
inline int read(){
    int x=0,c=getchar(),f=0;
    for(;c>'9'||c<'0';f=c=='-',c=getchar());
    for(;c>='0'&&c<='9';c=getchar())
    x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline bool scan_lf(double &num)
{
        char in;double Dec=0.1;
        bool IsN=false,IsD=false;
        in=getchar();
        if(in==EOF) return false;
        while(in!='-'&&in!='.'&&(in<'0'||in>'9'))
                in=getchar();
        if(in=='-'){IsN=true;num=0;}
        else if(in=='.'){IsD=true;num=0;}
        else num=in-'0';
        if(!IsD){
                while(in=getchar(),in>='0'&&in<='9'){
                        num*=10;num+=in-'0';}
        }
        if(in!='.'){
                if(IsN) num=-num;
                return true;
        }else{
                while(in=getchar(),in>='0'&&in<='9'){
                        num+=Dec*(in-'0');Dec*=0.1;
                }
        }
        if(IsN) num=-num;
        return true;
}
struct qwe{
	int x, y, step;
}t;
char s[55][55];
bool vis[55][55];
int xia[4][2] = {0,1,1,0,0,-1,-1,0};
int main()
{
	int n , m;
	while (~scanf("%d%d", &n, &m)){
		for (int i=0; i<n; i++)  scanf("%s", s[i]);
		
		int b = 0;
		for (int i=0; i<n; i++){
			for (int j=0; j<m; j++){
				if (s[i][j] == '#')  b ++;
			}
		}
		
		//cout << n*m - (n+m-1) - b << endl;
		memset(vis, false, sizeof vis);
		vis[0][0] = true;
		queue<qwe> q;
		t.x = 0 , t.y = 0 , t.step = 1;
		q.push(t);
		
		bool flag = false;
		while (!q.empty()){
			t = q.front();
			q.pop();
			for (int i=0; i<4; i++){
				int tx = t.x + xia[i][0];
				int ty = t.y + xia[i][1];
				if (tx<0 || ty<0 || tx>n-1 || ty>m-1 || vis[tx][ty] || s[tx][ty]=='#')
					continue;
				qwe tt;
				vis[tx][ty] = true;
				tt.x = tx , tt.y =  ty , tt.step = t.step + 1;
				q.push(tt);
				if (tx==n-1 && ty==m-1){
					flag = true;
					printf("%d\n", n*m-tt.step-b);
					break;
				}
			}
			if (flag)  break;
		}
		if (!flag)  puts("-1");
	}
	return 0;
}

Measured memory_bytes: 256
#ifndef ___GEOMETRY_LIBRARY
#define ___GEOMETRY_LIBRARY

#include <vector>
#include <algorithm>

template<class type>
class point2d {
public:
	type x, y;
	point2d() : x(type(0)), y(type(0)) {};
	point2d(type x_, type y_) : x(x_), y(y_) {};
	bool operator==(const point2d& p) { return x == p.x && y == p.y; }
	bool operator!=(const point2d& p) { return x != p.x || y != p.y; }
	point2d& operator+=(const point2d& p) { x += p.x; y += p.y; return *this; }
	point2d& operator-=(const point2d& p) { x -= p.x; y -= p.y; return *this; }
	point2d& operator*=(type val) { x *= val; y *= val; return *this; }
	point2d& operator/=(type val) { x /= val; y /= val; return *this; }
	point2d operator+(const point2d& p) const { return point2d(*this) += p; }
	point2d operator-(const point2d& p) const { return point2d(*this) -= p; }
	point2d operator*(type val) const { return point2d(*this) *= val; }
	point2d operator/(type val) const { return point2d(*this) /= val; }
	type norm() const { return x * x + y * y; }
	type abs() const { return type(std::sqrt(x * x + y * y)); }
	long double fabs() const { return std::sqrt((long double)(x * x + y * y)); }
	type dot(const point2d& p) const { return x * p.x + y * p.y; }
	type cross(const point2d& p) const { return x * p.y - y * p.x; }
	int ccw(const point2d& p1, const point2d& p2) const {
		point2d pr1 = p1 - point2d(*this);
		point2d pr2 = p2 - point2d(*this);
		if (pr1.cross(pr2) != 0) return pr1.cross(pr2) > 0 ? 1 : -1;
		if (pr1.dot(pr2) < 0) return 2;
		return pr1.norm() < pr2.norm() ? -2 : 0;
	}
};

template<class type>
class segment2d {
public:
	point2d<type> p1, p2;
	segment2d() : p1(point2d<type>()), p2(point2d<type>()) {};
	segment2d(const point2d<type>& p1_, const point2d<type>& p2_) : p1(p1_), p2(p2_) {};
	type norm() const { return (p1 - p2).norm(); }
	type abs() const { return (p1 - p2).abs(); }
	long double fabs() const { return (p1 - p2).fabs(); }
};

#endif // ___GEOMETRY_LIBRARY

#include <iostream>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	segment2d<double> s;
	cin >> s.p1.x >> s.p1.y >> s.p2.x >> s.p2.y;
	int q;
	cin >> q;
	cout.precision(15);
	for (int i = 0; i < q; ++i) {
		point2d<double> p;
		cin >> p.x >> p.y;
		double r = (p - s.p1).dot(s.p2 - s.p1) / (s.p2 - s.p1).norm();
		point2d<double> ans = p + (s.p1 + (s.p2 - s.p1) * r - p) * 2;
		cout << ans.x << ' ' << ans.y << '\n';
	}
	return 0;
}


Measured memory_bytes: 3316
import scala.io.StdIn

object Main extends App {
  var numberCounter = scala.collection.mutable.Map[Long,Long]().withDefaultValue(0)
  StdIn.readLine()
  val numbers = StdIn.readLine().split(' ').map(_.toLong)
  for(num <- numbers){
    numberCounter(num) = numberCounter(num)+1
  }

  val opNum=StdIn.readLine().toInt
  val operations :Seq[(Long,Long)]=for(i <- 1 to opNum)yield{
    val Array(a,b)=StdIn.readLine().split(' ').map(_.toLong)
    (a,b)
  }
  var tmp = numberCounter.map{case (k,v) => k*v}
    .sum
  for((a,b) <- operations){
    tmp = tmp - a*numberCounter(a) + b*(numberCounter(a))
    numberCounter(b) = numberCounter(b)+numberCounter(a)
    numberCounter(a) = 0

    println(tmp)
  }


}


Measured memory_bytes: 80944
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i<N; i++)
#define RVROOP(i, N) for(int i=N; i>=0; i--)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
bool NotPrime(int num)
{
    if (num < 2) return true;
    else if (num == 2) return false;
    else if (num % 2 == 0) return true; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return true;
        }
    }

    // 素数である
    return false;
}
int main() {
  int X; cin>>X;
  while(NotPrime(X)){
    X++;
  }
  cout<<X<<endl;
}

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

const ll MOD = 1e9+7;

ll Step(int num);

ll cnt = 0, dbg = 0;
int n, m;
map<int, int> hole;
vector<ll> memo(1e5+3, -1);

int main(){

    cin >> n >> m;
    for (int i=0; i<m; ++i){
        int temp;
        cin >> temp;
        hole[temp]++;
    }

    cnt = Step(n);
//    dbg = Step(2);

    cout << cnt << endl;
//    cout << dbg << endl;
    return 0;
}

ll Step(int num){

    if (hole.count(num)){
        return memo.at(num) = 0;
    }
    else{
        if (memo.at(num) != -1){
            return memo.at(num)%MOD;
        }
        // num==2の時の値を2にすると、num==1がholeの時の結果がおかしくなる
        else if (num <= 1){
            return 1;
    //        return 1;
        }
        else{
            return memo.at(num) = (Step(num - 1)%MOD + Step(num - 2)%MOD)%MOD;
        }
    }
}

Measured memory_bytes: 5760
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll Q, H, S, D;
    cin >> Q >> H >> S >> D;

    ll N;
    cin >> N;

    // 0.5 liter price
    H = min(2*Q, H);

    // 1.0 liter price
    S = min(2*H, S);

    if(2*S <= D){
        // all 1 liter
        p(S*N);
    }else{
        ll odd = N % 2;
        ll even = N - odd;
        ll price = odd * S + even * D / 2;
        p(price);
    }

    return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
D=[]
A=[0 for _ in range(N)]
for _ in range(K):
    d=int(input())
    a=map(int,input().split())
    D.append(a)
for z in D:
    for y in z:
        A[y-1]+=1
print(A.count(0))


Measured memory_bytes: 68164
#include<bits/stdc++.h>
using namespace std;
int main(){
  long h,w;cin>>h>>w;
  long b=0;
  vector<string>S(h);for(long i=0;i<h;i++){
    cin>>S[i];
    for(char c:S[i])if(c=='#')b++;
  }
  vector<long>D(w*h,-1);D[0]=0;
  queue<long>q;q.push(0);
  while(q.size()){
    long f=q.front();q.pop();
    if(f/w-1>=0&&D[f-w]==-1&&S[f/w-1][f%w]!='#'){
      D[f-w]=D[f]+1;q.push(f-w);
    }
    if(f/w+1<h&&D[f+w]==-1&&S[f/w+1][f%w]!='#'){
      D[f+w]=D[f]+1;q.push(f+w);
    }
    if(f%w-1>=0&&D[f-1]==-1&&S[f/w][f%w-1]!='#'){
      D[f-1]=D[f]+1;q.push(f-1);
    }
    if(f%w+1<w&&D[f+1]==-1&&S[f/w][f%w+1]!='#'){
      D[f+1]=D[f]+1;q.push(f+1);
    }
  }
  cout<<(D[w*h-1]!=-1?(w*h)-D[w*h-1]-b-1:-1)<<endl;
}

Measured memory_bytes: 3632
def main():
    n, a, b = map(int, input().split())
    data = [int(input()) for i in range(n)]
    ans = 0
    for i in range(n):
        if data[i] < a or data[i] >= b:
            ans += 1
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


transform = {
        'A': 'T',
        'T': 'A',
        'C': 'G',
        'G': 'C'
        }
b = s_in()
print(transform[b])



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

typedef long long ll;
typedef long double ld;

const int inf = 1e9;

int main(){
  int n;
  cin>>n;
  ll sum = 0;
  int u = 0;
  for(int i = 1; u < n; ++i, u++){
    if(i % 5 == 0 && i % 3 == 0)continue;
    if(i % 3 == 0 || i % 5 == 0)continue;
    sum += i;
  }
  cout<<sum<<endl;  
  return 0;
}




Measured memory_bytes: 3644
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<string> vs;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int n;

int main()
{
    cin >> n;
    cout << n / 3 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define PB push_back
#define POP pop_back()
#define PII pair<int,int>
#define FI first
#define SE second
#define ULL unsigned long long
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;

int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	while(n>1000)n-=1000;
	cout<<1000-n<<endl; 
 	return 0;
}







Measured memory_bytes: 3604
a,b,c,d=map(int,raw_input().split())
if a%d==0:
	p=a/d
else:
	p=a/d + 1

if c%b==0:
	q=c/b
else:
	q=c/b + 1

if q<=p:
	print "Yes"

else:
	print "No"

Measured memory_bytes: 64264
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;
    int n;
    cin >> n;
    int sum = 0;
    int nn = n;
    while(nn){
        sum += nn % 10;
        nn /= 10;
    }
    cout << (n % sum == 0 ? "Yes" : "No") << '\n';  
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}   

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
int main()
{
	int a, b, c,d=0;
	scanf("%d%d%d", &a, &b, &c);
	if (a % b != 0)
	{
		d = 1;
	}
	d = d + a / b;
	printf("%d", d * c);
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // 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 all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

signed main() {
  int N; cin >> N;
  vector<int> L(N);
  rep(i, N) {
    cin >> L[i];
  }
  sort(all(L));
  int ans = 0;
  FOR(i,0,N-2){
    FOR(j,i+1,N-1){
      FOR(k, j + 1, N) {
        if(L[i]+L[j] > L[k]) ans ++;
        else break;
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;
typedef vector<vl> v2;
typedef vector<v2> v3;
typedef vector<v3> v4;


const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;


graph tree;
ll n,q;
vl cnt;

void dfs(ll x){
  for(auto y : tree[x]){
    cnt[y.first] += cnt[x];
    dfs(y.first);
  }
}

int main(){
  cin >> n >> q;
  cnt = vl(n+1);
  for(ll i = 0;i < n-1;i++){
    ll a,b;
    cin >> a >> b;
    tree[a][b] = 0;
  }
  for(ll i = 0;i < q;i++){
    ll p,x;
    cin >> p >> x;
    cnt[p] += x;
  }
  dfs(1);
  for(ll i = 1;i <= n;i++) cout << cnt[i] << " ";
  cout << endl;

}


Measured memory_bytes: 40392
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    int A,B;
    cin >> A >> B;
    for(int i = 0; i <= 100000; i++){
        if(floor(double(i)* 0.08) == A && floor(double(i)* 0.10) == B){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

}


Measured memory_bytes: 256
from collections import deque
H,W=map(int,input().split())
stack=deque()
c=[input() for i in range(H)]
ans=0
reached=[[-1]*W for i in range(H)]
for i in range(H):
    for j in range(W):
        if c[i][j]=="#":
            stack.append((i,j))
            reached[i][j]=0
dydx=[(1,0),(-1,0),(0,1),(0,-1)]
while(stack):
    Y,X=stack.popleft()
    for dy,dx in dydx:
        y=Y+dy
        x=X+dx
        if y<0 or y>=H or x<0 or x>=W or c[y][x]=="#":
            continue
        if reached[y][x]!=-1:
            continue
        stack.append((y,x))
        reached[y][x]=reached[Y][X]+1
        ans=max(ans,reached[y][x])
print(ans)


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

long long mod = 1000000007LL;

long long dp[20000];
typedef pair<long long, long long> ii;
int main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	priority_queue<ii, vector<ii>, greater<ii> > pq;
	long long n, D, A; cin >> n >> D >> A;
	for(int i = 0;i < n;i++){
		long long x, h; cin >> x >> h;
		long long k = h / A;
		if(h % A != 0) k++;
		pq.push(ii(x,k));
	}
	long long acc = 0;
	long long ans = 0;
	while(!pq.empty()){
		ii u = pq.top(); pq.pop();
		//cout << u.first << " " << u.second << " " << acc << "\n";
		if(u.second <= 0){ //update
			acc += u.second;
		}
		else{
			long long L = u.second - acc;
			if(L <= 0) continue;
			else{
				ans += L;
				acc += L;
				pq.push(ii(u.first + 2 * D + 1, -L));
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 6512
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

ll N;

int main() {
  cin >> N;
  ll ans = 1;
  repe(i, 1, N) {
    ans *= i;
    ans %= MOD;
  }
  cout << ans;
}


Measured memory_bytes: 3576
import sys
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


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


def main():
    N, M = inpl()
    A = inpl()
    print(max(N - sum(A), -1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 68436
import math

n,k=map(int,input().split())
for i in range(1,k+1):
  if n-k<i-1:
      print(0)
  else :
    a=math.factorial(k-1)
    b=math.factorial(i-1)
    c=math.factorial(k-i)
    d=math.factorial(n-k+1)
    e=math.factorial(i)
    f=math.factorial(n-k-i+1)
    g=a//b//c
    h=d//e//f
    print(g*h%1000000007)

Measured memory_bytes: 3316
n = int(input())

a, b = 0, 0
c = 0
ans = 0
for i in range(n):
    t, x, y = map(int, input().split())
    if (t - c) % 2 == (abs(x - a) + abs(y - b)) % 2 and abs(x - a) + abs(y - b) <= t - c:
        continue
    else:
        ans = 1
if ans == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 45032
S=list(input())
n=len(S)
mod=10**9+7
dp=[[0]*4 for i in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
  if S[i-1]=="A":
    dp[i][0]=dp[i-1][0]%mod
    dp[i][1]=(dp[i-1][0]+dp[i-1][1])%mod
    dp[i][2]=dp[i-1][2]%mod
    dp[i][3]=dp[i-1][3]%mod
  elif S[i-1]=="B":
    dp[i][0]=dp[i-1][0]%mod
    dp[i][1]=dp[i-1][1]%mod
    dp[i][2]=(dp[i-1][1]+dp[i-1][2])%mod
    dp[i][3]=dp[i-1][3]%mod
  elif S[i-1]=="C":
    dp[i][0]=dp[i-1][0]%mod
    dp[i][1]=dp[i-1][1]%mod
    dp[i][2]=dp[i-1][2]%mod
    dp[i][3]=(dp[i-1][2]+dp[i-1][3])%mod
  else:
    dp[i][0]=dp[i-1][0]*3%mod
    dp[i][1]=(dp[i-1][0]+dp[i-1][1]*3)%mod
    dp[i][2]=(dp[i-1][1]+dp[i-1][2]*3)%mod
    dp[i][3]=(dp[i-1][2]+dp[i-1][3]*3)%mod
print(dp[n][3])

Measured memory_bytes: 28324
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;cin>>N>>K;
  vector<int> l(N);
  for(int i=0; i<N; i++)cin>>l[i];
  sort(l.begin(),l.end(),greater<int>());
  int wa=0;
  for(int i=0; i<K; i++){
    wa+=l[i];
  }
  cout<<wa<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;

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

int table[15][15];

int dup(string s,string t) {
  int i,j,k = min(s.length(), t.length());
  for(int i=k; i>=0; --i) {
    if(s.substr(s.length()-i) == t.substr(0,i)) {
      return i;
    }
  }
  return 0;
}

string conc(vector<int> &perm,vector<string> &input) {
  string res = input[perm[0]];
  for(int i=0; i<perm.size()-1; ++i) {
    res += input[perm[i+1]].substr(table[perm[i]][perm[i+1]]);
  }
  return res;
}

bool issubstr(string s,string t) {
  if(s.length() > t.length()) return false;
  for(int i=0; i<t.length()-s.length(); ++i) {
    if(t.substr(i,s.length()) == s) return true;
  }
  return false;
}

int main() {
  int i,j,k,tt,n;
  while(cin>>n, n) {
    memset(table,0, sizeof(table));

    vector<string> input(n),tmp;
    vector<int> dd;
    rep(i,n) cin>>input[i];

    rep(i,n) rep(j,n) if(issubstr(input[i],input[j])) dd.push_back(i);

    rep(i,n)
      if(find(dd.begin(), dd.end(), i) == dd.end()) tmp.push_back(input[i]);
    input.clear();
    rep(i,tmp.size()) input.push_back(tmp[i]);

    sort(input.begin(), input.end());
    rep(i,input.size()) rep(j,input.size()) table[i][j] = dup(input[i],input[j]);

    vector<int> perm;
    int total = 0;
    rep(i,input.size()) {
      perm.push_back(i);
      total += input[i].length();
    }

    int ans = 1<<29;
    string sa = "";
    do{
      tt = 0;
      rep(i,input.size()-1) {
	tt += table[perm[i]][perm[i+1]];
      }

      if(ans > total-tt) {
	ans = total-tt;
	sa = conc(perm,input);
      }else if(ans == total-tt) {
	string t = conc(perm,input);
	if(sa > t) sa = t;
      }
    }while(next_permutation(perm.begin(), perm.end()));

    cout<<sa<<endl;
  }
}

Measured memory_bytes: 924