akhauriyash/Code-Regression huggingface dataset:
N = input()

S=['SUN','MON','TUE','WED','THU','FRI','SAT']

if N == 'SUN':
  print(7)
elif N == 'MON':
  print(6)
elif N == 'TUE':
  print(5)
elif N == 'WED':
  print(4)
elif N == 'THU':
  print(3)
elif N == 'FRI':
  print(2)
elif N == 'SAT':
  print(1)

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using Graph = vector<vector<int>>;

int main()
{
    lint n,m;cin >> n>>m;
    vector<lint> a(m),b(m);
    REP(i, m) { cin >> a[i] >> b[i]; }
    lint V = n;
    vector<vector<int>> vec(n);
    //vector<queue<int>> vec(n); 
    //REP(i,n)vec.push_back(queue<int>()); // add a queue
    REP(i,m){
        vec[a[i]-1].push_back(b[i]-1);
        vec[b[i] - 1].push_back(a[i] - 1);
    }
    queue<int> q;
    q.push(0);
    vector<lint> used(n),dist(n),pre(n);
   REP(i,n){
        lint now = q.front();
        q.pop();
        REP(i,SZ(vec[now])){
            int x = vec[now][i];
            if (used[x] == 0)
            {
                q.push(x);
                used[x] = 1;
                dist[x] = i + 1;
                pre[x] = now;
            }
        }
        if(q.empty()){
            break;
        }
    }

    cout << "Yes" << "\n";
    FOR(i,1, n)
    {
        cout << pre[i] + 1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 15204
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    }
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! chmax {
    ($x:expr, $e:expr) => {
        if $x < $e {
            $x = $e;
        }
    };
}
macro_rules! chmin {
    ($x:expr, $e:expr) => {
        if $x > $e {
            $x = $e;
        }
    };
}

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

const INF: i64 = 1 << 60;

fn main() {
    input!{
        N: usize,
        R: usize,
    }
    if N >= 10 {
        println!("{}", R);
    } else {
        println!("{}", R + 100*(10-N));
    }
}


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

typedef long long ll;
#define INF 1e9

int main()
{
	ll i,j,k,n,tab[200010];
	cin>>n;
	for (i=1;i<=n;i++)
	 cin>>tab[i];
	ll prefix[200010];
	 for (i=1;i<=n;i++)
	 {
	 	if (i==1)
	 	 prefix[i]=tab[i];
	 	else
	 	 prefix[i]=prefix[i-1]+tab[i];
	 }
	ll best=-1;
	for (i=1;i<n;i++)
	{
		ll sisa=prefix[n]-prefix[i];
		ll diff=abs(sisa-prefix[i]);
		if (best==-1)
		 best=diff;
		else
		 best=min(diff,best);
	}
	cout<<best<<"\n";
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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 gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  int n; string s; cin >> n >> s;

  rep(bit, 4){
    vector<bool> sheep(n+1,false);
    if(bit & 1) sheep[0] = true;
    if(bit & 10) sheep[1] = true;
    // sheep[0] = (bit & 1);
    // sheep[1] = (bit & 10);
    for(int i = 1; i < n; i++){
      if(s[i] == 'o' && sheep[i] || s[i] == 'x' && !sheep[i]) sheep[i+1] = sheep[i-1];
      else sheep[i+1] = !sheep[i-1];
    }
    if(sheep[0] == sheep[n] && ( (s[0] == 'o') == sheep[0] ) == (sheep[n-1] == sheep[1]) ) {
      rep(i, n) std::cout << (sheep[i] ? "S" : "W");
      return 0;
    }
  }

  std::cout << -1 << '\n';
}


Measured memory_bytes: 512
n=int(input())
L=list(map(int,input().split()))
count=0


m=min(L)
for i in range(30):
  if m%2==1:
    break
  else:
    m/=2
    count+=1


ans=[0 for i in range(n)]
for i in range(n):
  for j in range(count):
    if L[i]%2==0:
      L[i]=L[i]//2
      ans[i]+=1
    else:
      break
   
print(min(ans))

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

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

  int sum = 0;
  int NC = N;
  for (int i = 8; i >= 0; i--) {
    int a = pow(10, (i));
    int b = NC / a;
    sum += b;
    NC = NC - (a * b);
  }
  cout << (((N % sum) == 0) ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int n;
vector<vector<int>> a;
ll memo[23][1 << 23];

ll dp(int i, int bit){
    if(i == -1 && bit == 0) return memo[0][bit] = 1;
    if(i == -1) return memo[0][bit] = 0;
    if(i + 1 < __builtin_popcount(bit)) return memo[i][bit] = 0;
    if(memo[i][bit] != -1) return memo[i][bit];
    
    ll res = 0;
    for(int j = 0; j < n; j++){
        if((bit & (1 << j)) == 0) continue;
        if(!a[i][j]) continue;
        int nbit = bit ^ (1 << j);
        res += dp(i - 1, nbit);
        res %= MOD;
    }

    return memo[i][bit] = res;

}

int main(void){
    cin >> n;
    a.resize(n);
    for(int i = 0; i < n; i++){
        a[i].resize(n);
        for(int j = 0; j < n; j++){
            cin >> a[i][j];
        }
    }

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= (1 << n); j++){
            memo[i][j] = -1;
        }
    }

    cout << dp(n - 1, (1 << n) - 1) << endl;
}

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

