akhauriyash/Code-Regression huggingface dataset:
K, N = input().split()
K = int(K)
N = int(N)
A = list(map(int, input().split()))
A.append(K + A[0])
max = 0
for i in range(N):
    if max < (A[i+1] - A[i]):
        max = A[i+1] - A[i]
print(K - max)


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
const ll MOD=1000000007;
int main(){
	ll H,W,N; cin>>H>>W>>N;
	map<P,ll> m;
	rep(i,N){
		ll A,B; cin>>A>>B;
		rep(s,3)rep(t,3){
			if(1<=A-s && A-s<=H-2 && 1<=B-t && B-t<=W-2) m[mp(A-s,B-t)]++;
		}
	}
	vector<ll> ans(10,0);
	for(auto itr=m.bg;itr!=m.ed;itr++){
		ans[itr->b]++;
	}
	ll cnt=0;
	rep1(i,9){
		cnt+=ans[i];
	}
	cout<<(H-2)*(W-2)-cnt<<endl;
	rep1(i,9){
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 56448
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a;
    cin >> a;
    cout << a+pow(a,2)+pow(a,3) << "\n";
    return 0;
}   

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int last[20], second[20];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    long long ret = 0;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        int mx = 0;
        for (int j=0; j<20; j++) {
            if (a & (1 << j)) {
                last[j] = second[j];
                second[j] = i + 1;
            }
            mx = max(mx, last[j]);
        }
        ret += i - mx + 1;
    }
    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll m;
map<ll, int> prime_factor(ll n) {
  map<ll, int> res;
  for(ll i=2; i*i<=n; i++) {
    while(n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if(n != 1) ++res[n];
  return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> m;

  map<ll, int> pf = prime_factor(m);

  ll ans = 0;
  for(auto& x:pf) {
    ll ts = x.second;
    int i = 1;
    while(ts >= i)  {
      ts -= i;
      i++;
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> l(n);
	rep(snip_i, n) cin >> l.at(snip_i);
	sort(l.begin(), l.end(), greater<int>());
	int ans = 0;
	rep(i, k){
		ans += l.at(i);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N, S;
  cin >> N >> S;
  int count = 0;
  for(int i = 1; i < N+1; i++){
  for(int j = 20; j < S+1; j++){
  int d,D;
    d = j / 10;
    D = j % 10;
    if(i == (d * D) && D >=2){
    count +=  1;
    }
  }
  }
  cout << count;
}


Measured memory_bytes: 256
N=int(input())
H=list(map(int, input().split()))
ans=0
cnt=0
for i in range(0,N-1):
    if H[i]>=H[i+1]:
        cnt+=1
    else:
        ans=max(ans,cnt)
        cnt=0
ans=max(ans,cnt)
print(ans)

Measured memory_bytes: 15020
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	D = inputInt()
	C = inputList()
	S = []
	ans = []
	for i in range(D):
		s = inputList()
		S.append(s)

	minC = min(C)
	minCn = 0
	for i,val in enumerate(C):
		if val == minC:
			minCn = i

	for i,val in enumerate(S):
		tmp = max(val)
		for j,vol in enumerate(val):
			if tmp == vol:
				ans.append(random.randint(1, 26))
				break

	for i in range(D):
		print(ans[i])

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


Measured memory_bytes: 78600
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

int main()
{
    long N;
    long K;
    cin >> N >> K;
    map<long,long> m;
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        m[a] += b;
    }
    int ans;
    for (auto it = m.begin(); it != m.end(); it++) {
        if (it->second >= K) {
            ans = it->first;
            break;
        }
        K -= it->second;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  char c;
  cin >> c;
  if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
    cout << "vowel\n";
  }
  else{
    cout << "consonant\n";
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int f=0;
	while(1){
		int n,a,b,c;
		pii d[10];
		string s[10];
		cin>>n;
		if(n==0) break;
		if(f==1) cout<<endl;
		rep(i,0,n){
			cin>>s[i]>>a>>b>>c;
			d[i].fi=3*a+c; d[i].se=n-i;
		}
		sort(d,d+n);
		reverse(d,d+n);
		rep(i,0,n){
			o(s[n-d[i].se]<<","<<d[i].fi);
		}
		f=1;
	}
}

Measured memory_bytes: 1208
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;

/*
ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}*/

int q, l, r, mem;
bool prime[100002];
int like2017[100002];
int main(){
	lp(100002) {
		prime[i] = true;
		like2017[i] = 0;
	}
	prime[0] = prime[1] = false;
	mem = 2;
	while (mem != 100001) {
//		cout << mem << endl;
		for (int i = mem + 1; i <= 100000; i++) {
			if (prime[i] && i%mem == 0) {
				prime[i] = false;
			}
		}
		for (int i = mem + 1; true; i++) {
			if (prime[i]) {
				mem = i;
				break;
			}
		}
	}
	lp(100000) {
		like2017[i + 1] = like2017[i];
		if (prime[i + 1] && i % 2 == 0 && prime[(i + 2) / 2])like2017[i + 1]++;
	}
	cin >> q;
	lp(q) {
		cin >> l >> r;
		cout << like2017[r] - like2017[l - 1] << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n;

    cin >> n;

    set<string> s;

    while(n--){
        string x;

        cin >> x;

        if(s.find(x) == s.end()) s.insert(x);
    }

    cout << (int)s.size() << endl;

	return 0;
}


Measured memory_bytes: 19248
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, k;
  cin >> a >> b >> k;
  set<int> res;
  for(int i = a; i < a + k; i++) res.insert(i);
  for(int j = b; j > b - k; j--) res.insert(j);
  for(auto n : res) if(a <= n && n <= b)cout << n << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();

		int length = 2 * (a + b);
		int area = a * b;

		System.out.println(area + " " + length);

	}
}


Measured memory_bytes: 26124
def chmin(a,b):
    if a<b :
        return a 
    else:
        return b
n = int(input())
h = list(map(int, input().split()))

dp = [float("inf")]*(10**5 + 10)

# 初期条件
dp[0] = 0

# 配るdp
for i in range(n-1):
    dp[i+1] = chmin(dp[i+1], dp[i] + abs(h[i]-h[i+1]))
    if i < n-2:
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i]-h[i+2]))

print(dp[n-1])



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

int A[505], C[505], S[505], F[505], N;

void solve(int i) {
    int t = 0;
    for (int j = i; j < N; j++) {
        t = max(S[j], ((t - 1) / F[j] + 1) * F[j]);
        t += C[j];
    }
    printf("%d\n", t);
}

int main() {
    scanf("%d", &N);
    for (int i = 1; i < N; i++) scanf("%d %d %d", &C[i], &S[i], &F[i]);
    for (int i = 1; i < N; i++) solve(i);
    printf("0\n");
    return 0;
}

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

main()
{
    ll x;
    cin>>x;
    for(ll i=-120;i<=120;i++){
        for(ll j=-120;j<120;j++)
            if(i*i*i*i*i-j*j*j*j*j==x){
                cout<<i<<" "<<j;return 0;
            }
    }
    return 0;
}


Measured memory_bytes: 3540
n = int(input())
res = n % 26

A = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s',
     't','u','v','w','x','y','z']

