akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long LL;
const int N = 1e5+10;
inline int read()
{
	register int x = 0 , f = 0; register char c = getchar();
	while(c < '0' || c > '9') f |= c == '-' , c = getchar();
	while(c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0' , c = getchar();
	return f ? -x : x;
}
int n , cnt , tot , res;
int head[N] , del[N] , du[N] , val[N] , dp1[N] , dp2[N];
char str[N];
struct edge{ int v , nex; }e[N << 1];
inline void add(int u , int v) { e[++cnt].v = v; e[cnt].nex = head[u]; head[u] = cnt; }

void dfs(int x , int fa)
{
	del[x] = str[x] == 'B';
	for(int i = head[x] , v; i ; i = e[i].nex)
	{
		v = e[i].v; if(v == fa) continue; dfs(v , x);
		if(!del[v]) du[x]++ , du[v]++;
		del[x] &= del[v];
	}
}

void dp(int x , int fa)
{
	tot += du[x];
	if((du[x] + (str[x] == 'B')) & 1) val[x] = 0; else val[x] = 2 , tot++;
	int mx1 = 0 , mx2 = 0 , flag = 0;
	for(int i = head[x] , v; i ; i = e[i].nex)
	{
		v = e[i].v; if(v == fa || del[v]) continue; dp(v , x);
		flag = 1; res = max(res , max(dp1[v] + val[x] + mx2 , dp2[v] + val[x] + mx1));
		mx1 = max(mx1 , dp1[v]); mx2 = max(mx2 , dp2[v]);
	}
	dp1[x] = mx1 + val[x]; if(flag) dp2[x] = mx2 + val[x]; else dp2[x] = -1e9;
}

int main()
{
	n = read(); if(!n) return puts("0") , 0; int u , v;
	for(int i = 1 ; i < n ; ++i) u = read() , v = read() , add(u , v) , add(v , u);
	scanf("%s" , str + 1); int rot = -1;
	for(int i = 1 ; i <= n ; ++i) if(str[i] == 'W') { rot = i; break; }
	if(rot == -1) return puts("0") , 0;
	dfs(rot , 0); dp(rot , 0); cout << tot - res << '\n';
	return 0;
}


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

sList = []
for i in range(n):
  sList.append(input())

cList = []
sN = ord('a')
while True:
  if ord('z')+1 == sN:
    break
  sA = 50
  for i in range(n):
    tmp = sList[i].count(chr(sN))
    if sA > tmp:
      sA = tmp
  cList.append(sA)
  sN += 1

cS = ''
for i in range(len(cList)):
  cS += chr(ord('a')+i)*cList[i]
  
 
print(cS)
 

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const ll INF = 1000000000;
const ll mod = 1000000007;
#define PI 3.1415926535
using Graph = vector<vector<int>>;
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;}
typedef pair<int, int> pair;
bool seen[505][505];

//dpTable
//bool dp[100050];

int main(){
    int N,X;
    cin >> N >> X;
    vector<int> L(N);
    vector<int> D(N + 1);
    rep (i,N) {
        cin >> L.at(i);
        D.at(i + 1) = D.at(i) + L.at(i);
    }
    rep (i,N + 1) {
        if (D.at(i) > X) {
            cout << i << endl;
            break;
        }
        else if (i == N) {
            cout << N + 1 << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

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; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	int A, B, C;
	cin >> A >> B >> C;

	map<int, int> syllable;
	syllable[A]++;
	syllable[B]++;
	syllable[C]++;

	if (syllable[5] == 2 and syllable[7] == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		char[] s = sc.next().toCharArray();
		int[] e = new int[s.length];
		int[] w = new int[s.length];
		e[0] = s[0] == 'E' ? 1 : 0;
		w[0] = s[0] == 'W' ? 1 : 0;
		for (int i = 1; i < N; i++) {
			e[i] = e[i-1] + (s[i] == 'E' ? 1 : 0);
			w[i] = w[i-1] + (s[i] == 'W' ? 1 : 0);
		}
		
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			int sum = 0;
			if (i != 0) {
				sum += w[i-1];
			}
			
			if (i != N-1) {
				sum += e[N-1] - e[i];
			}
			
			min = Math.min(min, sum);
		}
		
		System.out.println(min);
	}
	
}


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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _ % MOD
#define __ %= MOD

#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.begin(), v.end(), greater<auto>())
#define fill(a) memset(a, 0, sizeof(a))

#define swap(a, b) \
	{              \
		a = a + b; \
		b = a - b; \
		a = a - b; \
	}
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) << endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

#define pv(a)                                 \
	{                                         \
		rep(i, a.size()) cout << a[i] << " "; \
		cout << endl;                         \
	}
