akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
int N, M;
int As[100005];
int Bs[100005];
vector<int> bsHeap;
int job_selected[100005];

// struct greaters_As{  
//     bool operator()(const long& a,const long& b) const{  
//         return As[a]>As[b];  
//     }  
// };  

struct fewers_Bs{  
    bool operator()(const long& a,const long& b) const{  
        return Bs[a]<Bs[b] || (Bs[a] == Bs[b] && As[a]>As[b]);  
    }  
};  

int find(int idx){
    if (job_selected[idx]==0)
        return idx;
    
    return job_selected[idx] = find(job_selected[idx]);
}

int main(){
    scanf("%d%d",&N,&M);
    for(int i = 1; i <= N; ++i){
        scanf("%d%d",&As[i],&Bs[i]);
        if(As[i]<=M)
            bsHeap.push_back(i);
    }

    make_heap(bsHeap.begin(), bsHeap.end(),fewers_Bs()); 
    int M1 = M;
    long long s = 0;
    for(int j = 0; j < M && bsHeap.size() > 0; ++j){
        int top = bsHeap.front();
        int count = 0;
        pop_heap(bsHeap.begin(), bsHeap.end(),fewers_Bs()); 
        bsHeap.pop_back(); 
        bool found = false;
        int i = As[top];
        while(i<=M){
            if(job_selected[i]==0){
                job_selected[i] = find(i+1);
                found = true;
                break;
            }
            i = find(i+1);
        }
        if(!found){
            j--;
        }else{
            s += Bs[top];
            // printf("%d\n",top);
        }
    }

    printf("%lld\n",s);

}

Measured memory_bytes: 4576
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define rep(i,n) for(int i=0;i<(n);i++)
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; }
typedef long long ll;
#define PI 3.14159265358979323846264338327950L
const int mod=1000000007,MAX=200005,INF=1<<30;

int main() {
  	string n;
  	cin>>n;
  
  	int size=n.length();
  
    int x[1000100];
  	ll ans=0;
  	
  	
  	for(int i=0;i<size;i++){
      	 x[i]=0;
     	 x[i]=n[i]-48;
      	 ans+=x[i];
    }
  
	

  	if(ans%9==0){
    	cout<<"Yes"<<endl;
    }

  	else{
    	cout<<"No"<<endl;
    }

}

Measured memory_bytes: 3724
import Data.List

solve :: [String] -> String
solve ss = concatMap (uncurry replicate) $ zip nums chars
  where
    chars = ['a'..'z']
    nums = foldl1 (zipWith min) $ map f ss
    f s = map (\c -> length $ filter (==c) s) chars

main :: IO ()
main = do
    _ <- getLine
    s <- lines <$> getContents
    putStrLn $ solve s

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main(){
    IOS;
    int n;
    cin>>n;
    int cnt[n]={0};
    for(int i=0;i<n-1;i++){
    	int x; cin>>x;
    	cnt[x-1]++;
    }
    for(int i=0;i<n;i++) cout<<cnt[i]<<endl;
}

Measured memory_bytes: 5224
n, m = map(int, input().split())
a = []
ans = 0
cnt = 0
for i in range(n):
    x, y = map(int, input().split())
    a.append([x, y])
a.sort()

for i in range(n):
    cnt += a[i][1]
    ans += a[i][0] * a[i][1]
    if cnt == m:
        break
    if cnt > m:
        ans -= abs(cnt - m) * a[i][0]
        break
print(ans)


Measured memory_bytes: 20064
#include <iostream>

main(){
  int dp[31], n;
  dp[0] = 0;
  for(int i=1;i<31;i++){
    if(i%2) dp[i] = dp[i-1] + dp[i-1] + 1;
    else dp[i] = dp[i-1] + dp[i-2] + 1;
  }
  while(std::cin >> n) std::cout << dp[n] << std::endl;
}

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

int main(void) {
  ios::sync_with_stdio(false);
  int S, W;
  cin >> S >> W;
  if (S <= W)
    cout << "unsafe" << endl;
  else
    cout << "safe" << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>

int main( void ){
    int x, y, a, t;
    scanf("%d %d", &x, &y);

    if(x < y){
        t = x;
        x = y;
        y = t;
    }

    for(;;){
        a = x % y;
        x = y;
        y = a;
        if(a == 0){
            break;
        }
    }
    printf("%d\n", x);

    return 0;
}



Measured memory_bytes: 2092
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    if (a < c && c < b) {
      os.println("Yes");
      return;
    }
    
    if (b < c && c < a) {
      os.println("Yes");
      return;
    }
    
    os.println("No");
  }
}

