akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

readi b | Just (n, _) <- B.readInt b = n

solve :: Int -> Int -> Int -> [Int] -> Int
solve n c k ts = go 0 0 (head ts) ts
  where
    go !p q _ []
        | q == 0    = p
        | otherwise = p + 1
    go !p q r (x:xs)
        | q == c    = go (p + 1) 0 x (x:xs)
        | x > r + k = go (p + 1) 0 x (x:xs)
        | otherwise = go p (q + 1) r xs

main :: IO ()
main = do
    [n, c, k] <- fmap readi . B.words <$> B.getLine
    ts <- fmap sort . replicateM n $ readi <$> B.getLine
    print $ solve n c k ts

Measured memory_bytes: 30972
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include <numeric>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 99999999

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };





ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}
ll m = 10000007;
ll p[10], c[10];
int main() {
	int D, G;
	cin >> D >> G;
	REP(i, D) {
		cin >> p[i] >> c[i];
	}
	ll ans = INF;
	bool used[10];
	REP(i, 10)used[i] = false;
	//各配点の問題を解ききるかどうかで全探索(2^10通り)
	for (int x = 0; x < myPow(2, D, m); x++) {
		//例えばD = 10なら100000000000~1111111111を調べるので10進数だと0~1023
		int sum = 0;
		ll cnt = 0;
		for (int i = 0; i < D; i++) {
			if (x&(1 << i)) {//左からi桁目が1ならば
				used[i] = true;
				sum += 100 * (i + 1)*p[i] + c[i];
				cnt += p[i];
			}
		}
		if (sum >= G) {
			ans = min(ans, cnt);
		}
		else {
			REPR(i, D-1) {
				if (!used[i]) {
					REP(j, p[i]+1) {
						sum += 100 * (i + 1);
						cnt++;
						if (sum >= G) {
							ans = min(ans, cnt);
							break;
						}
					}
				}
			}
		}
		REP(i, 10)used[i] = false;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# DP(配るDP)
N = int(input())
h = list(map(int, input().split()))

dp = [float('inf')] * N
dp[0] = 0
for i in range(N - 2):
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
dp[N - 1] = min(dp[N - 1], dp[N - 2] + abs(h[N - 1] - h[N - 2]))
print(dp[N - 1])


Measured memory_bytes: 14356
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)

vvi a,b;
viii edj;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z;
    cin>>n;
    a.assign(n,vi(n));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
            if(j>i)edj.pb(mc(a[i][j],i,j));
        }
    }
    b = a;

    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                a[i][j] = min(a[i][j], a[i][k] + a[k][j]); 
            }
        }
    }
    if(a!=b){
        cout<<-1;
        return 0;
    }

    ll d = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            bool ok = true;
            for(int k=0;k<n;k++){
                if((a[i][j]==(a[i][k]+a[j][k]))&&(k!=i)&&(k!=j)){
                    ok = false;
                }
            }
            if(ok)
            d+=a[i][j];
        }
    }
    cout<<d;
    
    

    



    return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int sx,sy,gx,gy; cin >> sx >> sy >> gx >> gy;

  string ans = "";
  for(int i = sx; i < gx; i++){
    ans += "R";
  }
  for(int i = sy; i < gy; i++){
    ans += "U";
  }
  for(int i = sx; i < gx; i++){
    ans += "L";
  }
  for(int i = sy; i < gy; i++){
    ans += "D";
  }

  ans += "D";
  for(int i = sx; i < gx; i++){
    ans += "R";
  }
  ans += "RU";
  for(int i = sy; i < gy; i++){
    ans += "U";
  }
  ans += "LU";
  for(int i = sx; i < gx; i++){
    ans += "L";
  }
  ans += "LD";
  for(int i = sy; i < gy; i++){
    ans += "D";
  }
  ans += "R";

  cerr << ans << endl;
  cout << ans << endl;

}


Measured memory_bytes: 3580
import itertools

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

count = 0
for p, q in itertools.combinations([a, b, c, d, e], 2):
    if abs(p - q) > k:
        print(':(')
        break
    else:
        continue
else:
    print('Yay!')

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;

vl p,c;
ll n,k;

