akhauriyash/Code-Regression huggingface dataset:
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

n = int(input())
a = list(map(int, input().split()))

a.insert(0, -1)

env = [0] * (n+1)
hako = [0] * (n+1)
ind = []

for _ in range(n):
    i = n - _
    if a[i] != env[i]:
        hako[i] = 1
        ind.append(str(i))
        yakusuu = make_divisors(i)
        for j in yakusuu:
            if env[j] == 0:
                env[j] = 1
            else:
                env[j] = 0

goukei = sum(hako)
print(goukei)
if ind != []:
    mojiretu = ' '.join(ind)
    print(mojiretu)

Measured memory_bytes: 77296
import sys
input = sys.stdin.readline
from bisect import bisect_left

class SegmentTree:
    def __init__(self, n, ele, segfun):
        self.ide_ele = ele
        self.segfun = segfun
        self.n = n
        self.N0 = 1 << n.bit_length()
        self.data = [self.ide_ele] * (self.N0 * 2)

    def update(self, l, r, val):
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                self.data[l] = self.segfun(self.data[l], val)
                l += 1
            if r & 1:
                self.data[r - 1] = self.segfun(self.data[r - 1], val)
                r -= 1
            l //= 2
            r //= 2

    def query(self, i):
        i += len(self.data) // 2
        ret = self.data[i]
        while i > 0:
            i //= 2
            ret = self.segfun(ret, self.data[i])
        return ret

n,q = map(int,input().split())
chk = []
for i in range(n):
  s,t,x = map(int,input().split())
  chk.append((s-x,t-x,x))
  
d = [int(input()) for i in range(q)]
seg = SegmentTree(q,10**9+1,lambda a, b: min(a,b))

for a,b,x in chk:
  L = bisect_left(d,a)
  R = bisect_left(d,b)
  seg.update(L,R,x)
  
for i in range(q):
  m = seg.query(i)
  if m == 10**9+1:
    print(-1)
  else:
    print(m)

Measured memory_bytes: 115292
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	vector<int> p(a);
	vector<int> q(b);
	vector<int> r(c);
	rep(i,a)cin>>p[i];
	rep(i,b)cin>>q[i];
	rep(i,c)cin>>r[i];
	sort(all(p));
	sort(all(q));
	sort(all(r));
	vector<ip> check;
	rep(i,x)check.push_back(make_pair(p[a-i-1],1));
	rep(i,y)check.push_back(make_pair(q[b-i-1],2));
	rep(i,min(x+y, c))check.push_back(make_pair(r[c-i-1],3));
	sort(all(check));
	//for(auto x:check)cout<<x.first<<' '<<x.second<<endl;
	ll ans = 0LL;
	ll cnt = 0LL;
	ll now = check.size();
	while(x+y-cnt>0){
		now--;
		if(check[now].second == 1){if(x==0)continue; --x;}
		if(check[now].second == 2){if(y==0)continue; --y;}
		if(check[now].second == 3)++cnt;
		//cout<<check[now].first<<' '<<check[now].second<<endl;
		ans += check[now].first;
		//cout<<"   "<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	cin.tie(0)->sync_with_stdio(false);

	string s, t; cin >> s >> t;

	int res = 0;
	REP(i, (int)s.size() - (int)t.size() + 1) {
		int cnt = 0;
		REP(j, (int)t.size()) {
			if (s[i + j] == t[j])
				cnt++;
		}
		res = max(res, cnt);
	}
	cout << t.size() - res << '\n';
	return 0;
}

Measured memory_bytes: 3656
N,x=map(int,input().split())
A=[int(i) for i in input().split()]
ans=0
if A[0]>x:
    ans+=A[0]-x
    A[0]=x
for i in range(1,N):
    if A[i-1]+A[i]>x:
        ans+=A[i-1]+A[i]-x
        A[i]=x-A[i-1]
print(ans)

Measured memory_bytes: 63984
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

h,n = inpl()
att = []
cost = []
for i in range(n):
    a,b = inpl()
    att.append(a); cost.append(b)
dp = [[INF for i in range(h+1)] for j in range(n+1)]
dp[0][0] = 0

for i in range(n):
    cnt = h//att[i]
    for j in range(h+1):
        if att[i] >= j:
            dp[i+1][j] = min(dp[i][j], cost[i])
            continue
        dp[i+1][j] = min(dp[i][j], cost[i]+dp[i+1][j-att[i]])
# pprint.pprint(dp)
print(dp[n][h])

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

int main() {
    int k;
    string s;
    cin >> k >> s;
    if(k>=s.size()) cout << s;
    else {
        for(int i=0; i<k; i++){
            cout << s[i];
        }
        cout << "...";
    }
}

