akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};

int main(){
    ios::sync_with_stdio(false);
    int N, T;
    cin >> N >> T;
    int ans = INF;
    REP(i, N) {
        int c , t;
        cin >> c >> t;
        if (t <= T) {
            ans = min(ans, c);
        }
    }
    if (ans == INF) {
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
my $N = <STDIN>;

my $sum =0;
my @cal;

for(my $i=1;$i<=$N;$i++){
for(my $j=1;$j<=$N;$j++){
   $s = &gcd($i,$j); 
for(my $k=1;$k<=$N;$k++){
   if( $i==1||$j==1||$k==1){ $sum++;next;}    
   if($s ==1 ){ $sum++;next;}  
   $a = &gcd($k,$s); 
   $sum = $sum + $a;
   #print "gdc($i,$j,$k) $a sum$sum\n";
}
}
}
print "$sum";
exit;

sub gcd{ #最大公約数
  my ($x, $y) = @_;
  return $cal[$x][$y] if $cal[$x][$y]>0;
  my ($v, $u) = ($x, $y);
  while ($y) {
    my $r = $x % $y;
    $r += $y if $r < 0;
    $x = $y;
    $y = $r;
  }
  $cal[$v][$u] = $x;
  return $x;
}

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

int main(){
  int s[4] = {};
  int n=0;
  int flag=1;
  for(int i=0;i<6;i++){
    cin >> n;
    s[n-1] = s[n-1] +1;
  }
  for(int i=0;i<4;i++){
    if(s[i]>=3){
      flag=0;
    }
  }
  if(flag==1){
    cout<<"YES";
  }
  else{
    cout<<"NO";
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n=sc.nextInt();
        int a[]=new int[(int)1e6+1];
        Arrays.fill(a,0);
        for (int i=1;i<=n;i++){
            for (int j=i;j<=n;j+=i){
                a[j]++;
            }
        }
        long ans=0;
        int x=0;
        for (int i=1;i<n;i++){
            x=n-i;
            ans+=a[x];
        }
        System.out.println(ans);








        out.flush();

    }









    static void sort(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }
    static void sortReverse(long[] a) {
        ArrayList<Long> l=new ArrayList<>();
        for (long i:a) l.add(i);
//        Collections.sort.(l);
        Collections.sort(l,Collections.reverseOrder());
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long[] readArrayLong(long n) {
            long[] a=new long[(int)n];
            for (int i=0; i<n; i++) a[i]=nextLong();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }


}

Measured memory_bytes: 37920
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))

#define ld double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 2005

using namespace std;
///All indexing is 0-based
using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar
typedef long long ll;
typedef pair<ll, ll> par;

ll n,x,d,sol;

map<ll,vector<par> > v;



int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> x >> d;

    if(d == 0){
        if(x==0)
                cout << "1\n";
        else
                cout << (n+1) << "\n";
        return 0;
    }

    if(d<0) d*=-1 , x*=-1;

    for(ll i=0;i<=n;i++){
      ll ini = i*x/d + i*(i-1)/2;
      ll fin = i*x/d + i*(i-1)/2 + (n-i)*i;
      v[ (i*x%d + d) % d ].pb(par(ini,fin));
    }

    for(auto m:v){

        sort(all(m.se)) ;
        ll ini =-(1ll << 60);
        for(auto a:m.se){
            ini = max(ini,a.fi);
            sol += max(0ll,a.se-ini+1);
            ini = max(ini,a.se+1);
        }
    }

    cout << sol;



}


Measured memory_bytes: 22144
//************************
//*  Date: 2018.9.8      *
//*  Problem:            *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int main()
{
	int a,b;
	cin>>a>>b;
	repn(i,3)
	{
		if(a*b*i%2==1)
		{
			puts("Yes");
			rt0;
		}
	}
	puts("No");
	rt0;
}

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

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

    int H, N;
    cin >> H >> N;
    vector<int> skills(N);
    rep(i, N) cin >> skills[i];

    int sum = 0;
    for (auto num : skills) sum += num;
    if (H - sum <= 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h> 

using namespace std;
 
#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vi vector<int> 
#define vvi vector<vector<int>>
#define pb push_back
 
#ifdef LOCAL
    #define dbg(x) cout << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(10);
    solve();    
}