ll game(ll start){
    vb visit(n,false);
    vl scores(n,-1);
    visit[start] = true;
    scores[start] = 0;
    ll now = start;
    ll cnt = 0;
    while(scores[p[now]] == -1 && cnt < k){
        scores[p[now]] = scores[now]+c[p[now]];
        now = p[now];
        cnt++;
    }
    if(scores[p[now]] == -1){
        ll maxi = -inf;
        rep(i,n) if(i != start) maxi = max(maxi,scores[i]);
        return maxi;
    }
    scores[p[now]] = scores[now]+c[p[now]];
    now = p[now];
    if(scores[now] > 0){
        ll ngo = k/(cnt+1)-1;
        ll amari = k%(cnt+1);
        ll tasu = ngo*(scores[now]);
        //if(start == 0) cout<<tasu<<" "<<amari<<" "<<scores[now]<<endl;
        rep(i,n) scores[i] += tasu;
        rep(i,amari){
            //if(start == 0) cout<<scores[now]<<endl;
            scores[p[now]] = scores[now]+c[p[now]];
            now = p[now];
        }
        ll maxi = -inf;
        rep(i,n) maxi = max(maxi,scores[i]);
        return maxi;
    }
    else{
        ll maxi = -inf;
        //scores[p[now]] = scores[now]+c[p[now]];
        rep(i,n) maxi = max(maxi,scores[i]);
        return maxi;
    }
}

int main(void) {
    cin>>n>>k;
    p = vl(n);
    c = vl(n);
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    rep(i,n) cin>>c[i];
    ll maxi = -inf;
    rep(i,n){
        maxi = max(maxi,game(i));
    }cout<<maxi<<endl;
    return 0;
}


Measured memory_bytes: 3748
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//typedef long long LL;
using namespace std;

