akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;
int N;
int A,B,C;
vector<int>l;
long long INF=1000000000;
int dfs (int cur,int a, int b, int c){
    if(cur==N){
        if(a>0 && b>0 && c>0)
        return abs(a-A)+abs(b-B)+abs(c-C)-30;
        else
        return INF;
    }
    int ret0=dfs(cur+1,a,b,c);
    int ret1=dfs(cur+1,a+l[cur],b,c)+10;
    int ret2=dfs(cur+1,a,b+l[cur],c)+10;
    int ret3=dfs(cur+1,a,b,c+l[cur])+10;
    int MP1=min(ret0,ret1);
    int MP2=min(ret2,ret3);
    return min(MP1,MP2);
}


int main(){
cin>>N>>A>>B>>C;

int L;
for(int i=0;i<=N;i++){
cin>>L;
l.push_back(L);
}
cout<<dfs(0,0,0,0)<<endl;


 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans=b-a+1;
    ans-=((b/c)-(a/c));
    if(a%c==0) --ans;
    ans-=((b/d)-(a/d));
    if(a%d==0) --ans;
    ll x=lcm(c,d);
    ans+=((b/x)-(a/x));
    if(a%x==0 && a>=x) ++ans;
    cout << ans << "\n";
    return 0;
}   

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
vector<int>v[200005];
int arr[200005], ans[200005];
int n, q, a, b;
int main(void) 
{
	cin >> n >> q;
	int t = n;
	while (t > 1)
	{
		cin >> a >> b;
		v[b].push_back(a);
		t--;
	}
	for (int i = 1; i <= q; i++)
	{
		int a, b;
		cin >> a >> b;
		arr[a] += b;
	}
	ans[1] = arr[1];
	printf("%d", ans[1]);
	for (int i = 2; i <= n; i++) 
	{
		if (v[i].size() == 0)continue;
		int sum = 0;
		for (int j = 0; j < v[i].size(); j++) 
		{
			int k = v[i][j];
			sum += ans[k];
		}
		ans[i] = sum + arr[i];
		printf(" %d", ans[i]);
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

#define N 100010

using namespace std;

vector<pi> adj[N];
int ans[N];
int maxi=0;

void dfs(int v, int par, int pcolor)
{
    int color = 1;
    for(auto u:adj[v]){
        int nv=u.fi, idx=u.se;
        if (nv==par) continue;
        if (pcolor==color) color++;
        ans[idx] = color;
        maxi = max(maxi, color);
        dfs(nv,v,color);
        color++;
    }
}

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    rep(i, n-1){
        int a,b; cin>>a>>b;
        adj[a].emplace_back(b, i);
    }
    dfs(1,0,0);
    cout<<maxi<<endl;
    rep(i, n-1){
        cout<<ans[i]<<"\n";
    }
    return 0;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint a(n), b(n);
  rep(i, n) cin >> a[i];
  vector<bool> used(n, false);
  bool flag = true;
  rep(i, n) {
    cin >> b[i];
    if(!used[b[i]-1]) used[b[i]-1] = true;
    else flag = false;
  }
  if(flag) cout << "Yes" << endl;
  else {
    cout << "No" << endl;
    rep(i, n) cout << (used[a[i]-1] ? i+1 : 1) << " \n"[i==n-1];
    rep(i, n) cout << (used[a[i]-1] ? i+1 : 2) << " \n"[i==n-1];
  }

  return 0;
}



Measured memory_bytes: 4684
#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
#ifdef _WIN32
#include <windows.h>
#define print(x) PRINT(x, #x)
template<typename T> inline const void PRINT(T VARIABLE, string NAME)
{
#ifndef ONLINE_JUDGE /// ONLINE_JUDGE IS DEFINED ON CODEFORCES
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, 10);
    cerr << NAME << " = " << VARIABLE << '\n';
    SetConsoleTextAttribute(hConsole, 7);
#endif
}
#else
#define print(x) 0
#endif
struct pair_hash
{
    template<typename T1, typename T2>
    size_t operator () (const pair<T1, T2> &p) const
    {
        auto h1 = hash<T1> {}(p.first);
        auto h2 = hash<T2> {}(p.second);
        return h1 ^ h2;
    }
};
typedef long long ll;
typedef unsigned long long ull;
const ll INFLL = 2 * (ll)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
//ifstream fin(".in");
//ofstream fout(".out");
void die()
{
    cout << "NO";
    exit(0);
}
const int NMAX = 2 * 1e5 + 5;
const int MOD = 1e9 + 7; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;

int n;
int patru, doi, unu;