Measured memory_bytes: 23252
#include <iostream>
using namespace std;
bool kaibun(string s){
    int l=s.size();
    for(int i=0;i<l/2;++i){
        if(s[i]!=s[l-1-i]) return false;
    }
    return true;
}
int main(void){
    string s;
    cin>>s;
    int l=s.size();
    string s1=s.substr(0,l/2);
    string s2=s.substr((l+1)/2);
    bool b=(kaibun(s) && kaibun(s1));
    cout<<(b && kaibun(s2) ? "Yes":"No")<<endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
const ll MOD = 4000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

ll digit(ll n){
	string s=to_string(n);
	ll ret=0;
	for(int i=0;i<s.size();i++){
		ret+=(s[i]-'0');
		
	}
	
	return ret;
}


int main(){
	init();
	ll A,B;cin>>A>>B;string s;cin>>s;
	bool isOK=true;
	for(int i=0;i<s.size();i++){
		if(i==A){
			if(s[i]!='-'){
				isOK=false;
			}
		}else{
			//cout<<"y"<<endl;
			if('0'>s[i] or s[i]>'9')isOK=false;
		}
	}
	if(isOK)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


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

int main(){
  	int n;
  	cin >> n;
  	
  	rep(i,0,8){
		if(pow(2,i) > n){
          cout << pow(2,i-1) << endl;
          return 0;
        }
    }
      
    
  	return 0;
}

Measured memory_bytes: 256
import sys, collections, bisect, itertools, heapq, math, copy, string
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = SS()

    if S in string.ascii_uppercase:
        print('A')
    else:
        print('a')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10036
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef pair<int, int> P;

int n;
vector< vector<int> > graphlist(100100, vector<int>());
vector<int> avec(100100, 0);
vector<int> bvec(100100, 0);
vector< set<int> > colorlist(100100, set<int>());
vector<bool> visited(100100, false);

int main() {
    cin >> n;
    map<P, int> edge;
    for(int i = 0; i < n-1; ++i) {
        int aa, bb; cin >> aa >> bb; aa--; bb--;
        avec.at(i) = aa; bvec.at(i) = bb;
        graphlist.at(aa).emplace_back(bb);
        graphlist.at(bb).emplace_back(aa);
        edge[P(aa, bb)] = 0;
        edge[P(bb, aa)] = 0;
    }

    queue<int> que;
    que.push(0);
    while(!que.empty()) {
        int now = que.front();
        que.pop();
        visited.at(now) = true;
        int incolor = 1;
        for(int i = 0; i < graphlist.at(now).size(); ++i) {
            int next = graphlist.at(now).at(i);
            if(visited.at(next)) continue;
            if(colorlist.at(now).count(incolor) == 0) {
                colorlist.at(now).insert(incolor);
                colorlist.at(next).insert(incolor);
                edge[P(now, next)] = incolor;
                edge[P(next, now)] = incolor;
                incolor++;
                que.push(next);
            }else {
                incolor++;
                colorlist.at(now).insert(incolor);
                colorlist.at(next).insert(incolor);
                edge[P(now, next)] = incolor;
                edge[P(next, now)] = incolor;
                incolor++;
                que.push(next);
            }
        }
    }

    set<int> ans;
    for(int i = 0; i < n-1; ++i) {
        ans.insert(edge[P(avec.at(i), bvec.at(i))]);
    }

    cout << ans.size() << endl;
    for(int i = 0; i < n-1; ++i) {
        cout << edge[P(avec.at(i), bvec.at(i))] << endl;
    }
}

Measured memory_bytes: 33408
import java.util.Scanner;

public class Main{

  public static void main (String[] args){

    Scanner sc = new Scanner (System.in);

    int N = sc.nextInt();
    int D = sc.nextInt();
    
    int hani = D*2+1;
    
    int answer = N/hani;
    
    if (N%hani!=0){
      answer++;
    }
    
    System.out.println(answer);
  }
}

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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i, m, n) for(int i = (int)m; i < (int)n; i++)
typedef /*unsigned*/ long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n; cin >> n;
    vi h(n); rep(i,n) cin >> h[i];
    vi cost(n, 1000000000);

    for(int i = 0; i < n; i++){
        if(i == 0) cost[i] = 0;
        else if( i== 1) cost[i] = min(cost[0] + abs(h[1] - h[0]), cost[1]);
        else{
            cost[i] = min(cost[i], cost[i-1] + abs(h[i] - h[i-1])); 
            cost[i] = min(cost[i-2] + abs(h[i] - h[i-2]), cost[i] );
        }
    }
    cout << cost[n-1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> tree(n, vector<int>());
  rep(i, n-1){
    int from, to;
    cin >> from >> to;
    from--; to--;
    tree[from].push_back(to);
    tree[to].push_back(from);
  }

  set<int> s1, s2;
  queue<p> q;
  vector<bool> visited(n, false);
  bool iss1 = false;
  q.push({0, iss1});
  // visited[0] = true;
  // for(auto a : tree[0]){
  //   q.push(a);
  // }
  s1.insert(0);
  while(!q.empty()){
    int now = q.front().first;
    iss1 = q.front().second;
    q.pop();
    visited[now] = true;
    for(auto a : tree[now]){
      if(visited[a]) continue;
      q.push({a, !iss1});
      if(iss1) s1.insert(a);
      else s2.insert(a);
    }
  }

  if(s1.size() < s2.size()){
    swap(s1, s2);
  }

  map<int, int> res;
  vector<bool> used(n+1, false);
  if(int(s2.size()) <= n/3){
    int tmp = 3;
    for(auto a : s2){
      res[a] = tmp;
      used[tmp] = true;
      tmp += 3;
    }
    tmp = 1;
    for(auto a : s1){
      res[a] = tmp;
      used[tmp] = true;
      tmp++;
      if(tmp < n && used[tmp]) tmp++;
    }
    for(auto a : res){
      cout << a.second << ' ';
    }
    cout << endl;
    return 0;
  }

  int tmp = 1;
  bool flag = false;
  for(auto a : s1){
    if(tmp > n || flag){
      flag = true;
      if(tmp % 3 != 0) tmp = 3;
      if(tmp > n){
        cout << -1 << endl;
        return 0;
      }
      res[a] = tmp;
      used[tmp] = true;
      tmp += 3;
    }else{
      res[a] = tmp;
      used[tmp] = true;
      tmp += 3;
    }
  }

  // print(res);
  tmp = 2;
  for(auto a : s2){
    res[a] = tmp;
    used[tmp] = true;
    for (; tmp <= n; tmp++) {
      if(!used[tmp]) break;
    }
  }

  for(int i = 0; i < n-1; i++){
    cout << res[i] << ' ';
  }
  cout << res[n-1] << endl;

}


Measured memory_bytes: 31728
n,m = map(int,input().split())


a = list(map(int,input().split()))

a_sum = sum(a)
judge = a_sum/(4*m)

count = 0
for i2 in [i for i  in a if i >= judge]:
  count+=1

if count >= m:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9168
#include <iostream>
using namespace std;
using ll = long long;

ll gcd(ll a, ll b) {
  if (min(a, b) == 0) {
    return max(a, b);
  }
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}

bool solve(ll a, ll b, ll c, ll d) {
  if (a < b) {
    return false;
  }
  if (b > d) {
    return false;
  }
  if (b <= c) {
    return true;
  }
  ll g = gcd(b, d);
  if (b - g + a % g > c) {
    return false;
  }
  return true;
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if (solve(a, b, c, d)) {
      cout << "Yes" << '\n';
    } else {
      cout << "No" << '\n';
    }
  }
  return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int main()
{
	int n,m;
	cin >> n >> m;
	vvi v(110,vi(110,INF)),vv;
	rep(i,m){
		int a,b,c;
		cin >> a >> b >> c;
		v[a-1][b-1] = v[b-1][a-1] = c;
	}
	vv = v;
	for(int k = 0; k < n; k++){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				v[i][j] = min(v[i][j],v[i][k]+v[k][j]);
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(vv[i][j] == INF) continue;
			if(v[i][j] != vv[i][j]) ans++;
		}
	}
	cout << ans/2 << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
 
int main() {
  
  int X;
  cin >> X;

  long long ans = 0;
  ans += X/500 * 1000;
  X -= X/500*500;

  ans += X/5*5;
  cout << ans << endl;


}


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

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int par[20000];
int Rank[20000];

void init(int n){
    rep(i,n){
        par[i]=i;
        Rank[i]=0;
    }
}

int find(int x){
    if(par[x]==x) {
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}

void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    
    if(Rank[x]<Rank[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(Rank[x]==Rank[y])Rank[x]++;
    }
}



int main(){
	int n;
	while(cin>>n){
		if(n==0)break;

		pii data[200][200];
		rep(i,n){
			rep(j,n){
				int a,b;
				cin>>a>>b;
				data[i][j]=make_pair(a,b);
			}
		}

		init(20000);

		rep(i,n){
			rep(j,n){
				unite( n*i+j , n*data[i][j].second+data[i][j].first );
			}
		}
		bool used[20000]={};
		int c=0;
		rep(i,n)rep(j,n)used[ find(n*i+j) ]=true;
		rep(i,20000)if(used[i])c++;
		cout<<c<<endl;
	}
}

Measured memory_bytes: 1652
n=int(input())
R=sorted([list(map(int,input().split())) for i in range(n)], key=lambda R: -R[1])
B=sorted([list(map(int,input().split())) for i in range(n)])
ans=0
for c,d in B:
  for a,b in R:
    if a<c and b<d:
      R.remove([a,b]);ans+=1
      break
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdbool.h>

int main() {
	int i, n, a[200], count = -1;
	bool flag = false;

	scanf("%d", &n);

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

	while (flag == false) {
		for (i = 0; i < n; i++) {
			if (a[i] % 2 == 0) {
				a[i] /= 2;
				
			} else{
				flag = true;
				break;
			}
		}
		count++;;
	}
	
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		int n = Integer.parseInt(str);
		for (int i = 0; i < n; i++) {
			str = br.readLine();
			double[] locate = new double[6];
			String[] locatestr = str.split(" ");
			for (int j = 0; j < 6; j++) {
				locate[j] = Double.parseDouble(locatestr[j]);
			}
			double sub21x = locate[2] - locate[0];
			double sum21x = locate[2] + locate[0];
			double sub21y = locate[3] - locate[1];
			double sum21y = locate[3] + locate[1];
			double sub32x = locate[4] - locate[2];
			double sum32x = locate[4] + locate[2];
			double sub32y = locate[5] - locate[3];
			double sum32y = locate[5] + locate[3];
			double[] ans = Simultaneous(2 * sub21x, 2 * sub21y, sub21x * sum21x
					+ sub21y * sum21y, 2 * sub32x, 2 * sub32y, sub32x * sum32x
					+ sub32y * sum32y);
			Radius(ans[0], ans[1], locate[0], locate[1]);
		}
	}
	public static void Radius(double xp, double yp, double x1, double y1) {
		DecimalFormat df = new DecimalFormat("0.000");
		double radius = Math.pow((xp - x1) * (xp - x1) + (yp - y1) * (yp - y1),
				0.5);
		System.out.println(df.format(radius));
	}
	public static double[] Simultaneous(double a, double b, double c, double d,
			double e, double f) {
		DecimalFormat df = new DecimalFormat("0.000");
		double x = (double) (e * c - b * f) / (a * e - b * d);
		double y = (double) (a * f - c * d) / (a * e - b * d);
		System.out.print(df.format(x) + " " + df.format(y) + " ");
		double[] ans = { x, y };
		return ans;
	}
}

Measured memory_bytes: 26120
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
typedef mp::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n;i>0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;


int main()
{
    string s;
    cin>>s>>s;
    cout<<"A"<<s[0]<<"C\n";

    return 0;
}


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

using namespace std;
bool cmp(char a,char b){
	return a > b;
}

int main()
{
	string s,t;
	
	cin >> s;
	cin >> t;
	
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),cmp);
	
	if(s < t) 
	    cout << "Yes";
	else 
	    cout << "No";
	return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
