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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int result = 0;
		for(int i = 1; i <= n; i += 2){
			int count = 0;

			for(int j = 1; j <= i; j++){
				if(i % j == 0){
					count++;
				}
			}

			if(count == 8){
				result++;
			}
		}

		System.out.println(result);

	}

}


Measured memory_bytes: 23252
#include<queue>
#include<stdio.h>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define SIZE 1010
using namespace std;

typedef pair<int,int> P;

char mass[SIZE][SIZE];
int  data[SIZE][SIZE];
int  dx[4]={1,0,-1,0};
int  dy[4]={0,1,0,-1};
int  sx,sy,gx,gy;
int  h,w,n;
int  k;
int  sum=0;

int bfs();

int main(){

  int i,j;

  cin>>h>>w>>n;

  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      cin>>mass[i][j];
    }
  }

  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(mass[i][j]=='S'){
	sx=j;
	sy=i;
	break;
      }
    }
  }

  for(k=1;k<=n;k++){
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(mass[i][j]-'0'==k){
	  gx=j;
	  gy=i;
	}
      }
    }
    sum+=bfs();
    sx=gx;
    sy=gy;
  }                      
  
  cout<<sum<<endl;
  
  return 0;
}
int bfs(){

  int i,j;
  queue<P> que;

  memset(data,-1,sizeof(data));

  que.push(P(sy,sx));
  data[sy][sx]=0;

  while(!que.empty()){

    P p=que.front();
    que.pop();

    if(p.first==gy && p.second==gx){
      return data[p.first][p.second];
    }

    for(i=0;i<4;i++){
      int nx=p.second+dx[i];
      int ny=p.first+dy[i];

      if(nx>=0 && nx<w && ny>=0 && ny<h && mass[ny][nx]!='X' && data[ny][nx]==-1){
	que.push(P(ny,nx));
	data[ny][nx]=data[p.first][p.second]+1;
    }
   }
  }
 return 0;
}

Measured memory_bytes: 6192
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define mod 1000000007ll
#define mod1 998244353ll
#define endl '\n'
#define inf ((ll)1e18+1)
#include<chrono>
using namespace chrono;
mt19937_64 rng(high_resolution_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define debr(x,y) {cout<<"-->  "<<#x<<" to "<<#y<<" :  "; auto itr=x; while(itr!=y) cout<<(*itr++)<<' '; cout<<endl; }
#define deba(x) {cout<<"-->  "<<#x<<" :  "; for(auto ele:(x)) cout<<ele<<"  "; cout<<endl; }
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s);istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a <<"  ,  ";
    err(++it, args...);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    vector<ll> ar(n);
    for(ll x=0;x<n;x++){
        cin>>ar[x];
    }
    ll curr=1000;
    ll idx=0;
    while(idx<n){
        ll upto=idx+1;
        while(upto<n && ar[upto]>=ar[upto-1]){
            upto++;
        }
        // if(upto==n)break;
        ll share=curr/ar[idx];
        ll rem=curr-share*ar[idx];
        ll earn=share*ar[upto-1];
        curr=rem+earn;
        idx=upto;
    }
    cout<<curr<<endl;
    return 0;

}


Measured memory_bytes: 3652
#include <stdio.h>
int main(){
  int a,b,c,d,e;
  scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
  if(a == 0)
    printf("1");
  if(b == 0)
    printf("2");
  if(c == 0)
    printf("3");
  if(d == 0)
    printf("4");
  if(e == 0)
    printf("5");
  return 0;
}

Measured memory_bytes: 2088
N=int(input())
graph=[[] for i in range(N)]
for i in range(N-1):
    a,b=list(map(int,input().strip().split(' ')))
    a-=1
    b-=1
    graph[a]+=[b]
    graph[b]+=[a]

parent=[-1]*N
checked=[0]*N
dp=[[0]*2 for i in  range(N)]

from collections import deque
q=deque([0])
checked[0]=1
bfs=[]
while q:
    node=q.popleft()
    bfs+=[node]
    for adj in graph[node]:
        if checked[adj]==0:
            parent[adj]=node
            checked[adj]=1
            q+=[adj]

bfs=bfs[::-1]
MOD=10**9+7
for node in bfs:
    temp1=1
    temp2=1
    leaf=1
    for adj in graph[node]:
        leaf=0
        if adj != parent[node]:
            temp1*=(dp[adj][0]+dp[adj][1])
            temp1%=MOD
            temp2*=dp[adj][0]
            temp2%=MOD
    if leaf==1:
        dp[node][0]=1
        dp[node][1]=1
    
    else:
        dp[node][0]=temp1
        dp[node][1]=temp2

print(sum(dp[0])%MOD)
    
    

Measured memory_bytes: 82332
N, L = map(int, input().split())

A = []
for i in range(1, N + 1):
    A.append(L + i - 1)

