akhauriyash/Code-Regression huggingface dataset:
from collections import deque

def bfs():
    while len(que) != 0:
        p = que.popleft()
        for i in range(4):
            nextX = p[0] + moveR[i]
            nextY = p[1] + moveC[i]
            if 0 <= nextX and nextX < H\
                and 0 <= nextY and nextY < W\
                and s[nextX][nextY] != '#'\
                and s[nextX][nextY] == '.':
                s[nextX][nextY] = s[p[0]][p[1]] + 1
                que.append([nextX, nextY])

H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
moveR = [0, 1, -1, 0]
moveC = [1, 0, 0, -1]

que = deque()
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            que.append([i, j])
            s[i][j] = 0
bfs()
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, s[i][j])
print(ans)

Measured memory_bytes: 167432
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        flag=True
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l]!=b[k][l]:
                    flag=False
        if flag:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        private static long MOD = (long) (1e9 + 7);

        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            int K = in.Int();

            long ans = 0;
            for (long i = K; i <= N + 1; i++) {
                long a = (i * (i - 1)) / 2;
                long b = ((N + (N - i + 1)) * i) / 2;
                ans += b - (a - 1);
                ans %= MOD;
            }
            out.println((ans + MOD) % MOD);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 25944
program name
    implicit none
    integer(4):: n,cnt(0:100000)
    integer(4),allocatable:: a(:)
    integer(4):: i, mcnt

    read*, n
    allocate(a(n))
    read*, a(:)

    cnt(:) = 0

    do i=1,n
        cnt(a(i)) = cnt(a(i)) + 1
    end do
    mcnt=0
    do i=1,99999
        mcnt=max(mcnt,sum(cnt(i-1:i+1)))
    end do

    print*, mcnt
end program name

Measured memory_bytes: 1536
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;

int main()
{
	char s[10];
	scanf("%s", s); int n = strlen(s);
	for (int i = 0; i < n-1; i ++)
		if (s[i] == 'A' && s[i+1] == 'C'){
			puts("Yes"); return 0;
		}
	puts("No"); return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.strip.split(' ').map(&:to_i)
mp = []
maxd = 1
a.each_with_index do |el, idx|
  mp[idx + 1] = el
  maxd = [(el - idx).abs, maxd].max
end

maxd += 1

if maxd % 2 == 1
  maxd += 1
end

r1 = Array.new(n + 1)
r2 = Array.new(n + 1)

v1 = 0
v2 = 0

1.upto(n) do |idx|
  r1[idx] = maxd * idx
  r2[idx] = maxd * (n + 1 - idx)
end

2.upto(n) do |idx|
  to_add = idx - 1
  index = mp[idx]
  if index == n
    r1[index] += to_add
    next
  end

  if index == 1
    r2[1] += to_add
    next
  end

  r1[index] += to_add >> 1
  r2[index] += (to_add % 2 == 1 ? (to_add >> 1) + 1 : to_add >> 1)

  if r2[index] == r2[index - 1] || r2[index] == r2[index + 1]
    r2[index] -= 1
    r1[index] += 1
  end
end

printf("%s\n", r1[1..n].join(' '))
printf("%s\n", r2[1..n].join(' '))


Measured memory_bytes: 5748
N, K = map(int, input().split())
p = list(map(int, input().split()))

s = [0]*N
for i in range(N):
    s[i] = (p[i]+1) / 2
ss = [0]*(N+1)

for i in range(N):
    ss[i+1] = ss[i] + s[i]

ans = 0
for i in range(N - K + 1):
    ans = max(ans, ss[i+K] - ss[i])

print(ans)


Measured memory_bytes: 24804
import bisect
from collections import deque
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = [int(readline()) for _ in range(N)]

NUM = deque()
NUM.appendleft(A[0])

A = A[1:]


for a in A:
    if a <= NUM[0]:
        NUM.appendleft(a)
    else:
        i = bisect.bisect_left(NUM, a)
        NUM[i-1] = a


print(len(NUM))


Measured memory_bytes: 8180
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> a_i(n);
  for (int i = 0; i < n; i++) {
    cin >> a_i[i].first;
    a_i[i].second = i+1;
  }
  sort(a_i.begin(), a_i.end());
  
  for (int i = 0; i < n; i++) {
    cout << a_i[i].second;
    if (i == n-1) cout << endl;
    else cout << ' ';
  }
}

Measured memory_bytes: 1664
N=int(input())
if N==1:
    print("First")
    exit()