#define mark(v) cout << "Here--" << v << endl;

const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}
ll power(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y & 1)
			res = res * x;
		y = y >> 1;
		x = x * x;
	}
	return res;
} // modular exponent

ll n, A;
vector<ll> a(55);

int main()
{
	ios_base::sync_with_stdio(false); // don't use printf and scanf
	cin.tie(NULL);					  // cout<<fixed<<setprecision
	cin >> n >> A;
	repA(i, 1, n) cin >> a[i];
	ll cnt = 0;
	ll dp[n + 1][n + 1][n * A + 1];
	memset(dp, 0, sizeof(dp));
	dp[0][0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			for (int s = 0; s <= n * A; s++)
			{
				if (s < a[i])
				{
					dp[i][j][s] = dp[i - 1][j][s];
				}
				else if (s >= a[i])
				{
					dp[i][j][s] = dp[i - 1][j][s] + dp[i - 1][j - 1][s - a[i]];
				}
			}
		}
	}
	ll sum = 0;
	for (int k = 1; k <= n; k++)
	{
		sum += dp[n][k][k * A];
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 54360
parseInt(x) = parse(Int, x)
parseFloat(x) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    h=parseMap(split(readline()))
    garden=[0 for i in 1:n]
    ans=0
    M=findmax(h)[2]
    while h[M]>garden[M]
        cnt=0
        for j in 1:n
            if garden[j]==h[j]
                if cnt>0
                    ans+=1
                end
                cnt=0
            else
                garden[j]+=1
                cnt+=1
            end
        end
        if cnt>0
            ans+=1
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 171396
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
struct edge{int from,to,cost;};
signed main(){
  double a,b,c;
  cin>>a>>b>>c;
  if(0<(c-a-b)){
  int d=pow(c-a-b,2.0);
  if((4*a*b)<d)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
    }
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 384
object Main extends App {
  scala.io.Source.stdin.getLines.toList.init
    .map(_.split(" ").toList.map(_.toInt))
    .map{
      case List(-1, _, _) => "F"
      case List(_, -1, _) => "F"
      case List(a, b, c) if a + b < 30 => "F"
      case List(a, b, c) if a + b < 50 & c < 50 => "D"
      case List(a, b, c) if a + b < 65 => "C"
      case List(a, b, c) if a + b < 80 => "B"
      case _ => "A"
    }
    .map(println)
}

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

int main() {
	ll i, j, k, l, test, n;
	cin >> n;
	map<ll, ll> m;
	for (i = 0; i < n-1; i++) {
		cin >> k;
		m[k]++;
	}
	for (i = 1; i <= n; i++) {
		//cout << "car";
		cout << m[i] << "\n";
	}
}

Measured memory_bytes: 16076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;

struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<edge>> ;

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
const int MAXM = 200000;
bool has_been[MAXM];

int ans = 0;
int counter = 0;
void sear(const Graph &G, int first_node){
    counter++;
    has_been[first_node] = true;
    ans = max(counter, ans);
    for(int j : G[first_node]){
        if(!has_been[j]){
            sear(G,j);
        }
    }
}

int main(){
    int N,M;cin >> N >> M;
    memset(has_been, false, sizeof(has_been));
    Graph G(MAXM);
    rep(i,M){
        int a,b;cin >>a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    Rep(i,N){
        counter = 0;
        if(!has_been[i])sear(G,i);
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
  int N, M;
  cin >> N >> M;

  double difference = 0.03;
  double add = 0;
  double sum = 0;
  int i = 1;

  double win_prob = pow(0.5, M);
  double lose_prob = 1 - win_prob;
  double prob = 1;
  //cout << win_prob << endl;
  do {
    prob = win_prob * pow(lose_prob, i - 1);
    add = i * ((N - M) * 100 + M * 1900) * prob;
    i++;
    sum += add;
    //cout << add << endl;
    // if (i == 100) break;
  } while (add > difference);

  int result = ceil(sum);
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int D,N;
    cin>>D>>N;
    if(N==100)N=101;
    for(int i=0;i<D;i++){
        N*=100;
    }
    cout<<N<<endl;
}

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

int main() {
  int n; cin >> n;
  vector<int> x(n);
  for(int i = 0; i < n; i++){
    cin >> x.at(i);
  }
  long long out = 100000000;
  for(int i = 0 ; i < 100; i++){
    long long p = 0;
    for(int j = 0; j < n; j++){ 
      p += (x.at(j) - i)*(x.at(j) - i);
    }
    if(p < out) out = p;
  }
  cout << out;
}

Measured memory_bytes: 256
def gcd(a, b):
  if a == 0:
    return b
  return gcd(b%a, a)
n = int(raw_input())
lis = map(int, raw_input().strip().split())
if n == 1:
  print lis[0]
else:
  g = gcd(lis[0], lis[1])
  for i in range(2, n):
    g = gcd(g, lis[i])
  print g

Measured memory_bytes: 11320
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
 

 int main(void)
 {
    ll a,b,c,d;
    cin>>a>>b;
    c=a;
    d=b;
ll r,q;
if(a<b) swap(a,b);

q=a%b;

while(q!=0)
{
    a=b;
    b=q;

    q=a%b;
   
}

ll ans = c*d/b;
cout<<ans<<endl;

 }

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int i,x,y;
    for(i=1;;i++){
        scanf("%d %d",&x,&y); 
        if(x!=0||y!=0){
            if(x>y){
                printf("%d %d\n",y,x);
            }
            else{
                printf("%d %d\n",x,y);
            }
        }
        else{
            break;
        }
    }
    return 0;
}



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

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

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   int gcd(int a,int b){return b?gcd(b,a%b):a;};

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

int main(){
   int N ; cin >> N;
   cout << ((N % 2) ? 2 * N : N ) << endl; 
}

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

int main() {
  int N, T;
  cin >> N;
  T = 0;
  
  for (int i = 0; i < N; i++) {
   int r,l;
   cin >> r >> l;
     T += l - r + 1;
  }
  cout << T << endl;
}
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rp(i,n) for (int i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define all_acc(x) (x).begin(), (x).end(), 0LL
#define int long long
#define absSort(v) sort(a.begin(), a.end(), [](int i, int j) -> bool { return abs(i) < abs(j); });
using namespace std;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using ll = long long;
double pi=3.14159265359;

//出力するよ
void output_tate(vector<int> s){
    int n = s.size();
    for (int i = 0; i < n; i++){
        //if (i != 0)
        //    cout << " ";
        cout << s[i]<<endl;
    }
    //cout << endl;
}

void output_yoko(vector<int> s){
    int n = s.size();
    for (int i = 0; i < n; i++){
        if (i != 0)
            cout << " ";
        cout << s[i];//<<endl;
    }
    cout << endl;
}

int MOD = pow(10, 9) + 7;

int kaijou(int n){
    if(n==0) return 1;
    else{
        return ((n%MOD)*(kaijou(n-1)%MOD))%MOD;
    }
}

bool ispow(int n){
    int rn=sqrt(n);
    if(rn*rn==n) return true;
    else return false;
}

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

    int res=0;

    for(int i=0;i<3;i++){
        if(s[i]=='R') res++;
    }

    if(res==2){
        if(s[0]=='R'&&s[2]=='R') res=1;
    }

    cout<<res<<endl;
}


Measured memory_bytes: 3616
###B - Digital Gifts
n = int(input())
kanezuru = []
summoney = 0
for i in range(n):
    x, u = input().split()
    kanezuru.append([float(x), u])

for i in range(n):
    if kanezuru[i][1] == 'BTC':
        kanezuru[i][0] *= 380000.0
    summoney+= kanezuru[i][0]

print(summoney)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using pp = pair<int, int>;
const int INF = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ll ans = 1;
    for (int i = 1; i <= N; i++) {
        ans *= i;
        ans %= INF;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0] * n
for i in range(1,n):
  m = 10**10
  for j in range(min(i,k)):
    m = min(m,dp[i-j-1]+abs(h[i]-h[i-j-1]))
  dp[i] = m
print(dp[-1])

Measured memory_bytes: 52448
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
2^18=262144
価値の高いものから選んでいくか
L=20

20 20
15 11
14 9
とかで失敗する

1
23
4567
89012345
2^18=2^9^2=512*512
DP２つ用意すればいける?
512まで先に用意しとく?
2^9
5000*100000とか
限界？
256くらいなら
2000*100000くらい
しといて
１発で出せるようにするとか

0 -1 -1 2 -1 -1
0  0  0 2  2  2
mapだとTLE
普通の配列に１０００個くらいいれる場合
bit全探索？
*/
vector<ll> V(263000,0),W(263000,0);
vector<vector<ll>> DP(520,vector<ll>(100010,0));
ll N;

void dfs(ll v){
  for(ll i=0; i<=100000; i++){
    DP[v][i]=DP[v/2][i];
    if(i-W[v]>=0) DP[v][i]=max(DP[v][i],DP[v/2][i-W[v]]+V[v]);
  }
}

int main(){
  cin>>N;
  for(ll i=1; i<=N; i++)cin>>V[i]>>W[i];
  ll Q; cin>>Q;
  //DP用意(511以下
  ll n=min(511LL,N);
  for(ll i=0; i<=n; i++) DP[i][0]=0;
  for(ll i=1; i<=n; i++) dfs(i);
  for(ll i=0; i<Q; i++){
    ll v,L; cin>>v>>L;
    ll vv=v, ans=0;
    vector<pair<ll,ll>> C(0,{0,0});
    while(vv>511){
      C.emplace_back(W[vv],V[vv]);
      vv/=2;
    }
    ll csz=C.size();
    ll n=1<<csz;
    for(ll j=0; j<n; j++){
      ll sw=0,sv=0;
      for(ll k=0; k<csz; k++){
        if(j>>k&1){
          sw+=C[k].first;
          sv+=C[k].second;
        }
      }
      if(sw>L) continue;
      ans=max(ans,sv+DP[vv][L-sw]);
    }
    if(v<512) ans=DP[v][L];
    cout<<ans<<endl;
  }
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            ++cnt;
        }
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define int long long
#define MAX 100005
#define NIL -1
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int parent(int i){return i/2;}
int left(int i){return i*2;}
int right(int i){return i*2+1;}

signed main(){
  int h,A[MAX+1];
  cin>>h;
  loop(i,1,h+1)cin>>A[i];
  loop(i,1,h+1){
    cout<<"node "<<i<<": key = "<<A[i]<<", ";
    if(parent(i)>=1)cout<<"parent key = "<<A[parent(i)]<<", ";
    if(left(i)<=h)cout<<"left key = "<<A[left(i)]<<", ";
    if(right(i)<=h)cout<<"right key = "<<A[right(i)]<<", ";
    cout<<endl;
  }

  return 0;
}

Measured memory_bytes: 3088
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <bitset>

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
//constexpr long long MOD = 1000000007;

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

int main()
{
  int N, K;
  std::cin >> N >> K;
  int ans = 0;
  while(N)
  {
    ++ans;
    N /= K;
  }
  std::cout << ans << std::endl;
  return 0;
}



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

typedef long long ll;

int main()
{
    int i;
    string s,t;
    int a,b;
    cin >> s >> t;
    cin >> a >> b;
    string u;
    cin >> u;
    if(u == s){
        cout << a - 1 << " " << b << endl;
    }else{
        cout << a << " " << b-1 << endl;
    }
    return 0;
}

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

int main(){
    int x;
    int i = 1;
    cin >> x;
    if(x != 0){
        while(1){
            cout << "Case " << i << ": " << x << endl;
            cin >> x;
            i++;
            if(x == 0){
                break;
            }
        }
        
    }
    return 0;
}

Measured memory_bytes: 2980
N = int(input())
h = [int(i) for i in input().split()]
dp = [0 for i in range(N)]
dp[1]= abs(h[1]-h[0])
for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[N-1])

Measured memory_bytes: 53112
#include"bits/stdc++.h"
using namespace std;
int n;
int flag[10000000];
int main(){
	cin>>n;
	for(int i=1;i<sqrt(n);i++){
		for(int j=1;j<sqrt(n);j++){
			for(int k=1;k<sqrt(n);k++){
					flag[i*i+j*j+k*k+i*j+i*k+j*k]++;
				
			}
		}
	} 
	for(int i=1;i<=n;i++){
		printf("%d\n",flag[i]);
	}
}


Measured memory_bytes: 3884
#include <iostream>
using namespace std;
int main(void){
    int N;

    while(cin >> N){
        if(N == 0) break;
        int S = 1;
        for(int i = 2; i * i <= N; i++){
            if(N % i == 0){
                if(i * i == N) S += i;
                else S += i + N / i;
            }
        }
        if(N == 1 || S < N) cout << "deficient number" << endl;
        else if(S == N) cout << "perfect number" << endl;
        else cout << "abundant number" << endl;
    }
    return 0;
}



Measured memory_bytes: 3088
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0),cin.sync_with_stdio(0),cout.tie(0),cout.sync_with_stdio(0);
	int a, b;
	cin>>a>>b;
	cout<<max({a+b,a-b,a*b});
}