const int INF = 1e18, MAXN = 2e5 + 10, MOD = 1e9 + 7;

void solve() {
	int n, k; 
	cin >> n >> k;

	cout << (n - 1 + k - 2) / (k - 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; 
using namespace std;
#define int long long
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define mii map<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,b) for(ll (i)=0;i<(b);i++)
#define all(c) (c).begin(), (c).end()
#define F first
#define S second
#define CLR(p) memset(p, 0, sizeof(p))
#define SET(p) memset(p, -1, sizeof(p))
#define DEBUG true
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
//typedef long long int ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
tree_order_statistics_node_update> new_data_set; 
const int MAX=1e6+5;
#define MOD 1000000007
/*std::cout << std::fixed;
std::cout << std::setprecision(6);*/
//(a%mod-b%mod+mod)%mod



/************************************


 
*************************************/

vector<vector<ll>>v;
ll T=0;
ll cnt1=0,cnt0=0;
vector<ll>dep;
bool visited[MAX];
vector<ll>par;
vector<ll>tin,tout;
vector<ll>col;

int countDivisibles(int A, int B, int M) 
{ 
    
    if (A % M == 0) 
        return (B / M) - (A / M) + 1; 
  
    // A is not divisible by M 
    return (B / M) - (A / M); 
} 







signed main(){
    int t=1;
    // cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int d;
        map<int,int>m;
        for(int i=0;i<k;i++){
            cin>>d;
            for(int j=0;j<d;j++){
                int x;
                cin>>x;
                m[x]++;
            }
        }
        int cnt=0;
        for(int i=1;i<=n;i++){
            if(m[i]==0)
            cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    int a[n+1];
    int b[n+1];
    int c[n+1];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    for(int i = 1; i <= n-1; i++){
        cin >> c[i];
    }
    int score = 0;
    score += b[a[1]];
    for(int i = 2; i <= n; i++){
        score += b[a[i]];
        if(a[i-1]+1 == a[i]){
            score += c[a[i-1]];
        }
    }
    cout << score << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt();
        int sum=0;
        for (int i=1;i<=n;i++){
            for (int j=1;j<=n;j++){
                for (int k=1;k<=n;k++){
                    sum+=gcd(i,gcd(j,k));
                }
            }
        }
        System.out.println(sum);
    }
    static int gcd(int a,int b){
        if (a==0)return b;
        return gcd(b%a,a);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 32752
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
ll calc(ll x){
    ll ret = 0LL;
    bool fst = true;
    bool is_odd = (x % 2LL);

    rrep(i, 41, 1){
        int cur = ((x >> i) & 1);
        if(fst and cur == 0) continue;
        fst = true;

        ret += (is_odd ^ cur) * bit(i);
    }

    ret += ((x & 3) == 1 or (x & 3) == 2) ? 1:0;

    return ret;
}

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

    ll A, B; cin >> A >> B;

    ll res = calc(max(0LL, A - 1)) ^ calc(B);

    cout << res << endl;

    return 0;
}


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

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

	int n,k;
	cin >> n >> k;
	int p[n+1] = {0};
	for(int i = 1; i <= n; i++) cin >> p[i];
	for(int i = 2; i <= n; i++) p[i] += p[i-1];
	double ans = 0;
	for(int i = k; i <= n; i++) {
		int val = (p[i] - p[i-k] + k);
		ans = max(ans , val/2.0);
	}
	cout << fixed << setprecision(6) << ans << "\n";
	
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
  int n,m;
  int cnt=0;
  cin >> n >> m;
  
  vector<int> v(n);
  
  int a,b;
  for(int i = 0; i < m; ++i) {
    cin >> a;
    for (int j = 0; j < a; ++j) {
      cin >> b;
      v.at(b-1)++;
    }
  }
  
  cout << count(v.begin(), v.end(), 0) << "\n";
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <map>
using namespace std;
int n, m, mx;
string s[105], t;
map<string, int> mp;
int main()
{
    int i;
    cin>>n;
    for(i=0; i<n; i++) cin>>s[i], mp[s[i]]++;
    cin>>m;
    while(m--) cin>>t, mp[t]--;
    for(i=0; i<n; i++) mx = max(mx, mp[s[i]]);
    cout<<mx;
    return 0;
}

Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL<<60LL)
typedef long long ll;

using namespace std;


int main() {
	ll n, m; cin >> n >> m;
	ll lm = 1, rm = n;
	rep(i, m) {
		ll l, r; cin >> l >> r;
		lm = max(lm, l);
		rm = min(rm, r);
	}
	cout << max(0LL, rm - lm + 1) << endl;
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef string str;
typedef vector<char> vc;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define all(a) a.begin(), a.end()

template <typename T>
T Sum(vector<T> n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}
template <>
ld Sum(vector<ld> n, ll a, ll b)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}

template <typename T>
void Sort(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void Reve(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (reverse(n.begin() + a, n.end()));
  }
  else
  {
    return (reverse(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void V(T &n)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i];
  }
}

template <typename T, typename U>
void V2(T &n, U &m)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i];
  }
}

