akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

string s[1010];

int len[62],n;
char id[62];

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline void build(int o,int l,int r)
{
	if (l==r) { s[o]=string(len[l],id[l]);return; }
	int mid=(l+r)>>1;
	build(o<<1,l,mid);build(o<<1|1,mid+1,r);
	string res;int now=0;
	for (int i=0;i<s[o<<1|1].length();i++)
	{
		while (now<s[o<<1].length())
		{
			string str=res;str.push_back(s[o<<1|1][i]);
			str=str+s[o<<1].substr(now,s[o<<1].length()-now);
			cout<<"? "<<str<<endl;
			fflush(stdout);
			int hh=rd();
			if (s[o<<1].length()+i+1+hh>n) res.push_back(s[o<<1][now++]);
			else break;
		}
		res.push_back(s[o<<1|1][i]);
	} 
	s[o]=res+s[o<<1].substr(now,s[o<<1].length()-now);
}

int main()
{
	for (int i=0;i<26;i++) id[i]='a'+i;
	for (int i=0;i<26;i++) id[26+i]='A'+i;
	for (int i=0;i<10;i++) id[52+i]='0'+i;
	for (int i=0;i<62;i++)
	{
		string now(128,id[i]);
		cout<<"? "<<now<<endl;
		fflush(stdout);
		len[i]=128-rd();n+=len[i];
	}
	build(1,0,61);
	cout<<"! "<<s[1]<<endl;
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3792
a = [list(map(int,input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]

for i in range(3):
    for j in range(3):
        for k in range(N):
            if a[i][j]==b[k]:
                a[i][j]=0

ans = "No"

for i in range(3):
    if a[i][0]+a[i][1]+a[i][2]==0:
        ans = "Yes"
    if a[0][i]+a[1][i]+a[2][i]==0:
        ans = "Yes"

if a[0][0]+a[1][1]+a[2][2]==0 or a[0][2]+a[1][1]+a[2][0]==0:
    ans = "Yes"

print(ans)



Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e10;
const long double PI = (acos(-1));

struct mint {
	int x;
	mint(int x = 0) :x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= MOD)x -= MOD;
		return *this;
	}
	mint & operator-=(const mint a) {
		if ((x += MOD - a.x) >= MOD)x -= MOD;
		return *this;
	}
	mint & operator*=(const mint a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint a)const {
		return mint(*this) += a;
	}
	mint operator-(const mint a)const {
		return mint(*this) -= a;
	}
	mint operator*(const mint a)const {
		return mint(*this) *= a;
	}
	mint pow(int t)const {
		if (!t)return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1)a *= *this;
		return a;
	}

	//for prime mod
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a)const {
		mint res(*this);
		return res /= a;
	}
};
ostream& operator<<(ostream & os, const mint & m) {
	os << m.x;
	return os;
}

mint dp[10005][105][2];
//dp[i][num][sml]
//sml = 0 : 制限あり sml = 1 : 制限なし

signed main() {
	string K;
	int D;
	cin >> K >> D;
	int len = K.size();
	dp[0][0][0] = 1;
	rep(i, len)rep(j, D)rep(k, 2) {
		rep(d, 10) {
			int ni = i + 1, nj = (j + d) % D, nk = k;
			int nd = K[i] - '0';
			if (k == 0) {
				if (d > nd)continue;
				if (d < nd)nk = 1;
			}
			dp[ni][nj][nk] += dp[i][j][k];
		}
	}
	mint ans = dp[len][0][0] + dp[len][0][1] - 1;
	cout << ans << endl;
}

Measured memory_bytes: 16640
#include <iostream>
#include <string>
#include <map>
#include <set>
using namespace std;
#define MAX 100000

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

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



Measured memory_bytes: 3104
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;

int main(){
    int N;
    cin >> N;
    if(N/10 == 9 || N%10 == 9) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
using namespace std;
 
#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);
 
#define csh(a,n) memset(a,n,sizeof(a));
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int p=c%b;
	int count=1;
	for(int i=1;i<=b;i++)
	{
		if(i*a%b==p)
		{
			count=0;
		}
	}
	if(count)
	{
		cout<<"NO"<<endl;
	}
	else{
		cout<<"YES"<<endl;
	}
}

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

using namespace std;


#define min(a,b) ((a<b)?a:b)
#define max(a,b) ((a>b)?a:b)

#define ll long long

const ll INF = 1e18+5;

