akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int res, a, b, c, x;
int main(void){
    // Your code here!
    cin >> a >> b >> c >> x;
    res = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (x == 500 * i + 100 * j + 50 * k) res++;
            }
        }
    }
    cout << res << endl;
}


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

int a,b,c,k;
int main()
{
	cin>>a>>b>>c>>k;
	while(b<=a)
	{
		b<<=1;
		k--;
	}
	while(c<=b)
	{
		c<<=1;
		k--;
	}
	if(k>=0) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3648
//

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define YN(flag) (flag?"Yes":"No")
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    string s;int k;cin>>s>>k;
    set<string>a;
    int n=s.size();
    rep(i,0,n){
        rep(j,1,min(k+1,n-i+1)){
            a.insert(s.substr(i,j));
        }
    }
    int t=0;
    for(auto i:a){
        t++;
        if(t==k){cout<<i<<nnn;return 0;}
    }
    return 0;
}

Measured memory_bytes: 4772
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;



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

	int n;
	cin >> n;
	vector<ll> l(n);
	rep(i, n)
	{
		cin >> l[i];
	}
	ll ans = 0;

	for (int i = 0; i < n - 2; i++)
	{
		for (int j = i + 1; j < n - 1; j++)
		{
			for (int k = j + 1; k < n; k++)
			{
				if (l[i] != l[j] && l[i] != l[k] && l[j] != l[k])
				{
					if (l[i] + l[j] + l[k] - max(l[i], max(l[j], l[k])) > max(l[i], max(l[j], l[k])))
						ans++;
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3656
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    A = LI_()

    ord = [-1]*N

    city = 0
    cnt = 0
    teleport_path = []
    while ord[city]==-1:
        ord[city] = cnt
        teleport_path.append(city)
        city = A[city]
        cnt += 1
    loop_head = ord[city]
    loop_length = len(teleport_path) - loop_head
    # print(teleport_path, loop_head, loop_length)

    if K-1<loop_head:
        print(teleport_path[K]+1)
    else:
        K = loop_head + (K-loop_head)%loop_length
        print(teleport_path[K]+1)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 33440
#include <stdio.h>
int main(void){
    int W, H, N;
    scanf("%d %d %d", &W, &H, &N);
    int x[N], y[N], a[N];
    for (int i=0; i<N; i++) scanf("%d%d%d", &x[i], &y[i], &a[i]);
    int x1=0, x2=W, y1=0, y2=H;
    for(int i=0; i<N; i++){
        if(a[i]==1 && x[i]>x1) x1 = x[i];
        else if(a[i]==2 && x[i]<x2) x2 = x[i];
        else if(a[i]==3 && y[i]>y1) y1=y[i];
        else if(a[i]==4 && y[i]<y2) y2 = y[i];
    }
    if((x2-x1)<=0||(y2-y1)<=0) printf("%d", 0);
    else printf("%d",(x2-x1)*(y2-y1));
    return 0;
}

Measured memory_bytes: 1736
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class A
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var AB = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (A, B) = (AB[0], AB[1]);
            if (A == 1) A += 13;
            if (B == 1) B += 13;
            var answer = "Draw";
            if (A > B) answer = "Alice";
            if (A < B) answer = "Bob";
            Console.WriteLine(answer);
        }
    }
}


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

int bu[100010];
int main() {
	int N; cin >> N;
	for(int i=0; i<N; ++i){
	    int a;
	    cin >> a;
	    bu[a]++;
	}
	int eat=0;
	for(int i=1; i<=100000; ++i){
	    if(bu[i]>1) eat += bu[i]-1;
	}
	eat=(eat+1)/2;
	cout << N-eat*2 << endl;
	return 0;
}


Measured memory_bytes: 640
N = int(input())
lis = [0] * N
for i in range(N):
    P = int(input())
    P -= 1
    lis[P] = i
ans = 1
cnt = 1
for i in range(1,N):
    if lis[i] < lis[i-1]:
        cnt = 0
    cnt += 1
    ans = max(ans,cnt)
print(N-ans)


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

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

     ll a=0,b;
     for(ll i =1; i*i<=n; ++i){
        if(n%i==0){
          a = max (a,i);
          b = n/a; 
        }
     }
     int ans = 1;
     for(int i =1 ;; i++){
       if (b<10) {cout <<1 << endl;
                  return 0;}
       else if(b>=10){
       b/=10;
       ans++;}
       if(b<10) break;
     }
     cout << ans <<endl;
 }

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

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int X = 1<<N;
    vector<int> A(2*X);
    for(int i=0; i<X; i++){
        cin >> A[i];
        A[i+X] = A[i];
    }
    
    auto winner = [&](int x, int y){
        if(x > y) swap(x, y);
        return S[y-x-1] == '0' ? x : y;
    };
    static int dp[19][1<<19];
    for(int i=0; i<2*X; i++) dp[0][i] = A[i];
    for(int k=0; k<N; k++) for(int i=0; i+(1<<k)<2*X; i++) dp[k+1][i] = winner(dp[k][i], dp[k][i+(1<<k)]);
    for(int i=0; i<X; i++) printf("%d\n", dp[N][i]);
    return 0;
}



