akhauriyash/Code-Regression huggingface dataset:
def seiseki(m, f, r):
    if m == -1 or f == -1:
        return 'F'
    else:
        t = m + f
    
        if t >= 80:
            return 'A'
        elif 65 <= t < 80:
            return 'B'
        elif 50 <= t < 65:
            return 'C'
        elif 30 <= t < 50:
            if r >= 50:
                return 'C'
            else:
                return 'D'
        else:
            return 'F'

res = []
while True:
    m, f, v = map(int, input().split())
    if m == f == v == -1:
        break;
    res.append(seiseki(m, f, v))

for i in range(len(res)):
    print(res[i])

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

int main(void){
	int H,W,D;
	cin>>H>>W>>D;
	int x[H*W+1],y[H*W+1],dist[H*W+1];
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
        	int temp;
        	cin>>temp;
			x[temp] = i+1;
			y[temp] = j+1;
        }
    }
    for(int i=1;i<D+1;i++)dist[i] = 0;
    for(int i=D+1;i<H*W+1;i++){
		dist[i] = dist[i-D]+abs(x[i]-x[i-D])+abs(y[i]-y[i-D]);
    }
  	int Q;
    cin>>Q;
	for(int i=0;i<Q;i++){
		int L,R;
		cin>>L>>R;
		cout<<dist[R]-dist[L]<<endl;
    }
  return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
int n,par[100000],typ[100000],dep[100000];//root,internal node,leaf;
vector <int> chi[100000];

int depth(int now){
	if(dep[now] != -1)return dep[now];
	if(par[now]==-1)return 0;
	return depth(par[now])+1;
}
 
 
int main(){
	cin >> n;
	for(int i=0; i<n; i++){
		par[i] = -1;
		dep[i] = -1;
	}

	for(int i=0; i<n; i++){
		int id,k;
		cin >> id >> k;
		if(k == 0) typ[id] = 3;//leaf
		else{
			typ[id] = 2;//IN
			for(int j=0; j<k; j++){
			int c;
			cin >> c;
			chi[id].push_back(c);
			par[c] = id;
			}
		}
	}
	


	for(int i=0; i<n; i++){
		if(par[i] == -1) typ[i] = 1;//root
		cout << "node " << i << ": parent = " << par[i] << ", depth = " << depth(i) <<  ", ";
		if(typ[i] == 1)cout  << "root, [";
		else if(typ[i] == 2)cout  << "internal node, [";
		else cout  << "leaf, [";
		for(int k=0; k < chi[i].size(); k++){
			cout << chi[i][k];
			if(k != chi[i].size()-1) cout  << ", ";
		}
		cout << "]" << endl;
	}

    return 0;
}