template <typename T, typename U, typename W>
void V3(T &n, U &m, W &p)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i] >> p[i];
  }
}

void fYn(bool a)
{
  if (a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  exit(0);
}
//最大公約数
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);
}
//複数個の最小公倍数
ll nlcm(vector<ll> numbers)
{
  ll res;
  res = numbers[0];
  for (ll i = 1; i < numbers.size(); i++)
  {
    res = lcm(res, numbers[i]);
  }
  return res;
}
//累乗(xのn乗%mod)
ll mod_pow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
ll factorial(ll n)
{
  if (n > 0)
    return n * factorial(n - 1);
  else
    return 1;
}
//n ~ mの和
ll sigma(ll n, ll m)
{
  return ((n + m) * (m - n + 1) * 0.5);
}
//大文字->小文字(+32)
//少数はなるべく整数に

void Main()
{
  ll n;
  cin >> n;
  vs s(n);
  V(s);
  rep(i, n)
  {
    Sort(s[i]);
    //fin(s[i])
  }
  Sort(s);
  rep(i, n)
  {
    Sort(s[i]);
  }
  map<str, ll> ans;
  ll Ans = 0;
  rep(i, n)
  {
    if (ans.count(s[i]))
      ans[s[i]]++;
    else
      ans[s[i]] = 0;
  }
  rep(i, n)
  {
    if (ans.count(s[i]))
    {
      if (ans[s[i]] > 0)
        Ans += sigma(1, ans[s[i]]);
      ans.erase(s[i]);
    }
    else
    {
      continue;
    }
    
  }
  fin(Ans)
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


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

int main() {

    int n,k;

    cin >> n >> k;

    int i=0;
    int num=1;
    for (i=1;i<n;i++){
        num *= k;
        if(n<num){
            break;
        }
    }

    cout << i << endl;

}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 15;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

bool tchk[4050];

int r[4050];
int ans[4050];
int root(int x) {
	return (x == r[x]) ? x : (r[x] = root(r[x]));
}
int main() {
	srand(time(0));
	int A, B, N, i, j, cnt = 0;
	scanf("%d %d", &A, &B);
	if (A <= B) return !printf("Impossible");

	N = A + B;
	for (i = 0; i < N; i++) r[i] = i;
	
	int an = -1;
	while (1) {
		int st = rand() % N;

		int x = -1, y = -1;
		for (i = st; i < N + st; i++) if (!tchk[i%N]) break;
		x = i%N;
		for (i = i+1; i < N + st; i++) if (!tchk[i%N] && root(x) != root(i%N)) break;
		y = i%N;
		if (i >= N + st) {
			an = root(x);
			break;
		}

		char c1[2], c2[2];
		if (cnt >= 2 * N) while (1);
		printf("? %d %d\n", x, y);
		fflush(stdout);
		scanf("%s", c1);
		cnt++;

		if (c1[0] != 'N') {
			if (cnt >= 2 * N) while (1);
			printf("? %d %d\n", y, x);
			fflush(stdout);
			scanf("%s", c2);
			cnt++;
		}

		if (c1[0] == 'Y' && c2[0] == 'Y') {
			r[root(x)] = root(y);
		}
		else {
			vector <int> Vu1;
			vector <int> Vu2;
			for (i = 0; i < N; i++) if (!tchk[i] && root(x) != i && root(x) == root(i)) Vu1.push_back(i);
			Vu1.push_back(root(x));
			for (i = 0; i < N; i++) if (!tchk[i] && root(y) != i && root(y) == root(i)) Vu2.push_back(i);
			Vu2.push_back(root(y));

			for (i = 0; i < Vu1.size() && i < Vu2.size(); i++) tchk[Vu1[i]] = tchk[Vu2[i]] = true;
		}
	}
	//printf("Current Count : %d\n", cnt);

	vector <int> Vu2;
	for (i = 0; i < N; i++) if (r[i] == i && i != an) Vu2.push_back(i);
	
	ans[an] = 1;
	for (i = 0; i < Vu2.size(); i++) {
		int t = Vu2[i];

		if (i + 1 != Vu2.size()) {
			if (cnt >= 2 * N) while (1);
			printf("? %d %d\n", an, t);
			fflush(stdout);
			cnt++;

			char c[2];
			scanf("%s", c);
			ans[t] = (int)(c[0] == 'Y');
		}

		else {
			int tc = 0;
			for (i = 0; i < N; i++) tc += ans[root(i)];
			if (tc != A) ans[t] = 1;
		}
	}

	printf("! ");
	for (i = 0; i < N; i++) printf("%d", ans[root(i)]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 852
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
 
using namespace std;
typedef long long ll;

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

ll lcm(ll a,ll b){  
    return b/gcd(a, b)*a;  
}  
 

ll ans,mx,sum,mn=1e8;
int main(){
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0; i<n; i++){
		cin>>a[i];
	}
	ans=a[0];
	for(ll i=1; i<n; i++){
		ans=lcm(ans,a[i]);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ull  unsigned long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 300000;
int a[N];
char ans[2000][2000];
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt",  "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, m, d;
    cin >> n >> m >> d;
    for (int i = d; i <= n + m; i++){
        a[i] = a[i - d] ^ 1;
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            int x = i + j;
            int y = j + n - i - 1;
            if (a[x] && a[y]) ans[i][j] = 'R';
            if (a[x] && !a[y]) ans[i][j] = 'Y';
            if (!a[x] && a[y]) ans[i][j] = 'G';
            if (!a[x] && !a[y]) ans[i][j] = 'B';
        }
    }
    for (int i = 0; i < n; i++, cout << endl){
        for (int j = 0; j < m; j++) cout << ans[i][j];
    }
}


Measured memory_bytes: 3584
def counting_sort(A, n):
    k = max(A)
    B = [0] * n
    C = [0] * (k+1)
    for j in range(n):
        C[A[j]] += 1

    for i in range(1, k+1):
        C[i] = C[i] + C[i-1]

    for j in range(n-1, -1, -1):
        B[C[A[j]]-1] = A[j]
        C[A[j]] -= 1
    return B

n = int(input())
A = [int(i) for i in input().split()]
print(*counting_sort(A, n), sep=" ")


Measured memory_bytes: 224244
#include <iostream>                                                                                      
using namespace std;                                                                                     
int main(){                                                                                              
  int x, i;                                                                                              
  i =0;                                                                                                  
  cin >> x;                                                                                              
  while (x){                                                                                             
    cout<< "Case " << (i+1) << ": " << x << endl;                                                        
    i++;                                                                                                 
    cin >> x;                                                                                            
  }                                                                                                      
}                                                                                                        
   


Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int res = 0;
    if (n >= 100000) {
        n = 99999;
    }

    if (n >= 10000) {
        res += (n - 10000) + 1;
        n = 999;
    }

    if (n >= 1000) {
        n = 999;
    }

    if (n >= 100) {
        res += (n - 100) + 1;
        n = 9;
    }

    if (n >= 10) {
        n = 9;
    }

    if (n < 10) {
        res += n;
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
	int n;
	scanf("%d",&n);
	int i,j,k;
	int insuu_cnt;
	int insuu_goukei[2000]={0};
	
	
	//素因数分解
	for(i=1;i<=n;i++){
		insuu_cnt=0;
		k=i;
		while(k>1){
			for(j=2;j<=k;j++){
				if(k%j==0){
					insuu_goukei[j]++;
					k/=j;
					break;
				}
			}
		}
	}
	
	long long int yakusuu_cnt=1;
	for(i=1;i<=1000;i++){
		if(insuu_goukei[i]){
			//printf("%d:%d\n",i,insuu_goukei[i]);
		}
		yakusuu_cnt = yakusuu_cnt * (insuu_goukei[i]+1) % 1000000007;
	}
	
	printf("%d\n",yakusuu_cnt);
	
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner (System.in)){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int l = sc.nextInt();

			int[][] A = new int[n][m];
			int[][] B = new int[m][l];

			//読み込む----------------------------
			for (int i=0; i<n; i++) {
				for (int j=0; j<m; j++) {
					A[i][j] = sc.nextInt();
				}
			}

			for (int i=0; i<m; i++) {
				for (int j=0; j<l; j++) {
					B[i][j] = sc.nextInt();
				}
			}
			//-------------------------------------

			long[][] C = new long[n][l];
			for (int i=0; i<n; i++) {
				for (int j=0; j<l; j++) {
					for (int k=0; k<m; k++) {
						C[i][j] += A[i][k] * B[k][j];
					}
				}
			}

            for (int i=0; i<n; i++) {
				for (int j=0; j<l; j++) {
					System.out.print(C[i][j]);
					if (j!= l-1) System.out.print(" ");
				}
				System.out.print('\n');
			}
		}
	}
}