using namespace std;
using ll = long long int;
using ull = unsigned long long int;
#define vll vector<ll>

#define FOR(i, b, e) for(int i = (b); i < (e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REV(v) reverse((v).begin(), (v).end())
#define IN(v) cin >> (v);
#define VIN(v, n) REP(i, n) cin >> v[i];
#define OUT(v) cout << (v) << endl;
#define YN(b) OUT((b) ? "YES" : "NO")
#define Yn(b) OUT((b) ? "Yes" : "No")
#define yn(b) OUT((b) ? "yes" : "no")

const ll MOD = 1000000007;

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

  char c;
  cin >> c;
  if ('A' <= c && c <= 'Z') cout << "A" << endl;
  else cout << "a" << endl;

  return 0;
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline

N, M = map(int, input().split())

adj = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    adj[a - 1].append(b - 1)
    adj[b - 1].append(a - 1)

vst = [-1] * N
q = [0]
vst[0] = 0
cnt = 0
for u in q:
    cnt += 1
    for v in adj[u]:
        if vst[v] < 0:
            vst[v] = u
            q.append(v)

if cnt == N:
    print('Yes')
    for k in vst[1:]:
        print(k + 1)

else:
    print('No')

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

int main(){ 
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int res = 0;
  res += min(k, a);
  k -= a;
  if (k <= b) {
    cout << res << endl;
    return 0;
  }
  k -= b;
  res -= k;
  cout << res << endl;
  return 0;
} 

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

#define int long long
#define pb push_back
#define ff first
#define ss second
int ans1=LONG_LONG_MAX;
void backtrack(vector<int> &c,vector<vector<int>> &a,int n,int m,int x,int idx,vector<int> &ans,int sum)
{
    //cout<<"CAlled:\n";
    int k;
    for(k=0;k<ans.size();k++)
    {
        if(ans[k]>0)
        {
            break;
        }
    }
    if(k==ans.size())
        ans1=min(ans1,sum);
    for(int i=idx;i<n;i++)
    {
        for(int j=0;j<m;j++)
            ans[j]=ans[j]-a[i][j];
        backtrack(c,a,n,m,x,i+1,ans,sum+c[i]);
        for(int j=0;j<m;j++)
           ans[j]=ans[j]+a[i][j];
    }
}
int32_t main()
{
    int n,m,x;
    cin>>n>>m>>x;
    
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));
    vector<int> ans(m,x);
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
        for(int j=0;j<m;j++)
            cin>>a[i][j];
    }
    backtrack(c,a,n,m,x,0,ans,0);
    if(ans1==LONG_LONG_MAX)
        cout<<-1;
    else
        cout<<ans1;
}

Measured memory_bytes: 3628
n,k = map(int,input().split())
a = list(map(int,input().split()))
MOD = 10**9+7

