akhauriyash/Code-Regression huggingface dataset:
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int h,w;cin >> h >> w;
    vvc mp(h,vc(w));
    set<int> yoko,tate;
    rep(i, h) {
        bool ok = true;
        rep(j, w) {
            cin >> mp[i][j];
            if(mp[i][j]=='#') ok = false;
        }
        if(ok) yoko.insert(i);
    }
    rep(j, w) {
        bool ok=true;
        rep(i, h) {
            if(mp[i][j]=='#') ok = false;
        }
        if(ok) tate.insert(j);
    }
    rep(i, h) {
        bool ok = false;
        rep(j, w) {
            if(yoko.count(i)||tate.count(j)) continue;
            cout << mp[i][j];
            ok=true;
        }
        if(ok)cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b){
    if (a < b) swap(a,b);
    if (a % b == 0) return b;
    return gcd(a % b, b);
}

int main(){
    ll k, tot =0;
    cin >> k;

    FOR(i, 1, k){
        FOR(j, 1, k){
            FOR(m, 1, k){
                tot += gcd(i, gcd(j, m));
            }
        }
    }

    cout << tot << endl;
}
   

Measured memory_bytes: 3632
using System;

namespace ABC026A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);


            int n;

            if (a == b && b == c && c == a)
                n = 1;
            else if (a == b || b == c || c == a)
                n = 2;
            else
                n = 3;

            Console.WriteLine(n);

            Console.ReadKey();
        }
    }
}


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

