akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

long long modp(long long a, long long p) {
    long long res = a % p;
    if (res < 0) res += p;
    return res;
}

int main(void){
    int N; cin >> N;
    int M = N;
    string ans = "";

    if(N == 0){
        cout << 0 << endl;
        return 0;
    }

    while(N){
        ans += toString(modp(N,2));
        if(N<0){
            N = -1*N + 1;
            N /= 2;
        }
        else{
            N /= 2;
            N *= -1;
        }
    }
    REVERSE(ans);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<int> A, B;


  return (A+B-1) / B;
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}


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

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;

const int MAX_N = 100000;
vector<vi> pre(MAX_N + 1);
vi dist(MAX_N + 1);
vector<bool> visited(MAX_N + 1);

void dfs(int v) {
    visited[v] = true;
    for (int vp : pre[v]) {
        if (!visited[vp]) 
            dfs(vp);
        dist[v] = max(dist[v], dist[vp] + 1);
    }
}

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

    int n, m;
    cin >> n >> m;
    int u, v;
    
    for (int i = 0; i < m; ++i) {
        cin >> u >> v;
        pre[v].push_back(u);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (!visited[i]) {
            dfs(i);
            ans = max(ans, dist[i]);
        }
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 10624
n = int(input())
A = list(map(int, input().split()))
A.insert(0,0) 
B = [-1 for x in range(n)]
C = [0 for x in range(max(A) + 1)]

for a in A[1:]:
    C[a] += 1

for i in range(1, max(A) + 1): # 累加和
    C[i] += C[i - 1]
    
for j in range(1, n + 1):
    B[C[A[j]]-1] = A[j]
    C[A[j]] -= 1

print(" ".join(map(str, B)))


Measured memory_bytes: 243372
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}

-- 1. Don't parse Strings, parse Text -- using takes takes 
--    only 40% of the time of Strings.
-- 2. 

import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.Text (Text)
import qualified Data.List as L

import qualified Data.Vector.Unboxed as V
import Data.Vector.Unboxed (Vector)
import qualified Data.Vector.Unboxed.Mutable as VMut

import Control.Monad  ( replicateM )

import System.IO.Unsafe
import Data.Bits (shiftR)

