akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize(2)
// Happy TLE and WA every day!
// by: zxb the vegetable chicken
#include<bits/stdc++.h>
#define mp              make_pair
#define rep(i,n)        for(int i = 0; i < n; i++)
#define foreach(i,c)    for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define BINF            0x7fffffff
#define INF             0x3f3f3f3f
#define LINF            4557430888798830399
#define pb              push_back
#define F               first
#define S               second
#define Time            clock()/CLOCKS_PER_SEC
#define read            ZXBs_fast_input
#define write           ZXBs_fast_output
#define int             long long
#define find            use_dsu_to_find_its_parent
//#define usingFiles
using namespace std;

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

inline bool read(int& x){
	x = 0;
	int c;
	int sign = 1;
	while( (c = getchar()) < '0' || c > '9' ) if(c == '-') sign = -1;
	x = c ^ '0';
	while( (c = getchar()) >= '0' && c <= '9' ) x = (x<<3) + (x<<1) + (c ^ '0');
	x *= sign;
	return 1;
}

inline bool write(int x){
	if(x >= 10) write(x / 10);
	putchar(x % 10 + '0');
	return 1;
}

const int rp = 666666;
const bool debug = 1;
const bool I_good_vegetable_a = 1;

int par[200200];
void init(int _n){
	rep(i, _n) par[i] = i;
}
int find(int now){
	if(par[now] == now) return now;
	return par[now] = find(par[now]);
}
bool unite(int a, int b){
	int Pa = find(a), Pb = find(b);
	if(Pa == Pb) return false;
	par[Pa] = Pb;
	return true;
}

int n, d;
int a[200200];
vector< pair< int, pii > > edge;

void solve(int l, int r){ // [l; r]
	if(l >= r) return ;
	int m = (l + r) / 2;
	int mnL = LINF, mnposL;
	for(int i = l; i <= m; i++){
		if(a[i] - d * (i + 1) < mnL){
			mnL = a[i] - d * (i + 1);
			mnposL = i;
		}
	}
	int mnR = LINF, mnposR;
	for(int i = m + 1; i <= r; i++){
		if(a[i] + d * (i + 1) < mnR){
			mnR = a[i] + d * (i + 1);
			mnposR = i;
		}
	}
	for(int i = m + 1; i <= r; i++){
		edge.pb( mp(mnL + a[i] + d * (i + 1), mp(mnposL, i)) );
	}
	for(int i = l; i <= m; i++){
		edge.pb( mp(mnR + a[i] - d * (i + 1), mp(i, mnposR)) );
	}
	solve(l, m);
	solve(m + 1, r);
}

signed main(){
	ios::sync_with_stdio(false);
	#ifdef usingFiles
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cin >> n >> d;
	init(n);
	rep(i, n) cin >> a[i];
	solve(0, n - 1);
	sort(edge.begin(), edge.end());
	int ans = 0;
	rep(i, edge.size()){
		if(find(edge[i].S.F) != find(edge[i].S.S)){
			ans += edge[i].F;
			unite(edge[i].S.F, edge[i].S.S);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 103904
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int ans = 0;
    int now = 1;
    for(int i = 0; i < N; i++){
      int a = Integer.parseInt(sc.next());
      if(a != now){
        ans++;
      }else{
        now++;
      }
    }
    if(ans == N){
      ans = -1;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 48888
n, k = map(int, input().split())
xs = list(map(int, input().split()))

zero = len(xs)
for i in range(len(xs)):
    if xs[i] >= 0:
        zero = i
        break

dic_positive = {0: 0}
dic_negative = {0: 0}
for i in range(len(xs) - zero):
    dic_positive[i + 1] = xs[zero + i]

for i in range(zero):
    dic_negative[i + 1] = abs(xs[zero - i - 1])


init_max = 1000000000000000
candidate = init_max
for i in range(k + 1):
    if dic_negative.get(i) is not None and dic_positive.get(k - i) is not None:
        candidate = min(
            candidate,
            dic_negative[i] + dic_negative[i] + dic_positive[k - i],
            dic_negative[i] + dic_positive[k - i] + dic_positive[k - i]
        )

print(candidate)

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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }

    int64_t res = 0;
    map<int, int> m;
    for (int i = 0; i < N; i++)
    {
        int Ai = A.at(i);
        res += m[i - Ai];
        m[Ai + i] += 1;
    }
    cout << res << endl;
}

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

using namespace std;
typedef long long ll ;
#define forl(i,n) for(int i=0 ; i<n ; i++)

int main()
{
	int T=1;
	// cin >> T ;

	while(T--)
	{
		int n ;
		cin>>n ;
		int a[3][n];
		for(int i=0 ; i<n ; i++)
		{
			cin>>a[0][i]>>a[1][i]>>a[2][i] ;
		}
		int dp[3][n] ;
		dp[0][0]=a[0][0] ;
		dp[1][0]=a[1][0] ;
		dp[2][0]=a[2][0] ;

		for(int i=1 ; i<n ; i++)
		{
			dp[0][i] = max(dp[1][i-1],dp[2][i-1]) + a[0][i] ;
			dp[1][i] = max(dp[0][i-1],dp[2][i-1]) + a[1][i] ;
			dp[2][i] = max(dp[1][i-1],dp[0][i-1]) + a[2][i] ;
		}
		int ans=max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1])) ;
		cout<<ans<<endl ;
	}
	return 0;
}

