akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//const ll MOD=1e9+7;
//static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}



const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){

    COMinit();
    int n,k;
    cin>>n>>k;
    vector<ll> v(n);
    rep(i,n){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    ll ans = 0;

    for(int i=n-1;i>=k-1;i--){
        ans += v[i]*COM(i,k-1);
        ans%=MOD;
    }

    //cout<<ans<<endl;
    for(int i=0;i<=n-k;i++){
        ans = (ans-(v[i]*COM(n-i-1,k-1)%MOD)+MOD)%MOD;
        ans%=MOD;
//        ans -= v[i]*COM(n-i-1,k-1)%MOD;
//        if(ans<0){
//            ans+=MOD;
//        }
//        ans%=MOD;

    }
    cout<<ans%MOD<<endl;




    
return 0;
}


Measured memory_bytes: 12928
#include<iostream>
#include<set>
using namespace std;typedef set<int>S;S s[86];S::iterator q;char e[9999];int p;S PT();S U(S a,S b){for(q=b.begin();q!=b.end();++q)a.insert(*q);return a;}S D(S a,S b){for(q=b.begin();q!=b.end();++q)a.erase(*q);return a;}S PB(){S a=PT();for(;;){if(e[p]=='u'){p++;a=U(a,PT());}else if(e[p]=='i'){p++;a=D(a,D(s[85],PT()));}else if(e[p]=='d'){p++;a=D(a,PT());}else if(e[p]=='s'){p++;S b=PT();a=U(D(a,b),D(b,a));}else return a;}}S PT(){S a;if(e[p]=='('){p++;a=PB();p++;}else if(e[p]=='c'){p++;a=D(s[85],PT());}else{a=s[e[p++]];}return a;}int main(){char n;int m,v;for(;cin>>n>>m;){if(n-82){for(s[n].clear();m--;s[85].insert(v))cin>>v,s[n].insert(v);}else{cin>>e;p=0;S r=PB();for(q=r.begin();q!=r.end();cout<<(++q!=r.end()?' ':'\n'))cout<<*q;if(r.empty())cout<<"NULL\n";s[85].clear();}}}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a) memset(a,0,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first 
#define se second
int main(){
	int n;
	scanf("%d",&n);
	ll ans=1LL*n*(n+1)*(n+2)/6;
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		if(u>v) swap(u,v);
		ans-=1LL*u*(n-v+1); 
	}
	printf("%lld\n",ans); 
	return 0;
}

