akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define f(i,l,n) for(ll i=l;i<n;i++)
#define ff first
#define ss second
#define pb push_back
#define E "\n"
#define mp make_pair
#define N (ll)pow(2,32)-1
 
const int M=1e9+7;
int dp[50][10];




int cal(int len,int num)
{

  int &ans=dp[len][num];
  if(ans!=-1) return ans;
  

  if(len==1) return ans=1;

  ans=0;

  for(int i=max(0LL,num-1);i<=min(9LL,num+1);i++)
  {
    ans+=cal(len-1,i);
  }
  return ans;
}
string ans="";
void final(int len,int num,int b)
{
  int need=cal(len,num);
  need=need-b;
  //cout<<num<<" "<<len<<" "<<need<<E;
  
  ans+=(char)(num+'0');

  if(len==1)
  {
    return ;
  }

  int cnt=0;
 // cout<<"F\n";
  for(int i=max(0LL,num-1);i<=min(9LL,num+1);i++)
  {
    cnt+=cal(len-1,i);
   // cout<<"cnt need "<<cnt<<" "<<need<<E;
    if(cnt>=need)
    {
      final(len-1,i,cnt-need);
      return ;
    }
  }
  return ;
}

 int solve()
 {

  memset(dp,-1,sizeof dp);
  int k;
  cin >> k;

  int cnt=0;
  int len=1;

  while(1)
  {
    
    for(int num=1;num<=9;num++)
    {
      cnt+=cal(len,num);
      //cout<<cnt<<" "<<len<<" "<<num<<E;
      if(cnt>=k)
      {
       // cout<<len<<" "<<num<<" "<<cnt<<" "<<k<<" "<<cal(len,num)<<E;
        final(len,num,cnt-k);
        cout<<ans<<E;
        return 0;
      }
    }
    len++;
  } 

  //cout<<dp[2]<<E;
  return 0;
 }
int32_t main()
{
  
  int t=1;
  //cin >> t;
  while(t--)
  {
    solve();  
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N;
  cin >> N;
  cout << (1000-N%1000)%1000 << endl;

  return 0;
}


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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define All(x) (x).begin(), (x).end()
#define mp make_pair
#define Task "abc"

typedef long long ll;
const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(NULL);
//  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  int a, b, c, k; cin >> a >> b >> c >> k;
  int d = max(0, k - a - b);
  cout << min(a, k) - d;
return 0;
}




Measured memory_bytes: 3620
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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

	int a, b, c, d;
	cin >> a>>b;
	if (a == b)
		cout << "Draw" << endl;
	else if (a == 1)
		cout << "Alice" << endl;
	else if (b == 1)
		cout << "Bob" << endl;
	else if (a > b)
		cout << "Alice" << endl;
	else
		cout << "Bob" << endl;
	return 0;
}



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

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

using namespace std;

int main() {
  int a[12];
  map<int,int> mp;
  rep(i,12) {
    cin >> a[i];
    ++mp[a[i]];
  }
  rep(i,12) rep(j,12) {
    map<int,int> mp2 = mp;
    mp2[a[i]] -= 4;
    mp2[a[j]] -= 4;
    if( mp2[a[i]] < 0 || mp2[a[j]] < 0 ) {
      continue;
    }
    map<int,int> counter;
    int key = -1;
    for(auto v : mp2) {
      if( v.second > 0 ) {
        counter[v.first] += v.second;
        key = v.first;
      }
    }
    if( counter.size() != 1 ) continue;
    if( counter[key] == 4 ) {
      puts("yes");
      return 0;
    }
  }
  puts("no");
  return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a[100005],b[100005],c[100005];
ll sum;
ll M;
ll amari(ll i,ll j){
	if(i%j>=0){
		return i%j;
	}else{
		return i%j+j;
	}
}
int main(void){
	cin>>n;
	ll SUM=n*(n+1)/2;
	cin>>a[0];
	sum=sum+a[0];
	for(int i=1;i<n;i++){
		cin>>a[i];
		sum=sum+a[i];
		b[i-1]=a[i]-a[i-1];
	}
	b[n-1]=a[0]-a[n-1];
	if(sum%SUM!=0){
		cout<<"NO"<<endl;
		return 0;
	}
	ll k=sum/SUM;
	for(int i=0;i<n;i++){
		b[i]=b[i]-k;
		if(b[i]%n!=0||b[i]>0){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
}


Measured memory_bytes: 1792
import math
n = int(input())

for i in range(n):
  x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())


  if abs((x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3)) < 1e-10:
    print('YES')
  else:
    print('NO')


Measured memory_bytes: 5660
import java.io.*;
public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int rec=0,rho=0;
		int a,b,d;
		String str;
		try{
			while((str=br.readLine())!=null&&!str.isEmpty()){
				String[] s=str.split(",");
				a=Integer.parseInt(s[0]);
				b=Integer.parseInt(s[1]);
				d=Integer.parseInt(s[2]);
				if(a*a+b*b==d*d) rec++;
				else if(a==b) rho++;
			}
			System.out.println(rec+"\n"+rho);
		}catch(Exception e){
			System.out.println("Input Error");
		}
	}
}

