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

int main(){
  constexpr int Xmax= 100;
  constexpr int Nbit= Xmax+ 2;
  int target,N;
  cin >> target >> N;

  bitset<Nbit> bs;
  int buf;
  for(int i=0; i<N; i++){
    cin >> buf;

    bs.set(buf);
  }
  
  bool found1= false;
  int cand1= INT_MAX;
  for(int x=target; x >= 0; x--){
    if(!bs.test(x)){
      cand1= x;
      found1= true;
      break;
    }
  }
  
  bool found2= false;
  int cand2= INT_MAX;
  for(int x=target+ 1; x<Nbit; x++){
    if(!bs.test(x)){
      cand2= x;
      found2= true;
      break;
    }
  }

  int ans= (abs(cand1- target) <= abs(cand2- target)) ? cand1
                                                      : cand2;
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
int main(void){
    int n,ans,x=0,i;
    char s[100000];
    scanf("%d %s", &n, s);
    ans=n;
    for(i=1; i<n; i++)
    {
        if(s[i-1]!=s[i])
        {
            ans-=x;
            x=0;
        }
        else
        x++;
    }
    printf("%d\n", ans-x);
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>          // putchar(), fgets()
#include <stdlib.h>         // strtol()
#include <ctype.h>          // isupper()

typedef struct code_tbl
{
	const char c;
	const char *code;
} code_t;

const char NUL = '\0';
const char *code[26] = 
{
	/* A         B           C       D       E      F        G           H         I       J           K       L        M           N               */
	  "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", /* x */
	/* O        P      Q           R       S        T        U           V           W         X           Y           Z                            */
	  "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"               /* x */
};

const code_t code2[6] = {{' ', "101"}, {'\'', "000000"}, {',', "000011"}, {'-', "10010001"}, {'.', "010001"}, {'?', "000001"}};
const char chara[6] = {' ', '.', ',', '-', '\'', '?'};

int
main(int argc, char **argv)
{
	char line[101];
	char trans[801];  /* 8 * 100 + 1 */
	char bina[906]; /* 800 + 159 + 1 */
	const char *s, *t;
	char *u;
	char *nextp = NULL;
	int i;

	while (fgets(line, sizeof(line), stdin) != NULL)
	{
		int ix = 0;
		s = line;
		for (; *s != '\n' && *s != NUL; ++s)
		{
			if (isupper(*s))
				t = code[*s - 'A'];

			else
			{
				for (i = 0; i < 6 && *s != code2[i].c; ++i)
					;

				t = code2[i].code;
			}

			for (; *t != NUL; ++t)
				trans[ix++] = *t;

		}

		trans[ix] = NUL;
		s = trans;
		u = bina;
		while (*s != NUL)
		{
			if (s != trans)
				*u++ = ' ';

			for (i = 0; i < 5; ++i)
			{
				if (*s == NUL)
					*u++ = '0';
				else
					*u++ = *s++;
			}
		}

		*u = NUL;		
		s = bina;
		while (*s != NUL)
		{
			i = strtol(s, &nextp, 2);
			s = nextp;
			if (i < 0x1a)
				putchar(i + 'A');
			else
				putchar(chara[i - 0x1a]);
		}

		putchar('\n');
	}

	return 0;
}

Measured memory_bytes: 520
#pragma GCC optimize ("Ofast")
#include <iostream>
using namespace std;

inline void fastin(int &num) {
    int c;
    num = 0;
    c = getchar();
    for (; (c > 47 && c < 58); c = getchar()) num = num * 10 + c - 48;
}
 
int main(){
    int n; fastin(n);

    for (int i = 0; i < n; ++i){
        int a; fastin(a);
        if (a % 2 == 1) {
            putchar_unlocked('f');
            putchar_unlocked('i');
            putchar_unlocked('r');
            putchar_unlocked('s');
            putchar_unlocked('t');
            return 0;
        }
    }
 
    putchar_unlocked('s');
    putchar_unlocked('e');
    putchar_unlocked('c');
    putchar_unlocked('o');
    putchar_unlocked('n');
    putchar_unlocked('d');
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
int main(){
	double d;
	cin>>d;
	double ans=0.0;
	double a=1.0;
	while(true){
		if(a>d)break;
		if(d<=(double)sqrt((double)(a*a+1.0)))
			ans=a+1.0;
		a+=1.0;
	}
	double b=(double)sqrt((double)2.0)*d;
	if(ans<b)ans=b;
	cout<<fixed<<setprecision(20)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1284
#input
S = str(input())

#output
S1 = int(S[:2])
S2 = int(S[2:])

if S1 == 0 and S2 == 0:
    print("NA")
elif S1 ==0 and 0 < S2 <= 12:
    print("YYMM")
elif S1 == 0 and S2 > 12:
    print("NA")
elif S2 == 0 and S1 > 12:
    print("NA")
elif S2 == 0 and 0 < S1 <= 12:
    print("MMYY")
elif 0 < S1 <= 12 and 0 < S2 <= 12:
    print("AMBIGUOUS")
elif S1 > 12 and 0 < S2 <= 12:
    print("YYMM")
elif 0 < S1 <= 12 and S2 > 12:
    print("MMYY")
elif S1 > 12 and S2 > 12:
    print("NA")

Measured memory_bytes: 3064
#include <stdio.h>
int main(){
  
  int W, H, x, y, r;
  scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
  if ( 0 + r <= x && x <= W - r && 0 + r <= y && y <= H - r) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<62)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/
constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a/gcd(a,b)*b;}


ll mul(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}

ll power(ll x,ll y){
    if(y==0) return 1;
    else if(y==1) return x%MOD;
    else if(y%2==0) return power(x,y/2)*power(x,y/2)%MOD;
    else return (power(x,y/2)*power(x,y/2))%MOD*x%MOD;
}

ll divi(ll a,ll b){
    return mul(a,power(b,MOD-2));
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll h,n;
    cin>>h>>n;
    ll a,sum=0;
    rep(i,n){
        cin>>a;
        sum+=a;
    }
    Yn(h<=sum);

}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int a,b,c,min,mid,max;
  scanf("%d%d%d",&a,&b,&c);
  min=(a<b)?a:b;
  min=(min<c)?min:c;
  max=(a>b)?a:b;
  max=(max>c)?max:c;
  mid=a+b+c-min-max;
  if(min+mid==max){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt();
    if (a+b >= c) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


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

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		solve(s);
		s.close();
	}

	public static void solve(Scanner s) {
		int n = s.nextInt();
		int l = s.nextInt();
		String[] str = new String[n];

		for (int i = 0; i < n; i++) {
			str[i] = s.next();
		}

		Arrays.sort(str);

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			sb.append(str[i]);
		}

		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 10192
import sys
sys.setrecursionlimit(10**7)
black = 0
white = 0
#x,y渡すと、（ｈ、ｗ）に入ってるかどうか判定
def check(s,t):
    if (0 <=  s <= h - 1) and (0 <= t <= w - 1):
        return True
    else:
        return False
def bfs(que):
    finished = set()
    while que:
        x , y, color = que.popleft()
        if x+y*w not in finished:
            finished.add(x+y*w)
            for i, j in ((1, 0), (0, 1)):
                if abs(i) + abs(j) < 2 and check(y+j,x+i):
                    if (x+i)+(y+j)*w not in finished:
                        que.append([x+i,y+j,grid[y+j][x+i]])
                    if color != grid[y+j][x+i]:
                        adjacent_list[x+w*y].append((x + i)+w*(y + j))
                        adjacent_list[(x + i)+w*(y + j)].append(x+w*y)
def dfs(node):
    global white
    global black
    finished.add(node)
    y,x = divmod(node,w)
    if grid[y][x] == '#':
        black += 1
    else:
        white += 1
    for i in adjacent_list[node]:
        if i not in finished:
            dfs(i)
from collections import deque
h,w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
ans = 0
adjacent_list = [[] for i in range(h*w)]
que = deque()
que.append([0,0,grid[0][0]])
bfs(que)
#再び初期化
finished = set()
for i in range(h*w):
    #頂点iからdfsをする。黒と白をカウントしておいて最後にかける
    black = 0
    white = 0
    if i not in finished:
        dfs(i)
        ans += black * white
print(ans)



Measured memory_bytes: 278688
def main():
    n=int(input())
    aa=map(int,input().split())
    x=1
    for a in aa:
        if a == 0:
            print(0)
            return
        if x<1000000000000000000:
            x*=a
    if x>1000000000000000000:
        print(-1)
    else:
        print(x)
main()

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

int main(){
    int n;
    cin>>n;
    vint x(n),y(n);
    rep(i,n){
        cin>>x[i]>>y[i];
    }
    map<pair<ll,ll>, int> table;

    rep(i,n){
        reps(j,i+1,n){
            table[mp(x[i]-x[j],y[i]-y[j])]+=1;
            table[mp(x[j]-x[i],y[j]-y[i])]+=1;
        }
    }
    int maxnum=0;
    for(auto x:table){
        //cout<<x.second<<" "<<maxnum<<endl;
        maxnum=max(maxnum,x.second);
    }
    cout<<n-maxnum<<endl;
}

Measured memory_bytes: 384
var
        n,d,i,j:byte;
        t,a,b,c:string;
begin

        readln(n);
        readln(t);
        for i:=1 to n do if t[i]<>' ' then a:=a+t[i];
        for j:=1 to n do  b:=b+t[i+j+1];
        i:=0;
        while i<>n do
        begin
                if (d=0) then
                begin
                        inc(i);
                        c:=c+a[i];
                        inc(d);
                end;
                if (d=1) then
                begin
                        c:=c+b[i];
                        dec(d);
                end;
        end;
        write(c);
        
end.







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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 2;
//const ll mod = 1e9+7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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 (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

const ll N_MAX = 2000005;

ll inv[N_MAX],fac[N_MAX],finv[N_MAX];
void make(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll) i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}

ll combination(ll C, ll D){
    if(C<D||C<1) return 0;
    dump(fac[C])
    dump(finv[D])
    dump(finv[C-D])
    return fac[C]*(finv[D]*finv[C-D]%mod)%mod;
}

ll comb(ll n, ll r){
	return (n==(r|(n-r)));
}

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

    ll N;
    cin >> N;
    string s;
    cin >> s;
    vector<ll> a(N);
    REP(i, N) a[i] = s[i] - '0';

    ll x = 0;
    REP(i, N){
    	x += comb(N-1, i)*a[i];
    	x %= 2;
    }
    //dump(x)

    ll res = -1;
    if(x%2==1){
    	res = 1;
    }else{
    	vector<ll> b(N-1);
    	REP(i, N-1) b[i] = abs(a[i+1]-a[i]);
    	bool ok = true;
    	REP(i, N-1){
    		if(b[i]==1) ok = false;
    	}
    	if(ok){
    		ll y = 0;
    		REP(i, N-1){
    			b[i] /= 2;
    		}
    		REP(i, N-1){
    			y += comb(N-2, i)*b[i];
    			y %= 2;
    		}
    		if(y%2==1){
    			res = 2;
    		}else{
    			res = 0;
    		}
    	}else{
    		res = 0;
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 17052
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define INF 1e+15

int main()
{
	int N,M,L;
	cin >> N >> M >>L;
	vector<vector<ll>> graph(N,vector<ll> (N,INF));
	ll A,B,C;
	for (int i=0;i<M;i++)
	{
		cin >> A >> B >> C;
		graph[A-1][B-1]=C;
		graph[B-1][A-1]=C;
	}
	for (int k=0;k<N;k++)
		for (int i=0;i<N;i++)
			for (int j=0;j<N;j++)
			{
				graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
			}
	for (int i=0;i<N;i++)
		for (int j=0;j<N;j++)
		{
			if(graph[i][j]<=L) graph[i][j]=1;
			else graph[i][j]=INF;
		}

	for (int k=0;k<N;k++)
		for (int i=0;i<N;i++)
			for (int j=0;j<N;j++)
			{
				graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
			}
	int Q; cin >> Q;
	int a,b;
	for (int i=0;i<Q;i++)
	{
		cin >> a>>b;
		if (graph[a-1][b-1]==INF) cout << -1 << endl;
		else cout << graph[a-1][b-1]-1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
 
int main(void){
	
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	if(a%3==0 || b%3==0 || (a+b)%3==0 ){
	printf("Possible\n");
	} else  {
	printf("Impossible\n");
	}
	return 0;
}

Measured memory_bytes: 128
object Main extends App {
  val sc = new java.util.Scanner(Console.in)

  def nextInt() = Integer.parseInt(sc.next)
  def next() = sc.next

  var taro = 0
  var hanako = 0

  var n = nextInt
  while (n > 0) {
    val cmp = next compare next
    if (cmp > 0)
      taro += 3
    else if (cmp < 0)
      hanako += 3
    else {
      taro += 1
      hanako += 1
    }
    n -= 1
  }

  println(s"$taro $hanako")
}



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  string s;
  cin >> n >> s;
  bool f = false;
  if (n % 2 == 0) {
    f = true;
    rep(i, n / 2) if (s[i] != s[i + n / 2]) f = false;
  }
  cout << (f ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b; cin >> a >> b;
  if( a % 3 == 0 || b % 3 == 0 || (a+b)%3 == 0){ 
    cout << "Possible" << endl;}
  else{ cout << "Impossible" << endl;}
  
  return 0;
} 

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

int main() {
    int N, A;
    cin >> N;
    map<int, int> mp;
    rep(i,N) {
        cin >> A;
        ++mp[A];
    }
    ll ans = 1;
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    rep(i,2) pq.push(0);
    for (auto x : mp) {
        if (x.second >= 2) {
            if (x.first > pq.top()) {
                pq.pop();
                pq.push(x.first);
                if (x.second >= 4) {
                    if (x.first > pq.top()) {
                    pq.pop();
                    pq.push(x.first);
                    }
                }
            }
        }
    }
    rep(i,2) {
        ans *= pq.top();
        pq.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 8176
n, k = map(int, input().split())
A = list(map(int, input().split()))

B = [[0]*2 for _ in range(42)]
for a in A:
    b = format(a, 'b')
    b = list(b)
    b.reverse()
    for i in range(len(b)):
        if b[i] == '1':
            B[i][1] += 1

for i in range(42):
    if B[i][1] != 0:
        B[i][0] = n-B[i][1]
B.reverse()
#print(B)
temp = 0
max_ = 0
for i, (b0, b1) in enumerate(B):
    if b1 == 0:
        if temp + 2**(41-i) <= k:
            max_ += n*2**(41-i)
            temp += 2**(41-i)
    else:
        if b0 >= b1:
            if temp + 2**(41-i) <= k:
                max_ += b0*2**(41-i)
                temp += 2**(41-i)
            else:
                max_ += b1*2**(41-i)
                temp += 0
        else:
            max_ += b1*2**(41-i)
            temp += 0
print(max_)


Measured memory_bytes: 20860
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template< typename T > using matrix = vector< vector< T > >;

//FUNCTION  
void solve(void)
{
  int N,C;
  cin>>N>>C;
  vector<vector<int> > D(C,vector<int>(C));
  vector<map<int,int> > mp(3);
  for (int i = 0; i < C; i++)
  {
    for (int j = 0; j < C; j++)
    {
      cin>>D[i][j];
    }
  }
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      int A;
      cin>>A;
      A--;
      mp[(i+j+2)%3][A]++;
    }
  }
  
  vector<vector<int> > COST(3,vector<int>(C,0));
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < C; j++)
    {
      for (auto itr = mp[i].begin(); itr != mp[i].end(); itr++)
      {
        // if(i==2)DEBUG(itr->second);
        COST[i][j] += D[itr->first][j]*itr->second;
      } 
    }
  }
  // DEBUG(COST);
  int ANS = INF;
  for (int i = 0; i < C; i++)
  {
    for (int j = 0; j < C; j++)
    {
      for (int k = 0; k < C; k++)
      {
        if(i != j && j != k && k != i)
        {
          chmin(ANS,COST[0][i] + COST[1][j]+COST[2][k]);
        }
      }
    }
  }
  cout<<ANS<<endl;
  
  
  
  
  

  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

void trace (int A[], int n){
    for(int i=0;i<n;i++){
        if(i>0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

void insertionSort(int A[], int n){
    int v,j;
    for(int i=1;i<n;i++){
        v = A[i];
        j = i-1;
        while(j>=0 && A[j] >v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A, n);
    }
}

int main() {
    int n;
    int A[100];
    
    cin >> n;
    for(int i=0;i<n;i++) {
        cin>>A[i];
    };
    
    trace(A,n);
    insertionSort(A,n);
    return 0;
}


Measured memory_bytes: 3088
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

ll n,a,b;

int main(){
  cin >> n >> a >> b;
  if(a > b) cout << 0 << endl;
  else if(n == 1){
    if(a != b) cout << 0 << endl;
    else cout << 1 << endl;
  }
  else{
    ll ans = (n - 2) * (b - a) + 1;
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
using ll = long long;

int main(){
  ll n; cin >> n;
  vector<ll> r(n);
  REP(i,n) cin >> r[i];
  ll maxd = r[1] - r[0], minr = r[0];
  FOR(i,1,n){
    maxd = max(r[i] - minr, maxd);
    minr = min(r[i], minr);
  }
  cout << maxd << endl;
  return 0;
}


Measured memory_bytes: 4352
#include <iostream>
const int MAX_N = 1000100;
using namespace std;
struct P 
{
    string name;
    int val;
};
template<class Type> class Queue
{
    public:
        int head = 0, tail = 0;
        Type *Q;
        Queue(int size)
        {
            Q = new Type[2 * size];
        }
        void push(Type x)
        {
            Q[tail] = x;
            tail++;
        }
        Type pop(){
            Type ret = Q[head];
            head++;
            return ret;
        }
        Type front()
        {
            return Q[head];
        }
        bool empty(){
            return head == tail;
        }
};
int main()
{
    int n, t;
    cin >> n >> t;
    Queue<P> que(MAX_N);
    for(int i = 0; i < n; i++)
    {
        P info;
        cin >> info.name >> info.val;
        que.push(info);
    }
    int sum = 0;
    while(!que.empty())
    {
        P tmp = que.front(); que.pop();
        if(tmp.val - t <= 0) 
        {
            sum += tmp.val;
            cout << tmp.name << " " << sum << "\n";
        }
        else
        {
            tmp.val -= t;
            sum += t;
            que.push(tmp);
        }
    }
    return 0;
}


Measured memory_bytes: 36656
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 
		int h = sc.nextInt();
		int w = sc.nextInt();

		int sqare = h * w;
		int round = 2 *(h + w);
		
		System.out.println(sqare + " " + round);

	}

}

Measured memory_bytes: 17160
#include <iostream>
int main(){

  int N;
  scanf("%d",&N);
  int A[N];
  double sum=0.0;
  for (int i=0; i<N; i++){
    scanf("%d",&A[i]);
    sum+=1./A[i];
  }
  for (int i=0; i<N; i++){
    //printf("%d\n",A[i]);
  }
  double ans = 1./sum;
  printf("%f\n",ans);

  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  if (a > b) {
    ans += a;
    a--;
  }
   else {
     ans += b;
     b--;
   }if (a > b) {
    ans += a;
    a--;
  }
   else {
     ans += b;
     b--;
   }
  cout << ans << endl;
}
  
  

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

int main(){
	string s;
	string t;
	int cnt=0;
	cin>>s>>t;

	for(int i=0;i<s.size();i++){
		if(s[i]==t[i]);
		else cnt++;
	}

	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 3872
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()

//#define MOD 1000000007LL
#define MOD 998244353LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;


int n;
deque<string> ans;

void solve(string s, char c) {
	if (s.size() == n) {
		ans.emplace_back(s);
		return;
	}
	for (char c2 = 'a'; c2 <= c + 1; c2++) {
		solve(s + c2, max(c, c2));
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	solve("a", 'a');
	while (!ans.empty()) {
		cout << ans.front() << "\n";
		ans.pop_front();
	}
}

Measured memory_bytes: 7936
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

int n,m,a[19],U;

int jc[(1<<16)+5],ny[(1<<16)+5];
int C(int n,int m) 
{
	if (n<m) return 0;
	return (ll)jc[n]*ny[m]%mod*ny[n-m]%mod;
}

int dp[19][(1<<16)+5],bit[(1<<16)+5];


int main()
{
	scanf("%d%d",&n,&m);
	U=1<<n;
	for (int i=1;i<=m;i++) scanf("%d",&a[i]);
	
	jc[0]=jc[1]=ny[0]=ny[1]=1;
	for (int i=2;i<=U;i++) jc[i]=(ll)jc[i-1]*i%mod,ny[i]=(mod-mod/i)*ny[mod%i]%mod;
	for (int i=2;i<=U;i++) ny[i]=(ll)ny[i-1]*ny[i]%mod;
	
	bit[0]=1;for (int i=1;i<U;i++) if (i&1) bit[i]=mod-bit[i>>1];else bit[i]=bit[i>>1];
	
	int ans=0;
	dp[m+1][0]=1;
	for (int i=m+1;i>=1;i--) 
	{
		for (int s=U-1;s>=0;s--) if (dp[i][s]) 
		{
		//	printf("dp[%d][%d]=%d\n",i,s,dp[i][s]);
			if (i==1) 
			{
				ans=((ll)bit[s]*jc[U-1-s]%mod*dp[i][s]+ans)%mod;
				continue;
			}
			dp[i-1][s]=dp[i][s];
			
			for (int j=0;j<n;j++) if ( !(s&(1<<j)) ) 
			dp[i-1][s|(1<<j)]=
			((ll)C( U-a[i-1]-s ,(1<<j)-1 )*jc[1<<j]%mod*dp[i][s] + dp[i-1][s|(1<<j)] )%mod;
		}
	}
	printf("%lld",(ll)ans*U%mod);
	return 0;
}


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

int main() {
	int n, k; cin >> n >> k;
	vector<int>L(n); for (auto&& x : L)cin >> x;
	sort(L.rbegin(), L.rend());
	int sum = 0;
	for (int i = 0; i < k; i++) sum += L[i];
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
  #define int long long int 
  #define vi vector<int>
  #define pii pair<long long ,long long>
  #define pll pair<int,int>
  #define mod 1000000007
  #define hell 998244353
  #define all(x) x.begin(),x.end()
  #define mp(x,y) make_pair(x,y)
  #define mem(a,val) memset(a,val,sizeof(a))
  #define eb push_back
  #define ff first
  #define ss second
  #define rep(n) for(int i=0;i<n;i++)
  #define lb lower_bound
  #define up upper_bound
  
  void solve()
  { 
    
      string s;
      cin>>s;
      for(int i=0;i<s.length();i++)
      {
         if(i & 1)
           {
              if(s[i]=='R')
              {
                 cout<<"No";
                 return;
              }
           }
           else
            if(s[i]=='L')
            {
               cout<<"No";
               return;
            }

      }
      cout<<"Yes";

  }



  signed main()
  {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    
    
     
    
    int T;
    T=1;
    
    while(T--)
    {
      solve();
    }
    return 0;
  }

Measured memory_bytes: 384
def valid?(a, b, c)
  a <= b + c && b <= c + a + 1 && c <= a + b + 1
end
 
def calc(rear, front, west, east, north, south, limit, best)
  path = Array.new(limit, 0)
  limit.times do |i|
    a = rear + front
    b = west + east
    c = north + south
 
    if east > 0 && valid?(b - 1, c, a)
      rear, front, west, east = east - 1, west, rear, front
      y = 69
    elsif north > 0 && valid?(c - 1, a, b)
      rear, front, north, south = north - 1, south, front, rear
      y = 78
    elsif south > 0 && valid?(c - 1, a, b)
      rear, front, north, south = south - 1, north, rear, front
      y = 83
    #elsif west > 0 && valid?(b - 1, c, a)
    else
      rear, front, west, east = west - 1, east, front, rear
      y = 87
    end
     
    if best
      x = best[i]
      return best if x < y
      best = nil if x > y
    end
    path[i] = y  
  end
  path
end
 
def find(target, limit)
  best = nil
  target.permutation(6).to_a.uniq.each do |rear, front, west, east, north, south|
    a = rear + front
    b = west + east
    c = north + south
    if valid?(a, b, c)
      best = calc(rear, front, west, east, north, south, limit, best)
    end
  end
  best
end
 
loop do
  target = gets.split.map!(&:to_i)
  break if target.all?(&:zero?)
  p, q = gets.split.map!(&:to_i)
  result = find(target, q)
  puts result ? result[p-1..-1].pack('C*') : 'impossible'
end

Measured memory_bytes: 90628
ym = int(input())
 
ym1 = int(ym/100)
ym2 = int(ym%100)
 
if ym1 >= 1 and ym1 <= 12 and ym2 >= 1 and ym2 <=12:
  print('AMBIGUOUS')
elif ym2>=1 and ym2<=12:
  print('YYMM')
elif ym1>=1 and ym1<=12:
  print('MMYY')
else:
  print('NA')

Measured memory_bytes: 3060
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    target = LI()

    target.sort()

    ans = 0

    for i in range(N):
        for j in range(i+1, N):
            for k in range(j+1, N):
                if target[i] != target[j] != target[k]:
                    if target[k] < target[i] + target[j]:
                        ans += 1

    print(ans)


main()


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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  int N;
  cin>>N;
  vector<int> A(N),B(N);
  for(int i = 0; i < N; i++){
    cin>>A[i]>>B[i];
  }
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  if(N%2==1){
    int a = A[N/2],b = B[N/2];
    cout<<b-a+1<<endl;
  }
  else {
    int a = (A[N/2]+A[N/2-1]),b=(B[N/2]+B[N/2-1]);
    cout<<b-a+1<<endl;
  }
}

Measured memory_bytes: 4796
def med(a,b,c)
a = [a,b,c]
a.sort!
elements = a.count
center =  elements/2
elements.even? ? (a[center] + a[center+1])/2 : a[center]  
end

#s =  [1,2,3,4,5,6,7].permutation.map{|t| t.each_cons(5).map{|t| med(*t.each_cons(3).to_a.map{|a,b,c| med(a,b,c)})}}.uniq
#p [1,2,3,4,5].permutation.map{|t| [t, med(*t.each_cons(3).to_a.map{|a,b,c| med(a,b,c)})]}.select{|t|t[1]==2}.map{|t| t[0]}#.uniq

#p s.map{|t| med(*t)}.uniq

nm = gets.chomp.split(" ").map(&:to_i)

n = nm[0]
x = nm[1]

if n ==1 && x==1
puts "Yes"
puts x
elsif n == 2 && x == 2
puts "Yes"
[1,2,3].each do |l|
p l
end
elsif x <  2 || x >= n * 2 - 3 + 2
puts "No"
else
puts "Yes"
if n-x+1==1
(2*n-1).times do |i|
p i-(n-x)+1
end
else
ary = [*1..2*n-1]
ans = [x-1,x,x+1]

k = ary - ans
#p ans, k

k.each_slice(2) do |a,b|
  ans.unshift(a)
  ans << b
end

ans.each do |l|
puts l
end
end
end


Measured memory_bytes: 9556
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcount((unsigned int)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, A, B; cin >> N >> A >> B;
    cout << min(N*A, B) << endstr;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
char a[20];
int n;
void f(int k , char c)
{
	if(k>n) return ;
	int d=0;
	//cout<<"k=> "<<k<<endl;
	while(d<k-1)
	{
		f(k+1 , max(c , a[k]));
		a[k]++;
		for(int i=1;i<=n;i++)
			cout<<a[i];
		cout<<endl;
		d++;
		if(a[k]>max(c , a[k-1]))
			break;
	}
	f(k+1 , max(a[k] , a[k+1]));
	a[k]='a';
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		a[i]='a';
	for(int i=1;i<=n;i++)
		cout<<a[i];
	cout<<endl;
	f(2 , 'a');
	/*for(int i=1;i<=n;i++)
		f(i);*/
}

Measured memory_bytes: 1536
#include<iostream>
#include<cstdlib>
#include<stack>
using namespace std;

int main() {
  // 標準ライブラリからstackを使用
  stack<int> S;
  int a, b, x;
  string s;

  while( cin >> s ) {
    if ( s[0] == '+' ) {
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a + b);
    } else if ( s[0] == '-' ) {
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a - b);
    } else if ( s[0] == '*' ) {
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a * b);
    } else {
      S.push(atoi(s.c_str()));
    }
  }

  cout << S.top() << endl;

  return 0;
}


Measured memory_bytes: 3172
#include <cstdio>
#include <cstring>
int main()
{
	int JOI_count,IOI_count,len,i;
	char str[10001];
	while(scanf("%s",str) != EOF)
	{
		JOI_count=0;
		IOI_count=0;
		len = strlen(str);
		for(i=1;i<len-1;i++)
		{
			if(str[i] == 'O')
			{
				if(str[i+1] == 'I')
				{
					if(str[i-1] == 'J')
					{
						JOI_count++;
					}
					if(str[i-1] == 'I')
					{
						IOI_count++;
					}
				}
			}
		}
		printf("%d\n",JOI_count);
		printf("%d\n",IOI_count);
	}
	return 0;
}

Measured memory_bytes: 984
#include<bits/stdc++.h>
#define p_ pair<int,int>
#define mp_ make_pair
#define ll long long
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
int a[maxn],lis[maxn],ans[maxn];
int n;
vector<int> g[maxn];
void dfs(int u,int f)
{
    int pos = lower_bound(lis+1,lis+n+1,a[u])-lis;
    int tmp = lis[pos];
    lis[pos] = a[u];
    ans[u] = max(pos,ans[f]);
    for(int v:g[u]) if(v!=f){
        dfs(v,u);
    }
    lis[pos] = tmp;
}
int main()
{
    fastio();
    cin>>n;
    rep(i,1,n) cin>>a[i];
    rep(i,1,n-1) {int u,v;cin>>u>>v;g[u].pb(v),g[v].pb(u);}
    memset(lis,127,sizeof(lis));
    dfs(1,0);
    rep(i,1,n) cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 31280
N = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

a = make_divisors(N)

ans = []

for i in a:
    j = N//i
    ans.append(i-1+j-1)

print(min(ans))

Measured memory_bytes: 39152
#include<iostream>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
typedef long long llong;

int A, B, C;
bool flag = false;
int main()
{
	cin >> A >> B >> C;
	if (A > B && A > C && C > B)
		flag = true;
	else if (A < C && C < B)
		flag = true;

	if (flag)
		cout << "Yes";
	else
		cout << "No";


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextLong()

  var x = 0L
  for (i <- 1L to N) {
    if (!(i % 3 == 0 || i % 5 == 0)) {
      x += i
    }
  }

  println(x)
}


Measured memory_bytes: 57664
S = input()

acgt = ['A', 'C', 'G', 'T']


max_l = 0

for i in range(len(S)):
    l = 0
    for j in range(i, len(S)):
        if S[j] in acgt:
            l+=1
        else:
            break
    if l > max_l:
        max_l = l
print (max_l)


Measured memory_bytes: 9052
main = getLine >>= putStrLn . solve . map read . words

solve (n:a:b:c:d:_) =
  if any f [0..n] then "YES" else "NO"
  where f m = a + m * c - (n - 1 - m) * d <= b && b <= a + m * d - (n - 1 - m) * c

Measured memory_bytes: 1020
import scala.collection.mutable._

import io.StdIn.readLine

object Main extends App {
  val map:Map[String,Int] = new HashMap[String,Int]
  val s = readLine.split(" ")
  s.foreach(e => {
    if(!map.contains(e)) map.put(e,1)
    else map.put(e,map(e)+1)
  })
  val maxF = map.maxBy(_._2)._1
  val l = s.map(_.length).max
  val maxL = s.find(_.length == l).get

  println(maxF + " " + maxL)
}


Measured memory_bytes: 44112
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int main (void)
{
    intmax_t N, a[(int)2e5 + 1];
    intmax_t box[(int)2e5 + 1] = {0}, M = 0;

    scanf("%jd", &N);
    for (size_t i = 1; i <= N; i++) {
        scanf("%jd", &a[i]);
    }

    for (size_t i = N; i > (N / 2); i--) {
        if (a[i]) {
            M++;
            box[i] = 1;
        }
    }
    for (size_t i = (N / 2); i > 0; i--) {
        intmax_t balls = 0;
        for (size_t j = (i * 2); j <= N; j += i) {
            balls += box[j];
        }
        if (a[i] != (balls % 2)) {
            M++;
            box[i] = 1;
        }
    }

    printf("%jd\n", M);
    if (M <= 0) return 0;
    for (size_t i = 1; i <= N; i++) {
        if (box[i]) {
            printf("%zd", i);
            if (--M) {
                printf(" ");
            } else {
                printf("\n");
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3968
import sys
from heapq import *

H,W=map(int,input().split())
si,sj=[int(x)-1 for x in input().split()]
ti,tj=[int(x)-1 for x in input().split()]
A=list(sys.stdin)

ans=-1
hp=[(0,si,sj)]
dirs=[-2,-1,0,1,2]
dist=[[float('inf')]*W for _ in range(H)]
dist[si][sj]=0
while hp:
    k,i,j=heappop(hp)
    if i==ti and j==tj:
        ans=k
        break
    if k>dist[i][j]:
        continue
    for di in dirs:
        for dj in dirs:
            if di==dj==0:
                continue
            ni,nj=i+di,j+dj
            if not (0<=ni<H and 0<=nj<W):
                continue
            if A[ni][nj]=='#':
                continue
            if abs(di)+abs(dj)==1:
                nk=k
            else:
                nk=k+1
            if nk>=dist[ni][nj]:
                continue
            dist[ni][nj]=nk
            heappush(hp,(nk,ni,nj))

print(ans)


Measured memory_bytes: 130952
#include <iostream>
using namespace std;
int main() {
    int l , r, d;
    int count = 0;
    cin>> l >> r >> d;
    for(int i = l; i <= r; i++){
        if(i%d == 0)
            count++;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define int long long
#define eb emplace_back
#define endl "\n"
#define FOR(P,Q) for(P=0;P<Q;P++)
#define FORR(P,Q) for(P=1;P<=Q;P++)
#define pb push_back
typedef long long ll;
using namespace std;

int dp[100005];
    
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  #ifndef ONLINE_JUDGE
	freopen("error.txt","w",stderr);
	#endif

	int n,h[100005],i,k=2;
	cin>>n>>k;
	FORR(i,n){
		cin>>h[i];
	}
	FORR(i,n){
		dp[i]=1e9+9;
	}
	dp[1]=0;
	FORR(i,n){
		for(int j=1;j<=k;j++){
			if(i>j){
				dp[i]=min(abs(h[i]-h[i-j])+dp[i-j],dp[i]);
			}
			
		}
	}
	cout<<dp[n];
	cerr<<"success";

return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <cassert>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;

int dfs(int x, bool A, bool B, bool C) {
	if (x > n) return 0;
	int ret = 0;
	if (A && B && C) ret++;
	ret += dfs(x * 10 + 7, true, B, C);
	ret += dfs(x * 10 + 5, A, true, C);
	ret += dfs(x * 10 + 3, A, B, true);
	return ret;
}

signed main() {
	cin >> n;
	cout << dfs(0, false, false, false) << endl;
	return 0;
}

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

int main() {
	
	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			int result = i*j;
			cout << i << "x"<< j <<"=" << result << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1116
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let s: Vec<char> = read::<String>().chars().rev().collect::<Vec<char>>();
    let tokens: Vec<Vec<char>> = vec!["dream", "dreamer", "erase", "eraser"].into_iter().map(|x| x.chars().rev().collect::<Vec<char>>()).collect();

    let mut idx = 0;
    while idx < s.len() {
        let mut found = false;
        for t in &tokens {
            let n = t.len();
            if idx + n <= s.len() {
                let mut isok = true;
                for i in 0..n {
                    if s[idx+i] != t[i] {
                        isok = false;
                    }
                }
                if isok {
                    found = true;
                    idx += n;
                    break
                }
            }
        }
        if !found {
            break
        }
    }
    println!("{}", if idx == s.len() { "YES" } else { "NO" });
}

Measured memory_bytes: 4352
from collections import deque
H,W = map(int,input().split())
Ch,Cw = map(int,input().split())
Dh,Dw = map(int,input().split())
S = []
for _ in range(H):
    S.append(list(input()))

warp = [[-1 for i in range(W)]for j in range(H)]

Q = deque([[Ch-1,Cw-1,0]])

while(len(Q) != 0):
    x,y,cnt = Q.popleft()

    if(warp[x][y] != -1):   #skip
        continue

    warp[x][y] = cnt        #ワープ魔法の必要回数

    for tx in range(-2,3):
        for ty in range(-2,3):
            nx = x+tx
            ny = y+ty

            if(0 <= nx < H and 0<= ny < W and S[nx][ny]=="."):
                if(abs(tx)+abs(ty) == 1):#徒歩で行けるなら前に
                    Q.appendleft([nx,ny,cnt])
                elif(abs(tx)+abs(ty)>=2):#ワープ魔法必要なら後ろに
                    Q.append([nx,ny,cnt+1])

print(warp[Dh-1][Dw-1])

Measured memory_bytes: 263404
import sys

input = sys.stdin.readline


def main():
    X, N = map(int, input().split())
    p = list(map(int, input().split()))

    i = 0
    while True:
        if X - i not in p:
            ans = X - i
            break
        if X + i not in p:
            ans = X + i
            break
        i += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9176