akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,m,h,w;
string a[111];
int cnt[26];
bool flag[111][111];
int dbcnt,scnt,ncnt;

signed main(){
	 cin>>h>>w;
	 rep(i,h)cin>>a[i];
	 rep(i,h){
	 	rep(j,w){
	 		cnt[(char)a[i][j]-'a']++;
	 	}
	 }
	 rep(i,h){
	 	rep(j,w){
	 		if(flag[i][j] || flag[i][w-j-1] || flag[h-i-1][j]  || flag[h-i-1][w-j-1])continue;
	 		if(i==h-i-1 && j==w-j-1){
	 			flag[i][j]=true;
	 			dbcnt++;
	 		}
	 		else if(i==h-i-1){
	 			flag[i][j]=true;
	 			flag[i][w-j-1]=true;
	 			scnt++;
	 		}
	 		else if(j==w-j-1){
	 			flag[i][j]=true;
	 			flag[h-i-1][j]=true;
	 			scnt++;
	 		}
	 		else{
	 			flag[i][j]=true;
	 			flag[h-i-1][j]=true;
	 			flag[i][w-j-1]=true;
	 			flag[h-i-1][w-j-1]=true;
	 			ncnt++;
	 		}
	 	}
	 }
	 //DEB(dbcnt)END DEB(scnt)END DEB(ncnt)END
	 int cont=0;
	 do{
	 	cont=0;
	 	rep(i,26){
	 		if(cnt[i]%2==1 && dbcnt>0){
	 			cnt[i]--;
	 			dbcnt--;
	 			cont=1;
	 		}
	 	}
	 }while(cont==1);
	 
	 if(dbcnt%2==0)scnt+=dbcnt/2;
	 do{
	 	cont=0;
	 	rep(i,26){
	 		if(cnt[i]%4==2 && scnt>0){
	 			cnt[i]-=2;
	 			scnt--;
	 			cont=1;
	 		}
	 	}
	 }while(cont==1);
	 if(scnt%2==0)ncnt+=scnt/2;
	 do{
	 	cont=0;
	 	rep(i,26){
	 		if(cnt[i]%4==0 && cnt[i]>0 && ncnt>0){
	 			cnt[i]-=4;
	 			ncnt--;
	 			cont=1;
	 		}
	 	}
	 }while(cont==1);
	 int f=1;
	 rep(i,26){
	 	if(cnt[i])f=0;
	 	//ARDEB(i,cnt)END
	 }
	 if(f)cout<<"Yes"<<endl;
	 else cout<<"No"<<endl;
}


Measured memory_bytes: 256
def hantei(t,x,y):
  if t%2==(x+y)%2 and t>=(abs(x)+abs(y)):
    return True
  else:
    return False
N=int(input())
result=[]
t=0
x=0
y=0
T=0
Y=0
X=0
for i in range(N):
  t,x,y=map(int,input().split())
  result.append(hantei(t-T,x-X,y-Y))
  T=t
  X=x
  Y=y
if False in result:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 3872
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T>

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

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

vector<int> bfs(vvi L,int S){ //List,Start
  vector<int> v(L.size(),-1);
  v[S]=0;
  queue<int> q;
  q.push(S);
  while(!q.empty()){
    int a=q.front();
    q.pop();
    for(int x:L[a]){
      if (v[x]==-1){
        v[x]=v[a]+1;
        q.push(x);
      }
    }
  }
  return v;
}

void initialize(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << fixed << setprecision(15);
}

/////////////////////////////////////////

