akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<random>
using namespace std;
int main(){
  int a[200];
  int n, result=-1;
  int c=1;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int k=0; k<31; k++){ //bit
    for(int i=0; i<n; i++){
      if(a[i]&c){
        result = k;
        break;
      }
    }
    if(result>=0) break;
    c <<= 1;
  }
  cout << result << endl;
  return 0;
}


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

using namespace std;

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;

    ll ans = N * (N - 1) / 2 + (M - 1) * M / 2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# Problem E - Dividing Chocolate

# input
H, W, K = map(int, input().split())
board = [['']*W for i in range(H)]
for i in range(H):
    s = list(input())
    for j in range(W):
        board[i][j] = s[j]

# initialization
min_divide = 10**10
s = [0]*(H-1) # 横線の入り方 0:無 1:有
is_ok = True

# search
for i in range(2**(H-1)): # bit全探索
    # sの初期化
    h_count = 0
    w_count = 0
    for j in range(H-1):
        if ((i>>j)&1):
            s[j] = 1
            h_count += 1
        else:
            s[j] = 0

    # 列の全探索
    s_score = [0]*H # 各区域のスコア
    s_cur = [0]*H
    for j in range(W):
        c = 0
        s_cur = [0]*H

        for k in range(H):
            if board[k][j]=='1':
                s_cur[c] += 1

            # Kを超えていないかのチェック
            if s_cur[c]>K:
                is_ok = False
                break

            # 次の遷移先(横線の有無でグループが別れる)
            if k+1<H:
                if s[k]==1:
                    c += 1
        # Kを超えていたらループ中止
        if not is_ok:
            break
        # 前の列のグループと足してみてKを超えていないかチェック
        # 超えていれば縦線分割を施す
        group_smaller = True
        if j>0:
            for c_num in range(c+1):
                if s_score[c_num]+s_cur[c_num]>K:
                    group_smaller = False
        else:
            group_smaller = True

        if group_smaller:
            for c_num in range(c+1):
                s_score[c_num] += s_cur[c_num]
        else:
            w_count += 1
            for c_num in range(c+1):
                s_score[c_num] = s_cur[c_num]

    if not is_ok:
        is_ok = True
        continue

    for c_num in range(h_count+1):
        if s_score[c_num]>K:
            h_count = 10 ** 6

    # 縦線と横線の合計でmin_divideを更新
    min_divide = min(min_divide, w_count + h_count)

# output
print(min_divide)


Measured memory_bytes: 50012
#include<stdio.h>
int main(void)
{
    int stu[31]={0},i,a=0,b=0,count=0;
    for(i = 1;i <= 28;i++){
        scanf("%d", &a);
        stu[a] = 1;
    }
    for(i = 1;i <= 30;i++){
        if(stu[i] == 0){

            if(count == 0)a = i;
            if(count == 1)b = i;
            count++;
        }

    }
    if(a > b)printf("%d\n%d\n",b,a);
    if(a < b)printf("%d\n%d\n",a,b);


    return 0;
}

Measured memory_bytes: 1796
#include<bits/stdc++.h>
using namespace std;
int a[100];
int bubbleSort(int a[],int n)
{
	int sum=0;
   bool flag=1;
	for(int i=0;flag;i++)
	{
		flag=0;
		for(int j=n-1;j>=i-1;j--)
		{
			if(a[j]<a[j-1])
			{
				flag=1;
				swap(a[j],a[j-1]);
				sum++;
			}
		}
	}
	return sum;
}

int main()
{
	int n,sw;
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>a[i];
	sw=bubbleSort(a,n);
	for(int i=0;i<n;i++)
	{
		if(i) cout<<" ";
		cout<<a[i];
	}
	cout<<endl;
	cout<<sw<<endl;
	return 0;
}


Measured memory_bytes: 3108
#include <stdio.h>
#include <algorithm>
using namespace std;

#define REP(i, N) for(int (i) = 0; (i) < (N); i++)
#define MAX 1 << 20

int main(){
    int n, a[100005];
    scanf("%d", &n);
    REP(i, n) scanf("%d", &a[i]);
    int p = a[0], count = 0;
    REP(i, n){
        count++;
        if(p == 2) break;
        else if(i == n-1) count = -1;
        else p = a[p-1];
    }
    printf("%d", count);
    return 0;
}

Measured memory_bytes: 512
(defun round-one ()
  (let ((a (read))
	(b (read))
	(ans))
    (dotimes (i 3)
      (if (/= a (1+ i))
	  (if (/= b (1+ i))
	      (setf ans (1+ i)))))
    ans))

(format t "~D~%" (round-one))

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

int main() {
  string str; cin >> str;
  bool n, e, w, s; n = e = w = s = false;
  REP(i, str.size()) {
    if (str[i] == 'N') n = true;
    else if (str[i] == 'E') e = true;
    else if (str[i] == 'W') w = true;
    else if (str[i] == 'S') s = true;
  }
  
  if (n ^ s || e ^ w) cout << "No" << endl;
  else cout << "Yes" << endl;
  
  return 0;
}

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

