akhauriyash/Code-Regression huggingface dataset:
MAX = 9999999
def m():
    h, w = map(int, input().split())
    s = []
    s.append(list(('#'*(w+2))))
    for j in range(h):
        s.append(list('#'+input()+'#'))
    s.append(list(('#' * (w + 2))))

    g = [[[] for _ in range(w+2)] for _ in range(h+2)]
    cnt = 0
    for i in range(1, h+1):
        for j in range(1, w+1):
            if s[i][j] == '#':
                cnt +=1
                continue
            if s[i][j+1] == '.':
                g[i][j].append((i, j+1))
            if s[i+1][j] == '.':
                g[i][j].append((i+1, j))
            if s[i][j-1] == '.':
                g[i][j].append((i, j-1))
            if s[i-1][j] == '.':
                g[i][j].append((i-1, j))

    def dijkstra():
        d = [[MAX for _ in range(w + 2)] for _ in range(h + 2)]
        p = [[MAX for _ in range(w + 2)] for _ in range(h + 2)]
        visited = [[-1 for _ in range(w + 2)] for _ in range(h + 2)]
        d[1][1] = 0
        p[1][1] = -1
        while True:
            mincost = MAX
            for i in range(1, h + 1):
                for j in range(1, w + 1):
                    if visited[i][j] != 1 and d[i][j] < mincost:
                        mincost = d[i][j]
                        u = (i,j)
            if mincost == MAX:
                break
            visited[u[0]][u[1]] = 1

            for i in range(1, h + 1):
                for j in range(1, w + 1):
                    if visited[i][j] != 1 and u in g[i][j]:
                        if d[u[0]][u[1]] +1 < d[i][j]:
                            d[i][j] = d[u[0]][u[1]] + 1
                            p[i][j] = u
                            visited[i][j] = 0
        return d
    ans = dijkstra()
    if ans[h][w] == MAX:
        return -1
    return (w*h) - ans[h][w] - cnt -1

print(m())

Measured memory_bytes: 45660
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