Measured memory_bytes: 3820
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
long long a , b , c ;
cin >> a >> b >> c;
if ( a >= c && a >= b) cout << (a&1)*b*c;
else if(b >= c) cout  <<(b&1)*a*c;
else cout << (c&1)*a*b;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
map<int,int>::iterator it;
int main()
{
    int n,a;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a);
        if(mp[a]==0)
        mp[a]++;
        else mp[a]--;
    }
    long long sum=0;
    for(it=mp.begin();it!=mp.end();it++)
    {
        sum+=it->second;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  
  int n;
  cin >> n;
  
  int ans = 0;
  for(int a=1;a<n;a++){
    ans += (n-1)/a;
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

int a[3][35];

int main(){
  int N,C;
  cin>>N>>C;
  int D[35][35];
  rep(i,C) rep(j,C){
    cin>>D[i][j];
  }
  int c[505][505];
  rep(i,N) rep(j,N){
    cin>>c[i][j];
    c[i][j]--;
  }
  rep(h,N) rep(w,N){
    if((h+w)%3==0)
      a[0][c[h][w]]++;
    else if((h+w)%3==1)
      a[1][c[h][w]]++;
    else
      a[2][c[h][w]]++;
  }
  int ans=1e9;
  rep(i,C) rep(j,C) rep(k,C){
    if(i==j||i==k||j==k) continue;
    int sum=0;
    rep(l,3) rep(m,C){
      if(l==0)
	sum+=a[l][m]*D[m][i];
      else if(l==1)
	sum+=a[l][m]*D[m][j];
      else
	sum+=a[l][m]*D[m][k];
    }
    ans=min(sum,ans);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1280
program prob3
    implicit none
    integer :: a(5), ans, i, mi
    read(*,*) a
    ans = 0
    do i = 1, 5
        ans = ans + a(i)
        ans = ((ans - 1) / 10 + 1) * 10
    end do
    mi = 10
    do i = 1, 5
        if(mod(a(i), 10) == 0) then
            cycle
        end if
        mi = min(mod(a(i), 10), mi)
    end do
    ans = ans - (10 - mi)
    write(*,*) ans

    stop
contains
end program prob3

Measured memory_bytes: 2788
//解説AC
//vacantをはかせてreturnする

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


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

    int left = 0;
    //fflush
    cout << left << endl;
    string s;
    cin >> s;
    if (s == "Vacant") return 0;

    int right = n;

    while(right - left > 1){
        int mid = (right + left) / 2;
        cout << mid << endl;
        string t;
        cin >> t;
        if (t == "Vacant") return 0;
        else{
            if (((mid - left)%2 == 1 && s != t) || ((mid - left)%2 == 0 && s == t)){
                left = mid;
                s = t;
            }
            else right = mid;
        }
    }

    return 0;
}


Measured memory_bytes: 3800
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-13 13:06:55
                2020-04-13 14:12:37 余計な部分を削った版
*/

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

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;

        return true;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        int rx = root(x);
        return -par[rx];
    }
};

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(m), b(m), c(k), d(k);
    for (int i = 0; i < m; i++)
        cin >> a[i] >> b[i];
    for (int i = 0; i < k; i++)
        cin >> c[i] >> d[i];

    UnionFind tr(n);
    for (int i = 0; i < m; i++) {
        tr.unite(a[i]-1, b[i]-1);
    }

    vector<set<int>> notf(n);
    for (int i = 0; i < m; i++) {
        notf[a[i]-1].insert(b[i]-1);
        notf[b[i]-1].insert(a[i]-1);
    }
    for (int i = 0; i < k; i++) {
        if (tr.same(c[i]-1, d[i]-1)) {
            notf[c[i]-1].insert(d[i]-1);
            notf[d[i]-1].insert(c[i]-1);
        }
    }
    
    for (int i = 0; i < n; i++) {
        int ans = tr.size(i) - notf[i].size() - 1;
        cout << ans << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 26240
def abc095C():
    a, b, c, x, y = map(int, input().split())

    diff = abs(x - y)
    price1 = [(a + b) * min(x, y), 2 * c * min(x, y)][a + b >= c * 2] + diff * [a, b][x < y]
    print(min(price1, max(x, y) * c * 2))


abc095C()

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

// バケット法による解法
int main() {
    int n;
    cin >> n;
    // vector<int> d(n);
    int d[110];
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    int num[110] = {0};
    for (int i = 0; i < n; i++) {
        num[d[i]]++;
    }
    int cnt = 0;
    for (int i = 1; i <= 100; i++) {
        if (num[i]) {
            ++cnt;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,l,r)for(int i=(int)l;i<(int)r;i++)
#define rep(i,n)Rep(i,0,n)
typedef long long lld;
typedef long double Lf;
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define N 200001

int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	printf("%d", a * b);
}

Measured memory_bytes: 1732
n=int(input())
dic={}

for i in range (n):
  key=input()
  if key not in dic:
    dic[key]=1
  else:
    dic[key]+=1
    
max_v=max(dic.values())

ls=sorted(list(filter(lambda key:dic[key]==max_v,list(dic))))

for key in ls:
  print (key)

Measured memory_bytes: 32988
#include <cstdio>
#include <cstdlib>

int main()
{
	long long X, Y, Z;
	
	scanf("%lld%lld", &X, &Y);
	
	Z = X * (Y - 1);
	
	if(Z % Y == 0) printf("-1\n");
	else printf("%lld\n", Z);
	return 0;
}

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



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

  ll X, a, b;
  cin >> X;

  rep(i, 150){
    rep(j, 150){
      a = pow(i,5)-pow(j,5);
      b = pow(i,5)+pow(j,5);
      if (a == X)
      {
        cout << i << ' ' << j << "\n";
        return 0;
      }
      if (b == X)
      {
        cout << i << ' ' << -j << "\n";
        return 0;
      }
      
      
    }
  }

  }




Measured memory_bytes: 4076
N = gets.to_i
if N == 3
  p 61; exit
end

Mod = 10**9+7
CS = ["A","G","C","T"]

def gen(s = "")
  return s if s.size == 4
  CS.map{ |c|
    gen(s + c)
  }.flatten(1)
end

ss = gen()
dp = Hash[ss.map{ |s| [s,1] }]

[
  "AGC*",
  "GAC*",
  "ACG*",
  "*AGC",
  "*GAC",
  "*ACG",
  "A*GC",
  "AG*C",
].each{ |s|
  ["A","T","G","C"].each{ |c|
    dp.delete(s.sub("*",c))
  }
}

(4...N).each{
  ddp = Hash[dp.map{ |s,v| [s,0] }]
  dp.each{ |s,v|
    CS.each{ |c|
      t = s[1..3]+c
      if ddp[t]
        #p "#{s} -> #{t}"
        ddp[t] = (ddp[t] + dp[s]) % Mod
      end
    }
  }
  dp = ddp
}
p dp.values.inject(:+) % Mod


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
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;}
class My_Debug
{
private:
	bool DEBUG_FLAG;	
public:
	My_Debug():DEBUG_FLAG(true){}
	void dump(vector<int>& v){
		int sz = v.size();
		printf("[");
		for(int i=0;i<sz;i++)printf("%d%c",v[i],(i==sz-1)?']':',');
		printf("\n");
	}
	void dump(int* v,int sz){
		printf("[");
		for(int i=0;i<sz;i++)printf("%d%c",v[i],(i==sz-1)?']':',');
		printf("\n");
	}
};
int main(){
	int N;
	cin >> N;
	int ans = 0;
	for(int i=0;i<N;i++){
		int l,r;
		cin >> l >> r;
		ans += r-l+1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;

public class Main {
  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String input = br.readLine();
    String[] param = input.split(" ");
    int a = Integer.parseInt(param[0]);
    int b = Integer.parseInt(param[1]);
    int s = a * b;
    int l = (a + b) * 2;
    System.out.println(s + " " + l);
  }
}

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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N;
	cin>>N;
	map<int,int> ans;
	rep(i,N){
		int t;
		cin>>t;
		ans[t]++;
	}
	int e_ans = 0;
	for(auto x:ans)if(x.second%2 == 1)e_ans++;
		cout<<e_ans<<endl;
	return 0;
}

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

int main() {

  int n,k;
  while(1) {
    cin >> n >> k;
    if(n == 0 && k == 0) break;

    int a[101] ={};
 
    for(int i=0;i<n;i++) cin >> a[i];

     int ck = -1;
    for(int i=0;i<=n-k;i++) {
      int t = 1;
      for(int j=0;j<k;j++) t*= a[j+i];
      if(ck <t) ck = t;
    }

    int ck2=-1;
    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
	if(i == j) continue;
	swap(a[i] ,a[j]);
	for(int l=0;l<=n-k;l++) {
	  int t = 1;
	  for(int m=0;m<k;m++) t*= a[m+l];
	  if(ck2 <t) ck2 = t;
	}
	swap(a[i],a[j]);
      }
    }

    // cout << ck <<" "<<ck2<<endl;
    if(ck2-ck < 0 ) cout <<"NO GAME"<<endl;
    else cout << ck2-ck <<endl;
  }
  return 0;  
}