int main(){
    int h;
    int w;
    int ans=0;
    cin >> h >> w;
    vector<vector<char>> s(w, vector<char>(h));
    vector<vector<int>> w_left_light(w, vector<int>(h));
    vector<vector<int>> w_right_light(w, vector<int>(h));
    vector<vector<int>> h_upper_light(w, vector<int>(h));
    vector<vector<int>> h_lower_light(w, vector<int>(h));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> s[j][i];
        }
    }
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s[j][i]=='.'){
                if(j!=0){
                    w_left_light[j][i]=w_left_light[j-1][i]+1;
                }else{
                    w_left_light[j][i]=1;
                }
            }else{
                w_left_light[j][i]=0;
            }
        }
    }
    for(int i=0; i<h; i++){
        for(int j=w-1; j>=0; j--){
            if(s[j][i]=='.'){
                if(j!=w-1){
                    w_right_light[j][i]=w_right_light[j+1][i]+1;  
                }else{
                    w_right_light[j][i]=1;
                }
            }else{
                w_right_light[j][i]=0;
            }
        }
    }

    for(int j=0; j<w; j++){
        for(int i=0; i<h; i++){
            if(s[j][i]=='.'){
                if(i!=0){
                    h_upper_light[j][i]=h_upper_light[j][i-1]+1;                  
                }else{
                    h_upper_light[j][i]=1;
                }
            }else{
                h_upper_light[j][i]=0;
            }
        }
    }
    for(int j=0; j<w; j++){
        for(int i=h-1; i>=0; i--){
            if(s[j][i]=='.'){
                if(i!=h-1){
                    h_lower_light[j][i]=h_lower_light[j][i+1]+1;
                }else{
                    h_lower_light[j][i]=1;           
                }
            }else{
                h_lower_light[j][i]=0;
            }
        }
    }
    int tmp;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            tmp = w_left_light[j][i] + w_right_light[j][i] + h_upper_light[j][i] + h_lower_light[j][i] - 3;
            if(ans<tmp){
                ans = tmp;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 69120
import os, sys, re, math
sys.setrecursionlimit(100000)
N,M = list(map(int,input().split(' ')))
A = list(map(int,input().split(' ')))

match = [100,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]
    if m == 0:
        return ""

    ret = None
    for a in A:
        tmp = None
        if m - match[a] >= 0:
            tmp = doit(m - match[a])
            if tmp is not None:
                tmp = str(a) + tmp
                if ret is not None:
                    if len(ret) < len(tmp) or (len(ret) == len(tmp) and tmp > ret):
                        ret = tmp
                else:
                    ret = tmp

    memo[m] = ret
    return ret

print(doit(N))


Measured memory_bytes: 33836
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int n = 0;
		try {
			scanner = new Scanner(System.in);
			n = scanner.nextInt();
			int[] wk = new int[n];
			for (int i = 0; i < n; i++) {
				wk[i] = scanner.nextInt();
			}
			Arrays.sort(wk);

			int count = 0;
			for (int i = 0; i < wk.length - 1; i++) {
				count += wk[i];
			}

			System.out.println(count <= wk[wk.length - 1] ? "No" : "Yes");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void mizu() {

		for (int i = 0; i < wkH.length; i++) {

			if (wkH[i] == 0) {
				continue;
			} else if (wkH[i] > 0) {
				wkH[i]--;
				if (i + 1 < wkH.length && wkH[i + 1] == 0) {
					return;
				}
			}

		}
	}

	boolean isExit = false;
	int res = 0;
	int[] wk;
	int[] wkH;
	int n = 0;

	private void solveB() {
		Scanner scanner = null;
		n = 0;

		try {
			scanner = new Scanner(System.in);
			n = scanner.nextInt();
			wk = new int[n];
			for (int i = 0; i < n; i++) {
				wk[i] = scanner.nextInt();
			}
			wkH = wk;

			while (!isExit()) {
				res++;
				mizu();
			}

			System.out.println(res);
		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private boolean isExit() {
		boolean res = true;

		for (int i = 0; i < wkH.length; i++) {
			if (wkH[i] != 0) {
				res = false;
			}
		}
		return res;
	}

	private void solveC() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 24148
import sys
N = int(input())
# list = list(input() for _ in range(N))
list = [int(i) for i in sys.stdin.readlines()] # こっちのが早い

def insertionSort(N, g):
  c = 0
  for i in range(g, N):
    v = list[i]
    j = i - g
    while j >= 0 and list[j] > v:
      list[j+g] = list[j]
      j -= g
      c += 1
    list[j+g] = v
  return c

# def shell_sort(n):
  #数列Gの作成

cnt = 0
m = 0
G = []

h = 1
while h <= N:
  G.insert(0, h)
  h = 3 * h + 1
for i in range(len(G)):
  cnt += insertionSort(N, G[i])

print(len(G))
print(' '.join(map(str, G)))
print(cnt)
for i in range(N):
  print(list[i])




Measured memory_bytes: 116564
def main():
    switch_number = []
    N, M = map(int, input().split())
    for _ in range(M):
        k = tuple(map(int, input().split()))
        switch_number.append(k[1:])
    p = list(map(int, input().split()))

    ans = 0
    for i in range(2 ** N):
        binary = list(map(int, format(i, 'b').zfill(N)))
        a = True
        for k, number in enumerate(switch_number):
            count = 0
            for j in number:
                if binary[j - 1] == 1:
                    count += 1
            if count % 2 != p[k]:
                a = False
                break
        if a:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("input.txt", "r", stdin);
    string s;
    cin >> s;
    int n = s.length();
    bool satisfy = true;
    if(s[0] != 'A') { satisfy = false; }
    int cnt = 0;
    //cerr << n << endl;
    for(int i = 2; i < n-1; i++){
        if(s[i] == 'C') { cnt++; }
    }
    //cerr << cnt << endl;
    if(cnt > 1 || cnt == 0) { satisfy = false; }
    //cerr << cnt << endl;
    for(int i = 0; i < n; i++){
        if(s[i] != 'A' && s[i] != 'C'){
            if(isupper(s[i])){
                satisfy = false;
                //cerr << "3" << endl;
            }
        }
    }
    if(s[n-1] == 'C') satisfy = false;
    if(satisfy == true){
        printf("AC\n");
    }else{
        printf("WA\n");
    }
    return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/

ll gcd(ll a,ll b){
  if(a<b) swap(a,b);
  ll t = a%b;
  if(t==0) return b;
  else return gcd(b,t);
}
int main() {
  ll a,b;
  cin >> a >> b;
  ll g = gcd(a,b);

  ll k = sqrt(g);
  if(k*k!=g) k+=1;
  vector<bool> sp = vector<bool>(2*k,true);
  sp[0] = false;
  sp[1] = false;
  vl cand;
  cand.push_back(g);
  FOR(i,2,k+1){
    if(g%i==0){
      cand.push_back(i);
      cand.push_back(g/i);
    }
  }
  sort(cand.begin(),cand.end());
  //REP(i,cand.size()) cout << cand[i] << endl;
  vector<bool> so(cand.size(),true);
  REP(i,cand.size()){
    FOR(j,i+1,cand.size()){
      if(cand[j]%cand[i]==0) so[j] = false;
    }
  }
  ll ans = 1;
  REP(i,cand.size()){
    if(so[i] && cand[i]!=1) {
      ans++;
      //DEBUG(cand[i]);
    }
  }
//
//  REP(i,primes.size()){
//    bool fg = false;
//    while(g%primes[i]==0){
//      fg = true;
//      g /= primes[i];
//    }
//    if(fg) ans++;
//  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

char rep[100003];

int main() {
	int n; cin >> n;
	string s;
	cout << 0 << endl;
	cin >> s;
	rep[0] = s[0];
	if (rep[0] == 'V') return 0;
	int res = 19;
	int lo = 0, hi = n;
	while (hi - lo > res) {
		int mid = lo + (hi - lo) / 2;
		cout << mid << endl;
		cin >> s;
		if (s[0] == 'V') return 0;
		rep[mid] = s[0];
		--res;
		if ((mid - lo) % 2 == 1 && rep[mid] == rep[lo] || (mid - lo) % 2 == 0 && rep[mid] != rep[lo]) {
			hi = mid;
		}
		else {
			lo = mid;
		}
	}
	for (int i = lo + 1; i < hi; ++i) {
		cout << i << endl;
		cin >> s;
		rep[i] = s[0];
		if (rep[i] == 'V') return 0;
	}
	return 0;
}


Measured memory_bytes: 852
#include <stdio.h>
#define N 100000

int main(){
  int A[N], i, j, num;
  int x, p, temp;
  
  scanf("%d", &num);

  for(i = 0 ; i < num; i++){
    scanf("%d", &A[i]);
  }

  x = A[num-1];
  i = -1;
  
  for(j = 0; j < num-1; j++){
    if(A[j] <= x){
      i = i+1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  
  temp = A[i+1];
  A[i+1] = A[num-1];
  A[num-1] = temp;

  j = i+1;

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



Measured memory_bytes: 2244
num = [0 for i in range(2019)]
num[0] = 1
count = 0
s = input()
now = 0
p = 1
for i in range(len(s) - 1, -1, -1):
    now = (now + int(s[i]) * p) % 2019
    count += num[now]
    num[now] += 1
    p = p * 10 % 2019
print(count)

Measured memory_bytes: 9092
array = gets.split("").map(&:to_i)
a=10*array[0]+array[1]
b=10*array[2]+array[3]
if a>0 && a<13
  if b>0 && b<13
    puts "AMBIGUOUS"
  else
    puts "MMYY"
  end
else
  if b>0 && b<13
    puts "YYMM"
  else
    puts "NA"
  end
end

Measured memory_bytes: 1788
from collections import deque
a = deque(reversed(input()))
b = deque(reversed(input()))
c = deque(reversed(input()))
ne = a.pop()
while(True):
    if ne == 'a':
        if not a: break
        ne = a.pop()
    elif ne == 'b':
        if not b: break
        ne = b.pop()
    else:
        if not c: break
        ne = c.pop()
print(ne.upper())

Measured memory_bytes: 9296
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#define MAX_N 120000
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
ll modinv(ll a, ll m){
  ll b=m,u=1,v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  u%=m;
  if(u<0) u+=m;
  return u;
}
signed main(){
  init_io();
  ll n,ans=0,pin[MAX_N],cnt=1,per,tw=2,val;
  pin[0]=pin[1] = 1;
  cin >> n;
  vector<ll> x(n),rt(MAX_N);
  rt[0] = 1;
  for(int i=0;i<n;i++){
    cin >> x[i];
  }
  for(ll i=1;i<MAX_N;i++){
    rt[i] = (i)* rt[i-1];
    rt[i] %= MOD;
  }
  pin[0] = 1;
  for(ll i=1;i<MAX_N;i++){
    pin[i] = (pin[i-1])%MOD + modinv(i+1,MOD);
    pin[i] %= MOD;
  }
  ans = 0;
  for(int i=0;i<n-1;i++){
    ll dis = x[i+1]-x[i];
    dis %= MOD;
    ans += dis*pin[i];
    ans %= MOD;
  }
  ans *= rt[n-1];
  ans %= MOD;
  cout << ans << endl;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <vector>
#include <map>
#include <set>

#define ll long long
#define h   "\n"
#define ios
using namespace std;

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

    set<string> ss;

    map<string,int> m;
    vector <string> v;

    for(int i=0;i<n;i++)
    {
        cin>>s;
        m[s]++;
       v.push_back(s);
        ss.insert(s);
    }

    int mx=0;

    for(int i=0;i<v.size();i++)
        if(m[v[i]]>mx)
            mx=m[v[i]];

//cout<<mx<<h;

for(auto r:ss)
{
    if(m[r]==mx)
        cout<<r<<h;
}

    return 0;
}


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

typedef long long int ll;
typedef long double   ld;

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

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                       cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int t; cin >> t; while(t--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    pll                      pair <long long int , long long int>
#define    ook(x)                   order_of_key(x)
#define    fbo(x)                   find_by_order(x)

int main(){
     speed upp
     int n; cin >> n;
     int arr[n+5] , ans[n+5];
     ll sum = 0;
     f(i,1,n){
         cin >> arr[i];
         if(i%2==0){
             sum-=arr[i]; continue;
         }
         sum+=arr[i];
     }
     ans[1] = sum;
     cout << ans[1] << " ";
     f(i,2,n){
         ans[i] = 2*arr[i-1] - ans[i-1];
         cout << ans[i] << " ";
     }
}

Measured memory_bytes: 2176
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<size_t N> struct solve {

	lint lun[N + 5];

	constexpr solve() : lun() {

		for (int i = 1; i <= 9; i++) lun[i] = i;

		for (int st = 1, idx = 10; idx <= N; st++) {

			if (lun[st] % 10 != 0) lun[idx++] = lun[st] * 10 + lun[st] % 10 - 1;
			lun[idx++] = lun[st] * 10 + lun[st] % 10;
			if (lun[st] % 10 != 9) lun[idx++] = lun[st] * 10 + lun[st] % 10 + 1;
			
		}

	}

};

solve<100000> S;

int main() {

	int N;
	scanf("%d", &N);
	printf("%lld", S.lun[N]);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
typedef   long long int ll;
int main () 
{
    ll n;cin>>n;
    ll a[n],b[n+1]={0},sum=0,k,k1=0,k2=0;
    for (ll i=0;i<n;i++) cin>>a[i];
    for (ll i=0;i<n;i++) {
        b[a[i]]++;
    }
    for (ll i=1;i<=n;i++) {
        if (b[i]>1) {
            sum+=(b[i]*(b[i]-1))/2;
        }
    }
    for (ll i=0;i<n;i++) {
        k1=0;k2=0;
        if(b[a[i]]>1) {
            k=b[a[i]];
            k1=0;
            k1=(k*(k-1))/2;
             k--;
             k2=0;
             if (k>1) {
                 k2=(k*(k-1))/2;
             } 
        }      
        cout<<sum+k2-k1<<endl;
        }
    
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  int H,W;cin>>H>>W;vs S(H);rep(i,H)cin>>S[i];
  vi dx={0,0,1,1,1,-1,-1,-1};
  vi dy={1,-1,1,0,-1,1,-1,0};
    
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i][j]!='.')continue;
      if(S[i][j]=='.'){
        cnt=0;
        for(int k=0;k<8;k++){
          if(i+dx[k]>=0&&i+dx[k]<H&&j+dy[k]>=0&&j+dy[k]<W){
            if(S[i+dx[k]][j+dy[k]]=='#')cnt++;
          }
        }
        S[i][j]=cnt+'0';
      }
    }
  }
  rep(i,H)cout<<S[i]<<endl;
}







Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Queue;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;



public class Main{
	
	static int posx;
	static int posy;
	static int type;
	static int diff;
	static int INF = Integer.MAX_VALUE;
	static int[][] d;
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}



	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}


	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}


	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}


	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 
	 String S=sc.next();
	 
	 char[] c=S.toCharArray();
	 boolean flag=true;
	 
	 for(int i=0;i<c.length;i++) {
		 if((i+1)%2==0) {
			 if(c[i]=='R') {
				 flag=false;
				 break;
			 }
		 }else {
			 if(c[i]=='L') {
				 flag=false;
				 break;
			 }
			 
		 }
	 }
	 
	if(flag) {
		System.out.println("Yes");
	}else {
		System.out.println("No");
	}
     
	
	 
	 
	 
	
	 
	 
	 
 }
	


}


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

int H=1, W=1;

int main() {
    for (;H*W!=0;) {
        cin >> H >> W;
        for (int i=0; i<H/2; i++) {
            for (int j=0; j<W/2; j++) cout << "#.";
            if (W%2==1) cout << '#';
            cout << endl;
            for (int j=0; j<W/2; j++) cout << ".#";
            if (W%2==1) cout << '.';
            cout << endl;
        }
        if (H%2==1) {
            for (int j=0; j<W/2; j++) cout << "#.";
            if (W%2==1) cout << '#';
            cout << endl;
        }
        if (H*W != 0) cout << endl;
    }
}


Measured memory_bytes: 3088
List =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
 
i = int(input())
 
print(List[i-1])

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

int main(){
  int m,k;
  cin>>m>>k;
  if(k==0){
	rep(i,1<<m)
      cout<<i<<" "<<i<<endl;
    return 0;
  }
  if(k==1&&m==1){
    cout<<-1<<endl;
    return 0;
  }
  if(k>=1<<m){
    cout<<-1<<endl;
    return 0;
  }
  cout<<k<<endl;
  rep(i,1<<m){
    if(i==k)continue;
	cout<<i<<endl;
  }
  cout<<k<<endl;
  for(int i=(1<<m)-1;i>=0;i--){
	if(i==k)continue;
	cout<<i<<endl;
  }
}


Measured memory_bytes: 3636
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if __name__ == "__main__":
    N, M = map(int, input().split())
    ret = 0
    if M >= 2:
        ret += combinations_count(M, 2)
    else:
        pass
    if N >= 2:
        ret += combinations_count(N, 2)
    else:
        pass
    print(ret)


Measured memory_bytes: 3060
package main

import (
        "fmt"
)

func solution(n int, a []int) int {
        c := 0
        rise := 0 // -1: down, 1: up
        for i := 1; i < n; i++ {
                d := a[i] - a[i-1]
                switch {
                case d > 0 && rise == -1:
                        c++
                        rise = 0
                case d < 0 && rise == 1:
                        c++
                        rise = 0
                case d > 0:
                        rise = 1
                case d < 0:
                        rise = -1
                }
        }
        return c + 1
}

func main() {
        var n int
        fmt.Scan(&n)
        a := make([]int, n)
        for i := range a {
                fmt.Scan(&a[i])
        }
        fmt.Println(solution(n, a))
}

Measured memory_bytes: 6308
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int[] a = strToIntArray(br.readLine());

			List<String> SList = new ArrayList<String>();
			for (int i = 0; i < a[0]; i++) {
				SList.add(br.readLine());
			}

			Collections.sort(SList);

			StringBuilder sb = new StringBuilder("");

			for (String string : SList) {
				sb.append(string);
			}
			System.out.println(sb.toString());
		} catch (Exception e) {
			System.err.println("Error:" + e.getMessage());
		}
	}

	// Stringで読みこんでスペースで分割されている数字を配列に入れるやつ
	// 利用法 int[] A = strTointArray(br.readLine());
	static int[] strToIntArray(String S) {
		String[] strArray = S.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}
}


