akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Vector;

public class Main {

    public static void main(String[] args) throws IOException {
        Vector<Integer> vec=new Vector<>();
        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int q=Integer.parseInt(br.readLine());
        for(int i=0;i<q;i++){
            StringTokenizer st=new StringTokenizer(br.readLine());
            int a=Integer.parseInt(st.nextToken());
            if(a==2)vec.remove(vec.size()-1);
            else{
                int b=Integer.parseInt(st.nextToken());
                if(a==0)vec.add(b);
                else out.println(vec.get(b));
            }
        }
        out.flush();
    }
}


Measured memory_bytes: 66436
#include <bits/stdc++.h> 
using namespace std; 
const int MAX_CHAR = 26; 
  
// function to store frequency of 
// each character in each string 
void frequency(int fre[][MAX_CHAR], string s[], int n) 
{ 
    for (int i = 0; i < n; i++) { 
        string str = s[i]; 
        for (int j = 0; j < str.size(); j++)  
            fre[i][str[j] - 'a']++;         
    } 
} 
  
// function to Find longest possible sequence of N 
// strings which is anagram to each other 
void LongestSequence(int fre[][MAX_CHAR], int n) 
{ 
	string out;
    // to get lexicographical largest sequence. 
    for (int i = MAX_CHAR-1; i >= 0; i--) { 
  
        // find minimum of that character 
        int mi = fre[0][i]; 
        for (int j = 1; j < n; j++)  
            mi = min(fre[j][i], mi);         
  
        // print that character 
        // minimum number of times 
        
        while (mi--)  
            out+=(char)('a' + i);         
    }
    if(out.size()!=0)
    {
    	sort(out.begin(),out.end());
    	cout << out << endl;
    } 
} 
  
// Driver code 
int main() 
{ 
  	int n;
  	cin>> n;
  	string s[n];
    for(int i = 0;i<n;i++)
    {
    	cin >> s[i];
    }
  	
    // to strore frequency of each character in each string 
    int fre[n][26] = { 0 }; 
  
    // to get frequency of each character 
    frequency(fre, s, n); 
  
    // function call 
    LongestSequence(fre, n); 
  
    return 0; 
} 

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