ans = []
while n//26 > 0 :
  res = n % 26
  if res != 0:
    ans.append(A[res-1])
    n = n // 26
  elif res == 0:
    ans .append(A[25])
    n = n // 26 -1

if n != 0:
  ans.append(A[n-1])

print(*ans[::-1], sep='')


Measured memory_bytes: 9256
import java.util.*;

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

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[][] p = new int[N][3];
    int px = 0;
    int py = 0;
    int ph = 0;
    for (int i = 0; i < N; i++) {
      p[i][0] = sc.nextInt();
      p[i][1] = sc.nextInt();
      p[i][2] = sc.nextInt();
      if (p[i][2] > 0) {
        px = p[i][0];
        py = p[i][1];
        ph = p[i][2];
      }
    }
    
    for (int i = 0; i <= 100; i++) {
      for (int j = 0; j <= 100; j++) {
        int ch = Math.abs(px-i) + Math.abs(py-j) + ph;
        if (isValidH(p, i, j, ch)) {
          System.out.println(i + " " + j + " " + ch);
          return;
        }
      }
    }
  }
  
  private static boolean isValidH(int[][] p, int cx, int cy, int ch) {
    for (int k = 0; k < p.length; k++) {
      int x = p[k][0];
      int y = p[k][1];
      int h = p[k][2];
      if (h != Math.max(ch - Math.abs(x-cx) - Math.abs(y-cy), 0)) {
        return false;
      }
    }
    return true;
  }


}

Measured memory_bytes: 23764
#include <cstdio>
#include <algorithm>

using std::max;