const int maxn=5005, mod=1e9+7;

int N,L;
int dp[maxn][maxn];
char s[maxn];

main()
{
	scanf("%d%s",&N,s); L=strlen(s);
	
	memset(dp,0,sizeof(dp));
	
	dp[0][0]=1;
	for (int i=1; i<=N; ++i)
	{
		dp[i][0] = (dp[i-1][0] + dp[i-1][1]) % mod;
		
		for (int j=1; j<=i; ++j)
	        dp[i][j] = (dp[i-1][j-1] * 2ll + dp[i-1][j+1]) % mod;
	}
	
	long long res=dp[N][L];
	for (int i=1; i<=L; ++i)
		// res /= 2
		res = res * 500000004 % mod;
		//500000004 = 0.5 mod 1e9+7
	cout<<res;
}

Measured memory_bytes: 98048
N = int(input())
D, X = [int(_) for _ in input().split()]
A = [int(input()) for _ in range(N)]

r = 0

for i in range(1, D + 1):
    for j in A:
        if i % j == 1 or j == 1:
            r += 1

print(r + X)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
	int A, B, C, K; 
	cin >> A >> B >> C >> K; 
	int cnt = 0; 
	while(A >= B){
		B *= 2; cnt ++; 
	}
	while(B >= C){
		C *= 2; cnt ++; 
	}
	if(cnt <= K) cout << "Yes" << "\n"; 
	else cout << "No" << "\n"; 
}

Measured memory_bytes: 3632
#153d
h = int(input())

# (10 ** 12) / (1024 ** 4) < 1

if h == 1:
  print(1)
  exit()

for i in range(1, 41):
  h //= 2
  if h == 1:
    print(2 ** (i + 1) - 1)
    exit()

Measured memory_bytes: 2940
# coding: utf-8
import numpy as np
from functools import lru_cache
import time

def main(): 
    if True:
        S = np.asarray(list(map(int,list(str(input())))))
    else:
        pass
    #print(S)

    A = np.asarray(range(S.size))
    B = np.asarray([0]*S.size)
    B[A%2==0] = 0
    B[A%2==1] = 1
    
    C = np.asarray([0]*S.size)
    C[A%2==0] = 1
    C[A%2==1] = 0
    
    res1 = np.sum(np.bitwise_xor(S,B))
    res2 = np.sum(np.bitwise_xor(S,C))
    print(min(res1,res2))

if __name__ =='__main__':
    main()

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

int main() {
	ll a;
	cin >> a;
	vector <ll> arr;
	ll count=0;
	arr.resize(a);
	for (int x=0;x<a;x++){
		cin >> arr[x];
	}
	for (int x=1;x<(a-1);x++){
		if (((arr[x]>arr[x-1])&&(arr[x]<arr[x+1]))||((arr[x]<arr[x-1])&&(arr[x]>arr[x+1]))){
			count +=1;
		}
	}
	cout << count ;
}	


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long maxn=1e5+5;
const long long inf=0x3f3f3f3f;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    long long n,ans=0;
    cin>>n;
    for(long long i=1;i<=n;i++)
    {
    	for(long long j=1;j<=n;j++)
    	{
    		if(i*j>=n)
    			break;
    		ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3648
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
    
    
N = int(input())
ss = []
for i in range(N):
	ss.append("".join(sorted(list(input()))))
	
dicS = {}
for s in ss:
	if s not in dicS:
		dicS[s] = 1
	else:
		dicS[s] += 1
		
#print(dicS)
		
ans = 0
for v in dicS.values():
	if v != 1:
		ans += cmb(v, 2)
	
print(ans)

Measured memory_bytes: 19996
#include <iostream>
#include <vector>
#include <array>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;
long long N;
std::vector<long long> a, p;

long long build_a (long long k){
  if ( k == 0 ) return a[k] = 1;
  if ( a[k] != -1 ) return a[k];
  return a[k] = 2*build_a(k-1)+3;
}

long long build_p (long long k){
  if ( k == 0 ) return p[k] = 1;
  if ( p[k] != -1 ) return p[k];
  return p[k] = 2*build_p(k-1)+1;
}

long long sol ( ll k, ll X ) {
  if ( X == 0 ) return 0;
  else if ( X == 1 && k == 0 ) return 1;
  else if ( X == 1 ) return 0;

  else if ( 2 <= X && X <= 1+a[k-1] ) return sol(k-1, X-1);
  else if ( X == 2+a[k-1] ) return p[k-1]+1;
  else if ( (3+a[k-1]) <= X && X <= (2+2*a[k-1]) ) return p[k-1]+1+sol(k-1, X-2-a[k-1]);
  else if ( X >= a[k] ) return p[k];
  else assert(0);
}

int main (void) {

  long long X; std::cin >> N >> X;

  a.assign(N+1, -1);
  p.assign(N+1, -1);

  build_a(N);
  build_p(N);
  std::cout << sol(N, X) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int prime(int num);

int main(void)
{
	int n, num;
	int c = 0;
	int i;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d", &num);
		if (prime(num)){
			c++;
		}
	}
	
	printf("%d\n", c);
	
	return (0);
}

int prime(int num)
{
	int i;
	
	if (num <= 1){
		return (0);
	}
	if (num == 2){
		return (1);
	}
	if (num % 2 == 0){
		return (0);
	}
	for (i = 3; i * i <= num; i += 2){
		if (num % i == 0){
			return (0);
		}
	}
	return (1);
}

Measured memory_bytes: 596
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    priority_queue<int,vector<int>,greater<int>> que;
    que.push(4);
    que.push(7);
    while(1) {
        int v = que.top();
        que.pop();
        if(v == N) {
            cout << "Yes" << endl;
            break;
        } else if(N < v)  {
            cout << "No" << endl;
            break;
        }
        que.push(v+4);
        que.push(v+7);
    }
}

Measured memory_bytes: 5488
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define pll pair<ll,ll>
#define vll vector<ll>
#define forn(i,n) for(ll i=0; i<n; ++i)
#define pb push_back
#define MOD 1000000007
#define range(c) c.begin() , c.end()
#define Print(a) for(auto it : a)cout << (it) <<" ";cout << endl;
#define test ll t;cin >> (t);while(t--)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : ";cout << arg1 <<" ";}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {const char *comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : ";
cout << arg1 <<" ";cout << " | ";__f(comma + 1, args...);}
char local ='O';
#define db(...) if(local=='L') {__f(#__VA_ARGS__, __VA_ARGS__); cout<<endl;}
//////////////////////////////////////////////////////////////
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
	local = 'L';
