akhauriyash/Code-Regression huggingface dataset:
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
X = 0
Y = []
for i in range(M):
    X = list(map(int,input().split()))
    Y.append(int(a[X[0] - 1] + b[X[1] - 1] - X[2]))
Y.sort()
a.sort()
b.sort()

if Y[0] < a[0] + b[0]:
    print(Y[0])
else:
    print(a[0] + b[0])

Measured memory_bytes: 18736
def main():
	N, M, C = map(int, input().split())
	B = list(map(int, input().split()))
	c = 0
	for i in range(N):
		A = list(map(int, input().split()))
		t = 0
		for j in range(M):
			t += A[j]*B[j]
		if 0 < t + C:
			c += 1
	print(c)
	return

if __name__ == '__main__':
	main()


Measured memory_bytes: 3060
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;

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

double const pi=3.1415926535;

int printint(int n){
	cout<<n<<endl;
	return 0;
}

int prints(string s){
	cout<<s<<endl;
	return 0;
}

int main(){
	int n,k;
	int l[60];
	cin>>n>>k;
	rep0(n)cin>>l[i];
	sort(l,l+n);
	int ans=0;
	for(int i=n-1;i>=n-k;i--){
		ans+=l[i];
	}
	printint(ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 3e5 + 5 ; 
int n, a[N], Ans ; 
signed main()
{
	n = gi() ; int m = 3 * n ;
	rep( i, 1, m ) a[i] = gi() ;
	sort( a + 1, a + m + 1 ) ;
	int tr = 0, cnt = 0 ;
	for( re int i = m; i >= 1; -- i ) {
		if( tr ) Ans += a[i], ++ cnt ;
		if( cnt == n ) break ;
		tr ^= 1 ; 
	}
	cout << Ans << endl ;
	return 0 ;
}


Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main()
{
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	double t = abs((h + m / 60) * 30 - m * 6);
	t = min(t, 360 - t);
	cout << fixed << setprecision(20) << sqrt(a * a + b * b - 2 * a * b * cos(M_PI * t / 180)) << endl;

	return 0;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

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

  vector<int> p(n);
  vector<double> e(n);
  for (int i = 0; i < n; ++i) {
    int pi;
    cin >> pi;
    p[i] = pi;
    double ei = ((double)pi + 1) / 2;
    e[i] = ei;
  }

  double ret = 0.0;
  double sum = 0.0;
  for (int i = 0; i < n; ++i) {
    if (i >= k) {
      sum -= e[i - k];
    }
    sum += e[i];
    ret = max(ret, sum);
  }

  cout << std::fixed << std::setprecision(15) << ret << endl;

  return 0;
}


Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define rint register int
#define INF ((1 << 30) - 1)
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define Pair pair < int, int >
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i, k, j) for(rint i = (k); i >= (j); i--)
#define For(i, k, j) for(rint i = (k); i <= (j); i++)
#define Foe(i, u) for(rint i = lst[u], v = e[i].v; i; i = e[i].nxt, v = e[i].v)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout)
//#define int long long
const int P = 998244353; //
using namespace std;
inline void ckmax(int &a, int b) {a = max(a, b);}
inline void ckmin(ll &a, ll b) {a = min(a, b);}
inline void mulmod(int &a, int b) {a = 1ll * a * b % P;}
inline void addmod(int &a, int b) {int t = a + b; a = (t >= P ? t - P : t); }
inline int ksm(int a, int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline int inv(int a) {return ksm(a, P-2);}
namespace FastIO {
    const int SIZE=1<<16; char buf[SIZE], obuf[SIZE], str[64]; int bi=SIZE, bn=SIZE, opt;
    int read(char *s) {
        while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
        int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
    }
    bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n)return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
    void write(int x) {
        if(!x) obuf[opt++] = '0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
        if (opt>=(SIZE>>1)){fwrite(obuf, 1, opt, stdout); opt=0;}
    }
    void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf, 1, opt, stdout); opt=0;}}
    void Fflush() { if (opt) fwrite(obuf, 1, opt, stdout); opt=0;}
}
const int MAXN = 1e6 + 5;
int n, a[MAXN], b[MAXN];
signed main()
{
	#ifndef ONLINE_JUDGE
		file("pro");
	#endif
	cin >> n;
	For(i, 1, n) cin >> a[i] >>b[i];
	For(i, 1, n - 2) {
		if(a[i] == b[i] && a[i + 1] == b[i + 1] && a[i + 2] == b[i + 2]) {
			cout <<"Yes" <<endl; return 0;
		}
	}
	cout <<"No" <<endl;
    return FastIO::Fflush(), 0;
}
/*

*/