ans=0
for i in range(n):
    cnt1=0
    cntall=0
    for j in range(n):
        if a[i]>a[j]:
            cntall+=1
            if i<j:
                cnt1+=1

    ans =(ans + cnt1*k + cntall*k*(k-1)//2) % MOD

print(ans)


Measured memory_bytes: 67732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  bool p[26];
  rep(i,0,26) p[i]=true;
  rep(i,0,s.size()){
    p[s[i]-'a']=false;
  }
  int j=0;
  while(j<26 && !p[j]){
    j++;
  }
  if(j==26) cout<<"None"<<endl;
  else cout<<(char)(j+'a')<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
using namespace std;
#define ll long long
int main(int argc, char const *argv[])
{
    int x, a, b;
    cin >> x >> a >> b;
    x -= a;
    printf("%d\n", x%b);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#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()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(ALL(v));
  ll res = 0;
  for (int i = 0; i < k; ++i) {
    res += v[i];
  }
  cout << res << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll w[300010],e[300010];
int main() {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	for(ll i=0;i<n;i++){
		char now=s[i];
		if(now=='W'){
			w[i]=1;
		}
		else{
			e[i]=1;
		}
	}
	for(ll i=1;i<n;i++){
		w[i]=w[i]+w[i-1];
	}
	for(ll i=n-2;i>=0;i--){
		e[i]=e[i+1]+e[i];
	}
	ll ans=inf;
	for(ll i=0;i<n;i++){
		ll now=w[i]+e[i]-1;
		ans=min(now,ans);
		
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 5380
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int c[3][3];
  for(int i=1;i<=3;i++){
    for(int j=1;j<=3;j++){cin >> c[i][j];}
  }
  int a,b,d,e;
  int count=0;
  a=c[1][2]-c[1][1];
  b=c[1][3]-c[1][2];
  d=c[2][1]-c[1][1];
  e=c[3][1]-c[2][1];
  for(int i=1;i<=3;i++){
    if(c[i][2]-c[i][1]==a){count++;}
    if(c[i][3]-c[i][2]==b){count++;}
    if(c[2][i]-c[1][i]==d){count++;}
    if(c[3][i]-c[2][i]==e){count++;}
  }
  if(count==12){cout << "Yes" << endl;}
  else{cout << "No" << endl;}
}

Measured memory_bytes: 256
listA=[]
listB=[]
result_vec=[]
i,j=map(int,input().split())
for n in range(i):
    listA.append(list(map(int,input().split())))
for n in range(j):
    listB.append(int(input()))
for n in range(i):
    result=0
    for m in range(j):
        result+=listA[n][m]*listB[m]
    result_vec.append(result)
for n in range(i):print(result_vec[n])


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

int main() {
  int h,w;
  int black = 0;
  cin >> h >> w;
  vector<int>move_h = {0,1,-1,0};
  vector<int>move_w = {1,0,0,-1};
  vector<string>grid(50);
  vector<vector<int>> d(50,vector<int>(50));
  for (int i = 0; i < h; i++) {
    cin >> grid.at(i);
  }
  for (int i = 0; i < h; i ++) {
    for (int j = 0; j < w; j++) {
      if (grid.at(i).at(j) == '#') {
        black++;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      d.at(i).at(j) = INT_MAX;
    }
  }
  
  d.at(0).at(0) = 0;  
  queue<pair<int,int>> q;
  q.push(make_pair(0,0));
  
  while(!q.empty()) {
    auto cur = q.front();
    q.pop();
    int cur_h = cur.first;
    int cur_w = cur.second;
    
    for (int i = 0; i < 4; i++) {
      int next_h = cur_h + move_h.at(i);
      int next_w = cur_w + move_w.at(i);
      
      if (0 <= next_h && next_h < h && 0 <= next_w && next_w < w
           && grid.at(next_h).at(next_w) != '#' 
             && d.at(next_h).at(next_w) == INT_MAX) {
        d.at(next_h).at(next_w) = d.at(cur_h).at(cur_w) + 1;
        q.push(make_pair(next_h,next_w));
      }
      
    }
  }
  if (d.at(h-1).at(w-1) == INT_MAX) {
    cout << -1;
  }
  else {
    cout << h * w - (d.at(h-1).at(w-1)+1) - black;
  }
  
}

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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    if (s[0] == 'R') {
        ans++;
        if (s[1] == 'R') {
            ans++;
            if (s[2] == 'R') ans++;
        }
    }else { //s[0]==S
        if (s[1] == 'R') {
            ans++;
            if (s[2] == 'R') ans++;
        }else { //s[1]==S
            if (s[2] == 'R') ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
using System;

namespace _057_TheNumberofArea
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;

			while ((inputStr = Console.ReadLine ()) != null)
			{
				int inputNum = int.Parse (inputStr);
				int sum = inputNum * (inputNum + 1) / 2 + 1;
				Console.WriteLine (sum);
			}
		}
	}
}

Measured memory_bytes: 9024
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
const int M=1e5+10;
int n,m;
typedef pair<int,int> P;
P a[M];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%d%d",&a[i].fi,&a[i].se);
    sort(a,a+n);
    int cnt=0;
    ll ans=0;
    for(int i=0;;i++)
    {
        ans+=(ll)a[i].fi*a[i].se;
        cnt+=a[i].se;
        if(cnt>=m)
        {
            ans-=(ll)(cnt-m)*a[i].fi;
            break;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1024
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
A = []
for _ in range(N):
    A += [list(map(int, input().split()))]

num = 0
for i in range(N):
    cost = sum([a * b for (a, b) in zip(A[i], B)]) + C
    if cost > 0:
        num += 1
print(num)

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define X first
#define Y second
#define INF 1000 * 1000 * 1000
#define LL long long
#define LINF INF * (LL)INF
#define PB push_back
#define SZ(a) ((LL)a.size())
#define INVALID 2392139
const LL MAX = 300005;
const LL minim = -1000 * 1000 - 1;
const LL zsuv = MAX;
using namespace std;
using namespace __gnu_pbds;
const int mod = 1000 * 1000 * 1000 + 7;
vector<vector<int> > g(2005);
int suma[2005];
int cnt[2005];
string s;
void dfs(int u , int depth = 0, int p = -1)
{
	suma[u] = depth * s[u];
	for(auto v : g[u])
	{
		if(v == p)
			continue;
		dfs(v , depth + 1 , u);
		suma[u] += suma[v];
	}
}
void dfs2(int u , int p)
{
	cnt[u] = s[u];
	vector<int> sumas;
	int total = 0;
	for(auto v : g[u])
	{
		//cout << "RebroBef: " << u << " " << v << endl;
		if(v == p)
			continue;
		//cout << "RebroAft: " << u << " " << v << endl;
		dfs2(v , u);
		cnt[u] += cnt[v];
		sumas.PB(suma[v] + cnt[v]);
		total += suma[v] + cnt[v];
	}
	suma[u] = total;
	sort(sumas.begin() , sumas.end());
	if(SZ(sumas))
	{
		if((sumas.back() * 2) <= total)
		{
			suma[u] &= 1;
		}
		else
		{
			suma[u] = total - (total - sumas.back()) * 2;
		}
	}
	//cout << u << "U" << suma[u] << endl;
	//suma[u] += cnt[u];
}
int main()
{
	int n;
	cin >> n;
	cin >> s;
	for(auto &x : s)
		x -= '0';
	for(int i = 1; i < n; i++)
	{
		int u , v;
		cin >> u >> v;
		u--;v--;
		g[u].PB(v);
		g[v].PB(u);
	}
	int ans = INF;
	for(int i = 0; i < n; i++)
	{
		memset(suma , 0 , sizeof suma);
		dfs(i);
		if(suma[i] & 1)
			continue;
		//cout << i << " " << suma[i] << endl;
		bool bad = false;
		int mxV = -1;
		for(auto v : g[i])
			mxV = (mxV == -1 || suma[mxV] < suma[v]) ? v : mxV;
		if(suma[mxV] * 2 <= suma[i])
		{
			ans = min(ans , suma[i] / 2);
			continue;
		}
		int prevSum = suma[mxV];
		int sumaI = suma[i];
		memset(suma , 0 , sizeof suma);
		suma[i] = sumaI;
		memset(cnt , 0 , sizeof cnt);
		//cout << mxV << endl;
		dfs2(mxV , i);
		//cout << cnt[mxV] << " " << suma[mxV] << endl;
		
		if((suma[mxV] + cnt[mxV]) <= suma[i] - prevSum)
			ans = min(ans , suma[i] / 2);
	}
	if(ans == INF)
		cout << -1;
	else
		cout << ans;
}


Measured memory_bytes: 640
// Try AtCoder
// authoer: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let r = get!();
    let d = get!();
    let mut x = get!();
    
    for _ in 0..10 {
        x = r * x - d;
        println!("{}", x);
    }
}

Measured memory_bytes: 4352
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	for i := n; i < 1000; i++ {
		s := strconv.Itoa(i)
		if s[0] == s[1] && s[1] == s[2] {
			fmt.Fprintln(wr, i)
			return
		}
	}
}


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

int main() {
	vector<vector<string>> data(3);
	string stra,strb,strc;
	string next = "a";
	cin >> stra;

	cin >> strb;

	cin >> strc;
	int a = 0, b = 0, c = 0;
	while (true) {
		if (next == "a") {
			if (a < stra.size()) {
				next = stra[a];
				a++;
			}
			else {
				cout << "A" << endl;
				break;
			}
		}
		else if (next == "b") {
			if (b < strb.size()) {
				next = strb[b];
				b++;
			}
			else {
				cout << "B" << endl;
				break;
			}

		}
		else {
			if (c< strc.size()) {
				next = strc[c];
				c++;
			}
			else {
				cout << "C" << endl;
				break;
			}

		}
	}

	return 0;

}

Measured memory_bytes: 3600
#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long n;
    long long t, a;
    long long ans;
    long long hi;
    long long minv = 1ll << 50ll;
    long long h;

    scanf("%lld", &n);
    scanf("%lld %lld", &t, &a); t *= 1000; a *= 1000;

    for (long long i = 0; i < n; i++) {
        scanf("%lld", &h);
        
        hi = t - h * 6;

        if (minv > abs(a - hi)) {
            minv = abs(a - hi);
            ans = i + 1;
        }
    }

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

    return 0;
}


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

int main(void){
    char s[100001];
    scanf("%s", &s);
    int len = strlen(s);
    int a0 = 0;
    int a1 = 0;
    for(int i = 0;i < len;i++){
        if((s[i] + i) % 2 == 0){
            a0++;
        }else{
            a1++;
        }
    }
    if(a0 < a1){
        printf("%d\n", a0);
    }else{
        printf("%d\n", a1);
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

void solve() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);

  ll ma = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ma = max(ma, a[i]);
  }

  ll left = 0;
  ll right = ma + 1;

  while (right - left > 1) {
    const ll mid = (left + right) / 2;

    ll sum = 0;
    for (int i = 0; i < n; i++) {
      sum += (a[i] + mid - 1) / mid - 1;
    }

    if (sum <= k)
      right = mid;
    else
      left = mid;
  }

  cout << right << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


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

int main() {
  int n,k,c;
  cin>>n>>k>>c;
  
  string s;
  cin>>s;
  char p[n];
  
  for(int i=0; i<n; i++) p[i] = s.at(i);
  
  int a[k];
  int b[k];
  
  int count = 0;
  
  for(int i=1; i<=n;){
    if(p[i-1]=='o'){
      a[count]=i;
      count++;
      i = i+c+1;
    }
    else i++;
  }
  
  count = 1;
  
  for(int i=n; i>=1;){
    if(p[i-1]=='o'){
      b[k-count]=i;
      count++;
      i = i-c-1;
    }
    else i--;
  }
  
  for(int i=0; i<k; i++){
    if(a[i]==b[i]) cout << b[i] << endl;
  }
}

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

using namespace std;

const int N = 3010;

int dp[N][N];
int pt[N][N];
int n, m;
string s, t;

int solve(int x, int y) {
  if (x == n || y == m) return 0;
  int &ret = dp[x][y];
  if (ret != -1) return ret;
  ret = solve(x + 1, y);
  if (ret < solve(x, y + 1)) {
    ret = solve(x, y + 1);
    pt[x][y] = 1;
  }
  if (s[x] == t[y] && ret < 1 + solve(x + 1, y + 1)) {
    ret = 1 + solve(x + 1, y + 1);
    pt[x][y] = 2;
  }
  return ret;
}

string res;
void get(int x, int y) {
  if (x == n || y == m) return;
  if (pt[x][y] == 2) {
    res.push_back(s[x]);
    get(x + 1, y + 1);
  }
  else if (pt[x][y] == 0) {
    get(x + 1, y);
  }
  else {
    get(x, y + 1);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> s >> t;
  n = s.size();
  m = t.size();
  memset(dp, -1, sizeof dp);
  solve(0, 0);
  get(0, 0);
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 71552
n=int(input())
a={}
for _ in range(n):
    s=input()
    if(s in a):
        a[s]+=1
    else:
        a[s]=1
a=sorted(a.items(),key=lambda x:x[1],reverse=True)
b=[]
b.append(a[0][0])
for j in a[1:]:
    if(j[1]==a[0][1]):
        b.append(j[0])
    else:
        break
for t in sorted(b):
    print(t)

Measured memory_bytes: 43228
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  cin >> s;
  s = "0" + s;
  int n = (int) s.size();
  reverse(s.begin(), s.end());
  vector<vector<long long>> dp(n + 1, vector<long long>(2, 1LL << 60));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    int x = s[i] - '0';
    for (int d = 0; d <= 9; d++) {
      if (x + d < 10) {
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + x + d + d);
      } else {
        dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + d + (x + d) % 10);
      }
      if (x + d + 1 < 10) {
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + d + x + d + 1);
      } else {
        dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + d + (x + d + 1) % 10);
      }
    }
    //cerr << dp[i + 1][0] << " " << dp[i + 1][1] << endl;
  }
  cout << dp[n][0] << endl;
  return 0;
}

