akhauriyash/Code-Regression huggingface dataset:
#import decimal
#decimal.getcontext().prec==500 Floatの桁数を500まで増やす
#Decimal(c).sqrt() それで平方根を求める
#Decimal(1) / Decimal(7) 1/7
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
#input = sys.stdin.readline


#N=int(input())

N=int(input())
A=[int(input()) for i in range(N)]
count=A[0]-1
m=1
for i in range(1,N):
    z=(A[i]-1)//(m+1)
    count+=z
    if not z:
        m=max(m,A[i])
    #print(m,z,A[i])
print(count)


Measured memory_bytes: 74836
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

int main() {
    #ifdef LOCAL
    assert(freopen("a.in", "r", stdin));
    #else
    #endif
    int n;
    cin >> n;
    vector<int> v;
    forn (i, n) {
        int a, b;
        cin >> a >> b;
        v.push_back(a);
        v.push_back(b);
    }
    sort(v.begin(), v.end());
    int res = 0;
    forn (i, n)
        res += v[i * 2];
    cout << res << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    int n;
    cin >> n;
    int tmp=0;
    int m = 0;

    rep(i,n+10){
        tmp += i;
        if(tmp >= n){
            m = i;
            break;
        }
    }
    
    for(int i = m; i > 0; i--){
        if(n >= i){
            cout << i << endl;
            n -= i;
        }
    }

    return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
struct Node{
  Int l,r,d;
  Node(){l=r=d=-1;}
  Node(Int d):d(d){l=r=-1;}
};
  
signed main(){
  Int n,l;
  cin>>n>>l;
  vector<string> s(n);
  for(Int i=0;i<n;i++) cin>>s[i];
  sort(s.begin(),s.end(),
       [](string a,string b){return a.size()<b.size();});

  vector<Node> v;
  v.push_back(Node(0));
  for(string u:s){
    Int p=0;
    for(Int i=0;i<(Int)u.size();i++){
      if(u[i]=='0'){
	if(v[p].l<0){
	  v[p].l=v.size();
	  v.push_back(Node(v[p].d+1));
	}
	p=v[p].l;
      }
      if(u[i]=='1'){
	if(v[p].r<0){
	  v[p].r=v.size();
	  v.push_back(Node(v[p].d+1));
	}
	p=v[p].r;
      }
    }
  }
  
  auto grundy=[](Int x){
    Int k=1;
    while(x%2==0) x>>=1,k<<=1;
    return k;
  };
  Int ans=0;
  for(Int i=0;i<(Int)v.size();i++){
    Int c=(v[i].l<0)+(v[i].r<0);
    if(c&1) ans^=grundy(l-v[i].d);
  }
  cout<<(ans?"Alice":"Bob")<<endl;
  return 0;
}


Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
#define ck cout<<(id++)<<endl
typedef long long ll;
const int maxn=1e6+100;
const int maxc=26;
const int mod=998244353;
char s[20][1100];
int a[20][1100];
int id;
int main()
{
    int h,w,k;
    scanf("%d%d%d",&h,&k,&w);
    for(int i=1;i<=h;i++)
    scanf("%s",s[i]);
    for(int i=1;i<=h;i++){
        for(int j=0;j<k;j++){
            a[i][j+1]=s[i][j]-'0';
        }
    }
    int mine=h*k;
    for(int i=0;i<(1<<(h-1));i++){
        //ck;
        int e=0,dp[12]={},cnt=0,vis=1;
        for(int j=1;j<=k;j++){
            int now[12]={},flag=1;
            e=0;
            for(int u=1;u<=h;u++){
                now[e]+=a[u][j];
                if((i>>(u-1))&1)
                    e++;
            }
            for(int u=0;u<=e;u++){
                if(dp[u]+now[u]>w)
                    flag=0;
                if(now[u]>w)
                    vis=0;
            }
            if(flag){
                for(int u=0;u<=e;u++)
                    dp[u]+=now[u];
            }else {
                for(int u=0;u<=e;u++)
                    dp[u]=now[u];
                cnt++;
            }

        }
        //e=__builtin_popcount(i);
        if(vis) mine=min(mine,cnt+e);
    }
    cout<<mine<<endl;
    return 0;
}
/*

*/


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

using namespace std;

template <class T> inline T updmax(T& a, T b) { return a = max(a, b); }
template <class T> inline T updmin(T& a, T b) { return a = min(a, b); }

struct edge {
    int to;
    int score;
    edge(int to, int score) : to(to), score(score) { ; }
};

using node = vector<edge>;
using graph = vector<node>;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, p;
    cin >> n >> m >> p;
    graph g(n);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--, c -= p;
        g[a].emplace_back(edge(b, -c));
    }
    vector<long long> dist(n, 0x7f7f7f7f7f7f7f7f);
    dist[0] = 0;
    for (int k = 0; k < 3 * n; k++) {
        bool flag = false;
        for (int i = 0; i < n; i++) {
            for (auto e : g[i]) {
                if (dist[i] + e.score < dist[e.to]) {
                    dist[e.to] = dist[i] + e.score;
                    if (e.to == n - 1) flag = true;
                }
            }
        }
        if (flag && k >= 2 * n) {
            cout << -1 << "\n";
            return 0;
        }
    }
    cout << max(-dist[n - 1], 0LL) << endl;
    return 0;
}

