akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int H,W,K;
char A[880][880];

int dist[880][880];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int ans;

void bfs(pair<int,int> start){
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            dist[i][j]=MOD;
        }
    }
    dist[start.first][start.second]=0;
    queue<pair<int,int>> Q;
    Q.push(start);
    while(Q.size()){
        pair<int,int> now=Q.front();
        Q.pop();
        int x=now.first;
        int y=now.second;
        ans=min(ans,(x+K-1)/K);
        ans=min(ans,(y+K-1)/K);
        ans=min(ans,(H-1-x+K-1)/K);
        ans=min(ans,(W-1-y+K-1)/K);
        if(dist[x][y]==K) continue;
        for(int i=0;i<4;i++){
            int nx=x+dx[i];
            int ny=y+dy[i];
            if(nx<0||ny<0||nx>=H||ny>=W) continue;
            if(dist[nx][ny]<MOD) continue;
            if(A[nx][ny]=='#') continue;
            dist[nx][ny]=dist[x][y]+1;
            Q.push(make_pair(nx,ny));
        }
    }
    return;
}


int main(){
  cin>>H>>W>>K;
  pair<int,int> start;
  for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
          cin>>A[i][j];
          if(A[i][j]=='S') start=make_pair(i,j);
      }
  }
  ans=100000;
  bfs(start);

  cout<<ans+1<<endl;

  return 0;
}


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

/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <ctype.h>
*/


using namespace std;

typedef pair<int , int > pii;
typedef pair<long , long> pll;
typedef pair<pii , int > piii;
typedef pair<pll , long > plll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector <pii> vii;
typedef vector<pll> vll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned long long int ulli;
typedef long long int lli;
typedef double d;
typedef float f;
typedef string s;
typedef char ch;
typedef pair<int,ll> pill;

#define loop(n) for(int i = 0; i < (n); i++)
#define lp(x , s , e) for(int x = (s); x < (e); x++)
#define lpe(x , s , e) for(int x = (s); x <= (e); x++)
#define readline(s) getline(cin,s)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define clr(x , val) memset((x) , (val) , sizeof(x))
#define endl '\n'

ll power(ll a, ll b)
{
    ll res = 1;
    for(int i = 0; i<b; i++)
       res *= a;

    return res;
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	int a , b;
	cin >> a >> b;
	cout << (a - 1) * (b - 1) << endl;
    return 0;
}


Measured memory_bytes: 256
/*
    Created by Ezio112
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<ll> vll;
ll inf(1e18);
#define mod ll(1e9+7)
//#define mod ll(998244353)
#define ff first
#define ss second
ll power(ll a,ll b)
{
	if(!b)
		return 1;
	ll dp=power(a,b/2)%mod;
	
	if(b&1) return (((dp*dp)%mod)*a)%mod;
	
	return (dp*dp)%mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll test=1;
    //cin>>test;

    while(test--)
    {
		ll n;
		cin>>n;
		
		vector<ll> vec(n);
		for(ll &x:vec)
			cin>>x;
			
		vector<short int> dp(2000005);
		for(ll x:vec)
			++dp[x];
			
		for(ll i=1;i<dp.size();++i)
		{
			if(dp[i]==0)
				continue;
				
			for(ll j=2*i;j<dp.size();j+=i)
				dp[j]=0;
		}
		ll sum=0;
		for(ll x:dp) if(x==1)
			sum+=x;
		cout<<sum;
	}
	return 0;
}


Measured memory_bytes: 8704
#include <iostream>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) if (scanf("%d", &v)<1);

int main() {
  int N; in(N);

  int four = 0, two = 0;
  rep(i, N) {
    int a; in(a);
    if (a % 4 == 0)
      ++four;
    else if (a % 2 == 0)
      ++two;
  }
  int nobody = N - two - four;
  if (two > 0 && four >= nobody || two == 0 && four + 1 >= nobody)
    printf("Yes\n");
  else
    printf("No\n");


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    long long sum=0;
    for(i=1;i<=n;i++)
    {
        if(i%3==0||i%5==0||i%15==0)
        {
            continue;
        }
        else
        {
            sum=sum+i;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3668
#include<stdio.h>

int gcd(int x,int y){
	int tmp;
	if(x<y){
		tmp = x;
		x = y;
		y = tmp;
	}
	while(x%y){
		tmp = y;
		y = x%y;
		x = tmp;
	}
	return y;
}

int lcm(int x,int y){
	int la;
	la = (double)x*y/gcd(x,y);
	return la;
}

int main()
{
	int a,b;
	while(~scanf("%d%d",&a,&b)){
		printf("%d %d\n",gcd(a,b),lcm(a,b));
	}
	return 0;
}

Measured memory_bytes: 596
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

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

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func sum(n int, q [][]int) int {
	res := 0
	for i := 0; i < 2; i++ {
		for j := 1; j < len(q[i]); j++ {
			res += abs(q[i][j] - q[i][j-1])
		}
	}
	return res
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	a := nextInts(n)
	sort.Sort(sort.IntSlice(a))

	// 大小の順
	q1 := make([][]int, 2)
	for i := range q1 {
		q1[i] = make([]int, 0)
	}
	q1[0], q1[1] = append(q1[0], a[0]), append(q1[1], a[0])
	for l, r := 1, n-1; l <= r; {
		q1[0] = append(q1[0], a[r])
		r--
		if l <= r {
			q1[1] = append(q1[1], a[r])
			r--
		}
		if l <= r {
			q1[0] = append(q1[0], a[l])
			l++
		}
		if l <= r {
			q1[1] = append(q1[1], a[l])
			l++
		}
	}

	// 小大の順
	q2 := make([][]int, 2)
	for i := range q2 {
		q2[i] = make([]int, 0)
	}
	q2[0], q2[1] = append(q2[0], a[n-1]), append(q2[1], a[n-1])
	for l, r := 0, n-2; l <= r; {
		q2[0] = append(q2[0], a[l])
		l++
		if l <= r {
			q2[1] = append(q2[1], a[l])
			l++
		}
		if l <= r {
			q2[0] = append(q2[0], a[r])
			r--
		}
		if l <= r {
			q2[1] = append(q2[1], a[r])
			r--
		}
	}

	puts(max(sum(n, q1), sum(n, q2)))
}


Measured memory_bytes: 7552
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
int main() {
	int k;
	cin >> k;
	if(k<=2) {
		cout << k << endl;
		for(int i=1; i<=k; i++) {
			for(int j=1; j<=k; j++) {
				if(j==k) printf("%d",j);
				else printf("%d ",j);
			}
			cout << endl;
		}
		return 0;
	}
	int n=k+1;
	n>>=1;
	if(n%2==1) n++;
	cout << n << endl;
	int cnt1=1,cnt2=2;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			int tar;
			if(i&1) {
				tar=(cnt1+j)%n;
				if(tar>=k) tar-=n;
			} else {
				tar=n+(cnt2+j)%n;
				if(tar>=k) tar-=n;

			}
			if(j==n) printf("%d",1+tar);
			else printf("%d ",1+tar);
		}
		if(i&1) cnt1+=2;
		else cnt2+=2;
		printf("\n");
	}
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
using vpii = vector<pii>;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())

int main() {
	int n;
	cin >> n;
	vector<tuple<string, int, int>> d(n);
	rep(i, n) {
		string a;
		int b;
		cin >> a >> b;
		d[i] = make_tuple(a, -b, i + 1);
	}
	vsort(d);
	rep(i, n) cout << get<2>(d[i]) << endl;

}

Measured memory_bytes: 256
/***     
 * When I wrote this
 * only God & I understood
 * what I was doing
 * Now, God only knows 
 /***/ 
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip>
#include<map>
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
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;}
//fixed<< setprecision(2)
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll t;
    while (cin >> t)
    {
        if(t>=400&&t<=599)cout<<"8\n";
        else if(t>=600&&t<=799)cout<<"7\n";
        else if(t>=800&&t<=999)cout<<"6\n";
        else if(t>=1000&&t<=1199)cout<<"5\n";
        else if(t>=1200&&t<=1399)cout<<"4\n";
        else if(t>=1400&&t<=1599)cout<<"3\n";
        else if(t>=1600&&t<=1799)cout<<"2\n";
        else if(t>=1800&&t<=1999)cout<<"1\n";
    }
}

