akhauriyash/Code-Regression huggingface dataset:
using System;

namespace AOJ.Volume2
{
    public class LastOne
    {
        public static int Main()
        {
            int n = int.Parse(Console.ReadLine());
            for(int i = 0; i < n; i++)
            {
                var input = Console.ReadLine().Split(' ');
                int k = int.Parse(input[0]);
                int p = int.Parse(input[1]);

                Console.WriteLine(k % p == 0 ? p : k % p);
            }
            return 0;
        }
    }
}

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, k; cin >> n >> k;
    vector<ll> v(n);
    REP(i, n) cin >> v[i];
    ll index_of_1 = find(ALL(v), 1) - v.begin();

    ll min_count = INF;
    for (size_t base = max(0LL, index_of_1 - n + 1); base < min(n - 1, index_of_1 + n - 1); base++) {
        ll count = 0;
        ll current = base;
        while (current > 0) {
            count++;
            current -= k - 1;
        }

        current = base;
        while (current < n-1) {
            count++;
            current += k - 1;
        }

        min_count = min(min_count, count);
    }
    cout << min_count << endl;
    return 0;    
}

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

typedef long long ll;
const int N = 200005;

ll a[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin>>n;
	
	int x = 0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		x ^= a[i];
	}
	
	for(int i=0;i<n;i++){
		int ans = x ^ a[i];
		cout<<ans<<" ";
	}
	
	return 0;
}


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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

//
// # Examples
//
// # integers
// input! { n: i32, m: i32, ... }
//
// # array
// input! { n: i32, v: [i32; n], }
//
// # matrix
// input! { n: i32, m: i32, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: i32,
//     w: i32,
//     board: [chars; h],
// }

// https://practice.contest.atcoder.jp/tasks/practice_1
//fn main() {
//    input!{
//        a: i32, b: i32, c: i32,
//        foo: chars,
//    }
//    let s: String = foo.into_iter().collect();
//    println!("{} {}", a+b+c, s);
//}
use std::cmp;
fn main() {
    input!{
        a: usize, b: usize, c: usize, d: usize
    }

    println!("{}", cmp::min(a,b)+cmp::min(c,d));
}

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

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



Measured memory_bytes: 3020
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int n,k;
vector<int> v;

void solve(){
    int m = min(n,k);
    long long ans = 0;
    for(int i=0; i <= m; i++){
        for(int j=0; j<=i; j++){
            vector<int> v2;
            for(int h=0; h < j; h++){
                v2.push_back(v[h]);
            }
            for(int h=n-1; h >= n - (i-j); h--){
                v2.push_back(v[h]);
            }
            for(int h=0; h < (k-i) && !v2.empty() ; h++){
                auto p = min_element(v2.begin(),v2.end());
                if(*p >= 0) break;
                v2.erase(p);
            }
            if(!v2.empty()){
                long long tmp = accumulate(v2.begin(),v2.end(),0);
                if(ans < tmp) ans = tmp;
            }
        }
    }
    cout << ans << endl;
}

int main(){
    cin >> n >> k;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        v.push_back(a);
    }
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
	int a,b,c;
  	cin>>a>>b>>c;
  
  	if(c>=a&&c<=b){
    	cout <<"Yes"<< endl;
    }else if(c<=a&&c>=b){
    	cout <<"Yes"<< endl;
    }else{
    	cout <<"No"<< endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int fib[50];
    fib[0] = 1;
    fib[1] = 1;
    for(int i = 2;i < 50; i++)
    {
        fib[i] = fib[i-1] + fib[i-2];
    }
    cout << fib[n] << endl;
    return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
using Int = long long;
vector<int> scc(const vector<vector<int>> &G) {
    int N = G.size();
    vector<int> low(N), dfsnum(N, -1), comp(N, -1);
    stack<int> L;
    int num = 0, conum = 0;
    auto visit = [&](auto&& visit, int p) -> void {
        L.push(p);
        low[p] = dfsnum[p] = num++;
        for (int q : G[p]) {
            if (comp[q] >= 0) continue;
            if (dfsnum[q] < 0) {
                visit(visit, q);
                low[p] = min(low[p], low[q]);
            } else {
                low[p] = min(low[p], dfsnum[q]);
            }
        }
        if (low[p] == dfsnum[p]) {
            for (;;) {
                int v = L.top(); L.pop();
                comp[v] = conum;
                if (v == p) break;
            }
            conum++;
        }
    };
    for (int i = 0; i < N; i++) {
        if (comp[i] < 0) visit(visit, i);
    }
    return comp;
}
struct TwoSat {
    int N;
    vector<vector<int>> G;
    TwoSat(int n) : N(n), G(2 * n) {}
    int neg(int x) {
        if (x < N) return x + N;
        else return x - N;
    }
    void add_clause(int x, int y) {
        G[neg(x)].push_back(y);
        G[neg(y)].push_back(x);
    }
    vector<bool> satisfy() {
        vector<bool> ans(N);
        auto comp = scc(G);
        for (int i = 0; i < N; i++) {
            if (comp[i] == comp[i + N]) {
                return {};
            }
            ans[i] = comp[i] < comp[i + N];
        }
        return ans;
    }
};
int main() {
    int N, D; cin >> N >> D;
    vector<int> X(N), Y(N);
    for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];
    TwoSat ts(N);
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            // !(i is X && j is X) == !(i && j) == !i || !j
            if (abs(X[i] - X[j]) < D) {
                ts.add_clause(ts.neg(i), ts.neg(j));
            }
            if (abs(X[i] - Y[j]) < D) {
                ts.add_clause(ts.neg(i), j);
            }
            if (abs(Y[i] - X[j]) < D) {
                ts.add_clause(i, ts.neg(j));
            }
            if (abs(Y[i] - Y[j]) < D) {
                ts.add_clause(i, j);
            }
        }
    }
    auto ans = ts.satisfy();
    if (ans.empty()) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
        for (int i = 0; i < N; i++) {
            cout << (ans[i] ? X[i] : Y[i]) << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 3752
import java.util.Scanner;
import java.util.Arrays;
 
public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int n = stdIn.nextInt();
        String[] s = new String[n];
        for(int i=0; i<n; i++){
            s[i] = stdIn.next();
        }

        Arrays.sort(s);

        String prev = s[0];
        int counter = 1;
        for(int i=1; i<n; i++){
            if(!s[i].equals(prev)){
                counter++;
            }
            prev = s[i];
        }

        System.out.println(counter);
    }
}