import sys

input = sys.stdin.buffer.readline
n, m = map(int, input().split())
AB = []
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort(key=lambda x: [-x[0], -x[1]])
ans = 0
kouho = []
for d in range(1, m + 1):
    while AB and AB[-1][0] <= d:
        a, b = AB.pop()
        heappush(kouho, (-b, a))
    if kouho:
        p, q = heappop(kouho)
        ans += -p
print(ans)


Measured memory_bytes: 94556
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int M1,D1,M2,D2;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>M1>>D1>>M2>>D2;
	cout<<(M1!=M2)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int m[4] = {25, 10, 5, 1};

int main() {
  int n;
  cin >> n;
  int num = 0;
  int i= 0;

  num += n/m[i];

  while((n %= m[i++]) != 0) {
    num += n/m[i];
  }

  cout << num << endl;
}



Measured memory_bytes: 3124
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
		int n = sc.nextInt();
		long k = sc.nextLong();
		int[] a = new int[n];
		Long[] pass = new Long[n];

		long count = 0;
		int target = 1;
		for (int i = 1; i <= n; i++) {
			a[i - 1] = sc.nextInt();
			while (target <= i) {
				count++;
				if (Objects.nonNull(pass[target - 1])) {
					//すでに通った道だとしたらループしている。
					long loopCount = count - pass[target - 1];
					long last = (k - count) % loopCount;
					target = a[Arrays.asList(pass).indexOf(pass[target - 1] + last)];
					count = k;
				} else {
					pass[target - 1] = count;
					target = a[target - 1];
				}
				if (count == k) {
					break;
				}
			}
			if (count == k) {
				break;
			}
		}

		// 出力
		System.out.println(target);
		sc.close();
	}
}


