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

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


signed main(void) 
{
    string s;
    cin >>s;
    ll r = 0;
    ll w = 0;
    ll l = s.size();
        
    rep(i, l) {
        if (s[i] == 'W') {
            r += abs(i-w);
            w++;
        }
    }
    mes(r);

    
    
    
    
    
    

}


Measured memory_bytes: 3704
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll K;
ll countdigits(ll n){
  ll ans=0;
  while(n){n/=K;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,N,res,ans=inf;
  cin>>N;
  vec v(N);
  rep(i,N)cin>>v[i];
  rep(j,101){
    res=0;
    rep(i,N)res+=(v[i]-j)*(v[i]-j);
    chmin(ans,res);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#define int long long
using namespace std;
signed main() {
	double a, b, c, d, h, t;
	cin >> a >> b >> t;
	t = t / 180 * 3.14159265358979;
	h = b * sin(t);
	d = a - sqrt(b * b - h * h);
	if (t > 3.14159265358979 / 2)d = a + sqrt(b * b - h * h);
	c = sqrt(d * d + h * h);
	printf("%.10f\n%.10f\n%.10f\n", a * h / 2, a + b + c, h);
	cin >> a;
}


Measured memory_bytes: 3348
import java.util.Scanner;

//Persistence
public class Main{

	static int[] w;
	static int n, m;
	
	static boolean f(int W){
		int need = 1;
		int s = 0;
		for(int i=0;i<n;i++){
			if(w[i]>W)return false;
			if(s+w[i]>W){
				need++;
				s = 0;
			}
			s+=w[i];
		}
		return need <= m;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			m = sc.nextInt();
			n = sc.nextInt();
			if((m|n)==0)break;
			w = new int[n];
			for(int i=0;i<n;i++)w[i]=sc.nextInt();
			int l = 1;
			int r = 1500000;
			while(r-l>1){
				int mid = (l+r)/2;
				if(f(mid))r = mid;
				else l = mid;
			}
			System.out.println(f(l)?l:r);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {

        int T[50001];

        int n, m, c[20];
        cin >> n >> m;

        for(int i = 0; i < m; i++) {
                cin >> c[i];
        }

        for(int j = 0; j <= n; j++) {
                T[j] = j;
        }

        for(int i = 1; i <= m; i++) {
                for(int j = c[i]; j <= n; j++) {
                        T[j] = min(T[j], T[j-c[i]]+1);
                }
        }

        cout << T[n] << endl;


}

Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int r,D;
    int x;
    cin >> r >> D >> x;
    for(int i=0;i<10;i++){
        x = r * x - D;
        cout << x << endl;
        
    }
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	int arr[n];
	long long res=0;
	for (int i=0; i<n; i++){
		cin >> arr[i];
	}
	sort(arr,arr+n, greater<int>());
	bool same=false;
	for (int i=1; i<n; i++){
		if (arr[i]==arr[i-1] && arr[i-1]==arr[i-2] &&  same){
			res=arr[i];
			res*=res;
			same=false;
			break;
		
		}
		else if (same)
			break;
		else if (arr[i]==arr[i-1] && !same){
			res=arr[i];
			arr[i]=0;
			same=true;
			i++;
		}
		else
			same=false;
	}
	if (same==true){
		for (int i=1; i<n; i++){
			if (arr[i]==arr[i-1] && arr[i]!=0){
				res*=arr[i];
				break;
			}
		}
	}
	cout << res << '\n';
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,i,ans=0;cin>>N;ll A[N];
  REP(i,N)cin>>A[i];
  REP(i,N-1)if(A[i+1]<A[i]){
    ans+=A[i]-A[i+1];A[i+1]=A[i];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5156
object Main extends App {
  val sc = new java.util.Scanner(System.in)

  while (sc.hasNext) {
    val cards = sc.next()
    if (cards == "-") sys.exit()
    val hList = List.fill(sc.nextInt())(sc.nextInt())
    execute(cards, hList)
  }

  def execute(cards: String, hList: List[Int]): Unit = {
    lazy val shuffle = makeShuffleFun(cards)
    hList.foreach(shuffle(_))
    println(shuffle(0))

    def makeShuffleFun(c: String): (Int) => String = {
      var cards = c
      (h: Int) => {
        if (h != 0) cards = cards.drop(h) ++ cards.take(h)
        cards
      }
    }
  }
}

Measured memory_bytes: 45376
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  string S; cin >> S;
  string T; cin >> T;

  int N_S = S.size();
  int N_T = T.size();
  vector<vector<int>> dp(N_S + 10, vector<int>(N_T + 10, 0));
  dp[0][0] = dp[0][1] = dp[1][0] = 0;
  for (int i = 0; i < N_S; ++i){
    for (int j = 0; j < N_T; ++j){
      if (S[i] == T[j]) chmax(dp[i + 1][j + 1], dp[i][j] + 1);
      else chmax(dp[i + 1][j + 1], dp[i][j]);
      chmax(dp[i + 1][j + 1], dp[i + 1][j]);
      chmax(dp[i + 1][j + 1], dp[i][j + 1]);
    }
  }
  string ans = "";
  while (N_S > 0 && N_T > 0){
    // (i, j + 1) -> (i + 1, j + 1)
    if (dp[N_S][N_T] == dp[N_S - 1][N_T]) --N_S;
    // (i + 1, j) -> (i + 1, j + 1)
    else if (dp[N_S][N_T] == dp[N_S][N_T - 1]) --N_T;
    // (i, j) -> (i + 1, j + 1)
    else {
      ans = S[N_S- 1] + ans;
      --N_S, --N_T;
    }
  }
  //cout << dp[N_S][N_T] << endl;
  cout << ans << endl;
}


Measured memory_bytes: 35712
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
   vector<int> v(3);
   for(auto &it:v)cin>>it;
   if(v[0]*v[2]<v[1])cout<<v[2]<<endl;
   else cout<<v[1]/v[0]<<endl;
}
int32_t main(){
  IOS;
  solve();
  //debug();
 #ifdef LOCAL_DEFINE
 cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
 #endif	
}


Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;
const int INF=1e9;

int calc(int lshift,string& a,string& b){
    int n=a.size();
    vector<int> isOK(n);
    for(int i=0;i<n;i++) isOK[i]=(a[i]==b[(i+n-lshift)%n]);
    int sc=count(isOK.begin(),isOK.end(),0);
    int res=INF;

    int pos=0;
    for(int i=0;i<n;i++) if(b[i]=='1') pos=i-n;
    for(int i=0;i<n;i++){
        if(b[i]=='1') pos=i;
        if(i-lshift<=pos) isOK[i]=true;
    }
    vector<int> Rmove(n);
    for(int i=n-1;i>=0;i--) if(b[i]=='1') pos=i+n;
    for(int i=n-1;i>=0;i--){
        if(b[i]=='1') pos=i;
        if(!isOK[i]) Rmove[i]=pos-i;
    }

    vector<int> Lmove(n);
    for(int i=0;i<n;i++) if(b[i]=='1') pos=i-n;
    for(int i=0;i<n;i++){
        if(b[i]=='1') pos=i;
        if(!isOK[i]) Lmove[i]=i-pos;
    }

    vector<int> ids(n);
    iota(ids.begin(),ids.end(),0);
    sort(ids.begin(),ids.end(),[&](int lhs,int rhs){return Lmove[lhs]>Lmove[rhs];});

    int id=0;
    int r=0;
    for(int l=n;l>=lshift;l--){
        while(id<ids.size() && l<Lmove[ids[id]]){
            r=max(r,Rmove[ids[id]]);
            id++;
        }
        res=min(res,lshift+(l-lshift)*2+r*2+sc);
    }
    return res;
}
int solve(string a,string b){
    int res=INF;
    for(int i=0;i<=a.size();i++){
        res=min(res,calc(i,a,b));
    }
    return res;
}

int main(){
    string a,b;
    cin>>a>>b;
    if(count(b.begin(),b.end(),'0')==b.size()){
        cout<<(count(a.begin(),a.end(),'0')==a.size() ? 0 : -1)<<endl;
        return 0;
    }
    int res=solve(a,b);
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    res=min(solve(a,b),res);
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []
for i in range(N):
  A.append(list(map(int, input().split())))

right = 0

for i in range(N):
  src = 0
  for j in range(M):
    src += A[i][j]*B[j]
  if src+C>0:
    right+=1

print(right)

Measured memory_bytes: 3064
# coding: utf-8
MOD = int(1e9 + 7)

def f(N, M, s, t):
    dp = [[0] * (M + 1) for _ in range(N + 1)]
    cums = [[0] * (M + 1) for _ in range(N + 1)]

    for i in range(1, N + 1):
        for j in range(1, M + 1):
            dp[i][j] = 0 if s[i-1] != t[j-1] else (cums[i-1][j-1] + 1) % MOD
            cums[i][j] = cums[i-1][j] + cums[i][j-1] - cums[i-1][j-1] + dp[i][j]
    return((cums[N][M] + 1) % MOD)

n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
print(f(n, m, s, t))


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

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, pair<T1, T2> P)
{
    return s << '<' << P.first << ", " << P.second << '>';
}
template <class T>
ostream &operator<<(ostream &s, vector<T> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        if (i > 0)
        {
            s << " ";
        }
        s << P[i];
    }
    return s;
}
template <class T>
ostream &operator<<(ostream &s, vector<vector<T>> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        s << endl
          << P[i];
    }
    return s << endl;
}
template <class T>
ostream &operator<<(ostream &s, set<T> P)
{
    EACH(it, P) { s << "<" << *it << "> "; }
    return s << endl;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, map<T1, T2> P)
{
    EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; }
    return s << endl;
}
template <class T>
void show(vector<T> v)
{
    for (int i = 0; i < v.size(); i++)
    {
        cerr << v[i] << " ";
    }
    cerr << "\n";
}
typedef long long ll;

signed main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    if (a.back() - a[0] >= 2)
    {
        cout << "No" << endl;
        return 0;
    }
    if (a.back() == a[0])
    {
        if (a.back() == 2 || a.back() == 1)
        {
            cout << "Yes" << endl;
        }
        else
        {
            if (n == a[0] + 1 || n >= 2 * a[0])
            {
                cout << "Yes" << endl;
            }
            else
            {
                cout << "No" << endl;
            }
        }
    }
    else if (a.back() - a[0] == 1)
    {
        int idx;
        for (int i = 0; i < n; i++)
        {
            if (a[i] != a[0])
            {
                idx = i;
                break;
            }
        }
        //cerr << idx << endl;
        if (idx == a[0] && a[n - 1] == a[n - 2])
        {
            cout << "Yes" << endl;
        }
        else
        {
            if (n-idx >= 2*(a.back() - idx) && idx<a[0]){
                cout << "Yes" << endl;
            }
            else cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = Integer.parseInt(stdIn.next());
        int[] digit = new int[n];
        Arrays.fill(digit, -1);
        int m = Integer.parseInt(stdIn.next());
        int[] s = new int[m];
        int[] c = new int[m];
        boolean check = true;
        for (int i = 0; i < m; i++) {
            s[i] = Integer.parseInt(stdIn.next());
            c[i] = Integer.parseInt(stdIn.next());
            if (digit[s[i] - 1] != -1 && digit[s[i] - 1] != c[i]) {
                check = false;
            }
            digit[s[i] - 1] = c[i];
        }
        if (n != 1 && digit[0] == 0) {
            check = false;
        }

        int ans = 0;
        if (check) {
            if (m != 0) {
                for (int i = 0; i < n; i++) {
                    if (i == 0 && digit[i] == -1) {
                        ans += Math.pow(10, n - 1);
                    } else if (digit[i] != -1) {
                        ans += digit[i] * Math.pow(10, n - i - 1);
                    }
                }
            } else if (m == 0 && n != 1) {
                ans = (int)Math.pow(10, n - 1);
            }
            System.out.println(ans);
        } else {
            System.out.println(-1);
        }
    }
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
int64_t c(vector<int64_t> &f,vector<int64_t> &fi,int p,int a,int b){
  if(b<0||b>a)
    return 0;
  return f.at(a)*fi.at(b)%p*fi.at(a-b)%p;
}
int main(){
  int n,k;
  cin>>n>>k;
  int p=1000000007;
  vector<int64_t> f(n+1,1);
  for(int i=1;i<=n;i++)
    f.at(i)=f.at(i-1)*i%p;
  vector<int64_t> fi(n+1,1);
  int q=p-2;
  vector<bool> b;
  while(q>0){
    b.push_back(q%2==1);
    q/=2;
  }
  for(int d=(int)b.size()-1;d>=0;d--){
    fi.at(n)=fi.at(n)*fi.at(n)%p;
    if(b.at(d))
      fi.at(n)=fi.at(n)*f.at(n)%p;
  }
  for(int i=n;i>=1;i--)
    fi.at(i-1)=fi.at(i)*i%p;
  vector<int64_t> a(n);
  for(int i=0;i<n;i++)
    cin>>a.at(i);
  sort(a.begin(),a.end());
  for(int i=n-1;i>=0;i--)
    a.at(i)-=a.at(0);
  int64_t s=0;
  for(int i=0;i<n;i++)
    s=(s+(c(f,fi,p,i,k-1)-c(f,fi,p,n-1-i,k-1)+p)*a.at(i))%p;
  cout<<s<<endl;
}

Measured memory_bytes: 5544
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;
const int mod = 1000000007;

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

	vector<int> a(N+1,0);

	for(int i=0; i<M; i++)
	{
		int index;
		cin>>index;
		a[index] = 1;
	}
	
	vector<int> dp(N+1);

	dp[0] = 1;
	for(int i=0; i<N; i++)
	{
		if(i+1<=N && a[i+1] == 0)
		{
			dp[i+1] += dp[i];
			dp[i+1] %= mod;
		}
		if(i+2<=N && a[i+2] == 0)
		{
			dp[i+2] += dp[i];
			dp[i+2] %= mod;
		}
	}

	cout<<dp[N]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int a,b;
	cin>>a>>b;
	int sum=0;
	if(a==1){
		sum+=300000;
	}else if(a==2){
		sum+=200000;
	}else if(a==3){
		sum+=100000;
	}
	if(b==1){
		sum+=300000;
	}else if(b==2){
		sum+=200000;
	}else if(b==3){
		sum+=100000;
	}
	if(b==1&&a==1){
		sum+=400000;
	}
	cout<<sum<<endl;
	return 0;
}


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

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

    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= N; j++) {
            int k = N - i - j;
            if(k >= 0 && 10000 * k + 5000 * j + 1000 * i == Y) {
                cout << k << " " << j << " " << i << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;

#define rep(i,n) for(ll i = 0; i < n; i++)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define YesNo(a) (a)?cout<<"Yes"<<endl:cout<<"No"<<endl
#define YESNO(a) (a)?cout<<"YES"<<endl:cout<<"NO"<<endl
#define INF (2e9)
#define PI (acos(-1))

int main(void){
    int a,b; cin >> a >> b;
    string sa = to_string(a);
    string sb = to_string(b);
    
    string af_b = "";
    rep(i,a){
        af_b += sb;
    }
    string af_a = "";
    rep(i,b){
        af_a += sa;
    }
    
    cout << MIN(af_a, af_b) << endl;
}


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

using namespace std;

int main() {
	string s;
	int ans;
	bool flag = true;
	cin >> s;
	ans = s.length();
	
	for (int i = ans-1; i > 0; i--) {
		if (i % 2 == 0) {
			for (int j = 0; j < i / 2;j++) {
				if (s[j] == s[j + (i / 2)]) {
					flag = true;
				}
				else {
					flag = false;
					break;
				}

			}
			if (flag) {
				ans = i;
				break;
			}
		}
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
#include <numeric>
#include <functional>
#include <iomanip>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }




int main(int argc, char* argv[])
{
	cout << std::fixed << std::setprecision(10);

	for (;;) {
		int N;

		cin >> N;
		if (cin.fail()) break;

		std::vector<int> V(2 * N);
		for (int i = 0; i < 2 * N; i++) {
			cin >> V[i];
		}
		sort(V.begin(), V.end());

		int result = 0;
		for (int i = 0; i < N; i++) {
			result += min(V[i * 2 + 1], V[i * 2]);
		}
		cout << result << endl;
	}

	return 0;
}


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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int x,y;cin>>x>>y;cout<<x+y/2<<endl;

  return 0;
}


Measured memory_bytes: 256
/* ex8_1 
melo */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 11
typedef struct{
    int size;//最大何個までstackに入るか
    int count;//現在のデータの数
    char data[SIZE];//データ配列
    char *top;//一番上のポインタ
} stack;
void initialize_stack(stack *stk);
void print_stack(stack *stk);
void push(stack *stk,char input);
char pop(stack *stk);
stack stk;
int main(void){
    char key[SIZE],result[SIZE];
    int i;
    initialize_stack(&stk);
    scanf("%s",key);
    for(i=0;i<strlen(key);i++){
        if(key[i]!='B'){
            push(&stk,key[i]);
        }
        else{
            pop(&stk);
        }
    }
    print_stack(&stk);
    return 0;
}
void initialize_stack(stack *stk){
    stk->count=0;
    stk->size=SIZE;
    stk->top=&(stk->data[SIZE]);
}
void push(stack *stk,char input){
    if(stk->count >= stk->size){
        printf("Error: stack overflow. (x=%c)\n", input);
        exit(1);
    }
    else{
        stk->top--;
        *(stk->top)=input;
        stk->count++;
    }
}
char pop(stack *stk){
    char input;
    if(stk->count<=0){
        return '\t';
    }
    else{
        input=*(stk->top);
        stk->top++;
        stk->count--;
        return input;
    }
}
void print_stack(stack *stk){
    char *ptr;
    ptr =stk->top;
    ptr+=stk->count-1;
    for(int i=stk->count-1;i>=0;i--){
        printf("%c", *ptr--);
    }
    printf("\n");
}


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

struct UnionFind{
    vector<int> par;
    int cnt;
    UnionFind(int n) : par(n, -1), cnt(n) {}
    void unite(int x, int y){
        x = find(x); y = find(y);
        if(x != y){
            if(par[y] < par[x]) swap(x, y);
            par[x] += par[y]; par[y] = x; cnt--;
        }
    }
    int find(int x){
        return par[x] < 0 ? x : par[x] = find(par[x]);
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    int size(int x){
        return -par[find(x)];
    }
    int size(){
        return cnt;
    }
};

int main(){
    int n, k, l;
    cin >> n >> k >> l;
    UnionFind uf1(n), uf2(n);
    int p, s;
    for(int i = 0; i < k; i++){
        cin >> p >> s;
        p--; s--;
        uf1.unite(p, s);
    }
    for(int i = 0; i < l; i++){
        cin >> p >> s;
        p--; s--;
        uf2.unite(p, s);
    }
    map<pair<int, int>, int> mp;
    for(int i = 0; i < n; i++){
        mp[make_pair(uf1.find(i), uf2.find(i))]++;
    }
    for(int i = 0; i < n; i++){
        cout << mp[make_pair(uf1.find(i), uf2.find(i))];
        cout << (i == n - 1 ? "\n" : " ");
    }
    return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false

int totient(int N){
    if(N<0){
        return 0;
    }
    int R = N;
    for(int i=2;i*i<=N;i++){
        if(N%i==0){
            R -= R/i;
            while(N%i==0){
                N/=i;
            }
        }
    }
    if(N>1){
        R -= R/N;
    }
    return R;
}

long long power(long long b,long long e){
    long long r=1;
    while(e){
        if(e&1){
            r=(r*b)%MOD;
        }
        b=(b*b)%MOD;
        e >>=1;
    }
    return r;
}

signed main(void){
    int N,K;
    cin >> N >> K;
    int Ans=0;
    for(int i=1;i<=K;i++){
        int b = power(K/i,N);
        int phi = totient(i);
        int r = (b*phi)%MOD;
        //cout << b MM phi MM r << endl;
        Ans=(Ans+r)%MOD;
    }
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve()
{
    int n;
    cin>>n;
    vector<int> ar(n);
    for(auto &i:ar)
        cin>>i;
    map<int,int> mp;
    for(int i=0;i<n;i++)
        mp[ar[i]+i]++;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(mp.count(i-ar[i]))
        {
            ans+=mp[i-ar[i]];
        }
    }
    //ans/=2;
    cout<<ans;
}
int32_t main()
{
    _FAST
    int t;
    t=1;
    //cin>>t;
    while(t--)
        solve();
    
    return 0;
}

Measured memory_bytes: 17100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
ll pow_mod(ll n,ll k,ll m){
  ll res=1;
  for(;k>0;k>>=1){
    if(k&1){
      res=(res*n)%m;
    }
    n=(n*n)%m;  
  }
  return res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin >> n;
    vector<int> c(n);
    for(int i=0;i<n;i++){
        int b;cin >> b;
        c[i]=b;
    }
    sort(c.begin(),c.end());
    ll ans=0;
    for(int i=0;i<n;i++){
        (ans+=c[i]*(n+1-i)%mod)%=mod;
    }
    (ans*=pow_mod(4,n-1,mod))%=mod;
    cout << ans << endl;
}

Measured memory_bytes: 1024
n = int(input())
w=[]
for i in range(n):
    w.append(input())
a=0
for i in range(1,n):
    if w.count(w[i])==1 and w[i-1][-1]==w[i][0]:
       a += 1
    else:
        print('No')
        break
    if a==n-1:
        print('Yes')
    else:
        pass

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; ++i){
    cin >> a[i];
  }
  vector<int> d(N);
  int M = 0;
  for(int i = N; i > 0; --i){
    int tmp = i;
    int cnt = 0;
    while(tmp <= N){
      cnt += d[tmp-1];
      tmp += i;
    }
    if(cnt%2 != a[i-1]) d[i-1] = 1, M++;
  }
  cout << M << endl;
  for(int i = 0; i < N; ++i){
    if(d[i] == 1) cout << i+1 << " ";
  }
  cout << endl;
}


Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    while(true){
        int h,w;
        cin >> h >> w;
        if(h==0&&w==0) break;
        for(int i = 0; i < h; ++i){
            for(int j = 0; j < w; ++j){
                if(i == 0 || i == h-1 || j == 0 || j == w-1){
                    cout << '#';
                }else{
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 2972
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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 cnt[200010];
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    rep(i,N-1){
        int a; cin >> a;
        a--;
        cnt[a]++;
    }
    rep(i,N){
        cout << cnt[i] << "\n";
    }
}

Measured memory_bytes: 5128
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

const int INF = 100000000;
const int N = 100000;

int dp[N][10][2];
//pos, left, right, foot
//0 == left, 1 == right

bool isCorrect(int l, int r){
  if(r == 1 || r == 4 || r == 7){
    if(l != 1 && l != 4 && l != 7) return false;
  }else if(r == 2 || r == 8){
    if(l == 3 || l == 6 || l == 9) return false;
  }
  return true;
}

main(){
  string input;
  while(cin >> input){
    if(input == "#") break;
    fill(dp[0][0], dp[N-1][10], -1);
    dp[0][input[0]-'0'][0] = dp[0][input[0]-'0'][1] = 0;
    int size = input.size();
    for(int i=0;i<size-1;i++){
      for(int j=0;j<10;j++){
	for(int k=0;k<2;k++){
	  if(dp[i][j][k] < 0) continue;
	  if(k == 0){
	    if(isCorrect(j, input[i+1]-'0')){
	      if(dp[i+1][input[i+1]-'0'][1] < 0) dp[i+1][input[i+1]-'0'][1] = dp[i][j][k];
	      else dp[i+1][input[i+1]-'0'][1] = min(dp[i+1][input[i+1]-'0'][1], dp[i][j][k]);
	    }else{
	      if(dp[i+1][input[i+1]-'0'][0] < 0) dp[i+1][input[i+1]-'0'][0] = dp[i][j][k] + 1;
	      else dp[i+1][input[i+1]-'0'][0] = min(dp[i+1][input[i+1]-'0'][0], dp[i][j][k] + 1);
	    }
	  }else{
	    if(isCorrect(input[i+1]-'0', j)){
	      if(dp[i+1][input[i+1]-'0'][0] < 0) dp[i+1][input[i+1]-'0'][0] = dp[i][j][k];
	      else dp[i+1][input[i+1]-'0'][0] = min(dp[i+1][input[i+1]-'0'][0], dp[i][j][k]);
	    }else{
	      if(dp[i+1][input[i+1]-'0'][1] < 0) dp[i+1][input[i+1]-'0'][1] = dp[i][j][k] + 1;
	      else dp[i+1][input[i+1]-'0'][1] = min(dp[i+1][input[i+1]-'0'][1], dp[i][j][k] + 1);
	    }
	  }
	  //cout << i << ' ' << j << ' ' << k << ' ' << dp[i][j][k] << endl;
	}
      }
    }
    int ans = INF;
    for(int i=0;i<10;i++){
      for(int j=0;j<2;j++){
	if(dp[size-1][i][j]<0) continue;
	ans = min(ans, dp[size-1][i][j]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 8956
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int A, B;
    string S;
    cin >> A >> B >> S;
    
    bool judge = true;
    rep(i, A) {
        if (S[i] == '-') judge = false;
    }
    if (S[A] != '-') judge = false;
    for (int i = A + 1; i < A + B + 1; ++i) {
        if (S[i] == '-') judge = false;
    }
    
    if (judge) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, std::vector<long long> A){
  ll ans = 0;
  ll anss = 0;

  for(ll i=0; i<N; i++)
     A[i] -= (i+1);
  sort(A.begin(), A.end());
  ll x = A[N/2];
  ll y = A[N/2 - 1];
  for(ll i=0; i<N; i++) {
    ans += abs(A[i] - x);
    anss += abs(A[i] - y);
  }
  std::cout << min(anss, ans) << std::endl;
  
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, std::move(A));
  return 0;
}



Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    int N, S1 = 0, S2 = 0, min;
    cin >> N;
    int W[N];
  
    for(int i = 0; i < N; i++){
        cin >> W[i];
    }  
    
    
    min = 10000000;
    for(int T = 1; T < N; T++){
        for(int i = 0; i < N; i++){
            if(i <= T)
                S1 += W[i];
            else
                S2 += W[i];
        }
        if(min > abs(S1 - S2))
            min = abs(S1 - S2);
        S1 = 0;
        S2 = 0;
    }
    
    cout << min << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll d,n;
	scanf("%lld%lld",&d,&n);
	printf("%lld",n+n/100);
	rep(i,0,d)printf("00");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,A,B;
    cin >> N >> A >> B;
    int cnt[3] = {};
    rep(i,0,N){
        int a;
        cin >> a;
        if(a <= A)cnt[0]++;
        else if(a <= B)cnt[1]++;
        else cnt[2]++;
    }
    cout << min({cnt[0], cnt[1], cnt[2]}) << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
ans = float("inf")
E = s.count('E')
W = 0
for i in s:
  if i == 'E':
    E -= 1
    ans = min(ans, E+W)
  else:
    W += 1
    ans = min(ans, E+W-1)
print(ans)

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

int main() {
  int n, k; cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int t; cin >> t;
  }
  cout << ((n - 1) + (k - 2)) / (k - 1) << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> ans(N + 1);
  for (int x = 1; x <= 100; x++) {
    for (int y = 1; y <= 100; y++) {
      for (int z = 1; z <= 100; z++) {
        int tmp = x * x + y * y + z * z + x * y + y * z + z * x;
        if (tmp < N + 1) ans.at(tmp)++;
      }
    }
  }
  for (int i = 1; i < N + 1; i++) {
    cout << ans.at(i) << "\n";
  }
}

Measured memory_bytes: 3588
from sys import stdin
N = int(stdin.readline().rstrip())
A = []
for i in range(N):
    A.append(int(input()))
    
ans = 0
for i in range(N-1):
    ans += (A[i]//2)
    A[i+1] -= min(A[i+1],A[i]%2)
    ans += min(A[i+1],A[i]%2)
ans += (A[-1]//2)
print(ans)

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int cnt = 0;
    for (int j = 0; j + i < N; j++) {
      if (S.at(j) == S.at(j + i)) cnt++;
      else cnt = 0;
      ans = max(ans, min(i, cnt));
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int mt[10];
	int i, j, buf;

	for (i = 0; i < 10; i++){
		scanf("%d", &mt[i]);
	}

	for (i = 0; i < 9; i++){
		for (j = i+1; j < 10; j++){
			if (mt[j] >= mt[i]){
				buf = mt[i];
				mt[i] = mt[j];
				mt[j] = buf;
			}

		}	
	}

	for (i = 0; i < 3; i++){
		printf("%d\n", mt[i]);
	}
	return 0;
}

Measured memory_bytes: 2744
import Control.Monad

grade m f r
  | m == -1 || f == -1 = "F"
  | m + f >= 80 = "A"
  | m + f >= 65 = "B"
  | m + f >= 50 = "C"
  | m + f >= 30 = if r >= 50 then "C" else "D"
  | otherwise = "F"

toIntList list = map (\x -> read x :: Int) . words $ list

main = do
  a <- return . lines =<< getContents
  mapM_ putStrLn $ map (\[m, f, r] -> grade m f r) $ filter (/= [-1, -1, -1]) $ map toIntList a

Measured memory_bytes: 4040
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int count = 0;
		if (s.charAt(0) == '1') count++;
		if (s.charAt(1) == '1') count++;
		if (s.charAt(2) == '1') count++;
		System.out.println(count);
		sc.close();
	}
}


Measured memory_bytes: 21844
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]
del_list = []
n = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            break
    else:
        del_list.append(i)
for i in reversed(del_list):
    del a[i]
del_list = []
for j in range(len(a[0])):
    for i in range(len(a)):
        if a[i][j] == "#":
            break
    else:
        del_list.append(j)
for j in reversed(del_list):
    for i in range(len(a)):
        del a[i][j]
for i in range(len(a)):
    ans = ""
    for j in range(len(a[0])):
        ans += a[i][j]
    print(ans)


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

using namespace std;

#define pan(i,n) for(int i=0;i<n;i++)
#define pans(i,n,a) for(int i=a;i<n;i++)
#define ll long long int
#define vi vector<ll>
#define vl vector<ll>
#define pb push_back
#define INF 1000000007
#define PI 3.141592653
#define inf 100007
#define pll pair<ll,ll>
#define pii pair<int,int>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

int main(){
    ll n,res=0;
    cin>>n;
    vl v(n),psum;
    pan(i,n){
        cin>>v[i];
        if(i==0) psum.pb(v[i]);
        else psum.pb(psum[i-1]+v[i]);
    }
    sort(psum.begin(),psum.end());
    pan(i,(int)psum.size()){
        if(psum[i]==0) res++;
        int x=lower_bound(psum.begin()+i+1,psum.end(),psum[i])-psum.begin(),y=upper_bound(psum.begin()+i+1,psum.end(),psum[i])-psum.begin();
        if (psum[x]==psum[i]) res+=(y-x);
    }
    cout<<res;
}

Measured memory_bytes: 3956
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

bisectRight :: Ord a => (Int -> a) -> a -> Int -> Int -> Int
bisectRight f x lo hi
  | lo >= hi  = lo
  | x < f mid = bisectRight f x lo mid
  | otherwise = bisectRight f x (mid+1) hi
  where
    mid = lo + (hi - lo) `div` 2
main = do
  [n, m, k] <- getIntList
  as <- getIntVec n
  bs <- getIntVec m

  ta <- VM.new (n+1)
  VM.set ta (0::Int)
  tb <- VM.new (m+1)
  VM.set tb (0::Int)

  forM_ [1..n] $ \i -> do
    let a = as V.! (i-1)
    t <- VM.read ta (i-1)
    VM.write ta i (t+a)

  forM_ [1..m] $ \i -> do
    let b = bs V.! (i-1)
    t <- VM.read tb (i-1)
    VM.write tb i (t+b)

  va <- V.freeze ta
  vb <- V.freeze tb

  let solve :: Int -> Int -> Int
      solve j res
        | j > n = res
        | otherwise =
            let elapsed = va V.! j
            in if elapsed > k
               then res
               else let rest = k - elapsed
                        x = bisectRight (\x -> vb V.! x) rest 0 m
                        nb = if vb V.! x <= rest
                          then x
                          else x-1
                    in solve (j+1) (max res (j+nb))

  print $ solve 0 0


Measured memory_bytes: 21456
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = Tuple{Int,Int}[(0,0) for i in 1:n]
	for i in 1:n
		p,q = readline() |> split |> parseMap
		a[i] = (p,q)
	end
	a = sort(a,by=x->x[1]+x[2],rev=true)
	x = 0
	y = 0
	for i in 1:n
		if i%2==1
			x+=a[i][1]
		else
			y+=a[i][2]
		end
	end
	println(x-y)
end

main()

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

int main(){
    int a,b;
    cin>>a>>b;
    int ans;
    ans=((b-1)+(a-1)-1)/(a-1);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3612
n, l = map(int, input().split())
tot = 0
for i in range(0, n):
    tot += l + i
dif = 100000000000
ans = 0
for i in range(0, n):
    a = tot - (l + i)
    if abs(tot - a) < dif:
        ans = a
        dif = abs(tot - a)
print(ans)

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

int N, M;
int a[200005];
map<int,int> mp;

int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		int dt; scanf("%d", &dt);
		mp[dt]++;
	}
	scanf("%d", &M);
	for (int i = 1; i <= M; i++) {
		int dt; scanf("%d", &dt);
		if (!mp[dt]) { puts("NO"); return 0;}
		mp[dt]--;
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 9600
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ele int
using namespace std;
#define maxn 110
ele n,a,b,f[maxn][maxn];
ele solve(ele i,ele j){
	ele &res=f[i][j];
	if (~res) return res;
	if ((i==0 && j==1) || (i==n-1 && j==n-2)) return res=0;
	res=0;
	if (i && i-1!=j) res=res || !solve(j,i-1);
	if (i<n-1 && i+1!=j) res=res || !solve(j,i+1);
	return res;
}
int main(){
	scanf("%d%d%d",&n,&a,&b); --a,--b;
	memset(f,-1,sizeof(f));
	puts(solve(a,b)?"Alice":"Borys");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
	int num_student;
	int *data;
	int i,j;
	double alpha, alpha_square = 0 , m = 0, sum = 0;
	
	while(1){	
		scanf("%d", &num_student);
		if(num_student == 0)
			return 0;
		
		data = malloc(sizeof(int) * num_student);
		
		for(i=0 ; i < num_student ; i++){
			scanf("%d", &data[i]);
			m += data[i];
		}
		m /= num_student;
		//printf("m=%f\n", m);
		
		for(i=0 ; i < num_student ; i++){
			sum += pow(data[i] - m, 2);
			//printf("i=%d:sum=%f\n", i, sum);
		}
		alpha_square = sum / num_student;
		//printf("alpha_square=%f\n", alpha_square);
		
		alpha = sqrt(alpha_square);
		printf("%f\n", alpha);
		
		alpha = 0;
		alpha_square = 0;
		m = 0;
		sum = 0;
		free(data);
		
	}
	return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define intMax 2147483647
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repp(ii, aa, bb) for (int ii = aa; ii >= bb; ii--)
#define be(a) (a.begin(), a.end())
#define rbe(p) (p.rbegin(), p.rend())
#define pb push_back

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vector<int> A(n), dp(n, -1);
    rep(i, 0, n)
    {
        cin >> A[i];
    }
    dp[0] = 0;
    dp[1] = abs(A[0] - A[1]);
    rep(i, 2, n)
    {
        dp[i] = min(dp[i - 1] + abs(A[i - 1] - A[i]), dp[i - 2] + abs(A[i - 2] - A[i]));
    }
    cout << dp[n - 1];
}

Measured memory_bytes: 1024
N,M=map(int,input().split())
graph=[[]for _ in range(N)]
deg=[0]*N
for i in range(M):
    xx,yy=map(int,input().split())
    graph[xx-1].append(yy-1)
    deg[yy-1]+=1

que=[]
dp=[0]*N

for i in range(N):
    if deg[i]==0:
        que.append(i)
while len(que)>0:
    k=que.pop(0)
    for x in graph[k]:
        deg[x]-=1
        if deg[x]==0:
            que.append(x)
            dp[x]=max(dp[x],dp[k]+1)
print(max(dp))


Measured memory_bytes: 22704
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1000050;
//ここまでテンプレ
int main(){
	ll N;
	cin>>N;
	ll mini=INFLL;
	for(int i=0;i<N;i++){
		ll a;
		cin>>a;
		if(a%2){
			cout<<"first"<<endl;
			return 0;
		}
	}
	cout<<"second"<<endl;
	return 0;
}

Measured memory_bytes: 256