Measured memory_bytes: 3104
N,M = map(int, input().split(" "))

a = []

for i in range(N):
    a.append(list(map(int, input().split(" "))))

#print(a)

ans = 0

for j in range(1,M+1):
    cnt_M = 0
    for k in range(N):
        for i in range(1,a[k][0]+1):
            if a[k][i] == j:
                cnt_M = cnt_M + 1
    #print(cnt_M)
    if cnt_M == N :
        ans = ans +1

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct d {
  struct d *parent;
  struct d *left;
  struct d *right;
  int key;
} node;
typedef node * Node;

 Node root;

void insert(int key){
  Node x = root;
  Node y = NULL;
  Node z;

  z = (Node)malloc(sizeof(node));
  z->key = key;
  z->left = NULL;
  z->right = NULL;

  while(x != NULL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;

  if(y == NULL){
    root = z;
  }
  else if (z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }
}

void find(int key){
  Node x = root;

  while(1){
    if(x == NULL){
      puts("no");
      return;
    }
    else if(x->key == key){
      puts("yes");
      return;
    }
    else if(key < x->key){
      x = x->left;
    }
    else if(x->key < key){
      x = x->right;
    }
  }
}

void inorderTreeWalk(Node x){
  if(x != NULL){
    inorderTreeWalk(x->left);
    printf(" %d",x->key);
    inorderTreeWalk(x->right);
  }
}

void preorderTreeWalk(Node x){
  if(x == NULL){
    return;
  }
  printf(" %d",x->key);
  preorderTreeWalk(x->left);
  preorderTreeWalk(x->right);
}

void printer(){
  inorderTreeWalk(root);
  printf("\n");
  preorderTreeWalk(root);
  printf("\n");
}

int main(){
  int i, n, key;
  char command[10];

  scanf("%d ",&n);
  for(i=0; i<n; i++){
    scanf("%s ",command);
    if(!strcmp(command, "insert")){
      scanf("%d ",&key);
      insert(key);
    }
    else if(!strcmp(command, "print")){
      printer();
    }
    else if(!strcmp(command, "find")){
      scanf("%d ",&key);
      find(key);
    }
  }

  return 0;
}



Measured memory_bytes: 20440
def A_Digit_Sum_2():
    a=input()
    count=0
    c=0
    for i in range(len(a)-1):
        if a[i+1]=='9':
            count+=1
    #print(count)
    if count==(len(a)-1):
        for i in range(len(a)):
            c+=int(a[i])
    else:
        c=(len(a)-1)*9+int(a[0])-1
    print(c)

A_Digit_Sum_2()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 1; i <= (n); ++i)
typedef long long ll;


