akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    // 整数の入力
    int n;
    cin >> n;

    vector<int> d;
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;

        d.push_back(t);
    }

    //昇順
    sort(d.begin(), d.end());

    int cnt = 0;

    for(int i = 0; i < n - 1; i++){
       if(d[i] < d[i + 1]){
           cnt++;
       }
    }
    
    // 出力
    cout << cnt + 1 << endl;
    return 0;
}

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

int main()
{
    int h,w ; 
    cin>>h>>w ; 
    
    ll dp[h][w] ; 
    char grid[h][w] ; 
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>grid[i][j] ;
        }
    }
    
    memset(dp,0,sizeof(dp)); 
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(grid[i][j]=='#')
            dp[i][j]=-1 ; 
        }
    }
    
    int mod=1e9+7 ; 
    int k=h+1; 
    for(int i=0;i<h;i++){
        if(grid[i][0]=='.')
        dp[i][0]=1 ; 
        else{
            dp[i][0]=-1 ; 
            k=i ; 
            break ; 
        }
    }
    
    for(int i=k+1;i<h;i++){
        dp[i][0]=-1 ;
    }
    
    k=w+1 ; 
    for(int j=0;j<w;j++){
        if(grid[0][j]=='.')
        dp[0][j]=1 ; 
        else{
            dp[0][j]=-1 ; 
            k=j ;
            break ; 
        }
    }
    
    for(int j=k+1;j<w;j++){
        dp[0][j]=-1 ;
    }
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(grid[i][j]=='#')
            dp[i][j]=-1 ; 
        }
    }

    for(int i=1;i<h;i++){
        for(int j=1;j<w;j++){
        
          if(dp[i][j]!=0)
          continue ; 
          
          if(grid[i-1][j]!='#' && dp[i-1][j]!=-1)
            dp[i][j]+=dp[i-1][j]%mod ; 
           
          if(grid[i][j-1]!='#' && dp[i][j-1]!=-1)
            dp[i][j]+=dp[i][j-1]%mod ; 
            
          if(dp[i-1][j]==-1 && dp[i][j-1]==-1){
              dp[i][j]=-1 ; 
          }
          
        }
    }
    
    if(dp[h-1][w-1]!=-1)
    cout<<dp[h-1][w-1]%mod ; 
    else
    cout<<0 ; 
    
    return 0;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back 
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	string s;
	cin >> s;
	if(s.length() < 3){
		cout << 0 << '\n';
		return 0;
	}
	ll ans = n * (n - 1) * (n - 2) / 6;
	map<char, vector<int> > col;
	col['R'] = col['G'] = col['B'] = vector<int>(n + 1);
	for(int i = n - 1; i >= 0; i--){
		col['R'][i] = col['R'][i + 1];
		col['B'][i] = col['B'][i + 1];
		col['G'][i] = col['G'][i + 1];
		col[s[i]][i]++;
	}
	//cout << ans << '\n';
	for(int i = 0; i < s.length() - 2; i++){
		for(int j = i + 1; j < s.length() - 1; j++){
			int x = j - i;
			int k = j + x;
			if(s[i] == s[j]){
				ans -= n - (j + 1);
			}
			else {
				ans -= col[s[i]][j + 1];
				ans -= col[s[j]][j + 1];
				if(k < n && s[k] != s[i] && s[k] != s[j])
					ans--;
			}
			//cout << ans << '\n';
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
static const int MMAX=20;
static const int NMAX=50000;
static const int INFTY=(1<<29);


int main(){
	int n,m;
	cin>>n>>m;
	int c[21];
	int t[NMAX+1];
	for(int i=0;i<m;i++){
		cin>>c[i];
	}
	memset(t,9999999,sizeof(t));
	t[0]=0;
	for(int i=0;i<m;i++){
		for(int j=0;j+c[i]<=n;j++){
			t[j+c[i]]=min(t[j+c[i]],t[j]+1);
		}
	}
	cout<<t[n]<<endl;
} 


Measured memory_bytes: 3288
#include<bits/stdc++.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++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define INF 100000000

int calc(int a,int b);

int main(){
  int n;
  cin >> n;
  int ans;
  cin >> ans;
  rep(i,n-1){
    int a;
    cin >> a;
    ans = calc(ans,a); 
  }
  cout << ans << endl;
}

int calc(int a,int b){
  while(!(a % b == 0 || b % a == 0)){
    if(a > b) a %= b;
    else b %= a;
  }
  return min(a,b);
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{
    public static void main(String[] args){
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String[] s = br.readLine().split(" ");
            if(s[0].charAt(s[0].length() - 1) == s[1].charAt(0) && s[1].charAt(s[1].length() - 1) == s[2].charAt(0))
                System.out.println("YES");
            else
                System.out.println("NO");
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 22740
#K-th Common Divisor
A,B,K = gets.chomp.split(" ").map(&:to_i)
max = 0
ans = []
if A >= B
    max = A
else
    max = B
end

for i in 1..max
    if A % i == 0 && B % i == 0
        ans.push(i)
    end
end
puts ans[ans.length-K]

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

int main() {
    int n; cin >> n;
    vector<int> h(n, 0);
    for (int i = 0; i < n; i++) cin >> h[i];
    int pt = 0, ans = 0;
    while (pt < n) {
        int cur = pt;
        bool flag = false;
        while (cur < n && h[cur]) {
            h[cur] -= 1;
            cur++;
            flag = true;
        }
        while (pt < n && h[pt] == 0) {
            pt++;
        }
        ans += flag;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

unsigned int N,ans;
int main(void) {
  
  scanf("%d", &N);
  
  // 1桁ずつ取り出して合計する
  ans = 0;
  while(N > 10) {
    ans += (N % 10);
    N /= 10;
  }
  ans += N;
  
  printf("%d", ans);
  
  return 0;
}

Measured memory_bytes: 128
n,m=map(int,input().split())
mod=10**9+7
a=[]
for i in range(m):
    a.append(int(input()))
aa=set(a)
l=[0 for i in range(n+1)]
l[0]=1

for i in range(n):
    if i+1 not in aa:
        l[i+1]+=l[i]
        l[i+1]=l[i+1]%mod
    if i+2 not in aa and i+2<n+1:
        l[i+2]+=l[i]
        l[i+2]=l[i+2]%mod

print(l[n])

Measured memory_bytes: 13212
<?php
list($H, $W, $K) = ints();
for($i = 0; $i < $H; $i++){
  foreach(str_split(trim(fgets(STDIN))) as $v){
    $map[$i][] = boolval($v); 
  }
}
$min = 10**10;
for($i = 0, $I = 2**($H-1); $i < $I; $i++){
  $over = 0;
  $line[0] = 0;
  $ii = $i;
  for($j = 1; $j < $H; $j++){
    $line[$j] = $line[$j-1] + ($ii & 1);
    $ii >>= 1;
  }
  $groupCount = $line[$H-1]+1;
  $counts = array_fill(0, $groupCount, 0);
  $fromJ = 0;
  for($j = 0; $j < $W; ++$j){
    for($k = 0; $k < $H; ++$k){
      if($map[$k][$j])++$counts[$line[$k]];
    }
    if(max($counts) > $K){
      $counts = array_fill(0, $groupCount, 0);
      if($fromJ == $j)continue 2;
      $fromJ = $j;
      ++$over;
      --$j;
    }
  }
  chmin($min, $over + popcount($i));
}
echo $min;
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


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

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

ll lcm(ll a, ll b){
    return a * (b / gcd(a, b));
}

int main(){
    ll N,ans = 1;
    cin >> N;
    for(int i = 0; i < N; i++){
        ll tmp;
        cin >> tmp;
        if(ans % tmp != 0){
            ans = lcm(ans,tmp);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
data = [int(input()) for i in range(5)]
 
m = 0   # 最後の差分(diff)の最大値
res = 0 # 全ての調理時間を差分込みで集計した時間
for d in data:
    if d % 10 != 0:
        diff = 10 - d % 10
    else:
        diff = 0
    res += d + diff
    m = max(m,diff)
 
print(res-m)

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

using namespace std;

typedef long long ll;

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

const ll MOD = ll(1e9 + 7);

vector<int> A;

ll solve(const int N) {
    int counter_r = 0;
    int counter_g = 0;
    int counter_b = 0;
    ll acc = 1;

    for (const auto &a : A) {
        int num = 0;
        if (counter_r == a) num++;
        if (counter_b == a) num++;
        if (counter_g == a) num++;

        acc = (acc * num) % MOD;

        if (counter_r == a) {
            counter_r++;
        } else if (counter_b == a) {
            counter_b++;
        } else if (counter_g == a) {
            counter_g++;
        }
    }

    return acc;
}

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

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

    cout << solve(N) << endl;

    return 0;
}


Measured memory_bytes: 640
import java.util.*;
 
public class Main {
 
    static int array[];
    static int ans[];
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();     
        long ans = 0;
 
        for (int i = 1; i < n; i++) {
            ans += i;
        }
 
        System.out.println(ans);
 
        sc.close();
 
    }
 
}

Measured memory_bytes: 35844
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int a[10000000] = {};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    ll z = 0;
    cin >> n;
    for( int i = 1 ; i <= n ; i++ ) {
        for( int j = i ; j <= n ; j += i ) a[j]++;
    }
    for( int i = 1 ; i <= n ; i++ ) z += 1ll * i * a[i];
    cout << z;
}


Measured memory_bytes: 42684
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll a[200005];
ll s[200005];
int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i <n - k; i++) {
		if (a[i] < a[i + k]) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	
	return 0;
}

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

using namespace std;

using ll = long long;

int const maxn = 3030;

int a[maxn];
ll dp[maxn][maxn];

ll solve(int l, int r) {
    if (l == r) {
        return a[l];
    }

    ll& d = dp[l][r];

    if (d != -1) {
        return d;
    }

    d = max(a[l] - solve(l+1, r), a[r] - solve(l, r-1));

    return d;
}

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

    int n;
    cin >> n;

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

    memset(dp, -1, sizeof(dp));

    cout << solve(0, n-1) << "\n";
}

Measured memory_bytes: 72192
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"d,g=map(int,input().split())\n"
"l=[list(map(int,input().split()))for _ in range(d)]\n"
"for i in range(d):\n"
"    s=l[i][0]*100*-~i\n"
"    l[i].append(s+l[i][1])\n"
"    l[i].append(s)\n"
"a=10**18\n"
"for i in range(1<<d):\n"
"    s=t=k=0\n"
"    for j in range(d):\n"
"        if (i>>j)&1:\n"
"            s+=l[j][2]\n"
"            t+=l[j][0]\n"
"        else:\n"
"            k=j\n"
"    if s+l[k][3]<g:continue\n"
"    if s<g:\n"
"        t+=-(-(g-s)//(100*-~k))\n"
"    a=min(a,t)\n"
"print(a)\n"
"\"";
  system(s);
  return 0;
}            

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

int main() {
  int64_t x;
  cin >> x;
  int64_t ans = ceil(x / 5.5);
  if ( (x - 6) % 11 == 0 ) {
    ans -= 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define PREP(it,array) for(vector<P>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)

#define MP       make_pair
#define PB       push_back
#define ALL(x)   (x).begin(),(x).end()

const int INF = 1<<29;
const double EPS = 1e-9;
double zero(double d){
  return d < EPS ? 0.0 : d;
}

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

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

struct Sta{
  int ax,ay;
  int bx,by;
  int count;
};

int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);

  int X,Y;
  while( cin>>X>>Y, X ){
    int tx,ty;
    cin >>tx>>ty;

    int kx,ky;
    cin>>kx>>ky;

    bool dep[Y+1][X+1];
    REP(i,Y){
      REP(j,X){
	int ttt;
	cin >> ttt;
	dep[i+1][j+1] = ttt;
      }
    }

    bool used[X+1][Y+1][X+1][Y+1];
    memset( used, 0, sizeof(used) );

    queue<Sta> que;
    Sta s;
    s.ax = tx;
    s.ay = ty;
    s.bx = kx;
    s.by = ky;
    s.count = 0;
    que.push(s);

    int res=101;
    while( ! que.empty() ){
      Sta t = que.front(); que.pop();
      if( t.ax == t.bx && t.ay == t.by ){
	res = t.count;
	break;
      }

      if( t.count >= 100 ){
	break;
      }
	
      REP(i,4){
	Sta t2 = t;
	t2.count++;

	int nAx = t2.ax + dx[i];
	int nAy = t2.ay + dy[i];
	int nBx = t2.bx + dx[(i+2)%4];
	int nBy = t2.by + dy[(i+2)%4];
	if( 0<nAx && nAx <= X && 0<nAy && nAy<=Y ){
	  if( ! dep[nAy][nAx] ){
	    t2.ax = nAx;
	    t2.ay = nAy;
	  }
	}
	if( 0<nBx && nBx <= X && 0<nBy && nBy<=Y ){
	  if( ! dep[nBy][nBx] ){
	    t2.bx = nBx;
	    t2.by = nBy;
	  }
	}

	if( ! used[t2.ax][t2.ay][t2.bx][t2.by] ){
	  used[t2.ax][t2.ay][t2.bx][t2.by] = true;
	  que.push(t2);
	}
      }
    }

    if(res==101)
      cout << "NA" << endl;
    else
      cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 7960
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define MAX_K 100005
int N,M,K;
P t[MAX_K];
map<P,bool> mp;

int main(){
  scanf("%d %d %d",&N,&M,&K);
  for(int i=0;i<K;i++){
    int x,y;
    scanf("%d %d",&y,&x);
    y++;
    x++;
    mp[P(y,x)]=1;
  }
  
  for(int y=3;y<=N+1;y++)mp[P(y,0)]=1;
  for(int y=0;y<=N-2;y++)mp[P(y,M+1)]=1;
  for(int x=3;x<=M+1;x++)mp[P(0,x)]=1;
  for(int x=0;x<=M-2;x++)mp[P(N+1,x)]=1;

  bool ans=false;
  queue< P > Q;
  map< P , int > visited;
  visited[ P(N+1,0) ]=1;
  Q.push( P(N+1,0) );
  visited[ P(0,M+1) ]=2;
  Q.push( P(0,M+1) );
  
  while(!Q.empty()){
    P p=Q.front();Q.pop();

    for(int dy=-2;dy<=2;dy++){
      for(int dx=-2;dx<=2;dx++){
        P np=p;
        np.first+=dy;
        np.second+=dx;
        if( visited.count(np)==0 )continue;
        if(visited[np]!=visited[p])ans=true;
      }
    }
    for(int dy=-1;dy<=1;dy++){
      for(int dx=-1;dx<=1;dx++){
        P np=p;
        np.first+=dy;
        np.second+=dx;
        if(visited.count(np)){
          if(visited[np]!=visited[p]){
            printf("0\n");
            return 0;
          }
          continue;
        }
        if(mp.count(np)==0)continue;
        visited[np]=visited[p];
        Q.push(np);
      }
    }
  }
  if(ans)printf("1\n");
  else printf("2\n");
  return 0;
}

Measured memory_bytes: 66496
s = input()
t = input()

ls = len(s)
lt = len(t)
ANS = []

for i in range(ls) :
    if s[i] == t[0] or s[i] == "?" :
        co = 0
        for k in range(lt) :
            if 0 <= i+k < ls and (s[i+k] == t[k] or s[i+k] == "?") :
                co += 1
        if co == lt :
            ANS.append((s[:i]+t+s[i+lt:]).replace("?","a"))
            
#print(ANS)
ANS.sort()
if len(ANS) > 0 :
    print(ANS[0])
else :
    print("UNRESTORABLE")


Measured memory_bytes: 3064
N, C, K = map(int, input().split())

T = [int(input()) for i in range(N)]

T.sort()
A = T[0]
SUM = 1
ans = 0
for i in range(1, N):
    SUM += 1
    if T[i] - A > K:
        ans += 1
        SUM = 1
        A = T[i]
    elif SUM > C:
        ans += 1
        SUM = 1
        A = T[i]

        
print(ans+1)
    


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

long long gcd(long long a, long long b){
	if (a % b){
		return gcd(b, a%b);
	} else {
		return b;
	}
}

int main()
{
	long long  a, b;
	cin >> a >> b;
	long long n = gcd(a, b);
	vector<pair<long long, long long>> fs;
	for (long long i = 2; i*i <= n; i++){
		if (n % i == 0){
			int cnt = 0;
			while (n % i == 0){
				n /= i;
				cnt++;
			}
			fs.emplace_back(i, cnt);
		}
	}
	if (n > 1){
		fs.emplace_back(n, 1);
	}
	cout <<fs.size() + 1 << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,q) for(int i = 0; (q) > i; i++)
int main(){
  string s,t;cin>>s>>t;
  sort(all(s));
  sort(all(t),greater<int>());
  string kekka = "yet";
  rep(i, min(s.size(),t.size())){
    if(s[i] < t[i]){
      kekka="Yes";break;
    }else if(s[i] == t[i])continue;
    else{
      kekka="No";break;
    } 
  }
  if(kekka=="yet"){
    if(s.size()<t.size())kekka="Yes";
    else kekka="No";
  }
  cout << kekka << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    int N; cin>>N;
    vector<ll> a(N+1,0);
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int ans=0;
    int count=1;
    for(int i=0;i<N;i++){
        if(a[i]!=a[i+1]){
            if(a[i]>count)ans+=count;
            else if(a[i]<count) ans+=(count-a[i]);
            count=1;
        }
        else{
            count++;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        int L = scanner.nextInt();
        int[] vals = new int[N];
        int tot = 0;
        for(int i = 0; i < N; i++) {
            vals[i] = L + i;
            tot += vals[i];
        }
        int bestDiff = Integer.MAX_VALUE/2;
        int val = 0;
        for(int i = 0; i < N; i++) {
            int diff = Math.abs(vals[i]);
            if (diff < bestDiff) {
                bestDiff = diff;
                val = vals[i];
            }
        }
        out.println(tot - val);
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}


Measured memory_bytes: 22612
#include <iostream>

using namespace std;

int main()
{
   //cout << "Hello World" << endl; 
   int X,i,k,n=1;
   cin >> X;
   for(i=1;n<=X;i++){
       k = (360*n)/X;
       if(k*X==360*n) break;
       else n+=1;
   }
   cout << k;
   return 0;
}

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

#define FOR(r) for(int i = 0; i < r; i++)

int main(){
int a, b, c, ans = 0;
scanf("%d", &a);
FOR(a){
scanf("%d%d", &b, &c);
ans += c - b + 1;
}
printf("%d\n", ans);
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <map>

using namespace std;


int c1,c2,c3;


int main()
{
    int n;scanf("%d",&n);
    long long ans=1;
    c1=c2=c3=-1;
    while (n--){
        int tmp;scanf("%d",&tmp);int _tmp=0;
        if (c1==tmp-1) _tmp++;
        if (c2==tmp-1) _tmp++;
        if (c3==tmp-1) _tmp++;
        ans*=_tmp;
        ans%=1000000007;
        if (c1==tmp-1) c1++;
        else if (c2==tmp-1) c2++;
        else if (c3==tmp-1) c3++;
    }
    printf("%lld\n",ans);
}



Measured memory_bytes: 128
#include <stdio.h>

int num[26];

int main() {
#ifdef TEST
    freopen("input", "r", stdin);
#endif

    char ch;
    while (EOF != scanf("%c", &ch)) {
        int pos = ch - 'a';
        if(pos >= 0 && pos <= 25) num[pos]++;
        pos = ch - 'A';
        if(pos >= 0 && pos <= 25) num[pos]++;
    }

    for (int i = 0; i < 26; ++i) {
        printf("%c : %d\n", 'a' + i, num[i]);
    }
    return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

#include <set>
#include <map>
#include <iomanip>

using namespace std;

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

using ll = long long;

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

	vector<ll> S(N, 0);
	rep(i, N - 1) {
		ll a;
		cin >> a;

		S[a - 1]++;
	}

	rep(i, N) {
		cout << S[i] << endl;
	}
	

	return 0;
}

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

using namespace std;
#define rep(i, s, n) for(int i = s;i<n;i++)
#define repe(i, s, n) for(int i = s;i<=n;i++)

typedef pair<int, int> P;

bool pairCompare(const P &firstElof, const P &secondElof) {
    return firstElof.first < secondElof.first;
}

int main(void) {
    int N, T;
    vector<pair<int, int >> cost;
    cin >> N >> T;
    rep(i, 0, N) {
        P inp;
        cin >> inp.first >> inp.second;
        if (inp.second <= T) {
            cost.push_back(inp);
        }
    }

    if (cost.empty()) {
        cout << "TLE" << endl;
    } else {
        sort(cost.begin(), cost.end(), pairCompare);
        cout << cost.front().first << endl;
    }
}

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

int base;

int hit(){
	if(base==3) return 1;
	else base++;
	return 0;
}

int homerun(){
	base++;
	return base;
}

int main(){
	int inning;
	std::cin >> inning;

	for(int i=0;i<inning;i++){
		int outCount=0;
		int point=0;
		std::string result;
		base=0;
		while(outCount<3){
			std::cin >> result;

			if(result == "HIT"){
				point += hit();
			} else if(result == "HOMERUN"){
				point += homerun();
				base=0;
			} else if(result == "OUT"){
				outCount++;
			}
		}
		std::cout << point << std::endl;
	}

    return 0;
}


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

int main()
{
  std::string S;
  std::cin >> S;

  int cnt = 0;

  for ( char c : S ) {
    if ( c == 'o' ) cnt++;
  }

  std::cout << 700 + 100 * cnt << std::endl;

  return 0;
}


Measured memory_bytes: 256
var  A,F:array[0..1000000] of longint;
      k,n,i,min,j,tam:longint; f1:text;

 BEGIN
  assign(f1,''); reset(f1);
  readln(f1,n,k);
  for i:=1 to n do read(f1,A[i]);
  F[1]:=0;
  F[2]:=abs(A[2]-A[1]);
  for i:=3 to k do
   BEGIN
    min:=1000000000;
    for j:=1 to i-1 do
     BEGIN
      tam:=F[i-j]+abs(A[i-j]-A[i]);
      if tam<min then
       BEGIN
        min:=tam;
       END;
     END;
    F[i]:=min;
   END;

  for i:=k+1 to n do
   BEGIN
    min:=1000000000;
    for j:=1 to k do
     BEGIN
      tam:=F[i-j]+abs(A[i-j]-A[i]);
      if tam<min then
       BEGIN
        min:=tam;
       END;
     END;
    F[i]:=min;
   END;
  write(F[n]);
  readln;
  close(f1);
 END.



Measured memory_bytes: 4608
#include<cstdio>
using namespace std;

int main(){
	long long x,y;
	scanf("%lld%lld",&x,&y);
	long long now=x;
	int ans=0;
	for(register int i=1;now<=y;i++){
		ans++;
		now*=2;
	}
	printf("%d",ans);
	return 0;
}

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

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

multiset<int, greater<int>> s;

signed main(){
    IOS;
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
    	int a;
    	cin >> a;
    	s.insert(a);
    }
    for (int i = 0; i < m; i++) {
    	auto it = s.begin();
    	int a = *it;
    	s.erase(it);
    	s.insert(a/2);
    }
    int sum = 0;
    for (auto i : s) {
    	sum += i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,k;
    scanf("%d %d",&n,&k);
    char s[n];
    scanf("%s",s);
    s[k-1]=s[k-1]+32;
    printf("%s\n",s);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n;

signed main() {
	cin >> n;
	for (int i = 1; i <= 3500; i++)for (int j = 1; j <= 3500; j++) {
		int x = n * i*j;
		int s = 4 * x / n;
		int t = x / i + x / j;
		int y = s - t;
		if (0 < y && !(x%y)) {
			cout << i << " " << j << " " << x / y << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 764
import java.util.Scanner;

public class Main {
    public static void main(String... args){
        Scanner scan = new Scanner(System.in);
        while(true){
            String s = scan.nextLine();
            if(s.equals("."))break;
            if(search(s))System.out.println("yes");
            else System.out.println("no");

        }
        
        scan.close();
    }

    static boolean search(String s){
        for(int i = 0;i < s.length();i++){
            if(s.charAt(i) == '('){
                int x = findMaruKakko(s, i+1);
                if(x == -1)return false;
                else i = x;
                continue;
            }
            if(s.charAt(i) == '['){
                int x = findShikakuKakko(s, i+1);
                if(x == -1)return false;
                else i = x;
                continue;
            }
            if(s.charAt(i) == ')')return false;
            if(s.charAt(i) == ']')return false;
            
        }
        return true;
    }

    static int findMaruKakko(String s, int begin){
        for(int i = begin;i < s.length();i++){
            if(s.charAt(i) == ')')return i;
            if(s.charAt(i) == ']')return -1;
            if(s.charAt(i) == '('){
                int x = findMaruKakko(s, i+1);
                if(x == -1)return -1;
                else i = x;
                continue;
            }
            if(s.charAt(i) == '['){
                int x = findShikakuKakko(s, i+1);
                if(x == -1)return -1;
                else i = x;
                continue;
            }
        }
        return -1;

    }

    static int findShikakuKakko(String s, int begin){
        for(int i = begin;i < s.length();i++){
            if(s.charAt(i) == ']')return i;
            if(s.charAt(i) == ')')return -1;
            if(s.charAt(i) == '('){
                int x = findMaruKakko(s, i+1);
                if(x == -1)return -1;
                else i = x;
                continue;
            }
            if(s.charAt(i) == '['){
                int x = findShikakuKakko(s, i+1);
                if(x == -1)return -1;
                else i = x;
                continue;
            }
                
            
        }
        return -1;

    }
    

}


Measured memory_bytes: 44828
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DPreparingBoxes solver = new DPreparingBoxes();
        solver.solve(1, in, out);
        out.close();
    }

    static class DPreparingBoxes {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n + 1];
            for (int i = 1; i <= n; i++)
                a[i] = in.nextInt();

            int[] answer = solve(a);

            int count = 0;
            StringBuilder sb = new StringBuilder();
            for (int i = 1; i <= n; i++) {
                if (answer[i] > 0) {
                    sb.append(i + " ");
                    count++;
                }
            }

            if (count == 0) {
                out.println(count);
            } else {
                sb.deleteCharAt(sb.length() - 1);
                out.println(count);
                out.println(sb);
            }
        }

        private static int[] solve(int[] a) {
            int n = a.length - 1;
            int[] answer = new int[n + 1];

            for (int i = n; i >= 1; i--) {
                int tot = 0;
                for (int j = 2 * i; j <= n; j += i) {
                    tot ^= answer[j];
                }
                tot ^= a[i];
                answer[i] = tot;
            }
            return answer;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main() {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    cout << a.at(n-1) - a.at(0) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        long year = 0;
        long money = 100;
        while (money < X ) {
            money += money / 100;
            year++;
        }
        System.out.println(year);
        sc.close();
    }
}

Measured memory_bytes: 35740
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

struct pl {
    bool operator()(const pll &a, const pll &b) {
        return a.first * a.second < b.first * b.second;
    }
};

int main(void)
{
    IOS
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n),f(n);
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> f[i];
    sort(ALL(a));
    sort(RALL(f));
    ll ng = -1, ok = a.back() * f.front();
    ll jump = ok / 2;

    auto isok = [&](ll &x){
        bool ret = true;
        ll k2 = k;
        REP(i,a.size()) {
            ll c = a[i] * f[i] - x;
            if (c > 0) {
                if (c % f[i] == 0) k2 -= c / f[i];
                else k2 -= c / f[i] + 1;

                if (k2 < 0) {
                    ret = false;
                    break;
                }
            }
        }
        return ret;
    };

    ll cnt = ok - jump;
    while(ng +1 < ok) {
        jump /= 2;
        if (jump == 0) jump = 1;
        if (isok(cnt)) {
            ok = cnt;
            cnt -= jump;
        } else {
            ng = cnt;
            cnt += jump;
        }
        cerr << ng << " " << ok << endl;
    }
    
    cout << ok << endl;

    return 0;
}

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

int main() {
  string bstr;

  while (getline(cin, bstr)) {
    int n = 26; 
    while (n--) {
      if (bstr.find("this", 0) != string::npos) {
        break;
      } else if (bstr.find("that", 0) != string::npos) {
        break;
      } else if (bstr.find("the", 0) != string::npos) {
        break;
      }   
      for (int i = 0; i < bstr.size(); i++) {
        if (bstr[i] >= 'a' && bstr[i] <= 'z') {
          if (bstr[i] != 'z')
            bstr[i]++;
          else
            bstr[i] = 'a';
        }
      }   
    }   
    cout << bstr << endl;
  }

  return 0;
}

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

int main(){
  int n; cpp_int t = 1; cin >> n;
  vector<long> v(n);
  rep(i, n){
    cin >> v[i];
    if(v[i] == 0) t = 0;
  }
  rep(i, n){
    t *= v[i];
    if(t > 1000000000000000000){
      t = -1;
      break;
    }
  }
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 4084
#include <stdio.h>

void solve(size_t n, int limit, int* out_value, int *out_weight) {
	int vdat[n], wdat[n];
	int V[2][limit + 1], W[2][limit + 1];
	int i, w, diff, v1, w1;

	for (w = 0; w < limit + 1; w++) {
		V[0][w] = W[0][w] = V[1][w] = W[1][w] = 0;
	}

	for (i = 0; i < n; i++) {
		scanf("%d,%d ", vdat+i, wdat+i);
	}

	for (i = 0; i < n + 1; i++) {
		for (w = 0; w < limit + 1; w++) {
			diff = w - wdat[i - 1];
			if (i - 1 >= 0 && diff >= 0) {
				v1 = V[0][diff] + vdat[i - 1];
				w1 = W[0][diff] + wdat[i - 1];
			} else {
				v1 = 0;
				w1 = 0;
			}

			if (v1 >= V[0][w]) {
				V[1][w] = v1;
				W[1][w] = w1;
			} else {
				V[1][w] = V[0][w];
				W[1][w] = W[0][w];
			}
		}
		for (w = 0; w < limit + 1; w++) {
			V[0][w] = V[1][w];
			W[0][w] = W[1][w];
		}
	}
	*out_value = V[1][limit];
	*out_weight = W[1][limit];
}

int main() {
	int ca, w, n, value, weight;

	for (ca = 1;; ca++) {
		scanf("%d ", &w);
		if (w == 0)
			break;

		scanf("%d ", &n);
		solve(n, w, &value, &weight);
		printf("Case %d:\n%d\n%d\n", ca, value, weight);
	}
	return 0;
}

Measured memory_bytes: 628
#include <iostream>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)
#define myforInv(i,N) for(i=N;i>=0;i--)
#define myforFLInv(i,f,l) for(i=f;i>l;i--)

using namespace std;

int main(){
	string S,T;
	cin >> S >> T;
	if(equal(S.begin(),S.end(),T.begin()))cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin>>n>>k;
    if (k>(n-1)*(n-2)/2){
        cout<<"-1\n";
        return 0;
    }
    int c = (n-1)*(n-2)/2-k;
    int m = c+(n-1);
    cout<<m<<"\n";
    rep(i,n-1){
        cout<<n<<" "<<i+1<<"\n";
    }
    rep(i,n-1)rep(j,n-1){
        if (c==0) break;
        if (i>=j) continue;
        cout<<i+1<<" "<<j+1<<"\n";
        c--;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n, m;
string s;
stack<llong> ans;

int main() {
    cin >> n >> m;
    cin >> s;

    for (int i = 0; i < s.size(); i++) {
        int cnt = 0;
        while (s[i] == '1') {
            i++;
            cnt++;
        }

        if (cnt >= m) {
            cout << -1 << endl;
            return 0;
        }
    }

    for (int i = s.size() - 1; i > 0; i--) {
        llong c = m;
        while (i - c < 0 || s[i - c] == '1') {
            c--;
        }

        i -= c - 1;
        ans.push(c);
    }

    while (!ans.empty()) {
        cout << ans.top() << ' ';
        ans.pop();
    }

    return 0;
}


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

int main(){
    string S;
    cin >> S;
    int res = (int)S.size();//INF
    for(char c:S){
        int tmp = 0;
        for(int i = 0; i < S.size();){
            int j = i;
            while(j < S.size() && !((S[j] == c)^(S[i] == c)))++j;
            if(S[i]!=c)tmp = max(tmp,j-i);
            i = j;
        }
        res = min(res,tmp);
    }
    cout << res << endl;
}

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

const int N=1e5,MOD=998244353;

int n;
char str[3*N+3];

struct MODNUM{
    int num;
    MODNUM(){}
    MODNUM(int _n):num(_n){}
    MODNUM operator *(const MODNUM B){return 1ll*num*B.num%MOD;}
    MODNUM operator +(const MODNUM B){return (1ll*num+B.num)%MOD;}
    MODNUM operator -(const MODNUM B){return ((1ll*num-B.num)%MOD+MOD)%MOD;}
    MODNUM operator +=(const MODNUM B){return *this=(*this)+B;}
    MODNUM operator *=(const MODNUM B){return *this=(*this)*B;}
    MODNUM operator -=(const MODNUM B){return *this=(*this)-B;}
}ans,num[4][4];

int main(){
    // freopen("legend.in","r",stdin);
    // freopen("legend.out","w",stdout);
    scanf("%d%s",&n,str+1);
    for(int i=1;i<=3*n;i++){
        if(str[i]=='R') str[i]='1';
        if(str[i]=='G') str[i]='2';
        if(str[i]=='B') str[i]='3';
    }
    ans=1;
    for(int i=1;i<=3*n;i++){
        int ano1,ano2,thi=str[i]-'0';
        if(str[i]=='1') ano1=2,ano2=3;
        if(str[i]=='2') ano1=1,ano2=3;
        if(str[i]=='3') ano1=1,ano2=2;
        if(num[ano1][ano2].num) ans*=num[ano1][ano2],num[ano1][ano2]-=1;
        else if(num[ano1][0].num) ans*=num[ano1][0],num[ano1][0]-=1,num[min(ano1,thi)][max(ano1,thi)]+=1;
        else if(num[ano2][0].num) ans*=num[ano2][0],num[ano2][0]-=1,num[min(ano2,thi)][max(ano2,thi)]+=1;
        else num[thi][0]+=1;
    }
    for(int i=1;i<=n;i++) ans*=i;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 512
import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[-int(i) for i in a]

heapq.heapify(b)

for i in range(m):
    x=-heapq.heappop(b)//2
    heapq.heappush(b,-x)

print(-sum(b))


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

int main()
{
  ll n, m, ans;
  ans = 0;
  cin >> n >> m;

  if (n >= m)
  {
    ans += m / 2;
  }
  else
  {
    ans += n;
    m -= 2 * n;
    ans += m / 4;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3524
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    string s;
    cin >> s;
    if(s[0] == s[1] && s[0] == s[2]){
        cout << "Yes" << endl;
    }else if(s[3] == s[1] && s[3] == s[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#define LL long long
#define lowbit(x) ((x)&-(x))
using namespace std;
const int MAX = 300010;
struct segment
{
    int l,r;
    bool operator < (const segment&a)
    {
        return r-l < a.r-a.l;
    }
}seg[MAX];
int N,M,v[MAX],s[MAX<<2],lazy[MAX<<2];
void pushup(int rt)
{
    s[rt] = s[rt<<1] + s[rt<<1|1];
}
void pushdown(int rt,int l)
{
    if (lazy[rt])
    {
        s[rt<<1] += lazy[rt]*(l-(l>>1));
        s[rt<<1|1] += lazy[rt]*(l>>1);
        lazy[rt<<1] += lazy[rt];
        lazy[rt<<1|1] += lazy[rt];
        lazy[rt] = 0;
    }
}
void update(int L,int R,int p,int l,int r,int rt)
{
    if (L <= l && r <= R)
    {
        s[rt] += p*(r-l+1);
        lazy[rt] += p;
        return ;
    }
    pushdown(rt,r-l+1);
    int m = (l+r)>>1;
    if (L <= m) update(L,R,p,l,m,rt<<1);
    if (m < R) update(L,R,p,m+1,r,rt<<1|1);
    pushup(rt);
}
int query(int L,int R,int l,int r,int rt)
{
    if (L <= l && r <= R) return s[rt];
    pushdown(rt,r-l+1);
    int m = (l+r)>>1, sum = 0;
    if (L <= m) sum += query(L,R,l,m,rt<<1);
    if (m < R) sum += query(L,R,m+1,r,rt<<1|1);
    return sum;
}
int main(void)
{
    while (~scanf("%d%d",&N,&M))
    {
        for (int i=0;i<N;i++) scanf("%d%d",&seg[i].l,&seg[i].r);
        sort(seg,seg+N);
        //memset(s,0,sizeof(s));
        //memset(v,0,sizeof(v));
        int d, lim = M/sqrt(N);
        //printf("lim = %d\n",lim);
        for (d=1;d<=lim;d++)
        {
            for (int i=0;i<N;i++) if (seg[i].r/d > (seg[i].l-1)/d) v[d]++;
        }
        int i=0;
        for (;d<=M;d++)
        {
            for (;i<N && seg[i].r-seg[i].l+1<=d;i++)
            {
                update(seg[i].l,seg[i].r,1,1,M,1);
                //printf("l = %d, r = %d\n",seg[i].l,seg[i].r);
                //for (int j=1;j<=M;j++) printf("%d ",query(j,j,1,M,1)); puts("");
            }
            for (int j=1;j*d<=M;j++) v[d] += query(j*d,j*d,1,M,1);
            v[d] += N-i;
        }
        for (int i=1;i<=M;i++) printf("%d\n",v[i]);
    }
    return 0;
}


Measured memory_bytes: 5632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

import static java.lang.Integer.parseInt;

/**
 * Elementary data structures - Queue
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		// read
		line = br.readLine();
		int n = parseInt(line.substring(0, line.indexOf(' ')));
		int q = parseInt(line.substring(line.indexOf(' ') + 1));
		Deque<Process> queue = new ArrayDeque<Process>();

		for (int i = 0; i < n; i++) {
			line = br.readLine();
			String name = line.substring(0, line.indexOf(' '));
			int time = parseInt(line.substring(line.indexOf(' ') + 1));
			queue.offer(new Process(name, time));
		}

		// solve
		int elapse = 0;
		StringBuilder sb = new StringBuilder();
		while (!queue.isEmpty()) {
			Process p = queue.poll();
			if (p.time <= q) {
				elapse += p.time;
				sb.append(p.name + " " + elapse + "\n");
			} else {
				p.time -= q;
				elapse += q;
				queue.offer(p);
			}
		}
		System.out.print(sb);
	} //end main
}

class Process {
	String name;
	int time;

	Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
}

Measured memory_bytes: 43412
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto xs = readints;
    xs.sort();
    if (xs == [1, 4, 7, 9]) writeln("YES");
    else writeln("NO");
}


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

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

	int n,k; cin >> n >> k;
	vector<bool> snuke;
	snuke.assign(n+1,false);
	while(k){
		int d; cin >> d;
		int a;
		for(int i=0;i<d;i++){
			cin >> a;
			snuke[a]=true;
		}

		k--;
	}
	int count =0;
	for(int i=1;i<n+1;i++){
		if(!snuke[i])count++;
	}
	cout << count ;

}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[5];
  scanf("%s",a);
  for(int i=0;a[i]!='\0';i++)
  {
  if(a[i]=='1'){
    a[i]='9';
  }
    else if(a[i]=='9'){
    a[i]='1';
    
    }
  }

printf("%s\n",a);
return 0;

}


Measured memory_bytes: 256