#endif

	
	ll n;
	cin >> n;
	ll a[n];
	forn(i,n)
	{
		cin >> a[i];
	}
	ll ans = 0;
	ll mx = a[0];
	for(int i=1;i<n;i++)
	{
		if(a[i] < mx)
			ans+= mx - a[i];
		mx = max(mx, a[i]);
	}
		cout << ans << endl;
	
}

Measured memory_bytes: 5136
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        class Data
        {
            public string Name { get; set; }
            public int Time { get; set; }
        }

        static void Main(string[] args)
        {
            var nums = GetNumbersInt();
            var n = nums[0];
            var q = nums[1];
            var list = Enumerable.Range(0, n).Select(x => GetStrings()).Select(xs => new Data() { Name = xs[0], Time = int.Parse(xs[1]) });
            var queue = new Queue<Data>(list);
            var t = 0;
            while (queue.Count != 0)
            {
                var data = queue.Dequeue();
                if (data.Time <= q)
                {
                    t += data.Time;
                    System.Console.WriteLine(data.Name + " " + t);
                }
                else
                {
                    data.Time -= q;
                    queue.Enqueue(data);
                    t += q;
                }
            }
        }

        //static StreamReader Console = new StreamReader("input.txt");

        static int insertionSort(int[] A, int n, int g, int cnt)
        {
            for (int i = g; i < n; i++)
            {
                var v = A[i];
                var j = i - g;
                while (j >= 0 && A[j] > v)
                {
                    A[j + g] = A[j];
                    j = j - g;
                    cnt++;
                }
                A[j + g] = v;
            }
            return cnt;
        }

        static int shellSort(int[] A, int n, int[] m)
        {
            var cnt = 0;
            for (int i = 0; i < m.Length; i++)
            {
                cnt = insertionSort(A, n, m[i], cnt);
            }
            return cnt;
        }

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static double GetDounble()
        {
            return double.Parse(Console.ReadLine().Trim());
        }

        static int[] GetNumbersInt(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static long[] GetNumbersLong(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToArray();
        }

        static double[] GetNumbersDouble(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToArray();
        }

        static string[] GetStrings(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
        }
    }
}

Measured memory_bytes: 17268
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n,m;
    cin>>n>>m;
    int a[n];
    int sum = 0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum += a[i];
    }
    sort(a,a+n,greater<int>());
    int cnt = 0;
    for(int i=0;i<n;i++){
        if(sum <= 4*m*a[i])cnt++;
    }
    if(cnt >= m) cout << "Yes\n";
    else cout << "No\n";
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }





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

    int N, A, B;
    cin >> N >> A >> B;
    
    vector<int> h(N);
    rep(i, N) cin >> h[i];
    
    int l = 0, r = inf;
    while (1) {
        int mid = (l + r) / 2;
        int cnt = 0;
        rep(i, N) {
            cnt += max(1LL * 0, (h[i] - (ll)B * mid + (A - B - 1)) / (A - B));
            if (cnt > mid) break;
        }
        if (cnt <= mid) r = mid; // rがokの条件
        else l = mid;
        // out(l << " " << r);
        if (l + 1 == r) break;
    }
    
    out(r);
}