Measured memory_bytes: 16900
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
// #pragma GCC optimize ("Ofast,unroll-loops,-ffloat-store")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

string to_string(const string& s) { return '"' + s + '"'; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
    #define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 3
#endif
 
#define cin_exception cin.exceptions(cin.failbit);
#define cout_precision cout.setf(ios::fixed); cout.precision(15);
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using ld = long double; using vi = vector<int>;
using ll = int_fast64_t; using ull = uint_fast64_t;
using vl = vector<ll>; using vul = vector<ull>;

// -----------------------------------------------------------------------------

const int H = 10 + 5;
const int W = 1e3 + 5;
int h, w, k;
string s[H];
int ca[H];
int v[H];

void solve() {
    cin >> h >> w >> k;
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    int re = INT_MAX;
    for (int mask = 0; mask < (1 << (h - 1)); ++mask) {
        int row_cuts = 0, x = mask;
        for (int r = 1; r < h; ++r) {
            if (x & 1) ca[r] = ++row_cuts;
            else ca[r] = row_cuts;
            x >>= 1;
        }
        fill_n(v, h, 0);
        int col_cuts = 0, fail = 0;
        for (int c = 0; c < w; ++c) {
            int cut = 0;
            for (int r = 0; r < h; ++r) {
                if (s[r][c] == '0') continue;
                ++v[ca[r]];
            }
            for (int i = 0; i < h; ++i) {
                if (v[i] > k) {
                    cut = 1;
                    break;
                }
            }
            if (!cut) continue;
            ++col_cuts;
            fill_n(v, h, 0);
            for (int r = 0; r < h; ++r) {
                if (s[r][c] == '0') continue;
                ++v[ca[r]];
            }
            for (int i = 0; i < h; ++i) {
                if (v[i] > k) {
                    fail = 1;
                    break;
                }
            }
            if (fail) break;
        }
        if (fail) continue;
        re = min(re, row_cuts + col_cuts);
    }
    cout << re << '\n';
}

// -----------------------------------------------------------------------------

int main() {
    fast_io;
#ifdef LOCAL
    cin_exception;
#endif
    int t = 1;
    // cin >> t;
    // preprocess();
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,k;
// ll arr[10002][10005]={0};

ll solve(ll a[],ll b[],ll n,ll k, vector<vector<ll>>& arr){
if(n==0||k==0)return 0;

  if(arr[n][k]!=0)return arr[n][k];

  if(a[n-1]>k){
  arr[n][k]=solve(a,b,n-1,k,arr);
    return arr[n][k];
    }
  
  arr[n][k]=max(b[n-1]+solve(a,b,n-1,k-a[n-1],arr),solve(a,b,n-1,k,arr));
  return arr[n][k];


}



int main(){
  
  cin>>n>>k;
  ll a[n],b[n];
  vector<vector<ll>>arr(n+1,vector<ll>(k+1,0));
//   for(int i=0;i<=)
for(ll i=0;i<n;i++)cin>>a[i]>>b[i];

ll t=solve(a,b,n,k,arr);


cout<<t;
}
  

Measured memory_bytes: 80256
#include<bits/stdc++.h>
const int maxn = 100100;
const int mod = 1e9 + 7;
typedef long long ll;
struct T{ int u, v, w; } e[maxn];
struct { int to,nxt,v; }way[maxn << 1];
inline ll pow(int a,int b,int ans = 1) {
	for(;b;b >>= 1,a = (ll) a * a % mod) if(b & 1)
		ans = (ll) ans * a % mod;
	return ans;
}
int h[maxn], num;
inline void link(int x,int y,int v) {
	way[++num] = {y,h[x],v}, h[x] = num;
	way[++num] = {x,h[y],v}, h[y] = num;
}
int bz[20][maxn], max[20][maxn], dep[maxn];
inline void dfs(int x,int f = 0) {
	dep[x] = dep[f] + 1;
	for(int i = 1;i < 20;++i) {
		bz[i][x] = bz[i - 1][bz[i - 1][x]];
		max[i][x] = std::max(max[i - 1][x], max[i - 1][bz[i - 1][x]]);
	}
	for(int i = h[x];i;i=way[i].nxt) if(way[i].to != f) {
		max[0][way[i].to] = way[i].v;
		bz[0][way[i].to] = x;
		dfs(way[i].to,x);
	}
}
inline void up(int & x,int y) {
	if(x < y) x = y;
}
inline int get(int x,int y) {
	if(dep[x] > dep[y]) std::swap(x, y);
	int ret = 0;
	for(int d = dep[y] - dep[x]; d; d &= d - 1) up(ret, max[__builtin_ctz(d)][y]), y = bz[__builtin_ctz(d)][y];
	for(int i = 19;i >= 0;--i) if(bz[i][x] != bz[i][y]) {
		up(ret, max[i][x]), x = bz[i][x];
		up(ret, max[i][y]), y = bz[i][y];
	}
	if(x != y) up(ret, std::max(max[0][x], max[0][y]));
	return ret;
}
int in[maxn];
int fa[maxn];
inline int find(int x){ return fa[x] == x ? x : fa[x] = find(fa[x]); }
int n, m;
ll x, sum;
int main() {
	std::ios::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> m >> x;
	for(int i = 1;i <= n;++i) fa[i] = i;
	for(int i = 1;i <= m;++i) std::cin >> e[i].u >> e[i].v >> e[i].w;
	std::sort(e + 1,e + m + 1,[](const T & x,const T & y) { return x.w < y.w; });
	int c = 0;
	for(int i = 1;i <= m;++i) {
		if(find(e[i].u) != find(e[i].v)) {
			fa[find(e[i].u)] = find(e[i].v);
			sum += e[i].w;
			link(e[i].v, e[i].u, e[i].w);
			in[i] = 1, ++c;
		}
	}
	if(c < n - 1) {
		std::cout << 0 << '\n';
		return 0;
	}
	dfs(1);
	if(x < sum) {
		std::cout << 0 << '\n';
		return 0;
	}
	if(x == sum) {
		int cnt = 0;
		for(int i = 1;i <= m;++i) cnt += get(e[i].u, e[i].v) == e[i].w;
		std::cout << (pow(2, cnt) - 2) * pow(2, m - cnt) % mod << '\n';
		return 0;
	}
	int cnt0 = 0, cnt1 = 0;
	for(int i = 1;i <= m;++i) cnt0 += e[i].w - get(e[i].u, e[i].v) < x - sum;
	for(int i = 1;i <= m;++i) cnt1 += e[i].w - get(e[i].u, e[i].v) == x - sum;
	std::cout << 2 * (pow(2, cnt1) - 1) * pow(2, m - cnt0 - cnt1) % mod << '\n';
}


Measured memory_bytes: 16768
def isPrime( x )
	return true if ( 2 == x || 3 == x )
	return false if ( 0 == x%2 )
	
	for i in ( 3 .. x )
		break if x < i*i
		return false if 0 == x%i
	end
	
	return true
end

n = gets.to_i
nums = []
n.times {
	nums.push( gets.to_i )
}

cnt = 0
for i in ( 0 ... n )
	if isPrime( nums[i] )
		cnt += 1
	end
	i += 1
end
puts( cnt )

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	vector<int>a(3); for(auto&i:a)cin>>i;
	sort(a.begin(),a.end(),[](auto a,auto b){return a>b;});
	int ans=0;
	for(int i=1;i<3;++i)ans+=abs(a.at(i)-a.at(i-1));
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
import sys

n, m, r = list(map(int, input().split(" ")))

if n * m > r:
    print(0)
    sys.exit()

r = r - n * m
res = 1
for i in range(1, n + r):
    res *= i
for i in range(1, n):
    res //= i
for i in range(1, r + 1):
    res //= i
print(int(res))


Measured memory_bytes: 5636
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

let main() =
    let [| k; x |] = reada int
    if k * 500 >= x then "Yes" else "No"
    |> puts
    ()

main()
writer.Close()


Measured memory_bytes: 11220
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int a, b;

    cin >> a >> b;

    cout << max({a + b, a * 2 - 1, b * 2 - 1}) << endl;
}

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

int main(){
  ll n;
  cin>>n;
  ll xpymax=-(ll)1e10,xpymin=(ll)1e10,xmymax=-(ll)1e10,xmymin=(ll)1e10;
  for(int i=0;i<n;i++){
    ll x,y;
    cin>>x>>y;
    xpymax=max(xpymax,x+y);
    xpymin=min(xpymin,x+y);
    xmymax=max(xmymax,x-y);
    xmymin=min(xmymin,x-y);
  }
  ll ans=0;
  ans=max(ans,xpymax-xpymin);
  ans=max(ans,xmymax-xmymin);
  cout<<ans<<endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>

using namespace std;

#define ll long long
#define ld long double

#define rep(i, n)      for (int i = 0; i < (int)(n); ++i)
#define rep3(i, m, n)  for (int i = (m); i < (int)(n); ++i)
#define rrep(i, n)     for (int i = (int)(n)-1; i >= 0; --i)
#define rrep3(i, m, n) for (int i = (int)(n)-1; i >= (m); --i)
#define all(x) begin(x), end(x)
#define rall(x) end(x), begin(x)

#define endl '\n'


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

ll solve(ll N) {
  return N*(N-1)/2;
}

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

  ll N;
  cin >> N;

  auto ans = solve(N);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3188
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue> 
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
#define int LL
#define db double
using namespace std;
const int N   = 2e5+233;
//const int mod = ;
const int INF =numeric_limits<int >::max();
#define For(n) for (int i=1;i<=n;++i)
#define rep(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
	x=0;
	char ch=getchar();
	int f=1;
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
}

int n,a[N],b[N],k;

signed main()
{
	read(n);
	rep(i,1,n) read(a[i]),b[i]=a[i];b[n+1]=INF>>1;
	sort(b+1,b+1+n);
	int M=b[n];k=n;
	rep(i,1,n) 
		if (abs(a[i]*2-M)<=abs(a[k]*2-M)) k=i;
	printf("%lld %lld",M,a[k]);
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    int N, A, min = 1e+9, max = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A;
        if (A > max) {
            max = A;
        }
        if (A < min) {
            min = A;
        }
    }
    cout << max - min;
}