L=[[]for i in range(N+1)]
for i in range(N-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
#print(L)
C=[0 for i in range(N+1)]

D=[10000000 for i in range(N+1)]
D[1]=0
Q=[1]
for i in range(10**6):
    if i==N:
        break
    for j in L[Q[i]]:
        if D[j]==10000000:
            Q.append(j)
            D[j]=D[Q[i]]+1
#print(D)
F=0
cnt=0
for i in range(1,N+1):
    if D[i]>cnt:
        cnt=D[i]
        F=i
d=[10000000 for i in range(N+1)]
d[F]=0
Q=[F]
for i in range(10**6):
    if i==N:
        break
    for j in L[Q[i]]:
        if d[j]==10000000:
            Q.append(j)
            d[j]=d[Q[i]]+1
#print(d)
ans=0
for i in range(1,N+1):
    if d[i]>ans:
        ans=d[i]
if ans%3==1:
    print("Second")
else:
    print("First")

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

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  if (s == t.substr(0, t.length() - 1)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<cmath>
#include<queue>
#include<functional>
#include<algorithm>
#include<string>
#include<set>
#include<cstring>
 
using namespace std;
 

int main(void)
{
	
	int n;
	while(cin>>n,n){
		vector<set<int> > dp(n);
		vector<vector<int> > vf(n);
		
		for(int i=0;i<n;i++) dp[i].insert(i);



		for(int i=0;i<n;i++){
			int m;
			cin>>m;
			for(int j=0;j<m;j++){
				int f;
				cin>>f;
				vf[i].push_back(f);
			}
			sort(vf[i].begin(),vf[i].end());
		}
		
		int res=-1;
		for(int i=1;i<=30 && res==-1;i++){
			vector<int> meet;
			set<int> update;
			for(int j=0;j<n;j++){
				if(binary_search(vf[j].begin(),vf[j].end(),i)){
					meet.push_back(j);
					for(auto it=dp[j].begin();it!=dp[j].end();it++)	update.insert(*it);
				}
			}
			
			for(int j=0;j<meet.size();j++){

				dp[meet[j]]=update;

			}
			for(int j=0;j<n;j++){
				if(dp[j].size()>=n) res=i;
			}
		}
		cout<<res<<endl;

	}
	
	return 0;
}

Measured memory_bytes: 1340
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int s=0;
	int o=1;
	cin>>n;
	for(int i=0;i<10;i++,o*=10)
	{
		s+=n/o%10;
	}
	n%s==0?cout<<"Yes":cout<<"No";
}

Measured memory_bytes: 256
import scala.io.StdIn._

object Main {
  var map: Map[Int, Boolean] = Map.empty[Int, Boolean]

  def main(args: Array[String]): Unit = {
    val n = readInt
    if (n == 0) return
    val list = readIntList(n)
    val count = list.count(isPrimeNumber)
    println(count)
  }

  def readIntList(n: Int): List[Int] = {
    var list: Array[Int] = Array.empty
    for (i <- 0 until n) {
      list :+= readInt
    }
    list.toList
  }

  def isPrimeNumber(value: Int): Boolean = {
    if (value < 2) false
    else if (value == 2) true
    else if (value % 2 == 0) false
    else {
      val sqrt = Math.sqrt(value).toInt
      for (i <- 3 to sqrt by 2) {
        if (value % i == 0) {
          return false
        }
      }

      true
    }
  }
}



Measured memory_bytes: 245916
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define REP(n) FOR(i,n)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

int main() {
  int a,b;
  cin>>a>>b;
  if(max(a,b)>9){
    cout<<-1;
  }else{
    cout<<a*b;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		String str1=s.next();
		String str2=s.next();
		
		int n=str1.length();
		
		int count=0;
		
		for(int i=0;i<n;i++)
		{
			if(str1.charAt(i)!=str2.charAt(i))
			{
				count++;
			}
		}
		
		System.out.println(count);
		
	}
	
}

Measured memory_bytes: 41032
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

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

const ll INF=1e9+7;

int main(){
    ll h,w;
    cin >> h >> w;
    vector<vector<char>> s(h,vector<char>(w));
    ll ans=0;
    rep(i,h){
        rep(j,w){
            cin >> s[i][j];
            if(s[i][j]=='.') ans++;
        }
    }
    vector<vector<ll>> d(h,vector<ll>(w,INF));
    ll dx[4]={-1,1,0,0};
    ll dy[4]={0,0,-1,1};
    queue<pll> que;
    d[0][0]=1;
    que.push(make_pair(0,0));
    while(!que.empty()){
        pll x=que.front();
        que.pop();
        rep(i,4){
            ll nx=x.fi+dx[i];
            ll ny=x.se+dy[i];
            if(0<=nx && nx<=h-1 && 0<=ny && ny<=w-1 && d[nx][ny]==INF && s[nx][ny]=='.'){
                d[nx][ny]=d[x.fi][x.se]+1;
                que.push(make_pair(nx,ny));
            }
        }
    }
    if(d[h-1][w-1]==INF){
        cout << -1 << endl;
    }
    else{
        ans-=d[h-1][w-1];
        cout << ans << endl;
    }
} 


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B,C,D;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C>>D;
	if(A+B<C+D) cout<<"Right"<<endl;
	else if(A+B>C+D) cout<<"Left"<<endl;
	else cout<<"Balanced"<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
def main():
    a, b, c, d = map(int, input().split())
    if a >= 0:
        if b >= 0:
            if c >= 0:
                return b * d
            
            if d >= 0:
                return max(a*c, b*d)
            return a * d
    else:
        if b >= 0:
            if c >= 0:
                return b * d
            if d >= 0:
                return max(a*c, b*d)
            return a * c
        if c >= 0:
            return b * c
        if d >= 0:
            return a * c
        return a * c

if __name__ == "__main__":
    print(main())

Measured memory_bytes: 9164
while True:
  n, m = map(int, input().split())
  if n == 0:break
  lst = []
  for _ in range(n):
    num, x = input().split()
    lst.append((num, int(x)))
  
  ans= 0
  for _ in range(m):
    b = input()
    for num, x in lst:
      for i in range(8):
        if num[i] == "*" or num[i] == b[i]:continue
        else:break
      else:
        ans += x
        break 
  print(ans)


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR (a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] "
template <typename T>
struct IsC {
  template <typename C>
  static char test(typename C::const_iterator*);
  template <typename C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream&, const C&);
template <typename T1, typename T2>
ostream& operator<<(ostream&, const pair<T1, T2>&);
template <typename... T> using TS = tuple_size<tuple<T...>>;
template<size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return o << ", " << get<idx>(t) << ')';
}
template<size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << ", " << get<idx>(t), t);
}
template<size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << '(' << get<idx>(t), t);
}
template<typename T>
ostream& operator<<(ostream& o, const tuple<T>& t) {
  return o << get<0>(t);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p) {
  return o << mt(p.fi, p.se);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(
    ostream& o, const C& c) {
  o << '[';
  for (auto it = c.cbegin(); it != c.cend(); ++it)
    o << *it << (next(it) != c.cend() ? ", " : "");
  return o << ']';
}
template <typename T>
void tprint(vector<vector<T>>& v, size_t width = 0, ostream& o = cerr) {
  if (!DEBUG) return;
  for (auto& vv : v) {
    for (auto& i : vv) o << setw(width) << i;
    o << endl;
  }
}

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

  int n; cin >> n;
  vi cnt(n + 1);
  for (int x = 1; x * x <= n; ++x) {
    for (int y = 1; y * y + x * x <= n; ++y) {
      for (int z = 1; x * x + y * y + z * z <= n; ++z) {
        int sol = x*x + y*y + z*z + x*y + y*z + z*x;
        if (sol <= n) ++cnt[sol];
      }
    }
  }
  FOR (i, 1, n + 1) cout << cnt[i] << endl;
  
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

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

int main() {
  int n;
  cin >> n;
  vector<int> a;
  //queue<int> ok;
  rep(i, n) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());

  int a_max = a[n-1];
  vector<bool> eratos(a_max+1, true);
  int cnt=0;

  rep(i, n){
    int x = a[i], check = x*2;
    while(check<a_max+1){
      eratos[check] = false;
      check += x;
    }
  }

  int seq=1;
  rep(i, n){
    if(eratos[a[i]]){
      cnt++;
    }
    if(i!=0&&a[i-1]==a[i]){
      seq++;
    }else{
      if(seq>1){
        if(eratos[a[i-1]]){
          cnt -= seq;
        }
        seq = 1;
      }
    }
  }

  if(eratos[a[n-1]]&&seq>1){
    cnt -= seq;
  }

  cout << cnt << endl;

  return 0; 
}

