akhauriyash/Code-Regression huggingface dataset:
s=input()
flag1,flag2,flag3=False,False,True
import string
for i,moji in enumerate(s):
    if i==0 and moji=="A":
        flag1=True
    elif 2<=i<=len(s)-2 and moji=="C" and flag2==False:
        flag2=True
    else:
        if moji in string.ascii_uppercase:
            flag3=False
            break
if flag1 and flag2 and flag3:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 38640
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val k = sc.nextInt()
    val p = Array(n) { sc.nextInt() - 1 }
    val c = Array(n) { sc.nextLong() }
    var ans = Long.MIN_VALUE
    for (i in 0 until n) {
        val lst = mutableListOf(c[i])
        var x = p[i]
        while (x != i) {
            lst.add(c[x])
            x = p[x]
        }
        val l = lst.count()
        val sum = lst.sum()
        val r = (k - 1) % l + 1
        var max = -Long.MAX_VALUE
        var max2 = -Long.MAX_VALUE
        var sum2 = 0L
        for (j in 0 until minOf(k, l)) {
            sum2 += lst[j]
            max = maxOf(max, sum2)
        }
        sum2 = 0L
        for (j in 0 until r) {
            sum2 += lst[j]
            max2 = maxOf(max2, sum2)
        }
        if (sum > 0 && k >= l) {
            max = maxOf(max, 0)
        }
        var v: Long
        if (sum > 0) {
            v = sum * ((k - 1) / l) + max2
        } else if (k <= l) {
            v = max2
        } else {
            v = maxOf(max, max2)
        }
        ans = maxOf(ans, v)
    }
    println(ans)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 56672
#include <iostream>
#include <climits>

using namespace std;
int main (){
    int n,x;
    cin >> n >> x;
    int m[n];
    int min=INT_MAX;
    for (int i = 0; i < n; i++){
        cin >> m[i];
        x-=m[i];
        if(min > m[i]) min=m[i];
    }
    cout << n+(x/min) << "\n";
}

Measured memory_bytes: 256
def calc(nums, pattern)
  n = nums.dup
  ret = n.dup.map(&:to_s)

  case pattern[0]
  when '+' then
    n[1] += n[0]
  when '-' then
    n[1] = n[0] - n[1]
  end

  case pattern[1]
  when '+' then
    n[2] += n[1]
  when '-' then
    n[2] = n[1] - n[2]
  end

  case pattern[2]
  when '+' then
    n[3] += n[2]
  when '-' then
    n[3] = n[2] - n[3]
  end

  if n[3] == 7
    ret[0] + pattern[0] + ret[1] + pattern[1] + ret[2] + pattern[2] + ret[3] + '=7'
  else
    nil
  end
end

n = gets.chars.map(&:to_i)

patterns = [
  ['+', '+', '+'],
  ['+', '+', '-'],
  ['+', '-', '+'],
  ['+', '-', '-'],
  ['-', '+', '+'],
  ['-', '+', '-'],
  ['-', '-', '+'],
  ['-', '-', '-']
]

patterns.each do |p|
  ans = calc(n, p)
  if !ans.nil?
    puts ans
    break
  end
end

Measured memory_bytes: 1788
import math

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

aaa = h * 30 + m * 0.5
bbb = m * 6
ccc = aaa - bbb

if ccc < -180:
	ccc += 360
elif ccc > 180:
	ccc = 360 - ccc
else:
	ccc = abs(ccc)
	
ddd = ccc * math.pi / 180
eee = a ** 2 + b ** 2 - 2 * a * b * math.cos(ddd)

print(eee ** (1/2))

Measured memory_bytes: 9536
s = input()

c_exists = False
f_exists = False
for c in s:
    if c == 'C' and not c_exists:
        c_exists = True
    if c_exists and c == 'F' and not f_exists:
        f_exists = True

if c_exists and f_exists:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <bitset>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

const int MAXN = 300005;

int n;
int a[MAXN];

bool check(int l,int r)
{
	for (int i = l;i <= r;i += 2)
		if (a[i] == i)
			return 0;
	int lst = 0;
	for (int i = l;i <= r;i += 2)
		if (a[i] < i)
		{
			if (a[i] < lst)
				return 0;
			lst = a[i];
		}
	lst = n + 1;
	for (int i = r;i >= l;i -= 2)
		if (a[i] > i)
		{
			if (a[i] > lst)
				return 0;
			lst = a[i];
		}
	return 1;
}