Measured memory_bytes: 5956
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std; 
#define MAXA 100000000
#define MAXB 100000000
#define MAXC 100000000
#define MAXD 100000000
#define MAXN 50
#define MAXM 50
int main(int argc,char const* argv[])
{
  int a,b;
  double c,d;
  cin >> a >> b;
  c=a,d=b;
  if((a+b)/2 < (c+d)/2)
    {
      cout << ((a+b)/2)+1 << endl;
    }
  else
    {
      cout << ((a+b)/2) << endl;
    }
  


  return 0;
}


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

int n,b;

inline int read(){
	int s=0,t=1;
	char c=getchar();
	while((c>'9'||c<'0')&&c!='-')c=getchar();
   	if(c=='-')t=-1,c=getchar();
   	while(c>='0'&&c<='9')s=s*10+c-'0',c=getchar();
   	return s*t;
}

int main(void){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	if(i%2==1)b++;
	printf("%.10lf",(b+0.0)/(n+0.0));
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main
{

	public static void main(String[] args) throws NumberFormatException, IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> strLst = new ArrayList<String>();
		int cnt = 0;
		int max;
		int other;
		String inputLine = "";
		String[] lines;

		br.readLine();
		while (cnt <= 1000 && (inputLine = br.readLine()) != null)
		{
			max = 0;
			other = 0;
			lines = inputLine.split(" ");

			for (int i = 0; i < 3; ++i)
			{
				other += (int) Math.pow(Integer.parseInt(lines[i]), 2);
				if (max < Integer.parseInt(lines[i]))
				{
					max = Integer.parseInt(lines[i]);
				}
			}
			other -=(int) Math.pow(max, 2);

			if (other == (int) Math.pow(max, 2))
				strLst.add("YES");
			else
				strLst.add("NO");

			++cnt;
		}

		for(String result : strLst)
		{
			System.out.println(result);
		}

	}

}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
    /* for writing output to output.txt */
    int n; cin >> n;
    double c = 2 * 3.141592653589793238 * n;
    cout << c << endl;

    return 0;
}


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

using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int ans=0;
	int dp[n+1]={};
	for(int i=1;i<n;i++)
	{
		if(i==1)
			dp[i]=abs(a[i]-a[i-1]);
		else 
			dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin>>N;
    
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            int A = i*j;
            if(A == N){
                cout<< "Yes" <<endl;
                return 0;
            }
        }
    }
    
    cout << "No" << endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>

using namespace std;

int dfs(auto& nodes, int current_index, int parent_index, int& time) {
    int children = 0;
    
    auto& current_node = nodes[current_index];
    current_node.time = time;
    current_node.low = time;
    
    for (auto adjacent_index : current_node.adjacent) {
        if (adjacent_index == parent_index) {
            continue;
        }
        
        auto& adjacent_node = nodes[adjacent_index];
        if (adjacent_node.time) {
            current_node.low = min(adjacent_node.time, current_node.low);
        } else {
            ++children;
            dfs(nodes, adjacent_index, current_index, ++time);
            
            if (current_node.time <= adjacent_node.low) {
                current_node.is_articulation_point = true;
            }
            
            current_node.low = min(adjacent_node.low, current_node.low);
        }
    }
    
    return children;
}