Measured memory_bytes: 384
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools
from collections import defaultdict

N,*A = map(int,read().split())

Acum = [0] + list(itertools.accumulate(A))

counter = defaultdict(int)
answer = 0
for x in Acum:
    answer += counter[x]
    counter[x] += 1

print(answer)


Measured memory_bytes: 41444
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var nums = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).OrderBy(x => x).ToList();
        var bnum = 0L;
        for (var i = 0; n > i; i++)
        {
            if (nums[i] == bnum)
            {
                Console.WriteLine("NO");
                return;
            }
            bnum = nums[i];
        }
        Console.WriteLine("YES");
    }
}


Measured memory_bytes: 36404
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
   int A,B,M,d=1000000000;
   cin >> A >> B >> M;
   int a[A],b[B];
   rep(i,A) cin >> a[i];
   rep(i,B) cin >> b[i];
   rep(i,M){
       int x,y,c;
       cin >> x >> y >> c;
       d = min(d,a[x-1]+b[y-1]-c);
   }
   sort(a,a+A);
   sort(b,b+B);
   d = min(d,a[0]+b[0]);
   cout << d << endl;
}

Measured memory_bytes: 1024
card=[list(map(int,input().split())) for i in range(3)]
N=int(input())
target_list=[int(input()) for i in range(N)]

