akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
    return x>y;
}
const int N=55;
const int mod=1e9+7;
char A[101],B[101],C[101];
int main()
{
    int a,b,c;
    int la,lb,lc;
    while(cin>>A>>B>>C){
        int tmp;
        la=strlen(A);
        lb=strlen(B);
        lc=strlen(C);
        tmp=1;
        a=b=c=-1;
        while(1){
            if(a==la){
                cout<<"A"<<endl;
                break;
            }
            else if(b==lb){
                cout<<"B"<<endl;
                break;
            }
            else if(c==lc){
                cout<<"C"<<endl;
                break;
            }
            if(tmp==1){
                a++;
                tmp=A[a]-'a'+1;
            }
            else if(tmp==2){
                b++;
                tmp=B[b]-'a'+1;

            }
            else if(tmp==3){
                c++;
                tmp=C[c]-'a'+1;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
// E - Dist Max
#include <bits/stdc++.h>
using namespace std;

int main(){
	int64_t N, x, y, p[2], m[2];
	cin>>N>>x>>y;
	p[0] = p[1] = x + y;
	m[0] = m[1] = x - y;
	while(--N){
		cin>>x>>y;
		tie(p[0], p[1]) = minmax({p[0], p[1], x + y});
		tie(m[0], m[1]) = minmax({m[0], m[1], x - y});
	}
	cout<< max(p[1] - p[0], m[1] - m[0]) <<endl;
}


Measured memory_bytes: 3628
import java.util.*;

public class Main{
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);
        String str = sc.next();

        int mod = (int)1e9+7;
        char arr[] = str.toCharArray();
        int dp[][] = new int[str.length()][13];


        if (arr[0]=='?'){
            for (int i=0; i<10; i++) dp[0][i]=1;
        }else{
            int t = arr[0]-'0';
            dp[0][t]=1;
        }
//        for (int i=0; i<10; i++) dp[0][i]=1;

        for (int i=1; i<str.length(); i++){
            int x = -1;
            if (arr[i]!='?'){
                x = arr[i] - '0';
            }
            for (int j=0; j<10; j++){
                if (x==-1 || x==j){
                    for (int k=0; k<13; k++){
                        int m = (k*10+j)%13;
                        dp[i][m] += dp[i-1][k];
                        dp[i][m] %= mod;
                    }
                }
            }
        }
        System.out.println(dp[str.length()-1][5]);

//        System.out.println(dp[1][0]);

    }

}

Measured memory_bytes: 33280
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;

#define ll long long

#define MOD 1000000007

int main()
{
    int m;
    int d;
    cin >> m >> d;
    int d1;
    int d10;
    int counter = 0;
    for (int i = 1; i < m+1; i++)
    {
        for (int j = 1; j < d+1; j++)
        {
            d10 = j/10;
            d1 = j%10;
            if (d1>=2 && d10>=2 && d1*d10==i)
            {
                counter++;
            }
            
        }
        
    }
    cout << counter << endl;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)2e5 + 5;
const dbl pi = acos(-1);

int n, a[maxn], d[maxn];

int main() {
//	fin("t.in");
	sync;
	cin >> n;
	F(i, 0, n) {
		cin >> a[i];
	}
	clean(d);
	int ans = 0;
	F(i, 0, n) {
		d[a[i]] = d[a[i] - 1] + 1;
		ans = max(ans, d[a[i]]);
	}
	cout << n - ans << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

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

	    int a= gi();
	    int b= gi();

        System.out.print((a+b)%24);
//        if ((a.equals("H") && b.equals("H")) || (a.equals("D") && b.equals("D"))) {
//        	System.out.print("H");
//        }else{
//        	System.out.print("D");
//        }

	   
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

Measured memory_bytes: 35548
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let k: u64 = read();
    let mut a = vec![49 + k / 50 - k % 50; 50];
    for i in 0..(k % 50) as usize {
        a[i] += 51;
    }
    println!("50");
    println!(
        "{}",
        a.iter()
            .map(|&x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}


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

using namespace std;

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;



namespace std {
    bool operator < (const P& a, const P& b) {
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
}
double cross(const P& a, const P& b) {
    return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
    return real(conj(a)*b);
}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

struct L : public vector<P> {
    L(const P &a, const P &b) {
        push_back(a); push_back(b);
    }
};

typedef vector<P> G;

struct C {
    P p; double r;
    C(const P &p, double r) : p(p), r(r) { }
};

vector<P> convex_hull(vector<P> ps) {
    int n = ps.size(), k = 0;
    sort(ps.begin(), ps.end());
    vector<P> ch(2*n);
    for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
        while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
    for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull
        while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
    ch.resize(k-1);
    return ch;
}

int main(){
    int n;
    while(cin >> n, n){
        vector<P> v;
        for(int i=0; i< n; i++){
            double x, y;
            scanf("%lf,%lf", &x, &y);
            P p;
            p.real(x); p.imag(y);
            v.push_back(p);
        }
        vector<P> q =  convex_hull(v);
        cout << n-q.size() << endl;
    }
}

Measured memory_bytes: 1296
import java.util.Scanner;


class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int [] a = new int[6];
		a[0] = scan.nextInt();
		a[1] = scan.nextInt();
		a[2] = scan.nextInt();
		a[3] = scan.nextInt();
		a[4] = scan.nextInt();
		a[5] = scan.nextInt();
		String moji = scan.next();
		int kai = moji.length();
		int i,taihi;
		for(i = 0;i < kai;i++){
			char b = moji.charAt(i);
			if(b == 'N'){
				taihi = a[0];
				a[0] = a[1];
				a[1] = a[5];
				a[5] = a[4];
				a[4] = taihi;
			}else if(b == 'W'){
				taihi = a[0];
				a[0] = a[2];
				a[2] = a[5];
				a[5] = a[3];
				a[3] = taihi;
			}else if(b == 'S'){
				taihi = a[0];
				a[0] = a[4];
				a[4] = a[5];
				a[5] = a[1];
				a[1] = taihi;
			}else if(b == 'E'){
				taihi = a[0];
				a[0] = a[3];
				a[3] = a[5];
				a[5] = a[2];
				a[2] = taihi;
			}
		}
		System.out.println(a[0]);
		scan.close();
	}
}



Measured memory_bytes: 26140
import numpy as np
N = int(input())

def Num_Each_Digit(N,limit):
    ans = np.array([])
    
    if N < 10**(limit):
        for i in range(1,limit+1):
            if (10**(i-1) > N):
                break
            if i == 1:
                ans = np.append( ans, (N%(10**i)))
            elif i > 1:
                ans = np.append( ans, (N%(10**i)-N%(10**(i-1)))/(10**(i-1)))

        return ans
                
    else:
        print("too large")
        return N
    
digit = Num_Each_Digit(N,10)
    
if N == 10**(len(digit)-1):
    print(10)
    
else:
    print(int(np.sum(digit)))


Measured memory_bytes: 12740
import java.util.*;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int K = Integer.parseInt(sc.next());
        sc.close();
        final int A[] = { 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 };

        System.out.println(A[K - 1]);
    }
}

Measured memory_bytes: 21972
/**
 * author: dhakad_123
**/

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


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >>s;
    
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" <<"\n";
    }
    else {
        cout<<"No" <<"\n";
    }
    return 0;
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

