akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
     
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
     
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
  int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  int i;
  for (i = 0; i < a; i++) {
    if (s[i] == '-') {
      cout << "No" << endl;
      return 0;
    }
  }
  if (s[a] != '-') {
    cout << "No"<< endl;
    return 0;
  }
  for (i = a+1; i < s.size(); i++) {
    if (s[i] == '-') {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
int main (void){
int i,a,b,c,d=0 ;
scanf("%d",&a) ;
scanf("%d",&b) ;
scanf("%d",&c) ;
for( i=a;i<=b;i++){
 if(c%i==0){ 
d++; }}
printf("%d\n",d) ;
return 0 ;}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
//#define MOD 1000000007
#define MOD 998244353
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;

int cost(int a,P p){
	if(p.second<a)return a-p.second;
	if(a<p.first)return p.first-a;
	return 0;
}
int New(int a,P p){
	if(p.second<a)return p.second;
	if(a<p.first)return p.first;
	return a;
}
signed main(){
	int n;scanf("%d",&n);
	/*ll L=LLONG_MIN,R=LLONG_MAX;
	rep(i,n){
		ll l,r;cin>>l>>r;
		L=max(L,l);
		R=min(R,r);
	}
	cout<<abs(L)+abs(L-R)+abs(R)<<endl;*/
	multiset<P,function<bool(P,P)>>a([](P a,P b){return a<b;}),
									b([](P a,P b){return P(a.second,a.first)<P(b.second,b.first);});
	rep(i,n){
		ll l,r;cin>>l>>r;
		a.insert(P(l,r));
		b.insert(P(l,r));
	}
	auto a2=a,b2=b;
	int pos=0;
	ll ans=0;
	int cnt=0;
	while(!a.empty()){
		P p;
		if(cnt%2==0){
			p=*a.rbegin();
		}
		else{
			p=*b.begin();
		}
		ans+=cost(pos,p);
		a.erase(a.find(p));
		b.erase(b.find(p));
		pos=New(pos,p);
		cnt++;
		/*
		auto p=*a.rbegin(),q=*b.begin();
		if(a.size()==1){
			if(cost(pos,p)+abs(New(pos,p))<cost(pos,q)+abs(New(pos,q))){
				
			}
		}
		if(cost(pos,p)<cost(pos,q)){
			ans+=cost(pos,q);
			pos=New(pos,q);
			a.erase(a.find(q));
			b.erase(b.find(q));
		}
		else{
			ans+=cost(pos,p);
			pos=New(pos,p);
			a.erase(a.find(p));
			b.erase(b.find(p));
		}*/
	}
	ans+=abs(pos);
	
	int pos2=0;
	ll ans2=0;
	int cnt2=0;
	while(!a2.empty()){
		P p;
		if(cnt2%2==0){
			p=*b2.begin();
		}
		else{
			p=*a2.rbegin();
		}
		ans2+=cost(pos2,p);
		a2.erase(a2.find(p));
		b2.erase(b2.find(p));
		pos2=New(pos2,p);
		cnt2++;
	}
	ans2+=abs(pos2);
	cout<<max(ans,ans2)<<endl;
}

Measured memory_bytes: 27264
from itertools import accumulate
n, k, *A = map(int, open(0).read().split())
for _ in range(min(k, 50)):
    B = [0] * (n+1)
    for i in range(n):
        B[max(0, i-A[i])] += 1
        B[min(n, i+A[i]+1)] -= 1
    *A, = accumulate(B)
print(*A[:n])

Measured memory_bytes: 211080
#include <iostream>
using namespace std;
#define el '\n'
typedef long long ll;
int N, X[102],ans = 0x3f3f3f3f;
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin >> N;
	for(int i = 1;i<=N;i++)cin >> X[i];
	for(int i = 1;i<=100;i++){
		int tmp = 0;
		for(int j = 1;j<=N;j++)tmp+=((X[j]-i)*(X[j]-i));
		ans = min(ans, tmp);
	}
	cout << ans << el;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {

     string s;
     cin>>s;
     if(s == "SUN") cout<<7;
     else if(s == "MON") cout<<6;
     else if(s == "TUE") cout<<5;
     else if(s == "WED") cout<<4;
     else if(s == "THU") cout<<3;
     else if(s == "FRI") cout<<2;
     else cout<<1;
}




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

# ユークリッドの互除法で最大公約数を求める
def gcd( a, b ):
    # print(a,b)
    if a == 0: return b
    return gcd( b%a, a )

ans = A[0]
for i in range(N-1):
    ans = gcd( ans, A[i+1] )

print( ans )

Measured memory_bytes: 14224
import math

n = int(input())
x = [int(x) for x in input().split()]
y = [int(x) for x in input().split()]

for p in range(1, 4):
    D = sum([abs(x[i]-y[i]) ** p for i in range(n)]) ** (1/p)
    print(D)

print(max([abs(x[i]-y[i]) for i in range(n)]))


Measured memory_bytes: 5700
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,ans,v[1001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>v[i];
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            for(int k=j+1;k<=n;k++)
        {
            int a=v[i];
            int b=v[j];
            int c=v[k];
            if(a+b>c&&b+c>a&&a+c>b&&a!=b&&b!=c&&a!=c)
                ans++;
        }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
int dy[] = {1, 0, 0, -1};
int dx[] = {0, 1, -1, 0};
int b[110][110];
int w, h;
int xs, ys, xg, yg;
int color;
bool flag = false;
bool used[110][110];

void dfs(int y, int x, int py, int px){
	rep(i, 4){
		int ny = y + dy[i], nx = x + dx[i];
		if(used[ny][nx]) continue;//???????????¨???????????????????????????
		if(!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
		if(b[ny][nx] != color) continue;
		if(ny == py && nx == px) continue;//??????????????¢
		if(ny == yg && nx == xg){
			used[ny][nx] = true;
			flag = true; return;//????????????
		}
		used[ny][nx] = true;
		dfs(ny, nx, y, x);
	}
	return;//????????¢?????¨???????????????
}

int main(void){
	while(1){
		rep(i, 110)rep(j, 110){
			b[i][j] = -1; used[i][j] = false;
		}
		cin >> w >> h;
		if(w == 0 && h == 0) return 0;
		cin >> xs >> ys >> xg >> yg;
		xs--; ys--; xg--; yg--;
		int n; cin >> n;
		rep(i, n){
			int c, d, x, y;
			cin >> c >> d >> x >> y;
			x--; y--;
			if(d == 0){//?¨?
				b[y][x] = b[y][x + 1] = b[y][x + 2] = b[y][x + 3] = c;
				b[y + 1][x] = b[y + 1][x + 1] = b[y + 1][x + 2] = b[y + 1][x + 3] = c;
			}else{//???
				b[y][x] = b[y][x + 1] = c;
				b[y + 1][x] = b[y + 1][x + 1] = c;
				b[y + 2][x] = b[y + 2][x + 1] = c;
				b[y + 3][x] = b[y + 3][x + 1] = c;
			}
		}
		color = b[ys][xs];
		if(color == -1) {//?????????????????????????????????
			printf("NG\n"); continue;
		}
		used[ys][xs] = true; flag = false;
		dfs(ys, xs, -1, -1);
		if(flag) printf("OK\n");
		else printf("NG\n");
	}
}

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

n=int(input())

INF=10**9+7

ans=0
ans=pow(10,n,INF)

ans-=pow(8,n,INF)

temp=pow(10,n,INF)-pow(9,n,INF)
ans=temp*2-ans

ans=ans%INF

print(ans)

Measured memory_bytes: 61736
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string.h>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

const string YES = "Yes";
const string NO = "No";


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

  int n;
  ll ans = 0;
  cin >> n;
  for(int i = 1; i <= n; i++){
    if(i % 3 == 0 || i % 5 == 0){
      continue;
    }else{
      ans += i;
    }
  }
  cout << ans << endl;






  // char a[3] = {0};
  // cin >> a;
  // rep(i, 3){
  //   if(a[i] == '7'){
  //     cout << YES << endl;
  //     return 0;
  //   }
  // }
  // cout << NO << endl;

  return 0;
}


Measured memory_bytes: 3644
from math import *
N=int(input())
L=[list(map(int,input().split())) for i in range(N)]
S=0
for i in range(N):
    for j in range(N):
        S+=sqrt((L[i][0]-L[j][0])**2+(L[i][1]-L[j][1])**2)
print(S/N)

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

int p[33];
int input;

int main(){
	fill(p, p+30, false);

	for(int i=0; i < 28; i++){
		cin >> input;
		p[input-1] = true;
	}
	for(int i=0; i < 30; i++){
		if(!p[i]) cout << i+1 << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+1;
ll a[N];
ll n;
inline  ll r(){
	char ch;
	ll ans=0,f = 1;
	ch = getchar();
	while(ch>'9' || ch<'0'){if(ch=='-') f*=-1; ch = getchar(); 	}
	while(ch>='0' && ch<='9'){ans = ans*10	+ ch - '0';  ch = getchar();}
	return ans*f;
}
int main (){
	n = r();
	ll ans = 0;
	int fushu = 0;
	for(int i=1;i<=n;i++){
	
		a[i] = r();
		if(a[i]<0) fushu ++;
		ans = ans + abs(a[i]);
		a[i] = abs(a[i]);	
	}
	sort(a+1,a+n+1);
	if(fushu%2==1) ans = ans - 2*a[1];
	cout<<ans<<endl;
	
}

Measured memory_bytes: 1024
from collections import Counter
from collections import defaultdict

def main(n,k,r,s,p,t):
    score = 0
    for i in range(len(t)):
        if i < k:
            continue
        if t[i] == t[i-k]:
            t[i] = "N"
    c = Counter(t)
    i = defaultdict(int,c)
    score += i["r"]*p + i["s"]*r + i["p"]*s
    return score
    
n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = list(input())
print(main(n,k,r,s,p,t))

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

int main(){
    int n, m;
    cin >> n >> m;

    vector<long long int> a(n), b(m), c(m);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<m; i++){
        cin >> b[i] >> c[i];
    }

    vector<pair<long long int, long long int>> bc(m);
    for(int i=0; i<m; i++){
        bc[i] = make_pair(-c[i], b[i]);
    }
    sort(bc.begin(),bc.end());

    priority_queue<long long int> pq;
    for(int i=0; i<n; i++){
        pq.push(a[i]);
    }

    int count = 0;
    bool flag = false;
    for(auto pair : bc){ 
        for(int i=0; i<pair.second; i++){
            pq.push(-pair.first);
            count += 1;
            if(count > n){
                flag = true;
                break;
            }
        }
        if(flag == true) break;
    }

    long long int sum = 0;
    for(int i=0; i<n; i++){
        sum += pq.top();
        //cout << pq.top() << " ";
        pq.pop();
    }

    while(!pq.empty()){
        //cout << pq.top() << " ";
        pq.pop();
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 6388
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define digit(N) cout << fixed << setprecision((N))

vector<int> eratosthenes(int N)
{
	vector<int> res;
	vector<bool> prime(N + 1, 1);
	prime[0] = prime[1] = false;
	for (int i = 2; i * i <= N; ++i)
	{
		if (prime[i] == true)
		{
			for (int j = 2 * i; j <= N; j += i)
			{
				prime[j] = false;
			}
		}
	}
	for (int i = 0; i <= N; ++i)
	{
		if (prime[i] == true)
			res.push_back(i);
	}
	return res;
}

int main()
{
	auto prime = eratosthenes(1000001);

	int N;
	while (cin >> N)
	{
		int index = 0;
		while (index < prime.size() && prime[index] <= N)
			index++;
		cout << index << endl;
	}
}


Measured memory_bytes: 3460
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws InterruptedException {
        FastScanner fs=new FastScanner();
        int T=fs.nextInt();
        int ac = 0, wa = 0, tle = 0, re = 0;

        for (int tt=0; tt<T; tt++) {
            String a = fs.nextString();
            switch (a) {
                case "AC":
                    ac++;
                    break;
                case "WA":
                    wa++;
                    break;
                case "TLE":
                    tle++;
                    break;
                case "RE":
                    re++;
                    break;
            }
        }
        System.out.println("AC x " + ac);
        System.out.println("WA x " + wa);
        System.out.println("TLE x " + tle);
        System.out.println("RE x " + re);
    }

    void sort(int[] a) {
        ArrayList<Integer> list=new ArrayList<>();
        for (int i:a) list.add(i);
        Collections.sort(list);
        for (int i=0; i<a.length; i++) a[i]=list.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");

        public String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }

        public String nextString() {
            return String.valueOf(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public long[] readLongArray(int n) {
            long[] a=new long[n];
            for (int i=0; i<n; i++) a[i]=nextLong();
            return a;
        }
    }
}

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

class dice{
public:
    vector<int> me = {1, 2, 3, 4, 5, 6};
    void roll(char n){
        vector<int> tmp(6);
        if(n == 'N'){
            tmp[0] = me[1]; tmp[1] = me[5]; tmp[2] = me[2];
            tmp[3] = me[3]; tmp[4] = me[0]; tmp[5] = me[4];
        }
        if(n == 'E'){
            tmp[0] = me[3]; tmp[1] = me[1]; tmp[2] = me[0];
            tmp[3] = me[5]; tmp[4] = me[4]; tmp[5] = me[2];
        }
        if(n == 'S'){
            tmp[0] = me[4]; tmp[1] = me[0]; tmp[2] = me[2];
            tmp[3] = me[3]; tmp[4] = me[5]; tmp[5] = me[1];
        }
        if(n == 'W'){
            tmp[0] = me[2]; tmp[1] = me[1]; tmp[2] = me[5];
            tmp[3] = me[0]; tmp[4] = me[4]; tmp[5] = me[3];
        }
        if(n == 'L'){
            tmp[0] = me[0]; tmp[1] = me[2]; tmp[2] = me[4];
            tmp[3] = me[1]; tmp[4] = me[3]; tmp[5] = me[5];
        }
        if(n == 'R'){
            tmp[0] = me[0]; tmp[1] = me[3]; tmp[2] = me[1];
            tmp[3] = me[4]; tmp[4] = me[2]; tmp[5] = me[5];
        }
        me = tmp;
    }
    int TOP(){
        return me[0];
    }
};

int main(void){
    int n;
    cin >> n;
    dice d[n];
    rep(i, n)
        rep(j, 6) cin >> d[i].me[j];
    rep(i, n){
        for(int j = i + 1; j < n; j++){
            if(d[i].me == d[j].me){
                cout << "No" << endl;
                return 0;
            }
            char r[] = "LLLLNLLLLNLLLLNLLLLNLLLLWLLLLWLLLLWLLLLWLLLL";
            rep(k, 43){
                d[j].roll(r[k]);
                if(d[i].me == d[j].me){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3168
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        char[] S = scanner.next().toCharArray();
        int N = S.length;
        long ans = 0;
        char[] upd = new char[N];
        int p = 0;
        for(int i = 0; i < N; i++) {
            if (i < N-1 && S[i] == 'B' && S[i+1] == 'C') {
                upd[p++] = 'D';
                i++;
            }
            else upd[p++] = S[i];
        }
        long cnt = 0;
        for(int i = 0; i < p; i++) {
            if (upd[i] == 'B' || upd[i] == 'C') cnt = 0;
            else if (upd[i] == 'A') cnt++;
            else ans += cnt;
        }
        out.println(ans);
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}


Measured memory_bytes: 25556
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
#define diup(v,a,k) distance((v).begin(),(k)+upper_bound((v).begin(),(v).end(),(a)))
#define dilo(v,a,k) distance((v).begin(),(k)+lower_bound((v).begin(),(v).end(),(a)))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
#define MOD 1000000007
//---------------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}


void Main(){
  int n;
  cin>>n;
  ll k;
  cin>>k;
  vl a(n);
  cin>>a;
  vl inv(n,0);
  vl d(n,0);
  rep(i,n){
    rep(j,n){
      if(a[i]>a[j]){
        d[i]++;
        if(j>i) inv[i]++;
      }
    }
  }
  ll ans=0;
  rep(i,n){
    ll b = k*inv[i] ;
    if(b>MOD) b%=MOD; 
    ll bk = k*(k-1)/2;
    if(bk>MOD) bk%=MOD; 
    bk *= d[i];
    if(bk>MOD) bk%=MOD; 
    ll bkk = b+bk;
    if(bkk>MOD) bkk%=MOD; 
    ans += bkk; 
    if(ans>MOD) ans%=MOD; 
  }
  cout<<ans<<endl;
} int main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 256
from collections import deque
import copy
N = int(input())

q = deque()

a = ord("a")

q.append([0, 0])

while len(q) > 0:
    task = q.popleft()
    if len(task) == N + 1:
        for i in task[1:]:
            print(chr(a + i), end="")
        print()
    else:
        for i in range(task[0] + 1):
            newtask = copy.copy(task)
            newtask.append(i)
            q.append(newtask)
        newtask = copy.copy(task)
        newtask.append(task[0] + 1)
        newtask[0] = task[0] + 1
        q.append(newtask)

Measured memory_bytes: 29484
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
// #define endl "\n"
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
ll mod = 1e9 + 7;
//const double pi = acos(-1.0);
/*
ll kmp(string x)
{
    ll n= x.length();
    //cout<<x<<endl;
    vector<ll> lcp(x.length(), 0);
    for(ll i=1;i<n;i++)
    {
        ll j=lcp[i-1];
        while(j>0 && x[j]!=x[i])
            j=lcp[j-1];
        if(x[i]==x[j])
            j++;
        lcp[i]=j;
    }
    return lcp[n-1];
}

int N = 1000002;
int ar[100002];
void sieve()
{
    for(int i=1;i<=N;i++)
        ar[i] = 1;
    ar[0] = 0;
    for(int i=2;i*i<=N;i++)
    {
        if(ar[i] && i*i<=N)
        {
            for(int j = i*i; j<=N;j+=i)
                ar[j] = 0;
        }
    }
}

ll modex(ll a,ll b){
    if(b<=0){
        return 1;
    }
    if(b%2==0)
    {
        ll x = modex(a, b/2);
        return ((x*x)%mod);
    }
    else
        return ((a%mod * modex(a, b-1))%mod);
}

ll c[1010][1010];

ll combina(ll i, ll j){
        for (int i=0;i<=1005;i++)
        for (int j=0;j<=i;j++)
        {
            if (j==i||j==0)
                c[i][j]=1;
            else
            c[i][j]=c[i-1][j-1]+c[i-1][j];
            c[i][j]%=mod;
        }
        return c[i][j];
}
void find_fac(int x){
    vector<ll> di;
    for(ll i = 2; i*i <= x; i++)
    {
        if(x%i==0){
            di.push_back(i);
            while(x%i==0)
                x/=i;
        }
    }
    if(x > 1)
        di.push_back(x);
}
*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout.precision(12);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int r = 0, w = 0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='W')
            w++;
        else
            r++;
    }
    int an = 0;
    for(int i=0;i<r;i++)
        if(s[i]=='W')
            an++;
    cout<<an<<endl;
    return 0;
}


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

int main(){
    int k;
    cin >> k;
    vector<long long> A;
    int mas = 0, keta = 0;
    for(int i=0;i<k;i++){
        if(i > 8){
            A.push_back(A[mas]);
            if(A[i]%10 -1 <= keta && keta <= A[i]%10 +1 && keta <= 9){
            }
            else{
                mas++;
                A[i] = A[mas];
                keta = (A[i]%10? A[i]%10-1:0);
            }
            A[i] = A[i]*10 + keta;
            keta++;
        }
        else{
            A.push_back(i+1);
        }
    }

    cout << A[A.size()-1] << endl;
    return 0;
}

Measured memory_bytes: 1400
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String at = sc.next();
        if(at.equals("ABC")){
            System.out.println("ARC");
        }else if(at.equals("ARC")){
            System.out.println("ABC");
        }
    }
}


Measured memory_bytes: 35596
X,Y=map(int,input().split())
a=(2*Y-X)/3
b=(2*X-Y)/3
check=False
if a%1!=0 or b%1!=0:
  check=True
n=a//1
r=b//1
def cmb(n, r, mod):
    if (r<0 or r>n):
        return 0
    r = min(r, n-r)
    n=int(n)
    r=int(r)
    return (g1[n]*g2[r]*g2[n-r])%mod

mod=10**9+7
N=10**6
g1=[1,1]
g2=[1,1]
inverse=[0, 1]

for i in range(2,N+1):
    g1.append((g1[-1]*i) % mod)
    inverse.append((-1*inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1]*inverse[-1]) % mod)
ans=cmb(n+r,r,mod)
print(ans if not check else 0)



Measured memory_bytes: 123788
//
// Created by 伊東麻沙美 on 2019/10/22.
//

#include<iostream>
#include<algorithm>
using namespace std;


int main(){

    int i,j;
    char x;
    cin>>i>>x>>j;
    //scanf("%d%s%d",&i,&x,&j);
    if(x=='+'){
        printf("%d",i+j);
    }
    if(x=='-'){
        printf("%d",i-j);
    }

    return 0;
}

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


int main()
{
    int n;
    cin >> n;
    string s; cin >> s;

    char bef = 0;
    int ans = 0;
    rep(i, n){
        if (bef != s[i]) ans++;
        bef = s[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;
int n, id = 0;
int *a = new int[2000000];

void maxheapify(int i){
  int largest = i;
  if(2 * i <= id){
    if(a[largest] < a[2 * i]) largest = 2 * i;
  }
  if(2 * i + 1 <= id){
    if(a[largest] < a[2 * i + 1]) largest = 2 * i + 1;
  }
  if(largest == i) return;
  int t = a[i];
  a[i] = a[largest];
  a[largest] = t;
  maxheapify(largest);
}

void build(){
  for(int i = id / 2; i >= 1; i--){
    maxheapify(i);
  }
}

void build2(int n){
  int x = n, y = n / 2, z = a[n];
  while(y >= 1 && z > a[y]){
    a[x] = a[y];
    x = y;
    y /= 2;
  }
  a[x] = z;
  return;
}

void solve(){
  string *c = new string[2000000];
  int *d = new int[2000000];
  for(int i = 0; i < 2000000; i++){
    cin >> c[i];
    if(c[i] == "insert") cin >> d[i];
    else if(c[i] == "end") break;
  }
  for(int i = 0; i < 2000000; i++){
    if(c[i] == "insert"){
      a[++id] = d[i];
      build2(id);
    }
    else if(c[i] == "extract"){
      cout << a[1] << endl;
      a[1] = a[id--];
      maxheapify(1);
    }
    else break;
  }
  return;
}

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



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


int main(){
  cout<<fixed<<setprecision(10);
  double a,b,x,ans;
  cin>>a>>b>>x;
  if(a*a*b/2<=x){
    //cout<<a*a/2/(a*a*a*b-x)<<endl;
    ans=atan(a*a*a/2/(a*a*b-x));
    ans=ans*180.0/PI;
    ans=90.0-ans;
  }else{
    ans=atan(2*x/(a*b*b));
    ans=ans*180.0/PI;
    ans=90.0-ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	ll ans = a.back();
	a.pop_back();
	int c = 0;
	rep(i, n - 2)
	{
		c++;
		ans += a.back();
		if(c == 2){
			a.pop_back();
			c = 0;
		}
	}
	cout << ans << endl;
}

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

#define N 200009
int k,n,x[N],d[N];

int main()
{
	cin >> k >> n;
	for(int i = 0;i<n;i++)
	{
		cin >> x[i];
	}
	sort(x,x+n);
	for(int i = 1;i<n;i++)
	{
		d[i] = x[i]-x[i-1];
	}
	d[0] = x[0]+k-x[n-1];
	//for(int i = 0;i<n;i++)cout << d[i] << " ";//
	cout << k-*max_element(d,d+n);
	return 0;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;


int main() {
    ll x;
    cin >> x;

    REPN(i, 1, sqrt(x)+1) {
        if(x % i == 0) {
            ll tmp = i;
            REPN(a, -200, 201) {
                ll b = a - tmp;
                ll tmp2 = a * a * a * a * a;
                ll tmp3 = b * b * b * b * b;
                if(tmp2 - tmp3 == x) {
                    cout << a << " " << b << endl;
                    return 0;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	int N;
	cin >> N;
	string A, B, C;
	cin >> A >> B >> C;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		set<char> s;
		s.insert(A[i]);
		s.insert(B[i]);
		s.insert(C[i]);
		if (s.size() == 2) ans++;
		else if (s.size() == 3) ans += 2;
	}
	cout << ans << endl;
}

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

const int INF=100000000;

int dp[2][2][5001];
int cost[10000];

bool update(int &a,int v){
	if(a<v) return false;
	a=v;
	return true;
}

int main(){
	int N;
	cin >> N;
	for(int i=0; i<N-1; ++i){
		cin >> cost[i];
	}
	int ans=INF;
	int ptr=0;
	fill_n(dp[ptr][0],N/2+1,INF);
	fill_n(dp[ptr][1],N/2+1,INF);
	dp[ptr][0][N/2-1]=dp[ptr][1][N/2]=0;
	ptr^=1;
	for(int i=1; i<N; ++i){
		int prev=ptr^1;
		fill_n(dp[ptr][0],N/2+1,INF);
		fill_n(dp[ptr][1],N/2+1,INF);
		for(int j=0; j<=N/2; ++j){
			if(j+1<=N/2) update(dp[ptr][0][j],dp[prev][0][j+1]);
			update(dp[ptr][1][j],dp[prev][0][j]+cost[i-1]);
			if(j+1<=N/2) update(dp[ptr][0][j],dp[prev][1][j+1]+cost[i-1]);
			update(dp[ptr][1][j],dp[prev][1][j]);
			if(j==0){
				if(i<N-1) dp[ptr][0][j]+=cost[i];
			}
		}
		update(ans,min(dp[ptr][0][0],dp[ptr][1][0]));
		ptr^=1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1276
while True:
    n, k = map(int, input().split())
    if n == 0 and k == 0: break
    a = [int(input()) for i in range(n)]
    s = sum(a[0:k])
    ss = [s]
    for i in range(k, n):
        s = s + a[i] - a[i-k]
        ss.append(s)
    print(max(ss))


Measured memory_bytes: 11700
# AtCoder My Practice
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.chomp end
def gi() gets.to_i end
def gf() gets.to_f end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
def vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end
MV4 = [[0, 1], [1, 0], [0, -1], [-1, 0]]
MV8 = MV4 + [[1, 1], [1, -1], [-1, -1], [-1, 1]]
DV7 = 7 + 10 ** 9
############################################################

# 解説読後
# http://arc058.contest.atcoder.jp/data/arc/058/editorial.pdf
# いくつか正解のコード見ていて解説の逆元の説明に間違い箇所がある
#  x^1000000005 じゃなくて (x!)^1000000005


# 二分累乗法
# http://chausson.eng.kagawa-u.ac.jp/Comp/Prog/DosC/Sec4/Note432.html
def binpow(v, e) 
    a = 1
    x = v
    while e > 0
        if e.even?
            x = (x * x) % DV7 # 通常の二分累乗法では mod はない(この問題専用の計算)
            e /= 2
        else
            a = (a * x) % DV7
            e -= 1
        end
    end
    a
end

H, W, A, B = gis

t = [0] * (H + W + 1) # 階乗
b = [0] * (H + W + 1) # (mod 1000000009 前提の) 逆元

t[0] = 1
b[0] = 1
(1 .. (H + W)).each do |i|
    t[i] = (i * t[i - 1]) % DV7
    b[i] = binpow(t[i], DV7 - 2)
end

# コンビネーションは  C(N; K) = N! / (K! * (N - K)!)
# t[N] := N! (mod 1000000009)
# binpowで逆元を求めたので
# b[K] := (1 / K!) (mod 1000000009)
# b[N -K] := (1 / (N - K)!) (mod 1000000009)
# ゆえに
# C(N; K) = t[N] * b[K] * b[N -K]

c = 0

(B ... W).each do |i|
    w1 = i
    h1 = H - A - 1
    c1 = (t[w1 + h1] * b[w1] * b[h1]) % DV7
    w2 = W - i - 1
    h2 = A - 1
    c2 = (t[w2 + h2] * b[w2] * b[h2]) % DV7
    c += c1 * c2
end

puts c % DV7

Measured memory_bytes: 4988
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7;
ll sumdp[200005], dp[200005];
int c[200005];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &c[i]);
	}
	n = unique(c, c + n) - c;
	sumdp[c[0]] = 1;
	for (int i = 0; i < n; ++i) {
		dp[i] = sumdp[c[i]];
		if (i + 1 < n) {
			sumdp[c[i + 1]] += dp[i];
			sumdp[c[i + 1]] %= MOD;
		}
	}
	printf("%lld\n", dp[n - 1]);
}


Measured memory_bytes: 4096
#include <array>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>

namespace geometry
{
template <uint32_t Dimension, typename T>
class Point
{
    static_assert(1 <= Dimension);
    static_assert(std::is_arithmetic<T>::value);

    std::array<T, Dimension> m_values;

public:
    Point() = default;

    Point(std::initializer_list<T> the_value)
    {
        assert(the_value.size() == Dimension);

        // 初期化子内でinitializer_listを渡す方法(文法)がないため、本体で代入
        std::copy(the_value.begin(), the_value.end(), m_values.begin());
    }

    Point(const Point& the_other) = default;

    T operator[](const size_t the_index) const
    {
        assert(the_index < Dimension);
        return m_values[the_index];
    }
};

template <typename U>
class Distance
{
    U m_value;

public:
    Distance() = delete;

    template <uint32_t Dimension, typename T>
    Distance(
        const geometry::Point<Dimension, T>& the_one,
        const geometry::Point<Dimension, T>& the_other)
    {
        double sum = 0;

        for (uint32_t d = 0; d < Dimension; ++d)
        {
            const T diff = the_one[d] - the_other[d];
            sum += diff * diff;
        }

        m_value = static_cast<U>(std::sqrt(sum));
    }

    U value() const { return m_value; }
};
}  // namespace geometry

int main()
{
    uint32_t A, B, H, M;

    std::cin >> A >> B >> H >> M;

    // 時針の角度
    const double hour_hand_angle = (H / 12.0 + M / 60.0 / 12) * 360 * M_PI / 180;

    // 時針の位置
    geometry::Point<2, double> hour_hand_location{
        A * cos(M_PI / 2 - hour_hand_angle),
        A * sin(M_PI / 2 - hour_hand_angle)};

    // 分針の角度
    const double minute_hand_angle = M / 60.0 * 360 * M_PI / 180;

    // 分針の位置
    geometry::Point<2, double> minute_hand_location{
        B * cos(M_PI / 2 - minute_hand_angle),
        B * sin(M_PI / 2 - minute_hand_angle)};

    // 距離
    geometry::Distance<double> d(hour_hand_location, minute_hand_location);

    std::cout << std::setprecision(15) << d.value() << std::endl;

    return 0;
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define MAX_V 200

int V;//頂点数
vector<int> G[MAX_V];//グラフの隣接リスト表現
int match[MAX_V];//マッチングのペア
bool used[MAX_V];//DFSですでに調べたかのフラグ

//uとvを結ぶ辺をグラフに追加する
void add_edge(int u, int v){
    G[u].push_back(v);
    G[v].push_back(u);
}

//増加パスをDFSで探す
bool dfs(int v){
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        int u = G[v][i], w = match[u];
        if(w < 0 || !used[w] && dfs(w)){
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

//二部グラフの最大マッチングを求める
int bipartite_matching(){
    int res = 0;
    memset(match, -1, sizeof(match));
    for(int v = 0; v < V; v++){
        if(match[v] < 0){
            memset(used, 0, sizeof(used));
            if(dfs(v)){
                res++;
            }
        }
    }
    return res;
}

signed main(){
    int n;
    cin >> n;
    int a[n],b[n];
    REP(i,n){
        cin >> a[i] >> b[i];
    }
    int c[n],d[n];
    REP(i,n){
        cin >> c[i] >> d[i];
    }
    REP(i,n){
        REP(j,n){
            if(a[i] < c[j] && b[i] < d[j]){
                add_edge(i, n + j);
            }
        }
    }
    V = 2 * n;
    cout << bipartite_matching() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int INF (1<<30);

int main() {
  ll x;
  cin >> x;

  ll now = 100;

  ll ans = 1;

  while (true) {
    now = now * 1.01;
    if (now >= x) {
      cout << ans << endl;
      break;
    }
    ans++;
  }

  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    ll x;cin >> x;

    int t=x/500;
    int f=(x-t*500)/5;

    cout << 1000*t+5*f << endl;

    return 0;
}





Measured memory_bytes: 3640
let rec add_debt debt n =
    if n <= 0 then debt
    else add_debt (floor ((ceil (debt*.1.05/.1000.0)) *.1000.0)) (n-1)

let () =
    let debt = 100000.0 in
    let n    = read_int () in
    Printf.printf "%d\n" (int_of_float (add_debt debt n))

Measured memory_bytes: 2268
#include <iostream>

using namespace std;

const int MAX_HW = 100;

int main(int argc, char const *argv[]) {
  int h, w;
  cin >> h >> w;

  char a[h][w], ans[MAX_HW+2][MAX_HW+2];
  for (size_t i = 0; i < h+2; i++) {
    ans[i][0] = '#';
    ans[i][w+1] = '#';
  }
  for (size_t i = 0; i < w+2; i++) {
    ans[0][i] = '#';
    ans[h+1][i] = '#';
  }
  for (size_t i = 0; i < h; i++) {
    for (size_t j = 0; j < w; j++) {
      cin >> a[i][j];
      ans[i+1][j+1] = a[i][j];
    }
  }
  for (size_t i = 0; i < h+2; i++) {
    for (size_t j = 0; j < w+2; j++) cout << ans[i][j];
    cout << endl;
  }
  return 0;
}


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

namespace AtTest._500problems
{
    class CF2016B_C
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int[] wh = ReadInts();
            long w = wh[0];
            long h = wh[1];
            long[] ps = new long[w];
            long[] qs = new long[h];
            for (int i = 0; i < w; i++) ps[i] = ReadLong();
            for (int i = 0; i < h; i++) qs[i] = ReadLong();
            Array.Sort(ps);
            Array.Sort(qs);
            long[] pSums = new long[w];
            for (int i = 0; i < w; i++)
            {
                pSums[i] = ps[i];
                if (i > 0) pSums[i] += pSums[i - 1];
            }
            long res = pSums[w - 1];
            long now = w - 1;
            for(long i = h - 1; i >= 0; i--)
            {
                //WriteLine(res);
                while (now >= 0 && ps[now] >= qs[i]) now--;
                if (now >= 0) res += pSums[now];
                res += qs[i] * (w - now);
                //WriteLine(now);
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 17628
#include<stdio.h>
int main(void)
{
	int N,tmpN,tmp1,tmp2,tmp3;
	scanf("%d", &N);
	while (true) {
		tmpN = N;
		tmp1 = tmpN % 10; tmpN /= 10;
		tmp2 = tmpN % 10; tmpN /= 10;
		tmp3 = tmpN % 10;
		if (tmp1 == tmp2 && tmp1 == tmp3) {
			printf("%d", N);
			return 0;
		}
		N++;
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int Max_N=50,Max_D=1e2;
int N,A[Max_N+10]={};
int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++) scanf("%d",&A[i]);
	int Ans=0;
	for(int i=1;i<=N;i++)
	 for(int j=i+1;j<=N;j++)
	  Ans+=A[i]*A[j];
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 256
program C
    implicit none
    integer(8) :: N,K,Q,i,x,sumP=0,tmp,idx
    
    integer(8),allocatable :: Player(:)
    
    read(*,*) N,K,Q
    allocate(Player(N))

    player = 0

    do i=1,Q
        read (*,*) x
        Player(x) = Player(x) + 1
    enddo


    do i=1,N
        tmp = K - Q + Player(i)
        if(tmp > 0)then
            write(*,*) 'Yes'
        else
            write(*,*) 'No'
        endif
    enddo
    deallocate(Player)

end program C



Measured memory_bytes: 1536
import sys
input = sys.stdin.buffer.readline

from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

cnt = defaultdict(int)
for a in A:
    cnt[a] += 1

sum_cnt = 0
for a in cnt.values():
    sum_cnt += a * (a - 1) // 2
#print(cnt)
#print(sum_cnt)

for a in A:
    cnta = cnt[a]
    print(sum_cnt - cnta * (cnta - 1) // 2 + (cnta - 1) * (cnta - 2) // 2)

Measured memory_bytes: 71920
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int>A(n), dp(n, INT_MAX);
	for(auto&a:A)cin>>a;
	dp[0]=0;
	for(int i=0; i<n; i++){
		for(int j=1; j<3; j++)
		if(i+j<n){
			dp[i+j]=min(dp[i+j], dp[i]+abs(A[i]-A[i+j]));
		}
	}
	cout<<dp[n-1]<<"\n";
}


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

int main () {

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

  string s; cin >> s;
  if (s.back() == 's') {
    cout << s << "es" << '\n';
  }else {
    cout << s << 's' << '\n';
  }

	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K;
  int A;
  int B;
  int i=1;
  cin>>K;
   cin>>A>>B;
  for(int j=0;j=1001;j++){
    if(A<=K*i&&K*i<=B){
      cout<<"OK"<<endl;
      break;
    }
     if(K*i>=B){
       cout<<"NG"<<endl;
       break;
     }
    i++;
  }
 
      
}

Measured memory_bytes: 3600
<?php
fscanf(STDIN, "%d", $n);
$a = explode(' ', trim(fgets(STDIN)));
rsort($a);
$x = [0, 0];
for ($i = 0; $i < $n; $i++) {
	$x[$i % 2] += $a[$i];
}
echo $x[0] - $x[1];

Measured memory_bytes: 4728
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX 10000
 
int main(){
    int n;
    double a,b,c,d[MAX+1];
     
    cin >> n >> a >> b >> c;
    for(int i = 0 ; i < n ; i++){
        cin >> d[i];
    }
    sort(d,d+n);
     
    int k = 1;
    double max;
    max = (d[n-1]+c)/(a+k*b);
    for(int i = n - 1 ;i > 1; i--){
        double sum = d[i];
        for(int j = i-1 ; j > 0 ; j--){
            if(max < (c+sum+d[j])/(a+(k+1)*b)){
                k++;
                sum += d[j];
                max = (c+sum)/(a+k*b);
            }
            else goto end;
        }
    }
end:
    int ans = (int)max;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3276
N = gets.to_i
A = gets.split.map(&:to_i)

ave = A.inject(:+) / N.to_f

ans = 0
minf = Float::INFINITY

A.each_with_index do |a, i|
  abs = (ave - a).abs

  if minf > abs
    minf = abs
    ans = i
  end
end

puts ans


Measured memory_bytes: 1788
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input! {
        H: usize,
        W: usize,
        h: usize,
        w: usize,
    }
    println!("{}", (H-h)*(W-w));
}


Measured memory_bytes: 4352
#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 < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int c[3][3];
  rep(i,3)rep(j,3) cin >> c[i][j];

  int a[3], b[3];
  int x = 0;
  a[0] = x;
  rep(i,3) b[i] = c[0][i] - a[0];
  rep(i,3) a[i] = c[i][0] - b[0];

  bool ok = true;
  rep(i,3) {
    rep(j,3) {
      if (c[i][j] != a[i] + b[j]) ok = false;
    }
  }
  
  puts(ok ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256