for i, line in enumerate(card):
    for j, pt in enumerate(line):
        if pt in target_list:
            card[i][j] = 1 # マークあり
        else:
            card[i][j] = 0 #マークなし

result = False
# 横
for l in card:
    if l.count(1) == 3:
        result = True

# 縦
for l in list(zip(*card)):
    if l.count(1) == 3:
        result = True

# 斜め
if card[1][1] == 1: #真ん中にマークあり
    if card[0][0] == 1 and card[2][2] == 1:
        result = True
    if card[0][2] == 1 and card[2][0] == 1:
        result = True

if result:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll A[53];

int main(){
    ll K;
    cin >> K;
    if(K==0){
        cout << 2 << endl;
        cout << "1 1" << endl;
        return 0;
    }
    cout << 50 << endl;
    if(K<=50){
        rep(i,50){
            if(i<K){
                A[i]=50-i;
            }
        }
    }
    else{
        ll C=(K-1)/50;
        ll B=(K-1)%50;
        rep(i,50){
            if(i<=B){
                A[i]=50+C-i;
            }
            else{
                A[i]=50+C-1-i;
            }
        }
    }
    rep(i,50){
        cout << A[i] ;
        if(i==49){
            cout << endl;
        }
        else{
            cout << " ";
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int i,j,n,a[200],b[200],x[200],A;
	n=0;
	for(i=0;i<200;i++){
		a[i]=0;
		b[i]=0;
	scanf("%d %d",&a[i],&b[i]);
		if(a[i] == 0 && b[i] == 0){
		n=i;
		break;
	}
	}
	A=0;
	for(i=0;i<200;i++){
	A=a[i]+b[i];
	if(A == 0){
		x[i]=0;
	}
	else x[i]=1;
	for(j=0;j<7;j++){
		if(A >= 10){
		x[i]=x[i]+1;
	}
		else break;
	A=A/10;
	}
	}
	
	for(i=0;i<n;i++){
		printf("%d\n",x[i]);
	}
return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

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

    if (X < A || X > A + B) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }

    return 0;
}


Measured memory_bytes: 3464
import fractions
def lcm(x, y):
    return x * y // fractions.gcd(x, y)

A, B, C, D = map(int,input().split())
E = lcm(C, D)
print((B - (B // C + B // D - B // E))-((A-1)-((A-1) // C + (A-1) // D - (A-1) // E)))



Measured memory_bytes: 5304
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
void solve()
{
	string str;
	ll a=0,b=0;
	cin>>str;
	for(int i=0;i<str.size();i++)
	{
		if(str[i]=='A')
			a=1;
		if(str[i]=='B')
			b=1;
	}
	if(a==1&&b==1)
	{
		cout<<"Yes\n";
	}
	else
		cout<<"No\n";
	
	return;
}
int main()
{
	
	ll t=1;
	//rl(t);

	//cin>>t;
	//scanf()
	while(t--)
	{
		solve();
	}
	
	return 0;
}

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

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, u, k, vi;
    std::cin >> n;
    std::vector<std::vector<int>> v(n+1);
    std::queue<int> ex;
    ex.push(1);
    int distance[101]={};
    for (int i=2; i<101; i++) {
        distance[i] = -1;
    }
    for (int i=0; i<n; i++) {
        std::cin >> u >> k;
        for (int j=0; j<k; j++) {
            std::cin >> vi;
            v[u].push_back(vi);
        }
    }

    while (not ex.empty()) {
        int a = ex.front();
        ex.pop();
        for (int i=0; i<v[a].size(); i++) {
            if (distance[v[a][i]] == -1) {
                ex.push(v[a][i]);
                distance[v[a][i]] = distance[a] + 1;
            }
        }
    }

    for (int i=1; i<=n; i++) {
        std::cout << i << " " << distance[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 3172
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(stdin.readline().rstrip()) for _ in range(N)]

def insertion_sort(a, n, g, count):
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j = j - g
            count += 1
        a[j+g] = v

    return a, count

def shell_sort(a, n, m, G):
    count = 0
    for i in range(100):
        if i == 0:
            G[i] = n//2+1
        else:
            G[i] = G[i-1]//2-1
        if G[i] < 0:
            G[i-1] = 1
            G[i] = 0
            m = i
            break
    for i in range(m):
        a, count = insertion_sort(a, n , G[i], count)
    
    return a, count, m , G

G = [0]*100
m = 0
A, count, m, G = shell_sort(A, N, m, G)
print(m)
for i in range(m):
    if i == m-1:
        print(G[i])
    else:
        print(G[i], end=" ")
print(count)
for i in range(N):
    print(A[i])


Measured memory_bytes: 45516
#include <iostream>
#include <cmath>
#include <cstring>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <unordered_map>

#define DEBUG false
#define OJ_DEBUG

#define $(x) {if (DEBUG) {cout << __LINE__ << ": "; {x} cout << endl;}}
#define _(x) {cout << #x << " = " << x << " "; }
const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef std::pair<int, int> pii;
typedef unsigned long ul;

int main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int a, b;
    cin >> a >> b;
    for (int i = 1; i <= 1e4; ++i) {
        int n1 = i * 10/100, n2 = i * 8/100;
        if (a == n2 && b == n1) {
            cout << i << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';
    return 0;
}

Measured memory_bytes: 256
class BinarySearchTree:
    def __init__(self):
        self.lcs = {}
        self.rcs = {}
        self.root = None

    def insert(self, key):
        if self.root is None:
            self.root = key
            self.lcs[key] = None
            self.rcs[key] = None
            return
        parent = self.root
        while True:
            if key < parent:
                if self.lcs[parent] is None:
                    self.lcs[parent] = key
                    self.lcs[key] = None
                    self.rcs[key] = None
                    break
                else:
                    parent = self.lcs[parent]
            else:
                if self.rcs[parent] is None:
                    self.rcs[parent] = key
                    self.lcs[key] = None
                    self.rcs[key] = None
                    break
                else:
                    parent = self.rcs[parent]

    def _print(self, cur):
        self.preorder.append(cur)
        if self.lcs[cur]:
            self._print(self.lcs[cur])
        self.inorder.append(cur)
        if self.rcs[cur]:
            self._print(self.rcs[cur])

    def print(self):
        self.preorder = []
        self.inorder = []
        self._print(self.root)
        print(' ' + ' '.join(map(str, self.inorder)))
        print(' ' + ' '.join(map(str, self.preorder)))


T = BinarySearchTree()
N = int(input())
for _ in range(N):
    s = input().split()
    if s[0] == 'insert':
        T.insert(int(s[1]))
    else:
        T.print()



Measured memory_bytes: 107988
#include <cstdio>
using namespace std;
long long power(long long x,long long y,long long z)
{
	if(y==0)
	{
		return 1;
	}
	long long tmp=power(x,y>>1,z),ans=(tmp*tmp)%z;
	if(y&1)
	{
		ans=(ans*x)%z;
	}
	return ans;
}
long long n,a,x,y,u=1,v=1;
int main()
{
	scanf("%lld%lld%lld",&n,&x,&y);
	a=power(2,n,1000000007);
	for(long long i=n;i>n-x;i--)
	{
		u=(u*i)%1000000007;
	}
	for(long long i=2;i<=x;i++)
	{
		u=(u*power(i,1000000005,1000000007))%1000000007;
	}
	for(long long i=n;i>n-y;i--)
	{
		v=(v*i)%1000000007;
	}
	for(long long i=2;i<=y;i++)
	{
		v=(v*power(i,1000000005,1000000007))%1000000007;
	}
	printf("%lld",(a-u-v-1+10000000070ll)%1000000007);
	return 0;
}

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

int main(){
  int N,ans=0;
  cin>>N;
  vector<int>vec(2*N);
  for(int i=0;i<2*N;i++){
  cin>>vec.at(i);
  }
    for(int i=0;i<N;i++){
    if(vec.at(i)-vec.at(i+N)>0)
      ans+=vec.at(i)-vec.at(i+N);
    }
  cout<<ans<<endl;
 }

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
void func(int in[],int a,int b){
  rep(i,5){
    if(in[i]==a)cout<<1<<endl;
    else cout<<2<<endl;
  }
}
int main(){
  int in[5];
  while(cin>>in[0],in[0]){
    rep(i,4)cin>>in[i+1];
    int c1=0,c2=0,c3=0;
    rep(i,5){
      if(in[i]==1)c1++;
      if(in[i]==2)c2++;
      if(in[i]==3)c3++;
    }
    if((c1&&c2&&c3)||c1==5||c2==5||c3==5)rep(i,5)cout<<3<<endl;
    else{
      if(!c1)func(in,2,3);
      else if(!c2)func(in,3,1);
      else if(!c3)func(in,1,2);
    }
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define lowbit(a) ((a)&(-(a)))
using namespace std;

void file(bool opt)
{
	if (opt&&fopen("in.txt", "r"))
	{
		freopen("in.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	}
}

long long L, A, B;
long long mod;
long long ans = 0;
long long powt[19];
struct mat {
	int val[3][3];
	mat() { memset(val, 0, sizeof val); }
	void init(int i)
	{
		memset(val, 0, sizeof val);
		val[0][0] = powt[i] % mod, val[1][0] = val[1][1]= val[2][2] = 1;
		val[2][1]=B%mod;
	}
};

mat operator*(mat a, mat b)
{
	mat c;
	for (int i = 0; i<3; i++)
		for (int j = 0; j<3; j++)
			for (int k = 0; k<3; k++)
				c.val[i][j] = (c.val[i][j] + 1ll * a.val[i][k] * b.val[k][j]) % mod;
	return c;
}

void poww(long long L,long long R,int d)
{
	long long n = (R - L) / B + 1;
	mat res;
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
			res.val[i][j] = (i == j);

	mat a;
	a.init(d);

	while (n)
	{
		if (n & 1)res = res * a;
		n >>= 1;
		a = a*a;
	}
	ans = (1ll * ans*res.val[0][0]%mod + L % mod*res.val[1][0] % mod + res.val[2][0]) % mod;
}

int main()
{
	cin >> L >> A >> B >> mod;
	powt[0] = 1;
	for (int i = 1; i <= 18; i++)
		powt[i] = powt[i - 1] * 10ll;

	long long ed = A + B * (L - 1);

	for (int d = 1; d <= 18; d++)
	{
		if (A < powt[d])
		{
			long long R = (powt[d] - 1 - A) / B * B + A;
			R = min(R, ed);
			poww(A, R, d);
			if (R == ed)break;
			A = R + B;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  cout << a[0] + a[1] << endl;
  return 0;
}


Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()
a = [0] * n
ac = 0

for i in range(1, n):
    if s[i - 1] == 'A' and s[i] == 'C':
        ac += 1
    a[i] = ac

for i in range(q):
    l, r = map(int, input().split())
    print(a[r - 1] - a[l - 1])

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

//-----------------------------------------------------------------------------


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

	int n,a,b,c;
	cin>>n;
	if(n==2) {
		cin>>a>>b;
		FOR(i,1,min(a,b)+1) {
			if(a%i==0&&b%i==0) cout<<i<<endl;
		}
	}
	else {
		cin>>a>>b>>c;
		FOR(i,1,min(a,min(b,c))+1) {
			if(a%i==0&&b%i==0&&c%i==0) cout<<i<<endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3220
package main

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var a, b, c string
	con.Scan(&a, &b, &c)
	if a[len(a)-1] == b[0] && b[len(b)-1] == c[0] {
		con.Println("YES")
	} else {
		con.Println("NO")
	}
	return nil
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define P pair<int,int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define int long long

signed main() {
    int board[3][3];
    bool check[3][3];
    rep(i,3) rep(j,3) {
        cin >> board[i][j];
        check[i][j] = false;
    }

    int n;
    cin >> n;
    while(n--){
        int a;
        cin >> a;
        rep(i,3){
            rep(j,3){
                if(board[i][j] == a) check[i][j] = true;
            }
        }
    }
    bool flag = false;
    rep(i,3) {
        int cnt = 0;
        rep(j,3){
            if(check[i][j]) cnt++;
        }
        if(cnt == 3) {
            flag = true;
            break;
        }
    }
    rep(i,3) {
        int cnt = 0;
        rep(j,3){
            if(check[j][i]) cnt++;
        }
        if(cnt == 3) {
            flag = true;
            break;
        }
    }

    if(check[2][0] && check[1][1] && check[0][2]) flag = true;
    if(check[0][0] && check[1][1] && check[2][2]) flag = true;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;


}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
const int INF=1e9;
using namespace std;

main(){
  int N;
  cin >> N;
  int K;
  cin >> K;
  int h[N];
  for(int ii=0;ii<N;ii++){
    cin >> h[ii];
  }
  int dp[N];
  for(int ii=0;ii<N;ii++){
    dp[ii]=INF;
  }
  dp[0]=0;
  for(int ii=0;ii<N;ii++){//🐸は戻らない。
    for(int jj=1;jj<=K;jj++){
      if(ii+jj<N){
	dp[ii+jj]=min(dp[ii+jj],dp[ii]+abs(h[ii+jj]-h[ii]));
      }
    }
  }
  cout << dp[N-1] << endl;
}


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

#define int long long

signed main() {
    int x, y;
    cin >> x >> y;
    int c, ans=LONG_MAX;
    for(int i=0; i<4; ++i) {
        if(i==0) c=0;
        else if(i==3) c=2;
        else c=1;
        if(y>=x) ans = min(ans, y-x+c);
        x = -x;
        if(i==1)y=-y;;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] H = new int[N+1];
    boolean[] notGoodH = new boolean[N+1];
    for (int i = 1; i <= N; i++) H[i] = sc.nextInt();
    for (int i = 0; i < M; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      if (H[a] >= H[b]) notGoodH[b] = true;
      if (H[a] <= H[b]) notGoodH[a] = true;
      //System.out.println(Arrays.toString(notGoodH));
    }
    int ans = -1;
    for (boolean n : notGoodH) if (!n) ans++;
    System.out.println(ans);
  }
}

Measured memory_bytes: 49692
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
const int N = 5e3 + 5, mod = 1e9 + 7, b = 31, b2 = 37;
int pw[N], inv[N], pw2[N], inv2[N], pref[N], pref2[N];
int mul(int a, int b)
{
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return (1ll * a * b) % mod;
}
int add(int a, int b)
{
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return (a + b) % mod;
}
int fastpow(int base, int power)
{
    if(!power)
        return 1;
    int ret = fastpow(base, power / 2);
    ret = mul(ret, ret);
    if(power & 1)
        ret = mul(ret, base);
    return ret;
}
void pre()
{
    pw[0] = inv[0] = pw2[0] = inv2[0] =1;
    int mul_inv = fastpow(b, mod - 2);
    int mul_inv2 = fastpow(b2, mod - 2);
    for(int i = 1; i < N; i++)
    {
        pw[i] = mul(pw[i - 1], b), inv[i] = mul(inv[i - 1], mul_inv);
        pw2[i] = mul(pw2[i - 1], b2), inv2[i] = mul(inv2[i - 1], mul_inv2);
    }
}
pair<int, int>get_hash(int l, int r)
{
    pair<int, int>ans;
    ans.F = pref[r] - (l ? pref[l - 1] : 0);
    ans.S = pref2[r] - (l ? pref2[l - 1] : 0);
    ans.F = mul(ans.F, inv[l]);
    ans.S = mul(ans.S, inv2[l]);
    return ans;
}
struct hash_pair
{
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    pre();
    string s;
    int n, ans = 0;
    cin >> n >> s;
    for(int i = 0;i < n;++i)
    {
        pref[i] = pref2[i] = 0;
        if(i)   pref[i] = pref[i - 1], pref2[i] = pref2[i - 1];
        pref[i] = add(pref[i], mul(s[i] - 'a' + 1, pw[i]));
        pref2[i] = add(pref2[i], mul(s[i] - 'a' + 1, pw2[i]));
    }
    for(int i = 0;i < n;++i)
    {
        unordered_map<pair<int, int>, pair<int, int>, hash_pair>mp;
        for(int j = 0;j + i < n;++j)
        {
            pair<int, int> hsh = get_hash(j, j + i);
            if(mp.find(hsh) == mp.end())
                mp[hsh] = {j, j + i};
            else if(j > mp[hsh].S)
                ans = i + 1;
        }
    }
    cout << ans;
    return 0;
}


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

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

using ll = long long;
using ull = unsigned long long;

int main() {
  int n;
  int s[13], h[13], c[13], d[13];
  rep(i, 13) s[i] = 0, h[i] = 0, c[i] = 0, d[i] = 0;
  cin >> n;
  rep(i, n) {
    char x;
    int y;
    cin >> x >> y;
    if (x == 'S') s[y -1] = 1;
    if (x == 'H') h[y -1] = 1;
    if (x == 'C') c[y -1] = 1;
    if (x == 'D') d[y -1] = 1;
  }
  rep(i, 13) if (s[i] == 0) cout << 'S' << ' ' << i + 1 << endl;
  rep(i, 13) if (h[i] == 0) cout << 'H' << ' ' << i + 1 << endl;
  rep(i, 13) if (c[i] == 0) cout << 'C' << ' ' << i + 1 << endl;
  rep(i, 13) if (d[i] == 0) cout << 'D' << ' ' << i + 1 << endl;
  return 0;
}



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

using namespace std;
using ll = long long;

int main()
{
    int r, g, b, k, c = 0;
    cin >> r >> g >> b >> k;
    while (g <= r)
    {
        g *= 2;
        c++;
    }
    while (b <= g)
    {
        b *= 2;
        c++;
    }
    if (c <= k)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


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

int main()
{
    long long n, a, b;
    cin >> n >> a >> b;
    long long t, s;
    t = n / (a + b);
    if (n - (a + b) * t > a)
    {
        s = a;
    }
    else
    {
        s = n - (a + b) * t;
    }
    cout << a * t + s << endl;
}

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

int main(){
  int N;
  long long X=0, su_sum=0, ans = 1000000000000000000LL;
  cin >> N;
  vector<long long> a(N);

  //入力を受け取る＋カードの総和Xの計算
  for (int i=0; i<N; i++){
    cin >> a[i];
    X += a[i];
  }

  //su_sum(xのこと)をi=0 ~ Nまで計算し、ansより小さければ更新
  for (int i=0; i<N-1; i++){
    su_sum += a[i];
    ans = min(ans, abs(X - 2*su_sum));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
# 全てグーを出すのは明らかに合法手。
# そこから任意の位置をパーに変えると
# 引き分け→勝ち：スコアが1増える。
# 負け→引き分け：スコアが1増える。
# これは位置に依存しない。したがって、パーの回数を最大にするのが最高スコアになる。
# パーの回数を最大にするように適当に決めつけ・決め打ちして答えにする
s = input()
score = 0
for i in range(len(s)):
	if i % 2 == 0:
		# グーを出します
		if s[i] == "p":
			score -= 1
	else:
		# パーを出します
		if s[i] == "g":
			score += 1

print(score)


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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  
  int K, b;
  string S;
  cin >> K >> S;
  b = S.size();
  if (K >= b) {
    cout << S << endl;
  }
  else {
    vector<char> a(K);
    for (int i = 0; i < K; i++) {
      a.at(i) = S.at(i);
    }
    for (int i = 0; i < K; i++) {
      cout << a.at(i);
    }
    cout << "..." << endl;
  }
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int N, M, ans;
  ans = 0;
  cin >> N >> M;
  int H[N+10] = {0};
  int A[M+10] = {0};
  int B[M+10] = {0};
  int Num[N+10] = {0};
  for (int i = 1; i <= N; ++i) {
    cin >> H[i];
  }
  /*
  for (int i = 0; i < M; ++i) {
    cin >> A[i] >> B[i];
  }*/
  for (int i = 0; i < M; ++i) {
    cin >> A[i] >> B[i];
    int tmpA = A[i];
    int tmpB = B[i];
    if (Num[tmpA] == 0) {
      // ++ans;
      if (H[tmpA] < H[tmpB]) {
        if (Num[tmpB] != 2) {
          Num[tmpB] = 1;
        }
        Num[tmpA] = 2;
      }
      else if (H[tmpA] > H[tmpB]) {
        Num[tmpA] = 1;
        Num[tmpB] = 2;
      } else {
        Num[tmpA] = 2;
        Num[tmpB] = 2;
      }
    }
    else if (Num[tmpA] == 1) {
      if (H[tmpA] < H[tmpB]) {
        // --ans;
        Num[tmpA] = 2;
      }
      else if (H[tmpA] > H[tmpB]) {
        Num[tmpB] = 2;
      }
      else if (H[tmpA] == H[tmpB]) {
        Num[tmpA] = Num[tmpB] = 2;
      }
    }
    else if (Num[tmpA] == 2) {
      if (H[tmpA] >= H[tmpB]) {
        Num[tmpB] = 2;
      }
    }
    /*
    else if (Num[tmpB] == 1) {
      if (H[tmpA] > H[tmpB]) {
        // --ans;
        Num[tmpB] = 2;
      }
    }*/
  }
  for (int i = 1; i <= N; ++i) {
    // printf("%d\n", Num[i]);
    if (Num[i] == 0 || Num[i] == 1) {
      ++ans;
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 5324
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vi A(N),B(N);
  rep(i,0,N) cin>>A[i]>>B[i];
  int ans=0;
  vi C,D;
  rep(i,0,N){
    if(A[i]<B[i]) ans+=A[i];
    else if(A[i]>B[i]){
      ans+=A[i]-B[i];
      C.pb(B[i]);
    }
    else D.pb(A[i]);
  }
  sort(ALL(C),greater<int>());
  rep(i,0,C.size()-1) ans+=C[i];
  if(D.size()!=N){
    rep(i,0,D.size()) ans+=D[i];
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 896
N,M,C = map(int,input().split())
B=[int(x) for x in input().split()]

A=dict()
for i in range(1,N+1):
    A[i]=[int(x) for x in input().split()]

count=0
for i in range(1,N+1):
    work=0
    for x in range(len(B)):
        work+=A[i][x]*B[x]
    if work+C > 0:
        count+=1 

print(count)

Measured memory_bytes: 3064