akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    Map<String, Integer> map = new HashMap<>();
    
    char[] chars = new char[10];
    StringBuilder sb;
    long sum = 0;
    for (int i = 0; i < N; i++) {
      sc.next().getChars(0, 10, chars, 0);
      Arrays.sort(chars);
      sb = new StringBuilder();
      for (int j = 0; j < 10; j++) {
        sb.append(chars[j]);
      }
      
      String key = sb.toString();
      Integer val = map.get(key);
      if (val == null) {
        val = 1;
      } else {
        val++;
      }
      map.put(key, val);
      sum += val - 1;
    }
    
    System.out.println(sum);
  }
}

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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n, m;

const int mod = 2019;

void read() {
  cin >> n >> m;
  if (m / 2019 * 2019 >= n) {
    cout << "0\n";
    exit (0);
  }
  n %= 2019;
  m %= 2019;
}

void solve() {
  int mn = 1e9;
  for(int i = n; i < m; ++i)
    for(int j = i + 1; j <= m; ++j)
      mn = min (mn, (i * j) % mod);
  cout << mn << "\n";
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  //cin >> t;           // PLEASE REMOVE IT IF NEEDED
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
#define MAXN 300100
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

struct res{
string nome;
int nota;
int id;	
	
};

int cmp(res a,res b){
	if(a.nome==b.nome)return a.nota>b.nota;
	return a.nome<b.nome;
}


int32_t main(){
	int n;
	cin>>n;
	vector<res> A(n);
	for(int i=0;i<n;i++){
		cin>>A[i].nome>>A[i].nota;
		A[i].id=i+1;
	}
	sort(A.begin(),A.end(),cmp);
	for(int i=0;i<n;i++){
		cout<<A[i].id<<endl;
	}
	
}

Measured memory_bytes: 256
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
    int n,ans;cin>>n;
    ans=1000-n%1000;
    if(ans==1000)ans=0;
    cout<<ans<<"\n";
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//If wrong on pretest 2 means logically wrong


/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


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

int main() {
    vector<pair<int, int> > xy;
    for (int i = 0; ;i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        if (x == 0 && y == 0) {
            break;
        }
        if (x > y) {
            swap(x, y);
        }
        pair<int, int> p(x, y);
        xy.push_back(p);
    }
    for (int i = 0; i < xy.size(); i++) {
        printf("%d %d\n", xy.at(i).first, xy.at(i).second);
    }
}


Measured memory_bytes: 3240
#include<stdio.h>
int main(void)
{
	int h,w,i,j;
	do{
	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		{
			if(h!=0 && w!=0)printf("#");
		}
		if(h!=0 && w!=0)printf("\n");
	}
	if(h!=0 && w!=0)printf("\n");
	}while(h!=0 && w!=0);
return 0;
}