const int MAXN=1e5+5;
int n,ans;
int a[3][MAXN],cnt[MAXN];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[1][i]);
	for(int i=1;i<=n;++i)
		a[0][i]=a[1][i]-1,a[2][i]=a[1][i]+1;
	for(int i=1;i<=n;++i)
		++cnt[a[0][i]],++cnt[a[1][i]],++cnt[a[2][i]];
	for(int i=0;i<=1e5;++i)
		ans=max(ans,cnt[i]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    bool cnt = false;
    for(int i = 0; i < s.size(); i ++){
        if(s[i] =='C'){
            cnt = 1;
        }
        if(s[i] == 'F' && cnt){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;

int insertion_sort(int xs[], int n, int g){
    int cnt = 0;
    for(int i = g; i < n; ++i){
        //int v = xs[i];
        for(int j = i-g; j >= 0 && xs[j+g] < xs[j]; j-=g){
            ++cnt;
            swap(xs[j+g], xs[j]);
        }
    }
    return cnt;
}

vector<int> gen_g(int n){
    auto vec = vector<int> {};
    while(n > 1){
        n /= 2;
        vec.push_back(n);
    }
    if(!vec.size()) vec.push_back(1);
    return vec;
}

int shell_sort(int xs[], int n, vector<int> g){
    int cnt = 0;
    vector<int>::iterator it;
    for(it = g.begin(); it != g.end(); ++it){
        cnt += insertion_sort(xs, n, *it);
    }
    return cnt;
}

template <class T>
void print_array(T xs[], int n){
    for(int i = 0; i < n; ++i){
        cout << xs[i] << '\n';
    }
}

void print_vector(vector<int> vec){
    vector<int>::iterator it;
    for(it = vec.begin(); it != vec.end(); ++it){
        if(it != vec.begin()) cout << ' ';
        cout << *it;
    }
    cout << '\n';
}

int main(){
    int n;
    cin >> n;
    int xs[n];
    for(int i = 0; i < n; ++i){
        scanf("%d", &xs[i]);
    }
    vector<int> g = gen_g(n);
    int cnt = shell_sort(xs, n, g);

    cout << g.size() << '\n';
    print_vector(g);
    cout << cnt << '\n';
    print_array(xs, n);
}

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

int main() {
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    ll minim = min(min(min(min(a,b),c),d),e);
    ll res = n/minim;
    if (n%minim>0) res++;
    cout << res+4;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
long long int n, a, b;
 
int main()
{
	cin >> n >> a >> b;
	a *= (n - 2);
	b *= (n - 2);
	b - a < -1 ? cout << 0 : cout << b - a + 1;
	return 0;	
}


Measured memory_bytes: 256
def solve():
    data = read()
    result = think(data)
    write(result)


def read():
    n = int(input())
    data = []
    for i in range(n):
        data.append(read_data())
    return data


def read_data():
    return list(map(int, input().split(' ')))


def think(data):
    result = []
    for d in data:
        if is_right_triangle(d):
            result.append('YES')
        else:
            result.append('NO')
    return result


def is_right_triangle(d):
    x, y, z = d[0], d[1], d[2]
    return (x ** 2 == y ** 2 + z ** 2) or (y ** 2 == z ** 2 + x ** 2) or (z ** 2 == x ** 2 + y ** 2)


def write(result):
    for r in result:
        print(r)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 5760
import math
import bisect
from queue import Queue
from collections import deque

s = input()

dp = [0 for _ in range(len(s)+1)]

dp[0] = 1

for i in range(len(s)+1):
    if(dp[i] == 1):
        if(i+4 < len(s)):
            if("".join(s[i:i+5]) == "dream"):
                dp[i+5] = 1
            if ("".join(s[i:i + 5]) == "erase"):
                dp[i+5] = 1
        if (i + 6 < len(s)):
            if ("".join(s[i:i + 7]) == "dreamer"):
                dp[i + 7] = 1
        if (i + 5 < len(s)):
            if ("".join(s[i:i + 6]) == "eraser"):
                dp[i + 6] = 1

if(dp[len(s)] == 1):
    print("YES")
else:
    print("NO")

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

// const int M = 100000;
const int M = 20;

int main() {
    int N;
    cin >> N;
    vector<lint> A(N, 0);
    rep(i, N) cin >> A[i];
    A.push_back(-1);

    lint sum = 1000;
    lint k   = 0;

    for (int i = 0; i < N; i++) {
        if (A[i + 1] <= A[i]) { continue; }

        for (int j = i + 1; j < N; j++) {
            if (A[j] > A[i] and A[j] > A[j + 1]) {
                k = sum / A[i];
                sum -= A[i] * k;

                sum += k * A[j];
                k = 0;
                i = j;
                break;
            }
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
using ll = long long;
using ull = unsigned long long;

ll lcm(ll x, ll y){
  ll k = __gcd(x, y);
  ll z = (x / k)*y;
  return z;
}


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

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

  ll num = lcm(n, m);
  bool f = true;

  vector<pair<ll, char>> v(n);
  for(ll i = 0; i < n; i++){
    v[i].second = s[i];
    v[i].first = 1 + (num/n)*i;
    
    if((m * i) % n == 0 && (m * i) / n < m){
      if(v[i].second != t[(m * i) / n]){cout << -1 << endl; f = false; break;}
    }
  }


  if(f){cout << num << endl;}
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
void input()
{
	freopen("/home/rakib/input.txt","r",stdin);
	freopen("/home/rakib/output.txt","w",stdout);
}
int main()
{
//	input();
    string a,b;
    cin>>a>>b;
  int c = 0;
  for(int i=0;i<a.size();i++)
  {
    if(a[i]!=b[i])
      c++;
  }
  cout<<c<<endl;
   
}

Measured memory_bytes: 3840
if __name__ == '__main__':
    s = list(input())
    t = list(input())

    max_score = 0
    if len(s) == len(t):
        max_score = sum([s[j] == t[j] for j in range(len(t))])
    else:
        for i in range(0, len(s) - len(t)):
            score = sum([s[i + j] == t[j] for j in range(len(t))])
            if max_score < score:
                max_score = score
    print(len(t) - max_score)




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

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

	vector<char> ans;

	for (int i = 0; i < S.size();i++) {
		if (S.at(i) == '0') {
			ans.push_back('0');
		}
		else if (S.at(i) == '1') {
			ans.push_back('1');
		}
		else if(S.at(i)=='B' && ans.size()>0){
			ans.pop_back();
		}
	}

	for (int i = 0; i < ans.size();i++) {
		cout << ans.at(i);
	}
}

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

PA = [0]
for i, a in enumerate(A):
    PA.append(a + PA[-1])

res = float("inf")
for i in range(1, len(PA) - 1):
    if PA[i] == PA[-1] - PA[i]:
        res = 0
    res = min(res, abs(PA[-1] - PA[i] - PA[i]))

print(res)


Measured memory_bytes: 26220
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d, e, k;
    
    vector<int> s(5);
    
    for(int i = 0; i < 5; i++) cin >> s[i];
    
    cin >> k;
    for (int i = 0; i < 5; i++ ) {
        
        for (int j = 0; j < 5; j++ ) {
            if(k < s[j] - s[i]) {
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=405,INF=1<<30;
bool dead[MAX];//0 確実に生 1確実に死
bool either[MAX][MAX];
int N;

void go(int a,int b){
    
    if(dead[a]&&dead[b]) return;
    
    if(either[a][b]||dead[a]||dead[b]){
        either[a][b]=either[b][a]=1;
        dead[a]=1;
        dead[b]=1;
        
        for(int j=0;j<N;j++){
            if(j==a||j==b) continue;
            
            either[j][a]=either[a][j]=1;
            either[j][b]=either[b][j]=1;
        }
        
        return;
    }
    
    either[a][b]=either[b][a]=1;
    
    for(int j=0;j<N;j++){
        if(j==a||j==b) continue;
        
        if(either[j][a]||either[j][b]){
            either[j][a]=either[a][j]=1;
            either[j][b]=either[b][j]=1;
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int M;cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        go(a,b);
    }
    
    int ans=0;
    for(int i=0;i<N;i++) for(int j=i+1;j<N;j++) if(!either[i][j]) ans++;
    
    cout<<ans<<endl;
}


Measured memory_bytes: 3832
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    string s;
    cin >> s;
    int ans = 0;
    int pre = stoi(s.substr(0, 2));
    int post = stoi(s.substr(2, 2));
    if (pre > 0 && pre <= 12)
        ans = ans | 1;
    if (post > 0 && post <= 12)
        ans = ans | 2;
    if (ans == 0) {
        cout << "NA" << endl;
    } else if (ans == 1) {
        cout << "MMYY" << endl;
    } else if (ans == 2) {
        cout << "YYMM" << endl;
    } else if (ans == 3) {
        cout << "AMBIGUOUS" << endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int A,B,C,D,E,F;
  cin>>A>>B>>C>>D>>E>>F;
  int n=1,m=-1;
  for(int a=0;a*A*100<=F;a++){
    int x=F-a*A*100;
    for(int b=0;b*B*100<=x;b++){
      int y=min(x-b*B*100,(a*A+b*B)*E);
      for(int c=0;c*C<=y;c++){
        int d=(y-c*C)/D;
        if(m*(a*A+b*B)<(c*C+d*D)*n){
          n=a*A+b*B;
          m=c*C+d*D;
        }
      }
    }
  }
  cout<<n*100+m<<' '<<m<<endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define INF 1e18
#define MOD 1000000007
#define N 1000005
#define BB(V) V[V.size()-2]
#define ex(V) return printf(V),0
using namespace std;
int p[N];
int fnd(int x){return p[x]=p[x]==x?x:fnd(p[x]);}
void unn(int x,int y){p[fnd(y)]=fnd(x);}
int a[N];
int chk[N];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",a+i),p[i]=i;
	for(int i=0;i<m;i++){
		int t1,t2;
		scanf("%d%d",&t1,&t2);
		unn(t1,t2);
	}
	int cnt=0;
	for(int i=1;i<=n;i++)if(fnd(a[i])==fnd(i))cnt++;
	printf("%d",cnt);
}

Measured memory_bytes: 8448
#include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
int main(void){
    string ken="()[]";
    while(1){
        bool frg=true;
        string in,nate="";
        getline(cin,in);
        if(in==".")break;
        for(int s=0;s<in.length();s++){
            if(in[s]==ken[0]||in[s]==ken[2]){
                nate+=in[s];
            }
            if(in[s]==ken[1]){
                if(nate[nate.length()-1]==ken[0]){
                    string work=nate;
                    nate="";
                    for(int i=0;i<work.length()-1;i++){
                        nate+=work[i];
                    }
                }else{
                    frg=false;
                    break;
                }
            }
            if(in[s]==ken[3]){
                if(nate[nate.length()-1]==ken[2]){
                    string work=nate;
                    nate="";
                    for(int i=0;i<work.length()-1;i++){
                        nate+=work[i];
                    }
                }else{
                    frg=false;
                    break;
                }
            }
        }
        if(frg&&nate=="")cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1184
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
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;}


int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  set<ll> st;
  rep(i, n){
    ll x;
    cin >> x;
    st.insert(x);
  }
  int q;
  cin >> q;
  int res = 0;
  rep(i, q){
    ll x;
    cin >> x;
    if(st.find(x) != st.end())res++;
  }
  cout << res << endl;
	return 0;
}



Measured memory_bytes: 3116
InputData=[]
while True:
    try:
        in1,in2 = map(int,raw_input().split(" "))  # Python2
        if in1==0 and in2==0 : break
        InputData.append([in1,in2])
    except EOFError:
        break

for i in range(len(InputData)):
    in1,in2 = InputData[i]
    x = int(in1) * int(in2)
    y = (int(in1) + int(in2)) * 2
    print(str(x) + " " + str(y))

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef long long ll;

void solve() {
  int a, b, c, ans = 100000;
  cin >> a >> b >> c;
  ans = min(a + b, ans);
  ans = min(a + c, ans);
  ans = min(b + c, ans);
  cout << ans << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate nPm
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    string s; cin >> s;
    string ans = "";
    rep(i, s.size()) {
        if (s[i] == 'B') {
            if (ans != "") ans.pop_back();
        } else {
            ans += s[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
class DisjointSet:

    def __init__(self, N):
        self.parents = [i for i in range(N)]
        self.size = [1]*N

    def find_parent(self, x):
        path = []
        while self.parents[x] != x:
            x = self.parents[x]
            path.append(x)
        for p in path:
            self.parents[p] = x
        return x

    def find_size(self, x):
        return self.size[self.find_parent(x)]

    def union(self, x, y):
        root_x = self.find_parent(x)
        root_y = self.find_parent(y)
        if self.find_parent(root_x) != self.find_parent(root_y):
            self.parents[root_x] = root_y
            self.size[root_y] += self.size[root_x]


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, M, K = read_ints()
    disjoint_set = DisjointSet(N)
    suggestions = [-1]*N
    for _ in range(M):
        a, b = read_ints()
        a -= 1
        b -= 1
        disjoint_set.union(a, b)
        suggestions[a] -= 1
        suggestions[b] -= 1
    for _ in range(K):
        c, d = read_ints()
        c -= 1
        d -= 1
        if disjoint_set.find_parent(c) == disjoint_set.find_parent(d):
            suggestions[c] -= 1
            suggestions[d] -= 1
    return [disjoint_set.find_size(i)+suggestions[i] for i in range(N)]


if __name__ == '__main__':
    print(*solve())


Measured memory_bytes: 89396
/*
 * ID:  ITP1_10_B
 * Problem: Triangle
 */

#include <stdio.h>
#include <math.h>

int main(void)
{
    double a, b, C_degree;
    double h, c, S, L, C_radian;


    scanf("%lf %lf %lf", &a, &b, &C_degree);
    C_radian = M_PI * C_degree / 180.0;
    h = b * sin(C_radian);
    S = 0.5 * a * h;
    c = sqrt(a * a + b * b - 2 * a * b * cos(C_radian));
    L = a + b + c;

    printf("%f\n%f\n%f\n", S, L, h);

    return 0;
}



Measured memory_bytes: 2104
function plus (a, b) {
  return a + b;
}

function main (input) {
  const list = input.split('\n');
  const N = list[0] * 1;
  const W = list[1].split(' ').map(v => v * 1);
 
  var nArr = new Array(N).fill(0); 
  const abs = nArr.reduce((arr, val , i) => {
    const Ni = i + 1;
    const S1 = W.slice(0, Ni + 1).reduce(plus, 0);
    const S2 = W.slice(Ni + 1).reduce(plus, 0);
    const a = Math.abs(S1 - S2)
    arr.push(a);
    return arr;
  }, []);
  
  console.log(Math.min.apply(null, abs));
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));

Measured memory_bytes: 9420
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

al = input()
bl = input()
ans = 0
for i in range(0, 3):
    if(al[i] == bl[i]):
        ans += 1
print(ans)

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

#define pb push_back
#define fst first
#define snd second
#define ALL(s) s.begin(),s.end()
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define SZ(x) ((int)(x).size())
#define PI acos(-1)
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
using namespace std;

int main() {FIN;
    int n,k; cin>>n>>k;
    vector<int> v(n);
    fore(i,0,n) cin>>v[i];
    bool dp[k+1]; memset(dp,false,sizeof(dp));
    fore(i,0,k+1){
        fore(j,0,n) if(v[j]<= i) dp[i] |= !dp[i-v[j]];
    }
    if(dp[k]) cout<<"First\n";
    else cout<<"Second\n";
    return 0;
}



Measured memory_bytes: 3744
#include <ctype.h>
#include <stdio.h>
#include <string.h>

int W, H;
int map[100][100];
bool visited[100][100];

int dr[4] = {-1, 1, 0, 0};
int dc[4] = {0, 0, -1, 1};

void visitColor(int r, int c, char color) {
  for (int i = 0; i < 4; ++i) {
    int nr = r + dr[i];
    int nc = c + dc[i];
    if (nr >= 0 && nr < H && nc >= 0 && nc < W && !visited[nr][nc] && map[nr][nc] == color) {
      visited[nr][nc] = true;
      visitColor(nr, nc, color);
    }
  }
}

int getPartitions() {
  memset(visited, false, sizeof(visited));
  int result = 0;
  for (int r = 0; r < H; ++r) {
    for (int c = 0; c < W; ++c) {
      if (!visited[r][c]) {
        visited[r][c] = true;
        result++;
        visitColor(r, c, map[r][c]);
      }
    }
  }
  return result;
}

int main() {
  //freopen("PropertyDistribution.in", "r", stdin);
  while (scanf("%d%d", &H, &W) == 2 && H != 0 && W != 0) {
    for (int r = 0; r < H; ++r) {
      for (int c = 0; c < W; ++c) {
        char ch;
        do {
          ch = getchar();
        } while (isspace(ch));
        map[r][c] = ch;
      }
    }
    int result = getPartitions();
    printf("%d\n", result);
  }
  return 0;
}

Measured memory_bytes: 3132
#include<iostream>
using namespace std;
int a,b,c,d;
int main(){
cin>>a>>b>>c>>d;
if(a+b>c+d) cout<<"Left"<<endl;
if(a+b==c+d) cout<<"Balanced"<<endl;
if(a+b<c+d) cout<<"Right"<<endl;
return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:isize,
    b:isize,
    c:usize,
    d:[(isize,isize,usize);c],
    }
    let mut t=(0,b);
    let mut y=(0,a);
    for i in 0..c {
        if d[i].2==1 {
            y.0=max(y.0,d[i].0)
        }
        if d[i].2==2 {
            y.1=min(y.1,d[i].0)
        }
        if d[i].2==3 {
            t.0=max(t.0,d[i].1)
        }
        if d[i].2==4 {
            t.1=min(t.1,d[i].1)
        }
    }
    println!("{}",(max(0,(t.1-t.0)))*(max(0,y.1-y.0)))
}

Measured memory_bytes: 2116
#include <cstdio>
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

#define ll unsigned long long
#define pb push_back
using namespace std;
const int N = 100005;
int a[N], d[N];
int main () {
	int n;
	cin >> n;
	for (int i=0; i<n; i++) cin >> a[i];
	d[0]=0;
	d[1]=abs(a[0]-a[1]);
	for (int i=2; i<n; i++){
		d[i]=min(d[i-1]+abs(a[i]-a[i-1]),d[i-2]+abs(a[i]-a[i-2]));
	}
	cout << d[n-1];
	return 0;
}

Measured memory_bytes: 1024
//int -> ll
//http://web.mit.edu/~ecprice/acm/acm08/notebook.html#file12
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include<bits/stdc++.h>
typedef long long ll;
#define x first
#define y second
#define REP(i,sss,eee) for(int i=sss;i<=eee;++i)
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
std::vector<double> inp;
std::vector<std::vector<double>> dp;
int main(){
	int n;cin>>n;
	inp.resize(n+1);
	REP(i,1,n){cin>>inp[i];}
	int tar=((n/2)+1);
	dp.resize(n+1,std::vector<double>(n+1,0));
	dp[0][0]=1;
	for(int move=1;move<=n;++move)
	{
		for(int hnum=0;hnum<=move;++hnum)
		{
			if(hnum==0){dp[move][hnum]=(dp[move-1][hnum]*(1-inp[move]));}
			dp[move][hnum]=((dp[move-1][hnum-1]*inp[move])+(dp[move-1][hnum]*(1-inp[move])));
		}
	}
	double ans=0;
	REP(i,tar,n)
	{
		ans+=dp[n][i];
	}
	printf("%.15lf\n",ans);
}

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

int N;

long long  gcd(long long  a, long long  b){
	if(a%b==0) return b;
	else gcd(b,a%b);
}

int main(){
	while(cin >> N){
		long long ans = 1;
		for(int i=0;i<N;i++){
			long long a;
			cin >> a;
			long long  r = gcd(ans,a);
			ans *= a/r;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

const int MAXK=1000;
int a[3*MAXK][3*MAXK];
int s[2][MAXK][MAXK];

int main(){
  int N,K;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    int x,y;
    char c;
    cin>>x>>y>>c;
    if(c=='W') y+=K;
    x%=2*K, y%=2*K;
    a[x][y]++;
    a[x+K][y+K]++;
    a[x+K][y]--;
    a[x][y+K]--;
  }
  for(int i=0;i<3*K;i++){
    for(int j=0;j<3*K-1;j++){
      a[i][j+1]+=a[i][j];
    }
  }
  for(int i=0;i<3*K;i++){
    for(int j=0;j<3*K-1;j++){
      a[j+1][i]+=a[j][i];
    }
  }
  for(int i=0;i<3*K;i++){
    for(int j=0;j<3*K;j++){
      int k=(i/K+j/K)%2; //color
      s[k][i%K][j%K]+=a[i][j];
    }
  }
  int ans=0;
  for(int k=0;k<2;k++){
    for(int i=0;i<2*K;i++){
      for(int j=0;j<2*K;j++){
        ans=max(ans,s[k][i][j]);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 43264
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int a[] = new int[100002];
        int c[] = new int[100002];
        for(int i = 1; i <= n; i++)
        {
            a[i] = sc.nextInt();
        }
        for(int i = 1; i <= n + 1; i++)
        {
        	c[i] = Math.abs(a[i - 1] - a[i]) + c[i - 1];
        }
        
        for(int i = 1; i <= n; i++)
        {
        	System.out.println(c[i - 1] + Math.abs(a[i - 1] - a[i + 1]) + (c[n + 1] - c[i + 1]));
        }
	}
}

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

int main(){
  int n,minj,N[100],swapnumber=0;
  cin>>n;
  for(int i=0;i<n;i++)cin>>N[i];
  for(int i=0;i<n;i++){
    minj=i;
    for(int j=i;j<n;j++)if(N[j]<N[minj])minj=j;
    if(N[i]>N[minj]){
      swap(N[i],N[minj]);
      swapnumber++;
    }
  }
  for(int i=0;i<n;i++){
    if(i!=n-1)cout<<N[i]<<" ";
    else cout<<N[i]<<endl;
  }
  cout<<swapnumber<<endl;
return 0;
}

Measured memory_bytes: 1160
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
public static class P {
  public static void Main() {
    var abx = Console.ReadLine().Split().Select(int.Parse).ToArray();
    double a = abx[0];
    double b = abx[1];
    double x = abx[2];
    x /= a;
    double res;
    if (x >= a * b / 2) res = Calc(a, (a * b - x) * 2 / a);
    else res = Calc(x * 2 / b, b);
    Console.WriteLine(res);
  }
  public static double Calc(double a, double b) => Atan(b / a) / PI * 180;
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <stdlib.h>

#define D_MAX 1000000000
#define N_MAX 100000
#define M_MAX 10000
#define min(x,y) (((x)<(y))?(x):(y))

int d;
int n;
int m;

int ad[N_MAX+1];
int ak[M_MAX+1];


void MergeSort(int array[],int left,int right){
  int awork[N_MAX+1];
  int mid;
  int i;
  int j;
  int x;
  int y;
  
  if( left >= right ){
    return;
  }
  
  mid = (left + right) / 2;
  MergeSort( array, left, mid);
  MergeSort( array, mid+1, right);
  
  for( i=left; i<=mid; i++){
    awork[i] = array[i];
  }
  
  j = right;
  for( i=mid+1; i<=right; i++){
    awork[i] = array[j];
    j--;
  }
  
  x = left;
  y = right;
  
  for( i=left; i<=right; i++){
    if(awork[x] <= awork[y]){
      array[i] = awork[x];
      x++;
    }else{
      array[i] = awork[y];
      y--;
    }
  }
}


int calcDist(void){
  int i;
  int j = 1;
  int sum = 0;
  int diff;
  int preDiff = 0;
  int minDist = d;
  int tmpDist;
  int halfDist = d >> 1;
  
  for( i=1; i<=m; i++){
    
    while(ad[j] < ak[i]){
      j++;
    }
    minDist = min( abs(ad[j-1]-ak[i]),abs(ad[j]-ak[i]) );
    sum += minDist;
    
  }
  
  return sum;
}


void input(void){
  int i;
  scanf("%d",&d);
  if( d != 0){
    scanf("%d",&n);
    scanf("%d",&m);
    ad[0] = 0;
    for( i=1; i<=n-1; i++){
      scanf("%d",&ad[i]);
    }
    ad[n] = d;
    for( i=1; i<=m; i++){
      scanf("%d",&ak[i]);
    }
  }
}

int main(void){
  int i;
  int sumDist = 0;
  while( 1 ){
    input();
    if( d == 0 ){
      break;
    }
    MergeSort( ad, 0, n);
    MergeSort( ak, 1, m);
    sumDist = calcDist();
    printf("%d\n",sumDist);
    sumDist = 0;
  }
}




Measured memory_bytes: 8836
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    title = defaultdict(int)
    cumsum = [0]
    for i in range(1, N + 1):
        s, t = readline().strip().decode('utf-8').split()
        title[s] = i
        cumsum.append(cumsum[-1] + int(t))
    X = readline().decode('utf-8').strip()
    ans = cumsum[-1] - cumsum[title[X]]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9436
s = input()
a = ["R", "U", "D"]
b = ["L", "U", "D"]

ans = "Yes"
for i in range(len(s)):
    if i%2 == 0:
        if s[i] not in a:
            ans ="No"
    else:
        if s[i] not in b:
            ans = "No"
print(ans)


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

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

    vector<int> A(N);
    for_(i,0,N) cin >> A[i];

    sort(ALL(A));
    reverse(ALL(A));

    lint ans = A[0];
    multiset<int> S = {A[1]};

    for (int i=2; i<N; i += 2) {
        auto it = S.end(); --it;
        
        ans += *it;
        S.insert(A[i]);

        if (i + 1 < N) {
            ans += *it;
            S.insert(A[i + 1]);
        }

        S.erase(it);
    }

    cout << ans << endl;
}

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

const ll mod=1e9+7;

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

/*-------------------------------------------*/

template<typename T,typename E>
struct SegmentTree{
private:
    typedef function<T(T,T)> F;
    typedef function<T(T,E)> G;
    int n;
    T identity;
    F f;
    G g;
    vector<T> dat;
    void init(int n_){
        n=1;
        while(n<n_)n*=2;
        dat.assign(2*n-1,identity);
    }
    void build(int n_,vector<T> v){
        for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
        for(int i=n-2;i>=0;i--) dat[i]=f(dat[i*2+1],dat[i*2+2]);
    }

public:
    SegmentTree(int n_,F f,G g,T id,vector<T>v=vector<T>()):identity(id),f(f),g(g){
        init(n_);
        if(n_==(int)v.size()) build(n_,v);
    }
    void update(int k,E a){
        k+=n-1;
        dat[k]=g(dat[k],a);
        while(k>0){
            k=(k-1)/2;
            dat[k]=f(dat[k*2+1],dat[k*2+2]);
        }
    }
    T query(int a,int b){
        T vl=identity,vr=identity;
        for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1){
            if(l&1) vl=f(vl,dat[(l++)-1]);
            if(r&1) vr=f(dat[(--r)-1],vr);
        }
        return f(vl,vr);
    }
};

struct s{
    int l,r;
    ll c;
    bool operator<(const s&R)const{return l!=R.l?l<R.l:r<R.r;}
};

int main(){
    int n,m;
    cin>>n>>m;
    vector
v(m);
    rep(i,m){
        int l,r;
        ll c;
        cin>>l>>r>>c;
        v[i]={l-1,r-1,c};
    }
    sort(v.begin(),v.end());
    SegmentTree<ll,ll> dp(
        n,
        [](ll a,ll b){return min(a,b);},
        [](ll a,ll b){return min(a,b);},
        1e18
    );
    dp.update(0,0);
    rep(i,m){
        dp.update(v[i].r,dp.query(v[i].l,v[i].r)+v[i].c);
    }
    cout<<(dp.query(n-1,n)<1e18?dp.query(n-1,n):-1)<<endl;
}

Measured memory_bytes: 3840
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <stack>
#include <string>

using namespace std;

typedef long long LL;

int n;
char s[11111];

int main() {
    cin >> n;
    
    scanf("%s",s);
    for (int i = 0; s[i]; ++i) {
        char c = s[i] + n%26;
        if(c>'Z') c-=26;
        printf("%c",c);
    }
    cout << endl;
}

Measured memory_bytes: 256