Measured memory_bytes: 61160
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    string s, t;
    cin >> s>>t;
    bool flag = 0;
    for (int i = 0; i < s.size(); i++) {
        bool flag2 = 1;
        for (int j = 0; j <s.size(); j++) {
            if (t[j] != s[(j + i) % s.size()]) flag2 = 0;
        }
        if (flag2) flag = 1;
    }
    if (flag) cout << "Yes" << endl;
    else cout <<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

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

    cout << min(c, b/a) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
n = int(input())

if n % 2 != 0:
    print(0)
    sys.exit()

# nの階乗をpで何回割れるか
def solve(n, p):
    if n == 1 or n == 0:
        return 0
    return n//p + solve(n//p, p)

print(solve(n//2, 5))

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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define output(x) cout << ( x ? "YES" : "NO" ) << '\n' ;
#define N 1000005
using namespace std;
int n;
int lpf[N],mobius[N],a[N]; 
void least_prime_factor() 
{ 
    for (int i = 2; i < N; i++)  
        if (!lpf[i]) 
            for (int j = i; j < N; j += i) 
                if (!lpf[j]) 
                    lpf[j] = i; 
} 
void Mobius() 
{ 
    for (int i = 1; i < N; i++) {
        if (i == 1) 
            mobius[i] = 1; 
        else { 
            if (lpf[i / lpf[i]] == lpf[i]) 
                mobius[i] = 0;
            else
                mobius[i] = -1 * mobius[i / lpf[i]]; 
        } 
    } 
} 
  
int gcd_pairs() 
{ 
    int maxi = 0; 
    int fre[N] = { 0 };
    for (int i = 0; i < n; i++) { 
        fre[a[i]]++; 
        maxi = max(a[i], maxi); 
        // cout << "came";
    }
    least_prime_factor(); 
    Mobius();
    int ans = 0;
    for (int i = 1; i <= maxi; i++) { 
        if (!mobius[i]) 
            continue; 
  
        int temp = 0; 
        for (int j = i; j <= maxi; j += i) 
            temp += fre[j]; 
        ans += temp * (temp - 1) / 2 * mobius[i]; 
    } 
    return ans; 
} 
void solve(){
    cin >> n;
    int gc = -1;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(gc == -1)
            gc = a[0];
        gc = __gcd(gc,a[i]);
    }
    int val = gcd_pairs();
    if(val == ((n * (n - 1)) / 2)){
        cout << "pairwise coprime\n";
    }
    else if(gc == 1){
        cout << "setwise coprime\n";
    }
    else{
        cout << "not coprime\n";
    }
}

int32_t main()
{
    FLASH
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 34904
s = input()

n = len(s)

if n <= 2:
    print(n)
    exit()

g = [0] * n
g[0] = 1
if s[0] == s[1]:
    g[1] = 1
    g[2] = 2
elif s[1] == s[2]:
    g[1] = 2
    g[2] = 2
else:
    g[1] = 2
    g[2] = 3

for i in range(3, n):
    if s[i] == s[i-1]:
        g[i] = g[i-3] + 2
    else:
        g[i] = g[i-1] + 1

print(g[-1])

Measured memory_bytes: 11240
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define PI 3.14159265358979323846264338327950288
 
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;

bigint suffix[200005] ;
int main(){
    FAST_IO ;
    int N ; cin >> N ;
    bigint arr[N+3] ;
    for( int i = 0 ; i < N ; i++ )
        cin >> arr[i] ;
    suffix[N] = 0 ;
    for( int i = N - 1 ; i >= 0 ; i-- ){
        suffix[i] = (suffix[i+1] + arr[i]) % mod ;
    }
    bigint ans = 0 ;
    for( int i = 0 ; i < N ; i++ ){
        bigint c = (arr[i] % mod * suffix[i+1]) % mod ;
        ans = ( ans + c ) % mod ;
    }
    cout << ans << endl ;
    return 0 ;
    
}
 
 
 

Measured memory_bytes: 6768
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;

int main() {
  string a,b,c;cin>>a>>b>>c;
  cout << "A" << b[0] << "C" << endl;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<vector<int> > a(2, vector<int>(n));
    for (int i = 0; i < n; i++) cin >> a[0][i];
    for (int i = 0; i < n; i++) cin >> a[1][i];

    vector<vector<int> > dp(2, vector<int>(n, 0));

    dp[0][0] = a[0][0];
    dp[1][0] = a[0][0] + a[1][0];

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

}


Measured memory_bytes: 256
n, m, c = map(int, input().split())
B = list(map(int, input().split()))
num = 0
ans = 0
for i in range(n):
    A = list(map(int, input().split()))
    for j in range(m):
        num += A[j] * B[j]
    if num + c > 0:
        ans += 1
    num = 0
print(ans)

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

typedef long long ll;

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

	vector<pair<ll, ll>> v;
	for (int i = 0; i < N; i++) {
		ll x, l;
		cin >> x >> l;
		v.push_back(make_pair(x + l, x - l));
	}
	sort(v.begin(), v.end());

	int ans = 1;
	ll end = v[0].first;
	for (int i = 1; i < N; i++) {
		if (end <= v[i].second) {
			ans++;
			end = v[i].first;
		}
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if ((a + b) % 2 == 0) {cout << (a + b) / 2 <<endl;
                      }
  else {cout << (a + b) / 2 + 1 <<endl;
       }
       }

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

signed main() {
  int n,m;
  cin >> n >> m;

  if(n % 2 == 1) {
    for (int i = 1; i <= m; i++) {
      cout << i << " " << n - i + 1 << '\n';
    }
  } else {
    int add = 0;
    for (int i = 1; i <= m; i++) {
      if((n - i + 1) - i <= n/2) add = -1;
      cout << i << " " << n - i + 1 + add << '\n';
    }
  }
}


Measured memory_bytes: 3628
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx,avx2")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No");

    return 0;
}


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