Measured memory_bytes: 55644
import java.util.Scanner;

public class Main {

	public static void main (String[] args)  {

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		
		
		System.out.println(s.equals("hi") || s.equals("hihi") || s.equals("hihihi") || s.equals("hihihihi") || s.equals("hihihihihi") ? "Yes" : "No");


	}




}


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

int main()
{
	//int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, ans = 0;
	//cout << LONG_MAX << endl;
	int p[200001];
	int n;
	cin >> n;
	cin >> c;
	if (c!=0)
	{
		cout << -1 << endl;
		return 0;
	}
	for (a = 1; a < n; a++)
	{
		cin >> b;
		if (b==c+1)
		{

		}
		else if (b<=c)
		{
			ans += c;
		}
		else if (b-1>c)
		{
			cout << -1 << endl;
			return 0;
		}
		c = b;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
   string a,b;
   cin >> a >> b;
   ll c=0;
   for(ll i=0;i<a.size();i++)
   {
       if(a[i]!=b[i])
        c++;
   }
   cout << c << endl;
}


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

long long N, K, A[200009]; vector<long long>B;

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) {
		long long sum = 0;
		for (int j = i; j < N; j++) {
			sum += A[j]; B.push_back(sum);
		}
	}

	long long V = 0;
	for (int i = 60; i >= 0; i--) {
		long long cnt = 0;
		for (int j = 0; j < B.size(); j++) {
			if ((B[j] | (V + (1LL << i))) == B[j]) cnt++;
		}
		if (cnt >= K) V += (1LL << i);
	}
	cout << V << endl;
	return 0;
}

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