Measured memory_bytes: 56008
def f(K, S):
    #ここに処理を書いてください
    res = 0
    for i in range(K+1):
      for j in range(K+1):
        if i + j <= S and S-i-j <= K:
          res += 1
    return res

inx = list(map(int, input().split()))
print(f(inx[0], inx[1]))


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)

using namespace std;


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)   cin >> a[i];

    vector<pair<ll, ll>> list;
    bool end = false;
    ll cnt = 0;
    while(!end && cnt < 2*n+5){
        end = true; cnt++;
        for(ll i = n-2; 0 <= i; i--){
            if(a[i] <= a[i+1]) continue;
            end = false;

            // -1 -3
            if(a[i+1] < 0 && a[i] < 0){
                list.push_back({i+1, i});
                a[i] += a[i+1];
            }
            // 3 -4
            else if(a[i+1] < 0 && abs(a[i]) < abs(a[i+1])){
                list.push_back({i+1, i});
                list.push_back({i+1, i});
                a[i] += 2*a[i+1];
            }
        }
    }

    rep(i, n-1){
        if(a[i] <= a[i+1]) continue;
        // a[i+1] < a[i]
        // a[i] a[i+1]        
        
        if(a[i+1] < 0){
            // 3 -1
            if(abs(a[i+1]) <= abs(a[i])){
                list.push_back({i, i+1});
                list.push_back({i, i+1});
                a[i+1] += 2*a[i];
            }
        }
        // 3 1
        else{
            list.push_back({i, i+1});
            a[i+1] += a[i];
        }
        
    }
    
    cout << list.size() << endl;
    for(auto p : list){
        cout << (p.first+1) << " " << (p.second+1) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int mod = 1e9 + 7;

ll fpow(ll a, ll b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

ll inv(ll x) {
	return fpow(x, mod - 2);
}

ll C(ll n, ll m) {
	ll res = 1;
	ll mi = min(m, n - m);
	for (int i = 1; i <= mi; i++) {
		res = res * (n - i + 1) % mod * inv(i) % mod;
	}
	return res;
}

int main() {
	ll n, a, b; cin >> n >> a >> b;
	cout << (fpow(2, n) - C(n, a) - C(n, b) - 1 + mod + mod) % mod;
}

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

int main() {
  int n;
	cin >> n;
	int y;
  cin >> y;
  int cnt=0;
  bool found=false; 
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n-i;j++){
      for(int k=0;k<=n-i-j;k++){
        if(i+j+k==n){
          if(10000*i+5000*j+1000*k==y){
            cout << i << " " << j << " " << k;
            found=true;
            break;
          }
        }
      }       
      if(found==true){
        break;
      }
    }       
    if(found==true){
      break;
    }   
  }
  if(found==false){
    cout << -1 << " " << -1 << " " << -1;
  }
}