Measured memory_bytes: 43408
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
int main(){
    int n,c,k;cin>>n>>c>>k;
    int arr[n];
    if(c==1){
        cout << n;return 0;
    } 
    fo(j,n){
        cin >> arr[j];
    }  
    sort(arr,arr+n);
    int cnt =0,i=0;
    while(i<n){
        if(i==n-1){
            ++cnt;
            cout << cnt;return 0;
        }
        else if(arr[i+1]-arr[i]<=k){
            for(int j = i+1;j<n;++j){
                if((arr[j]-arr[i]<=k)&&(j-i+1)<c){
                    if(j==n-1){
                        ++cnt;
                        cout << cnt;return 0;
                    }
                }
                else if(j-i+1==c&&(arr[j]-arr[i]<=k)){
                    ++cnt;i=j+1;j=n;             
                }
                else if(arr[j]-arr[i]>k){
                    ++cnt;i=j;
                }
            }
        }
        else{
            ++cnt;++i;
        }     
    }
    cout <<cnt;
}

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

long long pow(long long a, long long n) {
    if (n == 0) return 1;
    
    if (n == 1) return a;
    
    if (n % 2 == 0) {
        long long half = pow(a, n / 2);
        return half * half;
    }
    else return pow(a, 1) * pow(a, n - 1);
}

int main() {
    int n;
    cin >> n;
    int f[n][5][2];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            for (int k = 0; k < 2; k++)
            {
                cin >> f[i][j][k];
            }
        }        
    }
    
    int p[n][11];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 11; j++)
        {
            cin >> p[i][j];
        }
    }
    
    int ans = -1000000000;
    for (int bit = 0; bit < pow(2, 10); bit++)
    {
        int c = 0;
        for (int i = 0; i < 10; i++) if (bit&(1<<i)) c++;
        if (c == 0) continue;
        
        int sum = 0;
        for (int i = 0; i < n; i++)
        {
            int cnt = 0;
            for (int j = 0; j < 5; j++)
            {
                for (int k = 0; k < 2; k++)
                {
                    if (bit&(1<<(j * 2 + k)) && f[i][j][k]) cnt++;
                }
            }
            sum += p[i][cnt];
        }
        ans = max(ans, sum);
    }
    
    cout << ans << endl;
}


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

using namespace std;

struct Vector {
  double x, y;
  Vector() {}
  Vector(double x, double y): x(x), y(y) {}
  Vector operator+(Vector v) { return Vector(x + v.x, y + v.y); }
  Vector operator-(Vector v) { return Vector(x - v.x, y - v.y); }
  Vector operator*(double k) { return Vector(x * k, y * k); }
  Vector operator/(double k) { return Vector(x / k, y / k); }
  bool operator==(Vector v)  { return abs(x - v.x) < 1e-10 && abs(y - v.y) < 1e-10; }
  friend void input(Vector &v) { cin >> v.x >> v.y; }
  friend double norm(Vector v) { return dot(v, v); }
  friend double  abs(Vector v) { return sqrt(norm(v)); }
  friend double   dot(Vector v1, Vector v2) { return v1.x * v2.x + v1.y * v2.y; }
  friend double cross(Vector v1, Vector v2) { return v1.x * v2.y - v1.y * v2.x; }
  friend void show(Vector v) { if (abs(v.x) < 1e-10) v.x = 0.0; if (abs(v.y) < 1e-10) v.y = 0.0; printf("%.10f %.10f\n", v.x, v.y); }
  friend bool ccw(Vector v, Vector v1, Vector v2) { return cross(v1 - v, v2 - v) > 1e-10; }
  friend bool  cw(Vector v, Vector v1, Vector v2) { return cross(v1 - v, v2 - v) < -1e-10; }
  friend bool parallel(Vector v1, Vector v2) { return abs(cross(v1, v2)) < 1e-10; }
  friend bool onLine(Vector v, Vector v1, Vector v2) { return v == v1 || v == v2 || (parallel(v1 - v, v2 - v) && dot(v1 - v, v2 - v) < -1e-10); }
  friend int direct(Vector v1, Vector v2, Vector v) { if (ccw(v1, v2, v)) return  1; if (cw(v1, v2, v)) return -1; if (dot(v2 - v1, v - v1) < -1e-10) return  2; if (dot(v1 - v2, v - v2) < -1e-10) return -2; return 0; }
};
typedef Vector Point;

