akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports, dead_code, unused_variables, unused_mut)]
use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;
use permutohedron::LexicalPermutation;
const INF: i32 = std::i32::MAX;
const MOD: i32 = 1e9 as i32 + 7;

struct Get<R: std::io::BufRead> {
    stdin: R,
    v: Vec<String>,
    i: usize,
}
impl<R: std::io::BufRead> Get<R> {
    pub fn new(stdin: R) -> Self {
        Get {
            stdin,
            v: Vec::new(),
            i: 0,
        }
    }
    fn split_line(&mut self) {
        self.i = 0;
        self.v.clear();
        let mut buf = String::new();
        self.stdin.read_line(&mut buf).unwrap();
        let buf = buf.trim().to_owned();
        let mut ws = buf.split_whitespace();
        loop {
            let x = ws.next();
            if x.is_none() {
                break;
            }
            let x = x.unwrap().to_owned();
            self.v.push(x);
        }
    }
    #[allow(dead_code)]
    pub fn once<T: std::str::FromStr>(&mut self) -> T {
        if self.i == self.v.len() {
            self.split_line();
        }
        let elem = &self.v[self.i];
        self.i += 1;
        elem.parse().unwrap_or_else(|_| panic!())
    }
    #[allow(dead_code)]
    pub fn line<T: std::str::FromStr>(&mut self) -> String {
        self.i = 0;
        self.v.clear();
        let mut buf = String::new();
        self.stdin.read_line(&mut buf).unwrap();
        let buf = buf.trim().to_owned();
        buf
    }
}

fn main() {
    let stdin = std::io::stdin();
    let stdin = std::io::BufReader::new(stdin.lock());
    let get = Get::new(stdin);
    solve(get);
}

fn solve<R: std::io::BufRead>(mut get: Get<R>) {
    let x: i32 = get.once();

    println!("{}", if x >= 30 {"Yes"}else{"No"})

}