void solve(long long A, long long B){
    ll ans=0;
    rep(i,max(A,B)){
        if(A*i%B==0){
            ans=A*i;
            break;
        }
    }
    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

const int N = 10;
bool visited[N];
vector<ll> vals;
ll cost[N][N];
int n, j;

void dfs(int i, ll s) {
	visited[i] = true;
	int outs = 0;
	for (int t = 0; t < n; ++t) {
		if (! visited[t]) {
			++outs;
			dfs(t, s + cost[i][t]);
		}
	}
	if (outs == 0 && i > j) vals.push_back(s);
	visited[i] = false;
}

bool works() {
	for (j = 0; j+1 < n; ++j) dfs(j, 0);
	sort(vals.begin(), vals.end());
	cerr << vals.back() << '\n';

	bool ans = true;
	for (int i = 0; i+1 < vals.size(); ++i) {
		if (vals[i] == vals[i+1]) ans = false;
	}
	vals.clear();
	return ans;
}

int main() {
	vector<vector<int>> xr = {
	{1},
	{1,2},
	{1,2,4},
	{1,2,4,7},
	{1,2,4,7,12},
	{1,2,4,8,13,18},
	{1,2,4,8,14,19,24},
	{1,2,4,8,15,24,29,34},
	{1,7,10,13,21,26,41,43,45}
	};

	cin >> n;
	ll b = 1;
	for (int i = 0; i+1 < n; ++i) {
		for (j = i+1; j < n; ++j) {
			cost[i][j] = b * xr[n-2-i][j-1-i];
			cost[j][i] = cost[i][j];
		}
		if (i+2 < n) b *= (xr[n-2-i][n-2-i] + xr[n-2-i][n-3-i]);
	}
	if (works()) {
		for (int i = 0; i < n; ++i) {
			for (j = 0; j < n; ++j) {
				cout << cost[i][j] << ' ';
			}
			cout << '\n';
		}
	} else cout << "QAQ\n";
}


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

int main(){
	int H,W;
	while(1){
		cin>>H>>W;
		if(H==0&&W==0)break;
	
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				cout<<"#";
			}
			cout<<endl;
		}
		cout<<endl;
	}	
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, ll> x;
  ll sum = 0;
  rep(i, n) {
    cin >> a[i];
    x[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  vector<P> bc(q);
  rep(i, q) {
    ll b, c;
    cin >> b >> c;
    bc[i].first = b;
    bc[i].second = c;
  }
  rep(i, q) {
    ll y = bc[i].second - bc[i].first;
    sum += y * x[bc[i].first];
    cout << sum << endl;
    x[bc[i].second] += x[bc[i].first];
    x[bc[i].first] = 0;
  }
  return 0;
}

Measured memory_bytes: 10236
#include<bits/stdc++.h>
using namespace std;
const int N=2e8+5;
char s[N],t[N];
int n,m,xx,yy,nex[N];
void kmp_init()
{
    int i=1,k=0;
    while(i<=xx*m)
        if(k==0||t[i]==t[k]) nex[++i]=++k;
    else k=nex[k];
}
int main()
{
    scanf("%s%s",s+1,t+1);
    n=strlen(s+1);m=strlen(t+1);
    xx=5000000/m;
    for(int j=1;j<xx;j++)
    for(int i=1;i<=m;i++)
        t[i+m*j]=t[i];
    kmp_init();
    int ans=0,p=m*xx/n;
    int now=0,pos=0;
    m*=xx;
    for(int l=1;l<=p;l++)
    {
        for(int i=1;i<=n;i++)
        {
            pos++;
            while(pos&&t[pos]!=s[i])
                pos=nex[pos];
            ans=max(ans,pos);
        }
    }
    m/=xx;
    if(ans==n*p||ans>=n*(p-1)) printf("-1\n");
    else printf("%d\n",ans/m);
}


Measured memory_bytes: 31104
n = gets.to_i
strs = []
n.times do
  a, b = gets.chomp.split

  na = 0
  prefix = 1
  a.chars.each do |ch|
    case ch
    when /[2-9]/
      prefix = ch.to_i
    when "m"
      na += prefix * 1000
      prefix = 1
    when "c"
      na += prefix * 100
      prefix = 1
    when "x"
      na += prefix * 10
      prefix = 1
    when "i"
      na += prefix
      prefix = 1
    end
  end

  nb = 0
  prefix = 1
  b.chars.each do |ch|
    case ch
    when /[2-9]/
      prefix = ch.to_i
    when "m"
      nb += prefix * 1000
      prefix = 1
    when "c"
      nb += prefix * 100
      prefix = 1
    when "x"
      nb += prefix * 10
      prefix = 1
    when "i"
      nb += prefix
      prefix = 1
    end
  end

  # p [na, nb]

  s = na + nb
  rm = s / 1000
  rc = (s - rm * 1000) / 100
  rx = (s - rm * 1000 - rc * 100) / 10
  ri = s % 10

  res = ""
  res += "m" if rm == 1
  res += rm.to_s + "m" if rm > 1
  res += "c" if rc == 1
  res += rc.to_s + "c" if rc > 1
  res += "x" if rx == 1
  res += rx.to_s + "x" if rx > 1
  res += "i" if ri == 1
  res += ri.to_s + "i" if ri > 1

  puts res
end

Measured memory_bytes: 9288
N=int(input())
li=[list(map(int,input().split())) for i in range(N)]
dp=[[0]*3 for i in range(N)]
for i in range(N):
    if i==0:
        for j in range(3):
            dp[i][j] = li[i][j]
    else:
        for j in range(3):
            if j == 0:
                dp[i][j] = li[i][0] + dp[i-1][1] if dp[i-1][1] >= dp[i-1][2] else li[i][0] + dp[i-1][2]
            if j == 1:
                dp[i][j] = li[i][1] + dp[i-1][0] if dp[i-1][0] >= dp[i-1][2] else li[i][1] + dp[i-1][2]
            if j == 2:
                dp[i][j] = li[i][2] + dp[i-1][0] if dp[i-1][0] >= dp[i-1][1] else li[i][2] + dp[i-1][1]
print(max(dp[N-1]))


Measured memory_bytes: 74072
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int Max = 100000 + 5;
ll n, town[Max], hero[Max];

int main() {
    scanf("%lld", &n);
    for (int i = 1; i <= n + 1; i++)
        scanf("%lld", &town[i]);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &hero[i]);
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ll nowm, nowh;
        nowm = town[i] + town[i + 1];
        nowh = min(nowm, hero[i]);
        ans += nowh;
        if(hero[i] > town[i]) {
            town[i + 1] = nowm - hero[i];
            if(town[i + 1] < 0)
                town[i + 1] = 0;
        }
    }
    printf("%lld", ans);
    return 0;
}

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