struct Circle {
  Point c;
  double r;
  Circle() {}
  Circle(Point c, double r): c(c), r(r) {}
  friend void input(Circle &c) { cin >> c.c.x >> c.c.y >> c.r; }
  friend int intersect(Circle c1, Circle c2) { if (abs(c1.c - c2.c) - c1.r - c2.r > 1e-10) return 0; if (c1.r - c2.r - abs(c1.c - c2.c) > 1e-10) return 2; if (c2.r - c1.r - abs(c1.c - c2.c) > 1e-10) return -2; return 1; }
};

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

  for (int i = 0; i < n; i++) {
    Circle a, b;
    input(a);
    input(b);
    cout << intersect(a, b) << endl;
  }

  return 0;
}


Measured memory_bytes: 3172
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b == c || a + c == b || b + c == a) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<=(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int dou(int a){
  return a*a;
}

int tri(int a){
  return a*a*a;
}
 
int main(){

  while(1){
	double e;
	cin >> e;
	if(e==0) break;

	int x,y,z;

	int cb = cbrt(e+0.00001);
	
	int m = 1000000;

	REP(i,cb){
	  z = cb - i;
	  int huga = sqrt(e - tri(z)+0.000001);
	  REP(j,huga){
		y = huga - j;
		x = e - tri(z) - dou(y);
		if(m>(x+y+z)) m = x+y+z;
	  }
	}

	cout << m << endl;

	//	cout << z << endl;


  }
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long 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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int n;
	cin >> n;
	vector<int>l(n), r(n);
	int ans = 0;
	rep(i, n) {
		cin >> l[i] >> r[i];
		ans += r[i] - l[i] + 1;
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    int day,hwN;
    cin >> day >> hwN;
    int hwS=0,temp;
    for(int i=0; i<hwN; i++){
        cin >> temp;
        hwS+=temp;
        if (hwS>day) break;
    }
    if (hwS>day) cout << "-1";
    else cout << day-hwS;

    return 0;
}


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

int main() 
{
	int r,g,b;
	scanf("%d %d %d",&r,&g,&b);
	r=r*100+g*10+b;
	if(r%4==0){printf("YES\n");}
	else{printf("NO\n");}
	
}

Measured memory_bytes: 256
ans = Array.new(10**4+1, 0)
(1..100).each{|i|
  (1..100).each{|j|
    (1..100).each{|k|
      wk = i**2 + j**2 + k**2 + i*j + j*k + k*i
      ans[wk] += 1 if wk <= 10**4
    }
  }
}

puts ans[1, gets.to_i]


Measured memory_bytes: 14280
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pll> vec(n);
    rep(i,n){
        int a,b;
        cin >> a >> b;
        if(a < b) swap(a,b);
        vec[i] = pll(a,b);
    }
    ll mx1=0,mx2=0,mn1=INF,mn2=INF;
    rep(i,n){
        cmx(mx1,vec[i].fi),cmx(mx2,vec[i].se);
        cmn(mn1,vec[i].fi),cmn(mn2,vec[i].se);
    }
    ll cand1 = (mx1-mn1)*(mx2-mn2);
    ll mlen = mx1-mn2;
    priority_queue<P> que;
    ll mx,mn=INF;
    rep(i,n){
        cmn(mn,vec[i].fi);
        que.push(P(vec[i].fi,vec[i].se));
    }
    while(!que.empty()){
        P p = que.top();
        mx = p.fi;
        cmn(cand1,mlen*(mx-mn));
        que.pop();
        if(p.se < 0){
            break;
        }
        cmn(mn,(ll)p.se);
        que.push(P(p.se,-1));
    }
    cout << cand1 << "\n";
    return 0;
}


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

const int N = 10;
char s[N + 1];
char t[N + 2];

int main() 
{
	scanf("%s%s", s, t);
	int n = strlen(s);
	t[n] = 0;
	if (!strcmp(s, t)) printf("Yes\n");
	else printf("No\n");
	return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> V(N);
    for(int i = 0; i < N; i++){
        cin >> V.at(i);
    }
    //入力終了
    int c = 0 , a = 0; //c = 偶数カウント a = 条件カウント
    for(int i = 0; i < N; i++){
        if(V.at(i) % 2 == 0){
            c = c + 1;
            if(V.at(i) % 3 == 0 || V.at(i) % 5 == 0){
                a = a + 1;
            }
        }
    }
    if(c == a){
        cout << "APPROVED" << endl;
    }
    else{
        cout << "DENIED" << endl;
    }
}

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

li = [input() for _ in range(n)]

check = ['AC', 'WA', 'TLE', 'RE']
ans = [0] * 4

for i in li:
    for j in range(4):
        if i == check[j]:
            ans[j] += 1
            
for i in range(4):
    print(check[i] + ' x ' + str(ans[i]))

Measured memory_bytes: 16192
A,B,C,X = [int(input()) for i in range(4)]
X_original = X
n = 0

for i in range(int(A)+1):
    X = X_original
    X500 = X - i*500
    for j in range(int(B)+1):
        X100 = X500 - j*100
        for k in range(int(C)+1):
            X50 = X100-k*50
            if X50== 0:
                n += 1

print(n)

Measured memory_bytes: 9164
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int icicles[100005];
int n, l;

int life (int i )
{
	int res = l - icicles[i];
	
	// i 番目のつららが一番大きい
	if (icicles[i-1] < icicles[i] && icicles[i] > icicles[i+1] ){
		return res;
	}else	// 前のつららが大きく、後ろのつららが小さい
	if (icicles[i-1] > icicles[i] && icicles[i] > icicles[i+1] ){
		return life (i-1) + res;
	}else	// 前のつららが小さく、後ろのつららが大きい
	if (icicles[i-1] < icicles[i] && icicles[i] < icicles[i+1] ){
		return life (i+1) + res;
	}else{	// i 番目のつららが一番小さい
		return max (life (i-1), life (i+1) ) + res;
	} // end if
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.icicles4", "r", stdin );
	while (scanf ("%d %d", &n, &l ) != EOF ){
		memset (icicles, 0, sizeof (icicles ) );
		for (int i = 1; i <= n; i++ ){
			scanf ("%d", &icicles[i] );
		} // end rep
		
		int res = 0;
		for (int i = 1; i <= n; i++ ){
			int curr = life (i );
			res = max (res, curr );
		} // end for
		printf ("%d\n", res );

	} // end loop
		
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i,n) cin >> d[i];
	int ans=0;
	rep(i,n){
		for(int j=i+1; j<n; j++){
			ans += d[i]*d[j];
		}
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll A, B, M;
ll a[100010], b[100010];
ll mi = INF;
std::vector<P> cost[100010];

int main()
{
  std::cin >> A >> B >> M;

  rep( i, A )
    std::cin >> a[i];

  rep( i, B )
    std::cin >> b[i], chmin( mi, b[i] );

  rep( i, M ) {
    ll x, y, c;
    std::cin >> x >> y >> c;
    --x; --y;
    cost[x].emplace_back( y, c );
  }

  ll ans = INF;

  rep( i, A ) {
    chmin( ans, a[i]+mi );

    for( auto p : cost[i] )
     chmin( ans, a[i]+b[p.first]-p.second );
  }

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

  return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

ll oddSolve(ll x) {return ((x+1) / 2) % 2;}

ll solve(ll x){
    if (x % 2 == 1) return oddSolve(x);
    else return oddSolve(x+1) ^ (x+1);
}

int main(){
    ll a, b;
    cin >> a >> b;
    cout << (solve(b) ^ solve(a-1)) << endl;
    return 0;
}

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

int main() {
	while (1) {
		double n;
		cin >> n;
		if (n < 0)
			break;

		int in = (int)n;
		double dou;
		for (dou = n; dou >= 1; dou--);

		double ans=0;
		for (int i = 0; i < 8; i++) {
			ans += (in % 2)*pow(10, i);
			in /= 2;

			
			if (i < 4) {
				int doub = dou * 2;
				ans += doub * pow(10, -i - 1);
				if (doub == 1)
					dou = dou * 2 - 1;
				else
					dou *= 2;
			}
		}
		if (in > 0 || dou != 0)
			cout << "NA" << endl;
		else {
			for (int i = 0;; i++) {
				if (ans - pow(10, i) < pow(10, i)) {
					for (int j = 0; j < 7 - i; j++)
						cout << 0;
					break;
				}
			}
			cout << fixed;
			cout << setprecision(4) << ans << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3280
#include <cstdio>
#include <vector>
typedef std::vector<int> vin;
const int INFN = 1e9+7;
const int MAXN = 2e5+5;
int A[MAXN];
vin G[MAXN];
int L[MAXN];      // LIS stack
int up[MAXN];     // DFS parent
int N;

int ret[MAXN];

void dfs(int u) {
  int pos = std::lower_bound(L, L + N, A[u]) - L;
  int save = L[pos];
  L[pos] = A[u];
  
  ret[u]  = std::lower_bound(L, L + N, INFN) - L;
  for (int v: G[u]) {
    if (v != up[u]) {
      up[v] = u;
      dfs(v);
    }
  }
  L[pos] = save;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
  }
  for (int i = 1; i < N; ++i) {
    int u, v;
    scanf(" %d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 0; i < N; ++i) {
    L[i] = INFN;
  }
  up[1] = 1;
  dfs(1);
  for (int i = 1; i <= N; ++i) {
    printf("%d\n", ret[i]);
  }
  return 0;
}

Measured memory_bytes: 28788
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
ll n,m;
cin >>n>>m;
ll a[n],b,c,sum=0;
vector <pair<ll,ll>> p;
for(ll i=0;i<n;i++) {
  cin >>a[i];
}
for(ll i=0;i<m;i++) {
  cin >>b>>c;
  p.push_back(make_pair(c,b));
}
sort(a,a+n);
sort(p.begin(),p.end());
reverse(p.begin(),p.end());
ll k=0;
for(ll i=0;i<m;i++){
  ll ps=p[i].second;
  for(ll j=0;j<ps;j++){
  if(k==n) break;
  sum+=max(a[k],p[i].first);
  k++;
  }
}
for(ll i=k;i<n;i++) sum+=a[i];
cout <<sum<<endl;
}


Measured memory_bytes: 3188
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var moji = Console.ReadLine().Trim();
            if (moji == "0") goto end;
            var result = 0;
            for (int i = 0; i < moji.Length; i++)
            {
                result += int.Parse(moji[i].ToString());
            }
            Console.WriteLine(result);
            result = 0;
        }
    end:;
    }
}


Measured memory_bytes: 17912
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);


// ===

fn main() {
    let n: usize = read();
    let a: Vec<i32> = readnc();

    let mut sum = 0;
    for i in a {
        sum += i-1;
    }
    println!("{}", sum);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long ll;

void dump(const map<int, int> &M)
{
    for (auto p : M)
    {
        cerr << p.first << ":" << p.second << endl;
    }
}

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

    int N;
    cin >> N;

    map<int, int> M;
    ll sum = 0;
    rep(i, N)
    {
        int A;
        cin >> A;
        M[A]++;
        sum += A;
    }

    int Q;
    cin >> Q;
    rep(i, Q)
    {
        int B, C;
        cin >> B >> C;
        M[C] += M[B];
        sum -= ((ll)B * M[B]);
        sum += ((ll)C * M[B]);
        M[B] = 0;
        cout << sum << endl;
    }
}


Measured memory_bytes: 7480
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

using namespace std;

#define lint long long
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF (int)(1e9+10)
#define LLINF (lint)(1e18+10)

int main(){
    lint h, w, n;
    cin >> h >> w >> n;
    lint ans[10] = {0};
    set< pair<lint, lint> > st;
    map< pair<lint, lint>, lint > mp;
    lint dx[] = {-2, -1, 0, -2, -1, 0, -2, -1, 0}, dy[] = {-2, -2, -2, -1, -1, -1, 0, 0, 0};
    rep(i, n){
        lint a, b;
        cin >> a >> b;
        rep(j, 9){
            if(a+dy[j] >= 1 && a+dy[j] <= h-2 && b+dx[j] >= 1 && b+dx[j] <= w-2){
                pair<lint, lint> tmp = make_pair(a+dy[j], b+dx[j]);
                st.insert(tmp);
                mp[tmp]++;
            }
        }
    }
    auto itr = st.begin(), last = st.end();
    while(itr != last){
        ans[mp[*itr]]++;
        itr++;
    }
    ans[0] = (h-2) * (w-2) - (lint)(st.size());
    rep(i, 10){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 112768
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

long long gcd(long long x,long long y){
	if(y == 0)	return x;
	else		return gcd(y,x%y);
}

main(){
	long long a,b,k;
	bool x;
	vector<int> v,l;
	cin>>a>>b;
	k = gcd(max(a,b),min(a,b));
	
	v.push_back(1);

	for(int i=2;i<=sqrt(k);i++){
		if(k%i != 0)	continue;
		l.push_back(i);
		x = true;
		for(int j=1;j<v.size();j++){
			if(i%v[j] == 0){
				x = false;
				break;
			}
		}
		if(x)
			v.push_back(i);
	}
	for(int i=l.size()-1;i>=0;i--){
		if(k/l[i] == l[i])	continue;
		x = true;
		for(int j=1;j<v.size();j++){
			if((k/l[i])%v[j] == 0){
				x = false;
				break;
			}
		}
		if(x)
			v.push_back(k/l[i]);
	}
	x = true;
	for(int i=1;i<v.size();i++)
		if(k%i == 0){
			x = false;
			break;
		}
	if(x && k!=1)
		v.push_back(k);
	cout<<v.size()<<endl;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
  input!{n: i32};
  println!("{}", match n % 10 {
    2 | 4 | 5 | 7 | 9 => "hon",
    0 | 1 | 6 | 8 => "pon",
    3 => "bon",
    _ => panic!()
  });
}

Measured memory_bytes: 2144
n, m = map(int, input().split())

max_l = 1
min_r = n
for i in range(m):
  l, r = map(int, input().split())
  max_l = max(max_l, l)
  min_r = min(min_r, r)
  
ans = min_r - max_l + 1
if ans < 0:
  ans = 0
  
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
using Graph = vector<vector<int>>;
Graph G;

int main(){
    int k, t; cin >> k >> t;
    vector<int> a(t);
    rep(i, t) cin >> a[i];
    int sum = 0;
    int MAX = 0;
    rep(i, t){
        sum += a[i];
        MAX = max(a[i], MAX);
    }
    int dif = sum - MAX;
    cout << max(MAX - dif - 1, 0) << endl;
}

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

const int END = -1;
struct StNod
{
  int m_nParnt;
  int m_nLeft;
  int m_nRigt;

  StNod() :
     m_nParnt(END), m_nLeft(END), m_nRigt(END)
  { }
};

enum EnDir
{
  D_Left,
  D_Right,
};

void fnInput(vector<int> &rvnPodr, vector<int> &rvnIodrSeq)
{
  int nMaxSiz;

  cin >> nMaxSiz;
  rvnPodr.resize(nMaxSiz);
  rvnIodrSeq.resize(nMaxSiz + 1);

  for (int i = 0; i < nMaxSiz; i++)
    cin >> rvnPodr[i];

  int nNode;
  for (int i = 1; i < nMaxSiz + 1; i++)
  {
    cin >> nNode;
    rvnIodrSeq[nNode] = i;
  }
}

void fnStructTree(const vector<int> &cnrvnPodr, const vector<int> &cnrvnIodrSeq, vector<StNod> &rvoNod)
{
  for (int i = 1; i < cnrvnPodr.size(); i++)
  {
    int nParnt = END;
    int nx = cnrvnPodr[0];
    EnDir enDir;
    while (nx != END)
    {
      nParnt = nx;
      if (cnrvnIodrSeq[ cnrvnPodr[i] ] < cnrvnIodrSeq[nx])
      {
        nx = rvoNod[nx].m_nLeft;
        enDir = D_Left;
      }
      else
      {
        nx = rvoNod[nx].m_nRigt;
        enDir = D_Right;
      }
    }

    rvoNod[ cnrvnPodr[i] ].m_nParnt = nParnt;
    if (enDir == D_Left)
      rvoNod[nParnt].m_nLeft = cnrvnPodr[i];
    else
      rvoNod[nParnt].m_nRigt = cnrvnPodr[i];
  }
}

void fnPostOrder(const vector<StNod> &cnrvoNod, int nx)
{
  static int stnPrt = 0;
  if (nx == END)  return;

  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nLeft);
  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nRigt);

  if (stnPrt++) cout << " ";
  cout << nx;
}

void fnResult(const vector<StNod> &cnrvoNod)
{
  int nx = 1;
  while (cnrvoNod[nx].m_nParnt != END)
    nx = cnrvoNod[nx].m_nParnt;

  fnPostOrder(cnrvoNod, nx);
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnPodr, vnIodrSeq;
  fnInput(vnPodr, vnIodrSeq);

  StNod oNod;
  vector<StNod> voNod(vnIodrSeq.size(), oNod);
  fnStructTree(vnPodr, vnIodrSeq, voNod);
  
  fnResult(voNod);
  return 0;
}

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

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i,a,b) for(int i=a; i<b; i++)
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define mod 1000000007