Measured memory_bytes: 3624
n,k = map(int,input().split())
if(n<=k//2):
    print(n)
elif (n<=k):
    print(abs(n-k))
else:
    amari = n%k
    if(amari<=abs(amari-k)):
        print(amari)
    else:
        print(abs(amari-k))

Measured memory_bytes: 3060
x,y=map(int,input().split())
s=[1,3,5,7,8,10,12]
d=[4,6,9,11]
if x==y:
  print("Yes")
elif x in s and y in s:
  print("Yes")
elif x in d and y in d:
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

const lint MOD = pow(10, 9) + 7;

/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/


int main() {
	int N;
	cin >> N;
	cout << (N - 1) / 2 << endl;
}


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

int main(){
  int n;
  cin >> n;
  string s="No";
  for(int i=0;i<=25;i++){
    for(int j=0;j<=14;j++){
      if(i*4 + j*7 == n){
        s="Yes";
      }
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;


ll dp[570003] = {};

int seginit(int n_) {
    int n;

    n = 1;
    while (n < n_) {
        n *= 2;
    }

    return n;
}

void update(int n, int k, ll a) {
    k += n - 1;
    dp[k] = a;

    while (k > 0) {
        k = (k - 1) / 2;
        if (dp[k] >= a) break;
        dp[k] = a;
    }
}

ll query(int a, int b, int k, int l, int r) {
    if (b <= l || r <= a) return 0;
    if (a <= l && r <= b) return dp[k];

    ll v1, v2;
    v1 = query(a, b, k * 2 + 1, l, (l + r) / 2);
    v2 = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(v1, v2);
}

int main(void) {
    int n, kn, i, h[200003], a[200003];
    ll t;

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

    kn = seginit(n);

    for (i = 0; i < n; i++) {
        t = query(0, h[i] - 1, 0, 0, kn);
        update(kn, h[i] - 1, t + a[i]);
    }

    cout << dp[0] << endl;

    return 0;
}

Measured memory_bytes: 5376
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int[][] num = new int[3000][2];
		int temp;
		int count = 0;
		
		Scanner scanner = new Scanner(System.in);
		for(int i = 0; i < 3000; i++) {
			num[i][0] = scanner.nextInt();
			num[i][1] = scanner.nextInt();

			if(num[i][0] >= 0 && num[i][0]<=10000 && num[i][1] >= 0 && num[i][1]<=10000) {
				if(num[i][0] > num[i][1]) {
					temp = num[i][0];
					num[i][0] = num[i][1];
					num[i][1] = temp;
				}
			}
			if(num[i][0] == 0 && num[i][1] == 0) {
				count = i;
				break;
			}
		}
		for(int j = 0; j < count; j++) {
			System.out.println(num[j][0] + " " + num[j][1]);
		}
	}

}

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

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;


bool strcompare(string s1, string s2) {
  for(int i=0; i <= s1.length(); ++i) {
    if(s1[i] > s2[i]) return true;
    if(s1[i] < s2[i]) return false;
  }
  return false;
}

int main(void) {
  int n;
  cin >> n;

  string T[1000], H[1000];
  rep(i, n) cin >> T[i] >> H[i];

  int Tr=0, Hr=0;
  rep(i, n) {
    if(T[i] == H[i]) {
      Tr++;
      Hr++;
    } else if(strcompare(T[i], H[i])) {
      Tr += 3;
    } else {
      Hr += 3;
    }
  }

  cout << Tr << " " << Hr << endl;
}



Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
int n;
int a[110],b[110];
int main(){
	 cin>>n;
	 for(int i=1;i<=n;i++){
	 	cin>>a[i]>>b[i];
	 }
	 for(int i=1;i<=n-2;i++){
	 	if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2]){
	 		cout<<"Yes"<<endl;
	 		return 0;
		 }
	 }
	 cout<<"No"<<endl;
	 return 0;
} 

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

//iに負けた人の番号をG[i]に格納
vector<ll> G[100000];

ll depth(ll n) {
  if (G[n].size() == 0) return 0;
  priority_queue<ll> que;
  for (ll i = 0; i < G[n].size(); i++) {
    ll p = G[n][i];
    que.push(depth(p));
  }
  ll res = 0;
  for (ll i = 0; i < G[n].size(); i++) {
    ll q = que.top(); que.pop();
    res = max(res, q+i+1);
  }
  return res;
}

int main() {
  ll N; cin >> N;
  for (ll i = 0; i < N-1; i++) {
    ll x; cin >> x; x--;
    G[x].push_back(i+1);
  }
  cout << depth(0) << endl;
}

Measured memory_bytes: 15104
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val candidates = for {
      bit <- 0 until (1 << 4)
    } yield {
      val a1 = if ((bit & (1 << 0)) != 0) {
        "A"
      } else {
        ""
      }
      val a2 = if ((bit & (1 << 1)) != 0) {
        "A"
      } else {
        ""
      }
      val a3 = if ((bit & (1 << 2)) != 0) {
        "A"
      } else {
        ""
      }
      val a4 = if ((bit & (1 << 3)) != 0) {
        "A"
      } else {
        ""
      }
      val s = a1 + "KIH" + a2 + "B" + a3 + "R" + a4
      s
    }

    val set = candidates.toSet


    val in = new Scanner(System.in)
    val S = in.next()
    if (set.contains(S)) {
      println("YES")
    } else {
      println("NO")
    }
  }
}


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