int main()
{
    FASTIO;
    cin >> n;
    for1(i, n)
    {
        int a;
        cin >> a;
        if(a % 4 == 0) patru++;
        else if(a % 2 == 0) doi++;
        else unu++;
    }
    if(patru >= unu || (patru >= unu - 1 && doi == 0)) cout << "Yes";
    else cout << "No";


    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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 main(){
	ll N, X;
	vector<ll> cake;
	cin >> N >> X;
	rep(i, 0, N){
		ll temp;
		cin >> temp;
		cake.push_back(temp);
	}
	ll sum = accumulate(begin(cake), end(cake), 0);
	ll cnt = (X - sum) / (*min_element(begin(cake), end(cake)));

	cout << cnt + N << endl;
	return 0;
}


Measured memory_bytes: 256
k = int(input())
hoge = [
    1,
    1,
    1,
    2,
    1,
    2,
    1,
    5,
    2,
    2,
    1,
    5,
    1,
    2,
    1,
    14,
    1,
    5,
    1,
    5,
    2,
    2,
    1,
    15,
    2,
    2,
    5,
    4,
    1,
    4,
    1,
    51,
]

print(hoge[k - 1])



Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int a = sc.nextInt();
		int[] d = new int[51];
		for (int i = 0;i < n;i++) d[i] = sc.nextInt();
		long[][][] dp = new long[60][60][2510];
		dp[0][0][0] = 1;
		for (int i = 0;i < n;i++) {
			int x = d[i];
			for (int j = 0;j < n;j++) {
				for (int k = 0;k < 2500;k++) {
					if (dp[i][j][k]>0) {
						dp[i+1][j][k] += dp[i][j][k];
						dp[i+1][j+1][k+x] += dp[i][j][k];
					}
				}
			}
		}

		long ret = 0;

		for (int i = 1;i <= n;i++) {
			for (int j = 1;j <= 2500;j++) {
				if (i*a==j&&dp[n][i][j]>0) {
					ret += dp[n][i][j];
				}
			}
		}

		System.out.println(ret);
	}
}