{-# INLINE binarySearchPBounds #-}
binarySearchPBounds p vec = loop
 where
 loop !l !u
   | u <= l    = return l
   | otherwise = VMut.unsafeRead vec k >>= \e -> if p e then loop l k else loop (k+1) u
  where k = (u + l) `shiftR` 1

{-# INLINE binarySearchL #-}
binarySearchL vec e = binarySearchPBounds (>= e) vec 0 (VMut.length vec)

{-# INLINE binarySearchR #-}
binarySearchR vec e = binarySearchPBounds (> e) vec 0 (VMut.length vec)


forceEither :: Either a b -> b
forceEither (Right r) = r 

parseLineT :: Text -> [Int]
parseLineT txt =
  map (fst . forceEither . T.decimal) $ T.splitOn (T.pack " ") txt

getStdInputT :: IO [Text]  
getStdInputT = do
  res@[n, as, bs, cs] <- replicateM 4 T.getLine
  return res

bisectLeftV :: Int -> Vector Int -> Int
bisectLeftV n xs = unsafePerformIO $ do 
  xs' <- V.unsafeThaw xs
  binarySearchL xs' n

bisectRightV :: Int -> Vector Int -> Int
bisectRightV n xs = unsafePerformIO $ do 
  xs' <- V.unsafeThaw xs
  binarySearchR xs' n


sortedList :: t -> Text -> Vector Int
sortedList n txt = 
  V.fromList $ L.sort $ parseLineT txt


fhiyoProbTSrt
  :: [Text]
     -> (Int, Vector Int, [Int], Vector Int)
fhiyoProbTSrt [nStr, asStr, bsStr, csStr] = 
  let [n] = parseLineT nStr
      as =  sortedList n asStr
      bs =  parseLineT  bsStr
      cs = sortedList n csStr
  in (n, as, bs, cs)


fhiyoSolve (n, as, bs, cs) = 
  foldl (+) 0 $ map (\ b -> (bisectLeftV b as) * (n - bisectRightV b cs)) bs


stdinF = do
  ls <- getStdInputT 
  let problem = (fhiyoProbTSrt ls)
  print $ (fhiyoSolve problem)



main = 
  stdinF





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

int main(){
    int64_t n;
    cin >> n;
    map<int64_t, int64_t> mp;
    for(int64_t i = 0; i < n; i++){
        int64_t tmp;
        cin >> tmp;
        mp[tmp]++;
    }
    bool f = true;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        if(itr->second > 1) f = false;
    }
    cout << (f ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 12800
#include <iostream>
using namespace std;
int main()
{
    long long numa,x;
    cin >> numa >> x;
    if(x<=numa/2){
        x = numa-x;
    }
    long long numb = numa;
    long long ans = 0;

    long fin;

    ans += x;
    numb -= x;
    x= numb;
    ans += ((numa/x)*2-1)*x;
    numa %= x;
    if(numa<numb){
        swap(numa,numb);
    }
    fin = x;
    x = numb;
    if(x == 0){
        goto ANSWER;
    }

    for(;;){
        ans += (numa/x)*2*x;
        numa %= x;
        if(numa<numb){
            swap(numa,numb);
        }
        fin = x;
        x = numb;
        if(x==0){
            break;
        }
    }

ANSWER:
    ans -= fin;
    cout << ans << endl;

    return 0;

}

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

using namespace std;

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

	if (B % A == 0) {
		cout << A + B << endl;
	}
	else {
		cout << B - A << endl;
	}

}






Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	vector<vector<char> > C(H, vector<char>(W, '.'));
	REP(i, H)REP(j, W)cin >> C[i][j];
	vvll dp(H, vll(W, 0));
	dp[0][0] = 1;
	REP(i, H) {
		REP(j, W) {
			if (i != H - 1) {
				if (C[i + 1][j] == '.') {
					dp[i + 1][j] += dp[i][j];
					dp[i + 1][j] %= MOD;
				}
			}
			if (j != W - 1) {
				if (C[i][j + 1] == '.') {
					dp[i][j + 1] += dp[i][j];
					dp[i][j + 1] %= MOD;
				}
			}
		}
	}
	cout << dp[H - 1][W - 1] << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 9336
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin>>s;
	cout<<s[0]<<s.length()-2<<s.back()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const int N = 100010;
const int M = 50;
ll n, k, a[N], g[M], h[M];

ll calc (int s, int x) {
  ll res = 0;
  for (int i = 0; i < n; i++) {
    int t = (a[i] & (1LL << x)) > 0;
    if (t ^ s) res += (1LL << x);
  }
  return res;
}

ll solve() {
  h[0] = max(calc(1, 0), calc(0, 0));
  if (k & 1) g[0] = h[0];
  else g[0] = calc(0, 0);

  for (int i = 1; i < M; i++) {
    h[i] = max(calc(1, i), calc(0, i)) + h[i - 1];
    if (k & (1LL << i)) {
      g[i] = max(calc(1, i) + g[i - 1], calc(0, i) + h[i - 1]);
    } else {
      g[i] = calc(0, i) + g[i - 1];
    }
  }
  return g[M - 1];
}

int main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  printf("%lld\n", solve());
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

signed main(){
   IOS;
   int n, k; cin >> n >> k;
   vector<int> a(n);
   for(auto &x : a) cin >> x;
   sort(a.begin(), a.end());
   int ans = 0;
   for(int i = 0; i < k; i++) ans+=a[i];
   cout << ans << "\n";
}

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

using namespace std;

int main(){
  vector<int> v(3);
  for(int i=0;i<3;i++){
    cin>>v[i];
  }
  sort(v.begin(),v.end());
  int ans=0;
  ans=abs(v[0]-v[1])+abs(v[1]-v[2]);

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        int cnt = selectionSort(a,N);
        for (int i = 0; i < N; i++) {
            if(i > 0) System.out.print(" ");
            System.out.print(a[i]);
        }
        System.out.println();
        System.out.println(cnt);
        
        sc.close();
    }

    static int selectionSort(int[] A,int N)
    {
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            int minj = i;
            for (int j = i; j < N; j++) {
                if(A[j] < A[minj])
                {
                    minj = j;
                }
            }
            if(A[i] == A[minj])continue;
            int buf = A[i];
            A[i] = A[minj];
            A[minj] = buf;
            cnt++;
        }
        return cnt;
    }
}


Measured memory_bytes: 26516
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class E
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public static readonly int INF = int.MaxValue / 2;

	public void Solve()
	{
		int N = GetInt();
		int M = GetInt();
		int[] a = new int[M];
		int[] b = new int[M];
		int[,] c = new int[M, M];
		for(int i = 0; i < M; i++)
		{
			a[i] = GetInt();
			b[i] = GetInt();
			for(int j = 0; j < b[i]; j++)
				c[i, j] = GetInt() - 1;
		}

		int[,] dp = new int[M + 1, 1 << N];
		for(int i = 0; i <= M; i++)
			for(int j = 0; j < (1 << N); j++)
				dp[i, j] = INF;

		dp[0, 0] = 0;
		for(int i = 0; i < M; i++)
		{
			for(int s = 0; s < (1 << N); s++)
			{
				chmin(ref dp[i + 1, s], dp[i, s]);
				int t = s;
				for(int j = 0; j < b[i]; j++)
					t |= (1 << c[i, j]);

				chmin(ref dp[i + 1, t], dp[i, s] + a[i]);
			}
		}

		Console.WriteLine((dp[M, (1 << N) - 1] == INF) ? -1 : dp[M, (1 << N) - 1]);
	}

	private void chmin(ref int x, int y) => x = Math.Min(x, y);
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 28768
package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	io := newIo()
	n := io.nextInt()
	T := io.nextInt()

	var ans, pre int
	for i := range make([]struct{}, n) {
		ti := io.nextInt()
		ans += T
		if i != 0 {
			diff := ti - pre
			ans -= max(0, T-diff)
		}
		pre = ti
	}
	fmt.Println(ans)
}