Measured memory_bytes: 1160
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
        
        int max = Math.max(a, b);
        max = Math.max(max, c);
        int notMax = 0;
        if (a != max) {
          notMax += a;
        }
        if (b != max) {
          notMax += b;
        }
        if (c != max) {
          notMax += c;
        }
    
		// 出力
		System.out.println(max == notMax ? "Yes" : "No");
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n; cin >> n;
    string s; cin >> s;
    ll cnt = 0;
    ll mn = INF;
    ll kuro = 0;
    ll siro = 0;
    vl sirocnt(n);
    ll kuromax = -INF;
    ll index = n;
    for(ll i=n-1; i>=0; i--){
        if(s[i] == '#') kuro++;
        else siro++;
        sirocnt[i] = siro;
        //cout << kuro << " " << siro << endl;
        if(kuro - siro >= 0 && kuromax < kuro - siro){
            kuromax = kuro - siro;
            index = i;
        }
    }
    ll ans = index == n ? 0 : sirocnt[index];
    rep(i,index){
        if(s[i] == '#') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2180
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using ll = long long;
using namespace std;

int main(){
  ll N, K;

  cin >> N >> K;

  vector<ll> H(N);

  for(auto& h : H){
    cin >> h;
  }

  if(N <= K){
    cout << 0 << endl;
  }else{
    sort(H.begin(), H.end());

    ll ans = 0;

    for(ll i = 0; i < N-K; ++i){
      ans += H[i];
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**6)

def dfs(v, graph):
    if visited[v]:
        if not calculated[v]: #visited and not calculated == loop
            return -1 
        return depth[v]
    visited[v] = True
    for e in graph[v]: # すべての辺をなめる
        res = dfs(e, graph) # 再帰
        if res == -1: 
            return -1 # ループを見つけたら-1を返す
        
        depth[v] = max(depth[v], res+1) #より深い経路を発見したか？
    calculated[v] = True 
    return depth[v]


if __name__ == '__main__':
    N = int(input())
    Ng = N*(N-1)//2
    graph = [[] for _ in range(Ng)]
    G_id = [[-1]*N for _ in range(N)]
    
    game_id = 0
    first_game_id = []
    for i in range(N):
        row = list(map(int, input().split()))
        for d, r in enumerate(row):
            if G_id[i][r-1] == -1: #新しい試合の組み合わせ
                G_id[i][r-1] = game_id 
                G_id[r-1][i] = game_id
                
                if d != 0: # 行が更新されているかのチェック
                    graph[before].append(game_id)
                else:
                    first_game_id.append(game_id)
                    
                before = game_id # idの更新・一つ記録
                game_id += 1
            else: # 既存の組み合わせ
                if d != 0: # 行が更新されているかのチェック
                    graph[before].append(G_id[i][r-1])
                else:
                    first_game_id.append(G_id[i][r-1])
                before = G_id[i][r-1] #現在の試合を記録
    
    depth = [1]*Ng # 頂点から出発したときの最長経路
    visited = [False]*Ng
    calculated = [False]*Ng
    flag = True
    ans = 1
    for i in first_game_id:
        res = dfs(i, graph)
        if res == -1:
            flag = False
        else:
            ans = max(ans, res)
    if flag:
        print(ans)
    else:
        print(-1)
    
    

Measured memory_bytes: 162560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 
ll N, W;
vector<vector<P>> obj(4);
 
int main(void){
	
	scanf("%lld %lld", &N, &W);
	ll base = 0;
	for(int i = 0; i < N; ++i){
	    ll w, v; scanf("%lld %lld", &w, &v);
	    if(i == 0) base = w;
	    obj[w - base].push_back(make_pair(v, w));
	}
	for(int i = 0; i < 4; ++i){
	    sort(obj[i].begin(), obj[i].end(), greater<P>());
	    if(!obj[i].size()) obj[i].push_back(make_pair(0, 0));
	}
	
	ll ans = 0;
    for(int i = 0; i <= N; ++i){
        for(int j = 0; i + j <= N; ++j){
            for(int k = 0; i + j + k <= N; ++k){
                for(int l = 0; i + j + k + l <= N; ++l){
                    ll weight = 0, value = 0;
                    if(i > 0) for(int n = 0; n < obj[0].size() && n < i; ++n) weight += obj[0][n].second, value += obj[0][n].first;
                    if(j > 0) for(int n = 0; n < obj[1].size() && n < j; ++n) weight += obj[1][n].second, value += obj[1][n].first;
                    if(k > 0) for(int n = 0; n < obj[2].size() && n < k; ++n) weight += obj[2][n].second, value += obj[2][n].first;
                    if(l > 0) for(int n = 0; n < obj[3].size() && n < l; ++n) weight += obj[3][n].second, value += obj[3][n].first;
                    if(weight <= W) ans = max(ans, value);
                }
            }
        }
    }
	printf("%lld\n", ans);
	
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF       numeric_limits<int>::max()
#define NINF      numeric_limits<int>::min()
#define MOD       1000000007

using namespace std;
using Int = long long;

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

    vector<int> coin_vals{500, 100, 50, 10, 5, 1};

    while(true) {
        int in;
        std::cin >> in;
        if(in == 0) {
            break;
        }

        int ans    = 0;
        int change = 1000 - in;
        for(const auto& coin_val : coin_vals) {
            ans    += change / coin_val;
            change %= coin_val;
        }

        std::cout << ans << std::endl;
    }

    return 0;
}



Measured memory_bytes: 3152
#include <stdio.h>
#include <string.h>

int main(){
	char s[200+1]={0};
	scanf("%s",s);
	int len = strlen(s), flag=0;

	s[len-2]='\0';
	len-=2;

	while( len > 2 ){
		for(int i=0; i<len/2; i++){
			if( s[i]!=s[len/2+i] ){ flag=1; break; }
		}
      	if( !flag ){ break; }
     	else{
			s[len-2]='\0';
			len-=2;
      		flag=0;
        }
	}
	printf("%d\n", strlen(s));
	return 0;
}

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

#define rep(i,n) for(int (i)=0; (i)<(int)(n); (i)++)
#define all(x) (x).begin(), (x).end()
#define sqr(x) (x)*(x)
#define CEIL(a,b) ((a)+(b)-1) /(b)

typedef long long ll;
const int INF = 1001001001;

void sort_second(vector<pair<ll, ll>> &A, int N); //A:array of pair, N:size of array

int main() {
    int N;
    cin >> N;
    set<int> S;
    int a;
    rep(i, N) {
        cin >> a;
        if(S.count(a)) {
            cout << "NO" << endl;
            return 0;
        }
        else {
            S.insert(a);
        }
    }
    cout << "YES" << endl;

    return 0;
}

void sort_second(vector<pair<ll, ll>> &A, int N) {
    rep(i, N) swap(A.at(i).first, A.at(i).second);
    sort(all(A));
    rep(i, N) swap(A.at(i).first, A.at(i).second);
}

Measured memory_bytes: 9600
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		int k = Integer.parseInt(sc.nextLine());
		sc.close();
		
		int[] dupArr = new int[s.length()+1];
		
		char beforeChar = s.charAt(0);
		int length = 1;
		for(int i = 1; i < s.length(); i++) {
			char nowChar = s.charAt(i);
			if(nowChar == beforeChar) {
				length++;
			}else {
				beforeChar = nowChar;
				dupArr[length] += 1;
				length = 1;
			}
		}
		dupArr[length] += 1;
		
		if(dupArr[s.length()] > 0) {
			
			System.out.println((long)s.length() * (long)k / 2L);
			
		}else {
			
			long replaceAtSingle = 0;
			for(int i = 2; i < s.length();i++) {
				replaceAtSingle += (i/2) * dupArr[i]; 
			}
			
			if(s.charAt(0) == s.charAt(s.length() - 1)) {
				
				int startDup = 0;
				int endDup = 0;
				
				char startEndChar = s.charAt(0);
				while(s.charAt(startDup) == startEndChar) {
					startDup++;
				}
				while(s.charAt(s.length() - endDup -1) == startEndChar) {
					endDup++;
				}
				
				long replaceAtDup =replaceAtSingle;
				replaceAtDup -= startDup/2;
				replaceAtDup -= endDup/2;
				replaceAtDup += (startDup + endDup)/2;
				
				System.out.println(replaceAtSingle + replaceAtDup *(k-1));
				
			}else {
				System.out.println(replaceAtSingle*k);
			}
			
		}
		
	}

}


Measured memory_bytes: 21716
$<.readlines.map(&:chomp).each do |given|
  text = ""
  while given.length > 0
    if given[0] == "@"
      text += given[2] * given[1].to_i
      given = given[3..-1]
    else
      text += given[0]
      given = given[1..-1]
    end
  end
  puts text
end


Measured memory_bytes: 6832
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int r = cin.nextint;
        int g = cin.nextint;
        int b = cin.nextint;
        if ((g * 10 + b ) % 4 == 0)
        {
            WriteLine("YES");
        }
        else
        {
            WriteLine("NO");
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 2e5 + 7;
int n, A, B, C, D;
char s[N];
int main() {
#ifdef fwat
#endif
	n = gi(), A = gi(), B = gi(), C = gi(), D = gi();
	scanf("%s", s + 1);
	int mx = 0;
	for(int i = A, j = i; i <= C; i = j + 1, j = i) {
		while(j + 1 <= C && s[j + 1] == s[j]) ++j;
		if(s[i] == '#') Max(mx, j - i + 1);
	}
	if(mx > 1) return puts("No"), 0;
	mx = 0;
	for(int i = B, j = i; i <= D; i = j + 1, j = i) {
		while(j + 1 <= D && s[j + 1] == s[j]) ++j;
		if(s[i] == '#') Max(mx, j - i + 1);
	}
	if(mx > 1) return puts("No"), 0;
	bool fg = 0;
	for(int i = B - 1, j = i; i <= D + 1; i = j + 1, j = i) {
		while(j + 1 <= D + 1 && s[j + 1] == s[j]) ++j;
		if(s[i] == '.' && j - i + 1 >= 3) fg = 1;
	}
	if(C > D && !fg) return puts("No"), 0;
	puts("Yes");
	return 0;
}

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

#define ll long long
const ll MAXN= 1e5+10;

ll a[MAXN];

int main()
{
	ll n;
	cin>>n;
	ll num2=0,num4=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]%4==0){
			num4++;
		}
		else if(a[i]%2==0){
			num2++;
		}
	}
	if(num4>=n/2||num2>=(n- (num4*2) )){
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <tuple>
template <typename T> constexpr T my_abs(const T &x) { return x < 0 ? -x : x; }
using ll = long long;
constexpr int MOD = 1e9 + 7;
int app[35];
char str[100005];
int main()
{
	// freopen("AGC031-A.in", "r", stdin);
	int n, ans = 1;
	scanf("%d%s", &n, str);
	for (int i = 0; i < n; i++)
		app[str[i] - 'a']++;
	for (int i = 0; i < 26; i++)
		ans = (ll)ans * (app[i] + 1) % MOD;
	printf("%d\n", (ans + MOD - 1) % MOD);
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double EPS = 1e-9;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int n;
int s[100];

int main() {
	// cin.tie(0); // tie
	// ios::sync_with_stdio(false); // sync
	while (cin >> n, n) {
		int mini = 10000, maxi = -1;
		int sum = 0;
		rep(i, n) {
			int s; cin >> s;
			if (mini > s) mini = s;
			if (maxi < s) maxi = s;
			sum += s;
		}
		int av = (sum - mini - maxi) / (n - 2);
		cout << av << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()
using lint = long long;
template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }
inline int bitCount(int x) { return __builtin_popcount(x); }
inline int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int N;
	cin >> N;
	cout << 180 * (N-2) << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
      
        if (A < 10 && B < 10) {
        	System.out.print(A * B);
        } else {
        	System.out.print(-1);
        }
	
	return;

	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	vector<int> s, h, c, d;
	for(int i = 1; i < 14; i++){
		s.push_back(i);
		h.push_back(i);
		c.push_back(i);
		d.push_back(i);
	}
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		char mark;
		int num;
		cin >> mark >> num;
		switch(mark){
			case 'S':
				s[num - 1] = 0;
				break;
			case 'H':
				h[num - 1] = 0;
				break;
			case 'C':
				c[num - 1] = 0;
				break;
			case 'D':
				d[num - 1] = 0;
				break;
		}
	}

	for(int i = 0; i < 13; i++){
		if(s[i] != 0){
			cout << "S " << s[i] << '\n';
		}
	}
	for(int i = 0; i < 13; i++){
		if(h[i] != 0){
			cout << "H " << h[i] << '\n';
		}
	}
	for(int i = 0; i < 13; i++){
		if(c[i] != 0){
			cout << "C " << c[i] << '\n';
		}
	}
	for(int i = 0; i < 13; i++){
		if(d[i] != 0){
			cout << "D " << d[i] << '\n';
		}
	}
}



Measured memory_bytes: 3112
K=int(input())
a=list(range(1,10))
if K<=9:
  print(a[K-1])
  quit()
count=9
i=0
while count<K+1:
  b=a[i]%10
  if b!=0:
    a.append(a[i]*10+b-1)
    count+=1
  a.append(a[i]*10+b)
  count+=1
  if b!=9:
    a.append(a[i]*10+b+1)
    count+=1
  i+=1
print(a[K-1])

Measured memory_bytes: 7268
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>



int main() {
	
	int width, height;
	int ox, oy, r;
	bool judge = true;

	std::cin >> width >> height >> ox >> oy >> r;

	//ue
	if (judge && oy + r > height)judge = false;

	//sita
	if (judge && oy - r < 0)judge = false;

	//migi
	if (judge && ox + r > width)judge = false;

	//hidari
	if (judge && ox - r < 0)judge = false;

	if (judge)printf("Yes\n");
	else printf("No\n");

	//system("pause");
	return 0;
}


Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {

	public static void printArray(int num, int[] array) {
		for (int i = 0; i < num; i++) {
			if (i != 0) {
				System.out.print(" ");
			}
			System.out.print(array[i]);
		}
		System.out.println("");
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] array = new int[100];
		int num;
		int minIndex;
		int temp;
		int count = 0;

		// 入力
		num = scan.nextInt();
		for (int i = 0; i < num; i++) {
			array[i] = scan.nextInt();
		}

		// ソート
		for (int i = 0; i < num; i++) {
			minIndex = i;
			for (int j = i; j < num; j++) {
				if (array[j] < array[minIndex]) {
					minIndex = j;
				}
			}
			if (i != minIndex) {
				temp = array[i];
				array[i] = array[minIndex];
				array[minIndex] = temp;
				count++;
			}
		}

		// 出力
		printArray(num, array);
		System.out.println(count);

	}
}


