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

#define FOR(i,b,e) for (int i = (b); i <= (e); i++)
#define FORD(i,b,e) for (int i = (b); i >= (e); i--)
#define SIZE(c) ((int) (c).size())

#define pb push_back
#define st first
#define nd second

using namespace std;


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

typedef vector <int> VI;
typedef vector <ll> VL;
typedef vector <bool> VB;
typedef vector <pii> VP;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;

ll solve(int n, VL &a, VL &b) {
    ll ops = 0;

    while (true) {
        bool chg = false;

        FOR(i,0,n-1) {
            if (b[i] < a[i]) {
                return -1;
            } else if (b[i] > a[i]) {
                ll bPrev = b[(i - 1 + n) % n];
                ll bNext = b[(i + 1) % n];

                ll adjSum = bPrev + bNext;
                ll over = b[i] - a[i];

                if (over >= adjSum) {
                    ops += over / adjSum;
                    over %= adjSum;

                    b[i] = a[i] + over;
                    chg = true;
                }
            }
        }

        if (a == b) {
            return ops;
        }

        if (!chg) {
            return -1;
        }
    }
}

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

    int n;
    cin >> n;

    VL a(n);
    FOR(i,0,n-1) cin >> a[i];

    VL b(n);
    FOR(i,0,n-1) cin >> b[i];

    cout << solve(n, a, b);

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double 
#define fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
int main() {
	ll n;
	cin>>n;
	ll sum=0;
	fo(i,1,n+1){
	    if((i%3!=0)&&(i%5!=0))sum+=i;
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long li;
const li MAX = 100001;
li n, dp[101][100001], a, b, w, inf = 99999999999;
vector<pair<li, li>> items;
int main() {
	cin >> n >> w;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		items.push_back({ a, b });
	}
	for (int i = 1; i < 100001; i++) {
		dp[0][i] = inf;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < 100001; j++) {
			if (j - items[i - 1].second < 0) { dp[i][j] = dp[i - 1][j]; continue; }
			dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - items[i - 1].second] + items[i - 1].first);
		}
	}
	li ans = 0;
	for (int i = 1; i <= n; i++) {
		for (li j = 1; j < 100001; j++) {
			if (dp[i][j] <= w) ans = max(ans, j);
		}
	}
	cout << ans;
	//system("pause");
	return 0;
}

Measured memory_bytes: 79104
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            //入力
            string n = Console.ReadLine();

            //sの位置に応じて場合分けする
            if(n[0] == '7' || n[1] == '7' || n[2] == '7' )
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }

Measured memory_bytes: 25884
#!/usr/bin/python3

import sys

def input():
    return sys.stdin.readline().rstrip('\n')

#S = input()
#A1,A2,A3 = list(map(int,input().split()))
A = int(input())
B = int(input())

C = [1,2,3]
C.remove(A)
C.remove(B)

print(C[0])


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

using namespace std;

int main() {
	int x, a, b;
	cin >> x >> a >> b;

	cout << (abs(a - x) < abs(b - x) ? "A" : "B") << endl;
	return 0;
}


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

typedef long long ll;
int N, A, B;
ll v[55];
// 組み合わせテーブル
ll C[55][55];  // C[n][k] => nCk

void comb_table(int N){
  for (int i=0;i<=N;++i) {
    for (int j=0;j<=i;++j) {
      if (j==0 or j==i) {
        C[i][j] = 1;
      } else {
        C[i][j] = (C[i-1][j-1]+C[i-1][j]);
      }
    }
  }
}