type io struct {
	reader    *bufio.Reader
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
	}
}

func (io *io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) nextString() string {
	for io.nextToken >= len(io.tokens) {
		line := io.nextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) nextInt() int {
	i, _ := strconv.Atoi(io.nextString())
	return i
}


Measured memory_bytes: 8704
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

bool compare(const pair<pair<int,string>,int>  &a, const pair<pair<int,string>,int>  &b){
  if(a.first.second!=b.first.second) return a.first.second < b.first.second;
  else return a.first.first > b.first.first;
}

#if 0
#define DEBUG(x) do{cerr << x << endl;}while(0);
#else
#define DEBUG
#endif

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

	vector<int> l(n);


	vector<int> sum(n+1);
	sum[0] = 0;

	int ans = 0;

	for( int i=0; i<n; ++i ){
		cin >> l[i];
		sum[i+1] = sum[i] + l[i];
		if( sum[i+1] <= x ){
			ans++;
		}
	}

	cout << ans+1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(void){

  int i, j, H, W;

  while(1){
    scanf("%d %d", &H, &W);
    if(H == 0 && W == 0){
      break;
    }
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
        if((i+j)%2 == 0){
          printf("#");
        }else{
          printf(".");
        }
      }
      printf("\n");
    }
    printf("\n");
  }


  return 0;

}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int rate(int n) {
    if (n < 3200) {
        return n / 400;
    }
    return -1;
}
 