int main()
{
	scanf("%d",&n);
	for (int i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	int MAX = 0,lst = 0;
	bool ok[2] = {1,1};
	for (int i = 1;i <= n;i++)
	{
		MAX = max(MAX,a[i]);
		ok[i & 1] &= (a[i] == i);
		if (MAX == i)
		{
			ok[0] &= check(lst + 1 + (lst & 1),i - (~i & 1));
			ok[1] &= check(lst + 1 + (~lst & 1),i - (i & 1));
			if (!ok[0] && !ok[1])
			{
				puts("No");
				return 0;
			}
			ok[0] = ok[1] = 1;
			lst = i;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1408
def check(D, x, y):
    if (((x**2)+(y**2))**0.5) <= D:
        return True

    return False

def main():
    [N, D] = [int(x) for x in input().split()]
    ans = 0

    for i in range(N):
        [x,y] = [int(x) for x in input().split()]
        if check(D, x, y):
            ans += 1
    print(ans)


main()


Measured memory_bytes: 70348
K, N = input().split(' ')
K = int(K)
N = int(N)
A = []
A = input().split(' ')
A = [int(A[i]) for i in range(N)]
D = []
for i in range(N-1):
  D.append(int(A[i+1]-A[i]))
LAST = A[0] + K - A[-1]
D.append(LAST)
print(K - max(D))

Measured memory_bytes: 31520
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){

	int n;
	char *strwrt;
	char *strorg;
	char *p,*q;
	char str[101];
	int m;		// m loop
	int i,j;	// i times j;
	int len;
	char c;
	int keta,wa;

	while(scanf("%d\n",&n)!=EOF){
		if(n==0)break;
		scanf("%[^\n]\n",str);
		len=strlen(str);
		
		strorg=(char *)malloc(len+1);
		if(strorg==NULL){
			printf("malloc error\n");
			return -1;
		}
		strcpy(strorg,str);
		
		for(m=1;m<=n;m++){
			
			p=strorg;
			c=*p;
			i=1;
			len=0;

			while(*p!='\0'){
				p++;
				if(*p==c){
					i++;
				} else {
					len+=1;

					keta=1;
					for(wa=i;wa/=10;keta++);
					len+=keta;
					i=1;
				}
				
				c=*p;

			}


			strwrt=(char *)malloc(len+1);
			strwrt[len]='\0';
			p=strorg;
			q=strwrt;
			c=*p;
			i=1;
			while(*p!='\0'){
				p++;
				if(*p==c){
					i++;
				} else {
					//len+=1;
					
					keta=1;
					for(wa=i;wa/=10;keta++);
					sprintf(q,"%d",i);
					q+=keta;
					sprintf(q,"%c",c);
					q++;

					i=1;
				}
				
					c=*p;

			}
			
			
			free(strorg);
			strorg=(char *)malloc(len+1);
			strcpy(strorg,strwrt);
			free(strwrt);
		
		
		
		}
		printf("%s\n",strorg);
		free(strorg);

	
	}




	return 0;
}

Measured memory_bytes: 708
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

#define max(a,b) ((a > b) ? a : b)
#define min(a,b) ((a < b) ? a : b)
#define abs(a) ((a < 0) ? -(a) : a)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static inline int ri() {
	int a;
	scanf("%d", &a);
	return a;
}

int main() {
	int i = ri();
	int j = (i-1) / 999;
	if (j) printf("ABD");
	else printf("ABC");
	
	return 0;
}


Measured memory_bytes: 128
N=int(raw_input())
a=map(int,raw_input().split(' '))

t=[0]*(10**5+1)

for n in a:
    if n==0:
        t[n]+=1
        t[n+1]+=1
    elif n==10**5:
        t[n-1]+=1
        t[n]+=1
    else:
        t[n-1]+=1
        t[n]+=1
        t[n+1]+=1

print max(t)

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

typedef long long ll;

#define        optimize           ios::sync_with_stdio(0); cin.tie(0);
#define PI    acos(-1.0)
#define pb push_back
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define RESET(a, b) memset(a, b, sizeof(a))
#define pii pair <int, int>
#define pll pair <ll, ll>
#define setbiti(x) __builtin_popcount(x)
#define setbitll(x) __builtin_popcountll(x)
#define gcd(a, b) __gcd(a, b)

#define        MX        200005
ll ara[MX];
int main()
{
    optimize
    ll n;
    cin>>n;

    for(int i = 0; i < n; i++){
        cin>>ara[i];
    }
    sort(ara, ara+n, greater <ll> ());

    ll ans = 0;
    for(int i = 0; i < n-1; i++){
        if(ara[i] == ara[i+1]){
            if(ans){
                ans *= ara[i];
                break;
            }
            else{
                ans = ara[i];
                i++;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4436
H, W = map(int, input().split())
row=[]
for i in range(H):
    row.append(input())
i=0
while(True):
    if('.'*W in row):
        row.remove('.'*W)
    else:
        break
columns=[]
for i in range(W):
    for j in range(len(row)):
        if(j==0):
            columns.append(row[j][i])
        else:
            columns[i]+=row[j][i]
while(True):
    if('.'*(len(row)) in columns):
        columns.remove('.'*len(row))
    else:
        break
row = []
for i in range(len(columns[0])):
    for j in range(len(columns)):
        if(j==0):
            row.append(columns[j][i])
        else:
            row[i]+=columns[j][i]
for i in range(len(row)):
    print(row[i])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,x;
  cin >> n >> x;
  n%=500;
  if(n<=x) pr("Yes");
  else pr("No");
}

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


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

W,H,x,y = MI()
if 2*x == W and 2*y == H:
    print(H*W/2,1)
else:
    print(H*W/2,0)



Measured memory_bytes: 80068
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  cin>>N;
  vector<vector<long long>> vmm;
  long long x,l;
  for (long long i=0;i<N;i++){
    cin>>x>>l;
    vmm.push_back({x-l,x+l});
  }
  sort(vmm.begin(),vmm.end(),[](const vector<long long> &alpha,const vector<long long> &beta){return alpha[1] < beta[1];});
  long long maxbef=vmm[0][1];
  long long ans=1;
  for (long long i=1;i<N;i++){
    if (vmm[i][0]>=maxbef){
      ans++;
      maxbef=vmm[i][1];
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 6708
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <limits>//setprecision
#include <iomanip>
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
//#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
long long MOD = 998244353;

void chmax(long long &a,long long b){if(a < b) a = b;}
void chmin(long long &a,long long b){if(a > b) a = b;}

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}



int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N;long long K;cin >> N >> K;
    vector<long long> retu(N);
    long long G;
    long long maxi = 0;
    for(int i = 0;i<N;i++){
        cin >> retu.at(i);
        maxi = max(maxi,retu.at(i));
        if(i == 0) G = retu.at(i);
        else G = gcd(G,retu.at(i));
    }
    if(K % G == 0 && maxi >= K){
        cout << "POSSIBLE" << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }
}


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

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

ll power(ll p, int n)
{
    if (n == 0) {
        return 1;
    }
    if (n % 2 == 1) {
        return power(p, n - 1) * p;
    } else {
        const ll h = power(p, n / 2);
        return h * h;
    }
}

int main()
{
    int n;
    cin >> n;
    bool p;
    cin >> p;
    int zeros = 0;
    int ones = 0;
    for (ll i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a % 2 == 1) {
            ones++;
        } else {
            zeros++;
        }
    }
    if (ones == 0 and p) {
        cout << 0 << endl;
        return 0;
    }
    if ((not p) and ones == 0) {
        cout << power(2, zeros) << endl;
        return 0;
    }
    cout << power(2, zeros) * power(2, ones) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int g(int a, int b)
{
	if(a > b){
		int tmp = a; a = b; b = tmp;
	}
	while(a != 0){
		int tmp = b % a; b = a; a = tmp;
	}
	return b;
}

int main()
{
	int N;
	scanf("%d", &N);

	int res;
	scanf("%d", &res);
	for(int n=1; n<N; n++){
		int a;
		scanf("%d", &a);
		res = g(a, res);
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 128
package main

import (
	"fmt"
	"sort"
)

func main() {
	var k int
	a := make([]int, 3)
	for i := range a {
		fmt.Scan(&a[i])
	}
	fmt.Scan(&k)
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	for i := 0; i < k; i++ {
		a[0] *= 2
	}
	fmt.Println(a[0] + a[1] + a[2])
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vec<ll> a(n),b(n); rep(i,n)cin >> a[i] >> b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(n%2==1)cout << b[n/2] - a[n/2] + 1 << endl;
    else cout << (ll)(((double)(b[(n-1)/2]+ b[n/2])/2 - (double)(a[(n-1)/2]+a[n/2])/2)*2 + 1) << endl;
}


Measured memory_bytes: 6364
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i <(n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

    int n,x;
    vector<int>m(1111);
    cin>>n>>x;
    rep(i,n)cin>>m[i];
    int sum = 0;
    rep(i,n)sum +=m[i];

    
    int mi =m[0];

    rep(i,n)if(mi>m[i])mi = m[i];
    int ans =(x-sum)/mi;

cout<< n+ans<<endl;






}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using db = double;
using ii = pair <int, int>;

#define int long long
#define FOR(a, b, c) for(int a = b, _c = c; a <= _c; ++a)
#define FORD(a, b, c) for(int a = b, _c = c; a >= _c; --a)
#define REP(a, b, c) for(int a = b, _ = c; a < _; ++a)
#define ALL(a, b) for(auto &a : b)
#define pb push_back
#define mp make_pair
#define all(a) begin(a), end(a)
#define reset(f, x) memset(f, x, sizeof(f))
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define bit(x, i) (x >> (i - 1) & 1ll)
#define onbit(x, i) (x | (1ll << (i - 1)))
#define offbit(x, i) (x & ~(1ll << (i - 1)))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll

template <class T> void Max(T &x, T y) { x = (x > y) ? x : y;}

const int N = 22;
const ll mod = 1e9 + 7;
int n;
vector <int> ad[N];
ll f[1 << N];

main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n;
  FOR(i, 1, n) {
    FOR(j, 1, n) {
      int tt;
      cin >> tt;
      if(tt) ad[i].push_back(j);
    }
  }
  f[0] = 1;
  FOR(tt, 0, (1ll << n) - 2) {
    int i = __builtin_popcount(tt) + 1;
    ALL(v, ad[i]) {
      if(!bit(tt, v)) {
        int nex = onbit(tt, v);
        f[nex] = (f[nex] + f[tt]) % mod;
      }
    }
  }
  cout << f[(1ll << n) - 1];
}


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

using namespace std;

int main(){
    int n;
    int64_t total =0;
    cin >>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        a[i]= a[i] - i-1;
    }

    sort(a.begin(),a.end());

    for(auto &e:a) total += abs(e -a[n/2]);

    cout << total;
   
}

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

int main(){
    int N, L;
    cin >> N >> L;    
    string str[N] = {};
    for(int i=0; i<N; i++){
        cin >> str[i];
    }
    sort(str, str+N);
    for(int i=0; i<N; i++){
        cout << str[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

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

llint a,b;

void solve(){
  cin >> a >> b;
  if(a>=10 || b>=10)cout << -1;
  else cout << a*b;
  cout << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


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

int main() {
	string a, b; cin >> a >> b;
	if (a.size() == b.size()) {
		for (int i = 0; i < a.size(); i++) {
			if (a[i] > b[i]) {
				cout << "GREATER" << endl;
				break;
			}
			else if (a[i] < b[i]) {
				cout << "LESS" << endl;
				break;
			}
			if (i == a.size() - 1) {
				cout << "EQUAL" << endl;
				break;
			}
		}
	}
	else {
		if (a.size() > b.size()) {
			cout << "GREATER" << endl;
		}
		else {
			cout << "LESS" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VM
main=print.solve.VU.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve hwcas=VU.sum.VU.map f$as where
  (cs,as)=VU.splitAt 100$VU.drop 2 hwcas
  g=wf 10 cs
  f a=if a<0 then 0 else g VU.! a
wf n es = VU.generate n (\i->d VU.! idx i 1) where
  idx i j = i*n+j
  d = VU.create $ do
    d <- VU.thaw es
    forM_ [0..n-1] $ \k ->
      forM_ [0..n-1] $ \i ->
        forM_ [0..n-1] $ \j -> do
          a <- VM.read d (idx i j)
          b <- liftM2 (+) (VM.read d (idx i k)) (VM.read d (idx k j))
          VM.write d (idx i j) $ min a b
    return d

Measured memory_bytes: 6288
h, w, a, b = map(int, input().split())

ans = []

for i in range(h):
    ans.append([])
    for j in range(w):
        if i < b and j < a:
            ans[i].append(0)
        elif i >= b and j >= a:
            ans[i].append(0)
        else:
            ans[i].append(1)

for i in range(h):
    for j in range(w):
        print(ans[i][j], end='')
    print()


Measured memory_bytes: 15604
/* 
    
*/ 
#include <bits/stdc++.h>
#define md(x, y)  ((x + y) >> 1)
#define ls(x)      (x << 1)
#define rs(x)      (x << 1 | 1)
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const ll INF = 5e18;
const int MAXN = 1e5 + 10;
ll T, n, a, b, c, d;
map<ll, ll> mp;
ll f(ll x)
{
    if(x == 0)  return 0;
    else if(x == 1) return d;
    if(mp[x]) return mp[x];
    ll ret = INF;
    if(ret / d > x) ret = d * x;

    if(x % 2 == 0)
        ret = min(ret, f(x / 2) + a);
    else 
    {
        ll up = (x / 2) * 2;
        ll tmp = (x - up) * d;
        ret = min(ret, f(x / 2) + a + tmp);
        up = (x / 2 + 1) * 2;
        tmp = (up - x) * d;
        ret = min(ret, f(up / 2) + a + tmp);
    }
    if(x % 3 == 0)
    {
        ret = min(ret, f(x / 3) + b);
    }
    else 
    {
        ll up = x / 3 * 3;
        ll tmp = (x - up) * d;
        ret = min(ret, f(x / 3) + b + tmp);
        up = (x / 3 + 1) * 3;
        tmp = (up - x) * d;
        ret = min(ret, f(up / 3) + b + tmp);
    }
    if(x % 5 == 0)
    {
        ret = min(ret, f(x / 5) + c);
    }
    else 
    {
        ll up = x / 5 * 5;
        ll tmp = (x - up) * d;
        ret = min(ret, f(x / 5) + c + tmp);
        up = (x / 5 + 1) * 5;
        tmp = (up - x) * d;
        ret = min(ret, f(up / 5) + c + tmp);
    }
    return mp[x] = ret;
}

int main()
{
    cin >> T;
    while(T--)
    {
        cin >> n >> a >> b >> c >> d;
        mp.clear();
        cout << f(n) << endl;
    }   
    return 0;
}

Measured memory_bytes: 4428
import scala.io.{ StdIn => in}
import scala.annotation.tailrec

object Main extends App {
  val mod = 1000000007
  val n = in.readInt
  val arr = Array.ofDim[Int](n+1)

  in.readLine.split(" ").map(_.toInt).foreach{i => {
    arr(i) += 1
  }}

  def f(acc:Int, idx:Int, isEven:Boolean):Int = {
    val rem = if(isEven) 0 else 1
    @tailrec
    def rec(acc:Int, idx:Int):Int = {
      if(idx > n) acc
      else if(idx % 2 == rem) {
        if(arr(idx) == 2) rec(acc*2%mod, idx+1)
        else 0
      }
      else if(arr(idx) == 0) rec(acc, idx+1) else 0
    }

    rec(acc,idx)
  }

  val ans = if(arr(0) == 1) f(1,1,true)
    else if(arr(1) == 2) f(2,2,false)
    else 0

  println(ans)
}

Measured memory_bytes: 42388
a, b, c, d = gets.chomp.chars.map(&:to_i)
if    a + b + c + d == 7 then puts "#{a}+#{b}+#{c}+#{d}=7"
elsif a + b + c - d == 7 then puts "#{a}+#{b}+#{c}-#{d}=7"
elsif a + b - c + d == 7 then puts "#{a}+#{b}-#{c}+#{d}=7"
elsif a + b - c - d == 7 then puts "#{a}+#{b}-#{c}-#{d}=7"
elsif a - b + c + d == 7 then puts "#{a}-#{b}+#{c}+#{d}=7"
elsif a - b + c - d == 7 then puts "#{a}-#{b}+#{c}-#{d}=7"
elsif a - b - c + d == 7 then puts "#{a}-#{b}-#{c}+#{d}=7"
elsif a - b - c - d == 7 then puts "#{a}-#{b}-#{c}-#{d}=7"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
const lint mod = 1e9 + 7;

int n, a, b, c, d;
lint dp[1010][1010];

lint powmod(long x, long n){
  lint ret = 1;
  while(n > 0){
    if(n&1) ret *= x, ret %= mod, n -= 1;
    else x *= x, x %= mod, n >>= 1;
  }
  return ret;
}

vector<lint> fact;
vector<lint> revfact;

void setfact(int n){
  fact.resize(n+1); revfact.resize(n+1);
  fact[0] = 1;
  rep(i, n) fact[i+1] = fact[i] * (i+1) % mod;
  
  revfact[n] = powmod(fact[n], mod-2);
  for(int i=n-1; i>=0; i--) revfact[i] = revfact[i+1] * (i+1) % mod;
}

lint f(int i, int j, int k){
    return fact[n-(j-i*k)] * revfact[k] % mod * revfact[n-(j-i*k)-i*k] % mod * powmod(revfact[i], k) % mod;
}

lint dfs(int i, int j){
    if(dp[i][j] >= 0) return dp[i][j];
    lint ret = dfs(i-1, j) * f(i, j, 0) % mod;
    For(k, c, d+1){
        if(j < i*k) break;
        if(i == a && j > i*k) continue;
        ret = (ret + dfs(i-1, j-i*k) * f(i, j, k) % mod) % mod;
    }
    return dp[i][j] = ret;
}

int main(){
    scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
    setfact(2000);
    rep(i, b+1)rep(j, n+1) dp[i][j] = -1;
    rep(j, n+1){
        if(j%a || (1<=j && j<a*c) || j>a*d) dp[a][j] = 0;
        else{
            int k = j / a;
            dp[a][j] = fact[n] * revfact[n-j] % mod * revfact[k] % mod * powmod(revfact[a], k) % mod;
        }
    }
    printf("%lld\n", dfs(b, n));
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
int n,k,m,a,ans,h[1000000],b,mas[1000000];
vector<vector<int> > v;
int main() 
{
  v.resize(1000000);
  cin>>n>>k;
  for(int i=1;i<=n;i++)
  {
      cin>>h[i];
  }
  for(int i=0;i<k;i++)
  {
      cin>>a>>b;
      if(h[a]<=h[b])
      {
          mas[a]=1;
      }
      if(h[b]<=h[a])
      {
          mas[b]=1;
      }
  }
  for(int i=1;i<=n;i++)
  {
      if(mas[i]==0)
      {
          ans++;
      }
  }
  cout<<ans;
}

Measured memory_bytes: 27524
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)//半開区間[a, b)
#define rep(i,n) for(int i=0;i<n;i++)//半開区間[0, n)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)//半開区間[a, b)を上から
#define reprev(i,n) reprrev(i,0,n)//半開区間[0, n]を上から
typedef long long ll;//intは[-2147483648, 2147483647]の範囲 
typedef unsigned long long ull;//非負整数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
                     
const ll mod = 1e9+7;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
                     
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int X, A; cin >> X >> A;
  cout << ((X>=A)? 10:0) << endl; 
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(); // スイッチの数
        int M = sc.nextInt(); // 電球の数

        // スイッチ： 0 ～ N-1
        // 電球：     0 ～ M-1
        // connectedSwitch： 各電球に繋がっているスイッチ達のリスト
        List<List<Integer>> connectedSwitchesList = new ArrayList<>();
        for (int i = 0; i < M; i++) {
            int k = sc.nextInt();
            List<Integer> connectedSwitches = new ArrayList<>();
            for (int j = 0; j < k; j++) {
                connectedSwitches.add(sc.nextInt() - 1); // 問題文上のスイッチのインデックスを、プログラミング上のインデックスに合わせる。
            }
            connectedSwitchesList.add(connectedSwitches);
        }
        int[] p = new int[M];
        for (int i = 0; i < M; i++) {
            p[i] = sc.nextInt();
        }

        // スイッチの最大数は10なので、on/off の組み合わせは全部で 1024 通り。
        // 総当たりで試しても間に合うはず。 on/off の全ての組み合わせを作成したい。
        int onOffCombinationCount = (int)(Math.pow(2, N));
        int count = 0;
        for (int onOff = 0; onOff < onOffCombinationCount; onOff++) {
            boolean isAllLightsOn = true;
            for (int i = 0; i < M; i++) {
                boolean isOn = checkLight(onOff, connectedSwitchesList.get(i), p[i], N);
                if (isOn == false) {
                    isAllLightsOn = false;
                    break;
                }
            }
            if (isAllLightsOn == true) {
                count++;
            }
        }

        System.out.print(count);
    }

    // 与えられた ON/OFF のリストと、電球とスイッチの接続状況から、その電球がつくかどうか調べる。
    boolean checkLight(int onOffBit, List<Integer> connectedSwitches, int p, int N) {
        StringBuffer tmp = new StringBuffer();
        //
        for (int i = 0; i < N; i++) {
            if (connectedSwitches.contains(i)) {
                tmp.append(1);
            }
            else {
                tmp.append(0);
            }
        }
        int switchBit = Integer.parseInt(tmp.toString(), 2);
        int lightOnCount = Integer.bitCount(onOffBit & switchBit);
        if (lightOnCount % 2 == p) {
            return true;
        }
        else {
            return false;
        }
    }


    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}

Measured memory_bytes: 23372
#include<stdio.h>
#include<stdlib.h>
int fun(char *);
int fun(char *s)
{
    int i,ans=0;
    for(i=0;s[i]!='\0';i++)
    {
        if(s[i]=='2')
        {
            ans++;
        }
    }
    return ans;
}
int main()
{
    char a[10];
    scanf("%s",a);
    printf("%d\n",fun(a));
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    string s;
    cin>>s;
    s[5]=' ',s[13]=' ';
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int binarySearch(int key,int n,int A[]){
  int L=0,R=n,mid;

  while(L<R){
    mid=(L+R)/2;
    if(A[mid]==key) return 1;
    else if(key<A[mid])R=mid;
    else L=mid+1;
  }
  return 0;
     }

   int main(){

     int i,j,n,count=0,N,A[1000000],key;


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



     scanf("%d",&N);
     for(j=0; j<N; j++){
       scanf("%d",&key);
       if(binarySearch(key,n,A)!=0){
         count++;
       }
    }

 printf("%d\n",count);

     return 0;
   }





                                     


Measured memory_bytes: 2128
#include <bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
*/
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
using ll=long long int; using dd=double;
using pii=pair<int,int>; using pll=pair<ll,ll>;
typedef vector<int> vi;
const ll INFLL=(ll)2e18, MOD=1'000'000'007;
const int INF=0x3f3fffff;
/////////////////// DEBUG MODE ///////////////////////////////////
#define D(x) cerr<<#x<<" is: "<<x<<'\n';
#define DD(x,y) cerr<<"("<<#x<<","<<#y<<") are: "<<x<<" "<<y<<'\n';
/////////////////// GLOBAL VARIABLES ////////////////////////////
vector<vector<int>> adj; vector<bool> vis;
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};


/////////////////// FUNCTIONS ////////////////////////////////////
inline ll mexp(ll x,ll n,ll m){ll res=1;while(n){if(n&1)res=(res*x)%m;n>>=1;x=((x%m)*(x%m))%m;}return res;}
bool ispow2(ll x){ return x && (!(x&(x-1)));}
ll gcd(ll x, ll y){ pll p{x,y}; while(p.ss) p={p.ss,p.ff%p.ss}; return p.ff;}

ll n; vv<ll> v;
/////////////////// MAIN STARTS //////////////////////////////////
int main(){
  ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
  cout<<fixed;cerr<<fixed; cout<<setprecision(8); cerr<<setprecision(3);
  srand(time(NULL)); rand();

#ifdef DEBUG
  auto tStart = clock(); //freopen("op.txt","w",stdout);
#endif

  cin>>n; v.resize(n);
  for (int i=0;i<n;i++){
    cin>>v[i]; v[i]-=1LL+i;
  }
  ll low=-1e6, high=1e10;

  auto f=[](ll b){ll sum=0; for(int i=0;i<n;++i) sum+=abs(v[i]-b); return sum;};
  while(high-low>2){
    ll m1=low+(high-low)/3, m2=low+((high-low)*2)/3;
    ll t1=f(m1), t2=f(m2);
    if(t1>t2) low=m1;
    else high=m2;
  }
  ll ans=INFLL;
  for(;low<=high;++low) {
    ans=min(ans,f(low));
    //DD(low,f(low));
  }
  cout<<ans<<'\n';



#ifdef DEBUG
	cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1e3<<"ms.\n";
#endif
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N;
  cin >> N;
  vector<int> X(N);
  REP(i, N){
    cin >> X[i];
  }

  int ans = INF;
  for(int i = -103; i <= 103; i++){
    int res = 0;
    REP(j, N){
      res += (X[j]-i)*(X[j]-i);
    }
    chmin(ans, res);
  }

  cout << ans << endl;

  return 0;
}

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

int main()
{
    int h,n,x,sum=0;
    cin>>h>>n;
    while(n--){ 
        cin>>x;
        sum+=x;
    } 
    cout<<(sum>=h?"Yes":"No");
    

         
      
        

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "../../../debug_print.hpp"
#else
#define debug(...)
#endif
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    vector<string> c(2);
    scan(c);
    auto origin = c;
    reverse(all(c));
    for (auto &&i : c) {
        reverse(all(i));
    }

    debug(c);
    if (c == origin)
        print("YES");
    else
        print("NO");

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	count := 0
	for i := 0; i < len(s)/2; i++ {
		if s[i] != s[len(s)-1-i] {
			count++
		}
	}
	fmt.Println(count)

}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
#define MAX 1000000007
int main(){
	int n, m; cin >> n >> m;
	int a;
	bool b[n+1];
	for(int i = 0; i < n+1; i++) b[i] = true; 
	for(int i = 0; i < m; i++){
		cin >> a;
		b[a] = false;
	}
	long long int c[n+1]; c[0] = 1;
	if(n == 1){
		cout << 1 << endl;
		return 0;
	}else if(n == 2){
		if(b[1]) cout << 2 << endl;
		else cout << 1 << endl;
		return 0;
	}
	for(int i = 1; i < n+1; i++){
		if(!b[i]) c[i] = 0;
		else if(i==1) c[i] = c[i-1];
		else c[i] = (c[i-1] + c[i-2]) % MAX;
	}
	cout << c[n] << endl;
}


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

const int mxN = 3e3 + 2;
string s, t;
int n, m, dp[mxN][mxN];
pair<int, int> parent[mxN][mxN];

int calc(int i, int j)
{
    if (i < 0 || j < 0)
        return 0;
    return dp[i][j];
}

int main()
{
    cin >> s >> t;
    n = s.length(); m = t.length();

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {            dp[i][j] = 0;
            if (calc(i - 1, j) >= dp[i][j])
            {
                parent[i][j] = {i - 1, j};
                dp[i][j] = calc(i - 1, j);
            }
            if (calc(i, j - 1) >= dp[i][j])
            {
                parent[i][j] = {i, j - 1};
                dp[i][j] = calc(i, j - 1);
            }
            if (s[i] == t[j] && calc(i - 1, j - 1) + 1 >= dp[i][j])
            {
                parent[i][j] = {i - 1, j - 1};
                dp[i][j] = calc(i - 1, j - 1) + 1;
            }
        }
    }

    string ret = "";
    pair<int, int> cur = {n - 1, m - 1};
    while (cur.first >= 0 && cur.second >= 0)
    {
        if (s[cur.first] == t[cur.second])
            ret.push_back(s[cur.first]);
        cur = parent[cur.first][cur.second];
    }
    reverse(ret.begin(), ret.end());

    cout << ret << endl;
}

Measured memory_bytes: 109152
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a,b;
bool flag,vis[101];
char s[101][101];
int main(){
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%s",s[i]);
	for(int i=0;i<b;i++){
		flag=0;
		for(int j=0;j<a;j++)
			if (s[j][i]=='#')flag=1;
		if (!flag)vis[i]=1;
	}
	for(int i=0;i<a;i++){
		flag=0;
		for(int j=0;j<b;j++)
			if (s[i][j]=='#')flag=1;
		if (flag){
			for(int j=0;j<b;j++)
				if (!vis[j])printf("%c",s[i][j]);
			printf("\n");
		}
	}
} 

Measured memory_bytes: 128
// let coding = begin

#include<bits/stdc++.h>

#define ll long long
#define pb       push_back
#define all(a)   a.begin(), a.end()

using namespace std;
const int MAX = 1e9+9;
const int MIN = -1e9;
const int N= 1e5;
int n;
int main(){
  clock_t start;
  cin >> n;
  int ans=0;
  for(int i=1; i<=n; i++){
    int cnt=0;
    for(int j=1; j<=i; j++){
      if(i%j == 0) cnt++;
    }
    if(cnt==8 && i%2 != 0){
      ans++;
    }
  }
  cout << ans << endl;

  cerr << "Time: " << (clock() - start) / (double)(CLOCKS_PER_SEC / 1000) << " ms" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int MAX = 10;
int c[MAX][MAX];

void warshall_floyd() {
  for (int k = 0; k <= 9; k++){       // 経由する頂点
    for (int i = 0; i <= 9; i++) {    // 始点
      for (int j = 0; j <= 9; j++) {  // 終点
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
}
int main() {

    int h, w;
    cin >> h >> w;
    rep(i, 10){
        rep(j, 10){
            cin >> c[i][j];
        }
    }
    warshall_floyd();

    vector<vector<int>> a(h, vector<int>(w));
    int ans = 0;
    rep(i, h){
        rep(j, w){
            cin >> a[i][j];
            if(a[i][j] != -1){
                ans += c[a[i][j]][1];
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REPE(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> T lcm(T a, T 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) b = a; }
typedef long long ll;

int main() {
    string s; cin >> s;
    int sum = 0;
    for(int i = 0; i < s.size(); i++){
        sum += s[i] - '0';
    }
    if(stoi(s) % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 256
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val sc = new FastScanner(System.in)
  val n, q = sc.nextInt()
  val queries = List.fill(q)((sc.nextInt(), sc.nextInt()-1))

  var white = 0L
  var xs = ArrayBuffer[Int](0)
  var ys = ArrayBuffer[Int](0)
  val wx = Array.fill(n-1)(0L)
  val wy = Array.fill(n-1)(0L)
  wx(0) = n-2
  wy(0) = n-2
  var xmin = n-2
  var ymin = n-2

  def binSearch(a: ArrayBuffer[Int], begin: Int, end: Int, k: Int): Int = {
    if (end - begin <= 1) {
      end
    } else {
      val m = begin + (end - begin) / 2
      if (a(m) >= k) binSearch(a, begin, m, k) else binSearch(a, m, end, k)
    }
  }

  for ((z, i) <- queries) {
    if (z == 1) {
      val idx = binSearch(xs, 0, xs.size, i)
      val w = if (idx == 1) {
        xmin = i-1
        ymin
      } else {
        wx(xs(idx-1))
      }
      wx(i) = w
      white += w
      xs.insert(idx, i)
    } else {
      val idx = binSearch(ys, 0, ys.size, i)
      val w = if (idx == 1) {
        ymin = i-1
        xmin
      } else {
        wy(ys(idx-1))
      }
      wy(i) = w
      white += w
      ys.insert(idx, i)
    }
  }

  println((n-2).toLong * (n-2) - white)
}

class FastScanner(source: java.io.InputStream) {
  val buf = new Array[Byte](1024)
  var now, end = 0

  def isPrintable(b: Byte): Boolean = 33 <= b && b <= 126
  def isNum(b: Byte): Boolean = 48 <= b && b <= 57

  def hasNextByte: Boolean = {
    if (now < end) {
      true
    } else {
      now = 0
      end = source.read(buf)
      end > 0
    }
  }

  def nextByte(): Byte = {
    if (hasNextByte) {
      val b = buf(now)
      now += 1
      b
    } else {
      -1
    }
  }

  def hasNext: Boolean = {
    while (hasNextByte && !isPrintable(buf(now))) {
      now += 1
    }
    hasNextByte
  }

  def next(): String = {
    if (hasNext) {
      val sb = new StringBuilder()
      var b = nextByte()
      while (isPrintable(b)) {
        sb += b.toChar
        b = nextByte()
      }
      sb.toString
    } else {
      throw new NoSuchElementException()
    }
  }

  def nextInt(): Int = {
    nextLong().toInt
  }

  def nextLong(): Long = {
    if (hasNext) {
      var b = nextByte()
      var sign = 1
      var n = 0L
      if (b == '-') {
        sign = -1
        b = nextByte()
      }
      while (isNum(b)) {
        n = n * 10 + (b - 48)
        b = nextByte()
      }
      sign * n
    } else {
      throw new NoSuchElementException()
    }
  }

  def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 69960
n,w = map(int, input().split())
item = [list(map(int,input().split())) for i in range(n)]
dp = [0 for i in range(w+2)]
for j in item:
	for i in range(1,w+2):
		if w+1-i+j[1] <=w:
			dp[w+1-i+j[1]] = max(dp[w+1-i+j[1]],dp[w+1-i]+j[0])
print(dp[w])


Measured memory_bytes: 5928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod=1e9+7;
 
int main(){
    string s;cin>>s;
    vector<int> X;
    int p=0;
    rep(i,s.size()){
        if(s[i]=='x')++p;
        if(s[i]!='x'){
            X.push_back(p);
            p=0;
        }
    }
    X.push_back(p);
    string t;
    rep(i,s.size()){
        if(s[i]!='x')t.push_back(s[i]);
    }
    rep(i,t.size()/2){
        if(t[i]!=t[(int)t.size()-1-i]){
            cout<<-1<<endl;
            exit(0);
        }
    }
    int ans=0;
    rep(i,X.size()/2){
        if(ans+=abs(X[i]-X[(int)X.size()-1-i]));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1020