Measured memory_bytes: 256
n,m = map(int, input().split())
A = list(map(int,input().split()))

min_limit = sum(A)*(1 / (4*m))
select_ok = 0

for i in A:
  if i >= min_limit:
    select_ok += 1

if select_ok >= m:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 9108
n,y = map(int,input().split())

sign = 0
ans = [y//10000,0,0]
y = y - 10000*ans[0]
n = n - ans[0]
ans[1] = y//5000
y = y - 5000*ans[1]
n = n - ans[1]
ans[2] = y//1000
y = y - 1000*ans[2]
n = n - ans[2]

if (y != 0) or (n < 0):
  sign = 1

if n <= 3:
  if ans[0] < n:
    sign = 1
  else:
    ans[0] -= n
    ans[1] += 2*n
else:
  temp = n%4
  if ans[0]-temp < 0:
    sign = 1
  else:
    temp_1 = temp + 4*min((ans[0]-temp)//4,(n-temp)//4)
    ans[1] +=temp_1*2
    ans[0] -= temp_1
    n -= temp_1

judge = n//4
if ans[1] < judge:
  sign = 1
else:
  ans[1] -= judge
  ans[2] += judge*5
  
if sign == 1:
  print("-1 -1 -1")
else:
  print(ans[0],ans[1],ans[2])

Measured memory_bytes: 3064
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe
import Control.Monad

main = do
  [d,n] <- map (read::String->Int) . words <$> getLine
  print $ ([1*100^d,2*100^d..99*100^d]++[101*100^d])!!(n-1)

Measured memory_bytes: 3976
S = input()
C = [0 for _ in range(len(S))]
b = "R"
l,r = 0,0
for i,s in enumerate(S):
    if s != b and s == "L":
        #print("ST",i)
        for j in range(1,i+1):
            #print("#l",i,j,S[i-j])
            if S[i-j] == "L":
                l = j - 1
                break
        else:
            l = j
        j = 0
        for j in range(1,len(S)-i):
            #print("#r",i,j,S[i+j])
            if S[i+j] == "R":
                r = j
                break
        else:
            r = j + 1
        #print(i,l,r)
        C[i] = (r+1)//2 + l//2
        C[i-1] = r//2 + (l+1)//2
    b = s
print(*C)

Measured memory_bytes: 6400
import sys
from io import StringIO
import unittest


def resolve():
    n = int(input())

    if n < 600:
        print(8)
    elif n < 800:
        print(7)
    elif n < 1000:
        print(6)
    elif n < 1200:
        print(5)
    elif n < 1400:
        print(4)
    elif n < 1600:
        print(3)
    elif n < 1800:
        print(2)
    else:
        print(1)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """725"""
        output = """7"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """1600"""
        output = """2"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16232
/*
[tenka1-2019] E - Polynomial Divisors
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e4;
const int MAX_P = 1e5;

int N;
vector<int> A;
vector<int> primes;

ll gcd(ll a, ll b) {
    while (b > 0) {
        swap(b, a %= b);
    }
    return a;
}

bool can(int p) {
    vector<int> a = A;
    for (int i = N - p; i >= 0; i--) {
        a[i + 1] += a[i + p];
        a[i + p] = 0;
    }
    return all_of(a.begin(), a.end(), [=](int i) { return i % p == 0; });
}

void solve() {
    bool is_prime[MAX_P + 1];
    fill(is_prime, is_prime + MAX_P + 1, true);
    for (int p = 2; p <= MAX_P; p++) {
        if (!is_prime[p]) {
            continue;
        }
        primes.push_back(p);
        for (int i = p * 2; i <= MAX_P; i += p) {
            is_prime[i] = false;
        }
    }

    int g = 0;
    for (int i = 0; i <= N; i++) {
        g = gcd(g, abs(A[i]));
    }
    for (int p : primes) {
        while (g % p == 0) {
            g /= p;
        }
    }
    if (g != 1) {
        primes.push_back(g);
    }

    for (int p : primes) {
        if (can(p)) {
            cout << p << endl;
        }
    }
}

int main() {
    cin >> N;
    A.resize(N + 1);
    for (int i = N; i >= 0; i--) {
        cin >> A[i];
    }

    solve();

    return 0;
}


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

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

Measured memory_bytes: 3600
n = int(input())
card = list()
mark = ['S','H','C','D']
for i in range(n):
 a,b = input().split()
 b = int(b)
 if a == 'S': card.append(0+b)
 elif a == 'H': card.append(13+b)
 elif a == 'C': card.append(26+b)
 else: card.append(39+b)
for i in range(1,53):
 if not (i in card): 
     print(mark[(i-1)//13],(i-1)%13+1)


Measured memory_bytes: 5604
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#ifdef DEBUGLOCAL
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;+--)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);+--)
#define rep0(i,n) for(i=0;i<(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define MP make_pair
#define PB push_back
#define SS stringstream
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

bool clause(string s){
	string a,b,c;
	s=s.substr(1,sz(s)-2);
	a=s.substr(0,s.find("&"));
	s=s.substr(s.find("&")+1,sz(s)-s.find("&")-1);
debug<<s<<endl;
	b=s.substr(0,s.find("&"));
	s=s.substr(s.find("&")+1,sz(s)-s.find("&")-1);
debug<<s<<endl;
	c=s;
debug<<s<<endl;
debug<<a<<" "<<b<<" "<<c<<endl;
	if(sz(a)==2&&sz(b)==1&&a[1]==b[0])return false;
	if(sz(b)==2&&sz(a)==1&&b[1]==a[0])return false;
	if(sz(a)==2&&sz(c)==1&&a[1]==c[0])return false;
	if(sz(c)==2&&sz(a)==1&&c[1]==a[0])return false;
	if(sz(b)==2&&sz(c)==1&&b[1]==c[0])return false;
	if(sz(c)==2&&sz(b)==1&&c[1]==b[0])return false;
	return true;
}

bool expression(string s){
	int i;
	while((i=s.find("|"))!=-1){
		string c=s.substr(0,i);
		if(expression(c))return true;
		s=s.substr(i+1,sz(s)-i-1);
	}
	return clause(s);
}

int main() {
	string exp;
	for(;;){
		cin>>exp;
		if(exp=="#")break;
		cout<<(expression(exp)?"yes":"no")<<endl;
	}
	return 0;
}

Measured memory_bytes: 1296
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int k;
	cin >> k;

	if (k == 3) {
		cout << "Yes\n";
		cout << "3\n";
		cout << "2 1 2\n";
		cout << "2 3 1\n";
		cout << "2 2 3\n";
	}
	else {

		int num = 0;
		for (int i = 0; i * i < 2 * k; i++) {
			if (i * (i + 1) == k * 2) {
				num = i;
				break;
			}
		}

		if (num == 0) cout << "No" << "\n";
		else {
			
			cout << "Yes" << "\n";
			cout << num + 1 << "\n";
			vector<vector<int>> ans(num, vector<int>(num));
			int cnt = 1;
			for (int i = 0; i < num; i++) {
				for (int j = 0; j < num - i; j++) {
					ans[i][j] = ans[num - j - 1][num - i - 1] = cnt++;
				}
			}

			for (int i = 0; i < num; i++) {
				cout << num << " ";
				for (int j = 0; j < num; j++) {
					cout << ans[i][j] << " ";
				}
			}
			
			cout << num << " ";
			for (int i = 0; i < num; i++) cout << ans[i][num - i - 1] << " ";
			cout << "\n";

		}

	}

	return 0;
}

Measured memory_bytes: 2176
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author Administrator
 */

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic 
        Scanner sc=new Scanner(System.in);
        int book[]=new int[4];
        int n=sc.nextInt();     
        for(int i=0;i<4;i++){
            book[i]=0;
        }
        for(int i=0;i<n;i++){
            String s=sc.next();
            if(s.equals("P")){
                book[0]=1;
            }
            else if(s.equals("W")){
                book[1]=1;
            }
            else if(s.equals("G")){
                book[2]=1;
            }
            else{
                book[3]=1;
            }
        }
        int sum=book[0]+book[1]+book[2]+book[3];
        if(sum==3)
            System.out.println("Three");
        else{
            System.out.println("Four");
        }
    }
}