Measured memory_bytes: 768
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int n,k,r;
	cin>>n>>k;
	vector<int>v(n);
	rep(i,n)cin>>v[i];
	long long int max=0,sum;
	rep(left,k+1){
		rep(right,k+1){
			r=k-left-right;
			if(r>=0&&left+right<=n&&(left>0||right>0)){
				vector<int> a(left+right);
				rep(i,left)a[i]=v[i];
				rep(i,right)a[i+left]=v[n-1-i];
				sort(a.begin(),a.end());
				rep(i,r){
					if(a[i]<0)a[i]=0;
				}
				sum=0;
				rep(i,a.size())sum+=a[i];
				if(max<sum)max=sum;
			}
		}
	}
	cout<<max<<endl;



	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>

#define Maxn 200010

using namespace std;

inline int read() {
    int x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int n, f[Maxn], val[Maxn], low[Maxn];

struct Edge {
    int next, to;
}
edge[Maxn * 2];
int head[Maxn], edge_num = 1;

void add_edge(int from, int to) {
    edge[++edge_num].next = head[from];
    edge[edge_num].to = to;
    head[from] = edge_num;
}

pair <int, int> update(int l, int r, int v) {
    while(l < r) {
        int mid = (l + r) >> 1;
        if(low[mid] < v) l = mid + 1;
        else r = mid;
    }
    int temp = low[l];
    low[l] = v;
    return make_pair(l, temp);
}

void dfs(int u, int fa, int len) {
    bool flag; pair <int, int> info;
    // cout << "before:" << u << " " << len << " " << low[len] << endl;
    if(val[u] > low[len]) low[++len] = val[u], flag = 1;
    else info = update(0, len, val[u]), flag = 0;
    f[u] = len;
    // cout << "after:" << u << " " << len << " " << low[len] << " " << low[1] << " " << modpos << endl;
    for(int i = head[u]; i; i = edge[i].next) {
        int v = edge[i].to;
        if(v == fa) continue;
        dfs(v, u, len);
    }
    if(flag) low[len] = 0;
    else low[info.first] = info.second;
}

int main() {
    n = read();
    for(int i = 1; i <= n; ++i) val[i] = read();
    int u, v;
    for(int i = 1; i < n; ++i) {
        u = read(); v = read();
        add_edge(u, v);
        add_edge(v, u);
    }
    dfs(1, 0, 0);
    for(int i = 1; i <= n; ++i) printf("%d\n", f[i]);
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;

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

    // 素数である
    return true;
}


int main(){

  int n;
  cin>>n;
  int ans=1;
  while(ans<=n){
      ans*=2;
      
}
if(ans>n){
      ans/=2;
  }
 cout<<ans<<endl;
}

Measured memory_bytes: 3668
n, m = [int(i) for i in input().split()]

a_b = []
for i in range(n):
  a_b.append([int(i) for i in input().split()])

a_b.sort(key=lambda x: x[0])

count = 0
payment = 0
for i in a_b:
  count += i[1]
  payment += i[0] * i[1]
  if count >= m:
    payment -= (count - m) * i[0]
    break

print(payment)

Measured memory_bytes: 22748
/**
 *  author: abhiy13
 *  created: 07.07.2019 17:46:49
**/
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int mod = 2019;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int l, r;
  cin >> l >> r;
  if(r - l + 1 >= mod) {
    cout << 0 << '\n';
  } else {
    ll res = ll(1.1e18);
    for(int i = l; i <= r; ++i) {
      for(int j = i + 1; j <= r; ++j) {
        res = min(res, (i * 1LL * j) % mod);
      }
    }
    cout << res << '\n';
  }
  return 0;
}

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