bool comp(pair<ll,ll> a, pair<ll,ll> b){
	return a.second > b.second;
}
int main(void){
	ll n,k;
	cin>>n>>k;
	vector<pair<ll,ll> > sushi(n);
	rep(i,n)cin>>sushi[i].first>>sushi[i].second;
	sort(sushi.begin(), sushi.end(),comp);
	
	//rep(i,n)cout<<sushi[i].first<<","<<sushi[i].second<<endl;

	//最初のポイントの計算
	ll ans=0,base=0;
	ll num[n+1];
	rep(i,n)num[i+1]=0;
	rep(i,k){
		base+=sushi[i].second;
		num[sushi[i].first]++;
	}
	ll kind=0;
	rep(i,n)
		if(num[i+1]!=0)kind++;
	ans=base+kind*kind;
	//kind種類の寿司が入ってる時の最大値
	
	ll pivot=k;
	//i個目を抜いて新しい種類を入れて高いスコアが出せるか
	for(int i=k-1;i>-1;i--){
		//2個以上でなければ取る意味ない
		if(num[sushi[i].first]>=2){
			for(;pivot<n;pivot++){
				//新しい種類しか取る必要なし
				if(num[sushi[pivot].first]==0){
					base = base-sushi[i].second+sushi[pivot].second;
					kind++;
					//cout<<"base: "<<base<<",kind: "<<kind<<endl;
					if(ans < base+kind*kind)ans = base+kind*kind;
					num[sushi[i].first]--;
					num[sushi[pivot].first]++;
					pivot++;
					break;
				}
			}
		}
	}

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


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

int main() {
  int N;
  cin >> N;
  int T[N], sum = 0;
  for (int i=0; i<N; i++) {
    cin >> T[i];
    sum += T[i];
  }
  int M;
  cin >> M;
  int P[M], X[M];
  for (int i=0; i<M; i++)
    cin >> P[i] >> X[i];
  for (int i=0; i<M; i++)
    cout << sum - T[P[i]-1] + X[i] << endl;;
  return 0;
}

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

int main() {
 int N;
 cin >> N;
  long long sum = 0;
  for(int i = 1; i < N+1; i++){
    if(i % 3 != 0 && i % 5 != 0){
      sum += i;
    }
  }
      cout << sum << endl;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
  int main(){
int a,b,c,d=0;
cin>>a>>b;
for(int i=1;i<=b;i++){
cin>>c;
d=d+c;
}
if(d>=a) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 998244353;

// dp[i][s]:i番目まで考えたとき和がsになる場合の数
LLONG dp[3001][3001];

int main()
{
	int N, S; cin >> N >> S;
	vector<int> as(N); for (auto &ai : as) cin >> ai;
	dp[0][0] = 1;
	for (int i = 1; i <= N; ++i)
	{
		int ai = as[i - 1];
		// aiを使うとき
		for (int s = ai; s <= S; ++s)
		{
			dp[i][s] += dp[i - 1][s - ai];
		}
		// aiを使わないとき->使わない数をTに入れるかどうかで2通りの場合分け
		for (int s = 0; s <= S; ++s)
		{
			dp[i][s] += dp[i - 1][s] * 2;
			dp[i][s] %= MOD;
		}
	}
	cout << dp[N][S] << endl;
}

Measured memory_bytes: 73960
#include<bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define w(x) scanf("%d",&x);while(x--)
#define ws(x) scanf("%d",&x);getchar();while(x--)
#define rep(i,b) for(i=0;i<=b;i++)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 2*acos(0.0)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const int N=1e6+2;
long long  mod=1e9+9;
int t,j,cs=0,n,a,b,i;
string s,c;

int main()
{
    cin>>s>>c;
    int ans=0;
    for(i=0;i<s.size();i++){
        if(s[i]!=c[i])
            ans++;
     }
     cout<<ans<<endl;
}



Measured memory_bytes: 3848
#include <iostream>

int main()
{
    int a, b;
    int c, d;
    std::cin >> a >> b >> c >> d;

    int area_ab { a * b };
    int area_cd { c * d };

    if (area_ab > area_cd) {
        std::cout << area_ab << std::endl;
    }
    else {
        std::cout << area_cd << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<climits>
#include<set>
#include<map>
#include<stack>
#define ll long long
using namespace std;
int main() {
    ll n,k,t,ans=0;
    cin>>n>>k;
    vector<pair<ll,ll>>p;
    vector<ll>count(200001,0);
    for(ll i=0;i<n;i++){
        cin>>t;
        count[t]++;
    }
    ll s=0;
    for(ll i=1;i<=200000;i++){
        if(count[i]){
            p.push_back(make_pair(count[i],i));
        }
    }
    sort(p.begin(),p.end());
    while(p.size()-s>k){
        ans+=p[s].first;
        s++;
    }
    cout<<ans<<endl;


}
 

Measured memory_bytes: 7920
import static java.lang.System.*;

import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public void solve() {
		int X = nextInt();
		out.println(X/500*1000+X%500-X%5);
	}

	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}

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

	double sqrt(double x) {
		return Math.sqrt(x);
	}

	double pow(double x, double y) {
		return Math.pow(x, y);
	}

	public static void main(String[] args) {
		Main m = new Main();

		m.solve();
	}

	public void println(Object o) {
		out.println(o);
	}

}


Measured memory_bytes: 22356
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}
int main()
{
	if(fopen("vj.in","r"))
	{
		freopen("vj.in","r",stdin);
		freopen("vj.out","w",stdout);
	}

	int q=read();
	while(q--)
	{
		int a=read(),b=read(),c=read(),d=read(),n=a+b;
		int k=ceil((double)max(a,b)/(double)(min(a,b)+1));
		int l=0,r=n+1,mid,ans=0,na,nb,brd;
		while(l<r)
		{
			mid=l+r>>1;
			na=a-mid/(k+1)*k-mid%(k+1);
			nb=b-mid/(k+1);
			if((ll)nb<=(ll)na*k)
				ans=mid+1,l=mid+1;
			else r=mid;
		}
		na=a-ans/(k+1)*k-ans%(k+1),nb=b-ans/(k+1);
		brd=ans+nb-na*k+1;
		for(int i=c;i<=min(d,ans);i++)
			if(i%(k+1))
				putchar('A');
			else 
				putchar('B');
		for(int i=max(c,ans+1);i<=d;i++)
			if((i-brd)%(k+1))
				putchar('B');
			else
				putchar('A');
		puts("");
	}
	return 0;
}
/*
BABAB
BABAB

AABAABAABB
AABAABAABB

BABAB
A

AABAABAABB
BAABA

AABAABABBABBABBABB
ABAB
*/


Measured memory_bytes: 384
#include <iostream>
#include <map>

using namespace std;

char board[8][8];

int usedCol[8];
int usedRow[8];
int usedDiagL[15];
int usedDiagR[15];
int skipRow[8];

void PrintBoard() {
    for ( int row=0; row<8; ++row ) {
	for ( int col=0; col<8; ++col ) cout << board[row][col];
	cout << endl;
    }
}

bool Placeable( int row, int col ) {
    if ( usedCol[col] || usedRow[row] || usedDiagL[row-col+7] || usedDiagR[row+col] ) return false;
    return true;
}

void Put( int row, int col ) {
    board[row][col] = 'Q';
    usedCol[col] = usedRow[row] = usedDiagL[row-col+7] = usedDiagR[row+col] = 1;
}

void Release( int row, int col ) {
    board[row][col] = '.';
    usedCol[col] = usedRow[row] = usedDiagL[row-col+7] = usedDiagR[row+col] = 0;
}

bool Try( int row, int col, int piece ) {

    if ( piece == 8 ) return true;

    if ( skipRow[row] >= 0 ) {

	int col = skipRow[row];
	
	for ( int i=0; i<8; ++i ) {
	    if ( i == col ) continue;
	    if ( Try( row+1, i, piece+1 ) ) return true;
	}
    }
    
    if ( Placeable( row, col ) ) {

	Put( row, col );

	for ( int i=0; i<8; ++i ) {
	    if ( i == col ) continue;
	    if ( Try( row+1, i, piece+1 ) ) return true;
	}
	
	Release( row, col );
    }
    
    return false;
    
}

int main() {


    for ( int i=0; i<8; ++i ) {
	for ( int j=0; j<8; ++j ) {
	    board[i][j] = '.';
	}
	usedCol[i] = usedRow[i] = 0;
	skipRow[i] = -1;
    }
    for ( int i=0; i<15; ++i ) usedDiagL[i] = usedDiagR[i] = 0;

    int n, row, col;
    cin >> n;

    for ( int i=0; i<n; ++i ) {
	cin >> row >> col;
	board[row][col] = 'Q';
	if ( !Placeable( row, col ) ) cout << "strange input" << endl;
	Put( row, col );
	//	cout << row << " " << col << endl;
	skipRow[row] = col;
    }

    for ( int col=0; col<8; ++col ) {

	//	cout << "try x = " << col << endl;
	//	PrintBoard();
	    
	if ( Try( 0, col, 0 ) ) break;
    }

    PrintBoard();
    
    return 0;
}



Measured memory_bytes: 3112
#include<stdio.h>
//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}
int main() {
	long long int n, m, num[500] = {}, result;
	scanf("%lld%lld",&n,&m);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &num[i]);
		result += small(num[i], m - num[i]) * 2;
	}
	
	printf("%lld", result);
			
}




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