int main()
{

    int _total,capacity;

    cin>>_total>>capacity;


    int sum_val=0;

    vector<int> val(_total),weight(_total);

    for(int i=0;i<_total;i++)
        {
            cin>>weight[i]>>val[i];
            sum_val+=val[i];

        }


    vector<ll> dp(sum_val+1,INF);//To Store The Minimum weight for that value

    dp[0]=0;    

    for(int i=0;i<_total;i++)
        {

            for(int _val=sum_val;_val>=val[i];_val--)
                dp[_val]=min(dp[_val],dp[_val-val[i]]+weight[i]);

        }

    ll ret=0;

    for(int i=0;i<sum_val+1;i++)
        if(dp[i]<=capacity)
            ret=max(ret,i);



    cout<<ret;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e5+5;
vector<int> edges[MAX];
int dist[MAX];
int in_degree[MAX];
bool visited[MAX]={false};
void dfsUtil(int s){
    visited[s] = true;
    for(auto i : edges[s]){
        dist[i] = max(dist[i],dist[s]+1);
        --in_degree[i];
        if(!in_degree[i])
            dfsUtil(i);
    }
}
int main(int argc, const char** argv) {
    int N,M,i,j,x,y;
    cin>>N>>M;
    for(i=0;i<M;++i){
        cin>>x>>y;
        edges[x].push_back(y);
        ++in_degree[y];
    }
    for(i=1;i<=N;i++)
        if(!visited[i] && in_degree[i]==0)
            dfsUtil(i);
    int answer = 0;
    for(i=0;i<=N;++i)
        answer = max(answer,dist[i]);
    cout<<answer<<endl;
    return 0;
}

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


struct Node {
  int key;
  struct Node *right, *left, *parent;
};

struct Node *root, *NIL;

void insert(int k) {
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z = (struct Node *)malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
     x = x->right;
    }
  }
  
  z->parent = y;
  if(y == NIL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }

}


void inorder (struct Node *u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right); 
}

void preorder(struct Node *u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

	
int main(void){

  int n, i, x;
  char str[32];
 
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%s",str);
    if(strcmp(str,"insert") == 0){
      scanf("%d", &x);
      insert(x);
    }else if(strcmp(str,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
 
return 0;


}


Measured memory_bytes: 25204
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int q = sc.nextInt();
        for(int i=0;i<q;i++){
            String s = sc.next();
            String t = sc.next();
            int DP[][] = new int[s.length()+1][t.length()+1];
            for(int j=0;j<s.length()+1;j++)Arrays.fill(DP[j],0);
            for(int j=1;j<=s.length();j++){
                for(int k=1;k<=t.length();k++){
                    if(s.charAt(j-1)==t.charAt(k-1)) DP[j][k] = Math.max(DP[j][k],DP[j-1][k-1]+1);
                    else DP[j][k] = Math.max(DP[j-1][k],DP[j][k-1]);
                }
            }
            System.out.println(DP[s.length()][t.length()]);
        }
    }
}


Measured memory_bytes: 63968
def main():
    N = int(input())
    A = [0]
    A += list(map(int, input().split()))
    A.append(0)
    total_dist = sum([abs(A[i+1] - A[i]) for i in range(N + 1)])
    for i in range(1, N + 1):
        print(total_dist - abs(A[i+1] - A[i]) - abs(A[i] - A[i-1]) + abs(A[i+1] - A[i-1]))


if __name__ == '__main__':
    main()


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

int main() {
    long long n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    
    auto check = [&] (long long m) -> bool {
        long long low = m * -d + (n - 1 - m) * c;
        long long high = m * -c + (n - 1 - m) * d;
        return (low <= b - a and b - a <= high);
    };
    
    bool ans = false;
    for (int i = 0; i < n; i++) ans |= check(i);
    cout << (ans ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  
  long long a,b,c;
  
  scanf("%lld %lld.%lld",&a,&b,&c);
  //printf("%lld %lld %lld\n",a,b,c);
  printf("%lld\n",a*(b*100+c)/100);
    
  return 0;
        
}

Measured memory_bytes: 1728
function Main(input) {
    input = input.trim();
    input = input.split("\n")
    var a = parseInt(input[0])
    if(input[1].length<=a){console.log(input[1])}else{
        console.log(input[1].slice(0,a)+"...")
    }



}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 


Measured memory_bytes: 29632
# ABC117C - Streamline
def main():
    N, M, *X = map(int, open(0).read().split())
    X = sorted(set(X))
    dist = [j - i for i, j in zip(X, X[1:])]
    dist.sort(reverse=1)
    ans = sum(dist[N - 1 :])
    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    string s;
    cin>>s;
    int arr[26]={0};
    for (char i:s){
        arr[i-'a']++;
    }for (int i=0;i<26;i++){
        if (arr[i]>1){
            cout<<"no";
            return 0;
        }
    }cout<<"yes";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int A,B,C;
  cin>>A>>B;
  int count=0;
  for(int i=2;i<N;i++){
    cin>>C;
    if(A<B&&B<C) count++;
    else if(C<B&&B<A) count++;
    A=B;
    B=C;
    }
  cout<<count<<endl;
  }

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n, i,  max = 0, temp;
    long long totalHeight = 0;
    int *a;
    cin >> n;
    a = new int[n];
    for (i = 0; i < n; i++){
        cin >> temp;
        *(a + i) = temp;
        if (*(a + i) > max)
            max = *(a + i);
        else if (*(a + i) < max) {
            totalHeight+=(max - *(a + i));            
        }
    }
    cout << totalHeight;
}