Measured memory_bytes: 7460
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<string>
#define STDIN freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);
using namespace std;
const int N = 2e5 + 10;
int a[N];
int b[N];
int main()
{
   // STDIN;
    int n, k, c;
    string s; 
    cin >> n >> k >> c >> s;
    int j = 0, i = 0;
    for (;i<=n, j < k;i++)
    {
        if (s[i] == 'o')
        {
            a[j++] = i;
            i += c;
        }
    }
    for (j = 0, i = n-1; i >= 0, j < k; i--)
    {
        if (s[i] == 'o')
        {
            b[j++] = i;
            i -= c;
        }
    }
    /*for (int i = 0; i < k ;i++)
    {
        printf("%d%c", b[i], i == k - 1?'\n':' ');
    }*/
    for (int i = 0, j = k-1; i < k; i++,j--)
    {
        if (a[i] == b[j])
        {
            cout << a[i] + 1 << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3332
#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<iterator>
#include<iomanip>
#include<cmath>
#include<map>
#include<string.h>
#include<algorithm>

using namespace std;
void ll(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main() {

	ll();
	
	int a, b, sum = 0;
	cin >> a >> b;
	sum = a + b;
	if (sum % 3 == 0)
		cout << "Possible"<<endl;
	else if (sum == 0)
		cout << "Impossible"<<endl;
	else if (b % 3 == 0 || a % 3 == 0)
		cout << "Possible"<< endl;
	else
		cout << "Impossible"<<endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define endl '\n'
//#define int long long
const long long mod=1000000007;
const int N=10010;
ll binpow(ll a,ll b){
    if (!b) return 1ll;
    if (b%2ll) return (a*binpow(a,b-1ll))%mod;
    else return binpow((a*a)%mod,b/2ll);
}
int a[N];
map<int,int>cnt;
int32_t main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=n;i++){
        int x=a[i];
        int d=2;
        while (d*d<=x){
            int cn=0;
            while (x%d==0){
                x/=d;
                cn++;
            }
            if (cn) cnt[d]=max(cnt[d],cn);
            d++;
        }
        if (x>1) cnt[x]=max(cnt[x],1);
    }
    ll lcm=1ll;
    for (auto cur:cnt){
        lcm*=binpow(cur.first,cur.second);
        lcm%=mod;
    }
    ll sum=0ll;
    for (int i=1;i<=n;i++){
        sum+=binpow(a[i],mod-2)*lcm;
        sum%=mod;
    }
    cout<<sum;
    return 0;

}
//5 4 4 3 5 1 8
//1 0 0 -1 1 -3 4


Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    int P[25]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},Q[21]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    double c=a*100/8;
    double d=b*100/10;
    for(int i=0;i<25;i++){
        if(a<=double((c-12+i)*0.08) & double((c-12+i)*0.08)<a+1){
            P[i]=(c-12+i);
            if(c-12+i<0){
                P[i]=2000;
            }
        }
        else {
            P[i]=2000;
        }
    }
    for(int i=0;i<20;i++){
        if(b<=double((d-10+i)*0.1) &double((d-10+i)*0.1)<b+1){
            Q[i]=(d-10+i);
            if(d-10+i<0){
                Q[i]=2000;
            }
        }
        else{
            Q[i]=2000;
        }
    }
    int answer=2000;
    for(int i=0;i<25;i++){
        for(int j=0;j<20;j++){
            if(P[i]==Q[j] & answer>P[i]){
                answer=P[i];
            }
        }
    }
    if(answer==2000){
        cout<<-1<<endl;
    }
    else {
        cout<<answer<<endl;
    }
}


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


def solve(N: int, A: "List[int]"):
    m = {}
    for i in range(N):
        m[A[i]] = i + 1

    ans = []
    ms = sorted(m.items(), key=lambda x :x[0])
    for i in range(N):
        ans.append(ms[i][1])

    print(' '.join(map(str,ans)))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 101812
from collections import defaultdict

count = defaultdict(int)
n = int(input())
tmp_max=0
for i in range(n):
    s=input()
    tmp_cnt = count[s]
    tmp_max = max(tmp_max,tmp_cnt+1)
    count[s]+=1

ans=[]
for k,v in count.items():
    if v==tmp_max:
        ans.append(k)
ans=sorted(ans)
for s in ans:
    print(s)


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

long long s[400][30]; 
const int Shurui=26;//今回は26種類
int Date;//今回は1年間なので365日
long long Seigenjikan=1800000;//実行時間

int main() {
  clock_t start = clock();
  cin >>Date;
  vector<long long>c(Shurui);
  vector<int>last(Shurui,0);//前回の日にち
  vector<int>t(Date,0);//開催する順番
  for(int i=0;i<Shurui;i++)t[i]=i%Shurui;//とりあえずの値
  long long wa=0;
  for(int i=0;i<Shurui;i++){
    cin>>c[i];
    wa+=c[i];
  }
  for(int i=0;i<Date;i++){
    for(int j=0;j<Shurui;j++){
      cin>>s[i][j];
    }
  }
  long long kotae=0;
  long long hikukazu=0;
  long long atai=0;
  for(int i=0;i<Date;i++){
    atai=0;
    for(int j=0;j<Shurui;j++){
      if(s[i][j]>atai){
        t[i]=j;
        atai=s[i][j];
      }
    }
  }
  for(int i=0;i<Date;i++){
    atai=0;
    atai=s[i][t[i]];
    hikukazu+=wa-c[t[i]]*(i+1-last[t[i]]);
    last[t[i]]=i;
    kotae+=atai-hikukazu;
  }  
  clock_t end = clock();
  long long time = end - start;
  //cout<<start<<" "<<end<<" "<<time<<endl;
  while(time<Seigenjikan){
    long long d=rand()%Date;
    long long q=rand()%Shurui;
    long long old=t[d];
    t[d]=q;
    long long new_kotae=0;
    hikukazu=0;
    for(int i=0;i<Date;i++){
      atai=0;
      atai=s[i][t[i]];
      hikukazu+=wa-c[t[i]]*(i+1-last[t[i]]);
      last[t[i]]=i+1;
      new_kotae+=atai-hikukazu;
    }
    if(new_kotae<kotae){
      t[d]=old;
    }else{
      kotae=new_kotae;
      for(long long i=0;i<Date;i=i+13){
        if(i>=Date)break;
        t[d+i]=q;
      }
    }
    end = clock();
    time = end - start;
    //if(time>1500000)cout<<time<<endl;
  }
  for(int i=0;i<Date;i++){
    cout<<t[i]+1<<endl;
  }
  return 0;
}

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

using namespace std;

int main(){
  int sum;
  vector<int> a(3),b(3);
  
  for(int i=0; i<a.size(); i++){
    cin >> a.at(i);
  }
  for(int i=0; i<b.size(); i++){
    b.at(i) = abs(a.at((i+1)%3) - a.at(i%3));
  }
  sort(b.begin(),b.end());
  
  for(int i=0; i<a.size()-1; i++){
    sum += b.at(i);
  }
  cout << sum << endl;
  
  

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int num_int;
    scanf("%d",&num_int);
    
    if(num_int == 0){
        printf("underfined\n");
    } else {
        int in_int_1;
        scanf("%d",&in_int_1);
        int min,max;
        long sum;
        min = max = sum = in_int_1;
        
        int i;
        for(i = 2; i <= num_int ; i++){
            int in_int_i;
            scanf("%d",&in_int_i);
            
            if(min > in_int_i){
                min = in_int_i;
            }
            
            if(max < in_int_i){
                max = in_int_i;
            }
            
            sum += in_int_i;
        }
        
        printf("%d %d %ld\n",min,max,sum);
    }
    return 0;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    
    vector<bool> v(n + 1, false);
    while(k--){
        int d;
        cin >> d;
        while(d--){
            int a;
            cin >> a;
            if(v[a] == false)
                v[a] = true;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++){
        if(v[i] == false)
            ans++;
    }
    cout << ans << endl;
}

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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            string[] strs = str.Split(' ');
            int k = int.Parse(strs[0]);
            int t = int.Parse(strs[1]);
            str = Console.ReadLine();
            strs = str.Split(' ');
            List<KeyValuePair<int, int>> a = new List<KeyValuePair<int, int>>();
            for (int i = 0; i < t; i++)
            {
                a.Add(new KeyValuePair<int, int>(i, int.Parse(strs[i])));
            }

            int result = 0;
            int now = -1;

            if (t > 1)
            {

                while (a.Sum(x => x.Value) > 0)
                {
                    a.Sort((x, y) => -(x.Value.CompareTo(y.Value)));
                    if (a.ElementAt(0).Key != now)
                    {
                        now = a.ElementAt(0).Key;
                        var val = a.ElementAt(0).Value - 1;
                        a.RemoveAt(0);
                        a.Add(new KeyValuePair<int, int>(now, val));
                    }
                    else
                    {
                        if (a.ElementAt(1).Value > 0)
                        {
                            now = a.ElementAt(1).Key;
                            var val = a.ElementAt(1).Value - 1;
                            a.RemoveAt(1);
                            a.Add(new KeyValuePair<int, int>(now, val));
                        }
                        else
                        {
                            result = a.ElementAt(0).Value;
                            break;
                        }
                    }
                }
            }
            else
            {
                result = a.ElementAt(0).Value - 1;
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 7376
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s; cin >> s;
  string t = "";
  FOR(i,0,s.length()) {
    if(s[i] != 'x') {
      t += s[i];
    }
  }
  int ans = 0;
  int cnt_l = 0, cnt_r = 0;
  int l = 0, r = s.length() - 1;
  while(l < r) {
    while(s[l] == 'x') cnt_l++, l++;
    while(s[r] == 'x') cnt_r++, r--;
    ans += max(cnt_l, cnt_r) - min(cnt_l, cnt_r);
    cnt_l = cnt_r = 0;
    l++;
    r--;
  }
  if(t.length() % 2 == 0) {
    int l = t.length() / 2 - 1, r = t.length() / 2;
    while(l >= 0 && r < t.length() && t[l] == t[r]) {
      l--;
      r++;
    }
    if(l == -1 && r == t.length()) {
      cout << ans << endl;
      return 0;
    }
  } else {
    int l = t.length() / 2, r = t.length() / 2;
    while(l >= 0 && r < t.length() && t[l] == t[r]) {
      l--;
      r++;
    }
    if(l == -1 && r == t.length()) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

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

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)

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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main() { _
	int n, w; cin >> n >> w;
	vector<pair<ll, ll>> v(n);

	FOR(i,0,n) cin >> v[i].f >> v[i].s;

	vector<vector<ll>> dp(n+5, vector<ll>(w+5, 0));
	for(ll i = n-1; i >= 0; i--) {
		for(ll j = 0; j <= w; j++) {
			if(j < v[i].f) dp[i][j] = dp[i+1][j];
			else dp[i][j] = max(v[i].s + dp[i+1][j-v[i].f], dp[i+1][j]);
		}
	}

	cout << dp[0][w] << endl;
	return 0;
}



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

int n;  
ll k;   
vector<ll>a;

bool check(ll x){
    ll tmp = 0;
    rep(i, n){
        tmp += (a[i]-1)/x;
        if(tmp > k) return false;
    }
    return true;
}

ll solve(){
    ll ok = 10000000000, ng = 0;
    while(ng < ok - 1){
        ll ptr = (ok+ng)/2;
        if(check(ptr))  ok = ptr;
        else            ng = ptr;
    }
    return ok;
}

int main(){
    cin >> n;
    cin >> k;
    a.resize(n);
    rep(i, n)   cin >> a[i];
    cout << solve() << endl;
}


Measured memory_bytes: 4744
#include <bits/stdc++.h>
using namespace std;
typedef int64_t Int;


int main() {
  int K;
  cin >> K;
  
  if (K <= 9) {
    cout << K << endl;
    return 0;
  }
  else {
    Int cnt = 9;
    
    vector<vector<Int>> L(20);
    L[0] = {1,2,3,4,5,6,7,8,9};
    
    for (int i = 1; i < 20; i++) {
      for (int j = 0; j < L[i-1].size(); j++) {
        Int now = L[i-1][j];
        Int r = now % 10;
        
        if (r >= 1) L[i].push_back(now * 10 + r - 1);
        L[i].push_back(now * 10 + r);
        if (r <= 8) L[i].push_back(now * 10 + r + 1);
      }
    
      if (K <= cnt + L[i].size()) {
        cout << L[i][K - cnt - 1] << endl;
        break;
      }
      else {
        cnt += L[i].size();
      }
    }
  }
}


Measured memory_bytes: 1976
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

string s;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> s;
	bool ok = false;
	FOR(i, s.size()-1) {
		if (s.substr(i, 2) == "AC") ok = true;
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define mod 1000000007
#define pub(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    for(ll i =0;i<n;i++){
        cout<<s[i]<<t[i];
    }
   
    return 0;
}


Measured memory_bytes: 3600
N,a,b,c,d=map(int, input().split())
N-=1
a,b=0,abs(b-a)
#上下をn回とすると、0<=n<=N//2

for i in range(N//2+1):
  e=b-(N-i*2)*d
  f=b-(N-i*2)*c
  if e<=(d-c)*i and (c-d)*i<=f:
    print('YES')
    exit()
print('NO')

Measured memory_bytes: 9140
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
int main()
{
    int N;
    ll X;
    std::cin >> N >> X;
    std::vector<ll> x(N), sum(N, 0);
    for (int i = 0; i < N; i++) { std::cin >> x[i], sum[i] = (i == 0 ? 0LL : sum[i - 1]) + x[i]; }
    auto cost = [](const int i) { return i == 1 ? 5 : 2 * i + 1; };
    auto get = [&](const int s, const int t) { return sum[t - 1] - (s == 0 ? 0 : sum[s - 1]); };
    ll ans = 1LL << 60;
    for (int i = 1; i <= N; i++) {
        const int n = (N + i - 1) / i;
        __int128_t sum = i * X;
        for (int j = 1; j <= n; j++) {
            const int s = std::max(0, N - i * j);
            const int t = N - i * (j - 1);
            sum += (__int128_t)get(s, t) * cost(j);
        }
        ans = std::min((__int128_t)ans, sum);
    }
    std::cout << ans + N * X << std::endl;

    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,k,a[100005],j,l,r;
	long long b=0,ans=1e9;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	j=upper_bound(a,a+n,0)-a;
	l=max(0,j-k);
	r=min(n-1,j+k-1);
	for(int i=l;i<=r-k+1;i++)
	{
		if(a[i+k-1]>0)
			b=abs(a[i])+2*abs(a[i+k-1]);
		else
			b=abs(a[i]);
		ans=min(ans,b);
	}
	for(int i=r;i>=l+k-1;i--)
	{
		if(a[i-k+1]<0)
			b=abs(a[i])+2*abs(a[i-k+1]);
		else
			b=abs(a[i]);
		ans=min(ans,b);
	}
	cout<<ans;
 } 

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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
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; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n, k;
    cin >> n >> k;
    vector<int> a(n, 0);

    for (int i = 0; i < n; i++) cin >> a[i], a[i]--;

    vector<int> s, ord(n, -1);
    int c = 1, l = 0, v = 0;
    while (ord[v] == -1) {
        ord[v] = s.size();
        s.push_back(v);
        v = a[v];
    }
    c = s.size() - ord[v];
    l = ord[v];

    if (k < l) cout << s[k]+1 << endl;
    else {
        k -= l;
        k %= c;
        cout << s[l+k]+1 << endl;
    }

    return 0;
}



Measured memory_bytes: 5856
MAX_DIGIT = 40
SMALL = 0
EQUAL = 1
N, K = map(int, input().split())
A = list(map(int, input().split()))

dp = [[-1 for _ in range(2)] for _ in range(MAX_DIGIT+1)]
dp[0][EQUAL] = 0

for d in range(MAX_DIGIT):
    shift = MAX_DIGIT - d - 1
    bit_count = 0
    for a in A:
        if a >> shift & 1:
            bit_count += 1

    cost0 = (1 << shift) * bit_count
    cost1 = (1 << shift) * (N - bit_count)

    # small -> small
    if dp[d][SMALL] != -1:
        dp[d+1][SMALL] = max(dp[d+1][SMALL], dp[d][SMALL] + max(cost0, cost1))

    # equal -> small
    if dp[d][EQUAL] != -1:
        if K >> shift & 1:
            dp[d+1][SMALL] = max(dp[d+1][SMALL], dp[d][EQUAL] + cost0)

    # equal -> equal
    if dp[d][EQUAL] != -1:
        if K >> shift & 1:
            dp[d+1][EQUAL] = max(dp[d+1][EQUAL], dp[d][EQUAL] + cost1)
        else:
            dp[d+1][EQUAL] = max(dp[d+1][EQUAL], dp[d][EQUAL] + cost0)

ans = max(dp[MAX_DIGIT][EQUAL], dp[MAX_DIGIT][SMALL])
print(ans)

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

using namespace std;

int main() {
    string s;
    cin >> s;
    size_t max_count = 0;
    for (size_t i = 0; i < s.length(); ++i) {
        for (size_t j = 1; j <= s.length() - i; ++j) {
            auto ss = s.substr(i, j);
            bool is_valid = true;
            for (const auto& c : ss) {
                if (!(c == 'A' || c == 'C' || c == 'G' || c == 'T')) {
                    is_valid = false;
                    break;
                }
            }
            if (is_valid && ss.length() > max_count) max_count = ss.length(); 
        }
    }
    cout << max_count << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
def main():
    h, w, *a = map(int, open(0).read().split())
    m = [a[i * w:(i + 1) * w] for i in range(h)]
    m.append([2] * w)

    ans = ''
    cnt = 0
    for i in range(h):
        for j in range(w):
            if m[i][j] % 2 == 0:
                continue
            if j != w - 1:
                cnt += 1
                m[i][j + 1] += 1
                ans += '{0} {1} {2} {3}\n'.format(i + 1, j + 1, i + 1, j + 2)
            elif i != h - 1:
                cnt += 1
                m[i + 1][j] += 1
                ans += '{0} {1} {2} {3}\n'.format(i + +2, j + 1, i + 1, j + 1)
            else:
                pass
    print(cnt)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14456
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    if(N*A>B) cout << B << endl;
    else cout << N*A << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int N,M,X;
  cin>>N>>M>>X;
  vector<int> C(N);
  vector<vector<int>> A(N,vector<int> (M,0));
  rep(i,N){
    cin>>C[i];
    rep(j,M) cin>>A[i][j];
  }

  int ans=MOD;
  for(int bit=1;bit<(1<<N);bit++){
    vector<int> score(M,0);
    int res=0;
    for(int i=0;i<N;i++){
      if(bit&(1<<i)){
        res+=C[i];
        for(int j=0;j<M;j++) score[j]+=A[i][j];
      }
    }

    bool ok=true;
    for(int j=0;j<M;j++) if(score[j]<X) ok=false;
    if(ok) chmin(ans,res);
  }

  if(ans==MOD) cout<<-1<<endl;
  else cout<<ans<<endl;

  return 0;
}


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

int main() {
	char a[4],b[4];
	scanf("%3s", a);
	scanf("%3s", b);
	if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) {
		printf("YES");
	}
	else {
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    //全体の和と、a[i]の入力
    ll all_sum = 0;
    rep(i, n){
        cin >> a[i];
        all_sum += a[i];
    }
    ll mn = 1000000000000110;
    ll x = 0;
    ll y = 0;
    rep(i, n-1){
        x += a[i];
        y = all_sum - x;
        if(mn > fabs(x - y)) mn = fabs(x - y);
    }
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 4824
#include <iostream>
#include <math.h>
using namespace std;
int main(){
   int x;
   int a;
   int b;
   cin >> x >> a >> b;
	if ((x-a)*(x-a) < (x-b)*(x-b)) {
		cout << 'A';
	} else {
		cout << 'B';
	}
	cout << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var ai = Sarray();
            var ans = 0;
            foreach (var a in ai)
            {
                var t = a;
                while (t % 2 == 0)
                {
                    t /= 2;
                    ++ans;
                }

            }
            WriteLine(ans);

            //Out.Flush();
        }
    }
}

Measured memory_bytes: 14304
#include <cctype>
#include <cstdio>
#include <queue>
#include <vector>
#include <functional>
#define INF 100000000

using namespace std;
typedef pair<int,int> P;

class Node{
public:
  Node(int x, int y, int f):x(x),y(y),f(f){}
  int x,y,f;
  int tonum(){return (x<<7)+(y<<1)+f;}
};

Node tonode(int num){
  return Node(num>>7,num>>1&63,num&1);
};

int hoge[2][9][2] = {{{1,2},{1,1},{1,0},{1,-1},{1,-2},{2,1},{2,0},{2,-1},{3,0}},
		     {{-1,2},{-1,1},{-1,0},{-1,-1},{-1,-2},{-2,1},{-2,0},{-2,-1},{-3,0}}};

int w,h;
int map[100][100];
int d[100000];
bool visit[100000];

void dijkstra(Node from) {
  int m = from.tonum();
  priority_queue<P,vector<P>,greater<P> > que;
  fill(d,d+100000,INF); fill(visit,visit+100000,false);
  d[m] = 0;
  que.push(P(0,m));
  while(!que.empty()) {
    P p = que.top(); que.pop();
    int cand = p.second;
    if (visit[cand])
      continue;
    visit[cand] = true;
    
    for (int i=0; i<9; i++) {
      Node n = tonode(cand);
      int dx = hoge[n.f][i][0], dy = hoge[n.f][i][1];
      int x = n.x+dx, y= n.y+dy, f = (n.f+1)&1;
      if (x >= 0 && x < w && y >= 0 && y < h && map[x][y] != INF) {
	int next = Node(x,y,f).tonum();
	if (d[next] > d[cand] + map[x][y]) {
	  d[next] = d[cand] + map[x][y];
	  que.push(P(d[next],next));
	}
      }
    }
  }
}

int main() {
  while(scanf("%d %d",&w,&h),w) {
    vector<Node> start,goal;

    for (int y=0; y<h; y++) {
      for (int x=0; x<w; x++) {
	char c;
	while(isspace(c=getchar())) ;
	switch (c) {
	case 'X':
	  map[x][y]=INF;
	  break;
	case 'S':
	  map[x][y] = 0;
	  start.push_back(Node(x,y,0));
	  start.push_back(Node(x,y,1));
	  break;
	case 'T':
	  map[x][y] = 0;
	  goal.push_back(Node(x,y,0));
	  goal.push_back(Node(x,y,1));
	  break;
	default:
	  map[x][y] = c-'0';
	}
      }
    }

    int ans = INF;
    for (int s=0; s<start.size(); s++){
      dijkstra(start[s]);
      for (int g=0; g<goal.size(); g++) {
	ans = min(ans,d[goal[g].tonum()]);
      }
    }
  
    printf ("%d\n",(ans==INF)?-1:ans);
  }
}

Measured memory_bytes: 1552
n, m = map(int, input().split())
k = list(map(int, input().split()))
del k[0]
ans = set(k)

for i in range(n-1):
    x = list(map(int, input().split()))
    del x[0]

    x = set(x)
    ans = ans & x

ans = list(ans)

print(len(ans))

Measured memory_bytes: 38312
import collections

s = input().strip()
t = input().strip()

counter0 = collections.Counter()
counter1 = collections.Counter()

for c in s:
    counter0[c] += 1
for c in t:
    counter1[c] += 1
values0 = sorted(counter0.values())
values1 = sorted(counter1.values())

ok = True
for x0, y0 in zip(values0, values1):
    if x0 != y0:
        ok = False
        break
if ok:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 4144
def binary_search(data, value):
    left = 0            # 探索する範囲の左端を設定
    right = len(data) - 1            # 探索する範囲の右端を設定
    while left <= right:
        mid = (left + right) // 2            # 探索する範囲の中央を計算
        if data[mid] == value:
            # 中央の値と一致した場合は位置を返す
            return mid
        elif data[mid] < value:
            # 中央の値より大きい場合は探索範囲の左を変える
            left = mid + 1
        else:
            # 中央の値より小さい場合は探索範囲の右を変える
            right = mid - 1
    return -1            # 見つからなかった場合

n = int(input())
s = input()

r = [i+1 for i, x in enumerate(s) if x == 'R']
g = [i+1 for i, x in enumerate(s) if x == 'G']
b = [i+1 for i, x in enumerate(s) if x == 'B']

c = 0
for i in r:
    for j in g:
        if binary_search(b, 2*i - j) != -1:
            c += 1
        if binary_search(b, 2*j - i) != -1:
            c += 1
        if binary_search(b, (i+j)/2) != -1:
            c += 1

ans = (len(r)*len(g)*len(b) - c)
print(ans)

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

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

    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;

    int passed = 0;
    int b_idx = 1;
    rep(i, n){
        if(s[i] == 'a'){
            if(passed < a+b){
                puts("Yes");
                ++passed;
            }
            else puts("No");
        }
        else if(s[i] == 'b'){
            if(passed < a+b && b_idx <= b){
                puts("Yes");
                ++b_idx;
                ++passed;
            }
            else puts("No");
        }
        else puts("No");
    }

    

    return 0;
}

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

