akhauriyash/Code-Regression huggingface dataset:
/*
      author : nishi5451
      created: 11.08.2020 01:20:33
*/

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


int main(){
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(n*a, b) << endl;
    return 0;
}

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

#define SZ(v) ((int)(v).size())
using ll = long long;

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

	string s, t;
	cin >> s >> t;
	for (int i(0); i < SZ(s); ++i)
		if (s[i] != t[i])
		{
			cout << "No" << endl;
			return 0;
		}
		cout << "Yes" << endl;
}


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


int main(){fastio
    ll n;cin>>n;
    string s[n];
    rep(i,0,n-1)cin>>s[i];
    ll ans=0;
    rep(p,0,(n-1)){
        string t[n];
        rep(i,0,n-1){
            rep(j,p,p+n-1){
                t[i]+=s[i][j%n];
            }
        }
        
        bool fl=true;
        rep(i,0,n-1){
            rep(j,0,n-1){
                if(t[i][j]!=t[j][i])fl=false;
            }
        }
        if(fl)ans++;
    }
    cout<<ans*n<<endl;
    
    return 0;
}


Measured memory_bytes: 692
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#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 <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

int x[200],y[200];

main(){
  int n;
  while(cin>>n,n){
    int maxx=0,maxy=0,minx=0,miny=0;
    x[0]=y[0]=0;
    rep(i,n-1){
      int ni,di;
      cin>>ni>>di;
      switch(di){
      case 0:
        x[i+1]=x[ni]-1;
        y[i+1]=y[ni];
        break;
      case 1:
        x[i+1]=x[ni];
        y[i+1]=y[ni]-1;
        break;
      case 2:
        x[i+1]=x[ni]+1;
        y[i+1]=y[ni];
        break;
      case 3:
        x[i+1]=x[ni];
        y[i+1]=y[ni]+1;
        break;
      }
      minx=min(minx,x[i+1]);
      miny=min(miny,y[i+1]);
      maxx=max(maxx,x[i+1]);
      maxy=max(maxy,y[i+1]);
    }
    cout<<(maxx-minx+1)<<' '<<(maxy-miny+1)<<endl;
  }
}

Measured memory_bytes: 0
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
pre = None
for ai in a:
    ans += b[ai - 1]
    if pre is not None and pre + 1 == ai:
        ans += c[ai - 2]
    pre = ai

print(ans)


Measured memory_bytes: 3060
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 
 using namespace std;
 
 int main()
 {
   int d;
   while(cin>>d)
   {
     int s=0;
     int yield=600/d;
     for(int i=0;i<yield-1;i++) s+=(i+1)*(d)*(i+1)*(d)*d;
     cout<<s<<endl;               
   }
   //while(1);      
   return 0;    
 }
 

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

int main()
{
    char s[500009];
    int i,j,k,l,c,now;
    vector<int>v;
    c=1;
    cin >> s;
    l=strlen(s);
    for(i=1;i<=l;i++)
    {
        if(i==l || (s[i]!=s[i-1]))
        {
            if(s[i-1]=='<')
                v.push_back(-c);
            else v.push_back(c);
            c=1;

        }
        else c++;
    }
    long long ans=0;
    l=v.size();
    for(i=0;i<l-1;i++)
    {
        if(v[i]<0)
        {
            v[i]*=(-1);
            if(v[i+1]>v[i])
                ans+=((long long)(v[i])*(v[i]-1))/2;
            else ans+=((long long)(v[i])*(v[i]+1))/2;

        }
        else
        {
            if(i==0)
                ans+=((long long)(v[i])*(v[i]+1))/2;
            else if(v[i-1]>=v[i])
                ans+=((long long)(v[i])*(v[i]-1))/2;
            else ans+=((long long)(v[i])*(v[i]+1))/2;
        }
    }

    if(v[i]<0) { v[i]*=(-1);ans+=((long long)(v[i])*(v[i]+1))/2;}
    else
    {
        if(v[i-1]>=v[i])
            ans+=((long long)(v[i])*(v[i]-1))/2;
        else ans+=((long long)(v[i])*(v[i]+1))/2;
    }
    cout << ans << endl;


}


Measured memory_bytes: 1912
#include<iostream>
#include<deque>
#include<queue>
#include<math.h>
#include<string>
#include<string.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<iomanip>
#include<map>
#include<bitset>
#include<algorithm>
#include<stack>
#include<unordered_map>
#include<cstdlib>
#include<unordered_set>
#include<algorithm>
#include<chrono>
 
#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
		
#define ii pair	<long long ,long long >
#define i64ii pair< long long, pair<int,int> >
#define i64i pair<long long , int >
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define iii pair<int, ii >	
#define in freopen("entrada","r",stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define id pair<int ,double > 
#define di pair<double, int>
 
#define pi 3.14159265359
#define nl (no<<1)
#define nr ( (no<<1)|1)
#define mid l + ( (r-l)>>1)
 
using namespace std;
 
 
typedef long long ll;	
typedef vector< int> vi;
typedef long double ld;
		
typedef  pair <ii, ii > iiii;	
typedef vector < ii > vii;
 
const int MAX = 6e2;
const int maxn = 1e6 + 100;


int n;

ll mod = 1e9 + 7, a[maxn] , bs[maxn], mmc;

ll w(ll n ){
	return ( n + mod )  % mod;
}

void f( ll n){
	for(ll i = 2;i <= n;i++){
		if ( bs[i] == 0 ){
			 bs[i] = i;
			for( ll j = 2*i; j <= n;j+=i) {
				bs[j] = i;
			}
		}
	}
}