using namespace std;

int main()
{
  string s;
  cin>>s;
  if(s=="Sunny")
  {
      cout<<"Cloudy"<<endl;
  }
  else if(s=="Cloudy")
  {
      cout<<"Rainy"<<endl;
  }
  else if(s=="Rainy")
  {
      cout<<"Sunny"<<endl;
  }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for(int i=0; i<n; i++)

vector<bool> seen;
vector<long long> num(200200);
void dfs(const Graph &G, int v) {
    seen[v] = true;

    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; 
        num[next_v]+=num[v];
        dfs(G, next_v); 
    }
}

int main() {
    int N; cin >> N;
    int Q; cin >> Q;
    Graph G(N);
    for (int i = 0; i < N-1; ++i) {
        int a, b;
        cin >> a >> b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    int p[Q],x[Q];
    rep(i,Q){
        cin>>p[i]>>x[i];
        num[p[i]-1] += x[i];
    } 
    
    seen.assign(N, false); 
    dfs(G, 0);

    rep(i,N) cout<<num[i]<<" ";
    cout<<endl;
}

Measured memory_bytes: 25856
A, B, M = [int(n) for n in input().split()]
a  = [int(n) for n in input().split()]
b = [int(n) for n in input().split()]
ma = sorted(a)[0]
mb = sorted(b)[0]
XY = {}
ans = ma + mb
for m in range(M):
    x, y, c = [int(n) for n in input().split()]
    dv = a[x-1] + b[y-1] - c
    ans = min(ans , dv)
print(ans)
        

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

int main() {
	
	ll h,n;
	cin>>h>>n;
	
	ll arr[n];
	
	for(int i=0;i<n;i++)
	cin>>arr[i];
	
	ll sum=0;
	
	for(int i=0;i<n;i++)
	sum+=arr[i];
	
	if(sum>=h){
	    std::cout << "Yes" << std::endl;
	}
	else{
	    std::cout << "No" << std::endl;
	}
	
	
	
	return 0;
}

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

#define int long long
#define INT int
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;
const long long INF = 1LL << 60;

vector<pair<long long, long long>> prime_factorize(long long N)
{
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; ++a)
    {
        if (N % a != 0)
            continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0)
        {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1)
        res.push_back({N, 1});
    return res;
}
int n;