int main()
{
	string s,t;
	cin >> s;

	t = s;

	vector<char>x;

	reverse(t.begin(), t.end());

	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != t[i])
		{
			cout << "No";
			return 0;
		}
	}

	int q = (s.size() - 1) / 2;
	int p = (s.size() + 3) / 2;

	for (int i = 0; i < q; i++)
	{
		x.push_back(s[i]);
	}
	vector<char>y(x);

	reverse(y.begin(), y.end());

	for (int i = 0; i < x.size(); i++)
	{
		if (x[i] != y[i])
		{
			cout << "No";
			return 0;
		}
	}

	x.clear();

	for (int i = p -1; i < s.size(); i++)
	{
		x.push_back(s[i]);
	}

	vector<char>z(x);

	reverse(z.begin(), z.end());

	for (int i = 0; i < x.size(); i++)
	{
		if (x[i] != z[i])
		{
			cout << "No";
			return 0;
		}
	}

	cout << "Yes";
	return 0;
}

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

typedef long long ll;

int main() {
	std::string S;
	ll K;
	std::cin >> S >> K;

	for(size_t i = 0; i < S.length(); ++i) {
		if((ll) i == K - 1 || S[i] != '1') {
			std::cout << S[i] << std::endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s, t string
	_, _ = fmt.Scan(&s, &t)

	var ans int
	for i := 0; i < 3; i++ {
		if s[i] == t[i] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int n ; cin >> n;
    long long a , b , x[n];
    cin >> a >> b;
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    long long mn = 0;
    for (int j = 0; j < n-1; ++j) {
        mn += min(b , (x[j+1] - x[j])*a);
    }
    cout << mn;
}



Measured memory_bytes: 4332
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int ans=0;
	cin>>n;
	int x;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		ans=ans+x;
	}
	ans=ans-n;
	cout<<ans<<endl;
	return 0;
}

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

#define INF 999999999
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define pub push_back
#define pob pop_back
#ifdef LOCAL
  #define de(e) cout << "L" << __LINE__ << ": " << e << "\n" // debug echo
  #define dr(e) cout << "L" << __LINE__ << ": " << #e << " -> " << e << "\n" // debug repr
#else
  #define de(e)
  #define dr(e)
#endif
#define out(fmt, ...) printf(fmt, __VA_ARGS__); printf("\n")
int gcd(int m, int n) { if((0 == m) || (0 == n)){return 0;} while(m != n){ if(m > n){m -= n;}else{n -= m;} } return m; }
int lcm(int m, int n) { if((0 == m) || (0 == n)){return 0;} return (m / gcd(m, n)) * n; }

//
// Implementation
//

int main() {
  ll X, Y; cin >> X >> Y;
  ll prev = X;
  ll cur = X;
  ll cnt = 0;
  while (cur <= Y) {
    cur += prev;
    if (prev*2 == cur) {
      prev = cur;
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() { 
  int a,b,c,x; cin >> a >> b >> c >> x;
  int count = 0;
  for (int i = 0; i <= a; i++){
    for (int j = 0; j <= b; j++){
      for (int k = 0; k <= c; k++){
        int total = 500*i + 100*j + 50*k; 
        if (total == x) count++; }}}
  cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;

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

        String S = sc.next();
        char[] chars = new char[S.length()];

        for (int i=0; i<S.length(); i++) {
            chars[i] = S.charAt(i);
        }

        int sum = 0;
        for (char c : chars) {
            if (c == 'o') {
                sum++;
            }
        }
        System.out.println((sum + (15 - S.length())) >= 8 ? "YES" : "NO");
    }
}



Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
	for(int i=0;i<a.size();++i)
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 512
// 2149_LuckManipulator.cpp
//
#include <bits/stdc++.h>
using namespace std;

int n, a, b, c, x, buf;
deque<int> que;

int dfs(int x, int frame) {
  if(frame > 10000) return -1;

  if(que.front() == x) que.pop_front();

  if(que.empty()) return frame;
  else return dfs((a * x + b) % c, frame + 1);
}

void solve() {
  cout << dfs(x, 0) << endl;
  que.clear();
}

int main() {
  while(cin >> n >> a >> b >> c >> x) {
    if(n == 0 && a == 0 && b == 0 && c == 0 && x == 0) break;
    for(int i = 0; i < n; ++i) {
      cin >> buf;
      que.push_back(buf);
    }
    solve();
  }
  return 0;
}



Measured memory_bytes: 3100
#include <iostream>

using namespace std;

bool is_prime(int n) {
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0) return false;
    }
    return true;
}

int main()
{
    int N;
    cin >> N;
    int count = 0;
    while (N--) {
        int n;
        cin >> n;
        if (is_prime(n)) ++count;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3080
#include <stdio.h>
#include <math.h>

int primecheck(int m){
    int i;
    
    //if(m==1)return 0;
    //if(m==2||m==3)return 1;
    for(i=2;i<=sqrt(m);i++){
        if(m%i==0)return 0;
    }
    return 1;
}

int main(void){
    int i,n;
    
    while(scanf("%d",&n) != EOF){
        for(i=n-1;;i--){
            if(primecheck(i)){
                printf("%d ",i);
                break;
            }
        }
        
        for(i=n+1;;i++){
            if(primecheck(i)){
                printf("%d\n",i);
                break;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const ll MAX_N = 100000;

// vector<int> dp(100000, 1e9);

int main()
{
    bool flg = true;
    ll N,K;
    ll digit = 1;
    // ll A[1005];
    cin >> N>> K;

    while((N/K)>=1){
        N = N / K;
        digit++;
    }
        printf("%lld",digit);
    return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

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

int main() {

	ll n; cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) {
		ll tmp; cin >> tmp;
		a[i] = tmp - (i + 1);
	}
	sort(a.begin(), a.end());
	ll solution;
	if (n % 2 == 0) {
		solution = a[n / 2 - 1];
	}
	else {
		solution = a[n / 2];
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans += abs(a[i] - solution);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int> a(N + 1); for (int i = 0; i < N; i++) cin >> a[i];
  a[N] = 0;
  int same_n = 0, same_count = 0, ans = 0;
  for (int i = 0; i <= N; i++) {
    if (a[i] == same_n) same_count++;
    else {
      ans += same_count / 2;
      same_n = a[i];
      same_count = 1;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector <int> a(n);

	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	bool ans = true;
	for(int i = 0; i < n; i++) {
		if (a[i] % 2 == 0) {
			if (a[i] % 3 == 0 || a[i]  % 5 == 0) {
				;
			} else {
				ans = false;
			}
		}
	}
	if(ans == false) {
		cout << "DENIED" << endl;
	} else {
		cout << "APPROVED" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let s: Vec<u8> = read::<String>().into_bytes();

    let mut ans = 0;
    for c in s {
        if c == '+' as u8 {
            ans += 1;
        } else {
            ans -= 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<sstream>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int l[2005],r[2005];
struct diff
{
    int l;
    int r;
    friend bool operator < (const diff &a,const diff &b)
    {
        return a.l<b.l;
    }
};
diff d[2005];
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    string a,b;
    cin>>a>>b;
    int n=a.length();
    int i;
    int last=-1;
    for (i=0;i<n;i++)
    {
        if (b[i]=='1') last=i;
    }
    if (last==-1)
    {
        if (a==b)
        {
            printf("0\n");
            return 0;
        }
        else
        {
            printf("-1\n");
            return 0;
        }
    }
    last-=n;
    for (i=0;i<n;i++)
    {
        if (b[i]=='1') last=i;
        l[i]=i-last;
    }
    for (i=n-1;i>=0;i--)
    {
        if (b[i]=='1') last=i;
    }
    last+=n;
    for (i=n-1;i>=0;i--)
    {
        if (b[i]=='1') last=i;
        r[i]=last-i;
    }
    int final_min=n*1000;
    for (i=0;i<n;i++)
    {
        int sum=0;
        int j;
        for (j=0;j<n;j++)
        {
            if (b[j]!=a[(j-i+n)%n])
            {
                d[sum].l=l[j];
                d[sum].r=r[j];
                sum++;
            }
        }
        if (sum!=0) sort(d,d+sum);
        int r_most=0;
        int min_ans=n*100;
        for (j=sum-1;j>=0;j--)
        {
            //l_most = d[j].l;
            //go to left!
            min_ans=min(min_ans,i+r_most*2+max(d[j].l-i,0)*2);
            //go to right!
            min_ans=min(min_ans,(n-i)+d[j].l*2+max(r_most-(n-i),0)*2);
            r_most=max(r_most,d[j].r);
        }
        min_ans=min(min_ans,i+r_most*2+max(0-i,0)*2);
        min_ans=min(min_ans,(n-i)+0*2+max(r_most-(n-i),0)*2);
        //printf("%d\n",min_ans+sum);
        final_min=min(final_min,min_ans+sum);
    }
    printf("%d\n",final_min);
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main() {
	int n;
	char s[N];
	int x, y, z, xx;
	f(i, N)s[i] = 0;
	bool a[11][11][11];
	bool aa[11][11];
	vector<int>b[10];
	vector<int>d;
	int ans = 0;
	f(i, 11) {
		f(j, 11) {
			f(k, 11)a[i][j][k] = false;
			aa[i][j] = false;
		}
	}
	a[0][0][0] = true;
	aa[0][0] = true;
	f(i, 10)b[i].push_back(0);
	scanf("%d", &n);
	scanf("%s", s);
	f(ii, n) {
		z = s[ii] - '0' + 1;
		d.clear();
		f(i, b[z-1].size()) {
			x = b[z-1][i] / 11;
			y = b[z-1][i] % 11;
			a[x][y][z] = true;
				if (!aa[y][z]) {
                  aa[y][z]=true;
					xx = 11 * y + z;
					f(j, 10) {
						if(j!=z-1)b[j].push_back(xx);
					}
					d.push_back(xx);
				}
		}
		b[z-1] = d;
	}
	f(i, 10) {
		f(j, 10) {
			f(k, 10) {
				if (a[i + 1][j + 1][k + 1])ans++;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 384
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()
a = LIST()

l = [1]*n
l1 = [l[i]*(-1)**i for i in range(n)]
l2 = [l[i]*(-1)**(i+1) for i in range(n)]

ans1 = 0
tmp1 = 0
for i, r in enumerate(a):
	tmp1 += r
	if tmp1*l1[i] <= 0:
		ans1 += abs(tmp1) + 1
		tmp1 = l1[i]

ans2 = 0
tmp2 = 0
for i, r in enumerate(a):
	tmp2 += r
	if tmp2*l2[i] <= 0:
		ans2 += abs(tmp2) + 1
		tmp2 = l2[i]

print(min(ans1, ans2))

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
               int[] ldm_ok = new int[3];
                int [] ldm = new int[3];
                for (int i = 0; i < n; i++)
                {
                    Regex regex = new Regex(":| ");
                    string[] hms = regex.Split(Console.ReadLine());
                    int hh = int.Parse(hms[0]);
                    int mm = int.Parse(hms[1]);
                    int ss = int.Parse(hms[2]);
                    int tmp = Math.Abs(mm-ss);
                    int wtime = Math.Min(tmp,60-tmp);
                    
                        if(hh>=11&&hh<=14){
                            if(wtime<=8)
                            ldm_ok[0]++;
                            ldm[0]++;
                        }
                        else if(hh>=18&&hh<=20){
                            if(wtime<=8)
                            ldm_ok[1]++;
                            ldm[1]++;
                        }
                        else if(hh>=21&&hh<=23||hh==0||hh==1){
                            if(wtime<=8)
                                ldm_ok[2]++;
                                ldm[2]++;
                            
                        }
                }
                String[] type = {"lunch ","dinner ","midnight "};
                for(int i=0;i<3;i++){
                    if(ldm[i]!=0)
                        Console.WriteLine(type[i]+(ldm_ok[i]*100/ldm[i]));
                    else Console.WriteLine(type[i]+"no guest");
                }
            }
        }
    }
}

Measured memory_bytes: 21348
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int dp[101][100001];

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n, W;
	cin >> n >> W;
	int w[n + 1], v[n + 1];
	for(int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j < 100001; j++) {
			dp[i][j] = inf;
		}
	}
	dp[0][0] = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < 100001; j++) {
			if(dp[i - 1][j] != inf) {
				dp[i][j] = min(dp[i][j], dp[i - 1][j]);
			}
			if(j >= v[i] && dp[i - 1][j - v[i]] != inf) {
				dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
			}
		}
	}
	for(int i = 100000; i >= 0; i--) {
		if(dp[n][i] <= W) {
			cout << i;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 82500
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li,li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li,li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = 9223372036854775807;

void Yes(li b){
  if(b)cout<<"Yes";
  else cout<<"No";
}
void yes(li b){
  if(b)cout<<"yes";
  else cout<<"no";
}

int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cout.precision(16);

  li N,A,B;
  cin >>N>>A>>B;

  li times = N/(A+B);
  if(N%(A+B) < A){cout << times*A+N%(A+B);}
  else{cout <<times*A+A;}

}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
	priority_queue<int> q;
	int n,m;
	scanf("%d%d",&n,&m);
	int t;
	while(n--){
		scanf("%d",&t);
		q.push(t);
	}
	int sum=0;
	while(m--){
		sum+=q.top();
		q.pop();
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256