ll solve() {
    ll N;
    cin >> N;
    string S;
    cin >> S;

    vector<vector<ll>> num(N, vector<ll>(N, -1));
    for ( int i = 0; i < N; i++ ) {
        for ( int j = i+1; j < N; j++ ) {
            if ( num[i][j] >= 0 ) continue;
            int k = 0;
            while ( j + k < N && S[i+k] == S[j+k] ) k++;
            int h = k;
            while ( k >= 0 && j+h-k < N ) {
                num[i+h-k][j+h-k] = min(k, j-i);
                k--;
            }
        }
    }
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        for ( int j = i+1; j < N; j++ ) {
            if ( ans < num[i][j] ) ans = num[i][j];
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 195840
#include<stdio.h>
int main(void){
    int n, tmp;
    scanf("%d", &n);
    while(n > 0){
        tmp = n / 10;
        if(n % 10 ==  7){
            printf("Yes\n");
            break;
        }
        n = tmp;
        if(tmp == 0){
            printf("No\n");
            break;
        }
    }
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





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

  vector<string> p(n);
  rep(i,n){
    cin>>p[i];
  }

  vector<vector<int>> q(n,vector<int>(m,0));
  int cnt;
  rep(i,n){
    cnt=0;
    rep(j,m){
      if(p[i][j]=='.') {
        cnt++;
        q[i][j]+=cnt;
      }
      else cnt=0;
    }
    cnt=0;
    for(int j=m-1;j>=0;j--){
      if(p[i][j]=='.') {
        cnt++;
        q[i][j]+=cnt;
      }
      else cnt=0;
    }
  }


  rep(i,m){
    cnt=0;
    rep(j,n){
      if(p[j][i]=='.') {
        cnt++;
        q[j][i]+=cnt;
      }
      else cnt=0;
    }
    cnt=0;
    for(int j=n-1;j>=0;j--){
      if(p[j][i]=='.') {
        cnt++;
        q[j][i]+=cnt;
      }
      else cnt=0;
    }
  }

  int ans=0;
  rep(i,n){
    rep(j,m){
      if(p[i][j]=='.') chmax(ans,q[i][j]);
    }
  }

  cout << ans-3 << endl;
}


Measured memory_bytes: 20096
#include<stdio.h>

int f[44];
int makefibonacci(void){
  int i;
  f[0]=1;
  f[1]=1;
  for(i=2;i<45;i++){
    f[i]=f[i-1]+f[i-2];
  }
}
int main(){
  int n;
  makefibonacci();
  scanf("%d",&n);

  printf("%d\n",f[n]);

  return 0;
}



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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return x * y % mod;
}

int main()
{
    long long n;
    std::cin >> n;

    std::map<long long, long long> map;
    for (int i = 0; i < n; i++) {
        long long temp;
        std::cin >> temp;

        map[temp]++;
    }

    long long ans = 0;
    for (auto t : map) {
        if (t.second - t.first >= 0) {
            ans += t.second - t.first;
        } else {
            ans += t.second;
        }
    }

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


Measured memory_bytes: 6272
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
  int N; 
  cin >> N;
  N /= 3;
  cout << N << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int N;
long Y,A[300];
long dp[6][301];
main()
{
	cin>>N>>Y;
	long S=0,ans=0;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		S+=A[i];
	}
	Y-=S/5;
	for(int i=0;i<N;i++)
	{
		for(int k=0;k<=5;k++)for(int j=0;j<=N;j++)dp[k][j]=0;
		dp[0][0]=1;
		for(int j=0;j<N;j++)
		{
			long sum=Y;
			for(int k=j+1;k<=N;k++)
			{
				sum+=A[(i+k-1)%N];
				if(sum>=0)
				{
					for(int l=0;l<5;l++)dp[l+1][k]+=dp[l][j];
				}
			}
		}
		ans+=dp[5][N];
	}
	cout<<ans/5<<endl;
}



Measured memory_bytes: 3116
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
using namespace std;
typedef long long ll;
const long long llnrm=LLONG_MAX;
const int nrm=INT_MAX;
const int nrn=INT_MIN;
const int nmax=1e5+5;
const int mod=1e9+7;
const int lim=1e8;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if (a+b>c+d){
		cout<<"Left";
	}
	else if (a+b<c+d){
		cout<<"Right";
	}
	else if(a+b==c+d){
		cout<<"Balanced";
	}
}


Measured memory_bytes: 256
//
// Created by Chisec Coin on 17/7/15.
//

#include <iostream>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <sstream>
#include <map>
const int NIL = -1;
typedef long long ll;
using std::cin;using std::cout;using std::endl;using std::max;using std::min;

ll a[200005], sum1[200005], sum2[200005];

inline ll absll(const ll& i) {
    return i > 0 ? i : -i;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (i == 0) {
            sum1[i] = a[i];
        } else {
            sum1[i] += sum1[i - 1] + a[i];
        }
    }
    for (int i = n - 1; i >= 0; --i) {
        if (i == n - 1) {
            sum2[i] = a[i];
        } else {
            sum2[i] += sum2[i + 1] + a[i];
        }
    }
    int i = 0;
    ll minx = 9223372036854775807;
    while (i != n - 1) {
        minx = min(absll(sum1[i] - sum2[i + 1]), minx);
        i++;
    }
    cout << minx << endl;

    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main() {
	int h, w, m;
	cin >> h >> w >> m;
	vector<int> a(h);
	vector<int> b(w);
	map<P,int> mp;
	rep(i, m) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		a[x]++; b[y]++;
		P p = make_pair(x, y);
		mp[p]++;
	}

	vector<int> aa = a;
	vector<int> bb = b;
	sort(aa.rbegin(), aa.rend());
	sort(bb.rbegin(), bb.rend());
	int mh = aa[0],mw=bb[0];

	vector<int> c;
	vector<int> d;
	rep(i, h) {
		if (a[i] == mh) {
			c.push_back(i);
		}
	}
	rep(i, w) {
		if (b[i] == mw) {
			d.push_back(i);
		}
	}
	rep(i, c.size())rep(j, d.size()) {
		P p = make_pair(c[i], d[j]);
		if (mp[p] == 0) {
			cout << mh + mw << endl;
			return 0;
		}
	}
	cout << mh + mw-1 << endl;
}

