akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

	if (k <= a) {
		cout << k << endl;
	}
	else if (k>a && k <= a+b) {
		cout << a << endl;
	}else if(k > a+b){
		cout <<  a - (k-a-b) << endl;
	}

	return 0;
}

Measured memory_bytes: 3612
n = int(input())
li = [input().split() for _ in range(n)]
#print(src)
#[['khabarovsk', '20'], ['moscow', '10'], ['kazan', '50'], ['kazan', '35'], ['moscow', '60'], ['khabarovsk', '40']]
key_li = []
for l in li:
    if l[0] not in key_li:
        key_li.append(l[0])
dict = {}
sorted_ki = sorted(key_li)
for i,s in enumerate(sorted_ki):
    dict[i] = []
    for j,l in enumerate(li):
        if s == l[0]:
            dict[i].append([int(l[1]),j])
fin_li = []
for k in range(len(dict)):
    each_li = []
    for d in dict[k]:
        if d not in each_li:
            each_li.append(d[0])
    s_e_li = sorted(each_li, reverse=True)
    for s_e in s_e_li:
        for d in dict[k]:
            if s_e == d[0]:
                fin_li.append(d[1]+1)
for f in fin_li:
    print(f)

Measured memory_bytes: 3064
N, M = map(int, input().split())
sdt = []
for i in range(N):
    a, b = map(int, input().split())
    sdt.append((a, b))

chk = []
for i in range(M):
    a, b = map(int, input().split())
    chk.append((a, b))

ans = [0] * N

for i in range(N):
    jdg = float("INF")
    for k in range(M):
        a, b = sdt[i]
        c, d = chk[k]
        if jdg > abs(a-c)+abs(b-d):
            ans[i] = k+1
            jdg = abs(a-c)+abs(b-d)

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

Measured memory_bytes: 39536
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl;
#define NN cout << "No" << endl;
#define ve vector
const int INF = 1000000007;
const long double eps = 1.0E-14;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
// *max_element(all(d));
int n,m;
bool check(int a, int b, vector<string> img, vector<string> img_tmp){
  bool res = true;
  rep(i,m)rep(j,m){
    if(img[i + a][j + b] != img_tmp[i][j])res = false;
  }
  return res;
}
int solve(){
  cin >> n >> m;
  vector<string>img(n),img_tmp(m);
  rep(i,n)cin >> img[i];
  rep(i,m)cin >> img_tmp[i];
  bool ans = false;
  rep(i,n - m + 1)rep(j,n - m + 1){
    if(check(i,j,img,img_tmp)){
      ans = true;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
  return 0; 
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
} 

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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
	freopen ("F.in", "r", stdin);
	freopen ("F.out", "w", stdout);
}

const int N = 5010, Mod = 1e9 + 7;

int n; char str[N];

inline int fpm(int x, int power) {
	int res = 1;
	for (; power; power >>= 1, x = 1ll * x * x % Mod)
		if (power & 1) res = 1ll * res * x % Mod;
	return res;
}

int dp[N][N];

inline void Add(int &a, int b) {
	if ((a += b) >= Mod) a -= Mod;
}

int main () {

	n = read();
	scanf ("%s", str + 1);

	int len = strlen(str + 1);

	dp[0][0] = 1;
	For (i, 0, n - 1) For (j, 0, i) {
		Add(dp[i + 1][j + 1], dp[i][j] * 2 % Mod);
		Add(dp[i + 1][max(0, j - 1)], dp[i][j]);
	}

	printf ("%d\n", 1ll * dp[n][len] * fpm(fpm(2, len), Mod - 2) % Mod);

	return 0;

}


Measured memory_bytes: 96512
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new java.util.Scanner(System.in);
    int N =Integer.parseInt(sc.nextLine());
    List<Integer> omochi = new ArrayList<>();
    List<Integer> omochi2 = new ArrayList<>();
    for (int i = 0; i < N; i++) {
      omochi.add(Integer.parseInt(sc.nextLine()));
    }
    Collections.sort(omochi);
    for (int n = 0; n < N; n++) {
      if (n > 0) {
        if (omochi.get(n - 1) != omochi.get(n)) {
          omochi2.add(omochi.get(n));
        }
      } else {
        omochi2.add(omochi.get(n));
      }
    }
    System.out.println(omochi2.size());
  }
}


Measured memory_bytes: 23764
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
using namespace std;
typedef long long ll;
ll qread()
{
	ll ans=0;char c=getchar();
	while(c<'0' or c>'9') c=getchar();
	while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
	return ans;
}
void write(ll num)
{
	if(num>9) write(num/10);
	putchar('0'+num%10);
}
void writeln(ll num) {write(num);puts("");}
#define pr pair<int,int>
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
const int INF=0x3f3f3f3f;
void chmax(int &x,int y) {x=x>y?x:y;}