Measured memory_bytes: 384
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let (a, b) = get!(i64, i64);
    if (1..4).any(|x| a * b * x % 2 == 1) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 8572
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <cmath>
using namespace std;
typedef long long ll;
//typedef pair<ll, ll> P;

#define rep(i, m) for(ll i=0;i<(m);i++)
#define rep1(i, m) for(ll i=1;i<=(m);i++)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int N, Ma, Mb;
int a[50], b[50], c[50];
const int INF = 1 << 30;
int dp[50*10][50*10][50];
int rec(int A, int B, int i) {
   if (dp[A][B][i] == 0) {
      dp[A][B][i] = INF;
      if ((A + a[i] )*Mb == ( B + b[i])*Ma) {
         dp[A][B][i] = c[i];
      }
      if (i < N) {
         dp[A][B][i] = min({dp[A][B][i], rec(A, B, i+1), rec(A+a[i], B+b[i], i+1) + c[i]});
      }
   }
   return dp[A][B][i];
}

int main() {
   cin >> N >> Ma >> Mb;
   rep1(i, N) {
      cin >> a[i] >> b[i] >> c[i];
   }
   int result = rec(0, 0, 1);
   if (result >= INF) {
      cout << -1 << endl; 
   } else {
   cout << rec(0, 0, 1) << endl;
   }
}

Measured memory_bytes: 22912
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons;
import std.math, std.numeric;

void main() {
    long n, x; scan(n, x);

    if (x > n - x) {
        x = n - x;
    }

    if (x == n - x) {
        writeln(3*x);
        return;
    }

    long ans = n;

    void dfs(long x, long y) {
        if (x % y == 0) {
            ans += (x / y) * 2 * y - y;
            return;
        }
        else {
            ans += (x / y) * 2 * y;
            dfs(y, x % y);
        }
    }

    dfs(n - x, x);

    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,a,b,c=0,ans=0;
    cin>>n>>a>>b;
    for(int i=0; i<=n; i++){
        c=i/10000+(i%10000)/1000+(i%1000)/100+(i%100)/10+(i%10);
        if(a <= c && c <= b){
        ans += i;
    }
    
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    mat = [[0]*n for i in range(n)]
    l = [list(map(int, input().split())) for _ in range(m)]
 
    for i in l:
        mat[i[0]-1][i[1]-1] = 1
        mat[i[1]-1][i[0]-1] = 1
 
    
    ver = [i for i in range(n)]
 
    cnt = 0
 
    def dfc(now, moved):
        
        nonlocal cnt
 
        moved.sort()
        if moved == ver:
            cnt += 1
        
        for i in range(n):
            if (mat[now][i] == 0) or (i in moved):
                continue
            
            dfc(i, moved + [i])
 
    dfc(0, [0])
    print(cnt)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        //リスト定義
        ArrayList<Integer> A = new ArrayList<Integer>();
        
        int num = sc.nextInt();
        
        int number = 0,order;
        for(int i = 0;i < num;i++){
            //命令変数定義
            order = sc.nextInt();;
            //条件定義
            switch(order){
                //pushBack
                case 0:
                    number = sc.nextInt();
                    A.add(number);
                    break;
                //randomAccess
                case 1:
                    number = sc.nextInt();
                    System.out.println(A.get(number));
                    break;
                //popBack
                case 2:
                    A.remove(A.size() - 1);
                    break;
            }
        }
    }
}


Measured memory_bytes: 140932
import java.io.*;

public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

      int n = Integer.parseInt(in.readLine());
      int[] table = new int[3];

      String[] lines;
      final int t = 0;
      final int x = 1;
      final int y = 2;
      boolean isPossible = true;

      for(int i=0; i<n; i++) {
        lines = in.readLine().split(" ");
        for(int j=0; j<3; j++)
          table[j] = Integer.parseInt(lines[j]);

          int d = table[x] + table[y];
          int time = table[t];
          if(time < d || (time - d) % 2 != 0) {
            isPossible = false;
            break;
          }
      }

      String ans = isPossible ? "Yes" : "No";
      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

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

