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

#define int long long

using namespace std;

signed main(){
    string s,t;
    cin>>s>>t;
    int dp[s.length()+1][t.length()+1]; 
    pair<int,int> prev[s.length()+1][t.length()+1]; 
    memset(dp,0,sizeof(dp));
    // dp[i][j] = length of longest  subsequence for s[0->i] & t[0->j]
    dp[0][0]=0;
    for(int i=1;i<=s.length();i++){
        for(int j=1;j<=t.length();j++){
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            prev[i][j]=(dp[i-1][j]>dp[i][j-1])?prev[i-1][j]:prev[i][j-1];
            if(s[i-1]==t[j-1]){
                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
                prev[i][j] = make_pair(i-1,j-1);
            }
        }
    }
    // for(int i=0;i<=s.length();i++){
    //     for(int j=0;j<=t.length();j++){
    //         cout<<"("<<prev[i][j].first<<" , "<<prev[i][j].second<<") ";
    //     }
    //     cout<<"\n";
    // }
    // cout<<dp[s.length()][t.length()];
    string ans="";
    int size=dp[s.length()][t.length()];
    pair<int,int> curr=prev[s.length()][t.length()];
    while(size>0){
        ans = s[curr.first]+ans;
        curr = prev[curr.first][curr.second];
        size--;
    }
    cout<<ans;
}

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