Measured memory_bytes: 3680
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    int dp[n];
    dp[0]=0;
    dp[1]= abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i-2]-h[i])+dp[i-2]);
    }
    cout<< dp[n-1];
    return 0;
}


Measured memory_bytes: 4380
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  scanf("%d", &n);
  map<int, int> cnt;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    cnt[x]++;
  }
  bool found = false;
  int ret = 1;
  for (int i = n - 1; i >= 0; i -= 2) {
    if (cnt[i] != (i == 0 ? 1 : 2)) found = true;
    ret = ret * cnt[i] % MOD;
  }
  if (found) {
    puts("0");
  } else {
    printf("%d\n", ret);
  }
  return 0;
}


Measured memory_bytes: 4096
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int N_time = scan.nextInt();

		int A_costPerHour = scan.nextInt();

		int B_teigaku = scan.nextInt();

		int ans = 0;

		ans = Math.min(N_time * A_costPerHour, B_teigaku);

		System.out.println(ans);

	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


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

int main() {
    long long n;
    long long k;
    cin >> n >> k;
    double p=0;
    for(long long i=1;i<n+1;i++){
        long long b=i;
        double pp = 1.0/n;
        for(int j=1;j<999;j++){
            if(b>=k){
                p += pp;
                break;
            }
            pp = pp / 2.0;
            b=b*2;
        }
    }
    printf("%.16f",p);
}



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