using namespace std;

int main(){

	int k;
	cin >> k;
	int c = 7 % k;
	for(int i=1;i <= 1e7;i++){
		if(c == 0){
			cout << i << endl;
			return 0;
		}
		c = (c *10+7) % k;
	}
	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	double ans=1;
	for(int i=1;i<=n;i++){
		for(int j=2;j<=n;j++){
			if(pow(i,j)<=n){
				ans=max(pow(i,j),ans);
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import collections
h, w = [int(_) for _ in input().split()]
S = [list('.' * (w + 1))] + [['.'] + list(input()) for _ in range(h)]
B = [[99999] * (w + 1) for _ in range(h + 1)]
B[1][1] = 0 if S[1][1] == '.' else 1
cand = collections.deque([(1, 2), (2, 1)])
while cand:
    x, y = cand.popleft()
    if B[x][y] == 99999:
        B[x][y] = min(B[x][y - 1] + (S[x][y] == '#' != S[x][y - 1]),
                      B[x - 1][y] + (S[x][y] == '#' != S[x - 1][y]))
        if x < h:
            cand += [(x + 1, y)]
        if y < w:
            cand += [(x, y + 1)]
print(B[-1][-1])


Measured memory_bytes: 43120
n = int(input())
s = list(str(input()))
if n%2==1:
    print("No")
else:
    tmp=0
    for i in range(int(n/2)):
        if s[i] != s[i+int(n/2)]:
            tmp=1
            break
    if tmp==0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    a = list(map(int, rl().split()))
    
    n = a[0]
    for i in range(1, N):
        n ^= a[i]
    for i in range(N):
        a[i] ^= n
    print(*a)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 95312
#include <iostream>
#include <cmath>

int main(void){
    int a,b,ans;
	std::cin >> a >> b;
    ans = 0;
  	if (a == b){
          for(int i = 0; i < a; i++){
             ans = ans + b * std::pow(10,i);
          }
          std::cout << ans << std::endl;
          return 0;
    } 

    if ( a > b ){
        for(int i = 0; i < a; i++){
             ans = ans + b * std::pow(10,i);
          }
          std::cout << ans << std::endl;
    } else {
        for(int i = 0; i < b; i++){
             ans = ans + a * std::pow(10,i);
          }
          std::cout << ans << std::endl;
    }
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  vin l(n);
  rep(i,0,n) cin>>l[i];
  int sum=0;
  int mx=0;
  rep(i,0,n){
    sum+=l[i];
    mx=max(mx,l[i]);
  }
  bool ans=false;
  if(sum-mx>mx) ans=true;
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}









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


int main(){
	int n,map[4][3][10];
	cin >> n;
	for(int k=0;k<4;k++){
		for(int i=0;i<3;i++){
			for(int j=0;j<10;j++){
				map[k][i][j]=0;
			}
		}
	}
	while(n--){
		int b,f,r,v;
		cin >> b >> f >> r >> v;
		map[b-1][f-1][r-1]+=v;
	}
	for(int k=0;k<4;k++){
		for(int i=0;i<3;i++){
			for(int j=0;j<10;j++){
				cout << " " << map[k][i][j];
			}
			cout << endl;
		}
		if(k!=3) cout << "####################" << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import heapq
import math

n, h = map(int, input().split())
max_a = 0
b = []
sum_b = 0
for _ in range(n):
    x, y = map(int, input().split())
    if x > max_a:
        max_a = x
    b.append(y)
    sum_b += y

b = list(map(lambda x: x*(-1), b))
heapq.heapify(b)
total = 0
flag = False
max_b = 0
for i in range(1, 10**8):
    if len(b) != 0:
        max_b = heapq.heappop(b)*(-1)
    else:
        flag = True
    if max_b < max_a or flag:
        print(i-1 + math.ceil((h - total) / max_a))
        exit()
    else:
        total += max_b
        if total >= h:
            print(i)
            exit()


Measured memory_bytes: 11084
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int n;
vector<string> ans;
void dfs(string s,char mx){
  if(s.size()==n){
    ans.push_back(s);
  }
  else{
    for(char c='a';c<=mx;c++){
      if(c==mx) dfs(s+c,mx+1);
      else dfs(s+c,mx);
    }
  }
}

int main(){
  cin >> n;
  ans.resize(0);
  dfs("a",'b');
  rep(i,ans.size()){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 7796
#include <iostream>
#include <map>

int n;
int a;
int under_red, over_red;
std::map<std::string, int> mp;
std::string color(int a) {
    std::string res;
    if      (a <  400) res = "Gray";
    else if (a <  800) res = "Brown";
    else if (a < 1200) res = "Green";
    else if (a < 1600) res = "Light Blue";
    else if (a < 2000) res = "Blue";
    else if (a < 2400) res = "Yellow";
    else if (a < 2800) res = "Orange";
    else if (a < 3200) res = "Red";
    else               res = "Great";
    return res;
}


int main() {
    std::cin >> n;
    for (int i=0; i<n; ++i) {
        int a;
        std::string c;
        std::cin >> a;
        c = color( a );
        if (mp.find(c) == mp.end()) {
            mp[c] = 1;
        } else {
            ++mp[c];
        }
    }
    int min, max;
    if (mp.size() == 1) {
        min = 1;
        if (mp.find("Great") == mp.end()) {
            max = 1;
        } else {
            max = mp["Great"];
        }
    } else {
        if (mp.find("Great") == mp.end()) {
            // No Great
            min = mp.size();
            max = min;
        } else {
            // At least one Great
            min = mp.size()-1;
            max = min+mp["Great"];
        }
        // min = (mp.find("Great") == mp.end()) ? mp.size() : mp.size()-1;
        // max = (mp.find("Great") == mp.end()) ? min : std::min(8, min + mp["Great"]);
    }
    
    std::cout << min << ' ' << max << std::endl;
    return 0;
}

Measured memory_bytes: 256
function Main(input) {
  var one = input.slice(0,1);
  var two = input.slice(1,2);
  var three = input.slice(2,3);
  var four = input.slice(3,4);
  
  if(one == two || two == three || three == four){
     console.log("Bad");
     }else{
       console.log("Good");
     }
  
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<stack>
#define maxn 3005
using namespace std;
typedef long long  LL;
LL gcd(LL a,LL b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
LL min_g(LL a,LL b)
{
    LL t=gcd(a,b);
    return a/t*b;
}
int main()
{
    int n;
    scanf("%d",&n);
    LL sum=0;
    for(int i=0;i<n;i++)
    {
        int t;
        scanf("%d",&t);
        sum+=t-1;
    }
    cout<<sum<<endl;



    return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
int inf = 1000000000; //10e9

int main() {

    int n;
    cin >> n;
    vector<vector<int>> d(n,vector<int>(2));
    rep(i,n) rep(j,2) cin >> d[i][j];

    bool isanswer = false;

    rep(i,n-2){
        if(d[i][0] == d[i][1]){
            if(d[i+1][0] == d[i+1][1]){
                if(d[i+2][0] == d[i+2][1]){
                    isanswer = true;
                }
            }
        }
    }

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

    return 0;

}

Measured memory_bytes: 3636
// Java program For handling Input/Output 
import java.io.*; 
import java.util.*;
import java.math.*;
//import java.awt.*;

public class Main 
{ 
    FastReader sc;
    //actual logic
    void solve() throws IOException{
        int n = sc.ni();
        int m = sc.ni();
        System.out.println((n == m) ? "Yes":"No");

    }

    //constructor
    Main()
    {
        try{  
            sc = new FastReader();
        }catch(Exception e){
            System.out.println(e);
        }
    }


    //main metohd
    public static void main(String[] args) throws IOException
    { 
     new Main().solve();
 }
    //Utility methods

 static class FastReader{
    BufferedReader br;
    StringTokenizer st;
    FastReader(){
        br = new BufferedReader(new InputStreamReader(System.in));
        try{
            st = new StringTokenizer(br.readLine());
        }catch(Exception e){
            System.out.println(e);
        }
    }

    FastReader(String s){
        try{
            br = new BufferedReader(new FileReader(s));
            st = new StringTokenizer(br.readLine());
        }catch(Exception e){
            System.out.println(e);
        }
    }

    String ns(){
        if(!st.hasMoreTokens())
        {
            try{
                st = new StringTokenizer(br.readLine());
            }catch(Exception e){
                System.out.println(e);
            }    
        }
        return st.nextToken();

    }

    int ni(){
        return Integer.parseInt(ns());
    }

    long nl(){
        return Long.parseLong(ns());
    }

    double nd(){
        return Double.parseDouble(ns());
    }
}
}


Measured memory_bytes: 21460
#n = gets.to_s.to_i
n,l = gets.to_s.split.map{|i|i.to_i}
cts = Array.new(n){ gets.to_s.split.map{|i|i.to_i} }

ans = 10 ** 18
cts.each_with_index do |ct,i|
  c = ct[0]
  t = ct[1]
  
  # p ct
  
  next if t > l
  
  ans = c if ans > c
end

puts ans != 10 ** 18 ? ans : "TLE"

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

int main() {

    int k,s;

    cin >> k >> s;

    int ans = 0;

    for(int i=0; i<=k; i++){
        for(int j=0; j<=k; j++){
            if(s-i-j <= k && s-i-j >= 0){
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(void){
    int n, ans = 0;
    cin >> n;
    
    int k = 0, tmp = n;
    while(tmp > 0){
        tmp /= 10;
        k++;
    }
    
    if(k == 1) ans += n%10;
    if(k == 2) ans += 9;
    if(k == 3) ans += n-100 + 9 + 1;
    if(k == 4) ans += 900 + 9;
    if(k == 5) ans += n-10000 + 900 + 9 + 1;
    if(k == 6) ans += 90000 + 900 + 9;
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, M = map(int, input().split())

A = [tuple(map(int, input().split())) for _ in [0]*N]
C = [tuple(map(int, input().split())) for _ in [0]*M]


for a, b in A:
    mind = 10**10
    mini = -1
    for i, (c, d) in enumerate(C):
        if mind > abs(c-a)+abs(d-b):
            mind = abs(c-a)+abs(d-b)
            mini = i
    print(mini+1)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

int f(int n){
    return (n % 2 == 0) ? n / 2 : 3 * n + 1;
}

void solve(){
    int s;
    cin >> s;
    int a[200];
    a[1] = s;
    int i = 2;
    while(i < 200){
        a[i] = f(a[i - 1]);
        for(int j = 1; j < i; j++){
            if(a[j] == a[i]){
                cout << i;
                return;
            }
        }
        i++;
    }
    for(int i = 0; i < 200; i++) cout << a[i] << ' ';
}


int main(){
    int q = 1;
    //cin >> q;}
    while(q--) solve();
}
// vse dolzhny vyiti v internet po hhtp


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int N=2e6+16;
using namespace std;
ll n,m,p;
map<ll,ll>mp;
ll sum[N];
ll num[N];
int main()
{
    ll ans=0;//记录最终答案
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>num[i];
        sum[i]=sum[i-1]+num[i];
    }
    for(int i=1;i<=n;i++){
    	sum[i]=(sum[i]-i%m+m)%m;//预处理前缀和
	}
        
    ll low=min(m-1,n);//cout<<low<<" ";	
    for(int i=0;i<=low;i++)
    {
        ans+=mp[sum[i]];//cout<<res<<endl;
        mp[sum[i]]++;
    }
    for(int i=low+1;i<=n;i++)
    {
        mp[sum[i-m]]--;
        ans+=mp[sum[i]];//cout<<res<<endl;
        mp[sum[i]]++;
    }
    cout<<ans<<endl;
    return 0;
}

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

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: i32 = sc.read();
    for i in 1..n+1 {
        // 3の倍数または10進数表示で3を含む
        if i % 3 == 0 || i.to_string().bytes().any(|b| b == b'3') {
            print!(" {}", i);
        }
    }
    println!("");
}



Measured memory_bytes: 5052
#include <cstdio>

const int N=2005;
const int P=924844033;
int n,k,a[N],fac[N];
long long f[N][N][2][2];
bool vis[N];

int main() {
    scanf("%d%d",&n,&k);
    fac[0]=1;
    for (int i=1;i<=n;++i) fac[i]=1LL*fac[i-1]*i%P;
    int tot=0;
    for (int i=1;i<=n;++i) if(!vis[i]) for(int j=i;j<=n;j+=k) vis[j]=1,a[++tot]=j;
    f[0][0][0][0]=1;
    a[0]=-(1<<30);
    for (int i=1;i<=n;++i){
        f[i][0][0][0]=1;
        for (int j=1;j<=i;++j){
            f[i][j][0][0]=(f[i-1][j][1][0]+f[i-1][j][0][0]+(a[i]-a[i-1]==k)*f[i-1][j-1][0][0])%P;
            f[i][j][0][1]=(a[i+1]-a[i]==k)*(f[i-1][j-1][1][0]+f[i-1][j-1][0][0])%P;
            f[i][j][1][0]=(f[i-1][j][0][1]+f[i-1][j][1][1]+(a[i]-a[i-1]==k)*f[i-1][j-1][0][1])%P;
            f[i][j][1][1]=(a[i+1]-a[i]==k)*(f[i-1][j-1][0][1]+f[i-1][j-1][1][1])%P;
        }
    }
    int ans=0;
    for (int i=0;i<=n;++i){
        int sum=(f[n][i][0][0]+f[n][i][0][1]+f[n][i][1][0]+f[n][i][1][1])%P;
        if(i&1) (ans+=P-1LL*sum*fac[n-i]%P)%=P;
        else (ans+=1LL*sum*fac[n-i]%P)%=P;
    }
    printf("%d\n",ans);
    return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll h, w, k;
    cin >> h >> w >> k;
    string s[h];
    rep(i, h) { cin >> s[i]; }
    bool color[h][w];
    rep(i, h) {
        rep(j, w) { color[i][j] = s[i][j] == '#'; }
    }

    ll ans = 0;
    rep(l0, 1 << h) {
        rep(l1, 1 << w) {
            ll num = 0;
            rep(i, h) {
                if (l0 & (1 << i)) {
                    continue;
                }
                rep(j, w) {
                    if (l1 & (1 << j))
                        continue;
                    if (color[i][j])
                        num++;
                }
            }
            if (num == k) {
                ans++;
            }
        }
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int gcd (int a, int b) {
    if ( a % b == 0 ) return b;
    return gcd(b, a%b);
} 

int main(){
//    chrono::system_clock::time_point  start, end; // 型は auto で可
//    start = chrono::system_clock::now(); // 計測開始時間
    int n;
    cin >> n;
    ll sum = 0;
    for (ll i = 1; i <= n; ++i) {
        for (ll j = 1; j <= n; ++j) {
            for (ll k = 1; k <= n; ++k) {
                ll a = i, b = j, c = k;
                if ( b > a ) swap(a,b);
                ll gcd_num = gcd(a,b);
                if ( c > gcd_num ) swap(c, gcd_num);
                gcd_num = gcd(gcd_num, c);
                sum += gcd_num;
            }
        }
    }
    cout << sum << endl;
//    end = chrono::system_clock::now();  // 計測終了時間
//    double elapsed = chrono::duration_cast<chrono::milliseconds>(end-start).count(); //処理に要した時間をミリ秒に変換
//    printf("%lf\n", elapsed);
    return 0;
}


Measured memory_bytes: 3636
R,G,B,N= map(int,input().split())

x_max= N//R
y_max= N//G
ans=0

for x in range(x_max+1):
    for y in range(y_max+1):

        z= (N-R*x-G*y)//B

        if z >=0 and (N-R*x-G*y)% B ==0:
            ans += 1

print(ans)

Measured memory_bytes: 40940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int mod2 = 998244353;

int main() {
  int n;
  cin >> n;
  vector<int> b(n-1);
  for (int i = 0;i < n-1;i++) cin >> b[i];
  vector<int> a(n);
  a[0] = b[0];
  for (int i = 1;i < n-1;i++) a[i] = min(b[i-1], b[i]);
  a[n-1] = b[n-2];
  int ans = 0;
  for (int i = 0;i < n;i++) ans += a[i];
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
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(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#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 SQ(a) (a*a)
#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())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int main() {
	int a, b;
	cin >> a >> b;
	cout << (a + b) % 24 << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var s, t string
	fmt.Scanf("%s %s", &s, &t)
	fmt.Printf(t + s)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m,count=0,answer=0;
  string str;
  cin >> n;
  vector<string> s(n);
  for(int i=0;i<n;i++) cin >> s.at(i);

  cin >> m;
  vector<string> t(m);
  for(int i=0;i<m;i++) cin >> t.at(i);
  
  for(int i=0;i<n;i++){
  	str = s.at(i);
  	for(int j=0;j<n;j++){
  		if(str==s.at(j)) count++;
  	}
  	for(int j=0;j<m;j++){
  		if(str==t.at(j)) count--;
  	}
  	if(answer<count) answer = count;
  	count = 0;
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

// -----------------------------------------------------------------------------
// IO functions

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func nb() []byte {
	b, err := r.ReadBytes(' ')
	if err != nil {
		panic(err)
	}
	return b
}

func ns() string {
	s, err := r.ReadString(' ')
	if err != nil {
		panic(err)
	}
	return s
}

func nl() int64 {
	var ll int64
	fmt.Fscan(r, &ll)
	return ll
}

func ni() int {
	var ll int
	fmt.Fscan(r, &ll)
	return ll
}

func nf() float64 {
	var ff float64
	fmt.Fscan(r, &ff)
	return ff
}

// -----------------------------------------------------------------------------
// Simple math functions

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// =============================================================================

func main() {
	defer w.Flush()

	n := ni()
	x := ni()
	t := ni()
	fmt.Fprintf(w, "%d\n", (n+x-1)/x*t)
}

// =============================================================================


Measured memory_bytes: 1844
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(std::string S){
  if (S == "SAT") {
    std::cout << 1 << std::endl;
  } else if (S == "FRI") {
    std::cout << 2 << std::endl;
  } else if (S == "THU") {
    std::cout << 3 << std::endl;
  } else if (S == "WED") {
    std::cout << 4 << std::endl;
  } else if (S == "TUE") {
    std::cout << 5 << std::endl;
  } else if (S == "MON") {
    std::cout << 6 << std::endl;
  } else {
    std::cout << 7 << std::endl;
  }
}

int main(){
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a = [[e, i] for i, e in enumerate(a, 1)]

a.sort(reverse=True)

dp = [[0] * (n + 1) for _ in range(n + 1)]

for t, (e, idx) in enumerate(a, 1):
    for i in range(1, t + 1):
        j = t - i
        dp[i][j] = max(dp[i][j], dp[i-1][j] + e * abs(idx - i))

    for j in range(1, t + 1):
        i = t - j
        dp[i][j] = max(dp[i][j], dp[i][j-1] + e * abs(idx - (n - j + 1)))

ans = 0
for i in range(1, n + 1):
    j = n - i
    ans = max(ans, dp[i][j])

print(ans)


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

#define ll long long
#define ff first
#define ss second
#define pb push_back

using namespace std;

const int N  = 1e6 + 69, INF = 1e9, mod = 1e9 + 7;

const ll INFLL = 1e18;

int n, K;
ll dp[405][405], A[N], sum[405][405];

int main(){

        cin >> n;

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

        for(int l = 1; l <= n; l++){
                for(int r = l; r <= n; r++){
                        sum[l][r] = sum[l][r-1] + A[r];
                        dp[l][r] = INFLL;
                }
                dp[l][l] = 0;
        }


        for(int cnt = 2; cnt <= n; cnt++){
                for(int l = 1; l + cnt - 1 <= n; l++){
                        int r = l + cnt - 1;
                        for(int mid = l; mid < r ; mid++){
                                dp[l][r] = min(dp[l][r],dp[l][mid] + dp[mid+1][r] + sum[l][mid] + sum[mid+1][r]);
                        }
                }
        }


        cout << dp[1][n] << endl;
}


Measured memory_bytes: 3712
abc = int(input())
arc = int(input())
agc = int(input())
apc = int(input())
atc = int(input())

num_list = [abc, arc, agc, apc, atc]

def fn(num):
  if num % 10 == 0:
    return 0
  else:
    return 10 - num % 10

num_list_res = [fn(num) for num in num_list]
max_idx = num_list_res.index(max(num_list_res))

ans = 0
for i in range(len(num_list)):
  if i == max_idx:
    ans += num_list[i]
  else:
    ans += num_list[i] + num_list_res[i]
print(ans)

Measured memory_bytes: 3064
// abc160_b
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#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 x,cnt500=0,cnt5=0;
  cin>>x;
  cnt500=x/500;
  cnt5=(x%500)/5;
  cout<<cnt500*1000+cnt5*5<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
const long mod = 1000000007;
int main() {
    int n;
    cin >> n;
    vector<long> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    b[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--) {
        b[i] = (a[i] + b[i + 1]) % mod;
    }
    int r = 0;
    for (int i = 0; i < n - 1; i++) {
        r = r + (a[i] * b[i + 1]) % mod;
        r %= mod;
    }
    cout << r << endl;
}


Measured memory_bytes: 6360
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		String input = scanner.next();
		
		if ("a".equals(input) || "i".equals(input) || "u".equals(input) ||
			"e".equals(input) || "o".equals(input)) {
			System.out.println("vowel");
		} else {
			System.out.println("consonant");
		}
	}
}

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

vector<int> bfs(vector<vector<int>> &G, int start) {
    int n = (int)G.size();
    vector<int> res(n);

    queue<int> que;
    vector<bool> visited(n, false);
    que.push(start);
    visited[start] = true;
    while (!que.empty()) {
        int u = que.front(); que.pop();
        for (int v : G[u]) {
            if (visited[v]) continue;
            visited[v] = true;
            res[v] = res[u] + 1;
            que.push(v);
        }
    }

    return res;
}

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

    vector<int> distFennec = bfs(G, 0);
    vector<int> distSnuke = bfs(G, N - 1);

    int cntFennec = 0, cntSnuke = 0;
    for (int i = 0; i < N; i++) {
        if (distFennec[i] <= distSnuke[i]) {
            cntFennec++;
        } else {
            cntSnuke++;
        }
    }

    if (cntFennec > cntSnuke) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }

    return 0;
}

Measured memory_bytes: 6528
from math import factorial
n, a, b = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

def nCr(n, r):
    global mod
    ans = 1
    for i in range(r):
        ans = (ans * (n-i)) % mod
    return (ans * pow(factorial(r), mod-2, mod)) % mod

print((pow(2, n, mod) - nCr(n, a) - nCr(n, b) - 1) % mod) 

Measured memory_bytes: 11280
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
	vector<int> array;
	bool prime[1000001];
	long long int n,t,a = 0,i,j = 0;
	for (i = 3; i <= 1000000; i += 2){
		prime[i] = true;
	}
	prime[2] = true;
	for (i = 3; i <= 1000; i += 2){
		if (prime[i] == 1){
			for (j = 3; j <= 1000000 / i; j += 2){
				prime[i * j] = false;
			}
		}
	}
	for(int i = 2;i<=1000000;i++){
		if(prime[i] == true) {
			array.push_back(i);
			a++;
		}
	}
	while(cin >> n && n){
		t = 0;
		for(int i = 0;i<n;i++){
			t+=array[i];
		}
		cout << t << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll h, w, ch, cw, dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    ch--, cw--, dh--, dw--;
    vector<string> s(h);
    rep1(i, h) cin >> s[i];
    vector<P> d;
    d.push_back(make_pair(1, 0));
    d.push_back(make_pair(-1, 0));
    d.push_back(make_pair(0, 1));
    d.push_back(make_pair(0, -1));
    queue<P> q, old;
    vector<vector<ll> > visit(h, vector<ll>(w, -1));
    q.push(make_pair(ch, cw));
    visit[ch][cw]++;
    while (!q.empty()){
        P xy = q.front(); q.pop();
        ll x = xy.first, y = xy.second;
        rep1(i, 4){
            ll nx = x+d[i].first, ny = y+d[i].second;
            if (nx>=0 && nx<h && ny>=0 && ny<w) {
                if (visit[nx][ny]==-1 && s[nx][ny]=='.') {
                    visit[nx][ny] = visit[x][y];
                    q.push(make_pair(nx, ny));
                }
            }
        }
        old.push(make_pair(x, y));
        if (q.empty()) {
            while (!old.empty()) {
                xy = old.front(); old.pop();
                x = xy.first, y = xy.second;
                for (ll i=-2; i<=2; i++) {
                    for (ll j=-2; j<=2; j++) {
                        ll nx = x+i, ny = y+j;
                        if (nx>=0 && nx<h && ny>=0 && ny<w && s[nx][ny]=='.'){
                            if (visit[nx][ny]==-1 || visit[nx][ny]>visit[x][y]+1) {
                                visit[nx][ny] = visit[x][y] + 1;
                                q.push(make_pair(nx, ny));
                            }
                        }
                    }
                }
            }
        }
    }
    cout << visit[dh][dw] << endl;
    //printf("%.12f", ans);
}

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

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

    int N, color;
    cin >> N;

    int A[10], others = 0, cnt = 0;
    memset(A, 0, sizeof A);

    for(int i = 0; i < N; i++){
        cin >> color;
        if(color >= 1 && color <= 399) A[0] = 1;
        else if(color >= 400 && color <= 799) A[1] = 1;
        else if(color >= 800 && color <= 1199) A[2] = 1;
        else if(color >= 1200 && color <= 1599) A[3] = 1;
        else if(color >= 1600 && color <= 1999) A[4] = 1;
        else if(color >= 2000 && color <= 2399) A[5] = 1;
        else if(color >= 2400 && color <= 2799) A[6] = 1;
        else if(color >= 2800 && color <= 3199) A[7] = 1;
        else others++;
    }
    for(int i = 0; i < 8; i++){
        if(A[i]) cnt++;
    }
    if(!cnt) cout << 1 << " " << others << "\n";
    else cout << cnt << " " << cnt+others << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    unordered_set<ll> s;
    for(int i = 0; i < n; ++i){
        ll d;
        cin >> d;
        s.insert(d);
    }
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
S = [input() for i in range(N)]
input_dict = defaultdict(int)
for key in S:
    input_dict[key] += 1
max_value = max(input_dict.values())
max_list = []
for k, v in input_dict.items():
    if v == max_value:
        max_list.append(k)
max_list.sort()
[print(i) for i in max_list]

Measured memory_bytes: 35572
c = [[int(a) for a in input().split()] for _ in range(3)]
ok = True

b = [c[0][0], c[0][1], c[0][2]]
a = [0, c[1][0] - b[0], c[2][0] - b[0]]

for i in range(3):
    for j in range(3):
        if a[i] + b[j] != c[i][j]:
            ok = False
print("Yes") if ok else print("No")

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

using namespace std;

int main() {
  while (true) {
    int n,k;
    cin >> n >> k;
    if(n == 0 && k == 0)
      return 0;

    int sum[n+1];
    sum[0] = 0;

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

    int ans = -1987654321;

    for (int i = 0; i < n-k; i++){
      int tmp = sum[i+k] - sum[i];
      if(tmp > ans)
        ans = tmp;
    }

    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1548
#include<bits/stdc++.h>
using namespace std;
const int N=300005;
const long long M=998244353;
const long long iv2=499122177;
int n,k,s,t,a[55],f[N],i,j,id[55],b[55],p;
long long dp[N],C[55][55],ans;
int main()
{
	scanf("%d %d %d %d",&n,&k,&s,&t);
	for(j=0;j<18;++j)
		if(((s>>j)&1)&&(!((t>>j)&1)))
		{
			puts("0");
			return 0;
		}
	for(i=0;i<=50;++i)
	{
		C[i][0]=C[i][i]=1;
		for(j=1;j<i;++j)
			C[i][j]=C[i-1][j]+C[i-1][j-1];
	}
	memset(id,-1,sizeof(id));
	int y=0;
	for(j=0;j<18;++j)
		if((!((s>>j)&1))&&((t>>j)&1))
			id[j]=y++;
	for(i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		if((a[i]&s)==s&&((a[i]|t)==t))
		{
			++p;
			for(j=0;j<18;++j)
				if(((a[i]>>j)&1)&&id[j]!=-1)
					b[p]|=1<<id[j];
		}
	}
	--k;
	for(int u=1;u<=p;++u)
	{
		memset(f,0,sizeof(f));
		memset(dp,0,sizeof(dp));
		for(i=u+1;i<=p;++i)
		{
			int s=0;
			for(j=0;j<y;++j)
				if(((b[i]>>j)&1)!=((b[u]>>j)&1))
					s|=1<<j;
			++f[s];
		}
		for(i=0;i<y;++i)
			for(j=0;j<(1<<y);++j)
				if((j>>i)&1)
					f[j]+=f[j^(1<<i)];
		for(i=0;i<(1<<y);++i)
			for(j=0;j<=k;++j)
				dp[i]+=C[f[i]][j];
		for(i=0;i<y;++i)
			for(j=0;j<(1<<y);++j)
				if((j>>i)&1)
					dp[j]-=dp[j^(1<<i)];
		ans+=dp[(1<<y)-1];
	}
	cout<<ans<<endl; 
}

Measured memory_bytes: 7316