int main() {
  int A; int B;
  cin>>A>>B;
  if(A==2){
    if(B==2)
      cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
 else if(A==4||A==6||A==9||A==11){
    if(B==4||B==6||B==9||B==11)
      cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  else{
    if(B==1||B==3||B==5||B==7||B==8||B==10||B==12)
      cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define all(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define tr(container, it) \
	for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) 

// #define sz(a) int((a).size())
// #define pb push_back
// #define fill(a,v) memset(a,v,sizeof a)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;

#define trace3(x,y,z) cout<< '>' << #x << ':' << x \
		<< " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;

#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x \
	<< " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;


inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

const double pi = acos(-1);

/////////////////////////////////////////////////////////////////////

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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } // __gcd(0,0) gives exception

const int MAX_N = 110;

int arr[28]={0};

int main(){
	int H,W,odd=0,even=0;
	string s;
	scanf("%d %d",&H,&W);
	for(int i=0;i<H;i++){
		cin>>s;
		for(int i=0;i<W;i++){
			arr[s[i]-'a'+1]++;
		}
	}
	for(int i=1;i<27;i++){
		arr[i]=arr[i]%4;
		if(arr[i]%2){
			odd++;
		}
		else if(arr[i]){
			even++;
		}
	}
	if(H%2==0 && W%2==0){
		if(even==0 && odd==0)
			printf("Yes\n");
		else
			printf("No\n");
	}
	else if(H%2==1 && W%2==1){
		if(odd==1 && 2*even<=(H+W-1))
			printf("Yes\n");
		else
			printf("No\n");
	}
	else{
		//trace2(odd,even);
		if(odd==0){
			if(H%2){
				if(even<=(W/2))
					printf("Yes\n");
				else
					printf("No\n");
			}
			else{
				if(even<=(H/2))
					printf("Yes\n");
				else
					printf("No\n");
			}
		}
		else
			printf("No\n");
	}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

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

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N, D;
double X[10][10];

int main(){
  cin >> N >> D;
  REP(i, N) REP(j, D) cin >> X[i][j];

  ll ans = 0;
  REP(i, N) {
    for (int j = i + 1; j < N; j++) {
      double s = 0.0;
      REP(d, D) {
        s += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
      }
      double dis = sqrt(s);
      if(floor(dis) == dis) ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// Date: 2020-03-07

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int main() {
    LL n, a, b;
    cin >> n >> a >> b;
    LL ans = n/(a+b)*a;
    LL rem = n-n/(a+b)*(a+b);
    ans += min(rem, a);
    cout << ans;

    return 0;
}

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

template<typename T>
struct DiameterForEdge {
    using Edge = pair<int, T>;
    vector<T> dp;
    vector<vector<Edge>> g;
    DiameterForEdge(int n) : dp(n), g(n) { }
    void add_edge(int u,int v, T c) {
        g[u].emplace_back(v, c);
        g[v].emplace_back(u, c);
    }
    void dfs(int u, int p, int &s) {
        if (p < 0) dp[u] = T(0);
        if (dp[s] < dp[u]) s = u;
        for (Edge &e: g[u]) if (e.first != p) {
            dp[e.first] = dp[u] + e.second;
            dfs(e.first, u, s);
        }
    }
    pair<int, int> endPoints() {
        int s = 0; dfs(s, -1, s);
        int t = s; dfs(t, -1, t);
        return {s, t};
    }
    T build() {
        int t = endPoints().second;
        return dp[t];
    }
    vector<T> distance(int v) {
        dfs(v, -1, v);
        return dp;
    }
    vector<T> farthest() {
        int t = endPoints().second;
        auto ds = dp;
        auto dt = distance(t);
        for (int i = 0; i < ds.size(); i++) ds[i] = max(ds[i], dt[i]);
        return ds;
    }
};

int main() {
    int n; cin >> n;
    DiameterForEdge<int> g(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        g.add_edge(a, b, 1);
    }
    int diam = g.build();
    cout << ((diam % 3 == 1) ? "Second" : "First") << endl;
    return 0;
}

Measured memory_bytes: 18560
#include<stdio.h>

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

  int A[100],v;
  int i,j;

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

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

  for(i=1;i<n;i++){
    v = A[i];
    j = i-1;
    while(j>=0 && A[j]>v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    for(j=0;j<n;j++){
      printf("%d",A[j]);
      if(j<n-1) printf(" ");
      else printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 2096
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while(ch > '9' || ch < '0') { if(ch == '-') f = -1; ch = getchar(); }
	do x = x * 10 + ch - 48, ch = getchar(); while(ch >= '0' && ch <= '9');
	return x * f;
}

typedef long long ll;
const int MAXN = 500001;
const int mod = 998244353;

int n,m;
ll fac[MAXN],ifac[MAXN];
ll pown[MAXN],powm[MAXN];

ll C(int n,int m) {
	return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

int main() {
	n = read(), m = read();
	fac[0] = 1;
	for(int i = 1;i <= n || i <= m;i++) fac[i] = (fac[i - 1] * i) % mod;
	ifac[0] = ifac[1] = 1;
	for(int i = 2;i <= n || i <= m;i++) ifac[i] = ((mod - mod / i) * ifac[mod % i]) % mod;
	for(int i = 2;i <= n || i <= m;i++) ifac[i] = (ifac[i - 1] * ifac[i]) % mod;
	pown[0] = powm[0] = 1;
	for(int i = 1;i <= m;i++) pown[i] = (pown[i - 1] * (n + 1)) % mod;
	for(int i = 1;i <= n;i++) powm[i] = (powm[i - 1] * (m + 1)) % mod;
	ll ans = 0;
	for(int i = 0;i <= n && i <= m;i++) {
		ll res = (C(n,i) * C(m,i)) % mod;
		res = res * fac[i] % mod;
		res = res * pown[m - i] % mod;
		res = res * powm[n - i] % mod;
		if(i & 1) ans = (ans + mod - res) % mod;
		else ans = (ans + res) % mod;
	}
	std::printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 15872
#include <iostream>

void solve(int amin, int amax, int nmin, int nmax) {
    if (amin + 1 != amax) {
        std::cout << "No" << std::endl;
        return;
    }

    int multi_colors = amax - nmin;
    if (1 <= multi_colors && 2 * multi_colors <= nmax) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

}
int main()
{
    int n;
    std::cin >> n;

    int as[2] = {-1, -1};
    int count[2] = {0, 0};

    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        if (as[0] < 0) {
            as[0] = a;
            count[0]++;
        } else if (as[0] == a) {
            count[0]++;
        } else if (as[1] < 0) {
            as[1] = a;
            count[1]++;
        } else if (as[1] == a) {
            count[1]++;
        } else {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    if (as[1] < 0) {
        if (as[0] == n - 1) {
            std::cout << "Yes" << std::endl;
        } else if (2 * as[0] <= n) {
            std::cout << "Yes" << std::endl;
        } else {
            std::cout << "No" << std::endl;
        }
        return 0;
    }

    if (as[0] < as[1]) {
        solve(as[0], as[1], count[0], count[1]);
    } else {
        solve(as[1], as[0], count[1], count[0]);
    }
    return 0;
}


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

int mod = 1000000007;
int64_t large = 9223372036854775807;

int main()
{
    string S;
    int K;
    cin >> K >> S;
    if (S.size() <= K)
        cout << S;
    else
    {
        for (int i = 0; i < K; i++)
            cout << S[i];
        cout << "...";
    }
}

Measured memory_bytes: 3624
<?php
class Harmony {
    var $A, $B;
    
    function __construct() {
        list($this->A, $this->B) = explode(" ", trim(fgets(STDIN)));
    }
    function __invoke() {
        if (($this->A + $this->B) % 2 === 0) {
            return ($this->A + $this->B) / 2;
        } else {
            return "IMPOSSIBLE";
        }
    }
}

$Harmony = new Harmony();
echo $Harmony();

Measured memory_bytes: 4728
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const double EPS = 1E-10;

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



int main(){
    int N, M; std::cin >> N >> M;
    std::vector<std::pair<int , int>> ba(M);
    for(int i(0); i < M; ++i){
        std::cin >> ba[i].second >> ba[i].first;
    }
    std::sort(ba.begin(), ba.end());
    int cnt(0), cur(-1);
    for(int i(0); i < M; ++i){
        if(cur < ba[i].second){
            cur = ba[i].first - 1;
            ++cnt;
        }
    }
    std::cout << cnt << std::endl;
    return 0;
}


Measured memory_bytes: 1152
import sys
from collections import defaultdict

def solve():
    input = sys.stdin.readline
    N = int(input())
    C = defaultdict(int)
    for _ in range(N):
        s = input().strip("\n")
        C[s] += 1
    P = ["AC", "WA", "TLE", "RE"]

    for p in P:
        print(p + " x " + str(C[p]))
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9472
// Problem : B - Easy Linear Programming
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//look at my code
//my code is amazing
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define mod 1000000007 //998244353
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define nl "\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define cout1(a) cout<<a<<nl
#define cout2(a,b) cout<<a<<" "<<b<<nl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<nl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<nl
#define vcout(v,i) cout<<v[i].fi<<" "<<v[i].se<<nl
#define x first
#define y second
#define vc vector
#define pb push_back
#define ar array
#define all(a) (a).begin(), (a).end()
#define ms(v,n,x) fill(v,v+n,x);
#define init(c,a) memset(c,a,sizeof(c))
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define maxi(a,b,c) max(a,max(b,c))
#define maxii(a,b,c,d) max(max(a,b),max(c,d))
#define mini(a,b,c) min(a,min(b,c))
#define md(a,b)  ((a%mod)*(b%mod)+mod)%mod 
#define inf 9e18
#define cases ll T;cin>>T;while(T--)
#define BLOCK 500
//const double PI = 3.141592653589793238460;
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
// const int N=;

int32_t main()
{
    
	fast
	
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll ans=0;
	if(k>0){
		ll x=min(k,a);
		k-=x;
		ans+=x;
	}
	
	if(k>0){
		ll x=min(k,b);
		k-=x;
	}
	
	if(k>0){
		ll x=min(k,c);
		ans-=x;
		
	}
	
	cout<<ans;
	

	



    

	return 0;
    
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    /*左から決まらないか？
    そもそも縦に並ぶか横に重ねて並ぶかしか可能性がない
    今回の条件だと
    ...aad...
    ...cbb..
    みたいに一個ずれて重なることがあり得ない。一個のサイズがどれも2だから
    じゃあ簡単じゃないか？
     */
    int n;
    string s,t;
    cin>>n;
    cin>>s;
    cin>>t;
    ll ans;
    int i=0;
    if(s[0]==t[0]){
        ans=3;i++;
    }
    else{
        ans=3*2;i+=2;
    }
    while(i<n){
        if(s[i-1]==t[i-1]){
            if(s[i]==t[i]){
                ans=(ans*2)%mod;
                i++;
            }
            else{
                ans=(ans*2)%mod;
                i+=2;
            }
        }
        else{
            if(s[i]==t[i]){
                i++;
            }
            else{
                ans=(ans*3)%mod;
                i+=2;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            var S = ReadLine();
            var diff = 0L;
            for (var i = 1; i < S.Length; ++i)
                if (S[i] != S[i - 1]) ++diff;
            WriteLine(diff);
        }
    }
}

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

using namespace std;
typedef long long ll;

constexpr int MOD=1000000007;

int main(){
  ll N, K;
  cin >> N >> K;
  
  ll sum = 0;
  for(ll i=K; i<=N+1; i++){
    ll temp = (((ll)((N+1)-i) * i + 1) % MOD);
    sum = sum + temp;
  }
  
  cout << (sum % MOD) << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define MAX_N 2000
using namespace std;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, m, l, a[MAX_N+5], b[MAX_N+5], c[MAX_N+5], d[MAX_N+5];
bool cmp(const int &x, const int &y) {return a[x] < a[y];}
int main() {
	read(n), read(l), read(m);
	for (int i = 1; i <= n; i++)
		read(a[i]), b[i] = i;
	sort(b+1, b+n+1, cmp); int ans = 0x3f3f3f3f;
	for (int l = 1, r; l <= n; l++) {
		int cnt = 0, tim = 0;
		memset(c, 0, sizeof c), memset(d, 0, sizeof d);
		for (int p = 1, q; p <= n; p = max(p+1, q)) {
			for (q = p; a[q] >= a[b[l]]; q++) ; cnt++;
			for (int i = p; i < q; i++) d[c[i] = cnt]++;
		}
		for (r = l; tim < m && r <= n; r++)
			if (d[c[b[r]]] >= ::l) d[c[b[r]]]--, tim++;
		if (tim == m) ans = min(ans, a[b[r-1]]-a[b[l]]);
	}
	return printf("%d\n", ans), 0;
}


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

// for debug macro
bool global_debug_flag = false;
#define DEBUG(val) \
  if (global_debug_flag) cout << #val << " = " << val << endl

int main() {
  string s;
  read s;
  string ans(s.size(), 'x');
  cout << ans << endl;
}


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

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

	long long onel=min(4*a,min(2*b,c));
	long long twol=min(2*onel,d);


	if(n%2==0)
		cout<<n/2*twol<<endl;
	else if(n==1)
		cout<<onel<<endl;
	else
		cout<<n/2*twol+onel<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
#define WRONGMS 1900

int main() {
	int n, m,acms,wams,total;
	cin >> n >> m;
	acms = (n - m)*100;
	wams = m*WRONGMS;
	total = (acms + wams)*pow(2,m);
	cout << total << endl;
	return 0;
}

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

using namespace std;

int main(){
	int N; cin>>N;
	vector<int> a(N), b(N), c(N);
	for(int n=0; n<N; n++)
		cin>>a[n];
	for(int n=0; n<N; n++)
		cin>>b[n];
	for(int n=0; n<N; n++)
		cin>>c[n];
	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());
	sort(c.rbegin(), c.rend());
	vector<int> bm(N); //bm gives for each i the number of Cs larger than Bi
	int s=0;
	for(int x=0; x<N; x++){
		while(s<N&&c[s]>b[x]){
			s++;
		}
		bm[x] = s;
	}
	long long ans = 0;
	long long t=0;
	s=0;
	for(int x=0; x<N; x++){
		while(s<N&&b[s]>a[x]){
			t += bm[s];
			s++;
		}
		ans += t;
	//	cout << t << endl;
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
	int n, m; cin >> n >> m;
	vector<bool> get(n, false);
	vector<int> wr(n, 0);
	for (int i = 0; i < m; i++) {
		int p; cin >> p; p--;
		string s; cin >> s;
		if (s == "AC") get.at(p) = true;
		else if (get.at(p) == false) wr.at(p)++; 
	}
	int ca = 0, pen = 0;
	for (int i = 0; i < n; i++) {
		if (get.at(i) == true) {
			ca++;
			pen += wr.at(i);
		}
	}
	cout << ca << " " << pen << endl;
}

Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

int main()
{

  ll n; cin >> n;
  vector<ll> d(n+1); rep(i,n){cin>>d[i+1];}

  if (d[1]!=0){cout << 0;return 0;}

  vector<ll> num(n+1,0);
  ll M=0;
  for (int i=2; i<=n; i++){
    num[d[i]]++;
    M=max(M,d[i]);
  }

  ll ans=1;

  for (int i=1; i<M; i++){
    rep(j,num[i+1]){
      ans *= num[i];
      ans %= 998244353;
    }
  }

  if (M==0 || num[0]>0){ans = 0;}

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int x,y;
  cin >> x >> y;
  if(y%2!=0) {
    cout << "No" << endl;
    return 0;
  }
  int a,b;
  a = 2*x-y/2;
  b = y/2 - x;
  if(a==0 and b == 0) {
    cout << "No" << endl;
    return 0;
  }
  Yes(a>=0 and b >= 0);

  return 0;
}


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

using namespace std;

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

    vector<bool> vec(N, false);
    for(int i=0; i<K; i++){
        int num;
        cin >> num;
        for(int j=0; j<num; j++){
            int index;
            cin >> index;
            vec.at(index-1) = true;
        }
    }

    int count=0;
    for(int i=0; i<N; i++){
        if(!vec.at(i))count++;
    }
    cout << count;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

ll dp[31];

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

    dp[1]=1;
    dp[2]=2;
    dp[3]=4;
    for(int i=4;i<31;i++) dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
    while(true){
        int d;cin>>d;
        if(d==0) return 0;
        ll ans = dp[d]/3650;
        if(dp[d]%3650>0) ans++;
        cout<<ans<<endl;
    }
}



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

int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<char>> C(H,vector<char>(W));
  rep(i,H){
    rep(j,W){
      cin >> C.at(i).at(j);
    }
  }
  rep(i,H){
    rep(k,2){
      rep(j,W){
        cout << C.at(i).at(j);
      }
      cout << endl;
    }
  }
}


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

using namespace std;

int main(){
  int n;
  cin >> n;
  
  int ans = 111;
  int d = 1e9;
  for(int i=111; i<=999; i+=111){
  	if(i>=n && abs(i-n) < d){
  		ans = i;
  		d = abs(i-n);
  	}
  }
  
  cout << ans << endl;
  
  
  return 0;
}

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

int main(){
    char sr[256];
    cin>>sr;
    for(int i=0;i<=strlen(sr)-1;++i){
        if (sr[i]==','){
            cout<<' ';
        }
        else{
            cout<<sr[i];
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const int MAX_N=300001;

int main(){
  int N,M;
  cin >> N >> M ;
  int cnt[N];
  fill(cnt,cnt+N,0);
  rep(i,M){
    int a,b;
    cin >> a >> b ;
    a--; b--;
    cnt[a]++; cnt[b]++;
  }
  rep(i,N) cout << cnt[i] << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
int const MAXN=440;
int n, v[MAXN];
long long int dp[MAXN][MAXN], pre[MAXN];
long long int sum(int l, int r){
	return (l==0?pre[r]:pre[r]-pre[l-1]);
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>v[i];
		pre[i]=v[i];
		if(i>0)	pre[i]+=pre[i-1];
	}
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			dp[i][j]=1e18;
	for(int len=1;len<n;len++)
		for(int start=0;start+len<n;start++){
			for(int p=1;p<=len;p++)
				dp[start][start+len]=min(dp[start][start+len],dp[start][start+p-1]+dp[start+p][start+len]);
			dp[start][start+len]+=sum(start,start+len);
		}
	cout<<dp[0][n-1];
}

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

using namespace std;

int main () {
   int N;
   cin>>N;
   string S;
   cin>>S;
   int x=0;
   for(int i=0;i<N-2;i++){
       if(S.substr(i,3)=="ABC")
           x++;
   }
   cout<<x;
return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
X, K, D = list(map(int, input().split()))
x = int(X)
D = int(D)
j = 0
j = abs(X//D)

if j > K:
    j = K


if x > 0:
    x = x - (D*j)
else:
    x = x + (D*j)

j = (K-j) % 2

if j==0:
    print(abs(x))
else:
    if x > 0:
        x = x - D
    else:
        x = x + D
    print(abs(x))


Measured memory_bytes: 26416
#include <bits/stdc++.h>
using namespace std;
#define init_value 0 

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

struct segtree{
	//元データx[i]はv[n+i]
	//v[i]の親はv[i/2],子はv[i*2]とv[i*2+1]
	vector<int> v;
	int n;
	
	segtree(vector<int> x){
		n=1;
		while(true){
			if(n>=x.size())break;
			n*=2;
		}
		v.resize(2*n,init_value);
		
		for(int i=0;i<x.size();i++){
			v[n+i]=x[i];
		}
		for(int i=n-1;i>=0;i--){
			v[i]=func(v[i*2],v[i*2+1]);
		}
	}
	
	
	void update(int x,int val){
		x+=n;
		v[x]=val;
		while(true){
			x=(x)/2;
			v[x]=func(v[x*2],v[x*2+1]);
			if(x<=0)break;
		}
	}
	
	//区間[l,r)におけるクエリ処理
	int query(int l,int r){
		int res = init_value;
		l+=n;r+=n;
		while(true){
			if(l%2==1){
				res=func(v[l],res);
				l++;
			}
			if(r%2==1){
				res=func(v[r-1],res);
				r--;
			}
			if(l>=r)break;
			l/=2;r/=2;
		}
		return res;
	}
	int func(int a,int b){
		return gcd(a,b);
	}
	
};

int main(){
	int N;
	cin>>N;
	vector<int> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	
	segtree seg(A);
	
	int maxi = 0;
	for(int i=0;i<N;i++){
		maxi = max(maxi,gcd(seg.query(0,i),seg.query(i+1,N)));
	}
	
	cout<<maxi<<endl;
	
	
	return 0;
}

Measured memory_bytes: 2048
#include<stdio.h>
int main() {
	int S, h,m,s;
	scanf("%d", &S);
	h = S / 3600;
	m = (S % 3600) / 60;
	s = (S % 3600) % 60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 1020
#include <stdio.h>
#include <string.h>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=10050;
const int maxe=40414;
const int INF=0x3f3f3f3f;
struct note
{
    int v;
    int d;
    int c;
    int next;
};
note edge[maxe];
int head[maxn];
int cnt;
void init()
{
    memset(head,-1,sizeof(head));
    cnt=0;
}
void addedge(int u,int v,int d,int c)
{
    edge[cnt].v=v;
    edge[cnt].c=c;
    edge[cnt].d=d;
    edge[cnt].next=head[u];
    head[u]=cnt++;
}
int cost[maxn];
int dis[maxn];
bool vis[maxn];
queue<int>q;
void spfa(int n)
{
    while(!q.empty())q.pop();
    for(int i=1; i<=n; i++)
        cost[i]=dis[i]=INF;
    memset(vis,false,sizeof(vis));
    dis[1]=0;
    cost[1]=0;
    vis[1]=true;
    q.push(1);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=false;
        for(int i=head[u]; i!=-1; i=edge[i].next)
        {
            int v=edge[i].v;
            int val=edge[i].d;
            if(dis[v]>dis[u]+val||(dis[v]==dis[u]+val&&cost[v]>edge[i].c))//有多条最短路时，取花费最小的
            {
                dis[v]=dis[u]+val;
                cost[v]=edge[i].c;
                if(!vis[v])
                {
                    q.push(v);
                    vis[v]=true;
                }
            }
        }
    }
}
int main()
{
    int n,m;
    int u,v,d,c;
    while(~scanf("%d%d",&n,&m))
    {
        if(n==0&&m==0) break;
        init();
        for(int i=0; i<m; i++)
        {
            scanf("%d%d%d%d",&u,&v,&c,&d);
            addedge(u,v,c,d);
            addedge(v,u,c,d);
        }
        spfa(n);
        int ans=0;
        for(int i=1; i<=n; i++)
            ans+=cost[i];
        printf("%d\n",ans);
    }
    return 0;
}



Measured memory_bytes: 3984
N, Q = map(int, input().split())
es = [[] for i in range(N)]
value = [0]*N

for i in range(N-1):
  a, b = map(int, input().split())
  es[a-1] += [b-1]
  es[b-1] += [a-1]

for i in range(Q):
  p, x = map(int, input().split())
  value[p-1] += x

stuck = [0]
log = [1]*N
log[0] = 0

while stuck:
  e = stuck.pop()
  for f in es[e]:
    if log[f]:
      log[f] = 0
      value[f] += value[e]
      stuck += [f]

ans = [str(v) for v in value]
print(*ans)


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

int main() {
  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<long> F(N);
  for (int i = 0; i < N; i++) cin >> F.at(i);
  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());
  vector<long> AF(N);
  for (int i = 0; i < N; i++) AF.at(i) = A.at(i) * F.at(i);
  long ok = 1e18, ng = -1;
    while (ok - ng > 1) {
      long mid = (ok + ng) / 2;
      long sum = 0;
      for (int i = 0; i < N; i++) {
        if (AF.at(i) > mid) sum += ((AF.at(i) - mid) + F.at(i) - 1) / F.at(i);
      }
      (sum <= K) ? ok = mid : ng = mid;
    }
  cout << ok << "\n";
}

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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

using ll = long long;
const int N = 2e5 + 5;
int f[N];
int a[N];



int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        f[a[i]]++;
    }

    for (int i = 0; i <= n; i++) {
        debugf("f[%d]=%d\n", i, f[i]);
        ll fx = f[i];
        if (fx > 0)
            ans += fx * (fx - 1) / 2;
    }

    debugf("!%lld\n", ans);

    for (int i = 0; i < n; i++) {
        ll fx = f[a[i]];
        ans -= fx * (fx - 1) / 2;
        f[a[i]]--;
        fx = f[a[i]];
        ans += fx * (fx - 1) / 2;

        cout << ans << endl;

        fx = f[a[i]];
        ans -= fx * (fx - 1) / 2;
        f[a[i]]++;
        fx = f[a[i]];
        ans += fx * (fx - 1) / 2;
    }



    return 0;
%>

Measured memory_bytes: 3712
module Is = Set.Make (struct type t = int let compare = compare end)

let id x = x

let solve n =
  let rec aux n' s o =
    if n' <= 0 then (s, o)
    else
      match Scanf.scanf "%d " id / 400 with
      | a when a < 8 -> aux (pred n') (Is.add a s) o
      | _ -> aux (pred n') s (succ o)
  in
  aux n Is.empty 0

let () =
  Scanf.scanf "%d\n" solve
  |> (fun (s, o) -> (max 1 (Is.cardinal s), Is.cardinal s + o))
  |> fun (mi, ma) -> Printf.printf "%d %d\n" mi ma

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)


template<class T> inline bool chMax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b){ if (a > b) { a = b; return true; } return false; }
template<class T> inline ll gcd(T a, T b){ if (a % b == 0){ return b; } else{ return gcd(b, a%b); } }
template<class T> inline ll lcm(T a, T b){ return a * b / gcd(a, b); }
template<class T> inline ll fact(T a){ if (a == 1){ return a; } else{ return a * fact(a - 1); } }

int main(){
    ll N;
    vector<pair<ll, ll>> A;
    cin >> N;
    rep(i, 0, N){
        ll temp;
        cin >> temp;
        A.push_back(make_pair(temp, i + 1));
    }
    sort(begin(A), end(A));
    for (pair<ll, ll> elm : A){
        cout << elm.second << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 2544
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
using ll = long long int;

const int N_MAX = 1E+07 + 5;
ll cnt[N_MAX];

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

    memset(cnt, 0, sizeof(cnt));
    ll ans = 0;
    for(int i = 1; i <= k; i++){
        for(int j = 1; i * j <= k; j++){
            cnt[i * j]++;
        }
        ans += i * cnt[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 81756
// AOJ 0245: Time Sale
// 2017.12.16 bal4u@uu

#include <stdio.h>
#include <string.h>

#define QMAX 400000
typedef struct { char r, c, t; int d, b; } Q;
Q q[QMAX+2]; int top, end;
typedef struct { int d, s, e; } G;
G sell[10];
signed char map[21][21];
char mk[21][21][101][1024];
char buf[50], *p;
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

int in()
{
	int n = 0;
	while (*p >= '0') n = 10*n + (*p++ & 0xf);
	p++;
	return n;
}

int main()
{
	int X, Y, r, c, n, i, j, sr, sc, max, ans;
	int d, t, b, r2, c2;

	while (fgets(p=buf, 10, stdin) && *p != '0') {
		X = in(), Y = in();
		for (r = 0; r < Y; r++) {
			fgets(p=buf, 50, stdin);
			for (c = 0; c < X; c++) {
				if (*p == '.') map[r][c] = -1;
				else if (*p == 'P') sr = r, sc = c, map[r][c] = -1;
				else map[r][c] = *p & 0xf;
				p += 2;
			}
		}
		fgets(p=buf, 5, stdin);
		n = *p & 0xf, max = 0;
		for (i = 0; i < n; i++) {
			fgets(p=buf, 50, stdin);
			j = in();
			sell[j].d = in(), sell[j].s = in(), sell[j].e = t = in();
			if (t > max) max = t;
		}

		ans = 0;
		memset(mk, 0, sizeof(mk));
		q[0].r = sr, q[0].c = sc, q[0].t = 0, q[0].d = 0, q[0].b = 0;
		top = 0, end = 1;
		while (top != end) {
			r = q[top].r, c = q[top].c, t = q[top].t, d = q[top].d, b = q[top].b;
			if (++top == QMAX) top = 0;

			if (t > max) continue;

			if (mk[r][c][t][b]) continue;
			mk[r][c][t][b] = 1;
			if (d > ans) ans = d;

			for (i = 0; i < 4; i++) {
				r2 = r + mv[i][0], c2 = c + mv[i][1];
				if (r2 < 0 || r2 >= Y || c2 < 0 || c2 >= X) continue;
				if ((j = map[r2][c2]) >= 0) {
					if (!(b & (1 << j)) && sell[j].s <= t && t < sell[j].e) {
						d += sell[j].d;
						b |= 1 << j;
					}
				}
			}
			for (i = 0; i < 4; i++) {
				r2 = r + mv[i][0], c2 = c + mv[i][1];
				if (r2 < 0 || r2 >= Y || c2 < 0 || c2 >= X || map[r2][c2] >= 0) continue;
				q[end].r = r2, q[end].c = c2, q[end].t = t+1, q[end].d = d, q[end].b = b;
				if (++end == QMAX) end = 0;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    long long N;
    cin >> N;
    long long g = 0;
    for (int i = 0; i < N; ++i) {
        long long a; cin >> a;
        g = GCD(g, a);
    }
    cout << g << endl;
}

Measured memory_bytes: 256
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn

object Main extends App {
  val Array(a, b, h, m) = readIntArr
  val a1: Double = 2D * Math.PI / 60.0 / 12.0 * (h * 60 + m)
  val a2: Double = 2D * Math.PI / 60.0 * m
  val x1 = Math.sin(a1) * a
  val y1 = Math.cos(a1) * a
  val x2 = Math.sin(a2) * b
  val y2 = Math.cos(a2) * b
  val dist = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))
  println(dist)

  def readIntPair: (Int, Int) = {
    val Array(x, y) = StdIn.readLine().split(" ").map(_.toInt)
    (x, y)
  }

  def readIntArr = StdIn.readLine().split(" ").map(_.toInt)
}






Measured memory_bytes: 54772
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		sc.close();
		String abc = "qwertyuiopasdfghjklzxcvbnm";
		Map<String, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			if (map.containsKey(String.valueOf(s.charAt(i)))) {
				map.put(String.valueOf(s.charAt(i)), map.get(String.valueOf(s.charAt(i))) + 1);
			} else {
				map.put(String.valueOf(s.charAt(i)), 1);
			}
		}
		long ans = 1;
		long mod = 1000000007;
		for (int i = 0; i < 26; i++) {
			long get = 1;
			if (map.containsKey(String.valueOf(abc.charAt(i)))) {
				get += (long) map.get(String.valueOf(abc.charAt(i)));
			}
			ans *= get;
			ans %= mod;
		}
		ans--;
		System.out.println(ans);
	}
}

Measured memory_bytes: 41420
def main():
    n = int(input())
    a = list(map(int,input().split()))

    yen = 1000
    stock = 0
    for i in range(n-1):
        stock_now = 0
        if stock > 0:
            yen += stock * a[i]
            stock = 0
        if a[i+1] > a[i] and i < n-1:
            stock_now = yen // a[i]
            yen -= stock_now * a[i]
            stock += stock_now
    print(yen+stock*a[-1])

if __name__=='__main__':
    main()


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

/************************** definations *******************************/
#define pi              2*acos(0.0)
#define ll              long long int
#define sc1(a)          scanf("%lld",&a)
#define sc2(a,b)        scanf("%lld %lld",&a,&b)
#define pf1(a)          printf("%lld\n",a)
#define pf2(a,b)        printf("%lld %lld\n",a,b)
#define Case(a)         printf("Case %d: ",a)
#define Casel(a)        printf("Case %lld: ",a)
#define INF             1e9
#define INFL            1e18
#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair
#define NEWLINE         cout << endl;
#define DONE            cerr << "Done" << endl
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << endl
#define READ            freopen("alu.txt", "r", stdin)
#define WRITE           freopen("vorta.txt", "w", stdout)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)
#define M               10000007
#define mod             100000007
/************************** definations *******************************/

int main()
{
    FASTIO;
    vector<int> v; int n,a,i,j,sum=0;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a;
        v.PB(a);
    }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            sum+= (v[i]*v[j]);
        }
    }
    cout << sum ;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int max;
    int count = 0;
    int i, j;
    cin >> n;
    int h[n];
    rep(i, n) {
      cin >> h[i];
    }
    max = -1;
    rep(i, n) {
      if (max <= h[i]) {
        count++;
        max = h[i];
      }
    }

    cout << count << '\n';

    return 0;
}


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

int main() {

    int x, y;

    scanf("%d %d", &x, &y);

    int isCheck = 0;

    if (y % 2 == 0) {

        for (int i = 0; i <= x; i++) {

            int turu = i;
            int kame = x - i;

            int mysum = turu * 2 + kame * 4;

            if (mysum == y) {
                isCheck = 1;
                break;
            }


        }
    }

    printf("%s", (isCheck == 0 ? "No" : "Yes"));


    return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<long long>a(5,0);
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    if(s.at(0)=='M'){
      a.at(0)++;
    }
    if(s.at(0)=='A'){
      a.at(1)++;
    }
    if(s.at(0)=='R'){
      a.at(2)++;
    }
    if(s.at(0)=='C'){
      a.at(3)++;
    }
    if(s.at(0)=='H'){
      a.at(4)++;
    }
  }
  long long ans=0;
  ans+=(a.at(0)*a.at(1)*(a.at(2)+a.at(3)+a.at(4)));
  ans+=(a.at(0)*a.at(2)*(a.at(3)+a.at(4)));
  ans+=(a.at(1)*a.at(2)*(a.at(3)+a.at(4)));
  ans+=(a.at(4)*a.at(3)*(a.at(0)+a.at(1)+a.at(2)));
  cout << ans << endl;
}


Measured memory_bytes: 3592
n = int(input())
R = list(map(int,input().split()))

def trace():
    for i in range(len(R)):
        if i != len(R) - 1:
            print(R[i],end=' ')
        else:
            print(R[i])

flag = True
count = 0
while flag:
    flag = False
    for i in range(1,n) [::-1]:
        if R[i] < R[i-1]:
            R[i],R[i-1] = R[i-1],R[i]
            count += 1
            flag = True

trace()

print(count)


Measured memory_bytes: 5608
n = int(input())
mod = 10**9+7
def cmb(n,r,mod):
    r = min(r, n-r)
    return (fact[n] * factinv[r] * factinv[n-r]) % mod
def makefact(n,mod):
    fact = [1,1]
    factinv = [1,1]
    inv = [0,1]
    for i in range(2,n+1):
        fact.append((fact[-1]*i) % mod)
        inv.append(-inv[mod%i]*(mod//i)%mod)
        factinv.append((factinv[-1]*inv[-1])%mod)
    return fact,factinv
fact,factinv = makefact(n,mod)
ans = 0
max_i = n//3
for i in range(1,max_i+1):
    ans += cmb(n-2*i-1,i-1,mod)
    ans %= mod
print(ans)

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

int main(void){
    int N;
    cin>>N;
    long long A[N+1],B[N+1];
    pair<int,int> C[N+1];
    long long T;
    T=0;
    for(int i=1;i<=N;i++){
        cin>>A[i]>>B[i];
        C[i] = make_pair(A[i] + B[i],i);
    }

    sort(C+1, C+N+1);
    reverse(C+1,C+N+1);



    for(int i=1;i<N+1;i++){
        if(i%2==1){
            T=T+A[C[i].second];
        }else{
            T=T-B[C[i].second];
        }



        
    }

    cout<<T<<endl;


    return 0;
}

Measured memory_bytes: 2688