int main(){
  
  int A, B;
  
  cin >>A >>B;
  
  int product;
  product = A * B;
  
  int P;
  P = product % 2;
  
  if (P == 0){
    cout << "Even" <<endl;
  }else{
    cout <<"Odd" <<endl;
  }
  
  
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;

int A, B, C;
ll K;

int main() {
	scanf("%d%d%d%lld", &A, &B, &C, &K);
	printf("%d", (K & 1LL) == 1LL ? B - A : A - B);

	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;

int main() {
	int n, k;
	char s[50];
	cin >> n >> k;
	scanf("%s", s);
	s[k-1] = tolower(s[k-1]);
	cout << s << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000002486618624LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, a, c[9] = {0};

  std::cin >> N;

  for (int i = 0; i < N; i ++) {
    std::cin >> a;

    c[std::min(a / 400, 8)] ++;
  }

  int cm = 0, cp;

  for (int i = 0; i < 8; i ++)
    if (c[i])
      cm ++;

  if (cm == 0 && c[8]) {
    cm = 1;

    c[8] --;
  }
    
  cp = cm + c[8];

  std::cout << cm << ' ' << cp << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long i, j = 1;
		long b = (long) Math.floor(Math.sqrt(a));

		for (i = b; i >= 1; i--) {
			if (a % i == 0) {
				j = i;
				break;
			}
		}

		i = a / j;

		System.out.println((i - 1) + (j - 1));
	}

}


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;
const int IINF = INT_MAX;
int n,m,one;
int b[20],p[20],bc[1<<16],buf[20];

bool isValid(int bitmask){
  vector<int> vec;
  rep(i,n){
    int cnt = 1;
    int color = ( bitmask >> i ) & 1;
    while( i+1 < n && ( ( bitmask >> (i+1) ) & 1 ) == color ) {
      ++cnt;
      ++i;
    }
    vec.push_back(cnt);
  }
  if( vec.size() != m ) return false;
  rep(i,m) if( vec[i] != p[i] ) return false;
  return true;
}

void compute(){
  int mini = IINF;
  rep(bitmask,(1<<n)) if( bc[bitmask] == one ) {
    if( !isValid(bitmask) ) continue;
    int cost = 0;
    rep(i,n) buf[i] = b[i];
    rep(i,n) if( buf[i] != ( ( bitmask >> i ) & 1 ) ) {
      int k=-1;
      REP(j,i+1,n) if( buf[j] == ( ( bitmask >> i ) & 1 ) ) { k = j; break; }
      for(int j=k;j>i;j--) { swap(buf[j],buf[j-1]); ++cost; }
    }
    mini = min(mini,cost);
  }
  cout << mini << endl;
}

int main(){
  rep(i,(1<<16)) bc[i] = __builtin_popcount(i);
  cin >> n >> m;
  rep(i,n) { cin >> b[i]; one += b[i]; }
  rep(i,m) cin >> p[i];

  compute();
  return 0;
}

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

using namespace std;

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

	int n;
	int v[55]={0};
	int c[55]={0};
	
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> v[i];
	}
	
	for(int i=0; i<n; i++){
		cin >> c[i];
	}
	
	int sum=0;
	
	for(int i=0; i<n; i++){
		if((v[i]-c[i])>0) sum+=v[i]-c[i]; 
	}
	
	cout << sum << endl;
	
	return 0;
}


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