Measured memory_bytes: 4336
import math
import collections


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
counter = collections.Counter(s)
print(sum([combinations_count(i, 2) for i in counter.values() if i > 1]))

Measured memory_bytes: 68824
# -*- coding: utf-8 -*-
# 標準入力の取得
N, M = list(map(int, input().split()))
N, M = min(N, M), max(N, M)

# 求解処理
N, M = min(N, M), max(N, M)
result = 0
if N == 1:
    if M == 1:
        result = 1
    else:
        result = M - 2
else:
    result = (N - 2) * (M - 2)

# 結果出力
print(result)


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

using namespace std;
typedef long long ll;

int main() {
  int n,m,k;
  cin >> n >> m >> k;
  vector<ll> a(n+1),b(m+1);
  a[0] = 0;
  for(int i=1;i<n+1;++i){
    cin >> a[i];
    a[i] += a[i-1];
  }
  b[0] = 0;
  for(int i=1;i<m+1;++i){
    cin >> b[i];
    b[i] += b[i-1];
  }
  int time=0;
  int r=0;
  int j=0;
  int l=m;
  while(a[j]<=k && j<=n){
    time = k-a[j];
    //cout<<time<<endl;
    while(b[l]>time){
      if(l==0) break;
      l--;
    }
    //cout<<j<<" "<<l<<endl;
    if(r<l+j){
      r=l+j;
      //cout<<"r= "<<r<<endl;
    }
    j++;
    //cout<<"j= "<<j<<endl;
  }
  
  cout<<r<<endl;

  


}

Measured memory_bytes: 6428
import math
n,d = map(int,input().split())
dimention = []
ret =0
for i in range(n):
    next = list(map(int,input().split()))
    dimention.append(next)
for i in range(n-1):
    for j in range(i+1,n):
        s = 0
        for k in range(d):
            v = dimention[i][k]-dimention[j][k]
            s+= v*v
        ans = math.sqrt(s)
        ans = int(ans)
        if ans*ans==s:
            ret+=1
print(ret)

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

using namespace std;

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

#define MOD 1000000007

int main() {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    string s = "";
    for (int i = 0; i < a.size(); i++) {
        if (a[i] == b[i]) {
            s += "v";
        } else {
            s += "h";
            i++;
        }
    }

    LL cnt;
    if (s[0] == 'h') cnt = 6;
    else cnt = 3;
    for (int i = 1; i < s.size(); i++) {
        if (s[i] == 'h' && s[i - 1] == 'h') cnt *= 3;
        else if (s[i - 1] == 'h' && s[i] == 'v');
        else cnt *= 2;
        cnt %= MOD;
    }

    cout << cnt << endl;

    return 0;
}


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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

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

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;

    rep(i, s.size()) {
        char t = (s[i] + n - 'A') % 26 + 'A';
        cout << t;
    }
    return 0;
}


Measured memory_bytes: 256
import sys

while True:
    n=int(input())
    score={}
    if n==0:
        sys.exit()
    for _ in range(n):
        e,p,q=[int(i) for i in input().split(" ")]
        score[e]=score.get(e,0)+p*q

    employee=[]
    for e in score:
        if score[e]>=1000000:
            employee.append(e)

    if len(employee)==0:
        print("NA")
    else:
        for e in employee:
            print(e)



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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14) <<double値



int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    ll n;
    cin >> n;
    ll min_=1000000000001;

    for(ll i=1;i*i<=n;++i){
        if(n%i == 0){
            //if(i!=1 && i*i!=n){
                min_ = min(min_,(n/i-1)+(i-1));
            //}
        }
    }

    cout << min_;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <tuple>