Measured memory_bytes: 26416
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b;
    cin >> a >> b;
    cout << (a * 3 + b) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

char al[11] = {'a','b','c','d','e','f','g','h','i','j','k'};

int n;

void dfs(string s){
    if(s.size() == n){
        cout << s << endl;
        return;
    }
    set<char> st;
    int idx = 0;
    rep(i,s.size()){
        st.insert(s[i]);
        chmax(idx, s[i]-'a');
    }
    for(auto e : st){
        dfs(s + e);
    }
    ++idx;
    char nex = 'a' + idx;
    dfs(s + nex);
    return;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    dfs("a");
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main(){
    int count[4][3][10];
    int b,f,r,v,i,ii,iii,iiii,n;
    for(i=0;i<4;++i){
        for(ii=0;ii<3;++ii){
            for(iii=0;iii<10;++iii){
                count[i][ii][iii]=0;
            }
        }
    }
    cin>>n;
    for(i=0;i<n;++i){
        cin>>b>>f>>r>>v;
            count[b-1][f-1][r-1]=v+count[b-1][f-1][r-1];
    if(count[b-1][f-1][r-1]>9){
        count[b-1][f-1][r-1]=9;
    }
    if(count[b-1][f-1][r-1]<0){
        count[b-1][f-1][r-1]=0;
    }
}
    for(i=0;i<4;i++){
    for(ii=0;ii<3;ii++){
        for(iii=0;iii<10;iii++){
            if(iii==9){
                cout<<count[i][ii][iii];
            }
            else if(iii==0){
                cout<<" "<<count[i][ii][iii]<<" ";
            }
            else{
                cout<<count[i][ii][iii]<<" ";
            }
        }
        cout<<endl;
    }
        if(i<3){
            cout<<"####################"<<endl;}
    }
    return 0;
}

Measured memory_bytes: 3104
N = int(input())
S = input()

all = S.count("R") * S.count("G") * S.count("B")
count = 0
for i in range(N):
    for j in range(1,N):
        k = 2*j - i
        if k < N and i < j:
            if (S[i] != S[j]) and (S[j] != S[k]) and (S[k] != S[i]):
                count += 1
print(all-count)    

Measured memory_bytes: 73632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int i,j,k,h,x,q,n,c,p[101][101],l[101];
  while(cin>>n,n){
    for(i=1;i<=n;i++)
      for(cin>>p[i][0],j=1;j<=p[i][0];j++)
        cin>>p[i][j];
    for(cin>>k,q=i=0;i<k;i++)cin>>l[i];
    for(i=1;i<=n;i++){
      for(c=0,j=1;j<=p[i][0];j++){
        if(p[i][0]<k)break;
        for(h=0;h<k;h++)if(p[i][j]==l[h])c++;
      }
      if(c==k){
        if(q==1){q=0;break;}
        x=i;q=1;
      }
    }
    if(!q)cout<<-1<<endl;
    else cout<<x<<endl;
  }
}