using namespace std;

const int maxn =1e5 + 7;

int cnta[maxn][2], cntb[maxn][2], n;
string s[2];

int GetA(int u, int v, int type)
{
    return cnta[v][type] - cnta[u - 1][type];
}
int GetB(int u, int v, int type)
{
    return cntb[v][type] - cntb[u - 1][type];
}

int32_t main()
{
    auto start = chrono::steady_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
    for(int id = 0; id < 2; id++)
    {
        cin >> s[id];
        s[id] = ' ' + s[id];
        for(int i = 1; i < s[id].length(); i++)
        {
            cnta[i][id] = cnta[i - 1][id];
            cntb[i][id] = cntb[i - 1][id];
            if(s[id][i] == 'A') cnta[i][id]++;
            else cntb[i][id]++;
        }
    }
    int q;
    cin >> q;
    while(q--)
    {
        int a, b, u, v;
        cin >> a >> b >> u >> v;
        int r1 = (GetA(a, b, 0) - GetB(a, b, 0)) % 3;
        if(r1 < 0) r1 += 3;
        int r2 = (GetA(u, v, 1) - GetB(u, v, 1)) % 3;
        if(r2 < 0) r2 += 3;
        if(r1 != r2)
        {
            cout << "NO" << '\n';
        }
        else cout << "YES" << '\n';
    }
    auto finish = chrono::steady_clock::now();
}

