akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<stdio.h>

#define MAX 251
using namespace std;

int getParent(int i) {
    return i/2;
}

int getLeft(int i) {
    return 2*i;
}

int getRight(int i) {
    return 2*i+1;
}

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

    int parent, left, right;
    for(int i = 1; i <= n; i++) {
        printf("node %d: key = %d, ", i, arr[i]);

        parent = getParent(i);
        if(parent > 0)
            printf("parent key = %d, ", arr[parent]);

        left = getLeft(i);
        if(left <= n)
            printf("left key = %d, ", arr[left]);

        right = getRight(i);
        if(right <= n)
            printf("right key = %d, ", arr[right]);

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

Measured memory_bytes: 3204
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
using namespace std;

#define INF 1e18
#define int long long

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

signed main() {
    int n, k; cin >> n >> k;
    vector<int> h(n), dp(n, INF);
    for(int i = 0; i < n; i++) cin >> h[i];

    dp[0] = 0;
    for(int i = 1; i < n; i++) {
        for(int j = 1; j <= min(i, k); j++) {
            chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }

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


Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  int c[b],d = 0;
  for(int i = 0;i < b;i++){
    cin >> c[i];
    d += c[i];
  }
  if(a - d >= 0){
    cout << a - d << endl;
  }
  else{
    cout << -1 << endl;
  }
}
  

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int arr[MAXN];
int main(){
    //~ freopen("file.in", "r", stdin);
    int n,ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
		scanf("%d",arr+i);
	for(int i=1;i<=n;i++)
		if(arr[i]==i){
			swap(arr[i],arr[i+1]);
			ans++;
		}
	printf("%d\n",ans);	
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define inf 1<<30
#define il inline 
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il int max(int x,int y){return x>y?x:y;}
il int min(int x,int y){return x<y?x:y;}
il int abs(int x){return x>0?x:-x;}
il void swap(int &x,int &y){int t=x;x=y;y=t;}
il void readl(ll &x){
    x=0;ll f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
il void read(int &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
using namespace std;
/*===================Header Template=====================*/
#define N 100010
int a[4];
int main(){
	in3(a[1],a[2],a[3]);
	sort(a+1,a+4);
	int ans=a[3]-a[2]+a[2]-a[1];
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 200100;
long long n, pos[N], f[N], ans, a[N];

priority_queue <pair<long long, long long> > pq;
set <long long> s;

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

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> a[i];
		pq.push({-a[i], i});
	}
	s.insert(0);
	s.insert(n + 1);

	while(!pq.empty()) {
		long long x = pq.top().nd; pq.pop();
		auto it = s.upper_bound(x);
		long long r = *it;
		auto it2 = prev(it);
		long long l = *it2;
		// dbg(x, l, r);
		ans += a[x] * (r - x) * (x - l);
		s.insert(x);
		// dbg(x, ans);
	}
	cout << ans << '\n';
}	



Measured memory_bytes: 15084
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int n;
	cin>>n;
	int ans=0;
	rep(i,n){
		string s;cin>>s;
		if(s=="E869120")++ans;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3208
#include <stdio.h>

void azunyann(int taketatuayana) {
	static int toyosakiaki = 0;
	if (toyosakiaki) putchar(' '); else toyosakiaki = 1;
	printf("%d", taketatuayana);
}

int main(void) {
	int K, X;
	int i;
	if (scanf("%d%d", &K, &X) != 2) return 1;
	for (i = X - K + 1; i <= X + K - 1; i++) {
		azunyann(i);
	}
	putchar('\n');
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <stdint.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
using namespace std;
 
#define int long long
 

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

int LCM(int a, int b){
	
	
return (a*b)/gcd(a, b);  
	
	
}

 
int f(int x){
	
	
	int res = 0;
	
	while( x%2 == 0){
		
		x/=2;
		res++;
	}
	
	return res;
	
}


int prime(int n){
	
	for(int i=n; i<=INT_MAX; i++){
		
		bool flag = true;
		for(int j=2; j<i; j++){
			
			if(i%j == 0){
				flag = false;
				break;
			}
			
		}
		if(flag)
			return i;
	}
	
	
	
}
 
int32_t main() {
 
 	int x;
 	
 	cin >> x; 
 	
 	cout << prime(x) << endl;
 	
}








Measured memory_bytes: 3188
#include <iostream>
const int maxn=105;
using namespace std;
int a[maxn];
int main(int argc, char *argv[]) {
	int n,m,tot=0,cnt=0;
	cin>>n>>m;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		tot+=a[i];
	}
	double avg=tot/4.0/m;
	for(int i=1;i<=n;++i){
		if(a[i]>=avg)
			cnt++;
	}
	if(m>cnt) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  private static int getIndex(int[] p, List<List<Integer>> perms) {
    int ans = 0;
    for (int i = 0; i < perms.size(); i++) {
      boolean match = true;
      List<Integer> perm = perms.get(i);
      for (int j = 0; j < p.length; j++) {
        if (p[j] != perm.get(j)) {
          match = false;
          break;
        }
      }
      if (match) {
        ans = i;
        break;
      }
    }
    return ans;
  }
  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] p = sc.nextIntArray(n);
    int[] q = sc.nextIntArray(n);
    List<List<Integer>> perms = new ArrayList<>();
    List<List<Integer>> nextPerms = new ArrayList<>();
    perms.add(new ArrayList<Integer>());
    for (int i = 0; i < n; i++) {
      nextPerms.clear();
      for (List<Integer> perm : perms) {
        for (int j = 1; j <= n; j++) {
          if (perm.contains(j)) continue;
          List<Integer> pm = new ArrayList<>();
          pm.addAll(perm);
          pm.add(j);
          nextPerms.add(pm);
        }
      }
      perms.clear();
      perms.addAll(nextPerms);
    }
    int a = getIndex(p, perms);
    int b = getIndex(q, perms);
    System.out.println((int) Math.abs(a - b));
  }
}

Measured memory_bytes: 38116
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;//cost, vertex
struct edge{
  int to, cost;
};

int main(int argc, char *argv[]){
  int n, m, r;
  cin >> n >> m >> r;
  vector<vector<edge> > g(n);
  int from;
  for (int i = 0; i < m; i++) {
    edge e;
    cin >> from >> e.to >> e.cost;
    g[from].push_back(e);
  }
  int dp[n];
  for (int i = 0; i < n; i++) {
    dp[i] = 1e9;
  }
  dp[r] = 0;
  priority_queue<pii, vector<pii>, greater<pii> > que;
  que.push(mp(0, r));
  //???????????§?????????
  //??????????????????????????????
  while(!que.empty()){
    int v = que.top().second;
    int c = que.top().first;
    que.pop();
    if(dp[v] < c)continue;
    for (int i = 0; i < g[v].size(); i++) {
      edge e = g[v][i];
      if(dp[e.to] > c + e.cost){
        dp[e.to] = c + e.cost;
        que.push(mp(dp[e.to], e.to));
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if(dp[i] == 1e9)std::cout << "INF" << std::endl;
    else std::cout << dp[i] << std::endl;
  }

  return 0;
}

Measured memory_bytes: 11228
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<functional>

#define LLI long long int

using namespace std;

int main(){
	int a;cin>>a;
	string s;cin>>s;
	string ans;
	if(a>=3200){
			ans=s;
	}else{
			ans="red";
	}
	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 256
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

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

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

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 = list(map(int,sys.stdin.readlines())) #縦入力
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
n,m =  map(int, sys.stdin.readline().split())

dp=[0]*(n+1)
list_a = set(map(int,sys.stdin.readlines()))

dp[0]=1

for i in range(1,n+1):
    dp[i] = (dp[i-1] + dp[i-2]) % big_prime #dp[-1]=0
    if i in list_a:
        dp[i]=0
ans = dp[n]
print(ans)


Measured memory_bytes: 21228
use std::io::Read;

fn main() {
    let mut buff = String::new();
    std::io::stdin().read_to_string(&mut buff).unwrap();
    let mut iter = buff.split_whitespace();

    let x1: i32 = iter.next().unwrap().parse().unwrap();
    let y1: i32 = iter.next().unwrap().parse().unwrap();
    let x2: i32 = iter.next().unwrap().parse().unwrap();
    let y2: i32 = iter.next().unwrap().parse().unwrap();

    let diff_y = y2 - y1;
    let diff_x = x2 - x1;

    println!(
        "{} {} {} {}",
        x2 - diff_y,
        y2 + diff_x,
        x1 - diff_y,
        y1 + diff_x
    );

    ()
}


Measured memory_bytes: 4352
from collections import defaultdict, deque
n, m = map(int, raw_input().split())

edge = defaultdict(list)
for _ in xrange(m):
    a, b = map(int, raw_input().split())
    # if a > b:
    #     a, b = b, a
    edge[a].append((a,b))
    edge[b].append((a,b))

i = 1
while not edge[i]:
    i += 1

q = deque()

have_been_to = [False] * (n+1)
have_been_to[i] = True

num_of_edge = [0] * (n+1)
c = 1
path = deque([i])
# print edge
for d in xrange(2):
    frm = i
    q.extend(edge[i])
    while q:
        (a, b) = q.popleft()
        # print path
        if frm == b and not have_been_to[a] and num_of_edge[a] < 2 and num_of_edge[frm] < 2: # never been to and don't have 2 edges
            q.extendleft(edge[a])
            have_been_to[a] = True
            num_of_edge[a] += 1
            num_of_edge[frm] += 1
            # print a, b
            if d == 1:
                path.append(a)
            else:
                path.appendleft(a)
            frm = a
            c += 1
        elif frm == a and not have_been_to[b] and num_of_edge[b] < 2 and num_of_edge[frm] < 2: # never been to and don't have 2 edges
            q.extendleft(edge[b])
            have_been_to[b] = True
            num_of_edge[b] += 1
            num_of_edge[frm] += 1
            # print a, b
            if d == 1:
                path.append(b)
            else:
                path.appendleft(b)
            frm = b
            c += 1
print c
print " ".join(map(str,path))





Measured memory_bytes: 48044
#include<iostream>
#include<map>
using namespace std;
map<string,bool>M;
main()
{
	int n;cin>>n;
	for(int i=0;i<n;i++)
	{
		string s;cin>>s;M[s]=1;
	}
	cin>>n;
	int a=1;
	for(int i=0;i<n;i++)
	{
		string s;cin>>s;
		if(M[s])
		{
			cout<<(a?"Opened by ":"Closed by ")<<s<<endl;
			a=!a;
		}
		else
		{
			cout<<"Unknown "<<s<<endl;
		}
	}
}



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

int main() {
  int64_t N, W;
  cin >> N >> W;
  
  vector<vector<int64_t>> dp(N+1, vector<int64_t>(W+1, 0));
  vector<int64_t> weight(N);
  vector<int64_t> value(N);
  
  //重さおよび価値入力
  for (int i=0; i<N; i++) {
    cin >> weight.at(i) >> value.at(i);
    //cout << weight.at(i) << " " << value.at(i) << endl;//チェック
  }
  
  //品物一つにつき一巡（i）。dp.at(i+1)行目にvalue.at(i)を足した価値→N行目にAns。
  for (int i=0; i<N; i++) {
    for (int w=1; w<=W; w++) {//1からでも回る。w=0列は重さ無し
      if (w<weight.at(i)) {//i行目の重さが指定の重さ:wより大きいと、i行目の品物は選ばれない。
        dp.at(i+1).at(w)=dp.at(i).at(w);
      }
      else {/*i行目の重さがw以下ならば、1.選ばない 2.w-i列目の重さ（重さw-iにおける最大価値)
      +i行目の価値　のうち最大の方*/
        dp.at(i+1).at(w)=max(dp.at(i).at(w), dp.at(i).at(w-weight.at(i))+value.at(i));
      }
    }
  }
  cout << dp.at(N).at(W) << endl;
}

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

typedef pair<int, int> pii;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

const int N = 100010;

int k, n, L;
string s, ans;

bool check(string &cur) {
	int cnt = 0;
	for (int ptr = 0; ptr < n; ) {
		if (ptr + L > n) {
			cnt++;
			break;
		}
		if (s.substr(ptr, L) <= cur) ptr += L;
		else {
			if (L == 1) {
				cnt = N;
				break;
			}
			ptr += L - 1;
		}
		cnt++;
	}
	return cnt <= k;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> k >> s;
	// if ((int)s.size() == 1) {
	// 	cout << s;
	// 	return 0;
	// } else if ((int)s.size() == 2) {
	// 	if (k == 0) cout << s;
	// 	else cout << max(s[0], s[1]);
	// 	return 0;
	// }
	k++;
	n = s.size(), L = (n + k - 1) / k;
	s += '$';
	n = s.size();
	vector<int> p(n), c(n), inds;
	{
		vector<pair<char, int> > a(n);
		for (int i = 0; i < n; i++) a[i] = {s[i], i};
		sort(all(a));
		for (int i = 0; i < n; i++) p[i] = a[i].S;
		c[p[0]] = 0;
		for (int i = 1; i < n; i++) {
			if (a[i].F == a[i - 1].F)
				c[p[i]] = c[p[i - 1]];
			else c[p[i]] = c[p[i - 1]] + 1;
		}
	}
	int k = 0;
	while ((1 << k) < n) {
		vector<pair<pii, int> > a(n);
		for (int i = 0; i < n; i++) 
			a[i] = {{c[i], c[(i + (1 << k)) % n]}, i};
		sort(all(a));
		for (int i = 0; i < n; i++) p[i] = a[i].S;
		c[p[0]] = 0;
		for (int i = 1; i < n; i++) {
			if (a[i].F == a[i - 1].F)
				c[p[i]] = c[p[i - 1]];
			else c[p[i]] = c[p[i - 1]] + 1;
		}
		k++;
	}
	s.pop_back();
	n = s.size();
	for (int i: p) 
		if (i + L <= n) 
			inds.pb(i);
	int l = 0, r = inds.size() - 1;
	while (l <= r) {
		int mid = (l + r) >> 1;
		string cur = s.substr(inds[mid], L);
		if (check(cur)) {
			ans = cur;
			r = mid - 1;
		} else l = mid + 1;
	}
	cout << ans;
}


Measured memory_bytes: 5320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); i++)

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> cnt(n + 1, 0);
  vector<ll> h(n + 1, 0);
  REP(i, n) {
    ll a;
    cin >> a;
    cnt[i + 1] = a;
  }

  for (int l = k + 1; l < n + 1; l++) {
    if (cnt[l - k] < cnt[l]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  int c = b-a+1;
  for(int i = 0;i < 2*a-2;i++){
    cout << c+i << " ";}
  cout << b+a-1 << endl;
}

Measured memory_bytes: 256
from functools import reduce

N, M = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))

t = [reduce(lambda x, y: x | (1 << (y - 1)), e, 0) for e in s]
result = 0
for i in range(2 ** N):
    for j in range(M):
        if (bin(i & t[j]).count('1') & 1) != p[j]:
            break
    else:
        result += 1
print(result)


Measured memory_bytes: 3572
import numpy as np

N,D = [int(x) for x in input().split()]
l = list()
for i in range(N):
    l.append([int(x) for x in input().split()])

count = 0
for c in l:
    if np.sqrt(c[0] ** 2 + c[1] ** 2) <= D:
        count += 1
print(count)

Measured memory_bytes: 60280
######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)#################
#####################2020#############################
######################################################
import sys
input = sys.stdin.readline

# import sys
import heapq 
import copy
import math
import decimal
# import sys.stdout.flush as flush
# from decimal import *
#heapq.heapify(li) 
#
#heapq.heappush(li,4) 
#
#heapq.heappop(li)
#
# &	Bitwise AND Operator	10 & 7 = 2
# |	Bitwise OR Operator	10 | 7 = 15
# ^	Bitwise XOR Operator	10 ^ 7 = 13
 
# <<	Bitwise Left Shift operator	10<<2 = 40
# >>	Bitwise Right Shift Operator
# '''############ ---- Input Functions ---- #######Start#####'''
 

def inp():
	return(int(input()))
def inlt(): 
	return(list(map(int,input().split())))
def insr():
	s = input()
	return(list(s[:len(s) - 1]))
def insr2():
	s = input()
	return((s[:len(s) - 1]))
def invr():
	return(map(int,input().split()))
 ############ ---- Input Functions ---- #######End
 # #####   

def pr_list(a):
	print(*a, sep=" ")
def main():
	# tests =  inp()
	tests = 1
	mod = 998244353
	limit = 10**18
	ans = 0
	for test in range(tests):
		[n,k] = inlt()
		h = inlt()
		dp = [sys.maxsize for i in range(n+3)]
		dp[0] = 0
		for i in range(0,n):
			for j in range(1,k+1):
				if i+j <n:
					dp[i+j] = min(dp[i+j],dp[i] + abs(h[i+j] - h[i]))
		# print(dp)
		print(dp[n-1])

if __name__== "__main__":
	main()

Measured memory_bytes: 76856
a = map(int, raw_input().split())
while a != [0,0]:
	print '#' * a[1]
	for i in xrange(a[0]-2):
		print '#' + '.' * (a[1] - 2) + '#'
	print '#' * a[1]
	a = map(int, raw_input().split())
	print ""

Measured memory_bytes: 6436
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NK = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, K) = (NK[0], NK[1]);
        var A = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var l = 0;
        var r = 1_000_000_000;

        while(r - l > 1)
        {
            var m = (l + r) / 2;

            bool ok(int l)
            {
                var k = 0;
                for (int i = 0; i < N; i++)
                    k += MathExt.DivideAndRoundUp(A[i], l) - 1;

                return k <= K;
            }

            if (ok(m))
                r = m;
            else
                l = m;
        }

        WriteLine(r);
    }
}