Measured memory_bytes: 2128
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main() {
  string w;
  cin >> w;

  map<char, int> mp;
  for (int i=0; i<w.size(); i++) {
    mp[w[i]]++;
  }

  bool judge=true;
  map<char, int>::iterator it=mp.begin();
  for (; it!=mp.end(); it++) {
    if ((it->second & 1) == 1) judge = false;
  }

  if (judge) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int N,M; cin >> N >> M;
    vector<pair<int,char>> sc(M);
    REP(i,M) cin >> sc[i].first >> sc[i].second;

    REP(i,pow(10,N)){
        string res = to_string(i);
        int cnt=0;
        //cout << res << endl;
        REP(j,M){
            if(res[sc[j].first-1]!=sc[j].second){
                break;
            }else{
                cnt++;
            }
            //cout << res[sc[j].first-1] << " " << sc[j].second << " cnt= " << cnt << endl;
        }
        if(cnt==M and res.size()==N){
            cout << res << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#define MAX 200000
int main(void) {
    long long n, i, a[MAX], left=0, right=0, dif, min;
    scanf("%lld", &n);
    for(i=0; i<n; i++) {
        scanf("%lld", &a[i]);
        right += a[i];
    }
    left = a[0];
    right -= a[0];
    min = left>right ? left-right : right-left;
    
    for(i=1; i<n-1; i++) {
        left += a[i];
        right -= a[i];
        dif = left>right ? left-right : right-left;
        if(dif<min)
            min = dif;
    }
    printf("%lld\n", min);
}


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream&
operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream&
operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream&
operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

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

    ll N, K; cin >> N >> K;
    ll ans = 0;
    repeat(b, K + 1, N + 1) {
        ll up = (N - K) / b;
        ll low = (N - b + 1) / b;
        ll ans2 = 0;
        if(up != low) {
            ll l = K, r = b - 1;
            while(l + 1 < r) {
                ll m = (l + r) / 2;
                ll v = (N - m) / b;
                (v == up ? l : r) = m;
            }
            ans2 += (l - K + 1) * (up + 1);
            ans2 += (b - 1 - r + 1) * (low + 1);
        } else {
            ans2 += (b - K) * (up + 1);
        }
        // cerr << "B = " << b << " : " << ans2 << endl;
        ans += ans2 - (K == 0);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long x = sc.nextLong();
		long ans = b/x + 1;
		if(a!=0) {
			ans -= (a-1)/x + 1;
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 23764
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<cstring>
#include<string>
using namespace std;
int a[5][5];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int s,w;
	scanf("%d %d %d",&a[1][1],&a[1][2],&a[2][2]);
	s=a[2][2]*3;w=a[2][2];
	a[3][3]=s-a[1][1]-w;
	a[3][2]=s-a[1][2]-w;
	a[1][3]=s-a[1][1]-a[1][2];
	a[2][3]=s-a[1][3]-a[3][3];
	a[2][1]=s-w-a[2][3];
	a[3][1]=s-a[1][1]-a[2][1];
	a[3][2]=s-a[1][2]-w;
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			printf("%d ",a[i][j]);
		}
		printf("\n");
	}
	return 0;
}
//8 3 4
//1 5 9
//6 7 2


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    cout << N * (N - 1)/2 + M * (M - 1)/2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int a[100];

int main()
{
    for(int i = 0; i < 3; i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+3);
    if(a[0]==5 && a[1]==5 && a[2]==7){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

}


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

int main(){
    int N,K,Q;
    cin >> N >> K >> Q;
    vector<int> point(N+1,K-Q);
    for(int i=0;i<Q;i++){
        int a;
        cin >> a;
        point[a]++;
    }
    for(int i=1;i<=N;i++){
        cout << (point[i]>0? "Yes":"No") << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i<b; i++)
int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    rep(i, 0, n) {
      string s2 = s.substr(i, n - i);
      string t2 = t.substr(0, n - i);
      if(s2 != t2) continue;
      cout << n + i << endl;
      return 0;
    }
    cout << n * 2 << endl;
}


Measured memory_bytes: 3612
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	if n%s(n) == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func s(n int) (res int) {
	for n != 0 {
		res += n % 10
		n /= 10
	}
	return
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main(void){
    int a=0,b=0,c=0,d=0;
    int N;
    scanf("%d",&N);
   
    for(int i = 0; i<N;i=i+1){
        char str[256];
        scanf("%s",&str);
        if(strcmp(str,"AC")==0 ) a++;
        if(strcmp(str,"WA")==0 ) b++;
        if(strcmp(str,"TLE")==0 ) c++;
        if(strcmp(str,"RE")==0 ) d++;


    }

    printf("AC x %d\n",a);
    printf("WA x %d\n",b);
    printf("TLE x %d\n",c);
    printf("RE x %d\n",d);
   
    return 0;
}

Measured memory_bytes: 1736
#include<iostream>
using namespace std;
int main(){
	
	int room[4][3][10]={0},b,f,v,r,n,k,j;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>b>>f>>r>>v;
		b=b-1;
		f=f-1;
		r=r-1;
		room[b][f][r]=room[b][f][r]+v;
	}
	for(j=0;j<3;j++){
		for(k=0;k<10;k++){
			cout<<" "<<room[0][j][k];
			if(k==9){
				cout<<endl;
			}
		}
	}
	cout<<"####################"<<endl;
	for(j=0;j<3;j++){
		for(k=0;k<10;k++){
			cout<<" "<<room[1][j][k];
				if(k==9){
					cout<<endl;
				}	
		}	
	}
	cout<<"####################"<<endl;
	for(j=0;j<3;j++){
		for(k=0;k<10;k++){
			cout<<" "<<room[2][j][k];
				if(k==9){
					cout<<endl;
				}
		}
	}
	cout<<"####################"<<endl;
	for(j=0;j<3;j++){
		for(k=0;k<10;k++){
			cout<<" "<<room[3][j][k];
				if(k==9){
					cout<<endl;
				}
		}
	}
	return 0;
}

Measured memory_bytes: 3080
#include <stdio.h>
int main(void){
    while(1){
        int h, w, t;
        int mh, mw, mt = 150 * 150 *2;
        
        //データを読み込む
        scanf("%d %d", &h, &w);
        
        if(h == 0 && w == 0){
            break;
        }
        
        //対角線の長さの２乗を計算
        t = h * h + w * w;
        
        //考えられる高さと幅の組をすべて調べて、与えられたと長方形の対角線の長さを超える最小のせ長方形を見つける
        int i, j, at;
        for(i = 1; i <= 150; i++){
            for(j = 1; j <= 150; j++){
                if(i < j){
                    at = i*i+j*j;
                    if(t < at || (t == at && h < i)){
                        if(mt > at || (mt == at && mh > i)){
                            mt = at;
                            mh = i;
                            mw = j;
                        }
                    }
                }
            }
        }
        
        printf("%d %d\n", mh, mw);
    }
}



Measured memory_bytes: 2748
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>

using namespace std;

void solve(int A, int B) {
  int ans;
  if (B % A == 0) {
    ans = A + B;
  } else {
    ans = B - A;
  }
  printf("%d\n", ans);
}

int main() {
  int A, B;
  cin >> A >> B;
  solve(A, B);
  return 0;
}

Measured memory_bytes: 256
n, k, q = [int(i) for i in input().split()]
subarray = [q] * n

for _ in range(q):
    temp = int(input())
    subarray[temp-1] -= 1

for i in range(n):
    if k - subarray[i] <= 0:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 6596
# D - 2017-like Number
from itertools import accumulate
from math import sqrt


def get_primes(n: int) -> set:
    """Return a list of prime numbers < n in O(N)."""
    if n < 2:
        return set()

    sieve = [1] * n
    for i in range(3, int(sqrt(n)) + 1, 2):
        if sieve[i]:
            sieve[i * i:: 2 * i] = [0] * ((n - i ** 2 - 1) // (2 * i) + 1)
    return {2} | {i for i in range(3, n, 2) if sieve[i]}


def main():
    Q, *LR = map(int, open(0).read().split())
    primes = get_primes(10 ** 5 + 1)
    is_2017_like = [1 if i in primes and (i + 1) // 2 in primes else 0 for i in range(10 ** 5 + 1)]
    cumsum = tuple(accumulate(is_2017_like))
    ans = [cumsum[r] - cumsum[l - 1] for l, r in zip(*[iter(LR)] * 2)]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N;
double sum;
char u[100];
ll i, j, k;

int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        double x;
        scanf("%lf%s", &x, u);
        if(u[0]=='B'){
            x *= 380000;
        }
        sum += x;
    }
    printf("%lf", sum);

    return 0;
}

Measured memory_bytes: 256
n = int(input())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += min(ai[i], bi[i])
    ans += min(ai[i+1], bi[i]-min(ai[i], bi[i]))
    ai[i+1] -= min(ai[i+1], bi[i]-min(ai[i], bi[i]))
print(ans)


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

int main(){
	vector<int> nums;
	int n;
	while( cin >> n, n ){
		nums.clear();
		nums.resize(n);
		for( int i=0; i<n; i++ )
			cin >> nums[i];
		int max=-50000000;
		for( int i=0; i<n; i++ ){
			int sum=0;
			for( int j=i; j<n; j++ ){
				sum += nums[j];
				if( max < sum )		max = sum;
			}
		}
		cout << max << endl;
	}
}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 2010, M = 2 * N, INF = 0x3f3f3f3f;

int n, x, y;
int h[N], e[M], ne[M], idx;
int q[N * N], cnt[N], dist[N];

void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}

void bfs(int s)
{
	memset(dist, 0x3f, sizeof dist);
	
	int hh = 0, tt = -1;
	q[ ++ tt] = s;
	dist[s] = 0;
	
	while (hh <= tt)
	{
		int t = q[hh ++ ];
		for (int i = h[t]; ~i; i = ne[i])
		{
			int j = e[i];
			if (dist[j] != INF) continue;
			dist[j] = dist[t] + 1;
			cnt[dist[j]] ++ ;
			q[ ++ tt] = j;
		}
	}
}

int main()
{
	memset(h, -1, sizeof h);
	scanf("%d%d%d", &n, &x, &y);
	for (int i = 1; i < n; i ++ ) add(i, i + 1), add(i + 1, i);
	add(x, y), add(y, x);
	
	for (int i = 1; i <= n; i ++ ) bfs(i);
	
	for (int i = 1; i < n; i ++ ) printf("%d\n", cnt[i] / 2);
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int p[100000];
int y[100000];
int z[100000];
int ans[100000];

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int  Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}void hSwap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}

void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(int x[], int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}

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


int main() {
	int d;
	scanf("%d", &d);
	int cnt = 25 - d;
	printf("Christmas");
	REP(i, cnt) {
		printf(" Eve");
	}
	puts("");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;*/

string s;
int pow10[200010];
int suf[200010];
int cnt[3000];

int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    cin >> s;
    pow10[0] = 1;
    Forn(i, 200000) pow10[i] = pow10[i-1] * 10 % 2019;
    suf[s.size()] = 0;
    cnt[0]++;
    for(int i=s.size()-1; i>=0; i--)
    {
        suf[i] = (suf[i+1] + (s[i] - '0') * pow10[s.size()-1-i]) % 2019;
        cnt[suf[i]]++;
    }
    ll ans = 0;
    forn(i, 2019)
    {
        ll x = cnt[i];
        ans += (x) * (x-1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5308
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

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

	string s, t;
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < 3; i++) if (s[i] == t[i]) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] pn = new int[n+1];

        for (int i = n; i > 0; i--){
            int tmp = i;
            for(int j=2; tmp != 1;){
                if(tmp % j == 0){
                    pn[j]++;
                    tmp /= j;
                } else {
                    j++;
                }
            }
        }
        long result = 1;
        for(int count : pn){
            result = result * (count + 1)% 1000000007;
        }
        System.out.println(result );
    }
}


Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 36