Measured memory_bytes: 256
import sys, math
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    A = [0, 0] + list(map(int, input().split()))

    ans = [0] * (N + 1)
    for i in range(2, N + 1):
        ans[A[i]] += 1
    for i in range(1, N + 1):
        print(ans[i])
    


if __name__ == "__main__":
    main()


Measured memory_bytes: 100108
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int N,K; cin >> N >> K;
    string s; cin >> s;

    char c = s[K-1];
    if(c == 'A') s[K-1]='a';
    if(c == 'B') s[K-1]='b';
    if(c == 'C') s[K-1]='c';
    cout << s <<endl;
}


Measured memory_bytes: 256
using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    using System.Text.RegularExpressions;

    class Program
    {
        static void Main()
        {
            var input = System.Console.ReadLine().Split(' ').Select((x) => long.Parse(x)).ToArray();
            var x = input[0];
            var k = input[1];
            var d = input[2];
            long? guusuu = null;
            long? kisuu = null;

            long shou = Math.Abs(x) / d;
            long amari = Math.Abs(x) % d;
            long kaisuu = k - shou;
            if (shou > k)
            {
                var ans = Math.Abs(x) - (k * d);
                Output(ans.ToString());
                return;
            }
            if (kaisuu % 2 == 0)
            {
                Output(amari.ToString());
                return;
            }
            else
            {
                Output(Math.Abs(amari - d).ToString());
                return;
            }
        }
        private static void Output(string str)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            Console.WriteLine(str);

            Console.Out.Flush();
        }
    }