cur_diff = float('inf') 
ans = float('inf')
Sum = sum(A)
for a in A:    
    tmp = Sum - a
    diff = abs(Sum - tmp)
    if diff < cur_diff:
        cur_diff = diff
        ans = tmp

print(ans)

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

int N, X;
int x[100010];

int main()
{
	cin >> N >> X;
	for (int i = 0; i < N; ++i)
		cin >> x[i];
	sort(begin(x), begin(x) + N);
	set<int> s;
	int ps[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23 };
	for (int i = 0; i < N; ++i) {
		int d;
		if (i) {
			d = abs(x[i] - x[i - 1]);
			s.emplace(d);
			for (auto p : ps) {
				s.emplace(d / p);
			}
		}
		d = abs(x[i] - X);
		s.emplace(d);
		for (auto p : ps) {
			s.emplace(d / p);
		}
	}
	int D = 1;
	for (auto d : s) {
		if (d == 0)
			continue;
		int m = X % d;
		bool b = true;
		for (int j = 0; j < N; ++j) {
			if (x[j] % d != m) {
				b = false;
				break;
			}
		}
		if (b) {
			D = max(D, d);
		}
	}
	cout << D << endl;
	return 0;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b;
  cin >> a >> b;
  ll ans = 0;
  ll cnt = 1;
  while (cnt < b){
    cnt += (a-1);
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;
int N,K;
vector<int> pN;
 
int main(){
  cin>>N>>K;
  int x;
  for(int i =0;i<N;i++){
    cin>>x;
    pN.push_back(x);
  }
  sort( pN.begin(), pN.end() );
  int sum=0;
  for(int i=0;i<K;i++)sum=sum+pN[i];
  cout<<sum<<endl;
}


Measured memory_bytes: 3600
A=int(input())
B=int(input())
C=int(input())
X=int(input())

m=0
for s in range(A+1):
    for t in range(B+1):
        for u in range(C+1):
            if 500*s+100*t+50*u==X:
                m +=1
print(m) 

Measured memory_bytes: 3060
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main(){
	FIO
	
	int a, b, c;
	cin >> a >> b >> c;
	a -= b;
	cout << a % c << '\n';
	return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD (1000*1000*1000+7)
using namespace std;
const int mxN=3002;
double dp[mxN][mxN],p[mxN];

int vis[mxN][mxN],n,m;

double solve(int i,int j)
{
	if(j<0) return 0.0;
	if(i==0) return (j==0);
	if(vis[i][j])
		return dp[i][j];
	vis[i][j]=1;

	return dp[i][j]=(1.0-p[i])*solve(i-1,j)+p[i]*solve(i-1,j-1);

}
int main()
{
	
	
   cin>>n;
   double ans=0.0;
   for(int i=1;i<=n;i++)
    	cin>>p[i];

    for(int i=0;i<=n;i++)
    {
    	int j=n-i;
    	if(i>j)
    		ans+=solve(n,i);
    }
    printf("%.9lf\n",ans);
	return 0;
}



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

int main()
{
  int n;
  cin >> n;
  int a[n];
  int av = 0;
  for (int i = 0; i < n; i++){
    int x;
    cin >> x;
    a[i] = x;
    av += x;
  }
  av = (double)av / (double)n + 0.5;
  int ans = 0;
  
  for (int i = 0; i < n; i++){
    int d = abs(a[i] - av);
    ans += d * d;
  }

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


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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846

    vector<int>ans(10005);
    void solve(){
        for(int i=1;i<=200;i++){
            for(int j=1;j<=200;j++){
                for(int k=1;k<=200;k++){
                    int total=(i*i)+(j*j)+(k*k)+(i*j)+(i*k)+(j*k);
                    if(total<=10001)
                        ans[total]++;
                }
            }
        }
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
            cout<<ans[i]<<"\n";
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 3512
(defun count-left (str)
  (loop for ch across (reverse str)
        with rp = 0
        with id = 0 do
        (if (eq ch #\))
            (incf rp)
            (if (zerop rp)
                (incf id)
                (decf rp)))
        finally (return id)))

(defun count-right (str)
  (loop for ch across str
        with lp = 0
        with id = 0 do
        (if (eq ch #\()
            (incf lp)
            (if (zerop lp)
                (incf id)
                (decf lp)))
        finally (return id)))

(let* ((n (read-line))
       (s (read-line)))
  (declare (ignore n))
  (dotimes (i (count-right s))
    (princ #\())
  (princ s)
  (dotimes (i (count-left s))
    (princ #\)))
  (terpri))


Measured memory_bytes: 15848
#include <stdio.h>

int a, b;

int main(){
    scanf("%d %d", &a, &b);
    
    if(a > b)
        printf("a > b\n");
    else if (a < b)
        printf("a < b\n");
    else
        printf("a == b\n");
    
    return 0;
}


Measured memory_bytes: 2088
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
 
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)
 
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

 
int main() {
    int N; cin >> N;
    vector<int> s(N);
    rep(i,N) cin >> s[i];
    sort(s.begin(), s.end());
    
    int res = accumulate(s.begin(), s.end(), 0);
    if (res % 10 == 0) {
        rep(i,N) {
            if (s[i] % 10 != 0) {
                res -= s[i];
                break;
            }
        }
    }
    if (res % 10 == 0) res = 0;

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
n=int(input())
li=[]
for i in range(n):
  s=input()
  li.append(s)
co=Counter(li)
print("AC x "+str(co["AC"])) 
print("WA x "+str(co["WA"])) 
print("TLE x "+str(co["TLE"])) 
print("RE x "+str(co["RE"])) 

Measured memory_bytes: 16616
#include<stdio.h>

int main()
{
 char s[8];
 int i;
 int count=0;

 for(i=0;i<6;i++)
 {
   scanf("%c",&s[i]);
   if(s[i]=='1') count++;
 }
 printf("%d\n",count);
 return 0;
}


Measured memory_bytes: 128
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  xs <- inpi toDbl
  mapM_ putStrLn $ solve xs

solve :: [Double] -> [String]
solve = map classify

classify :: Double -> String
classify s | s <= 48.0 = "light fly"
           | s <= 51.0 = "fly"
           | s <= 54.0 = "bantam"
           | s <= 57.0 = "feather"
           | s <= 60.0 = "light"
           | s <= 64.0 = "light welter"
           | s <= 69.0 = "welter"
           | s <= 75.0 = "light middle"
           | s <= 81.0 = "middle"
           | s <= 91.0 = "light heavy"
           | otherwise = "heavy"

toDbl :: String -> Double
toDbl s = read s

inpi :: (String -> a) -> IO [a]
inpi f = map f . lines <$> getContents

Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n, m;
ll a[55], b[55], c[55], d[55];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	FOR(i, n) cin >> a[i] >> b[i];
	FOR(i, m) cin >> c[i] >> d[i];
	vector<ll> ans(n);
	FOR(i, n) {
		ll mi = 5000000000;
		int pos = -1;
		FOR(j, m) {
			if (abs(a[i]-c[j]) + abs(b[i]-d[j]) < mi) {
				mi = abs(a[i]-c[j]) + abs(b[i]-d[j]);
				pos = j;
			}
		}
		ans[i] = pos+1;
	}
	FOR(i, n) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define drep(i,cc,n) for(int i=(cc);i<=(n);++i)
#define rep(i,n) drep(i,0,n-1)
#define drrep(i,cc,n) for(int i=(cc);i>=(n);--i)
#define rrep(i,n) drrep(i,0,n-1)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,v.size())if(i==0)cout << v[i];else cout << " " << v[i]; cout << endl;
#define arrprint(v,n) rep(i,n)if(i==0)cout << v[i];else cout << " " << v[i]; cout << endl;
#define matprint(v,n,m) rep(i,n){rep(j,m){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
using ll = long long;
using P = pair<int,int>;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int d;
vector<int> c(26);
vector<vector<int>> s;
vector<int> t;
vector<int> last(26, -1);

ll score(){
    ll res = 0;
    rep(i,d){
        res += s[i][t[i]];
        last[t[i]] = i;
        rep(j,26) res -= c[i] * (i - last[j]);
    }
    return res;
}

int main(){
    cin >> d;
    rep(i,26) cin >> c[i];
    s.resize(d);
    rep(i,d)s[i].resize(26);
    rep(i,d)rep(j,26) cin >> s[i][j];
    t.resize(d);
    rep(i,d) t[i] = i%26;

    // cout << score() << endl;
    rep(i,d)cout << t[i]+1 << endl;

    // cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h> 
// #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define forn(i,o,n) for(int i=o;i<n;i++)
#define int long long
// #define endl "\n"
#define mod 1000000007
#define double long double
#define pb push_back
#define swap(x,y) (x^=y^=x^=y)
using namespace std;
void dfs(vector<vector<int> > &g,vector<int> &visit,vector<int> &dist,int i)
{
    visit[i]=1;
    for(auto j:g[i])
    {
        if(!visit[j])
             dfs(g,visit,dist,j);

         dist[i]=max(dist[i],dist[j]+1);
    }
}

int32_t main(){
     #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout); 
    #endif
    int n,m;
    cin>>n>>m;
    vector<vector<int> > g(n);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].push_back(b);
    }

    std::vector<int> visit(n,0);
    vector<int>dist(n,0);
    for(int i=0;i<n;i++)
    {
        if(!visit[i])
            dfs(g,visit,dist,i);
    }
    int ans=0;
    for(auto j:dist)
        ans=max(ans,j);


    cout<<ans<<endl;

}

Measured memory_bytes: 13632
#include <bits/stdc++.h>
#include <cstdlib>  // abs()
#include <math.h> //M_PI
typedef long long ll;
using namespace std;

int main(){
ll n,ans=0; cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i); a.at(i)-=(i+1); 
  }
sort(a.begin(),a.end());
  int m=n/2;
    for(int i=0;i<n;i++){
ans+=abs(a.at(i)-a.at(m));
    }
cout<<ans<<endl;
}

Measured memory_bytes: 1024
/* code by AbhiTaker
         ____
        /    \
       /  __  \              _______      __       _   _    _____    _____
      /  /  \  \            |__   __|    /  \     | | / /  |  ___|  |  _  \
     /  /____\  \     ___      | |      / /\ \    | |/ /   | |__    | |_)  )
    /  /______\  \   |___|     | |     / /__\ \   |   /    |  __|   |    _/
   /  /        \  \            | |    / /----\ \  | |\ \   | |___   | |\ \
  /__/          \__\           |_|   /_/      \_\ |_| \_\  |_____|  |_| \_\
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define M 1000000007
#define N 1000016
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define inf 9000000000000000000


int main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll a,b,c,maxi = 0,cnt = 0,ans;
    cin>>a>>b>>c;
    maxi = max(a, max(b,c));
    ans = (maxi - a)/2 + (maxi - b)/2 + (maxi-c)/2;
    a += 2*((maxi - a)/2);
    b += 2*((maxi - b)/2);
    c += 2*((maxi - c)/2);
    if( maxi - a == 1)
        cnt++;
    if( maxi - b == 1)
        cnt++;
    if( maxi - c == 1)
        cnt++;
    if(cnt==0)
        cout<<ans<<"\n";
    if(cnt==1)
        cout<<ans + 2<<"\n";
    if(cnt==2)
        cout<<ans + 1<<"\n";

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    char s[100005];
    ll n,ans=0,g=0,p=0;
    scanf("%s",s);
    n=strlen(s);
    rep(i,0,n){
        if(s[i]=='g') g++;
        else p++;
    }
    if(n%2) ans=(ABS(p-g)-1)/2;
    else ans=ABS(p-g)/2;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
cnt = 0

def Merge(As, Ms, l, m, r):
    global cnt
    cnt += r - l
    L = As[l:m] + [float('inf')]
    R = As[m:r] + [float('inf')]
    Lm = Ms[l:m]
    Rm = Ms[m:r]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] <= R[j]:
            As[k] = L[i]
            Ms[k] = Lm[i]
            i += 1
        else:
            As[k] = R[j]
            Ms[k] = Rm[j]
            j += 1
    return

def MergeSort(As, Ms, l, r):
    if r - l > 1:
        m = (l + r) // 2
        MergeSort(As, Ms, l, m)
        MergeSort(As, Ms, m, r)
        Merge(As, Ms, l, m, r)
    return

def Partition(A, p, r):
    i = p - 1
    for j in range(p, r):
        if A[j] <= A[r]:
            i += 1
            A[i], A[j] = A[j], A[i]
            M[i], M[j] = M[j], M[i]
    A[i+1], A[r] = A[r], A[i+1]
    M[i+1], M[r] = M[r], M[i+1]
    return i+1

def QuickSort(A, p, r):
    if p < r:
        m = Partition(A, p, r)
        QuickSort(A, p, m-1)
        QuickSort(A, m+1, r)

n = int(input())
M, A = [], []
for i in range(n):
    a, b = input().split()
    M.append(a)
    A.append(int(b))
As = A[:]
Ms = M[:]
QuickSort(A, 0, n-1)
MergeSort(As, Ms, 0, n)
if M == Ms:
    print('Stable')
else:
    print('Not stable')
for i in range(n):
    print('{} {}'.format(M[i], A[i]))


Measured memory_bytes: 13212
import java.util.Scanner;
 
public class Main {
  
  private static double p = 2 * Math.PI;
 
    public static void main(String[] args) {
      Scanner in = new Scanner(System.in);
      int r = in.nextInt();
        
      in.close();
      
      System.out.println(p * r);
    }
}

Measured memory_bytes: 35980
n, m = map(int, input().split())
pn = list(map(lambda x:int(x)-1, input().split()))
ls = [-1] * n
for i in pn:
    ls[pn[i]] = i
#print(ls)

par = [i for i in range(n)]

def find(x):
    if par[x] == x:
        return x
    else:
        s = find(par[x])
        par[x] = s
        return s

def unite(x,y):
    s = find(x)
    t = find(y)
    if s>t:
        par[s] = t
    else:
        par[t] = s


for _ in range(m):
    x, y = map(lambda x:int(x)-1, input().split())
    unite(ls[x],ls[y])

dic = {}
for i in range(n):
    a = find(i)
    if a in dic:
        dic[a].add(ls[i])
    else:
        dic[a] = set([ls[i]])
#print(dic)
#print(par)
ans = 0
for i in range(n):
    if i in dic[find(i)]:
       ans+=1
print(ans)

Measured memory_bytes: 49508
#include <cmath>
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;

map<ll, ll> prime_fac(ll A)
{
    map<ll, ll> mp{};

    ll root_A = pow(A, 0.5);
    for (ll d = 2; d <= root_A; d++)
    {
        while (A % d == 0)
        {
            mp[d]++;
            A /= d;
        }

        if (A == 1) break;
    }

    if (A != 1) mp[A]++;

    return mp;
}

int main()
{
    ll N, P;
    cin >> N >> P;

    map<ll, ll> pf = prime_fac(P);

    ll ans = 1;
    for (auto k : pf)
    {
        ll p = k.first, e = k.second;
        if (e >= N) ans *= pow(p, e / N);
    }

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

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
ll sieve[1000001]={0},i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p);
p=(p*p);
k>>=1;
}
return a;
}
using namespace std;
  ll countDivisors(ll n) 
{ 
    ll cnt = 0; 
    for (ll i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            if (n / i == i) 
                cnt++; 
  
            else 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
ll cas=1;
 while(tc--)
 {
	ll n;
	cin>>n;
	ll ans=n*(n+1)/2;
	ll x;
	x= 3*(n/3+1)*(n/3)/2+5*(n/5+1)*(n/5)/2-15*(n/15+1)*(n/15)/2;
	cout<<ans-x;
cout<<"\n"; 
 } 
}


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

using namespace std;

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

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

int main() {
  int n;
  scanf("%d", &n);
  map<int, int, greater<int>> cnt;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    cnt[x]++;
  }
  int ret = 0;
  for (auto& it : cnt) {
    int x = it.first, rem = it.second;
    int p = 1;
    while (p <= x) p <<= 1;
    int y = p - x;
    if (y == x) {
      ret += rem / 2;
      continue;
    }
    if (cnt.count(y)) {
      int t = min(rem, cnt[y]);
      rem -= t;
      cnt[y] -= t;
      ret += t;
    }
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 9600
import math
x = int(input())
k = 0
t = 0

if (math.sqrt(8 * x + 1) == math.floor(math.sqrt(8 * x + 1))):
  a = (-1 + math.sqrt(1 + 8 * x))/2
  print(int(a))
else:
  x = (-1 + math.sqrt(1 + 8 * x))//2
  print(int(x) + 1)


Measured memory_bytes: 3060
A = int(input())
B = int(input())
C = int(input())
X = int(input())
X_match_cnt = 0

tmp_sum = 0
for i in range(0, A+1):
    for j in range(0, B+1):
        for k in range(0, C+1):
            tmp_sum = 500 * i + 100 * j + 50 * k
            if tmp_sum == X:
                X_match_cnt += 1
                break
            elif tmp_sum > X:
                break
            else:
                continue

print(X_match_cnt)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto& x : A) cin >> x;
	int sum = 0;
	for (auto x : A) sum ^= x;
	for (auto x : A) cout << (sum^x) << " ";
	cout << endl;
}


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

int main() {
  int x, a, b;
  cin >> x >> a >>b;
  if (abs(x - a) < abs(x - b)) {
    cout << "A" << endl;
  } else {
    cout << "B" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp12
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int A = a[0];
            int B = a[1];
            var res = "No";
            for (int C = 1; C <= 3; C++)
                if ((A * B * C) % 2 == 1)
                    res = "Yes";
            Console.WriteLine(res);                
        }
    }
}

Measured memory_bytes: 13268
al = list(list(map(int, input().split())) for _ in range(3))
n = int(input())
bl = list(int(input()) for _ in range(n))

bingo = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
# for b in bl:
#     if al.count(b) != 0:
#         for i in range(3):
#             for j in range(3):
#                 if al[i][j] == b:
#                     bingo[i][j] = 1
#
# print(bingo)

for i in range(3):
    for j in range(3):
        if bl.count(al[i][j]) > 0:
            bingo[i][j] = 1

for b in bingo:
    if b.count(1) == 3:
        print('Yes')
        exit()

# if bingo[0][0] == 1 and bingo[1][0] == 1 and bingo [2][0] == 1:

for i in range(3):
    if bingo[0][i] == 1 and bingo[1][i] == 1 and bingo [2][i] == 1:
        print('Yes')
        exit()

if bingo[0][0] == 1 and bingo[1][1] == 1 and bingo[2][2] == 1:
    print('Yes')
    exit()

if bingo[0][2] == 1 and bingo[1][1] == 1 and bingo[2][0] ==1:
    print('Yes')
    exit()

print('No')

Measured memory_bytes: 3064
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String postalCode = sc.next();
		boolean okFlag = true;
		if ("-".equals(String.valueOf(postalCode.charAt(a)))) {
			for (int i = 0; i < a; i++) {
				String target = String.valueOf(postalCode.charAt(i));
				if ("1".equals(target) ||  "2".equals(target) || "3".equals(target)
						|| "4".equals(target) || "5".equals(target) || "6".equals(target)
						|| "7".equals(target) || "8".equals(target) || "9".equals(target)
						|| "0".equals(target)) {
				} else {
					okFlag = false;
					break;
				}
			}
			for (int i = a + 1; i < a + b + 1 ; i++) {
				String target = String.valueOf(postalCode.charAt(i));
				if ("1".equals(target) ||  "2".equals(target) || "3".equals(target)
						|| "4".equals(target) || "5".equals(target) || "6".equals(target)
						|| "7".equals(target) || "8".equals(target) || "9".equals(target)
						|| "0".equals(target)) {
				} else {
					okFlag = false;
					break;
				}

			}
		} else {
			okFlag = false;
		}
		if (okFlag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22612
from collections import deque


H, W = map(int, input().split())
M = []
black_before = 0
for i in range(H):
    s = list(input().strip())
    black_before += s.count('#')
    M.append(s)


def bfs(sx, sy):
    dist = [[-1 for _ in range(W)] for _ in range(H)]
    q = deque()
    q.append((sx, sy))
    dist[sy][sx] = 0

    while q:
        x, y = q.popleft()
        for dx, dy in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
            newx, newy = x+dx, y+dy
            if not (0 <= newx < W):
                continue
            if not (0 <= newy < H):
                continue
            if M[newy][newx] == '#':
                continue
            if dist[newy][newx] != -1:
                continue
            q.append((newx, newy))
            dist[newy][newx] = dist[y][x] + 1
    return dist[H-1][W-1]


step = bfs(0, 0)

if step == -1:
    print(-1)
    exit()

black_after = H * W - step - 1
print(black_after - black_before)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll N,K;
    cin >> N >> K;
    vector<pll> dt(N);
    REP(i, N){
        cin >> dt[i].se >> dt[i].fi;
    }

    auto calc = [](ll t, ll x){return t+x*x;};

    RSORT(dt);
    priority_queue<ll,vector<ll>, greater<ll>> q;
    map<int,int> num;
    ll total = 0;

    REP(i, K){
        total += dt[i].fi; //上からK個取ったときの最大値
        if(num[dt[i].se] == 0)
            num[dt[i].se]++;
        else
            q.push(dt[i].fi); //同じ種類が二個目以上のときキューに入れる  

    }
    ll ans = calc(total, num.size());

    //残りのN-K個をチェック
    if(!q.empty())
    for (int i = K; i < N; i++) {
        if(num[dt[i].se]!=0)continue;
        ll f = q.top();q.pop();
        total -= f;
        total += dt[i].fi;
        num[dt[i].se]++;
        chmax(ans, calc(total, num.size()));
    }   
    pr(ans);
}

Measured memory_bytes: 5244
H,W = list(map(int,input().split()))
A = [list(str(input())) for i in range(H)]
 
black = []
 
cnt = 0
 
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            black.append([i,j])
 
length = len(black)
            
while (length < H*W):
    gray = []
    for l in black:
        if l[1] != 0:
            c1 = [l[0],l[1]-1]
            if A[c1[0]][c1[1]] == ".":
                gray.append(c1)
                A[c1[0]][c1[1]] = "#"
        if l[1] != W-1:
            c2 = [l[0],l[1]+1]
            if  A[c2[0]][c2[1]] == ".":
                gray.append(c2)
                A[c2[0]][c2[1]] = "#"
        if l[0] != 0:
            c3 = [l[0]-1,l[1]]
            if  A[c3[0]][c3[1]] == ".":
                gray.append(c3)
                A[c3[0]][c3[1]] = "#"
        if l[0] != H-1:
            c4 = [l[0]+1,l[1]]
            if  A[c4[0]][c4[1]] == ".":
                gray.append(c4)
                A[c4[0]][c4[1]] = "#"
    
    black = [l for l in gray]
    
    cnt += 1
    length += len(black)
    
print(cnt)

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

N = int(input())
S = input().rstrip()

R = [None]*(2*N)
odd = False
for i in range(2*N):
    if S[i] == 'W':
        if odd:
            R[i] = 1
            odd = False
        else:
            R[i] = 0
            odd = True
    else:
        if odd:
            R[i] = 0
            odd = False
        else:
            R[i] = 1
            odd = True
if sum(R) != N:
    print(0)
else:
    ans = 1
    mod = 10**9+7
    num_r = 0
    for i in range(2*N):
        if R[i]:
            num_r += 1
        else:
            ans = (ans*num_r)%mod
            num_r -= 1
    for n in range(1, N+1):
        ans = (ans*n)%mod
    print(ans)

Measured memory_bytes: 4968
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define fst first
#define snd second
using ll = long long;
using I = pair<int, int>;
const int D = 16;

// clang-format off
template <class T, size_t D> struct _Vec { using type = vector<typename _Vec<T, D - 1>::type>; };
template <class T> struct _Vec<T, 1> { using type = vector<T>; };
template <class T, size_t D> using Vec = typename _Vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
// clang-format on

vector<int> split(ll n) {
  vector<int> dig(D);
  for (int i = D - 1; i >= 0; i--) {
    dig[i] = n % 10;
    n /= 10;
  }
  return dig;
}

Vec<int, 3> solveDP(const vector<int>& dig) {
  Vec<int, 3> dp = make_v(D + 1, 2, D * 9 + 1, 0);
  dp[D][0][0] = dp[D][1][0] = 1;
  for (int i = D - 1; i >= 0; i--) {
    for (int big = 0; big < 2; big++) {
      for (int dsum = 0; dsum <= D * 9; dsum++) {
        for (int d = big ? 0 : dig[i]; d <= 9; d++) {
          if (dsum - d < 0) break;
          dp[i][big][dsum] |= dp[i + 1][big | (d > dig[i])][dsum - d];
        }
      }
    }
  }
  return dp;
}

ll solveGreedy(const vector<int>& dig, const Vec<int, 3>& dp, int dsum) {
  if (!dp[0][0][dsum]) {
    return -1;
  }
  ll m = 0;
  bool big = false;
  for (int i = 0; i < D; i++) {
    for (int d = big ? 0 : dig[i]; d <= 9; d++) {
      if (dp[i + 1][big | (d > dig[i])][dsum - d]) {
        m = m * 10 + d;
        big |= d > dig[i];
        dsum -= d;
        break;
      }
    }
  }
  return m;
}

ll f(ll n) {
  auto dig = split(n);
  auto dp = solveDP(dig);
  ll p = 1, q = 0;
  for (int k = 1; k <= D * 9; k++) {
    ll m = solveGreedy(dig, dp, k);
    if (m < 0) continue;
    if (p * k > m * q || (p * k == m * q && p > m)) {
      p = m;
      q = k;
    }
  }
  return p;
}

int main() {
  int K;
  while (cin >> K) {
    vector<ll> res;
    res.push_back(1);
    while (res.size() < K) {
      ll n = res.back();
      res.push_back(f(n + 1));
    }
    for (ll x : res) cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}


//#define int ll
ll N, x;
ll A[2020];
ll mi[2020][2020];
class BColorfulSlimes {
public:

void solve(std::istream& cin, std::ostream& cout) {
    cin >> N >> x;
    memset(mi,0,sizeof(mi));
    _for(i,N)cin >> A[i], mi[i][0] = A[i];
    _for(n,N)_for(d,N-1)mi[n][d+1] = min(mi[n][d], A[(n+d+1)%N]);
    ll res = 1e18;
    _for(d,N){
        ll sum = 0;
        _for(n,N)sum += mi[n][d];
        res = min(res, sum+d*x);
    }
    cout << res << endl;

}
};


#undef int
int main() {
	BColorfulSlimes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 32128
#include <iostream>
#include <sstream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

int main() {
	int A,B; 
	cin >> A>>B;
  int ans=max(A+B,A-B);
  ans=max(ans,A*B);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//Think simple yet elegant.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
const ll maxn=500005;
const ll mod=1e9+7;


int main(){
	fast;
	int n,x,t;
	cin>>n>>x>>t;
	int ans=(n/x)*t;
	if(n%x!=0)
		ans+=t;
	cout<<ans;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int S, a, b;
  cin >> S;
  a=S/100;
  b=S%100;
  if(1<=a && a<=12) {
    if(b==0 || 12<b) {
      cout << "MMYY" << endl;
    }
    if(1<=b && b<=12) {
      cout << "AMBIGUOUS" << endl;
    }
  }
  if(a==0 || 12<a) {
    if(1<=b && b<=12) {
      cout << "YYMM" << endl;
    }
    if(b==0 || 12<b) {
      cout << "NA" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {

	long long int sub_of_ab, a, b, tmp;

	scanf("%lld %lld", &a, &b);
	sub_of_ab = b - a;
	tmp = b;

	for(;sub_of_ab > 0;sub_of_ab--) {
		tmp -= sub_of_ab;
	}

	tmp = -tmp;

	printf("%lld\n", tmp);
	return 0;
}



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

int main()
{
int A, B;
cin >> A >> B;
string s;
cin >> s;
vector<int> p;
for(int i = 0;i < A + B + 1;i++) {
if(s[i] == '-') p.push_back(i);
}
cout << ((int)p.size() == 1 && p[0] == A ? "Yes" : "No") << endl;
}

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


int main() {
	while (1) {
		int x, y;
		cin >> x >> y;
		if (x == 0 && y == 0)
			break;
		else
			if (x < y)
				cout << x << " " << y << endl;
			else
				cout << y << " " << x << endl;
	}
}


Measured memory_bytes: 3068
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	list := getStdinIntArr()
	A := list[0]
	P := list[1]

	P += A * 3
	fmt.Printf("%d\n", P/2)

}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 1024*1024*10)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


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

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

Measured memory_bytes: 8064
INF = 10 ** 9
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [INF] * N
dp[0] = 0
for i in range(1, N):
    for j in range(K):
        if i + j < N:
            dp[i + j] = min(dp[i + j], dp[i - 1] + abs(h[i - 1] - h[i + j]))

print(dp[N - 1])

Measured memory_bytes: 84100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()


int main(){
    int n;
    cin >> n;
    vector<int> A(n), B(n);
    map<int, int> mp;
    for(int i = 0; i < n; i++) {
        cin >> A[i];
        B[i] = A[i];
    }
    sort(all(B));
    for(int i = 0; i < n; i++) {
        mp[B[i]] = i;
    }
    int cnt = 0;
    for(int i = 0; i < n; i++){
        int idx = mp[A[i]];
        if(abs(idx-i) % 2 != 0) cnt++;
    }
    cout << cnt/2 << endl;
    return 0;
}


Measured memory_bytes: 5760
A, B, C, D, E, F = map(int, input().split())

ans = {}


def main():
    MAX_A = F // (100 * A)

    for i in range(MAX_A + 1):
        MAX_B = (F - i * 100 * A) // (100 * B)

        for j in range(MAX_B + 1):
            if i == 0 and j == 0:
                continue

            a = i * A + j * B

            SAT = a * E

            CD = F - a * 100

            SAT_FLG = True

            if CD < SAT:
                SAT_FLG = False

            CD = min(SAT, CD)

            MAX_C = CD // C

            for k in range(MAX_C + 1):
                l = (CD - k * C) // D

                b = k * C + l * D

                if SAT == b:
                    print(a * 100 + b, b)
                    return

                LACK = SAT - b
                if not LACK in ans:
                    # Create New
                    ans[LACK] = (a * 100 + b, b, SAT_FLG)
                elif not ans[LACK][-1]:
                    # SAT_FLG False
                    # Overwrite
                    ans[LACK] = (a * 100 + b, b, SAT_FLG)

    print(" ".join([str(i) for i in ans[min(ans.keys())][:-1]]))
    return


main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>

using namespace std;

const int N = 1234567;

int dp[1100];

int rec(int cur)
{
  if (cur == 0)
    return 1;
  if (cur < 0)
    return 0;
  if (dp[cur] != -1)
    return dp[cur];
  return dp[cur] = rec(cur - 4) | rec(cur - 7);
}

int main()
{
  int n;
  cin >> n;
  memset(dp, -1, sizeof dp);
  bool ans = rec(n);
  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int a[110];

int main()
{
	int i,j,sum,mnc=0x7fffffff;
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	for(i=-100;i<=100;i++){
		sum=0;
		for(j=1;j<=n;j++) sum+=(a[j]-i)*(a[j]-i);
		mnc=min(mnc,sum);
	}
	cout<<mnc<<endl;
 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define mod 1000000000000000000
    #define MOD 		1000000007
    #define ll long long
    #define mp 		make_pair
    #define pb 		push_back
    #define forn(i,n) 	for(ll i=0;i<n;i++)
    #define for1(i,n) 	for(ll i=1;i<=n;i++)
    #define forn1(i,n) 	for(int i=1;i<n;i++)
    #define rep(i,x,n)  for(ll i=x;i<=n;i++)
    #define repr(i,x,j) for(ll i=x;i>=j;i--)
    #define vi vector<ll>
    #define mii map<int,int>
    #define vii vector<pair<int,int>>
    #define vvi vector<vector<int>>
    #define pii pair<int,int>
    #define F first
    #define S second
    #define fill(a,x) memset(a,x,sizeof a);
    #define all(x) x.begin(),x.end()
    #define test ll t;cin>>t;while(t--)
    #define yes cout<<"YES"<<endl
    #define no cout<<"NO"<<endl
    #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define R return 0
    int main()
    {
    	IOS;
        ll n;
        cin>>n;
        string s;
        cin>>s;
        ll cntr=0,cntw=0,cnta=0;
        forn(i,s.size())
        {
            if(s[i]=='W')
            cntw++;
            else if(s[i]=='R')
            cntr++;
        }
        ll ans=min(cntw,cntr);
        forn(i,cntr)
        {
            if(s[i]!='R')
            cnta++;
        }
        ans=min(ans,cnta);
        cout<<ans<<endl;
        R;
    }

Measured memory_bytes: 3732
#include <iostream>

using namespace std;

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

Measured memory_bytes: 3644