int n, t, x, y, nx, ny, nt, cost, duration;
string ans = "Yes";

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d %d %d", &t, &x, &y);
        cost = abs(nx - x) + abs(ny - y);
        duration = t - nt;
        if (cost > duration || cost % 2 != duration % 2) ans = "No";
        x = nx, y = ny, t = nt;
    }
    cout << ans << endl;
    
    return 0;
}

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

namespace ABC122C2
{
    class Program
    {
        static void Main(string[] args)
        {
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int Q = int.Parse(input[1]);
            // 文字列の入力
            string S = Console.ReadLine();
            int[] cumulative = new int[N + 1];//累積和
            cumulative[0] = 0;
            cumulative[1] = 0;
            for (int i = 2; i <= S.Length; i++)
            {
                if ((S.Substring(i-1, 1) == "C")&&(S.Substring(i-2, 1) == "A"))
                {
                    cumulative[i] = cumulative[i - 1] + 1;
                }
                else
                {
                    cumulative[i] = cumulative[i - 1];
                }
            }
/*
            foreach (var item in cumulative)
            {
                Console.Write(item+" ");
            }
*/
            for (int i = 0; i < Q; i++)
            {
                string[] inputLR = Console.ReadLine().Split(' ');
                int l = int.Parse(inputLR[0]);
                int r = int.Parse(inputLR[1]);
                Console.WriteLine(cumulative[r] - cumulative[l]);
            }
        }
    }
}