Measured memory_bytes: 21972
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;

signed main(){
    int n;
    ll L;
    cin>>n>>L;
    V<ll> a(n);
    cinf(n,a);
    bool ok=0;
    int last;
    rep(i,n-1){
        if(a[i]+a[i+1]>=L){
            ok=1;
            last=i+1;
            break;
        }
    }
    if(ok){
        cout<<"Possible"<<endl;
        int m=1;
        while(m<last){
            cout<<m++<<endl;
        }
        m=n-1;
        while(m>last){
            cout<<m--<<endl;
        }
        cout<<last<<endl;
    }else cout<<"Impossible"<<endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int n,m;
map<int,int> mp;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		++mp[x];
	}
	bool check=true;
	scanf("%d",&m);
	for (int i=1;i<=m;i++)
	{
		int x;
		scanf("%d",&x);
		--mp[x];
		if (mp[x]<0) check=false;
	}
	if (check) cout << "YES" << endl; else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 9600
### constant

MAX_INT = 1 << 30

### main

n, m, k = gets.strip.split(' ').map{|s| s.to_i}

edges = n.times.map{[]}
nbrs = n.times.map{[]}

m.times do
  a, b, l = gets.strip.split(' ').map{|s| s.to_i}
  a -= 1
  b -= 1

  edges[a][b] = edges[b][a] = l
  nbrs[a] << b
  nbrs[b] << a