Measured memory_bytes: 19032
#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;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll m;cin>>m;
  rep(i,0,m){
    ll d,c;cin>>d>>c;
    res+=c;
    buf+=d*c;
  }
  res+=(buf-1)/9;
  cout<<res-1<<endl;
  return 0;
}

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

using namespace std;
using ll = long long;

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

ll ts = 1000000007;

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

  ll k;
  string s;
  cin >> k >> s;

  if (s.size() <= k) {
    cout << s << "\n";
  } else {
    cout << s.substr(0, k) << "..."
         << "\n";
  }
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;

}

signed main() {
	ll n;

	cin >> n;

	vector<double> p(n + 1, 0.0);
	vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0.0));

	REP(i, n) {
		cin >> p[i + 1];
	}

	dp[1][0] = 1.0 - p[1];
	dp[1][1] = p[1];

	FOR(i, 2, n + 1) {
		FOR(j, 1, i + 1) {
			dp[i][j] += dp[i - 1][j - 1] * p[i];
		}
		REP(j, i + 1) {
			dp[i][j] += dp[i - 1][j] * (1.0 - p[i]);
		}
	}

	double ans = 0.0;

	FOR(i, (n + 1) / 2, n + 1) {
		ans += dp[n][i];
	}

	cout << setprecision(10) << scientific << ans << endl;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