Measured memory_bytes: 572
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long m = sc.NextLong();
        long d = sc.NextLong();

        long answer = 0;
        for (int i = 10; i <= d; i++)
        {
            long d1 = i % 10;
            long d10 = i / 10;
            if (d1 >= 2 && d10 >= 2 && d10 * d1 <= m)
            {
                answer++;
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27520
#include <stdio.h>
#include <string.h>

const int maxN = 2e5 + 5;

int main() {
    char s[maxN], t[maxN];
    scanf("%s %s", s, t);
    int ans = 0;
    for (int i = 0; i < strlen(s); i++) {
        if (s[i] != t[i]) ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 2120
#include <iostream>

using namespace std;


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

  int ans{};
  for (auto i = 105; i <= N; i +=2) {
    int n{};
    for (auto j = 1; j <= i; ++j) {
      if (i%j==0) ++n;
    }
    if (n==8) ++ans;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define INF 1e9

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

    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int a = x2 - x1;
    int b = y2 - y1;

    int x3 = x2 - b;
    int y3 = y2 + a;

    int x4 = x1 - b;
    int y4 = y1 + a;

    printf("%d %d %d %d", x3,y3,x4,y4);
}

Measured memory_bytes: 256
import sys
W = []
N = [1,2,4,8,16,32,64,128,256,512]
for line in sys.stdin:
    W.append(int(line))
for x in W:
    ans = []
    for y in N:
        if x & y:
            ans.append(str(y))
    print(' '.join(ans))

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

template <typename T, typename F>
class SegTree{
  int n; T uni; F f;
  vector<T> dat;
public:
  SegTree(int _n, F f, T uni) : f(f), uni(uni) {
    n = 1;
    while(n < _n) n *= 2;
    dat = vector<T>(2*n,uni);
  }
  void set(int k, const T x) {
    dat[k+n] = x;
  }
  void build() {
    for(int i = n-1; i >= 0; i--) {
      dat[i] = f(dat[2*i],dat[2*i+1]);
    }
  }
  void update(int k, T x) {
    k += n;
    dat[k] += x;
    while(k >>= 1){
      dat[k] = f(dat[2*k],dat[2*k+1]);
    }
  }
  T query(int a, int b) {
    T l = uni, r = uni;
    for(a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if(a & 1) l = f(l,dat[a++]);
      if(b & 1) r = f(dat[--b],r);
    }
    return f(l,r);
  }
};

struct HLD {
  int n;
  vector<vector<ll>>& g;
  vector<ll> vid, head, sz, par;

  HLD(vector<vector<ll>>& g): g(g), n(g.size()), vid(n,-1), head(n), sz(n,1), par(n) {}

  void dfs1(ll v, ll p) {
    if(g[v].size() && g[v][0] == p) swap(g[v][0],g[v].back());
    for(auto &to : g[v]) {
      if(to == p) continue;
      dfs1(to, v);
      sz[v] += sz[to];
      if(sz[to] > sz[g[v][0]]) swap(to,g[v][0]);
    }
  }

  void dfs2(ll v, ll p, ll &k) {
    par[v] = p; vid[v] = k++;
    for(auto to : g[v]) {
      if(to == p) continue;
      head[to] = (to == g[v][0] ? head[v] : to);
      dfs2(to,v,k);
    }
  }

  void build(vector<ll> rs = vector<ll>(1,0)) {
    ll k = 0;
    for(ll r : rs) {
      dfs1(r,-1);
      head[r] = r;
      dfs2(r,-1,k);
    }
  }

  void for_each_vertex(ll u, ll v, const function<void(ll,ll)>& f) {
    while(true) {
      if(vid[u] > vid[v]) swap(u,v);
      f(max(vid[head[v]],vid[u]),vid[v]);
      if(head[u] != head[v]) v = par[head[v]];
      else break;
    }
  }

  void for_each_edge(ll u, ll v, const function<void(ll,ll)>& f) {
    while(true) {
      if(vid[u] > vid[v]) swap(u,v);
      if(head[u] != head[v]) {
        f(vid[head[v]],vid[v]); 
        v = par[head[v]];
      } else {
        if(u != v) f(vid[u]+1,vid[v]);
        break;
      }
    }
  }

  ll lca(ll u, ll v) {
    while(true) {
      if(vid[u] > vid[v]) swap(u,v);
      if(head[u] == head[v]) return u;
      v = par[head[v]];
    }
  }
};

int main() {
  int n;
  cin >> n;
  vector<vector<ll>> g(n);
  rep(i,n) {
    int k;
    cin >> k;
    int c;
    rep(j,k) {
      cin >> c;
      g[i].push_back(c);
      g[c].push_back(i);
    }
  }
  HLD hld(g);
  hld.build();
  auto f = [](ll a, ll b){return a + b;};
  SegTree<ll,decltype(f)> st(n,f,0);
  st.build();
  int q;
  cin >> q;
  vector<ll> ans; 
  rep(i,q) {
    int type;
    cin >> type;
    if(type == 0) {
      ll v, w;
      cin >> v >> w;
      st.update(hld.vid[v],w);
    } else {
      int v;
      cin >> v;
      ll val = 0;
      hld.for_each_vertex(0,v,[&](int l, int r){val += st.query(l,r+1);});
      ans.push_back(val);
    }
  }
  for(ll x : ans) cout << x << endl; 
}


Measured memory_bytes: 20008
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

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

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:usize = read();
    let h:Vec<u32> = (0..n).map(|_| read()).collect();

    let mut mx:u32 = 0;
    let mut ans:u32 = 0;
    for i in 0..n {
        if h[i] >= mx {ans+=1}
        mx = max(mx, h[i]);
    }

    println!("{}", ans);
    
}


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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            var c = int.Parse(Console.ReadLine());
            var d = int.Parse(Console.ReadLine());
            var e = int.Parse(Console.ReadLine());

            var x = a + b + c + d + e;
            var list = new List<int>() { a, b, c, d, e };

            var list1 = new List<int>();
            foreach (var item in list)
            {
                var s = item % 10;
                if (s != 0)
                {
                    var l = 10 - s;
                    list1.Add(l);
                }
            }
            list1.Sort();
            var an = 0;
            for (int i =0; i < list1.Count-1; i++)
            {
                an += list1[i];
            }
            Console.WriteLine(an+x);
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <numeric>

using namespace std;

typedef long long int ll;
typedef long int li;

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

int main(){
    ll ans=0;
    ll n,a[5];
    cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    ll ti = 1000000000000007;
    for(int i=0;i<5;i++)ti = min(a[i],ti);
    ll x;
      if(n%ti==0)x=n/ti-1;
  else x=n/ti;
    ans = 5 + x;
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}


/*
1 1 1 1  1  1  1  1    7C0
1 2 3 4  5  6  7  8    8c1
1 3 6 10 15 21 28 36   9C2
    6 16 31 52 80 116  10C3
    6 22 53 105185301
  

*/


vector<ll> fac = {1}; 
vector<ll> ifac = {1}; 

ll mpow(ll x, ll n, ll mod){ 
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}

void init(ll n, ll mod) {
    for (ll i = 0; i < n; i++) {
        fac.push_back(fac[i] * (i+1) % mod);
        ifac.push_back(ifac[i] * mpow(i+1,mod-2,mod) % mod);
    }
}

ll cmb(ll n, ll r, ll mod){ //aCbをmod計算
    if (n == 0 && r == 0) return 1;
    if (n < r || n < 0) return 0;
    ll tmp = ifac[n-r]* ifac[r] % mod;
    return tmp * fac[n] % mod;
}

int main() {
    ll H, W, A, B; cin >> H >> W >> A >> B;
    ll D = 1e9+7;
    init(H+W+1,D);
    ll res = 0;
    ll tmp = 0;
    for (ll x = B+1; x <= W; x++) {
        //cout << (cmb(H-A-1+x-1,H-A-1,D)-tmp) * cmb(A+W-x,A,D) << endl; 
        //res = (res + cmb(H-A-1+x-1,H-A-1,D) * cmb(A+W-x,A,D)) % D;
        res = (res + ((cmb(H-A-1+x-1,H-A-1,D)-tmp) * cmb(A+W-x,A,D))%D + D) % D;
        tmp = cmb(H-A-1+x-1,H-A-1,D)%D ;
    }
    cout << res % D << endl;




}


Measured memory_bytes: 3564
#include<stdio.h>
#include <set>
#include <stdio.h>
using namespace std;
int main()
{
    int n,key;
    scanf("%d",&n);

    set<int> st;
    while(n--)
    {
        scanf("%d",&key);
        if(st.count(key)==0)
        {
            st.insert(key);
        } else
            {
                st.erase(key);
            }
    }
    printf("%d",st.size());
}


Measured memory_bytes: 4992
<?php
// Your code here!
fscanf(STDIN,"%d %d %d %d %d",$w,$h,$x,$y,$r);

if($x-$r < 0 || $x+$r > $w || $y-$r < 0 || $y+$r > $h){
    echo "No";
}elseif($x-$r>=0 && $x+$r<=$w && $y-$r>=0 && $y+$r<=$h){
    echo "Yes";
}else{
    echo "No";
}
?>



Measured memory_bytes: 9192
i = list(map(int, input().split()))
j = list(map(int, input().split()))
a = 0
for cc in j:
  if 1 <= cc and cc <= 10**4:
    a += 1
    
if i[1] == a:
  if 1 <= i[0] and i[0] <= 10**6 and 1 <= i[1] and i[1] <= 10**4:
    if i[0] >= sum(j):
      print(i[0] - sum(j))
    else:
      print('-1')

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
template<typename T>
map<T,ll> compress(vector<T> v){
  auto t=v;
  sort(ALL(t));
  t.erase(unique(ALL(t)),t.end());
  map<T, ll> ret;
  for(ll i=0;i<(ll)t.size();i++)
    ret[t[i]]=i;
  return ret;
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll>h(n);
  rep(i,0,n)cin>>h[i];
  h.PB(0);
  auto mp=compress(h);
  vector<ll>idx;
  for(auto z:mp)idx.PB(z.fi);
  auto dp=make_v(n+1,k+1,mp.size(),INF);
  dp[0][0][0]=0;
  rep(i,0,n){
    rep(j,0,k+1){
      rep(o,0,mp.size()){
        chmin(dp[i+1][j][mp[h[i]]],dp[i][j][o]+max(0LL,h[i]-idx[o]));
        if(j!=k){
          chmin(dp[i+1][j+1][o],dp[i][j][o]);
          chmin(dp[i+1][j+1][0],dp[i][j][o]);
        }
      }
    }
    //cout<<i<<endl;
    //debug(dp[i+1],k+1,mp.size());
  }
  res=INF;
  rep(j,0,k+1)rep(o,0,mp.size())chmin(res,dp[n][j][o]);
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 216960
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
	long long P, C[500000];

	int N, Q;

	scanf("%d", &N);

	scanf("%lld", &P);

	scanf("%d", &Q);

	long long zenbugaishoku = 0;

	for (int i = 0; i < N; i++)
	{
		scanf("%lld", &C[i]);

		zenbugaishoku += C[i];

		C[i] = C[i] - (Q - i) * P;
	}

	long long *E = C + N;

	sort(C, E);

	long long Answer = zenbugaishoku;

	long long sum = zenbugaishoku;

	long long V = 2 * P;

	for (int i = 0; i < N; i++)
	{
		sum += V * i - C[i];

		Answer = max(sum, Answer);
	}

	printf("%lld\n", Answer);

	return 0;
}

Measured memory_bytes: 6648
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
int main() {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "rt", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    fast
    string s;cin>>s;
    int a=0, b=0;
    for(int i=0; i<3; i++){
    	if(s[i]=='A'){
    		a++;
    	}else b++;
    }
    if(a==3 || b==3) cout<<"No";
    else cout<<"Yes";

#ifndef ONLINE_JUDGE
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}

Measured memory_bytes: 256
#if 0

#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int L[1000+10][1000+10];
string S1, S2;

int main() {
  cin >> S1 >> S2;
  for (int j = 0; j < 1000+10; j++) {
    L[0][j] = j; L[j][0] = j;
  }
  for (int x = 1; x <= S1.length(); x++) {
    for (int y = 1; y <= S2.length(); y++) {
      if (S1[x-1] == S2[y-1])
        L[x][y] = L[x-1][y-1];
      else {
        int A[3] = {L[x-1][y], L[x][y-1], L[x-1][y-1]};
        L[x][y] = *min_element(A, A+3) + 1;
      }
    }
  }
  cout << L[S1.length()][S2.length()] << endl;
}



Measured memory_bytes: 7200
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;





signed main() {
    ll n;
    map <ll, ll> mp;
    rep(i, 3) {
        
        cin >> n;
        mp[n] ++;
    }
    
    if (mp[5] == 2 && mp[7] == 1) {
        mes("YES");
    } else mes("NO");
    
    
    
    
    
    
    
    
}

Measured memory_bytes: 3556
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

  int n,q;
  scanf("%d",&n);

  int a[n];
  ll sum = 0;;
  int num[100001] = {0};
  for(int i = 0; i < n; ++i){
    scanf("%d",&a[i]);
    sum += a[i];
    num[a[i]] ++;
  }
  scanf("%d",&q);

  int b,c;
  for(int i = 0; i < q; ++i){
    scanf("%d%d",&b,&c);
    if(num[b] != 0) sum = sum + ((c-b) * num[b]);
    num[c] += num[b];
    num[b] = 0;
    printf("%lld\n",sum);
  }

  return 0;
}


Measured memory_bytes: 2508
s = input()
h = int(s[:2])
l = int(s[2:])
def mmok(i):
  return 1 <= i <= 12
if mmok(h):
  if mmok(l):
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if mmok(l):
    print('YYMM')
  else:
    print('NA')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n;
    string s;
    cin>>n>>s;
    vector<int> p(2e5+50,0);
    for(int i=1; i<2e5+50; i++){
        int a=i;
        int cnt=0;
        while(a){
            cnt++;
            a%=__builtin_popcount(a);
        }
        p[i]=cnt;
    }
    int kosuu=0;
    rep(i,n){
        if(s[i]=='1') kosuu++;
    }
    if(kosuu>1){
        vector<int> qp(n), qm(n);
        qp[n-1]=1;
        qm[n-1]=1;
        if(kosuu==2) qm[n-1]=0;
        for(int i=n-2; i>=0; i--){
            qp[i]=qp[i+1]*2;
            qp[i]%=(kosuu+1);
            qm[i]=qm[i+1]*2;
            qm[i]%=(kosuu-1);
        }
        int karisump=0, karisumm=0;
        rep(i,n){
            if(s[i]=='1'){
                karisump+=qp[i];
                karisump%=(kosuu+1);
                karisumm+=qm[i];
                karisumm%=(kosuu-1);
            }
        }
        rep(i,n){
            int kari;
            if(s[i]=='0'){
                kari=karisump;
                kari+=qp[i];
                kari%=(kosuu+1);
            }
            else{
                kari=karisumm;
                kari-=qm[i];
                if(kari<0){
                    kari+=(kosuu-1);
                }
                kari%=(kosuu-1);
            }
            cout<<p[kari]+1<<endl;
        }
    }
    else if(kosuu==1){
        rep(i,n){
            if(s[i]=='1') cout<<0<<endl;
            else{
                if(i==n-1 || s[n-1]=='1') cout<<2<<endl;
                else cout<<1<<endl;
            }
        }
    }
    else{
        rep(i,n){
            cout<<1<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6000
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

int main() {
    cin>>N>>K;
    vec a(N);
    rep(i,N) cin>>a[i];
    sort(ALL(a));
    ll sum = 0;
    rep(i,K) sum += a[i];
    cout<<sum<<endl;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] != t[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3652
#coding:utf-8
ans=[]
while True:
    curAns=[]
    n=input()
    if n ==0:
        break
    for i in xrange(n):
        lst=map(int,raw_input().split())
        lst.append(sum(lst))
        curAns.append(lst)
    lLst=[]                             #最後のリスト
    for i in xrange(n+1):               #横方向探索
        verSum=0
        for j in xrange(n):             #縦方向探索
            verSum+=curAns[j][i]
        lLst.append(verSum)
    curAns.append(lLst)
    relAns=[]
    for i in curAns:
        tmpLst=map(str,i)
        nLst=[]
        for j in tmpLst:
            nLst.append(j.rjust(5))
        ansStr=''.join(nLst)
        relAns.append(ansStr)
    ans.append(relAns)

for i in ans:
    for j in i:
        print j

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

int main(){
  string S, T;
  cin >> S;
  cin >> T;
  int i=0;
  if(S[0] == T[0]){
  	i++;
  }
  if(S[1] == T[1]){
  	i++;
  }
  if(S[2] == T[2]){
  	i++;
  }
  cout << i;
  return 0;
}

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

using namespace std;
typedef long long LL;

const int MAXN = 1E5 + 5;
int n, a[MAXN], sum, f[31], cnt;

template <class T>
void read(T& x, T f = 1, char ch = getchar()) {
    x = 0;
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

int main() {
    read(n);
    for (int i = 1; i <= n; i++) {
        read(a[i]);
        sum ^= a[i];
        a[i] ^= a[i] - 1;
        for (int j = 30; ~j; j--)
            if ((a[i] >> j) & 1) {
                f[j] = 1;
                break;
            }
    }
    for (int i = 30; ~i; i--)
        if ((sum >> i) & 1)
            if (f[i]) sum ^= (1 << (i + 1)) - 1, cnt++;
    printf("%d\n", sum ? -1 : cnt);
    return 0;
}


Measured memory_bytes: 4112
import java.util.*

fun main(args: Array<String>) {
    val (n, q) = readLine()!!.split(' ').map { it.toInt() }

    val g = Array(n + 1) { mutableListOf<Int>() }
    repeat(n - 1) {
        val (a, b) = readLine()!!.split(' ').map { it.toInt() }
        g[a].add(b)
        g[b].add(a)
    }

    val cnt = IntArray(n + 1)
    repeat(q) {
        val (p, x) = readLine()!!.split(' ').map { it.toInt() }
        cnt[p] += x
    }

    val visited = BooleanArray(n + 1) { false }
    val stack = ArrayDeque<Int>()
    stack.addLast(1)

    while (stack.isNotEmpty()) {
        val v = stack.removeLast()
        visited[v] = true

        for (u in g[v]) {
            if (visited[u]) continue
            cnt[u] = cnt[v] + cnt[u]
            stack.addLast(u)
        }
    }

    println(cnt.slice(1..n).joinToString(" "))
}


Measured memory_bytes: 152028
s = io.read()
if s == "ooo" then
  print(1000)
elseif s == "xoo" then
  print(900)
elseif s == "oxo" then
  print(900)
elseif s == "oox" then
  print(900)
elseif s == "xxo" then
  print(800)
elseif s == "oxx" then
  print(800)
elseif s == "xox" then
  print(800)
else
  print(700)
end

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

int main() { 
    int n;
    string s;
    cin >> n;
    map<string, int> mp;
    for(int i = 0; i < n; ++i) {
        cin >> s;
        mp[s]++;
    }
    int c_max = 0;
    auto begin = mp.begin(), end = mp.end();
    for(auto iter = begin; iter != end; iter++) {
        c_max = max(iter->second, c_max);
    }
    begin = mp.begin(), end = mp.end();
    for(auto iter = begin; iter != end; iter++) {
        if(iter->second == c_max) {
            cout << iter->first << '\n';
        }
    }


    return 0;
}


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

int main() {
	int N,b,i,j,d,e;
	cin >> N;
	b=2*N;
	int a[b];
	int c;
	for(i=0;i<b;i++){
		cin >> a[i];
	}
	sort(a,a+b);
	j=0;
	c=0;
	while(j<b){
		if(a[j]<=a[j+1]){
			c=c+a[j];
		}else if(a[j]>=a[j+1]){
			c=c+a[j+1];
		}
		j=j+2;
		
	}
	
	
	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i+1;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}

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


typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
    /* Credits: Thomas Draper */
    if ((first == last) || (first == k) || (last == k))
        return false;
    Iterator itr1 = first;
    Iterator itr2 = last;
    ++itr1;
    if (last == itr1)
        return false;
    itr1 = last;
    --itr1;
    itr1 = k;
    --itr2;
    while (first != itr1)
    {
        if (*--itr1 < *itr2)
        {
            Iterator j = k;
            while (!(*itr1 < *j)) ++j;
            iter_swap(itr1,j);
            ++itr1;
            ++j;
            itr2 = k;
            rotate(itr1,j,last);
            while (last != j)
            {
                ++j;
                ++itr2;
            }
            rotate(k,itr2,last);
            return true;
        }
    }
    rotate(first,k,last);
    return false;
}



int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  while(true){
      C-=B;
      if(A<=0){
          cout << "No" << endl;
          break;
      }else if(C<=0){
          cout << "Yes" << endl;
          break;
      }
      A-=D;
      if(A<=0){
          cout << "No" << endl;
          break;
      }else if(C<=0){
          cout << "Yes" << endl;
          break;
      }
  }

}


Measured memory_bytes: 3628
//https://atcoder.jp/contests/abc147/tasks/abc147_c
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N; cin>>N;    
    vector<unordered_map<ll,ll>> tbl(N+1);
    FOR(i,1,N+1){
        ll A; cin>>A;
        auto&& t=tbl.at(i);
        REP(j,A){
            ll x,y; cin>>x>>y;
            t[x]=y;
        }
    }
    ll mx=pow(2,N);
    ll ans=0;
    auto count_bit = [&](ll flag) {
        ll ret=0;
        REP(i,N){
            if(flag&(1<<i)) ++ret;
        }
        dump(flag,ret);
        return ret;
    };
    auto check_func = [&](ll flag)->ll{
        REP(i,N){
            if (flag & (1<<i)){ //本当は確認
                const auto& t=tbl.at(i+1);
                for(auto& m:t){
                    ll tmp=(1<<m.first-1);
                    if((bool)(flag&(tmp)) != (bool)m.second) return 0;
                }
            }
        }
        return count_bit(flag);
    };
    dump(check_func(7));
    dump(check_func(3));
    FOR(i,1,mx){
        ans=max(check_func(i),ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int N;
  cin>>N;
  cout<<(10000-N)%1000<<endl;
return 0;}

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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;

template< class T >
struct CumulativeSum
{
  vector< T > data;

  CumulativeSum(int sz) : data(sz, 0) {};

  void add(int k, int x)
  {
    data[k] += x;
  }

  void build()
  {
    for(int i = 1; i < data.size(); i++) {
      data[i] += data[i - 1];
    }
  }

  T query(int k)
  {
    if(k < 0) return (0);
    return (data[min(k, (int) data.size() - 1)]);
  }
};

vector< bool > get_prime(int n)
{
  vector< bool > prime(n + 1, true);

  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;

  for(int i = 2; i * i <= n; i++) {
    if(prime[i]) {
      for(int j = i + i; j <= n; j += i) prime[j] = false;
    }
  }

  return (prime);
}


int main()
{
  int Q;
  cin >> Q;
  auto p = get_prime(100001);
  CumulativeSum< int > s(100001);
  for(int i = 1; i < 100001; i += 2) {
    if(p[i] && p[(i + 1) / 2]) {
      s.add(i, 1);
    }
  }
  s.build();
  while(Q--) {
    int l, r;
    cin >> l >> r;
    cout << s.query(r) - s.query(l - 1) << endl;

  }

}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

//GCD(最大公約数)
ll gcd(ll a, ll b) {
   return b ? gcd(b, a % b) : a;
}

//LCM(最小公倍数)
ll lcm(ll a, ll b) {
   return a / gcd(a, b) * b;  //オーバーフローする場合など 必要に応じて
}

ll f(ll x) {
    ll res = 0;
    while(x % 2 == 0) {
        x /= 2;
        res++;
    }
    return res;
}

int main() {
    ll n, m;
    cin >> n >> m;
    vll a(n);
    rep(i, n) {
        cin >> a[i];
    }

    rep(i, n) {
        if(a[i] % 2 == 1) {
            cout << 0 << endl;
            return 0;
        }
        a[i] /= 2;
    }

    ll t = f(a[0]);
    rep(i, n) {
        if(t != f(a[i])) {
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= t;
    }
    m >>= t;

    ll l = 1;
    rep(i, n) {
        l = lcm(l, a[i]);
        if(l > m) {
            cout << 0 << endl;
            return 0;
        }
    }

    m /= l;
    ll ans = (m + 1) / 2;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n, intervel = list(map(int, input().split()))
    ts = list(map(int, input().split()))
    ts += [ts[-1] + intervel]

    total_t = 0
    previous_t = ts[0]

    # See:
    # https://atcoder.jp/img/arc073/editorial.pdf
    for i in range(1, n + 1):
        current_t = ts[i]
        total_t += min(current_t - previous_t, intervel)
        previous_t = current_t

    print(total_t)


Measured memory_bytes: 26832
N = int(input())
A = list(map(int,input().split()))

dic = {}
for i in range(N):
    data = i + 1 + A[i]
    if data in dic:
        dic[data] += 1
    else:
        dic[data] = 1
        
ans = 0
for i in range(N):
    res = i + 1 - A[i]
    if res in dic:  ans += dic[res]
print(ans)

Measured memory_bytes: 118848
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, int>;
vector<int> num;

int main()
{
    constexpr int m = 1e5 + 1;
    ll n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    num.assign(m, 0);
    for (int i = 0; i < n; ++i)
    {
        ++num[a[i]];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        int cnt = num[a[i]];
        if (a[i] > 0) cnt += num[a[i] - 1];
        if (a[i] < m - 1) cnt += num[a[i] + 1];
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
long N;
long ret;
int dfs(long x, int mask)
{
  if(x > N)
    return 0;
  if(mask == 7)
    ret++;
  dfs(x*10+3, mask|1);
  dfs(x*10+5, mask|2);
  dfs(x*10+7, mask|4);
}
 
int main()
{
  cin >> N;
  ret = 0;
  dfs(0,0);
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

bool dp[3500][3500];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	dp[0][0] = true;
	double milk = -1;
	int water = 0, sugar = 0;
	rep(i,f+1){
		rep(j,f+1){
			if(!dp[i][j]) continue;
			if(i+j != 0){
				double thismilk = (double)(100*j) / (double)(i+j);
				if(thismilk > milk){
					milk = thismilk;
					water = i;
					sugar = j;
				}
			}
			if(i+j+a*100 <= f) dp[i+a*100][j] = true;
			if(i+j+b*100 <= f) dp[i+b*100][j] = true;
			if(i+j+c <= f && j+c <= e*(i/100)) dp[i][j+c] = true;
			if(i+j+d <= f && j+d <= e*(i/100)) dp[i][j+d] = true;
		}
	}
	cout << water+sugar << " " << sugar << endl;
	return 0;
}


Measured memory_bytes: 8448
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let s: Vec<char> = s.trim().chars().collect();
    const MOD: u64 = 1_000_000_007;
    let mut way = 1;
    let mut ans = 0;
    for c in s {
        if c == '1' {
            ans = (3 * ans + way) % MOD;
            way = 2 * way % MOD;
        } else {
            ans = 3 * ans % MOD;
        }
    }
    ans = (ans + way) % MOD;
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 4352
def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x % y)


a = int(input())
b = list(map(int, input().split()))
c = 0
for i in range(a):
    c = g_c_d(c, b[i])
print(c)


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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 3;

int A[N][N];

int main(){
    fIO

    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> A[i][j];
        }
    }

    int n;
    cin >> n;

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

        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 3; k++) {
                if(A[j][k] == b[i]) {
                    A[j][k] = 0;
                }
            }
        }
    }

    for(int i = 0; i < 3; i++) {
        int cnt = 0;
        for(int j = 0; j < 3; j++) {
            if(A[i][j] == 0) cnt++;
        }
        if(cnt == 3) return cout << "Yes", 0;
    }

    for(int i = 0; i < 3; i++) {
        int cnt = 0;
        for(int j = 0; j < 3; j++) {
            if(A[j][i] == 0) cnt++;
        }
        if(cnt == 3) return cout << "Yes", 0;
    }

    int cnt = 0;
    for(int i = 0, j = 0; i < 3, j < 3; i++, j++) {
        if(A[i][j] == 0) cnt++;
    }

    int cnt1 = 0;
    for(int i = 0, j = 2; i < 3, j >= 0; i++, j--) {
        if(A[i][j] == 0) cnt1++;
    }
    if(cnt == 3 || cnt1 == 3) return cout << "Yes", 0;
    cout << "No";

}









Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
 
long A, B, N;
 
long f(double x) {
  return floor((A*x)/B)-A*floor(x/B);
}
 
int main() {
  cin >> A >> B >> N;
  long min = N > B-1 ? B-1 : N;
  cout << f(min) << endl;
  return 0;
}

Measured memory_bytes: 3592
package main

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

// AtCoder Functions
var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextFloat64() float64 {
	sc.Scan()
	f, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}
func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

func unshift(element int, slice []int) []int {
	slice = append(slice[:1], slice[:]...)
	slice[0] = element
	return slice
}
func spliceInsert(index int, element int, slice []int) []int {
	slice = append(slice[:index+1], slice[index:]...)
	slice[index] = element
	return slice
}
func spliceRemove(index int, slice []int) []int {
	slice = append(slice[:index], slice[index+1:]...)
	return slice
}
func stringToSlice(str string) []string {
	return strings.Split(str, "")
}

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()

	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = nextInt()
	}
	B := make([]int, N)
	for i := 0; i < N; i++ {
		B[i] = nextInt()
	}
	C := make([]int, N-1)
	for i := 0; i < N-1; i++ {
		C[i] = nextInt()
	}

	ret := 0
	prev := 100
	for i := 0; i < N; i++ {
		ret += B[A[i]-1]
		if A[i]-1 == prev {
			ret += C[A[i]-2]
		}
		prev = A[i]
	}

	fmt.Println(ret)
}


Measured memory_bytes: 640