template<typename T>
T fastexpo(T x, T y)
{
	T res = 1;
	while(y > 0)
	{
		if(y&1) res *= x;
		x *= x;
		y >>= 1;
	}
	return res;
}

template<typename T>
T modpower(T x, T y, T m=mod)
{
	x %= m;
	T res = 1;
	while(y > 0)
	{
		if(y&1) res = (res*x)%m;
		x = (x*x)%m;
		y >>= 1;
	}
	return res;
}


int main()
{
	FASTIO
	string s, ans;
	cin >> s;
	ans = (s == "ABC")  ? "ARC" : "ABC";
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3664
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
vector<LL> G[5005];
const LL MOD=1000000007;
LL g[5005],n,dp[5005][5005],sizen[5005],f[5005];
void dfs(LL now,LL pre)
{
	sizen[now]=1;
	dp[now][1]=1;
	for(unsigned int i=0;i<G[now].size();++i)
	{
		LL to=G[now][i];
		if(to==pre)	continue;
		dfs(to,now);
		memset(f,0,sizeof f);
		for(LL i=1;i<=sizen[now];++i)	for(LL j=0;j<=sizen[to];++j)	f[i+j]+=dp[now][i]*dp[to][j]%MOD,f[i+j]%=MOD;
		memcpy(dp[now],f,sizeof f);
		sizen[now]+=sizen[to];
	}
	for(LL i=2;i<=sizen[now];i+=2)	dp[now][0]+=MOD-dp[now][i]*g[i]%MOD,dp[now][0]%=MOD;
}
int main(){
	g[0]=1;
	scanf("%lld",&*&n);
	for(LL i=2;i<=n;i+=2)	g[i]=g[i-2]*(i-1)%MOD;
	for(LL i=1;i<n;++i)
	{
		LL u,v;
		scanf("%lld %lld",&*&u,&*&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1,0);
	printf("%lld",MOD-dp[1][0]);
	return 0;
}

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

int main()
{
  string s;
  cin >> s;
  long long int i,sum=0;
  for(i=0;i<s.length();i++)
  {
    sum += s[i]-'0';
  }
  	if(sum%9==0 || sum==0)
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
  return 0;
 }
  

Measured memory_bytes: 3692
from collections import deque
import math
N,M=map(int,input().split())
"""
BFSする。探索される側をメモ。
"""
dist = [-1 for i in range(N)]
graph = [[] for i in range(N+1)]
for i in range(M):
  A,B=map(int,input().split())
  graph[A].append(B)
  graph[B].append(A)
  
#print(dist, graph)

# init
ans = [-1]*(N+1)
q = deque()
q.append(1)
while len(q)>0:
  #print(q,dist)
  node = q.popleft()
  for j in graph[node]:
    if ans[j] == -1:
      ans[j]=node
      q.append(j)
print("Yes")
print("\n".join(list(map(str,ans[2:]))))

Measured memory_bytes: 42380
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, m, h, r;
vector<P> p1, p2;
bool used[110];

int main(){
	while (cin >> n&&n){
		fill(used, used + 110, 0);
		REP(i, n){
			cin >> h >> r;
			p1.push_back(P(h, r));
		}
		p1.push_back(P(INF, INF));
		cin >> m;
		REP(i, m){
			cin >> h >> r;
			p2.push_back(P(h, r));
		}
		sort(ALL(p1));
		sort(ALL(p2));
		int ans = n;
		int nowh = -1, nowr = -1;
		REP(i, p1.size()){
			REP(j, m){
				//cout << used[i] << " ";
				if (used[j] == 0){
					if (nowh < p2[j].first&&p2[j].first < p1[i].first&&
						nowr < p2[j].second&&p2[j].second < p1[i].second){
						ans++;
					}
					else if (p1[i].first <= p2[j].first || p1[i].second <= p2[j].second){
						nowh = p1[i].first, nowr = p1[i].second;
						break;
					}
					used[j] = 1;
				}
			}
			//cout << endl;
		}
		if (ans < max(m, n))cout << max(m, n) << endl;
		else cout << ans << endl;
		p1.clear();
		p2.clear();
	}
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long int ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
////////////////////////////////////////////////////////////////////
int main()
{
    string S;
    cin >> S;

    ll cnt=0;
    REP(i,S.size()){
        if (S[i] == 'o') cnt++;
    }
    //cout << S.size() << endl;
    int remain=15-S.size();

    if(cnt+remain>=8) cout << "YES";
    else cout << "NO" << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    long N = 1_000_000_007L;
    Scanner scanner = new Scanner(System.in);
    String str = scanner.next();

    long[][] d = new long[str.length() + 1][4];
    d[0][0] = 1;
    for (int i = 1; i <= str.length(); i++) {
      char ch = str.charAt(i - 1);

      int n = ch == '?' ? 3 : 1;
      int a = 0, b = 0, c = 0;
      if (ch == 'A' || ch == '?') a = 1;
      if (ch == 'B' || ch == '?') b = 1;
      if (ch == 'C' || ch == '?') c = 1;
      d[i][0] = d[i - 1][0] * n % N;
      d[i][1] = d[i - 1][1] * n % N + a * d[i - 1][0];
      d[i][2] = d[i - 1][2] * n % N + b * d[i - 1][1];
      d[i][3] = d[i - 1][3] * n % N + c * d[i - 1][2];

      for (int j = 0; j < 4; j++) d[i][j] %= N;
    }

    System.out.println(d[str.length()][3]);
  }
}


Measured memory_bytes: 30308
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())

using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<VB> VVB;

int main(void){
	long N,K;
	cin >> N >> K;

	VI a(N);
	long tmp;

	REP(i,N) cin >> a[i];

	VVB dpl(N+1,VB(K+1,false)),dpr(N+1,VB(K+1,false));
	dpl[0][0] = true;
	dpr[0][0] = true;

	FOR(i,1,N+1){
		REP(k,K+1) {
			if (k - a[i-1] >= 0) dpl[i][k] = (dpl[i-1][k] || dpl[i-1][k-a[i-1]]);
			else dpl[i][k] = dpl[i-1][k];
			if (k - a[N-i] >= 0) dpr[i][k] = (dpr[i-1][k] || dpr[i-1][k-a[N-i]]);
			else dpr[i][k] = dpr[i-1][k];
		}
	}

	//dump2d_arr(dpl);
	//dump2d_arr(dpr);

	long ans = N;
	bool flg;

	FOR(i,1,N+1){
		if (a[i-1] >= K) {
			ans --;
			continue;
		}

		flg = false;
		FOR(j,1,a[i-1]+1){
			if (flg) break;
			REP(k,K-j+1){
				if (i == 1) {
					if (dpr[N-1][K-j]) {
						ans--;	
						flg = true;
						break;
					}
				}

				else if (i == (N)) {
					if (dpl[N-1][K-j]) {
						ans--;
						flg = true;
						break;
					}
				}

				else if (dpl[i-1][k] && dpr[N-i][K-k-j]){
					ans --;
					flg = true;
					break;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

inline void mazak(int *a, int *b, int *c){
	*a = *a+*b+*c;
}

int main(){
	
	int a,b,c ;
	cin>>a>>b>>c;
	mazak(&a,&b,&c);
	if(a>=22)
		cout<<"bust";
	else
		cout<<"win";
}

Measured memory_bytes: 256
#include <cstdio>

#define N 100005

typedef long long ll;

int parents[N];

int find(int x){
        if (x == parents[x]) return x;
        else return find(parents[x]);
}

int main(){
        int n, q;
        while(~scanf("%d %d", &n, &q)){
                if (n == 0 && q == 0) break;
                for (int i = 2; i <= n; i++){
                        scanf("%d", &parents[i]);
                }
                parents[1] = 1;
                ll sum = 0;
                char c;
                int x;
                for (int i = 0; i < q; i++){
                        getchar();
                        scanf("%c %d", &c, &x);
                        if (c == 'Q') sum += find(x);
                        else parents[x] = x;
                }
                printf("%lld\n", sum);
        }
        return 0;
}

Measured memory_bytes: 3016
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////
#define R(i,n) for(int i=0;i<(n);++i)
/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int N;
	cin >> N;
	vector<int>D(N);
	IN(D);
	int ans = 0;
	R(i, N)for (int j = i + 1; j < N; ++j) {
		ans += D[i] * D[j];
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <map>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)	
using namespace std;
int n,a,b;
int main()
{
    fast; 
	cin>>n>>a>>b;
	cout<<min(a,b)<<' '<<max(0,a+b-n)<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
v = [int(i) for i in input().split()]

numList = [[0, i] for i in range(10**5+1)]
numList2 = [[0, i] for i in range(10**5+1)]

for i in range(n):
    if i % 2 == 1:
        numList[v[i]][0] += 1
    else:
        numList2[v[i]][0] += 1

numList = list(reversed(sorted(numList)))
numList2 = list(reversed(sorted(numList2)))

if numList[0][1] == numList2[0][1]:
    print(n - max(numList[0][0] + numList2[1][0],numList[1][0] + numList2[0][0]))
else:
    print(n - numList[0][0] - numList2[0][0])


Measured memory_bytes: 36216
H,W=map(int,input().split())
L=[[0 for i in range(W)] for j in range(H)]
for i in range(H):
  L1=list(input())
  L[i]=L1
L = [["."] + i + ["."] for i in L]
L = [["." for i in range(W+2)]] + L + [["." for i in range(W+2)]]
for i in range(H+2):
  for j in range(W+2):
    if L[i][j]=="#":
      if L[i][j+1]==L[i][j-1]==L[i+1][j]==L[i-1][j]==".":
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 9204
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#define MIN 1<<31-1
#define HMAX 1000000000000000000
#define MOD 1000000007
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RSET(s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
typedef long long int ll;
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int mi=MIN;
	for(int i=0;i<n;i++)
	{
		int w;cin>>w;
		mi=min(mi,w);
		k-=w;
	}
	cout<<n+k/mi;
}

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

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;

bool custom1 (pii a, pii b) {
  return a.first < b.first;
}

bool custom2 (pii a, pii b) {
  return a.second < b.second;
}

const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vvi fl(10, vi(10));

  for(int i=1;i<=n;i++) {
    string s = to_string(i);
    int f = s[0] - '0';
    int l = s[s.size()-1] - '0';

    fl[f][l]++;
  }

  long long int ans = 0;

  for(int i=1;i<=9;i++) {
    for(int j=1;j<=9;j++) {
      ans += fl[i][j] * fl[j][i];
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256