Measured memory_bytes: 2412
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi A, B;
string S, T;

void input() {
  int x, y, z;
  ;
  cin >> S;
}
void solve() {
  int cnt = 0;
  rep(i, 0, S.size() - 2) {
    if (S[i] != S[i + 1]) {
      cnt++;
    }
  };
  cout << cnt << endl;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 512
# https://atcoder.jp/contests/abc119/tasks/abc119_c
import copy

def solve(t, l, c):
    # 長さ t の竹を L から少ないコストで作る方法を探す
    min_cost = 100000
    cand = []

    ptn = 1 << len(l)
    # print(l)
    # print("ptn = {}".format(ptn))
    for i in range(1, ptn):
        answers = []
        for j in range(0, len(l)):
            if (i >> j) & 1:
                answers.append(l[j])
        temp_cost = abs(t - sum(answers)) + (10 * (len(answers) - 1) if len(answers) > 1 else 0)
        if temp_cost < min_cost:
            min_cost = temp_cost
            cand = answers

    # print("cand = {}".format(cand))
    for d in cand:
        del l[l.index(d)]
    return min_cost, l

def main():
    N, A, B, C = map(int, input().split())
    L = [int(input()) for _ in range(N)]
    L.sort()

    answer = 1000000
    for targets in [[A, B, C], [A, C, B],[B, A, C],[B, C, A], [C,B,A],[C,A,B]]:
        is_done = [False] * 3
        L2 = copy.copy(L)
        total_cost = 0
        for i in range(len(targets)):
            if targets[i] in L2:
                del L2[L2.index(targets[i])]
                is_done[i] = True

        for i in range(3):
            if is_done[i]:
                continue

            # i の竹を L から少ないコストで作る方法を探す
            # print("try target = {}".format(targets[i]))
            cost, L2 = solve(targets[i], L2, 0)
            # print("cost = {}".format(cost))
            total_cost += cost

        answer = min(answer, total_cost)

    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while( true ) {
        int n;
        cin >> n;
        if( n == 0 ) break;

        for( int i = 0; i < n; ++i ) {
            int a, b, c;
            cin >> a >> b >> c;
            char cl = 'C';
            if( ( a + b + c ) / 3 >= 50 && ( a >= 80 || b >= 80 ) ) cl = 'B';
            if( ( a + b + c ) / 3 >= 70 ) cl = 'B';
            if( ( a + b + c ) / 3 >= 80 ) cl = 'A';
            if( ( a + b ) / 2 >= 90 ) cl = 'A';
            if( a == 100 || b == 100 || c == 100 ) cl = 'A';
            cout << cl << endl;

        }
    }

    return 0;
}





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