bool memoo[10001][10];
int memo[10001][10];
int n, m;
vector<int> these;
int func(int cur, int num){
    if (num > m-1){
        
        if (cur != 0){
            memoo[cur][num] = true;
            memo[cur][num] = -1000000000;
            return -1000000000;
        }
        memoo[cur][num] = true;
        memo[cur][num] = 0;
        return 0;
    }
    if (cur < 0){
        return -1000000000;
    }
    if (memoo[cur][num]){
        return memo[cur][num];
    }
    int maxx = -1000000000;
    for (int i=0; i<=cur/these[num]; i++){
        maxx = max(maxx, i+func(cur-i*these[num], num+1));
    }
    memoo[cur][num] = true;
    memo[cur][num] = maxx;
    return maxx;
}
int arr[9];
string res = "";
void backtrace(int cur, int num, int curnum){
    if (num > m-1){
        return;
    }
    int last = 0;
    if (arr[num] == 7){
        //cout << these[num] << endl;
    }
    for (int i=0; i<=cur/these[num]; i++){
        int val = memo[cur-i*these[num]][num+1];
        if (val == curnum-i){
            if (arr[num] == 7){
                //cout << val << endl;
            }
            last = i;
        }
    }
    for (int j=0; j<last; j++){
        res += (char)(arr[num]+'0');
    }
    backtrace(cur-last*these[num], num+1, curnum-last);
    
}
int main(){
  prep();
  
  cin >> n >> m;
  these = {2, 5, 5, 4, 5, 6, 3, 7, 6};
  //these = {6, 7, 3, 6, 5, 4, 5, 5, 2};
  vector<int> neww;
  bool have[10] = {false};
  for (int i=0; i<m; i++){
      int num;
      cin >> num;
      arr[i] = num;
  }
  sort(arr, arr+m);
  for (int i=0; i<m; i++){
      neww.push_back(these[arr[i]-1]);
  }
  these = neww;
  reverse(these.begin(), these.end());
  reverse(arr, arr+m);
  
  int val = func(n, 0);
  backtrace(n, 0, val);
  cout << res;
  return 0; 
}

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

ll Pow(ll a, ll b, ll c){
    ll ans = 1;
    a %= c;
    while (b){
        if (b & 1) ans = (ans * a) % c;
        a = (a * a) % c;
        b >>= 1;
    }
    return (ans % c);
}

bool cmp(const int &a, const int &b){
    return a < b;
}

ll gcd(ll x, ll y){
    return x % y == 0 ? y : gcd(y, x % y);
}

ll lcm(ll x, ll y){
    return x / gcd(x, y) * y;
}

const int MAXN = 2000 + 5;
const int mod = 1e9 + 7;
ll comb[MAXN][MAXN];

void init(){
	for (int i = 0; i < MAXN; i++){
		comb[i][0] = comb[i][i] = 1;
		for (int j = 1; j < i; j++){
			comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
			comb[i][j] %= mod;
		}
	}
}

const int MAXM = 1e6;
int primes[MAXM], cnt;
bool st[MAXN];

void get_prime(int n){
	for (int i = 2; i <= n; i++){
		if (!st[i]) primes[cnt++] = i;
		for (int j = 0; j < cnt && i * primes[j] <= n; j++){
			st[i * primes[j]] = true;
			if (i % primes[j] == 0) break;
		}
	}
}

ll mult_mod(ll a, ll b, ll c){
    a %= c;
    b %= c;
    ll res = 0;
    while (b){
        if (b & 1){
            res += a;
            res %= c;
        }
        a <<= 1;
        a %= c;
        b >>= 1;
    }
    return res;
}