puts yn_judge(get_nsp.include?("9"))

Measured memory_bytes: 1788
# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(10000000)

#const
dxdy=((1,0),(0,1))
# my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())
    

#絶対TLEする！A問題のpython回答はこちら！！！！

def sx(h,w,ans=0):#depth-first? search functionを障害物を消しながら行う
    from collections import deque as DQ
    q=DQ()
    q.append((h,w,ans,0))
    
    flag=0
    while (len(q) >0):
        temp=q.popleft()
        s,t,z,flag=temp
        
        if s>=H or t>=W:continue
        #print(maze[s][t])
        if maze[s][t]=="#":
            z+=1-flag
            flag=1
        elif maze[s][t]==".":
            flag=0
        #print((s,t,z))            
        if z<dp[s][t]:
            dp[s][t]=z
            for d in dxdy:
                q.append((s+d[0],t+d[1],z,flag))

def resolve():
    
    global anss ,dp,H,W,maze
    global res
    res=0
    H,W=pin()
    dp=[[(H+W)]*W for _ in range(H)]
    
    maze=tuple(tuple(input())for i in range(H))
    sx(0,0)
    #print(min(anss),len(anss),res)
    print(dp[H-1][W-1])
    

"""         
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 3
.##
.#.
##."""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2 2
#.
.#"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """4 4
..##
#...
###.
###."""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """5 5
.#.#.
#.#.#
.#.#.
#.#.#
.#.#."""
        output = """4"""
        self.assertIO(input, output)
if __name__=="__main__":resolve()



Measured memory_bytes: 68696
import java.util.*;

 class Main
 {
   public static void main(String args[])
   { 
    Scanner sc = new Scanner(System.in);
    
    int v = sc.nextInt();//Vertical
    
    int h = sc.nextInt();//horizontal
    
    int a = v * h ;//area
    
    int l = 2 * ( v + h );//Lap
    
    System.out.println(a + " " + l);
   }
   
 }