int main(){
  initialize();
  int N;
  cin >> N;
  ll A[N];
  rep(i,N) {
    cin >> A[i];
    A[i]*=2;
  }
  ll B[N+1];
  B[0]=0;
  rep(i,N){
    B[i+1]=A[i]-B[i];
  }
  B[0]=B[N]/2;
  rep(i,N){
    B[i+1]=A[i]-B[i];
  }
  rep(j,N) cout << B[j] << (j==N-1?"\n":" ");
  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <cmath>

int main(){
    
    int a, b;
    
    std::cin >> a >> b;
    
    int sum = b;
    
    if(b < 10){
        sum += a * 10;
    }
    else if(b < 100){
        sum += a * 100;
    }
    else{
        sum += a * 1000;
    }
    
    int root = sqrt(sum);
    if(sum == root * root){
        std::cout << "Yes" << std::endl;
    }
    else{
        std::cout << "No" << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
package main

import(
	"fmt"
	"os"
	"bufio"
	"strings"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var s string
	if sc.Scan() {
		s = sc.Text()
	}

	sei := strings.Split(s, " ")

	a, _:= strconv.Atoi(sei[0])
	b, _:= strconv.Atoi(sei[1])

	ans := 0;
	outlet := 1;
	for outlet < b {
		outlet--
		outlet += a
		ans++
	}

	fmt.Println(ans);
}

Measured memory_bytes: 640
def do():
    n, x, m = map(int, input().split())
    if x == 1: # x = 1の時は強制的にn
        print(n)
        return
    #print(n,x,m)
    dat = []
    d = dict()
    dat.append(x)
    d[x] = True
    #print(x)
    issyu_total = x % m
    isloop = False

    for i in range(n-1): # 最大でもn-1回
        #print(x)
        x = x ** 2 % m
        if x == 0: # 0になったときはそのあと全部0 なので、
            print(sum(dat) % m)
            return
        if x in d:
            #print("hit" + str(i) + " " + str(x))
            isloop = True
            loopstart = dat.index(x)
            break
        dat.append(x)
        issyu_total = (issyu_total + x)
        d[x] = True

    if isloop is False:
        print(issyu_total)
        return

    import math

    res = 0
    #print("loop on")
    #print(loopstart)
    loopsum = sum(dat[loopstart:])
    looplength = len(dat) - loopstart

    res = sum(dat)
    n -= len(dat)

    fullloop = math.floor(n / looplength) # 範囲分
    res += fullloop * loopsum

    nokori = n % fullloop
    res += sum(dat[loopstart:loopstart+nokori])

    #print("loopcount={0}, issyutotal={1}, nokori={2}, fl ={3} ".format(looplength, issyu_total, nokori,fullloop))
    print(res)
    #print(492443256176507 - res)






do()



Measured memory_bytes: 77380
# -*- coding: utf-8 -*-

N = int(input())

list = [list(map(int,input().split())) for i in range(N)]

# sort
list.sort(key=lambda x:x[1])
#check
time = 0
result = True
for i in list:
    A, B = i
    time += A

    #print("work[{0}({1},{2})] time:{3}".format(i,A,B,time))

    if time > B:
        result = False
        break

message = "Yes" if result else "No"
print(message)


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

using namespace std;

int main() {
  int N, ans{}, bh{}, at{}, ba{};
  cin >> N;
  vector<string> s(N);
  for (auto &x : s) {
    cin >> x;
    if (x[0] == 'B')
      if (x.back() == 'A') ++ba;
      else ++bh;
    else if (x.back() == 'A') ++at;
    for (int i = 0, n = x.size(); i < n - 1; ++i)
      if (x[i] == 'A' && x[i + 1] == 'B') ++ans, ++i;
  }

  ans += ba;
  if (bh + at) {
    ans += min(bh, at);
  } else if (ba) {
    --ans;
  }
  cout << ans << endl;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

llint frac(llint n, llint m) {
    llint ans = 1LL;
    for(int in=n;in>=1;in--) {
        ans *= in;
        ans %= MOD;
    }
    for(int im=m;im>=1;im--) {
        ans *= im;
        ans %= MOD;
    }
    if(n==m) {
        ans *= 2;
        ans %= MOD;
    }
    return ans;
}

int main(void) {
    llint n, m, ans;
    cin >> n >> m;

    if(abs(n-m)>=2)  {
        cout << 0 << endl;
        return 0;
    }
    else {
        ans = frac(n, m);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl
#define MAXE(a,b) a=max(a,b)
#define MINE(a,b) a=min(a,b)

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int N;cin >> N;
    vector<int> vec;
    int K;cin >> K;
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        vec.push_back(b);
    }

    vector<int> dp(N,INF);
    dp[0] = 0;

    for(int a = 1;a < N;a++){
        for(int b = max(0,a-K);b < a;b++){
            dp[a] = min(dp[a],dp[b] + abs(vec.at(b)-vec.at(a)));
        }
    }
   // REP(a,N)cout<<dp[a]<<" ";
    cout<<endl;
    cout<<dp[N-1]<<endl;
    return 0;
}


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

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

  vector<int> vec;
  for(int i=N;i>0;i--){
    bool flag=false;
    for(int j=b.size();j>0;j--){
    	if(b[j-1]==j){
          if(j>i){
            cout<<"-1"<<endl;
            return 0;
          }
      	  b.erase(b.begin()+(j-1));
          vec.insert(vec.begin(),j);
          flag=true;
          break;
    	}
  	}
    if(!flag){
      cout<<"-1"<<endl;
      return 0;
    }
  }
  for(int i=0;i<N;i++){
    cout<<vec[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2002;
const int mod = 1e9 + 7;
int dp[N], n;

int solve(int cursum){
   if(cursum == 0)
      return 1;

   if(cursum == 1 || cursum == 2) 
      return 0;
    
    int &ans = dp[cursum];
    if(ans != -1)
       return ans;

    ans = 0;

    for(int i = 3; i <= cursum; i++)
       ans = (ans + solve(cursum - i)) % mod;

    return ans;
}

int32_t main() 
{
  ios::sync_with_stdio(0); 
  cin.tie(0); cout.tie(0);
 
  cin >> n;

  memset(dp, -1, sizeof dp);

  cout << solve(n);

  return 0;
}

Measured memory_bytes: 3684
#include <iostream>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  int a,b,c,d;
  cin >> a;
  cin >> b;
  cin >> c;
  
  if(c-b==b-a){

  cout << "YES"<<endl;
  }else{
    cout << "NO" <<endl;
  }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> d(k);
    rep(i, 0, k) cin >> d[i];
    rep(i, n, 100000){
        int m = i;
        bool f = true;
        while(m > 0){
            int tmp = m % 10;
            m /= 10;
            rep(j, 0, k) if(d[j] == tmp) f = false;
        }
        if(f){
            cout << i << endl;
            return 0;
        }
    }
}

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  queue<char> qa;
  for (int i = 0; i < A.length(); i++) {
    qa.push(A.at(i));
  }
  queue<char> qb;
  for (int i = 0; i < B.length(); i++) {
    qb.push(B.at(i));
  }
  queue<char> qc;
  for (int i = 0; i < C.length(); i++) {
    qc.push(C.at(i));
  }

  int ans = 0;
  char next = qa.front();
  qa.pop();
  while (1) {
    if (next == 'a') {
      if (qa.empty()) {
        printf("A");
        return 0;
      }
      next = qa.front();
      qa.pop();
    } else if (next == 'b') {
      if (qb.empty()) {
        printf("B");
        return 0;
      }
      next = qb.front();
      qb.pop();
    } else {
      if (qc.empty()) {
        printf("C");
        return 0;
      }
      next = qc.front();
      qc.pop();
    }
  }
}


Measured memory_bytes: 256
import io, sys, atexit, os

import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations


def li ():
	return list (map (int, input ().split ()))


def num ():
	return map (int, input ().split ())


def nu ():
	return int (input ())


def find_gcd ( x, y ):
	while (y):
		x, y = y, x % y
	return x


mm = 1000000007



def solve ():
	t = 1
	for it in range (t):
		s=input()
		xp="ACGT"
		mx=0
		for i in range(len(s)):
			if(s[i] in xp):
				cc=0
				for j in range(i,len(s)):
					if(s[j] in xp):
						cc+=1
					else:
						break
				mx=max(mx,cc)
		print(mx)






if __name__ == "__main__":
	solve ()

Measured memory_bytes: 5588
def main():
    """
    0 <= c <= 100
    c(i,j) = a(i) + b(j)
    a: 整数 -> 負もあるのでc特定の数不明

    c1,1 = a1 + b1
    c1,2 = a1 + b2
    c1,3 = a1 + b3

    c2,1 = a2 + b1
    c2,2 = a2 + b2
    c2,3 = a2 + b3

    c3,1 = a3 + b1
    c3,2 = a3 + b2
    c3,3 = a3 + b3

    a or b だけの式にできる
    →等しいか試す
    """
    N = 3
    C = [
        tuple(map(int, input().split()))
        for _ in range(N)
    ]

    editorial(C, N)


def editorial(C, N):
    a = [None] * N
    b = [None] * N

    a[0] = 0
    for i in range(N):
        # c - a[0]だけど0なので省略
        b[i] = C[0][i]
    for i in range(N):
        a[i] = C[i][0] - b[0]

    for i in range(N):
        for j in range(N):
            if C[i][j] != a[i] + b[j]:
                print("No")
                return

    print("Yes")


def editorial2(C, N):
    """
    3 x 3:
    abc
    def
    ghi

    a+e=b+d => (a1+b1)+(a2+b2)=(a1+b2)+(a2+b1)
    b+f=c+e
    d+h=e+g
    e+i=f+h

    2 x 2のgridをつくり、その対角要素の和/逆対角要素の和が等しい
    """
    pass


def AC(C, N):
    a = is_valid_a(C, N)
    if not a:
        print("No")
        return

    b = is_valid_b(C, N)
    if not b:
        print("No")
        return

    print("Yes")


def is_valid_a(C, N):
    """
    c1,1 - c2,1: a1 - a2
    c1,2 - c2,2: a1 - a2
    c1,3 - c2,3: a1 - a2
    --------------
    ci,1 - c(i+1),1: ai - a(i+1)
    ci,2 - c(i+1),2: ai - a(i+1)
    ci,3 - c(i+1),3: ai - a(i+1)
    """
    from itertools import combinations
    for x, y in combinations([0, 1, 2], 2):
        valid = C[x][0] - C[y][0] == C[x][1] - C[y][1] == C[x][2] - C[y][2]
        if not valid:
            return False

    return True


def is_valid_b(C, N):
    """
    c1,1 - c1,2: b1 - b2
    c1,2 - c1,3: b2 - b3
    c1,3 - c1,1: b3 - b1
    --------------
    ci,1 - ci,2: b1 - b2
    ci,2 - ci,3: b2 - b3
    ci,3 - ci,1: b3 - b1
    """
    b1_m_b2 = set()
    b2_m_b3 = set()
    b3_m_b1 = set()
    for i in range(N):
        b1_m_b2.add(C[i][0] - C[i][1])
        b2_m_b3.add(C[i][1] - C[i][2])
        b3_m_b1.add(C[i][2] - C[i][0])

    return len(b1_m_b2) == 1 and len(b2_m_b3) == 1 and len(b3_m_b1) == 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <stdio.h>

int main()
{
    int i, j, n, s=0, c=0;
    scanf("%d", &n);
    if(n<105)
    {
        printf("%d", 0);
    }
    else if(n==105||n==106)
    {
        printf("%d", 1);
    }
    else
    {
        s = 1;
        for(i=107; i<=n; i+=2)
        {
            c = 0;
            for(j=1;j<=i; j+=2)
            {
                if(i%j==0)c++;
            }
            if(c>=8)s++;
        }
        printf("%d", s);
    }
    return 0;
}



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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A[3]; rep(i, 3) cin >> A[i];
    sort(A, A+3);
    int ans = 0;
    while(A[0] < A[2]){
        if(A[0]+1 == A[2]){
            A[0]++; A[1]++;
        }
        else A[0]+=2;
        sort(A, A+3);
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

    int a, b; //ボタンA, Bをしまう変数

    int max; //ボタンを押してもらえるコイン枚数の最大値
//input
    scanf("%d", &a); 
    scanf("%d", &b);

//calc
    for(int i=0; i<2; i++){
        if(a>b){
            //aを押す
            max += a;
            a--;
        }else{
            //bを押す
            max += b;
            b--;
        }
    }

    printf("%d", max);
    
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,ans=0;
    cin>>n;
    int arr[n+1];
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        if(i%2==1 && arr[i]%2==1)
            ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false); //cin.tie(NULL); cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second

using namespace std;
typedef long long ll;
typedef long double ld;

int n, k;
string s;

int ans = INT_MAX;
void solve(){
	cin >> s;
	n = s.size();
	for (int i=0; i<n; ++i){
		if (i > 2){
			k%=100;
		}
		k = k*10 + (s[i]-'0');
		ans = min(ans,abs(753-k));
	}
	cout << ans;
}	

int main(){ FIO;
	solve();
return 0;}

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

using namespace std;
typedef long long ll;

int main(){
  int N,M;
  cin >> N >> M;
  ll A[N];
  int B[M];
  ll C[M];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  for(int i=0;i<M;i++){
    cin >> B[i] >> C[i];
  }
  vector<pair<int,int> > all;
  for(int n=0;n<N;n++){
    all.push_back(make_pair(-A[n],1));
  }
  for(int n=0;n<M;n++){
    all.push_back(make_pair(-C[n],B[n]));
  }
  sort(all.begin(),all.end());
  int j=0;
  int num=0;
  ll sum=0;
  while(1){
    for(int i=0;i<all[j].second;i++){
      sum += -all[j].first;
      num++;
      if(num==N) break;
    }
    j++;
    if(num==N) break;
  }
  cout << sum << endl;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
AC
*/

ll K,c[100010];

void init(){
	cin>>K;
	rep(i,K){
		c[i]=1e18;
	}
}

int main(void){
	init();
	deque<ll> Q;
	Q.push_front(1);
	c[1]=1;
	while(!Q.empty()){
		ll p = Q.front();Q.pop_front();
		if(c[(p+1)%K]>c[p]+1){
			c[(p+1)%K]=c[p]+1;
			Q.push_back( (p+1)%K );
		}
		if(c[(p*10)%K]>c[p]){
			c[(p*10)%K]=c[p];
			Q.push_front( (p*10)%K );
		}
	}
	cout<<c[0]<<endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define     __        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     pi        acos(-1)
#define     ll        long long int
#define     f0(n)     for(int i=0;i<n;i++)
#define     mem(a)    memset(a,0,sizeof(a))
#define     mems(a)   memset(a,-1,sizeof(a))
int64_t n,ans,totb,remb;
int main()
{
   /* #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif  */
     __

    string s;
    cin>>s;
    n=s.size();
    for(int i=s.size()-1;i>=0;i--)
    {
        if(s[i]=='B') totb++;
    }
    remb=totb;
    for(int i=s.size()-1;i>=0;i--)
    {
        if(s[i]=='B')
        {
            ans+=n-(i+1)-(totb-remb);
            remb--;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

map<char,int> t;
int main(){
    string s;
    cin>>s;
    rep(i,s.size()){
        ++t[s[i]];
    }
    if(t.count('W')>0&&t.count('E')==0||t.count('E')>0&&t.count('W')==0){
        cout<<"No"<<endl;
        return 0;
    }
    if(t.count('S')>0&&t.count('N')==0||t.count('N')>0&&t.count('S')==0){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
from functools import lru_cache


@lru_cache(maxsize=None)
def fib(n):
    """ http://docs.python.jp/3/library/functools.html """
    if n < 2:
        return n
    return fib(n-1) + fib(n-2)


class Fibonacci(object):
    memo = [1, 1]

    def get_nth(self, n):
        if n < len(Fibonacci.memo):
            return Fibonacci.memo[n]
        # print('fib({0}) not found'.format(n))
        for i in range(len(Fibonacci.memo), n+1):
            result = Fibonacci.memo[i-1] + Fibonacci.memo[i-2]
            Fibonacci.memo.append(result)
            # print('fib({0})={1} append'.format(i, result))
        return Fibonacci.memo[n]


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())

    # ?????£??????????????°????¨????
    # f = Fibonacci()
    # result = f.get_nth(num)
    result = fib(num+1)

    # ???????????????
    print('{0}'.format(result))

Measured memory_bytes: 8300
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define fr first
#define sc second
#define pb push_back
const ll mod = 998244353;
const int N = 1e6+205;
ll bit[2][N];
void add(int id ,int idx, ll val){
	for(int i=idx;i>0;i-=(i&-i)){
		bit[id][i] = min(bit[id][i],val);
	}
}
ll get(int id,int idx){
	ll ret = N;
	for(int i = idx;i<N;i+=(i&-i)){
		ret = min(ret,bit[id][i]);
	}
	return ret;
}
void solve(){
	ll n,q; 
	cin>>n>>q; 
	for(int i=1;i<N;i++){
		bit[0][i] = bit[1][i] = n;
//		cout<<bit[0][i]<<" "<<bit[1][i]<<endl;
	}
	ll ans = (n-2)*(n-2);
	while(q--){
		int t,x;
		cin>>t>>x; 
		t--;
		ll mn = get(t,x);
		ans-=mn-2;
		add(1-t,mn,x);			
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 19276
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce




INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


sx, sy, tx, ty = LI()

way1 = 'R' * (tx - sx) + 'U' * (ty - sy)
way2 = 'L' * (tx - sx) + 'D' * (ty - sy)
way3 = 'D' + 'R' * (tx - sx + 1) + 'U' * (ty - sy + 1) + 'L'
way4 = 'U' + 'L' * (tx - sx + 1) + 'D' * (ty - sy + 1) + 'R'


print(way1 + way2 + way3 + way4)

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

using namespace std;

int main()
{
  		  int N;

          cin>>N;
          int count =0;

          for(int i=1; i<=N; i++)
          {
              string s = to_string(i);
              int x = s.length();
              if( x%2 != 0)
              {
                  count++;
              }
          }

          cout<<count<<endl;
}

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

int main() {
  int n, k, a, b, c, d, e, f, g, h, i, z, x;
  cin >> n >> k;
  a = 1;
  z = 0;
 for (int i = 0; i < n; i++)
 {cin >> x;
   if( x <= k -x){
   x = x * 2; }
   else { x = ( k - x ) * 2; }
  z += x;
 }  
  
  cout << z << endl;
}


Measured memory_bytes: 256
from itertools import accumulate


N = int(input())
S = input()

black = [0 for _ in range(N)]
white = [0 for _ in range(N)]

for i, s in enumerate(S):
    if s == '#':
        black[i] = 1
    else:
        white[i] = 1

# 累積和
black = [0] + black
black = list(accumulate(black))
white = [0] + white[::-1]
white = list(accumulate(white))[::-1]

ans = []
for i in range(N+1):
    ans.append(black[i] + white[i])

print(min(ans))


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

int main(){
  string s;
  cin >> s;
  if(s.size() == 1){
    cout << s << endl;
    return 0;
  }
  int c0 = 0, c9 = 0;
  rep(i, s.size()){
    if(s.at(i) == '0') c0++;
    if(s.at(i) == '9') c9++;
  }
  if(s.size()-1 == c0){
    int ans = s.front() - '0' - 1;
    ans += c0*9;
    cout << ans << endl;
    return 0;
  }
  if(c9 == s.size()){
    int ans = 9 * s.size();
    cout << ans << endl;
    return 0;
  }
  if(c9 == s.size()-1 && s.front() != '9'){
    int ans = c9 * 9 + (s.front() - '0');
    cout << ans << endl;
    return 0;
  }
  int ans = 9*(s.size()-1) + (s.front() - '0' - 1);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void)
{
    int n;
    int a[128];
    int i;

    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", a + i);
    for (i = n - 1; i >= 0; i--) printf("%d%c", a[i], "\n "[i > 0]);

    return 0;
}

Measured memory_bytes: 596
# -*- coding: utf-8 -*-
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

X, Y = map(int, input().split())



#  a = (i+2,j+1) の回数
#  b = (i+1,j+2) の回数
ans = 0
for a in range(X//2 + 1):
    b = X - a * 2
    y = 2 * b + a
    if b >= 0 and Y == y:
        ans = cmb(a+b, a) % (10**9 + 7)

print(ans)


Measured memory_bytes: 98788
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  char x;cin>>x;
  
  if(x=='A'){
    cout<<'T'<<endl;
  }
  else if(x=='T'){
    cout<<'A'<<endl;
  }
  else if(x=='G'){
    cout<<'C'<<endl;
  }
  else{
    cout<<'G'<<endl;
  }
}

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

public class Main {

	public static void main(String[] args) throws IOException{
		FastScanner f = new FastScanner(); //Replace "problem" with problem name
        
        int n = f.nextInt();
        int m = f.nextInt();
        ArrayList<ArrayList<Integer>> boats = new ArrayList<ArrayList<Integer>>();
        for(int i = 0; i < n; i++){
        	boats.add(new ArrayList<Integer>());
        }
        for(int i = 0; i < m; i++){
        	int a = f.nextInt() - 1;
        	int b = f.nextInt() - 1;
        	boats.get(a).add(b);
        	boats.get(b).add(a);
        }
        boolean exit = false;
        for(int i = 0; i < boats.get(0).size(); i++){
        	if(boats.get(boats.get(0).get(i)).contains(n-1)){
        		System.out.println("POSSIBLE");
        		exit = true;
        		break;
        	}
        }
        
        if(!exit){
        	System.out.println("IMPOSSIBLE");
        }
	}

	public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Measured memory_bytes: 84896
/*
 Abu Jafor Mohammad Saleh
 ios_base :: sync_with_stdio(false);
 cin.tie(NULL);
 */

#include<cstdio>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<limits>
#include <algorithm>
#include <unordered_map>
#include<fstream>
#define f first
#define s second
#define MOD 1000000007

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define BOUNDARY(i, j) ((i >= 0 && i < rows) && (j >= 0 && j < coloums))
#define mx 6e5 + 100;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//#include<bits/stdc++.h>
#define ll long long
const int maxn = 20005;
using namespace std;
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
int rows,coloums;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{
    fast;
    int n;
    cin>>n;
    int a[n+1];
    
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    
    int c =0;
    
    for(int i=0;i<n;i++)
    {
        c++;
        int x =a[i];
        while(a[i+1]>=x && i+1 < n)
        {
           // c++;
            i++;
        }
    }
    
    cout<<c<<endl;
}


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

int cnt=0;

void selectionSort(int *A, int N){
  for(int i=0;i<N;i++){
    int minj=i;
    for(int j=i;j<N;j++){
      if(A[j]<A[minj]) minj=j;
    }
    if(i!=minj){
      swap(A[i], A[minj]);
      cnt++;
    }
  }
}

int main(){

  int n, a[110];

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

  selectionSort(a, n);

  for(int i=0;i<n;i++){
    cout<<(i?" ":"");
    cout<<a[i];
  }
  cout<<endl<<cnt<<endl;

  return 0;
}



Measured memory_bytes: 3116
#include<stdio.h>

int main(){
    
    int n,min,max,a;
    long long sum=0;
    
    scanf("%d",&n);
    for(int i=0 ; i<n ; i++){
        scanf("%d",&a);
        if(i==0){
            max=min=a;
        }
        if(a<min){
            min=a;
        }
        if(a>max){
            max=a;
        }
        sum+=a;
    }
    printf("%d %d %lld\n",min,max,sum);
	
    
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	return 0;
}


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

using namespace std;

#define ll long long




void solve() {

	string s;
	cin >> s;
	int total = 0;
	for(char ch: s) {
		total += (ch - '0');
		total %= 9;
	}
	if(total) {
		cout << "No";
	}
	else {
		cout << "Yes\n";
	}

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int t = 1;
	// cin >> t;
	while(t--)
		solve();

	return 0;
}

Measured memory_bytes: 3728
from sys import stdin
readline = stdin.buffer.readline
read = stdin.buffer.read
def r_map(): return map(int, readline().rstrip().split())
# import numpy as np
# from numba import jit
# stdin = open('sample.txt')

def main():
    D, T, S = r_map()
    if S * T >= D:
        print('Yes')
    else:
        print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 61684
import itertools
import numpy as np
n,m,x = map(int,input().split())
#c = [0 for _ in range(n)]
a = []

for i in range(n):
    a.append(list(map(int,input().split())))

a = np.array(a)

lis = list(itertools.product([0,1],repeat=n))
mon = [10**8 for i in range(n)]
mi = 10**8

for i in lis:
    sum = [0 for _ in range(m+1)]
    hantei = 0
    for ind,j in enumerate(i):
        if j==1:
            sum += a[ind]

    for m in range(1,m+1):
        if sum[m]<x:
            hantei = 1
    if hantei == 0:
        mi = min(mi,sum[0])
if mi == 10**8:
    print(-1)
else:
    print(mi)


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

#ifdef _LOCAL_
	#define cout cerr
#endif
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define FORalld(it, a) for (__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
template<class T> inline T isqrt(T k) {T r = sqrt(k) + 1; while (r * r > k) r--; return r;}
template<class T> inline T icbrt(T k) {T r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}

void solve() {
	int n; cin >> n;
	map<int, int> hs;
	FOR(i, 0, n) {
		int x; cin >> x; hs[x]++;
	}
	int ans = 0, mn = INF, mx = -INF;
	FORall(it, hs) {
		ans += it->se - 1;
		if (it->se > 1) {
			chkmin(mn, it->fi);
			chkmax(mx, it->fi);
		}
	}
	if (ans & 1) ans++;
	cout << n - ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
	solve();
#ifdef _LOCAL_
	//printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int n; string s;
//0...羊 1..狼
void solve(int s0, int s1){
    vector <int> ans(n);
    ans[0] = s0, ans[1] = s1;
    for(int i=2;i<n;i++){
        if(ans[i-1]==0){
            if(s[i-1] == 'o') ans[i] = ans[i-2];
            else ans[i] = 1 - ans[i-2];
        }else{
            if(s[i-1] == 'o') ans[i] = 1 - ans[i-2];
            else ans[i] = ans[i-2];
        }
    }
    for(int i=0;i<n;i++){
        int mae, next;
        if(i==0) mae = n-1, next = 1;
        else if(i==n-1) mae = n-2, next = 0;
        else mae = i-1, next = i+1;
        if(ans[i]==0){
            if(s[i] == 'o'){
                if(ans[mae] != ans[next]) return;
            }else{
                if(ans[mae] == ans[next]) return;
            }
        }else{
            if(s[i] == 'o'){
                if(ans[mae] == ans[next]) return;
            }else{
                if(ans[mae] != ans[next]) return;
            }
        }
    }
    rep(i,n){
        if(ans[i] == 0) cout<<'S';
        else cout<<'W';
    }
    exit(0);
}
signed main(void){
    cin>>n>>s;
    
    solve(0,0); solve(0,1); solve(1,0); solve(1,1);
    cout<<-1<<endl;
}


Measured memory_bytes: 1392
def calc(x, y, op):
    if op == "+":
        res = x + y
    elif op == "-":
        res = x - y
    return res


s = input()

a, b, c, d = map(int, s)
operand = ["+", "-"]
ans = ""

for op1 in operand:
    res1 = calc(a, b, op1)
    for op2 in operand:
        res2 = calc(res1, c, op2)
        for op3 in operand:
            res3 = calc(res2, d, op3)
            if res3 == 7:
                ans = "{}{}{}{}{}{}{}=7".format(a, op1, b, op2, c, op3, d)
                break
        else:
            continue
        break
    else:
        continue
    break

print(ans)


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

typedef long long ll;

int main(){
    ll L0 = 2, L1 = 1, LN;
    int N;
    cin >> N;
    if(N == 0){
        cout << L0 << endl;
        return 0;
    }
    if(N == 1){
        cout << L1 << endl;
        return 0;
    }
    N--;
    while(N--){
        LN = L0+L1;
        L0 = L1;
        L1 = LN;
    }
    cout << LN << endl;
}

Measured memory_bytes: 3644
from collections import deque
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
SA = [0]
for i in range(N):
  temp = SA[-1] + A[i]
  SA.append(temp)
 
SB = [0]
for j in range(M):
  temp = SB[-1] + B[j]
  SB.append(temp)
ans = 0
for i in range(N+1):
  an = i
  if SA[i] > K:
    break
  else:
    nokori = K -SA[i]
    if nokori >= SB[-1]:
      bn = M
    else:
      ok = 0
      ng = M
      while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if nokori >= SB[mid]:
          ok = mid
        else:
          ng = mid
      bn = ok
  #print(an,bn)
  ans = max(ans,an+bn)
print(ans)

Measured memory_bytes: 136132
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,k;
    cin>>a>>b>>k;
    int c=0,val;
    int d[1000]={0};
    for(int i=1;i<=min(a,b);++i)
    {
        if(a%i==0 && b%i==0)
        {
            d[c]=i;
            c++;
        }
    }
    reverse(d,d+c);
    cout<<d[k-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define pi acos(-1)
#define ll long long
int main()
{
	ios_base::sync_with_stdio(0);
	ll n,m;
	cin>>n>>m;
	ll sum=0;
	while(m--){
		ll val;
		cin>>val;
		sum+=val;
	}
	if(sum<=n)cout<<n-sum<<endl;
	else cout<<-1<<endl;
	
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  int n; cin >> n;
  vector<P> x(n);
  
  for(int i = 0; i < n; i++){
    int a,b; cin >> a >> b;
    x[i] = P(a+b,a-b);
  }
  sort(x.begin(), x.end());
  int id = 0, mn = 999999999; 
  for(int i = 0; i < n; i++){
    if(mn > x[i].first){
      mn = x[i].first;
      id = i;
    }
  }
  int ans = 1;
  int left = x[id].first;
  for(int i = id+1; i < n; i++){
    int right = x[i].second;
    if(left > right) continue;
    ans++;
    left = x[i].first;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
s = list(input())
c = 0
l = 0
ol = len(s)
while ol != l:
    if len(s) == 1:
        c += 1
        l += 1
    elif len(s) != 1:
        if len(s) == l + 1:
            c += 1
            l += 1
        else:
            if s[l] != s[l + 1]:
                c += 1
                l += 1
            elif s[l] == s[l + 1]:
                if len(s) == l + 2:
                    c += 1
                    l += 2
                else:
                    c += 2
                    l += 3
print(c)

Measured memory_bytes: 4964
use proconio::input;

fn main() {
    input! {
        x: usize,
        y: usize,
    }

    solve(x, y);
}

fn solve(x: usize, y: usize) {
    for i in 0..(x + 1) {
        if 2 * i + 4 * (x - i) == y {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


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


void solve(std::vector<long long> H, std::vector<long long> M, long long K){
    int m = H[1] - H[0];
    m *= 60;
    m += M[1] - M[0];
    cout<<m - K<<endl;
}

int main(){
    std::vector<long long> H(2);
    std::vector<long long> M(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&H[i]);
        scanf("%lld",&M[i]);
    }
    long long K;
    scanf("%lld",&K);
    solve(std::move(H), std::move(M), K);
    return 0;
}


Measured memory_bytes: 3696
#HonestOrDishonest
def ABC_56_A():
    A,B = map(str, input().split())
    
    if A == 'H' and B == 'H':
        print('H')
    elif A == 'H' and B == 'D':
        print('D')
    elif A == 'D' and B == 'H':
        print('D')
    else:
        print('H')

if __name__ == '__main__':

    ABC_56_A()

Measured memory_bytes: 2940
N = int(input())
A = list(map(int, input().split()))

bits = [0] * 60
p = 10**9 + 7

for b in range(60):
  x = 1 << b
  for i in range(N):
    if A[i] & x:
      bits[b] += 1

ans = 0
for b in range(60):
  ans += (bits[b] * (N - bits[b])) * (1 << b)
  ans %= p

print(ans)

Measured memory_bytes: 122936
// Author: πα

#include <bits/stdc++.h>
using namespace std;
#define long int64_t
const double EPS = 1e-8;

int main()
{
    long s;
    cin >> s;
    long p = llround(ceil(sqrt(s)));
    long x = p, y = p;
    if(p*(p-1) >= s)
        y--;
    long z = x*y - s;
    cout << "0 0 " << x << ' ' << 1 << ' ' << z << ' ' << y;
    return 0;
}


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

const int cm = 1 << 11;
char cn[cm], * ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	fread(cn, 1, cm, stdin);
	int N = getint(), W = getint();

	vector<ll> dp(W + 1);
	rep(i, N) {
		int w = getint();
		int v = getint();
		rep (j, W - w + 1) {
			chmax(dp[j], dp[j + w] + v);
		}
	}

	printf("%lld", dp[0]);

	Would you please return 0;
}

Measured memory_bytes: 1152
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int N=scan.nextInt();
    double odd=0;
    for(int i=1;i<=N;i++){
      if(!(i%2==0)){
        odd++;
      }
    }
    System.out.println(String.format("%f",(double)odd/N));
  }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N;

vector<string> board;

int boardQuality(vector<string>& board) {
  int n = board.size();
  assert(n == board[0].size());
  set<int> s;
  rep(i, n) {
    set<char> t1, t2;
    rep(j, n) {
      if (board[i][j] != '.') t1.insert(board[i][j]);
      if (board[j][i] != '.') t2.insert(board[j][i]);
    }
    s.insert(t1.size());
    s.insert(t2.size());
    if (s.size() > 1) return -1;
  }
  return *(s.begin());
}

bool printBoard(int n) {
  assert(board.size() == n && board[0].size() == n);

  int q = boardQuality(board);
  if (q == -1) return false;

  printf("(n, k) = (%d, %d)\n", n, q);
  rep(i, n) {
    rep(j, n) cout << board[i][j];
    cout << endl;
  }
  return true;
}

bool searchBoard(int i, int n, int k, int v, int h) {
  if (v == 0 && h == 0) return printBoard(n);
  if (i == n * n) return false;

  int r = i / n;
  int c = i % n;
  if (v > 0 && r + 1 < n && board[r][c] == '.' && board[r + 1][c] == '.') {
    board[r][c] = 'a' + v + h;
    board[r + 1][c] = 'a' + v + h;
    if (searchBoard(i + 1, n, k, v - 1, h)) return true;
    board[r][c] = '.';
    board[r + 1][c] = '.';
  }
  if (h > 0 && c + 1 < n && board[r][c] == '.' && board[r][c + 1] == '.') {
    board[r][c] = 'a' + v + h;
    board[r][c + 1] = 'a' + v + h;
    if (searchBoard(i + 1, n, k, v, h - 1)) return true;
    board[r][c] = '.';
    board[r][c + 1] = '.';
  }
  return searchBoard(i + 1, n, k, v, h);
}

void search() {
  for (int n = 3; n < 7; ++n) {
    printf("searching n = %d...\n", n);
    for (int k = 1; k <= n; ++k) {
      for (int m = 1; 4 * m <= n * n; ++m) {
        if (k * n != 3 * m) continue;
        board = vector<string>(n, string(n, '.'));
        searchBoard(0, n, k, m, m);
      }
    }
  }
}

unordered_map<int, vector<string>> tile = {
    {3, {"c..", "c..", ".bb"}},
    {4, {"ihgg", "ihff", "eedc", "bbdc"}},
    {5,
     {
         "kji..",
         "kji..",
         "hggff",
         "h.edd",
         "ccebb",
     }},
    {6,
     {
         "mlk...",
         "mlk...",
         "j.iihh",
         "jgff..",
         ".g.edd",
         "cc.ebb",
     }},
    {7,
     {
         "aa..hi.",
         "....hin",
         "....jkn",
         "....jkl",
         "bbee..l",
         "ccff..m",
         "..ddggm",
     }}};

int main() {
  cin >> N;

  for (auto it = tile.begin(); it != tile.end(); it++) {
    if (boardQuality(it->second) == -1) {
      printf("Invalid: %d\n", it->first);
      return 0;
    }
  }

  if (N == 2) {
    cout << -1 << endl;
    return 0;
  }

  if (N == 3) {
    for (auto& line : tile[3]) cout << line << endl;
    return 0;
  }

  int y = (N % 4);
  if (y != 0) y += 4;
  int x = (N - y) / 4;

  rep(i, x) {
    rep(j, 4) {
      cout << string(i * 4, '.') << tile[4][j] << string(N - 4 * (i + 1), '.')
           << endl;
    }
  }
  rep(j, y) { cout << string(N - y, '.') << tile[y][j] << endl; }

  return 0;
}


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

typedef long long ll;

ll N;
bool check() {
  for (ll i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    if (a % 2 == 0 && a % 3 != 0 && a % 5 != 0) return false;
  }
  return true;
}
int main() {
  cin >> N;
  cout << (check() ? "APPROVED" : "DENIED") << endl;
  return 0;
}


Measured memory_bytes: 256