Measured memory_bytes: 30780
#include <stdio.h>

int main(void)
{
    int a, b, c;
    int i;
    int count = 0;

    scanf("%d %d %d", &a, &b, &c);

    for (i = a; i <= b; i++) {
        if (c % i == 0) {
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main(void){

  int h,w;
  scanf("%d %d", &h, &w);
  char a[h][w+1];
  for (int i = 0; i < h; i++) {
    scanf("%s", a[i]);
  }
  for (int i = 0; i < w+2; i++) {
    printf("#");
  }
  printf("\n#");
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] < 'a' || a[i][j] > 'z') {
        break;
      }
      printf("%c", a[i][j]);
    }
    printf("#\n#");
  }
  for (int i = 0; i < w+1; i++) {
    printf("#");
  }
  printf("\n");

  return 0;
}

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

static const int NIL = -1;

class TreeNode {
public:
    int parent;
    int left;
    int right;
    TreeNode() : parent(NIL), left(NIL), right(NIL) {}
};

void Preorder(vector<TreeNode>& tree, int root)
{
    if (root == NIL) return;
    cout << " " << root;
    Preorder(tree, tree[root].left);
    Preorder(tree, tree[root].right);
}

void Inorder(vector<TreeNode>& tree, int root)
{
    if (root == NIL) return;
    Inorder(tree, tree[root].left);
    cout << " " << root;
    Inorder(tree, tree[root].right);
}

void Postorder(vector<TreeNode>& tree, int root)
{
    if (root == NIL) return;
    Postorder(tree, tree[root].left);
    Postorder(tree, tree[root].right);
    cout << " " << root;
}

int main()
{
    int n;
    cin >> n;
    vector<TreeNode> tree(n);
    for (int i = 0; i < n; i++) {
        int id, left, right;
        cin >> id >> left >> right;
        tree[id].left = left;
        tree[id].right = right;
        tree[left].parent = id;
        tree[right].parent = id;
    }
    int root;
    for (int i = 0; i < n; i++) {
        if (tree[i].parent == NIL) {
            root = i;
            break;
        }
    }

    cout << "Preorder" << endl;
    Preorder(tree, root);
    cout << endl;

    cout << "Inorder" << endl;
    Inorder(tree, root);
    cout << endl;

    cout << "Postorder" << endl;
    Postorder(tree, root);
    cout << endl;
}




Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll N, i;
  cin >> N >> i;
  COUT(N - i + 1);
  return 0;
}

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

Measured memory_bytes: 0
#include<iostream>

using namespace std;

int main(void)
{
	char c;
	int a,b;
	int sum,ave;
	int i;
	sum=ave=i=0;
	while(cin>>a>>c>>b)
	{
		sum+=a*b;
		ave+=b;
		i++;
	}
	cout<<sum<<endl;
	cout<<(int)(((double)ave/i)+0.5)<<endl;
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int D; std::cin >> D;
    std::vector<int> c(26), t(D+1);
    std::vector<std::set<int>> days(26);
    for(int i(0); i < 26; ++i){
        days[i].emplace(0);
        days[i].emplace(D+1);
    }
    std::vector<std::vector<int>> s(D+1, std::vector<int>(26));
    for(int i(0); i < 26; ++i) std::cin >> c[i];
    for(int i(1); i <= D; ++i){
        int mx(0), id(-1);
        for(int j(0); j < 26; ++j){
            std::cin >> s[i][j];
            if(chmax(mx, s[i][j])) id = j;
        }
        t[i] = id;
        days[t[i]].emplace(i);
    }

    long long v(0);
    for(int i(1); i <= D; ++i){
        long long dcr(0);
        for(int j(0); j < 26; ++j){
            auto itr(std::upper_bound(std::begin(days[j]), std::end(days[j]), i));
            dcr += c[j] * (i - *(--itr));
        }
        v += s[i][t[i]] - dcr;
    }
    int M(1000000);
    srand((unsigned int)time(NULL));
    {
        int d, q;
        for(int qq(0); qq < M; ++qq){
            d = rand() % D + 1;
            q = rand() % 26;

            long long oldv(v);

            auto itr(days[t[d]].find(d));
            long long d1(*(--itr));
            itr = std::upper_bound(std::begin(days[t[d]]), std::end(days[t[d]]), d);
            long long d2((*itr)-1);
            v -= c[t[d]] * ((d1-d)*(d-d2) + d - d1);

            itr = std::lower_bound(std::begin(days[q]), std::end(days[q]), d);
            d1 = *(--itr);
            itr = std::upper_bound(std::begin(days[q]), std::end(days[q]), d);
            d2 = (*itr)-1;
            v += c[q] * ((d1-d)*(d-d2) + d - d1);

            v += s[d][q] - s[d][t[d]];
            if(oldv <= v){
                days[t[d]].erase(d);
                days[q].emplace(d);
                t[d] = q;
            }else{
                v = oldv;
            }
        }
    }
    for(int i(1); i <= D; ++i){
        std::cout << t[i] + 1 << "\n";
    }
    return 0;
}


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

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

    int i = 0;
    int ans = 0;
    while(i < s.size())
    {
        if (s[i] == 'A')
        {
            int l;

            for (l = i; s[l] == 'A'; l++){}
            if (s[l] != 'Z') break;
            for (; s[l] == 'Z'; l++){}

            ans = max(ans, l - i);
            i = l + 1;
        }
        else
            i++;
    }
    // cout << ans << endl;


    int from = s.size() - 1;
    int to = 0;
    rep(i, s.size())
    {
        if (s[i] == 'A')
            from = min(from, i);
        if (s[i] == 'Z')
            to = max(to, i);
    }
    cout << to - from + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if(s.equals("A")) {
			System.out.println("T");
		}else if(s.equals("T")) {
			System.out.println("A");
		}else if(s.equals("C")) {
			System.out.println("G");
		}else if(s.equals("G")) {
			System.out.println("C");
		}
	}

}