const int MAX_N=110;
int a[MAX_N];
int main()
{
	int n=qread(),m=qread();
	int cnt=0,x=0,y=0;
	for(int i=1;i<=m;i++)
	{
		a[i]=qread();
		if(a[i]&1) {cnt++;if(x==0) x=i; else y=i;}
	}
	if(m==1)
	{
		if(a[1]==1) printf("1\n1\n1\n",1);
		else printf("%d\n2\n%d 1",a[1],a[1]-1);
		return 0;
	}
	if(cnt>2) {puts("Impossible");return 0;}
	if(x>0) swap(a[1],a[x]);
	if(y>0) swap(a[m],a[y]);
	for(int i=1;i<=m;i++) printf("%d ",a[i]);puts("");
	if(a[1]==1) writeln(m-1); else writeln(m),printf("%d ",a[1]-1);
	for(int i=2;i<=m;i++) printf("%d ",a[i]+(i==m));
}
/*
6 4
2 1 1 2
*/

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
int main(){
 
    int A,B,r,l,K;
 
    scanf("%d%d",&A,&B);
 
    K=(A+B)/2;
    r=A-K;
    l=B-K;
    if(r<0){
    r=-1*r;
    }
    if(l<0){
        l=-1*l;
    }
    if(r==l){
        printf("%d",K);
    }
    else{printf("IMPOSSIBLE");}
 
    return 0;
 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,m;
	cin>>n>>m;
	if(n*2>=m){
		cout << m/2;
		return 0;
	}
	cout << n+(m-n*2)/4;
	return 0;
}

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

int main()
{
  i64 n;
  cin >> n;
  vector<i64> a(n);
  for (i64 i = 0; i < n; i++)
    cin >> a[i];
  vector<i64> sum(n + 1);
  for (i64 i = 0; i < n; i++)
    sum[i + 1] = sum[i] + a[i];
  i64 ans = 1e18;
  for (i64 i = 0; i < n; i++)
    ans = min(ans, abs(sum[i] - (sum[n] - sum[i])));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main(){
  int long long h;
  cin>>h;
  int long long n=0;
  while(h>0){
    h=h/2;
    n++;
  }
  int long long ans=2;
  for(int i=0;i<n-1;i++){
    ans=ans*2;
  }
  cout<<ans-1<<endl;
}

Measured memory_bytes: 256
N, T = map(int, input().split())
c_t = [[int(_) for _ in input().split()] for _ in range(N)]
flag = False
MinCost = 1000

for i in range(N):
    if c_t[i][1] <= T:
        flag = True
        if c_t[i][0] < MinCost:
            MinCost = c_t[i][0]

print(MinCost if flag else "TLE")

Measured memory_bytes: 3060
import java.util.*; 
 
class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
  	int b=sc.nextInt();
  	int t=1;
   	int c=0;
    while(t<b){
    t+=a-1;
    c++;
    }
    System.out.println(c);
    }
}

Measured memory_bytes: 21716
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    //a,b,mの入力
    int a = sc.nextInt();
    int b = sc.nextInt();
    int m = sc.nextInt();
    //クーポン入力の受け取り
    int x;
    int y;
    int z;
    //a.bの入力値受け取り
    int as[] = new int[a];
    int bs[] = new int[b];
    int ans; //結果
    int amin = 100000;//aの最小値
    int bmin = 100000;//bの最小値
    
    //a,bの入力及び最小値の算出
    for(int i = 0; i < a;i++) {
      as[i] = sc.nextInt();
      if(as[i] < amin) amin = as[i];
    }
    for(int i = 0; i < b;i++) {
      bs[i] = sc.nextInt();
      if(bs[i] < bmin) bmin = bs[i];
    }
    
    //クーポン無しでの最小値を初期値に
    
    ans = amin + bmin;
    
    //クーポンを使った場合を全て計算し、最小値を更新
    
   	for(int i = 0; i < m;i++){
      x = as[sc.nextInt()-1];
      y = bs[sc.nextInt()-1];
      z = x + y -sc.nextInt();
      
  	  if(z < ans) ans = z;
      	
    }
    
    //出力
    
    System.out.println(ans);
  }
}


Measured memory_bytes: 60348
n,k=map(int,input().split())
A=list(map(int,input().split()))

#m=A.index(1)

#le=m
#ri=n-m
#if le//(k-1)!=0 :
#    ri-=(k-1)-le%(k-1)

#print(le//(k-1)+ri//(k-1))