struct cards{
  char Name;
  char Value;
};

void bubble(struct cards p[],int n){
  int i,j;
  struct cards tmp;
  for(i=0;i<n;i++){
    for(j=n-1;j>=i;j--){
      if(p[j].Value<p[j-1].Value){
	tmp=p[j];
	p[j]=p[j-1];
	p[j-1]=tmp;
      }
    }
  }
}

void selection(struct cards p[],int n){
  int i,j,minj;
  struct cards tmp;
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(p[j].Value<p[minj].Value) minj=j;
    }
    tmp=p[i];
    p[i]=p[minj];
    p[minj]=tmp;
  }
}

int main(){
  int i,j,n,flag=0,a1[N],a2[N];
  scanf("%d",&n);
  struct cards p1[N],p2[N];
  for(i=0;i<n;i++){
    scanf(" %c%c",&p1[i].Name,&p1[i].Value);
  }
  for(i=0;i<n;i++){
    p2[i]=p1[i];
  }
  
  bubble(p1,n);
  selection(p2,n);
  
  for(i=0;i<n;i++){
    if(i==n-1)printf("%c%c\nStable\n",p1[i].Name,p1[i].Value);
    else printf("%c%c ",p1[i].Name,p1[i].Value);
  }
  for(i=0;i<n;i++){
    if(i==n-1)printf("%c%c\n",p2[i].Name,p2[i].Value);
    else printf("%c%c ",p2[i].Name,p2[i].Value);
  }
  for(i=0;i<n;i++){
    if(p1[i].Name != p2[i].Name){
      printf("Not stable\n");
      flag=1;
      break;
    }
  }
  if(flag==0)printf("Stable\n");
  return 0;
}