int main(){
    ll l, r;
    scanf("%lld%lld", &l, &r);
    if (l / 2019 != r / 2019) printf("0\n");
    else{
        ll ans = 0x3f3f3f3f;
        for (int i = l; i <= r; i++)
            for (int j = i + 1; j <= r; j++)
                ans = min(mult_mod(i, j, 2019), ans);
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int r, g , b, n;
	cin >> r >> g >> b >> n;
	ll ans = 0;
	for (int i = 0; i*r <= n; i++){
		for (int j = 0; j*g + i*r <= n; j++){
			if ((n - (i*r + j*g)) % b == 0) ans++;
		}
	}


	cout << ans << endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int card[4][52];
    char flag;
    int x;
    int n; cin >>n;
    for(int i=0;i<n;i++){
        cin >> flag >> x;
        if(flag=='S') card[0][x-1]=x;
        else if(flag=='H') card[1][x-1]=x;
        else if(flag=='C') card[2][x-1]=x;
        else if(flag=='D') card[3][x-1]=x;
    }
    for(int k=0;k<4;k++){
        for(int i=0;i<13;i++){
            if(card[k][i]!=i+1){
                if(k==0) cout << "S " << i+1 << endl;
                else if(k==1) cout << "H " << i+1 << endl;
                else if(k==2) cout << "C " << i+1 << endl;
                else if(k==3) cout <<"D " << i+1 << endl;
            }
        }
    }
    return 0;
}


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

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define fff ff
#define sss ss.ff
#define ttt ss.ss
#define INF (1 << 30)
#define LLF (1ll << 60)
#define PRIME (1000000007)
#define FASTIO std::ios::sync_with_stdio(false)
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define FILE_INPUT                  \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)

#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<string> vs;

/*-----------------END TEMPLATE-----------------*/

int main() {
  FASTIO;
  ll a, b;
  cin >> a >> b;
  if (b == 1) {
    cout << 0 << endl;
    return 0;
  }
  ll x = a;
  ll op = 1;
  while (x < b) {
    x += a - 1;
    op++;
  }
  cout << op << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map>       // pair
#include <string>
#include <stdio.h>
#include <numeric>
using namespace std;

int main(int argc, char const *argv[])
{

  int N;
  cin >> N;

  vector<tuple<string,int,int> > mat;
  for (int i = 0; i < N; i++)
  {
    string str;
    int a;
    cin>>str>>a;
    mat.emplace_back(str,-1*a,i);
  }

  sort(mat.begin(),mat.end());

  for (int i = 0; i < N; i++)
  {
    // cout << get<0>(mat[i]) << " " << get<1>(mat[i]) << " " << get<2>(mat[i]) << endl;
    cout <<get<2>(mat[i])+1 << endl;
  }

  
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a;
  cin>>b;
  int c[3]={1,2,3};
  for(int i=0;i<3;i++){
    if(c[i]==a||c[i]==b){
      c[i]=-1;
    }
  }
  for(int i=0;i<3;i++){
    if(c[i]!=-1){
      cout<<c[i]<<endl;
    }
  }
 return 0; 
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    map<int, int> last;
    rep(i, n){
        if(last.find(a[i]) != last.end()){
            continue;
        }
        last[a[i]] = n + i;
    }

    vector<int> nxt(n);
    for(int i = n - 1; i >= 0; i--){
        nxt[i] = last[a[i]] + 1;
        last[a[i]] = i;
    }

    for(int i = n - 1; i >= 0; i--){
        if(nxt[i] >= n){
            continue;
        }
        nxt[i] = nxt[nxt[i]];
    }
    rep(i, n){
        if(nxt[i] >= n){
            nxt[i] -= n;
        }
    }

    int cnt = 0;
    int pos = 0;
    do{
        pos = nxt[pos];
        cnt++;
        if(pos >= n){
            pos -= n;
            cnt++;
        }
    }while(pos != 0);

    k = (k - 1) % cnt;
    pos = 0;
    while(k > 0){
        pos = nxt[pos];
        k--;
        if(pos >= n){
            pos -= n;
            k--;
        }
    }

    if(k == -1){
        cout << endl;
        return 0;
    }

    map<int, int> m;
    stack<int> st;
    for(int i = pos; i < n; i++){
        if(m.find(a[i]) == m.end() || m[a[i]] == 0){
            m[a[i]]++;
            st.push(a[i]);
            continue;
        }
        while(m[a[i]] > 0){
            m[st.top()]--;
            st.pop();
        }
    }

    vector<int> ans;
    while(not st.empty()){
        ans.push_back(st.top());
        st.pop();
    }
    reverse(ALL(ans));
    for(int x : ans){
        cout << x << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 32884
import sys

input = sys.stdin.readline

def main():
    ans = 0
    H, W, M = map(int, input().split())
    bombs = []
    hs = [0]*(H)
    ws = [0]*(W)
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append(tuple([h-1, w-1]))
        hs[h-1] += 1
        ws[w-1] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    maxhindex = [i for i, x in enumerate(hs) if x == maxh]
    maxwindex = [i for i, x in enumerate(ws) if x == maxw]

    isfound = False

    bombs = set(bombs)
    for i in maxhindex:
        for j in maxwindex:
            if (i, j) not in bombs:
                print(ans)
                exit()

    print(ans-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 90028