int main() {
    int n, m;
    
    cin >> n >> m;
    if (n == 0 || m == 0) {
        return 0;
    }
    
    struct node {
        int time{0};
        int low{0};
        bool is_articulation_point{false};
        vector<int> adjacent;
    };
    
    vector<node> nodes(n);
    for (int i = 0; i < m; ++i) {
        int from, to;
        cin >> from >> to;
        nodes[from].adjacent.push_back(to);
        nodes[to].adjacent.push_back(from);
    }
    
    int time = 0;
    nodes[0].is_articulation_point = dfs(nodes, 0, -1, ++time) > 1;
    
    for (int i = 0; i < nodes.size(); ++i) {
        if (nodes[i].is_articulation_point) {
            cout << i << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 4656
// import java.io.*;
// import java.math.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        Queue<Integer> q = new PriorityQueue<Integer>(Collections.reverseOrder());
        for (int i = 0; i < N; i++) {
            q.add(sc.nextInt());
        }
        for (int i = 0; i < M; i++) {
            q.add(q.poll() / 2);
        }
        long result = 0L;
        for (int x : q) {
            result += x;
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 61184
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int64_t INF = 1LL << 60;

int main() {
  int N,M,K;
  cin>>N>>M>>K;
  for(int i=0;i<=N;i++){
	  for(int j=0;j<=M;j++){
		  if(M*i+N*j-2*i*j==K){cout<<"Yes"<<endl;return 0;}
	  }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
a,b,c,d=map(int,input().split())

def gcd(a,b):
    if a==0:
        return b
    else:
        return gcd(b%a,a)

cdlcm=c*d//gcd(c,d)

cd=b//c-(a-1)//c
dd=b//d-(a-1)//d
cdd=b//(cdlcm)-(a-1)//(cdlcm)

print(round(b-a+1-(cd+dd-cdd)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
void fp(bool flag, string s, string t){
    if(flag)cout << s << endl;
    else cout << t << endl;
}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    intl cnt = 0;
    cnt += ((n/500) * 1000);
    n %= 500;
    cnt += n/5 * 5;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> ipair;
#define int long long
#define pb push_back
#define ff first
#define INF INT_MAX
#define ss second
#define fr(i, j, a) for (int i = j; i < a; i++)
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define sz size()
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<ipair>
#define mod 1000000007
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
void init() {
  int n;
  cin >> n;
  vi a(n);
  for (int &i : a)
    cin >> i;
    int ans=0;
  for (int &x : a)
    ans += (x - 1);
  cout << ans << endl;
}
int32_t main() {
  IOS;
  init();
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, c, ans;
  cin >> a;
  ans = 0;
  unsigned long long b;
  b = 1;
  for (int i = 0; i < a; i++) {
    cin >> c;
    b *= c;
    while (b % 2 == 0) {
    b /= 2;
    ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

int main() {
    string s;
    cin>>s;

    if(s=="Sunny") cout<<"Cloudy"<<endl;
    else if(s=="Cloudy") cout<<"Rainy"<<endl;
    else cout<<"Sunny"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl

int a[51],b[51],c[51],d[51];
int n,q,m;

vector<int>ans;

int best=0;


int check(){
   int cur=0;
   for(int k=0;k<q;k++){
     if(ans[b[k]]-ans[a[k]]==c[k]){
       cur+=d[k];
     }
   }
     return cur;

}




void backtrack(int i,int j){

 if(i>=n){
   best=max(best,check());
   return;
 }
 for(int it=j;it<=m;it++){
   ans.push_back(it);
   backtrack(i+1,it);
   ans.pop_back();
 }

}



int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>n>>m>>q;

  for(int i=0;i<q;i++){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
    a[i]--;
    b[i]--;
    
   }  
   
   backtrack(0,1);

  cout<<best<<endl;


  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
    int ans=0,n,a[10001]={};
    cin>>n;
    n*=2;
    for (int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i+=2)
        ans=ans+min(a[i],a[i+1]);
    cout<<ans;
    return 0;
}

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

    if (A > B)
    {
        ans = 0;
    }
    else
    {
        if (N == 1)
        {
            if (A == B)
            {
                ans = 1;
            }
            else
            {
                ans = 0;
            }
        }
        else
        {
            ans = (B - A) * (N - 2) + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  string A, B;
  cin >> A >> B;
 
  if(A.size() > B.size()){
    cout << "GREATER" << endl;
  }else if(A.size() < B.size()){
    cout << "LESS" << endl;
  }else{
    for(int i = 0; i < A.size(); i++){
      if(A[i] > B[i]){
        cout << "GREATER" << endl;
        exit(0);
      }else if(A[i] < B[i]){
        cout << "LESS" << endl;
        exit(0);
      }
    }
  cout << "EQUAL" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int N = scanner.nextInt();
		int K = scanner.nextInt();

		System.out.println((int)Math.floor(Math.log(N) / Math.log(K)) + 1);

	}

}


Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

vector <pair <int, int> > edges[200];
int r[8];
int d[200][256];
//bool decided[200][256];

int in_r(int v, int R){
  for(int i = 0; i < R; i++){
    if(r[i] - 1 == v){
      return i;
    }
  }
  return -1;
}
void dijikstra(int S, int N, int R){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < (1 << R); j++){
            d[i][j] = INT_MAX;
        }
    }

    priority_queue < pair <int, pair<int, int> > , vector <pair <int, pair<int, int> > >, greater<pair <int, pair<int, int> > > > pq;
    d[S][0] = 0;
    pq.push(make_pair(0, make_pair(S, 0)));
    while(!pq.empty()){
        auto cur = pq.top();
        auto cur_cost = cur.first;
        auto cur_node = cur.second.first;
        auto cur_bitset = cur.second.second;
        pq.pop();
        if(d[cur_node][cur_bitset] < cur_cost){
            continue;
        }

        int r_ind = in_r(cur_node, R);
        int next_bitset = cur_bitset;
        if(r_ind >= 0){
          next_bitset = (cur_bitset | (1 << r_ind));
          d[cur_node][next_bitset] = cur_cost;
        }
        for(int i = 0; i < edges[cur_node].size(); i++){
            auto next = edges[cur_node][i];
            auto next_node = next.second;
            auto cost = next.first;
            int next_d = d[cur_node][cur_bitset] + cost;
            if(d[next_node][next_bitset] > next_d){
                d[next_node][next_bitset] = next_d;
                pq.push(make_pair(next_d, make_pair(next_node, next_bitset)));
            }
        }
    }
}

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

   for(int i = 0; i < R; i++){
     cin >> r[i];
   }

   for(int i = 0; i < M; i++){
       int a;
       int b;
       int c;
       cin >> a >> b >> c;
       edges[a - 1].push_back(make_pair(c, b - 1));
       edges[b - 1].push_back(make_pair(c, a - 1));
   }

   int ans = INT_MAX;
   for(int i = 0; i < R; i++){
    dijikstra(r[i] - 1, N, R);
    
     for(int j = 0; j < R; j++){
       if(i == j){
         continue;
       }
       ans = min(ans, d[r[j] - 1][(1 << R) - 1]);
     }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 3396
#include <cstdio>
#include <map>
#include <queue>
#include <string>

using namespace std;

const int INF = -1;
const int MAX_H = 1000;
const int MAX_W = 1001;
const int MAX_N = 9;

int H, W, N;
char field[MAX_H][MAX_W];
int d[MAX_H][MAX_W];
int sx, sy, gx, gy;
int power = 1;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

typedef pair<int, int> P;

void reset_d() {
  for (int i = 0; i < H; i++)
    for(int j = 0; j < W; j++) d[i][j] = INF;
}

int bfs(int c) {
  queue<P> que;
  reset_d();
  d[sx][sy] = c;
  que.push(P(sx, sy));
  while(que.size()) {
    P p = que.front(); que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if ( 0 <= nx && nx <= H && 0 <= ny && ny <= W && field[nx][ny] != 'X' && d[nx][ny] == INF) {
        d[nx][ny] = d[p.first][p.second] + 1;
        que.push(P(nx, ny));
        if (field[nx][ny] - '0' == power) {
          sx = nx;
          sy = ny;
          power++;
          return d[nx][ny];
        }
      }
    }
  }
  return INF;
}

void solve() {
  int c = 0;
  for (int i = 0; i < N; i++) {
    c = bfs(c);
  }
  printf("%d\n", c);
}


int main() {
  scanf("%d %d %d", &H, &W, &N);
  for (int i = 0; i < H; i++) {
    scanf("%s", field[i]);
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (field[i][j] == 'S') {
        sx = i;
        sy = j;
      }
      if (field[i][j] == 'G') {
        gx = i;
        gy = j;
      }
    }
  }
  solve();
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  int count=0;
  for(int i=0;i<n;i++){
    if(a.at(i)==i+1){
      count++;
    }
  }
  if(count==n || count==n-2){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
num_val = str(input())

if num_val[len(num_val) - 1] in ['2', '4', '5', '7', '9']:
    print('hon')
elif num_val[len(num_val) - 1] in ['0', '1', '6', '8']:
    print('pon')
elif num_val[len(num_val) - 1] in ['3']:
    print('bon')


Measured memory_bytes: 61624
#include<stdio.h>
#define l 1000000007
int main()
{
    long long N,K,i,sum=0;
    scanf("%lld %lld",&N,&K);
    for(i=K;i<=N+1;i++)

        {
		sum+=(i*((2*N)-i+1))/2-((i*(i-1))/2)+1;	}

printf("%lld\n",sum%l);
    return 0;

}

Measured memory_bytes: 1732
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	int n, c[500], s[500], f[500];
	cin >> n;
	FOR(i, n - 1)cin >> c[i] >> s[i] >> f[i];

	FOR(i, n) {
		int t = 0;
		for (int j = i; j < n - 1; j++) {
			if (t < s[j]) t = s[j];
			else if (t % f[j] == 0);
			else t = t + f[j] - t % f[j];
			t += c[j];
		}
		cout << t << endl;
	}

	return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
        int A, B, K;
        cin >> A >> B >> K;
        vector<int> vec;
        for (int i = 1; i < min(A, B) + 1; i++)
        {
                if (A % i == 0 && B % i == 0)
                {
                        vec.push_back(i);
                }
        }
        reverse(all(vec));
        cout << vec[K-1] << endl;

        return 0;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  int ans = abs((a+b)/2);
  if((a+b)%2 == 0){
    cout << ans;
    return 0;
  }
  else cout << "IMPOSSIBLE";
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<string>
#define N 6009
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;

int main()
{
    int sx, sy, tx, ty;
    scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
    for(int i = sy + 1; i <= ty; i++) printf("U");
    for(int i = sx + 1; i <= tx; i++) printf("R");
    for(int i = ty - 1; i >= sy; i--) printf("D");
    for(int i = tx - 1; i >= sx; i--) printf("L");
    printf("L");
    for(int i = sy; i <= ty; i++) printf("U");
    for(int i = sx; i <= tx; i++) printf("R");
    printf("DR");
    for(int i = ty; i >= sy; i--) printf("D");
    for(int i = tx; i >= sx; i--) printf("L");
    printf("U\n");
    return 0;
}


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

int H, W, D;
int A[310][310];
int Q;
int L[100010], R[100010];
int res[100010];
int x[100010], y[100010];
int Left[270010], Right[270010];
int Tree[55][270010];
int n2;
int n;

void calc()
{
	int i, j;
	for(i=0; i<Q; i++){
		for(j=L[i]; j<R[i]; j+=D){
			res[i] += abs(x[j+D]-x[j]) + abs(y[j+D]-y[j]);
		}
	}
}

void addTree(int ii, int jj, int vv)
{
	int j = jj+n2;
	while(j>=1){
		Tree[ii][j] += vv;
		j /= 2;
	}
}

void pre()
{
	int i, j;
	n = (W*H-1)/D+1;
	n2 = 1;
	while(n2<n)
		n2 *= 2;
	for(j=0; j<n2; j++){
		///Left[j] = Right[j] = j;
		Left[n2+j] = Right[n2+j] = j;
	}
	for(j=n2-1; j>=1; j--){
		Left[j] = Left[2*j];
		Right[j] = Right[2*j+1];
	}
	for(i=0; i<50; i++){
		for(j=0; j<n2-2; j++){
			addTree(i, j, abs(x[j*D+i]-x[(j+1)*D+i])+abs(y[j*D+i]-y[(j+1)*D+i]));
		}
		if((j+1)*D+i <= W*H)
			addTree(i, j, abs(x[j*D+i]-x[(j+1)*D+i])+abs(y[j*D+i]-y[(j+1)*D+i]));
	}
}

int srch(int ii, int nd, int ll, int rr)
{
	if(Left[nd]>=ll && Right[nd]<=rr)
		return Tree[ii][nd];
	if(Left[nd]>rr || Right[nd]<ll)
		return 0;
	return srch(ii, 2*nd, ll, rr) + srch(ii, 2*nd+1, ll, rr);
}

void calc2()
{
	int i;
	for(i=0; i<Q; i++){
		int ii = L[i] % D;
		if(L[i] == R[i])
			res[i] = 0;
		else
			res[i] = srch(ii, 1, L[i]/D, R[i]/D-1);
	}
}

void solve()
{
	int i, j;
	for(i=0; i<H; i++){
		for(j=0; j<W; j++){
			x[A[i][j]] = i;
			y[A[i][j]] = j;
		}
	}
	if(D>=50){
		calc();
	}
	else{
		pre();
		calc2();
	}
	for(i=0; i<Q; i++)
		printf("%d\n", res[i]);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	int i, j;
	scanf("%d%d%d", &H, &W, &D);
	for(i=0; i<H; i++)
		for(j=0; j<W; j++)
			scanf("%d", &A[i][j]);
	scanf("%d", &Q);
	for(i=0; i<Q; i++)
		scanf("%d%d", &L[i], &R[i]);
	solve();
	return 0;
}

Measured memory_bytes: 59392
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int n, k, ans;
    ans = 0;
    cin >> n >> k;
    rep(i,n){
        int h;
        cin >> h;
        if(h >= k)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
def main():
	# a,b,k = map(int,input().split())
	n,k = map(int,input().split())
	# s = str(input())
	a = list(map(int,input().split()))
	rsp = list(str(input()))
	# l = [list(map(int, input().split())) for _ in range(n-1)]
	# s = list(s)
	ans = 0
	jan = []
	for i in range(n):
		# print("---i = {}---".format(i))
		if i < k:
			if rsp[i] == "r":
				ans += a[2]
				jan.append("p")
			elif rsp[i] == "s":
				ans += a[0]
				jan.append("r")
			elif rsp[i] == "p":
				ans += a[1]
				jan.append("s")
		elif rsp[i] == "s" and jan[i-k] == "r":
			jan.append("z")
		elif rsp[i] == "r" and jan[i-k] == "p":
			jan.append("z")
		elif rsp[i] == "p" and jan[i-k] == "s":
			jan.append("z")
		else:
			if rsp[i] == "s":
				ans += a[0]
				jan.append("r")
			elif rsp[i] == "r":
				ans += a[2]
				jan.append("p")
			elif rsp[i] == "p":
				ans += a[1]
				jan.append("s")
		# print(jan)
		# print(len(jan))
	
	print(ans)

	
 
 
if __name__ == '__main__':
	main()

Measured memory_bytes: 51980
import java.util.*;
import java.util.HashMap;

public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		int k=sc.nextInt();
		
		if(k<=1){
			System.out.println(0);
			System.exit(0);
		}
		
		int[] a=new int[n];
		
		
		int tmp1=0;
		for(int i=0;i<n;i++){
			a[i]=(sc.nextInt()+tmp1-1)%k;
			if(a[i]<0)a[i]+=k;
			tmp1=a[i];
			//System.out.println(a[i]);
		}
		
		
        long ans=0;
		
		HashMap<Integer, Integer> map=new HashMap<Integer, Integer>();
		
		for(int i=0;i<n;i++){
			if(!map.containsKey(a[i])){
				map.put(a[i], 0);
			}
			ans+=map.getOrDefault(a[i],0);
			map.put(a[i], map.get(a[i])+1);
			if(i>=k-1){
				map.put(a[i-k+1], map.get(a[i-k+1])-1);
			}else{
				if(a[i]==0)ans++;
			}
		}	
			
			
		System.out.println(ans);
	}
}
		
	

Measured memory_bytes: 87904
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
long long fact[210000];
long long finv[210000];
long long inv[210000];
long long C(int a,int b){
	if(a<b||b<0)return 0;
	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<210000;i++)
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	for(int i=1;i<210000;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
	long long ret=0;
	for(int i=1;i<a;i++){
		long long ks=(long long)b*b*(a-i)%mod*i%mod;
		ret=(ret+ks)%mod;
	}
	for(int i=1;i<b;i++){
		long long ks=(long long)a*a*(b-i)%mod*i%mod;
		ret=(ret+ks)%mod;
	}
	ret=ret*C(a*b-2,c-2)%mod;
	printf("%lld\n",ret);
}


Measured memory_bytes: 5120
n,k=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
T=list(T)

ans=0

for i in range(k):
  if T[i]=="r":ans+=P
  elif T[i]=="s":ans+=R
  else:ans+=S

for i in range(k,n):
  if T[i]==T[i-k]:T[i]="a"
  else:
    if T[i]=="r":ans+=P
    elif T[i]=="s":ans+=R
    else:ans+=S

print(ans)

Measured memory_bytes: 4084
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	int N;
	cin >> N;

	vector<int> A(N, 0);
	vector<int> B(N, 0);
	vector<int> C(N - 1, 0);

	for (int i = 0; i < A.size(); i++) {
		cin >> A[i];
	}

	for (int i = 0; i < B.size(); i++) {
		cin >> B[i];
	}

	for (int i = 0; i < C.size(); i++) {
		cin >> C[i];
	}

	long long ans = 0;

	for (int i = 0; i < A.size(); i++) {
		ans += B[A[i] - 1];
		if ((i + 1) != A.size() && (A[i] + 1) == A[i + 1]) {
			ans += C[A[i] - 1];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  ll i,A,B,K,ans;
  cin>>A>>B>>K;
  set<ll> se;
  rep(i,K){
    se.insert(A+i);
    se.insert(B-i);
  }
  for(auto x:se){
    if(A<=x&&x<=B){
      cout<<x<<endl;
    }
  }
  return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int K;
    cin >> K;
    
    ll ans = 0;
    for(int i = 1;i <= K;i++) if(i%2==0) ans++;
    if(K%2==0) cout << ans * ans << endl;
    else cout << ans * (ans + 1) << endl;


}


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

int main() {
	short x, y;
  	cin >> x >> y;
  	for (short i = x; i >= 0; i--) {
    	if (2 * (x - i) + 4 * i == y) {
        	cout << "Yes";
          	return 0;
        }
    }
  	cout << "No";
  	return 0;
}

Measured memory_bytes: 3616
def update(l, r, v):
    L = l + N0; R = r + N0
    while L < R:
        if R & 1:
            R -= 1
            data[R-1] = v

        if L & 1:
            data[L-1] = v
            L += 1
        L >>= 1; R >>= 1
# a_iの現在の値を取得
def _query(k):
    k += N0-1
    s = INF
    while k >= 0:
        if data[k]:
            s = max(s, data[k])
        k = (k - 1) // 2
    return s
# これを呼び出す
def query(k):
    return _query(k)[1]

from bisect import bisect_left
from sys import stdin

if __name__ == '__main__':
    n, q = map(int, stdin.readline().rstrip().split())
    stx = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n)]
    l = [int(stdin.readline().rstrip()) for _ in range(q)]

    INF = (-1, 2**31-1)
    N = len(l)
    N0 = 2**(N-1).bit_length()
    data = [None]*(2*N0)

    stx.sort(key=lambda x:x[2], reverse=True)
    for i, (s, t, x) in enumerate(stx):
        i1 = bisect_left(l, s - 0.5 - x)
        i2 = bisect_left(l, t - 0.5 - x)
        update(i1, i2, (i, x))

    for i in range(q):
        tmp = query(i)
        if tmp == INF[1]:
            print(-1)
        else:
            print(tmp)


Measured memory_bytes: 119132
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
char s[MAXN];
int L;
void Solve() {
    scanf("%s",s + 1);
    L = strlen(s + 1);
    if(s[1] == s[L]) {
	--L;
	if(L & 1) puts("First");
	else puts("Second");
    }
    else {
	if(L & 1) puts("First");
	else puts("Second");
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main(){   
   int n;
   cin>>n;
   vector<int>a(n);
   int sum=0;
   rep(i,n){
      cin>>a[i];
      sum+=a[i];
   }
   vector<int>::iterator iter=max_element(a.begin(),a.end());
   int index=distance(a.begin(),iter);
   index=a[index];
   ((sum -  index) > index)? cout<<"Yes":cout<<"No";

  
   

return 0;
}

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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}

int main(){
    int a = read(), b = read(), c = read();
    swap (a, b);
    swap (a, c);
    cout << a << ' ' << b << ' ' << ' ' << c << endl;
    return 0;
}

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

int a[105];

int main()
{
    int n;

    scanf("%d",&n);

    for (int i = 0;i < n;i++)
        scanf("%d",a+i);

    int sum = 0;

    for (int i = 0;i < n;i++)
    {
        sum += a[i];
    }

    sort(a,a+n);

    if (sum % 10) printf("%d\n",sum);
    else
    {
        bool f = 0;
        int maxn = 0;
        int cnt = -1;

        while (1)
        {
            if (cnt != -1) sum -= a[cnt];

            for (int i = cnt + 1;i < n;i++)
            {
                if ((sum - a[i]) % 10)
                {
                    maxn = sum - a[i];
                    f = 1;
                    break;
                }
            }

            if (f) break;
            else
            {
                cnt++;
            }

            if (cnt >= n) break;
        }

        if (f) printf("%d\n",maxn);
        else printf("0\n");
    }



    //printf("%d",b[n-1]);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N, K;
int A[500];

int main() {
	cin >> N >> K;
	REP(i, N) scanf("%d", A + i);
	
	int sum = accumulate(A, A + N, 0);
	
	vector<int> divisor;
	for (ll i = 1; i * i <= sum; i++) if (sum % i == 0) {
		divisor.push_back(i);
		if (i * i != sum) divisor.push_back(sum / i);
	}
	sort(ALL(divisor), greater<int>());
	
	for (int x : divisor) {
		ll cntn = 0, cntp = 0;
		vector<int> v;
		REP(i, N) v.push_back(A[i] % x);
		sort(ALL(v), greater<int>());
		
		cntn = accumulate(ALL(v), 0);
		bool ok = cntn <= K, ans = cntn % x == 0;
		REP(i, N) {
			cntn -= v[i];
			cntp += x - v[i];
			if (cntn <= K && cntp <= K) ok = true;
		}
		
		if (!ok) ans = false;
		
		if (ans) {
			cout << x << endl;
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
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 FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, y;
    cin >> n >> y;
    y /= 1000;

    REP(i,n+1) REP(j,n+1){
        int s = y - 10 * i - 5 * j;
        if (i + j + s == n && s >= 0){
            cout << i << " " << j << " " << s << endl;
            return 0;
        }
    }
    cout << "-1 -1 -1" << endl;

    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

class Main {
public:
    Main() {
        int N;
        cin >> N;
        int a = 11;
        REP(i, N) {
            while (true) {
                bool ok = true;
                for (int j = 3; j * j <= a; j += 2) {
                    if (a % j == 0) {
                        ok = false;
                        break;
                    }
                }
                if (ok) break;
                a += 10;
            }
            cout << a << endl;
            a += 10;
        }
    }
};

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

    Main ans;

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> vp(n);
	rep(i, n){
		int a, b;
		cin >> a >> b;
		vp.at(i) = make_pair(a, b);
	}
	sort(vp.begin(), vp.end());
	int index = 0;
	ll ans = 0;
	while(m > 0){
		if(vp.at(index).second <= m){
			ans += (ll)vp.at(index).first * vp.at(index).second;
			m -= vp.at(index).second;
		}else{
			ans += (ll)vp.at(index).first * m;
			m -= m;
		}
		index++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define mod 1000000007 
#define check exit(0)
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
using namespace __gnu_pbds;
using namespace std;
 
int main()
{
    jaldi
    int n,m;
    cin>>n>>m;
    vector<int> v(n,-1);
    for(int i=0;i<m;i++)
    {
        int l,d;
        cin>>l>>d;
        if(d==0 && l==1 && n!=1)
        {
            cout<<-1;
            return 0;
        }
        if(v[l-1]==-1) v[l-1]=d;
        else if(v[l-1]==d) continue;
        else
        {
            cout<<-1;
            return 0;
        }
    }
    if(v[0]==-1) if(n!=1) v[0]=1;
    for(int x:v) 
    {
        x==-1?cout<<0:cout<<x;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void fix_cout(){cout << fixed << setprecision(20) ;}
//void chmin(ll &a,ll b){if(a>b) a = b ;}

int main(){
	ll n,m,d,k ;
	cin >> n >> m >> d ;
	if(d==0) k = n ;
	else k = 2*(n-d) ;
	fix_cout() ;
	cout << (ld)k*(m-1)/n/n << endl ;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>

using namespace std;

bool visited[100001];
vector<int> E[100001];
int black=0,white=0;

bool isBlack(int v){
    visited[v]=true;
    if(E[v].size()==1&&visited[E[v][0]]){
        ++black;
        return true;
    }
    bool hasBlack=false;
    for(int u:E[v])if(!visited[u])if(isBlack(u))hasBlack=true;
    if(hasBlack)++white;
    else ++black;
    return !hasBlack;
}

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

    REP(i,N-1){
        int a,b;cin>>a>>b;
        E[--a].push_back(--b);
        E[b].push_back(a);
    }
    fill_n(visited,N+1,false);
    isBlack(0);

    if(black>white){
        cout<<"First"<<endl;
    }else{
        cout<<"Second"<<endl;
    }



    return 0;
}

Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
#define ma 1e9

int main(){
  int n;cin>>n;
  vector<vector<int>> dp(3,vector<int>(n,0));
  for(int i=0;i<3;i++)cin>>dp[i][0];
  
  for(int i=1;i<n;i++){
    int a,b,c;cin>>a>>b>>c;
    dp[0][i]=a+max(dp[1][i-1],dp[2][i-1]);
    dp[1][i]=b+max(dp[0][i-1],dp[2][i-1]);
    dp[2][i]=c+max(dp[1][i-1],dp[0][i-1]);
  }
  
  cout<<max(max(dp[0][n-1],dp[1][n-1]),dp[2][n-1])<<endl;
}

Measured memory_bytes: 1792
object MainKt {
  @JvmStatic fun main(args:Array<String>) {
    val N=readLine()!!.toInt()
    val lr= (1..N).map {
      val arg=readLine()!!.split(" ").map(String::toLong)
      Pair(arg[0],arg[1])
    }
    println(lr.map{
      val (l,r)=it
      r-l+1
    }.fold(0L) {sum,ele->sum+ele})
  }
}

Measured memory_bytes: 36068