Measured memory_bytes: 4296
a, b = map(int, input().split())

def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(x, y, mod):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2, mod)**2 % mod
    else            : return power(x, y//2, mod)**2 * x % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

import math
if (2 * a - b) % 3 != 0 or (2 * b - a) % 3 != 0:
    print(0)
else:
    d = (2 * b - a) // 3
    c = (2 * a - b) // 3
    if c < 0 or d < 0:
        print(0)
    else:
        print(comb(c+d, c, 10 ** 9 + 7))


Measured memory_bytes: 38640
#include <bits/stdc++.h>
#define isz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()

#define watch(x) std::cerr << #x << " = " << x
#define watchln(x) watch(x) << std::endl
#define cerr cerr && debug && std::cerr

template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
    os << "{";
    for (int i = 0; i < isz(vec); i++) {
        if (i > 0) os << ", ";
        os << vec[i];
    }
    return os << "}";
}

const int debug = 0;


using vi = std::vector<int>;
using ll = long long;

void assert_tle(bool q) { while (!q); }

int naive(vi d, const int n, int x, const int m) {
    for (auto &it : d) it %= m;
    std::cerr << "naive" << std::endl;
    watchln(d);
    watchln(x);
    watchln(n);
    watchln(m);
    assert(0 <= x && x < m);
    int cnt = 0;
    for (int iter = 1, i = 0; iter < n; iter++, i++) {
        if (i == isz(d)) i -= isz(d);
        int next = x + d[i];
        if (next >= m) next -= m;
        std::cerr << "a[" << iter << "] = " << next << std::endl;
        cnt += (x < next);
        x = next;
    }
    return cnt;
}