struct node{
	struct node *right;
	struct node *left;
	struct node *parent;
	int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum (Node x ){

}

Node treeSearch (Node u, int k ){

}

Node treeSuccessor (Node x ){

}

void treeDelete (Node z ){
	Node y;	// node to be deleted
	Node x;	// child of y
}

void insert (int k ){
	Node y = NIL;
	Node x = root;
	Node z;

	z = malloc (sizeof (struct node ) );
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	if (x == NIL ){
		root = z;
	}else{
		do{
			if (x->key < k ){
				y = x->right;
			}else{
				y = x->left;
			} // end if

			if (y != NIL ){
				y->parent = x;
			}else{
				if (x->key < k )
					x->right = z;
				else
					x->left = z;
			} // end if
			x = y;
		}while (x != NIL ); // end while
	} // end if
}

void inorder (Node u ){
	if (u == NIL ) return;
	inorder (u->left );
	printf (" %d", u->key );
	inorder (u->right );
}

void preorder (Node u ){
	if (u == NIL ) return;
	printf (" %d", u->key );
	preorder (u->left );
	preorder (u->right );
}

int main()
{
	int n, i, x;
	char com[20];

	root = NIL;
	scanf ("%d", &n );
	for (i = 0; i < n; i++ ){
		scanf ("%s", com );
		if (com[0] == 'i' ){	// case insert 
			scanf ("%d", &x );
			insert (x );
		}else
		if (com[0] == 'p' ){ // case print
			inorder (root );
			printf ("\n" );
			preorder (root );
			printf ("\n" );
		} // end if
	}	// end for

	return 0;
}


Measured memory_bytes: 25188
n, y = gets.split.map(&:to_i)
key = 0
_i = _j = _k = -1
(0..n).each do |i|
  (0..(n-i)).each do |j|
    k = n - i - j
    if y == ( i * 10000 + j * 5000 + k * 1000 )
      _i = i
      _j = j
      _k = k
    end
  end
end

puts "#{_i} #{_j} #{_k}"


Measured memory_bytes: 3836
#include <stdio.h>
  
int main(){
   int c, i, j, k, n, x;
   scanf("%d %d",&n, &x);
   while(n != 0 ){
   c=0;
   for(i=1;i <= n-2;i++){
      for(j=i+1;j <= n-1;j++){
         for(k=j+1;k <= n;k++){
            if(i+j+k == x){
               c++;
            }
         }
      }
   }
   printf("%d\n",c);
   scanf("%d %d", &n, &x);
   }
   return 0;
}

Measured memory_bytes: 2684
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
min_a = min(a)
if min_a == max_a:
  if min_a == n-1 or min_a <= n // 2:
    print("Yes")
  else:
    print("No")
elif min_a + 1 == max_a:
  x = a.count(min_a)
  y = a.count(max_a)
  if x < max_a and (max_a - x) * 2 <= y:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Measured memory_bytes: 14092
gets
arr = gets.split.map(&:to_i)
MIN = arr.inject(1000000) do |cmin, i|
  cmin < i ? cmin : i
end

MAX = arr.inject(-1000000) do |cmax, i|
  cmax > i ? cmax : i
end

SUM = arr.inject(&:+)

puts "#{MIN} #{MAX} #{SUM}"

Measured memory_bytes: 9052
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    int c = a + b;
    if(c % 3 == 0 || a % 3 == 0 || b % 3 == 0){
        puts("Possible");
    }
    else {
        puts("Impossible");
    }
    return 0;
}

Measured memory_bytes: 256
target = list(map(int, input().split()))

num = target[0]
total = target[1]

for i in range(num + 1):
    tori = i
    kame = (num - i)
    if (tori * 2 + kame * 4) == total:
        print('Yes')
        break
else:
    print('No')


Measured memory_bytes: 9116
// atcoder/abc137/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

const int N = 2500 + 10;
const int M = 5000 + 10;

struct E {
  int src, dst;
  lli coin;
};

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m, p;
  while (cin >> n >> m >> p) {
    vector<E> es;
    for (int i = 0; i < m; ++i) {
      int a, b, c;
      cin >> a >> b >> c;
      --a;
      --b;
      es.push_back(E{a, b, p - c});
    }

    static lli coin[N];
    fill(coin, coin + N, 1LL << 60);
    coin[0] = 0;
    static bool vis[N];
    fill(vis, vis + N, false);
    vis[0] = true;

    for (int i = 0; i < n; ++i) {
      each (e, es) {
        if (vis[e.src]) {
          setmin(coin[e.dst], coin[e.src] + e.coin);
          vis[e.dst] = true;
        }
      }
    }
    const lli x = coin[n - 1];

    for (int i = n; i < n+n; ++i) {
      each (e, es) {
        if (vis[e.src]) {
          setmin(coin[e.dst], coin[e.src] + e.coin);
          vis[e.dst] = true;
        }
      }
    }
    const lli y = coin[n - 1];

    if (vis[n - 1]) {
      if (x == y) {
        cout << max(0LL, -1 * coin[n - 1]) << endl;
      } else {
        cout << -1 << endl;
      }
    } else {
      cout << 0 << endl;
    }
  }

  return 0;
}


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