Measured memory_bytes: 16320
N=int(input())
A=list(map(int,input().split()))
ans = 0
from collections import defaultdict
dic = defaultdict(int)
for i in range(N):
    dic[A[i]] += 1
    dic[A[i]+1] += 1
    dic[A[i]-1] += 1
for x in range(-1, 10**5+1):
    ans = max(ans, dic[x])
print(ans)

Measured memory_bytes: 88724
#include <iostream>

int main(){
    int t = 0;
    std::cin >> t;
    int h, m, s = 0;
    s = t % 60;
    m = (t % 3600) / 60;
    h = t / 3600;
    
    std::cout << h << ":" << m << ":" << s << std::endl;
    
    return 0;
}



Measured memory_bytes: 3096
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	long gcd(long a,long b) {
		return a==0?b:gcd(b%a,a);
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		long[][] cnt=new long[20][20];
		long ans=0;
		for (int i=0;i<N;++i) {
			double A=sc.nextDouble();
			int c5=-9,c2=-9;
			long a=(long)(A*1e9+.1);
			while (c5<9 && a%5==0) {
				++c5;
				a/=5;
			}
			while (c2<9 && a%2==0) {
				++c2;
				a/=2;
			}
			for (int u=-10;u<10;++u) {
				for (int v=-10;v<10;++v) {
					if (u+c2>=0&&v+c5>=0) ans+=cnt[u+9][v+9];
				}
			}
			cnt[c2+9][c5+9]++;
		}
		System.out.println(ans);
	}
	

	void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

}


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

