akhauriyash/Code-Regression huggingface dataset:
function convert_753_from_4b(based3){
  const str = based3.split('')
  var result = '';
  for(var i=0;i<str.length;i++){
    if(str[i]=='3'){result+='7'}
    if(str[i]=='2'){result+='5'}
    if(str[i]=='1'){result+='3'}
    if(str[i]=='0'){result+='0'}
  }
  return parseInt(result);
}

function generate_753_number(number){
  if(n.length==10){return n}
  return [generate_753_number(number + '3'),generate_753_number(number + '5'),generate_753_number(number + '7')]
}

function is_753(number){
  return (number==3 || number==5 || number==7)
}

function is_753_number(n){
  const splitted = n.toString().split('');
  const numbers = new Set(splitted);
  if(numbers.size!=3){return false;}

  return numbers.has('3') && numbers.has('5') && numbers.has('7')
}

function main(input){
  const N = parseInt(input.trim());

  var result=0;
  for(var i=0;i<=1048569;i++){
    var based4 = i.toString(4);
    var num_753 = convert_753_from_4b(based4);

    if(num_753>N){break;}

//console.log([i,based4,num_753])

    if(is_753_number(num_753)){
      result++;
      //console.log(num_753);
    }
  }


  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin','utf8'))

Measured memory_bytes: 16752
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<string,int> pairs;
bool compare(pairs x, pairs y)
{
    if(x.first != y.first)
    {
        return x.first<y.first;
    }
    else
    {
        return x.second>y.second;
    }
}
int main() 
{ 
    int n;
    cin>>n;
    vector <pairs> s;
    int num;
    string str;
    for(int i=0;i<n;i++) 
    {
        cin>>str;
        cin>>num;
        s.push_back(make_pair(str,num));
    }
    vector <pairs>::iterator it;
    vector <pairs> v=s;
    sort(s.begin(), s.end(), compare);
    for(it=s.begin();it!=s.end();it++)
    {
        pairs p = *it;
        vector<pairs>::iterator itr = find(v.begin(), v.end(),p);
        cout<<distance(v.begin(), itr)+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <limits.h>

typedef long long ll;

ll A[100005];
ll sell[100005];

int main(){

	int N;
	ll T;

	scanf("%d %lld",&N,&T);

	int i;

	for(i=0;i<N;i++){
	scanf(" %lld",&A[i]);
	}

	ll maxA=A[N-1];

	sell[N-1]=maxA;

	for(i=N-2;i>=0;i--){
		if(maxA<A[i]){maxA=A[i];}
		sell[i]=maxA;
	}
	maxA=-LLONG_MAX;
	for(i=0;i<N;i++){
		if(sell[i]-A[i]>maxA){maxA=sell[i]-A[i];}
	}
	int ans=0;

	for(i=0;i<N;i++){
		if(sell[i]-A[i]==maxA){ans++;}
	}

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

	return 0;
}

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

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

	vector<long> A;

	for (int a = 0; a < N; a++) {
		int newInt;
		cin >> newInt;
		A.push_back(newInt);
	}

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

	long now = 0;
	long max = 0;
	long max2 = 0;

	for (int a = N-1; a >= 0; a--) {
		if (now != A[a]) {
			now = A[a];
		}
		else {
			if (max == 0) {
				max = A[a];
				now = 0;
			}
			else {
				max2 = A[a];
				break;
			}
		}
	}

	cout << max*max2 << endl;
	
}



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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

int main() {
    vector<vector<int>>c(3,vector<int>(3));
    rep(i,3){
        rep(j,3){
            cin>>c[i][j];
        }
    }

    vector<int>a(3),b(3);
    a[0]=0,a[1]=c[0][1]-c[0][0],a[2]=c[0][2]-c[0][0];
    b[0]=c[0][0],b[1]=c[1][0],b[2]=c[2][0];

    bool jdg=true;
    rep(i,3){
        rep(j,3){
            if(c[i][j]!=a[j]+b[i]){
                jdg=false;
                break;
            }
        }
    }

    if(jdg){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    /*
    rep(i,3){
        rep(j,3){
            cout<<c[i][j]<<" ";
        }
        cout<<endl;
    }

    rep(i,3){
        cout<<a[i]<<" ";
    }
    cout<<endl;

    rep(i,3){
        cout<<b[i]<<" ";
    }
    cout<<endl;
    */


}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n=int(input())
l=[list(map(int,input().split())) for _ in [0]*n]
dp=[[-float("inf") for _ in [0]*3] for _ in [0]*n]
for i in range(3):
    dp[0][i]=l[0][i]
for i in range(1,n):
    for j in range(3):
        dp[i][j]=max(dp[i-1][(j+1)%3]+l[i][j],dp[i-1][(j+2)%3]+l[i][j])
print(max(dp[n-1][i] for i in range(3)))

Measured memory_bytes: 47992
// Maximum_Profit.cs

using System;

class Maximum_Profit {
	public static void Main() {

		int n;
		n = int.Parse(Console.ReadLine());
		int[] a = new int[n];

		for(int i = 0; i < n; i++) {
			a[i] = int.Parse(Console.ReadLine());
		}

		int max = a[1] - a[0];
		int min = a[0];
		for(int i = 1; i <= n - 1; i++) {
			max = Math.Max(max, a[i] - min);
			min = Math.Min(min, a[i]);
		}

		Console.WriteLine(max);

	}
}

Measured memory_bytes: 10736
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
typedef pair<int, int> P;

P f(int x) {
	int a = x % 10;
	int b = 0;
	while (x) {
		b = x;
		x /= 10;
	}
	return P(a, b);
}

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int n; 
		cin >> n;
		map<P, int> freq;
		for (int i = 1; i <= n; ++i) {
			P p = f(i);
			freq[p]++;
		}
		long long ans = 0;
		for (int i = 1; i <= n; ++i) {
			P p = f(i);
			P q(p.second, p.first);
			ans += freq[q];
		}
		cout << ans << endl;
		return;
}

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



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author toshif
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyReader in = new MyReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, MyReader in, PrintWriter out) {
            int[] g = new int[13];
            g[1] = 0;
            g[3] = 0;
            g[5] = 0;
            g[7] = 0;
            g[8] = 0;
            g[10] = 0;
            g[12] = 0;

            g[4] = 1;
            g[6] = 1;
            g[9] = 1;
            g[11] = 1;

            g[2] = 2;

            int x = in.nextInt();
            int y = in.nextInt();

            if (g[x] == g[y]) {
                out.println("Yes");
            } else {
                out.println("No");
            }

        }

    }

    static class MyReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public MyReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23636
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
using namespace std;