ll pwr ( ll n,  ll e){
	ll r = 1;
	while(e){
		if (e&1)r = ( r * n) % mod;
		n = ( n * n) % mod;
		e >>= 1;
	}
	return r;
}

int qt[maxn];

void fac(ll n ){
	map < int,int > m;
	while ( n > 1){
		m[bs[n]]++;
		n/=bs[n];
	}

	for ( auto y : m ){
		qt[y.f] = max ( qt[y.f] , y.s );
	}
}

int main (){
	fast_io
	//~ in
	f ( 1e6 );
	
	cin >> n;
	for(int i = 0 ;i < n;i++){
		cin >> a[i];
		fac(a[i] );
	}
	
	mmc = 1;
	for(int i = 0 ;i < maxn;i++) {
		mmc = w ( mmc * w ( pwr(i,qt[i]) ) );
	}
	
	ll ans = 0;
	for(int i = 0 ;i < n;i++){
		ans = w ( ans + w ( mmc * pwr( a[i], mod-2) ) );
	}
	
 cout << ans << '\n';
	return 0;
}
  


Measured memory_bytes: 12288
n = int(input())
h_list= list(map(int, input().split()))
ans =0
result = 0
for i in range(n):

    if i == n-1:
        break
        
    
    if h_list[i] >=h_list[i+1]:
        ans += 1
    else:
        ans = 0
        continue
    result=max(result, ans)
    
print(result)

Measured memory_bytes: 20472
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s.by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main(){
    let s = stdin();
    let mut s = s.lock();
    let s = &mut s;

    let n = read::<usize>(s).unwrap();
	let mut v : Vec<i32> = Vec::with_capacity(n );
	for _ in 0 .. n {
		v.push(read::<i32>(s).unwrap());
	}
	let mut cnt = 0;
	for i  in 0 .. n {
		if i+1 == n {
			continue;
		} 
		for j in i+1 .. n {
			if j+1 == n {
				continue;
			}
			for k  in j+1 .. n {
				if v[i] == v[j] || v[i] == v[k] || v[j] == v[k] {
					continue;
				}
				if v[i] + v[j] > v[k] 
				&& v[i] + v[k] > v[j]
				&& v[k] + v[j] > v[i] {
					cnt += 1;
				}	
			}
		}
	}
	println!("{}", cnt);
}


Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    string S; cin >> S;
    int red = 0, blue = 0;
    rep(i, N) {
        if (S[i] == 'R') red++;
        else if (S[i] == 'B') blue++;
    }
    if (red > blue) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;

int check(int num, vector<int> &A){
	int con = 0, N = A.size();
	for(int i = 0; i < N; i++)
		if(A[i] == 0) {if(num >= 0) con += max(i,0ll);}
		else if(A[i] >= 0 && num >= 0) con += max(0ll,min((long long)(upper_bound(A.begin(), A.end(), num / A[i]) - A.begin()), i));
		else if(A[i] < 0 && num >= 0) con += max(0ll,min(i - (upper_bound(A.begin(), A.end(), -((long long)abs(num) + abs(A[i]-1)-1)/ abs(A[i])) - A.begin()), i));
		else if(A[i] > 0 && num < 0) con += max(0ll,min((long long)(upper_bound(A.begin(), A.end(), -((long long)abs(num) + abs(A[i]) - 1)/ abs(A[i])) - A.begin()), i));
	return con;
}


signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	int N, K;
	vector<int> A;
	
	int l = -INF, h = INF, m;
	
	cin>>N>>K;
	
	A.resize(N);
	
	for(int i = 0; i < N; i++) cin>>A[i];
	
	sort(A.begin(), A.end());

	while(l+1<h){
		m = (l+h)/2;
		
		if (check(m, A) < K) l = m;
		else h = m;
	}
	
	cout<<h<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A; int B; int X;
		A = scan.nextInt();
		B = scan.nextInt();
		X = 0;
		if(A>=B){
		X=X+A;
		A=A-1;
		}else if(A<=B){
			X=X+B;
			B=B-1;
		}
		if(A>=B){
		X=X+A;
		A=A-1;
		}else if(A<=B){
		X=X+B;
		B=B-1;
}
		System.out.println(X);
		scan.close();
	}
}

Measured memory_bytes: 22996
#AGC008A

x,y=map(int,raw_input().split())
if x>0 and y>0 and x<y:
 print y-x
elif x>0 and y>0 and x>y:
 print y+x
elif x>0 and y<0 and abs(x)<abs(y):
 print abs(y)-x +1
elif x>0 and y<=0 and abs(x)>abs(y):
 print 1+abs(x)-abs(y)
elif x<0 and y>0 and abs(x)<abs(y):
 print 1+abs(y)-abs(x)
elif x<0 and y>0 and abs(x)>abs(y):
 print abs(x)-abs(y)+1
elif x<0 and y<0 and abs(x)<abs(y):
 print 1+abs(y)-abs(x)+1
elif x<0 and y<=0 and abs(x)>abs(y):
 print abs(x)-abs(y)
elif x==y:
 print 0
elif x==0 and y>0:
 print y
elif x>0 and y==0:
 print abs(x)+1
elif x==0 and y<0:
 print abs(y)+1
elif abs(x)==abs(y):
 print 1


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

int n, m;
vector<int> v[100005];
int dp[100005];