Measured memory_bytes: 23892
import sys
import math

def main():
  S = list(input())
  alphabets = set(list('abcdefghijklmnopqrstuvwxyz'))
  for s in S:
    alphabets.discard(s)
  if len(alphabets) == 0:
    print('None')
  else:
    left = list(alphabets)
    left.sort()
    print(left[0])

main()


Measured memory_bytes: 3956
#include <bits/stdc++.h>
    #define FOR(i, a, b) for(int i = a; i < b; i++)
    #define REP(i, n) FOR(i, 0, n)
    #define INF 999999999
    typedef long long ll;
    using namespace std;
    int main() {
        string S;
        cin >> S;
        bool flag = true;
        bool C_flag = false;
        int C_index;
        if(S[0] != 'A') flag = false;
        FOR(i, 2, S.size()-1) {
            if(S[i] == 'C') {
                C_flag = true;
                C_index = i;
            }
        }
        if(!C_flag) flag = false;
        FOR(i, 1, S.size()) {
            if(C_index == i) continue;
            if(isupper(S[i])) flag = false;
        }
        if(flag) puts("AC");
        else puts("WA");
    }

Measured memory_bytes: 256
N = int(input())
ans = []

def shichigo(n):
    global ans
    if int(n) > N:
        return
    if all([(s in n) for s in "753"]):
        ans.append(n)
    shichigo(str(int(n) * 10 + 3))
    shichigo(str(int(n) * 10 + 5))
    shichigo(str(int(n) * 10 + 7))

if N < 357:
    print(0)
else:
    shichigo('3')
    shichigo('5')
    shichigo('7')
    print(len(set(ans)))