Measured memory_bytes: 70176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
vector<int>p;

int main(){
	cin>>n>>k;
	for(int i=0; i<n; i++){
		int t;
		cin>>t;
		p.push_back(t);
	}
	sort(p.begin(),p.end());
	int amin=1000000000;
	for(int i=0; i<n-k+1; i++){
		amin=min(amin,abs(p[i]-p[i+k-1]));
	}
	cout<<amin<<endl;
}


Measured memory_bytes: 892
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
#include<cstdlib>
#include <queue>
#include <cmath>
#include <iomanip>
#include<list>
#include <utility>
#include <functional>
#include<map>
#include<stack>
#define T long long


int main(){
	std::string s,t;
	std::getline(std::cin,s);
	std::getline(std::cin,t);
	for(int i=0;i<s.size();i++){
		if(s[i]!=t[i]){
			std::cout << "No"<<std::endl;
			return 0;
		}
	}
	std::cout << "Yes"<<std::endl;
}


Measured memory_bytes: 3628
n, m = map(int, input().split())

right = 2*m+1

if m%2 == 0:
    for i in range(m//2):
        print(1+i, 1+m-i)
        print(2+m+i, right-i)

else:
    center = m+1
    for i in range(m//2):
        print(1+i, center-i)
        print(center+1+i, right-i)
    print(m//2+1, m//2+2)


Measured memory_bytes: 75024
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("ride.in");ofstream coutt("ride.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 

signed main(){
    FASTER;
    int a,b;cin>>a>>b;
    if(a>=13){
        cout<<b;
    }else if(a>=6 && a<=12){
        cout<<b/2;
    }else cout<<0;
}

Measured memory_bytes: 3616
#include <stdio.h>
int main(void)
{

  int a,b=1,c=2,d=3,e=4,f=5,g=6,h=7,i=8,j=9,k;

  for(a=1;a<=9;a++){
    k=a*b;
    printf("%dx%d=%d\n",b,a,k);}

   for(a=1;a<=9;a++){
    k=a*c;
    printf("%dx%d=%d\n",c,a,k);}
  for(a=1;a<=9;a++){
    k=a*d;
    printf("%dx%d=%d\n",d,a,k);}
 for(a=1;a<=9;a++){
    k=a*e;
    printf("%dx%d=%d\n",e,a,k);}
 for(a=1;a<=9;a++){
    k=a*f;
    printf("%dx%d=%d\n",f,a,k);}
 for(a=1;a<=9;a++){
    k=a*g;
    printf("%dx%d=%d\n",g,a,k);}
 for(a=1;a<=9;a++){
    k=a*h;
    printf("%dx%d=%d\n",h,a,k);} 
 for(a=1;a<=9;a++){
    k=a*i;
    printf("%dx%d=%d\n",i,a,k);}
 for(a=1;a<=9;a++){
    k=a*j;
    printf("%dx%d=%d\n",j,a,k);}
return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

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

  vector<int> h(n);
  rep(i,n) cin >> h[i];

  int ans = 0;

  int memo = 0;
  for(int i = 0; i < n; i++){
    if(memo >= h[i]){
      memo = h[i];
    }else{
      ans += h[i] - memo;
      memo = h[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ara(A,N) sort(A,A+N)
#define rev(A,N) sort(A,A+N,greater<long long>())
using namespace std;
int main()
{
  speed_up;
  string s1, s2;
  cin>>s1>>s2;
  ll n1, n2;
  n1 = s1.size();
  n2 = s2.size();
  if(n1 == n2)
  {
  if(s1>s2) cout<<"GREATER"<<endl;
  else if(s1 == s2) cout<<"EQUAL"<<endl;
  else cout<<"LESS"<<endl;
  }
  else
  {
      if(n1>n2) cout<<"GREATER"<<endl;
      else cout<<"LESS"<<endl;
  }


return 0;
}



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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  vector<int> start(26, -1);
  vector<int> goal(26, -1);

  for (int i = 0; i < S.size(); i++) {
    int a = S[i] - 'a';
    int b = T[i] - 'a';
    if (start[a] != -1 || goal[b] != -1) {
      if (start[a] != b || goal[b] != a) {
        cout << "No" << endl;
        return 0;
      }
    }
    start[a] = b;
    goal[b] = a;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define long long ll
int main()
{
	string s,s1;
	cin>>s;
	s1=s;
	reverse(s1.begin(),s1.end());
	if(s==s1)cout<<"Yes";
	else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<b?(a=b,1):0)
#define chmin(a,b) (a>b?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int p[65000];
int jo[65000];

int main() {
  int n;
  while(cin>>n,n) {
    ll sum = 0;
    REP(i,n) {
      cin >> p[i];
      sum += p[i];
    }
    REP(i,n-1) {
      cin >> jo[i];
      sum += jo[i];
    }
    ll ans = sum;
    sort(jo,jo+n-1);
    ll a = 0;
    REP(i,n-1) {
      a += jo[i];
      chmax(ans, (i+2)*(sum-a));
    }
    cout << ans << endl;
  }
}

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

int main (void){

    int a,b;
    int count = 0;
    scanf("%d %d", &a, &b);

    int h[5];
    for(int i = a; i <= b; i++){
    
        int tmp = i;
        for(int j = 0; j < 5; j++){
             h[j] = tmp%10;
             tmp /= 10;       
        }
    
        if( h[0] == h[4] && h[1] == h[3] )
          count++;

    }

    printf("%d", count);

    return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0287

"""
import sys
from sys import stdin
input = stdin.readline


def solve(m, n):
    units = [
        ('Mts', 68), ('Fks', 64), ('Nyt', 60), ('Asg', 56), ('Ggs', 52), ('Gok', 48), ('Sai', 44), ('Sei', 40),
        ('Kan', 36), ('Ko', 32), ('Jou', 28), ('Jo', 24), ('Gai', 20), ('Kei', 16), ('Cho', 12), ('Oku', 8), ('Man', 4)
    ]
    num = m ** n

    ans = ''
    for u, i in units:
        if num >= 10**i:
            ans += str(num // 10**i) + u
            num %= 10**i
    if num:
        ans += str(num)
    return ans


def main(args):
    while True:
        m, n = map(int, input().split())
        if m == 0 and n == 0:
            break
        ans = solve(m, n)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 5620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

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

  int ans=0;
  if(s.find("RRR")!=-1) ans=3;
  else if(s.find("RR")!=-1) ans=2;
  else if(s.find("R")!=-1) ans=1;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3608
import java.util.*;

public class Main {
    static long total = 0;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		int count = 0;
		for (int i = 1; i < arr.length; i++) {
		    if (arr[i] != arr[i - 1]) {
		        count++;
		    }
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 25812
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
int n;
cin>>n;
int m=n;
int sm=0;
while (n){
sm+=n%10;
n=n/10;
}
if (m%sm==0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 256
def search(x, visited, edges):
  if visited[x]:
    return

  visited[x] = True
  for to in edges[x]:
    search(to, visited, edges)

def main():
  while True:
    m = int(input())
    if m == 0:
      break
    n = int(input())
    mp = [0] + [int(input()) for _ in range(n)] + [0]
    visited = [False] * (n + 2)
    rev_visited = [False] * (n + 2)
    edges = [[] for _ in range(n + 2)]
    rev_edges = [[] for _ in range(n + 2)]
    for i in range(n + 2):
      for j in range(1, m + 1):
        nex = i + j
        nex = min(nex, n + 1)
        nex += mp[nex]
        nex = min(nex, n + 1)
        nex = max(nex, 0)
        edges[i].append(nex)
        rev_edges[nex].append(i)
  
    search(0, visited, edges)
    search(n + 1, rev_visited, rev_edges)
    for node in range(n + 1):
      if visited[node] and not rev_visited[node]:
        print("NG")
        break
    else:
      print("OK")

main()


Measured memory_bytes: 5768
#include<bits/stdc++.h>
using namespace std;
char ch[55];
int n,k;
int main() {
	cin>>n>>k;
	for(int i=0;i<n;i++) {
		cin>>ch[i];
	}
	ch[k-1]-='A';
	ch[k-1]+='a';
	cout<<ch<<endl;
}

Measured memory_bytes: 256
# AtCoder Beginner Contest 082 A
# [URL]      https://atcoder.jp/contests/abc082/tasks/abc082_a
# [compiler] Version 0.5.0

#==================================================================================================#

function get_data_from_stdin()
	return Base.parse.( Base.split( Base.readline( Base.STDIN ) ) )
end

function abc082_a()

	# STEP.01
	# get the target positive numbers
	a, b = get_data_from_stdin()

	# STEP.02
	# output the result
	Base.println( Base.STDOUT, Base.div(a+b, 2)+Base.rem(a+b, 2) )

	# STEP.TRUE_END
	return Base.nothing

end

#==================================================================================================#

Main.abc082_a()


Measured memory_bytes: 119424
import heapq
import copy

N = int(input())
rest = list(map(lambda x: -1*int(x), input().split()))
heapq.heapify(rest)
generated = [heapq.heappop(rest)]
flg = True
for i in range(N):
    tmp_generated = copy.copy(generated)
    tmp = []
    while len(tmp_generated) > 0:
        v = heapq.heappop(tmp_generated)
        found = False
        while len(rest)>0:
            t = heapq.heappop(rest)
            if v < t:
                heapq.heappush(generated, t)
                found = True
                break
            tmp.append(t)
        if not found:
            flg = False
            break
    for t in tmp:
        heapq.heappush(rest, t)
    if not flg:
        break
print('Yes' if flg else 'No')


Measured memory_bytes: 178368
import java.util.*;

public class Main {

    static class Edge {
        int from, to;

        public Edge(int from, int to) {
            this.from = from;
            this.to = to;
        }
    }

    static void bfs(int at) {
        visited = new boolean[N];
        visited[at] = true;

        Deque<Integer> deq = new ArrayDeque<>();
        deq.add(at);

        while (!deq.isEmpty()) {
            int node = deq.poll();
            List<Edge> edges = graph.get(node);

            for (Edge e : edges) {
                if (visited[e.to]) continue;

                dist[at][e.to] = dist[at][node] + 1;
                visited[e.to] = true;
                deq.offer(e.to);
            }
        }
    }

    static int N;
    static List<List<Edge>> graph;
    static int[][] dist;
    static boolean[] visited;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.next());
        int X = Integer.parseInt(sc.next()) - 1;
        int Y = Integer.parseInt(sc.next()) - 1;
        graph = new ArrayList<>();
        for (int i = 0; i < N; ++i) graph.add(new ArrayList<>());
        dist = new int[N][N];
        for (int i = 0; i < N; ++i) Arrays.fill(dist[i], 0);

        for (int i = 0; i < N-1; ++i) {
            graph.get(i).add(new Edge(i, i+1));
            graph.get(i+1).add(new Edge(i+1, i));
        }
        graph.get(X).add(new Edge(X, Y));
        graph.get(Y).add(new Edge(Y, X));

        for (int i = 0; i < N; ++i) {
            bfs(i);
        }

        int[] res = new int[N];
        for (int i = 0; i < N; ++i) {
            for (int j = i + 1; j < N; ++j) {
                ++res[dist[i][j]];
            }
        }

        for (int k = 1; k <= N-1; ++k)
            System.out.println(res[k]);
    }
}

Measured memory_bytes: 73700
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 9;
int n, d[N], pre[N], f[N], q, x, i;
int main () {
	for (scanf("%d%d", &n, pre), f[n] = i = 1; i <= n; ++i) scanf("%d", &d[i]), pre[i] = min(pre[i - 1], abs(pre[i - 1] - d[i]));
	for (i = n; i; --i) f[i - 1] = d[i] / 2 < f[i] ? f[i] + d[i] : f[i];
	for (scanf("%d", &q), i = 1; i <= q; ++i) puts((scanf("%d", &x), pre[x - 1] >= f[x]) ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 7808
S =input()
ZeroAdd =[]
for i in range(len(S)):
    if i == 0 and S[0] == "<":
        ZeroAdd.append(0)
    elif i == len(S)-1 and S[-1] == ">":
        ZeroAdd.append(len(S))
    elif S[i-1]==">" and S[i]=="<":
        ZeroAdd.append(i)
ans = 0
moji ="a"
if ZeroAdd[0] != 0:
    n = ZeroAdd[0]
    ans += n*(n+1)//2
if ZeroAdd[-1] != len(S):
    n = len(S) - ZeroAdd[-1]
    ans += n*(n+1)//2
if len(ZeroAdd)>1:
    for i in range(len(ZeroAdd)-1):
        moji = S[ZeroAdd[i]:ZeroAdd[i+1]]
        Sa = moji.count("<")
        La = moji.count(">")
        if Sa > La:
            n = Sa
            m = La - 1
        else:
            n = La
            m = Sa - 1
        ans += n*(n+1)//2+m*(m+1)//2
print(ans)

Measured memory_bytes: 9204
INF = 1000000


def bellman_ford(graph, source):
    lg = len(graph)
    unused = list(range(lg))
    d = [INF] * (lg)
    d[source] = 0

    while unused:
        v = min(unused, key=lambda u: d[u])
        unused.remove(v)
        for u in range(n + 1):
            d[u] = min(d[u], d[v] + graph[v][u])

    return d

n = int(input())
m = int(input())

cost = [[INF] * (n + 1) for i in range(n + 1)]
for i in range(m):
    ai, bi, ci, di = map(int, input().split(','))
    cost[ai][bi] = ci
    cost[bi][ai] = di

x1, x2, y1, y2 = map(int, input().split(','))

d_go = bellman_ford(cost, x1)[x2]
d_back = bellman_ford(cost, x2)[x1]

print(y1 - y2 - d_go - d_back)

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

int main() {
  string s;
  cin >> s;
  if (s[0] == s[1] && s[1] == s[2] || s[1] == s[2] && s[2] == s[3]) {
    cout <<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


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


def main():
    input()
    nums = rli()
    nums.sort()
    ans = 0
    for i in range(0, len(nums), 2):
        ans += nums[i]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<3;i++)ans+=s[i]=='R';
    if(ans==3)puts("3");
    else if(ans==1)puts("1");
    else if(ans==0)puts("0");
    else if(s[1]=='R')puts("2");
    else puts("1");
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <cmath>
#include <numeric>

#define MOD 1000000007

using namespace std;

typedef long long ll;

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;

typedef pair<ll, ll> pll;
typedef pair<int, int> pi;

typedef vector<pll> vpl;
typedef vector<pi> vpi;

typedef queue<ll> ql;
typedef queue<int> qi;

template <class T>
void printv(vector<T> vc) {
    for (auto e: vc) cout << e << " ";
    cout << endl;
}

template <class T>
void printvv(vector<T> vvc) { 
    for (auto vc: vvc) {
        for (auto e: vc) cout << e << " ";
        cout << endl;
    }
}

template <class T>
void printvp(vector<pair<T, T> > vp) {
    for (auto pT: vp) cout << pT.first << " " << pT.second << endl;
}

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

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

    int& m = p.back();
    m /= 2;

    int sum = accumulate(p.begin(), p.end(), 0);

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 888
#include <stdio.h>
#define num3 3

int main(void){
  int n;
  scanf("%d\n",&n);
  int Anum[n];
  int test=0;
  for(int i;i < n;i++){
    scanf("%d ",&Anum[i]);
    if((Anum[i] % 2) == 0 && (Anum[i] % 3) != 0 && (Anum[i] % 5) != 0){
      test++;
    }
  }
  if(test > 0){
    printf("\nDENIED");
  }
  else{
    printf("\nAPPROVED");
  }
  return 0;
}


Measured memory_bytes: 1728
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.array;

void main() {
    auto l = readln.chomp.split.map!(to!int).array;

    int a = l[0], b = l[1];
    int ans;

    for (int i = a; i <= b; ++i) {
        auto s = i.to!(string), t = s.map!(to!char).array.reverse;

        if (s == t) {
            ans++;
        }
    }

    writeln(ans);

    return;
}


Measured memory_bytes: 1276
using System;
using System.Collections.Generic;

namespace ProgrammingContest
{
    class Program
    {
        public void Solve()
        {
            var line = Console.ReadLine().Split(' ');
            int N = int.Parse(line[0]);
            long A = int.Parse(line[1]);
            long B = int.Parse(line[2]);
            line = Console.ReadLine().Split(' ');
            int[] X = new int[N];
            for (int i = 0; i < N; i++)
            {
                X[i] = int.Parse(line[i]);
            }

            long ans = 0;

            for (int i = 1; i < N; i++)
            {
                ans += Math.Min(B, A * (X[i] - X[i - 1]));
            }
            Console.WriteLine(ans);
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define repm(i,m,n) for(ll i=m;i<n;i++)
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define YesNo(a) (a)?cout<<"Yes"<<endl:cout<<"No"<<endl
#define YESNO(a) (a)?cout<<"YES"<<endl:cout<<"NO"<<endl
#define INF (2e9)
#define PI (acos(-1))
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

typedef long long ll;

int main(){
    ll N; cin >> N;
    vector<ll> A(N); rep(i,N) cin >> A[i];

    ll max_tall = 0;
    ll ans = 0;
    rep(i,N){
        max_tall = max(A[i], max_tall);
        ans += max(0, max_tall-A[i]);
    }

    cout << ans << endl;
}


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

using namespace std;

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

int main() {
	ll x, y;
	cin >> x >> y;
	ll ax,ay;
	ll ans = 0;
	ax = abs(x);
	ay = abs(y);
	if (x == 0 || y == 0) {
		if (x == 0 && y == 0){
			ans = 0;
		} else if (x == 0) {
			if (y > 0) {
				ans = y;
			} else {
				ans = labs(y);
				ans++;
			}
		} else if (y == 0) {
			if (x < 0) {
				ans = labs(x);
			} else {
				ans = labs(x);
				ans++;
			}
		}
	} else if (x > 0 && y > 0) {
		if (x <= y) {
			ans = y - x;
		} else {
			ans = x - y;
			ans += 2;
		}
	} else if (x > 0 && y < 0) {
		ans = labs(ay - x);
		ans++;
	} else if (x < 0 && y > 0) {
		ans = labs(ax - y);
		ans++;
	} else {
		if (x <= y) {
			ans = labs(ax - ay);
		} else {
			ans = labs(ay - ax);
			ans += 2;
		}
	}
	
	cout << ans << endl;
	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
constexpr int M = 1e9 + 7;
constexpr int INF = 1e9;

int main() {
    string S, T;
    cin >> S >> T;
    string res;
    for(int i = (int)S.size() - (int)T.size(); i >= 0; --i) {
        bool check = true;
        for(int j = 0; j < T.size(); ++j) {
            check &= S[i + j] == '?' || S[i + j] == T[j];
        }
        if(check) {
            for(int j = 0; j < i; ++j) {
                res += (S[j] == '?' ? 'a' : S[j]);
            }
            res += T;
            break;
        }
    }
    if(res.size() == 0) {
        cout << "UNRESTORABLE" << endl;
    } else {
        for(int i = res.size(); i < S.size(); ++i) {
            res += (S[i] == '?' ? 'a' : S[i]);
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 256
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

int main()
{
    IOS();
    ll K;
    cin>>K;
    cout<<(K/2) * ((K+1) /2)<<endl;
}


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


int main() {

int N;
cin>>N;
vector<long> a(N);
vector<long> b(N);
vector<long> c(N);

for(int i=0;i<N;i++) cin>>a[i];
for(int i=0;i<N;i++) cin>>b[i];
for(int i=0;i<N;i++) cin>>c[i];

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

long ans=0;
for(int i=0;i<N;i++){
  long B=b[i];
  auto ita = lower_bound(a.begin(),a.end(),B);
  auto itc = upper_bound(c.begin(),c.end(),B);
  long lenA=ita-a.begin();
  long lenC=c.end()-itc;
  //cout<<*ita<<" "<<*itc<<endl;
  //cout<<lenA<<" "<<lenC<<endl;
  ans += lenA*lenC;
}
cout<<ans<<endl;
}


Measured memory_bytes: 2560
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
#mod = 10 ** 9 + 7 
mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

#階乗#
lim = 50
fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1]

def C(n, r):
	return fact[n]//fact[n-r]//fact[r]


N, A, B = MAP()
v = sorted(LIST(), reverse=True)
key = v[A-1]
print(sum(v[:A])/A)

v = v[::-1]
n = bisect(v, key) - bisect_left(v, key)
m = N - bisect(v, key)


if m == 0:
	ans = 0
	for i in range(A, min(B-m, n)+1):
		ans += C(n, i)
	print(ans)
else:
	print(C(n, A-m))

Measured memory_bytes: 9980
import Data.Char
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as BS
main = do
  n <- readLn :: IO Int
  xs <- VU.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ VU.minimum $ VU.map (\i -> VU.sum $ VU.map (\x -> (x-i)^2) xs) $ VU.enumFromN (-100::Int) 201

Measured memory_bytes: 508
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int r;
	cin >> r;
	cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,a,b) for(int i(a);i<b;i++)
#define rep(i,n) for(int i(0);i<n;i++)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);
#define pres(x) cout<<fixed; cout<<setprecision(x);
#define open freopen("input.txt","r",stdin) ; freopen("output.txt","w",stdout);
#define watch(x) cout<<(#x)<<" is "<<x<<"\n";
#define out(x) cout<<x<<"\n";
#define pb push_back
#define all(v) v.begin() v.end()

int32_t main(){
	
	fast;
	//open;

	int n;
	cin>>n;
	int array[n];
	rep(i,n)cin>>array[i];
	int dp[n];
	dp[0]=1;
	f(i , 1 , n){
		if(array[i]<=array[i-1])dp[i] = dp[i-1] + 1;
		else dp[i] = 1;
	}

	sort(dp , dp + n);
	cout<<dp[n-1]-1;

	return 0;
}

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

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
int main(){
	ios::sync_with_stdio(false);
	int n,m;
	string s;
	cin>>n>>s>>m;
	for(int i=0;i<s.size();i++){
		if(s[i]!=s[m-1])s[i]='*';
	}	
	cout<<s;
	return 0;
}

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

using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;

template<typename C>
i64 Size(const C& c) { return static_cast<i64>(c.size()); }

template<typename C>
void Sort(C &c) { std::sort(c.begin(), c.end()); }

template<typename C>
void SortR(C &c) { std::sort(c.rbegin(), c.rend()); }

template<typename T, typename U, typename Comp=std::less<>>
bool ChMax(T& x_max, const U& x, Comp comp={}) {
  if(comp(x_max, x)) {
    x_max = x;
    return true;
  }
  return false;
}

template<typename T, typename U, typename Comp=std::less<>>
bool ChMin(T& x_min, const U& x, Comp comp={}) {
  if(comp(x, x_min)) {
    x_min = x;
    return true;
  }
  return false;
}

struct ProconInit {
  static constexpr int IOS_PREC = 15;
  static constexpr bool AUTOFLUSH = false;

  ProconInit() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(IOS_PREC);
    if (AUTOFLUSH) std::cout << std::unitbuf;
  }
} PROCON_INIT;

void solve() {
  i64 n; std::cin >> n;
  i64 m; std::cin >> m;
  std::vector<i64> a(m); for (auto &i : a) std::cin >> i;

  for (auto &i : a) {
    n -= i;
    if (n < 0) {
      std::cout << -1 << "\n";
      return;
    }
  }

  std::cout << n << "\n";
}

signed main() {
  solve();

  return 0;
}


Measured memory_bytes: 3700
using System;


namespace ConsoleApplication13
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 1;
            int x;
            while (true)
            {
                string s = Console.ReadLine();
                x = int.Parse(s);
                if (x == 0) break;

                if (0 < x)
                {
                    Console.WriteLine("Case"+" "+ i + ":"+" " + x);
                    i++;

                }

            }

        }
    }
}

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

using namespace std;

int main(void)
{
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	if(s[k-1] == 'A') s[k-1] = 'a';
	else if(s[k-1] == 'B') s[k-1] = 'b';
	else s[k-1] = 'c';
	cout<<s<<endl;
	return 0;
}



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

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A) {
    if (A.size() == n+1) {
        int now = 0;
        rep(i,q) {
            if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        ans = max(ans, now);
        return;
    }
    
    A.push_back(A.back());
    while (A.back() <= m) {
        dfs(A);
        A.back()++;
    }
}

int main() {
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    rep(i,q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<int>(1,1));
    cout << ans << endl;
}

Measured memory_bytes: 3580
//
//  main.cpp
//  rough
//
//  Created by abhishek kumar on 30/04/20.
//  Copyright © 2020 abhishek kumar. All rights reserved.
//

#include <iostream>
#include<vector>
using namespace std;
typedef long long int ll;


int main(int argc, const char * argv[]) {
    
    ll mod=1000000007;
    
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    char temp;
    vector<vector<ll>> arr(n+1,vector<ll>(m+1,0));
    
    for(auto i=1;i<n+1;i++)
    {
        for(auto j=1;j<m+1;j++)
        {
            cin>>temp;
            if(temp=='#') arr[i][j]=-1;
        }
    }
   
    
    for(auto i=1;i<m+1;i++)
    {
        if(arr[1][i]!=-1) arr[1][i]=1;
        else break;
    }
    
    for(auto i=1;i<n+1;i++)
       {
           if(arr[i][1]!=-1) arr[i][1]=1;
           else break;
       }
    
    
    
    
    
    for(auto i=2;i<n+1;i++)
    {
        for(auto j=2;j<m+1;j++)
        {
            if(arr[i][j]==-1) continue;
            
            if(arr[i-1][j] > 0) arr[i][j]=(arr[i][j] + arr[i-1][j])%mod;
            if(arr[i][j-1] > 0) arr[i][j]=( arr[i][j] + arr[i][j-1])%mod;
        }
    }
    
    if(arr[n][m]!=-1) cout<<arr[n][m];
    else cout<<"0";
    
    return 0;
}

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

using namespace std;

int *A;
int N;
int SwapNum;
int Count;

void BubbleSort()
{
  bool flag = true;
  int i = 0;
  SwapNum = 0;

  do
  {

    flag = false;
    for(int j = N - 1; j >= i + 1; --j)
    {
      if(A[j] < A[j-1])
      {
	int tmp = A[j];
	A[j] = A[j-1];
	A[j-1] = tmp;

	flag = true;
	++SwapNum;
      }

    }

    ++i;


  }while(flag);

  return;
}

void SelectionSort()
{

  SwapNum = 0;
  for(int i = 0; i < N; ++i)
  {
    int mini = i;
    bool flag = false;

    for(int j = i; j < N; ++j)
    {
      if(A[j] < A[mini])
      {
	mini = j; 
	flag = true;	
      }
    }

    if(flag)
    {
      int tmp = A[i];
      A[i] = A[mini];
      A[mini] = tmp;

      ++SwapNum; 
    }
  }

  return;

}

void InsertionSort(int g)
{

  for(int i = g; i < N; ++i)
  {
    int v = A[i];
    int j = i - g;

    while( j >= 0 && A[j] > v)
    {
      A[j + g] = A[j];
      j = j - g;
      ++Count;
    }
    A[j + g] = v;
  }

  return;
}

void ShellSort()
{

  Count = 0;

  int m = 0;
  int s = 1;

  while(N / s > 0)
  {
    s *= 2;
    ++m;
  }

  int G[N];

  for(int i = 0, s = 1; i < m; ++i, s *= 2)
    G[i] = N / s; 

  for(int i = 0; i < m; ++i)
    InsertionSort(G[i]);

  cout << m << endl;

  for(int i = 0; i < m; ++i) 
    cout << (i != 0 ? " " : "") << G[i];
  cout << endl;

  cout << Count << endl;

  for(int i = 0; i < N; ++i)
    cout << A[i] << endl;

  return;
}

int *L, *R;

void Merge(int left, int mid, int right)
{
  int n1 = mid - left;
  int n2 = right - mid;

  for(int i = 0; i < n1; ++i)
    L[i] = A[left+i];
  for(int i = 0; i < n2; ++i)
    R[i] = A[mid+i];

  R[n2] = L[n1] = INT_MAX;

  int i = 0, j = 0;

  for(int k = left; k < right; ++k, ++SwapNum)
    A[k] = (L[i] <= R[j]) ? L[i++] : R[j++];
}

void MergeSort(int left, int right)
{
  if(left + 1 < right)
  {
    int mid = (left + right) / 2;
    MergeSort(left, mid);
    MergeSort(mid, right);
    Merge(left, mid, right);

    //++SwapNum;
  }
}

int main()
{
  cin >> N;

  A = new int[N];
  L = new int[N];
  R = new int[N];

  for(int i = 0; i < N; ++i)
    cin >> A[i];

  SwapNum = 0;
  //BubbleSort();
  //SelectionSort();
  //ShellSort();

  MergeSort(0, N);

  cout << A[0];
  for(int i = 1; i < N; ++i)
    cout << " " << A[i];

  cout << endl;
  cout << SwapNum << endl;

  delete [] L;
  delete [] R;
  delete [] A;


}


Measured memory_bytes: 6764
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

    int main(){
        lint n,m;
        cin>>n>>m;
        lint x[n];
        lint y[n];
        lint z[n];
        rep(i,n)cin>>x[i]>>y[i]>>z[i];
        lint ans=0;
        lint g[n];
        rep(bit,8){
            bool a[3];
            fill(a,a+3,false);
            rep(i,3)if(bit&(1<<i))a[i]=true;
            rep(i,n){
                lint b=0;
                if(a[0])b+=x[i];
                else b-=x[i];
                if(a[1])b+=y[i];
                else b-=y[i];
                if(a[2])b+=z[i];
                else b-=z[i];
                g[i]=b;
            }
            lint comp=0;
            sort(g,g+n,greater<lint>());
            rep(i,m)comp+=g[i];
            ans=max(ans,comp);
        }
        cout<<ans<<endl;


    }
      

Measured memory_bytes: 3716
#include<iostream>

using namespace std;

int main(){
    int a[3][3];
    int key[3][3] ={{0,0,0},{0,0,0}, {0,0,0}};
    int i,j,k;
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            cin >> a[i][j];
        }
    }
    int n;
    int b[110];
    cin >> n;
    for(k=0;k<n;k++){
        cin >> b[k];
    }
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            for(k=0;k<n;k++){
                if(b[k]==a[i][j]){
                    key[i][j]=1;
                }
            }
        }
    }
    int flg = 0;
    for(i=0;i<3;i++){
        if(key[i][0]==1 && key[i][1]==1 && key[i][2] == 1){
            flg = 1;
        }
    }
    for(j=0;j<3;j++){
        if(key[0][j]==1 && key[1][j]==1 && key[2][j] == 1){
            flg = 1;
        }
    }
    if(key[0][0]==1 && key[1][1]==1 && key[2][2] == 1){
            flg = 1;
    }else if(key[0][2]==1 && key[1][1]==1 && key[2][0] == 1){
            flg = 1;
    }
    if(flg == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

int main()
{
	int n;
	vector<int> a;
	vector<int> b;
	cin >> n;
	a.reserve(n);
	b.reserve(n);
	rep(i, n)
	{
		int an;
		cin >> an;
		a.pb(an);
		b.pb(an - (i + 1));
	}

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

	int b_mid = b[b.size() / 2];

	ll sum = 0;
	rep(i, n)
	{
		sum += abs(a[i] - (b_mid + i + 1));
	}

	cout << sum << endl;

	return 0;
}


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

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

    std::string u = S.substr(0, 2);
    int ui = std::stoi(u);
    std::string d = S.substr(2, 2);
    int di = std::stoi(d);

    std::string ans;
    if ((ui == 0 && di == 0) || (ui > 12 && di > 12) || (ui == 0 && di > 12) || (ui > 12 && di == 0)) {
        ans = "NA";
    }
    else if ((ui > 0 && ui < 13) && (di > 0 && di < 13)) {
        ans = "AMBIGUOUS";
    }
    else if (ui == 0) {
        ans = "YYMM";
    }
    else if (di == 0) {
        ans = "MMYY";
    }
    else if (ui < 13) {
        ans = "MMYY";
    }
    else {
        ans = "YYMM";
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256