Measured memory_bytes: 26136
#include <iostream>

using namespace std;

int main(){
  string s;
  cin >> s;
  int num[4];
  num[0]=stoi(s.substr(0,1));
  num[1]=stoi(s.substr(1,1));
  num[2]=stoi(s.substr(2,1));
  num[3]=stoi(s.substr(3,1));

  string hugo[3];

  int ans=0;

  for (int bit = 0; bit < (1<<3); bit++) {
    ans=num[0];
    for (int i = 0; i < 3; i++) {
      if (bit & (1<<i)) {
        ans+=num[3-i];
        hugo[2-i]="+";
      }else{
        ans-=num[3-i];
        hugo[2-i]="-";
      }
    }
    if (ans==7) {
      cout << num[0];
      for (int i = 1; i <=3; i++) {
        cout << hugo[i-1] << num[i];
      }
      cout << "=7" << endl;
      return 0;
    }

  }
  return 0;

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
    private void solve() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<Integer>[] adjList = new ArrayList[n];
        int[] a = new int[m];
        int[] b = new int[m];
        for (int i = 0; i < n; i++) {
            adjList[i] = new ArrayList<>();
        }
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
            adjList[a[i]].add(b[i]);
            adjList[b[i]].add(a[i]);
        }
 
        int q = sc.nextInt();
        int[] v = new int[q];
        int[] d = new int[q];
        int[] c = new int[q];
        for (int i = 0; i < q; i++) {
            v[i] = sc.nextInt() - 1;
            d[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }
 
        boolean[][] visited = new boolean[n][11];
        int[] color = new int[n];
        Arrays.fill(color, -1);
        for (int i = q - 1; i >= 0; i--) {
            dfs(adjList, visited, color, v[i], d[i], c[i]);
        }
        for (int clr : color) {
            System.out.println(clr == -1 ? 0 : clr);
        }
    }
 
    private void dfs(ArrayList<Integer>[] adjList, boolean[][] visited, int[] color, int v, int d, int c) {
        if (visited[v][d]) {
            return;
        }
        if (color[v] == -1 && d == 0) {
            color[v] = c;
        } else {
            dfs(adjList, visited, color, v, d - 1, c);
            for (int adj : adjList[v]) {
                dfs(adjList, visited, color, adj, d - 1, c);
            }
        }
        visited[v][d] = true;
    }
 
    public static void main(String[] args) {
        // new B_SplatterPainting().solve();
        new Main().solve();
    }
}