Measured memory_bytes: 3112
abc=list(map(int,input().split()))
abc.sort()
ans=0

while 1:
    if abc[0]==abc[1]==abc[2]:
        print(ans)
        exit()

        
    if abc[1]!=abc[2]:
        abc[0]+=1
        abc[1]+=1
        ans+=1
    elif abc[1]==abc[2] and abc[1]+1==abc[0]:
        abc[1]+=1
        abc[2]+=1
        ans+=1
    else:
        abc[0]+=2
        ans+=1


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

int main(){

    ll N;
    cin >> N;
    vector<ll>A(N+1, 0), B(N, 0);
    for(ll i = 0; i < N + 1; i++)cin >> A[i];
    for(ll i = 0; i < N; i++)cin >> B[i];
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        ll tmp = min(A[i], B[i]);
        ans += tmp;
        A[i] -= tmp;
        B[i] -= tmp;
        tmp = min(A[i+1], B[i]);
        ans += tmp;
        A[i+1] -= tmp;
        B[i] -= tmp;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

double d(double x1, double y1, double x2, double y2) {
  return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}

int main() {
  ll n;
  cin >> n;
  vd x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  double ep = 1e-9;
  double ans = 1e18;
  rep(i, n - 1) rep2(j, i + 1, n) {
    double ox = (x[i] + x[j]) / 2;
    double oy = (y[i] + y[j]) / 2;
    double r = 0;
    rep(l, n) r = max(r, d(ox, oy, x[l], y[l]));
    ans = min(ans, r);
  }
  rep(i, n - 2) rep2(j, i + 1, n - 1) rep2(k, j + 1, n) {
    double a = d(x[j], y[j], x[k], y[k]);
    double b = d(x[k], y[k], x[i], y[i]);
    double c = d(x[i], y[i], x[j], y[j]);
    if(a + b - c < ep || b + c - a < ep || c + a - b < ep) continue;
    double aa = a * a * (b * b + c * c - a * a);
    double bb = b * b * (c * c + a * a - b * b);
    double cc = c * c * (a * a + b * b - c * c);
    double ox = (aa * x[i] + bb * x[j] + cc * x[k]) / (aa + bb + cc);
    double oy = (aa * y[i] + bb * y[j] + cc * y[k]) / (aa + bb + cc);
    double r = 0;
    rep(l, n) r = max(r, d(ox, oy, x[l], y[l]));
    ans = min(ans, r);
  }
  printf("%.18f\n", ans);
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//inline int in() { int x; scanf("%d",&x); return x;}
inline ll in() { ll x; cin >> x; return x; }
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

int main() {
  int n = in();
  if (n <= 9) {
    cout << n << endl;
  } else if (n <= 99) {
    cout << 9 << endl;
  } else if (n <= 999) {
    cout << n - 90 << endl;
  } else if (n <= 9999) {
    cout << 909 << endl;
  } else if (n <= 99999) {
    cout << n - 9090 << endl;
  } else if (n <= 999999) {
    cout << 90909 << endl;
  } else if (n <= 9999999) {
    cout << n - 909090 << endl;
  }
  return 0;
}


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

int main() {
    string s;
    int ans = 700;
    cin >> s;
    for (int tmp = 0; tmp < (int)s.size(); tmp++){
        if (s[tmp] == 'o'){
            ans += 100;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (ll i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << (x) << endl
#define debug2(x, y) cerr << #x << ": " << (x) << " " << #y << ": " << y << endl;
#define int long long
using namespace std;
using II = pair<int, int>;
using VII = vector<II>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { int n = d.size(); REP (i, n) s << d[i] << " "; return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& dd) { for (vector<T> d: dd) s << d << endl; return s; }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
const int MOD = 1e9 + 7;
signed main() {
  int N = in();
  VII a(N);
  REP (i, N) {
    a[i] = {in(), i};
  }
  sort(ALL(a));
  set<int> s;
  s.insert(-1);
  s.insert(N);
  int ans = 0;
  REP (i, N) {
    int idx = a[i].se;
    auto r = s.upper_bound(idx);
    auto l = prev(r);
    ans += (idx - *l) * (*r - idx) * a[i].fi;
    s.insert(idx);
  }
  cout << ans << endl;
}


Measured memory_bytes: 12800
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
int main(){
	std::ios::sync_with_stdio(false);
	int a[5],b,i,c;
	rep(i,3)
	cin>>a[i];
	sort(a,a+3);
	cout<<a[0]+a[1]<<endl;

} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

const ll INF = 1LL << 60;

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

  ll g = a[0];
  rep(i, n) g = gcd(g,a[i]);

  if(k%g == 0 && k <= amax) std::cout << "POSSIBLE" << '\n';
  else std::cout << "IMPOSSIBLE" << '\n';
}


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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
#define fileio freopen("template.in", "r", stdin), freopen("template.out", "w", stdout);
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    fastio;
    //fileio;

    string s, t;
    cin >> s >> t;
    int answer = 0;
    FOR(i, 0, s.size()) {
        if (s[i] != t[i]) {
            answer++;
        }
    }
    cout << answer << "\n";
    return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end()
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;

int main() {
	int a, b, c; CI a >> b >> c;
	CO(a - b) % c EN;
}

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

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

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(3e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n)cin >> a[i];
    int i=1, cnt=0, f=0;
    while(i<n){
        if (a[i-1]<a[i]){
            if(f<0){
                cnt++;
                f = 0;
            }
            else f = 1;
        }
        else if (a[i-1]>a[i]){
            if(f>0){
                cnt++;
                f = 0;
            }
            else f = -1;
        }
        i++;
    }
    cout << cnt+1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int a[maxn], pos[maxn];
ll fac[maxn], inv[maxn], facinv[maxn], bin[maxn];
void pre()
{
	fac[0] = 1; for(int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod;
	inv[1] = 1; for(int i = 2; i < maxn; ++i) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	facinv[0] = 1; for(int i = 1; i < maxn; ++i) facinv[i] = facinv[i - 1] * inv[i] % mod;
	bin[0] = 1; for(int i = 1; i < maxn; ++i) bin[i] = bin[i - 1] * 2 % mod;
}
ll C(int n, int m) { return (n < m || m < 0) ? 0 : fac[n] * facinv[m] % mod * facinv[n - m] % mod;}
int main()
{
	pre();
	int n, l, r;
	scanf("%d", &n);
	for(int i = 1; i <= n + 1; ++i)
	{
		scanf("%d", &a[i]);
		if(pos[a[i]])
		{
			l = pos[a[i]];
			r = i;
		}
		pos[a[i]] = i;
	}
	for(int k = 1; k <= n + 1; ++k)
	{
		ll ret = C(n + 1, k) - C(n - r + l, k - 1);
		ret = (ret % mod + mod) % mod;
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 7544