akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#define NIL NULL

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


typedef struct node * Node;


Node root = NIL;


Node treeMinimum(Node);
Node treeSearch(Node, int);
Node treeSuccessor(Node);
void treeDelete(Node);
void insert(int);
void inorder(Node);
void preorder(Node);


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
    
  }

  return 0;
}


Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;

  return x;
}


Node treeSearch(Node x, int k){
  if(x == NIL || k == x->key) return x;
  if(k < x->key) return treeSearch(x->left, k);
  else return treeSearch(x->right, k);
}


Node treeSuccessor(Node x){
  Node y;
  
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;

  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }

  return y;
}


void treeDelete(Node z){
  Node x, y;
  
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != x) z->key = y->key;
}


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

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


  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 u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
}


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



Measured memory_bytes: 20440
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define CLR(a,x) memset(a,x,sizeof(a))
#define MP make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pa;
const int maxn=1e5+10;

inline ll rd(){
    ll x=0;char c=getchar();int neg=1;
    while(c<'0'||c>'9'){if(c=='-') neg=-1;c=getchar();}
    while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*neg;
}

int N,a[maxn],f[maxn];

int main(){
    //freopen("","r",stdin);
	N=rd(),rd();
	for(int i=1;i<=N;i++) a[i]=rd();
	int mn=1e9+1,mi=0,ma=0;
	for(int i=1;i<=N;i++){
		f[i]=mi,ma=max(ma,a[i]-mn);
		if(a[i]<mn) mn=a[i],mi=i;
	}
	int lst=0,ans=0;
	for(int i=1;i<=N;i++){
		// printf("~%d %d\n",i,f[i]);
		if(a[i]-a[f[i]]==ma){
			if(f[i]>lst) ans++;
			lst=f[i];
		}
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;


int main(void)
{
    int  i;
    int  num;
    char input, output;
    map<char, char> cmap;

    for (;;) {
        scanf("%d", &num);
        if (num == 0) {
            break;
        }

        for (i = 0; i < num; i++) {
            getchar();
            scanf("%c", &input);
            getchar();
            scanf("%c", &output);
            cmap.insert(make_pair(input, output));
        }
        scanf("%d", &num);
        for (i = 0; i < num; i++) {
            getchar();
            scanf("%c", &input);
            if (cmap.find(input) == cmap.end()) {
                printf("%c", input);
            }
            else {
                printf("%c", cmap.at(input));
            }
        }
        printf("\n");
        cmap.clear();
    }

    return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>

int main(void)
{
	int i, j,k, l,h=0, w=0;

	while (1)
	{
		scanf("%d%d", &h, &w);
		if ((h == 0) && (w == 0)) break;
		for (i = 0;i < h;i++)
		{
			if ((i == 0) || (i == h - 1))
			{
				for (j = 0;j < w;j++) printf("#");
			}
			else {
				printf("#");
				for (k = 0;k < w - 2;k++)
				{
					printf(".");
				}
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
		return 0;
}


Measured memory_bytes: 572
N,M=map(int,input().split())
Red=[False]*N
Cnt=[1]*N
Red[0]=True
for i in range(M):
    x,y=map(lambda x:int(x)-1,input().split())
    Red[y]|=Red[x]
    Cnt[y]+=1
    Cnt[x]-=1
    if Cnt[x]==0:
        Red[x]=False
ans=0
for i in range(N):
    if Red[i] and Cnt[i]>0:
        ans+=1
print(ans)

Measured memory_bytes: 4596
while True:
    answer = 0
    N,X = map(int, input().split())
    if N == 0 and X == 0:
        break
    num_list = list(range(1,N+1))
    for A in num_list:
        if A > X:
            break
        elif A != N and A != N - 1:
            for B in num_list[A:]:
                if A + B > X:
                    break
                elif B != N:
                    for C in num_list[B:]:
                        if A + B + C == X:
                            answer += 1
                        elif A + B + C > X:
                            break
                else:
                    break
        else:
            break
    print(answer)


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

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

  int totalw = 0;
  vector<int> w(n);

  for(int i = 0; i < n; i++){
    cin >> w[i];
    totalw += w[i];
  }

  int min = 100000;
  int totalw1 = w[0];
  totalw -= w[0];

  for(int i = 1; i < n; i++){
    int dummy = abs(totalw - totalw1);

    if(dummy < min){
      min = dummy;
      totalw1 += w[i];
      totalw -= w[i];
    }

    else break;
  }

  cout << min << endl;

  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}
const int INF = 1000000000;
int main() {
    int n;
    cin >> n;
    vector<int>h(n);
    rep(i,n) cin >> h[i];
    int dp[1000005];
    rep(i,n) dp[i] = INF;
    dp[0] = 0;
    rep(i,n) {
        if(i==0) continue;
        chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        if(i>1)chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int intx, inty;
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String[] str = sc.nextLine().split(" ");
            intx = Integer.parseInt(str[0]);
            inty = Integer.parseInt(str[1]);

            if( intx == 0 && inty == 0) break;
            else if(intx < inty) System.out.println(intx + " " + inty);
            else System.out.println(inty + " " + intx);
        }
        sc.close();
    }
}

Measured memory_bytes: 37580
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int N;
    scanf("%d", &N);
    vector<int> H(N);
    for (int i = 0; i < N; ++i) scanf("%d", &H[i]);
    --H[0];
    if (N == 1) 
    {
        printf("Yes\n");
        return 0;
    }
    for (int i = 0; i < N - 1; ++i)
    {
        if (H[i] - 1 > H[i + 1])
        {
            printf("No\n");
            return 0;
        }
        else if (H[i] - 1 == H[i + 1])
        {
            if (i > 0 && H[i - 1] <= H[i] - 1) --H[i];
            else if (i > 0 && H[i - 1] > H[i] - 1) 
            {
                printf("No\n");
                return 0;
            }
        }
        else // H[i] - 1 < H[i + 1]
        {
            if (i > 0 && H[i - 1] <= H[i] - 1) --H[i];
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 640
N = int(input())
A = [ int(it) for it in input().split() ]
B = [ int(it) for it in input().split() ]
C = [ int(it) for it in input().split() ]
A.sort()
B.sort()
C.sort()

#print (A)
#print (B)
#print (C)

jj = 0
jF = False
for _j in range(N):
  if (A[0] < B[_j]):
    jj = _j
    break
  if (_j == N-1):
    jF = True
if ( not jF ):
  i,k=0,0
  s = 0
  Flag = True
  for j in range(N):

    if (i<N):
      for _ in range(N*N):
        if ( A[i] >= B[j] ):
          break
        i += 1
        if (i==N):
          break
    for _ in range(N*N):
      if ( B[j] < C[k] ):
        break
      k += 1
      if ( k == N ):
        Flag = False
        break
    if ( not Flag ):
      break
    #print ( i,j,k )
    s += i*( N-k )
  print (s)
else:
  print (0)

Measured memory_bytes: 104548
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define pii pair<int,int>
using namespace std;

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

	if(s[0] == '7' || s[1] == '7' || s[2] == '7') cout<<"Yes\n";
	else cout<<"No\n";
}

Measured memory_bytes: 3624
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
    x=I()
    t=1800
    for i in range(10):
        if x>=t:
            print(i+1)
            exit()
        t-=200

main()


Measured memory_bytes: 61880
while True:
    a, b, r = map(int, input().split())
    result = a + b
    if a == b == r == -1:
        break
    if a == -1 or b == -1:
        print("F")
        continue
   
    if result >= 80:
        print("A")
    elif 65 <= result < 80:
        print("B")
    elif 50 <= result < 65:
        print("C")
    elif 30 <= result < 50:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")


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

int water(vector<int> & h){
  if(h.size() == 1) return h[0];
  
  int h0 = h[0]; bool same = true;
  int mini = h[0];
  for(int i = 1; i < h.size(); i++){
    if(h[i] != h0) same = false;
    if(h[i] < mini) {
      mini =  h[i];
    }
  }
  if(same) return h0;
  
  for(int i = 0; i < h.size(); i++){
    h[i] -= mini;
  }
  
  int pre = -1;
  int ans = mini;
  vector<int> next;
  for(int i = 0; i < h.size(); i++){
    if(h[i] != 0) next.push_back(h[i]);
    if(h[i] == 0) {
      if(i != pre + 1) {
        ans += water(next);
        next.clear();
      }
      pre = i;
    }
  }
  if(!next.empty()) ans += water(next);
  
  return ans;
}

int main() {
  int N; cin >> N;
  vector<int> h(N);
  for(int i = 0; i < N; i++) cin >> h[i];
  
  cout << water(h) << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
int u[1100000];
int i[1100000];
int y[1100000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=1,g=0;
  cin >>a;
  for(int n=0;n<a-1;n++){
    cin >>i[n];
  }
  for(int n=0;n<a-2;n++){
    d+=min(i[n],i[n+1]);
  }
  cout <<d+i[a-2]+i[0]<<'\n';
  return (0);
}


Measured memory_bytes: 2304
while True:
	n = int(raw_input())
	if n == 0:
		break
	employee_no = []
	info = {}
	for r in range(n):
		no,unit_price,quantity = map(int, raw_input().split(' '))
		if no in info:
			info[no] += unit_price*quantity
		else:
			info[no] = unit_price*quantity
		if not no in employee_no:
			employee_no.append(no)
	output_flg = False
	for no in employee_no:
		if info[no] >= 10**6:
			output_flg = True
			print no
	if not output_flg:
		print "NA"

Measured memory_bytes: 6452
#include<bits/stdc++.h>
using namespace std;
int main(){
   int N;
  string s;
  cin>>N>>s;
  vector<char>C(N);
  for(int i=0;i<N;i++)
  cin>>s.at(i);
  int sum=0;
  for(int i=1;i<N;i++)
    if(s.at(i)=='E')
      sum++;
  int ans=sum;
  for(int i=1;i<N;i++){
  if(s.at(i)=='E')
    sum--;
    if(s.at(i-1)=='W')
      sum++;
    if(sum<=ans)
      ans=sum;
  } cout<<ans<<endl;
   
  return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
#define pi 3.14159265358979323846
using namespace std;
int main()
{
  int a,b;
  int h,m;
  cin>>a>>b>>h>>m;
  double hedge=h*30;
  double medge=m*6;
  hedge+=medge/12;
  double theta=abs(hedge-medge);
  theta=(theta*(pi/180));
  theta=cos(theta);
  double ans=sqrt(a*a+b*b-2*a*b*theta);
  cout<<fixed<<setprecision(10)<<ans<<endl;
 
  
  
}
 


Measured memory_bytes: 4168
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AFairness solver = new AFairness();
        solver.solve(1, in, out);
        out.close();
    }

    static class AFairness {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {

            int a = in.scanInt();
            int b = in.scanInt();
            int c = in.scanInt();
            long k = in.scanLong();
            if (k % 2 == 0) out.println(a - b);
            else out.println(b - a);

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

        public long scanLong() {
            long integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

    }
}



Measured memory_bytes: 22740
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

typedef long long ll;
//typedef pair<ll, ll> P;

//static const ll MOD = 1000000007;
//static const ll INF = 100000000;

int main() {
    // input
    ll N;
    vector<ll> A;
    cin >> N;
    for (ll i = 0; i < N; i++) {
        ll a;
        cin >> a;
        A.emplace_back(a);
    }

    // process
    for (ll i = 0; i < N; i++) {
        if ((A[i] % 2) == 0) {
            if ((A[i] % 3) != 0) {
                if ((A[i] % 5) != 0) {
                    cout << "DENIED";
                    return 0;
                }
            }
        }
    }

    cout << "APPROVED";
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  int h=a[n-1];
  int sup=1e9;
  int ans;
  for(int i=0;i<n-1;i++){
    if(sup>abs(h-a[i]*2)){
      if(ans!=a[i]){
      sup=abs(h-a[i]*2);
      ans=a[i];
      }
    }
  }
  cout << h << ' ' << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  int N;
  while(cin >>N && N){
    bool f = true;
    vector<int> M(N), A(N), B(N);
    REP(i, N) cin >>M[i] >>A[i] >>B[i];
    REP(i, N){
      int sum = 0;
      REP(j, N) if(A[j] <= A[i] && A[i] < B[j]) sum += M[j];
      if(sum > 150) f = false;
    }
    cout <<(f ? "OK" : "NG") <<endl;
  }
  return 0;
}

Measured memory_bytes: 1188
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class Program
{
    static int n, k, q;
    static int[] a;
    static void Main()
    {
        /* 入力の受け取り */
        string[] input = Console.ReadLine().Split();
        n = int.Parse(input[0]);
        k = int.Parse(input[1]);
        q = int.Parse(input[2]);
        a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        /* Y=aiと固定して最小値を求めていく */
        int ans = int.MaxValue;
        for (int i = 0;i < n; i++) // Y=aiと固定
        {
            int Y = a[i];
            List<List<int>> sec = new List<List<int>>();
                                     // Y未満で分割した区間を管理
            sec.Add(new List<int>());
            for (int j = 0;j < n; j++)
            {
                if (a[j] < Y) // Y未満の処理
                {
                    sec.Add(new List<int>()); 
                    continue;
                }
                sec[sec.Count - 1].Add(a[j]);
            }
            List<int> removes = new List<int>(); // 取り除く候補を管理
            foreach (var b in sec) // 分割した各区間について
            {
                b.Sort();
                int m = Max(0,Min(q,b.Count - k + 1));
                for (int j = 0;j < m; j++)
                    removes.Add(b[j]);
            }
            removes.Sort();
            if (removes.Count < q) // q個も取り除けなかった場合
                continue;
            if (removes[0] != Y) // aiが取り除けなかった場合
                continue;
            ans = Min(ans,removes[q - 1] - Y); // 解の検討
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 45772
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;



int main(){
  int dp[3010][3010]={};

  string s,t;
  cin >> s >>t;

  rep(a,s.size()){
    rep(b,t.size()){
      if(s[a]==t[b]){dp[a+1][b+1]=dp[a][b]+1;}
      chmax(dp[a+1][b+1],dp[a+1][b]);
      chmax(dp[a+1][b+1],dp[a][b+1]);
    }
  }

  string ans="";
  int a=(int)s.size(),b=(int)t.size();

  while(a>0 && b>0){
    if(dp[a][b]==dp[a-1][b]){a--;}
    else if(dp[a][b]==dp[a][b-1]){b--;}
    else{ans = s[a-1]+ans;a--,b--;}
  }

  cout << ans << endl;
}

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

const int mod=1000000007;
int n,f[100010],la[100010],sla[100010][3],sum[100010],ans,fir;
char s[100010];

int main()
{
	scanf("%s",s+1),n=strlen(s+1),sum[0]=0;
	for (int i=1; i<=n; i++) sum[i]=(sum[i-1]+(s[i]-'a'+1))%3;
	sla[0][0]=0,sla[0][1]=sla[0][2]=-1;
	for (int i=1; i<=n; i++)
		memcpy(sla[i],sla[i-1],sizeof(sla[i])),sla[i][sum[i]]=i;
	la[0]=la[1]=-1;
	for (int i=2; i<=n; i++)
		if (s[i]==s[i-1]) la[i]=i-1;
		else la[i]=la[i-1];
	if (la[n]==-1) return puts("1"),0;
	f[n+1]=1;
	for (int nw,i=n; i; i--)
	{
		f[i]=(f[i]+f[i+1]>=mod?f[i]+f[i+1]-mod:f[i]+f[i+1]);
		if ((nw=la[i])!=-1)
		{
			nw=sla[nw][(sum[i]-((s[i]-'a')^1)+5)%3];
			if (nw!=-1) f[nw+1]=(f[nw+1]+f[i+1]>=mod?f[nw+1]+f[i+1]-mod:f[nw+1]+f[i+1]);
		}
	}
	ans=0;
	for (int i=1; i<=n; i++) if (sum[i-1]==0) 
		ans=(ans+f[i]>=mod?ans+f[i]-mod:ans+f[i]);
	return printf("%d\n",ans),0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
    int h, w;
    cin >> h >> w;

    vector<string> foo(h);

    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;

        string si;
        si.push_back('#');

        for (auto sii:s) {
            si.push_back(sii);
        }
        si.push_back('#');
        foo[i] = si;
    }

    for (int i = 0; i < w + 2; i++) {
        cout << '#';
    }

    cout << endl;


    for (auto si:foo) {
        cout << si << endl;
    }

    for (int i = 0; i < w + 2; i++) {
        cout << "#";
    }

    cout << endl;
}

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

using namespace std;

int main() {
  int a[3], b[3], c[3][3];
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j) cin >> c[i][j];
  for (int j = 0; j < 3; ++j) b[j] = c[0][j];
  for (int i = 0; i < 3; ++i) a[i] = c[i][0] - c[0][0];
  bool f = 1;
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j)
      if (a[i] + b[j] != c[i][j]) f = 0;
  cout << (f ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

template<ll mod> struct Mod_Int{
    ll x;
    Mod_Int() {}
    Mod_Int(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}

    Mod_Int &operator += (const Mod_Int &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }

    Mod_Int &operator -= (const Mod_Int &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    Mod_Int &operator *= (const Mod_Int &p) {
        x = (int) (1LL * x * p.x % mod);
        return *this;
    }

    Mod_Int &operator /= (const Mod_Int &p) {
        *this *= p.inverse();
        return *this;
    }

    Mod_Int operator -() const {return Mod_Int(-x);}

    Mod_Int operator + (const Mod_Int &p) const {return Mod_Int(*this) += p;}

    Mod_Int operator - (const Mod_Int &p) const {return Mod_Int(*this) -= p;}

    Mod_Int operator * (const Mod_Int &p) const {return Mod_Int(*this) *= p;}

    Mod_Int operator / (const Mod_Int &p) const {return Mod_Int(*this) /= p;}

    bool operator == (const Mod_Int &p) const {return x == p.x;}

    bool operator != (const Mod_Int &p) const {return x != p.x;}

    Mod_Int pow(ll n) const{
        Mod_Int now = *this, ret;
        ret.x = 1;
        while(n > 0){
            if(n & 1) ret *= now;
            now *= now, n >>= 1;
        }
        return ret;
    }

    Mod_Int inverse() const{
        return pow(mod-2);
    }
};

using mint = Mod_Int<MOD>;
const int MAX_N = 1e6;
mint fac[MAX_N+1];

void init(){
    fac[0] = {1};
    rep2(i, 1, MAX_N){
        mint a = {i};
        fac[i] = fac[i-1]*a;
    }
}

mint comb(mint n, mint k){
    return fac[n.x]/(fac[n.x-k.x]*fac[k.x]);
}

mint perm(mint n, mint k){
    return fac[n.x]/fac[n.x-k.x];
}
int main(){
    init();
    int N;
    cin >> N;
    //num[i]:=スコアがi以下になるような並べ方の数
    mint ans = {0}, num[N];
    //i個のマシンで全てを黒にする場合
    rep(i, N){
        if(2*i < N) {num[i] = {0}; continue;}
        num[i] = fac[i]*fac[N-1-i]*comb(i-1, N-i-1);
        ans += (num[i]-num[i-1])*i;
    }
    cout << ans.x << endl;
}

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

struct UnionFind{
    vector<int> par;
    int cnt;
    UnionFind(int n) : par(n, -1), cnt(n) {}
    void unite(int x, int y){
        x = find(x); y = find(y);
        if(x != y){
            if(par[y] < par[x]) swap(x, y);
            par[x] += par[y]; par[y] = x; cnt--;
        }
    }
    int find(int x){
        return par[x] < 0 ? x : par[x] = find(par[x]);
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    int size(int x){
        return -par[find(x)];
    }
    int size(){
        return cnt;
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    int p[n];
    UnionFind uf(n + 1);
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }
    int sum = 0;
    for(int i = 0; i < n; i++){
        if(uf.same(p[i], i + 1)) sum++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, k = sc.nextInt()
  val p = Array.fill(n)(sc.nextInt()-1)
  val c = Array.fill(n)(sc.nextLong())

  def decompose(a: Array[Int]): Array[Array[Int]] = {
    val n = a.length
    val visited = Array.fill(n)(false)
    var res = Array[Array[Int]]()

    for (i <- 0 until n) {
      var next = i
      var factor = Array[Int]()
      while (!visited(next)) {
        visited(next) = true
        factor :+= next
        next = a(next)
      }
      if (factor.nonEmpty) {
        res :+= factor
      }
    }

    res
  }

  val d = decompose(p).map(_.map(c))

  var ans = Long.MinValue
  for (f <- d) {
    val l = f.length
    val fa = (f ++ f).scanLeft(0L)(_ + _)
    val sum = fa(l) - fa(0)
    if (sum > 0) {
      val x = k / l
      val y = k % l
      val z = if (x == 0) 1 else 0
      for {
        i <- 0 until l
        j <- i+z to i+y
      } {
        ans = ans.max(sum * x + fa(j) - fa(i))
      }

      val w = if (x == 1) 1 else 0
      if (x != 0) {
        for {
          i <- 0 until l
          j <- i+w to i+l
        } {
          ans = ans.max(sum * (x-1) + fa(j) - fa(i))
        }
      }
    } else {
      for {
        i <- 0 until l
        j <- i+1 to i+(k.min(l))
      } {
        ans = ans.max(fa(j) - fa(i))
      }
    }
  }

  println(ans)
}


Measured memory_bytes: 58780
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <sstream>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll pow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow(N, P/2);
        return t*t;
    }
    return N * pow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}

int main() {
    ll h,w;cin>>h>>w;
    vector<vector<int>>a(h,vector<int>(w));
    rep(i,h){
        rep(j,w)cin>>a[i][j];
    }
    int cnt=0;
    vector<vector<int>> ans;
    rep(i,h){
       rep(j,w-1){
           if(a[i][j]%2==0)continue;
           cnt++;
           vector<int>v;
           a[i][j]--;
           a[i][j+1]++;
           v.push_back(i);
           v.push_back(j);
           v.push_back(i);
           v.push_back(j+1);
           ans.push_back(v);
       }
    }
    rep(i,h-1){
        if(a[i][w-1]%2==0)continue;
        cnt++;
        vector<int>v;
        a[i][w-1]--;
        a[i+1][w-1]++;
        v.push_back(i);
        v.push_back(w-1);
        v.push_back(i+1);
        v.push_back(w-1);
        ans.push_back(v);
    }
    cout<<cnt<<endl;
    rep(i,ans.size()){
        rep(j,3)cout<<ans[i][j]+1<<" ";
        cout<<ans[i][3]+1<<endl;
    }

}

Measured memory_bytes: 11312
#include<stdio.h>
#include<math.h>
typedef long long ll;
ll p5(ll n){
  return n*n*n*n*n;
}
int main(){
  ll X,A,B,i,t;
  scanf("%lld",&X);
  for(A=0;A<100000;A++){
    t = p5(A) - X;
    B = (ll)(pow(abs(t),0.2)) - 1;
    //printf("%lld %lld : %lld\n",A,t,B);
    if(p5(B)==abs(t)){
      break;
    }
    if(p5(++B)==abs(t)){
      break;
    }
    if(p5(++B)==abs(t)){
      break;
    }
  }
  if(t < 0){
    B *= -1;
  }
  printf("%d %d",A,B);
}

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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    ll ans = 0;
    ll x = a[0];
    for(int i = 1; i < n; ++i){
        ans += max(0LL, x - a[i]);
        x = max(x, a[i]);
    }
    cout << ans << endl;
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

int main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
	string a,b;
	cin>>a>>b;
	int m=a.size();
	int n=b.size();
	int dp[m+1][n+1];
	for (int i=0;i<=m;i++){
		for (int j=0;j<=n;j++){
			if (i==0 || j==0)dp[i][j]=0;
			else{
				if (a[i-1]==b[j-1])dp[i][j]=dp[i-1][j-1]+1;
				else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	string s="";
	if (dp[m][n]==0){
		cout<<s<<endl;
		return 0;
	}
	int i=m,j=n;
	while (i>0 && j>0){
		if (a[i-1]==b[j-1]){
			s+=a[i-1];
			i--;
			j--;
		}
		else{
			if (dp[i-1][j]>dp[i][j-1])i--;
			else j--;
		}
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
	return 0;
}

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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int32_t GCD(int a,int b){return b?GCD(b,a%b):a;}
int64_t GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int32_t LCM(int a, int b){return a * b / GCD(a, b);}
int64_t LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7; //10^9
constexpr int64_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/


constexpr int32_t MAX = 1e5+1;
vector<int64_t> fac(MAX, 0), finv(MAX, 0), inv(MAX, 0);
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

template<int32_t MAX> struct cominit{
    int64_t Fac[MAX], Finv[MAX], Inv[MAX];
    constexpr cominit(): Fac(), Finv(), Inv(){
        Fac[0] = Fac[1] = 1;
        Finv[0] = Finv[1] = 1;
        Inv[1] = 1;
        for (int i = 2; i < MAX; i++){
            Fac[i] = Fac[i - 1] * i % MOD;
            Inv[i] = MOD - Inv[MOD%i] * (MOD / i) % MOD;
            Finv[i] = Finv[i - 1] * Inv[i] % MOD;
        }        
    }
    
};

//#define int int64_t
signed main()
{
	//COMinit();
    constexpr auto com = cominit<MAX>();
	int n, m; cin >> n >> m;
    if(abs(n-m)>=2){
        cout << 0 << endl;
    }
    else{
        if(n>m || m > n){
            cout << com.Fac[n]*com.Fac[m]%MOD << endl;
        }
        else
        {
            cout << (com.Fac[n]*com.Fac[m]%MOD)*2%MOD << endl;
        }
        
    }
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line[] = br.readLine().split(" ");
		int a = Integer.parseInt(line[0]);
		int b = Integer.parseInt(line[1]);

		System.out.println(b >= a ? a : a - 1);
	}

}


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

int main(){
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int ans=0;
    //cout<<a[7]<<endl;
    for(int i=1;i<=n;i++){
        int dem=0;
        while((i+1 <= n) && (a[i+1] <= a[i])){
            dem++;
            i++;
        }
        ans=max(ans,dem);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define rep(i,a,b) for(int i = a;i <= b;i++)
using namespace std;
const int N = 1e5+100;
typedef long long ll;

int a[N];
int n;
int sum[N],xp[N];
ll tot,tmp;

void Merge(int l, int mid, int r)
{
	if(l == r) return;
	int p = l, q = mid+1, pos = l;
	while(p <= mid && q <= r){
		if(sum[p] < sum[q]) xp[pos++] = sum[p++];
		else{
			tmp += (p-l);
			xp[pos++] = sum[q++];
		}
	}
	while(p <= mid) xp[pos++] = sum[p++];
	while(q <= r) tmp += (p-l), xp[pos++] = sum[q++];
	for(int k = l; k <= r; k++)
		sum[k] = xp[k];
}

void Mergesort(int l,int r)
{
	if(l < r)
	{
		int mid = (l+r)>>1;
		Mergesort(l,mid);
		Mergesort(mid+1,r);
		Merge(l,mid,r);
	}
}

int check(int x)
{
	sum[0] = 0;
	tmp = 0;
	rep(i,1,n)
		if(a[i] <= x) sum[i] = 1;
		else sum[i] = -1;//, tmp++;
	rep(i,1,n)
		sum[i] += sum[i-1];
//	printf("x:%d, tmp:%lld, tot:%lld\n",x,tmp,tot);
	Mergesort(0,n);
//	printf("x:%d, tmp:%lld, tot:%lld\n",x,tmp,tot);
	if(tmp >= (tot/2+1)) return 1;
	else return 0;
}

int main()
{
	scanf("%d",&n);
	int l = 1e9, r = -1, ans;
	tot = 0;
	rep(i,1,n){
		scanf("%d",&a[i]);
		l = min(l,a[i]);
		r = max(r,a[i]);
		tot += i;
	} 
//	tot = n*(n+1)/2;
	while(l <= r)
	{
		int mid = (l+r)>>1;
		if(check(mid)){
		//	printf("Yes\n");
			ans = mid;
			r = mid-1;
		}
		else{
			l = mid+1;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1408
import * as fs from "fs";

// 4 3
// 3333
const input: string[] = fs.readFileSync("/dev/stdin", "utf8").split(" ");

const a: number = parseInt(input[0]);
const b: number = parseInt(input[1]);

let result: string = '';
if (a == b) {
    for (let i: number = 0; i < a; i++) {
        result += a.toString();
    }
} else if (a > b) {
    for (let i: number = 0; i < a; i++) {
        result += b.toString()
    }
} else {
    for (let i: number = 0; i < b; i++) {
        result += a.toString()
    }
}
console.log(result);



Measured memory_bytes: 7372
S = input()
cnt = [S.count(chr(ord('a')+i)) for i in range(26)]
if sum(cnt) == 26:
    pos = 0
    for j in range(25, 0, -1):
        if S[j] > S[j-1]:
            pos = j
            break
    if pos == 0:
        print(-1)
    else:
        a = S[pos:26]
        for x in a[::-1]:
            if S[pos-1] < x:
                T = S[:pos-1] + x
                print(T)
                break


else:
    for j in range(26):
        if cnt[j] == 0:
            S += chr(ord('a')+j)
            print(S)
            break

Measured memory_bytes: 3064
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
ll a,b,c,d;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>a>>b>>c>>d;
	if(a+b<c+d)
	cout<<"Right";
	else if(a+b>c+d)
	cout<<"Left";
	else
	cout<<"Balanced";
	return 0;
}


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

using namespace std;

const int MAXN = 205;
int l[MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    n *= 2;
    for(int i = 0; i < n; i++)
        cin >> l[i];
    sort(l, l + n);
    int ans = 0;
    for(int i = 0; i < n; i += 2)
        ans += l[i];
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 200005
#define LL long long
 
char s[N];
int tot[N][26],f[N];
int n,T;
 
LL calc(LL len,int ch)
{
	if(len<=n) return tot[len][ch];
	LL num1=tot[n][ch],num2=tot[T][ch];
	LL len1=n,len2=T;
	while(len1+len2<=len){
		num1=num1+num2,num2=num1-num2;
		len1=len1+len2,len2=len1-len2;
	}
	return num1+calc(len-len1,ch);
}
 
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1)/2;
	f[0]=0;f[1]=0;tot[1][s[1]-'a']=1;
	for(int i=2,p;i<=n;i++)
	{
		p=f[i-1];
		while(p&&s[p+1]!=s[i]) p=f[p];
		f[i]=s[p+1]!=s[i] ? 0:p+1;
		memcpy(tot[i],tot[i-1],sizeof(tot[i]));
		tot[i][s[i]-'a']++;
	}
	T=n-f[n];// cout << T << endl; return 0;
	LL l,r;
	cin>>l>>r;
	for(int i=0;i<26;i++)	cout<<calc(r,i)-calc(l-1,i)<<" ";
	return 0;
} 

Measured memory_bytes: 12288
<?php
// B
fscanf(STDIN, '%d', $n);
$ans = 0;
for ($i = 1; $i <= $n; $i += 2) {
    if (count(divisors($i)) === 8) $ans++;
}
echo $ans;

// 約数列挙
function divisors($max)
{
    $arr = [];
    $rmax = (int) floor(sqrt($max));
    for ($i = 1; $i <= $rmax; $i++) {
        if ($max % $i === 0) {
            $arr[] = $i;
            $arr[] = $max / $i;
        }
    }
    sort($arr);
    return array_unique($arr);
}

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}

const int N=6020;
int M;
int f[N],p2[N],p3[N],i2[N],i3[N],ifc[N];
int bp(int a,int pw){ 
    int r=1;
    for(;pw;(a*=a)%=M,pw/=2)if(pw&1)(r*=a)%=M;
    return r;
}
int inverse(int a){return bp(a%M,M-2);} 
int32_t main(){
    int n;
    cin>>n>>M;
    f[0]=p2[0]=p3[0]=i2[0]=i3[0]=ifc[0]=1;
    for(int i=1;i<N;++i){
        f[i]=(f[i-1]*i)%M;
        ifc[i]=inverse(f[i]);
        p2[i]=(p2[i-1]*2)%M;
        i2[i]=inverse(p2[i]);
        p3[i]=(p3[i-1]*3)%M;
        i3[i]=inverse(p3[i]);
    }
    int ans=0;
    forn(c3,n+1){
        int r=3*(n-c3);
        for(int c2=0;c2*2<=r;++c2){
            int c1=r-c2*2;
            if(c1<c2)continue;
            int cur=((f[n*3]*i2[c2]%M)*i3[c3]%M);
            (cur*=ifc[c1])%=M;
            (cur*=ifc[c2])%=M;
            (cur*=ifc[c3])%=M;
            // dbg(c1,c2,c3,cur,f[n*3],p2[c2],p3[c3],i2[c2],i3[c3],ifc[c1+c2+c3],f[c1+c2+c3]);
            if((ans+=cur)>=M)ans-=M;
        }
    }
    cout<<ans<<'\n';


    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste

// #include "UnionFind.hpp"
// #include "power.hpp"

signed main() {
    double a, b, c;
    cin >> a >> b >> c;
    cout << setprecision(15) << 0.5 * a * b * sin(M_PI * (c / 180)) << endl;
    cout << setprecision(15) << a + b + sqrt(pow(a, 2) + pow(b, 2) - (2 * a * b * cos(M_PI * (c / 180)))) << endl;
    cout << setprecision(15) << b * sin(M_PI * (c / 180)) << endl;
}



Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	char a[3][3];
	rep(i,3)rep(j,3) cin >> a[i][j];
	cout << a[0][0] << a[1][1] << a[2][2] << endl;
}

Measured memory_bytes: 256
X, Y = map(int, input().split())
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod
  
mod = 10 ** 9 + 7
  
if (X + Y) % 3 == 0:
  n = (X + Y) // 3 
  if min(X, Y) >= n:
    s = min(X, Y) - n
    ans = comb(n, s, mod)
  else:
    ans = 0
else:
  ans = 0

print(ans)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#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 srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 305;

double m[MAX_N][MAX_N][MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int u[3] = {};
    rep(i,n){
        int a;
        cin >> a;
        u[a-1]++;
    }
    rep(k,n+1){
        rep(j,n+1){
            rep(i,n+1){
                if(i+j+k == 0) continue;
                double cri = 0;
                if(i > 0) cri += m[i-1][j][k]*i;
                if(j > 0) cri += m[i+1][j-1][k]*j;
                if(k > 0) cri += m[i][j+1][k-1]*k;
                m[i][j][k] = (cri+n)/(double)(i+j+k);
            }
        }
    }
    printf("%.12lf\n",m[u[0]][u[1]][u[2]]);
    return 0;
}

Measured memory_bytes: 219392
/* ADLS1_6_B:Partition */
/* 20181120 AOJ */

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#define N 100000

int partition(int *A, int p, int r);
void swap(int *x, int *y);

int main(void){
	int n, i = 0, A[N], q;

	scanf("%d", &n);
	while(i < n) {
		scanf("%d", &A[i++]);
	}

	q = partition(A, 0, n - 1);
	for(i = 0; i < n; i++) {
		if(i) printf(" ");
		if(i == q) {
			printf("[%d]", A[i]);
		}else {
			printf("%d", A[i]);
		}
	}
	printf("\n");

	return 0;
}

int partition(int *A, int p, int r) {
	int i, j;

	i = p - 1;
	for(j = p; j < r; j++) {
		if(A[j] <= A[r]) {
			i++;
			swap(&A[i], &A[j]);
		}
	}
	swap(&A[++i], &A[r]);
	return i;
}

void swap(int *x, int *y) {
	int temp = *x;
	*x = *y;
	*y = temp;
}



Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
  string S, T;
  cin >> S >> T;
  ll c = 0;
  rep(i, sz(S)){
    if(S.at(i) != T.at(i)){
      c++;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 3852
gets
x = gets.split.map &:to_i
y = gets.split.map &:to_i
d = []
x.each_with_index{|e, i|
  d[i] = (e - y[i]).abs
}
puts d.inject :+
puts d.inject(0){|s, n| s + n*n} ** 0.5
puts d.inject(0){|s, n| s + n*n*n} ** (1.0 / 3)
puts d.max

Measured memory_bytes: 8876