int lp(int node) {
	if (dp[node] != 0) return dp[node];
	int m = 0;
	for (int i = 0; i < v[node].size(); ++i) {
		m = max(m, lp(v[node][i]) + 1);
	}
	
	return dp[node] = m;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	
	int x, y;
	for (int i = 0; i < m; ++i) {
		cin >> x >> y;
		v[x - 1].push_back(y - 1);
	}
	
	int m = 0;
	for (int i = 0; i < n; ++i) {
		m = max(m, lp(i));
	}
	
	cout << m << "\n";
}


Measured memory_bytes: 8192
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
typedef long long ll;

int main() {
    ll H, W;
    cin >> H >> W;
    ll res = 1e17;
    for(int i = 0; i < H; i++) {
        ll su = (H - i) * (W - W / 2);
        ll sl = (H - i) * (W / 2);
        res = min(res, max(i * W, max(su, sl)) - min(i * W, min(su, sl)));

        ll su2 = W * ((H - i) - (H - i) / 2);
        ll sl2 = W * ((H - i) / 2);
        res = min(res, max(i * W, max(su2, sl2)) - min(i * W, min(su2, sl2)));
    }

    for(int i = 0; i < W; i++) {
        ll su = (W - i) * (H - H / 2);
        ll sl = (W - i) * (H / 2);
        res = min(res, max(i * H, max(su, sl)) - min(i * H, min(su, sl)));

        ll su2 = H * ((W - i) - (W - i) / 2);
        ll sl2 = H * ((W - i) / 2);
        res = min(res, max(i * H, max(su2, sl2)) - min(i * H, min(su2, sl2)));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>

class Route {
public:
	Route(const int &n = 0) :state(n) {};
	bool filled() const { return state == ((1 << size) - 1); }
	Route remove(const int &n) const { return Route(state & (-1 - (1 << n))); }
	Route add(const int &n) const { return Route(state | (1 << n)); }
	bool include(const int &n) const { return (state & (1 << n)) != 0; }
	bool operator<(const Route &other) const { return state < other.state; }
	bool operator>(const Route &other) const { return other.state < state; }
	bool operator==(const Route &other) const { return state == other.state; }
	bool operator<=(const Route &other) const { return *this < (other) || *this == (other); }
	bool operator>=(const Route &other) const { return *this > (other) || *this == (other); }
	int to_i() const { return state; }
	void inspect() const;
	void inspect(int) const;
	static int size;
private:
	int state;
};
void Route::inspect() const {
	inspect(state);
	std::cout << std::endl;
}
void Route::inspect(int s) const {
	if (s > 1) {
		inspect(s / 2);
		std::cout << s % 2;
	}
	else {
		std::cout << s;
	}
}
class Edge {
public:
	Edge(const int &f = 0, const int &t = 0, const int &w = 0) :from(f), to(t), weight(w) {};
	bool operator<(const Edge &other) const { return (to < other.to); }
	int from, to, weight;
};
int dp(std::vector<std::vector<int>> &memo, std::vector<std::vector<Edge>> &edge, const Route &route, const int &vertex) {
	if (memo.at(route.to_i()).at(vertex) != -1) {
		return memo.at(route.to_i()).at(vertex);
	}
	else if (route.filled() && vertex == 0) {
		return memo.at(route.to_i()).at(vertex) = 0;
	}
	else {
		int min = 15001;
		for (auto &e : edge.at(vertex)) {
			//std::cout << "from " << e.from << " to " << e.to << std::endl;
			if (!route.include(e.to)) {
				auto temp = dp(memo, edge, route.add(e.to), e.to) + e.weight;
				//std::cout << vertex << "->" << e.to << " == ";
				//std::cout << temp << "---";
				//route.inspect();
				if (min > temp) {
					min = temp;
				}
			}

		}
		//std::cout << "vertex = " << vertex << "min = " << min << std::endl;
		return memo.at(route.to_i()).at(vertex) = min;
	}
}
int Route::size = 30;
int main() {
	int v, e;
	std::cin >> v >> e;
	Route::size = v;
	std::vector<std::vector<int>> vector((1 << v), std::vector<int>(v, -1));
	std::vector<std::vector<Edge>> edges(v, std::vector<Edge>(0));
	for (auto i = 0; i < e; ++i) {
		int s, t, d;
		std::cin >> s >> t >> d;
		edges.at(s).push_back(Edge(s, t, d));
	}
	if (dp(vector, edges, Route(0), 0) > 15000) {
		std::cout << -1 << std::endl;
	}
	else {
		std::cout << dp(vector, edges, Route(0), 0) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 4428
import sys
from itertools import product


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    m = list(map(int, input().split()))
    ans = [False] * q
    for e in product((0, 1), repeat=n):
        s = 0
        for i in range(n):
            s += e[i] * a[i]
        for i in range(q):
            if m[i] == s:
                ans[i] = True
    for a in ans:
        print("yes" if a else "no")


if __name__ == "__main__":
    main()



Measured memory_bytes: 5668
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <fstream>
#define N 205
#define inf 2000483640
using namespace std;
int main()
{
    char s[20];
    int l;
    scanf("%s", s);
    l = strlen(s);
    if(l >= 4 && s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I')
        puts("Yes");
    else
        puts("No");
    return 0;
}
/*
1
10
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{	
  	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
  	int i=0;
  	while((a>0)&&(c>0))
    {
      if(i%2!=0)
      {
        a-=d;
      }
      else
      {
        c-=b;
      }
      i++;
    }
  	if(a>0)
    {
      cout<<"Yes";
    }
  	else
    {
      cout<<"No";
    }
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>

using namespace std;

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

	for (int i = 0; i < s.length(); i++) {
		if (s[i] == ',') {
			cout << ' ';
		}
		else {
			cout << s[i];
		}
	}
	cout << '\n';
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	map<string,ll> ct;
	while(n-->0) {
		string s; cin>>s;
		sort(s.begin(),s.end());
		ct[s]++;
	}
	ll ret=0;
	for (const auto &it : ct) {
		ll x=it.second;
		ret+=x*(x-1)/2;
	}
	cout<<ret<<"\n";
	return 0;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	vector<int> a;
	int b, c, d;
	cin >> b >> c >> d;
	a.pb(b);
	a.pb(c);
	a.pb(d);
	sort(a.begin(), a.end());

	cout << a[0] + a[1] << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    string ans;
    if(S[S.size()-1]=='s'){
        ans = S + "es";
    }else{
        ans = S + "s";
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int b[] = new int[N];
        for (int i = 0; i < N; i++) {
            b[i] = scan.nextInt();
        }
        int count = 0;

        for (int y=0; y<N; y++){
            int sum = 0;

            for(int x=0;x<y;x++){
                
                if(b[y] >= b[x]){
                    sum = sum +1;
                }
            
            }
            if (sum == y){
                count++;
            }

        }

        System.out.println(count);
    }
}


Measured memory_bytes: 22996
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const ll MOD7 = 1000000007;

struct FactorialTable {
  vector<ll> fact;
  vector<ll> inv;
  ll m;

  explicit FactorialTable(ll n, ll m) {
    this->m = m;
    fact = vector<ll>(n + 1, 0);
    fact[0] = 1;
    for (int i = 1; i <= n; i++) {
      fact[i] = fact[i - 1] * i % m;
    }
    inv = vector<ll>(n + 1, 0);

    for (int i = n - 1; i >= 0; i--) {
      inv[i] = mod_pow(fact[i], m - 2);
    }
    /*
    inv[n] = mod_pow(fact[n], m - 2);
    for (int i = n - 1; i >= 0; i--) {
      inv[i] = inv[i + 1] * (i + 1) % m;
    }
    */

  }
  ll mod_pow(ll x, ll n) {
    ll ans = 1;
    while (n > 0) {
      if ((n & 1) == 1) ans = ans * x % m;
      x = x * x % m;
      n >>= 1;
    }
    return ans;
  }
  ll factorial(int n) {
    return fact[n];
  }
  ll comb(int n, int k) {
    return fact[n] * inv[k] % m * inv[n - k] % m;
  }
};

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

  int H, W, A, B;
  cin >> H >> W >> A >> B;

  FactorialTable f(H + W, MOD7);

  ll result = 0;
  for (int i = B + 1; i <= W; i++) {
    result += f.comb(H - A + i - 2, i - 1) *
              f.comb(A + W - i - 1, A - 1) % MOD7;
    result %= MOD7;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3328
using System;
namespace ForAtCoder
{
    class Program
    {
        static void Main()
        {
            string[] str = Console.ReadLine().Split(' ');

            long n = long.Parse(str[0]);
            int k = int.Parse(str[1]);

            try
            {
                string s = Convert.ToString(n, k);

                Console.WriteLine(s.Length);
            }
            catch
            {
                long a = n;
                long mod = 0;
                string rslt = "";

                while (a > 0)
                {
                    mod = a % k;
                    rslt += mod.ToString();

                    a = a / k;
                }

                Console.WriteLine(rslt.Length);
            }
        }
    }
}


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

int main() {
  int a,b,d=0;
  cin>>a>>b;
  vector<int> c(a);
  for(int i=0;i<a;i++){
    cin>>c.at(i);
  }
  sort(c.rbegin(),c.rend());
  for(int i=0;i<b;i++){
    d+=c.at(i);
  }
  cout<<d<<endl;
}

Measured memory_bytes: 3584
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 100)
	sc.Buffer(buf, 100+1024)
	sc.Split(bufio.ScanWords)
	length, _ := strconv.Atoi(readLine(sc))
	input := readLine(sc)
	slice := strings.Split(input, "")
	change, _ := strconv.Atoi(readLine(sc))

	for i := 0; i < length; i++ {
		if slice[i] == slice[change-1] {
			fmt.Print(slice[change-1])
		} else {
			fmt.Print("*")
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define fo(i, n) for(int i = 1; i <= (n); i ++)
#define out(x) cerr << #x << " = " << x << "\n"
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); ++ it)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
template<typename tp> inline void arr(tp *a, int n) {
  for(int i = 1; i <= n; i ++)
    cout << a[i] << " ";
  puts("");
}
int a, b, c, x, y;
main(void) {
  read(a); read(b); read(c);
  c <<= 1;
  read(x); read(y);
  int ans = max(x, y) * c;
  if(x > y) ans = min(ans, y * c + (x - y) * a);
  else ans = min(ans, x * c + (y - x) * b);
  ans = min(ans, x * a + y * b);
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;

int main()
{
    int a,b,c;
    while (cin>>a>>b>>c)
    {
        if (c>=a&&c<=b)cout<<"Yes"<<endl;
        else  cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
// AGC21-A.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <string>
using namespace std;

int main()
{
	string n;
	cin >> n;
	reverse(n.begin(), n.end());
    for (size_t i = 0; i < n.size()-1; i++)
	{
		if (n[i] != '9')
		{
			n[i + 1] -= 1;
			n[i] = '9';
		}
	}
	long long sum = 0;
	for (size_t i = 0; i < n.size(); i++)
	{
		sum += n[i] - '0';
	}

	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 256
// In the nAme Of Allah
#include<bits/stdc++.h>
#define pb push_back
#define ins insert
#define f first
#define pp pop_back
#define ll long long int
#define fst  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const ll mod=1e9+7;
using namespace std;
ll n,a[200005],s=0,p=0;
int main()
{
   fst;
   cin>>n;
   for(ll i=0;i<n;i++)
   {
       cin>>a[i];
       p+=(a[i]%mod)*(a[i]%mod)%mod;
       s+=(a[i]%mod);
       s%=mod;
       p%=mod;
       }
       if(((s*s)-p)%2==0)
       {
           cout<<(((s*s)-p)/2)%mod;
       }
       else{
        cout<<(((s*s)-p+mod)/2)%mod;
       }
   return 0;
}


Measured memory_bytes: 5224
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    int n,k;
    cin >> n >> k;
    int sum = 0;
    int a[n];
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    sort(a,a+n);
    if(sum-a[n-1]<=k){
        cout << sum << endl;
        return 0;
    }

    

    int ans = 1;

    vi v;
    v.push_back(1);
    v.push_back(sum);
    srep(i,2,sum+100){
        if(sum<i)break;
        if(100<i&&i*i>sum)break;
        if(sum%i==0){
            v.push_back(i);
            v.push_back(sum/i);
        }
    }

    sort(v.begin(),v.end(),greater<int>());
    rep(i,v.size()){
        if(v[i]==1)break;
        int x = v[i];
        int flag = 0;
        int ama[n];
        //cout << x << ":  ";
        rep(j,n){
            ama[j] = a[j] % x;
            //cout << ama[j] << ' ';
        }
        //cout << endl;
        sort(ama,ama+n);
        int le[n];
        int ri[n];
        rep(j,n){
            if(j==0){
                le[j] = ama[j];
            }else{
                le[j] = ama[j] + le[j-1];
            }
        }
        drep(j,n){
            int ama2 = x - ama[j];
            if(ama2==x){
                ama2 = 0;
            }
            if(j==n-1){
                ri[j] = ama2;
            }else{
                ri[j] = ama2 + ri[j+1];
            }
        }
        /*
        rep(j,n){
            cout << le[j] << ' ';
        }
        cout << endl;
        rep(j,n){
            cout << ri[j] << ' ';
        }
        cout << endl;
        */

        if(le[n-1]==0){
            cout << x << endl;
            return 0;
        }
        rep(i,n-1){
            if(le[i]==ri[i+1]){
                if(le[i]<=k){
                    cout << x << endl;
                    return 0;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;
const int mod1=998244353;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll ai,ao,at,aj,al,as,az;cin >> ai >> ao >> at >> aj >> al >> as >> az;
	ll ans=ao;
	if(aj%2==1 && al%2==1){
		if(ai>=1){
			ai--;
			aj--;
			al--;
			ans+=3;
		}
	}
	else if(ai%2==1 && aj%2==1 && al>0){
		ai--;
		aj--;
		al--;
		ans+=3;
	}
	else if(ai%2==1 && al%2==1 && aj>0){
		ai--;
		aj--;
		al--;
		ans+=3;
	}
	ans+=ai/2*2+aj/2*2+al/2*2;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	int n,k,m;
	cin>>n>>k>>m;
	if(m!=1e9){
		for(int i=1;i<=k;i++)cout<<m<<' ';
		for(int i=k+1;i<=n;i++)cout<<m+1<<' ';
	}else{
		for(int i=1;i<=k;i++)cout<<1000000000<<' ';
		for(int i=k+1;i<=n;i++)cout<<"1 ";
	}
	return 0;
}




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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
string S;
const int MAX_N = 200000;
int dp [MAX_N + 2];
bool vis [MAX_N + 2];
int nxt [MAX_N + 2] [26];
vector<int> prv [MAX_N + 2];
const int INF = 1e9;

void dfs(int curr)
{
	vis [curr] = true;
	for(const auto& it : prv [curr]) if(vis [it] == false && dp [curr] == dp [it] + 1){
		dfs(it);
	}
}

int main()
{
	cin >> S;
	N = S.size();

	{
		map<char,int> mp;
		for(int i = N - 1;i >= 0;i--){
			mp [S [i]] = i + 1;
			FOR(j,0,26){
				if(mp.count(j + 'a') == 0){
					nxt [i] [j] = N + 1;
					prv [N + 1].push_back(i);
				}
				else{
					nxt [i] [j] = mp [j + 'a'];
					prv [mp [j + 'a']].push_back(i);
				}
			}
		}
		FOR(i,0,26){
			nxt [N] [i] = N + 1;
			prv [N + 1].push_back(N);
		}
	}

	fill(dp,dp + N + 2,INF);
	dp [0] = 0;
	FOR(i,0,N + 1){
		FOR(j,0,26){
			chmin(dp [nxt [i] [j]],dp [i] + 1);
		}
	}
	dfs(N + 1);

	string ans;
	int curr = 0;
	while(curr < N + 1){
		FOR(i,0,26) if(vis [nxt [curr] [i]] && dp [curr] + 1 == dp [nxt [curr] [i]]){
			ans += 'a' + i;
			curr = nxt [curr] [i];
			break;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 59396
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int H, W, N;
	cin >> H >> W >> N;
	vector<vector<int> > G(H);
	for (int i = 0; i < N; ++i) {
		int a, b;
		cin >> a >> b; --a, --b;
		G[a].push_back(b);
	}
	function<int(int, int)> get_fin = [&](int x, int y) {
		if (y == 0 && x % 2 == 0) --x;
		if (y == W - 1 && (x + y) % 2 == 1) --x;
		if (x == -1) return y;
		int rem = x % (2 * W);
		int pot = y;
		if (x % 2 != y % 2) pot = 2 * W - y - 1;
		pot %= 2 * W;
		int fin = (pot - rem + 2 * W) % (2 * W);
		int ans = (fin < W ? fin : 2 * W - fin - 1);
		if (fin == -1) fin = 0;
		return ans;
	};
	vector<int> perm(W);
	for (int i = 0; i < W; ++i) perm[i] = i;
	for (int i = 0; i < H; ++i) {
		for (int j : G[i]) {
			int lc = get_fin(i, j);
			int rc = get_fin(i, j + 1);
			swap(perm[lc], perm[rc]);
		}
	}
	vector<int> ans(W);
	for (int i = 0; i < W; ++i) {
		int res = get_fin(H, i);
		ans[perm[res]] = i;
	}
	for (int i = 0; i < W; ++i) {
		cout << ans[i] + 1 << '\n';
	}
	return 0;
}


Measured memory_bytes: 13136
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int d, t, s;
	cin >> d >> t >> s ;
	
	if(s * t < d) cout << "No";
	else cout << "Yes";
	cout << endl;
	
	
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,m,x;cin>>n>>m>>x;
    vector<ll> c(n);
    vector<vector<ll>> a(n,vector<ll>(m));
    rep(i,n){
        cin>>c[i];
        rep(j,m)cin>>a[i][j];
    }
    ll res=1e+9;
    for(ll i=0;i<=(1<<12);i++){
        vector<ll> tmp(m,0);
        ll nowm=0;
        ll now=i;
        
        rep(j,n){
            if(now%2==0){
                now/=2;
                continue;
            }
            nowm+=c[j];
            rep(k,m)tmp[k]+=a[j][k];
            now/=2;
        }
        
        bool ok=true;
        rep(j,m){
            if(tmp[j]<x){
                ok=false;
                break;
            }
        }
        if(ok)chmin(res,nowm);
    }
    if(res==1e+9)cout<<-1<<endl;
    else cout<<res<<endl;
}

Measured memory_bytes: 3604
s=input()
c=0
tmp=0
ans=0
for b in s:
    if b=="A"or b=="C"or b=="G" or b=="T":
        c=1
    else:
        tmp=0
        c=0
    if c==1:
        tmp+=1
        if tmp>=ans:
            ans=tmp
print(ans)


Measured memory_bytes: 2940
from heapq import heappush, heappop

def prim(ad): # ad[i][j]: (重み, ノード)
    N = len(ad)
    used = [0]*N
    hq = []
    for ad_i in ad[0]:
        heappush(hq, ad_i)
    used[0] = 1
    res = 0
    while hq:
        w, v = heappop(hq)
        if used[v]: continue
        used[v] = 1
        for nw, nv in ad[v]:
            if used[nv]: continue
            heappush(hq, (nw, nv))
        res += w
    return res

N = int(input())
X = []
Y = []

for i in range(N):
    x, y = map(int,input().split())
    X.append((x,i))
    Y.append((y,i))

X.sort()
Y.sort()

ad = [[] for _ in range(N)]

for t in range(N-1):
    a, i = X[t]
    c, j = X[t+1]
    wx = abs(a-c)
    ad[i].append((wx,j))
    ad[j].append((wx,i))
    b, k = Y[t]
    d, l = Y[t+1]
    wy = abs(b-d)
    ad[k].append((wy,l))
    ad[l].append((wy,k))

ans = prim(ad)
print(ans)

Measured memory_bytes: 79940
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
const int INFTY = 1001001001;

class Edge{
public:
    int node;
    ll cost;
    Edge(int u, ll w) : node(u), cost(w) {}
};

void bfs(vector< vector<Edge> >& tree, vector<ll>& dist, vector<ll>& state, int node){
    queue<int> Q;
    Q.push(node);
    dist[node] = 0;
    state[node] = 0;
    while(!Q.empty()){
        node = Q.front();
        Q.pop();
        for(auto e : tree[node]){
            if(state[e.node] == -1){
                dist[e.node] = dist[node] + e.cost;
                if(dist[e.node] % 2 == 0){
                    state[e.node] = 0;
                }
                else{
                    state[e.node] = 1;
                }
                Q.push(e.node);
            }
        }
    }
}

int main()
{
    int N;
    cin >> N;
    vector< vector<Edge> > tree(N);
    vector< ll > dist(N, INFTY);
    vector< ll > state(N, -1);
    int u, v;
    ll w;
    for(int i=0;i<N-1;++i){
        cin >> u >> v >> w;
        --u;
        --v;
        tree[u].push_back(Edge(v, w));
        tree[v].push_back(Edge(u, w));
    }

    bfs(tree, dist, state, 0);

    for(int i=0;i<N;++i){
        cout << state[i] << endl;
    }
}


Measured memory_bytes: 10624
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())

U = 10**6 + 100

div = np.arange(1, U, dtype=np.int64)
div = div[N%div==0]

div = np.union1d(div, N//div)

answer = (div + (N//div)).min() - 2
print(answer)

Measured memory_bytes: 30516
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(u) for(int i=hd[u],v,w;v=e[i].v,w=e[i].w,i;i=e[i].n)
using namespace std;
typedef long long ll;
const int N=200200,LG=20,M=400400,P=1e9+7;
int Cas,n,m,fl,ti,A,B,C,ans;
int hd[N],fd[N],fa[N],d[N],sz[N],t[N],we[N],top[N],df[N],pr[N],ok[N],f[N][LG+2];
ll X,W,w[N];
struct edge{int n,v,w;}e[M<<1];
struct Edge{
    int u,v,w;
    bool operator < (const Edge&a)const{return w<a.w;}
}E[M];
int qpw(int x,int y){int z=1;for(;y;y>>=1,x=1ll*x*x%P)if(y&1) z=1ll*z*x%P;return z;}
void add(int u,int v,int w){e[++fl]={hd[u],v,w};hd[u]=fl;}
int fi(int x){return x==fd[x]?x:fd[x]=fi(fd[x]);}
void dfs1(int u){
    sz[u]=1;
    REP(u)if(v!=fa[u]){
        fa[v]=u;d[v]=d[u]+1;t[v]=w;
        dfs1(v);sz[u]+=sz[v];
        if(sz[v]>sz[we[u]]) we[u]=v;
    }
}
void dfs2(int u,int TP){
    top[u]=TP;pr[df[u]=++ti]=u;f[ti][0]=t[u];
    if(we[u]) dfs2(we[u],TP);
    REP(u)if(v!=fa[u] && v!=we[u]) dfs2(v,v);
}
int rmq(int x,int y){
    int len=log2(y-x+1);
    return max(f[x][len],f[y-(1<<len)+1][len]);
}
int ask(int u,int v){
    int ret=0;
    for(;top[u]!=top[v];u=fa[top[u]]){
        if(d[top[u]]<d[top[v]]) swap(u,v);
        ret=max(ret,rmq(df[top[u]],df[u]));
    }
    if(d[u]<d[v]) swap(u,v);
    if(df[v]<df[u]) ret=max(ret,rmq(df[v]+1,df[u]));
    return ret;
}
void work(){
    scanf("%d%d%lld",&n,&m,&X);
    FOR(i,1,m) scanf("%d%d%d",&E[i].u,&E[i].v,&E[i].w);
    sort(E+1,E+m+1);
    FOR(i,1,n) fd[i]=i;
    FOR(i,1,m){
        int u=E[i].u,v=E[i].v,w=E[i].w,fu=fi(u),fv=fi(v);
        if(fu!=fv) add(u,v,w),add(v,u,w),fd[fu]=fv,W+=w,ok[i]=1;
    }
    //cerr<<W<<' '<<X<<'\n';
    dfs1(1);dfs2(1,1);
    FOR(j,1,LG)FOR(i,1,n)if(i+(1<<j)-1<=n)
        f[i][j]=max(f[i][j-1],f[i+(1<<j-1)][j-1]);
    FOR(i,1,m) w[i]=ok[i]?W:W-ask(E[i].u,E[i].v)+E[i].w;
    FOR(i,1,m) w[i]<X?A++:(w[i]==X?B++:C++);
    //cerr<<A<<' '<<B<<" "<<C<<'\n';
    if(X==W) ans=1ll*(qpw(2,B)-2)%P*qpw(2,C)%P;
    else ans=2ll*(qpw(2,B)-1)%P*qpw(2,C)%P;
    cout<<ans<<'\n';
    W=fl=ti=A=B=C=0;
    FOR(i,1,m) ok[i]=0;
    FOR(i,1,n) hd[i]=fa[i]=f[i][0]=we[i]=0;
}
int main(){
    //freopen("b.in","r",stdin);
    //freopen("b.out","w",stdout);
    work();
}

Measured memory_bytes: 14592
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int arr[101] = {0};

int main()
{
	long long int a, b, total=0, n=0;
	cin >> a >> b;
	for(int i=0; i<a; i++)
	{
		int c;
		cin >> arr[i];
	}
	for(int i=0; i<a; i++)
	{
		total += arr[i];
	}
	for(int i=0; i<a; i++)
	{
		if(arr[i]*4*b >= total)
		{
			n ++;
		}
	}
	if(n >= b)
	{
		cout << "Yes";
	}
	else 
	{
		cout << "No";
	}
}



Measured memory_bytes: 3632
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    S = []
    for _ in range(N):
        S.append(int(input()))

    S = [0] + list(sorted(S))
    total = sum(S)
    for s in S:
        if (total - s) % 10 != 0:
            print(total - s)
            return

    print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3952
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> cnt(1e6+1);
    for (int x : a) {
        if (cnt[x] != 0) {
            cnt[x] = 2;
            continue;
        }
        for (int i = x; i <= 1e6; i += x) cnt[i]++;
    }
    int ans = 0;
    for (int x: a) {
        if (cnt[x] == 1) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7908
#include <bits/stdc++.h>
using namespace std;
using u32 = uint32_t;

void dfs(vector<u32>& S, const u32 N, u32 i, u32 m) {
	if (i < N) {
		for(u32 t=0; t<i+1 && t<=m+1; t++) {
			S[i] = t;
			dfs(S, N, i+1, max(m, t));
		}
	} else {
		for(u32 q=0; q<N; q++) {
			char a = 'a' + S[q];
			cout << a;
		}
		cout << endl;
	}
}

int main() {
	u32 N;
	cin >> N;

	vector<u32> S(N, 0);
	
	dfs(S, N, 0, 0);
	return 0;
}

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

int main() {
	string s;
	cin >> s;
	vector<string> word = {"dream", "dreamer", "erase", "eraser"};

	reverse(s.begin(), s.end());
	for (int i = 0; i < 4; i++) reverse(word.at(i).begin(), word.at(i).end());

	bool flag1 = true;
	int pre = 0;
	while (pre < s.size()) {
		bool flag2 = false;
		for (int j = 0; j < 4; j++) {
			if (s.substr(pre, word.at(j).size()) == word.at(j)) {
				flag2 = true;
				pre += word.at(j).size();
			}
		}
		if (!flag2) {
			flag1 = false;
			break;
		}
	}

	if (flag1) cout << "YES" << endl;
	else cout << "NO" << endl;

 	return 0;
 }

Measured memory_bytes: 512
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

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

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}

int main() {
    ll N;
    cin >> N;
    vector<int>H(N);

    rep(i,N){
        cin >> H[i];
    }

    int view=1;
    int highest=H[0];

    for(int i=1; i<N; i++){
        if(H[i]>=highest){
            view++;
            highest=H[i];
        }
    }

    cout << view << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
T = [int(x) for x in input().split()]
M = int(input())
PX = []
for _ in range(M):
    PX.append([int(x) for x in input().split()])
total = sum(T)
ans = []
for i in range(M):
    P, X = PX[i]
    temp = total - T[P - 1] + X
    ans.append(temp)
for j in ans:
    print(j)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  string str;
  cin >> str;
  int n=0,w=0,s=0,e=0;
  for(int i=0;i<str.size();i++){
    if(str[i]=='N'){
      n++;
    }
    if(str[i]=='W'){
      w++;
    }
    if(str[i]=='S'){
      s++;
    }
    if(str[i]=='E'){
      e++;
    }
  }
  bool c=true;
  if((n+s!=0&&n*s==0)||(w+e!=0&&w*e==0)){
    c=false;
  }
  if(c){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define int long long
typedef pair<int, int> P;
int let[26];
string mat[114];
signed main() {
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++)cin >> mat[i];
	for(int i=0;i<h;i++)
		for (int j = 0; j < w; j++)let[mat[i][j] - 'a']++;

	int k = 0;
	for (int i = 0; i < 26; i++)if (let[i] & 1)k++;
	if (k > 1) {
		puts("No");
		return 0;
	}
	if (h > w)swap(h, w);
	int l1 = 0;
	for (int i = 0; i < 26; i++) {
		if (let[i] & 1)l1++;
	}

	if (h == 1) {
		puts("Yes");
	}
	else {
		int l2 = 0;
		for (int i = 0; i < 26; i++) {
			if (let[i] % 4 == 2)l2++;
		}
		int am = 0;
		if (h & 1)am += w;
		if (w & 1)am += h;
		if (h & 1 && w & 1)am -= 2;

		if (am/2  < l2)puts("No");
		else puts("Yes");
	}

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var dates = new string[] { "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday" };
            var values = new int[] { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

            string s;
            int value = 0;
            while ((s = Console.ReadLine()) != null)
            {
                value = 0;
                var ary = s.Split(' ').Select(int.Parse).ToArray();
                if (ary[0] == 0 && ary[1] == 0) break;
                for (int i = 0; i < ary[0]-1; i++)
                    value += values[i];
                Console.WriteLine(dates[(value + ary[1] - 1) % 7]);
            }
        }
    }
}

Measured memory_bytes: 5696
use proconio::input;

fn main() {
    input! {
        a: i128,
        v: i128,
        mut b: i128,
        w: i128,
        t: i128,
    }
    b -= a;
    b = b.abs();

    if b - (v - w) * t <= 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 2116
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=1010;
int n,a[N],ret;
bool valid(int x) {
	VI d;
	while (x) {
		d.pb(x%10);
		x/=10;
	}
	rep(i,0,SZ(d)-1) if (d[i]!=d[i+1]+1) return 0;
	return 1;
}
int main() {
	scanf("%d",&n);
	rep(i,0,n) scanf("%d",a+i);
	ret=-1;
	rep(i,0,n) rep(j,i+1,n) if (valid(a[i]*a[j])) ret=max(ret,a[i]*a[j]);
	printf("%d\n",ret);
}

Measured memory_bytes: 2784
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

const int MAX_N = 305, MOD = 1000000007;
typedef pair<int, int> pii;

int N, M;
vector<pii> vec[MAX_N];

int f[MAX_N][MAX_N][MAX_N];

inline void update(int &x, int y) {
  x = (x + y) % MOD;
}

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1, L, R, X; i <= M; ++i) {
    scanf("%d%d%d", &L, &R, &X);
    vec[R].push_back(make_pair(L, X));
  }

  int res = 0;
  
  f[0][0][0] = 1;

  for (int a = 0; a <= N; ++a)
    for (int b = 0; b <= N; ++b)
      for (int c = 0; c <= N; ++c)
	if (f[a][b][c]) {
	  int k = max(a, max(b, c)), &val = f[a][b][c];
	  
	  for (pii x : vec[k]) {
	    int cnt = 0;
	    if (a >= x.first) cnt++;
	    if (b >= x.first) cnt++;
	    if (c >= x.first) cnt++;
	    if (cnt != x.second) val = 0;
	  }
	  
	  if (k < N) {
	    update(f[k + 1][b][c], val);
	    update(f[a][k + 1][c], val);
	    update(f[a][b][k + 1], val);
	  } else {
	    update(res, val);
	  }
	  
	}

  printf("%d\n", res);
  
  return 0;
}


Measured memory_bytes: 110848