Measured memory_bytes: 8144
#include <iostream>
#include <map>
using namespace std;
int main() {
  int A,B, C;
  map<int,int> m;
  cin >> A >> B >> C;
  m[A]++;
  m[B]++;
  m[C]++;
  if (m.size() == 2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
fun main (args : Array<String>) {
    val s = readLine()!!
    var sList : MutableList<String> = mutableListOf()

    for (i in s) {
        sList.add(i.toString())
    }

    if (sList[2] == sList[3] && sList[4] == sList[5]) {
        return println("Yes")
    } else {
        return println("No")
    }

}


Measured memory_bytes: 34392
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n,m;cin>>n>>m;
    int x[m];
    for(int i = 0;i<m;i++) cin>>x[i];
    sort(x,x+m);
    int s[m-1];
    for(int i = 0;i<m-1;i++){
      s[i] = x[i+1] -x[i];
    }
    sort(s,s+m-1);
    int g = 0;
    for(int i =0;i<m-1-n+1;i++){
      g+= s[i];
    }
    cout<<g;
    return 0;
}

Measured memory_bytes: 3912
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,q,result=0;
  int a[LIMIT2]={0};
  int b[LIMIT2]={0};
  char s[LIMIT1];

  scanf("%lld %lld %lld",&n,&k,&q);
  rep(i,q) scanf("%d",&a[i]);
  
  rep(i,q){
    b[a[i]-1]++;
  }
  rep(i,n){
    if(b[i]+k-q>0) printf("Yes\n");
    else printf("No\n");
  }

  return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;

template<class T> void dprint(T s){
  if(DEBUG){ cout << s << "\n"; }
}

struct edge{
  int u,v,w;
};

int main(int argc, char *argv[]){
  if(argc>1 && argv[1][0]=='D'){ DEBUG = 1;}

  int L; cin>>L;
  int r = 0;
  REPR(i,19){
    if(pow(2,i)<=L){
      r = i; break;
    }
  }
  int N = r+1;
  vector<edge> v;
  for(int i=1;i<=N-1;++i){
    v.push_back({ i,i+1,(int)pow(2,i-1)});
    v.push_back({ i,i+1,0});
  }
  for(int t=N-1;t>=1;--t){
    if(L - pow(2,t-1)>=pow(2,r)){
      v.push_back( {t,N, (int)(L - pow(2,t-1))}  );
      L -= pow(2,t-1);
    }
  }
  printf("%d %d\n",N,v.size());
  for(edge e:v){
    printf("%d %d %d\n",e.u,e.v,e.w);
  }
}

Measured memory_bytes: 4092
#include <bits/stdc++.h>
using namespace std;
inline int read(){
	register int x=0;
	register bool f=0;
	register char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-48;
		c=getchar();
	}
	return f?-x:x;
}
char cr[200];int tt;
inline void print(register long long x,register char k='\n') {
    if(!x) putchar('0');
    if(x < 0) putchar('-'),x=-x;
    while(x) cr[++tt]=x%10+'0',x/=10;
    while(tt) putchar(cr[tt--]);
    putchar(k);
}
char get(){
    char ch=getchar();
    while (ch!='.'&&ch!='#') ch=getchar();
    return ch;
}
const int maxn=505;
char a[maxn][maxn],b[maxn][maxn];
signed main(){
	int n=read(),m=read();
    for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			char ch=getchar();
			while(ch!='.' && ch!='#') ch=getchar();
			a[i][j]=b[i][j]=ch;
		}
	for(int i=1;i<=n;i++){
		a[i][1]='#',b[i][m]='#';
		if(i&1)
			for(int j=2;j<=m-1;j++) a[i][j]='#';
		else
			for(int j=2;j<=m-1;j++) b[i][j]='#';
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++) putchar(a[i][j]);
		puts("");
	}
	puts("");
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++) putchar(b[i][j]);
		puts("");
	}
	return 0; 
}