void bfs(vector<vector<ll>> &friends,vector<bool> &checked,queue<ll> &q,ll &k){
  ll i;
  for(i=0;i<friends.at(k).size();i++){
    if(!checked.at(friends.at(k).at(i))){
      q.push(friends.at(k).at(i));
    }
  }
}

int main(void){
  ll n,m,k;
  cin >> n >> m >> k;
  vector<ll> a(m),b(m);
  vector<vector<ll>> friends(n,vector<ll>(0));
  ll i;
  for(i=0;i<m;i++){
    cin >> a.at(i) >> b.at(i);
    a.at(i)--;
    b.at(i)--;
    friends.at(a.at(i)).push_back(b.at(i));
    friends.at(b.at(i)).push_back(a.at(i));
  }
  
  vector<ll> group(n);
  vector<bool> checked(n,false);
  queue<ll> q;
  for(i=0;i<n;i++){
    if(!checked.at(i)){
      q.push(i);
      while(!q.empty()){
        group.at(q.front())=i;
        bfs(friends,checked,q,q.front());
        checked.at(q.front())=true;
        q.pop();
      }
    }
  }
  
  vector<ll> count(n,0),member(n,0);
  for(i=0;i<n;i++){
    count.at(group.at(i))++;
  }
  for(i=0;i<n;i++){
    member.at(i)=count.at(group.at(i))-1-friends.at(i).size();
  }
  
  vector<ll> c(k,0),d(k,0);
  for(i=0;i<k;i++){
    cin >> c.at(i) >> d.at(i);
    c.at(i)--;
    d.at(i)--;
    if(group.at(c.at(i))==group.at(d.at(i))){
      member.at(c.at(i))--;
      member.at(d.at(i))--;
    }
  }
  
  cout << member.at(0);
  for(i=1;i<n;i++){
    cout << " " << member.at(i);
  }
}

Measured memory_bytes: 15780
#include<iostream>
using namespace std;
int main(){
	int a,b,c,san=0,tyo=0,don=0,ei=0;
	while(1){
    cin>>a>>b>>c;
	if(a<b)swap(a,b);
	if(a<c)swap(a,c);
	if(a<c+b&&b<a+c&&c<a+b)san=san+1;
	else break;
	if(a*a==b*b+c*c)tyo=tyo+1;
	if(a*a>b*b+c*c)don=don+1;
	if(a*a<b*b+c*c)ei=ei+1;
	}
	cout<<san<<" "<<tyo<<" "<<ei<<" "<<don<<endl;
	return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
int c[N]={0};
typedef struct cities{
    int num;
    long long year;
    int t;
    int st;
}city;
city b[N];
bool cmp1(cities s1,cities s2){
    if(s1.num == s2.num){
        return (s1.year<s2.year)?true:false;
    }
	else{
        return (s1.num<s2.num)?true:false;
    }
}
bool cmp2(cities s1,cities s2){
    return (s1.t<s2.t)?true:false;
}
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++){
    	scanf("%d %d",&b[i].num,&b[i].year);
        b[i].t = i;
    }
    sort(b+1,b+m+1,cmp1);
    for(int i = 1;i<=m;i++){
        b[i].st = c[b[i].num];
        c[b[i].num]++;
    }
    sort(b+1,b+m+1,cmp2);
    for(int i =1;i<=m;i++){
        printf("%06d%06d\n",b[i].num,b[i].st+1);
    }
    return 0;
}


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