end
#p edges
#p nbrs

sms = n.times.map{false}

k.times do
  si = gets.strip.to_i
  sms[si - 1] = true
end
#p sms

dists = n.times.map{MAX_INT}
q = []

for st in (0...n)
  if sms[st]
    q << st
    dists[st] = 0
  end
end

while ! q.empty?
  u = q.min{|a, b| dists[a] <=> dists[b]}
  q.delete u

  for v in nbrs[u]
    dv = dists[v]
    d = dists[u] + edges[u][v]
    if dists[v] > d
      dists[v] = d
      q << v if dv >= MAX_INT
    end
  end
end

max_dist = 0

for s0 in (0...n)
  d0 = dists[s0]
  for s1 in nbrs[s0]
    d1 = dists[s1]
    l = edges[s0][s1]

    d = (l + d1 - d0 + 1) / 2 + d0
    max_dist = d if max_dist < d
  end
end

puts max_dist

Measured memory_bytes: 103512
#! env python
# -*- coding: utf-8 -*-

import os
import sys


# ac_py.main.py
# Date: 2020/06/08
# Filename: main.py 
# Author: acto_mini

def main():
    n = int(input())
    a = list(map(int, input().split()))
    result = 0
    loop = True

    while True:
        for i, v in enumerate(a):
            if v % 2 == 1:
                loop = False
                break
            else:
                a[i] = v / 2
        if not loop: break
        result += 1

    print(result)
    return