#define int long long
//#define deb(x) cout<<#x<<" = "<<x<<"\n";
#define mod 1000000007


int fact[100005];
int inv[100005];
int power(int x,int y)
{
    int res=1;
    x =x%mod;
    while (y > 0)
    {
        if(y&1)
         res=(res*x)%mod;
         y=y>>1;
         x=(x*x)%mod;
    }
    return res % mod;
}  
int ncr(int n, int r)
{
	return ((fact[n] * inv[r]) % mod * inv[n-r]) % mod;
}
signed main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	/*****************************************/
	
	
	fact[0] = inv[0] = 1;
	int n, k; cin>>n>>k;
	
	for(int i=1; i<n+2; i++)
	{
		fact[i] = i*fact[i-1] % mod;
		inv[i] = power(fact[i], mod-2) % mod;
	}

	int a[n+1];
	for(int i=1; i<=n; i++) cin>>a[i];
	
	sort(a+1, a+n+1);
	
	int maxi = 0, mini = 0;
	
	for(int i = n-k+1; i>0; i--)
	{
		mini += a[i] * ncr(n-i, k-1) % mod;
		mini %= mod;
	}
	
	for(int i = k; i<=n; i++)
	{
		maxi += (a[i] * ncr(i-1, k-1)) % mod;
		maxi %= mod;
	}
	
	cout<< (maxi - mini + mod) % mod;
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