print(int((n-1-0.1)//(k-1)+1))


Measured memory_bytes: 13812
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int s[15];
int n = 3;

int main()
{
	for(int i = 1; i <= n; i++) cin >> s[i];
	sort(s + 1, s + 1 + n);
	int a = s[3] - s[1], b = s[3] - s[2];
	int p = 0;
	if(a % 2 == 0 && b % 2 == 0) p = min(a, b) + abs(a - b) / 2;
	else if((a & 1) && (b & 1)) p = min(a, b) + abs(a - b) / 2;
	else if(a & 1) p = b / 2 + 1 + a / 2 + 1;
	else p = a / 2 + 1 + b / 2 + 1;
	cout << p << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k, l = INT_MAX;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    
    for(int i = 0; i <= n - k;i++) {
        l = min(l, h[i + k - 1] - h[i]);
    }
    cout << l << endl;
 
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
int main(void){
    int i;
    int n=0,Sn=0;
    int num;
    if((scanf("%d",&n))==1){
        num=n;
        for(i=9;i>-1;i--){
            if(n/(pow(10.0,(double)i))!=0){
                Sn+=n/(pow(10.0,(double)i));
                n%=(int)pow(10.0,(double)i);
            }
        }
        if(num%Sn==0)printf("Yes\n");
        else printf("No\n");
        return 0;
    }
    else return -1;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) 
#define X first
#define Y second 
#define nl '\n'
#define AC return 0
#define pb(a) push_back(a) 
#define mst(a,b) memset(a, b, sizeof a)
#define rep(i,n) for(int i = 0; (i)<(n); i++)
#define rep1(i,n) for(int i = 1; (i)<=(n); i++)
#define scd(a) scanf("%lld", &a)
#define scdd(a,b) scanf("%lld%lld", &a, &b)
#define scs(s) scanf("%s", s)
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 1e6+10, M = 2e6+10, mod = 1e9+7, inf = 0x3f3f3f;
ll a[N]; 


int main()
{
	IOS;
	int n;
	cin>>n;
	bool ok = 0;
	int k = 0;
	rep1(i, n)
	{
		int a, b;
		cin>>a>>b;
		if(a == b)
			k++;
		else
			k = 0;
		if(k >= 3)
			ok = 1;
	}
	if(ok)
		puts("Yes");
	else
		puts("No");
	
	
	AC;
} 

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int m; cin >> m;
  cout << (48 - m) << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;

//2e5
const ll max_n = 1<<18;
const ll init_m=(1<<30);
ll leaf_n;
vector<ll> dat(max_n);

// 要素数決定、(1<<31)-1で初期化
void init(ll n) {
  leaf_n=1;
  while(leaf_n<n) leaf_n*=2;
  for(ll i=0;i<2*leaf_n-1;i++) dat[i]=init_m*2-1;
}

// from 0 [k]->a
void update(ll k,ll a) {
  k+=leaf_n-1;
  dat[k]=a;
  while(k>0) {
    k=(k-1)/2;
    dat[k]=min(dat[k*2+1],dat[k*2+2]);
  }
}

// (a,b,0,0,leaf_n),[a,b),[0,leaf_n)
ll find(ll a, ll b, ll k, ll l, ll r) {
  if(r<=a||b<=l) return init_m*2-1;
  if(a<=l&&r<=b) return dat[k];
  else {
    ll vl=find(a,b,k*2+1,l,(l+r)/2);
    ll vr=find(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
}

int main() {
  ll n,q;
  cin >> n >> q;
  init(n);
  for(ll i=0;i<q;i++) {
    ll c,x,y;
    cin >> c >> x >> y;
    if(c==0) {
      update(x,y);
    }
    else {
      cout << find(x,y+1,0,0,leaf_n) << endl;
    }
  }
}


Measured memory_bytes: 4780
#include<bits/stdc++.h>
#define maxn 200010
#define fi first
#define se second
#define LL long long 
#define pb push_back
#define Pii pair<LL,int>
#define mp make_pair
using namespace std;
char str[maxn];
int n, m;
int main(){
	cin >> n >> m;
	for(int i = 1; i <= n; i ++){
		cin >> str[i];
		if(!(str[i] <= '9' && str[i] >= '0')){
			cout << "No";
			return 0;
		}
	}
	char opt;
	cin >> opt;
	if(opt != '-'){
			cout << "No";
			return 0;
		}
	for(int i = 1; i <= m; i ++){
		cin >> str[i];
		if(!(str[i] <= '9' && str[i] >= '0')){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	S, T := readString2()
	A, B := readInt2()
	U := readString()
	if U == S {
		fmt.Println(A-1, B)
	} else if U == T {
		fmt.Println(A, B-1)
	} else {
		fmt.Println(A, B)
	}
}


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

void turn(int &vx, int &vy){
  int x, y;
  x = vx;
  y = vy;
  vx = -y;
  vy = x;
}

int main(){
  int x1, y1, x2, y2, x3, y3, x4, y4;
  cin >> x1 >> y1 >> x2 >> y2;
  int vx, vy;
  vx = x2 - x1;
  vy = y2 - y1;
  turn(vx, vy);
  x3 = x2 + vx;
  y3 = y2 + vy;
  turn(vx, vy);
  x4 = x3 + vx;
  y4 = y3 + vy;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << " " << endl;
  return 0;
}

Measured memory_bytes: 3628
c = [list(map(int,input().split())) for _ in range(3) ]
for a1 in range(101):
    b1 = c[0][0] - a1
    b2 = c[0][1] - a1
    b3 = c[0][2] - a1
    a2 = c[1][0] - b1
    a3 = c[2][0] - b1
    if a2+b1==c[1][0] and a2+b2==c[1][1] and a2+b3==c[1][2] and a3+b1==c[2][0] and a3+b2==c[2][1] and a3+b3==c[2][2]:
        print("Yes")
        break
else:
    print("No")
    

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

// {{{ Template for Competitive Programming
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n; i >= 0; --i)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1'010'000'000'000'000'017LL;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0 ,1 ,0,-1};
using vint = vector<int>;
using pint = pair<int, int>;
// }}}

bool check(vector<int> a) {
	bool flag = true;
	rep(i, a.size()-1) {
		if (a[i] > a[i+1]) flag = false;
	}
	return flag;
}

signed main() {
	int n;
	cin >> n;
	vector<int> p(n), q(n);
	for (auto &e : p) cin >> e;
	if (check(p)) {
		cout << "YES" << endl;
		return 0;
	}
	rep(i, n) {
		rep(j, n) {
			q = p;
			swap(q[i], q[j]);
			if (check(q)) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

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

	string s;
	if (r < 1200) {
		s = "ABC";
	} else if (r < 2800) {
		s = "ARC";
	} else {
		s = "AGC";
	}

	cout << s << endl;
	return 0;
}


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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  string s, t;
  bool flag = true;
  cin >> s >> t;
  rep (i, s.size()) {
    if (s[i] != t[i])
      flag = false;
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

using namespace std;


int main()
{
    int n , m , sum=0;
    cin>>n>>m;
    if(n>=2) sum+=(n*(n-1))/2;
    else sum+=0;

    if(m>=2) sum+=(m*(m-1))/2;
    else sum+=0;
    cout<<sum<<endl;
 
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=200005;
int f[MAXN],n,a[MAXN];LL K;
int nxt[MAXN],pos[MAXN];
int main()
{
//	freopen("b.in","r",stdin);
//	freopen("b.out","w",stdout);
	n=read();K=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=n;i>=1;i--)nxt[i]=pos[a[i]],pos[a[i]]=i;
	for(int i=n;i>=1;i--)if(!nxt[i])nxt[i]=pos[a[i]];
	memset(f,-1,sizeof(f));
	int ps,gg=0;
	LL total=0;
	for(int i=1,lst=0;i<=n;i=nxt[i]%n+1)
	{
		lst=total/n;gg=lst;
		if(f[i]!=-1){ps=i;break;}
		f[i]=lst;
		if(nxt[i]>i)total+=nxt[i]-i+1;
		else total+=nxt[i]+n-i+1;
	}
	int st=1;
	if(ps==1)f[ps]=gg;
	if(K>f[ps])
	{
		if((K%f[ps]))K%=f[ps],st=ps;
		else K=f[ps];
	}
	if(!K)return 0;
	total=0;
	for(int i=st,lst=0,nx;i<=n;i=nx)
	{
		lst=total/n;
		if(lst>K-1)break;
		if(nxt[i]>i)
		{
			nx=nxt[i]%n+1;
			total+=nxt[i]-i+1;
		}
		else
		{
			int nxlst=(total+nxt[i]+n-i)/n;
			if(nxlst<K)total+=nxt[i]+n-i+1,nx=nxt[i]%n+1;
			else
			{
				pr1(a[i]),nx=i%n+1;
				total++;
				if(total/n>=K)return 0;
			}
		}
	}
	return 0;
}




Measured memory_bytes: 4480
#include <stdio.h>
#include <math.h>

int main(void)
{
  long int i, n = 100, x;
  
  scanf("%ld", &x);

  for( i = 1; i < 100000; i++ ){
      n *= 1.01;
      if( n >= x ){
          printf("%ld\n", i);
          return 0;
      }
  }

  
}

Measured memory_bytes: 1728
#include <stdio.h>

int main(void) {
    char s[4];
    scanf("%s",&s);
    int ans1=10*(s[0]-48)+(s[1]-48);
     int ans2=10*(s[2]-48)+(s[3]-48);
     
     if(ans1<=12 && ans2<=12 && ans1>0 && ans2 >0)
        printf("AMBIGUOUS");
        
     else if((ans1>0 && ans1<=12) && ans2>=0)    
        printf("MMYY");
        
        
     else if(ans1>=0 && (ans2<=12 && ans2>0))
         printf("YYMM");
         
        
     else
        printf("NA");
     
             
	return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
bool R(){return true;}
template<typename T, typename ... Args>
bool R(T & x, Args & ... args){return cin >> x && R(args...);}
void init_io(){ios::sync_with_stdio(false);cin.tie(0);}

#define PB push_back
#define FOR(prom, a, b) for(int prom = (a); prom < (b); prom++)
#define FORDE(prom, a, b) for(int prom = (a); prom >= (b); prom--)
#define ALL(vec) (vec).begin(), (vec).end()
#define MM(co, cim) memset((co), (cim), sizeof((co)))
#define DEB(x) cerr << ">>> " << #x << " : " << x << endl;
#define INF   1000000007
#define INFLL 4000000000000000007LL

int n, k, p[1014];

void solve ()
{
  R(n, k);
  FOR(i, 0, n) R(p[i]);
  sort(p, p + n);
  int res = 0;
  FOR(i, 0, k) res += p[i];
  printf("%d\n", res);
}

int main ()
{
  init_io();
  int T = 1;
  //R(T);
  while (T--) solve();
  return 0;
}


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


def main():
    """Function."""
    n, m, x = map(int, input().split())
    a = list(map(int, input().split()))

    left, right = 0, 0
    for i in range(x):
        temp = x - (i + 1)
        if temp in a:
            left += 1

    for i in range(n - x):
        temp = x + i + 1
        if temp in a:
            right += 1

    print(min(left, right))


if __name__ == "__main__":
    main()


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

int main(){
  int N;
  cin >> N;
  vector<double> v(N);
  for(int i=0;i<N;i++){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  double average;
  for(int i=1;i<=N-1;i++){
    average=(v.at(v.size()-1)+v.at(v.size()-2))/2.0;
    v.pop_back();
    v.pop_back();
    v.push_back(average);
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
  }
  cout << v.front() << endl;
  return 0;
}


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

int main(void){
    int n;
    cin >> n;
    
    int f[n];
    
    for (int i = 0; i < n; i++) {
        cin >> f[i];
    }
    
    vector<int> s(0);
    for (int p = 0; p < n; p++) {
        if (f[p] % 2 == 0) {
            s.push_back(f[p]);
        } else {
            // no functions
        }
    }
    
    int ln = 0;
    for (int sp = 0; sp < s.size(); sp++) {
        if (s[sp] % 3 == 0) {
            ln++;
        } else if (s[sp] % 5 == 0) {
            ln++;
        } else {
            // no functions
        }
    }
    
    if (ln == s.size()) {
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(20000000)
n = int(input())
a = []
b = []
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)

a.sort()
b.sort()
if n % 2 == 0:
    ans = 0
    i = n//2-1
    j = n//2
    tmp = [[a[i], b[i]], [a[j], b[j]]]
    ans = (b[i] + b[j]) - (a[i] + a[j]) + 1
    print(ans)
else:
    mid_l = a[n//2]
    mid_r = b[n//2]
    print(mid_r - mid_l + 1)

Measured memory_bytes: 92660
N=int(input())
B=list(map(int, input().split()))

A = []

for i in range(N):
    if i == 0:
        A.append(B[i])
    elif i == N - 1:
        A.append(B[i-1])
    else:
        A.append(min([B[i-1], B[i]]))

print(sum(A))


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

typedef long long ll;
const int N = 2000006;

int a[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int a,b,c;
	cin>>a>>b>>c;
	cout<<max({a,b,c})-min({a,b,c});
	
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
// 型シノニム
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
// 定数
constexpr ll INF   = 1e16;
constexpr ll INM   = 114514;
constexpr ll MOD   = 1e9 + 7;
constexpr ld EPS   = 1e-12;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
// 便利関数
void IOS() { ios::sync_with_stdio(false), cin.tie(0); }
template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, ll t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll mod) {
	if (a > 0) return a % mod;
	if (a % mod == 0) return 0;
	ll x = -a / mod + 1;
	a += x * mod;
	return a % mod;
}
ll powm(ll a, ll b, ll m) {
	if (b == 0) {
		return 1;
	} else if (b % 2 == 0) {
		ll d = powm(a, b / 2, m);
		return (d * d) % m;
	} else {
		return (powm(a, b - 1, m) * a) % m;
	}
}
// 本体

int main() {
	IOS();
	ll n;
	cin >> n;
	vector<int> a(n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum ^= a[i];
	}
	for (int i = 0; i < n; i++) {
		if (i) cout << " ";
		ll t = sum ^ a[i];
		cout << t;
	}
	cout << endl;
}

Measured memory_bytes: 3988
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <algorithm>
#include <functional>
using namespace std;


int main(){
	

	int i,j;
	int N,K;
	long long diff = 9223372036854775807;
	long long temp;
	
	cin >> N >> K;
	
	vector<long long>H(N);

	for (i = 0; i < N; i++){
		cin >> H.at(i);
	}

	/* 数値を降順にソート */
	sort(H.begin(), H.end(), greater<long long>());

	for (i = 0; i < N-K+1; i++){
		temp = H.at(i) - H.at(i + K - 1);

		if (temp < diff){
			diff = temp;
		}
	}

	cout << diff << endl;

	

	return 0;
}

Measured memory_bytes: 1024
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 10 ** 6
for i in range(N):
	if i > 0:
		x = K - A[i] + A[i - 1]
	else:
		x = A[i - 1] - A[i]
	ans = min(ans, x)
print(ans)



Measured memory_bytes: 32120
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main(){
    int w, n;
    int d[31];
    while(cin >> w >> n){
        for(int i=1;i<=w;i++) d[i] = i;
        for(int i=0;i<n;i++){
            string s; cin >> s;
            for(int j=0;j<s.size();j++)
                if(s[j]==',') s[j] = ' ';
            istringstream iss(s);
            int a, b; iss >> a >> b;
            swap(d[a], d[b]);
        }
        for(int i=1;i<=w;i++) cout << d[i] << endl;
    }
}

Measured memory_bytes: 0
/////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////		
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define FR(i,a) for(auto i:a)
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
void solve()
{
	IN(n);
	vl v;
	FOR(i, 0, n)
	{
		IN(in);
		v.push_back(in);
	}
	ll sum = 0;
	FOR(i, 1, n)
	{
		if (v[i] < v[i - 1])
		{
			sum += v[i - 1] - v[i];
			v[i] = v[i - 1];
		}
	}
	cout << sum << endl;
}
int main()
{
	fastio
		//freopen("input.txt", "rt", stdin);
		//freopen("output.txt", "wt", stdout);
		ll test = 1;
	//cin >> test;
	while (test--)
	{
		solve();
	}
}

Measured memory_bytes: 5308
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>

using namespace std;
const long long int MOD=1e9+7;

vector<int> prime_list;

void gene_primes(int n){
  prime_list.push_back(2);
  for(int i=3;i<n;i+=2){
    bool is_prime=true;
    for(int j=0;prime_list[j]*prime_list[j]<=i;j++){
      if(i%prime_list[j]==0){
        is_prime=false;
        break;
      }
    }
    if(is_prime)prime_list.push_back(i);
  }
  for(int i=n;;i++){
    bool is_prime=true;
    for(int j=0;prime_list[j]*prime_list[j]<=i;j++){
      if(i%prime_list[j]==0){
        is_prime=false;
        break;
      }
    }
    if(is_prime){prime_list.push_back(i);break;}
  }
}

int main(){
  int n;
  cin >> n;
  gene_primes(n);
  cout << prime_list[prime_list.size()-1] << endl;
}


Measured memory_bytes: 384
import math

t = input()
moji_list = {1:"a",2:"b",3:"c",4:"d",5:"e",6:"f",7:"g",8:"h",9:"i",10:"j",11:"k",12:"l",13:"m",14:"n",15:"o",16:"p",17:"q",18:"r",19:"s",20:"t",21:"u",22:"v",23:"w",24:"x",25:"y",26:"z"}
print_list =[]

def hantei(t):
    global print_list
    try:
        int(t)
    except ValueError:
        return
    else:
        n = int(t)
    
    if 1 <= n and n <= 1000000000000001:
        while(n >= 1):
            s = n % 26
            if s == 0:
                s = 26
            print_list.insert(0, moji_list[s])
            n = math.floor(n / 26)
            if s == 26:
                n -= 1
    else:
        return

hantei(t)
pu = ''.join(print_list)
print(pu)

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

using namespace std;

#define scnaf scanf
#define sacnf scanf
#define sancf scanf

#define ln '\n'
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define MP(a,b) make_pair((a),(b))
#define PB(a) push_back((a))
#define P(p) cout << (p) << endl;
#define S(s) cin >> (s);
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

#define reps(i,a,b) for(int (i)=(a); (i)<(b); ++(i))
#define rep(i,n) reps(i,0,(n))
#define rreps(i,a,b) for(int (i)=(a); (i)>=(b); --(i))
#define rrep(i,n) reprt(i,n,0)

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;
const double EPS = 1e-9;
const double PI  = acos(-1.0);

ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

void Yes(bool f) {if(f){P("Yes");}else{P("No")}}
void yES(bool f) {if(f){P("yES");}else{P("nO")}}
void Yay(bool f) {if(f){P("Yay!");}else{P(":(")}}

/*********TEMPLATE**********/

ll A,B,C,K;

void init() {

  cin>>A>>B>>C>>K;

}

signed main() {

  init();

  if (K%2==0) {
    P(A-B);
  } else {
    P(B-A);
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

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

  int ans = 1e9;
  rep(i, 26){
    char c = 'a' + i;
    int tmp = 0;//文字 c を選んだ場合の必要な回数
    int cnt = 0;
    rep(j, n){
      if(s[j] == c){
        //printf("j:%d cnt:%d c:%c\n",j, cnt, c );
        chmax(tmp,cnt);
        cnt = 0;
      }
      else cnt++;
    }
    chmax(tmp, cnt);
    chmin(ans, tmp);
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        sc.close();

        String s = Integer.toBinaryString(l);
        int num1 = 0;
        for(int i=0; i<s.length(); i++){
            if(s.charAt(i) == '1') num1++;
        }
        System.out.println((s.length()) + " " + ((s.length()-1)*2+num1-1));
        for(int i=0; i<s.length()-1; i++){
            System.out.println((i+1) + " " + (i+2) + " 0");
            System.out.println((i+1) + " " + (i+2) + " " + (int)(Math.pow(2, i)));
        }
        int tmp = (int)(Math.pow(2, s.length()-1));
        for(int i=1; i<s.length(); i++){
            if(s.charAt(i) == '1'){
                System.out.println((s.length()-i) + " " + (s.length()) + " " + tmp);
                tmp += (int)(Math.pow(2, s.length()-i-1));
            }
        }
    }
}

Measured memory_bytes: 25044
n,d=map(int,input().split())
import math

X=[]

for i in range(n):   
    inp = [int(t) for t in input().split()]
    X.append(inp)

#print(X)

dis=0
n=0
ans=0

for Y in X[:-1]:
    n+=1
    for Z in X[n:]:
        for i in range(d):
            dis+=(Y[i]-Z[i])**2
        if round(math.sqrt(dis))**2 == dis:
            ans +=1
        
        #print(dis,ans)
        dis=0
        
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAX = 510000;
#define repi(i, n, init) for (ll i = init; i < (n); i++)


//---------- べき乗 ----------
int64_t power(int64_t a, int64_t n){
    if(n == 0) return 1;

    int64_t res = 1;
    while(n > 0){
        if(n % 2 == 1) res = res * a % MOD;
        a = a * a % MOD;
        n /= 2;
    }

    return res;
}

//---------- 逆元 ----------
int64_t inv(int64_t a){
    return power(a, MOD-2);
}


//--------- 組み合わせ ---------
int64_t comb(int64_t n, int64_t r){
  int64_t bunbo = 1, bunshi = 1;

  for(int i=0; i<r; i++){
    bunbo = bunbo * (r-i) % MOD;
    bunshi = bunshi * (n-i) % MOD;
  }

  return bunshi * inv(bunbo) % MOD;
}


int main(){ 
  int64_t N, A, B;
  cin >> N >> A >> B;

  int64_t ans = power(2, N) - comb(N, A) - comb(N, B) - 1;
  while(ans < 0) ans += MOD;

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


int main(){
	
	int N;
	cin>>N;
	
	vector<long long> A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	
	sort(A.begin(),A.end());
	
	if(N%2==0){
		long long ans = 0;
		for(int i=0;i<(N/2)-1;i++){
			ans -= A[i]*2;
		}
		ans -= A[N/2-1];
		ans += A[N/2];
		for(int i=N/2+1;i<N;i++){
			ans += A[i]*2;
		}
		cout<<ans<<endl;
	}
	else{
		long long a1 = 0,a2 = 0;
		for(int i=0;i<N/2;i++){
			a1 -= A[i]*2;
		}
		a1 += A[N/2] +A[N/2+1];
		for(int i=N/2+2;i<N;i++){
			a1 += A[i]*2;
		}
		
		for(int i=0;i<N/2-1;i++){
			a2 -= A[i]*2;
		}
		a2 -= A[N/2-1] + A[N/2];
		for(int i=N/2+1;i<N;i++){
			a2 += A[i]*2;
		}
		
		cout<<max(a1,a2)<<endl;
	}
	
	return 0;
}

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

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

  vector<int> R(N);

  for (int i = 0; i < N; i++) cin >> R.at(i);

  int minv = R.at(0);
  int maxv = R.at(1) - minv;

  for (int i = 1; i < N; i++) {
    if (maxv < R.at(i) - minv) maxv = R.at(i) - minv;
    if (minv > R.at(i)) minv = R.at(i);
  }

  cout << maxv << endl;
}



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

int N,k,a[100],m,n,tmp,A;

scanf("%d",&N);

for(k=0;k<N;k++)
scanf("%d",&a[k]);

for(n=0;n<N;n++){

for(m=n-1;m>=0;m--){

if(a[m]>a[m+1]){
tmp=a[m];
a[m]=a[m+1];
a[m+1]=tmp;
}else break;

}

for(k=0;k<N;k++){
printf("%d",a[k]);
if(k!=N-1)
printf(" ");
}
printf("\n");
}

}


Measured memory_bytes: 1992
#include <bits/stdc++.h>
using namespace std;
#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(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int H,W;
	int h,w;
	cin>>H>>W>>h>>w;
	int ans = (H-h)*(W-w);
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, a[100000], b[100000], ta = 0;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = n - 1; i >= 0; i--) {
		if ((a[i] + ta) % b[i] != 0) {
			ta += b[i] - (a[i] + ta) % b[i];
		}
	}
	cout << ta << endl;
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define Mod 1000000007
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
#define INF 999999999999999999
#define NN (ll)(1e6+5)
int mod(string s,int a) 
{ 
    int ans=0; 
    for (int i=0;i<s.length();i++) 
         ans=(ans*10+(int)s[i]-'0')%a; 
    return ans; 
}
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {    
       ll a,b,n,i,mx=-1;
       cin>>a>>b>>n;
       if(n>=b)
        cout<<((a*(b-1))/b)-(a*((b-1)/b));
       else 
        cout<<((a*(n))/b)-(a*((n)/b));
   }
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ld long double
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
const int MAX = 510000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//a^n%mod
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int main(){
  COMinit();
  int n,k;
  cin >> n >> k;
  ll a[n];
  rep(i,n)cin >> a[i];
  sort(a,a+n);
  ll ans=0;
  rep(i,n){
    if(i+1<k)continue;
    else ans=(ans+a[i]*COM(i,k-1))%MOD;
  }
  rep(i,n){
    if(n-i<k)continue;
    else ans=(ans+MOD-(a[i]*COM(n-i-1,k-1))%MOD)%MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 12928
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

alias P = Tuple!(long, "i", long, "p");

void main()
{
    auto N = readln.chomp.to!long;
    auto ii = new long[](N+1);
    foreach (i, p; readln.split.to!(long[])) ii[p] = i.to!long+1;
    auto T = redBlackTree!true(0, 0, ii[N], N+1, N+1);
    long res;
    foreach_reverse (p; 1..N) {
        auto c = ii[p];
        T.insert(c);
        auto l = T.lowerBound(c);
        auto b = l.back;
        l.popBack();
        auto a = l.back;
        auto r = T.upperBound(c);
        auto d = r.front;
        r.popFront();
        auto e = r.front;
        res += ((b-a)*(d-c) + (c-b)*(e-d)) * p;
    }
    writeln(res);
}

Measured memory_bytes: 11484
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int R = sc.nextInt();
        int[] r = new int[R];
        for (int i = 0; i < r.length; ++i) {
            r[i] = sc.nextInt() - 1;
        }
        int[] A = new int[M];
        int[] B = new int[M];
        int[] C = new int[M];
        for (int i = 0; i < M; ++i) {
            A[i] = sc.nextInt() - 1;
            B[i] = sc.nextInt() - 1;
            C[i] = sc.nextInt();
        }

        System.out.println(solve(N, A, B, C, r));

        sc.close();
    }

    static int solve(int N, int[] A, int[] B, int[] C, int[] r) {
        int[][] distances = new int[N][N];
        for (int i = 0; i < N; ++i) {
            Arrays.fill(distances[i], Integer.MAX_VALUE);
        }

        for (int i = 0; i < A.length; ++i) {
            distances[A[i]][B[i]] = C[i];
            distances[B[i]][A[i]] = C[i];
        }

        for (int k = 0; k < N; ++k) {
            for (int i = 0; i < N; ++i) {
                for (int j = 0; j < N; ++j) {
                    if (distances[i][k] != Integer.MAX_VALUE && distances[k][j] != Integer.MAX_VALUE) {
                        distances[i][j] = Math.min(distances[i][j], distances[i][k] + distances[k][j]);
                    }
                }
            }
        }

        return search(distances, r, 0);
    }

    static int search(int[][] distances, int[] r, int index) {
        if (index == r.length) {
            return IntStream.range(0, r.length - 1).map(i -> distances[r[i]][r[i + 1]]).sum();
        }

        int result = Integer.MAX_VALUE;
        for (int i = index; i < r.length; ++i) {
            swap(r, i, index);
            result = Math.min(result, search(distances, r, index + 1));
            swap(r, i, index);
        }

        return result;
    }

    static void swap(int[] a, int index1, int index2) {
        int temp = a[index1];
        a[index1] = a[index2];
        a[index2] = temp;
    }
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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 countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll A,B;
    cin >> A >> B;
    print(max((ll)0, A - 2*B));
    return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    bool flag = false;
    rep(i, N){
        int a;
        cin >> a;
        if(a % 2 == 1) flag = true;
    }

    if(flag) cout << "first" << endl;
    else cout << "second" << endl;

    return 0;
}

Measured memory_bytes: 256