if __name__ == '__main__':
    main()


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

string s;

inline void rec(ll n) {
    if (n / 26 == 0) {
        char c = 'a' + (n % 26);
        s += c;
        return ;
    }
    rec(n % 26);
    rec(n / 26 - 1);
}

int main() {
    cin.tie(0)->sync_with_stdio(false);
    ll n; cin >> n;
    n--;

    rec(n);
    reverse(s.begin(), s.end());
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359

//階乗
ll factorial(ll num){ll sum = 1; for(ll i=1;i<=num;i++) sum*=i; return sum;}
//素数判定
bool isPrime(ll num){if(num<2){return false;}else if(num==2){return true;}else if(num%2==0){return false;} double sqrtNum=sqrt(num);for(int i=3;i<=sqrtNum;i+=2){if(num%i==0)return false;}return true;}

int main(){
  ll a,b;
  cin >> a >> b;
  
  int minus = 0;
  for(int i = a; i <= b; i++){
    if(i<0) minus++;
    if(i==0){
      cout << "Zero" << endl;
      return 0;
    }
  }
  if(minus%2!=0) cout << "Negative" << endl;
  else cout << "Positive" << endl;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	int ans=n*(n-1)/2+m*(m-1)/2;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define sz(a) int((a).size())
#define all(a)  a.begin(), a.end()
#define	debug(ccc)	cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const double eps = 1e-8;
#define EQ(a,b) (fabs((a)-(b))<eps)
inline int max(int a,int b){return a<b?b:a;}
inline int min(int a,int b){return a>b?b:a;}
inline ll max(ll a,ll b){return a<b?b:a;}
inline ll min(ll a,ll b){return a>b?b:a;}
const int mod = 1e9+7;
const int N = 1e6+10;
const ll inf = 1e18;

ll power(ll a,ll n){
	if(n==0){
		return 1;
	}
	ll b = power(a,n/2);
	b = b*b%mod;
	if(n%2) b= b*a%mod;
	return b;
}

int add(int a,int b){ return (a+b)%mod;}
int mul(int a,int b){ return (ll)a*b%mod;}




int main(){
 // 	freopen("nice.in","r",stdin);
 // freopen("nice.out","w",stdout);
	int n,m; scanf("%d %d",&n,&m);
	ll sum = 0, a1 = 0;
	REP(i,n){
		ll x; scanf("%lld",&x);
		sum += x*i%mod-a1; sum%=mod; a1 = (a1+x)%mod;
	}
	ll sum2 = 0, a2 = 0;
	REP(i,m){
		ll x; scanf("%lld",&x);
		sum2 += x*i%mod-a2; sum2%=mod; a2 = (a2+x)%mod;
	}
	printf("%lld\n",(sum*sum2%mod+mod)%mod);
	return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int k, q;
    cin >> k >> q;
    ll d[k];
    //sum[i]:=[0,i]におけるd[i]の総和
    rep(i, k){
        cin >> d[i];
    }
    rep(i, q){
        ll n, x, m, sum[k];
        cin >> n >> x >> m;
        //加える数の総和
        sum[0] = d[0]%m;
        rep2(i, 1, k-1){
            sum[i] = sum[i-1]+(d[i]%m);
        }
        ll S = ((n-1)/k)*sum[k-1];
        if((n-1)%k > 0) S += sum[(n-1)%k-1];
        ll num = (S+x)/m - x/m;
        rep(i, k){
            if(d[i]%m == 0){
                num += (n-1)/k;
                if((n-1)%k > i) num++;
            }
        }
        cout << n-1-num << endl;
    }
}

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int>b(N);
    vector<int>check(N, true);
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }

    int cnt = 0;
    vector<int>a;
    int c = N;
    while (c--) {
        int loc = N-cnt;
        int i;
        for (i = N-1; i >= 0; i--) {
            if (check[i] == true && loc == b[i]) {
                check[i] = false;
                a.push_back(b[i]);
                cnt++;
                break;
            } else {
                if (check[i] == false) {
                    continue;
                }
                loc--;
            }
        }
        if (i==-1) {
            break;
        }
    }
    if (a.size() != N) {
        cout << -1 << endl;
    } else {
        for (int i = 0; i < N; i++) {
            cout << a[N-1-i] << endl;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

void dfs(const vector<vector<int>>& g, const int& i, vector<bool>& visited) {
    if (visited[i]) return;
    visited[i] = true;

    for (auto v : g[i]) {
        if (visited[v]) continue;
        dfs(g, v, visited);
    }
}

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<int>> g(n+1);

    for (int i=0; i<m; i++) {
        int a,b;
        cin >> a >> b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }

    int ans = 0;
    vector<bool> visited(n+1, false);
    for (int i=1; i<=n; i++) {
        if (visited[i]) continue;
        dfs(g, i, visited);
        ans++;
    }

    cout << ans - 1 << endl;
}

Measured memory_bytes: 9608
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
#define MOD 1000000007ll

using namespace std;

int main(int argc, char const *argv[])
{
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a <= k)
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }
    return 0;
}


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