#include <utility>
#include <stdlib.h>
#include <set>
#include <map>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define RSORT(x) sort(x.begin(),x.end(),greater<int>())
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	string s, ans = "Good";
	cin >> s;
	rep(i, 0, 3) {
		if (s[i] == s[i + 1]) {
			ans = "Bad";
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }

    sort(a.begin(), a.end());

    vector<int> b(n, 0);
    rep(i, n)
    {
        b[lower_bound(a.begin(), a.end(), a[i]) - a.begin()]++;
    }

    int result = 0;
    rep(i, n)
    {
        if (b[i] >= a[i]) {
            result += b[i] - a[i];
        } else {
            result += b[i];
        }
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
           
#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


struct Node
{
    string name;
    int x1, y1, x2, y2;
    vector<Node> child_nodes;
    bool include (int x, int y)
	{
	    return x1 <= x && x <= x2 && y1 <= y && y <= y2;
	}
};
Node parse(string s)
{
    Node res;

    int k;
    k = s.find(">");
    res.name = s.substr(1, k - 1);
    s = s.substr(k + 1);
    k = s.find("<");
    sscanf(s.substr(0, k).c_str(), "%d,%d,%d,%d", &res.x1, &res.y1, &res.x2, &res.y2);
    s = s.substr(k);
    s = s.erase(s.rfind("<"));

    while (!s.empty())
    {
	int i, tag;
	for (i = 1, tag = 1; tag; ++i)
	{
	    if (s[i] == '<')
	    {
		++i;
		if (s[i] == '/')
		    --tag;
		else
		    ++tag;
	    }
	}
	for ( ; s[i] != '>'; ++i)
	    ;
	res.child_nodes.push_back(parse(s.substr(0, i + 1)));
	s = s.substr(i + 1);
    }

    return res;
}
Node find_node(Node n, int x, int y)
{
    Node res;
    res.x1 = -1;
    if (n.include(x, y))
    {
	res = n;
	foreach (it, n.child_nodes)
	{
	    Node r = find_node(*it, x, y);
	    if (r.x1 != -1)
		res = r;
	}
    }
    return res;
}
int main()
{
    int n;
    while (cin >> n, n)
    {
	string s;
	cin >> s;
	Node root = parse(s);
	while (n--)
	{
	    int x, y;
	    cin >> x >> y;
	    Node res = find_node(root, x, y);
	    if (res.x1 >= 0)
		cout << res.name << " " << res.child_nodes.size() << endl;
	    else
		cout << "OUT OF MAIN PANEL 1" << endl;
	}
    }
}

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

string s;

int main(){
	cin >> s;
	for(int i=0;i<s.size();i++){
		if(i%2==0){
			if(s[i] == 'L'){
				cout << "No\n";
				return 0;
			}
		} else {
			if(s[i] == 'R'){
				cout << "No\n";
				return 0;
			}
		}
	}
	cout << "Yes\n";
	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}


const int X = 2010;

//head

int n, k, q;
int a[X];
map<int, vi> mp;
int ans = INF*10;
set<P> se;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k >> q;
  rep(i, n) cin >> a[i];

  rep(i, n) mp[a[i]].emplace_back(i);
  se.emplace(0, n);
  for(auto &ne: mp) {
    vi &v = ne.second;
    vi H;
    for(P p:se) {
      multiset<int> ss;
      for(int i = p.first; i < p.second; i++) ss.emplace(a[i]);
      while(ss.size() != k-1) {
        H.emplace_back(*ss.begin());
        ss.erase(ss.begin());
      }
    }
    if(H.size() < q) break;
    sort(all(H));
    chmin(ans, H[q-1]-H[0]);
    rep(i, v.size()) {
      auto itr = se.lower_bound(P(v[i]+1, 0));
      if(itr == se.begin()) continue;
      itr = prev(itr);
      P U = *itr;
      if(U.first > v[i] or U.second < v[i]) continue;
      se.erase(itr);
      if(U.second-v[i] > k) se.emplace(v[i]+1, U.second);
      if(v[i]-U.first >= k) se.emplace(U.first, v[i]);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3960
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#define full(c) c.begin(), c.end()
typedef unsigned long long int ull;
using namespace std;

struct Node{
	int id;
	vector <int> next;
};
void dfs(vector<Node> &node, int src, int &cnt, int n){
	static vector<int> rt;
	static vector<bool> flag(n + 1, false);
	rt.push_back(src);
	flag[src] = true;
	for (int nx : node[src].next){
		if (flag[nx] == false) dfs(node, nx, cnt, n);
	}
	flag[src] = false;
	if (rt.size() == n) cnt++;
	rt.pop_back();
}
int main(){
	int k, i, n, m, cnt = 0;
	cin >> n >> m;
	vector <Node> node(n + 1);
	for (i = 0; i <= n; i++) node[i].id = i;
	for (i = 0; i<m; i++){
		int a, b;
		cin >> a >> b;
		node[a].next.push_back(b);
		node[b].next.push_back(a);
	}
	dfs(node, 1, cnt, n);
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, S: str, T: str):
    outs=True
    for i in range(N):
        print(S[i], end="")
        print(T[i], end="")
    print()
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(N, S, T)

if __name__ == '__main__':
    main()


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

int main(){

    int n;
    cin >> n;
    vector<int> t(n);
    ll su=0;
    rep(i,n){
        cin >> t[i];
        su+=t[i];
    }
    int m;
    cin >> m;
    
    rep(i,m){
        ll p,x;
        cin>> p >> x;
        ll te=su-t[p-1]+x;
        cout << te << endl;
    }

    return 0;
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A
// Dijkstra法を用いた解法

// priority_queueに詰め込んでいき、重複したものを取り出したら捨てればいいという考えは思いつかなかった。priority_queueは「上澄みを取るだけの装置」と割りきっておくのが大事だった。
// また vector の使い方がわかっていなかったので、この機会に参考書で調べた。隣接リストを配列で作るとメモリが足りなくなりそうだが vector なら問題ない…ということも納得した。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;

int V, E, r, s, t, d;

vector<pair<int,int>> edges[100010]; // 隣接リスト(コスト付き)

long long infty = 10000*100000+100; // C[]はlong longを入れる。
priority_queue<pair<long long,int>> Q; // firstは上限の-1倍。secondは都市。
long long C[100010]; // 最小距離の上限を動的に入れる。
bool S[100010]; // 最小距離が確定したか？

int main() {
  // 初期化
  for (int i=0; i<100010; i++) {
    C[i] = infty;
    S[i] = false;
  }
  // 入力
  scanf("%d%d%d", &V, &E, &r);
  for (int i=0; i<E; i++) {
    scanf("%d%d%d", &s, &t, &d);
    edges[s].push_back(make_pair(t, d));
    // cerr << "edges[" << s << "][" << t << "] = " <<  edges[s][t] << endl;
  }
  // 優先度付きキューに初期状態を入れる。
  Q.push(make_pair(0, r));
  // Dijkstra法。
  while (!Q.empty()) {
    int u = Q.top().second;
    int tempC = -1 * Q.top().first;
    Q.pop();
    if (!S[u]) { // すでに最小距離確定した点は捨てる。
      C[u] = tempC;
      S[u] = true;
      // ここから緩和
      for (vector<pair<int,int>>::size_type i=0; i<edges[u].size(); i++) {
	int v = edges[u][i].first;
	int tempD = edges[u][i].second;
	if (!S[v] && C[v] > C[u] + tempD) {
	  C[v] = C[u] + tempD;
	  Q.push(make_pair(-1 * C[v], v)); // 緩和したものだけ入れれば十分。
	}
      }
    }
  }
  // 答えの出力。
  for (int i=0; i<V; i++) {
    if (C[i] < infty) {
      printf("%lld\n", C[i]);
    } else {
      printf("INF\n");
    }
  }
}

Measured memory_bytes: 12844
import numpy as np
import bisect
N,M,K= map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
if A[0]>K and B[0]>K:print(0);exit()

Asum=[0]
for i in range(N):
  if Asum[-1]+A[i]<=K:
    Asum.append(Asum[-1]+A[i])  
  else:break
    
Bsum=[0]
for j in range(M):
  if Bsum[-1]+B[j]<=K:
    Bsum.append(Bsum[-1]+B[j])
  else:break
    #AAsum=[]
#for i in range(len(Asum)):
#  AAsum.append(K-Asum[i])

#print(Asum)
#print(AAsum)
#print(Bsum)

C=[]
for i in range(len(Asum)):
  C.append(bisect.bisect(Bsum,K-Asum[i])+i-1)

#print(Asum)
#print(AAsum)
#print(Bsum)
#print(C)
print(max(C))
#176882


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

int main()
{
  string S;
  cin >> S;
  vector<int> A(26, 0);
  for (int i = 0; i < (int)S.size(); i++)
  {
    A.at((int)(S.at(i) - 'a'))++;
  }
  for (int i = 0; i < 26; i++)
  {
    if (A.at(i) == 0)
    {
      cout << (char)('a' + i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

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

signed main() {
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      if((s[i]!='R')&&(s[i]!='U')&&(s[i]!='D')){
        cout<<"No";
        return 0;
      }
    }else{
      if((s[i]!='L')&&(s[i]!='U')&&(s[i]!='D')){
        cout<<"No";
        return 0;
      }
    }
  }
  cout<<"Yes";
  return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/05/20.
//  Copyright © 2019 yuya. All rights reserved.
//

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



int main(){
    
    string S;
    cin >> S;
    
    for(int i=0;i<3;i++){
        if(S[i]==S[i+1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    
    cout << "Good" << endl;
    
    return 0;
}




Measured memory_bytes: 256
/*
 ╔═══╦═══╦═══╗
 ║╔═╗║╔══╩╗╔╗║
 ║║░║║╚══╗║║║║
 ║║░║║╔══╝║║║║
 ║╚═╝║╚══╦╝╚╝║
 ╚══╗╠═══╩═══╝
 ░░░╚╝░░░░░░░░
 */

#include <bits/stdc++.h>
#define ll					long long
#define MOD					1000000007
#define MAX					1e9
#define MIN                 -1e9
#define PI					acos(-1.0)
#define vi					vector<int>
#define vii					vector<vi>
#define vll					vector<ll>
#define mid(s,e)			(s+(e-s)/2)
#define clz(n)				__builtin_clzll(n)

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
template<typename T>
void printVec(const T &v, char sep=' ') {for (auto &i: v) cout << i << sep;}
template<typename T>
void printVecPair(const T &v, char sep=' ') {for (auto &i: v) cout << i.first <<" " << i.second<< sep;}


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main() {
	ios::sync_with_stdio(false);
 	cin.tie(0);
	ll r;
	cin>>r;
	cout<<3*r*r;
	return 0;
}





Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

typedef complex<double> P;
typedef vector<P> G;

/* 内積 */
double dot(const P& a, const P& b) {
	return real(conj(a)*b);
}
/* 外積 */
double cross(const P& a, const P& b) {
	return imag(conj(a)*b);
}
/*多角形の面積*/
double areaG(const G& g){
	double A = 0;
	for(int i =0;i <g.size();i++){
		A +=cross(g[i],g[(i+1)%g.size()]);
	}
	return abs(A/2.0);
}
int main(){
	G g;
	double x,y;
	char c;
	while(cin>>x>>c>>y){
		g.push_back(P(x,y));
	}
	printf("%.8f\n",areaG(g));
	return 0;
}

Measured memory_bytes: 1248
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;
    int m[n];
    rep(i,n) cin >> m[i];
    int sum=0, ans=n;
    rep(i,n) sum+=m[i];
    int mi = *min_element(m, m+n);
    x -= sum;
    ans += x/mi;
    cout << ans << endl;
    return 0;
}


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

typedef int ll;

#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()

typedef pair<int,int>pii;
typedef pair<int,pair<int,int> > piii;

const int mod=1e9+7;

int POWER[65];
int power(int a, int b) {int ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
int inv(int x) {return power(x,mod-2);}

void precompute() {
	POWER[0]=1;
	for(int i=1;i<63;i++) POWER[i]=POWER[i-1]<<1LL;
}

ll main() {
	// freopen("Task.in","r",stdin);freopen("Task.out","w",stdout);
	
	int a,b;
	cin>>a>>b;

	a=(a+b)%24;
	cout<<a<<endl;
}

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

void func141c() {
  int n, k, q, buff;
  cin >> n >> k >> q;
  vector<int> score(n, k-q);
  for (int i = 0; i < q; i++) {
    cin >> buff;
    score[buff-1]++;
  }
  for (int i = 0; i < n; i++) {
    if (score[i] > 0) {
      cout << "Yes\n";
    }else{
      cout << "No\n";
    }
  }
}

int main() {
  func141c();
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb push_back
#define rint register int
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=1e5+10;
const int inf=0x3f3f3f3f;

int n,ans;
int arr[maxn],p1[maxn],p2[maxn];

int gcd(int a,int b){
	if(a<b) swap(a,b);
	if(b==0) return a;
	if(a%b==0) return b;
	return gcd(b,a%b);
}

int main(){
	scanf("%d",&n);
	for(rint i=1;i<=n;++i) scanf("%d",&arr[i]);
	for(rint i=1;i<=n;++i) p1[i]=gcd(p1[i-1],arr[i]);
	for(rint i=n;i>=1;--i) p2[i]=gcd(p2[i+1],arr[i]);
	for(rint i=1;i<=n;++i) ans=max(ans,gcd(p1[i-1],p2[i+1]));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1536
from operator import itemgetter
N, M = map(int, input().split())
list1 = list()
for i in range(N):
  list1.append(list(int(x) for x in input().split()))
list1.sort(key=itemgetter(0))
ans = 0
j = 0
while True:
  if M > list1[j][1]:
    ans += list1[j][0] * list1[j][1]
    M -= list1[j][1]
    j += 1
  else:
    ans += list1[j][0] * M
    print(ans)
    exit()

Measured memory_bytes: 28972
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

typedef pair<int,int> P;

vector<P> vec[100005];

double p,t;

double dfs1(int d, int from){
  double ret = 0;
  for(auto to : vec[d]) if(to.fi != from){
    ret += (double)to.se + dfs1(to.fi, d);
  }
  return ret*p;
}

double dfs2(int d, int from){
  double ret = 0;
  for(auto to : vec[d]) if(to.fi != from){
    ret += (double)to.se + dfs2(to.fi, d);
  }
  ret *= p;
  ret += t;
  return ret;
}

int main(){
  int n;
  cin>>p>>n;
  rep(i,n-1){
    int x,y,z;
    cin>>x>>y>>z;
    x--;y--;
    vec[x].pb(mp(y,z));
    vec[y].pb(mp(x,z));
  }

  t = dfs1(0,-1);

  printf("%.7f\n", dfs2(0,-1));

  return 0;
}

Measured memory_bytes: 14944
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3f
//#define inf 0x3f3f3f3f
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inv(x) Power(x, mod - 2)
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define N 5005

using namespace std;
typedef pair<int,int> Pair;
typedef long long ll;

const long double Pi = 3.14159265358979323846l;
const int mod = 1e9 + 7;
inline int add(int x, int y) { return (x += y) - (x >= mod ? mod : 0); }
inline void inc(int &x, int y) { (x += y) -= (x >= mod ? mod : 0); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int Power(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = mul(res, x);
		x = mul(x, x), y >>= 1;
	} return res;
}

template <class T> inline T	input() {
	T x; char ch; while (!isdigit(ch = getchar()));
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return x;
}

template <class T> inline void chkmin(T &x, T y) { x = x < y ? x : y; }
template <class T> inline void chkmax(T &x, T y) { x = x > y ? x : y; }

struct {
	inline operator int () { return input<int>(); }
	inline operator long long () { return input<long long>(); }
	template <class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

int n, m;
long long f[N][N];
long long a[N], sum[N];
long long b[N][205];
int l[205][N], r[205][N];

long long dist(int l, int r) { return sum[r] - sum[l]; }

void Add(int xa, int xb, int ya, int yb, long long val) {
	f[xa][ya] += val, f[xb + 1][yb + 1] += val;
	f[xa][yb + 1] -= val, f[xb + 1][ya] -= val;
}

int main() {
	read(n, m);
	for (int i = 2; i <= n; ++i) read(a[i]);
	for (int i = 2; i <= n; ++i) sum[i] = sum[i - 1] + a[i];

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			read(b[i][j]);

	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n; ++j) {
			l[i][j] = j - 1;
			while (l[i][j] && b[l[i][j]][i] <= b[j][i]) l[i][j] = l[i][l[i][j]];
		}
		for (int j = n; j; --j) {
			r[i][j] = j + 1;
			while (r[i][j] <= n && b[r[i][j]][i] < b[j][i]) r[i][j] = r[i][r[i][j]];
		}
	}

	for (int i = 1; i <= m; ++i)
		for (int j = 1; j <= n; ++j)
			Add(l[i][j] + 1, j, j, r[i][j] - 1, b[j][i]);

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			f[i][j] += f[i][j - 1];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			f[i][j] += f[i - 1][j];

	long long ans = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = i; j <= n; ++j)
			chkmax(ans, f[i][j] - dist(i, j));
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 211840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
ll s;
int a, b, c, d;

int main() {
	scanf("%lld", &s);
	// 定一顶点在(0, 0), 构造向量(a, b)和(c, d)
	// 叉积求面积: s = ad - bc
	a = d = (int)sqrt(s);
	while(s > 1ll * a * d) {
		if(a < d) a++;
		else d++;
	}
	ll chk = 1ll * a * d - s;
	for(int i = 1; 1ll * i * i <= chk; i++) {
		if(!(chk % i)) {
			if(i <= 1e9 && chk / i <= 1e9) {
				b = i;
				c = chk / i;
				break;
			}
		}
	}
	printf("0 0 %d %d %d %d\n", a, b, c, d);
	return 0;
}

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

int main(){
    int A, B;
    cin >> A >> B;
    cout << ((A * (A - 1)) + (B * (B - 1))) / 2;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define printV(v) for(int i=0;i<v.size();i++){cout << v[i] << " ";} cout << endl;
ll a,b,c,d,e,f,g,n,m,k;
 

int main(){
    ios_base::sync_with_stdio(false);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string str; cin >> str;
    reverse(str.begin(),str.end());
    str.push_back('0');
    int dp1[str.size()+1];
    int dp2[str.size()+1];
    for(int i=0;i<=str.size();i++){
        dp1[i] = dp2[i] = 0;
    }
    dp1[0] = str[0] - '0';
    dp2[0] = 10 - dp1[0];
    bool fl = false;
    for(int i=1;i<str.size();i++){
        int curr = str[i] - '0';
        int curr2 = (curr + 1);
        int curr3 = 10 - curr;
        dp1[i] = min(dp1[i-1] + curr, dp2[i-1] + curr2);
        dp2[i] = min(dp1[i-1] + curr3,dp2[i-1] + (10 - (curr + 1)));
    }
    cout << min(dp1[str.size()-1],dp2[str.size()-1]);
    return 0;
}

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N + 2, 0);
  for (int i = 1; i <= N; i++){
    cin >> A[i];
  }
  int cost = 0;
  for (int i = 0; i <= N; i++){
    cost += abs(A[i + 1] - A[i]);
  }
  for (int i = 1; i <= N; i++){
    int tmp = cost;
    tmp -= abs(A[i] - A[i - 1]);
    tmp -= abs(A[i + 1] - A[i]);
    tmp += abs(A[i + 1] - A[i - 1]);
    cout << tmp << endl;
  }
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<=(b);++i)
#define DEC(i,a,b) for(int i=(a);i>=(b);--i)
#define dbg(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
template<typename T,typename U> inline bool smax(T&x,const U&y){return y>x?(x=y,1):0;}
template<typename T,typename U> inline bool smin(T&x,const U&y){return y<x?(x=y,1):0;}
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define X first
#define Y second

ll a,b,c,x,y;
int main(){
	cin>>a>>b>>c>>x>>y;
	if(a+b>2*c){
		ll z=min(x,y);x-=z,y-=z;
		ll ans=z*c*2;
		if(x)ans+=a>2*c?x*2*c:x*a;
		if(y)ans+=b>2*c?y*2*c:y*b;
		cout<<ans;
	}
	else{
		cout<<a*x+b*y;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int a[1000][1000];
int main(void){
    int n;
    scanf("%d", &n);
    if(n == 1){
        printf("Yes\n");
        printf("%d\n", 2);
        printf("1 1\n");
        printf("1 1\n");
        return 0;
    }
    for(int i = 3; i < 1000; i++){
        if(i*(i - 1) == 2*n){
            printf("Yes\n");
            printf("%d\n", i);

            //a[][]の生成
            int cnt = 1;
            for(int ii = 0; ii < i - 1; ii++){
                for(int jj = ii; jj < i - 1; jj++){
                    a[ii][jj] = cnt;
                    cnt++;
                }
            }
            cnt = 2;
            for(int ii = 0; ii < i - 1; ii++){
                for(int jj = ii + 1; jj < i; jj++){
                    a[jj][ii] = cnt;
                    cnt++;
                }
            }
            a[i-1][i-2] = 1;


            for(int j = 0; j < i; j++){
                printf("%d ", i - 1);
                for(int k = 0; k < i - 1; k++){
                    printf("%d", a[j][k]);
                    if(k == i - 2){
                        printf("\n");
                    }else{
                        printf(" ");
                    }
                }
            }

            return 0;
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 3364
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_C&lang=jp
#include<cstdio>
#include <cmath>

#define INPUT_MAX (int)10000		// 入力される整数の最大数
#define INPUT_MIN (int)1			// 入力される整数の最少数
#define INT_MAX (int)100000000		// 与えられる整数の最大値
#define INT_MIN (int)2				// 与えられる整数の最小値


class CPrime
{
	public:
		// Public member function
		bool JudgePrime( int num );
};


/*
 * *****************************************************
 * 関数概要  ：引数で与えられた整数が素数か判断する
 * @param[in] : num   素数か判断する整数
 * @return    : true  素数
 *              false 素数でない
 * *****************************************************
*/

bool CPrime::JudgePrime(int num)
{
	if( (num < INT_MIN) || (num > INT_MAX) )
	{
		// 与えられる整数の制約を満たしているか
		return false;
	}
	else if( (num != 2) && ((num % 2) == 0) )
	{
		// ２の倍数であるか(2を除く)
		return false;
	}
	for( int i = 3; i <= sqrt(num); i = i + 2 )
	{
		// √numの値までに割り切れる値があるか調べる
		if( (num % i) == 0 )
		{
			return false;
		}
	}
	
	return true;
}



int main(void)
{
	CPrime prime;
	
	int num;		// 取得した整数を入れる用
	int numint;		// 調べる整数の個数
	int countprime=0;	// 素数の数
	
	// 整数の個数を取得
	scanf( "%d%*c", &numint );
	
	if((numint < INPUT_MIN) || (numint > INPUT_MAX))
	{
		return -1;
	}

	for(int i = 0; i < numint; i++)
	{
		// 素数か調べる整数を取得
		scanf("%d%*c",&num);
		if( prime.JudgePrime(num) == true )
		{
			// 素数の数をカウント
			countprime++;
		}
	}
	
	printf("%d\n", countprime);
	
	return 0;
}




Measured memory_bytes: 2696
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mujin
{
	class Program
	{
		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());
			var x = Console.ReadLine().Split(' ').Select(y => int.Parse(y)).ToArray();
			long count = 1;
			var list = new Stack<int>();
			var mod = (long)(1000000007);
			for (int i = 0; i < N; i++)
			{
				list.Push(x[i]);
				if (x[i] < 2 * list.Count - 1)
				{
					count *= list.Count;
					list.Pop();
					count %= mod;
				}
			}
			for (int i = 0; i < list.Count; i++)
			{
				count *= i + 1;
				count %= mod;
			}
			Console.WriteLine(count);
		}
	}
}


Measured memory_bytes: 20704
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int n,i;

    int k = 1;
      
      
    scanf("%d", &n);
   

    for( i = 1 ; i <= ( n + n % 2 ) / 2 ; i = i + 1 ){   

        k = k * 2;

        if( k > n ){

            k = k / 2;

            break;

            }

        }
                  

    printf("%d\n", k );


    return 0;
                                                          
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int ans;
  if (A + B >=  A - B) {
    ans = A + B;
  } else {
    ans = A - B;
  }
  if (ans < A * B) {
    ans = A * B;
  }
  cout << ans << endl;
}


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

typedef long long LL;

LL time_seq[100];

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

int main() {
    int N;
    LL lcm;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> time_seq[i];
    sort(time_seq, time_seq + N);
    lcm = 1LL;
    for (int i = 0; i < N; i++) {
        lcm = lcm / gcd(max(lcm, time_seq[i]), min(lcm, time_seq[i])) * time_seq[i];
    }
    cout << lcm << endl;
    return 0;
}

Measured memory_bytes: 256