static class MathExt
{
    public static int DivideAndRoundUp(int x, int y) => (x + y - 1) / y; // (int)Math.Ceiling((double)x / (double)y);
    public static long DivideAndRoundUp(long x, long y) => (x + y - 1) / y;
}


Measured memory_bytes: 44908
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
int n;
int main(void){
    cin>>n;
    if(n<1200)cout<<"ABC\n";
    else if(n<2800)cout<<"ARC\n";
    else cout<<"AGC\n";
    
}


Measured memory_bytes: 256
a, b = list(map(int, input().split()))
s = input()
flag = 0
for i in range(a + b + 1):
    if i == a:
        if s[i] != '-':
            flag = 1
            break
    elif not s[i].isdigit():
        flag = 1
        break
if flag == 1:
    print ('No')
else:
    print ('Yes')


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

typedef pair<int,int>P;
typedef pair<int,P> PP;
const int MAX_N=2*1e5+1;
PP data[MAX_N];
bool infected[MAX_N];
int main(){
	int n,m;
	while(cin>>n>>m && n){
		fill(infected,infected+MAX_N,false);
		infected[1]=true;
		for(int i=0;i<m;i++){
			int t,s,d;
			cin>>t>>s>>d;
			data[i]=PP(t,P(s,d));
		}
		sort(data,data+m);
		for(int i=0;i<m;i++)infected[data[i].second.second]|=infected[data[i].second.first];
		int ans=0;
		for(int i=1;i<=n;i++)ans+=infected[i];
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i]>>y[i];
#define _GLIBCXX_DEBUG
#define V vector<int>
using namespace std;
using ll = long long;

int main(){
    int n; cin>>n;
    ll mod=1000000007;
    ll x=1;
    rep(i,1,n+1){
        x*=i;
        x%=mod;
    }
    cout<<x<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll INF = 1e17;
const int MAX_V = 302;
 
vector<vector<ll>> d(MAX_V, vector<ll>(MAX_V,INF));
vector<vector<ll>> s(MAX_V, vector<ll>(MAX_V,INF));
int V;
 
void warshall_floyd1(){
  rep(k,V+1){
    rep(i,V+1){
      rep(j,V+1) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
  }
}
 
void warshall_floyd2(){
  rep(k,V+1){
    rep(i,V+1){
      rep(j,V+1) s[i][j] = min(s[i][j], s[i][k] + s[k][j]);
    }
  }
}
 
int main(){
  int m; ll l;
  cin >> V >> m >> l;
  rep(i,m) {
    int a, b; ll c;
    cin >> a >> b >> c;
    if(c <= l){
      d[a][b] = c;
      d[b][a] = c;
    }
  }
  warshall_floyd1();
  rep(i,V+1) {
    rep(j,V+1) {
      if(d[i][j] <= l) s[i][j] = 1;
    }
  }
  warshall_floyd2();
  int q;
  cin >> q;
  int ans[q];
  rep(i,q) {
    int x, y;
    cin >> x >> y;
    if(s[x][y] == INF) ans[i] = -1;
    else ans[i] = s[x][y]-1;
  }
  for(auto k : ans) cout << k << endl;
  return 0;
}

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

signed main() {
	int n, x;
	cin >> n >> x;
	vector<int> l(n);
	rep(i, n) cin >> l[i];
	int cou = 1;
	int sum = 0;
	rep(i, n) {
		sum += l[i];
		if(sum <= x) {
			cou++;
		}
	}
	cout << cou << endl;
}


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

void dfs(const vector<vector<int>> &e, const vector<int> &a, vector<bool> &v, int x, vector<int> &f, vector<int> &ans) {
  v[x] = true;
  int d = distance(f.begin(), lower_bound(f.begin(), f.end(), a[x]));
  int t = f[d];
  f[d] = a[x];
  ans[x] = distance(f.begin(), lower_bound(f.begin(), f.end(), INT_MAX));

  for (int i = 0; i < e[x].size(); i++)
    if (!v[e[x][i]])
      dfs(e, a, v, e[x][i], f, ans);

  f[d] = t;
}

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);

  vector<vector<int>> e(n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);

    u--, v--;
    e[u].emplace_back(v);
    e[v].emplace_back(u);
  }

  vector<bool> v(n);
  vector<int> f(n, INT_MAX), ans(n);
  dfs(e, a, v, 0, f, ans);

  for (int i = 0; i < n; i++)
    printf("%d\n", ans[i]);

  return 0;
}