int main() {
  // 入力
  cin >> N >> A >> B;
  for (int i=0; i<N; i++) cin >> v[i];
  // A<=x<=Bの範囲においての価値の平均は、vを降順にソートした後に前からA個選んだ時が最大
  sort(v, v+N);
  reverse(v, v+N);
  ll sum = 0;
  double avg;
  for (int i=0; i<A; i++) sum += v[i];
  avg = (double)sum / A;
  // 1行目に平均の最大値を出力
  printf("%.6f\n", avg);
  // 平均が最大となるような品物の選び方の数を求める
  comb_table(N);  // 組み合わせテーブルを前処理で求めておく
  int anum_equal_cnt, apos_below_cnt;
  anum_equal_cnt = apos_below_cnt = 0;
  for (int i=0; i<N; i++) {
    if (v[i] == v[A-1]) {
      anum_equal_cnt++;
      if (i < A) {
        apos_below_cnt++;
      }
    }
  }
  ll cnt = 0;
  if (apos_below_cnt == A) {
    for (; apos_below_cnt<=B; apos_below_cnt++) {
      cnt += C[anum_equal_cnt][apos_below_cnt];
    }
  } else {
    cnt += C[anum_equal_cnt][apos_below_cnt];
  }
  // 2行目に平均が最大となるような品物の選び方の数を出力
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
# 諸々の入力
N=int(input())
A=list(map(int,input().split()))

flag=1 # flagはbool型みたいなもの
count=0 # 反転数

# バブルソート
while flag==1:
    flag=0
    for j in range(N-1,0,-1):
        if A[j-1]>A[j]:
            A[j-1],A[j]=A[j],A[j-1]
            flag=1
            count+=1

# 答えと反転数の出力
ans=list(map(str,A))
print(' '.join(ans))
print(count)



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

#define MAXLEN 1000000

struct sDLL {
    int key;
    int pre;
    int next;
};

int ghead, gtail, gemhead, gemtail, gcnt;
struct sDLL list[MAXLEN+1];

void dllOperation( char *command, int key )
{
	int i;
	int pre;

   	if( 0 == strcmp( "insert", command ) ) {
   		pre=ghead;
		if( gcnt <= (ghead+1) && gcnt < MAXLEN ) {
			ghead=gcnt++;
		} else {
			ghead=gemhead;
			gemhead=list[gemhead].next;
			 if( -1 == gemhead ) {
				gemtail=-1;
			}
		}
		
		if( -1 == pre ) {
   			gtail=0;		
		} else {
   			list[pre].pre=ghead;
   		}
   		list[ghead].key=key;
		list[ghead].pre=-1;
		list[ghead].next=pre;
   	} else if( 0 == strcmp( "delete", command ) ) {
    	i=ghead;
	   	while( -1 != i  ) {
	   		if( key == list[i].key ) {
	   			if( ghead == i ) {
	   				ghead = list[i].next;
                    list[ghead].pre=-1; 
	   			} else if( gtail == i ) {
	   				gtail=pre;
	   				list[gtail].next=-1;
	   			} else {
					list[pre].next = list[i].next;
	   				list[ list[i].next ].pre=list[i].pre;
	   			}
				if( -1 == gemtail ) {
					gemhead=i;
				} else {
					list[gemtail].next=i;
				}
				list[i].pre=gemtail;
				gemtail=i;	
				list[gemtail].next=-1;
	   			break;
	   		}
	   		pre=i;
	   		i=list[i].next;
	   	}
   	} else if( 0 == strcmp( "deleteFirst", command ) ) {

      	if( -1 == gemtail ) {
      		gemhead=ghead;
      	} else {
			list[gemtail].next=ghead;
		}
		list[ghead].pre=gemtail;
		gemtail=ghead;
		
		ghead=list[ghead].next;
 		if( -1 == ghead ) {
			gtail=-1;
		} else {
		   	list[ghead].pre=-1;
		}
 		
   		list[gemtail].next=-1;  		   		
   	} else {
   		if( -1 == gemtail ) {
			gemhead=gtail;
		} else {
			list[gemtail].next=gtail;
		}
   		pre=list[gtail].pre;
		list[gtail].pre=gemtail;
		gemtail=gtail;
		
		list[gemtail].next=-1;
		gtail=pre;
		if( -1 == pre ) {
			ghead=-1;
		} else {
			list[gtail].next=-1;	
		}	
   	}

	return;
}   	

int main( void ) 
{
    int i;
    int n;
    char command[12];
    int key;
     
    scanf( "%d", &n );
    gemhead=gemtail=ghead=gtail=-1;
    gcnt=0;
    for( i=0; i<n; i++ ) {
        scanf( "%s", command );
        if( 0 == strcmp( "deleteFirst", command ) ) {
        	key=0;        
        } else if( 0 == strcmp( "deleteLast", command ) ) {
        	key=0;
        } else {
        	scanf( "%d", &key );
        }
        dllOperation( command, key );
    }
    

    i=ghead;
    while( -1 != i ) {
      	printf( "%d", list[i].key );
       	if( -1 == (i=list[i].next) ) {
     		break;
     	} else {
     		printf( " " );
     	}
    }
	printf( "\n" );
	
	return 0;
}

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

int main() {
    int s;
    cin >> s;
    if(s%1000!=0) cout << (1000 - s%1000) << endl;
    else cout << s%1000 << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int A, X;
    cin >> X >> A;
    if (X < A) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}


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

using namespace std;
 
int main(void){

	long double xa,ya,xb,yb,xc,yc,xd,yd;

	while(cin>>xa>>ya>>xb>>yb>>xc>>yc>>xd>>yd){
		if((xb-xa)*(xd-xc)+(yb-ya)*(yd-yc)==0) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

    return 0;
}

Measured memory_bytes: 1216
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProconTemplate
{

    class Class2
    {
        public static void Main(string[] args)
        {
            //string[] asInput = Console.ReadLine().Split(' ');
            //int N = int.Parse(asInput[0]);
            //int K = int.Parse(asInput[1]);
            //int[] p = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            string s = Console.ReadLine();
            Console.WriteLine( s == "Sunny" ? "Cloudy" : s == "Cloudy" ? "Rainy" : "Sunny");
        }
    }
}


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

#define ll long long int
#define INFTY (1<<21)

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    ll K,A,B;
    cin>>K>>A>>B;
    ll ans;
    ll tmp = K-(A-1);
    if(B-A<=2 || tmp<0) ans = K+1;
    else ans = A + tmp/2*(B-A) + tmp%2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int S;
	int h;
	int m;
	int s;
	scanf("%d", &S);
	h = S / (60 * 60);
	m = S / 60 - h * 60;
	s = S - m * 60-h*3600;
	printf("%d:%d:%d\n", h, m,s);
	return 0;
}

Measured memory_bytes: 592
#include<iostream>
using namespace std;
int a,b,c,i,x[10001],ans=0;
int main(){
	cin>>a>>b>>c;
	for(i=1;i<=a;i++){
		cin>>x[i];
	if(x[i]<b||x[i]>=c){
		ans++;
	}
	}
	cout<<ans<<endl;	
	return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, M;
int L, R;
int A[100100];

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

    std::cin >> N >> M;

    for(int i=0;i<M;++i){
        std::cin >> L >> R;

        A[L] += 1;
        A[R + 1] -= 1;
    }

    int res = 0;

    for(int i=1;i<=N;++i){
        A[i] += A[i-1];

        if(A[i] == M){
            res += 1;
        }
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 640
str = gets.chomp.split(' ').map(&:to_i)
if str[0] == str[1] && str[0] != str[2]
  puts "Yes"
elsif str[0] == str[2] && str[0] != str[1]
  puts "Yes"
elsif str[1] == str[2] && str[1] != str[0]
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
import math

def count(a, b):
    a = len(str(a))
    b = len(str(b))

    return max(a, b)

N = int(input())
ans = 10**10

for a in range(1, math.ceil(math.sqrt(N))+1):
    if not N % a:
        b = N//a
        ans = min(ans, count(a, b))
print(ans)

Measured memory_bytes: 3060
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
using namespace std;


int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}
int main(){
    int N;
    cin >> N;
    vector<int> p(N);
   for(int i=0;i<N;i++){
       cin >> p[i];
   }
   sort(p.begin(),p.end(),greater<int>());
   p[0] /= 2;
cout << accumulate(p.begin(),p.end(),0) << endl;
}

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

int main(void) {

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    
    sort(a.begin(), a.end(), greater<int>());

    int ans = 0;
    int t = 1;
    rep(i,n){
        ans += t*a[i];
        t *= -1;
    }

    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 256
#154_D
n, k = map(int, input().split())
p = list(map(int, input().split()))

tmp = sum(p[0:k])
ans = tmp
for i in range(1,n-k+1):
    tmp += p[i+k-1] - p[i-1]
    ans = max(ans, tmp)

print((ans + k) / 2)

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

int main() {
  
  int N=0;
  
  cin >> N;
  
  if(N<1000) {
    
    cout << "ABC" << endl;
    
  } else if(1000<=N) {
    
    cout << "ABD" << endl;
    
  }
  
}

Measured memory_bytes: 256
def go():
    n,k=map(int,input().split())
    h=list(map(int,input().split()))
    dp=[0]*n
    for i in range(1,n):
        dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i))
    print(dp[n-1])
go()

Measured memory_bytes: 13980
using System;

namespace ProgramingTest
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string lines = System.Console.ReadLine();
            char c = lines[0];

            if (Char.IsUpper(c))
            {
                Console.WriteLine("A");
            }
            else
            {
                Console.WriteLine("a");
            }



        }
    }
}