Measured memory_bytes: 2108
a = []
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    a.append([H, W])
for i in range(len(a)):
    b = a[i]
    if b[0] % 2 == 0:
        for j in range(b[0] // 2):
            if b[1] % 2 == 0:
                print('#.'*(b[1] // 2))
                print('.#'*(b[1] // 2))
            else:
                print('#.'*(b[1] // 2) + '#')
                print('.#'*(b[1] // 2) + '.')
    else:
        for j in range(b[0] // 2):
            if b[1] % 2 == 0:
                print('#.' * (b[1] // 2))
                print('.#' * (b[1] // 2))
            else:
                print('#.'*(b[1] // 2) + '#')
                print('.#'*(b[1] // 2) + '.')
        if b[1] % 2 == 0:
            print('#.' * (b[1] // 2))
        else:
            print('#.' * (b[1] // 2) + '#')
    print('')


Measured memory_bytes: 5636
import sys
sys.setrecursionlimit(10**7)

def dfs(row, column):
    Map[row][column] = num
    for i in range(-1, 2):
        for j in range(-1, 2):
            if Map[row + i][column + j] == 1:
                dfs(row + i, column + j)

while True:
    w, h = map(int, input().split())
    if w == h == 0:
        break
    
    Map = [[0] * (w+2)]
    Map += [[0] + list(map(int, input().split())) + [0] for _ in range(h)]
    Map += [[0] * (w+2)]
    
    num = 1
    
    for i in range(h+2):
        for j in range(w+2):
            if Map[i][j] == 1:
                num += 1
                dfs(i,j)
    print(num-1)



Measured memory_bytes: 8000
#include <bits/stdc++.h>
using namespace std;
#define MX 1000000
#define mod 1000000007
long long fact[MX+5],inv[MX+5],dp[MX+5];
long long pow_log(long long x,int y)
{
	if (!y)
	return 1;
	long long ret=pow_log(x,y/2);
	ret=(ret*ret)%mod;
	if (y%2)
	ret=(ret*x)%mod;
	return ret;
}
long long ncr(int n,int r)
{
	if (n<r)
	return 0;
	return fact[n]*inv[r]%mod*inv[n-r]%mod;
}
int main()
{
	fact[0]=1;
	for (int i=1;i<=MX;i++)
	fact[i]=(fact[i-1]*i)%mod;
	inv[MX]=pow_log(fact[MX],mod-2);
	for (int i=MX-1;i>=0;i--)
	inv[i]=(inv[i+1]*(i+1))%mod;
	int n;
	scanf("%d",&n);
	n--;
	long long ans=0;
	for (int k=1;k<=n;k++)
	{
		dp[k]=ncr(k-1,n-k)*fact[k]%mod*fact[n-k]%mod;
		ans=(ans+(dp[k]-dp[k-1]+mod)%mod*k)%mod;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 23680
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let s = Array.init n @@fun _ -> read_line () |> split_string |> List.sort compare |> String.concat ""

let rec f n = if n = 0 then 0 else n + f (n - 1)

let () = 
  Array.sort compare s;
  let a = Array.fold_left (fun acc n ->
    match acc with
      | [] -> [(n, 1)]
      | (v, cnt) as t :: xs -> if v = n then (v, cnt + 1) :: xs else (n, 1) :: t :: xs
  ) [] s in
  a |> List.map snd |> List.map (fun i -> if i = 0 then 0 else f (i - 1)) |> List.fold_left (+) 0 |> Printf.printf "%d\n"

Measured memory_bytes: 15488
#include <iostream>

using namespace std;
typedef long long ll;
ll mod = 1000000007,num[100010];
ll pw(ll a, ll x){
    ll ret = 1;
    while(x){
        if(x&1) (ret *= a) %= mod;
        (a *= a) %= mod;
        x /= 2;
    }
    return ret;
}

int main(){
    ll i,j,n,k,ans = 0;
    cin >> n >> k;
    for(i=k;i>=1;i--){
        num[i] = pw(k/i,n);
        for(j=2*i;j<=k;j+=i){
            num[i] -= num[j];
            if(num[i]<0) num[i] += mod;
        }
    }
    for(i=1;i<=k;i++){
        (ans += i*num[i]%mod) %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4364
#include<iostream>
#include<vector>
using namespace std;
int main()
{
  int n,tmp;
  double ans,temp=0.0;
  vector<int> all;
  cin>>n;
  for(int i = 0;i<n;i++)
  {
    cin>>tmp;
    all.push_back(tmp);
    temp+=1.0/tmp;
  }
  
 ans=1.0/temp;
  
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
const int mxn=1e5+100;
int a[mxn],dp[mxn],n;
bool cal[mxn];
int abs (int x)
{
    return (x>0?x:-x);
}
int dpf (int x)
{

    if (cal[x]==true)
        return dp[x];
    cal[x]=true;
    dp[x]=dpf(x-1)+abs(a[x]-a[x-1]);
    if (x>1)
        dp[x]=min(dp[x],dpf(x-2)+abs(a[x]-a[x-2]));
    return dp[x];
}
int main()
{
    cin>>n;
    cal[0]=true;
    for (int i=0;i<n;i++)
        cin>>a[i];
    cout<<dpf(n-1);
    return 0;
}


Measured memory_bytes: 4224
datas = gets.split(" ").map{|ye|ye.to_i}
w = datas[0]
h = datas[1]
x = datas[2]
y = datas[3]
ans = w * h / 2.0
ans = ans.to_s
if  (x * 1.0 == w / 2.0) && (y * 1.0  == h / 2.0)
  ans += " 1"
else
  ans += " 0"
end

puts ans

Measured memory_bytes: 1788
import sys

s = sys.stdin.readline().strip()
def mypowerof2(exp):
        ret = 1
        for i in range(exp):
                ret *= 2
        return ret
def mypowerof10(exp):
        ret = 1
        for i in range(exp):
                ret *= 10
        return ret
res = 0
for i in reversed(xrange(len(s))):
        for j in xrange(len(s)-i):
                base = int(s[i]) * mypowerof10(j)
                rate = mypowerof2(i) * mypowerof2((len(s)-1) - i - j - 1)
                res += base * rate
#               print "base is", base
#               print "rate is", rate                                                                            

print res

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

void rot(D& d) {
	d.push_back(d[0]);
	d.pop_front();
}

D f(D d) {
	D ret = d;
	for(int i = 0; i < 3; i++) {
		rot(d);
		ret = min(ret, d);
	}
	return ret;
}

int overlap(D d) {
	int ret = 1;
	D t = d;
	for(int i = 0; i < 3; i++) {
		rot(d);
		if(t == d) ret++;
	}
	return ret;
}

ll P(int n, int k) {
	ll ret = 1;
	for(int i = n - k + 1; i <= n; i++) ret *= i;
	return ret;
}

D C[400];

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

	map<D, int> m, cnt;
	for(int i = 0; i < N; i++) {
		C[i] = D(4);
		for(int j = 0; j < 4; j++) {
			cin >> C[i][j];
		}
		C[i] = f(C[i]);
		m[C[i]]++;
	}

	for(auto p : m) {
		cnt[p.first] = overlap(p.first);
	}

	ll ans = 0;
	for(int i = 0; i < N; i++) {
		D d1 = C[i];
		m[d1]--;
		for(int j = i + 1; j < N; j++) {
			D d2 = C[j];
			m[d2]--;
			for(int r1 = 0; r1 < 4; r1++) {
				map<D, int> t;
				t[f(D({ d1[1], d1[0], d2[1], d2[0] }))]++;
				t[f(D({ d1[0], d1[3], d2[2], d2[1] }))]++;
				t[f(D({ d1[3], d1[2], d2[3], d2[2] }))]++;
				t[f(D({ d1[2], d1[1], d2[0], d2[3] }))]++;
				ll k = 1;
				for(auto p : t) {
					if(!m.count(p.first) || m[p.first] < p.second) {
						k = 0;
						break;
					}
					k *= P(m[p.first], p.second);
					for(int loop = 0; loop < p.second; loop++) {
						k *= cnt[p.first];
					}
				}
				ans += k;
				rot(d1);
			}
			m[d2]++;
		}
		m[d1]++;
	}

	cout << ans / 3 << endl;
}

Measured memory_bytes: 1152
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String s = sc.next();
            int k = sc.nextInt();

            Set<String> set = new HashSet<>();
            for (int i = 0; i < s.length(); i++) {
                for (int j = 1; j <= 5; j++) {
                    if ( i + j > s.length() ) {
                        break;
                    }
                    String sub = s.substring(i, i + j);
                    set.add(sub);
                }
            }

            List<String> list = new ArrayList<>(set);
            Collections.sort(list);
            System.out.println(list.get(k - 1));
        }
    }
}


Measured memory_bytes: 24916
# Cx, Cyは0〜100の整数なので、101 * 101パターンを全探索

N=int(input())
data=[None] * N
for i in range(N):
  data[i] = list(map(int,input().split()))

for Cx in range(101):
  for Cy in range(101):
    H = -1
    for i in range(len(data)):
      if data[i][2]<1:
        continue
      H = data[i][2] + abs(data[i][0] - Cx) + abs(data[i][1] - Cy)
      break
    
    for i in range(len(data)):
      if data[i][2] != max(H - abs(data[i][0] - Cx) - abs(data[i][1] - Cy),0):
        break
    else:
      print(Cx,Cy,H)
      exit(0)


Measured memory_bytes: 3064
/*  ex2_3
      fmuacshai */

#include <stdio.h>

int main(void){
    int N,A,B;
  //Nは一辺のマスの個数、Aは白のマス目の数、Bは黒のマスの個数
    scanf("%d",&N);
  //Nを入力
    scanf("%d",&A);
  //Aを入力
    B=N*N-A;
    printf("%d\n",B);
  //条件を満たすもののみ結果を出力する
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
typedef long long ll;
int getrand(int l, int r) { // [l, r]
    static uint32_t y = time(NULL);
    y ^= (y << 13); y ^= (y >> 17);
    y ^= (y << 5);
    return y % (r - l + 1) + l;
}
ll getrandll(ll l, ll r) { // [l,r]
    ll a = getrand(0, 999999999);
    ll b = getrand(0, 999999999);

    ll x = a * 1000000000LL + b;
    assert(0 <= x);

    return x % (r - l + 1) + l;
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




#define INF INT_MAX/2
string S; int N;
ll h[30];
unordered_map<ll, int> dp;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S; N = S.length();

    rep(i, 0, 30) h[i] = getrandll(0, 1LL << 60);

    ll x = 0;
    dp[0] = 0;
    int ans = 0;
    rep(i, 0, N) {
        x ^= h[S[i] - 'a'];
        
        int ma = INF;
        if (!dp.count(x)) dp[x] = INF;
        ma = min(ma, dp[x]);

        rep(i, 0, 26) {
            if (!dp.count(x ^ h[i])) dp[x ^ h[i]] = INF;
            ma = min(ma, dp[x ^ h[i]]);
        }

        dp[x] = min(dp[x], ma + 1);
        ans = ma + 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 170348
N, Q = gets.split.map(&:to_i)
adj = Array.new(N + 1) {Array.new}
(N-1).times do
    a, b = gets.split.map(&:to_i)
    adj[a] << b
    adj[b] << a
end
add = Array.new(N + 1, 0)
Q.times do
    pj, xj = gets.split.map(&:to_i)
    add[pj] += xj
end
visited = Array.new(N + 1, false)
count = Array.new(N + 1, 0)
stack = [[1, 0]]
visited[1] = true
while !stack.empty?
    current_p, parent_count = stack.pop
    count[current_p] = parent_count + add[current_p]
    adj[current_p].each do |next_p|
        if !visited[next_p]
            visited[next_p] = true
            stack.push([next_p, count[current_p]])
        end
    end
end
puts count[1..-1].join(" ")

Measured memory_bytes: 35556
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

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

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

ll nxt()
{
    ll x;
    cin >> x;
    return x;
}

const ll L = 1e5+5;

void solve()
{
    string s;
    cin >> s;

    ll n = sz(s);

    string temp = s;
    reverse(all(temp));

    if(s != temp)
    {
        cout << "No" << endl;
        return;
    }   

    string a = s.substr(0, n/2);
    string temp2 = a;
    reverse(all(temp2));

    if(a != temp2)
    {
        cout << "No" << endl;
        return;
    } 

    string b = s.substr(n/2+1, n/2);
    string temp3 = b;
    reverse(all(temp3));

    if(b != temp3)
    {
        cout << "No" << endl;
        return;
    } 

    cout << "Yes" << endl;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll T = 1;
    // T = nxt();

    while(T--)
    {
        solve();
    }

    return 0;
}

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

int main() {
	int N, l, r,sum=0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> l >> r;
		sum += r - l + 1;
	}
	cout << sum << endl;

	getchar(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200;
long long add[maxn], res[maxn];
vector<int> to[maxn];
void dfs(int r, long long val, int p = -1){
	val += add[r];
	res[r] = val;
	for(int n : to[r]){
		if(n != p){
			dfs(n, val, r);
		}
	}
}
int main(){
	int n, q; cin >> n >> q;
	for(int i = 0; i < n - 1; i++){
		int x, y; cin >> x >> y;
		to[x].push_back(y);
		to[y].push_back(x);
	}
	for(int i = 0; i < q; i++){
		int p, x; cin >> p >> x;
		add[p] += x;
	}
	dfs(1, 0);
	for(int i = 1; i <= n; i++) cout << res[i] << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 25600
#include <bits/stdc++.h>
using namespace std;
#include <boost/algorithm/string.hpp>
#define ll long long int
#define MOD 1000000007


int main()
{
    ll n,i,j,k,c=0,d=0,flag=0,max=0,min1=10000000000,max1=0,l,r,T,m,x,y,count1=0,q;
   /* freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n>>i>>j;
	if(n+i+j>=22)
    {
    cout<<"bust"<<endl;
    }
    else
    {
    cout<<"win"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i = l; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
  int n,m,ac = 0,pe = 0;
  scanf("%d %d",&n,&m);
  int a[n+1] = {};
  int u[n+1];
  rep(i,0,n+1) u[i] = 1;
  rep(i,0,m) {
    int p;
    string s;
    cin >> p >> s;
    if(s == "AC") {
      if(u[p]) {
        ac++;
        pe += a[p];
        u[p] = 0;
      }
    }
    else a[p]++;
  }
  printf("%d %d\n",ac,pe);
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,t,a,h[1007],index;
    double mini = 1000000.000;
    double temp;
    cin>>n>>t>>a;
    for(int i=0; i<n; i++)
    {
        cin>>h[i];
        temp = t-h[i]*0.006;
        if(abs(a-temp) < mini)
        {
            mini = abs(a-temp);
            index = i+1;
        }
    }
    cout<<index;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int n,c=0;
    string s;
    cin>>n>>s;
    for (int i=0 ; i<n-2 ; i++)
    if (s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') c++;
    
    cout<<c;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {
    public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		int[] num = new int[input];
		int count;
		
		for(int c = 0; c < input; c++){
			num[c] = scan.nextInt();
		}
		
		count = bubbleSort(num, input);
		
		for(int i = 0; i < input; i++){
			if(i != input - 1){
				System.out.print(num[i] + " ");
			}else{
				System.out.println(num[i]);
			}
		}
		System.out.println(count);
	}
	
	static int bubbleSort(int data[], int n){
		int temp;
		int c = 0;
		
		for(int i = 0; i < n - 1; i++){
			for(int j = n - 1; j > i; j--){
				if(data[j - 1] > data[j]){
					temp = data[j];
					data[j] = data[j - 1];
					data[j - 1] = temp;
					c++;
				}
			}
		}
		
		return c;
	}
     
}

Measured memory_bytes: 26276
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
  int a;
  double n;

  cin >> n >> a;

  if (( n - (int)((n / 1000) ) * 1000 <= a)){
    cout << "Yes" << endl;
  } else {
    cout << "No" << 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);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] pos = new int[n];
		for (int i=0;i<n;i++) {
			pos[i]=sc.nextInt();
		}
		int ans = Integer.MAX_VALUE;

		for (int i=0;i<n-k+1;i++) {
			ans = Math.min(ans, pos[i+k-1]-pos[i]+Math.min(Math.abs(pos[i+k-1]), Math.abs(pos[i])));
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 49852
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m, a, b, cnt = 0;
	bool judge;
	cin >> n >> m;
	vector<int> h(n);
	vector<vector<int>> gs(n);
	for (int i = 0; i < n; i++) {
		cin >> h.at(i);
	}
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		gs.at(a - 1).push_back(b - 1);
		gs.at(b - 1).push_back(a - 1);
	}
	for (int i = 0; i < n; i++) {
		judge = true;
		for (int j = 0; j < int(gs.at(i).size()); j++) {
			if (h.at(i) <= h.at(gs.at(i).at(j))) {
				judge = false;
			}
		}
		if (judge) {
			cnt++;
		}
	}
	cout << cnt << endl;
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int maxn = 1e3 + 10;
const int maxm = 1e4 + 10;
const ll mod = 998244353;

int main() {
    __;
    ll s;
    cin >> s;
    ll a = sqrt(s);
    ll b = a;
    if (a * b == s) {
        ll x = 0;
        ll y = 0;
        cout << 0 << ' ' << 0 << ' ' << b << ' ' << x << ' ' << y << ' ' << a << endl;
    } else if ((a + 1) * b >= s) {
        a++;
        ll x = a * b - s;
        ll y = 1;
        cout << 0 << ' ' << 0 << ' ' << b << ' ' << x << ' ' << y << ' ' << a << endl;
    } else {
        a++;
        b++;
        ll x = a * b - s;
        ll y = 1;
        cout << 0 << ' ' << 0 << ' ' << b << ' ' << x << ' ' << y << ' ' << a << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){
    int a, b;
    //char op;
    while( cin >> a >> b, a ){
        for( int i = 0; i < a; i++ ){
            for( int j = 0; j < b; j++ ){
                if( i == 0 || j == 0 || i == a-1 || j == b-1 ){
                    cout << '#';
                }else{
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1152
/*
Created by Rishu Sahu @ covid 20-20
*/
/*
*****************************************************************
*/

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

#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define pai pair<int,int>
#define pal pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,a,b) for(int i=a;i<=b;i++)
#define ff first 
#define ss second
#define sz(x) (int)x.size()
#define vi vector<int>
#define vl vector<ll>
#define mpl map<ll,ll>
#define mpi map<int,int>
#define pb push_back
#define all(x) x.begin(),x.end()

const int mod = 1e9+7;
const int INF = INT_MAX;
const int mxm = 500000;

void solve(){
    int n,w;
    cin>>n>>w;
    ll dp[n+4][w+4];
    memset(dp,0,sizeof(dp));
    ll wei[n],pro[n];
    for(int i=0;i<n;i++){
        cin>>wei[i]>>pro[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            if(wei[i-1]>j){
                dp[i][j]=dp[i-1][j];
            }else {
                dp[i][j]=max(dp[i-1][j],pro[i-1]+dp[i-1][j-wei[i-1]]);
            }
        }
    }
    cout<<dp[n][w]<<endl;
}

int main(){
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 84748
/* ex3_4
  bonbonc */

#include<stdio.h>
#include<stdbool.h>

int main(void){
	int number;
	bool flag; /*終わったかどうか*/
	flag = false;
	scanf("%d",&number);
	for(int i = 1;i<=9;i++){/*全探索*/
		for(int j = 1;j<=9;j++){
			if(i*j==number){
				flag = true;
			}
		}
	}

	if(flag){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main {

    static Scanner scan;

    private static int count = 0;

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

	// get length
	int length = scan.nextInt();

	// init m
	int m = 0;
	for (int i = length; i > 0; i = (i-1)/3) {
	    m++;
	}
	int[] G = new int[m];
	G[0] = 1;
	for (int i = 1; i < m; i++) {
	    G[i] = G[i-1]*3 + 1;
	}

	// get input array
	int[] input = new int[length];
	for (int i = 0; i < length; i++) {
	    input[i] = scan.nextInt();
	}

	// ShellSort
	for(int i = m-1; i >= 0; i--) {
	    input = insertionSort(input, length, G[i]);
	}

	//Print
	System.out.printf("%d\n", m);
	for(int i = m-1; i > 0; i--) {
	    System.out.printf("%d ", G[i]);
	}
	System.out.printf("%d\n%d\n", G[0], count);
	for (int i = 0; i < length; i++) {
	    System.out.printf("%d\n", input[i]);
	}
    }

    private static int[] insertionSort(int[] input, int length, int gap) {
	int v, j = 0;
	for (int i = gap; i < length; i++) {
	    v = input[i];
	    j = i - gap;
	    for ( ; j >= 0 && input[j] > v;) {
		input[j + gap] = input[j];
		j -= gap;
		count++;
	    }
	    input[j + gap] = v;
	}
	return input;
    }
}



Measured memory_bytes: 554244
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e5+10;
int n,m;
int a[maxn];
ll f[maxn];
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n>>m;
	for(int i=1,x;i<=m;i++){
		cin>>x;
		a[x]=1;
	}
	f[0]=1;
	for(int i=1;i<=n;i++){
		if(i-1>=0&&!a[i-1]) f[i]=(f[i]+f[i-1])%mod;
		if(i-2>=0&&!a[i-2]) f[i]=(f[i]+f[i-2])%mod;
	}
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    char s[n];
    int i,j;
    scanf("%s",s);
    long ans=0;
    char last ='\0';
    for(i=0;i<n;i++){
        if(last != s[i]){
            
            ans++;
        }
        last = s[i];
    }

    printf("%ld\n",ans);
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);

		String str;
		while((str=br.readLine())!=null){
			String[] sp = str.split(" ");

			int total = 0;

			int a = Integer.parseInt(sp[0]);
			int b = Integer.parseInt(sp[1]);
			int c = Integer.parseInt(sp[2]);
			int d = Integer.parseInt(sp[3]);
			int e = Integer.parseInt(sp[4]);
			int f = Integer.parseInt(sp[5]);

			total = a * 1 + b * 5 + c * 10 + d * 50 + e * 100 + f * 500;

			if(total >= 1000){
				System.out.println(1);
			}else{
				System.out.println(0);
			}
		}
	}

}

Measured memory_bytes: 24280
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int N;
	cin >> N;
	vector<ll> A(N),sum_l2r(N), sum_r2l(N);

	// 累積和を計算
	sum_l2r[0] = 0, sum_r2l[0] = 0;
	REP(i, N) {
		cin >> A[i];
		if (i > 0) {
			sum_l2r[i] += (sum_l2r[i - 1] + A[i]);
		}
		else sum_l2r[0] = A[0];
	}
	REP(i, N) {
		if (i > 0) {
			sum_r2l[i] += (sum_r2l[i - 1] + A[N - 1 - i]);
		}
		else sum_r2l[0] = A[N - 1];
	}

	// 真ん中の仕切りがi番目にあるときの最適な仕切り方
	// 0番目とN-1番目は定義されない
	vector<int> left_cutter(N - 1), right_cutter(N - 1);

	// 真ん中の仕切りの位置をずらしたときの左右の仕切りの最適な位置を求める
	// しゃく取り法
	// mid:[1]から[N-3]まで
	REPS(mid_ix, 1, N - 2) 
	{
		if (mid_ix > 1) {

			// 左方向
			left_cutter[mid_ix] = left_cutter[mid_ix - 1]; // 引継ぎ

			ll diff_l = abs(sum_l2r[mid_ix] - 2 * sum_l2r[left_cutter[mid_ix - 1]]);
			REPS(left_ix, left_cutter[mid_ix - 1] + 1, mid_ix) {
				if (diff_l > abs(sum_l2r[mid_ix] - 2*sum_l2r[left_ix])) {
					left_cutter[mid_ix] = left_ix;
					diff_l = abs(sum_l2r[mid_ix] - 2 * sum_l2r[left_ix]);
				}
				else break;
			}

			// 右方向
			right_cutter[mid_ix] = right_cutter[mid_ix - 1]; // 引継ぎ

			ll diff_r = abs(sum_r2l[mid_ix] - 2 * sum_r2l[right_cutter[mid_ix - 1]]);
			REPS(right_ix, right_cutter[mid_ix - 1] + 1, mid_ix) {
				if (diff_r > abs(sum_r2l[mid_ix] - 2 * sum_r2l[right_ix])) {
					right_cutter[mid_ix] = right_ix;
					diff_r = abs(sum_r2l[mid_ix] - 2 * sum_r2l[right_ix]);
				}
				else break;
			}

		}
		else {
			// mid_ix = 1のときは強制的に決まる
			left_cutter[1] = 0;
			right_cutter[1] = 0;
		}
	}

	ll ans = mod;
	REPS(mid_ix, 1, N - 2)
	{
		ll min_L = min(sum_l2r[mid_ix] - sum_l2r[left_cutter[mid_ix]], sum_l2r[left_cutter[mid_ix]]);
		ll max_L = max(sum_l2r[mid_ix] - sum_l2r[left_cutter[mid_ix]], sum_l2r[left_cutter[mid_ix]]);
		
		ll min_R = min(sum_r2l[N - 2 - mid_ix] - sum_r2l[right_cutter[N - 2 - mid_ix]], sum_r2l[right_cutter[N - 2 - mid_ix]]);
		ll max_R = max(sum_r2l[N - 2 - mid_ix] - sum_r2l[right_cutter[N - 2 - mid_ix]], sum_r2l[right_cutter[N - 2 - mid_ix]]);

		//cout << min_L << " " << max_L << " " << min_R << " " << max_R << endl;
		ans = min(max(max_L, max_R) - min(min_L, min_R), ans);
	}
	cout << ans << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 6776