int main()
{
    int n, m, l, r;
    int lmax = 0;
    int rmin = 1000000000;
    cin >> n >> m;
    for (size_t i = 0; i < m; i++)
    {
        cin >> l >> r;
        lmax = max(lmax, l);
        rmin = min(rmin, r);
    }
    if (lmax <= rmin)
    {
        cout << rmin - lmax + 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
v = gets.chomp.split.map(&:to_i)

ary = []

n.times do |i|
  ary.push(v[i])
end
arysort = ary.sort

(n-1).times do |i|
  sorezore_wa = (arysort[0] + arysort[1]).quo(2).to_f
  arysort.unshift(sorezore_wa)

  arysort.delete_at(1)
  arysort.delete_at(1)
end

p arysort[0]


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

int main() {
    int w, h, x, y, r, difX, difY;
    cin >> w >> h >> x >> y >> r;
    difX = w - x;
    difY = h - y;
    if ( x > 0 && y > 0 ) {
        if (difX >= r && difY >= r) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
import sys
sys.setrecursionlimit(250010)

N, M =map(int, input().split())
ab=[list(map(int, input().split())) for _ in range(M)]
node=[0 for _ in range(N)]
node[0]=1
ans=0

def dfs(v):
    global ans
    if all(x==1 for x in node):
        ans+=1
        return

    adj=[]
    for i in ab:
        if i[0]==v+1 and node[i[1]-1]==0:
            adj.append(i[1])
        if i[1]==v+1 and node[i[0]-1]==0:
            adj.append(i[0])
    for i in adj:
        node[i-1]=1
        dfs(i-1)
        node[i-1]=0
    return

dfs(0)
print(ans)


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

void solve() {
    int n, k;
    std::cin >> n >> k;

    std::vector<int> cnt(n, 0);
    while (k--) {
        int d;
        std::cin >> d;
        while (d--) {
            int x;
            std::cin >> x;
            ++cnt[--x];
        }
    }

    std::cout << std::count_if(cnt.begin(), cnt.end(),
                               [](int x) { return x == 0; })
              << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
#define ll long long
#define INF 100000000
#define uint unsigned int
using namespace std;

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

	if ((a < c && c < b) || (b < c && c< a)){
		cout << "Yes" << endl;

	}
	else {
		cout << "No" << endl;	
	}

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(int argc,char *argv[]){
  int h;
  int w;
  char isrd = 1;
  int ans;
  int i = 0,j=0,k=0,l=0;
  int goukei=0;
  long loopc=0;
  long lc=0;
  long a[10000],b[10000];
  long apoint=0,bpoint=0;
  while(isrd){
    scanf("%d",&loopc);
    if(loopc==0)break;
    isrd++;
    for(i = 0;i < loopc;i++){
      lc++;
      scanf("%ld",&apoint);
      scanf("%ld",&bpoint);
      if(apoint > bpoint){
	a[j] += apoint+bpoint;
      }
      if(bpoint > apoint){
	b[k] += bpoint+apoint;
      }
      if(apoint == bpoint){
	a[j] += apoint;
	b[k] += bpoint;
      }
    }
    j++;
    k++;
  }
  for(i=0;i < isrd;i++){
    if(a[i]==0 && b[i]==0)break;
    printf("%ld %ld\n",a[i],b[i]);
  }
  return 0;
}

Measured memory_bytes: 604