int main()
{
    int p, q, r;
    cin >> p >> q >> r;
    int ans = min(p + q, min(q + r, r + p));
    cout << ans << endl;
}

Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	//逆元を求める変数
	static int max=100008;
	static int MOD=1000000007;
	static long[] fac=new long[max];
	static long[] finv=new long[max];
	static long[] inv=new long[max];
	//逆元変数終わり
	public static void main(String[] args) {
		COMinit();		//逆元
		SC sc = new SC(System.in);
		int N=sc.nextInt();	//N種類、N+1文字なので鳩ノ巣理論でかならず2回でた数字が唯一つ存在する
		int kaburi=0;	//かぶっている数字
		boolean[] num=new boolean[N+1];
		int[] retu=new int[N+1];
		for(int i=0; i<=N; i++) {
			retu[i]=sc.nextInt();
			if(!num[retu[i]]) {
				num[retu[i]]=true;
			}
			else {
				kaburi=retu[i];
			}
		}
		int kaburi1=-1;
		int kaburi2=-1;
		for(int i=0; i<=N; i++) {
			if(retu[i]==kaburi) {
				if(kaburi1==-1) {
					kaburi1=i;
				}
				else {
					kaburi2=i;
				}
			}
		}
		int mae=kaburi1;
		int usiro=N-kaburi2;
		//前、後ろにどのくらいあるか
		long[] daburi=new long[mae+usiro+1];
		for(int i=0; i<=mae+usiro; i++) {
			daburi[i]=COM(mae+usiro,i);
		}
		for(int i=0; i<=N; i++) {
			if(i==0) {
				pl(N);
			}
			else if(i>0 && i<=mae+usiro){
				long ans=COM(N+1,i+1)-daburi[i];
				if(ans<0) {
					ans+=MOD;
				}
				pl(ans);
			}
			else if(i>mae+usiro && i<N) {
				long ans=COM(N+1,i+1);
				if(ans<0) {
					ans+=MOD;
				}
				pl(ans);
			}
			else if(i==N) {
				pl(1);
			}
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static void COMinit() {		//テーブルを作るみたい nCrの　または　階乗の？
		fac[0] = fac[1] = 1;
		finv[0] = finv[1] = 1;
		inv[1] = 1;
		for (int i = 2; i < max; i++){
			fac[i] = fac[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}
	static long COM(int n, int k){			//二項係数の計算
		if (n < k) return 0;
		if (n < 0 || k < 0) return 0;
		return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}
}

Measured memory_bytes: 59152
s_inv = str(input())[::-1]
dp = [1]+[0]*2018
MOD = 0
ans = 0
num = 0
k = 1

for i in range(len(s_inv)):
  num+=int(s_inv[i])*k
  MOD = num % 2019
  dp[MOD] += 1
  k = k*10
  k %= 2019
for i in dp:
  ans += i*(i-1)/2

print(int(ans))


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

int main(void) {
    int N; cin >> N;
    vector<ll> A;
    for(int i=0; i<N; i++) {
        ll x; cin >> x;
        A.push_back(x);
    }
    sort(A.begin(),A.end());
    for(int i=0; i<N-1; i++) {
        if(A[i]==A[i+1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 5372
N = int(input())
SP = []
for i in range(1,N+1):
    tmp =[]
    S_tmp,P_tmp = input().split()
    tmp.append(S_tmp)
    tmp.append(int(P_tmp))
    tmp.append(i)
    SP.append(tmp)

SP.sort()

tmp = []
for i in range(N):
    if (len(tmp)==0):
        tmp.append(SP[i])
    elif(tmp[0][0]==SP[i][0]):
        tmp.append(SP[i])
    else:
        tmp.sort(reverse=True,key=lambda x: x[1])
        for j in (tmp):
            print(j[2])
        #print(tmp)
        tmp = []
        tmp.append(SP[i])

tmp.sort(reverse=True,key=lambda x: x[1])
for j in (tmp):
            print(j[2])
#print(tmp)

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

int main()
{

#ifdef _d
    freopen("input.txt", "r", stdin);
#endif

    int n;
    cin >> n;
    int p = 0; // ac
    int q = 0; // wa
    int r = 0; // tle
    int s = 0; // re
    for (int i = 0; i < n; ++i) {
        string str;
        cin >> str;
        if (str == "AC") {
            ++p;
        } else if (str == "WA") {
            ++q;
        } else if (str == "TLE") {
            ++r;
        } else if (str == "RE") {
            ++s;
        }
    }
    cout << "AC x " << p << "\n";
    cout << "WA x " << q << "\n";
    cout << "TLE x " << r << "\n";
    cout << "RE x " << s << "\n";

    return 0;
}


Measured memory_bytes: 3628
package main


import (
	"fmt"
	"strings"
)

func main() {
	var a string
	fmt.Scan(&a)
	b := strings.Split(a,"")

	count := 0
	for k := range b {
		if b[k] == "1" {
			count++
		}
	}
	fmt.Println(count)
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

signed main(){
    int A, B;
    cin >> A >> B;
    FOR(i, 1, 1010){
        if((int)floor((double)i * 0.08) == A && (int)floor((double)i * 0.1) == B){
            PRINT(i);
            return 0;
        }
    }
    PRINT("-1");
    return 0;
}

Measured memory_bytes: 256
function Main(s) {
  var s = s.split("\n");
  var h = s[0].split(" ")[0]*1, w = s[0].split(" ")[1]*1;
  var s = s.slice(1, h + 1);
  var k = [0, -1, 1, 0];
  var l = [-1, 0, 0, 1];
  var head = ["_".repeat(w + 2)];
  var tail = ["_".repeat(w + 2)];
  for(var i = 0; i < h; i++) s[i] = "_" + s[i] + "_";
  var x = head.concat(s).concat(tail);
  var ans = "Yes";
  for(var i = 1; i < h + 1; i++) {
    for(var j = 1; j < w + 1; j++) {
      if (x[i][j] === "#") {
        var cnt = 0;
        for (var m = 0; m < 4; m++) {
          if (x[i + k[m]][j + l[m]] === ".") cnt++;
        }
        if (cnt === 4) {
          ans = "No";
          break;
        }
      }
    }
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

class BellmanFord{
    /*
    Copyright (c) 2020 0214sh7
    https://github.com/0214sh7/library/
    */
    private:
    typedef std::pair<std::pair<int,int>,long long> P;
    int V,E;
    long long INF = (1LL<<61);
    std::vector<std::pair<std::pair<int,int>,long long>> es;
    
    public:
    void init(std::vector<std::pair<std::pair<int,int>,long long>> edge){
        //辺数をもとめる　
        E=edge.size();
        //頂点数を決定する
        V=0;
        for(int i=0;i<edge.size();i++){
            V=std::max(V,edge[i].first.first+1);
            V=std::max(V,edge[i].first.second+1);
        }
        es=edge;
    }
    
    std::vector<std::pair<long long,bool>> solve(int s){
        std::vector<std::pair<long long,bool>> d;
        //INFで初期化する
        for(int i=0;i<V;i++){
            d.push_back({INF,false});
        }
        d[s].first=0;
        for(int j=0;j<2*V;j++){
             bool update=false;
            for(int i=0;i<E;i++){
                P k=es[i];
                if(d[k.first.first].first!=INF && d[k.first.second].first>d[k.first.first].first+k.second){
                    d[k.first.second].first=d[k.first.first].first+k.second;
                    if(j>=V){
                        d[k.first.second].second=true;
                    }
                    update=true;
                }
            }
            if(!update)break;
        }
        return d;
    }
    
    //init:{ {int,int},longlong}のvectorを渡すことで有向グラフを構築する
    //solve:始点を渡すとinitで構築したグラフでベルマンフォードをし、コストのvectorを返す
};


signed main(void){
    int N,M;
    int a,b,c;
    vector<std::pair<std::pair<int,int>,long long>> es;
    cin >> N >> M;
    REP(i,M){
        cin >> a >> b >> c;
        a--;b--;c*=-1;
        es.push_back({{a,b},c});
    }
    
    BellmanFord bell;
    bell.init(es);
    
    std::vector<std::pair<long long,bool>> S;
    S = bell.solve(0);
    
    if(S[N-1].second){
        cout << "inf" << endl;
    }else{
        cout << -1*S[N-1].first << endl;
    }
    
    return 0;
}



Measured memory_bytes: 384
h,w=map(int,input().split())

s=[input() for _ in range(h)]

ans=[[0]*w for _ in range(h)]
for i in range(w):
    if s[0][i]=='#' :
        break
    ans[0][i]=1
for j in range(h):
    if s[j][0]=='#' :
        break
    ans[j][0]=1

for i in range(1,h):
    for j in range(1,w):
        if s[i][j]=='#':
            ans[i][j]=0
        else:
            ans[i][j]=ans[i][j-1]+ans[i-1][j]

print(ans[h-1][w-1]%(1000000000+7))



Measured memory_bytes: 249624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  int x=tx-sx,y=ty-sy;
  for(int i=0;i<x;i++){
    cout<<'R';
  }
  for(int i=0;i<y;i++){
    cout<<'U';
  }
  for(int i=0;i<x;i++){
    cout<<'L';
  }
  for(int i=0;i<=y;i++){
    cout<<'D';
  }
  for(int i=0;i<=x;i++){
    cout<<'R';
  }
  for(int i=0;i<=y;i++){
    cout<<'U';
  }
  cout<<'L';
  cout<<'U';
  for(int i=0;i<=x;i++){
    cout<<'L';
  }
  for(int i=0;i<=y;i++){
    cout<<'D';
  }
  cout<<'R';
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

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

Measured memory_bytes: 13552
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,q,i; cin>>n>>q;
    string s; cin>>s;
    vector <int> ruiseki(n); //ACならCに+1
    for(i=0;i<n-1;i++){
        ruiseki[i+1]=ruiseki[i];
        if(s[i]=='A'&&s[i+1]=='C') ruiseki[i+1]++;
    }
    //for(i=0;i<n;i++) cout<<ruiseki[i]<<'*'<<i<<endl;
    for(i=0;i<q;i++){
        int a,b; cin>>a>>b; //3 7
        cout<<ruiseki[b-1]-ruiseki[a-1]<<endl;
        
    }
}

Measured memory_bytes: 1408
def main():
    A, B, C, D = list(map(int, input().split()))
    mod = 998244353
    u = [0] * (D + 1)
    v = [0] * (D + 1)
    u[B] = 1
    for b in range(B + 1, D + 1):
        u[b] = u[b - 1] * A
    for a in range(A + 1, C + 1):
        v[B] = u[B] * B % mod
        for b in range(B + 1, D + 1):
            v[b] = (u[b] * b + v[b - 1] * a - u[b - 1] * (a - 1) * (b - 1)) % mod
        u, v = v, u

    return u[D]

print(main())


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

typedef long long int int64;

#define MIN(a,b) ((a)<(b)?(a):(b))

void run(void){
  int n,x;
  scanf("%d%d",&n,&x);
  int *a=(int *)malloc(sizeof(int)*(n+1));
  a[0]=0;
  int i;
  for(i=1;i<=n;i++) scanf("%d",a+i);
  int64 *sum=(int64 *)malloc(sizeof(int64)*(n+1));
  sum[0]=0;
  for(i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
  int64 ans=(int64)2*n*x+5*sum[n];
  for(i=1;i<=n;i++){
    const int k=i;
    int64 local=(int64)x*(n+k);
    int j;
    for(j=1;j<=n/k;j++){
      local+=(j==1?5:2*j+1)*(sum[n-k*(j-1)]-sum[n-k*j]);
      if(local>=ans) break;
    }
    if(j<=n/k) continue;
    if(n%k!=0) local+=(j==1?5:2*j+1)*sum[n%k];
    ans=MIN(local,ans);
  }
  printf("%lld\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 2560
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int[]l=new int[n];
		Arrays.setAll(l,i->s.nextInt());
		Arrays.sort(l);

		int p=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[j]-l[i]<l[k]&&l[k]<l[i]+l[j])
						++p;

		System.out.println(p);
	}
}


Measured memory_bytes: 27408
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	vector<int> v(3);
	for (int i = 0; i < 3; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	if (v[0] == v[2]) {
		cout << 1 << endl;
	}
	else if (v[0] == v[1]||v[1]==v[2]) {
		cout << 2 << endl;
	}
	else {
		cout << 3 << endl;
	}
}


Measured memory_bytes: 256
import sys
n,m=map(int,input().split())
l=[[int(i) for i in l.split()] for l in sys.stdin]
possible=[]
possible2=[]
for i in l:
  if i[0]==1:
    possible.append(i[1])
for i in l:
  if i[1]==n:
    possible2.append(i[0])
if len(set(possible)&set(possible2))>0:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Measured memory_bytes: 48552
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let A: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let B: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let C: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let X: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let ans = (0..(A + 1)).map(
        |i| (0..(B + 1)).map(
            |j| (0..(C + 1)).filter(
                |&k| 500 * i + 100 * j + 50 * k == X
            ).count()
        ).sum::<usize>()
    ).sum::<usize>();

    println!("{}", ans);
}

Measured memory_bytes: 4352
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let s: String = read();
    let t: String = read();
    let mut ans = String::new();
    for i in 0..n {
        ans.push(s.chars().nth(i).unwrap());
        ans.push(t.chars().nth(i).unwrap());
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
using namespace std;
int gcd(int x, int y)
{
	int temp;
	while (y!=0){
		temp = x % y;
		x =y;
		y=temp;
	}
	return x;

}



int main()
{  
	ios_base::sync_with_stdio(false);
	cin.tie(0);
    int k, t, ans=0;
    cin>>k;
	for (int i = 1;i<=k;i++){
		for (int j =1;j<=k;j++){
			for (int m =1;m<=k;m++){
				t = gcd(i,j);
				t = gcd(t,m);
				ans += t;
			}
		}
	}
	cout<<ans;
	
	
    
}

Measured memory_bytes: 3592
loop do
  n, m = gets.chomp.split.map(&:to_i)
  
  if (n | m) == 0
    break
  end

  h = Array.new(n)
  w = Array.new(m)

  0.upto(n - 1) do |i|
    h[i] = gets.chomp.to_i
  end
  
  0.upto(m - 1) do |i|
    w[i] = gets.chomp.to_i
  end

  c_w = Array.new(1500 * 1000 + 1, 0)

  0.upto(m - 1) do |i|
    sum = w[i]
    c_w[sum] += 1
    (i + 1).upto(m - 1) do |j|
      sum += w[j]
      c_w[sum] += 1
    end
  end

  ans = 0

  0.upto(n - 1) do |i|
    sum = h[i]
    ans += c_w[sum]
    (i + 1).upto(n - 1) do |j|
      sum += h[j]
      ans += c_w[sum]
    end
  end

  puts ans
end

Measured memory_bytes: 17832
#include <bits/stdc++.h>
#include <cstring> 
using namespace std;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mpp make_pair
#define int long long int
#define F first
#define mem(a,b) memset(a,b,sizeof(a))
#define F first
#define S second
#define MOD 998244353
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
#define MAXN 2000000
#define MAXI 10000000000007


signed main(){
 
    fast;
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    int k, sum=0, i, j, r;
    cin>>k;
    for(i=1;i<=k;i++){
    	for(j=1;j<=k;j++){
    		for(r=1;r<=k;r++){
    			int g = __gcd(i, __gcd(j, r));
    			sum+=g;
    		}
    	}
    }
    cout<<sum<<endl;
}

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

#pragma GCC optimize("O3")
#pragma GCC target("sse2,avx,avx2,fma")

const long long MOD = 998244353;

long long inv[10000005];
long long invFact[10000005];
long long fact[10000005];

long long powmod(long long a, long long b){
    long long x = 1;
    long long y = a;
    while(b){
        if(b&1){ x = (x*y)%MOD; }
        y = (y*y)%MOD;
        b >>= 1;
    }
    return x;
}

int main(){
    int N;
    scanf("%d", &N);

    inv[1] = 1;
    for(int i = 2; i <= N; i ++){
        inv[i] = inv[MOD%i]*(MOD-MOD/i)%MOD;
    }

    fact[0] = 1;
    invFact[0] = 1;
    for(int i = 1; i <= N; i ++){
        fact[i] = (fact[i-1]*i)%MOD;
        invFact[i] = (invFact[i-1]*inv[i])%MOD;
    }

    long long tempPow2 = 1;
    long long ans = 0;
    for(int i = N; i > (N>>1); i --){
        //ans += tempPow2*ncr(N, i)%MOD;
        ans += (((tempPow2*invFact[N-i])%MOD) * invFact[i])%MOD;

        tempPow2 += tempPow2;
        if(tempPow2 >= MOD){tempPow2 -= MOD;}
    }
    //printf("ans(%d)=%lld\n", N, ans);
    ans = (ans+ans)%MOD;
    ans = ans*fact[N]%MOD;
    long long finalAns = (powmod(3, N)-ans+MOD)%MOD;

    printf("%lld", finalAns);
    return 0;
}


Measured memory_bytes: 234624
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<int> v;
    int a[n],s=1;
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    }
    for(int i=0;i<n-k;i++)
    {
    	if(a[i]<a[i+k])
    	{
    		cout<<"Yes"<<"\n";
    	}
    	else
    	{
    		cout<<"No"<<"\n";
    	}
    }
}
 

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

int main()
{
	int ans = 1;
	int n, k;

	cin >> n >> k;

	for( int i = 0; i < n; i++ ) {
		ans = min( ans + k, ans * 2 );
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re
import heapq


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    n = ii()

    ans = (n-1)//2
    print(ans)

main()


Measured memory_bytes: 23072
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,c,p,sum=0;
    cin>>n>>c;
    for(int i=0; i<c; i++){
            cin>>p;
            sum+=p;
    }
    if(sum%(n+1)==0){
            cout<<sum/(n+1)<<endl;
    }
    else if(sum%(n+1)>=1){
            cout<<sum/(n+1)+1<<endl;
    }
    else{
            cout<<"1"<<endl;
    }
}



Measured memory_bytes: 3124