signed main()
{
    cin >> n;
    auto d = prime_factorize(n);

    int ans = 0;
    map<int, int> indx;

    for (auto x : d)
    {
        //cout << x.first << " " << x.second << endl;
        indx[x.first] = x.second;
    }

    for (auto x : indx)
    {
        int i = 1;
        while (x.second > 0)
        {
            x.second -= i;
            if (x.second >= 0)
            {
                ans++;
            }
            i++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define re register
#define int long long
using namespace std;

inline int read(){
	re int ans = 0;re bool f = 1;re char ch = getchar();
	while(ch<'0'||ch>'9'){if (ch=='-')f = 0;ch = getchar();}
	while(ch>='0'&&ch<='9'){
		ans = (ans<<3)+(ans<<1)+(ch^48);
		ch = getchar();
	}
	return f?ans:~(ans-1);
}

signed main(void){
	int n = read();
	int ans = 0;
	for(re int i=1;i<=n;++i){
		if(i%3&&i%5){
			ans+=i;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 1005
#define PI 3.14159265358979323846264338327950
#define ll signed long long int
using namespace std;
ll t , n, k,  x = 0, y = 2, m, ans = 0 ;
ll a[MAXX], b[MAXX], c[MAXX], d;
double f = 0.5;
vector<ll> v[MAXX];
bool used[MAXX];

signed main()
{
	
	cin >> n ;
	for(ll i = 0; i < n-1; i++){
		cin >> b[i];
	}
	a[0]= b[0];
	a[1]= b[0];
	if(n == 1){
		cout << 2*a[0];
	}
	for(ll i = 0; i < n-1; i++){
		if(b[i] >= a[i]){
			a[i+1] = b[i];
		}
		else{
			a[i] = b[i];
			a[i+1] = b[i];
		}
	}
	for(ll i = 0; i < n; i++){
		ans += a[i];
	}
	cout << ans ;
	return 0;    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        
        int a = 0;
        int b = 0;
        int c = 0;
        int sum = 0;
        
        for(int i = 1; i <= K; i++) {
            for(int j = 1; j <= K; j++) {
                for(int k = 1; k <= K; k++) {
                    sum += gcd(gcd(i, j), k);
                }   
            }
        }
        System.out.println(sum);
        
    }
    static int gcd(int x, int y) {
        int amari = 0;
        if(x % y == 0) {
            return y;
        }else {
            amari = x % y;
            return gcd(y, amari);
        }
    }
}

Measured memory_bytes: 35796
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())

# 複数個の数値を、intの配列として取得
A = list(map(int, input().split()))

# (A[i],i)のタプルリストを作って、昇順ソート
L = []
for i in range(N):
    a = tuple([A[i],i+1])
    L.append(a)
L = sorted(L, key=lambda x:x[0])

for i in range(N):
    print(L[i][1])

Measured memory_bytes: 20324
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL

struct node {
  int key;
  struct node *right;
  struct node *left;
  struct node *parent;
};
typedef struct node * Node;
Node root;
void Insert(int );
void inorder(Node );
void preorder(Node );

int main()
{
  int i,j,k;
  char c[10];
  scanf("%d",&k);
  
  for(i=0;i<k;i++)
    {
      scanf("%s",&c[0]);
      if(c[0]=='i')
	{
	  scanf("%d",&j);
	  Insert(j);
	}
      else if(c[0]=='p') 
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
    }
  return 0;
}

void Insert(int p)
{
  Node x=root;
  Node y=NIL;
  Node z;
  
  z=(Node )malloc(sizeof(struct node));
  z->key=p;
  z->left=NIL;
  z->right=NIL;
  
  while(x!=NIL)
    {
      y=x;
      if(z->key < x->key) x=x->left;
      else x=x->right;

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

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

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

Measured memory_bytes: 25968
#include <bits/stdc++.h>
#define read(x) scanf("%d",&x)
#define write(x) printf("%d",x)
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;

int main(){
 	
	int n,k;
	cin>>n>>k;
	std::vector<long long> a(n);
	rep(i,n) cin>>a[i];
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	long long  sum = 0;
	for(int i=k;i<n;i++){
		sum += a[i];
	}
	cout<<sum;
	return 0;
}


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

using i64 = int64_t;

constexpr i64 MOD = 998244353;

i64 repeated_squaring(i64 x, i64 n) {
    i64 res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    vector<i64> v(n+1);
    bool flag = true;
    for(int i=0;i<n;++i){
        i64 d;
        cin >> d;
        v[d]++;
        if(i == 0 && d != 0)flag = false;
    }
    if(v[0] != 1 || !flag){
        cout << 0 << endl;
        return 0;
    }
    for(int i=1;i<n;++i){
        if(v[i] != 0 && v[i-1] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    i64 ans = v[0];
    for(int i=1;i<n;++i){
        if(v[i] == 0)break;
        i64 tmp = repeated_squaring(v[i-1], v[i]);
        ans *= tmp;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define M 1000000007
#define ll long long
#define pb push_back
#define F first
#define S second
#define vl vector<ll>
#define vvl vector<vl>
#define pii pair<int,int>
#define mkp make_pair

const int N=21;
ll a[N][N];
ll n;
ll last;
ll dp[2100000];
bool vis[2100000];


ll calc(ll temp, ll level)
{
	if(vis[temp]) return dp[temp]%M;
	
  	vis[temp]=true;
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		if((!(temp & (1<<i))) && a[level][i]==1)
		{
			ans=(ans+(calc(temp+(1<<i),level+1)%M))%M;
		}
	}
	dp[temp]=ans%M;
	return dp[temp];
}

int main()
{
	fio;
	cin >> n;
	for(ll i=0;i<n;i++){for(ll j=0;j<n;j++) cin >> a[i][j];}
  
  	last=(1<<(n)) -1;
  	//cout << last << endl;
  	dp[last]=1;
  	vis[last]=true;
	cout << calc(0,0)%M << endl;
}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k, ans = 1e9;
    cin >> n >> k;
    int arr[n + 5];
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr, arr + n);
    for(int i = 0; i <= n - k; i++)
        ans = min(ans, arr[i + k - 1] - arr[i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int cnt[100001];
int arr[100001];
bool left(int index)
{
    for (int i=0;i<index;i++)
    {
        if (cnt[arr[i]]>1)
        {
            return true;
        }
    }
    return false;
}
void show(int index)
{
    printf("Arr: ");
    for (int i=0;i<index;i++)
    {
        printf("%d ",arr[i]);
    }
    printf("\n");
    printf("Cnt: ");
    for (int i=0;i<index;i++)
    {
        printf("%d ",cnt[arr[i]]);
    }
    printf("\n");
}
main()
{
    int n,index=0;
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    {
        int input;
        scanf("%d",&input);
        if (cnt[input]==0)
        {
            arr[index]=input;
            index++;
        }
        cnt[input]++;
    }
    //show(index);
    while (left(index)==true)
    {
        for (int i=0;i<index;i++)
        {
            if (cnt[arr[i]]>1)
            {
                cnt[arr[i]]--;
                int mx=-999;
                int keepj;
                for (int j=0;j<index;j++)
                {
                    if (cnt[arr[j]]>mx)
                    {
                        mx = cnt[arr[j]];
                        keepj = j;
                    }
                }
                cnt[arr[keepj]]--;
            }
        }
        //show(index);
    }
    int ans=0;
    for (int i=0;i<index;i++)
    {
        ans+=cnt[arr[i]];
    }
    printf("%d",ans);

}


Measured memory_bytes: 896
/*  -*- coding: utf-8 -*-
 *
 * 2807.cc: Fractal Tree
 */

#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>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef pair<int,int> pii;
typedef vector<pii> vpii;

struct Stat {
  int i, prt;
  double p;
  Stat() {}
  Stat(int _i, int _prt, double _p): i(_i), prt(_prt), p(_p) {}
};

/* global variables */

vpii nbrs[MAX_N];

/* subroutines */

/* main */

int main() {
  double p;
  int n;
  scanf("%lf%d", &p, &n);

  for (int i = 1; i < n; i++) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    x--, y--;
    nbrs[x].push_back(pii(y, c));
    nbrs[y].push_back(pii(x, c));
  }

  queue<Stat> q;
  q.push(Stat(0, -1, 1.0));
  double t = 0.0;

  while (! q.empty()) {
    Stat u = q.front(); q.pop();
    vpii nbru = nbrs[u.i];
    double vp = u.p * p;

    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &vi = vit->first, &vc = vit->second;
      if (vi != u.prt) {
	t += vc * vp;
	q.push(Stat(vi, u.i, vp));
      }
    }
  }
  //printf("t=%lf\n", t);

  q.push(Stat(0, -1, 1.0));
  double ans = t;
  
  while (! q.empty()) {
    Stat u = q.front(); q.pop();
    vpii nbru = nbrs[u.i];
    double vp = u.p * p;
    ans += t * u.p;

    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &vi = vit->first;
      if (vi != u.prt)
	q.push(Stat(vi, u.i, vp));
    }
  }
  printf("%.10lf\n", ans);

  return 0;
}



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

ans = 0
for i in range(1,n+1):
    ans += i * (n+1-i)

for i in range(n-1):
    a,b = map(int,input().split())
    
    ans -= (min(a,b) * (n+1-max(a,b)))
    
print(ans)

Measured memory_bytes: 74376
#include <iostream>
using namespace std;
int main() {
  int a,b,c;
  cin>>a;
  cin>>b;
  if(a>9){
    cout<<-1<<endl;
  }
  else if(b>9){
    cout<<-1<<endl;
  }
  else{
    c=a*b;
    cout<<c<<endl;
  }
  	return 0;
}

Measured memory_bytes: 888
main :: IO ()
main = do
  n <- getLine
  hs <- map (read :: String -> Int) . words <$> getLine
  print $ ans hs

ans :: [Int] -> Int
ans hs = snd $ foldl (\(m,n) h -> if m <= h then (h,n+1) else (m,n)) (0,0) hs

Measured memory_bytes: 508
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;

int main() {
	
	long long int A, B, C, X, Y;
	
	cin >> A >> B >> C >> X >> Y;
	
	long long int ans1 = A * X + B * Y;
	long long int ans2 = 2 * C * X + B * max(0LL, Y - X);
	long long int ans3 = 2 * C * Y + A * max(0LL, X - Y);
	
	cout << min(ans1, min(ans2, ans3)) << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int n,x,y,ans[2010];
int main()
{
    int i,j,t;
    cin>>n>>x>>y;
    for(i=1;i<=n;i++)
     for(j=i+1;j<=n;j++)
     {
         t=min(j-i,abs(i-x)+1+abs(y-j));
         ans[t]++;
     }
    for(i=1;i<n;i++) cout<<ans[i]<<endl;
    //system("pause");
}
    


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc =  new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
      	int c = sc.nextInt();
      
      	if((c > a && c < b) || (c < a && c > b))
          System.out.println("Yes");
      	else
          System.out.println("No");

			
		sc.close();
	}
}

Measured memory_bytes: 21844
a, b, c = gets().chomp.split("\s").map{|x| x.to_i}

l = [a, b, c].sort()

diff1 = l[2] - l[0]
diff2 = l[2] - l[1]

r = diff2
rem = diff1 - diff2

if rem.even?
  r += rem / 2
  puts r
  exit()
end

r += rem / 2 + 1
r += 1

puts r


Measured memory_bytes: 14260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll H, W; cin >> H >> W;
  char c[H][W];
  for (ll i = 0; i < H; i++) {
    for (ll j = 0; j < W; j++) {
      cin >> c[i][j];
    }
  }
  vector<ll> dx = {1,0,-1,0};
  vector<ll> dy = {0,1,0,-1};
  bool ok = true;
  for (ll i = 0; i < H; i++) {
    for (ll j = 0; j < W; j++) {
      bool isolate = true;
      for (ll k = 0; k < 4; k++) {
        if (0 <= i+dx[k] && i+dx[k] < H && 0 <= j+dy[k] && j+dy[k] < W && c[i][j] == '#' && c[i+dx[k]][j+dy[k]] == '#') {
          isolate = false;
        }
      }
      //cout << isolate << endl;
      if (c[i][j] == '#' && isolate) {ok = false;}
    }
  }
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main()
{
    string s1;
    string s2;
    cin>>s1>>s2;
    int m=s1.size();
    int n=s2.size();
    int dp[m+1][n+1];
    for(int i=0;i<=m;i++)
    {
        dp[i][0]=0;
    }
    for(int j=0;j<=n;j++)
    {
        dp[0][j]=0;
    }
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(s1[i-1]==s2[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    /*for(int i=0;i<=m;i++)
    {
        for(int j=0;j<=n;j++)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    string ans="";
    int i=m;
    int j=n;
    while(i>0 && j>0)
    {
        if(s1[i-1]==s2[j-1])
        {
            ans=s1[i-1]+ans;
            i--;
            j--;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1])
            {
                i--;
            }
            else
            {
                j--;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 35456
n, s = map(int, input().split())
a = list(map(int, input().split()))
import numpy as np
mod = 998244353
f = np.zeros(3020, np.int64)
f[0] = 1
for b in a:
  ff = 2*f
  ff[b:] += f[:-b]
  ff %= mod
  f = ff
print(f[s])

Measured memory_bytes: 27264
N=int(input())
h=list(map(int,input().split()))
dp=[1000000001]*N
dp[0]=0
for i in range(N-1):
	dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
	if i<N-2:
		dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
print(dp[N-1])

Measured memory_bytes: 13976
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>; //pop_back pop_front push_back push_front front back clear empty
using L = vector<long long>;
using M = map<int,long long>;  //erase  (でキーごと削除) 追加削除検索O(log(N))
using A = vector<vector<long long>>;
using P = priority_queue<long long>; //erase  (でキーごと削除)
using U = unordered_map<int,long long>; //map  (との違いはkeyの順番を保持していない)

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define sortedreverce(vector) sort(vector.rbegin(),vector.rend()) //O(nlongn)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vdel(vector,a) vector.erase(vector.begin()+a)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
#define inf 1000000000000000000+10

template <typename T>
void print(T a){for (auto b:a){cout<<b<<" ";};cout<<endl;}
template <>
void print(unsigned long a){cout<<a<<endl;}
template <>
void print(char a){cout<<a<<endl;}
template <>
void print(bool a){cout<<a<<endl;}
template <>
void print(long long a){cout<<a<<endl;}
template <>
void print(A a){for (auto b:a){for (auto c:b){cout<<c<<" ";}cout<<endl;};cout<<endl;}
template <>
void print(string a){cout<<a<<endl;}


//存在確認はmap!!!!!!!!!!!!!か配列に埋め込んでcontinueで回避
//__gcd(a,b)はコンパイラがGCC時のみ
//printf("%.16f", ans); 誤差落ち対応君
vector<long long> groupby(string s){
    vector<long long> res;
    long long pre=s[0];
    long long tmp=1;
    for (long long i=1; i<s.size(); i++ ){
        if (s[i]==pre) tmp+=1;
        else{
            res.push_back(tmp);
            pre=s[i];
            tmp=1;
        }
    }
    res.push_back(tmp);
    return res;
}

int main(){
    string s;
    cin>>s;
    L a=groupby(s);
    long long cnt=0;
//    print(a);
    for(long long i=0  ;i<s.size()  ;i++){
        if (s[i]=='R' and s[i+1]=='L'){
            cout<<(a[cnt*2]+1)/2+a[cnt*2+1]/2<<" "<<a[cnt*2]/2+(a[cnt*2+1]+1)/2<<" ";
            cnt++;
            i++;
        }else{
            cout<<0<<" ";
        }
        
    }
}

Measured memory_bytes: 1656
//
// Created by Harshit on 20-08-2020.
//

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector <int> H(n+1,0);
    for(int i=0;i<n;i++){
        cin>>H[i+1];
    }
    vector <int> res(n+1,INT_MAX);
    res[1]=0;
    for(int i=1;i<=n;i++){
        for(int j=1;i+j<=n && j<=k;j++){
                res[i+j]=min(res[i+j],res[i]+abs(H[i+j]-H[i]));
        }
    }
    cout<<res[n]<<endl;
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
//vector<vector<int>> vec(i, vector<int>(j));

vector<int> input(int N) {
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    return vec;
}

void Main() {
    string s; cin >> s;
    vector<string> word = { "dream","dreamer","erase","eraser" };
    reverse(ALL(s));
    for (int i = 0; i < word.size(); i++)
    {
        reverse(ALL(word[i]));
    }
    int idx = 0;
    while (true) {
        if (s.substr(idx, 7) == word[1]) {
            idx += 7;
        }
        else if (s.substr(idx, 6) == word[3]) {
            idx += 6;
        }
        else if ((s.substr(idx, 5) == word[0]) || (s.substr(idx, 5) == word[2])) {
            idx += 5;
        }
        else {
            cout << "NO" << endl;
            break;
        }
        if (idx == s.size()) {
            cout << "YES" << endl;
            break;
        }
    }
}

int main() {
	Main();
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
using namespace std;
 

int dp[305][305][305];


signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif    

    string a;
    cin>>a;
    int k;
    cin>>k;
    int n=a.length();
    a="#"+a;
    for(int i=n;i>=1;i--)
    {
        dp[i][i][0]=1;
        for(int j=i+1;j<=n;j++)
        {
            for(int l=0;l<=k;l++)
            {
                if(a[i]==a[j])
                {
                    dp[i][j][l]=dp[i+1][j-1][l]+2;
                }
                else
                {
                    if(l>0)
                        dp[i][j][l]=dp[i+1][j-1][l-1]+2;
                } 
                dp[i][j][l]=max({dp[i][j][l],dp[i+1][j][l],dp[i][j-1][l]});
            }
        }
    }

    int mx=0;
    for(int i=0;i<=k;i++)
        mx=max(mx,dp[1][n][i]);
    cout<<mx;

}

Measured memory_bytes: 112264
#include<bits/stdc++.h>
#define REP(i,n) for(int (i)=0 ;(i)<(n);(i)++)
#define REPR(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(x) x.begin(),x.end()
#define REVERSE(x) reverse(x.begin(),x.end())
#define SORT(x,n) sort(x,x)
#define P pair<int,int>
typedef long long LL;
const int INF=1000000007;
using namespace std;
LL gcd(LL a,LL b){
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
LL number(LL a,LL b,LL div){
  if(a%div==0){
    return b/div-a/div+1;
  }
  else{
    return b/div-a/div;
  }
}
int main(){
  LL a,b,c,d;
  cin>>a>>b>>c>>d;
  LL lcm=c*d/gcd(c,d);
  LL ans=b-a+1-number(a,b,c)-number(a,b,d)+number(a,b,lcm);
  cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
  int N;
  cin >> N;
  vint P(N);
  cin >> P;
  
  int cnt = 0;
  int min = P[0];
  REP(i,N){
    if(min >= P[i]){
      min = P[i];
      cnt++;
    }
  }
  
  cout << cnt << endl;
  
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define exists(s,x) (s).find(x)!=(s).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
#define fi first
#define se second
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;
 
inline ll add(ll x, ll y) {return (x+y)%MOD;}
inline ll mul(ll x, ll y) {return (x*y)%MOD;}
inline ll sub(ll x, ll y) {
    ll res = x - y;
    if(res < 0) res += MOD;
    return res;
}
inline ll modpow(ll x, ll y) {
    ll res = 1;
    while(y) {
        if(y&1) res = mul(res,x);
        y >>= 1;
        x = mul(x,x);
    }
    return res;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    int q; cin >> q;
    int revcnt = 0;
    vector<pair<int,pair<int,char>>> v;
    vector<int> w(q,0);
    REP(i,q) {
        int ev; cin >> ev;
        if(ev == 1) {
            w[i] = 1;
        }
        else {
            int j; char c; cin >> j >> c;
            v.push_back(make_pair(i,make_pair(j,c)));
        }
    }
    for(int i = q-1; i>0; --i) w[i-1] += w[i];
    if(w[0]%2) reverse(all(s));
    deque<char> dq;
    for(auto& p:v) {
        int ty = p.se.fi;
        int idx = p.fi;
        char c = p.se.se;
        if((ty+w[idx]) % 2) dq.push_front(c);
        else s += c;
    }
    string ans;
    while(!dq.empty()) {
        char c = dq.front(); dq.pop_front();
        ans += c;
    }
    ans += s;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5700
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
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;}
constexpr long long INF = 1e18;

int dp[3030][3030];

signed main(){
	int N,T;
	cin>>N>>T;
	vector<int>a(N),b(N);
	vector<pair<int,int>>v(N);
	REP(i,N)cin>>v[i].first>>v[i].second;
	sort(ALL(v));
	REP(i,N){
		a[i] = v[i].first;
		b[i] = v[i].second;
	}
	REP(i,N){
		REP(j,T){
			CHMAX(dp[i+1][j],dp[i][j]);
			if(j+a[i]<=T)CHMAX(dp[i+1][j+a[i]],dp[i][j]+b[i]);
			else CHMAX(dp[i+1][T],dp[i][j]+b[i]);
		}
	}
	int ma = 0;
	REP(i,3030)REP(j,3030)CHMAX(ma,dp[i][j]);
	cout<<ma<<endl;
}

Measured memory_bytes: 71936
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	string s;
	cin >> s;
	for (auto &t : s) {
		if (t == '?') t = 'D';
	} 
	cout << s << endl;
}

Measured memory_bytes: 3380
#include <stdio.h>

#define MAX 1000000
#define NIL -1

struct Node{int p, l, r; };

struct Node T[MAX];
int n, D[MAX];

void print(int u);
int rec(int u, int p);

int main(){
  int i, j, k, d, v, c, l, r;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    T[i].p=NIL;
    T[i].l=NIL;
    T[i].r=NIL;
}

  for(i=0; i<n; i++){
    scanf("%d%d", &v, &d);
    for(j=0; j<d; j++){
      scanf("%d", &c);
      if(j==0) T[v].l=c;
      else T[l].r =c;
      l=c;
      T[c].p=v;
    }
  }
  for(i=0; i<n; i++){
    if(T[i].p==NIL) r=i;
  }

  rec(r, 0);

  for(i=0; i<n; i++) print(i);

  return 0;
}

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p==NIL) printf("root, ");
  else if(T[u].l==NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for(i=0, c=T[u].l; c!=NIL; i++, c=T[c].r){
    if(i) printf(", ");
    printf("%d", c);
}
  printf("]\n");

}

int rec(int u, int p){
  D[u]=p;
  if(T[u].r!=NIL) rec(T[u].r, p);
  if(T[u].l!=NIL) rec(T[u].l, p+1);
}

Measured memory_bytes: 8228
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		
	Scanner scan = new Scanner(System.in);
	String str = scan.next();
	
	String[] strArray = str.split("");
	
	int count = 0;
	
	for(int i = 0; i < strArray.length ; i++ ) {
	if(strArray[i].equals("1")) {
		count++;
	  }
	 }
	System.out.println(count);
	}
}

Measured memory_bytes: 22868
unittest
{
	assert( [ "2 2", "1 2", "3 4", "3 4", "2 1" ].parse.expand.solve == 0 );
	assert( [ "2 3", "1 10 80", "80 10 1", "1 2 3", "4 5 6" ].parse.expand.solve == 2 );
	
	assert( [ "2 2", "0 0", "0 0", "80 80", "80 80" ].parse.expand.solve == 80 );		// 追加ケース
}



import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hw = input.front.split.to!( long[] );
	auto ass = new long[][]( hw[ 0 ], hw[ 1 ] );
	foreach( ref as; ass )
	{
		input.popFront;
		as = input.front.split.to!( long[] );
	}
	auto bss = new long[][]( hw[ 0 ], hw[ 1 ] );
	foreach( ref bs; bss )
	{
		input.popFront;
		bs = input.front.split.to!( long[] );
	}
	return tuple( ass, bss );
}

auto solve( long[][] ass, long[][] bss )
{
	// dp[ y ][ x ][ 偏り ] = この位置でこの偏りにできるか
	auto dp = new bool[][][]( ass.length, ass[ 0 ].length, 1 + ( ass.length + ass[ 0 ].length - 1 ) * 80 );
	dp[ 0 ][ 0 ][ abs( ass[ 0 ][ 0 ] - bss[ 0 ][ 0 ] ) ] = true;
	for( auto y = 0L; y < dp.length; y++ )
	{
		for( auto x = 0L; x < dp[ y ].length; x++ )
		{
			for( auto d = 0L; d < dp[ y ][ x ].length; d++ )
			{
				if( !dp[ y ][ x ][ d ] ) continue;
				
				if( y + 1 < dp.length )
				{
					auto v = abs( ass[ y + 1 ][ x ] - bss[ y + 1 ][ x ] );
					dp[ y + 1 ][ x ][ abs( d - v ) ] = true;
					dp[ y + 1 ][ x ][      d + v   ] = true;
				}
				if( x + 1 < dp[ y ].length )
				{
					auto v = abs( ass[ y ][ x + 1 ] - bss[ y ][ x + 1 ] );
					dp[ y ][ x + 1 ][ abs( d - v ) ] = true;
					dp[ y ][ x + 1 ][      d + v   ] = true;
				}
			}
		}
	}
	foreach( d, b; dp[ $ - 1 ][ $ - 1 ] )
	{
		if( b ) return d;
	}
	assert( false );
}


Measured memory_bytes: 105724
import numpy as np
from sys import argv
import time
np.random.seed(10)


def input_from_file():
    with open(argv[1], "r") as f:
        D = int(f.readline())
        C = np.array(f.readline().split(), dtype=int)
        S = tuple(tuple(map(int, f.readline().split())) for _ in range(D))
    return D, C, S


def input_from_console():
    D = int(input())
    C = np.array(input().split(), dtype=int)
    S = tuple(tuple(map(int, input().split())) for _ in range(D))
    return D, C, S


def greed(D, C, S):
    last = np.ones(26, dtype=int)
    ans = []
    for s in S:
        s = np.array(s)
        tmp = s + C * last
        i = np.argmax(tmp)
        last[i] = 0
        last += 1
        ans.append(i + 1)
    return ans


def calc_score(D, C, S, T):
    res = 0
    last = np.ones(26, dtype=int)
    for d, t in enumerate(T):
        t -= 1
        last[t] = 0
        score = S[d][t]
        score -= (C * last).sum()
        res += score
        last += 1
    return res


def output_to_file(ans):
    with open("output.txt", "w", newline="") as f:
        for a in ans:
            f.write("{}\n".format(a))


def main():
    start = time.time()
    lim = 1.800
    D, C, S = input_from_console()
    #D, C, S = input_from_file()
    #初期解, 貪欲法
    sol = greed(D, C, S)
    score = calc_score(D, C, S, sol)
    while True:
        d = np.random.randint(0, D)
        q = np.random.randint(1, 27)
        old = sol[d]
        sol[d] = q
        new_score = calc_score(D, C, S, sol)
        if new_score > score:
            score = new_score
        else:
            sol[d] = old
        if time.time() - start >= lim:
            break
    print(*sol, sep="\n")
    # output_to_file(sol)


if __name__ == "__main__":
    main()

Measured memory_bytes: 27724
package main

import "fmt"

func main() {
	var foldNum int
	var minNum, maxNum int
	fmt.Scan(&foldNum)
	fmt.Scan(&minNum, &maxNum)

	var OK bool = false
	for i := minNum; i <= maxNum; i++ {
		if i%foldNum == 0 {
			OK = true
		}
	}

	if OK {
		fmt.Println("OK")
	} else {
		fmt.Println("NG")
	}
}


Measured memory_bytes: 1752
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	aa := make(SortBy, n)

	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
	}

	sort.Sort(aa)
	var ans int64
	for aa[0] >= int64(n) {
		loop := aa[0] / int64(n)
		ans += loop
		aa[0] = aa[0] % int64(n)
		for j := 1; j < n; j++ {
			aa[j] += loop
		}
		sort.Sort(aa)
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

type SortBy []int64

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] > a[j] }


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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    K=I()
    a,b=MI()
    
    flag=0
    for i in range(a,b+1):
        if i%K==0:
            flag=1
    
    if flag==1:
        print("OK")
    else:
        print("NG")
    
main()


Measured memory_bytes: 61728
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 5e+3+5;
const int M = 205;

int n,m;
LL a[N];
int b[N][M];
LL f[N][N];
int sta[N],top;

void add(int x1,int x2,int y1,int y2,int v){f[x1][y1]+=v;f[x1][y2+1]-=v;f[x2+1][y1]-=v;f[x2+1][y2+1]+=v;}

int main(){
	n=get();m=get();
	fo(i,2,n)a[i]=get();
	fo(i,1,n)a[i]+=a[i-1];
	fo(i,1,n)fo(j,1,m)b[i][j]=get();
	fo(i,1,m){
		top=0;
		fo(x,1,n){
			while(top&&b[sta[top]][i]<b[x][i]){
				add(sta[top-1]+1,sta[top],sta[top],x-1,b[sta[top]][i]);
				top--;
			}
			sta[++top]=x;
		}
		fo(x,1,top)add(sta[x-1]+1,sta[x],sta[x],n,b[sta[x]][i]);
	}
	fo(i,1,n)
		fo(j,1,n)f[i][j]=f[i][j]+f[i-1][j]+f[i][j-1]-f[i-1][j-1];
	LL ans=0;
	fo(i,1,n)
		fo(j,i,n){
			LL tmp=a[i]-a[j]+f[i][j];
			if (tmp>ans)ans=tmp;
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 199936