Measured memory_bytes: 33876
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double A[] = new double[N];
		double answer = 0;

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextDouble();
		}

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

		System.out.println(1 / answer);
	}
}


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

int main() {
    long long int N, K;
    cin >> N >> K;

    if(N > K) {
        N = N % K;
    }
    while(1){
        long long int N2 = abs(N - K);
        if(N2 < N) {
            N = N2;
        }
        else {
            break;
        }
    }

    cout << N << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        inp = list(input())
        a.append(inp)
    
    dp = [[10**9]*w for i in range(h)]
    
    for i in range(h):
        for j in range(w):
            if a[i][j] == '.' and [i,j] != [0,0]:
                if i >= 1:
                    dp[i][j] = dp[i-1][j]+1
                    if j >= 1:
                        dp[i][j] = min(dp[i][j],dp[i][j-1]+1)
                else:
                    dp[i][j] = dp[i][j-1]+1
            elif a[i][j] == '#':
                dp[i][j] = 0
    for i in range(h):
        for j in range(w-1,-1,-1):
            if a[i][j] == '.' and [i,j] != [0,w-1]:
                if i >= 1:
                    dp[i][j] = min(dp[i-1][j]+1,dp[i][j])
                    if j+1 <= w-1:
                        dp[i][j] = min(dp[i][j],dp[i][j+1]+1)
                else:
                    dp[i][j] = min(dp[i][j+1]+1,dp[i][j])
    for i in range(h-1,-1,-1):
        for j in range(w):
            if a[i][j] == '.' and [i,j] != [h-1,0]:
                if i+1 <= h-1:
                    dp[i][j] = min(dp[i+1][j]+1,dp[i][j])
                    if j >= 1:
                        dp[i][j] = min(dp[i][j],dp[i][j-1]+1)
                else:
                    dp[i][j] = min(dp[i][j-1]+1,dp[i][j])
    for i in range(h-1,-1,-1):
        for j in range(w-1,-1,-1):
            if a[i][j] == '.' and [i,j] != [h-1,w-1]:
                if i+1 <= h-1:
                    dp[i][j] = min(dp[i+1][j]+1,dp[i][j])
                    if j+1 <= w-1:
                        dp[i][j] = min(dp[i][j],dp[i][j+1]+1)
                else:
                    dp[i][j] = min(dp[i][j+1]+1 ,dp[i][j])
        
    res = -1
    for i in range(h):
        for j in range(w):
            res = max(res,dp[i][j])

    print(res)



if __name__ == '__main__':
    main()

Measured memory_bytes: 92912
# include <bits/stdc++.h>
# define ll long long
using namespace std;
const ll mod = 998244353 , N = 2e5 + 10;
ll n , res = 1 , a[N] , x[N] , to = 0; 
ll power(ll a , ll b){
	ll res = 1;
	for(; b; b >>= 1 , a = a * a % mod)
		if(b & 1)
			res = res * a % mod;
	return res;
} 
int main(){
	cin >> n;
	for(int i = 1; i <= n; i ++) cin >> x[i] , a[x[i]] ++ , to = max(to , x[i]);
	res = a[0] == 1 && x[1] == 0;
	for(int i = 1; i <= to; i ++) res &= !!a[i];
	for(int i = 1; i <= to; i ++)
		res = res * power(a[i - 1] , a[i]) % mod;
	cout << res << '\n';
}

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

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	
	cout << min(b / a, c) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

vector<long long> solve(vector<int> &v1, vector<int> &v2, int X){
    int N = v1.size();
    vector<long long> ret(N, 0);
    long long sm = 0;
    priority_queue<int> pq;
    for(int i=0; i<X; i++) {
        sm += v1[i];
        pq.push(v2[i] - v1[i]);
        ret[i] = sm;
    }

    for(int i=X; i<N; i++){
        sm += v1[i];
        pq.push(v2[i] - v1[i]);
        int tp = pq.top();
        pq.pop();
        sm += tp;
        ret[i] = sm;
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, Y, Z, N;
    cin >> X >> Y >> Z;
    N = X + Y + Z;
    vector<int> A(N), B(N), C(N);
    for(int i=0; i<N; i++)
        cin >> A[i] >> B[i] >> C[i];

    vector<pair<int, int>> vec(N);
    for(int i=0; i<N; i++) vec[i] = make_pair(A[i] - B[i], i);
    sort(vec.begin(), vec.end(), greater<pair<int, int>>());

    vector<int> v1(N), v2(N);
    for(int i=0; i<N; i++){
        v1[i] = A[vec[i].second];
        v2[i] = C[vec[i].second];
    }
    vector<long long> gol = solve(v1, v2, X);

    for(int i=0; i<N; i++){
        v1[i] = B[vec[N-1-i].second];
        v2[i] = C[vec[N-1-i].second];
    }
    vector<long long> sil = solve(v1, v2, Y);

    long long ans = 0;

    for(int i=X-1; i<=N-Y-1; i++)
        ans = max(ans, gol[i] + sil[N-2-i]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5244
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long N = sc.nextInt();
        final long Mod = 1000000000+7;
        long i=1;
        long ans = 1;
        while(i<=N){
            ans = (ans*i)%Mod;
            i++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
 
using namespace std;
 
int main(){
	int N;
	scanf("%d",&N);
	int T[N+5];
	int A[N+5];
	for(int i=1;i<=N;i++){
		scanf("%d",&T[i]);
	}
	for(int i=1;i<=N;i++){
		scanf("%d",&A[i]);
	}
	T[0]=T[N+1]=A[0]=A[N+1]=-1;
	int zero=0;
	
	int M[N+2];//掛け算
	int H[N+2];//ハイヤー
	for(int i=0;i<=N+1;i++){
		M[i]=0;
		H[i]=0;
	}
	
	int tallestT=0;
	int tallestA=0;
	for(int i=1;i<=N;i++){
		if(T[i]>=tallestT)tallestT=T[i];
		if(A[i]>=tallestA)tallestA=A[i];		
	}
	if(tallestT!=tallestA)zero=1;
		
	
	for(int i=1;i<=N;i++){
		if(A[i]!=A[i+1]){
			M[i]=1;
			H[i]=A[i];
			if(A[i]>T[i]) zero = 1;
		}
		if(T[i]!=T[i-1]){
		    M[i]=1;
			if(H[i]!=0&&H[i]!=T[i]){
				zero=1;
			}
			H[i]=T[i];
			if(T[i]>A[i]) zero = 1;
		}
		if(A[i]==A[i+1]&&T[i]==T[i-1]&&H[i]==0){
			M[i]=min(A[i],T[i]);
		}
	}
	
	
	unsigned long long ans=1;
	for(int i=1;i<=N;i++){
		M[i]=M[i]%(1000000000+7);
		ans=ans*M[i]%(1000000000+7);
		ans=ans%(1000000000+7);
	}
	
	ans=ans%(1000000000+7);
	
	if(zero==1)printf("0\n");
	if(zero==0)printf("%d\n",ans);
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std; 
int main(){
  int a,b,c;
  cin >>a>>b>>c;
  
  if(a+b+c==17){
  	if((a==5||b==5||c==5)&&(a==7||b==7||c==7)){
      cout << "YES";
    }
  }else{
  	cout << "NO";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int l,r;
	long long ans=1e9;;
	scanf("%d%d",&l,&r);
	int mx=min(r,l+2019);
	for(int i=l;i<=mx;++i)
		for(int j=i+1;j<=mx;++j)ans=min(ans,1ll*i*j%2019);
	cout<<ans;
}

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

int main(){
	string s;
	cin >> s;
	if(s[s.length()-1]=='s'){
		s.push_back('e');
		s.push_back('s');
	}
	else if(s[s.length()-1]!='s'){
		s.push_back('s');
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3624
var f1:text; A,B,C: array [0..1000000] of longint;
     a1,b1,c1,i,n:longint;

 function max(x,y:longint):longint;
 BEGIN
  if x<y then exit(y) else exit(x);
 END;

 BEGIN
  assign(f1,''); reset(f1);
  readln(f1,n);
  readln(f1,A[1],B[1],C[1]);
  for i:=2 to n do
   BEGIN
    readln(f1,a1,b1,c1);
    A[i]:=max(B[i-1],C[i-1])+a1;
    B[i]:=max(A[i-1],C[i-1])+b1;
    C[i]:=max(A[i-1],B[i-1])+c1;
   END;
  write(max(A[n],max(B[n],C[n])));
  readln;
  close(f1);
 END.



Measured memory_bytes: 8704
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
signed main()
{
	int a,b,c,k,ans=0;
	cin>>a>>b>>c>>k;
	if (k<=a){
		cout<<k;
		re 0;
	}
	k-=a;
	ans+=a;
	if (k<=b){
		cout<<ans;
		re 0;
	}
	k-=b;
	cout<<ans-k;
	re 0;
}

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

int main() {
  int n;
  cin>>n;
  long long ans = 0;
  int cnt_minus = 0;
  int cnt_0 = 0;
  int min_abs = 1e9;
  for (int i=0; i<n; i++) {
    int a;
    cin>>a;
    ans += abs(a);
    if (a == 0) {
      ++cnt_0;
    } else if (a < 0) {
      ++cnt_minus;
    }
    min_abs = min(min_abs, abs(a));
  }

  if (cnt_minus % 2 == 1 && cnt_0 == 0) {
    ans -= 2 * min_abs;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream> 
#include<string>
using namespace std;
int main()
{
	string s;
	int k; 
	cin >> s;
	cin >> k;   
	
	int x=0;
	
		if (s.at(0)!='1')
		{ 
			x = 1;
			cout << s.at(0) << "\n"; 
			
		}   
		else
		{
			for (int i = 1; i < k; ++i)
			{
				if (s.at(i)!='1')
				{
					cout << s.at(i) << "\n"; 
					x = 1; 
					break;
				} 
				
			} 
			if (x==0)
			{
				cout << 1 << "\n";
			}
		}
	
}
	

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if(min(a, b) < c && c < max(a,b))
	{
		cout << "Yes\n";
	}else
	{
		cout << "No\n";
	}
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import numpy as np
d= int(input())
 
C = list(map(int,input().split()))
CB = [0 for i in range(len(C))]
 
c = sum(C)
 
total = 0
 
#print(c,C,CB)
L = []
 
for i in range(d):
    L.append(list(map(int,input().split())))
 
#print(L)
 
 
#print(T)
 
def cnt(CB,t):
    for i in range(len(CB)):
        if i != t:
            CB[i] += 1
        else:
            CB[i] = 0
    
    return CB
 
def sumA(C,CB):
    a = 0
    for i in range(len(CB)):
        a += CB[i]*C[i]
    return a
 
def check(L,C,CB):
    a = L[0]+CB[0]*C[0]
    r = 0
    for i in range(len(CB)):
        if a < L[i]+CB[i]*C[i]:
            r = i
    return r
 
for i in range(d):
    ## 最大値で更新
#    ind = np.argmax(L[i])
#    CB = cnt(CB,ind)
#    total += L[i][ind] - sumA(C,CB)
    
    ind = i%26
    CB = cnt(CB,ind)
    total += L[i][ind] - sumA(C,CB)


    print(ind+1)
 

Measured memory_bytes: 27656
#include <stdio.h>
#include <stdlib.h>
int d_cnt;
long int X, K, D, a, b, c;
int main(void) {
 
	scanf("%ld %ld %ld", &X, &K, &D);
	if(X < 0){
		d_cnt = 1;
		X = labs(X);
	}
	a = X % D;
	if(a < 0){
		a = a + D;
	}
	b = (X - a) / D;
	if(K > b){
	X = X - D * b;
 
	if((K-b) >= 2){
			if(((K - b) % 2) == 0){
				printf("%ld", X);
			}else{
				printf("%ld", labs(X-D));
			}
		}else if((K-b) == 1){
			printf("%ld", labs(X-D));
		}else if((K-b) == 0){
			printf("%ld", X);
		}
	}else{
		printf("%ld", (X-K*D));
	}
	return 0;
}

Measured memory_bytes: 1728
#include<stdio.h>

int main(void){

  int a , i, j, hoge, sum = 0;
  scanf("%d",&a);
  a = a * 2;

  int x[a];

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

  for(i = 0; i < a - 1 ; i++){
    for(j = a - 1; j > i; j--){
      if(x[j] < x[j-1]){
        hoge = x[j];
        x[j] = x[j-1];
        x[j-1] = hoge;
      }
    }
  }
    for(i = 0; i < a; i++){
  //    printf("%d",x[i]);
      if(i % 2== 0){
        sum += x[i];
      }
  }
  printf("%d\n",sum);
  return 0;
  }


Measured memory_bytes: 128
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int L=4*1000+10;
int table[2][L][L];
int N,K;
int area(int t, int p,int q){
	return table[t][p+K-1][q+K-1]-table[t][p-1][q+K-1]-table[t][p+K-1][q-1]+table[t][p-1][q-1];
}
int main() {
	cin >> N >> K;
	for(int i=0;i<N;i++){
		int x,y;
		char c;
		cin >> x >> y >> c;
		x%=2*K;
		y%=2*K;
		//cerr << x << " " << y << ": " << c << endl;
		int t=c=='B'?0:1;
		for(int p=0;p<2;p++){
			for(int q=0;q<2;q++){
				table[t][x+p*2*K][y+q*2*K]++;
			}
		}
	}
	for(int t=0;t<2;t++){
		for(int i=0;i<4*K;i++){
			for(int j=1;j<4*K;j++){
				table[t][i][j]+=table[t][i][j-1];
			}
		}
		for(int i=1;i<4*K;i++){
			for(int j=0;j<4*K;j++){
				table[t][i][j]+=table[t][i-1][j];
				//cerr << table[t][i][j] << " ";
			}
			//cerr << endl;
		}
		//cerr << endl;
	}
	//cerr << area(1,1+2*K,1+2*K) << endl;
	int ret=0;
	for(int p=0;p<K;p++){
		for(int q=0;q<K;q++){
			int r=0;
			for(int u=1;u<=2;u++){
				for(int v=1;v<=2;v++){
					r+=area(u==v?0:1,p+u*K,q+v*K);
				}
			}
			//cerr << p << ", " << q << ": " << v << endl;
			ret=max(ret,r);
			ret=max(ret,N-r);
		}
	}
	cout << ret << endl;
	return 0;
}



Measured memory_bytes: 125696
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;



int main(){
  int n, m;
  cin >> n >> m;
  vector<int> x, y;
  rep(i, m){
    int a, b;
    cin >> a >> b;
    if (a == 1) x.push_back(b);
    else if (b == n) y.push_back(a);
  }
  x.push_back(20000000);
  sort(ALL(x));
  bool ok = false;
  rep(i, y.size()){
    auto it = lower_bound(x.begin(), x.end(), y[i]);
    int v = it - x.begin();
    if (x[v] == y[i]) ok = true;
  }
  if (ok) cout << "POSSIBLE\n";
  else cout << "IMPOSSIBLE\n";
}


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

int x,y;
int main(){
 for(int i=0;i<3000;i++){
  cin>>x>>y;
  if(x==0&&y==0){
   break;
  }
  if(x<=y){
   cout<<x<<" "<<y<<endl;
  }else{
   cout<<y<<" "<<x<<endl;
  }
 }
}

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

// bool sortbysec(const pair<int,int>&a, const pair<int,int>&b)
// {
//     return a.second>b.second;
// }

int main() 
{
    string s;
    cin>>s;
    if(s[1]=='B')
        cout<<"ARC\n";
    else
        cout<<"ABC\n";
}

Measured memory_bytes: 3488
using System;
using System.Text.RegularExpressions;
class Program
{
    static void Main(string[] args)
    {
        MatchCollection results
            = Regex.Matches(Console.ReadLine(), "[A|T|C|G]+");
        int length = 0;
        foreach (Match m in results)
        {
            if (m.Value.Length > length)
                length = m.Value.Length;
        }
        Console.WriteLine(length);
        Console.Read();
    }
}

Measured memory_bytes: 15956
from collections import deque

s = list(input())
s = deque(s)
n = int(input())
dire = False

for i in range(n):
    q = input().split()
    if q[0] == '1':
        dire = not dire
    else:
        t = int(q[1])-1

        if dire ^ t:
            s.append(q[2])
        else:
            s.appendleft(q[2])
if dire:
    s.reverse()

print(''.join(s))

Measured memory_bytes: 8548
#include<bits/stdc++.h>
using namespace std;
#define LL long long


int main()
{
    long long m,s,ss;
    cin>>m;

        m=m;
        s=m/11;
        ss=m%11;
        //cout<<ss<<"\n";
        if(ss>0 and ss<=6)
        {
            ss=1;
        }
        else if(ss>0 and ss<11)
        {
            ss=2;
        }

        s=s*2+ss;

        cout<<s<<"\n";
   // freopen("asass.txt","w",stdout);

   /*long long start=0,ends=0,i,l;
   string st;
   cin>>st;
   l=st.size();
   for(i=0;i<l;i++)
   {
       if(st[i]=='A')
       {
           start=i;
           break;
       }
   }
   for(i=l-1;i>start;i--)
   {
       if(st[i]=='Z')
       {
           ends=i;
           break;
       }
   }
   cout<<(ends-start)+1<<"\n";*/
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

char s[maxn];
int len,suf[maxn],pre[maxn],mn,ans;

int main()
{
	scanf("%s",s+1); len=strlen(s+1); mn=0; ans=inf;
	rep(i,1,len) pre[i]=pre[i-1]+(s[i]=='0'?-1:1);
	suf[len]=pre[len]; per(i,len-1,1) suf[i]=min(suf[i+1],pre[i]); mn=min(mn,suf[1]);
	rep(j,1,2)
	{
		int nw=0,p=0;
		rep(i,1,len)
		{
			if(s[i]!='?') nw+=(s[i]=='0'?-1:1);
			else
			{
				if(suf[i]-pre[i-1]+nw-2>=mn) nw--;
				else nw++;
			}
			p=max(p,nw);
		}
		ans=min(ans,p-mn); mn--;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);++(i))
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define ppb(x) pop_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;

int main() {
  string s, t;
  cin >> s; cin >> t;
  int res = 1000;
  int ns = s.size(), nt = t.size();
  REP(i,ns-nt+1) {
    int tmp = 0;
    REP(j,nt) if (s[i+j] != t[j]) tmp++;
    res = min(res, tmp);
  }
  fprintf(stdout, "%d\n", res);
  return 0;
}


Measured memory_bytes: 3732
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> h(n + 1, 0);

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

  int ans = 0;
  while (true) {
    bool is_all_zero = true;
    for (int i = 0; i < n; i++) {
      if (h[i] != 0) {
        is_all_zero = false;
      }
    }
    if (is_all_zero) {
      break;
    }
    int now = 0;
    bool flag = false;
    while (now < n + 1) {
      if (h[now] != 0) {
        h[now]--;
        flag = true;
      } else if (h[now] == 0 && flag) {
        ans++;
        flag = false;
      }
      now++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1000000007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

long long calc(vector<long long> &pos, vector<long long> &neg, long long zero, long long x){
    long long ign = 0;
    for(auto a : pos) if(a*a<=x) ign++;
    for(auto a : neg) if(a*a<=x) ign++;

    long long cnt = 0;
    for(auto a : pos){
        long long thr;
        if(x >= 0) thr = x / a;
        else thr = -((-x+a-1)/a);
        cnt += upper_bound(pos.begin(), pos.end(), thr) - pos.begin();
        cnt += upper_bound(neg.begin(), neg.end(), thr) - neg.begin();
    }
    for(auto a : neg){
        long long thr;
        if(x <= 0) thr = (-x-a-1)/(-a);
        else thr = x / a;
        cnt += pos.end() - lower_bound(pos.begin(), pos.end(), thr);
        cnt += neg.end() - lower_bound(neg.begin(), neg.end(), thr);
    }
    cnt = (cnt - ign) / 2;
    if(x >= 0){
        cnt += zero*(zero-1)/2 + zero*(pos.size() + neg.size());
    }
    return cnt;
}


int main(){
    long long N, K;
    cin >> N >> K;
    vector<long long> A(N);
    REP(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    vector<long long> pos, neg;
    long long zero = 0;
    REP(i, N){
        if(A[i] > 0) pos.push_back(A[i]);
        else if(A[i] < 0) neg.push_back(A[i]);
        else zero++;
    }
    long long lb = -(1LL<<60);
    long long ub = +(1LL<<60);
    while(ub - lb > 1){
        long long mid = (lb + ub) / 2;
        long long cnt = calc(pos, neg, zero, mid);
        if(cnt >= K) ub = mid;
        else lb = mid;
    }
    cout << ub << endl;
    return 0;
}

Measured memory_bytes: 4084
#include<stdio.h>
int a[10005];

int main()
{
    int N,M;
     int sum=0,ans=0;
    scanf("%d%d",&N,&M);

    for(int i=1;i<=M;i++)
    {
        scanf("%d",&a[i]);

    }

    for(int i=1;i<=M;i++)
    {
        sum=sum+a[i];
        if(sum>N)
            {
                ans=-1;
                break;
            }
    }


    if(sum<=N)
    {
        ans=N-sum;
    }
    printf("%d",ans);

}


Measured memory_bytes: 1768