using ll = long long;
const int INF = 1001001001;

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

vector<vector<int>> hen(9);
int cnt = 0;

void f(set<int> nokori, int now)
{
  if (nokori.empty()) {
    cnt++;
    return; 
  }
  for (int x : hen[now]) {
    auto it = nokori.find(x);
    if (it != nokori.end()) {
      set<int> nkr = nokori;
      auto itr = nkr.find(x);
      nkr.erase(*itr);
      f(nkr, *itr);
    }
  }
}

int main()
{
  int n, m;
  cin >> n >> m;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    hen[a].push_back(b);
    hen[b].push_back(a);
  }

  set<int> tyouten;
  for (int i = 2; i <= n; i++) {
    tyouten.insert(i);
  }
  f(tyouten, 1);

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;

int main()
{
	int h[1000],w[1000];
	int i=0;
	int n=1;
	
	while(1){
		cin >> h[i] >> w[i];
		if(h[i] ==0 && w[i] == 0)	break;
		i++;
		n++;
	}
	
	for(i=0; i<n; i++){
		for(int j=1; j<=h[i]; j++){
			for(int m=1; m<=w[i]; m++)
				cout << '#';
			cout << endl;
		}
		if(i<= n-2)
			cout << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int a,b;
    cin >> a >> b;

    vector<int> pmn;
    pmn.push_back(a+b);
    pmn.push_back(a-b);
    pmn.push_back(a*b);

    decltype(pmn)::iterator max = std::max_element(pmn.begin(), pmn.end());
    cout << *max;
}


Measured memory_bytes: 256
from itertools import combinations

num_sticks = input()
sticks = [int(x) for x in input().split()]

triplets = combinations(sticks, 3)

count = 0
for triplet in triplets:
    if (
        (triplet[0] + triplet[1] > triplet[2])
        and (triplet[0] + triplet[2] > triplet[1])
        and (triplet[1] + triplet[2] > triplet[0])
    ):
        if len(set(triplet)) < 3:
            continue
        count += 1

print(count)

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

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

ll A,B,C;

void solve(){
    if((A+B) >= 10)
        cout << "error" << endl;
    else
        cout << A+B << endl;
}

int main(){
    cin >> A >> B;

    solve();
}


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

int main(){
    ll a, b, c, d;  cin >> a >> b >> c >> d;
    ll x=c, y=d, tmp=1;
    if(y<x) swap(x, y);
    while(1){
        if(y%x==0)  break;
        tmp = x;
        x = y%x;
        y = tmp; 
    }
    ll ma = (a-1)/c + (a-1)/d - (a-1)/(c*d/x);
    ll mb = b/c + b/d - b/(c*d/x);
    cout << b-a+1 - (mb - ma) << endl;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

st = set()
for i in range(2**n):
    sm = 0
    for j in range(n):
        if ((i>>j)&1):
            sm = sm+a[j]
            st.add(sm)
q = int(input())
m = list(map(int,input().split()))
for i in range(q):
    if (m[i] in st):
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5656
//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prinp(p) cout<<p.first<<" "<<p.second<<endl
#define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7,MAX = 1e6+5;
const ll INF = 1e18+5;

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
              
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define int ll
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);

using namespace std;

const int maxn = (int)1e5 + 100;
const int mod = (int)1e9 + 7;
const int P = (int) 1e6 + 7; 

#define inf mod

typedef long double ld;                          
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;                        


int n, m, dp[3111][3111];
string s, t;
int calc(int i, int j){
  if(!i || !j) return 0;
  int &res = dp[i][j];
  if(res != -1) return res;
  res = 0; 
  if(s[i] == t[j]) res = calc(i - 1, j - 1) + 1;
  else res = max(calc(i - 1, j), calc(i, j - 1));
  return res;
}
string path(int i, int j){
  if(!i || !j) return "";
  if(s[i] == t[j]) return path(i - 1, j - 1) + s[i];
  else{
    if(dp[i - 1][j] == dp[i][j]) return path(i - 1, j);
    else return path(i, j - 1);
  }
}
main () {
  cin >> s >> t;
  n = sz(s), m = sz(t);
  s = '1' + s, t = '1' + t;
  memset(dp, -1, sizeof(dp));
  calc(n, m);
  cout << path(n, m); 
}


Measured memory_bytes: 76288
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(lcm2(a, b));
        sc.close();

    }

    private static long lcm2(long m, long n) {
        return m * n / gcd(m, n);
    }

    private static long gcd(long m, long n) {
        if (m < n)
            return gcd(n, m);
        if (n == 0)
            return m;
        return gcd(n, m % n);
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    int f=0;
    for(int i=n;i>0;i/=10){
        f+=i%10;
    }
    if(n%f==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define sqr(x) ((x)*(x))
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define y1 asdfghjkl
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const ll N = 2e6;
const ll INF = 1e18 + 7;
 
void boost() {
     ios_base :: sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
}
void file() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
}
ll fast_pow(ll a, ll b){
	ll res = a, ret = 1;
	while(b){
		if(b&1)
			ret = (ret*res)%mod;
		res = (res*res)%mod;
		b>>=1;
	}
	return ret;
}
ll o[N];
int main() {
	boost();
	ll n,ans=0;
	cin >> n;
	for(int a = 1; a <= n; a++) {
		for(int b = 1; b * a <= n; ++b){
			if(a*b==n)
				continue;
			o[a]++;
		}
	}
	for(int i = 0; i < N;++i)
		ans+=o[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 11396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=998244353;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=5e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=1e6+10;
	//------------------FIXED------------------
	int dp[N];
	void main()
	{
		int n=qread(),S=qread();int ans=0;
		fo(i,1,n)
		{
			int aa=qread();if(aa>S) continue;
			if(aa==S) {add(ans,1ll*i*(n-i+1)%MOD);continue;}
			add(ans, 1ll*dp[S-aa]*(n-i+1)%MOD );fd(j,S,aa+1) add(dp[j],dp[j-aa]);add(dp[aa],i);
		}write(ans);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 119296
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  ll A,B,m;
  cin>>A>>B>>m;
  vector<ll>a(A),b(B);
  rep(i,A)cin>>a[i];
  rep(i,B)cin>>b[i];
  ll ans=INF;
  rep(i,m){
    ll x,y,c;
    cin>>x>>y>>c;
    x--;y--;
    chmin(ans,a[x]+b[y]-c);
  }
  sort(all(a));sort(all(b));
  cout<<min(a[0]+b[0],ans);
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


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

const int INF= 1e9 +5;
typedef std::vector<lli> vi;
typedef pair<int,int> ii;


void max_self(int& a,int b)
{
    a=max(a,b);
}

void dfs(int i,vi edges[],vi &dist,vector<bool>&vis,vi &indeg)
{
    vis[i]=true;
    for(auto x:edges[i])
    {
        dist[x]=max(dist[x],dist[i]+1);
        indeg[x]--;
        if(indeg[x]==0)
        {
            dfs(x,edges,dist,vis,indeg);
        }
    }
}

int main() {

    int n,m;
    scanf("%d%d",&n,&m);
    
    vi edges[n+1];
    vi indeg(n+1,0);
    for(int i=0;i<m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        edges[x].pb(y);
        indeg[y]++;
    }
   
    
    vi dist(n+1,0);
    
    vector<bool>vis(n+1);
    
    for(int i=1;i<=n;i++)
    {
        if(!vis[i] && indeg[i]==0)
        {
            dfs(i,edges,dist,vis,indeg);
        }
    }
    
    
    
    lli ans=0;
    for(auto x:dist)
    {
        ans=max(ans,x);
    }
    
    cout<<ans<<endl;
	return 0;
}

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

int main(void) {
  long long A, B, C;
  cin >> A >> B >> C;
  if (A % 2 != 0 && B % 2 != 0 && C % 2 != 0) {
    cout << 0 << endl;
  } else if (A == B && B == C) {
    cout << -1 << endl;
  } else {
    long long ans = 0;
    while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
      long long A_, B_, C_;
      A_ = (B + C) / 2;
      B_ = (A + C) / 2;
      C_ = (A + B) / 2;
      A = A_;
      B = B_;
      C = C_;
      ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a[100], ave, ans;

int main() {
	cin >> n;
	rep(i,n) {
		cin >> a[i];
		ave += a[i];
	}
	ave = (int)round((double)ave / n);
	rep(i,n) ans += (ave-a[i])*(ave-a[i]);
	cout << ans << ln;
}

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


int main() {
    ll h; cin >> h;
    ll x=0;
    while(h>0){
        h/=2;
        x++;
    }
cout << fixed << setprecision(0) << pow(2,x)-1 << endl;
}

Measured memory_bytes: 256
class Dice:
  def __init__(self):
    self.top = 1
    self.front = 2
    self.left = 4

  @property
  def bottom(self):
    return 7 - self.top

  @property
  def back(self):
    return 7 - self.front

  @property
  def right(self):
    return 7 - self.left

  def move(self, direction):
    if direction == 'N':
      bottom = self.bottom
      self.top = self.front
      self.front = bottom
    elif direction == 'W':
      right = self.right
      self.left = self.top
      self.top = right
    elif direction == 'E':
      bottom = self.bottom
      self.top = self.left
      self.left = bottom
    elif direction == 'S':
      back = self.back
      self.front = self.top
      self.top = back

  def __repr__(self):
    print(self.__dict__)

dice = Dice()
numbers = input().split()
for cmd in input():
  dice.move(cmd)
print(numbers[dice.top - 1])

Measured memory_bytes: 7544
import numpy as np
import sys

input = sys.stdin.readline

A,B,C = map(int,input().split())


if A == B == C and A%2 == 0 and B%2 == 0 and C%2 == 0:
    ans = -1
else:
    ans = 0
    while A%2 == 0 and B%2 == 0 and C%2 == 0:
        next_a = C/2 + B/2
        next_b = A/2 + C/2
        next_c = A/2 + B/2
        A = next_a
        B = next_b
        C = next_c
        ans += 1

print(ans)


Measured memory_bytes: 21656
a = []
for _ in range(3):
    a.append(list(map(int, input().split())))
n = int(input())
b = []
for _ in range(n):
    b.append(int(input()))

box = [[0] * 3 for _ in range(3)]

for i in range(3):
    for j in range(3):
        for k in range(n):
            if b[k] == a[i][j]:
                box[i][j] = 1

if box[2][0] == 1 and box[2][1] == 1 and box[2][2] == 1:
    print("Yes")
elif box[0][0] == 1 and box[0][1] == 1 and box[0][2] == 1:
    print("Yes")
elif box[1][0] == 1 and box[1][1] == 1 and box[1][2] == 1:
    print("Yes")
elif box[0][0] == 1 and box[1][0] == 1 and box[2][0] == 1:
    print("Yes")
elif box[0][1] == 1 and box[1][1] == 1 and box[2][1] == 1:
    print("Yes")
elif box[0][2] == 1 and box[1][2] == 1 and box[2][2] == 1:
    print("Yes")
elif box[0][2] == 1 and box[1][1] == 1 and box[2][0] == 1:
    print("Yes")
elif box[0][0] == 1 and box[1][1] == 1 and box[2][2] == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3188
X=int(input())

div=[]
for i in range(1, int(X**0.5)+1):
        if X % i == 0:
            div.append(i)
            if i != X // i:
                div.append(X//i)

for k in div:
    x=X//k
    b=(-k)//2
    while True:
        f=((b+k)**5-b**5)//k
        if f==x:
            print(b+k,b)
            exit()
        if f>x:
            #print("over")
            break
        b-=1
    b=(-k)//2
    while True:
        f=((b+k)**5-b**5)//k
        if f==x:
            print(b+k,b)
            exit()
        if f>x:
            #print("over")
            break
        b+=1

Measured memory_bytes: 9480
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>

namespace TokorotenLab
{
    /*
    Arguments:
        Search range: [begin, end)
        Target function: f(x)
    Requirement:
        f(x) => { false, ..., false, true, ..., true }
    Judge:
        true_bound == begin => All f(x) are true
        true_bound == end => All f(x) are false
    */
    std::pair<long long, long long> binary_search(long long begin, long long end, std::function<bool(long long)> f)
    {
        long long false_bound = begin - 1LL; // ( ..., false_bound] => false
        long long true_bound = end; // [true_bound, ... ) => true
        long long x;

        while(true_bound - false_bound > 1LL)
        {
            x = false_bound + (true_bound - false_bound) / 2LL;
            if(f(x))
            {
                true_bound = x;
            }
            else
            {
                false_bound = x;
            }
        }

        return std::make_pair(false_bound, true_bound);
    }
}

using namespace std;

int main()
{
    int a, b, c;

    cin >> a >> b >> c;

    cout << max(0, c - (a - b)) << endl;

    return 0;
}

Measured memory_bytes: 256
#Guess The Number https://atcoder.jp/contests/abc157/tasks/abc157_c
N,M = map(int,input().split())
Num_List = [[] for i in range(N)]
for i in range(M):
    Keta,Rule = map(int,input().split())
    Num_List[Keta-1].append(Rule)

for k in range(N):
    Num_List[k]=list(set(Num_List[k]))

Answer=""
for m in range(N):
    Length = len(Num_List[m])
    if Length == 0:
        if (m == 0) & (N != 1):
            Answer += "1"
        else:
            Answer += "0"
    elif Length == 1:
        if (m == 0) & (Num_List[m][0] == 0) & (N != 1) :
            Answer = "-1"
            break
        else:
            Answer += str(Num_List[m][0])
    else:
        Answer = "-1"
        break

print(int(Answer))

Measured memory_bytes: 9124
from collections import deque

N,K = map(int,input().split(" "))

V = deque(map(int,input().split(" ")))

def search(N,K,V,score):
    ans = 0
    for i in range(min(N,K)+1):
        for j in range(min(N,K)-i+1):
            score = []
            for a in range(i):#do operation A
                score.append(V[a])
            for b in range(j):#do operation B
                score.append(V[len(V)-b-1])
            score=sorted(score)
            counter = 0

            while(counter < K-i-j):#do operation C,D
                if len(score)== 0:
                    break;
                if score[0]<0:
                    score.pop(0)
                    counter +=1
                else:
                    break;   
            ans = max(ans,sum(score))

    return ans

score = []
ans = search(N,K,V,score)
print(ans)

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

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define MOD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int n = s.size();
    bool pal = true;
    for(int i=0; i<n/2; i++){
        if(s[i] != s[n-i-1]){
            pal = false;
            break;
        }
    }
    for(int i =0; i<(n-1)/2; i++){
        if(s[i]!= s[((n-1)/2)-1-i]){
            pal = false;
            break;
        }
    } for(int i =((n+3)/2)-1; i<n; i++){
        if(s[i]!= s[n-1-i]){
            pal = false;
            break;
        }
    }

    if(pal){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    
}

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

#define ff first
#define ss second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ep emplace
#define MOD 1000000007LL
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define for1(i, n) for(int i = 1; i <= int(n); i++)
#define ford(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define fore(i, a, b) for(int i = int(a); i <= int(b); i++)
#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

typedef long long ll;

const ll oo = 1000000000000000000;
const int N = 100005;

char s[N];

int main(){

    scanf("%s", s);

    string ss = s;

    printf("%s\n", ss.find("AC") != string::npos ? "Yes": "No");



    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
/*bool ok(int *q,int m,int h,int count){
  for(int i=0;i<count;i++){
    if(q[i]>m) continue;
    for(int j=0;j<count;j++){
      if(q[i]+q[j]<=m&&q[i]+q[j]>h) return true;
    }
  }
  return false;
  }*/
int main(){
  int n,m;
  while(cin>>n>>m){
    if(n==0&&m==0) return 0;
    int data[n+1];
    int q[(n+1)*(n+1)/2];
    int ans = 0;
    for(int i=0;i<n;i++) cin >> data[i];
    data[n] = 0;
    int count = 0;
    for(int i=0;i<=n;i++){
      for(int j=i;j<=n;j++){
	if(data[i]+data[j]>m) continue; 
	  q[count] = data[i] + data[j];
	  count++;
      }
    }
    sort(q,q+count);
    int j = count - 1;
    for(int i=0;i<count;i++){
      while(0<=j&&m<q[i]+q[j]) j--;
      if(j==-1) break;
	ans = max(ans,q[i]+q[j]);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3140
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    vector<int> candies(3);
    rep (i, 3) { cin >> candies[i]; }

    sort(ALL(candies));

    if (candies[0] + candies[1] == candies[2])
    {
        cout << "Yes" << "\n";
    }
    else
    {
        cout << "No" << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		while(true) {
			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();

			if(op.equals("?")) {
				break;
			}

			if(op.equals("+")) {
				System.out.println(a + b);
			} else if(op.equals("-")) {
				System.out.println(a - b);
			} else if(op.equals("*")) {
				System.out.println(a * b);
			} else {
				System.out.println(a / b);
			}
		}
	}

}



Measured memory_bytes: 26120
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, k = LI()
dp = [[[0]*n**2*4 for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1
for i in range(n):
    for j in range(i+1):
        for l in range(k+1):
            dp[i+1][j+1][l+2*(j+1)] += dp[i][j][l]
            dp[i+1][j+1][l+2*(j+1)]%=mod
            dp[i+1][j][l+2*j] += dp[i][j][l]*(j*2+1)
            dp[i+1][j][l+2 * j] %= mod
            if j!= 0:
                dp[i+1][j-1][l+(j-1)*2] += dp[i][j][l]*j*j
                dp[i+1][j-1][l+(j-1)*2]%=mod



print(dp[n][0][k]%mod)



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



namespace ConsoleApplication31
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
 
            for (int e = a-1; e > 0;e--)
            {
                Console.Write(b[e]+" ");
            }
            Console.WriteLine(b[0]);
        } 
    }
}

Measured memory_bytes: 9632
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    int A, B;
    cin >> A >> B;

    cout << ((A*B%2)?"Odd":"Even") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int v[n+1],c[n+1];
	
	int hasil=0;
	
	for (int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	
	for (int i=0;i<n;i++)
	{
		cin>>c[i];
	}
	
	for (int i=0;i<n;i++)
	{
		if (v[i]>c[i])
		{
			hasil=hasil+(v[i]-c[i]);
		}
	}
	
	cout<<hasil<<"\n";
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<set>
#include<algorithm>
#define LL long long
using namespace std;
typedef set<int>::iterator siter;
set<int> s;
LL Get(LL l,LL r)
{
	LL tmp=r-l+1,i;
	for(i=1;i<tmp;i*=2ll);
	return i;
}
int main()
{
	LL a,b,t,ans=0;
	scanf("%lld%lld",&a,&b);
	if(a==b) { printf("1\n"); return 0; }
	for(t=1;t<a;t*=2ll);
	while(t>b)
	{
		t/=2;
		if(a&t) a-=t,b-=t;
	}
	ans+=t-a;
	for(;t<=b;t*=2ll) ans+=min(t-a+Get(t,min(2ll*t-1,b)),t);
	printf("%lld\n",ans);
}

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

ABC = [[] for i in range(N)]
for i in range(N):
    ABC[i] = list(map(int,input().split()))

DP = [[0,0,0] for i in range(N)]

for i in range(3):
    DP[0][i] = ABC[0][i]

for i in range(N-1):
        DP[i + 1][0] = max(DP[i][1] + ABC[i + 1][0], DP[i][2] + ABC[i + 1][0])
        DP[i + 1][1] = max(DP[i][0] + ABC[i + 1][1], DP[i][2] + ABC[i + 1][1])
        DP[i + 1][2] = max(DP[i][0] + ABC[i + 1][2], DP[i][1] + ABC[i + 1][2])

ans = max(DP[N-1][0], DP[N-1][1], DP[N-1][2])

print(ans)

Measured memory_bytes: 47384
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);;

	int INF=1<<28;
	double EPS=1e-9;

	int[][] a;
	int w, h;
	boolean[][] visited;

	void run(){
		for(;;){
			h=sc.nextInt();
			w=sc.nextInt();
			if((h|w)==0){
				break;
			}
			a=new int[h][w];
			visited=new boolean[h][w];
			for(int j=0; j<h; j++){
				String s=sc.next();
				for(int i=0; i<w; i++){
					switch(s.charAt(i)){
					case '@':
						a[j][i]=0;
						break;
					case '#':
						a[j][i]=1;
						break;
					case '*':
						a[j][i]=2;
						break;
					}
				}
			}
			solve();
		}
	}

	void solve(){
		int ans=0;
		for(int j=0; j<h; j++){
			for(int i=0; i<w; i++){
				if(!visited[j][i]){
					ans++;
					bfs(i, j);
				}
			}
		}
		println(ans+"");
	}

	void bfs(int x, int y){
		LinkedList<P> que=new LinkedList<P>();
		que.offer(new P(x, y));
		visited[y][x]=true;
		int[] dx={0, 0, -1, 1};
		int[] dy={-1, 1, 0, 0};
		for(; !que.isEmpty();){
			P p=que.poll();
			for(int i=0; i<4; i++){
				P q=new P(p.x+dx[i], p.y+dy[i]);
				if(q.x>=0&&q.x<w&&q.y>=0&&q.y<h&&!visited[q.y][q.x]
						&&a[p.y][p.x]==a[q.y][q.x]){
					que.offer(q);
					visited[q.y][q.x]=true;
				}
			}
		}
	}

	class P{
		int x, y;

		P(int x, int y){
			this.x=x;
			this.y=y;
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

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

int main(int argc, const char * argv[]) {
    int H, W, i1, i2, i3;
    
    while(true){
        cin >> H >> W;
        
        if(H==0 && W==0)
            break;
        
        for(i1=0;i1<W;i1++){
            cout << "#";
        }
        cout << endl;
        for(i2=0;i2<H-2;i2++){
            cout << "#";
            for(i3=0;i3<W-2;i3++){
                cout << ".";
            }
            cout << "#" << endl;
        }
        for(i1=0;i1<W;i1++){
            cout << "#";
        }
        cout << endl << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3136
#include<stdio.h>
int main(void){
    int i,x,ans;
    while(scanf("%d",&x)!=EOF){
        ans=0;
        for(i=1;i<600/x;i++){
            ans+= (x*i * x*i) * x;
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 592
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n; cin >> n;
    pair<ll, ll> arr[200001];
    ll a, b;
    REP(i, n) {
        cin >> arr[i].first >> arr[i].second;
    }
    sort(
        begin(arr),
        begin(arr)+n,
        [](pair<ll, ll> a, pair<ll, ll>b) { return a.second < b.second; }
    );
    ll tmp = 0;
    REP(i, n) {
        if (tmp + arr[i].first <= arr[i].second) {
            tmp += arr[i].first;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 6728
N, x = map(int, input().split())
A = list(map(int, input().split())) * 2
A = A[::-1]

effective_costs = [float('inf')] * N
ans = float('inf')

# 魔法を使う回数
for k in range(N):
    effective_costs = [min(effective_costs[i], A[i+k]) for i in range(N)]
    ans = min(ans, sum(effective_costs) + k * x)

print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int h,w; cin >> h >> w;
  int a[h][w];
  REP(i,h) REP(j,w) cin >> a[i][j];

  vector<tuple<int,int,int,int>> ans;
  REP(i,h-1) {
    REP(j,w) {
      if(a[i][j]%2==0) continue;
      a[i][j]--; a[i+1][j]++;
      ans.push_back( make_tuple(i,j,i+1,j) );
    }
  }
  REP(j,w-1) {
    if (a[h-1][j]%2==0) continue;
    a[h-1][j]--; a[h-1][j+1]++;
    ans.push_back( make_tuple(h-1,j,h-1,j+1) );
  }

  cout << ans.size() << endl;
  for(auto x: ans) {
    cout
      << get<0>(x)+1 << " "
      << get<1>(x)+1 << " "
      << get<2>(x)+1 << " "
      << get<3>(x)+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 6272
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Algae
            var line = ReadLine();
            int r = line[0];
            int D = line[1];
            int x = line[2];

            for(int i = 0; i < 10; i++)
            {
                x = r * x - D;
                Console.WriteLine(x);
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11220
N=int(input())
A=input()
B=input()
C=input()

ans=0
for i in range(N):
  t=0
  if A[i]!=B[i]:
    t+=1
  if C[i]!=A[i] and C[i]!=B[i]:
    t+=1
  ans+=t
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

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

  vector< int > a(N);

  int ans[3] = {};
  for(int i = 0; i < N; i++) {
    cin >> a[i];
    if(a[i] % 4 == 0) {
      ans[0]++;
    }
    else if(a[i] % 2 == 0) {
      ans[1]++;
    }
    else {
      ans[2]++;
    }
  }

  if(ans[2] > ans[0]+1) {cout << "No" << endl; return 0;}
  else if(ans[2] == ans[0]+1 && ans[1] > 0) {cout << "No" << endl; return 0;}
  else cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>

using namespace std;



signed main(int argc, char *argv[]) {
  int n,m;
  map<string, int> s,t;
  string card;
  int points=0;

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

  cout << endl<<endl;
  cin >> m;
  for (int j=0;j<m;++j){
    cin >> card;
    t[card]++;
  }

  for (auto it=s.begin(); it!=s.end(); it++){
    points = max(points, s[it->first]-t[it->first]);
  }

  cout << endl<<endl<<points<<endl;


  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long k = sc.nextLong();
        b = Math.max(0, b - Math.max(0, k - a));
        a = Math.max(0, a - k);
        System.out.println(a + " " + b);
    }
}

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

int n, pw3[20], ans[531450];
string T;

string reduce(string T){
	string res = "";
	for(auto ch:T){
		if(res.size() && res.back()=='S' && ch=='S')
			res.pop_back();
		else res += ch;
	}
	return res;
}

void solve(int m, string T, int i, int p){
	if(m==n) {ans[i] = p; return;}
	rep(d,0,2){
		string nextT = "";
		int x = d;
		for(auto ch:T){
			if(ch=='S'){
				x = (3-x)%3;
				nextT += 'S';
			}else{
				x = (x+1)%3;
				if(x==0) nextT += 'R';
			}
		}
		solve(m+1, reduce(nextT), i+d*pw3[m], p+x*pw3[m]);
	}
}

int main() {
	cin>>n>>T;
	pw3[0] = 1;
	rep(i,1,n) pw3[i] = pw3[i-1] * 3;
	
	solve(0, reduce(T), 0, 0);
	
	rep(i,0,pw3[n]-1) printf("%d ", ans[i]);
	return 0;
}

Measured memory_bytes: 6628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	if(n == 1)
		cout << "Hello World" << endl;
	else if(n == 2)
	{
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
int main(){
   map<int,int> m;
   ll cnt=0;
   int n;
   cin >> n;
   vector<int> v(n);
   rep(i,n){
      int tmp;
      cin >> tmp;
      v[i]=tmp;
      m[tmp]++;
   }
   for (auto q:m){
      ll tmp;
      tmp=(ll)q.second*(ll)(q.second-1)/2LL;
      cnt+=tmp;
   }
   for (int i=0;i < n;i++){
      cout << cnt-(m[v[i]]-1) << endl;
   }
   return 0;
}



Measured memory_bytes: 8320
from collections import deque
H,W = map(int, input().split())
A = 0
dp = [None] * H
mat = deque(maxlen=W*H)
for h in range(H):
    s = list(input())
    for w, x in zip(range(W), s):
        if x == "#":
            mat.append((h, w, 0))
    dp[h] = s

while len(mat):
    h, w, cnt = mat.popleft()

    for t, h, w, cnt in ((h > 0, h - 1, w, cnt),(h < H-1, h + 1, w, cnt),(w > 0, h , w - 1, cnt),(w < W-1, h , w + 1, cnt)):
        if t and dp[h][w] == ".":
            mat.append((h, w, cnt+1))
            dp[h][w] = "#"

print(cnt)


Measured memory_bytes: 153308