akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

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

  for(i = 0 ; i <= VMAX ; i++)
    {
      C[i] = 0;
    }

  for(j = 1 ; j <= n ; j++)
    {
      C[A[j]]++;
    }

  for(i = 1 ; i <= VMAX ; i++)
    {
      C[i] += C[i-1];
    }

  for(j = n ; j > 0 ; j--)
    {
      B[C[A[j]]] = A[j];
      C[A[j]]--;
    }

  for(i = 1 ; i <= n ; i++)
    {
      printf("%d",B[i]);
      if(i <= n-1) printf(" ");
    }

  printf("\n");
  
  return 0;
}



Measured memory_bytes: 9708
(let* ((n (read))
       (ans 0)
       (p (make-hash-table :test 'equal :size (expt 10 6))))
  (loop :for i :from 1 :to n
        :do (let ((s (read-line)))
              (unless (gethash s p)
                (setf (gethash s p) t)
                (incf ans))))
  (format t "~A~%" ans))


Measured memory_bytes: 94252
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a>c){
    if(c>b) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else{
    if(b>c) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<ll,P> event;

const ll MAX = 510000;
const ll MOD = 1000000007;
const int INF = 1<<30;
vector<set<int> > st;
int main() {
  int N;  
  string S;
  int Q;
  cin>>N>>S>>Q;
  st.assign(26,set<int>({INF}));
  rep(i,N){
    st[S[i]-'a'].insert(i);
  }
  rep(i,Q){
    int a;
    cin>>a;
    if(a==1){
      int b;
      char c;
      cin>>b>>c;b--;
      st[S[b]-'a'].erase(b);
      st[c-'a'].insert(b);
      S[b]=c;
    }
    if(a==2){
      int l,r;
      cin>>l>>r;
      l--;
      int ans=0;
      rep(j,26){
        int g=*st[j].lower_bound(l);
        int h=*st[j].lower_bound(r);
        if(g<h){ans++;}
      }
      cout<<ans<<endl;
    }
  }
}

Measured memory_bytes: 27196
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define REPE(i, a, b) for (int i = (a); i <= int(b); ++i)
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
#define PB push_back
#define EB emplace_back
using LL = long long;
using PII = pair<int, int>;
#define F first
#define S second
int n, m;
char s[111];
int c[128];

int main() {
  scanf("%d%d", &n, &m);
  REP(i, n) {
    scanf("%s", s);
    REP(j, m) c[s[j]]++;
  }
  int c4 = (n / 2) * (m / 2) * 4;
  int c1 = (n & 1) * (m & 1);
  int c2 = ((n & 1) ? m : 0) + ((m & 1) ? n : 0) - c1 * 2;
  REP(i, 128) {
    if (c[i] == 0) continue;
    int t = min(c4, c[i] / 4 * 4);
    c4 -= t;
    c[i] -= t;
    t = min(c2, c[i] / 2 * 2);
    c2 -= t;
    c[i] -= t;
    t = min(c1, c[i]);
    c1 -= t;
    c[i] -= t;
    if (c[i]) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");

  return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                               \
  cerr << #v << ": ";                              \
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", "; \
  cerr << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()

int main() {
  int N;
  cin >> N;
  vi ans(N + 1);

  REP(i, N - 1) {
    int tmp;
    cin >> tmp;
    ans[tmp]++;
  }

  FOR(i, 1, N + 1) { cout << ans[i] << endl; }
}


Measured memory_bytes: 4048
import math
n = int(input())
a = ["M","A","R","C","H"]
dic = {}
def combination(n,r):
	return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
for i in range(n):
	x = input()
	if x[0] in a:
		if x[0] in dic:
			dic[x[0]] += 1
		else:
			dic[x[0]] = 1
b = []
for i in dic.values():
	b.append(i)

ans = 0
for i in range(len(dic)):
	for j in range(i+1,len(dic)):
		for k in range(j+1,len(dic)):
			ans += b[i]*b[j]*b[k]
print (ans)

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int h, w; cin >> h >> w;
    vector<string> a(h);
    for(int i = 0; i < h; i++) cin >> a[i];

    for(int i = 0; i <= w + 1; i++) cout << "#";
    cout << endl;

    for(int i = 0; i < h; i++){
        cout << "#";
        cout << a[i];
        cout << "#" << endl;
    }

    for(int i = 0; i <= w + 1; i++) cout << "#";
    cout << endl;
}


Measured memory_bytes: 256
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-26 21:00:48
*/

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

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if (ceil((double)c/b) <= ceil((double)a/d)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

int p,n;

struct data{
  double a,b; // a/b
  data(){}
  data(double a, double b):a(a),b(b){}
  double getValue(){return a/b;}
  bool operator < (const data& d) const { return a/b < d.a/d.b;}
};

vector<data> V;


void init(){
  V.clear();
}

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

void solve(){

  data up((1<<20),1),low(-1,1);

  for(int i = 1; i <= n; i++)
    for(int j = 1; j <= n; j++){
      data tmp(i,j);
      if(tmp.getValue() < sqrt(p) && gcd(i,j) == 1){
        if(low < tmp) low = tmp; 
        break;
      }

      if(up.getValue() > tmp.getValue() && gcd(i,j) == 1) up = tmp; 
    }

  cout << up.a << "/" << up.b << " " << low.a << "/" << low.b << endl;
}

int main(){

  while(cin >> p >> n && p+n){
    init();
    solve();
  }
  return 0;
}

Measured memory_bytes: 1232
n = int(input())

a = list(map(int,input().split()))
#print(a)
q = int(input())
z = [0 for i in range(100001)]
for i in range(len(a)):
    z[a[i]] += 1
x = sum(a)
b = []
for _ in range(q):
    b.append(list(map(int,input().split())))
#print(b)


for i in range(q):
    x += (b[i][1] - b[i][0]) * z[b[i][0]]
    z[b[i][1]] += z[b[i][0]]
    z[b[i][0]] = 0
    print(x)

Measured memory_bytes: 32920
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  cin.tie(0);
  double a, b, x;
  cin >> a >> b >> x;
  double menseki = x / a;
  if (menseki * 2 <= a * b) {
    double l = menseki * 2 / b;
    double kakudo = atan(l / b);
    printf("%.10f\n", 90 - kakudo * 180 / M_PI);
  } else {
    menseki = a * b - menseki;
    double l = menseki * 2 / a;
    double kakudo = atan(l / a);
    printf("%.10f\n", kakudo * 180 / M_PI);
  }
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main (void)
{
   
	int W, H, x, y, r;


	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if(x<0||y<0)
	{
		printf("No\n");
	
	}
	
	else
	{
		if(r>x||r>y)
		{
			printf("No\n");
		}
		else
		{
			if((r+x)<=W && (r+y)<=H)
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}

	}
     return 0;
}

Measured memory_bytes: 584
using System;
using System.Collections.Generic;
class Pg
{
    static void Main()
    {
        var pm = new Prime();
        var prLst = new List<int>();
        var ansLst = new List<string>();
        var prime = pm.prime();
        for (int n; (n = int.Parse(Console.ReadLine())) != 1;prLst.Clear())
        {
            for (int i = 2; i < Prime.MAX; ++i)
            {
                if (!prime[i] && n % i == 0)
                    prLst.Add(i);
            }

            ansLst.Add(string.Concat(n,": ",string.Join(" ",prLst)));
        }
        Console.WriteLine(string.Join("\n", ansLst));
    }
}
class Prime
{
    internal const int MAX = 300000;
    internal bool[] prime()
    {
        var prime = new bool[MAX];

        for (int i = 2; i <= MAX; ++i)
        {
            if (i % 7 == 1 || i % 7 == 6)
            {
                for (int j = 6; i * j < MAX; ++j)
                {
                    prime[i * j] = true;
                }
            }
            else
            {
                prime[i] = true;
            }
        }
        return prime;
    }
}



Measured memory_bytes: 20028
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = new String();
        try {
			while ((line = br.readLine()) != null) {
			    String[]	as  = line.split(" ");
			    int			n1 = Integer.parseInt(as[0]);
			    int			n2 = Integer.parseInt(as[1]);
			    String		s1 = String.valueOf(n1 + n2);
			    System.out.println(s1.length());
			}
		}
        catch (Exception e) {}
	}
}

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

int N;
vector<vector<int>> G;
vector<int> V;
int ans;

void dfs(int v, int cnt) {
  if (cnt == N) {
    ans++;
    return;
  }
  V.at(v) = 1;
  for (int i = 0; i < G.at(v).size(); i++)
    if (!V.at(G.at(v).at(i)))
      dfs(G.at(v).at(i), cnt + 1);
  V.at(v) = 0; 
}

int main() {
  int M;
  cin >> N >> M;
  G.resize(N + 1), V.resize(N + 1);
  for (int i = 0, a, b; i < M && cin >> a >> b; i++)
    G.at(a).push_back(b), G.at(b).push_back(a);
  dfs(1, 1);
  cout << ans << "\n";
}

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

cnt = K
ans = ''

for s in S:
    if s == 'a':
        ans += 'a'
    elif cnt >= 123 - ord(s):
        cnt -= 123 - ord(s)
        ans += 'a'
    else:
        ans += s

last = ans[-1]
last = chr((ord(last) - 97 + cnt) % 26 + 97)
print(ans[:-1] + last)


Measured memory_bytes: 3572
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    string symmetric(256, ' ');
    symmetric['('] = ')';
    symmetric[')'] = '(';
    symmetric['['] = ']';
    symmetric[']'] = '[';
    symmetric['{'] = '}';
    symmetric['}'] = '{';

    string s;
    cin >> s;
    int n = s.size();

    int ret = 0;
    for(int i=0; i<(1<<n); ++i){
        bitset<15> bs(i);
        int m = bs.count();
        if(m < 3 || m % 2 == 0)
            continue;
        string t;
        for(int j=0; j<n; ++j){
            if(bs[j])
                t += s[j];
        }

        int a = 0;
        int b = m-1;
        while(b - a > 2){
            if(symmetric[t[a]] != t[b])
                break;
            ++ a;
            -- b;
        }
        if(b - a == 2 && t.substr(a, 3) == "iwi")
            ret = max(ret, m);
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
void chmin(LL& a, LL b) {
	a = min(a, b);
}
//////////////

void solve() {
	int N;
	cin >> N;
	string word = "MARCH";
	vector<LL>A(5,0);
	for (int i = 0; i < N; ++i) {
		string S;
		cin >> S;
		for (int j = 0; j < 5; ++j) {
			if (S[0] == word[j]) {
				A[j]++;
			}
		}
	}
	LL ans = 0;
	for(int a=0;a<5;++a)
		for (int b = a+1; b < 5; ++b)
			for (int c = b + 1; c < 5; ++c) {
				ans += A[a] * A[b] * A[c];
			}
				
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
m0 = 0
m1 = 0
m2 = 0

if n%2 == 0:
    for i,ai in enumerate(a):
        if i%2 == 0:
            m0 += ai
        else:
            m1 = max(m0,m1+ai)
    print(max(m0,m1))
else:
    for i,ai in enumerate(a):
        if i%2 == 0:
            if i > 0:
                m2 = max(m2+ai,m1,m0)
            if i < n-1:
                m0 += ai
        else:
            m1 = max(m0,m1+ai)
    print(max(m0,m1,m2))


Measured memory_bytes: 31640
n,m = [int(x) for x in input().split()]
x = sorted([int(x) for x in input().split()])
l = sorted([abs(x[i+1] - x[i]) for i in range(m-1)], reverse=True)

ans = 0

if not l:
    pass
else:
    ans = sum(l[n-1:])

print(ans)

Measured memory_bytes: 13832
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n, ans = 0;
	string s;

	cin >> n >> s;
	char prev = '!';
	for (int i = 0; i < n; i++) {
		if (s.at(i) == prev) {
			continue;
		}
		ans++;
		prev = s.at(i);
	}
	cout << ans << endl;

	return 0;
}

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

int main()
{
	string set;
	int m;

	while(1) {
		cin >> set;
		if (set.compare(string("-")) == 0) break;
		cin >> m;

		int h;
		for (int i = 0; i < m; i++) {
			cin >> h;
			string move;
			for (int j = 0; j < h; j++)
				move[j] = set[j];
			for (int k = h; k < set.length(); k++)
				set[k-h] = set[k];
			for (int k = 0; k < h; k++)
				set[k+set.length()-h] = move[k];
		}

		for (int i = 0; i < set.length(); i++)
			cout << set[i];
		cout << endl;
	}
}

Measured memory_bytes: 1208
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        ArrayList<String> ar = new ArrayList<>();
        for(int i = 0; i < n; i++){
            ar.add(sc.next());
        }
        Collections.sort(ar);
        for(String st: ar)
            System.out.printf("%s", st);
        System.out.println();
    }
}

Measured memory_bytes: 22740
import java.util.*

// 最大文字数は12
// 本当は 5の12乗にしないといけないと思うが、メモリオーバーで通らないから
val dictionary = BooleanArray(Math.pow(5.0, 11.0).toInt()) { false }

fun getKey(c: Char) = when (c) {
    'A' -> 1
    'C' -> 2
    'G' -> 3
    'T' -> 4
    else -> 0
}

// Aを1、Cを2、Gを3、Tを4とする5進数の10数表現を返す.
fun getKey(str: String): Int {
    var key = 0
    var p = 1
    str.forEach {
        key += p * getKey(it)
        p *= 5
    }
    return key
}

fun insert(str: String) {
    dictionary[getKey(str)] = true
}

fun find(str: String): Boolean = dictionary[getKey(str)]

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextLine().toInt()
    repeat(n) {
        val inst = scanner.nextLine().split(" ")
        when {
            inst[0] == "insert" -> {
                insert(inst[1])
            }
            inst[0] == "find" -> {
                if (find(inst[1])) {
                    println("yes")
                } else {
                    println("no")
                }
            }
        }
    }
}



Measured memory_bytes: 490288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    multiset<int> rest;
    cin >> N;
    for(int i = 1; i <= pow(2, N); i++) {
        int s;
        cin >> s;
        rest.insert(s);
    }
    auto itr = rest.end();
    itr--;
    multiset<int> exist;
    exist.insert(*itr);
    rest.erase(itr);
    for(int day = 1; day <= N; day++) {
        multiset<int> NEW;
        for(auto itr = exist.begin(); itr != exist.end(); itr++) {
            auto itr2 = rest.lower_bound(*itr);
            if(itr2 == rest.begin()) {
                cout << "No" << endl;
                return 0;
            }
            itr2--;
            NEW.insert(*itr2);
            rest.erase(itr2);
        }
        for(auto itr = NEW.begin(); itr != NEW.end(); itr++) {
            exist.insert(*itr);
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 18816
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n, k; cin >> n >> k;
    vector<ll> A(n); rep(i, n) cin >> A[i];
    multiset<ll> mst;
    for(int left=0; left<n; left++){
        ll sum = 0;
        for(int right = left; right < n; right++){
            sum += A[right];
            mst.insert(sum);
        }
    }
    ll res = 0;
    for(ll mask = pow(2,40); mask>0; mask /= 2){
        int cnt = 0;
        for(auto a: mst){
            if(a&mask)cnt++;
        }
        if(cnt>=k){
            res += mask;
            for(auto a: mst){
                if(!(a&mask))mst.erase(a); 
            }
        }
    }
    cout << res << ln;
}


Measured memory_bytes: 26988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
//#define s second
#define f first
long long const mod = 1000000007; 
#define inf 1000000000000000000
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod)+mod)%mod;}
inline ll mul(ll a, ll b){ return (((a%mod)*(b%mod))%mod+mod)%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

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

ll power(ll x,ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
}

ll modInv(ll x)
{
    return power(x,mod-2,mod)%mod;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
        
   
    ll n,k;
    cin>>n>>k;
    ll ans=power(k,n,mod);
    //ll total=pow(k,n);
    ll count=0;
    ll arr[k+1];

    for(ll i=k;i>=2;i--)
    {
        ll num=k/i;
        ll z1=power(num,n,mod);
        ll z2=0;
        ll ans2=0;
        ans2=(ans2+z1)%mod;

        

        for(ll j=i*2;j<=k;j=j+i)
        {
           // if(vis[j])
             //   continue;
            //vis[j]=true;
            if(j<=k)
                z2=arr[j];
            else 
                break;
            ans2=sub(ans2,z2);
        }
        arr[i]=ans2;
        ans=add(ans,mul(ans2,i-1));
        
        //count=(count+z1)%mod;
        
       // ans=sub(ans,z);
       // cout<<z<<" "<<ans<<endl;
    }
   // ll diff=sub(total,count);
    //cout<<total<<" "<<count<<" "<<diff<<endl;
    //ans=add(ans,diff);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4280
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<deque>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int mp[440000];
int num[220000];

int main()
{
	int *dp = mp + 220000;
	int n,m;cin >> n >> m;
	vector<int> v(n);
	REP(i,n)
	{
		cin >> v[i];v[i]--;
		dp[v[i]-num[v[i]]]++;
		num[v[i]]++;
	}

	int ret = 0;
	for(int i = 0; i < n;i++)
	{
		if(dp[i] == 0)ret++;
	}
	
	REP(i,m)
	{
		int a,b;cin >> a >> b;a--;b--;
		num[v[a]]--;
		dp[v[a]-num[v[a]]]--;
		if(v[a]-num[v[a]] >= 0&&dp[v[a]-num[v[a]]] == 0)ret++;
		v[a] = b;
		dp[v[a]-num[v[a]]]++;
		if(v[a]-num[v[a]] >= 0&&dp[v[a]-num[v[a]]] == 1)ret--;
		num[v[a]]++;
		cout << ret << endl;
//		SHOW1d(v,n);
//		SHOW1d(dp,n);
	}
	
	return 0;
}

Measured memory_bytes: 3840
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

struct Sieve {
    int n;
    vector<int> f, primes, sum;
    Sieve(int n=1):n(n), f(n+1), sum(n+1) {
        f[0] = f[1] = -1;
        for(int64_t i=2; i<=n; ++i) {
            sum[i] = sum[i-1];
            if(f[i]) continue;
            if(i&1 && f[(i+1)/2] == (i+1)/2) {
                ++sum[i];
            }
            primes.push_back(i);
            f[i] = i;
            for(int64_t j = i*i; j <= n; j += i) {
                if(!f[j]) f[j] = i;
            }
        }
    }
    //素数判定
    bool isPrime(int x) {return f[x] == x;}
    //素数列挙
    vector<int > factorList(int x) {
        assert(x <= n);
        vector<int> res;
        while(x != 1) {
            res.emplace_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    //素因数分解　pair(素数, 素因数の数)
    vector<pair<int, int> > factor(int x) {
        vector<int> fl = factorList(x);
        if(fl.size() == 0) return {};
        vector<pair<int, int> > res(1, pair<int, int>(fl[0], 0));
        for(int p : fl) {
            if(res.back().first == p) {
                ++res.back().second;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
} P(100000);

int main() {
    int q;
    cin >> q;
    vi l(q), r(q);
    rep(i, q) {
        cin >> l[i] >> r[i];
    }

    rep(i, q) {
        cout << P.sum[r[i]]-P.sum[l[i]-1] << '\n';
    }
}

Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
// #define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
// #define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
// using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int BinarySearch(int key,int n,int S[]){
    int l=0,r=n;
    while(r-l>1){
        int mid=(l+r)/2;
        if(S[mid]>key)r=mid;
        else l=mid;
    }
    return S[l]==key?1:0;
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8
ll dp[3][200007];

int main(){
    char  S[200007];
    int cnt=0;
    cin >> S;
    dp[0][0]=1;
    dp[1][1]=1;
    dp[2][2]=1;
    for(int i=0;i<strlen(S);i++){
        rep(j,3){
            if(j==0 && i>0 && S[i]!=S[i-1]){
                dp[j][i]=max(dp[0][i-1]+1,max(dp[1][i-1]+1,max(dp[2][i-1]+1,dp[j][i])));
            }
            if(j==0 && i>0){
                dp[j][i]=max(dp[1][i-1]+1,max(dp[2][i-1]+1,dp[j][i]));
            }
            if(j==1 && i>1 ){
                dp[j][i]=max(dp[0][i-2]+1,max(dp[1][i-2]+1,max(dp[2][i-2]+1,dp[j][i])));
            }
            if(j==1 && i>2 ){
                dp[j][i]=max(dp[0][i-3]+1,max(dp[1][i-3]+1,max(dp[2][i-3]+1,dp[j][i])));
            }
        }
    }
    cout << max(dp[0][strlen(S)-1],max(dp[1][strlen(S)-1],dp[2][strlen(S)-1])) <<endl;
}

Measured memory_bytes: 5112
package main

import "fmt"

func main() {
	var n int
	x := make([]string, 20)
	y := make([]float64, 20)

	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&y[i])
		fmt.Scan(&x[i])
	}

	ans := 0.0
	for i := 0; i < n; i++ {
		if x[i] == "JPY" {
			ans += y[i]
		} else if x[i] == "BTC" {
			ans += y[i] * 380000.0
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;

struct uu{
    int nr, bonus, ds;
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (argc == 2 && atoi(argv[1]) == 123456789)
        freopen("d:\\code\\cpp\\stdin", "r", stdin);

   // double start = clock();

   int d, g;
   cin >> d >> g;
   vector<uu> pc(d);
   for(int i=0; i<d; i++) {
       cin >> pc[i].nr >> pc[i].bonus;
       pc[i].ds = (i+1)*100;
   }
   //sort(pc.begin(), pc.end());

    vector<int> ii(d);
    for(int i=0; i<d; i++)
        ii[i] = i;

    int sol = 1e9;
    while(1){
        int nr = 0;
        int score = 0;
        for(int i=0; i<d; i++){
            int j = ii[i];
            if ( (g-score+pc[j].ds-1)/pc[j].ds < pc[j].nr ){
                nr += (g-score+pc[j].ds-1)/pc[j].ds;
                score += nr*pc[j].ds;
            }
            else{
                nr += pc[j].nr;
                score += pc[j].nr*pc[j].ds + pc[j].bonus;
            };
            if (nr > sol)
                break;
            if (score >= g)
                break;
        }
        sol = min(sol, nr);
        if (!next_permutation(ii.begin(), ii.end()))
            break;
   }
    cout << sol << endl;
    //cout << (clock()-start)/CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
    int a, b;
    char str[128];

    while (scanf("%d %d", &a, &b) == 2){
        sprintf(str, "%d", a + b);
        printf("%d\n", strlen(str));
    }

    return (0);
}

Measured memory_bytes: 612
unittest
{
	assert( [ "5 3" ].parse.expand.solve == 9 );
	assert( [ "3 4" ].parse.expand.solve == 7 );
	assert( [ "6 6" ].parse.expand.solve == 12 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ab = input.front.split.to!( long[] );
	return tuple( ab[ 0 ], ab[ 1 ] );
}

auto solve( long a, long b )
{
	if(      b < a ) return a + a - 1;
	else if( a < b ) return b + b - 1;
	else             return a + b;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 3017.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  n = unique(as, as + n) - as;
  //printf("n=%d:", n);
  //for (int i = 0; i < n; i++) printf(" %d", as[i]); putchar('\n');
  
  int maxl = 1;
  for (int i = 0; i + 1 < n;) {
    int j = i + 1;
    if (as[i] < as[j])
      while (j < n && as[j - 1] < as[j]) j++;
    else
      while (j < n && as[j - 1] > as[j]) j++;
    int l = j - i;
    //printf("(%d-%d)=%d\n", i, j, l);
    if (maxl < l) maxl = l;
    i = j - 1;
  }

  printf("%d\n", maxl);
  return 0;
}



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

int main() {
  const long long INF = 1LL << 60;
  int h[100010];
  long long dp[100010];
  for (int i = 0; i < 100010; ++i) dp[i] = INF;
  dp[0] = 0LL;

  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> h[i];
  }

  for (int i = 0; i < N; ++i) {
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i+1] - h[i]));
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i+2] - h[i]));
  }

  cout << dp[N - 1] << endl;

  return 0;
}


Measured memory_bytes: 1408
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;

// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin)
  {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
  {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next()
  {
    if (idx < str.length)
    {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0)
    {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)()
  {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len)
  {
    T[] ret = new T[len];

    foreach (ref c; ret)
    {
      c = next!(T);
    }

    return ret;
  }

  void scan()()
  {
  }

  void scan(T, S...)(ref T x, ref S args)
  {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType))
  {
    str ~= s.to!(char[]).strip.split;
  }
}

//Digit count---{{{
int DigitNum(int num) {
  int digit = 0;

  while (num != 0) {
    num /= 10;
    digit++;
  }

  return digit;
}
//}}}
//}}}

void main() {
  Scanner sc = new Scanner;

  int N, M;
  sc.scan(N, M);

  int[] like = new int[M];
  like[] = 0;

  foreach (i; 0 .. N) {
    int K;
    sc.scan(K);

    int tmp;
    foreach (j; 0 .. K) {
      sc.scan(tmp);
      like[tmp - 1]++;
    }
  }

  int sum = 0;
  foreach (i; 0 .. M) {
    if (like[i] == N) {
      sum++;
    }
  }


  writeln(sum);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int N;
int x[10], y[10];

int main() {
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> x[i] >> y[i];

  double dist[10][10];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int diff_x = x[i] - x[j];
      int diff_y = y[i] - y[j];
      dist[i][j] = sqrt(diff_x * diff_x + diff_y * diff_y);
    }
  }

  vector<int> perm;
  for (int i = 0; i < N; i++)
    perm.push_back(i);

  double d = 0.;
  int count = 0;
  do {
    for (int i = 0; i < N - 1; i++) {
      d += dist[perm[i]][perm[i + 1]];
    }
    count++;
  } while (next_permutation(perm.begin(), perm.end()));
  d /= count;
  cout << fixed << setprecision(15) << d << endl;

  return 0;
}


Measured memory_bytes: 3784
N = int(input())
a = list(map(int, input().split()))
acc = [0] * (N + 1)
for i in range(N):
    acc[i + 1] = acc[i] + a[i]
result = 10 ** 15
for i in range(1, N):
    x = acc[i]
    y = acc[N] - x
    result = min(result, abs(x - y))
print(result)

Measured memory_bytes: 23800
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int n, m, k;
constexpr ll mod = 1e9 + 7;
ll fact[300000], finv[300000], inv[300000];
void init() {
	fact[0] = fact[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i <= n * m; i++) {
		fact[i] = fact[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll ncr(ll n, ll r) {
	if (n == 0)
		return 1;
	if (k == 0)
		return n;
	return fact[n] * (finv[r] * finv[n - r] % mod) % mod;
}

int main() {
	scanf("%d %d %d", &n, &m, &k);
	init();

	ll sum = 0;
	for (int i = 1; i < n; i++) {
		sum += ncr(n * m - 2, k - 2) * (n - i) % mod * m % mod * m % mod * i % mod;
		sum %= mod;
	}
	for (int i = 1; i < m; i++) {
		sum += ncr(n * m - 2, k - 2) * (m - i) % mod * n % mod * n % mod * i % mod;
		sum %= mod;
	}
	printf("%lld\n", sum);
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;



struct UnionFind {
    vector<int> par;
    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n; 
    vector<P> px(n),py(n);
    rep(i,n) {
        int x,y;
        cin >> x >> y;
        px[i]=make_pair(x,i);
        py[i]=make_pair(y,i);
    }
    sort(px.begin(),px.end());
    sort(py.begin(),py.end());
    vector<pair<int,P>> d;
    rep(i,n-1) {
        d.push_back(make_pair(abs(px[i+1].first-px[i].first),make_pair(px[i].second,px[i+1].second)));
        d.push_back(make_pair(abs(py[i+1].first-py[i].first),make_pair(py[i].second,py[i+1].second)));
    }
    sort(d.begin(),d.end());
    UnionFind tree(n);
    int ans=0;
    rep(i,d.size()) {
        if (!tree.same(d[i].second.first,d[i].second.second)) {
            ans+=d[i].first;
            tree.unite(d[i].second.first,d[i].second.second);
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 6516
#include <stdio.h>

int main(void)
{
    int i, j, k;
    int n;
    int building, floor, room, people;
    int cnt[4][3][10];
    /*people[building][floor][room]*/

    /*initialize*/
    for (i = 0; i < 4; i++){
        for (j = 0; j < 3; j++){
            for (k = 0; k < 10; k++){
                cnt[i][j][k] = 0;
            }
        }
    }

    /*count*/
    scanf("%d", &n);
    for (i = 1; i <= n; i++){
        scanf("%d %d %d %d", &building, &floor, &room, &people);
        cnt[building - 1][floor - 1][room - 1] += people;
        /*building No.1, floor No.1, room No.1 is cnt[0][0][0]*/
    }

    for (i = 0; i < 4; i++){
        if (i){
            printf("####################\n");
        }
        for (j = 0; j < 3; j++){
            for (k = 0; k < 10; k++){
                printf(" %d", cnt[i][j][k]);
            }
            printf("\n");
        }
    }

    return 0;
}

Measured memory_bytes: 612
#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<int,int>;
 
int main() {
  int n;
  cin >> n;
  ll a,ans;
  double loga,logans;
  bool check=false;
  ans = 1;
  rep (i, n){
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    else if ((log10(a)+log10(ans))>18 || a > 1000000000000000000/ans ) check = true;
    else ans *= a;
  }
  if (check == true) cout << -1 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 3964
module ABC130

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public  :: task_C
  private :: calculate_area
  private :: judge_pattern

  ! <type> for this <module>
  type coordinate
    integer(INT32), public :: x
    integer(INT32), public :: y
  end type coordinate

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_C

    ! variables for this <subroutine>
    type(coordinate) :: rectangle
    type(coordinate) :: point

    ! STEP.01
    ! read out the coordinates
    read(unit=INPUT_UNIT, fmt=*) &!
      rectangle%x, rectangle%y, &!
      point%x,     point%y

    ! STEP.03
    ! calculate & output the result
    write(unit=OUTPUT_UNIT, fmt='(ES23.15e3,1X,I1)', advance='yes'), &!
      calculate_area (rectangle),       &!
      judge_pattern  (rectangle, point)

    ! STEP.END
    return

  end subroutine task_C

  pure function calculate_area (data_rectangle) result(val_area)

    ! arguments for this <function>
    type(coordinate), intent(in) :: data_rectangle

    ! return value of this <function>
    real(REAL64) :: val_area

    val_area = 5.0e-001_REAL64 * data_rectangle%x * data_rectangle%y
    return

  end function calculate_area

  pure function judge_pattern (data_rectangle, data_point) result (val_stat)

    ! arguments for this <function>
    type(coordinate), intent(in) :: data_rectangle
    type(coordinate), intent(in) :: data_point

    ! return value of this <function>
    integer(INT8) :: val_stat

    ! variables for this <function>
    logical :: stat_x, stat_y

    stat_x = data_rectangle%x .eq. data_point%x + data_point%x
    stat_y = data_rectangle%y .eq. data_point%y + data_point%y

    if (stat_x .and. stat_y) then
      val_stat = 1_INT8
    else
      val_stat = 0_INT8
    end if

    return

  end function judge_pattern

end module ABC130


program main

  ! <module>s to import
  use, non_intrinsic :: ABC130

  ! require all variables to be explicitly declared
  implicit none

  call task_C

end program main

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

using LL = long long;
using Point = pair<LL, LL>;

LL H, W, D;
vector<vector<LL>> A;
vector<Point> P;

vector<vector<LL>> solve() {
  auto N = H*W*1;
  vector<vector<LL>> sum(D+1);
  for(auto i=1; i<=D; ++i) {
    sum[i].emplace_back(0);
    for(auto x=i; x+D<=N; x+=D) {
      auto y=x+D;
      auto a=P[x];
      auto b=P[y];
      auto cost = abs(a.first-b.first) + abs(a.second-b.second);
      sum[i].emplace_back(sum[i].back() + cost);
    }
  }
  return sum;
}

int main() {
  cin >> H >> W >> D;
  A = vector<vector<LL>>(H, vector<LL>(W));
  for(auto& i: A) for(auto& j: i) cin >> j;

  P.resize(H*W+1);
  for(auto i=0; i<H; ++i) for(auto j=0; j<W; ++j) P[A[i][j]] = Point(i, j);

  auto sum = solve();

  int Q;
  cin >> Q;
  for(auto i=0; i<Q; ++i) {
    LL L, R;
    cin >> L >> R;
    auto d = (L%D);
    if(d==0) d=D;
    auto l = (L+D-1)/D-1, r = (R+D-1)/D-1;
    cout << sum[d][r] - sum[d][l] << endl;
  }
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

 int main(){
  ll n ;cin>> n;
  vector<P> A(n) ;
  rep(i,n) cin>>A[i].second>>A[i].first ;
  bool ok=1 ;
  sort(A.begin(),A.end()) ;
  ll time=0 ;
  rep(i,n){
   time+=A[i].second ;
   if(A[i].first<time){
      ok=0;
      break ;
   }
  }
   if(ok==1) cout<<"Yes"<<endl ;
    else cout<<"No"<<endl ;
   return 0;
  }

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

using namespace std;

#define int long long

void solve()
{
    int n,k;cin>>n>>k;
    int a[n];
    for(int i = 0 ; i < n ; i++)
        cin>>a[i];

    int dp[n];

    dp[0] = 0;

    for(int i = 1 ; i < n ; i++)
    {
        int ctr = 0 , mn = INT_MAX;
        for(int j = i-1; j>=0 && ctr<k; j--)
        {
            mn = min(mn , dp[j] + abs(a[i] - a[j]));
            ctr++;
        }
        dp[i] = mn;
    }

    cout<<dp[n-1]<<endl;
}



int32_t main()
{
    int t = 1;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
#define endl "\n"



void solve(){
   ll n;
   cin>>n;
   vector<ll>v(n);
   for(ll i=0;i<n;i++){
       cin>>v[i];
   }
   ll cash=1000;
   ll i=0;
   ll stocks=0;

   while(i<v.size()){

       while(i+1<v.size()&&v[i+1]<=v[i]){
           i++;
       }
       
       if(i+1==v.size()){break;}
       ll num=cash/v[i];
       cash-=num*v[i];
       stocks=num;
      
       while(i+1<v.size()&&v[i+1]>=v[i]){
           i++;
       }
       cash+=stocks*v[i];
       stocks=0;
       i++;

   }
   if(stocks!=0){
       cash+=v[v.size()-1]*stocks;
       
   }
   cout<<cash<<endl;
}


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

   solve();
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  int n,c[26]={};
  string s;
  cin>>n;
  fr(j,26) c[j]=100;
  fr(i,n){
    cin>>s;
    fr(j,26) if(c[j]>count(s.begin(),s.end(),'a'+j)) c[j]=count(s.begin(),s.end(),'a'+j);
  }
  fr(j,26) fr(i,c[j]) cout<<(char)('a'+j);
  cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <deque>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <unordered_map>

using namespace std;
int main(){
    long long n,k=0;
    cin >> n >> k;
    long long p;
    long long wa=0;
    queue<long long> mem;
    for(long long i=0;i<k;i++){
        mem.push(0);
    }
    long long head=0;
    long long ans=0;
    for(long long i=0;i<n;i++){
        cin >> p;
        mem.push(1+p);
        head = mem.front();
        mem.pop();
        wa = wa + 1 + p - head;
        ans=max(ans,wa);
    }

    cout << setprecision(10) << (double)ans/2 << endl;
}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define FORCLS(i,a,b) for(int i = (a); i <= (b); i++)
#define REPCLS(i,n) FORCLS(i,1,n)


int cnts[27];

void solve(){
    string in;
    cin >> in;
    unsigned long len = in.length();
    REP(i, len){
        cnts[(int)(in[i] - 'a')]++;
    }
    int sum = 0;
    for(int c : cnts) sum += c;
    bool isWinFirst = true;
    if (in[0] == in[len - 1]){
        isWinFirst = ((sum - 2) % 2) == 0;
    }
    else {
        isWinFirst = ((sum - 2) % 2) == 1;
        
    }
    cout << (isWinFirst ? "First" : "Second") << endl;
}

int main() {

    solve();
    
    return 0;
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

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

const int MOD = 1e9 + 7;

struct edge { int v, w; };

void dfs(int u, vector<vector<edge>>& G, vector<ll>& h, vector<int>& p) {
	for (edge e: G[u]) if (h[e.v] == LLONG_MAX) {
		h[e.v] = e.w - h[u];
		p[e.v] = !p[u];
		dfs(e.v, G, h, p);
	}
}

void f(int N, vector<vector<edge>>& G, ll x, vector<ll>& h, vector<int>& p) {
	h = vector<ll>(N, LLONG_MAX);
	h[0] = x;
	p = vector<int>(N);
	dfs(0, G, h, p);
}

int main() {
	int N, M; cin >> N >> M;
	vector<int> a(M), b(M), c(M);
	rep(i, M) scanf("%d%d%d", &a[i], &b[i], &c[i]), a[i]--, b[i]--;
	vector<vector<edge>> G(N);
	rep(i, M) G[a[i]].pb({b[i], c[i]}), G[b[i]].pb({a[i], c[i]});
	vector<ll> h; vector<int> p;
	f(N, G, 0, h, p);
	set<ll> st;
	rep(i, M) {
		int u = a[i], v = b[i], w = c[i];
		if (p[u] != p[v] && h[u] + h[v] != w) {
			cout << 0 << endl;
			return 0;
		}
		if (p[u] == p[v]) {
			ll x = (w - h[u] - h[v]) / 2;
			st.insert(p[u] ? -x : x);
		}
	}
	if (st.empty()) {
		ll x = 1;
		rep(u, N) if (!p[u]) x = max(x, -h[u] + 1);
		f(N, G, x, h, p);
		ll mi = LLONG_MAX;
		rep(u, N) if (p[u]) mi = min(mi, h[u]);
		cout << max(0LL, mi) << endl;
	}
	else {
		f(N, G, *(st.begin()), h, p);
		rep(u, N) if (h[u] <= 0) {
			cout << 0 << endl;
			return 0;
		}
		rep(i, M) {
			int u = a[i], v = b[i], w = c[i];
			if (h[u] + h[v] != w) {
				cout << 0 << endl;
				return 0;
			}
		}
		cout << 1 << endl;
	}
}


Measured memory_bytes: 15872