int main(){
  int n, coin = 17, num = 300;
  int ans[coin + 1][num];

  for(int i=1; i<=coin; i++)
    ans[i][0] = 1;

  for(int i=1; i<=coin; i++)
    for(int j=1; j<num; j++){
      if(j < i*i)
	ans[i][j] = ans[i-1][j];
      else{
	ans[i][j] = ans[i-1][j] + ans[i][j-i*i];
      }
    }

  while(cin >> n && n)
    cout << ans[17][n] << endl;

  return 0;
}

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

using namespace std;

int main()
{
    string S, T;
    cin >> S >> T;

    int size = S.size(), possible = false;
    for(int r = 0; r < size; r++)
    {
        int matching = true;

        for(int i = 0; i < size; i++)
        {
            if(T[i] != S[(i + r)%size])
                matching = false;
        }

        if(matching) possible = true;
    }

    cout << (possible ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string str;
  cin>>str;
  int count=0;
  int i=0;
  int j=str.size()-1;
  while(i<j)
  {
    if(str[i]==str[j]);
    else
      count++;
    i++;
    j--;
  }
  printf("%d\n",count);
  
  return 0;
}

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

int main() {
	long long int N, e[1000000] = { 0 }, t = 1, x, y;
	scanf("%lld", &N);
  	long double ne = (long double)N;
	long long int n = (long long int)sqrt(ne);
	for (long long int i = 1; i <= n; i++) {
		if (N % i == 0) {
			e[t] = i;
			t++;
		}
	}
	x = e[t-1];
	y = N / x;
	printf("%lld", x + y - 2);
	return 0;
}

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

int main(){

  long N,A,B;
  long c;

  cin >> N >> A >> B;
  c = N/(A+B);

  if( N - c*(A+B) >= A){
    cout << c*A + A << endl;
  }else{
    cout << c*A + (N - c*(A+B)) << endl;
  }
  
  }



Measured memory_bytes: 256
H = 3
W = 3
C = []
for _ in range(H):
    C.append([int(i) for i in input().split()])


Hs = [[] for _ in range(H)]
for i in range(H):
    Hs[i].append(C[i][0] - C[i][1])
    Hs[i].append(C[i][1] - C[i][2])
    Hs[i].append(C[i][2] - C[i][0])

Ws = [[] for _ in range(H)]
for i in range(H):
    Ws[i].append(C[0][i] - C[1][i])
    Ws[i].append(C[1][i] - C[2][i])
    Ws[i].append(C[2][i] - C[0][i])

if all([Hs[0] == h for h in Hs]) and all([Ws[0] == w for w in Ws]):
    print("Yes")
else:
    print("No")


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

using ll = long long;

//constant
const ll MOD = 1e+9 + 7;
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }


// ***************************************


int main(void) {

	string S;
	cin >> S;

	vector<int> dp(2);
	dp[1] = 1;

	for (auto c : S) {
		int num = c - '0';

		int a = min(dp[0] + num, dp[1] + 10 - num);
		int b = min(dp[0] + num + 1, dp[1] + 10 - (num + 1));
		dp = { a, b };
	}

	cout << dp[0] << endl;
	


	return 0;
}

Measured memory_bytes: 1412
function Main(input) {
    input = input.split("\n");
  	var a = parseInt(input[0], 10);
    var b=Math.floor(a/500);
  	var c=Math.floor((a%500)/5);
  	console.log(b*1000+c*5);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if (s<t) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
} 


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