struct node{
    int y, x, cost;

    bool operator<(const node & right) const {
        return cost > right.cost;
    }
};

template<typename T>
bool chmin(T &a, T b){
    if(a > b){
        a = b;
        return true;
    }else{
        return false;
    }
}

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

    int h, w;
    cin >> h >> w;

    vector<string> v(h);
    rep(i, h){
        cin >> v[i];
    }

    vector< vector<int> > dis(h, vector<int>(w, IINF));

    priority_queue<node> que;
    que.push({0, 0, 0});
    while(!que.empty()){
        node now = que.top();
        que.pop();
        if(!chmin(dis[now.y][now.x], now.cost)){
            continue;
        }
        if(now.y < h - 1 && dis[now.y + 1][now.x] > now.cost + (int)(v[now.y + 1][now.x] - '0')){
            que.push({now.y + 1, now.x, now.cost + (int)(v[now.y + 1][now.x] - '0')});
        }
        if(now.x < w - 1 && dis[now.y][now.x + 1] > now.cost + (int)(v[now.y][now.x + 1] - '0')){
            que.push({now.y, now.x + 1, now.cost + (int)(v[now.y][now.x + 1] - '0')});
        }
    }

    cout << dis[h - 1][w - 1] << endl;

    return 0;
}


Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	string t; cin >> t;
	REP(i,t.size()){
		if(t[i]=='?')
			cout << 'D';
		else
			cout << t[i];
	}
	cout << endl;
	return 0;
}

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