Measured memory_bytes: 172096
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
int n,now;
ll ans=0;
int a[200010];
int main(){
	scanf("%d",&n);
	int i,j;
	for(i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	if(a[1]!=0){
		printf("-1\n");return 0;
	}
	now=0;
	for(i=n;i>=1;--i){
		if(a[i]<now){
			printf("-1\n");return 0;
		}
		if(a[i]>now){
			now=a[i];ans=ans+(ll)a[i];
		}
		now--;now=max(now,0);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll x[N], y[N];
    REP(i, 0, N) {
        cin >> x[i] >> y[i];
    }
    ll maxsort[N], minsort[N];
    REP(i, 0, N) {
        if (x[i] >= y[i]) {
            maxsort[i] = x[i];
            minsort[i] = y[i];
        } else {
            maxsort[i] = y[i];
            minsort[i] = x[i];
        }
    }
    sort(maxsort, maxsort + N);
    sort(minsort, minsort + N);
    ll ans = (maxsort[N - 1] - maxsort[0]) * (minsort[N - 1] - minsort[0]);
    ll usedmark[N];
    fill(usedmark, usedmark + N, 0);
    ll tmp = 0;
    plglg balls[2 * N];
    REP(i, 0, N) {
        balls[i * 2] = plglg(x[i], i);
        balls[i * 2 + 1] = plglg(y[i], i);
    }
    sort(balls, balls + 2 * N);
    ll minnum = 0;
    ll ite = -1;
    while(tmp < N) {
        ite++;
        plglg ball = balls[ite];
        ll ind = ball.second;
        if (usedmark[ind] == 0) {
            tmp++;
        }
        usedmark[ind]++;
    }
    ll widedis = balls[2 * N - 1].first - balls[0].first;
    ll mindis = balls[ite].first - balls[minnum].first;
    while(1) {
        while(tmp == N) {
            mindis = min(mindis, balls[ite].first - balls[minnum].first);
            plglg popball = balls[minnum];
            ll ind = popball.second;
            usedmark[ind]--;
            if (usedmark[ind] == 0) {
                tmp--;
            }
            minnum++;
        }
        while(tmp < N && ite < 2 * N - 1) {
            ite++;
            plglg ball = balls[ite];
            ll ind = ball.second;
            if (usedmark[ind] == 0) {
                tmp++;
            }
            usedmark[ind]++;
        }
        if (ite == 2 * N - 1) {
            break;
        }
    }
    ll ansb = widedis * mindis;
    cout << min(ans, ansb) << endl;
}


Measured memory_bytes: 14336
n=int(input())
if len(str(n))%2==0:
  print((10**len(str(n))-1)//11)
else:print(n-10**(len(str(n))-1)+1+((10**(len(str(n))-1)-1)//11)) if len(str(n))!=1 else print(n)

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

#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 INF 1e9


int main(){ 
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;
  REP(i, N){
    cout << S[i] << T[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }

void main() {
  int N, M; readf("%d %d\n", &N, &M);

  void solve() {
    string answer;
    if (N == M) {
      foreach(i; 0..N) answer ~= '0' + N;
    } else if(N > M) {
      foreach(i; 0..N) answer ~= '0' + M;
    } else {
      foreach(i; 0..M) answer ~= '0' + N;
    }

    writeln(answer);
  }

  solve();
}


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

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 100005
#define maxK 305
#define MOD 1000
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, m, k, a[maxN];
ll dp[maxK][maxN];

int main () {
    scanf("%d%d%d", &n, &m, &k);
    fto(i, 1, n) scanf("%d", &a[i]);

    dp[1][0] = -oo;
    fto(j, 1, n) dp[1][j] = a[j];
    fto(i, 2, k) {
        dp[i][0] = -oo;
        deque<int> q;

        fto(j, 1, n) {
            while (!q.empty() && dp[i-1][q.back()] <= dp[i-1][j-1]) q.pop_back();
            q.push_back(j-1);
            while (q.front() < j-m) q.pop_front();
            dp[i][j] = dp[i-1][q.front()] + 1LL*a[j]*i;
        }
    }

    ll ans = *max_element(dp[k], dp[k]+n+1);
    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 235392
def main():
    input()  # n
    array = [int(x) for x in input().split()]
    mod = 10 ** 9 + 7
    total = 0
    center_blocks = 0
    for x in array:
        total += x
        center_blocks += x ** 2
    total = total ** 2
    return (total - center_blocks) // 2 % mod


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 31716
#include <bits/stdc++.h>
#define long long long

using namespace std;

const int N = 2e5+5;

int n;
vector<int> vl, vr;
long ans;

int main() {
    scanf("%d", &n);
    for(int i = 1, t; i <= n; i++) {
        scanf("%d", &t);
        vl.emplace_back(i + t);
        vr.emplace_back(i - t);
    }
    sort(vl.begin(), vl.end());
    sort(vr.begin(), vr.end());
    for(int i = 0; i < n; i++) {
        int cr = lower_bound(vr.begin(), vr.end(), vl[i]) - vr.begin();
        int cru = upper_bound(vr.begin(), vr.end(), vl[i]) - vr.begin();
    //    printf("%d ", cr);
        if(vr[cr] == vl[i]) {
            ans += (cru - cr);
        }
        
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 5120
from sys import stdin
import numpy as np


# noinspection PyShadowingBuiltinsInspection

def main():
    a, b, k = [int(x) for x in input().split()]
    if a >= k:
        print(a-k, b)
    elif a + b >= k:
        print(0, a + b - k)
    else:
        print(0,0)
    return


if __name__ == "__main__":
    main()

Measured memory_bytes: 22016
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

int main(){
  int n,b,sa,sb;
  cin >> n;
  vector<int> a;
  REP(i,n){
    cin >> b;
    a.push_back(b);
  }
  SORT(a);
  sa = sb = 0;
  REP(i,n){
    if (i%2==n%2) {
      sa += a[i];
    } else {
      sb += a[i];
    }
  }
  cout << sb - sa;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

R = [0] * N
G = [0] * N
B = [0] * N

for i in range(N):
    if S[i] == "R":
        R[i] += 1
    elif S[i] == "G":
        G[i] += 1
    else:
        B[i] += 1

from itertools import accumulate

R = [0] + list(accumulate(R))
G = [0] +list(accumulate(G))
B = [0] + list(accumulate(B))

ans = 0
for i in range(N):
    for j in range(i + 1, N - 1):
        if S[i] == S[j]: continue
        tmp = set(["R","G","B"])
        tmp.remove(S[i])
        tmp.remove(S[j])
        Sk = tmp.pop()
        no = j + (j - i)
        if Sk == "R":
            ans += R[min(N, no)] - R[j] + R[N] - R[min(N, no + 1)]
        elif Sk == "G":
            ans += G[min(N, no)] - G[j] + G[N] - G[min(N, no + 1)]
        else:
            ans += B[min(N, no)] - B[j] + B[N] - B[min(N, no + 1)]

print(ans)

Measured memory_bytes: 74796
#include <stdio.h>

int main(void){
  int i, j;
  char a[10000] = { 0 };
  int digit;

  for(i=0;scanf("%c",&a[i])==1;i++){}
  digit=i;

  for(i=0;i<digit;i++){
    if( 'A' <= a[i] && a[i] <= 'Z' ) 
      a[i]+='a'-'A';
    else if( 'a' <= a[i] && a[i] <= 'z' )
      a[i]-='a'-'A';
  }

  printf("%s",a);

  return 0;
}

Measured memory_bytes: 0
parseInt(x) = parse(Int, x);
parseMap(x::Array{SubString{String},1}) = map(parseInt, x);

N_MAX = 2 * 10^5;
fac = Array{Int}(N_MAX+1);
inv = Array{Int}(N_MAX+1);
MOD = 10^9 + 7;
#初期化
function COMINIT();fac[1] = 1;for i in 1:N_MAX-1;fac[i+1] = fac[i] * (i+1) % MOD;end;for i in 1:N_MAX;inv[i] = powermod(fac[i], MOD-2, MOD);end;end;
#nCk
function Comb(n, k);if n <= 0 || k < 0;return 0;end;if k > n;return 0;end;if k == 0 || n == k;return 1;end;return ((fac[n] * inv[k]) % MOD * inv[n-k])%MOD;end;
function H(n, m);return Comb(n + m, m);end;
function main();COMINIT();n,k = parseInt.(split(readline()));m = min(k, n-1);ans = 0;for i in 0:m;ans += (Comb(n,i) * H(n-1-i,i)) % MOD;ans %= MOD;end;println(ans);end;
main();



Measured memory_bytes: 156824
N=int(input())
C=input()
l=0
r=N-1
ans=0
while l<r:
    while l<r and C[l]=="R":
        l+=1
    while l<r and C[r]=="W":
        r-=1
    if l>=r:
        break
    l+=1
    r-=1
    ans+=1
print(ans)

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

struct Unionfind{
  vector<long> par,par2;
  map<pair<int,int>,int> res;

  Unionfind(long n): par(n),par2(n){
    rep(i,n){
      par[i] = i;
      par2[i] = i;
    }
  }

  int root(int x){
    if(par[x] == x)return x;
    else return par[x] = root(par[x]);
  }
  int root2(int x){
    if(par2[x] == x)return x;
    else return par2[x] = root2(par2[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx != ry){
      par[ry] = rx;
    }
  }
  void unite2(int x, int y){
    int rx = root2(x);
    int ry = root2(y);
    if(rx != ry){
      par2[ry] = rx;
    }
  }

  void ans(int n){
    rep(i,n){
      int r1 = root(i);
      int r2 = root2(i);
      res[{r1,r2}]++;
    }
    rep(i,n){
      cout << res[{root(i),root2(i)}] << " ";
    }
  }

};

int main(){
  long n,k,l;
  cin >> n >> k >> l;
  Unionfind tree(n);
  rep(i,k){
    long p,q;
    cin >> p >> q;
    p--;q--;
    tree.unite(p,q);
  }
  rep(i,l){
    long r,s;
    cin >> r >> s;
    r--;s--;
    tree.unite2(r,s);
  }
  tree.ans(n);
  return 0;
}

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

int num[100050];
int main(){
	int n, headache = 0;
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> num[i];
	}
	int c = 0;
	for(int i=1;i<=n;i++){
		if(i!=n and num[i]==i)swap(num[i],num[i+1]),c++;
		else if(num[i]==i)swap(num[i],num[i-1]),c++;
	}
	cout << c << endl;
	
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int a[100];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int best = (int) 1e9;
  for (int all = -100; all <= 100; ++all) {
    int total = 0;
    for (int i = 0; i < n; ++i) {
      total += (a[i] - all) * (a[i] - all);
    }
    best = min(best, total);
  }
  cout << best << '\n';
  return 0;
}

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

int n, dd[101], f[101], tmap[101][101];
int color[101], t = 1;
stack<int> S;

int a(){
	int d = S.top();
	dd[d] = t;
	t++;
	color[d] = 1;
	for (int i = 1; i <= n; i++){
		if (color[i] == 0 && tmap[d][i] == 1){
			S.push(i);
			a();
		}
	}
	
	f[d] = t;
	t++;
	return 0;
}


int main(){
	cin >> n;
	for (int i = 0; i < 100; i++){
		dd[i] = f[i] = color[i] = 0;
		for (int j = 0; j < 100; j++){
			tmap[i][j] = 0;
		}
	}

	int u, k, v;

	for (int i = 0; i < n; i++){
		cin >> u >> k;
		for (int j = 0; j < k; j++){
			cin >> v;
			tmap[u][v] = 1;
		}
	}
	for (int i = 1; i <= n; i++){
		if (color[i] == 0){
			S.push(i);
			a();
		}
	}
	for (int i = 1; i <= n; i++){
		cout << i << " " << dd[i] << " " << f[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1244
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] input1 = Console.ReadLine().Split(' ');
        int M1 = int.Parse(input1[0]);
        int D1 = int.Parse(input1[1]);
        string[] input2 = Console.ReadLine().Split(' ');
        int M2 = int.Parse(input2[0]);
        int D2 = int.Parse(input2[1]);

        if((D1 == 30 && D2 == 1) || (D1 == 31 && D2 == 1) || (D1 == 28 && D2 == 1))
            Console.WriteLine("1");
        else
            Console.WriteLine("0");
    }
}


Measured memory_bytes: 13140
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

class BIT{
public:
    int *p;
    int num;
    BIT(int arg){
        p = new int[arg+1];
        for(int i=0;i<arg+1;i++) p[i] = 0;
        num = arg;
    }
    
    //return sum of p[1] ... p[arg]
    int sum(int arg){
        int ret=0;
        while(arg > 0){
            ret += p[arg];
            arg -= arg & -arg;
        }
        return ret;
    }

    //add value to index-th node
    void add(int index, int value){
        while(index <= num){
            p[index] += value;
            index += index & -index;
        }
    }
};

int main(){
    std::ios::sync_with_stdio(false);
    BIT *bit[26];
    int n, q, t;
    char l, r;
    string s;
    cin >> n >> s >> q;
    for(int i=0;i<26;++i)
    {
        bit[i] = new BIT(n);
    }

    for(int i=0;i<s.length();++i)
    {
        char c = s[i] - 'a';
        bit[c]->add(i+1, 1);
    }

    for(int i=0;i<q;++i)
    {
        cin >> t;
        if(t == 1)
        {
            int ind;
            char c, before, after;
            cin >> ind >> c;
            if(s[ind-1] == c) continue;
            bit[s[ind-1] - 'a']->add(ind, -1);
            bit[c - 'a']->add(ind, 1);            
            s[ind-1] = c;
        }
        else
        {
            int l, r;
            cin >> l >> r;
            int count = 0;
            for(int i=0;i<26;++i)
            {
                if(bit[i]->sum(r) - bit[i]->sum(l-1) > 0)
                {

                    count++;
                }
            }
            cout << count << endl;
        }
        
    }
}

Measured memory_bytes: 51740
package main

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

const (
	defaultBufferSize = 1024
	maxBufferSize     = 1e6
	Mod               = 1e9 + 7
)

var sc = bufio.NewScanner(os.Stdin)

// sc.Buffer(make([]byte, defaultBufferSize), maxBufferSize)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func primeFactorization(x int) map[int]int {
	result := make(map[int]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			result[i]++
			x /= i
		}
	}
	if x != 1 {
		result[x]++
	}
	return result
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	for i := 2; i*i <= x; i++ {
		if i == x {
			continue
		}
		if x%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := readInt(), readInt()

	ans := -201
	ans = max(ans, a+b)
	ans = max(ans, a-b)
	ans = max(ans, a*b)
	fmt.Println(ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int MAXN = 800005;
const LL MOD = 924844033;
const LL Gi = 5, Ginv = 554906420;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

int n, siz[MAXN], cnt[MAXN], rev[MAXN];
LL fac[MAXN], inv[MAXN], finv[MAXN], F[MAXN], G[MAXN];

struct Edge {
	int v, nxt;
}e[MAXN];
int first[MAXN], eCnt;

inline void AddEdge(int u, int v) {
	e[++eCnt].v = v;
	e[eCnt].nxt = first[u];
	first[u] = eCnt;
}

void DFS(int u, int fa) {
	siz[u] = 1;
	for (int i=first[u];i;i=e[i].nxt) {
		int v = e[i].v;
		if (v == fa) continue;
		DFS(v, u);
		siz[u] += siz[v];
	}
}

inline LL ksm(LL x, LL k) {
    LL ret = 1;
    while (k) {
        if (k & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        k >>= 1;
    }
    return ret;
}

inline void NTT_init(int &len, int m) {
    int bit = -1;
    for(len=1;len<m;len<<=1) ++bit;
    for (int i=0;i<len;++i) {
        rev[i] = (rev[i>>1]>>1) | ((i&1)<<bit);
    }
}

void NTT(LL *a, int len, int type) {
    for (int i=0;i<len;++i) {
        if (i < rev[i]) {
            swap(a[i], a[rev[i]]);
        }
    }
    for (int i=1;i<len;i<<=1) {
        int p = (i<<1);
        LL wn = ksm((type==1)? Gi : Ginv, (MOD-1)/p);
        for (int j=0;j<len;j+=p) {
            LL wnk = 1;
            for (int k=0;k<i;++k) {
                LL x = a[j+k], y = wnk * a[j+k+i] % MOD;
                a[j+k] = (x + y) % MOD;
                a[j+k+i] = (x - y + MOD) % MOD;
                wnk = wnk * wn % MOD;
            }
        }
    }
    if (type == 1) return;
    LL Ninv = ksm(len, MOD-2);
    for (int i=0;i<len;++i) {
        a[i] = a[i] * Ninv % MOD;
    }
}

void init() {
	read(n);
	for (int i=1,u,v;i<n;++i) {
		read(u); read(v);
		AddEdge(u, v);
		AddEdge(v, u);
	}
	fac[0] = fac[1] = inv[0] = inv[1] = finv[0] = finv[1] = 1;
	for (int i=2;i<=n;++i) {
		fac[i] = fac[i-1] * i % MOD;
		inv[i] = (MOD-MOD/i) * inv[MOD%i] % MOD;
		finv[i] = finv[i-1] * inv[i] % MOD;
	}
}

void solve() {
	DFS(1, 0);
	for (int i=2;i<=n;++i) {
		++cnt[siz[i]];
		++cnt[n-siz[i]];
	}
	cnt[n] -= n;
	for (int i=0;i<=n;++i) {
		F[n-i] = fac[i] * (MOD-cnt[i]) % MOD;
		G[i] = finv[i];
	}
	int len; NTT_init(len, (n+1)<<1);
	NTT(F, len, 1); NTT(G, len, 1);
	for (int i=0;i<len;++i) {
		F[i] = F[i] * G[i] % MOD;
	}
	NTT(F, len, -1);
	for (int i=1;i<=n;++i) {
		printf("%lld\n", F[n-i] * finv[i] % MOD);
	}
}

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


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

int main()
{
	int x = 1, y = 1;
	while (x != 0 || y != 0) {
		int a, b;
		cin >> x >> y;
		if (x != 0 || y != 0) {
			if (x < y) {
				a = x, b = y;
			}
			else if (x >= y) {
				a = y, b = x;
			}
			cout << a << " " << b << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3000
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef long long llint;
typedef vector<long long int> vint;
typedef vector< vector<int> > vvint;
typedef vector<string> vstr;


int main(void) {
	string S;
	int a, b;
	cin>>S;
	a = (S[0]-'0') * 10 + (S[1]-'0');
	b = (S[2]-'0') * 10 + (S[3]-'0');
	if (a <= 12 && b <= 12&&a>0&&b>0)cout << "AMBIGUOUS" << endl;
	else if (a <= 12&&a>0)cout << "MMYY" << endl;
	else if (b <= 12&&b>0)cout << "YYMM" << endl;
	else cout << "NA" << endl;
		
}


Measured memory_bytes: 256
h,w,a,b=map(int,input().split())
n_func=[None for _ in [0]*200001]
n_func[0]=1
for i in range(1,200001):
    n_func[i]=(i*n_func[i-1])%(10**9+7)
def inv_n(n,mod=10**9+7):return pow(n,mod-2,mod)
def nCr(n,r,mod=10**9+7):return inv_n(n_func[n-r]*n_func[r]%mod,mod)*n_func[n]%mod

cnt=0
for i in range(h-a):
    cnt=(cnt+nCr(i+b-1,b-1)*nCr(h+w-b-i-2,w-b-1))%(10**9+7)
print(cnt)

Measured memory_bytes: 13052
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cassert>
using namespace std;

int H, N;

using Layer = vector<string>;
using Tower = vector<Layer>;

Tower t;
vector<Tower> blocks;

int erase(Tower &t) {
    int res = 0;
    for (auto &l : t) {
        if (l[0] == "##" && l[1] == "##") {
            l.clear();
            ++res;
        }
    }
    t.erase(remove(t.begin(), t.end(), Layer()), t.end());
    return res;
}

Tower shift(Tower t, int di, int dj) {
    Tower res(2, Layer(2, ".."));
    for (int l = 0; l < 2; ++l) {
        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < 2; ++j) {
                if (t[l][i][j] == '#') {
                    if (0 <= i - di && i - di < 2 && 0 <= j - dj && j - dj < 2) {
                        res[l][i - di][j - dj] = t[l][i][j];
                    } else {
                        return {};
                    }
                }
            }
        }
    }
    return res;
}

bool hit(const Tower &t, int p, const Tower &b) {
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                if (t[i + p][j][k] == '#' && b[i][j][k] == '#') {
                    return true;
                }
            }
        }
    }
    return false;
}

Tower put(Tower t, const Tower &b) {
    Tower res = t;
    int p = t.size() - 3;
    while (p >= 0 && !hit(t, p, b)) {
        --p;
    }
    ++p;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                if (b[i][j][k] == '#') {
                    assert(t[i + p][j][k] != '#');
                    res[i + p][j][k] = '#';
                }
            }
        }
    }
    return res;
}

int rec(int p, Tower t) {
    if (p == N) {
        return 0;
    }
    const Tower &b = blocks[p];
    int res = 0;
    for (int di = -1; di <= 1; ++di) {
        for (int dj = -1; dj <= 1; ++dj) {
            Tower nb = shift(b, di, dj);
            if (nb.size()) {
                Tower nt = put(t, nb);
                int score = erase(nt);
                score += rec(p + 1, nt);
                res = max(res, score);
            }
        }
    }
    return res;
}

int main() {
    while (cin >> H >> N && H) {
        t = Tower(H + 10, Layer(2, ".."));
        for (int i = 0; i < H; ++i) {
            cin >> t[i][0] >> t[i][1];
        }
        blocks = vector<Tower>(N, Tower(2, Layer(2)));
        for (int i = 0; i < N; ++i) {
            cin >> blocks[i][0][0] >> blocks[i][0][1] 
                >> blocks[i][1][0] >> blocks[i][1][1];
            if (blocks[i][0][0] == ".." && blocks[i][0][1] == "..") {
                swap(blocks[i][0], blocks[i][1]);
            }
        }
        cout << rec(0, t) << endl;
    }
}

Measured memory_bytes: 3180
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define ll long long

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

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


int gcd(int a, int b){
  int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

int upll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;
}

int downll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;
}

void sortup(ll*a,int n){
  qsort(a,n,sizeof(ll),upll);
}

void sortdown(ll*a,int n){
  qsort(a,n,sizeof(ll),downll);
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int MOD=1e9+7;

  long int s;
  scanf("%ld",&s);

  long int ans=0;

  long int kai[2000000];
  long int rekai[2000000];
  
  kai[0]=1;
  kai[1]=1;
  for(int i=2;i<2000000;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=MOD;
  }

  
  rekai[0]=1;
  rekai[1]=1;
  for(int i=2;i<2000000;i++){
    rekai[i]=rekai[i-1]*modinv(i,MOD);
    rekai[i]%=MOD;
  }

  //[1,s/3]Aの要素の個数の全探索
  for(long int i=1;i<=s/3;i++){
    long int a=i;
    long int b=s-3*i;

    long int now=kai[a+b-1];

    now*=rekai[a-1];
    now%=MOD;

    now*=rekai[b];
    now%=MOD;

    ans+=now;
    ans%=MOD;
  }

  printf("%ld\n",ans);

  return 0;
}

Measured memory_bytes: 32984
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a=new int[4];
		int[] b=new int[4];
		while(sc.hasNextInt()){
			for(int i=0; i<4; i++){
				a[i]=sc.nextInt();
			}
			for(int j=0; j<4; j++){
				b[j]=sc.nextInt();
			}
			System.out.println(hit(a,b)+" "+blow(a,b));

		}

	}
	public static int hit(int[] a,int[] b){
		int count=0;
		for(int i=0; i<a.length; i++){
			if(a[i]==b[i]){
				count++;
			}
		}
		return count;
	}

	public static int blow(int[] a,int[] b){
		int count=0;
		for(int i=0; i<a.length; i++){
			for(int j=0; j<b.length; j++){
				if(a[i]==b[j] && i!=j){
					count++;
				}

			}
		}
		return count;
	}
}

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

int main()
{
  string S,result;
  int K;
  cin >> K >> S;

  if(S.size()>K){
    result = S.substr(0,K) + "...";
  }else{ 
    result = S;
  }

  cout << result << endl;
}

Measured memory_bytes: 3636
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    let mut n: usize = read();
    let k: usize = read();
    let mut ans = 0;
    while n > 0 {
        ans += 1;
        n /= k;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352