Measured memory_bytes: 7580
#include"bits/stdc++.h"
using namespace std;
int main(){
	int a,b[222],s=0;
	cin>>a;
	for(int i=0;i<2*a;i++)
		cin>>b[i];
	sort(b,b+2*a);
	for(int i=0;i<2*a;i++)
		if(i%2==0)
			s=s+b[i];
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

def gcd(a, b):
    if a < b:
        return gcd(b, a)
    while b > 0:
        a, b = b, a % b
    return a

def sieve_of_eratosthenes_max(n):
    sieve = [0] * (n+1)
    sieve[0] = 0 #素数でない
    sieve[1] = 1 #素数でない
    for i in range(2, n+1):
        if sieve[i] == 0:
            for j in range(1, n // i + 1):
                sieve[i * j] = i
    return sieve

def factorize_by_sieve_of_eratosthenes(x, sieve):
    factor = defaultdict(int)
    while sieve[x] != x:
        factor[sieve[x]] += 1
        x //= sieve[x]
    factor[x] += 1
    return factor

n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()

sieve = sieve_of_eratosthenes_max(a_list[-1])
pairwise = True
setwise = True
primes = set()
x = a_list[0]
for a in a_list:
    x = gcd(x, a)
    if pairwise and a != 1:
        factor = set(factorize_by_sieve_of_eratosthenes(a, sieve).keys())
        if not primes.isdisjoint(factor):
            pairwise = False
        else:
            primes |= factor

if pairwise:
    print("pairwise coprime")
elif x == 1:
    print("setwise coprime")
else:
    print("not coprime")




Measured memory_bytes: 196824
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 10;

namespace FenwickTree
{

int BIT[MAXN];

inline int loBit(int x)
{
	return x & (-x);
}

void modify(int index, int val)
{
	index++;
	while(index < MAXN)
	{
		BIT[index] = (BIT[index] + val) % MOD;
		index += loBit(index);
	}
}

int query(int index)
{
	int result = 0;

	index++;
	while(index > 0)
	{
		result = (result + BIT[index]) % MOD;
		index -= loBit(index);
	}

	return result;
}

int query(int L, int R)
{
	return (query(R) - query(L - 1) + MOD) % MOD;
}

};

int N;
int sortAux[MAXN];
pair <int, int> xv[MAXN];
int L[MAXN], R[MAXN];
vector <int> query[MAXN];

inline bool cmpIndex(const int & x, const int & y)
{
	return xv[x].second < xv[y].second;
}

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

	cin >> N ;
	for(int i = 1; i <= N; i++)
		cin >> xv[i].second >> xv[i].first ;
	iota(&sortAux[1], &sortAux[N + 1], 1);

	sort(&xv[1], &xv[N + 1]);
	sort(&sortAux[1], &sortAux[N + 1], cmpIndex);

	int mn = 0x7F7F7F7F, mx = 0;
	for(int i = N; i >= 1; i--)
		mn = min(mn, sortAux[i]), L[i] = mn;
	for(int i = 1; i <= N; i++)
		mx = max(mx, sortAux[i]), R[i] = mx, query[R[i]].push_back(L[i]);

	FenwickTree::modify(0, 1);
	for(int iR = 1; iR <= N; iR++)
		for(int iL : query[iR])
			FenwickTree::modify(iR, FenwickTree::query(iL - 1, iR));
	cout << FenwickTree::query(N, N) << endl ;

	return 0;
}


Measured memory_bytes: 16000
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

int main()
{
    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;

    vector<int> xmoves, ymoves;
    bool nextx = true;
    for (int i = 0; i < s.size();)
    {
        if (s[i] == 'T')
        {
            i++;
            nextx = !nextx;
        }
        else
        {
            int count = 0;
            while (i < s.size() && s[i] == 'F')
            {
                i++;
                count++;
            }
            if (nextx)
            {
                xmoves.push_back(count);
            }
            else
            {
                ymoves.push_back(count);
            }
        }
    }

    if (xmoves.size() == 0)
    {
        xmoves.push_back(0);
    }
    if (ymoves.size() == 0)
    {
        ymoves.push_back(0);
    }

    const int maxn = 16030;
    int xdp[xmoves.size()][maxn];
    int ydp[ymoves.size()][maxn];

    rep(i, xmoves.size())
    {
        fill(xdp[i], xdp[i] + maxn, false);
    }
    rep(i, ymoves.size())
    {
        fill(ydp[i], ydp[i] + maxn, false);
    }

    if (s[0] == 'T')
    {
        xdp[0][xmoves[0] + maxn / 2] = true;
        xdp[0][-xmoves[0] + maxn / 2] = true;
    }
    else
    {
        xdp[0][xmoves[0] + maxn / 2] = true;
    }
    xdp[0][xmoves[0] + maxn / 2] = true;
    ydp[0][ymoves[0] + maxn / 2] = true;
    ydp[0][-ymoves[0] + maxn / 2] = true;

    for (int i = 1; i < xmoves.size(); i++)
    {
        rep(j, maxn)
        {
            if (xdp[i - 1][j])
            {
                xdp[i][j + xmoves[i]] = true;
                xdp[i][j - xmoves[i]] = true;
            }
        }
    }

    for (int i = 1; i < ymoves.size(); i++)
    {
        rep(j, maxn)
        {
            if (ydp[i - 1][j])
            {
                ydp[i][j + ymoves[i]] = true;
                ydp[i][j - ymoves[i]] = true;
            }
        }
    }

    if (xdp[xmoves.size() - 1][x + maxn / 2] && ydp[ymoves.size() - 1][y + maxn / 2])
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 250752
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
class DisjointSet{
private:
  vector< int > rank, p;
  void link(int x,int y){
    if(rank[x] > rank[y]){
      p[y] = x;
    } else {
      p[x] = y;
      if(rank[x] == rank[y]) rank[y]++;
    }
  }
public:
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    for(int i = 0; i < size; i++) p[i] = i, rank[i] = 0;
  }
  void Union(int x,int y){
    if(Find(x) != Find(y)) link(Find(x),Find(y));
  }
  int Find(int x){
    return( x != p[x] ? p[x] = Find(p[x]) : p[x]);
  }
};

struct edge{
  int u, v, cost;
  bool operator<(const edge& e) const {
    return cost < e.cost;
  }
};

int main(){
  int n, m;
  while(cin >> n >> m, n){
    vector< edge > edges;
    for(int i = 0; i < m; i++){
      int s, t, c;
      cin >> s >> t >> c;
      edges.push_back((edge){ s - 1, t - 1, c});
    }
    sort(edges.begin(), edges.end());
    DisjointSet UnionFind(n);
    vector< int > cost;
    for(int i = 0; i < edges.size(); i++){
      edge& e = edges[i];
      if(UnionFind.Find(e.u) != UnionFind.Find(e.v)){
        UnionFind.Union( e.u, e.v);
        cost.push_back(e.cost);
      }
    }
    if(cost.size() % 2 == 0){
      cout << (cost[cost.size() / 2] + cost[cost.size() / 2 + 1]) / 2 << endl;
    } else {
      cout << cost[cost.size() / 2] << endl;
    }
  } 
}

Measured memory_bytes: 1440