int main(){
    int N,M,ai,bi;
	cin>>N>>M;
    vector<int> vec(N+1);
 
    //入力
    for (int i=1; i<=M; i++){
        cin >> ai >> bi;
        vec.at(ai)++;
        vec.at(bi)++;
    }
    
    for (int i=1; i<=N; i++){
        cout<< vec.at(i) <<endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> plli;
typedef vector< vi > vvi ;
typedef vector< vlli > vvlli  ;
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define flli(i,a,b) for(long long int i=a;i<=b;i++)
#define bi(i,a,b) for(int i=a;i>=b;i--)
#define blli(i,a,b) for(long long int i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pi 2*acos(0.0)
#define pb push_back
#define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
#define present(v,num) (v.find(num)!=v.end())
#define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
#define pq priority_queue
#define mp make_pair
const int inf=INT_MAX;
const lli INF =LLONG_MAX;
const lli mod = 1e9+7;
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast;
    lli d,t,s;cin>>d>>t>>s;
    lli maxi=t*s;
    if(maxi<d)cout<<"No";
    else cout<<"Yes";
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

using namespace std;

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    string x;
    cin >> x;

    bool ok = true;
    for(int i=0;i<3;++i)
        if(x[i] == x[i+1])
            ok = false;
    
    if(ok) cout << "Good\n";
    else cout << "Bad\n";

    return 0;
}

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

using namespace std;

int main() 
{
	string x;
	cin>>x;
	
	int sum=0;
	for(int i=0;i<x.length();i++){
		sum+=x[i]-48;
	}
	
	if(sum%9==0){
		cout<<"Yes";
	} else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;

#define INF 0x3f3f3f3f

int main() {
  int H,W; cin>>H>>W;
  vector<string> S(H+2);
  for (int i=0;i<H+2;i++) {
    if (i==0 || i==H+1) {
      for (int j=0;j<H+2;j++) {
        S[i]+=".";
      }
    } else {
      string s; cin>>s;
      S[i]="."+s+"."; 
    }
  }

  bool can=true;
  for (int i=1;i<H+1;i++) {
    for (int j=1;j<W+1;j++) {
      if (S[i][j]=='#') {
        if (S[i-1][j]!='#' && S[i+1][j]!='#' && S[i][j-1]!='#' && S[i][j+1]!='#') {
          can=false;
          break;
        }
      }
    }
    if(!can) break;
  }
  cout<<(can?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//こんなクソコードを生み出してしまうなんて趣味は罪ね

const int mod = 1e9 + 7;
const int IMAX = 200000;
class unko {
public:
	int f[IMAX + 1];
	constexpr unko() : f() {
		f[0] = 1;
		rep1(i, IMAX) f[i] = ll(f[i - 1]) * 2 % mod;
	}
} f;

const ull ma = (1ull << 52) - 1;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N;
	cin >> N;
	ull AB[200001];
	int a0 = 0, b0 = 0;
	int ab00 = 0;
	int n = 0;
	rep(i, N) {
		ll a, b;
		cin >> a >> b;

		if (a == 0 && b == 0) {
			ab00++;
			continue;
		}
		if (a == 0) {
			a0++;
			continue;
		}
		if (b == 0) {
			b0++;
			continue;
		}

		if (a < 0) {
			a = -a;
			b = -b;
		}
		bool p = (b > 0);
		if (!p) {
			b = -b;
			swap(a, b);
		}

		ull tmp = 0;
		rep(i, 3) {
			tmp *= 3;
			if (b) {
				int k = __builtin_clzll(a) - __builtin_clzll(b);
				if (k > 0) a <<= k;
				else b <<= -k;
				if (a > b) {
					b <<= 1;
					k--;
				}
				double d = double(b) / a;
				ull tmp1 = *(ull*)& d;
				ull c = tmp1 & ma | (1ull << 52);
				lll sa = (lll(b) << 52) - lll(a) * c;
				while (sa >= 0) {
					sa -= a;
					c++;
				}
				while (sa < 0) {
					sa += a;
					c--;
				}
				tmp += ull(k + 63) << 53 | c;
				b = sa;
			}
		}

		if (p) AB[n++] = tmp << 1 | 1ull;
		else AB[n++] = tmp << 1;
	}
	sort(AB, AB + n);

	ll kotae = 1;
	ull mae = AB[0] >> 1;
	int k1 = 0, k2 = 0;
	rep(i, n) {
		if (mae != AB[i] >> 1) {
			kotae = kotae * (f.f[k1] + f.f[k2] - 1) % mod;
			k1 = 0;
			k2 = 0;
			mae = AB[i] >> 1;
		}
		if (AB[i] & 1ull) k1++;
		else k2++;
	}
	kotae = kotae * (f.f[k1] + f.f[k2] - 1) % mod;

	kotae = kotae * (f.f[a0] + f.f[b0] - 1) % mod;

	printf("%lld\n", (kotae - 1 + ab00 + mod) % mod);

	Would you please return 0;
}

Measured memory_bytes: 5316
n, k = map(int, input().split())
pis = list(map(int, input().split()))
sum_max = 0
sum_cd = 0
for i in range(k):
  sum_max += pis[i]
  sum_cd += pis[i]
for j in range(1,n-k+1):
  sum_cd -= pis[j-1]
  sum_cd += pis[j+k-1] 
  if sum_cd > sum_max:
    sum_max = sum_cd
expect = sum_max/2 + k / 2
print(expect)

Measured memory_bytes: 25060
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(fabs(a-b)>fabs(a-c))
        printf("B");
    else
        printf("A");
}

Measured memory_bytes: 128
Ans = "ABC"
Turn = 0
lis = list()
for i in range(3):
    lis.append(input())
while len(lis[Turn]):
    Tmp = ord(lis[Turn][0]) - ord("a")
    lis[Turn] = lis[Turn][1:len(lis[Turn])]
    Turn = Tmp
print(Ans[Turn])


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int R, G;
	cin >> R >> G;
	cout << G * 2 - R << endl;
}

Measured memory_bytes: 256
#include<map>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

struct UnionFind {
    int n;
    vector<int> U;
    UnionFind() {}
    UnionFind(int n_): n(n_), U(n, -1) {}
    int root(int x) {
	if (U[x] < 0) return x;
	return U[x] = root(U[x]);
    }
    int link(int x, int y) {
	x = root(x); y = root(y);
	if (x == y) return x;
	if (U[y] < U[x]) swap(x, y);
	U[x] += U[y];
	n--;
	return U[y] = x;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size() { return n; }
    int count(int x) { return -U[root(x)]; }
};


int N, K, L;
int A[200111];
VI G[200111];

int main() {
    scanf("%d%d%d", &N, &K, &L);
    UnionFind U(N), V(N);
    REP (i, K) {
	int x, y;
	scanf("%d%d", &x, &y);
	x--; y--;
	U.link(x, y);
    }
    REP (i, L) {
	int x, y;
	scanf("%d%d", &x, &y);
	x--; y--;
	V.link(x, y);
    }

    REP (i, N) G[U.root(i)].push_back(i);
    REP (i, N) {
	map<int, VI> mp;
	EACH (e, G[i]) mp[V.root(*e)].push_back(*e);
	EACH (e, mp) EACH (f, e->second) A[*f] = e->second.size();
    }

    rprintf("%d", A, A+N);

    return 0;
}



Measured memory_bytes: 17144
#include <iostream>

int main(int argc, char *argv[])
{
    int x, y;
    int ans = 0;

    std::cin >> x >> y;

    if (x == 3) {ans += 100000;}
    if (x == 2) {ans += 200000;}
    if (x == 1) {ans += 300000;}

    if (y == 3) {ans += 100000;}
    if (y == 2) {ans += 200000;}
    if (y == 1) {ans += 300000;}

    if (x == 1 && y == 1) {ans += 400000;}

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

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<functional>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main() {
	int A, B,C,K;
	cin >> A >> B>>C;
	cin >> K;

	int Y = 0;

	for (int i = 0; i <= K; i++) {
		for (int m = 0; m <= K-i; m++) {

			int R =(( pow(2, i)*A) +( pow(2, m)*B) +( pow(2, K - m - i)*C));

			if (Y < R) {
				Y = R;
			}
		}
	}

	cout << Y << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
#define MOD 1e9 + 7
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(c,a,b) for(ll c=a;c<b;c++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
	IOS
	ll n,m,a,b;
	
	ll i,j,cnt1,cnt;
	cin>>n>>m>>a>>b;
  ll x[n],y[m];
	for(i=0;i<n;i++)
		cin>>x[i];
	rep(i,0,m)
	{
		cin>>y[i];
	}
	for(j=a+1;j<=b;j++)
	{
		cnt=0;
		cnt1=0;
		rep(i,0,n)
		{
			if(x[i]<j)
				cnt++;
		}
		rep(i,0,m)
		{
			if(y[i]>=j)
				cnt1++;
		}
		if(cnt==n and cnt1==m)
		{
			return cout<<"No War",0;
		}
	}
	cout<<"War";
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a = scan.nextInt();
        int b = scan.nextInt();
        int h = scan.nextInt();
        System.out.println((a+b)*h/2);
    }
}


Measured memory_bytes: 21972
#include <iostream>
using namespace std;
int main()
{
	 int x , y , z ;
	 cin>>x>>y>>z ;
	 if (x==y && x!=z)
		 cout<<z ;
	 else if (x==z && z!=y) 
		 cout<<y ;
	 else if (y==z && y!=x) 
		 cout<<x ;
	 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, k;
  cin >> n >> k;
  cout << n - k + 1 << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

N, A, B = inpl()
D = A-B
H = []
res = 0
for _ in range(N):
    H.append(int(input()))

H = sorted(H)
l = sum(H) // (A+B*(N-1))
r = sum([h//A + (h%A>0) for h in H])

def judge(m):
    nH = [h - B*m for h in H]
    if sum([h//D + (h%D>0) for h in nH if h > 0]) <= m:
        return True
    else:
        return False

while r-l > 1:
    mid = (l+r)//2
    if judge(mid):
        r = mid
    else:
        l = mid
if judge(l):
    print(l)
else:
    print(r)

Measured memory_bytes: 14876
N = int(input())
d = list(map(int, input().split()))

result = 0
# 最後尾はもう全部計算されてるから除外
for i in range(N - 1):
  # i=1個目の時2と3の2パターンをかける
    for j in range(i + 1, N):
        result += d[i] * d[j]
print(result)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    cout << ((n - m) * 100 + 1900 * m) * (1 << m) << endl;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
const ll INF = 1<<30;

int main(){
    ll N; cin >> N;
    vector<ll> A(N+1),B(N+1);
    rep(i,N){
        ll a; cin >> a;
        B[a-1] = i+1;
    }
    rep(i,N) cout << B[i] << " ";
}

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

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORTASC(c) sort((c).begin(), (c).end())
#define SORTDESC(c, t) sort((c).begin(), (c).end(), std::greater<t>());
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

const double PI = acos(-1.0);

using ll = long long;
using namespace std;

int main()
{
    ll n;
    string s;

    cin >> n >> s;

    string t;
    FOR(i, 0, n/2){
        t += s[i];
    }

    if (t + t == s){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 100005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
     ll n,m;
     cin >> n >> m;
     ll ans = n*(n-1)/2;
     ans += m*(m-1)/2;
     cout<<ans;    
}

int main()
{
     FAST;
     ll t = 1;
   //  cin >> t;
     while(t--)
     {
          solve();
     }
}

Measured memory_bytes: 256
import bisect

N=int(input())
L=list(map(int,input().split()))

L=sorted(L)

ans=0
for i in range(N-1):
    for k in range(i+1,N-1):
        a=L[i]+L[k]
        b=bisect.bisect_left(L,a)
        ans=ans+(b-k-1)

print(ans)

Measured memory_bytes: 68508
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

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

    vvl dp(n+10, vl(3));  // dp[i][j] : i文字目までで最後の分割の文字数がjのときの分割個数の最大値
    dp[1][1] = 1;
    exrep(i, 1, n) {  // i文字目まで分割したとする
        exrep(j, 1, 2) {  // 最後の分割はj文字とする
            exrep(k, 1, 2) {  // 次の分割はk文字にする
                bool ok = true;  // 次の分割が可能ならtrue
                if(j == k) {
                    if(j == 1 && s[i-1] == s[i]) {
                        ok = false;
                    }
                    if(j == 2 && 2 <= i && i < n-1 && s[i-2] == s[i] && s[i-1] == s[i+1]) {
                            ok = false;
                    }
                }
                if(ok) {
                    chmax(dp[i+k][k], dp[i][j] + 1);        
                }
            }
        }
    }

    out(max(dp[n][1], dp[n][2]));
    re0;
}

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

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

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

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

    N %= K;
    cout << min(N, abs(N - K)) << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func count(a, b []string) (count int) {
	mapA := make(map[string]bool)
	for _, v := range a {
		mapA[v] = true
	}
	mapB := make(map[string]bool)
	for _, v := range b {
		mapB[v] = true
	}
	for k := range mapA {
		if _, ok := mapB[k]; ok {
			count++
		}
	}
	return count
}

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	a := strings.Split(s, "")
	max := 0
	for i := range a {
		first := a[:i]
		second := a[i:]
		c := count(first, second)
		if c > max {
			max = c
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  double t=acos(-1)*(11.0*m-60.0*h)/360.0;
  double L=sqrt(a*a+b*b-2*a*b*cos(t));
  cout<<fixed<<setprecision(11)<<L<<endl;
}
 

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

int N, A[10010];

long long int max(){
    long long int max = A[0];
    for (int i = 1; i < N; i++){
        if (A[i] > max){
            max = A[i];
        }
    }
    return max;
}

long long int sum(){
    long long int sum = 0;
    for (int i = 0; i < N; i++){
        sum += A[i];
    }
    return sum;
}

long long int min(){
    long long int min = A[0];
    for (int i = 1; i < N; i++){
        if (A[i] < min){
            min = A[i];
        }
    }
    return min;
}

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    cout << min() << ' ' << max() << ' ' << sum() << endl;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	int ans=0;
	cin >>n;
	VPi a(100010,mp(0,0)) , b(100010,mp(0,0));
	rep(i,100002){
		a[i].S = i;
		b[i].S = i;
	}
	int bef;
	rep(i,n){
		cin>>bef;
		
		if(i%2){
		a[bef].F++;
		}else{
			b[bef].F++;
		}
	}
	sort(all(a),greater<P>());
	sort(all(b),greater<P>());
	if(a[0].S != b[0].S){
		ans=n-a[0].F-b[0].F;
	}else{
		ans=n+min(-a[0].F-b[1].F,-a[1].F-b[0].F);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 60; int n, k;
const double eps = 1e-7;

struct Point
{
  double x, y;
  Point operator+(const Point &other) { return Point{x + other.x, y + other.y}; }
  Point operator-(const Point &other) { return Point{x - other.x, y - other.y}; }
  Point operator*(const double a) { return Point{x * a, y * a}; }
  double operator*(const Point &other) { return x * other.x + y * other.y; }
  double distance(Point &other) { return sqrt((x - other.x)*(x - other.x) + (y - other.y)*(y - other.y)); }
  double cross(Point &other) { return x*other.y - y*other.x; }
  Point rotate(double rad) { return Point{x * cos(rad) - y * sin(rad), x * sin(rad) + y * cos(rad)}; }
  Point normalized()
  {
    double norm = sqrt(x*x + y*y);
    return Point{x / norm, y / norm};
  }
  void read() { scanf("%lf %lf", &x, &y); }
  void print() { printf("(%3.3lf, %3.3lf)\n", x, y); }
};
struct Circle
{
  Point center; double radious;
  bool contains(Point &p) { return center.distance(p) <= radious + eps; }
  pair<Point, Point> circleIntersections(Circle &other)
  {
    double d = center.distance(other.center);
    double u = acos((other.radious*other.radious + d*d - radious*radious) / (2.0*other.radious*d));
    Point dc = (center - other.center).normalized() * other.radious;
    return pair<Point, Point>
    {
      other.center + dc.rotate(u),
      other.center + dc.rotate(-u)
    };
  }
};
struct Meat
{
  Point p; double c;
  void read() { p.read(); scanf("%lf", &c); }
  Circle getCircle(double T) { return Circle{p, T / c}; }
};
Meat meats[maxN];
Circle circles[maxN];

bool valid(Point &a)
{
  int done = 0;
  for (int i = 0; i < n; i++)
    done += circles[i].contains(a);
  return done >= k;
}
bool can(double T)
{
  for (int i = 0; i < n; i++)
    circles[i] = meats[i].getCircle(T);

  for (int i = 0; i < n; i++)
  {
    if (valid(meats[i].p))
      return true;

    for (int j = i + 1; j < n; j++)
    {
      pair<Point, Point> intersections = circles[i].circleIntersections(circles[j]);
      DEBUG {
        printf("\t%d %d\n", i, j);
        pair<Point, Point> intersections2 = circles[j].circleIntersections(circles[i]);
        printf("\t\tcenters %3.3lf: ", circles[i].radious); circles[i].center.print();
        printf("\t\tcenters %3.3lf: ", circles[j].radious); circles[j].center.print();
        printf("\t\tintersection1: "); intersections.first.print();
        printf("\t\tintersection1: "); intersections.second.print();
        printf("\t\tintersection2: "); intersections2.first.print();
        printf("\t\tintersection2: "); intersections2.second.print();
      }
      if (valid(intersections.first) || valid(intersections.second))
        return true;
    }
  }
  return false;
}

int main()
{
  while (scanf("%d %d", &n, &k) != EOF)
  {
    for (int i = 0; i < n; i++)
      meats[i].read();

    double lo = 0, hi = 1e6;
    while (abs(hi - lo) > eps)
    {
      double mid = (lo + hi) / 2;
      if (can(mid)) hi = mid;
      else lo = mid;
    }
    printf("%lf\n", lo);
  }
  return 0;
}

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll LL_INF = LLONG_MAX;
const long double PI = (acos(-1));
const ull MOD = 1000000007;


struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;
//最大公約数
template<class X> X gcd(X a, X b) {return b ? gcd(b,a%b):a;}

//最小公倍数（最大公約数の関数に依存/オーバーフローしずらい）
template <class X> X lcm2(X a, X b){
    X g = gcd(a, b);
    return a / g * b;
}
int main(){
    int N;
    cin >> N;
    ull ans = 1;
    for(int i = 0; i < N; i++){
        ull T;
        cin >> T;
        ans = lcm2(ans, T);
    }
    cout << ans << endl;
}

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

bool isEven(const string & s, int end)
{
    if (end % 2 != 0)
        return false;
    int middle = end / 2;
    for (int i = 0; i < middle; i++)
    {
        if (s[i] != s[middle + i])
            return false;
    }
    return true;
}

int main()
{
    string s;
    cin >> s;
    for (int end = s.length() - 1; end > 0; end--)
    {
        if (isEven(s, end))
        {
            cout << end << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3568
w, h, n = map(int,  input().split())
W = [0, w]
H = [0, h]

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and x > W[0]:
        W[0] = x
    if a == 2 and x < W[1]:
        W[1] = x
    if a == 3 and y > H[0]:
        H[0] = y
    if a == 4 and y < H[1]:
        H[1] = y
        
if W[0] > W[1] or H[0] > H[1]:
    print(0)
else:
    print((W[1] - W[0]) * (H[1] - H[0]))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	private static Scanner scan;
	public static void main(String[] args) {
		scan = new Scanner(System.in);
		scan.useDelimiter(",|\\s+");
		int a[] = new int[31];
		for(int i = 0;i < 31;i++){
			a[i] = i;
		}
		int w = scan.nextInt();
		int n = scan.nextInt();
		for(int i = 0;i < n;i++){			
			int a1 = scan.nextInt();
			int a2 = scan.nextInt();
			int b1 = a[a1];
			int b2 = a[a2];
			a[a1] = b2;
			a[a2] = b1;
		}
		for(int i = 1;i <= w;i++ ){
			System.out.println(a[i]);
		}
		System.exit(0);
	}
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int n, m;
    cin >> n >> m;
    pair<int,int> cut[100'000];
    for(int i=0;i<m;i++){
        int a, b;
        cin >> a >> b;
        cut[i] = {a,b};
    }
    sort(cut, cut+m);
    int right = -1, ans = 0;
    for(int i=0;i<m;i++){
        if(cut[i].first<=right){
            right=min(right, cut[i].second-1);
            continue;
        }
        ans++;
        right = cut[i].second-1;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1024
N,K,Q=map(int,input().strip().split())
A=[int(input()) for _ in range(Q)]

dp=[0 for _ in range(N)]
for n in range(Q):
    dp[A[n]-1]+=1

for n in range(N):
    if dp[n]+K-Q>0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 13672
z[9999],a,b,c;f(x,y){fflush(!printf("? %d %d\n",x,y));scanf("%s",&b);b=b=='Y';}main(i){if(scanf("%d%d",&a,&b),a<=b){puts("Impossible");return 0;}for(i=a+=b;~--i;)!c||f(i,z[c-1])?(z[c++]=i):c--;for(c=*z,i=a;~--i;)z[i]=f(c,i);for(printf("! "),i=0;i<a;)printf("%d",z[i++]);puts("");}

Measured memory_bytes: 724
import sys
from itertools import combinations
from collections import Counter
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    s = [input()[0] for _ in range(n)]
    c = Counter(s)
    ans = 0
    for x, y, z in combinations('MARCH', 3):
        ans += c[x] * c[y] * c[z]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10140
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  2000

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a;
    char ar[2];
    
    scanf("%c", ar);
    
    if ('A'<=ar[0]&&ar[0]<='Z') {
        printf("A");
    } else{
        printf("a");
    }
    
    return 0;
}



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

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

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

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.reserve(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }

bool same(int x, int y) { return root(x) == root(y); }

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

int main() {
  int K;
  cin >> K;
  cout << (K / 2) * (K - K / 2) << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Contests.ABC165
{
    /// <summary>
    /// 
    /// </summary>
    static class B
    {
        static void Main(string[] args)
        {
            var x = NextLong();

            long c = 100;

            var i = 0;
            while (c < x)
            {
                i++;
                c = (long)Math.Floor(c * 1.01);
            }

            Console.WriteLine(i);
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


Measured memory_bytes: 27560
n = int(raw_input())
al = map(int, raw_input().split())
bl = map(int, raw_input().split())
cl = map(int, raw_input().split())
al.sort()
bl.sort()
cl.sort()
ap = 0
cp = 0
t = 0
for b in bl:
    while ap < n and al[ap] < b:
        ap += 1
    while cp < n and cl[cp] <= b:
        cp += 1
    t += ap * (n - cp)
print t


Measured memory_bytes: 17708
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>

namespace ac119D{

constexpr int64_t MAXINF = 1LL << 60;
using dst_type = std::pair<int64_t, int64_t>;

dst_type bSearchLR(std::vector<int64_t>& vec, int64_t x){
    assert(!vec.empty());

    dst_type distLR(0,0);
    int32_t start = 0;
    int32_t end = (int32_t) vec.size() - 1;
    while(start < end - 1){
        int32_t mid = (end + start) / 2;
        if(x < vec[mid]){
            end = mid;
        }
        else{
            start = mid;
        }
    }
    if(x < vec[start]){
        distLR.first = MAXINF;
        distLR.second = vec[start] - x;
    }
    else if(x > vec[end]){
        distLR.first = x - vec[end];
        distLR.second = MAXINF;
    }
    else{
        distLR.first = x - vec[start];
        distLR.second = vec[end] - x;
    }

    return distLR;
}

int64_t minStep(dst_type& S_dst, dst_type& T_dst){
    int64_t minStep = MAXINF;
    //Left -> Left
    minStep = std::min(minStep, std::max(S_dst.first, T_dst.first));
    //Left(S) -> Right(T)
    minStep = std::min(minStep, S_dst.first * 2 + T_dst.second);
    //Right(S) -> Left(T)
    minStep = std::min(minStep, S_dst.second * 2 + T_dst.first);
    //Left(T) -> Right(S)
    minStep = std::min(minStep, T_dst.first * 2 + S_dst.second);
    //Right(T) -> Left(S)
    minStep = std::min(minStep, T_dst.second * 2 + S_dst.first);
    //Right -> RIght
    minStep = std::min(minStep, std::max(S_dst.second, T_dst.second));
    return minStep;
}

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

    int32_t A, B, Q;
    std::cin >> A >> B >> Q;
    std::vector<int64_t> S(A);
    std::vector<int64_t> T(B);
    for(auto& i : S){
        std::cin >> i;
    }
    for(auto& i : T){
        std::cin >> i;
    }
    std::sort(S.begin(), S.end());
    std::sort(T.begin(), T.end());

    for(int32_t i = 0; i < Q; i++){
        int64_t x = 0;
        std::cin >> x;
        dst_type S_dst = bSearchLR(S, x);
        dst_type T_dst = bSearchLR(T, x);
        int64_t res = minStep(S_dst, T_dst);
        std::cout << res << std::endl;
    }

    return 0;
}

} // namespace ac119D

int main(){
    ac119D::ac119D_main();
    return 0;
}

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

#define endl '\n'
#define PB push_back
#define PF push_front
#define MP make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

const int INF = 1e9 + 7;
const ll LINF = 1e18 + 14;

int main(){
    ios_base::sync_with_stdio(false); //cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> d1(n), d2(n);
    for (int i = 0; i < n; i++) {
        cin >> d1[i] >> d2[i];
    }
    bool ok = false;
    for (int i = 0; i < n-2; i++) {
        if (d1[i] == d2[i] &&
            d1[i+1] == d2[i+1] &&
            d1[i+2] == d2[i+2]) {
            ok = true;
        }
    }

    if (ok) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
} 


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

int main(){
    int n,x,b=0;
    cin >> n >> x;
    vector<int> a(n);
    for(int i = 0;i < n;i++)cin >> a[i];
    sort(a.begin(),a.end());
    for(int i = 0;i < n;i++){
        if(a[i] <= x){
            b++;
            x -= a[i];
        } else {
            cout << b << endl;
            return 0;
        }
    }
    if(x != 0)b -= 1;
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
money = 1000
stock = 0
 
for i in range(N):
    if i == N-1:
        money += stock * A[i]
        break
    if A[i] < A[i+1]:
        tmp_stock = money // A[i]
        stock += tmp_stock
        money -= tmp_stock * A[i]
    elif A[i] > A[i+1]:
        money += stock * A[i]
        stock = 0
    else:
        pass
 
print(money)


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

int main(){
  
  int r,D; cin >> r >> D;
  
  vector<int> mo(3000);
  cin >> mo[1999];
  
  for(int i = 1999; i < 2009 ; i++){
    mo[i+1] = r*mo[i] - D;
    cout << mo[i+1] << endl;
  }
  
  return 0;
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

Int n;
Int res;

void rec(Int x, bool a, bool b, bool c) {
    if (n < x) return;
    if (x <= n and a and b and c) {
        res++;
    }
    rec(x * 10 + 7, true, b, c);
    rec(x * 10 + 5, a, true, c);
    rec(x * 10 + 3, a, b, true);
}

int main() {
    cin >> n;
    rec(0, false, false, false);
    dump(res);
    return 0;
}


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

const long long MOD = 1e9+7;
typedef pair<int, int> ii;

int h[105];

long long memo[5][105][105];

long long pow2(long long b){
    if(b <= 29){
        return 1<<b;
    }else{
        long long temp = pow2(b>>1);
        if(b&1){
            return ((temp*temp)<<1)%MOD;
        }else{
            return temp*temp%MOD;
        }
    }
}

long long dp(int mode, int i, int j, int offset = 0){
    //if(i != 0 || j != 8){return 1;}
    if(memo[mode][i][j] != -1){
        return memo[mode][i][j];
    }

    int x = MOD;
    for(int k = i; k <= j; k ++){
        x = min(x, h[k]);
    }

    int w = 0;
    for(int k = i; k <= j; k ++){
        w += (h[k] == x);
    }

    vector<ii> startEnd;
    int s = i;
    for(int k = i; k <= j+1; k ++){
        if(k == j+1 || h[k] == x){
            // stop here
            int e = k;
            if(s == e){
                s = k+1;
                continue;
            }
            startEnd.push_back(ii(s, e-1));
            s = k+1;
        }
    }

    if(w == 0){w = j-i+1;} // edge case when all the heights are the same

    /*printf("dp(%d, %d, %d) offset=%d x=%d w=%d\n", mode, i, j, offset, x, w);
    for(ii se: startEnd){
        printf("ii(%d, %d)\n", se.first, se.second);
    }*/

    if(mode == 1){
        long long ans1 = pow2(x-offset);

        for(ii se: startEnd){
            int s, e;
            tie(s, e) = se;
            ans1 = ans1*dp(1, s, e, x)%MOD;
        }

        return memo[mode][i][j] = ans1%MOD;
    }else if(mode == 3){
        long long ans1 = (pow2(x-offset)+MOD-2)%MOD;
        long long ans3 = pow2(w);

        for(ii se: startEnd){
            int s, e;
            tie(s, e) = se;
            ans1 = ans1*dp(1, s, e, x)%MOD;
            ans3 = ans3*(dp(1, s, e, x)+dp(3, s, e, x))%MOD;
        }

        return memo[mode][i][j] = (ans1+ans3)%MOD;
    }
}

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

    for(int i = 0; i < N; i ++){
        scanf("%d", &h[i]);
    }

    memset(memo, -1, sizeof(memo));
    printf("%lld", dp(3, 0, N-1));
    return 0;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline
from heapq import *

def dijkstra(G, sta):
    dist = [10**18]*n
    dist[sta] = 0
    pq = []
    heappush(pq, (0, sta))
    
    while pq:
        d, v = heappop(pq)
        
        if dist[v]<d:
            continue
        
        for nv, w in G[v]:
            if dist[nv]>dist[v]+w:
                dist[nv] = dist[v]+w
                heappush(pq, (dist[nv], nv))
    
    return dist

n, m, s, t = map(int, input().split())
G1 = [[] for _ in range(n)]
G2 = [[] for _ in range(n)]

for _ in range(m):
    u, v, a, b = map(int, input().split())
    G1[u-1].append((v-1, a))
    G1[v-1].append((u-1, a))
    G2[u-1].append((v-1, b))
    G2[v-1].append((u-1, b))

d1 = dijkstra(G1, s-1)
d2 = dijkstra(G2, t-1)
ans = [0]

for i in range(n-1, -1, -1):
    ans.append(max(ans[-1], 10**15-d1[i]-d2[i]))

ans.reverse()

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

Measured memory_bytes: 117748
N, W = map(int, input().split())

wv = []
for i in range(N):
    wv.append(list(map(int, input().split())))
    
dp = [[0 for i in range(W+1)] for j in range(N+1)]

for i in range(N):
    for w in range(W+1):
        if w - wv[i][0] >= 0:
            dp[i+1][w] = max(dp[i][w - wv[i][0]] + wv[i][1], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]

print(dp[N][W])

Measured memory_bytes: 173448
def main():
    n, d = map(int, input().split())
    xy = []
    for _ in range(n):
        xy.append(list(map(int, input().split())))
    count = 0
    for i in range(n):
        if (xy[i][0])**2 + (xy[i][1])**2 <= d**2:
            count += 1
    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 102448
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#define MAX 500000
bool reverse = false;
int main(){
    char S[MAX];
    scanf("%s",S);
    int Q;
    int length=strlen(S);
    int back = 1;
    for(int i=0;i<length;i++){
        S[i+200000]=S[i];
        S[i]='\0';
    }

    scanf("%d",&Q);
    for(int i=0;i<Q;i++){
        int q;
        scanf("%d",&q);
        if(q==1){
            if(reverse)
                reverse = false;
            else
                reverse = true;
        }
        else{
            int F;
            char C;
            scanf("%d %c",&F,&C);
            if((F==1 && !reverse) || (F==2 && reverse)){
                S[200000-back]=C;
                back++;
            }
            else{
                S[200000+length] = C;
                length++;
            }   
        }
    }
    if(!reverse){
        for(int i=200000-back+1;i<200000+length;i++)
         printf("%c",S[i]);
    }
    else{
        for(int i=200000+length-1;i>200000-back;i--)
            printf("%c",S[i]);
    }
}





Measured memory_bytes: 896
//AtCoder Beginner Contest 043 B問題
#include <bits/stdc++.h>
#include <vector>

using namespace std;

int main(){
	int f = 0;
	char s[15];
	for(int i=0; i<15; i++){
		s[i] = 0;
	}
	scanf("%s", s);
	vector<char> ss(15); 
	for(int i=0; i<15; i++){
		if(s[i] == 'B' && f != 0){
			ss.erase(ss.begin()+f-1);
			f--;
		}
		else{
			ss[f] = s[i];
			f++;
		}
	}
	//ss.erase(ss.find('a'));
	for(int i=0; i<15; i++){
		if (ss[i] == 48){
			printf("%d", ss[i]-48);
		}
		if (ss[i] == 49){
			printf("%d", ss[i]-48);
		}
	}
	printf("\n");
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	int L; cin >> L;
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
	}
	int maxi = 0;
	int last = 0;
	rep(i, 0, N - 1) {
		if (chmax(maxi, a[i] + a[i + 1]))last = i;
	}
	if (maxi < L) {
		cout << "Impossible" << endl;
	}
	else {
		cout << "Possible" << endl;
		rep(i, 0, N - 1) {
			if (last == i)break;
			cout << i + 1 << endl;
		}
		rrep(i, 0, N - 1) {
			if (last == i)break;
			cout << i + 1 << endl;
		}
		cout << last + 1 << endl;
	}
	return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long

const int MOD =  1000000007;
const int IINF = INT_MAX;
const ll INF = 1LL << 60;


int main() {
    int n; cin >> n;
    V<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    sort(ALL(a), greater<ll>());
    ll ans = a[0];
    priority_queue<ll> q;
    for(int i = 1; i < n; i++){
        if(q.size() > 0){
            ll p = q.top();
            q.pop();
            ans += p;
        }
        q.push(a[i]);
        q.push(a[i]);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 6936
A, B, N = map(int, input().split())
if B == 1:
    print(0)
    exit()

if A == 1:
    print(0)
    exit()


if B >= N:
    print(max(int(A*N/B) - A*int(N/B), int(A*(N-1)/B) - A*int((N-1)/B),int(A*(N-2)/B) - A*int((N-2)/B)))
    exit()

else:
    print(max(int(A*N/B) - A*int(N/B), int(A*(N-1)/B) - A*int((N-1)/B), int(A*(B-1)/B) - A*int((B-1)/B)))
    exit()

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

struct unionfind{
  vector<int> par;
  unionfind(){}
  unionfind(int n){
    par.resize(n,-1);
  }
  int root(int k){
    if(par.at(k)<0)return k;
    return par.at(k) = root(par.at(k));
  }
  int size(int k){
    return -par[root(k)];
  }
  void unite(int a,int b){
    a = root(a);
    b = root(b);
    if(a==b)return ;
    if(size(a)<size(b))swap(a,b);
    par.at(a) += par.at(b);
    par.at(b) = a;
  }
  bool same(int a,int b){
    return root(a) == root(b);
  }
};

signed main(){

  int n,m,k;
  cin>>n>>m>>k;
  unionfind uni(n);
  vector<int> deg(n);
  for(int i=0;i<m;++i){
    int a,b;
    cin>>a>>b;
    a--;b--;
    deg.at(a)++;
    deg.at(b)++;
    uni.unite(a,b);
  }
  for(int i=0;i<k;++i){
    int c,d;
    cin>>c>>d;
    c--;d--;
    if(uni.same(c,d)){
      deg.at(c)++;
      deg.at(d)++;
    }
  }
  for(int i=0;i<n;++i){
    cout<<(uni.size(i)-deg[i]-1)<<" ";
  }
  cout<<endl;

}

Measured memory_bytes: 1664