int main() {
  vector<int> vec(9);
  REP(i, 9)
    cin >> vec.at(i);
  
  int n;
  cin >> n;
  
  REP(i, n) {
    int tmp;
    cin >> tmp;
    
    REP(j, 9) {
      if (vec.at(j) == tmp)
        vec.at(j) = 0;
    }
  }
    
  if (vec.at(0) + vec.at(1) +  vec.at(2) == 0
     || vec.at(3) + vec.at(4) +  vec.at(5) == 0
     || vec.at(6) + vec.at(7) +  vec.at(8) == 0
     || vec.at(0) + vec.at(3) +  vec.at(6) == 0
     || vec.at(1) + vec.at(4) +  vec.at(7) == 0
     || vec.at(2) + vec.at(5) +  vec.at(8) == 0
     || vec.at(0) + vec.at(4) +  vec.at(8) == 0
     || vec.at(2) + vec.at(4) +  vec.at(6) == 0)
      cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;

int main(){
	long long A,B,C;
	cin>>A>>B>>C;
	if(B+A>=C)cout<<B+C<<endl;
	else cout<<A+2*B+1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main () {
    int N;
    int R;
    int temp;
    int temp2;
    int digits_NbaseR = 0;
    /*
    int factor = 1;
    int NbaseR = 0;
    */
    int remainder_A;

    
    scanf("%d %d",&N,&R);
    
    temp = N;
    while (temp > 0) {
        temp2 = temp%R;
        /*
        NbaseR += temp2*factor;
        factor *= 10; 
        */
        temp = temp/R;
        digits_NbaseR++;
    }
    

    remainder_A = digits_NbaseR;
    
    printf("%d",remainder_A);
    
    return 0;

}

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

	

int main()
{
	int n;
	cin >> n;
	vector<string> s(n);
	for(int i = 0;i<n;i++)cin >> s[i];
	for(int i = 0;i<n;i++)
	{
		reverse(s[i].begin(),s[i].end());
	}
	sort(s.begin(),s.end());
	ll ans = 0;
	//for(auto i = s.begin();i!=s.end();i++)cout<<(*i)<<endl;cout<<endl;

	for(int i = 0;i<n;i++)
	{
		//if(s[i].size()==1)continue;
		ll now = 0;
		auto left = lower_bound(s.begin(),s.end(),s[i].substr(0,s[i].size()-1));

		//cout<<*left<<endl;

		for(auto j = left;j!=s.end();j++)
		{
			if(s[i]==(*j))continue;
			if(s[i].substr(0,s[i].size()-1)!=(*j).substr(0,s[i].size()-1))break;

			char x = s[i].back();
			for(int k = s[i].size()-1;k<(*j).size();k++)
			{
				if((*j)[k]==x)
				{
					ans++;
					break;
				}
			}
		}
		
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 9480
#include<bits/stdc++.h>
using namespace std;
#define M 1000000000000000000
typedef long long ll;
#define pb push_back
#define F first
#define S second
#define M6 3000009
#define M5 500009
#define pi 3.14159265
typedef pair<ll,ll> pll;
ll power(ll x,ll n){
    ll ret=1;
    x%=M;
    while(n>0){
        if(n&1) ret=(ret*x)%M;
        x=(x*x)%M;
        n/=2;
    }
    return ret;
}
ll m,n,ar[M5];
int  main()
{   ios_base::sync_with_stdio (0), cin.tie (0);
    ll test=1,t=1,flag,i,j,k,l,a,b,c,ans=0;
    while(test--){
        cin>>a>>b>>c>>k;
        if(abs(a-b)>M) cout<<"Unfair";
        if(k%2) cout<<b-a;
        else cout<<a-b;
    }
    return 0;
}  

Measured memory_bytes: 256
t = input()
ans = [None for _ in range(len(t))]
i = 0
while i < len(t):
    if t[i] == '?':
        if i == len(t)-1 or t[i+1] == 'P' or (i != 0 and t[i-1] == 'P'):
            ans[i] = 'D'
        elif t[i+1] == 'D':
            ans[i] = 'P'
        else:
            ans[i] = 'P'
            i += 1
            ans[i] = 'D'
    else:
        ans[i] = t[i]
    i += 1
for i in range(len(t)):
    print(ans[i], end='')
print()


Measured memory_bytes: 10820
//be naame khodaa
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
#define F first
#define S second
#define pb push_back
#define sz(x) ((int)(x).size())

inline int in(){ int x, y; y = scanf("%d", &x); return x; }

const int N = 100 + 10;

int a[N];

vector<int> ans;
int main(){
    int n;
    cin >> n; 

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

    for(int i = 0; i < n; i++) { 
        int j = -1; 
        int cnt = 0; 
        for(int k = 0; k < n; k++) 
            if( a[k] > 0 && cnt + 1 == a[k] ) 
                j = k; 
            else if( a[k] < 0 ) 
                cnt++; 

        if( j == -1 ) {
            cout << -1 << endl;
            return 0; 
        }
        ans.pb( a[j] ) ; 
        a[j] = -1; 
    }

    for(auto x: ans) 
        cout << x << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mid ((l+r)>>1)
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n; lnt a[55], s, tot;
bool chk(lnt x) {
	lnt cnt = 0;
	for (int i = 1; i <= n; i++)
		if (a[i] > x) cnt += (a[i]-x)/(n+1);
	return cnt <= s-n*n;
}
lnt bi_solve(lnt l, lnt r) {
	lnt ret = r;
	while (l <= r)
		if (!chk(mid)) l = mid+1;
		else ret = mid, r = mid-1;
	return ret;
}
void solve() {
	if (s >= n*n) {
		lnt mx = 0;
		for (int i = 1; i <= n; i++)
			a[i] += s-n*n, mx = max(mx, a[i]);
		lnt x = bi_solve(0, mx);
		for (int i = 1; i <= n; i++) if (a[i] > x)
			tot += (a[i]-x)/(n+1), a[i] -= (a[i]-x)/(n+1)*(n+1);
		for (int p = 1; tot < s-n*n; p = 1, tot++) {
			for (int i = 2; i <= n; i++)
				if (a[i] > a[p]) p = i;
			a[p] -= n+1;
		}
	}
	for (int p = 1; ; p = 1, tot++) {
		for (int i = 2; i <= n; i++)
			if (a[i] > a[p]) p = i;
		if (a[p] < n) break;
		for (int i = 1; i <= n; i++)
			if (i == p) a[i] -= n; else a[i]++;
	}
}
int main() {
	read(n);
	for (int i = 1; i <= n; i++)
		read(a[i]), s += a[i];
	return solve(), printf("%lld\n", tot), 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
// #define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

int h, w;
string s;

signed main(){
    while(1){
        cin >> s;
        if(s == "#") break;
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--; c--; d--;
        char t[11][11];
        int p = 0, q = 0;
        rep(i, 0, s.size()){
            if(s[i] == 'b'){
                t[p][q] = 'b';
                q++;
            }else if(s[i] == '/'){
                p++; q = 0;
            }else if('0' <= s[i] && s[i] <= '9'){
                rep(j, 0, (int)(s[i] - '0')){
                    t[p][q++] = '.';
                }
            }
        }
        p++;
        // rep(i, 0, p){
        //     rep(j, 0, q){
        //         cout << t[i][j];
        //     }
        //     cout << endl;
        // }
        string res = "";
        swap(t[a][b], t[c][d]);
        rep(i, 0, p){
            int now = 0;
            t[i][q] = '!';
            rep(j, 0, q + 1){
                if(j == q && now != 0){
                    res += (char)('0' + now);
                }
                if(now == 0){
                    if(t[i][j] == '.'){
                        now = 1;
                    }else if(t[i][j] == 'b'){
                        res += t[i][j];
                    }
                }else{
                    if(t[i][j] == '.') now++;
                    else if(t[i][j] == 'b'){
                        res += (char)('0' + now);
                        res += "b";
                        now = 0;
                    }
                }
            }
            if(i != p - 1) res += "/";
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 3004
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    r=int(input())
    g = int(input())
    print(2*g-r)
main()

Measured memory_bytes: 3060
#D問題
N,W = map(int,input().split())
WV = [list(map(int,input().split())) for i in range(N)]


w1 = WV[0][0]
WV.sort()

vlist = [[] for i in range(4)]
for i in range(N):
    w,v = WV[i][0],WV[i][1]
    d = w-w1
    vlist[d].append(v)
    
vrui = [[0] for i in range(4)]
for i in range(4):
    vlist[i].sort(reverse=True)
    for v in vlist[i]:
        vrui[i].append(vrui[i][-1]+v)
        
#print(vlist)
#print(vrui)
MAX = 0
for i in range(min(N+1,len(vlist[0])+1)):
    for j in range(min(N-i+1,len(vlist[1])+1)):
        for k in range(min(N-i-j+1,len(vlist[2])+1)):
            for l in range(min(N-(i+j+k)+1,len(vlist[3])+1)):
                #print(i,j,k,l)
                #print(w1*i+(w1+1)*j+(w1+2)*k+(w1+3)*l)
                #print(vrui[0][i],vrui[1][j],vrui[2][k],vrui[3][l])
                if (w1*i+(w1+1)*j+(w1+2)*k+(w1+3)*l) <= W:
                    MAX = max(MAX,(vrui[0][i]+vrui[1][j]+vrui[2][k]+vrui[3][l]))

print(MAX)
            

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

int main() {
    int n; cin >> n;
    int sum = 0;
    for (int i = 1; i <= n; ++i) {
        sum += i;
        if (sum >= n) {
            for (int j = 1; j <= i; ++j) {
                if (j != sum - n) cout << j << '\n';
            }
            return 0;
        }
    }
    return 1;
}


Measured memory_bytes: 256
public class Main {

  private static void solve() {
    int h = ni();
    int w = ni();
    int[][] c = ntable(10, 10);

    int[][] a = ntable(h, w);

    c = wf(c);

    long ret = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        int d = a[i][j];
        if (d >= 0) {
          ret += c[d][1];
        }
      }
    }
    System.out.println(ret);
  }

  public static int[][] wf(int[][] d) {
    int n = d.length;
    for (int k = 0; k < n; k++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          if (d[i][j] > d[i][k] + d[k][j]) {
            d[i][j] = d[i][k] + d[k][j];
          }
        }
      }
    }
    return d;
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    ll ans = A[N - 1];
    rep(i, N - 2) {
        ans += A[N - 2 - i / 2];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 4840
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j,k = 0;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n + 1);
  B = malloc(sizeof(short)*n + 1);

  /* your code */

  for(i = 1;i <= n;i++){
    scanf("%hd",&A[i]);
    if(k < A[i]){
      k = A[i];
    }
  }

  for(i =0;i <= k;i++){
    C[i] = 0;
  }
  for(j = 1;j <= n;j++){
    C[A[j]]++;
  }
  for(i = 1;i <= k;i++){
    C[i] += C[i - 1];
  }
  for(j = n;j > 0;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i = 1;i <= n;i++){
    if(i == n){
      printf("%d\n",B[i]);
    }else{
      printf("%d ",B[i]);
    }
  }
  

  return 0;
}



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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N, T; cin >> N >> T;

    vector<map<ll, ll > > G;
    G.assign(N, map<ll, ll>());

    for(ll i = 0; i < T; i++){
        ll a, b; cin >> a >> b;
        a--; b--;
        G[a][b]++;
        G[b][a]++;
    }

    auto b1 = G[0].begin(), e1 = G[0].end();
    for (auto iter = b1; iter != e1; iter++) {
        ll next = iter -> first;
        if(G[next][N-1] == 1){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }

    cout << "IMPOSSIBLE" << endl;

}



Measured memory_bytes: 40832
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <ctime>
#include <cstring>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#define Pr pair<int,int>
#define fread(ch) freopen(ch,"r",stdin)
#define fwrite(ch) freopen(ch,"w",stdout)

using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;
const int mod = 1e4+7;

LL ans;

void solve(LL x,LL sum)
{
    if(x == 0)
    {
        ans += sum;
        return;
    }

    for(LL i = 10; i/10 <= x; i *= 10)
    {
        solve(x/i,sum+x%i);
    }
}

int main()
{
    LL x;

    scanf("%lld",&x);

    ans = 0;
    solve(x,0);

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

    return 0;
}


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

int x ;
string s ;

void input ( ) {
    cin >> x ;
    cin >> s ;
}

void solve ( ) {
    if ( x >= 3200 ) { cout << s << "\n" ; }
    else { cout << "red\n" ; }
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 256
#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>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    Int N, M;
    vector<Int> A;
    vector<Int> rui;

    pair<Int, Int> calc(Int z) {
        // z以上
        Int cnt = 0;
        Int sum = 0;

        for (int i = 0; i < N; ++i) {
            Int y = z - A[i];
            auto pt = lower_bound(all(A), y);
            cnt += N - (pt - A.begin());

            if (pt != A.begin())
                sum += rui[N - 1] - rui[pt - A.begin() - 1];
            else
                sum += rui[N - 1];

            sum += (N - (pt - A.begin())) * A[i];
        }

        return make_pair(cnt, sum);
    }

    void solve() {
        cin >> N >> M;
        A.resize(N);
        rui.resize(N);
        for (int i = 0; i < N; ++i) {
            cin >> A[i];
        }
        sort(all(A));
        rui[0] = A[0];
        for (int i = 1; i < N; ++i) {
            rui[i] = rui[i - 1] + A[i];
        }


        Int ok = A[N - 1] + A[N - 1] + 1, ng = 0;

        while (ok - ng > 1) {
            Int mid = (ok + ng) / 2;
            auto tapi = calc(mid);
            if (tapi.first > M) {
                //小さすぎ
                ng = mid;
            } else {
                ok = mid;
            }
        }

        Int fns, fos, fnf, fof;
        fns = calc(ng).second;
        fos = calc(ok).second;
        fnf = calc(ng).first;
        fof = calc(ok).first;
        Int add = 0;

        if (fnf != fof) {
            add = (fns - fos) / (fnf - fof) * (M - fof);
        }

        Int ans = calc(ok).second + add;
        cout << ans << endl;

//        for (int i = 0; i <= 221; ++i) {
//            cout << calc(i).second << endl;
//        }

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
	long long a,b,k;
	int i,t;
	cin>>a>>b>>k;

	for(i=0;i<k;i++){
	if(a%2==0){
		b=b+(a/2);
		a=a/2;
	}
	else{
		a=a-1;
		b=b+a/2;
		a=a/2;
	}
	t=a; a=b; b=t;
   }
   if(k%2!=0)
   cout<<b<<" "<<a;
   else
   cout<<a<<" "<<b;
}

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

int main(){
  int a,b; cin >> a >> b;
  if(a+b==15){
    cout << "+" << endl;
  }else if(a*b==15){
    cout << "*" << endl;
  }else{
    cout << "x" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

bool fnc(int a[3][3]) {
	bool ok = true;
	rep(i, 3) {
		rep(j, 3) {
			if (a[i][j] != 0) {
				ok = false;
				break;
			}
		}
		if (ok == true)return ok;
		ok = true;
	}
	
	rep(i, 3) {
		rep(j, 3) {
			if (a[j][i] != 0) {
				ok = false;
				break;
			}
		}
		if (ok == true)return ok;
		ok = true;
	}
	
	rep(i, 3) {
		if (a[i][i] != 0) {
			ok = false;
			break;
		}
	}
	if (ok == true)return ok;
	ok = true;
	rep(i, 3) {
		if (a[2-i][i] != 0) {
			ok = false;
			break;
		}
	}
	return ok;
}
int main() {
	int a[3][3];
	rep(i, 3)rep(j, 3)cin >> a[i][j];
	int n;
	cin >> n;
	rep(i, n) {
		int b;
		cin >> b;
		rep(k, 3)rep(j, 3)  if (b == a[k][j])a[k][j] = 0;
	}
	if (fnc(a))cout << "Yes" << endl;
	else cout << "No";
	
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define all(a) a.begin(),a.end()

typedef long long ll;

ll solve(vector<string> &s,int n,int &y,int x){
    if(isdigit(s[y][x])) return s[y++][x] - '0';
    char op = s[y][x];
    ++y,++x;
    vector<int> term;
    while(y < n && (int)s[y].size() > x){
        term.push_back(solve(s,n,y,x));
    }
    if(op == '+') return accumulate(all(term),0);
    else return accumulate(all(term),1LL,multiplies<ll>());
}
//accumulate(a, a+5, 1, multiplies<int>());
int main(void){
    int n;
    while(cin>>n,n){
        vector<string> s(n);
        rep(i,n) cin>>s[i];
        int y = 0;
        cout<<solve(s,n,y,0)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3072
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var AB = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (A, B) = (AB[0], AB[1]);

        var ans = ((A + B) % 2 == 0) ? ((A + B) / 2).ToString() : "IMPOSSIBLE";

        WriteLine(ans);
    }
}


Measured memory_bytes: 28164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int64_t H;
int64_t A;
cin>>H;
for(int i=0;i<40;i++){
if(std::pow(2,i)<=H && H<std::pow(2,i+1)){
A=std::pow(2,i+1)-1;
}
}
cout<<A<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N, M; cin >> N >> M;
    ll K; cin >> K;
    ll A[N], B[M]; F0R(i, N) cin >> A[i];
    F0R(i, M) cin >> B[i];
    ll as = 0; F0R(i, N) as += A[i];
    ll bs = 0;
    int bp = 0;
    int ans = 0;
    F0Rd(i, N+1) {
		if (i < N) as -= A[i];
		if (as <= K) {
			while (bp < M && as + bs + B[bp] <= K) {
				bs += B[bp]; ++bp;
			}
			ckmax(ans, i + bp);
		}
	}
	cout << ans << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 6728
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int x,y; cin >> x >> y;
    rep(i,x+1){
        int j = x-i;
        if(i*2 + j*4 == y){
            yes();
            return 0;
        }
    }
    no();
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2>
bool chmax(T1 &a, const T2 b){if(a < b){a = b; return true;} return false;}
template <class T1, class T2>
bool chmin(T1 &a, const T2 b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (T i : v) os << i << ' ';
    return os;
}
void co() { cout << endl; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << endl; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1000000001;
constexpr ll LINF = 1000000000000000001;
constexpr ll MOD = 1000000007;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void) {
    ll n, d;
    cin >> n >> d;
    Vec x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    two_sat ts(n);

    rep(i, n){
        REP(j, i + 1, n){
            if (abs(x[i] - x[j]) < d) ts.add_clause(i, false, j, false);
            if (abs(x[i] - y[j]) < d) ts.add_clause(i, false, j, true);
            if (abs(y[i] - x[j]) < d) ts.add_clause(i, true, j, false);
            if (abs(y[i] - y[j]) < d) ts.add_clause(i, true, j, true);
        }
    }

    if (!ts.satisfiable()) puts("No");
    else{
        puts("Yes");
        auto ans = ts.answer();
        rep(i, n) co(ans[i] ? x[i] : y[i]);
    }

    return 0;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N = 2e3 + 5;
int check(string x , string y){
	int cnt = 0;
	for (int i = 0; i < x.size(); ++i){
		if(x[i] != y[i])cnt++;
	}
	return cnt;
}
int main(){
	string s , t;
	cin >> s >> t;
	int ans = 1e5;
	for (int i = 0; i < (int)s.size() - t.size() + 1; ++i){
		ans = min(ans , check(s.substr(i,t.size()) , t));
	}
	printf("%d\n",ans);
}	

Measured memory_bytes: 3716
N, K = map(lambda x: int(x), input().split(' '))
S = input()

c_lr = 0
c_rl = 0

for i in range(N-1):
    if S[i] == 'L' and S[i+1] == 'R':
        c_lr += 1
    elif S[i] == 'R' and S[i+1] == 'L':
        c_rl += 1

ans = N - 1 - c_lr - c_rl

for i in range(0, K):
    if c_lr > 0 and c_rl > 0:
        c_rl -= 1
        c_lr -= 1
        ans += 2
    elif c_lr > 0:
        c_lr -= 1
        ans += 1
    elif c_rl > 0:
        c_rl -= 1
        ans += 1

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll A,B,C;
  cin>>A>>B>>C;
  for(ll i=1;i<=B;i++) {
    if(A*i%B==C) {
cout<<"YES"<<endl;
      return 0;
    }
  }
  
  cout<<"NO"<<endl;
}

  


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

using namespace std;

int main()
{
    int H, W;
    string line;

    while (cin >> H >> W)
    {
        if (H == 0 && W == 0)
        {
            break;
        }

        line = "";

        for (int x = 0; x < W; x++)
        {
            line += "#";
        }

        for (int y = 0; y < H; y++)
        {
            cout << line << endl;
        }
        
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3180
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


if __name__ == '__main__':
    a,b,k = map(int, input().split())

    count = []
    for i in range(1,101):
        if a % i ==0 and b % i ==0:
            count.append(i)
    count.sort(reverse=True)
    print(count[k-1])


Measured memory_bytes: 5144
import std.stdio;
import std.algorithm;
import core.stdc.stdio;
import core.memory;

void main(){
	while(true){
	GC.collect;

	int[][4][23] nextTown;
	int[4] beTown;
	beTown[] = -1;
	int[10][10] mapData;
	int[] dx = [0,-1,0,1];
	int[] dy = [-1,0,1,0];
	int w,h;
	scanf("%d%d",&w,&h);
	if(w==0&&h==0)
		break;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			scanf("%d",&mapData[i][j]);
		}
	}
	int tc=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(mapData[i][j] == 0){
				mapData[i][j] = 255;
			}else if(mapData[i][j] == 1){
				mapData[i][j] = tc++;
			}else{
				mapData[i][j] = 114;
			}
		}
	}
	bool[] sl = new bool[tc];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(mapData[i][j] < 23){
				for(int k=0;k<4;k++){
					int ny=i+dy[k],nx=j+dx[k];
					while(0<=nx&&nx<w&&0<=ny&&ny<h){
						if(mapData[ny][nx] < 23)
							nextTown[mapData[i][j]][k] ~= mapData[ny][nx];
						ny += dy[k];
						nx += dx[k];
					}
				}
			}
			if(mapData[i][j] == 114){
				for(int k=0;k<4;k++){
					int ny=i+dy[k],nx=j+dx[k];
					while(0<=nx&&nx<w&&0<=ny&&ny<h){
						if(mapData[ny][nx] < 23){
							if(beTown[k] == -1)
								beTown[k] = mapData[ny][nx];
							sl[mapData[ny][nx]]=true;
						}
						ny += dy[k];
						nx += dx[k];
					}
				}
			}
		}
	}
	int[int] now;
	for(int k=0;k<4;k++){
		if(beTown[k] >= 0){
			now[(beTown[k]<<tc)|(1<<beTown[k])] = 1;
		}
	}
	for(int _=1;_<tc;_++){
		int[int] next;
		foreach(int state,int num;now){
			for(int k=0;k<4;k++){
				foreach(s;nextTown[state>>tc][k]){
					if((state&(1<<s))==0){
						int idx = (s<<tc)|(1<<s)|(state&((1<<tc)-1));
						int* np = idx in next;
						if(np == null)
							next[idx] = num;
						else
							(*np)+=num;
						break;
					}
				}
			}
		}
		swap(now,next);
	}
	int ans=0;
	foreach(int state,int num;now){
		if(sl[state>>tc]){
			ans += num;
		}
	}
	printf("%d\n",ans);
	
	}
}

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

#define pb push_back
#define mp make_pair
#define F(i, a, n, b) for(int i=a;i<n;i+=b)
#define REVF(i, a, b, c) for(int i=a;i>=b;i-=c)
#define REP(i, n) F(i, 0, n, 1)
#define REP1(i, n) F(i, 1, n+1, 1)
#define REV(i, n) REVF(i, n, 0, 1)
#define PTR(it, x) for(auto it=x.begin();it!=x.end();++it)
#define MOD 1000000007

typedef long long ll;

const int MAX = 1e6 + 5;

int a,b,c;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>a>>b;
	c = a-b*2;
	if(c < 0)
		c = 0;
	cout<<c;
	return 0;
}

Measured memory_bytes: 256