Measured memory_bytes: 128432
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    int pa,pb,pc,pd;
    int ta,tb,tc,td;
    cin >> pa >> pb >> pc >> pd;
    cin >> ta >> tb >> tc >> td;
    int ans = 1e9;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            for(int k = 0; k <= n; k++){
                for(int l = 0; l <= n; l++){
                    if(ta*i+tb*j+tc*k+td*l >= n){
                        ans = min(ans, pa*i+pb*j+pc*k+pd*l);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
ll fenwick[N];
void upd(ll node,ll val){
    while(node<N){
        fenwick[node]=max(fenwick[node],val);
        node+=node&(-node);
    }
}
ll query(ll node){
    ll ans=0;
    while(node>0){
        ans=max(ans,fenwick[node]);
        node-=node&(-node);
    }
    return ans;
}
ll dp[N],h[N],a[N];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    for(ll i=1;i<=n;i++)cin>>h[i];
    for(ll i=1;i<=n;i++)cin>>a[i];
    for(ll i=1;i<=n;i++){
        dp[i]=query(h[i])+a[i];
        upd(h[i] , dp[i]);
        dp[i]=max(dp[i],dp[i-1]);
    }
    cout<<dp[n];
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)
#define adiii \                               
  ios_base::sync_with_stdio(false); \                                      
  cin.tie(NULL);  \
  cout.tie(NULL);									
 
ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}
ll gcd(ll a,ll b) {if (b == 0) return a;return gcd(b, a % b);}

int main(){
	adiii
	string s;cin>>s;
	if(s=="ABC") cout<<"ARC";
	else cout<<"ABC";
	



}


Measured memory_bytes: 3608
#!/usr/bin/env python3

from sys import *
from math import *

N = int(input())
l = list(map(int, input().split()))
gray = 0
brown = 0
green = 0
cyan = 0
blue = 0
yellow = 0
orange = 0
red = 0
counter = 0
min = 0
max = 0

for i in range(N):
   if l[i] >= 1 and l[i] <= 399:
   	   gray = 1
   elif l[i] >= 400 and l[i] <= 799:
   	   brown= 1
   elif l[i] >= 800 and l[i] <= 1199:
   	   green = 1
   elif l[i] >= 1200 and l[i] <= 1599:
   	   cyan = 1
   elif l[i] >= 1600 and l[i] <= 1999:
   	   blue = 1
   elif l[i] >= 2000 and l[i] <= 2399:
   	   yellow = 1   	   
   elif l[i] >= 2400 and l[i] <= 2799:
   	   orange = 1   	   
   elif l[i] >= 2800 and l[i] <= 3199:
   	   red = 1
   elif l[i] >= 3200:
   	   counter += 1

flag_sum = gray + brown + green + cyan + blue + yellow + orange + red

max = counter + flag_sum

if flag_sum >= 1:
   min = flag_sum
if flag_sum == 0:
   min = 1

print(min, max)

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

int main() {
  int N, K, count=0;
  double n, sum, p;
  cin >> N >> K;
  n = (double)1/N;
  for (int i=1; i<=N; i++) {
    int j=i;
    while (j < K) {
      j *= 2;
      count++;
    }
    p = pow(0.5, count);
    //cout << p << endl;
    sum += n * pow(0.5, count);
    count = 0;
  }
  printf("%.16f", sum);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

int adja[101][101], dist[101];

void bfs() {
    int que[100], l = 0, d = 1;
    que[0] = 1;l++;
    while (l > 0) {
        int temp[100], m = 0;
        for (int i = 0; i < l; ++i) {
            int u = que[i];
            if (0 < dist[u] && dist[u] <= d)
                continue;
            dist[u] = d;
            for (int j = 0, v; (v = adja[u][j]) > 0; j++) {
                temp[m++] = v;
            }
        }
        memcpy(que, temp, sizeof(int) * m);
        l = m;
        d++;
    }
}

int main() {
    int n, k, u;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            cin >> adja[u][j];
        }
    }
    bfs();
    for (int i = 1; i <= n; ++i) {
        cout << i << " " << --dist[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n,l,r;
int a[60];
bool uru(int x){
    for(int i=0;i<n;i++){
        if((i)%2!=0 && x%a[i]==0){
            return false;
        }
        if((i)%2==0 && x%a[i]==0){
            return true;
        }
    }
    if(n%2==0) return true;
    else return false;
}
int main(){
    while(1){
        cin>>n>>l>>r;
        int cnt=0;
        if(n==0 && l==0 && r==0) break;
        for(int j = 0;j < n; j++){
            cin>>a[j];
        }
        for(int i = l;i <=r ; i++){
            if(uru(i)) {
                //cout<<i<<endl;
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 3048
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007

int n;

int main(){
  int n=0;
  cin >> n;
  int ans=0;
  REP(i,n){
    int ii=i+1;
    if ((ii>=1)&(ii<10))ans++;
    if ((ii>=100)&(ii<1000))ans++;
    if ((ii>=10000)&(ii<100000))ans++;
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 500000
#define INFTY 1000000001

int a[N];
int l[N],r[N];
int count=0;
void merge(int array[],int left,int mid,int right){
	int n1 = mid-left;
	int n2 = right-mid;
	int i,j,k;
	for(i=0;i<n1;++i) l[i]=array[left+i];
	for(i=0;i<n2;++i) r[i]=array[mid+i];
	l[n1] = r[n2] = INFTY;
	i=j=0;
	for(k=left;k<right;++k){
		count++;
		if(l[i]<=r[j]){
			array[k]=l[i];
			i++;
		}else{
			array[k]=r[j];
			j++;
		}
	}
}

void mergesort(int array[],int left,int right){
	if(left+1<right){
		int mid = (left+right)/2;
		mergesort(array,left,mid);
		mergesort(array,mid,right);
		merge(array,left,mid,right);
	}
}
		
int main(void){
	int n;
	int i;
	
	scanf("%d",&n);
	for(i=0;i<n;++i){
		scanf("%d",&a[i]);
	}
	
	mergesort(a,0,n);
	
	for(i=0;i<n;++i){
		if(i) printf(" ");
		printf("%d",a[i]);
	}
	printf("\n%d\n",count);
	return 0;
}

Measured memory_bytes: 5488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
          ll n,c=0,i;
          set<ll>s;
           cin>>n;
          ll a[n+1];
          vector<ll>v;
         
          for(ll i=0;i<n;i++)
          {
                    cin>>a[i];
                    if(a[i]%2==0)
                          {
                             v.push_back(a[i]);
                          }
          }
          for(i=0;i<v.size();i++)
          {
                    if(v[i]%3!=0 && v[i]%5!=0)
                              c=1;
          }
          if(c==1)
                    cout<<"DENIED";
          else cout<<"APPROVED";
          
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a != b && a != c && b != c) {
    puts("No");
  } else if (a == b && a == c && b == c) {
    puts("No");
  }  else {
    puts("Yes");
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
#define int long long int
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
lli dp[1005][10005] = {};
void solve(long long H, long long N, std::vector<long long> A,
           std::vector<long long> B)
{
  rep(i, N + 1) rep(j, H + 1) dp[i][j] = 1e18;
  dp[0][H] = 0;
  // k=0, .... chmin(dp[i+1][j-A[i]*k], dp[i][j]+i*B[i]);
  // dp[i+1][j] = min(dp[i][j+A[i]*i] + i*B[i])

  rep(i, N) rrep(j, H + 1)
  {
    chmin(dp[i + 1][j], dp[i][j]);
    chmin(dp[i + 1][max(0ll, j - A[i])], dp[i + 1][j] + B[i]);
  }
  cout << dp[N][0] << endl;
}

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

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


Measured memory_bytes: 78464
import bisect


n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
    
longest = [0]
longest[0] = a[0]
for i in range(1, n):
    if longest[-1] < a[i]:
        longest.append(a[i])
    else:
        j = bisect.bisect_right(longest, a[i])
        if longest[j-1] == a[i]:
            longest[j-1] == a[i]
        else:
            longest[j] = a[i]

print(len(longest))


Measured memory_bytes: 10356
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 1000000007
using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int e = max(a, c), f = min(b, d);
    if (e < f) cout << f - e << endl;
    else cout << '0' << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(std::string s){
    string t;
    ll pallow = 0;
    ll N = s.length();
    REP(i, N){
        if(pallow > 0){
            t.push_back('p');
            pallow --;
        }
        else{
            t.push_back('g');
            pallow++;
        }
    }
    ll cnt=0;
    REP(i, N){
        if(t[i]=='p' && s[i]=='g'){
            cnt ++;
        }
        else if(t[i]=='g' && s[i]=='p'){
            cnt --;
        }
    }
    cout << cnt <<endl;
}

int main(){
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


Measured memory_bytes: 640
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;cin >> n;
	n %= 10;
	if(n == 3) cout << "bon\n";
	else if(!n || n == 1 || n == 6 || n == 8) cout << "pon\n";
	else cout << "hon\n";
}


Measured memory_bytes: 3648
n = int(input())

if n == 0: print(0); exit()

minus = False
if n < 0:
    minus = True
    n *= -1

a = [int(x) for x in format(n, "050b")[::-1]] 
m = len(a)

for i in range(m):
    if a[i] and ((i % 2 and not minus) or (not i % 2 and minus)):
        a[i+1] += 1

for i in range(m):
    if a[i] == 2:
        a[i] = 0
        if a[i+1] >= 1:
            a[i+1] -= 1
        else:
            a[i+1] += 1
            a[i+2] += 1

ans = []
flg = False
for x in a[::-1]:
    if x == 1: flg = True
    if flg: ans.append(str(x))

print("".join(ans))


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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
static const double pi = 3.141592653589793;
int main(){
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    double kh = (60*h+m)*2*pi/720;
    double km = m*2*pi/60;
    double ans = sqrt((a*sin(kh)-b*sin(km))*(a*sin(kh)-b*sin(km))+(a*cos(kh)-b*cos(km))*(a*cos(kh)-b*cos(km)));
    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 4124
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main() {
    int N; cin>>N;
    vector<ll> L(N);
    for (int i = 0; i < N; i++){
        cin>>L[i];
    }
    int ans=0;
    for (int i = 0; i < N; i++){
        for (int j = i+1; j < N; j++){
            for (int k = j+1; k < N; k++){
                if(L[i]==L[j]||L[j]==L[k]||L[k]==L[i])continue;
                int l=max(max(L[i],L[j]),L[k]);
                int s=min(min(L[i],L[j]),L[k]);
                int m=L[i]+L[j]+L[k]-l-s;
                if(s+m>l)ans++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int64_t N,A,B; cin>>N>>A>>B;
    vector<int64_t> X(N);
    rep(n,0,N) cin>>X.at(n);

    vector<int64_t> D(N-1);
    rep(n,0,N-1) D.at(n)=X.at(n+1)-X.at(n);

    int64_t ans=0;
    for(auto d:D){
        if(A*d>B) ans+=B;
        else ans+=A*d;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

struct UnionFind{
  vector<int> r,p,yy;
  int k;
  UnionFind(){}
  UnionFind(int size,vector<int> yy,int k):yy(yy),k(k){init(size);}
  void init(int size){
    r.resize(size,0);
    p.resize(size,0);
    for(int i=0;i<size;i++) r[i]=1,p[i]=i;
  }
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  bool unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return 0;
    if(yy[x]&&yy[y]){
      if(!k) return 0;
      //cout<<k<<endl;
      k--;
    }
    if(r[x]<r[y]) swap(x,y);
    if(!yy[x]&&yy[y]) swap(x,y);
    //if(yy[x]||yy[y]) cout<<yy[x]<<" "<<yy[y]<<endl;
    r[x]+=r[y];
    p[y]=x;
    return 1;
  }
};
struct edge{
  int from,to,cost;
  edge(){}
  edge(int from,int to,Int cost):from(from),to(to),cost(cost){}
  bool operator<(const edge& e) const{
    return cost>e.cost;
  }
};
Int kruskal(int N,vector<edge> edges,vector<int> y,int t,int k){
  Int res=0;
  sort(edges.begin(),edges.end());
  UnionFind uf(N+1,y,t-(k+1));
  int cnt=N-1-k;
  //cout<<k<<" "<<cnt<<endl;
  for(int i=0;cnt&&i<(int)edges.size();i++){
    edge e=edges[i];
    if(!uf.same(e.from,e.to)){
      if(uf.unite(e.from,e.to)) res+=e.cost,cnt--;
    }
  }
  return res;
}


signed main(){
  
  Int n,t,k;
  Int cnt=0;
  while(cin>>n>>t>>k,n){
    vector<edge> edges;
    Int sum=0;
    for(Int i=0;i<n-1;i++){
      Int a,b,c;
      cin>>a>>b>>c;
      a--;b--;
      edges.push_back(edge(a,b,c));
      sum+=c;
    }
    
    vector<int> x(t);
    for(Int i=0;i<t;i++) cin>>x[i];
    vector<int> y(n,0);
    for(Int i=0;i<t;i++) y[--x[i]]=1;
    
    cout<<"Case "<<++cnt<<": "<<sum-kruskal(n,edges,y,t,k)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3440
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = SS()
    w = I()

    ans = [S[i] for i in range(0, len(S), w)]
    print(''.join(ans)) 

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9972
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
bc = [list(map(int, input().split())) for _ in range(m)]

bc.sort(reverse=True, key=lambda x:x[1])

i = 0
for b,c in bc:
    for j in range(i, min(n, i+b)):
        if a[j]<c:
            a[j] = c
    i = i+b
print(sum(a))


Measured memory_bytes: 82072
require 'pp'

a, b, c, d = gets.split.map(&:to_i)

turn = 0
loop do
    if turn % 2 == 0
        c -= b
        if c <= 0
            puts "Yes"
            break
        end
    else
        a -= d
        if a <= 0
            puts "No"
            break
        end
    end
    turn += 1
end


Measured memory_bytes: 14496
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mes(a,b) memset((a),(b),sizeof((a)))
#define syio std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
#define lson l, mid, rt << 1
#define rson mid+1, r, rt << 1 | 1
typedef long long ll;
typedef long double real;
typedef pair<int, int> pii;

const int oo = ~0u >> 2;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mxn = 1000003;
inline int read(){
    int x = 0,f = 1;char c = getchar();
    while(!isdigit(c))f = c == '-' ? -1 : 1,c = getchar();
    while(isdigit(c))x = x * 10 + c - '0',c = getchar();
    return x * f;
}
int n, a[mxn];
map<int, int> ct;
vector<int> v[mxn];
bool isnp[mxn];
void init()
{
    isnp[0] = isnp[1] = 1;
    for (int i = 2; i < mxn; ++ i)
    {
        if (isnp[i]) continue;
        v[i].push_back(i);
        for (int j = 2*i; j < mxn; j += i)
        {
            isnp[j] = 1;
            v[j].push_back(i);
        }
    }
}
int main()
{
    syio;
    cin>>n;
    for (int i = 1; i <= n; ++ i) cin>>a[i];
    int f1 = 0, f2 = 0;
    int gd = a[1];
    for (int i = 2; i <= n; ++ i) gd = __gcd(gd, a[i]);
    if (gd == 1) f2 = 1;
    init();
    for (int i = 1; i <= n && !f1; ++ i)
    {
        for (auto it : v[a[i]])
        {
            ct[it] ++;
            if (ct[it] != 1) {f1 = 1; break;}
        }
    }
    if (!f1) cout<<"pairwise coprime"<<endl;
    else if (f2) cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;
    return 0;
}

Measured memory_bytes: 63924
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInt64() int64 {
	var i int64
	if sc.Scan() {
		if num, err := strconv.ParseInt(sc.Text(), 10, 64); err == nil {
			i = num
		}
	}
	return i
}

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(nil, 1000000000000)

	n := nextInt64()
	as := make([]int64, n)

	mod := int64(1e9 + 7)

	for i := int64(0); i < n; i++ {
		as[i] = nextInt64() % mod
	}

	asum := make([]int64, n)
	asum[n-1] = as[n-1]
	for i := int64(1); i < n; i++ {
		asum[n-1-i] = (asum[n-i] + as[n-1-i]) % mod
	}

	ans := int64(0)
	for i := int64(0); i < n-1; i++ {
		ans += as[i] * (asum[i+1]) % mod
		ans = ans % mod
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7452
n, m, k = gets.chomp.split(" ").map(&:to_i)
as = gets.chomp.split(" ").map(&:to_i)
bs = gets.chomp.split(" ").map(&:to_i)

a = [0]
b = [0]

(0..(n-1)).each{ |i|
  a.push (a[i] + as[i])
}
(0..(m-1)).each{ |i|
  b.push (b[i] + bs[i])
}

answer = 0
j = m
(0..n).each{ |i|
  if a[i] > k
    break
  end
  while b[j] > k - a[i]
    j -= 1
  end
  answer = [answer, i + j].max
}

puts answer


Measured memory_bytes: 49260
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
typedef unsigned us;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

const int N=100005;

int n,m,k,num,h,w,l,s,ans[1000][1000];

int main(){
	scanf("%d%d%d",&n,&m,&k);
	h=1;w=1;s=1;
	rep(i,1,k+1) {
		scanf("%d",&num);
		rep(j,1,num+1) {
			ans[h][w]=i;
			if (w==m && s==1) {
				h++;s=-1;
			}else if (w==1 && s==-1) {
				h++;s=1;
			}else w+=s;
		}
	}
	rep(i,1,n+1) {
		rep(j,1,m) printf("%d ",ans[i][j]);
		printf("%d\n",ans[i][m]);
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define inf (1LL<<61)
#define MOD 1000000007
const ll N=2e5+5;
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
ll n;
ll h[100005];
ll cache[100005];
ll dp(ll i)
{
    if(i>n)
        return inf;
    if(i==n)
        return 0;
    ll &ans=cache[i];
    if(ans!=-1)
        return ans;
    ans=inf;
    ans=min(ans,dp(i+1)+abs(h[i+1]-h[i]));
    ans=min(ans,dp(i+2)+abs(h[i+2]-h[i]));
    
    return ans;
}
int main()
{
    IOS;
    cin>>n;
    for(ll i=1;i<=n;i++)
        cin>>h[i];
    
    memset(cache,-1,sizeof(cache));
    
    ll ans=dp(1);
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 4992
a,b,c,d=map(int,input().split())
x=c-a
y=d-b
s=""
s+="U"*y+"R"*x
s+="D"*y+"L"*x
s+="L"+"U"*(y+1)+"R"*(x+1)+"D"
s+="R"+"D"*(y+1)+"L"*(x+1)+"U"
print(s)




Measured memory_bytes: 3060
n = int(input())
r0 = int(input())
r1 = int(input())
min_r = min(r0, r1)
ans = r1 - r0
for _ in range(2, n):
    r = int(input())
    ans = max(ans, r - min_r)
    min_r = min(r, min_r)
print(ans)


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

int n,p[100000];
int bfs(){
  bool used[100000]={};
  deque<P> q;
  q.push_front(P(0,0));
  while(!q.empty()){
    int x=q.front().first,c=q.front().second;q.pop_front();
    if(x==n-1)return c;
    if(x<0||n<=x||used[x])continue;
    used[x]=1;
    if(p[x])q.push_front(P(x+p[x],c));
    else
      for(int i=1;i<7;i++)q.push_back(P(x+i,c+1));
  }
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>p[i];
  cout<<bfs()<<endl;
  return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	public static void main(String args[]){
		Scanner in=new Scanner(System.in);
		ArrayList<Integer> set= new ArrayList<Integer>();
		int tmp;
		ArrayList<Integer> result=new ArrayList<Integer>();
		int n=in.nextInt();
		int r=in.nextInt();
		int c,p;
		while (!(n==0 && r==0)) {
			for (int i=0;i<n;i++) {
				set.add(i+1);
			}
			for (int i=0;i<r;i++) {
				p=in.nextInt();
				c=in.nextInt();
				for (int j=0;j<c;j++) {
					tmp=set.get(n-p-c+1);
					set.add(tmp);
					set.remove(n-p-c+1);
				}
			}
			result.add(set.get(set.size()-1));
			n=in.nextInt();
			r=in.nextInt();
			set.clear();
		}

		for (int i=0;i<result.size();i++) {
			System.out.printf("%d%n",result.get(i));
		}
	}
}

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

int main() {
    string s = "aiueo";
    char c;
    cin >> c;

    string ans = "consonant";
    rep(i, 5) {
        if (s.at(i) == c) {
            ans = "vowel";
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;                                                                                  

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();

        double A = (double)r * r * Math.PI;
        double L = (double)r * 2 * Math.PI;
        System.out.println(String.format("%f", A) + " " + String.format("%f", L));
    }   
}

Measured memory_bytes: 28300
S = input()
N = len(S)
f = 0
for i in range((N-1)//2):
  if S[i] != S[-i-1]:
    f = 1
S_2 = S[:(N-1)//2]
N_2 = len(S_2)
for i in range(N_2//2):
  if S_2[i] != S_2[-i-1]:
    f = 1
if f == 1:
  print("No")
else:
  print("Yes")

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

typedef long long ll;

double a, b, x;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << setprecision(10) << fixed;

    double pi = atan(1) * 4;
    cin >> a >> b >> x;
    x /= a;
    if (x <= a * b / 2) {
        double d = atan2(b, x * 2 / b) * 180 / pi;
        cout << d << endl;
    } else {
        double k = (a * b - x) * 2 / a;
        double d = atan2(k, a) * 180 / pi;
        cout << d << endl;
    }

    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,h[100000];
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>h[i];
    for(int i=n-2;i>=0;i--){
        if(h[i]-1>h[i+1]){
            cout<<"No"<<endl;
            return 0;
        }
        if(h[i]-1==h[i+1])
            h[i]--;
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/irange.hpp>
#include <cmath>
#include <map>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
namespace mp = boost::multiprecision;
typedef long long ll;
const ll M = 1000000007;

int main(){
	mp::cpp_int n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0) {
		cout << (b - a) / 2;
		return 0;
	}
	if (n - b > a - 1) {
		cout << ((b - (a - 1) - 1) - 1) / 2 + (a - 1) + 1;
		return 0;
	}
	cout << n - (a + b - 1) / 2;
	return 0;
}


Measured memory_bytes: 888
h,n=map(int,input().split())
A=[]
AB=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    AB.append((a,b))

maA=max(A)
dp=[float("inf")]*(h+maA+1)
dp[0]=0
for i in range(h+1):
    for a,b in AB:
        dp[i+a]=min(dp[i+a],dp[i]+b)
print(min(dp[h:]))


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

int solve(string s){
  if(s[1]!='['){
    string tmp = s.substr(1,s.size()-2);
    int res = atoi(tmp.c_str()) ;
    return res/2 + res%2;
  }
  int c=0;
  int pre = 1;
  vector<int> list;
  for(int i=1;i<s.size()-1;i++){
    if(s[i]=='['){
      c++;
    }else if(s[i]==']'){
      c--;
    }
    if(c==0&&s[i]==']'){
      list.push_back(solve(s.substr(pre,(i-pre+1))));
      pre=i+1;
    }
  }
  sort(list.begin(),list.end());
  int ans = 0;
  for(int i=0;i<list.size()/2;i++){
    ans += list[i];
  }
  if(list.size()%2==1){
    ans+=list[list.size()/2];
  }
  return ans;
}


int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    cout<<solve(s)<<endl;
  }
}

Measured memory_bytes: 1296
int m[52][52];

solve(i,j){
  m[i][j]=0;
  if(m[i-1][j-1])solve(i-1,j-1);
  if(m[i][j-1])solve(i,j-1);
  if(m[i+1][j-1])solve(i+1,j-1);
  if(m[i-1][j])solve(i-1,j);
  if(m[i+1][j])solve(i+1,j);
  if(m[i-1][j+1])solve(i-1,j+1);
  if(m[i][j+1])solve(i,j+1);
  if(m[i+1][j+1])solve(i+1,j+1);
}

main(){
  int w,h,i,j,r;
  for(;scanf("%d%d",&w,&h),w;printf("%d\n",r)){
    memset(m,0,sizeof(m));
    r=0;
    for(i=1;i<=h;i++)
      for(j=1;j<=w;j++)
        scanf("%d",m[i]+j);
    for(i=1;i<=h;i++)
      for(j=1;j<=w;j++)
        if(m[i][j])solve(i,j),r++;
  }
exit(0);}

Measured memory_bytes: 832
#include <bits/stdc++.h>
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define Rrep(i,y,x) for(ll i=y;i>x;i--)
#define SIZE(a) ll(a.size())
#define vll vector<ll>
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define print(x) cout << (x) << endl
#define printvec(x) for(ll i=0;i<x.size();i++) cout << (x.at(i)) <<' ' 
typedef long long ll;
using namespace std;

vector<ll> f(vector<ll> A, ll N, ll M){
    deque<ll> H;
    vector<ll> L(N);
    H.push_back(0);
    rep(i,1,min(M+1,N)){
        L.at(i)=H.at(0);
        while ( H.size() >0 && A.at(H.at(H.size()-1)) <= A.at(i)){
            H.pop_back();
        }
        H.push_back(i);
    }
    rep(i,M+1,N){
        if (H.at(0)<i-M){
            H.pop_front();
        }
        L.at(i)=H.at(0);
        while ( H.size() >0 && A.at(H.at(H.size()-1)) <= A.at(i)){
            H.pop_back();
        }
        H.push_back(i);
    }
    vector<ll> ans(N);
    rep(i,1,N){
        ans.at(i)=A.at(L.at(i));
    }
    return ans;
}

int main(){
    ll N,M,K;
    cin>>N>>M>>K;
    vector<ll> A(N);
    rep(i,0,N){
        cin>>A.at(i);
    }
    vector<ll> dp(N+1),ndp(N+1);
    ll ans=0;
    vector<ll> B(N+1);
    rep (k,1,K+1){
        B = f(dp,N+1,M);
        rep(i,k,N+1){
            ndp.at(i)=B.at(i)+ k*A.at(i-1);
        }
        dp=ndp;
    }
    rep(i,0,N+1){
        ans=max(ans,dp.at(i));
    }
    print(ans);


}


Measured memory_bytes: 7744
# 入力
N = gets.to_i
x = []
x = gets.split.map(&:to_i)

"自分の解答"
# # xの平均を四捨五入
# m = ((x.inject(:+)).to_f/N.to_f).round

# var = 0
# N.times do |i|
#   var += (x[i]-m)**2
# end
# puts var

"想定解"
ans = 10e6
1.upto 100 do |i|
  var = 0
  N.times do |j|
    var += (x[j]-i)**2
  end
  
  ans = [var, ans].min
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
	int n;
	while(cin>>n,n!=0){
		int a[n+1][n+1];
		for(int i=0;i<n;i++){
			a[n][i]=0;a[i][n]=0;
		}
		a[n][n]=0;
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>a[i][j];
				//cout<<a[i][j]<<" ";
				a[i][n]+=a[i][j];
				a[n][j]+=a[i][j];
			}
			//cout<<endl;
		}
		
		for(int i=0;i<n;i++)a[n][n]+=a[n][i];
		
		for(int i=0;i<n+1;i++){
			for(int j=0;j<n+1;j++){
			printf("%5d",a[i][j]);
			}
			cout<<endl;
		}
		
	}

}

Measured memory_bytes: 1192
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;
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; }

int main(){
    ll k;
    cin>>k;
    lvec a(k);
    rep(i,k) cin>>a[i];
    ll max_n=2,min_n=2;
    bool ok=true;
    if(a[k-1]!=2) ok=false;
    for(int i=k-1;i>0;i--){
        ll s=min_n/a[i],t=max_n/a[i];
        if(s*a[i]%a[i-1]==0) min_n=s*a[i];
        else min_n=s*a[i]+a[i-1]-s*a[i]%a[i-1];
        max_n=(t+1)*a[i]-1-((t+1)*a[i]-1)%a[i-1];
        if(max_n<min_n){
            ok=false;
            break;
        }
    }
    ll s=min_n/a[0],t=max_n/a[0];
    min_n=s*a[0];max_n=(t+1)*a[0]-1;
    if(max_n<min_n) ok=false;
    if(ok) cout<<min_n<<' '<<max_n<<endl;
    else cout<<-1<<endl;
}

Measured memory_bytes: 1152
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;
    static int A;
    static int B;

    static void input()
    {
        cin = new Scanner();
        A = cin.nextInt();
        B = cin.nextInt();
    }
    static void solve()
    {
        input();
        if ((A + B) % 2 == 0)
            WriteLine((A + B) / 2);
        else
            WriteLine("IMPOSSIBLE");
    }

    
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        
        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
 
 
 
class Myon
{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
 
    static Scanner cin;
 
    // ここに回答
    void calc()
    {
        int r = cin.nextInt();
        int S = 3 * r * r;

        Console.WriteLine($"{S}");
    }
}
 
 
 
class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
 
 
    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <ctime>
#include <map>
#include <queue>

using namespace std; using ll=long long; using P=pair<ll,ll>; const int INF=1e9; const ll LNF=1e18;

int main(){
  ll n,m; cin>>n>>m;
  if (n>m) swap(n,m);
  if (n==1&&m==1) {
    cout<<1<<endl;
  } else if (n==1) {
    cout<<m-2<<endl;
  } else {
    cout<<(n-2)*(m-2)<<endl;
  }
}


Measured memory_bytes: 256
import math
A,B,K = map(int,input().split())
Alist = []
Blist = []
ab = max(A,B)
for a in range(1,ab+1):
    aa = A%a
    ba = B%a
    if aa == 0:
        Alist.append(a)
    if ba == 0:
        Blist.append(a)
AB = sorted(set(Alist) & set(Blist))
z = len(AB)
print(AB[z-K])

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

int main(){
  int n;  cin >> n;
  vector<long> a(n+1, 0), b(n+1, 0);
  for(int i=1; i<=n; i++)  cin >> a[i];
  sort(a.begin(), a.end());

  for(int i=1; i<=n; i++)
    b[i] = a[i] + b[i-1];

  long ans = 1;
  for(int i=n-1; i>=1; i--){
    if(b[i]*2 < a[i+1])  break;
    ans++;
  }

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


Measured memory_bytes: 4844
import Data.List
import qualified Data.Vector as V
import qualified Data.IntSet as IS
main=print.solve.map(map read.words).lines=<<getContents
solve([n,m]:ab)=length.filter(f.(0:))$permutations[1..n-1]where
  g=V.accum(flip IS.insert)(V.replicate n IS.empty)$concatMap(\[a,b]->[(a-1,b-1),(b-1,a-1)])ab
  f=all(\(a,b)->IS.member a$g V.! b).(zip=<<tail)

Measured memory_bytes: 5132
#include <bits/stdc++.h>
using namespace std;
#define maxn 200010
#define sz (1<<(26))
int a[maxn];            

int val[maxn];

int dp[sz];

int ans[maxn];

int main(){
    string s;
    cin>>s;
    int n= s.size();
    for (int i=0; i<n; i++) a[i+1]= s[i]-'a';
    for (int i=1; i<=n; i++){
        val[i]= val[i-1];
        val[i]^=(1<<a[i]);
    }

    for (int i=0; i<sz; i++) dp[i]= maxn;
    dp[0]=0;
    for (int i=1; i<=n; i++){
        int t= maxn;
        t= min(t, dp[val[i]])+1;
        for (int j=0; j<26; j++){
            t= min(t, dp[val[i]^(1<<j)]+1);
        }
        ans[i]= t;
        dp[val[i]]= min(dp[val[i]], t);
    }    
    cout<<ans[n]<<endl; 

}

Measured memory_bytes: 265092
//
// Created by munaiyi on 2020/3/8.
//

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

const int maxn = 2e5 + 5;
char shit[maxn];

int main() {
    int n, p;
    scanf("%d%d",&n, &p);
    scanf("%s", shit);
    if(p==2||p==5){
        long long ans = 0;
        for(int i=0;i<n;i++){
            int num = shit[i] - '0';
            if(num%p==0){
                ans += i + 1;
            }
        }
        printf("%lld\n", ans);
        return 0;
    }
    vector<int> cnt(p+1, 0);
    cnt[0]++;
    long long now = 0;
    long long ans = 0;
    long long ten = 1;
    for(int i=n-1;i>=0;i--){
        int num = shit[i] - '0';
        now = (ten * num + now)%p;
        ten = ten * 10 % p;
        //printf("%lld %d\n", now, i);
        ans += cnt[now];
        cnt[now]++;
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 512
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())))

count = 0
for i in range(n):
    summ = 0
    for j in range(m):
        summ = summ + a[i][j] * b[j]
    if summ + c > 0:
        count += 1
print(count)

Measured memory_bytes: 3064