akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
using namespace std;

char map1[55][55], map2[55][55];
int n, m;

int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j <= n; ++j)
		{
			cin >> map1[i][j];
		}
	}
	for(int i = 1; i <= m; ++i)
	{
		for(int j = 1; j <= m; ++j)
		{
			cin >> map2[i][j];
		}
	}
	
//	for(int i = 1; i <= n; ++i)
//	{
//		for(int j = 1; j <= n; ++j)
//		{
//			cout << map1[i][j];
//		}
//		cout << endl;
//	}
//	for(int i = 1; i <= m; ++i)
//	{
//		for(int j = 1; j <= m; ++j)
//		{
//			cout << map2[i][j];
//		}
//		cout << endl;
//	}
	
	
	for(int i = 0; i <= n - m; ++i)
	{
		for(int j = 0; j <= n - m; ++j)
		{
			bool flag = true;
			for(int k = 1; k <= m; ++k)
			{
				for(int w = 1; w <= m; ++w)
				{
					if(map1[i + k][j + w] != map2[k][w])
					{
						flag = false;
					}
				}
			}
			if(flag == true)
			{
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");
	return 0;
}

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

using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<bitset<20>> bita(n);
    for(int i=0;i<n;i++){
        bita[i]=a[i];
    }

    auto conflict=[](bitset<20> &lhs,bitset<20> &rhs){
        bool res=false;
        for(int j=0;j<20;j++){
            res|=(lhs[j] && rhs[j]);
        }
        return res;
    };
    ll res=0;
    ll tail=0;
    bitset<20> st=0;
    for(int i=0;i<n;i++){
        while(conflict(st,bita[i])){
            st^=bita[tail];
            tail++;
        }
        res+=i+1-tail;
        st^=bita[i];
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 2688
import scala.io.StdIn.readLine
import scala.math.{max,min}

object Main extends App {

  def getResult():Unit = {
    val Array(n,x) = readLine.split(" ").map(_.toInt)
    if( n!=0 || x!=0) {
      println( ( 1 until min(n-1,x/3) ).foldLeft(0) { (sum,i) => sum + max(min(n,(x-i+1)/2)- max(i+1,x-i-n),0)})
      getResult()
    }
  }

  getResult()
}

Measured memory_bytes: 44136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

struct Edge{
    int val;
    int id;
    Edge(int v,int i) : val(v),id(i){}
};
vector<vector<Edge>> G;
vector<int> ans;
void dfs(int now,int parent,int pre){
    int k = 1;
    for(auto next : G[now]){
        if(next.val==parent) continue;
        if(k==pre) ++k;
        ans[next.id] = k; ++k;
        dfs(next.val,now,ans[next.id]);
    }
}
int main(){
    int n;cin >> n;
    G.resize(n);
    ans.resize(n-1);
    rep(i,n-1){
        int a,b;cin >> a >> b;
        --a;--b;
        G[a].push_back(Edge(b,i));
        G[b].push_back(Edge(a,i));
    }
    dfs(0,-1,-1);
    int N = 0;
    rep(i,n-1) chmax(N,ans[i]);
    cout << N << endl;
    rep(i,n-1) cout << ans[i] << endl;
}

Measured memory_bytes: 8320
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		int B[] = new int[N];
		int C[] = new int[N];
		for(int i = 0 ; i < N ; ++i) {
			A[i] = sc.nextInt() - 1;
		}
		for(int i = 0 ; i < N ; ++i) {
			B[i] = sc.nextInt();
		}
		for(int i = 0 ; i < N - 1; ++i) {
			C[i] = sc.nextInt();
		}
		int S = 0;
		for(int i = 0 ; i < N ; ++i) {
			S += B[A[i]];
			if(i >= 1) {
				int cur = A[i];
				int prev = A[i - 1];
				if(prev + 1 == cur) {
					S += C[prev];
				}
			}
		}
		System.out.println(S);
	}
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;
int finder(vector<string> vec,string w){
    auto itr=find(all(vec),w);
    int index=distance(vec.begin(),itr);
    if (index!=vec.size()){
        return 1;
    }
    else{
        return 0;
    }
}

int main() {
    
    string s;
    cin>>s;
    vector<string> ss;
    for (int i=0;i<s.size();i++){
        string w="";
        for (int j=i;j<s.size();j++){
            w+=s.at(j);
            if (ss.size()<5){
                if (! finder(ss,w)){

                ss.push_back(w);
                sort(all(ss));
            }}
            else if (ss.at(4)>w){
                if (!finder(ss,w)){
                ss.push_back(w);
                sort(all(ss));
                ss.pop_back();
            }}
        }
    }
    int k;
    cin>>k;
    cout<<ss[k-1]<<endl;


    return 0;
}

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

int main()
{
	float n;
	scanf("%f", &n);

	for(int i=1; i<=50000; i++){
		if(floor(i*1.08)==n){
			printf("%d", i);
			return 0;
		}
	}
	printf(":(");

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
pair<int,int>a[100001];
int n ;
int main() {
  cin >> n ;
  for ( int i = 1 ; i <= n; i++ ){
    cin >> a[i].first ;
    a[i].second = i ;
  }
  sort ( a + 1 , a + n + 1 ) ;
  for( int i = 1 ; i <= n ; i++ )
    cout << a[i].second << " " ;
}

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

using namespace std;

typedef long long ll;

int main()
{
    int N;
    cin>>N;
    for(int i=1; i<=9; i++)
    {
        if(N%i==0 && N/i<=9)
        {
            cout<<"Yes";
            return 0;
        }

    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        N = N;
        int [] A = new int [N];
        for(int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        if(possible(N,A,K)) {
            System.out.println("POSSIBLE");
        } else {
            System.out.println("IMPOSSIBLE");
        }
    }

    public static boolean possible(int N, int [] A, int K) {
        int s = A[0];
        boolean flag = false;
        for(int i = 0; i < N; i++) {
            s = gcd(s,A[i]);
            if(K <= A[i]) flag = true;
        }
        if(K % s > 0) return false;
        return flag;
    }

    public static int gcd(int n, int m) {
        int r = n % m;
        while(r != 0) {
            n = m; m = r;
            r = n % m;
        }
        return m;
    }
}


Measured memory_bytes: 50148
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n';

using namespace std;

char a, b;

int main(){

    cin >> a >> b;

    if(a > b){
        cout << ">";
    } else if(a < b){
        cout << "<";
    } else if(a == b){
        cout << "=";
    }


}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

// char** arr = new char*[r];
// for(long long i = 0; i < r; i++) arr[i] = new char[c];

Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const lint INF=1e18;
int n,K;
int ar[100005];
lint sum[100005],sump[100005];
int main(){
  cin>>n>>K;
  REP(i,n) cin>>ar[i];
  REP(i,n){
    sum[i+1]=sum[i]+ar[i];
    sump[i+1]=sump[i]+max(ar[i],0);
  }

  lint res=0;
  REP(i,n+1-K){
    {
      lint tmp=max(0ll,sum[i+K]-sum[i]);
      tmp+=sump[i];
      tmp+=sump[n]-sump[i+K];
      chmax(res,tmp);
    }
  }
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 2176
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long N,A;
main()
{
	cin>>N>>A;
	long ans=N;
	for(int k=1;k<40;k++)
	{
		long p=pow(N,1./(k+1));
		long now=1;
		for(int i=0;i<k;i++)now*=p;
		for(int i=0;i<=k;i++)
		{
			ans=min(ans,A*k+p*k+i+(N+now-1)/now);
			now=now/p*(p+1);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]

from scipy.sparse.csgraph import floyd_warshall as fw
import numpy as np
a = fw(A)
ans = 0
for i in range(N):
    a[i][i] = np.inf
for i in range(N):
    for j in range(i):
        if A[i][j]!=a[i][j]:
            print(-1)
            exit()
        else:
            if a[i][j] < np.min(a[i]+a[j]):
                ans += a[i][j]
print(int(ans))

Measured memory_bytes: 23556
package main

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

func main() {
	A, B := ReadInt(), ReadInt()
	fmt.Println(
		Max(A+B, A-B, A*B),
	)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1844
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y, z;
    cin >> x >> y >> z;
    cout << (x - z) / (y + z) << endl;
}

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

int main() {
	long long k,n;
	cin >> n >> k;
	vector<long long> a(n);
	
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	sort(a.begin(),a.end());
	
	long long sum = 0;
	for(int i = 0; i < n - k; i++){
		sum += a[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define INF = 1000000000;
#define LLINF = 1LL << 62;
#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; }

int main() {
    double a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    a *= 100, b *= 100;
    map<double, int> water, sugar;
    for (int i = 0; a * i <= f; i++)for (int j = 0; b * j <= f; j++) {
        if (i || j)water[a * i + b * j];
    }
    for (int i = 0; c * i <= f; i++)for (int j = 0; d * j <= f; j++) {
        sugar[c * i + d * j];
    }
    vector<tuple<double, double, double>> ans;
    for (auto w : water)for (auto s : sugar) {
        if (w.first * e / 100 < s.first)continue;
        if (w.first + s.first > f)continue;
        ans.push_back(make_tuple(s.first / (w.first + s.first), w.first, s.first));
    }
    rSORT(ans, [](tuple<double, double, double> x, tuple<double, double, double>y) {
        return get<0>(x) > get<0>(y);
        });
    cout << get<1>(ans[0]) + get<2>(ans[0]) << " " << get<2>(ans[0]) << endl;
}

Measured memory_bytes: 1088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll memo[201][201];

ll gcd(ll x,ll y){
    if(memo[x][y]!=0)return memo[x][y];
    if(x<y) return memo[x][y]=gcd(y,x);
    if(y==0) return memo[x][y]=x;
    return memo[x][y]=gcd(y,x%y);
}

int main(){fastio
    ll k;cin>>k;
    ll ans=0;
    rep(i,1,k){
        rep(j,1,k){
            rep(l,1,k){
                ans+=gcd(i,gcd(j,l));
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 3924
/*
横一列に並べられた N 枚のカードがある．
左から i 枚目(1 ≦ i ≦ N)のカードには，整数 a_i が書かれている．
JOI 君は，これらのカードを用いて次のようなゲームを行う．
連続する K 枚以上のカードの列を選び，次の操作を行う．
選んだカードを，書かれている整数が小さい順に左から並べる．
並べたカードのうち，左から K 番目のカードに書かれた整数を紙に書き出す．
選んだカードを，すべて元の位置に戻す．
この操作を，連続する K 枚以上のカードの列すべてに対して行う．
すなわち，1 ≦ l ≦ r ≦ N かつ K ≦ r - l + 1 を満たすすべての (l,r) について，
a_l, a_{l+1}, ..., a_r のうち K 番目に小さな整数を書き出す．
こうして書き出された整数を，左から小さい順に並べる．
並べた整数のうち，左から L 番目のものがこのゲームにおける JOI 君の得点である．JOI 君の得点を求めよ．
制約
1 <= N <= 200000
1 <= K <= N
1 <= a_i <= N
1 <= L
JOI 君が書き出す整数は L 個以上である．
入力・出力
入力
入力は以下の形式で標準入力から与えられる．
N K L
a_1 a_2 ... a_N
出力
JOI 君の得点を 1 行で出力せよ．
<入力例 1>
4 3 2
4 3 1 2
<出力例 1>
3
1 ≦ l ≦ r ≦ N (= 4) かつ K (= 3) ≦ r - l + 1 を満たす
 (l,r) は，(1,3), (1,4), (2,4) の 3 通りある．
これらの (l,r) に対し，a_l, a_{l+1}, ..., a_r で 3 番目に小さな整数は，
それぞれ 4, 3, 3 である．
このうち L (= 2) 番目に小さい整数は 3 なので，JOI 君の得点は 3 である．
同じ整数が複数あるときも，重複して数えることに注意せよ．
<入力例 2>
5 3 3
1 5 2 2 4
<出力例 2>
4
JOI 君が書き出す整数は，
(l,r) = (1,3) に対し 5
(l,r) = (1,4) に対し 2
(l,r) = (1,5) に対し 2
(l,r) = (2,4) に対し 5
(l,r) = (2,5) に対し 4
(l,r) = (3,5) に対し 4
である．このうち L (= 3) 番目に小さい整数は 4 である．
<入力例 3>
6 2 9
1 5 3 4 2 4
<出力例 3>
4
<入力例 4>
6 2 8
1 5 3 4 2 4
<出力例 4>
3
*/
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long int ll;
int n,K;
ll L;
int ar[200005];
ll count(int x){
	int j=0,sum=0;
	ll res=0;
	for(int i=0;i<n;i++){
		while(j<n&&sum<K){
			if(ar[j]<x)
			{
			++sum;
			}
			++j;
		}
		if(sum==K)res+=n-j+1;
		if(ar[i]<x){
			--sum;
		}
	}
	return res;
}
int main(){
	cin>>n>>K>>L;
	//配列を使うためLの番号を1つずらす
	--L;
	for(int i=0;i<n;i++){
		//カードの数字を入力する
		cin>>ar[i];
	}
	//左端を0にする、右恥をカードの枚数+1する
	int lb=0,ub=n+1;
	//差が1にいかになったとき出力に移行する
	while(ub-lb>1){
		int md=(lb+ub)/2;
		if(count(md)>L)ub=md;
		else lb=md;
	}
	cout<<lb<<endl;
	return 0;
}


Measured memory_bytes: 3872
s=list(input())

from itertools import product as pr

p = list(pr(['+','-'],repeat=3))

for ope in p:
    f = s[0] + ope[0] + s[1] + ope[1] + s[2] + ope[2] + s[3]

    if eval(f)==7:
        print(f+'=7')
        exit(0)



Measured memory_bytes: 8984
#include<stdio.h>
#include<string.h>
int main(){
  int i,j,n,a,b,c,k,l;
  char str[1001],mei[8],p[1001],x;
  scanf("%s %d",str,&n);
  for(i=0;i<n;i++){
    c=0;
    k=0;
    scanf("%s",mei);
    if(mei[2]=='i'){
      scanf("%d %d",&a,&b);
      for(j=a;j<=b;j++){
	printf("%c",str[j]);
	c=1;
      }
    }
      if(c!=0)printf("\n");
    else if(mei[2]=='v'){
      scanf("%d %d",&a,&b);
      c=b;
      for(j=a;j<=(a+b)/2;j++){
	x=str[j];
	str[j]=str[c];
	str[c]=x;
	c--;
      }
    }
    else if(mei[2]=='p'){
      scanf("%d %d %s",&a,&b,p);
      for(j=a;j<=b;j++){
	str[j]=p[k];
	k++;
      }
    }
  }
      return 0;
}
    

Measured memory_bytes: 576
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector <int> a(n);
	for (int i = 0; i < n; i++){
        cin >> a[i];
	}
	map <int, int> cnt;
	for (int i = 0; i < n; i++){
        cnt[a[i]]++;
        cnt[a[i] - 1]++;
        cnt[a[i] + 1]++;
	}
	int ans = 0;
	for (auto x : cnt){
	ans = max(ans, x.second);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7972
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    int a = 0, b = 0, c = 0, d = 0;
    rep(i,n){
        string s;
        cin >> s;
        if(s == "AC") a++;
        if(s == "WA") b++;
        if(s == "TLE") c++;
        if(s == "RE") d ++;
    }
    cout << "AC x "<<a<< endl;
    cout << "WA x "<<b<< endl;
    cout << "TLE x "<<c<< endl;
    cout << "RE x "<<d<< endl;
    return 0;
}


Measured memory_bytes: 3596
n = int(input())
a = list(map(int,input().split()))

b = a[:]
b.sort()

c = [[ 0 for _ in range(3)] for _ in range(n+1)]

ct = 1
tmp = b[1]
sum = 0
for j in range(1,n):
  if b[j] == b[j-1]:
    ct += 1
  else :  
    c[tmp][0] = ct
    cm = int(ct*(ct-1)/2)
    c[tmp][1] = cm
    cm1 = int((ct-1)*(ct-2)/2)
    c[tmp][2] = cm1
    sum += cm
    tmp = b[j]
    ct = 1

c[tmp][0] = ct
cm = int(ct*(ct-1)/2)
c[tmp][1] = cm
cm1 = int((ct-1)*(ct-2)/2)
c[tmp][2] = cm1
sum += cm      

for k in a:
  print(sum-c[k][1] + c[k][2])

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

int main() {
  long long N , A , B;
  cin >> N >> A >> B;

  long long answer = N % (A + B);
  if(answer > A){
    cout << N / (A + B) * A + A << endl;
  }

  else{
    cout << A * (N / (A + B)) + (N -  N / (A + B) * (A + B)) << endl; 
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) begin(x), end(x)
#define dump(x) cerr << #x " = " << x << endl
using ll = long long;
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }
template <typename X, typename T> auto make_vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_vectors(X x, Y y, Z z, Zs... zs) { auto cont = make_vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
template <typename T> ostream & operator << (ostream & out, vector<T> const & xs) { REP (i, (int)xs.size() - 1) out << xs[i] << ' '; if (not xs.empty()) out << xs.back(); return out; }
template<typename Functor> struct fix_type { Functor functor; template<typename... Args> decltype(auto) operator() (Args && ... args) const & { return functor(functor, std::forward<Args>(args)...); } };
template<typename Functor> fix_type<typename std::decay<Functor>::type> fix(Functor && functor) { return { std::forward<Functor>(functor) }; }

void solve1(vector<vector<int> > & g, vector<int> xs, int k) {
    int n = xs.size();
    if (n <= 1) {
        return;
    } else {
        vector<int> ys(xs.begin() + (n / 2), xs.end());
        xs.resize(n / 2);
        for (int x : xs) {
            for (int y : ys) {
                g[x][y] = k;
                g[y][x] = k;
            }
        }
        solve1(g, xs, k + 1);
        solve1(g, ys, k + 1);
    }
}

vector<vector<int> > solve(int n) {
    vector<vector<int> > g = make_vectors(n, n, -1);
    vector<int> xs(n);
    iota(ALL(xs), 0);
    solve1(g, xs, 1);
    return g;
}

int main() {
    int n; cin >> n;
    vector<vector<int> > g = solve(n);
    REP (y, n) {
        REP3 (x, y + 1, n) {
            cout << g[y][x];
            if (x + 1 < n) {
                cout << ' ';
            }
        }
        cout << endl;
    }
    return 0;
}


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

int main()
{
  int h,n,t,ans=0;
  cin >> h >> n;
  for(int i=0; i<n; i++){
    cin >> t;
    ans += t;
  }
  if(h > ans){
    cout << "No";
  }else{
    cout << "Yes";
  }
  return 0;
}


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

int main(){
    int H,R;
    cin>>H>>R;
    if (H + R == 0) {
    cout<<0<<endl;
    } else if (H + R >= 0) {
    cout<<1<<endl;
    } else {
    cout<<-1<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int len = s.size();
    int sublen = len - 7;
    for(int i=0;i<=7;i++){
        string cand = s.substr(0, i) + s.substr(sublen + i, 7 - i);
        // cout << cand << endl;
        if(cand == "keyence"){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

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

int main()
{
    int a, b, c;
    char p;

    int x = 0, y = 0;

    while( cin >> a >> p >> b >> p >> c )
    {
        if( a * a + b * b == c * c )
            x++;
        if( a == b )
            y++;
    }

    cout << x << endl << y << endl;

    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
const int maxn = 1e5 + 10;
int n, color[maxn], vis[maxn] = {0};

struct Edge{
    long long weight;
    int to;
};

vector <int> G[maxn];
vector <Edge> edges;


void dfs(int root){
    vis[root] = 1;
    int len = G[root].size();
    for(int i = 0; i < len; i++){
        int a = G[root][i];
        Edge e = edges[a];
        int to = e.to;
        if(!vis[to]){
            int col = color[root];
            if(e.weight % 2 == 0){color[to] = color[root];}
            else{
                color[to] = (color[root] + 1) % 2;
            }
            dfs(to);
        }
    }
}

int main(){
    scanf("%d", &n);
    memset(color, -1, sizeof(color));
    for(int i = 0; i < n - 1; i++){
        int u, v, p;
        scanf("%d%d%d", & u, &v, &p);
        Edge e;
        e.to = u - 1;e.weight = p;
        edges.push_back(e);
        int m = edges.size();
        G[v - 1].push_back(m - 1);
        e.to = v - 1;
        edges.push_back(e);
        G[u - 1].push_back(m);
    }
    color[0] = 0;
    dfs(0);
    for(int i = 0; i < n; i++){
        printf("%d\n", color[i]);
    }
    return 0;
}


Measured memory_bytes: 11756
#include<bits/stdc++.h>
using namespace std;
string S;
int main(){
	int s,i;
	cin>>S,s=S.length();
	for(i=0;i<s;i++)if(S[i]==S[i+1]){
		cout<<"Bad";
		return 0;
	}
	cout<<"Good";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI 3.1415926535897
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


signed main(){
	int N;
	int A, B;
	cin >> N;

	if(N == 1) cout << "Hello World" << endl;
	else {
		cin >> A >> B;
		cout << A+B << endl;
	}

	return 0;
}

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

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

Measured memory_bytes: 3520
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

s = 0
num = 0
for i in range(n):
    if s + a[i] > k:
        break
    s += a[i]
    num += 1
an = num

bi = 0
while True:
    if s + b[bi] > k:
        break
    s += b[bi]
    num += 1
    bi += 1
    if bi == m:
        break
    
num_max = num
for i in range(an)[::-1]:
    if bi == m:
        break
    s -= a[i]
    num -= 1
    while True:
        if s + b[bi] > k:
            break
        s += b[bi]
        num += 1
        bi += 1
        if bi == m:
            break
        
    num_max = max([num, num_max])
print(num_max)

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s = in.readLine();
    String t = in.readLine();
    String s_rt = "";
    boolean matchingFlg = false;
    for(int i=0; i<s.length(); i++) {
      s_rt = s.substring(s.length()-i,s.length()) + s.substring(0,s.length()-i);
      if(s_rt.equals(t))
        matchingFlg = true;
    }
    System.out.println(matchingFlg==true?"Yes":"No");
  }
}

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

const long long maxn=200005,mod=1e9+7;
typedef long long ll;

ll vis[maxn],prime[maxn],mu[maxn];
ll tot;

ll sum[maxn],d[maxn];

void check(ll n)
{
	memset(vis, false, sizeof(vis));
	memset(mu,0,sizeof(mu));
	tot=0;
	mu[1]=1;
	for(long long i=2;i<=n;i++)
	{
		if(!vis[i])
		{
			mu[i]=-1;
			prime[++tot]=i;
		}
		for(long long j=1;j<=tot;j++)
		{
			long long k=prime[j]*i;
			if(k>n) break;
			vis[k]=true;
			if(i%prime[j]!=0)
				mu[k]=-mu[i];
		    else break;
		}
	}
	return;
}

ll n,k;

ll ans,s;

ll qpow(ll x, ll y)
{
	ans=1;
	while(y>0)
	{
		if(y%2==1) ans=ans*x%mod;
		y/=2; x=x*x%mod;
	}
	return ans;
}

ll cal(ll x)
{
	if(sum[x]!=-1) return sum[x];
	for(int i=2;i<=x;i++)
	{
		d[i]=(d[i-1]-mu[i]*qpow(x/i,n)%mod+mod)%mod;
	//	cout<<"d: "<<i<<' '<<d[i]<<endl;
	}
	sum[x]=(qpow(x,n)-d[x]+mod)%mod;
	//for(int i=1;i<=x;i++) d[i]=0;
//	cout<<"cal "<<x<<' '<<sum[x]<<endl;
	return sum[x];
}

int main()
{
	memset(sum,-1,sizeof(sum));
	check(maxn-5);
	cin>>n>>k;
	s=0;
	for(int i=1;i<=k;i++)
	{
		s=(s+i*cal(k/i)%mod)%mod;
	//	cout<<i*cal(k/i)<<endl;
	}
	cout<<s%mod<<endl;
	return 0;
}

Measured memory_bytes: 9248
import java.util.Scanner;

// Java8
public class Main
{
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) throws Exception
	{
		new Main().run();
	}
	
	void run()
	{
		int n = sc.nextInt();
		int[] as = new int[n+1];
		for(int i=1; i<=n; i++) as[i] = sc.nextInt();
		int p = 1;
		for(int i=1; i<=n; i++)
		{
			p = as[p];
			if(p==2)
			{
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}
	
}


Measured memory_bytes: 50800
#include <bits/stdc++.h>
#define ll long long
#define v vector<int>

using namespace std;

int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int H,W;
cin>>H>>W;
int h,w;
cin>>h>>w;
cout<<(H-h)*(W-w) <<"\n";
}

Measured memory_bytes: 3612
class Node
  def initialize(node)
    @node = node
    @parent = nil
    @children = []
    @depth = 0
  end

  def who_am_i
    if @parent == -1
      'root'
    elsif @children.empty?
      'leaf'
    else
      'internal node'
    end
  end

  def to_s
    "node #{node}: parent = #{parent}, depth = #{depth}, #{who_am_i}, #{children}"
  end

  attr_accessor :node, :parent, :children, :depth
end

class RootedTree
  def initialize(k)
    @node_list = []
    k.times do |i|
      @node_list << Node.new(i)
    end
  end

  def create_node(index, children)
    @node_list[index].children = children
    unless children.empty?
      children.each do |value|
        @node_list[value].parent = index
      end
    end
  end

  def eval_depth_of(index, target_node_index)
    return if @node_list[index].parent == -1
    @node_list[target_node_index].depth += 1
    eval_depth_of @node_list[index].parent, target_node_index
  end

  def search_root_node
    @node_list.each do |node|
      node.parent = -1 if node.parent.nil?
    end
  end

  attr_reader :node_list
end

n = gets.to_i
tree = RootedTree.new n
n.times do
  input = gets.split(' ').map(&:to_i)
  if !input[1].zero?
    children = input[2..-1]
  else
    children = []
  end
  tree.create_node input[0], children
end
tree.search_root_node

tree.node_list.each do |node|
  tree.eval_depth_of node.node, node.node
end

tree.node_list.each do |node|
  puts node.to_s
end




Measured memory_bytes: 30496
import math
def C(a,b):
    return math.factorial(a) // (math.factorial(b)*math.factorial(a-b))

N = int(input())
D = {} 
for i in range(N):
    s = list(input())
    if all(s[0] == s[j] for j in range(1,10)):
        continue
    else:
        temp = 10**26
        for j in range(10):
            temp += 10**(ord(s[j]) - 97)

        if temp in D:
            D[temp] = D[temp] + 1
        else:
            D[temp] = 1
ans = 0
for a in D.values():
    if a > 1:
        ans += C(a,2)
print(ans)

Measured memory_bytes: 15852
N = int(input())
ab = [tuple(map(int, input().split())) for _ in range(N)]
cd = [tuple(map(int, input().split())) for _ in range(N)]

ab.sort(key=lambda xy: xy[1], reverse=True)
cd.sort()

ans = 0
for c, d in cd:
    for index, (a, b) in enumerate(ab):
        if a < c and b < d:
            ab[index] = (201, 201)
            ans += 1
            break

print(ans)


Measured memory_bytes: 9140
S = input()
T = input()

dict1 = {}
ls =[]
for i in range(len(S)):
    if S[i] not in dict1:
        dict1[S[i]] = i
    ls.append(dict1[S[i]])

dict2 = {}
lt =[]
for i in range(len(T)):
    if T[i] not in dict2:
        dict2[T[i]] = i
    lt.append(dict2[T[i]])

if ls == lt:
    print("Yes")
else:
    print("No")

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

int main() {
  int a, b, c, m = 0;
  cin >> a >> b >> c;
  if(a + b < c - 1) cout << 2 * b + a + 1 << endl;
  else cout << b + c << endl;
  return 0;
}


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


int main() {
  string n;
  int count;
  cin >> n;
  count = 0;
  for (int i=0; i<3; i++) {
    if (n.at(i) == '1') {
      count ++; 
    }
  }
  cout << count << endl;

}


Measured memory_bytes: 3624
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define Max(a,b) ((a) < (b) ? (b) : (a))
#define Min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


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

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


int main() {
	int i, j, k;
	//ll N, M, K;
	int N, M, K;

	cin >> N >> K;
	ll ans = 0;
	ll min = 0;
	ll max = 0;

	rep(i, 0, K) {
		min += i;
		max += N - i;
	}

	rep(i, K, N+1) {
		ans += max - min+1;
		ans %= AAA;
		min += i;
		max += N - i;
	}
	ans += max - min + 1;
	ans %= AAA;
	cout << ans;

	return 0;

}




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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;


int main(){
    string words[3]={"hon","pon","bon"};
    vector<vector<int>>num(3);

    num[0]={2,4,5,7,9};
    num[1]={0,1,6,8};
    num[2]={3};

    int n;
    cin>>n;
    n%=10;
    rep(i,3){
        rep(k,num[i].size()){
            if(num[i][k]==n){
                cout<<words[i]<<endl;
                return 0;
            }
        }
    }
    return 0;

}
/*

*/


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
  int n,m;
  int x[12] = {0,3,4,0,2,5,0,3,6,1,4,6};
  while(cin >>n>>m,n||m){
    if((m+x[n-1])%7 == 1) cout <<"Thursday"<<endl;
    if((m+x[n-1])%7 == 2) cout <<"Friday"<<endl;
    if((m+x[n-1])%7 == 3) cout <<"Saturday"<<endl;
    if((m+x[n-1])%7 == 4) cout <<"Sunday"<<endl;
    if((m+x[n-1])%7 == 5) cout <<"Monday"<<endl;
    if((m+x[n-1])%7 == 6) cout <<"Tuesday"<<endl;
    if((m+x[n-1])%7 == 0) cout <<"Wednesday"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

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

typedef long long ll;
typedef vector<int> VI;
int a[100010];

bool dp[21][2010];
int main() {
    int n; cin >> n;
    REP(i, n) cin >> a[i];
    int q; cin >> q;
    
    for(int i=0; i<n; ++i) dp[i][0]=true;

    for(int i=0; i<n; ++i){
        for(int j=0; j<2010; ++j){
            dp[i+1][j] |= dp[i][j];
            if(j-a[i]>=0) dp[i+1][j] |= dp[i][j-a[i]];
        }
    }
    REP(i, q){
        int m; cin >> m;
        bool f=false;
        for(int i=0; i<=n; ++i){
            if(dp[i][m]) f=true;
        }
        if(f) cout << "yes" << endl;
        else cout << "no" << endl;
    }
	return 0;
}


Measured memory_bytes: 3124
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    int hi = N;
    int lo = 1;
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        lo = max(lo, s[0]);
        hi = min(hi, s[1]);
    }
    if (lo > hi) {
        writeln(0);
    } else {
        writeln(hi - lo + 1);
    }
}


Measured memory_bytes: 1276
#include <iostream>
using namespace std;
int main(void)
{
  long long X, A, B;
  cin >> X >> A >> B;
  if(B<=A) {
    cout << "delicious" << endl;
  } else if(A < B && B <= A+X) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "sstream"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const int N=1e5+1;
int arr[100];
int main() {
    quick
int n; cin>>n; long long ans=LONG_LONG_MAX;
for(int i=0;i<n;i++){cin>>arr[i];}
for(int i=0;i<=1e4;i++){
    long long sum=0;
for(int j=0;j<n;j++){
    sum+=(arr[j]-i)*(arr[j]-i);
}
if(sum<ans){ans=sum;}
}
cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<string>
using namespace std;
const int M=1e9+7;
int main(){
	long long int n;
	cin>>n;
	long long int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	long long int ans=0;
	long long int prefix[n];
	prefix[n-1]=a[n-1];
	for(long long int i=n-2;i>=0;i--){
		prefix[i]=a[i]+prefix[i+1];
	}
	for(int i=0;i<n-1;i++){
		ans+=((a[i]%M)*(prefix[i+1]%M))%M;
	}
	cout<<ans%M;
	return 0;
}

Measured memory_bytes: 6748
N = int(input())
S = list(input())

row = [0]*(N+2)
for i in range(N):
    if S[i] =='E':
        row[i+1] = row[i] + 1
    else:
        row[i+1] = row[i]
answer = [0]*N
for i in range(N):
    answer[i] += (i - row[i])
    a = row [N] - row[i+1]
    answer[i] += a
#print(S)
#print(row)
#print(answer)
print(min(answer))


Measured memory_bytes: 96116
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;


ll gcd(ll C, ll D){
    return D ? gcd(D, C%D) : C;
}
ll lcm(ll C, ll D){
    return C/gcd(C,D)*D;
}

ll f(ll X, int C, int D){
    
    ll res = X;
    res -= X/C;
    res -= X/D;
    res += X/lcm(C,D);
    return res;
}


int main(void){
    
    ll A,B;
    int C,D;
    
    cin >> A >> B >> C >> D;
    
    ll ans = f(B,C,D) - f(A-1,C,D);
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>

int main ()
{
	int a,b;
	scanf("%d %d",&a,&b);
	
	if (a>8||b>8)
	{
		printf(":(");
	} else if(a+b<=16||a+b>=0) {printf("Yay!");} 
	else printf(":(");
	
	return 0;
} 

Measured memory_bytes: 128
MOD=10**9+7

def perm(n,r)
  return 0 if r>n || n<0 || r<0
  return r.times.inject(1){|memo,i| memo*(n-i)%MOD}
end


N,K=gets.split.map(&:to_i)

edges=Array.new(N){Array.new}

(N-1).times do |i|
  a,b=gets.split.map(&:to_i)
  a-=1
  b-=1
  edges[a] << b
  edges[b] << a
end

visited=Array.new(N,false)
ans=(K*perm(K-1,edges[0].size))%MOD
visited[0]=true
stack=edges[0].dup
while !stack.empty?
  v=stack.pop
  visited[v]=true
  next if edges[v].size==1
  edges[v].each do |vv|
    stack << vv if !visited[vv]
  end
  ans=(ans*perm(K-2,edges[v].size-1))%MOD
end
p ans


Measured memory_bytes: 14204
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int a,b,c,d;//nは最大値36
int n;
int ans;//組み合わせの数
int main(){
  while(scanf("%d",&n) !=EOF){
  ans = 0;
  for(int a = 0;a <= 9; a++){
    for(int b = 0; b <= 9;b++){
      for(int c = 0; c <= 9;c++){
	for(int d = 0;d <=9;d++){
	  if(a + b+ c + d >36)
	    continue;
	  if(a +b + c + d==n){
	    ans++;
	      }
	}
      }
    }
  }
  printf("%d\n",ans);
	      }
  return 0;
}

Measured memory_bytes: 1188
using System;

namespace ITP1_4_D
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int min = 1000000, max = -1000000;
            long sum = 0;
            string[] str = Console.ReadLine().Split(' ');

            for (int i = 0; i < n; i++)
            {
                int a = int.Parse(str[i]);

                if (a < min) min = a;

                if (a > max) max = a;

                sum += a;
            }

            Console.WriteLine(min + " " + max + " " + sum);
        }
    }
}

Measured memory_bytes: 9896
import java.util.Scanner;

class Main{

	public static void main(String[] args) {

		int a,b,c;
		int count = 0;

		Scanner stdIn = new Scanner(System.in);

		a = stdIn.nextInt();
		b = stdIn.nextInt();
		c = stdIn.nextInt();

		for(int i = a; i <= b; i++) {

			if((c % i) == 0) {
				count++;
			}
		}

		System.out.println(count);

	}

}

Measured memory_bytes: 26280
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int INF = 1 << 30;

int f(string S,string T,int n){
    int cnt = 0;
    for(int i = 0;i < T.length();i++){
        if(S[n + i] != T[i]){
            cnt++;
        }
    }
    return cnt;
}

int main(){
    string S,T;

    cin >> S >> T;

    int ans = INF;

    for(int i = 0;i <= S.length() - T.length();i++){
        ans = min(f(S,T,i),ans);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3136
#include<stdio.h>
#include<algorithm>
using namespace std;
char in[20];
int main(){
	int a;scanf("%d",&a);
	while(a--){
		for(int i=0;i<10;i++)scanf("%s",in+i);
		int val=0;
		int ace=0;
		if(in[0]=='A'){val+=11;ace++;}
		else if(in[0]=='T'||in[0]=='J'||in[0]=='Q'||in[0]=='K'){val+=10;}
		else val+=in[0]-'0';
		if(in[1]=='A'){val+=11;ace++;}
		else if(in[1]=='T'||in[1]=='J'||in[1]=='Q'||in[1]=='K'){val+=10;}
		else val+=in[1]-'0';
		if(val>21){val-=10;ace--;}
		if(val==21){
			printf("blackjack\n");continue;
		}
		int at=2;
		while((val<17||(val==17&&ace))&&at<10){
			if(in[at]=='A'){val+=11;ace++;}
			else if(in[at]=='T'||in[at]=='J'||in[at]=='Q'||in[at]=='K'){val+=10;}
			else val+=in[at]-'0';
			if(val>21&&ace){val-=10;ace--;}
			at++;
		}
		if(val>21)printf("bust\n");
		else printf("%d\n",val);
	}
}

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

int main() {
  int n;
  cin >> n;
  
  int cnt = 0;
  int nn = n;
  
  while (nn > 0){
    nn /= 10;
    cnt++;
  }
  
  int ans;
  
  if (cnt == 1){
    ans = n;
  }else if (cnt == 2){
    ans = 9;
  }else if (cnt == 3){
    ans = 9 + (n-100+1);
  }else if (cnt == 4){
    ans = 9 + 900;
  }else if (cnt == 5){
    ans = 9+900+(n-10000+1);
  }else if (cnt == 6){
    ans = 9 + 900 + 90000;
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include<string>
#include<list>
#include<iostream>
using namespace std;
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  string str;
  list<int> data;
  list<int>::iterator it,l;
  int n,x;
  cin >> n;
  while(n--){
    cin >> str;
    if(str == "insert"){
      cin >> x;
      data.push_front(x);
    }else if(str == "delete"){
      cin >> x;
      for(it=data.begin(),l=data.end();it!=l;++it){
	if(*it == x){
	  data.erase(it);
	  break;
	}
      }
    }else if(str == "deleteFirst") data.pop_front();
    else data.pop_back();
  }
  for(it=data.begin(),l=--data.end();it!=l;++it) cout << *it << " ";
  cout << *it << endl;
}



Measured memory_bytes: 34400
#include<stdio.h>

int main(void){
	int time,h,m,s;
	scanf("%d",&time);
	
	h=time/3600;
	m=(time-h*3600)/60;
	s=time-h*3600-m*60;
	
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,k,a[20]={},ans=INF,cnt=0,M,x;
  cin >> n >> k;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=1; i<(1<<n); i++) {
    if(__builtin_popcount(i)<k||!(i&1)) {
      continue;
    }
    M=a[0];
    cnt=0;
    x=1;
    for(int j=1; j<n; j++) {
      if(x>=k) {
        break;
      }
      if(i&(1<<j)) {
        if(a[j]>M) {
          M=a[j];
          x++;
        }
        else {
          M++;
          x++;
          cnt+=M-a[j];
        }
      }
      else {
        M=max(M,a[j]);
      }
    }
    ans=min(ans,cnt);
  }
  cout << ans << endl;
}

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

int main()
{
    long long n, i, j, sum=0, tmp=0;
    string s;

    cin>>n>>s;

    vector <int> r(n+1),g(n+1),b(n+1);

    for(i=0; i<n; i++)
    {
        r[i+1] = r[i];
        g[i+1] = g[i];
        b[i+1] = b[i];

        if(s[i] == 'R')
            r[i+1]++;
        else if(s[i] == 'G')
            g[i+1]++;
        else
            b[i+1]++;
    }

    for(i=0; i<n; i++){
        if(s[i] == 'R')
        {
            for(j=i+1; j<n; j++)
            {
                if(s[j] == 'R')
                    continue;
                else if(s[j] == 'G')
                {
                    tmp = b[n]-b[j];

                    if(j+j-i<n && s[j+j-i] == 'B')
                        tmp--;
                    sum = sum+tmp;
                }
                else if(s[j] == 'B')
                {
                    tmp = g[n]-g[j];

                    if(j+j-i < n && s[j+j-i]=='G')
                        tmp--;
                    sum = sum+tmp;
                }
            }
        }


        else if(s[i] == 'G')
        {
            for(j=i+1; j<n; j++)
            {
                if(s[j] == 'G')
                    continue;
                else if(s[j] == 'B')
                {
                    tmp = r[n]-r[j];

                    if(j+j-i < n && s[j+j-i] == 'R')
                        tmp--;
                    sum = sum+tmp;
                }
                else if(s[j] == 'R')
                {
                    tmp = b[n]-b[j];

                    if(j+j-i < n && s[j+j-i] == 'B')
                        tmp--;
                    sum = sum+tmp;
                }
            }
        }

        else if(s[i] == 'B')
        {
            for(j=i+1; j<n; j++)
            {
                if(s[j] == 'B')
                    continue;
                else if(s[j] == 'R')
                {
                    tmp = g[n]-g[j];

                    if(j+j-i < n && s[j+j-i]== 'G')
                        tmp--;
                    sum = sum+tmp;
                }
                else if(s[j] == 'G')
                {
                    tmp = r[n]-r[j];

                    if(j+j-i < n && s[j+j-i]=='R')
                        tmp--;
                    sum = sum+tmp;
                }
            }
        }
        //cout<<sum<<endl;
    }

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3584