int main() {
    string S;
    int ans = 0;
    cin >> S;
    rep(i, S.size()) {
        if (S[i] == '+')
            ans++;
        else
            ans--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from fractions import *
while True:
	s=input()[::-1]
	if s=='#':break
	if s[0]=='h':
		angle=Fraction(0)
		cnt=5
	else:
		angle=Fraction(90)
		cnt=4
	i=1
	while cnt<len(s):
		if s[cnt]=='h':
			angle-=Fraction(90/2**i)
			cnt+=5
		else:
			angle+=Fraction(90/2**i)
			cnt+=4
		i+=1
	print(angle)

Measured memory_bytes: 10068
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

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

int main() {
	int N;
	cin >> N;
	vector<pair<int, int>> P(N);

	REP(i, N) {
		int tmp;
		cin >> tmp;
		P[i] = make_pair(tmp, i);
	}
	sort(P.begin(), P.end());

	int cnt = 1;
	int max_cnt = 1;
	REP(i, N) {
		if (P[i].second < P[i + 1].second) {
			cnt++;
		}
		else {
			max_cnt = max(max_cnt, cnt);
			cnt = 1;
		}
	}

	cout << N - max_cnt << endl;

	/*
	int num_front = 1;
	int num_back = 1;

	REP(i, N - 1) {
		if (P[i].second < P[i + 1].second) {
			num_front++;
		}
		else {
			break;
		}
	}
	REP(i, N - 1) {
		if (P[N - 1 - i].second > P[N - 2 - i].second) {
			num_back++;
		}
		else {
			break;
		}
	}

	cout << min(N - num_front, N - num_back) << endl;
	*/

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int64_t n; cin >> n;
	vector<int64_t> as(n);
	FOR_LT(i, 0, n) {
		cin >> as[i];
	}

	vector<int64_t> sums(n);
	int64_t sum = 0;
	FOR_LT(i, 0, n) {
		sum += as[i];
		sums[i] = sum;
	}

	auto it = lower_bound(sums.begin(), sums.end(), sum/2);
	int64_t ans = abs((sum - *it) - *it);
	if (it + 1 != sums.end()) {
		auto it2 = it + 1;
		ans = min(ans, abs((sum - *it2) - *it2));
	}
	if (it != sums.begin()) {
		auto it2 = it - 1;
		ans = min(ans, abs((sum - *it2) - *it2));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

int main(){
  ll n, k;  cin >> n  >> k;
  vector<ll> a(n);

  for(int i=0; i<n; i++)  cin >> a.at(i);
  ll rc=0, lc=0, ans=0;
  for(int i=0; i<n; i++){
    rc=0, lc=0;
    for(int j=i; j<n; j++){
      if(a[i]>a[j]) rc += 1;
      rc %= MOD;
    }
    for(int j=0; j<n; j++){
      if(a[i]<a[j]) lc += 1;
      lc %= MOD;
    }
    ans += rc*k%MOD;
    ans += k*(k-1)/2%MOD*lc%MOD;
    ans %= MOD;
  }
  // for(int i=n-1; 0<=i; i--){
  //   for(int j=n-1; 0<=j; j--)
  //     if(a[j]>a[i]) lc += 1;
  //     lc %= MOD;
  // }
  // ll ans, buff=(k+1)*k/2%MOD, bet=
  // ans = rc*buff%MOD + lc*bet%MOD;

  cout << ans << endl;
}


Measured memory_bytes: 256
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    X = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = (X//500)*1000+((X%500)//5)*5
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


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

int main()
{
    int x,y,a;
    int w,h,n;
    scanf("%d %d %d", &w, &h, &n);
    int grid[h][w];
    std::fill(grid[0], grid[0]+w*h, 1);

    while(scanf("%d %d %d", &x, &y, &a)!=EOF)
    {
        switch(a){
        case 1:
            for(int i=0; i<h; i++)
                for(int j=0; j<x; j++){
                    grid[i][j]=0;
                }
            break;
        case 2:
            for(int i=0; i<h; i++)
                for(int j=x; j<w; j++){
                    grid[i][j]=0;
                }
            break;
        case 3:
            for(int i=0; i<y; i++)
                for(int j=0; j<w; j++){
                    grid[i][j]=0;
                }
            break;
        case 4:
            for(int i=y; i<h; i++)
                for(int j=0; j<w; j++){
                    grid[i][j]=0;
                }
            break;
        }
        
    }

    int count=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(grid[i][j]==1) count++;
        }
    }
    std::cout<<count<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    int N, M;
    cin >> N >> M;
    vint A(M), C(M);
    rep(i, M) {
        int B;
        cin >> A[i] >> B;
        rep(j, B) {
            int c;
            cin >> c;
            C[i] |= (0x01 << (c - 1));
        }
    }
    vll dp((1 << N) + 1, LINF);
    dp[0] = 0;
    REP(i, 0, (1 << N)) {
        if (dp[i] == LINF) continue;
        rep(j, M) {
            dp[i | C[j]] = min(dp[i | C[j]], dp[i] + A[j]);
            //if (dp[i | C[j]] != -1)
            //    dp[i | C[j]] = min(dp[i | C[j]], dp[i] + A[j]);
            //else
            //    dp[i | C[j]] = A[i];
        }
    }
    if (dp[(1 << N) - 1] == LINF)
        cout << -1 << endl;
    else
        cout << dp[(1 << N) - 1] << endl;
    //cout << N << endl;
    return 0;
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio
    st s [3] ;
    loopcin( 3 , s) ;
    lli len1 = s[0].size() ,len2 = s[1].size() ;
    (s[0][len1 - 1] == s[1][0] && s[1][len2 - 1] == s[2][0] ? YES : NO ) ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256