int main() {
  string s,t;
  cin >> s >> t;
  int N,c;
  N=s.size();
  c=0;
  for (int i=0;i<N;i++) {
    if (s.at(i)!=t.at(i)) {
      c++;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 3916
#下1桁が小さい(しかし0でない)物を最後に残す
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
S=a+b+c+d+e
A=a%10
B=b%10
C=c%10
D=d%10
E=e%10
ListN=[]
if A!=0:
  ListN.append(A)
if B!=0:
  ListN.append(B)
if C!=0:
  ListN.append(C)
if D!=0:
  ListN.append(D)
if E!=0:
  ListN.append(E)

if len(ListN)==0:
  print(S)
else:
  Listn=[]
  ListN.sort()
  for i in range(1,len(ListN),1):
    q=10-int(ListN[i])
    S+=q
  print(S)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#define N 1000050
#define INF (1<<30)

#define gc() getchar()

using namespace std;
int a[N],b[N],n;
inline int rd() {
	int x=0,f=1; char ch=gc();
	while (ch<'0'||ch>'9') ch=='-'?f*=-1:0,ch=gc();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc();
	return x*f;
}

int go(int x) {
	for (int i=1;i<=2*n-1;i++) b[i] = a[i] >= x;
	int p = n % 2 == 0 , cur = INF;
	int ret = b[n] ^ p;
	for (int i=n-1;i>=1;i--) {
		if (b[i] == b[i+1] && n-i < cur) {
			cur = n-i;
			ret = b[i];
		} 
	}
	for (int i=n+1;i<=2*n-1;i++) {
		if (b[i] == b[i-1] && i-n < cur) {
			cur = i-n;
			ret = b[i];
		}
	}
	return ret;
}

int main() {
	n = rd();
	for (int i=1;i<=2*n-1;i++) a[i] = rd();
	int l = 1 , r = 2 * n - 1;
	while (l < r) {
		int mid = (l + r + 1) >> 1;
		if (go(mid)) l = mid; else r = mid - 1;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 5120
using System;

public class Test
{
    public static void Main()
    {
        int S, h, m, s;
        S = int.Parse(Console.ReadLine());

        h = S / 3600;
        S = S % 3600;

        m = S / 60;
        S = S % 60;

        s = S % 60;
        Console.WriteLine("{0}:{1}:{2}", h,m,s);

    }
}


Measured memory_bytes: 18004
#include <bits/stdc++.h>
using namespace std;
 
 
int main()
{
 
    int n;
    cin>>n;

    vector<int> d(n);
    for(int i=0;i<n;i++){
        cin>>d.at(i);
    }

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

    cout<<d.at(n/2)-d.at(n/2-1)<<endl;

    return 0;
}   

Measured memory_bytes: 640
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

int main()
{
    std::string s;
    std::cin >> s;
    std::reverse(s.begin(), s.end());

    std::map<long long, long long> remaining;

    long long num = 0;
    long long exp = 1;
    for (auto c : s) {
        num += (c - '0') * exp;
        num %= 2019;
        exp *= 10;
        exp %= 2019;
        remaining[num]++;
    }

    long long ans = 0;
    for (auto t : remaining) {
        if (t.first == 0) {
            t.second++;
        }
        ans += nCr_mod(t.second, 2);
    }

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


Measured memory_bytes: 3716
// class point	の練習（クラスの高度な実装）
#include <iostream>
using namespace std;



int main() {
	int W, H, x, y, r;
	int ans = 0;

	cin >> W >> H >> x >> y >> r;

	if (x - r<0 || x + r>W)ans = 2;
	if (y - r<0 || y + r>H)ans = 2;

	if (ans)cout << "No\n";
	else cout << "Yes\n";
	
	return 0;
}



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

using namespace std;

typedef long long int ll;

const int N = 4e3 + 5;

int st[N][15];
int lg[N];

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

  int n, x;
  cin >> n >> x;
  vector < int > a (2 * n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i + n] = a[i];
    st[i][0] = st[i + n][0] = a[i];
  }

  for (int j = 1; j < 15; j++) {
    for (int i = 0; i + (1 << j) <= 2 * n; i++) {
      st[i][j] = min (st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
    }
  }
  for (int i = 2; i < N; i++) {
    lg[i] = 1 + lg[i / 2];
  }

  ll mi_cst = LLONG_MAX;
  for (int k = 0; k < n; k++) {
    ll cst = (ll)k * x;
    int p = lg[k + 1];
    for (int i = n; i < 2 * n; i++) {
      // mi from i - k to i.
      cst += min (st[i - k][p], st[i - (1 << p) + 1][p]);
    }
    mi_cst = min (mi_cst, cst);
  }

  cout << mi_cst << '\n';
}


Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define mod 1000000007
#define pb push_back
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define ll long long int
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
const double pi = 3.14159265358979323846;



void solve()
{
	int i=0,j=0,k=0,n=0,m=0;
    while(1)
    {
        cin>>k;
        if(k==0)
        break;
      i++;}
    cout<<i+1;
    
    
}
int main() {
    fast
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  

Measured memory_bytes: 3604
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, n)	for(int i=0;i<(int)(n);i++)
using namespace std;
using ll=long long;
using p=pair<int,int>;

int main(){
    int n,m;
    cin>>n>>m;
    int a,b;
    vector<vector<int>> to(n, vector<int>());
    rep(i,m){
        cin>>a>>b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    //rep(i, n) cout<<to[i][0]<<endl;
    bool flg[200010]={false};
    flg[0]=true;
    queue<int> root;
    root.push(0);
    int ans[200010];
    
    while(!root.empty()){
        int v=root.front();
        //cout<<v<<endl;
        root.pop();
        for(int x:to[v]){
            //cout<<x<<endl;
            if(flg[x]) continue;
            root.push(x);
            ans[x]=v;
            flg[x]=true;
        }
    }
    cout<<"Yes"<<endl;
    for(int i=1;i<n;i++){
        cout<<ans[i]+1<<endl;
    }
}

Measured memory_bytes: 9868
#include <cstdio>
#include <algorithm>
using namespace std;
const int mod = 998244353;
typedef long long LL;
const int MAXN = 1e6 + 6;
LL n , m , fac[MAXN] , inv[MAXN] , finv[MAXN];
int main() {
	scanf("%lld %lld" , &n , &m);
	fac[0] = 1;
	for (LL i = 1; i <= n + m; ++i) fac[i] = fac[i - 1] * i % mod;
	finv[1] = inv[1] = 1;
	finv[0] = 1;
	for (LL i = 2; i <= n + m; ++i) inv[i] = (mod - mod / i) * inv[mod % i] % mod , finv[i] = finv[i - 1] * inv[i] % mod;
	LL ans = 0;
	for (int k = 1; k <= min(n , m); ++k) {
		ans = (ans + inv[2] * fac[n - k + m - k] % mod * finv[m - k] % mod * finv[n - k] % mod * fac[2 * k] % mod * finv[k] % mod * finv[k] % mod * finv[n + m] % mod * fac[n] % mod * fac[m] % mod) % mod;
	}
	ans = (ans + max(n , m)) % mod;
	printf("%lld" , ans);
	return 0;
}

Measured memory_bytes: 25160
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
//nCr mod m
#define MOD 998244353
#define M 10000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
ll dp[4010][4010];
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(dp[n][r]+1)return dp[n][r];
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return dp[n][r]=out;
}
//nHr
ll nHr(ll n,ll r){
	if(!r&&n!=r)return 0;
	if(!r)return 1;
	return nCr(n+r-1,r-1);
}
int main(){
	int k,n;
	cin>>k>>n;
	rep(i,4010)rep(j,4010)dp[i][j]=-1;
	
	vi fact(1010,1);
	loop(i,1,1010)fact[i]=fact[i-1]*2%MOD;
	loop(i,2,2*k+1){
		ll t=0;
		loop(j,1,k+1){
			int w=i-j;
			if(w>=1&&w<=k&&j<w)t++;
		}
		int w=(i+1)%2;
		ll out=0;
		rep(j,t+1){
			if(n-j>=0)(out+=nHr(n-j,k-t*2-w+j)*nCr(t,j)%MOD*fact[j]%MOD)%=MOD;
			if(n-1-j>=0&&w)(out+=nHr(n-1-j,k-t*2-w+j)*nCr(t,j)%MOD*fact[j]%MOD)%=MOD;
		}
		cout<<out<<endl;
	}
	
	
}







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

ll lcm(ll x, ll y) { return x / __gcd(x, y) * y; }

ll solve(ll N,ll M,vector<ll> &a){
    ll num,ans;
    ans=0;
    num=1;
     while(a[0]%2==0){
        rep(i,N){
            if(a[i]%2!=0)return 0;
            a[i] /=2;
        }
        M /=2;
    }

    rep(i,N) if(a[i]%2==0) return 0;
    rep(i,N){
        num = lcm(num,a[i]);
        if(num>M) return 0;
    }

    return (M/num+1)/2;
}
int main(){
    ll N,M;
    ll num=1;
    cin >> N >> M;
    vector<ll> a(N);
    rep(i,N){
        cin >> a[i];
        a[i]/=2;
    }
    ll ans=solve(N,M,a);
    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;

public class Main {
    public static void main(String[] args) throws IOException {
        String s;
        String t;
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String[] line = bf.readLine().split("\\s");
        s = line[0];
        line = bf.readLine().split("\\s");
        t = line[0];
        int dp[][] = new int[s.length()+1][t.length()+1];
        String ans = "";
        for(int i=1;i<=s.length();i++) {
            for(int j=1;j<=t.length();j++) {
                if(s.charAt(i-1) == t.charAt(j-1)) {
                    dp[i][j] = dp[i-1][j-1] + 1;
                } else {
                    dp[i][j] = Math.max((dp[i-1][j]), dp[i][j-1]);
                }
            }
        }
        int i = s.length(), j = t.length();
        while(i>0 && j>0) {
            if(s.charAt(i-1) == t.charAt(j-1)) {
                ans += s.charAt(i-1);
                i--;
                j--;
            } else if(dp[i-1][j] > dp[i][j-1]) {
                i--;
            } else {
                j--;
            }
        }
        String rev = "";
        j = ans.length();
        while(j>0) {
            rev+= ans.charAt(j-1);
            j--;
        }
        System.out.println(rev);
    }
}


Measured memory_bytes: 100620
k = int(input())
cnt = 0
for i in range(1, k+1):
    for j in range(i, k+1):
        if i != j:
            if i%2 == 0 and j%2 == 1:
                cnt += 1
            elif i%2 == 1 and j%2 ==0:
                cnt += 1
print(cnt)

Measured memory_bytes: 39152
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;



const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int n,m,res=0,d=0,LUCKY[1000]={},sum[30005][10]={},revsum[30005][10]={};
string str;
int main() {
	cout << fixed << setprecision(18);
	cin>>n>>str;
	sum[0][str[0]-'0']=1;
	revsum[n-1][str[n-1]-'0']=1;
	for(int i=1;i<n;i++){
		
		sum[i][str[i]-'0']=1;
		for(int j=0;j<10;j++){
			
			sum[i][j]=max(sum[i][j],sum[i-1][j]);
		}
	}
	for(int i=n-2;i>=0;i--){
		
		revsum[i][str[i]-'0']=1;
		for(int j=0;j<10;j++){
			
			revsum[i][j]=max(revsum[i][j],revsum[i+1][j]);
			//cout<<i<<" "<<j<<" "<<revsum[i][j]<<endl;
		}
	}
	for(int i=1;i<n-1;i++){
		for(int l=0;l<=9;l++){
			for(int r=0;r<=9;r++){
				if(sum[i-1][l]==1&&revsum[i+1][r]==1){
				LUCKY[l*100+(str[i]-'0')*10+r]=1;
				//cout<<l*100+(str[i]-'0')*10+r<<endl;
				}
			}
		}
	}
	for(int i=0;i<=999;i++){
		if(LUCKY[i]==1){
			res++;
		}
	}
	cout<<res;
} 


Measured memory_bytes: 4992
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int H, W;
    cin >> H >> W;
    vector<string> A(H);
    rep(i, H) cin >> A[i];
    vector<int> B(H + W - 1), C(H + W - 1);
    rep(i, H) rep(j, W) {
        if(A[i][j] == 'B') {
            B[i + j] = 1;
            C[H - 1 - i + j] = 1;
        }
    }
    int minB = inf, maxB = 0;
    int minC = inf, maxC = 0;
    rep(i, H + W - 1) {
        if(B[i] == 1){
            minB = min(minB, i);
            maxB = max(maxB, i);
        }
        if(C[i] == 1) {
            minC = min(minC, i);
            maxC = max(maxC, i);
        }
    }
    
    output(max(maxB - minB, maxC - minC));
    
    
    
    return 0;
}



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

int main() {
long long w,h,x,y;
cin >> w >> h >> x >> y;
long double ans=(long double)w*h/2;
if(w%2==0&&h%2==0){
if(x==w/2&&y==h/2){
    cout << fixed << setprecision(15) << ans << " " << "1";
}
else{
    cout << fixed << setprecision(15) << ans << " " << "0";
}}
else cout << fixed << setprecision(15) << ans << " " << "0";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define forsn(i,x,y) for(long long i = (x) ; i <= (y) ; ++i)
typedef long long ll;
typedef long double ld;

int main() {
  string s;
  cin >> s;
  int res = 0;
  char prev = s[0];
  for(int i = 1;i < s.size();i++) {
    if(prev != s[i]) {
      res++;
      prev = s[i];
    }
  }
  cout << res << endl;
  return 0;
}

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

using namespace std;

struct WeightedUnionFind
{
  vector< int > data, weight;

  WeightedUnionFind(int sz) : data(sz, -1), weight(sz, 0) {}

  void unite(int x, int y, int w)
  {
    auto a = find(x), b = find(y);
    if(data[a.first] > data[b.first]) {
      swap(a, b);
      w *= -1;
    }
    x = a.first, y = b.first;
    if(x == y) return;
    data[x] += data[y];
    data[y] = x;
    weight[y] = a.second - b.second - w;
  }

  pair< int, int > find(int k)
  {
    if(data[k] < 0) return (make_pair(k, 0));
    auto par = find(data[k]);
    data[k] = par.first;
    weight[k] = (par.second += weight[k]);
    return (par);
  }

  void diff(int a, int b)
  {
    if(find(a).first != find(b).first) cout << "UNKNOWN" << endl;
    else cout << weight[a] - weight[b] << endl;
  }
};

int main()
{
  int N, M;
  while(cin >> N >> M, N) {
    WeightedUnionFind tree(N);
    while(M--) {
      char A;
      int B, C, D;
      cin >> A >> B >> C;
      --B, --C;
      if(A == '!') {
        cin >> D;
        tree.unite(B, C, D);
      } else {
        tree.diff(B, C);
      }
    }
  }
}


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

int main(){
string s;
cin>>s;
bool flag = false;
for(int i=0;i<s.size();i++){
	if(i%2==0){
	int n = s[i]-'0';
	if(n==2){
		cout<<'k';
	}
	if(n==3){
		cout<<'s';
	}
	if(n==4){
	cout<<'t';
	}
	if(n==5){
	cout<<'n';
	}
	if(n==6){
	cout<<'h';
	}
	if(n==7){
	cout<<'m';
	}
	if(n==8){
	cout<<'y';
	}
	if(n==9){
	cout<<'r';
	}
	if(n==0){
	flag = true;
	}

	}else{
	char m = s[i];
	if(flag){
		
		flag=false;
		if(s[i]=='U'){
			cout<<"nn";
			continue;
		}else{
		cout<<'w';
		}
	}
	if(m=='T')cout<<'a';
	if(m=='L')cout<<'i';
	if(m=='U')cout<<'u';
	if(m=='R')cout<<'e';
	if(m=='D')cout<<'o';

	}



}
cout<<endl;


return 0;
}



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

long long calc(string s){
  int N = s.size();
  long long ret = stoll(s);
  
  //recursive step
  for(int i=1;i<N;i++){
    string sl = s.substr(0,i);
    string sr = s.substr(i,N-i);
    ret += stoll(sl)*pow(2,sr.size()-1);
    ret += calc(sr);
  }
  
  return ret;
}

int main(){
  string s;
  cin >> s;
  cout << calc(s) << endl;
  
}

Measured memory_bytes: 4080
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll  = long long;
template <typename T> T In() { T t; cin >> t; return t;}
template <typename T> vector<T> ReadVec1(int N) {
    vector<T> vec(N);
    for(int i = 0; i < N; i++)
        vec[i] = In<T>();
    return move(vec);
}
template <typename T> vector<vector<T>> Vec2(int i, int j, T ini = 0) {
    vector<vector<T>> vec(i, vector<T>(j, ini));
    return move(vec);
}
template <typename T> vector<vector<vector<T>>> Vec3(int i, int j, int k, T ini = 0) {
    vector<vector<vector<T>>> vec(i, vector<vector<T>>(j, vector<T>(k, ini)));
    return move(vec);
}

template <typename T> constexpr T gcd(T m, T n){
    return n == 0 ? m : gcd(n, m % n);
}
template <typename T> constexpr T lcm(T m, T n) {
    return n == 0 or m == 0 ? 0 : m  / gcd(m, n) * n;
}

ll count(ll A, ll C, ll D) { 
    return A - (A / C) - (A / D) + (A / lcm(C, D)); 
}

struct AB {
    int A, B;
    AB(int a, int b) { A = a, B = b;}
    bool operator>(const AB &rhs)const  { return B > rhs.B; }
};

int main() { 
    int N = In<int>();
    priority_queue<AB, vector<AB>, greater<AB>> queue;
    for(int i = 0; i < N; i++) {
        queue.push(AB(In<int>(), In<int>()));
    }

    ll time = 0;
    while(!queue.empty()) {
        AB ab = queue.top();
        queue.pop();
        if(time + ab.A > ab.B){
            cout << "No" << endl;
            return 0;
        }
        else{
            time += ab.A;
        }
    }
    cout << "Yes" << endl;
}

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

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

	ll time = 0;
	ll pos = 0;
	while (pos < x) {
		time++;
		pos = time * (time + 1) / 2;
	}
	cout << time << endl;
}

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

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

  vector<int> l(N);
  for (int i = 0; i < N; i++)
    cin >> l[i];
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());

  int ans = 0;
  for (int i = 0; i < K; i++)
    ans += l[i];
  cout << ans << endl;
}

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

long long a, b, c, d, k, t, l;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> a >> b >> c >> d;
		
	k = b / c - (a + c - 1) / c;
	t = b / d - (a + d - 1) / d;
	long long g = __gcd(c, d);
	g = c * d / g;
	l = b / g - (a + g - 1) / g;
	
	cout << b - a - k - t + l;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
    FAST
    ll x,a;
    cin>>x>>a;
    if(x<a)cout<<0;
    else cout<<10;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m,x,y;
int main()
{
	scanf("%d%d%d%d",&n,&m,&x,&y);
	for(int i=1;i<=n;printf("\n"),i++)
		if(i<=y) for(int j=1;j<=m;j++) printf(j<=x?"1":"0");
		else for(int j=1;j<=m;j++) printf(j<=x?"0":"1");
}

Measured memory_bytes: 1152
def main():
	N = int(input())
	ans = 0
	a_end = 0
	b_begin = 0
	a_end_b_begin = 0
	for i in range(N):
		S = input()
		ans += S.count("AB")
		if S[0] == "B":
			if S[-1] == "A":
				a_end_b_begin += 1
				continue
			b_begin += 1
		if S[-1] == "A":
			a_end += 1
	if a_end_b_begin > 0:
		ans += a_end_b_begin if a_end+b_begin>0 else a_end_b_begin-1
	ans += min(a_end, b_begin)
	print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int main()
{
	int n;
	cin >> n;
	vector<ll> al(n);
	vector<ll> suml(n);
	rep(i, n) {
		ll a;
		cin >> a;
		al[i] = a;
		if (i == 0)
		{
			suml[i] = a;
		}
		else
		{
			suml[i] += suml[i - 1] + a;
		}
	}
	ll ans = 0;
	rep(i, n) {
		ans += (al[i] % MOD) * ((suml[n - 1] - suml[i]) % MOD);
		ans %= MOD;
	}
	cout << ans << endl;
	system("pause");
}



Measured memory_bytes: 6404
#include <iostream>
using namespace std;
int main(){
    int x;
    cin >> x;
    if(x>=5)
    {
       int k=x/500;
       int l = (x%500)/5;
       long out = 1000*k + 5*l  ;
      cout << out;
     }
     else cout << 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char str[2000050];
int len,ans,nowlen=1,last,book[2000050],flag;
int main()
{
	cin>>str+1;
	len=strlen(str+1);
	str[0]=':';
	last=len;
	while(str[last]==str[last-1])last--;
	last--;
	for(int i=1;i<=last;i++)
	{
		if(str[i]!=str[i-1])
		{
			ans++;
			nowlen=2;
			book[i]=1;
			flag=i;
			continue;
		}
		if(str[i]==str[i-1]&&book[i-1]>1)
		{
			ans++;
			nowlen=2;
			book[i]=1;
			flag=i;
			continue;
		}
		if(str[i]==str[i-1])
		{
			if(nowlen==1)
			{
				ans++;
				nowlen=2;
				book[i]=1;
				flag=i;
				continue;
			}
			if(nowlen==2)
			{
				ans++;
				nowlen=1;
				book[i]=book[i+1]=2;
				i++;
				flag=i;
				continue;
			}
		}
	}
	int rem=len-flag;
	if(rem%3==0)ans+=rem/3*2;
	else ans+=rem/3*2+1;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;
typedef vector<map<lli,lli>> graph;

lli n;
vll a;
lli x;
lli y;
lli z;

int main(){
	cin >> n;
	a = vll(n);
	for(lli i = 0;i < n;i++){
		cin >> a[i];
	}
	for(lli i =0 ;i < n;i++){
		if(a[i] % 4 == 0){
			x++;
		}
		if(a[i] % 2 == 1){
			y++;
		}
	}
	if(x >= y){
		cout << "Yes" << endl;
		return 0;
	}
	if(x+y == n && x+1 == y){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long gcd(long long m,long long n)
{
	long long rem;
	while(n!=0)
	{
		rem=m%n;
		m=n;
		n=rem;
	}
	return(m);
}
int main()
{

        long long n,count=0;
        cin>>n;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                for(int k=1;k<=n;k++){
                    long long g=gcd(i,j);
                    count+= gcd(g,k);
                }
            }
        }
        cout<<count;
    }

Measured memory_bytes: 3632
num = int(input())
string = input()

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
assert len(alphabet) == 26

d = {char:alphabet.index(char) for char in alphabet}

new_string = ""
for char in string:
    new_string += alphabet[(d[char] + num) % 26]
print(new_string)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >>n;
    int a[n];
    for(int i=0;i<=n-1;i++){
        cin >>a[i];
    }
    int min=a[0],max=a[0];
    for(int j=0;j<=n-1;j++){
        if(min>=a[j]) min=a[j];
    }
    for(int j=0;j<=n-1;j++){
           if(max<=a[j]) max=a[j];
       }
    int ave=(max-min+1)/2;
    
    cout<<ave<<endl;
    
}



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

ab = [list(map(int, input().split())) for _ in range(n)]

dp = [0]*m

for i in range(n):
    for j in range(ab[i][0]):
        k = ab[i][j+1]
        dp[k-1] +=1
        
print(dp.count(n))

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


int main(){
	int x, y;
	cin >> x >> y;
	if(y%2==0&&2*x<=y&&y<=4*x){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}









Measured memory_bytes: 3532
// B - Some Sums
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> n >> a >> b;
  vlli d(n);
  repe(i, 1, n)
  {
    s = to_string(i);
    rep(j, 0, s.size())
    {
      c = s[j] - '0';
      ans += c;
      // cout << "s[" << j << "]: " << s[j] << " ans: " << ans << endl;
    }
    if (ans >= a && ans <= b)
    {
      count += i;
      // cout << "count: " << count << endl;
    }
    ans = 0;
  }
  cout << count << endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/21  Problem: ABC 061 B / Link: http://abc061.contest.atcoder.jp/tasks/abc061_b  ----- */


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

	LL N, M; cin >> N >> M;
	vector<LL> x(M), y(M);
	VL a(N);
	for (int i = 0; i < M; ++i) {
		cin >> x[i] >> y[i];
		x[i]--, y[i]--;
		a[x[i]]++; a[y[i]]++;
	}
	FOR(i, 0, N) {
		cout << a[i] << endl;
	}

	return 0;
}


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

alist = list(map(int,input().split()))

apploveflag = True

for a in range(n):
    if alist[a] % 2 == 0:
        if alist[a] % 3 != 0 and alist[a] % 5 != 0:            
            
            apploveflag = False


if apploveflag:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

string s;
int N, W, S, E;


int main()
{
	cin >> s;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'N') N++;
		if (s[i] == 'W') W++;
		if (s[i] == 'S') S++;
		if (s[i] == 'E') E++;
	}

	if (N + S > 0 && S * N == 0) {
		cout << "No" << endl;
		return 0;
	}

	if (E + W > 0 && E * W == 0) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;

	return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll X[100005], Y[100005];
ll NX[100005], MY[100005];

int main()
{
    int N, M;
    cin >> N >> M;
    REP(i, N)
    {
        cin >> X[i];
    }
    REP(i, M)
    {
        cin >> Y[i];
    }
    {
        //! X軸の使用回数
        int n = N - 1;
        FOR(i, (n + 1) / 2 + 1, 1)
        {
            ll t = ((n - 2 * (i - 1)) * i + (i - 1) * i) % MOD;
            NX[i - 1] = NX[n - i] = t;
        }
    }
    {
        //! Y軸の使用回数
        int m = M - 1;
        FOR(i, (m + 1) / 2 + 1, 1)
        {
            ll t = ((m - 2 * (i - 1)) * i + (i - 1) * i) % MOD;
            MY[i - 1] = MY[m - i] = t;
        }
    }

    ll LX = 0, LY = 0;
    REP(i, N - 1)
    {
        LX += (X[i + 1] - X[i]) * NX[i];
        LX %= MOD;
    }
    REP(i, M - 1)
    {
        LY += (Y[i + 1] - Y[i]) * MY[i];
        LY %= MOD;
    }
    cout << (LX * LY) % MOD << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define rkc ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define rfl(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
#define test ll t;cin>>t;while(t--)
#define lld long double
#define vpp vector<pair<ll,ll>>
#define ff first
#define ss second
const ll M = 1e9 + 7;
const double pi  =3.141592653589793238463;
int main()
{
    rkc;
    ll n,c=0;
    cin>>n;
    ll a[n];
    fl(i,0,n)cin>>a[i];
    if(n==1)cout<<"Yes";
    else{
    fl(i,0,n-1)
    {
        if(a[i+1]-a[i]>=1)c++;
        else if(a[i+1]-a[i]==0)c++;
        else if(a[i+1]-a[i]==-1)
        {a[i+1]=a[i+1]+1;c++;}
        else {cout<<"No";return 0;}
    }
    //cout<<c<<endl;
    cout<<"Yes";}
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000007;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct UnionFind {
    vector<int> par;
    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
        }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    for (int i = 0; i < M; ++i) {
        int A, B;
        cin >> A >> B;
        --A, --B;
        uf.unite(A, B);
    }
    int res = 0;
    for(int i = 0; i < N; ++i) {
        if (uf.par[i] == i) {
            ++res;
        }
    }
    cout << res-1 << endl;

    return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
signed main(){
    map<char, int>mp;
    bool flag=true;
    for(int i=0;i<4;i++){char tmp;cin>>tmp;mp[tmp]++;}
    for(auto it=mp.begin();it!=mp.end();++it){if(it->second!=2){flag=false;break;}}
    cout<<(flag?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include "cmath"
#include <cstdlib>

using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    vector<ll> dp(N+1);
    for (int i = 0; i < N+1; i++) {
        if (i == 0 || i == 1) {
            dp[i] = 0;
        } else if (i == 2) {
            dp[i] = dp[i-1] + abs(h[i-1] - h[i-2]);
        } else {
            ll a = dp[i-1] + abs(h[i-1] - h[i-2]);
            ll b = dp[i-2] + abs(h[i-1] - h[i-3]);
            dp[i] = (a > b ? b : a);
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1408
prime = {}
not_prime = {}

(2..1000000).each do |i|
  if not_prime[i] then
    next
  end
  prime[i] = true
  j=i+i
  while j < 1000000
    not_prime[j] = true
    j+=i
  end
end

while n = STDIN.gets
  n = n.chomp.to_i
  count=0
  (2..n).each do |i|
    if prime[i] then
      count += 1
    end
  end
  puts count
end

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

#全てABピザ
ans1=max(x,y)*2*c
#AはABピザ　BはBピザ
ans2=x*2*c+max(y-x,0)*b
#BはABピザ　AはAピザ
ans3=y*2*c+max(x-y,0)*a
#全てAピザBピザ
ans4=a*x+b*y
print(min(ans1,ans2,ans3,ans4))

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り　0:ON　1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if(system==0) param.add(sc.next());
				if(system==1) param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		if(param.get(0).equals("a") || param.get(0).equals("i") || param.get(0).equals("u")
				|| param.get(0).equals("e") || param.get(0).equals("o")){
			System.out.println("vowel");
		} else {
			System.out.println("consonant");
		}
	}
}

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

using namespace std;

using int64 = long long;

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

  int a, b;
  cin >> a >> b;
  if (abs(a - b) % 2 == 1) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << (a + b) / 2 << endl;
  }
}


Measured memory_bytes: 256
import itertools
# x,y = map(int,input().split())

# s=list(input())
a=input()
a=int(a)

li = list(map(int,input().split()))	

# s = [2, 3, 1, 4, 5]
# sorted(range(len(s)), key=lambda k: s[k])
max=0
for i in itertools.combinations(li,2):
    max+=i[0]*i[1]
print(max)

Measured memory_bytes: 3060