int main() {
    int n, a;
    cin >> n;
    map<int,int> m;
    for (int i = 0; i < n; i++) {
        cin >> a;
        m[rate(a)]++;
    }
    
    int ans = 0;
    int any = m[-1];
    for (int i = 0; i < 8; i++) {
        if (m[i]) ans++;
    }
    cout << max(1,ans) << " " << ans + any << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    string s; cin>>s;
    int N=s.size();

    int ans=0;
    REP(S,1<<(N-1)){
        int cur=s[0]-'0';
        REP(i,N-1){
            if(S>>i&1) ans+=cur,cur=0;
            cur=cur*10+(s[i+1]-'0');
        }
        ans+=cur;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
t = defaultdict(int)
n = int(input())
for i in range(n):
    s = input()
    t[s]+=1
print("AC x "+str(t["AC"]))
print("WA x "+str(t["WA"]))
print("TLE x "+str(t["TLE"]))
print("RE x "+str(t["RE"]))

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

const int N = 1e5 + 100;
int n, a[N];

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

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

    int sum = 0;
    cin >> n;
    forn(i,n) {
        cin >> a[i];
        sum += a[i]&1;
    }

    bool first = false;
    if (n%2 != sum%2) first = true;
    else if (n%2 == 1) {
        int turns = 0;
        while (true) {
            int pick = -1;
            forn(i,n) if (a[i]%2 == 1 && a[i] > 1) {
                pick = i;
                break;
            }

            if (pick == -1) break;
            a[pick]--;
            int g = 0; forn(i,n) g = gcd(g,a[i]);
            sum = 0; forn(i,n) a[i] /= g, sum += a[i]&1; 

            if (sum%2 == 1) turns++;
            else break;
        }
        first = turns%2 == 1;
    }
    cout << (first ? "First" : "Second") << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d;
  string s,ss;
  long long ans = 0;
  
  cin >> a >> b >> c;

  if(b-a == c-b) s = "YES";
  else s = "NO";
  
  cout << s << endl;

}

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

int main(){
    string s;
    cin >> s;
    int l = s.length();
    int t[l+1];
    int count[2020] = {};
    t[l] = 0;
    count[t[l]]++;
    long long n = 1;
    for (int i = 1; i < l+1; i++){
        t[l-i] = (t[l-i+1] + (s[l-i] - '0') * n) % 2019;
        count[t[l-i]]++;
        n = n * 10;
        n = n % 2019;
        //cout << t[l-i] << endl;
    }
    int sum = 0;
    for (int i = 0; i < 2020; i++){
        sum += count[i] * (count[i] - 1) / 2;
    }
    //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4500
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

template<typename T>
class segtree {
    int n;
    vector<T> val;
    T def;
    function<T(T,T)> merge,_update;
    T _query(int a,int b,int k,int l,int r) {
        if(b <= l || r <= a) return def;
        if(a <= l && r <= b) return val[k];
        T t1 = _query(a,b,2*k+1,l,(l+r)/2);
        T t2 = _query(a,b,2*k+2,(l+r)/2,r);
        return merge(t1,t2);
    }

public:
    segtree(int _n,vector<T> init,T def,
            function<T(T,T)> merge,function<T(T,T)> update)
            :def(def),merge(merge),_update(update) {
        n = 1;
        while(n < _n) n *= 2;
        val = vector<T>(2*n-1,def);
        rep(i,_n) val[i+n-1] = init[i];
        rrep(i,n-1) val[i] = merge(val[i*2+1],val[i*2+2]);
    }
    void update(int i,T x) {
        i += n-1;
        val[i] = _update(val[i],x);
        while(i > 0) {
            i = (i-1)/2;
            val[i] = merge(val[i*2+1],val[i*2+2]);
        }
    }
    // segment [a,b)
    T query(int a,int b) {
        return _query(a,b,0,0,n);
    }
    T operator[](int i) const { return val[i]; }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,q;
    string s;
    cin >> n >> s >> q;
    auto generate = [](char c) {
        bitset<26> b;
        b[c-'a'] = 1;
        return b;
    };
    vector<bitset<26>> init(n);
    rep(i,n) init[i] = generate(s[i]);
    segtree<bitset<26>> st(n,init,bitset<26>(0),
            [](auto a,auto b){ return a|b; },
            [](auto a,auto b){ return b; });
    rep(j,q) {
        int k;
        cin >> k;
        if(k == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            st.update(i,generate(c));
        } else {
            int l,r;
            cin >> l >> r;
            l--;
            cout << st.query(l,r).count() << endl;
        }
    }
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;





int main(){
  ll n;
  cin >> n;
  vector<ll>  w(n, 0);
  rep(i, n) cin >> w[i];


  ll sum = 0;
  rep(i, n) sum += w[i];

  ll s = 0;
  ll ab = 1e9;
  rep(i, n){
    ab = min(ab, abs(sum-s));
    sum -= w[i];
    s += w[i];
  }
  ab = min(ab, abs(sum-s));

  cout << ab << endl;



  return 0;
}


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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int A, B; cin >> A >> B;
    cout << (A - 1) * (B - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1LL<<60;
long double pi=3.14159265358979323846L;
double eps=1e-12;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll gya[2000110];
ll kai[2000110];
void nckinit(ll n,ll md){
  kai[0]=1;
  kai[1]=1;
  for(int i=2;i<=n;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=md;
  }
  gya[n]=gyaku(kai[n],md);
  for(int i=n-1;i>=1;i--){
    gya[i]=gya[i+1]*(i+1);
    gya[i]%=md;
  }
  gya[0]=1;
}
ll nck(ll n,ll k,ll md){
  if(k<0)return 0;
  if(k==0||n==k)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=md;
  ret*=gya[k];
  ret%=md;
  return ret;
}
ll npk(ll n,ll k,ll md){
  if(k<0)return 0;
  if(k==0)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=md;
  return ret;
}
ll s(ll r,ll c){
    ll ret=0;
    rep(i,1,c+2){
        (ret+=nck(r+i,r,mod))%=mod;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll r1,c1,r2,c2;
    cin>>r1>>c1>>r2>>c2;
    nckinit(2000010,mod);
    ll ans=0;
    ans+=s(r2,c2);
    (ans+=-s(r1-1,c2)+mod)%=mod;
    (ans+=-s(r2,c1-1)+mod)%=mod;
    (ans+=s(r1-1,c1-1)+mod)%=mod;
    cout<<ans<<endl;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

using namespace std;
int main() {

	int n, m;

	cin >> n >> m;
	vector<int> vec(n);
	
	vector<bool> tenbou(n,true);

	//set<int> st;

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

	for (int i = 0; i < m; i++)
	{

		int a, b;
		cin >> a >> b;

		/*st.insert(a);
		st.insert(b);*/


		if (vec[a - 1] < vec[b - 1]) {
			tenbou[a - 1] = false;
		}
		if (vec[a - 1] == vec[b - 1]) {
			tenbou[a - 1] = false;
			tenbou[b - 1] = false;
		}
		if (vec[a - 1] > vec[b - 1]) {
			tenbou[b - 1] = false;
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		if (tenbou[i]) {
			ans++;
		}
	}
	cout << ans << endl;




}

Measured memory_bytes: 3788
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

def read():
    A,B =map(int,input().split())

    return A,B


def solve(A,B):
    ans=lcm(A,B)
    return ans


if __name__ == '__main__':
    A,B = read()
    print("%d" % solve(A,B))


Measured memory_bytes: 3316
import itertools

n, m = map(int, input().split())

path = [[False] * n for i in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  path[a][b] = True
  path[b][a] = True
  
ans = 0

for i in itertools.permutations(range(n), n):
  if i[0] == 0:
    for j in range(n):
      if j == n - 1:
        ans += 1
        break
      if not path[i[j]][i[j+1]]:
        break
        
print(ans)

Measured memory_bytes: 9204
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };



int main() {
	llint n,a,b;
	cin >> n>>a>>b;
	hei(llint) s(n - 1),x(n);
	rep(i, 0, n)cin >> x[i];
	rep(i, 0, n - 1) {
		s[i] = x[i + 1] - x[i];
	}
	llint ans = 0;
	rep(i, 0, n - 1) {
		if (s[i] * a > b)ans += b;
		else ans += s[i] * a;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
def slove():
    import sys
    import itertools
    input = sys.stdin.readline
    ae = [int(input().rstrip('\n')) for _ in range(5)]
    k = int(input().rstrip('\n'))
    for v in itertools.combinations(ae, 2):
        i, j = v
        if abs(i - j) > k:
            print(":(")
            exit()
    print("Yay!")


if __name__ == '__main__':
    slove()


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 200200;

int n, a[M], m, b[M];

void read() {
  cin >> n;
  m = 2 * n - 1;

  for (int i = 0; i < m; ++i) {
    cin >> a[i];
    --a[i];
  }
}

bool bin(int x) {
  for (int i = 0; i < m; ++i)
    b[i] = a[i] <= x ? 1 : 0;

  int mid = n - 1;
  int l = mid, r = mid;
  int dl = 0, dr = 0;

  while (l > 0 && b[l - 1] != b[l]) {
    --l;
    ++dl;
  }

  while (r + 1 < m && b[r] != b[r + 1]) {
    ++r;
    ++dr;
  }

  if (l == 0 && r == m - 1) {
    return ((n - 1) % 2) ^ b[mid];
  }

  if (dl < dr) 
    return b[l];
  else
    return b[r];
}

void kill() {
  /*
  for (int i = 0; i < m; ++i) {
    cerr << i + 1 << " " << bin(i) << endl;
  }
  */
  int l = 0, r = m - 1;
  while (l < r) {
    int mb = (l + r) / 2;
    if (bin(mb))
      r = mb;
    else
      l = mb + 1;
  }

  cout << l + 1 << endl;
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 1920
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int DP[200005];

int main() {
  int N;
  cin>>N;
  string X;
  cin>>X;
  int bit = 0;
  for(int i=0;i<N;++i) {
    if(X[i]=='1') bit++;
  }
  if(bit==0) {
    for(int i=0;i<N;++i) cout<<1<<endl;
    return 0;
  }
  if(bit==1) {
    for(int i=0;i<N;++i) {
      if(X[i]=='1') cout<<0<<endl;
      else {
        if(i==N-1 || X[N-1]=='1') cout<<2<<endl;
        else cout<<1<<endl;
      }
    }
    return 0;
  }
  int DP1[N], DP2[N];
  int two1 = 1, two2 = 1;
  if(X[N-1]=='1') {
    DP1[N-1] = 1%(bit+1);
    DP2[N-1] = 1%(bit-1);
  }
  else {
    DP1[N-1] = 0;
    DP2[N-1] = 0;
  }
  for(int i=N-2;i>=0;--i) {
    two1 *= 2;
    two1 %= bit+1;
    two2 *= 2;
    two2 %= bit-1;
    if(X[i]=='1') {
      DP1[i] = (two1+DP1[i+1])%(bit+1);
      DP2[i] = (two2+DP2[i+1])%(bit-1);
    }
    else {
      DP1[i] = DP1[i+1];
      DP2[i] = DP2[i+1];
    }
  }
  int ans[N];
  two1 = 1;
  two2 = 1;
  for(int i=N-1;i>=0;--i) {
    if(X[i]=='1') {
      ans[i] = (DP2[0]-two2+(bit-1))%(bit-1);
    }
    else {
      ans[i] = (DP1[0]+two1)%(bit+1);
    }
    two1 *= 2;
    two1 %= bit+1;
    two2 *= 2;
    two2 %= bit-1;
  }
  for(int i=1;i<200005;++i) {
    bit = 0;
    for(int j=0;j<20;++j) {
      if((i&(1<<j))!=0) bit++;
    }
    DP[i] = 1+DP[i%bit];
  }
  for(int i=0;i<N;++i) {
    ans[i] = 1+DP[ans[i]];
  }
  for(int i=0;i<N;++i) cout<<ans[i]<<endl;
}



Measured memory_bytes: 6820
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let N: i32 = read();
    let P: Vec<i32> = (0..N).map(|_| read()).collect();
    let mut ans = 0;
    let mut ma = 0;
    for &p in &P {
        ans += p;
        ma = std::cmp::max(ma, p);
    }
    println!("{}", ans - ma/2);
}


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

def isPrime(n):
  if n < 2:
    return False
  i = 2
  while i*i <= n:
    if n%i == 0:
      return False
    i += 1
  return True

for i in range(X,X+10**5):
    if isPrime(i):
        print(i)
        exit()


Measured memory_bytes: 2940
import java.util.Scanner;
class Main{
    public static void main(String []args){
    Scanner input=new Scanner(System.in);
      String S=input.next();
      String T=input.next();
      int result=0;
      for(int i=0;i<S.length();i++){
      if(S.charAt(i)!=T.charAt(i)){
      ++result;}
      }System.out.println(result);
    }
}

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

xmin = int(n/1.08)
xmax = int((n+1)/1.08)


if n%27 == 0:
  print(xmax)
elif (n+1)%27 == 0:
  print(":(")
elif xmin == xmax:
  print(":(")
else:
  print(xmax)

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

using namespace std;

int main(void){
    map<string, int> s_cnt;
    int max_cnt = 0;

    int N;
    cin >> N;

    for(int i=0; i<N; i++){
        string s;

        cin >> s;
        s_cnt[s]++;

        max_cnt = max(max_cnt, s_cnt[s]);
    }

    for(auto&& s : s_cnt){
        if(s.second == max_cnt){
            cout << s.first << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 25216
import sys

if __name__ == "__main__":
 
    N = int(input())
 
    P = list(map(int,input().split()))

    if(0 in P):
        print(0)
    else:
        P.sort()

        mult = 1
        for i in P:
            mult *= i 
            if (mult > 10 ** 18):
                print(-1)
                sys.exit()

        print(mult)


Measured memory_bytes: 21640
h, w = gets.split.map(&:to_i)
s = h.times.map{gets.split}
r = h.times.to_a.product(w.times.to_a).select{|y, x| s[y][x] == "snuke"}
puts r.map{|y, x| "#{('A'..'Z').to_a[x]}#{y+1}"}

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

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

const long long INF = 1LL << 60;


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

    if(N < 6){
        cout << N << endl;
        return 0;
    }

    vector<int> dp(100010, 1000000000);
    dp.at(0) = 0;

    for(int i=1; i<= 100000; i++){
        int power = 1;
        while(power <= i){
            dp.at(i) = min(dp.at(i), dp.at(i-power)+1);
            power *= 6;
        }
    }

    for(int i=1; i<= 100000; i++){
        int power = 1;
        while(power <= i){
            dp.at(i) = min(dp.at(i), dp.at(i-power)+1);
            power *= 9;
        }
    }

    cout << dp.at(N) << endl;

/*
    int hoge = N;
    for(int i=0; i<=N; i++){
        int cc = 0;
        int t=i;
        while(t>0) cc+=t%6, t/=6;
        t=N-i;
        while(t>0) cc+=t%9, t/=9;
        if(hoge>cc) hoge = cc;  
    }

    cout << hoge <<endl;
*/


}

Measured memory_bytes: 640
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;

int main(int argc, char* argv[]) {

	string s;
	int flg[26] = {0};
	char ans = 'a';
	int i;

	cin >> s;

	for (i = 0; i < s.length(); i++) {
		flg[s[i] - 'a']++;
	}

	for (i = 0; i < 26; i++) {
		if (flg[i] == 0)
			break;

	}

	if(i==26){
        cout << "None" << endl;
	}else{
		cout << (char)(ans + i) << endl;
	}

	return 0;
}


Measured memory_bytes: 512
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
ll readll(){
    ll p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
int main(){
	ll x=readll(), k=readll(), d=readll();
	ll p=-x/d;
	ll ans;
	if (abs(p)>=k) ans=abs(x+k*d*(x<0?1:-1));
	else{
		k-=abs(p);
		if (x<0) p+=k&1;
		else p-=k&1;
		ans=abs(x+d*p);
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(){
  long int s,i,j,sum=0,n=0,t,u;
  scanf("%ld",&s);
  for(i=s;i;i/=10)n++;
  if(n-1)for(i=0;i<1<<(n-1);i++){
    t=1;u=s;
    for(j=0;j<n-1;j++){
      t*=10;
      if(i&1<<j){sum+=u%t;u/=t;t=1;}
    }
    sum+=u;
  }
  if(!(n-1))sum=s;
  printf("%ld",sum);
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
#include<iostream>
#include<cmath>
#include<queue>
#include<cctype>
#include<string>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define INF 2100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
int kin[4545],flg[45454545],dp[45454545];	
void sosu()
{
	for(int i=2;i<=1000000;i++) flg[i]=1;
	for(int i=2;i*i<=1000000;i++){
		if(flg[i]==1){
			for(int j=2;j*i<1000000;j++) flg[i*j]=0;
		}
	}
}
int main(void)
{
	sosu();
	int n,x,ff;
	while(cin>>n>>x) {
		if(!n&&!x) break;
		rep(i,0,n) cin>>kin[i];
		rep(i,0,x+1) dp[i]=0;
		dp[0]=1;
		rep(i,0,n) {
			rep(j,0,x) {
				if(dp[j]==1) {
					if(j+kin[i]<=x) dp[j+kin[i]]=1;
				}
			}
		}
		ff=0;
		for(int i=x;i>=2;i--) {
			if(dp[i]&&flg[i]) {cout<<i<<endl,ff=1;break;}
		}
		if(ff==0) cout<<"NA"<<endl;
	}
	return 0;
}
	
	
	
	
	

	

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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
    public:
    double x, y;
    
    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) { return Point(x + p.x, y + p.y); }
    Point operator - (Point p) { return Point(x - p.x, y - p.y); }
    Point operator * (double a) { return Point(a * x, a * y); }
    Point operator / (double a) { return Point(x / a, y / a); }

    double abs() {
        return sqrt(norm());
    }
    double norm() {
        return x * x + y * y;
    }

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const {
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }
};

typedef Point Vector;

double dot(Vector a, Vector b) {
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
    return a.x * b.y - a.y * b.x;
}

struct Segment {
    Point p1, p2;
};

typedef Segment Line;

class Circle {
    public:
        Point c;
        double r;
        Circle(Point c = Point(), double r = 0.0): c(c), r(r) {}
};

typedef vector<Point> Polygon;

bool isParallel(Vector a, Vector b) {
    return equals(dot(a, b), 0.0);
}

bool isParallel(Point a1, Point a2, Point b1, Point b2) {
    return isParallel(a1 - a2, b1 - b2);
}

bool isParallel(Segment s1, Segment s2) {
    return equals(cross((s1.p2 - s1.p1), (s2.p2 - s2.p1)), 0.0);
}

bool isOrthogonal(Vector a, Vector b) {
    return equals(cross(a, b), 0.0);
}

bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
    return isOrthogonal(a1 - a2, b1 - b2);
}

bool isOrthogonal(Segment s1, Segment s2) {
    return equals(dot((s1.p2 - s1.p1), (s2.p2 - s2.p1)), 0.0);
}

Point project(Segment s, Point p) {
    Vector base = s.p2 - s.p1;
    double r = dot(p - s.p1, base) / base.norm();
    return s.p1 + base * r;
}

Point reflect(Segment s, Point p) {
    Point projection = project(s, p);
    Vector toReflection = (projection - p) * 2.0;
    return p + toReflection; 
}

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    Point p1 = {x1, y1};
    Point p2 = {x2, y2};
    Segment s = {p1, p2};

    int q;
    cin >> q;
    double x, y;
    cout << fixed << setprecision(11);
    for (int i = 0; i < q; i++) {
        cin >> x >> y;
        Point p = {x, y};

        Point x = reflect(s, p);

        cout << x.x << " " << x.y << endl;
    }
}



Measured memory_bytes: 3284
#include<bits/stdc++.h>
#define ll long long int
#define sz  200010
using namespace std;


string ss[sz];

int main()
{


    string x="";

    ll h,w,i,j,k,p,a,b;

    cin>>h>>w;

    for(i=1; i<=h; i++)cin>>ss[i];

    for(i=1; i<=w+2; i++)x+="#";

    cout<<x<<endl;
    for(i=1; i<=h; i++)
    {
        cout<<"#"<<ss[i]<<"#"<<endl;
    }
    cout<<x<<endl;



    return 0;
}



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

const int MAXN = 4000;
const int MOD = 998244353;
int c[MAXN + 5][MAXN + 5];

void init() {
	for(int i=0;i<=MAXN;i++) {
		c[i][0] = 1;
		for(int j=1;j<=i;j++)
			c[i][j] = (c[i-1][j-1] + c[i-1][j]) % MOD;
	}
}

int solve(int N, int K) {
	if( N < 0 ) return 0;
	return c[N + K - 1][K - 1];
}

int f[MAXN + 5];

int main() {
	init(); int K, N, M;
	scanf("%d%d", &K, &N), M = (K + 1) >> 1;
	
	for(int i=1;i<=M;i++)
		for(int j=0;j<=i;j++) {
			int d = 1LL*c[i][j]*solve(N - 2*j, K)%MOD;
			f[i] = (f[i] + (j & 1 ? MOD - d : d) ) % MOD;
		}
	
	for(int i=2;i<=2*K;i++) {
		int t = ((min(i - 1, K) - max(i - K, 1) + 1) + 1) >> 1;
		printf("%d\n", f[t]);
	}
}

Measured memory_bytes: 61312
#include<iostream>
#include<stdio.h>
//#define scanf scanf_s
using namespace std;
int  main() {
	int y, m, d;
	scanf("%d/%d/%d", &y, &m, &d);
	if (y < 2019) {
		cout << "Heisei" << endl;
	}
	else if (y == 2019 && m <= 4 && d <= 30) {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}
	return 0;
}

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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int siz = 2e5 + 10;
const int SIZ = 1e6 + 10;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "3";

int a[siz], b[siz];

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];

        a[i] += a[i - 1];
    }

    for (int i = 1; i <= m; i++) {
        cin >> b[i];

        b[i] += b[i - 1];
    }

    int ans = 0;
    for (int i = 0; i <= n; i++) {
        if (k - a[i] < 0) {
            break;
        }

        int j = upper_bound(b + 1, b + 1 + m, k - a[i]) - b - 1;

        ans = max(ans, i + j);
    }

    cout << ans << "\n";

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


Measured memory_bytes: 6780
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int R;
    cin >> R;
    if(R<1200){
        cout << "ABC" << endl;
    }else if(R<2800){
        cout << "ARC" << endl;
    }else{
        cout << "AGC" << endl;
    }
}


Measured memory_bytes: 256
flag = 0
k= int(input())
lists = list(map(int, input().split())) #１行の入力をi[0],i[1]というように空白で分けてを取得し、iに値を入れる
for i in range(lists[0],lists[1]+1):
    if i % k == 0:
        flag = 1
    else:
        pass
if flag ==1 :
    print('OK')
else:
    print('NG')

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

int main()
{
	char a, b;
	int c, d;
	cin >> a >> b;

	switch (a)
	{
	case 'A':
		c = 10;
		break;
	case 'B':
		c = 11;
		break;
	case 'C':
		c = 12;
		break;
	case 'D':
		c = 13;
		break;
	case 'E':
		c = 14;
		break;
	case 'F':
		c = 15;
		break;
			
	}

	switch (b)
	{
	case 'A':
		d= 10;
		break;
	case 'B':
		d = 11;
		break;
	case 'C':
		d = 12;
		break;
	case 'D':
		d = 13;
		break;
	case 'E':
		d = 14;
		break;
	case 'F':
		d = 15;
		break;

	}

	if (c > d)
	{
		cout << ">";
		return 0;
	}
	else if (c < d)
	{
		cout << "<";
		return 0;
	}
	if (c == d)
	{
		cout << "=";
		return 0;
	}
}	


Measured memory_bytes: 256
X,K,D=map(int,input().split())
ans=0

if X==0:
    if K%2==0:
        ans = 0
    else:
        ans = D
elif K <= abs(X)//D:
    ans = abs(X) - D * K
elif (K-abs(X)//D)%2==0:
    ans = abs(X) - abs(X)//D * D
elif (K-abs(X)//D)%2==1:
    ans = D - abs(abs(X) - abs(X)//D * D)

print(ans)

Measured memory_bytes: 9144
from collections import Counter

def main():
    N = int(input())
    D = list(map(int, input().split()))
    d = Counter(D)
    # 前処理
    d[0] += 1
    for i in range(13):
        if (i == 0 or i == 12) and d[i] == 2:
            print(0)
            exit()
        elif d[i] >= 3:
            print(0)
            exit()
    ans = 0
    for i in range(2**11):
        time = [0, 24]
        if d[12] == 1:
            time.append(12)
        for j in range(1,12):
            if d[j] == 1:
                if i >> j & 1:
                    time.append(24-j)
                else:
                    time.append(j)
            elif d[j] == 2:
                time.append(24-j)
                time.append(j)
        time.sort()
        ret = 25
        for i in range(1,len(time)):
            ret = min(ret, time[i]-time[i-1])
        ans = max(ans, ret)

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9484