int main() {
    int L, R, d;
    cin >> L >> R >> d;

    int count, atai;
    count = 0;
    atai = 0;
    for(int i = 1; i < 102; i++){
        atai += d;
        if(atai >= L){
            if(atai <= R){
                count++;
            }else{
                break;
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3588
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

#define mod 1000000007

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

int main(){
    cin>>N;
    if(N/10==9||N%10==9){
        out("Yes");
    }
    else{
        out("No");
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    rep(i, a, b + 1) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3628
class Calc:
    def __init__(self, max_value, mod):
        """combination(max_value, all)"""
        fact = [-1] * (max_value + 1)
        fact[0] = 1
        fact[1] = 1
        for x in range(2, max_value + 1):
            fact[x] = x * fact[x - 1] % mod

        invs = [1] * (max_value + 1)
        invs[max_value] = pow(fact[max_value], mod - 2, mod)
        for x in range(max_value - 1, 0, -1):
            invs[x] = invs[x + 1] * (x + 1) % mod

        self.fact = fact
        self.invs = invs
        self.mod = mod

    def combination(self, n, r):
        if n - r < r:
            return self.combination(n, n - r)
        if r < 0:
            return 0
        if r == 0:
            return 1
        if r == 1:
            return n
        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod


def gen(n):
    x = n
    d = 2
    cnt = 0
    while x % d == 0:
        x //= d
        cnt += 1
    yield cnt

    d = 3
    while d * d <= n:
        cnt = 0
        while x % d == 0:
            x //= d
            cnt += 1
        yield cnt
        d += 2

    if x > 1:
        yield 1


def main():
    MOD = 10 ** 9 + 7

    N, M = map(int, input().split())

    cal = Calc(max_value=N + 30, mod=MOD)

    ans = 1
    for cnt in gen(M):
        ans = (ans * cal.combination(N + cnt - 1, cnt)) % MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  string s;
  int p=0,w=0,g=0,y=0;
  for (int i=0;i<n;i++){
    cin >> s;
  	if(s=="P") p++;
  	if(s=="W") w++;
  	if(s=="G") g++;
  	if(s=="Y") y++;
  }
  if(p>0 && w>0 && g>0 && y>0) cout << "Four" << endl; else cout << "Three" << endl;
}


Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;

int main() {

  std::string S;
  std::cin >> S;

  int n = S.size();

  int keep = 1000;
  for (int i = 0; i < n-2; i++) {
    char c1 = S.at(i);
    char c2 = S.at(i+1);
    char c3 = S.at(i+2);
    string num = "";
    num = num + c1 + c2 + c3;
    int numnum = atoi(num.c_str());

    int dif = abs(753 - numnum);
    if (keep > dif){
      keep = dif;
    }
  }
  std::cout << keep << '\n';
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(ll i=0;i<n;++i)
#define END(x) (*(x.end()-1))
#define INF INT_MAX / 2

using namespace std;
typedef long long ll;


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

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)*b;
}

int main(void){
    ll L,R;
    cin >> L >> R;
    ll ans = 2020;
    ll imax;
    imax = min(L+4038,R);
 
    for(ll i = L; i<=imax; ++i){
        for(ll j = i+1; j<=imax; ++j) {
            ans=min(ans,(i*j)%2019);
        }
    }
 
    cout << ans;
}
/*

*/


Measured memory_bytes: 3624
n,l=gets.split.map(&:to_i)
as=gets.split.map(&:to_i)

i = 0
loop{
	unless i+1 < as.length
		puts "Impossible"
		exit
	end
	if as[i]+as[i+1] >= l
		break
	end
	i += 1
}
puts "Possible"
1.upto(i){|j|
	puts j
}
(n-1).downto(i+1){|j|
	puts j
}


Measured memory_bytes: 11788
import math
def plot(x,y):
    print(f'{x:.8f} {y:.8f}')
def Koch(n,x1,y1,x2,y2):
    if n==0:
        plot(x1,y1)
        return
    sx=(2*x1+x2)/3
    sy=(2*y1+y2)/3
    tx=(x1+2*x2)/3
    ty=(y1+2*y2)/3
    ux=(tx-sx)*(1/2)-(ty-sy)*(math.sqrt(3)/2)+sx
    uy=(tx-sx)*(math.sqrt(3)/2)+sy+(ty-sy)*(1/2)
    Koch(n-1,x1,y1,sx,sy)
    Koch(n-1,sx,sy,ux,uy)
    Koch(n-1,ux,uy,tx,ty)
    Koch(n-1,tx,ty,x2,y2)
n=int(input())
Koch(n,0,0,100,0)
plot(100,0)



Measured memory_bytes: 5748
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>

int main()
{
	int i, n, *arr, no = 0, min = 0;

	scanf("%d", &n);

	arr = (int*)malloc(sizeof(int) * n);

	for (i = 0; i < n; i++)
		scanf("%d", &arr[i]);

	for (i = 1; i < n; i++)
	{
		arr[i - 1]--;
		
		if (min < arr[i - 1])
			min = arr[i - 1];

		if (arr[i - 1] > arr[i] || min > arr[i])
		{
			no = 1;

			break;
		}
	}

	if (no)
		printf("No\n");
	else
		printf("Yes\n");

	return 0;
}

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

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> g(N);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}

	deque<int> que;
	que.emplace_back(0);
	vector<int> ans(N, -1);
	vector<bool> used(N, false);
	ans[0] = 0;
	while (!que.empty()) {
		int u = que.front(); que.pop_front();
		if (used[u]) { continue; }
		used[u] = true;

		for (auto v : g[u]) {
			if (!used[v] && ans[v] < 0) {
				ans[v] = u;
				que.emplace_back(v);
			}
		}
	}

	for (int i = 1; i < N; ++i) {
		if (ans[i] < 0) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	for (int i = 1; i < N; ++i) {
		cout << ans[i] + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 10220
//code_sm
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu ((int)1e9+7)
#define set0(a) memset(a,0,sizeof(a))
#define all(a) a.begin()+1,a.end()
#define endl "\n"
template<typename T,typename U>
bool compare(T x,U y)
{
	if(abs((T)x-y)<=1e-9)
	return 1;
	return 0;
}
//sieve generation begin
vi PRIME;
void sieve(int n)
{
	bool a[n+1];
	memset(a,0,sizeof(a));
	a[0]=1;
	a[1]=1;
	for(int i=2;i*i<=n;i++)
	{
		if(a[i]==0)
		{
			for(int j=i*i;j<=n;j+=i)
			a[j]=1;
		}
	}
	for(int i=2;i<=n;i++)
	{
		if(a[i]==0)
		PRIME.pb(i);
	}
}
//sieve generation end
ll gcd(ll a,ll b)
{
	while(b%a)
	{
		ll c=b;
		b=a;
		a=c%a;
	}
	return a;
}
ll bigpow(ll base, ll exp) {
    ll res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base)%chotu;
       base=(base*base)%chotu;
       exp/=2;
    }
    return res;
}
ll mulmodin(ll x)
{
	return(bigpow(x,chotu-2)%chotu);
}
ll ncr_mod(ll n,ll r)
{
	ll store[n+1];
	store[1]=1;
	for(ll i=2;i<=n;i++)
	{
		store[i]=(store[i-1]*i)%chotu;
	}
	ll ans=(((store[n]*mulmodin(store[r]))%chotu)*mulmodin(store[n-r]))%chotu;
	return ans;
}
#define PI 3.141592653589793
void solve()
{
fastio
int a,b,h,m;
cin>>a>>b>>h>>m;
int min1=h*60+m;
int hour_travel=min1%720;
int min_travel=min1%60;
double deg_hour=0.5*(double)hour_travel;
double deg_min=6.0*(double)min_travel;
double angle=max(deg_hour,deg_min)-min(deg_hour,deg_min);
double co=cos(angle*PI/180.0);
double ans=a*a+b*b-2*a*b*co;
ans=sqrt(ans);
SET(19)<<ans;
}
int main()
{
//code
fastio
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


Measured memory_bytes: 4236
import numpy as np
N = int(input())
F = [[int(x) for x in input().split()] for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]

f = np.array(F)
ans = float("-inf")
for n in range(1, 2**10):
    a = np.array([int(x) for x in format(n, '010b')])
    p = sum([P[i][x] for i,x in enumerate(np.sum(f * a, axis=1))])
    ans = max(ans, p)
print(ans)

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

 int main()
 {
  int n,a[50],b[50],i,j,k,f,m;
  cin>>n;
   for(i=0;i<n;i++)
   {
     cin>>a[i];
   }
   f=0;
   for(i=0;i<n-1;i++){if(a[i]>a[i+1])f=1;}
   if(f==0){cout<<"YES"<<endl;return 0;}
   for(i=0;i<n;i++)
   {
     
     for(j=0;j<n;j++)
     {
       for(k=0;k<n;k++){b[k]=a[k];}
       m=b[i];
       b[i]=b[j];
       b[j]=m;
       f=0;
       for(k=0;k<n-1;k++){if(b[k]>b[k+1]){f=1;break;}}
       if(f==0){cout<<"YES"<<endl;return 0;}
     }
   }
   cout<<"NO"<<endl;
 }

Measured memory_bytes: 3580
import java.util.Scanner;
import java.util.Arrays;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String[] a = new String[n];
    for(int i = 0;i < n;i++){
      a[i] = sc.next();
    }
    Arrays.sort(a);
//    System.out.println(Arrays.toString(a));
    int count = 1;
    for(int j = 1;j < n;j++){
      if(a[j].equals(a[j - 1])){
        count--;
      }
      count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 69880
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi oe(2,0);
  rep(i,N) {
    int x;
    cin >> x;
    oe[x%2]++;
  }
  if (oe[1]%2==0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

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

typedef long long ll;
using namespace std;

int GetDigit(ll num){
    return to_string(num).length();
}

bool IsInt(double val){
    return ceil(val)!=floor(val) ?false:true;
}

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

ll N;
cin>>N;
int min_digit=GetDigit(N);
ll start=sqrt(N);

for(ll i=start;i>0;i--){
    if(N%i==0){
        min_digit=min(min_digit,GetDigit(N/i));        
        break;
    }
}
cout<<min_digit<<endl;

//system("pause");
return 0;
}

Measured memory_bytes: 256