Measured memory_bytes: 1280
import sys
while 1:
	H,W=map(int,raw_input().split())
	if H==0 and W==0:
		break;
	else:
		for h in range(H):
			for w in range(W):
				if (h + w) % 2 :
					sys.stdout.write('.')
				else:
					sys.stdout.write('#')

			sys.stdout.write('\n')
	sys.stdout.write('\n')

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

int main(){
  string S;
  cin >> S;
  int x, y;
  cin >> x >> y;
  vector<int> X(0);
  vector<int> Y(0);
  int T = 0;
  int F = 0;
  for(int i=0; i<S.size(); i++){
    if(S.at(i) == 'F'){
      F++;
    }
    else{
      if(T %2 == 0){
        X.push_back(F);
      }
      else{
        Y.push_back(F);
      }
      F = 0;
      T++;
    }
  }
  if(T %2 == 0){
    X.push_back(F);
  }
  else{
    Y.push_back(F);
  }
  
  const int S_MAX = 8000*2 + 10;
  const int ZERO = 8000;
  
  bool dpx[X.size()][S_MAX];
  bool dpy[Y.size()][S_MAX];
  
  for(int i=0; i<X.size(); i++){
    for(int j=0; j<S_MAX; j++){
      dpx[i][j] = false;
    }
  }
  for(int i=0; i<Y.size(); i++){
    for(int j=0; j<S_MAX; j++){
      dpy[i][j] = false;
    }
  }
  dpx[X.size()-1][ZERO] = true;
  dpy[Y.size()-1][ZERO] = true;
  
  for(int i=0; i<X.size(); i++){
    if(i == 0){
      dpx[i][X.at(i) + ZERO] = true;
      if(S.at(i) != 'F'){
        dpx[i][X.at(i)*-1 + ZERO] = true;
      }
    }
    else{
      for(int j=0; j<S_MAX; j++){
        if(dpx[i-1][j]){
          dpx[i][j + X.at(i)] = true;
          dpx[i][j - X.at(i)] = true;
        }
      }
    }
  }
  for(int i=0; i<Y.size(); i++){
    if(i == 0){
      dpy[i][Y.at(i) + ZERO]= true;
      dpy[i][Y.at(i)*-1 + ZERO]= true;
    }
    else{
      for(int j=0; j<S_MAX; j++){
        if(dpy[i-1][j]){
          dpy[i][j + Y.at(i)] = true;
          dpy[i][j - Y.at(i)] = true;
        }
      }
    }
  }
  
  if(dpx[X.size()-1][x+ZERO] && dpy[Y.size()-1][y+ZERO]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

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

  int sum = 0;
  vi a(n);
  rep(i, 0, n){
    cin >> a[i];
    sum += a[i];
    a[i] *= n;
  }

  int ansi = 0;
  rep(i, 0, n){
    if(abs(a[ansi]-sum) > abs(a[i]-sum)){
      ansi = i;
    }
  }

  cout << ansi << endl;

  return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	string in;
	cin >> in;
	vector<P> p;
	p.push_back(P(0,0));
	for(int i=0;i<in.size();i++){
		if(in[i]==p.back().first){
			p.back().second++;
		}
		else{
			p.push_back(P(in[i],1));
		}
	}
	int ret=0;
	for(int i=0;i+2<p.size();i++){
		if(p[i].first=='J'&&
		   p[i+1].first=='O'&&
		   p[i+2].first=='I'&&
		   p[i].second>=p[i+1].second&&
		   p[i+2].second>=p[i+1].second){
			ret=max(ret,p[i+1].second);
		}
	}
	cout << ret << endl;

}

Measured memory_bytes: 12204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, x, d = 10, sum = 0;
  cin >> N;
  x = N;
  
  while (x > 0) {
  sum += x % d;
  x /= d;
  }
  
  if (N % sum == 0) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int tedad=0;
    map<char,int>charha;
    char x[4];
    cin>>x;
    charha[x[0]]=5;
    for(int i=1;i<4;i++){
        if(charha[x[i]]==5){
            tedad++;
        }
        else{
            charha[x[i]]=5;
        }
    }
    if(tedad==2){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}


Measured memory_bytes: 3556
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

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

bool check_power2(ll x)
{
    if((x & (x-1)) == 0)
      return true;
    return false;
}

ll power(ll x, ll put)
{
  ll sol = 1;
  while(put)
  {
    if(put & 1)
    {
      sol*=x;
    }
    x = x*x;
    put>>=1;
  }
  return sol;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll h;
    cin >> h;

    ll lg = ceil(log2(h));
    if(check_power2(h))
      lg++;
    
    cout << power(2,lg) - 1;
    

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int w;
	cin>>w;
	string s;
	cin>>s;
	int ans=1;
	int n=s.size();
	char q=s[0];
	for(int i=0;i<n;++i)
	{
		if(s[i]!=q)
		{
			ans++;
			q=s[i];
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<long> a(n),b(n),c(n);
    for(int i = 0; i < n; i++)
        cin>>a[i];
    sort(a.begin(),a.end());
    for(int i = 0; i < n; i++)
        cin>>b[i];
    for(int i = 0; i < n; i++)
        cin>>c[i];
    sort(c.begin(),c.end());
    long count=0;
    for(int i = 0; i < n; i++){
        long an=lower_bound(a.begin(),a.end(),b[i])-a.begin();
        long cn=upper_bound(c.begin(),c.end(),b[i])-c.begin();
        cn=n-cn;
        count+=an*cn;
    }
    cout<<count;
}

Measured memory_bytes: 2560
from math import cos, pi, sqrt

a, b, h, m = map(int, input().split())

th = 2 * pi * (h / 12) + (2 * pi / 12) * (m / 60)
tm = 2 * pi * (m / 60)

answer = sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(th - tm))
print(answer)


Measured memory_bytes: 9496