ll solve(vi d, const int n, const int x, const int m) {
    std::cerr << "---------------------------" << std::endl;
    std::cerr << "fast" << std::endl;
    for (auto &it : d) it %= m;
    if (isz(d) > n) d.resize(n);
    int nZeros = 0;
    for (auto &it : d) nZeros += (it == 0);
    ll s = std::accumulate(all(d), 0LL);
    int last = n-2;
    int q = last / isz(d);
    int r = last % isz(d);
    ll y = x + q * s;
    nZeros *= q;
    for (int i = 0; i <= r; i++) y += d[i], nZeros += (d[i] == 0);
    ll nLess = y / m;
    watchln(x);
    watchln(y);
    watchln(nZeros);
    watchln(nLess);
    return n-1 - nLess - nZeros;
}
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    int k, q; std::cin >> k >> q;
    vi d(k);
    for (auto &it : d) std::cin >> it;
    while (q--) {
        int n, x, m; std::cin >> n >> x >> m;
        //int nv = naive(d,n,x%m,m);
        int ft = solve(d,n,x%m,m);
        //for (int n2 = 2; n2 <= 1000; n2++) {
        //    assert(naive(d,n2,x%m,m) == solve(d,n2,x%m,m));
        //}
        //assert(ft == nv);
        std::cout << ft << std::endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

int main()
{
  int N, X, Y;
  cin >> N >> X >> Y;
  X -= 1;
  Y -= 1;

  map<ll, ll> ans;
  REP(i, N)
  {
    FOR(j, i + 1, N - 1)
    {
      ll d1 = j - i;
      ll d2 = abs(X - i) + 1 + abs(Y - j);
      ans[min(d1, d2)]++;
    }
  }

  FOR(i, 1, N - 1)
  {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main(){
  string s;
  cin >> s;
  int A = 0;
  rep(i,s.size()-1){
    if(s.at(i) == s.at(i+1)){
      if(s.at(i+1) == '0'){
        s.at(i+1) = '1';
      }
      else{
        s.at(i+1) = '0';
      }
      A++;
    }
  }
  if(A > s.size()/2){
    cout << s.size() - A;  
  }
  else{
    cout << A;
  }
}

Measured memory_bytes: 512
import numpy as np

n = int(input())
a = np.array(input().split(), np.int64)


def check(x):
    cnt = np.maximum((a + x + 1) // (n + 1), 0)
    return cnt.sum() <= x


l = -1
r = 10 ** 18

while r - l > 1:
    m = (l + r) // 2
    if check(m):
        r = m
    else:
        l = m

for i in range(max(r - n * n, 0), r + 1):
    if check(i):
        print(i)
        exit()


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>>KA(N, vector<int>(M+1));
  for(int i=0; i<N; i++){
    for(int j=0; j<M+1; j++){
      cin >> KA.at(i).at(j);
      if(KA.at(i).at(0)==j)break;
    }
  }
  
  vector<int>count(M+1);
  for(int i=0; i<N; i++){
    for(int j=1; j<KA.at(i).at(0)+1; j++){
      count.at(KA.at(i).at(j))++;
    }
  }
  
  int ans =0;
  for(int i=1; i<M+1; i++){
    if(count.at(i)==N)ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3564
S = input()

first_zero_count=0
first_one_count=0

counter = '0'
for i in range (len(S)):
    if S[i] == counter:
        first_one_count += 1
    else:
        first_zero_count+=1
    if counter =='0':
        counter ='1'
    else:
        counter = '0'
    
print(min(first_one_count,first_zero_count))

Measured memory_bytes: 3188
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

total = 0

lst = [a, b, c, d, e]

neck = min(lst)
idx = lst.index(neck)

# print(neck, idx)

d, m = divmod(n, neck)
if m > 0:
    total += 1

total += idx + d + (5 - idx - 1)

print(total)


Measured memory_bytes: 3064
import java.util.Scanner;

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

        int rects = 0;
        int rhombus = 0;
        while (sc.hasNext()) {
            String s = sc.next();

            int a = Integer.parseInt(s.split(",")[0]);
            int b = Integer.parseInt(s.split(",")[1]);
            int c = Integer.parseInt(s.split(",")[2]);

            if (a == b) {
                rhombus++;
            } else if (a * a + b * b == c * c) {
                rects++;
            }
        }

        System.out.println(rects);
        System.out.println(rhombus);
    }
}

Measured memory_bytes: 26184
/**
 *    Created By:  PeekyBlinders
 **/
#include <bits/stdc++.h>

using namespace std;

#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define double long double
#define endl '\n'

signed main() {
    fio;
    int n , d , a; cin >> n >> d >> a;
    vector<int> x(n) , sub(n + 1);
    map<int , int> health;
    for(int i = 0 , h; i < n; i++) {
        cin >> x[i] >> h;
        health[x[i]] = h;
    }
    sort(x.begin() , x.end());
    int answer = 0 , R = 0;
    for(int L = 0; L < n; L++) {
        while(R < n and x[R] - x[L] <= 2 * d) {
            R++;
        }
        int curh = max(0LL , health[x[L]] - sub[L] * a);
        int times = (curh + a - 1) / a;
        answer += times;
        sub[L] += times;
        sub[R] -= times;
        sub[L + 1] += sub[L];
    }
    
    cout << answer << endl;

    return 0;
}



Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//素因数に2をなんこ持つかで整理。となりを足し合わせて2にできればいい
//2があれば0が2個許容
//1は隣同士ならいい
//1はまとめればいい
//0と2の個数が重要
//0202020 0が2-1個までならOK
//02020201111はだめだ
//020211
//020 OK
int main(){
  ll N; cin>>N;
  ll zero=0,one=0,two=0;
  for(int i=0; i<N; i++){
    ll a; cin>>a;
    if(a%4==0) two++;
    else if(a%2==0) one++;
    else zero++;
  }
  if(two>=zero) cout<<"Yes"<<endl;
  else if(two==zero-1 && one==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

void printv(vector<auto> const& s) {
  REP(i, s.size()) {
    cout << s[i] << endl;
  }
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, k; cin >> n >> k;
  vi x(n), y(n);
  vi xar(n), yar(n);
  REP(i, n) {
    cin >> x[i] >> y[i];
    xar[i] = x[i];
    yar[i] = y[i];
  }
  sort(ALL(x));
  sort(ALL(y));

  ll ans = 1ll * (x[n-1] - x[0]) * (y[n-1] - y[0]);

  REP(xi, n) {
    FOR(xj, xi+1, n) {
      REP(yi, n) {
        FOR(yj, yi+1, n) {
          int num = 0;
          ll lx = x[xi], rx = x[xj];
          ll by = y[yi], uy = y[yj];

          REP(i, n) {
            if(lx <= xar[i] && xar[i] <= rx && by <= yar[i] && yar[i] <= uy) {
              num++;
            }
          }

          if(num >= k) ans = min(ans, 1ll * (rx - lx) * (uy - by));
        }
      }
    }
  }

  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    string s[3]; rep(i,3) cin>>s[i];
    cout<<"A"<<s[1][0]<<"C"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int a[50], b[50], c[50];


int main(void) {

	int n,total = 0;
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		total += b[i];
	}
	for (int i = 0; i < n - 1; i++)
		cin >> c[i];

	for (int i = 0; i < n - 1; i++) {
		if (a[i] + 1 == a[i + 1]) {
			total += c[a[i] - 1];
		}
	}

	COUT(total);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <set>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long ll;

#define forn(i, n) for(int i = 0; i < (int)(n);++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define fi first
#define se second
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vb vector<bool>
#define vvi vector<vi>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

ll n;

void fastik() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

//ifstream &cin
void solve(){

}

ll get(ll x){
    return (n+x-1)/x;
}

bool check(char c){
    return c == 'A' || c == 'C' || c == 'G' || c =='T';
}

int main() {
    fastik();
    string s;cin>>s;
    vs a(10,"");
    forn(i,min(sz(s),10)){
        fore(j,i,min(sz(s),10)-1){
            if(check(s[j])){
                a[i] += s[j];
            }else{
                break;
            }
        }
    }
    int ans = 0;
    forn(i,10){
        ans = max(ans,sz(a[i]));
    }
    cout << ans;


}

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

using namespace std;
using ll = long long;

ll dp[3001][3001][4] = {};
ll mp[3001][3001] = {};
ll dpm(int dpi, int dpj, int dpk) {
	ll x = dp[dpi][dpj][0];
	rep (dpr, dpk+1) x = max(x, dp[dpi][dpj][dpr]);
	return x;
}
int main() {
	int r, c, n;
	cin >> r >> c >> n;

	rep(i,n) {
		int h, w, v;
		cin >> h >> w >> v;
		mp[h][w] += v;
	}

	for (int i = 1; i <= r; i++) {
		for (int j = 1; j <= c; j++) {
			rep(k,4) {
				if (k == 0) {
					ll m = dpm(i-1, j, 3);
					m = max(m, dp[i][j-1][0]);
					dp[i][j][0] = m;
					continue;
				}
				dp[i][j][k] = mp[i][j] + max(dp[i][j-1][k-1], dpm(i-1,j,3));
				dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k]);
			}
		}
	}
	ll m = dpm(r, c, 3);
	ll ans = m;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 355096
#include<stdio.h>

int main(){
  while(1){
    int done = 0, m, n, i, l;
    scanf("%d", &l);
    if(l == 0)return 0;
    for(i = 1;i <= 12;i++){
      scanf("%d%d", &m, &n);
      if(!done){
	l -= m - n;
	if(l <= 0){
	  printf("%d\n", i);
	  done = 1;
	}
      }
    }
    if(done == 0)
      puts("NA");
  }
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void GO(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
const int N = 1e5+10, OO = 0x3f3f3f3f;
int a, b, c;

int main() {
    GO();
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"

using namespace std;

typedef long long ll;

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


int main(){
	ios_base::sync_with_stdio(false);
	
	ll n,m;cin>>n>>m;
	string s,t;cin>>s>>t;

	ll ans = (n*m)/(gcd(n,m));

	ll i=0,j=0;
	ll g = gcd(n,m);
	while(i<n && j<m){
		if(s[i]!=t[j]){
			// cout<<i<<" "<<j<<endl;
			cout<<-1<<endl;
			return 0;
		}
		i = i+(ans/m);
		j = j+(ans/n);
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 640
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    S=input()
    T=input()
    temp=S
    for i in range(len(S)*3):
        temp=temp[-1]+temp[:-1]
        #print(temp)
        if temp==T:print("Yes");return
    print("No")
    #print()
#%%submit!
resolve()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
long long int n, W, best, w[105], v[105], dp[105][100005];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> W;
    for(long long int i=1;i<=n;i++){
        cin >> w[i] >> v[i];
    }
    for(long long int i=0;i<=n;i++){
        for(long long int j=0;j<=W;j++){
            if(i==0 or j==0){
                dp[i][j]=0;
            }
            else{
                best=dp[i-1][j];
                if(j>=w[i]){
                    best=max(best, dp[i-1][j-w[i]]+v[i]);
                }
                dp[i][j]=best;
            }
        }
    }
    cout << dp[n][W] << endl;
}

Measured memory_bytes: 80128
int_num = int(input())
takahashi_can_calculation = set()

for i_left in range(1, 10):
    for i_right in range(1, 10):
        result = i_left * i_right
        takahashi_can_calculation.add(result)

if int_num in takahashi_can_calculation:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9080
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
int main() {
int x,x500=0,x5=0,amari=0;
    cin >>x;
    if(x>=500)
    {
        x500=x/500;
    }
    amari = x%500;
    if(amari>=5)x5=amari/5;
    cout<<x500*1000+x5*5<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
	int num,ans,pat;
	while(1){
		cin >> num >> ans;
		if(num == 0 && ans == 0){
			break;
		}
		pat = 0;
		for(int x = 1;x < num + 1;x++){
			for(int y = x + 1;y < num + 1;y++){
				for(int z = y + 1;z < num + 1;z++){
					if((x + y + z) == ans){
						pat++;
					}
				}
			}
		}
		cout << pat << endl;
	}

	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;

const int N = 300003;
const int MOD = 1e9 + 7;

inline int getInt() {
  int x;
  scanf("%d", &x);
  return x;
}

int main() {
  int n = getInt();
  int k = getInt();
  vi h(n), a(n, INT_MAX);
  for (int &x : h) {
    x = getInt();
  }
  a[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i - 1, l = 0; l < k && j >= 0; j--, l++) {
      a[i] = min(a[i], a[j] + abs(h[i] - h[j]));
    }
  }
  printf("%d\n", a[n - 1]);
  return 0;
}


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

int main(){
	int x=0, max=0;
	int n;
	cin >> n;
	string s;
	cin >> s;

	for(int i=0; i<s.size(); i++){
		if(s[i]=='I'){
			x += 1;
			if(x>max) max=x;
		}
		if(s[i]=='D'){
			x-=1;
		}
	}

	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string S, T;
  cin >> S >> T;
  int cnt=0;
  rep(i,3){
    if(S[i]==T[i])cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
 
int main() {
 
  char key[] = {'y','h','n','u','j','m','i','k','o','p','l','\0'};
  char str[33];
  int hand,cha,i,j;
 
 
 
 
  while(1) {
 
  scanf("%s",str);
 
  if(str[0] == '#') break;
 
 
  for(i=0;i<strlen(key); i++) {
 
    if(key[i] == str[0]) break;
 
  }
 
  //rgiht:0 left:1
  if(strlen(key) == i) hand = 1;
  else hand = 0;
 
  //printf("hand = %d\n",hand);
 
  cha = 0;
  for(i=1;i<strlen(str);i++) {
     
    for(j=0;j<strlen(key);j++) {
       
      if(hand ==  0 && str[i] == key[j]){
    break;
      } else if(hand ==  1 && str[i] == key[j]){
    hand = 0;
    cha++;
    break;
      }
    }
    if(hand == 0 && strlen(key) == j) {
      cha++;
      hand = 1;
    }
 
  }
     
   
  printf("%d\n",cha);
 
  }
 
 
 
  return 0;
 
}

Measured memory_bytes: 2572
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	string s; cin >> s;
	vector<unordered_set<int>> bs(n);
	{
		unordered_set<int> set;
		int  num = 0;
		FOR_LT(i, 0, n) {
			set.insert(s[i] - '0');
			bs[i] = set;
		}
	}

	vector<unordered_set<int>> es(n);
	{
		unordered_set<int> set;
		FOR_DW(i, n - 1, 0) {
			set.insert(s[i] - '0');
			es[i] = set;
		}
	}

	int ans[10][10][10] = {0};

	FOR_LT(i, 1, n - 1) {
		int m = s[i] - '0';
		for (auto k : bs[i - 1]) {
			for (auto l : es[i + 1]) {
				ans[m][k][l] = 1;
			}
		}
	}

	int num = 0;
	FOR_LT(i, 0, 10) {
		FOR_LT(j, 0, 10) {
			FOR_LT(k, 0, 10) {
				num += ans[i][j][k];
			}
		}
	}

	cout << num << endl;

	return 0;
}

Measured memory_bytes: 27904
import collections
import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = int(input())
s = []
for i in range(n):
    a = sorted(input())
    s.append(a)

ss = []

for i in range(n):
    ss.append(''.join(s[i]))

c = collections.Counter(ss)
d = sorted(list(c.values()), reverse=True)

sum = 0

for i in d:
    if i == 1:
        print(sum)
        exit()
    else:
        a = combinations_count(i, 2)
        sum += a

print(sum)

Measured memory_bytes: 41024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ll n, m; cin >> n >> m;
    m/=2;
    if(n>m) cout << m << endl;
    else if(n==m) cout << n << endl;
    else cout << n + (m-n)/2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    int n, m, i, j, cnt, max=0;
    char s[101][11], t[101][11];
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%s", s[i]);
    }
    scanf("%d", &m);
    for(i=0; i<m; i++){
        scanf("%s", t[i]);
    }
    for(i=0; i<n; i++){
        cnt=0;
        for(j=0; j<n; j++){
            if(strcmp(s[i], s[j]) == 0) cnt++;
        }
        for(j=0; j<m; j++){
            if(strcmp(s[i], t[j]) == 0) cnt--;
        }
        if(max<cnt) max=cnt;
    }
    printf("%d\n", max);
}

Measured memory_bytes: 128
import java.util.*;

class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int W = sc.nextInt();

        int[] wt = new int[N];
        int[] val = new int[N];

        for (int i = 0; i < N; i++) {
            wt[i] = sc.nextInt();
            val[i] = sc.nextInt();
        }

        System.out.println(knapsack(W,N,wt,val));
    }

    static long knapsack(int W, int N, int[] wt, int[] val) {

        long[][] dp = new long[N+1][W+1];

        for (int i = 0; i <= N; i++) {
            for (int w = 0; w <= W; w++) {
                if (i == 0 || w == 0) 
                    dp[i][w] = 0;
                else if (wt[i-1] <= w) {
                    long a = val[i-1] + dp[i-1][w-wt[i-1]];
                    long b = dp[i-1][w];
                    dp[i][w] = Math.max(a,b);
                } else
                    dp[i][w] = dp[i-1][w];
            }
        }

        return dp[N][W];
    }
}







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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define ALL(x) (x).begin(), (x).end()
#define OUT(a) cout << (a) << "\n"

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

const ll MOD = 10e9 + 7;
ll dp[101][100001];

int main() {
    int a,b;
  	cin >> a >> b;
  	int res = b;
  	if (a <= 5 ) res = 0;
  	else if (a <= 12) res = b / 2;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
//I am so vegetable
//#define _LOCAL_
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define PB push_back
#define IN insert
#define ER erase
#define CT count
#define EP empty
#define _for(i,a,b) for(ll i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll N = 1e5 + 5;
const int MOD = 998244353;
const double eps = 1e-6;
const double pi = acos(-1);
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
priority_queue<int>ma;
priority_queue<int, vector<int>, greater<int> >mi;
ll sma, smi;
void add(int x) {
	if (!ma.empty() && ma.top() >= x) {
		ma.push(x);
		sma += x;
	}
	else {
		mi.push(x);
		smi += x;
	}
	while (mi.size() - ma.size() > 1) {
		int cur = mi.top(); mi.pop(); smi -= cur;
		ma.push(cur); sma += cur;
	}
	while (mi.size() - ma.size() < 1) {
		int cur = ma.top(); ma.pop(); sma -= cur;
		mi.push(cur); smi += cur;
	}
}
int main() {
	FIO;
	int T; cin >> T;
	ll sb = 0;
	while (T--) {
		int q; cin >> q;
		if (q == 1) {
			int x, b;
			cin >> x >> b;
			sb += b;
			add(x);
		}
		else {
			int x = mi.top();
			cout << x << ' ' << (1ll * x *(int)ma.size() - sma) + (smi - 1ll * x * (int)mi.size()) + sb << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 3452
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
long long int i,j;
int cmpr(const void*a,const void*b){
    return *(long long int*)a-*(long long int*)b;
}
int main(void){
    long long int n,m;
    long long int a[100000][2];
    scanf("%lld %lld",&n,&m);
    for(i=0;i<n;i++)scanf("%lld %lld",&a[i][0],&a[i][1]);
    qsort(a,n,sizeof(a[0]),cmpr);
    long long int sum=0,cnt=0;
   // for(int i=0;i<n;i++)printf("%d %d\n",a[i][0],a[i][1]);
    for(i=0;i<n;i++){
        for(j=0;j<a[i][1];j++){
            sum+=a[i][0];
            cnt++;
            if(cnt>=m) break;
        }
      if(cnt>=m) break;
    }
    printf("%lld",sum);
    return 0;
}

Measured memory_bytes: 3324
n, k = map(int, input().split())
a = list(map(int, input().split()))

num = 1
li = [1]
flag = [True] * n
flag[0] = False

for i in range(k):
    num = a[num-1]
    if flag[num-1]:
        li.append(num)
        flag[num-1] = False
    else:
        break

d = li.index(num)
ans = (k-d)%(len(li)-d)+d

print(li[ans])

Measured memory_bytes: 32368
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
N, M, X = ri_()
A = ri_()
i = bisect_left(A, X)
print(min(len(A[:i]), len(A[i:])))

Measured memory_bytes: 63596
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int N;
double dp[301][301][301];

double rec(int c1, int c2, int c3) {
  if (dp[c1][c2][c3] >= 0) return dp[c1][c2][c3];

  double f = N;
  if (c1 > 0) f += c1 * rec(c1-1, c2, c3);
  if (c2 > 0) f += c2 * rec(c1+1, c2-1, c3);
  if (c3 > 0) f += c3 * rec(c1, c2+1, c3-1);

  dp[c1][c2][c3] = f / (c1 + c2 + c3);
  return dp[c1][c2][c3];
}

int main() {
  cin >> N;
  map<int, int> m;
  for (int i = 0; i < N; ++i) {
    int a; cin >> a;
    m[a]++;
  }
  int c1 = m[1], c2 = m[2], c3 = m[3];

  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= N; ++j) {
      for (int k = 0; k <= N; ++k) {
        dp[i][j][k] = -1;
      }
    }
  }
  dp[0][0][0] = 0;
  printf("%.10f\n", rec(c1, c2, c3));
}


Measured memory_bytes: 216832
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
 //freopen("input.txt", "r", stdin); 
 //freopen("output.txt", "w", stdout); 
int n;
cin>>n;
cout<<(1000 - n%1000)%1000<<endl;
return 0;
}

Measured memory_bytes: 3668
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);


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

	int N;
	cin >> N;
	string s, t;
	cin >> s >> t;

	for (int a = N; a; a--) {
		bool flag = true;
		rep(i, a)if (s[N - a+i] != t[i])flag = false;
		if (flag) {
			cout << N * 2 - a << endl;
			return 0;
		}
	}

	cout<<N * 2 << endl;

	return 0;
}

Measured memory_bytes: 256
S = input()

M = ["N","W","S","E"]
Sw = [0,0,0,0]

for i in range(4):
    if M[i] in S: Sw[i] += 1
        
if (Sw[0]+Sw[2])%2==0 and (Sw[1]+Sw[3])%2==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064