Measured memory_bytes: 25680
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << vec[K-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int Q; long long H, W;
int main() {
	cin >> Q;
	while(Q--) {
		cin >> H >> W;
		long long R = __gcd(H, W);
		H /= R, W /= R;
		if((H + W) % 2 == 1) cout << "1 1" << endl;
		else cout << H * W / 2 + 1 << " " << H * W / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

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

    if(K==1) cout << 0 << endl;
    else cout << N-K << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP (i, n) cin >> a[i];
    sort(a.begin(), a.end());
    int tmp = -1, ans = -1;
    REP (i, n - 1) {
        if (min(a[i], a[n - 1] - a[i]) > tmp) {
            tmp = min(a[i], a[n - 1] - a[i]);
            ans = a[i];
        }
    }
    cout << a[n - 1] << " " << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a%2==1 && b%2==1){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


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

// 辺を表す構造体
struct edge{
    int to, cost;
};

// キューに入れる頂点を表す構造体
struct node{
    int id, cost;
};

constexpr int INF = (1 << 30) - 1;

// s:=始点 cost:=始点からの最短経路長がここに書き込まれる g:=隣接リストでグラフを渡す
void breadth_first_search(int s, vector<int>& cost, const vector< vector<edge> >& g){
    cost.resize(g.size());
    fill(cost.begin(), cost.end(), INF);
    cost[s] = 0;
    queue<node> que;
    que.push({s, 0});

    while(!que.empty()){
        node now = que.front();
        que.pop();
        if(cost[now.id] < now.cost){
            continue;
        }
        for(auto& e : g[now.id]){
            if(cost[e.to] > now.cost + e.cost){
                cost[e.to] = now.cost + e.cost;
                que.push({e.to, now.cost + e.cost});
            }
        }
    }

    return;
}

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

    vector< vector<edge> > g(n);
    for(int i = 0 ; i < n ; ++i){
        int u, k;
        cin >> u >> k;
        --u;
        for(int j = 0 ; j < k ; ++j){
            int v;
            cin >> v;
            g[u].push_back({--v, 1});
        }
    }

    vector<int> cost;
    breadth_first_search(0, cost, g);

    for(int i = 0 ; i < n ; ++i){
        cout << i + 1 << " ";
        if(cost[i] < INF){
            cout << cost[i] << endl;
        }else{
            cout << -1 << endl;
        }
    }

    return 0;
}


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




Measured memory_bytes: 14224
#define rep(i, m, n) for(int i = m; i < n; i++)
#define repM(i, m, n) for(int i = n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll; using namespace std;
//typedef pair<int,int> pii;
// d = distance(lower_bound(all(x)), upper_bound(all(x)));
int INF = 1e9;
int M = 1e9+7;
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
//#include <algorithm>

int main(){
  int N; cin >> N; int a[N], b[N], c[N-1], an=0, ls=-1;
  for(int i=0; i<N; i++) {cin >> a[i]; a[i]--;}
  for(int i=0; i<N; i++) cin >> b[i];
  for(int i=0; i<N-1; i++) cin >> c[i];
  for(auto x:a) {
    if (ls==-1) {an += b[x]; ls=x;}
    else {
      if (ls+1==x) an += b[x] + c[ls];
      else an += b[x];
      ls = x;
    }
  }
  cout << an << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

signed main() {
  string S, T;
  cin >> S >> T;
  int ans = 0;
  for( int i = 0; i < S.size(); i++ ){
    if( S[i] != T[i] ) ans++;
  }
  cout << ans << endl;

}

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

long long k, kd, kr;

int main() {
	std::cin >> k;
	puts("50");
	kd = k / 50ll;
	kr = k % 50ll;
	for(int i = 0; i < kr; ++i)
		printf("%lld ", 49ll + kd + 51ll - kr);
	for(int i = kr; i < 50; ++i)
		printf("%lld ", 49ll + kd - kr);
	putchar('\n');
	return 0;
}


Measured memory_bytes: 256
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n,m;
    fi>>n>>m;
    static int a[1 << 20];
    static int b[1 << 20];
    for (int i = 1;i <= n;++i)
        fi>>a[i];
    for (int i = 1;i <= m;++i)
        fi>>b[i];
    vector < vector < int > > s;
    for (int i = 1;i <= n;++i)
        s.push_back({a[i],1,0});
    for (int i = 1;i <= m;++i)
        s.push_back({b[i],0,1});
    sort(s.begin(),s.end());
    ++n;++m;
    int x = n,y = m;
    ll ans = 0;
    for (auto it : s)
        {
            if (it[1])
                ans += 1ll * it[0] * y;
            else
                ans += 1ll * it[0] * x;
            x -= it[1];
            y -= it[2];
        }
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}

Measured memory_bytes: 11948
nabcd = input().split()
n = int(nabcd[0])
a = int(nabcd[1])
b = int(nabcd[2])
c = int(nabcd[3])
d = int(nabcd[4])

course = input()

if '##' in course[a-1:c-1] or '##' in course[b-1:d-1]:
  print('No')

else:
  if c > d:
    if not '...' in course[b-2:d+1]:
      print('No')
    elif (not '...' in course[b-2:d-1]) and course[d-2]=='#':
      print('No')
    else:
      print('Yes')
  else:
    print('Yes')


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int n,p;cin>>n>>p;
    vector<int>X(n),Y(n);
    vector<P>V(n);
    rep(i,n){
        cin>>X[i]>>Y[i];
        V[i]=make_pair(X[i],Y[i]);
    }
    sort(all(X));
    sort(all(Y));
    int ans=(X[n-1]-X[0])*(Y[n-1]-Y[0]);
    rep(i,n)for(int j=i+1;j<n;j++){
        rep(k,n)for(int l=k+1;l<n;l++){
            int count=0;
            rep(v,n){
                int x=V[v].F,y=V[v].S;
                if(X[i]<=x&& x<=X[j] && Y[k]<=y && y<=Y[l])count++;
            }
            if(count>=p)ans=min(ans,(X[j]-X[i])*(Y[l]-Y[k]));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			final long P = sc.nextLong();
			
			ArrayList<HashMap<Integer, Long>> adj = new ArrayList<HashMap<Integer, Long>>();
			for(int i = 0; i < N; i++) { adj.add(new HashMap<Integer, Long>()); }
			
			for(int i = 0; i < M; i++) {
				final int a = sc.nextInt() - 1;
				final int b = sc.nextInt() - 1;
				final long c = sc.nextLong();
				
				if(!adj.get(a).containsKey(b)) { adj.get(a).put(b, 0l); }
				adj.get(a).put(b, Math.max(adj.get(a).get(b), c));
			}
			
			long[] costs = new long[N];
			boolean[] visited = new boolean[N];
			costs[0] = 0;
			visited[0] = true;
			
			boolean infinite = false;
			
			for(int times = 0; times < 2 * N; times++) {
				for(int node = 0; node < N; node++) {
					if(!visited[node]) { continue; }
					
					for(final Entry<Integer, Long> edge : adj.get(node).entrySet()) {
						final int next_index = edge.getKey();
						final long next_cost = costs[node] + edge.getValue() - P;
						
						if(!visited[next_index]) {
							visited[next_index] = true;
							costs[next_index] = next_cost;
						}else if(costs[next_index] < next_cost){
							if(next_index == N - 1 && times >= N) { infinite = true; break; }
							costs[next_index] = next_cost;
						}
					}
				}
			}
			
			System.out.println(infinite ? -1 : Math.max(0, costs[N - 1]));
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 150108
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <ctime>
using namespace std;
#pragma warning(disable: 4996)
string S;
int main() {
	cin >> S;
	if (S[0] == S[1] && S[1] == S[2])cout << "Yes" << endl;
	else if (S[1] == S[2] && S[2] == S[3])cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a,b,c;
  cin >> a >> b >> c;
  
  if(a.at(a.size()-1)==b.at(0)&&b.at(b.size()-1)==c.at(0)){
    cout <<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }

}


Measured memory_bytes: 256
# 貰うDP
N,K=map(int,input().split())
h=list(map(int,input().split()))
INF=10**9
dp=[INF]*(N)
dp[0]=0

for n in range(1,N):
    dp[n]=min([dp[k] + abs(h[n] - h[k]) for k in range(max(0,n-K), n)])
print(dp[N-1])

Measured memory_bytes: 52448
#include <iostream>
#include <string>
#include <stack>
#include <map>
#include <cstdlib>
#include <cctype>

using namespace std;

void str2arr(string s, string A[]) {
    int n = 0;
    string tmp = "";

    for (int i = 0; s[i] != '=' ; i++) {
        if ('0' <= s[i] && s[i] <= '9') {
            tmp += s[i];
        }
        else {
            if (tmp != "") { 
                A[n++] = tmp;
                tmp = "";
            }
            A[n++] = s[i];
        }
    }
    if (tmp != "") { A[n++] = tmp; }
    A[n++] = "=";
}

void Generate_RPN(string A[], string B[]) {
    map<string, int> table;
    stack<string> St;
    table["*"] = 1;
    table["/"] = 1;
    table["+"] = 0;
    table["-"] = 0;
    table["("] = -1;
    table[")"] = -1;

    int i, j = 0;
    for (i = 0; A[i] != "="; i++) {
        if ('0' <= A[i][0] && A[i][0] <= '9') {
            B[j++] = A[i];
        }

        else if (A[i] == "(") {
            St.push(A[i]);
        }
        else if (A[i] == ")") {
            while (St.top() != "(") {
                B[j++] = St.top(); St.pop();
            }
            St.pop();
        }
        else {
            while ((!St.empty()) && (table[St.top()] >= table[A[i]])) {
                B[j++] = St.top(); St.pop();
            }
            St.push(A[i]);
        }
    }
    while (!St.empty()) {
        B[j++] = St.top(); St.pop();
    }
    B[j] = "=";
}

int Calculate_RPN(string s[]) {
    stack<double> St;
    double a, b;

    for (int i = 0; s[i] != "="; i++) {
        if (s[i] == "+") {
            b = int(St.top()); St.pop();
            a = int(St.top()); St.pop();
            St.push(a+b);
        }
        else if (s[i] == "-") {
            b = int(St.top()); St.pop();
            a = int(St.top()); St.pop();
            St.push(a-b);
        }
        else if (s[i] == "*") {
            b = int(St.top()); St.pop();
            a = int(St.top()); St.pop();
            St.push(a*b);
        }
        else if (s[i] == "/") {
            b = int(St.top()); St.pop();
            a = St.top(); St.pop();
            St.push(a/b);
        }
        else {
            St.push(atoi(s[i].c_str()));
        }
    }
    return int(St.top());
}

int main() {
    int n;
    string A[100], B[100];
    string in;

    cin >> n;

    while (n--) {
        cin >> in;
        str2arr(in, A);
        Generate_RPN(A, B);
        cout << Calculate_RPN(B) << endl;
    }

    return 0;
}

Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
// #define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

ll d;
vector<ll> c(26);
vector<vector<ll>> s(365, vector<ll>(26));
vector<ll> t(365);
vector<ll> last(26, -1);

ll score(ll type, ll day, ll sc) {
  ll s_now = sc + s[day][type];
  REP(i, 26) { s_now -= c[i] * (day - last[i]); }
  return s_now;
}

ll sim(vector<ll> &yotei) {
  REP(i, 26) { last[i] = -1; }
  ll ss = 0;
  REP(i, d) {
    last[yotei[i]] = i;
    ss = score(yotei[i], i, ss);
  }
  return ss;
}

int main() {
  cin >> d;
  REP(i, 26) { cin >> c[i]; }
  REP(i, d) {
    REP(j, 26) { cin >> s[i][j]; }
  }

  REP(i, d) {
    ll tmp = 0, m = 0;
    REP(j, 26) {
      if (m < s[i][j]) {
        m = s[i][j];
        tmp = j;
      }
    }
    t[i] = tmp;
  }

  vector<pair<ll, ll>> ch(10);
  vector<ll> tmp(10);
  REP(j, 100000) {
    ll st = sim(t);
    DEBUG(st);

    bool f;
    REP(i, 10) {
      ll r_365, r_26;
      do {
        r_365 = rand() % 365;
        r_26 = rand() % 26;
        f = false;
        for (ll j = 0; j < i; j++) {
          if (r_365 == ch[j].first || r_26 == ch[j].second) f = true;
        }
      } while (f);

      ch[i].first = r_365;
      ch[i].second = r_26;
    }
    REP(i, 10) {
      // cout << "[" << ch[i].first << "]:" << t[ch[i].first] << "->"
          //  << ch[i].second << "\n";
      tmp[i] = t[ch[i].first];
      t[ch[i].first] = ch[i].second;
    }

    if (sim(t) < st) {
      REP(i, 10) {
        // cout << "back[" << ch[i].first << "]->" << tmp[i] << "\n";
        t[ch[i].first] = tmp[i];
      }
    }
  }

  // DEBUGS(t);
  // cout << sim(t) << "\n";
  //
  REP(i, d) {
     cout << t[i] + 1 << "\n";
    if (t[i] + 1 < 1 || 26 < t[i] + 1) {
      cout << "ERROR"
           << "\n";
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	ll ans = 1;
	ll posAn = 0;
	ll negAn = 0;
	int mod = 1000000007;
	vector<int>::iterator itrPos, itrNeg;
	int n;
	cin >> n;
	int k;
	cin >> k;
	// 整数入力
	// 正の数(ゼロを含む)・負の数に分ける
	vector<int> aPos = {};
	int aPosNum = 0;
	vector<int> aNeg = {};
	int aNegNum = 0;
	int aVal;
	// 数字入力
	rep(i, n) {
		cin >> aVal;
		if (aVal >= 0) {
			aPosNum++;
			aPos.push_back(aVal);
		}
		else if (aVal < 0) {
			aNegNum++;
			aNeg.push_back(aVal);
		}
	}
	// kが奇数
	if (k % 2 != 0) {
		// 正の数が含まれない
		if (aPosNum == 0) {
			sort(aNeg.begin(), aNeg.end(), greater<>());
			rep(i, k) {
				ans = ans * aNeg[i];
				ans = ans % mod;
			}
		}
		// 正の数が含まれる
		else {
			sort(aPos.begin(), aPos.end(), greater<>());
			// 一番大きい正の数をかける
			ans = ans * aPos[0];
			ans = ans % mod;
			// 一番最初の数を削除
			aPos.erase(aPos.begin() + 0);
			// kが偶数になる
			k--;
			aPosNum--;
		}
	}
	// kが偶数の時
	if (k % 2 == 0) {
		sort(aPos.begin(), aPos.end(), greater<>());
		sort(aNeg.begin(), aNeg.end(), greater<>());
		while (k > 0) {
			// すべてを掛け合わせるとき
			if (aPosNum + aNegNum == k) {
				rep(i, aPosNum) {
					ans = ans * aPos[i];
					ans = ans % mod;
				}
				rep(i, aNegNum) {
					ans = ans * aNeg[i];
					ans = ans % mod;
				}
				k = 0;
			}
			// 全てかけ合わせないとき
			else {
				// 正の数が2つ以上ある
				if (aPosNum >= 2) {
					// 負の数が2つ以上ある
					if (aNegNum >= 2) {
						itrPos = aPos.begin();
						itrNeg = aNeg.end();
						posAn = (ll)(*itrPos) * (ll)(*(itrPos + 1));
						// posAn = posAn % mod;
						negAn = (ll)(aNeg[aNeg.size() - 1]) * (ll)(aNeg[aNeg.size() - 2]);
						// negAn = negAn % mod;
						// 正の数2つの積 >= 負の数2つの積
						if (posAn >= negAn) {
							posAn = posAn % mod;
							ans = ans * posAn;
							ans = ans % mod;
							k = k - 2;
							// 正の数の大きい数2つを消す
							aPos.erase(aPos.begin() + 0, aPos.begin() + 2);
							aPosNum = aPosNum - 2;
						}
						// 正の数2つの積 < 負の数2つの積
						else {
							negAn = negAn % mod;
							ans = ans * negAn ;
							ans = ans % mod;
							k = k - 2;
							// 負の数の小さい数2つを消す
							aNeg.erase(aNeg.end()-2, aNeg.end());
							aNegNum = aNegNum - 2;
						}
					}
					// 負の数が2つ以上ない
					else
					{
						itrPos = aPos.begin();
						posAn = (ll)(*itrPos) * (ll)(*(itrPos + 1));
						posAn = posAn % mod;
						ans = ans * posAn;
						ans = ans % mod;
						k = k - 2;
						// 正の数の大きい数2つを消す
						aPos.erase(aPos.begin(), aPos.begin() + 2);
						aPosNum = aPosNum - 2;
					}
				}
				// 正の数が2つ以上ない
				else {
					itrNeg = aNeg.end();
					negAn = (ll)(aNeg[aNeg.size() - 1]) * (ll)(aNeg[aNeg.size() - 2]);
					negAn = negAn% mod;
					ans = ans * negAn ;
					ans = ans % mod;
					k = k - 2;
					// 負の数の小さい数2つを消す
					aNeg.erase(aNeg.end()-2, aNeg.end());
					aNegNum = aNegNum - 2;
				}
			}
		}
	}
	// ansが負の時
	if (ans < 0) {
		ans = ans + mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4304
#include <cstdio>
#include <algorithm>
using namespace std;
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
struct Event{
	int val, pos;
	inline bool operator <(const Event &x) const {
		return val < x.val;
	}
}a[200007];
int fastin(){
	register int i; register char ch;
	while (ch = getchar(), ch < '0' || ch > '9');
	i = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9') i = i * 10 + ch - '0';
	return i;
}
int main(){
	register int n, i, cnt, ans;
	n = fastin();
	for (i = 1; i <= n; ++i) a[i].val = fastin(), a[i].pos = i;
	sort(a + 1, a + n + 1);
	cnt = ans = 0;
	for (i = 1; i <= n; ++i) {
		if (a[i - 1].pos < a[i].pos) ++cnt;
		else cnt = 1;
		cmax(ans, cnt);
	}
	printf("%d", n - ans);
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a,b,c;
    cin>>a;
    cin>>b;
    cin>>c;
    if(a>b){swap(a,b);
        
    }
    if(b>c){swap(b,c);
        
        
    }
   
    if(a>b){swap(a,b);
        
        
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<long> a(3 * n);
	for (int i = 0; i < 3 * n; ++i) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	long ans = 0;
	for (int i = 1; i < 2 * n; i += 2) {
		ans += a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define int long long
map<char,map<int,int> > m;
map<char,int> l;
int dfs(string s,int p){
  int x=0,n=s.size();
  if(isdigit(s[p])){
    for(int i=p;i<n&&isdigit(s[i]);i++) x=x*10+s[i]-'0';
    return x;
  }
  if(isdigit(s[p+2])) for(int i=p+2;i<n&&isdigit(s[i]);i++) x=x*10+s[i]-'0';
  else x=dfs(s,p+2);
  return p?((x<0||x>=l[s[p]]||m[s[p]].find(x)==m[s[p]].end())?-1:m[s[p]][x]):x;
}
signed main(){
  string s;
  while(cin>>s,s!="."){
    m.clear();l.clear();
    vector<string> v;
    while(s!=".") v.push_back(s),cin>>s;
    int n=v.size(),i;
    for(i=0;i<n;i++){
      int p=v[i].find("=");
      if(p<0){
	if((l[v[i][0]]=dfs(v[i],0))<0) break;
      }else{
	int x=dfs(v[i],0),y=dfs(v[i],p+1);
	if(x<0||l[v[i][0]]<=x||y<0) break;
	m[v[i][0]][x]=y;
      }
    }
    cout<<(i==n?0:i+1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3332
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

int main(){
	while(1){
	int n,m,s1[105],s2[105],sum1=0,sum2=0;
		cin>>n>>m;
		if(n==0&&m==0) break;
		for(int i=0; i<n; i++){
			cin>>s1[i];
			sum1+=s1[i];
		}
		for(int i=0; i<m; i++){
			cin>>s2[i];
			sum2+=s2[i];
		}

		bool flag = false;
		int tt1,tt2, t1, t2, inf = 999999;
		for(int i=0; i<n; i++){
			for(int j=0; j<m; j++){
				t1 = sum1; t2 = sum2;
				t1 = t1 - s1[i] + s2[j];
				t2 = t2 + s1[i] - s2[j];
				if(t1 == t2){
					if(s1[i] + s2[j] < inf){
						inf = s1[i] + s2[j];
						tt1 = s1[i];
						tt2 = s2[j];
					}
					flag = true;
				}
			}
		}
		if(flag){
			cout<<tt1<<" "<<tt2<<endl;
		}else{
			cout<<-1<<endl;
		}
	}
	

	return 0;
}

Measured memory_bytes: 2984
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int v[] = { 3,5,7 };
int N;
map<ll, int>cnt;
void dfs(bool a = false, bool b = false, bool c = false, ll num = 0) {
	if (num > N)return;
	if (a && b && c) {
		if (!cnt.count(num))cnt[num]++;
		else return;
	}
	rep(i, 0, 3) {
		dfs((i == 0 ? true : a), (i == 1 ? true : b), (i == 2 ? true : c), num * 10 + v[i]);
	}
	return;
}

int main() {
	init();

	cin >> N;
	dfs();
	cout << cnt.size() << "\n";

	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 3333;
LL mp[MAX][MAX];
LL dp[MAX][MAX][4];
int R, C, K;

void solve() {
    cin >> R >> C >> K;
    LL sum = 0;
    REP(i, K) {
        int r, c, v;
        cin >> r >> c >> v;
        mp[r - 1][c - 1] = v;
        sum += v;
    }
    DEBUG(sum)

    REP(i, MAX) REP(j, MAX) REP(k, 4) dp[i][j][k] = -LLINF;
    dp[0][0][0] = 0;

    REP(i, R) REP(j, C) REP(k, 4) {
        if (dp[i][j][k] == -LLINF) continue;

        if (i < R) chmax(dp[i + 1][j][0], dp[i][j][k]);
        if (j < C) chmax(dp[i][j + 1][k], dp[i][j][k]);

        if (mp[i][j] > 0 && k < 3) {
            if (i < R) chmax(dp[i + 1][j][0], dp[i][j][k] + mp[i][j]);
            if (j < C) chmax(dp[i][j + 1][k + 1], dp[i][j][k] + mp[i][j]);
        }
    }

    LL ans = 0;
    REP(i, 4) {
        chmax(ans, dp[R][C - 1][i]);
        chmax(ans, dp[R - 1][C][i]);
    }

    cout << ans << endl;
}

int main(void) {
#ifndef ONLINE_JUDGE
    const auto in_stream = freopen("../in.txt", "r", stdin);
    if (in_stream == nullptr) {
        cerr << "ERROR!" << endl;
        return 1;
    }
#endif

    solve();

#ifndef ONLINE_JUDGE
    fclose(in_stream);
#endif
}


Measured memory_bytes: 428616
#include <iostream>
#include <math.h>
using namespace std;
 
int main()
{
    long n,m;
    cin>>n>>m;
    long tot=0;
    long s;
    for(int i=0;i<m;i++) {
      cin>>s;
      tot+=s;
    }
    if(n-tot<0) cout<<-1<<endl;
    else cout<<n-tot<<endl;
 
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <limits.h>
void mergeSort(int *, int, int);
void merge(int *, int, int, int);

int cnt = 0;
int L[2500010], R[2500010];

int main()
{
    int left = 0, right = 0, mid;
    int s[5000005];
    int n, i;

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

    mergeSort(s, 0, n);

    for (i = 0; i < n; i++)
    {
        printf("%d", s[i]);
        if (i != n - 1)
            printf(" ");
    }
    printf("\n%d\n", cnt);

    return 0;
}

void mergeSort(int *s, int left, int right)
{
    int mid;
    if (left + 1 < right)
    {
        mid = (left + right) / 2;
        mergeSort(s, left, mid);
        mergeSort(s, mid, right);
        merge(s, left, mid, right);
    }
}

void merge(int *s, int left, int mid, int right)
{
    int n1, n2;
    // int L[2500000],R[250000];
    int i = 0, j = 0, k;

    n1 = mid - left;
    n2 = right - mid;

    for (i = 0; i < n1; i++)
    {
        L[i] = s[left + i];
    }
    for (i = 0; i < n2; i++)
    {
        R[i] = s[mid + i];
    }
    L[n1] = 2000000000;
    R[n2] = 2000000000;

    i = 0;
    j = 0;

    for (k = left; k < right; k++)
    {
        cnt++;
        if (L[i] <= R[j])
        {
            s[k] = L[i];
            i++;
        }
        else
        {
            s[k] = R[j];
            j++;
        }
    }
}



Measured memory_bytes: 5652
n = input()

if n == 'SUN':
    print(7)
elif n == 'MON':
    print(6)
elif n == 'TUE':
    print(5)
elif n == 'WED':
    print(4)
elif n == 'THU':
    print(3)
elif n == 'FRI':
    print(2)
elif n == 'SAT':
    print(1)


Measured memory_bytes: 38384
#include<cstdio>
int N,A,B;
int o[303333],lo;
bool construct(){
	if(A == 1){
		if(B != N)return false;
		for(int i=N; i>=1; i--)
			printf("%d%c",i,i>1?' ':'\n');
		return true;
	}
	if(B == 1){
		if(A != N)return false;
		for(int i=1; i<=N; i++)
			printf("%d%c",i,i<N?' ':'\n');
		return true;
	}
	if(A + B <= N + 1 && (long long int)A*B >= N){
		lo = 0;
		for(int i=B; i>=1; i--)
			o[++lo] = i;
		for(int i=2; i<=A; i++){
			int sz = N - (lo + A - i + 1) + 1;
			if(sz > B)sz = B;
			int s = lo;
			for(int j=sz; j>=1; j--)
				o[++lo] = s + j;
		}
		for(int i=1; i<=N; i++)
			printf("%d%c",o[i],i<N?' ':'\n');
		return true;
	}else
		return false;
}
int main(){
	scanf("%d%d%d",&N,&A,&B);
	if(!construct()){
		puts("-1");
	}
	return 0;
}


Measured memory_bytes: 3328
def gcd(a,b)
  a,b = b,a%b while b > 0
  a
end

while line = gets
  n, x=line.chomp.split(" ").map(&:to_i)

  data = gets.chomp.split(" ").map(&:to_i)
  data << x
  data.sort!

  diff = data[1] - data[0]
  (data.size - 1).times do |i|
    diff = gcd(diff, data[i+1] - data[i])
  end
  puts diff
end



Measured memory_bytes: 10624
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
 
#define div1 1000000007
 
using namespace std;
 
int main(void)
{
    int N, i, ans=0;
    string S;

    cin >> N >> S;

    for(i=0; i<=N-3; i++){
	if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
	    ans++;
	}
    }

    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        int c=scanner.nextInt();

        int keep;

        if(a>b){
            keep=a;
            a=b;
            b=keep;
        }
        if(b>c){
            keep=b;
            b=c;
            c=keep;
        }
        if(a>b) {
            keep=a;
            a=b;
            b=keep;
        }
        System.out.println(a+" "+b+" "+c);
    }
}



Measured memory_bytes: 26276
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int ctoi(const char c){
	if('0' <= c && c <= '9') return (c-'0');
	return -1;
}

int main(){
	int N, T, A;
	cin >> N >> T >> A;
	vector<double> H(N);
	for(int i=0; i<N; ++i) cin >> H[i];
	int ans = 0;
	double best = intMAX;
	for(int i=0; i<N; ++i){
		double temp = T - H[i] * 0.006;
		if(abs(best - A) > abs(temp - A)){
			best = temp;
			ans = i+1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3660
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
suma,sumb=0,0
l=[0 for _ in range(n)]
for i in range(n):
    suma+=a[i]
    sumb+=b[i]
    l[i]=b[i]-a[i]
if sumb>suma:
    print(-1)
    exit()
l.sort()
cnt=0
ans=0
for i in range(n):
    if l[i]>0:
        cnt+=l[i]
        ans+=1
for i in l:
    if cnt>0:
        cnt+=i
        ans+=1
print(ans)

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

using namespace std;

#define DEBUG 0
#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define VIN(VECTOR,n)\
REP(CNT,n){\
	lli TMP;\
	cin>>TMP;\
	VECTOR.push_back(TMP);\
}
lli zettai(lli a){
	if(a>=0)return a;
	else return -a;
}

int main(){
	lli n,m;
	vector<lli> x[3];
	cin>>n>>m;
	REP(i,n){
		lli tmp[3];
		REP(j,3){
			cin>>tmp[j];
			x[j].push_back(tmp[j]);
		}
	}

	lli ansSum=0;

	for(int a=-1;a<2;a+=2){
	for(int b=-1;b<2;b+=2){
	for(int c=-1;c<2;c+=2){
		vector<lli> ans;
		lli sum=0;
		REP(i,n)ans.push_back(a*x[0].at(i)+b*x[1].at(i)+c*x[2].at(i));
		sort(ans.begin(),ans.end());
		REP(i,m)sum+=ans[i];
		if(ansSum <= zettai(sum))ansSum=zettai(sum);
	}
	}
	}

	cout<<ansSum<<endl;
}

Measured memory_bytes: 256
def counting_sort(a, b, k):
    c = [0 for _ in range(k + 1)]
    for i in range(len(a)):
        c[a[i]] += 1
    for i in range(1, len(c)):
        c[i] += c[i -1]
    for i in range(len(a) - 1, -1, -1):
        b[c[a[i]] - 1] = a[i]
        c[a[i]] -= 1

n = input()
a = list(map(int, input().split()))
b = [0 for _ in range(len(a))]
counting_sort(a, b, max(a))
print(*b)

Measured memory_bytes: 261880