int main(){
    int n;
    cin>>n;
    int b,f,r,v;
    int h1[3][10],h2[3][10],h3[3][10],h4[3][10];
    for(int i=0;i<3;i++){
        for(int j=0;j<10;j++){
            h1[i][j]=h2[i][j]=h3[i][j]=h4[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        cin>>b>>f>>r>>v;
        if(b==1) h1[f-1][r-1]+=v;
        else if(b==2) h2[f-1][r-1]+=v;
        else if(b==3) h3[f-1][r-1]+=v;
        else if(b==4) h4[f-1][r-1]+=v;
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<10;j++){
            cout<<" "<<h1[i][j];
        }
        cout<<endl;
    }
    cout<<"####################"<<endl;
    for(int i=0;i<3;i++){
        for(int j=0;j<10;j++){
            cout<<" "<<h2[i][j];
        }
        cout<<endl;
    }
    cout<<"####################"<<endl;
    for(int i=0;i<3;i++){
        for(int j=0;j<10;j++){
            cout<<" "<<h3[i][j];
        }
        cout<<endl;
    }
    cout<<"####################"<<endl;
    for(int i=0;i<3;i++){
        for(int j=0;j<10;j++){
            cout<<" "<<h4[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3104
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define ll long long 
ll a,b,c,x,y,ans=0;
int main()
{
	cin>>a>>b>>c>>x>>y;
	for(int aa=1,bb=1;aa<=x||bb<=y;aa++,bb++)
	{
		long long tmp=0;
		if(aa<=x) tmp+=a;
		if(bb<=y) tmp+=b;
		ans+=min(tmp,2*c);
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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 dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

int main() {
    string s; cin >> s;
    string a = s.substr(0,2), b = s.substr(2,2);
    
    if (a >= "01" && a <= "12" && b >= "01" && b <= "12") {
        cout << "AMBIGUOUS" << endl;
    } else if (a >= "01" && a <= "12") {
        cout << "MMYY" << endl;
    } else if (b >= "01" && b <= "12") {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }
    return 0;
}


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

int main() {
    int N; cin >> N;
    vector<int> p(N);
    vector<int> m(N);
    rep(i, N){
        int x, y; cin >> x >> y;
        p[i] = x+y;
        m[i] = x-y;
    }

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

    int ans = max(p[N-1] - p[0], m[N-1] - m[0]);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
ll m = 1000000000;
int main(){
  ll s;
  cin>>s;
  ll x=(m-s%m)%m;
  ll y=(s+x)/m;
  cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;
}

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

int main() {
  int N,M,k;
  k=0;
  cin >>N>>M;
  vector<int> x(M),l(M-1);
  for(int i=0;i<M;i++){
    cin >>x[i];
  }
  sort(x.begin(),x.end());
  for(int i=0;i<M-1;i++){
    l[i]=x[i+1]-x[i];
  }
  sort(l.begin(),l.end());
  if(N>=M){
    cout<<0<<endl;
  }
  else{
    for(int i=0;i<N-1;i++){
      k+=l[M-2-i];
    }
    cout <<x[M-1]-x[0]-k<<endl;
  } 
}

Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

long long getMaxMultilpleLessThanOrEqual(long long v, long long a) {
    return (v / a) * a;
}

long long getMinMultilpleMoreThanOrEqual(long long v, long long a) {
    return ((v + a - 1) / a) * a;
}


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

    vector<long long> a;
    REP(i, k) {
        long long ai;
        cin >> ai;
        a.push_back(ai);
    }

    reverse(ALL(a));

    long long minTotal = a[0];
    long long maxTotal = a[0] + a[0] - 1;

    if (a[0] != 2) {
        cout << "-1" << endl;
        return 0;
    }

    for (int i = 1; i < (int)a.size(); i++) {
        long long newMinTotal = getMinMultilpleMoreThanOrEqual(minTotal, a[i]);
        long long newMaxTotal = getMaxMultilpleLessThanOrEqual(maxTotal, a[i]) + a[i] - 1;

        if (newMaxTotal < newMinTotal ||
            getMaxMultilpleLessThanOrEqual(newMinTotal, a[i]) < minTotal ||
            getMaxMultilpleLessThanOrEqual(newMaxTotal, a[i]) > maxTotal) {
            cout << "-1" << endl;
            return 0;
        }

        minTotal = newMinTotal;
        maxTotal = newMaxTotal;

    }

    cout << minTotal << " " << maxTotal << endl;
        
    return 0;
}


Measured memory_bytes: 1400
#include<iostream>
using namespace std;
int main()
{
	int n,m,count=0;
	int S[10005],s[505];
	
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>S[i];
	}
	cin>>m;
	for(int i=0;i<m;i++)
	{
		cin>>s[i];
	}
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(s[i]==S[j])
			{
				count++;
				break; 
			}
		}
	}
	cout<<count<<endl;
	return 0;
	
	
} 


Measured memory_bytes: 3140
#include<iostream>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define MOD 1000000007

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

	if (abs(N - M) >= 2) cout << 0 << endl;
	else {
		long long n = 1, m = 1;
		REP(i, 1, N + 1) {
			n *= i;
			n %= MOD;
		}

		REP(i, 1, M + 1) {
			m *= i;
			m %= MOD;
		}

		if (N == M) {
			cout << (2 * n*m) % MOD << endl;
		}
		else {
			cout << (n * m) % MOD << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N = int(readline().rstrip())
L = []
for _ in range(N):
    a, b, c = map(int, readline().split())
    L.append((a, b, c))


dp = [[0 for _ in range(3)] for _ in range(N)]
dp[0][0] = L[0][0]
dp[0][1] = L[0][1]
dp[0][2] = L[0][2]
for i in range(1, N):
    a, b, c = L[i]
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c

ans = max(dp[-1])
print(ans)

Measured memory_bytes: 41720
#include<bits/stdc++.h>
    using namespace std;
  #define int long long int
    #define endl "\n"
    #define MOD 1000000007
    #define mod 1000000007
    #define M 1000000007
    
    #define pb push_back
    #define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b]
  //  #define mp make_pair
  #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);  
  #define mx 400005
  #define fiint(a,b) memset(a,b,sizeof(a))  
  #define bitcount __builtin_popcount
  #define fori(i,a,b) for(int i=a;i<b;i++)
  #define ford(i,a,b) for(int i=a;i>=b;i--)
  #define debug(x) cout<<x<<endl;
  #define cases(t) int t; cin>>t; while(t--)
  #define inf1 INT_MAX
  #define all(a) a.begin(),a.end()
  #define vec vector<int>
  #define pii pair<int,int>
  #define plii pair<int,int>
  #define pint pair<int,int>
  #define ff first
  #define ss second
  #define lb lower_bound
  #define ub upper_bound
  #define bs binary_search
  #define sz(x) (int)x.size()
#define PI                    3.14159265359

bool prime[10000001];

void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}

signed  main() 
{ 
	int n,w;cin>>n>>w;
	vector <int>v[n+1];
	int a,b;
	fori(i,1,n+1)
	{cin>>a>>b;v[i].pb(a);v[i].pb(b);}
	vector<vector<int>> dp(n+1 , vector<int>(w+1) );
	fori(i,1,n+1)
		fori(j,1,w+1)
				if( v[i][0] <= j  )
					dp[i][j] = max (dp[i-1][j] , v[i][1] + dp[i-1][j - v[i][0]]   ); 
				else dp[i][j]= dp[i-1][j];
		cout<<dp[n][w]<<endl;	

	
		
	
}




 


Measured memory_bytes: 80256
#include <iostream>
using namespace std;
int n, d[51], ans;
int main()
{
    //入力
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
    }
    //処理
    for (int i = 0; i < n - 1; i++)
    {
        for (int f = i + 1; f < n; f++)
        {
            ans += d[i] * d[f];
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
n,m,c = map(int, input().split())
b = [int(x) for x in input().split()]
codes = []
for _ in range(n):
    codes.append(list(int(x) for x in input().split()))

ans = 0
for i in range(n):
    cnt = c
    for j in range(m):
        cnt += b[j] * codes[i][j]

    if cnt > 0:
        ans += 1
    else:
        continue

print(ans)

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

long long lowbit(long long i) {
    return i & -i;
}

long long get(vector<long long>& bit, long long index) {
    long long result = 0;
    while (index > 0) {
        result += bit[index];
        index -= lowbit(index);
    }
    return result;
}

void add(vector<long long>& bit, long long index, long long val) {
    while (index < bit.size()) {
        bit[index] += val;
        index += lowbit(index);
    }
}

int main() {
    long long n, k, result = 0;
    cin >> n >> k;
    vector<long long> bit(n + 2), a(n + 1), b(n + 1);
    for (long long i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1] - k;
        b[i] = a[i];
    }
    sort(begin(b), end(b));
    for (long long i = 0; i <= n; i++) {
        result += get(bit, distance(begin(b), upper_bound(begin(b), end(b), a[i])));
        add(bit, distance(begin(b), lower_bound(begin(b), end(b), a[i])) + 1, 1);
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 4992
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		String s = reader.next();
		int K = reader.nextInt();
		String ans = "";
		Set<String> set = new HashSet<String>();

		for (int i = 1; i <= K&&i <= s.length(); i++) {
			for (int j = 0; j <= s.length() - i; j++) {
				String sb = s.substring(j, j+i);
				set.add(sb);
			}
		}

		Set<String> sortedSet = new TreeSet<String>(set);

		Iterator<String> itr = sortedSet.iterator();
		int count = 0;
		while (count < K && itr.hasNext()) {
			ans = itr.next();
			count++;
		}

		System.out.print(ans);
		reader.close();
	}
}





Measured memory_bytes: 27100
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=200009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

int vis[M+4];
vector<int>adj[M+4];
 main()

{
    fast
    int n,m;
    cin>>n>>m;
    while(m--)
    {
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    queue<int>q;
    q.push(1);
    vis[1]=1;
    vector<int>ses[n+3];
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(auto v:adj[u])
        {
            if(vis[v]==0)
            {
                q.push(v);
                vis[v]=1;
                ses[v].pb(u);
            }
        }
    }
    f(i,2,n)
    {
        if(vis[i]==0)
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    for(int i=2;i<=n;i++)
    {
        cout<<ses[i][0]<<endl;
    }
    return 0;

}





































Measured memory_bytes: 20296
#
S=input()
Q=int(input())
Query=[]
for i in range(Q):
    Query.append(list(input().split()))

muki=0#0で正方向、１で負方向
ans_right=[]
ans_left=[]
for i in range(Q):
    if Query[i][0]=="1":
        if muki==0:
            muki=1
        elif muki==1:
            muki=0
    else:
        if muki==0:
            if Query[i][1]=="1":
                ans_left.append(Query[i][2])
                #先頭にQuery[i][2]を追加
            elif Query[i][1]=="2":
                ans_right.append(Query[i][2])
                #末尾にQuery[i][2]を追加
        elif muki==1:
            if Query[i][1]=="1":
                ans_right.append(Query[i][2])
                #末尾にQuery[i][2]を追加
            elif Query[i][1]=="2":
                ans_left.append(Query[i][2])
                #先頭にQuery[i][2]を追加
ans_left.reverse()

S=list(S)
ans=ans_left+S+ans_right

if muki==0:
    ans="".join(ans)
    print(ans)
else:
    ans.reverse()
    ans="".join(ans)
    print(ans)

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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()
#define pb push_back

typedef long long ll;
typedef long double ld;

using namespace std;

ll a, v, b, w, t;

ll ABS(ll x)
{
    if (x < 0)
        return -x;
    return x;
}

int main()
{
    cin >> a >> v >> b >> w >> t;
    if (t * (v - w) >= ABS(a - b))
        cout << "YES";
    else
        cout << "NO";
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;

ll a, b;

void input() {
    cin >> a >> b;
//    cout << s;
}

void solve() {
    ll sum = a + b;
    if ( sum % 2 == 0) {
        cout << sum / 2 << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}



int main() {
    input();
    solve();

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(){
  int n;cin>>n;
  long long a[n];
  for(int i = 0; n > i; i++){
    cin>>a[i];
  }
  long long b[n+1];
  b[0] = 0;
  for(int i = 1; n >= i; i++){
    b[i] = b[i-1]+a[i-1];
  }
  long long ans = b[n]-b[0];
  for(int i = 0; n >= i; i++){
    //cout << b[n] << " " << b[i] << endl;
    ans = min(ans,abs((b[n]-b[i])-b[i]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;

signed main(){
    int h,w,d;cin >> h >> w >> d;
    int a[h+1][w+1];
    vector<P> nums(h*w);
    rep(i,h)rep(j,w){
        cin >> a[i][j];
        a[i][j]--;
        nums[a[i][j]] = P(i,j);
    }
    int q;cin >> q;
    vector<int> ans;
    vector<int> sum(h*w+1,0);
    rep(i,h*w+1){
        if(i + d <= h*w)sum[i+d] = sum[i]+abs(nums[i].first - nums[i+d].first) + abs(nums[i].second - nums[i+d].second);
        //trace(i,sum[i]);
    }
    while(q--){
        int l,r;cin >> l >> r;
        int ret = 0;
        l--;r--;
        //for(;l != r;l+= d){
        //    auto from = nums[l],to = nums[l+d];
        //    int xf = from.first,yf = from.second;
        //    int xt = to.first,yt = to.second;
        //    //trace(xf,yf,xt,yt,from,to,ret);
        ret += sum[r] -sum[l];
        
        ans.push_back(ret);

    }
    for(auto s:ans)cout << s << endl;
    return 0;
}

Measured memory_bytes: 4852
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	ll ans = 0;
	int tmp;
	int x, y;
	cin >> x >> y;
	if (y % 2 == 0 && 2 * x <= y && y <= 4*x) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	//cout << ans << endl;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

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

    const int MAX_N = 1e5;
    int N, x, a[MAX_N];
    cin >> N >> x;
    REP(i, N) {
        cin >> a[i];
    }
    ll res = 0;
    if (x < a[0]) {
        res = a[0] - x;
        a[0] = x;
    }
    FOR(i, 1, N, 1) {
        if (a[i - 1] + a[i] > x) {
            int t = a[i];
            a[i] = max(x - a[i - 1], 0);
            res += t - a[i];
        }
    }
    cout << res << "\n";
    return 0;
}


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

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int N;
    int D;
    cin >> N >> D;
    int x[N][D];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j ++) {
            cin >> x[i][j];
        }
    }

    int cnt = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            int l2 = 0;
            for (int k = 0; k < D; k++) {
                l2 += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            double l = sqrt(l2);
            if( l == (int)l) {
                cnt ++;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define endl '\n'
//#define int long long



signed main() { //[J][O][L][S][K][E][Y]
        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        double n; cin >> n;
        n /= 3;
        cout << fixed << setprecision(6) << (n * n * n);
        return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n-- > 0) {
            boolean[] used = new boolean[14];
            boolean ans = false;
            for (int i = 0; i < 6; i++) {
                used[sc.nextInt()] = true;
            }
            if (used[1] == used[13])
                ans=!used[1];
            else {
                int l = 6, r = 8;
                boolean t=false;
                for (;;) {
                    if (t == used[1]) {
                        if (used[r]^t)
                            r++;
                        else if (used[l]^t)
                            l--;
                    } else  {
                        if (used[l]^t)
                            l--;
                        else if (used[r]^t)
                            r++;
                    }
                    if (r == 13) {
                        ans= !used[1];
                        break;
                    }
                    if (l == 1) {
                        ans=  used[1];
                        break;
                    }
                    t = !t;
                }
            }
            System.out.println(ans ? "yes" : "no");
        }
    }
}


Measured memory_bytes: 28200
use whiteread::parse_line;

fn calc(n: usize, p: &mut Vec<usize>, qhsd: [usize; 4]) -> usize {
    if p[n] == std::usize::MAX {
        let mut res = std::usize::MAX;
        if 2 <= n && n <= 4 {
            res = res.min(calc(n - 1, p, qhsd) + qhsd[0]);
            res = res.min(calc(n - 2, p, qhsd) + qhsd[1]);
        }
        if n >= 4 {
            res = res.min(calc(n - 4, p, qhsd) + qhsd[2]);
        }
        if n >= 8 {
            res = res.min(calc(n - 8, p, qhsd) + qhsd[3]);
        }
        p[n] = res;
    }
    p[n]
}

fn main() {
    let (q, h, s, d): (usize, usize, usize, usize) = parse_line().unwrap();
    let n: usize = parse_line().unwrap();
    let mut p: Vec<usize> = vec![std::usize::MAX; 10];
    p[0] = 0;
    p[1] = q;
    let ans;

    let calc4 = calc(4, &mut p, [q, h, s, d]);
    let calc8 = calc(8, &mut p, [q, h, s, d]);
    if 2 * calc4 < calc8 {
        ans = n * calc4;
    } else {
        ans = n / 2 * calc8 + n % 2 * calc4;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2180
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        int d = scanner.nextInt();
        int n = scanner.nextInt();
        int result = 0;
        if (d == 0) {
            for (int i = 0; i < n; i++) {
                result += 1;
                if(result%100==0){
                    result += 1;
                }
            }

        } else if (d == 1) {
            for (int i = 0; i < n; i++) {
                result += 100;
                if(result%10000==0){
                    result += 100;
                }
            }

        } else if (d == 2) {
            for (int i = 0; i < n; i++) {
                result += 10000;
                if(result%1000000==0){
                    result += 10000;
                }
            }


        }
        System.out.println(result);
    }
}

Measured memory_bytes: 23636
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
dist = []
for i in range(m - 1):
  dist.append(x[i + 1] - x[i])
dist.sort()
if (n > m):
  print(0)
else:
  print(sum(dist[:m - n]))

Measured memory_bytes: 13968
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    long n,ans=1000,a;
    char s[11];
    scanf("%s",s);
    n=strlen(s);
    for(int i=0;i+2<n;i++){
        a=0;
        for(int j=0;j<3;j++){
            a*=10;
            a+=s[j+i]-'0';
        }
        //printf("%d\n",a);
        ans=min(ans,abs(a-753));
    }
    printf("%d\n",ans);
}

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

long long N;
vector<long long> X;
vector<vector<long long> > V;

pair<long long, long long> DFS(long long P) {
	vector<pair<long long, long long> > VP;
	for (long long NP : V[P]) {
		pair<long long, long long> Q = DFS(NP);
		if (Q.first == -1 && Q.second == -1) return { -1, -1 };
		VP.push_back(Q);
	}
	long long COUNT = 0;
	bitset<5010> BS;
	BS[0] = 1;
	for (pair<long long, long long> Q : VP) {
		BS = (BS << Q.first) | (BS << Q.second);
		COUNT += Q.first + Q.second;
	}
	long long MAX = -1;
	for (int i = 0; i <= X[P]; i++) if (BS[i]) MAX = i;
	if (MAX == -1) return { -1, -1 };
	return { X[P], COUNT - MAX };
}

int main() {
	cin >> N;
	V.resize(N);
	X.resize(N);
	for (int i = 1; i < N; i++) {
		long long P;
		cin >> P;
		P--;
		V[P].push_back(i);
	}
	for (int i = 0; i < N; i++) cin >> X[i];
	pair<long long, long long> ANS = DFS(0);
	if (ANS.first == -1 && ANS.second == -1) cout << "IMPOSSIBLE" << endl;
	else cout << "POSSIBLE" << endl;
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n),b(n),c(n);

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

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

	int sum=0;
	map<int,int> mc;
	const int max_size=1000000000+1;
	mc[max_size]=0;
	for (auto it=c.rbegin();it!=c.rend();++it)
	{
		++sum;
		mc[*it]=sum;
	}

	map<int,int64_t> mb;
	int64_t count=0;
	mb[max_size]=0;
	for (auto it=b.rbegin();it!=b.rend();++it)
	{
		count+=(mc.upper_bound(*it))->second;
		mb[*it]=count;
	}

	count=0;
	for (int i=0;i<n;++i)
	{
		count+=(mb.upper_bound(a[i]))->second;
	}
	cout << count << endl;
}







Measured memory_bytes: 15404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR (a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] "
template <typename T>
struct IsC {
  template <typename C>
  static char test(typename C::const_iterator*);
  template <typename C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream&, const C&);
template <typename T1, typename T2>
ostream& operator<<(ostream&, const pair<T1, T2>&);
template <typename... T> using TS = tuple_size<tuple<T...>>;
template<size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return o << ", " << get<idx>(t) << ')';
}
template<size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << ", " << get<idx>(t), t);
}
template<size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << '(' << get<idx>(t), t);
}
template<typename T>
ostream& operator<<(ostream& o, const tuple<T>& t) {
  return o << get<0>(t);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p) {
  return o << mt(p.fi, p.se);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(
    ostream& o, const C& c) {
  o << '[';
  for (auto it = c.cbegin(); it != c.cend(); ++it)
    o << *it << (next(it) != c.cend() ? ", " : "");
  return o << ']';
}
template <typename T>
void tprint(vector<vector<T>>& v, size_t width = 0, ostream& o = cerr) {
  if (!DEBUG) return;
  for (const auto& vv : v) {
    for (const auto& i : vv) o << setw(width) << i;
    o << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0); cin.tie(0);

  int x; cin >> x;
  int ans = 8;
  for (int i = 600; i <= 1800; i += 200) {
    if (x >= i) --ans;
  }

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


Measured memory_bytes: 3648
n, a, b = map(int, input().split())
i_sum_sum = 0

def disassemble(i):
    ilist = []
    while i > 0:
        ilist.append(i%10)
        i //= 10
    ilist.reverse()
    i_sum = sum(ilist)
    return(i_sum)

for i in range(1, n+1):
    i_sum = disassemble(i)
    if a <= i_sum <= b:
        i_sum_sum += i

print(i_sum_sum)


Measured memory_bytes: 3060
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
};

/** Problem1192 : Tax Rate Changed **/
int main()
{
	int x, y, s;
	while (cin>>x>>y>>s, x||y||s) {
		int ans=0;
		for (int i=1; i<=s; i++) {
			for (int j=1; j<=s; j++) {
				if (i*(100+x)/100 + j*(100+x)/100 == s) {
					ans = max(ans, i*(100+y)/100 + j*(100+y)/100);
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
#include <iostream>
#include <vector>
using namespace std;

int n,m;
int a[2005][2005],b[2005][2005],ans;
char c;
vector <int> num[2005],lie[2005];

int main(void){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++){
		a[i][0]=-1;
		num[i].push_back(0);
		a[i][m+1]=-1;
		for(int j=1;j<=m;j++){
			cin>>c;
			if(c=='.')a[i][j]=0;
			if(c=='#')
			a[i][j]=-1,num[i].push_back(j);
		}
		num[i].push_back(m+1);
	}
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	b[i][j]=a[i][j];
	for(int i=1;i<=n;i++){
		for(int j=0;j<num[i].size();j++){
			int s=0;
			for(int k=num[i][j]+1;a[i][k]==0&&k<=m;k++)
			s++;
			for(int k=num[i][j]+1;a[i][k]==0&&k<=m;k++)
			a[i][k]=s;
		}
	}
	for(int i=1;i<=m;i++){
		b[0][i]=-1;
		lie[i].push_back(0);
		b[n+1][i]=-1;
		for(int j=1;j<=n;j++)
		if(b[j][i]==-1)
		lie[i].push_back(j);
		lie[i].push_back(n+1);
	}
	for(int i=1;i<=m;i++){
		for(int j=0;j<lie[i].size();j++){
			int s=0;
			for(int k=lie[i][j]+1;b[k][i]==0&&k<=n;k++)
			s++;
			for(int k=lie[i][j]+1;b[k][i]==0&&k<=n;k++)
			b[k][i]=s;
		}
	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=m;j++)
//		printf("%d ",b[i][j]);
//		printf("\n");
//	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
		ans=max(ans,a[i][j]+b[i][j]-1);
	}
	printf("%d",ans);
}


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

using ll=long long;

int main() {
  int i,N,M,x;
  ll s=0;
  cin >> N >> M;
  priority_queue<int> A;
  for(i=0; i<N; i++) {
    cin >> x;
    A.push(x);
  }
  for(i=0; i<M; i++) {
    int mn = A.top();
    A.pop();
    A.push(mn/2);
  }
  while(!A.empty()) {
    s += A.top();
    A.pop();
  }
  cout << s << endl;
}


Measured memory_bytes: 1020
# from sys import exit

alp = ['a', 'b', 'c', 'd', 'e', 'f', 'g',
        'h', 'i', 'j', 'k', 'l', 'm', 'n',
         'o', 'p', 'q', 'r', 's', 't', 'u',
          'v', 'w', 'x', 'y', 'z']
alp += [a.upper() for a in alp]
id = [i for i in range(0, 52)]
alp2num = dict(zip(alp, id))
num2alp = dict(enumerate(alp))
while(True):
    N = int(input())
    if N == 0:
        exit()
    k = [int(n) for n in input().split()]
    S = input()
    L = len(S)
    for i in range(L):
        id = alp2num[S[i]]-k[i % N] % 52
        if id < 0:
            id += 52
        print(num2alp[id], end="")
    print()



Measured memory_bytes: 5632
import math
A,B,X=map(int, input().split())
C=2*X/(A*B)
if C<=A:
    math.atan(B/C)*(180)/math.pi
    C=2*X/(A*B)
    print(math.atan(B/C)*(180)/math.pi)
else:
    Y=A*A*B-X
    C=2*Y/(A*A)
    
    C=2*Y/(A*A)
    print(math.atan(C/A)*(180)/math.pi)
    

Measured memory_bytes: 3060
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in); 
		//input integer
		int H1 = sc.nextInt();
		//input integer divided by a space
		int M1 = sc.nextInt();
		int H2 = sc.nextInt();
		int M2 = sc.nextInt();
		int K = sc.nextInt();
		int totalAwake = (H2-H1)*60+(M2-M1);
		int study = totalAwake - K;
		//output
		System.out.println(study);
		sc.close();
	}

}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  map<char, int> mp;
  int n = int(s.size());
  if(n == 1){
    cout << "YES" << endl;
    return 0;
  }

  for(char c : s){
    mp[c]++;
  }
  if(mp.size() == 2 && n != 2){
    cout << "NO" << endl;
    return 0;
  }
  if(mp.size() == 1){
    cout << "NO" << endl;
    return 0;
  }

  int maxv = -1;
  int next = -1;

  for(auto a : mp){
    if(a.second >= maxv){
      maxv = a.second;
    }
  }
  for(auto a : mp){
    if(a.second >= next && a.second < maxv){
      next = a.second;
    }
  }
  int count = n - next - maxv;

  maxv -= count;
  next -= count;
  if(maxv >= 3){
    cout << "NO" << endl;
  }else if(next >= 2 || maxv >= 2){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
}


Measured memory_bytes: 512
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

n = int(input())
ans = num2alpha(n).lower()
print(ans)

Measured memory_bytes: 9180
#include "cstdio"
using namespace std;
int main()
{
	int i,a,b,c=0;
	scanf("%d",&a);
	b=a;
	while(a!=0)
	{
		c+=a%10;
		a/=10;
	}
	if(b%c==0)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"sort"
)

func main() {
	v := make([]int, 3)
	for i := range v {
		fmt.Scan(&v[i])
	}
	sort.Ints(v)
	if v[0]+v[1] == v[2] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

using namespace std;
typedef long long ll;
int main()
{
    int arr[60001]={0};
    int num;
    for(int x =1 ; x <=100 ; x++)
    {
        for(int y=1; y<=100;y++)
        {
            for(int z=1; z<=100 ;z++)
            {
                num=(x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(x*z) ;
                arr[num]++;
            }
        }
    }
    int n ;
    cin >> n;
    for(int i=1 ; i <=n ; i++)
    {
        cout << arr[i] << "\n";
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> X(N), v(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    v[i] = X[i];
  }

  sort(v.begin(), v.end());
  int median1 = v[N / 2 - 1];
  int median2 = v[N / 2];

  for (int i = 0; i < N; i++) {
    if (X[i] <= median1) {
      cout << median2 << endl;
    } else {
      cout << median1 << endl;
    }
  }
}

Measured memory_bytes: 3712
#include <iostream>
#include <cmath>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;

int main()
{
    long double a, b, x;
    cin >> a >> b >> x;
    const long double pi = acos(-1);
    long double rad;

    if (x < a * a * b / 2.0)
    {
        rad = atan(x * 2.0 / (a * b * b));
        rad = (pi / 2.0 - rad);
    }
    else
    {
        rad = atan(2 * (a * a * b - x) / (a * a * a));
    }

    cout << std::setprecision(10) << rad * 180.0 / pi << endl;

    return 0;
}

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

int main(){
    int n;
    cin>>n;
    int S=0;
    
    vector<int> res;
    for(int i=1;i<=n;i++){
        S+=i;
        if(S>=n){
            for(int j=i;j>=1;j--){
                if(n>=j){
                    n-=j;
                    res.push_back(j);
                }
            }
        }
    }
    sort(res.begin(),res.end());
    
    for(int i=0;i<res.size();i++){
        cout<<res[i]<<endl;
    }
}

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

using namespace std;

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

    int num;
    vector<int> H;
    for(int i=0;i<N;i++){
        cin >> num;
        H.push_back(num);
    }

    vector<int> dp(N,0);

    dp[0]=0;
    dp[1]=abs(H[1]-H[0]);

    for(int i=2;i<N;i++){
        dp[i] = min(dp[i-1] + abs(H[i]-H[i-1]),dp[i-2] + abs(H[i]-H[i-2]));
    }

    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1144
#include <stdio.h>
#include <stdlib.h>


int main(void){
  long N,ans = 0;
  scanf("%ld",&N);
  long a,A[100002];
  long count;

  for(int i = 0;i < 100002;i++) A[i] = 0;
  for(int i = 0;i < N;i++){
    scanf("%ld",&a);
    A[a]++;
  }

  for(int i = 1;i < 100001;i++){
    count = A[i-1]+A[i]+A[i+1];
    if(ans < count) ans = count;
  }
  printf("%ld\n",ans);
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n;
    cin >> n;
    vector<vector<ll>> g(n+1);
    map<p, ll> I{};
    for(ll i = 0; i < n-1; i++){
        ll a, b, c;
        cin >> a >> b >> c;
        g[a].push_back(b);
        g[b].push_back(a);
        I[p(a,b)] = c; I[p(b,a)] = c;
    }
    ll q, k;
    cin >> q >> k;
    vector<p> vp;
    for(ll i = 0; i < q; i++){
        ll a, b;
        cin >> a >> b;
        vp.push_back(p(a, b));
    }
    vector<ll> dist(n+1, -1);
    queue<ll> que;
    dist[k] = 0;
    que.push(k);
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(ll nv : g[v]){
            if(dist[nv]!=-1) continue;
            dist[nv] = dist[v]+I[p(v, nv)];
            que.push(nv);
        }
    }
    for(ll i = 0; i < q; i++){
        ll a = vp[i].first, b = vp[i].second;
        cout << dist[a]+dist[b] << endl;
    }
    return 0;
}


Measured memory_bytes: 24432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int N,M;
  cin >> N >> M;
  priority_queue<pair<int,int>> q;

  for(int i = 0;i < N;i++){
    int A;
    cin >> A;
    q.push(make_pair(A,1));
  }

  for(int i = 0;i < M;i++){
    int B,C;
    cin >> B >> C;
    q.push(make_pair(C,B));
  }

  ll ans = 0;
  for(int i = 0;i < N;i++){
    auto p = q.top();
    q.pop();

    ans += p.first;
    if(p.second > 1){
      p.second--;
      q.push(p);
    }
  }

  cout << ans << endl;
}


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

int main() {
	ll n,m,p;
	cin>>n>>m>>p;
	ll s[5005],e[5005],c[5005];
	ll ans[2510];
	for(ll i=0;i<m;i++){
		cin>>s[i]>>e[i]>>c[i];
		s[i]--;e[i]--;c[i]-=p;
		c[i]*=-1;
	}
	for(ll i=0;i<n;i++){
		ans[i]=INF;
	}
	ans[0]=0;
	for(ll i=0;i<n;i++){
		for(ll j=0;j<m;j++){
			ll now=s[j];
			ll nex=e[j];
			if(ans[nex]>ans[now]+c[j]){
				ans[nex]=ans[now]+c[j];
			}
		}
	}
	ll ans2[2510];
	bool hu[2510],sto[2510],eto[2510];
	for(ll i=0;i<n;i++){
		ans2[i]=ans[i];
		hu[i]=sto[2510]=eto[2510]=false;
	}
	sto[0]=eto[n-1]=true;
	for(ll i=0;i<n;i++){
		for(ll j=0;j<m;j++){
			ll now=s[j];
			ll nex=e[j];
			if(ans[nex]>ans[now]+c[j]){
				ans[nex]=ans[now]+c[j];
			}
			if(sto[now]==true){
				sto[nex]=true;
			}
			if(eto[nex]==true){
				eto[now]=true;
			}
		}
	}
	for(ll i=0;i<n;i++){
		if(ans[i]<ans2[i]&&eto[i]&&sto[i]){
			cout<< -1;
			return 0;
		}
	}
	if(ans[n-1]>0){
		cout <<0;
	}else{
	cout <<abs(ans[n-1]);
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3804
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int A,B;
int main() {
	cin>>A>>B;
	char S[11];
	int ans=0;
	for(int i=0;i<A+B+1;i++){
		cin>>S[i];
		if(i==A){
			if(S[i]=='-'){
				ans++;
			}
		}else{
			if(S[i]!='-'){
				ans++;
			}
		}
	}
	if(ans==A+B+1)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,d[100000];
	cin>>n;
	for(int i=0;i<n;i++)
	  d[i]=1;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		d[upper_bound(d,d+n,-a)-d]=-a;
	}
	cout<<lower_bound(d,d+n,1)-d<<endl;
	return 0;
}

Measured memory_bytes: 768
# -*- coding: utf-8 -*-
mod = 10**9 + 7

n, m = map(int, raw_input().split())
x = map(int, raw_input().split())
y = map(int, raw_input().split())

sx = sum(x)
sy = sum(y)
zx = 0
zy = 0
for i, xi in enumerate(x):
    zx += sx - (n - i)*xi
    sx -= xi
    zx = (zx + mod) % mod
for i, yi in enumerate(y):
    zy += sy - (m - i)*yi
    sy -= yi
    zy = (zy + mod) % mod

print zx*zy%mod


Measured memory_bytes: 14496
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
	t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
	l, r = map(int, input().split())
	print(t[r-1] - t[l-1])


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

int gcd(int x,int y)
{
  int ret=1;
  for(int i=2;i<=min(x,y);i++)if(x%i==0&&y%i==0)ret=i;
  return ret;
}

int main()
{
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  int g=gcd(A,B);
  if(C%g==0)printf("YES\n");
  else printf("NO\n");
  return 0;
}

Measured memory_bytes: 3652