akhauriyash/Code-Regression huggingface dataset:
###############################################
#                                             #
#   author: raghav_0901 (Raghav Dalmia)       #
#   updated on: 04-08-2020,  3:48:16 pm IST   #
#                                             #
###############################################


from math import *

k = int(input())

if(k % 2 == 0 or k % 5 == 0):
    print(-1)
else:
    ans = 1
    num = 7 % k
    while(num > 0):
        num = ((num * 10) + 7) % k
        ans = ans + 1
    print(ans)


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

using namespace std;

int main()
{
    string s; cin >> s;
    bool good = false;
    for (int i = 0; i < 2; i++) {
        if (s[i] == s[i + 1] && s[i + 1] == s[i + 2]) {
            good = true;
            break;
        }
    }

    cout << (good ? "Yes" : "No") << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main() {
  int n,m,mod=256;
  cin >> n;
  map<string,P> ma;
  for(int i=0; i<n; i++) {
    string s;
    P p;
    cin >> s >> p.first >> p.second;
    ma[s]=p;
  }
  queue<vector<int> > que;
  cin >> m;
  for(int i=0; i<m; i++) {
    string s;
    cin >> s;
    vector<int> a(mod);
    fill(a.begin(),a.end(),0);
    if(s[0]=='+') a[0]=2;
    else if(s[0]=='-') a[0]=3;
    else if(s[0]=='*') a[0]=4;
    else if(s[0]=='/') a[0]=5;
    else if(isdigit(s[0])) {
      stringstream ss;
      ss << s;
      int x;
      ss >> x;
      a[x%mod]=1;
    } else {
      for(int i=ma[s].first; i<=ma[s].second; i++) a[i]=1;
    }
    que.push(a);
  }
  stack<vector<int> > s;
  while(!que.empty()) {
    vector<int> c=que.front();que.pop();
    if(c[0]>=2) {
      vector<int> a,b,d(mod);
      fill(d.begin(),d.end(),0);
      b=s.top();s.pop();
      a=s.top();s.pop();
      for(int i=0; i<mod; i++) {
	for(int j=0; j<mod; j++) {
	  if(!a[i] || !b[j]) continue;
	  if(c[0]==2) d[(i+j)%mod]=1;
	  if(c[0]==3) d[(i-j+mod)%mod]=1;
	  if(c[0]==4) d[(i*j)%mod]=1;
	  if(c[0]==5) {
	    if(j==0) {
	      cout << "error" << endl;
	      return 0;
	    } else d[(i/j)%mod]=1;
	  }
	}
      }
      s.push(d); 
    } else s.push(c);
  }
  cout << "correct" << endl;
  return 0;
}

Measured memory_bytes: 1364
#include <iostream>
#include <vector>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>

using namespace std;


int main() {
    long long int n;
    cin>>n;
    long long int num=n;
    long long int ans=n-1;

    for (long long int i = 2; i*i <= n; i++) {
          if((n%i)==0 && ans>i+(n/i)-2) ans=i+(n/i)-2;
    	}

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();

        if(A*B > C*D || A*B == C*D){
            System.out.println(A*B);
        }else{
            System.out.println(C*D);
        }
    }
}

Measured memory_bytes: 21716
package main
import (
  "fmt"
)
func main() {
  var a, b int
  fmt.Scan(&a, &b)
  var result int
  for i := 0; i < 100000; i++ {
    if i == 0 {
      if b == 1 {
        result = 0
        break
      } else {
        continue
      }
    }
    if b <= a*i-(i-1) {
      result = i
      break
    }
  }
  fmt.Println(result)
}

Measured memory_bytes: 512
a, b, k = [int(x) for x in input().split()]
i = a
j = b
arr = []
while i < a + k and i <= j:
#     print('i:', i)
    arr.append(i)
    arr.append(j)
    i += 1
    j -= 1
a = list(set(arr))
a.sort()
for i in a:
    print(i)
    

Measured memory_bytes: 3060
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,ans=0,p=0; cin>>n;
    vector<int> a(n,0),v(n,0);
    rep(i,n) cin>>a[i];
    rep(i,n){
        if(v[p]==0){
            v[p]=1; ans++;
            p=a[p]-1;
            if(p==1) break;
        }
        else{
            ans=-1; break;
        }
    }
    cout<<ans<<endl;
}

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

int N, L;
int A[100001];

int main() {
  cin >> N >> L;
  for (int i=1; i<=N; i++) cin >> A[i];

  int s = -1;
  for (int i=1; i<=N-1; i++) {
    if (A[i] + A[i+1] >= L) {
      s = i;
      break;
    }
  }
  if (s == -1) {
    cout << "Impossible\n";
  }
  else {
    cout << "Possible\n";
    for (int i=1; i<s; i++) cout << i << "\n";
    for (int i=N-1; i>=s+1; i--) cout << i << "\n";
    cout << s << "\n";
  }
  return 0;
}


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

int main() {
  int H, W; cin >> H >> W;
  int N; cin >> N;
  vector<int> A;
  for (int i = 1; i <= N; i++) {
    int cnt; cin >> cnt;
    for (int j = 0; j < cnt; j++) A.push_back(i);
  }
  vector<vector<int>> T(H, vector<int>(W));
  int index = 0;
  for (int i = 0; i < W; i++) {
    if (i % 2 == 0) {
      for (int j = 0; j < H; j++) {
        T.at(j).at(i) = A.at(index);
        index++;
      }
    }
    else {
      for (int j = H-1; j >= 0; j--) {
        T.at(j).at(i) = A.at(index);
        index++;
      }
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) cout << T.at(i).at(j) << " ";
    cout << endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
typedef long long ll;
using namespace std;
typedef pair<int,int> P;
vector<int> dir={-1,0,1,0,-1,-1,1,1,-1};

const ll mod=1000000007;

int main() {
  bool flag=true;
	int a,b,c,d;
  cin >> a >> b >> c >> d;
  while(a>0&&c>0){
    c-=b;
    if(c<=0)flag=false;
    a-=d;
  }
  if(flag)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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やllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  ll X;
  cin >> X;
  ll ans = 0;
  for(ll i=1; i<=40; i++){
    ll temp = i;
    for(ll j=1; j<=20; j++){
      temp *= i;
      if(X >= temp){
        chmax(ans,temp);
      }else{
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 
#define nint int
using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> pii;
typedef pair<double,double> dop;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;




signed main()
{
int n,m;
std::cin >> n >> m;
std::vector<int> checklist(n,0);

for(int i = 0; i < m; i++){
    int a,b;
    std::cin >> a >> b;
    a--;
    b--;
    checklist[a]++;
    checklist[b]++;
}
int flag = 0;
for(int i = 0; i < n; i++){
    if(checklist[i] % 2 != 0){
        flag = 1;
        break;
    }
}
if(flag){
    std::cout << "NO" << std::endl;
} else {
    std::cout << "YES" << std::endl;
}
return 0;
}

Measured memory_bytes: 1024
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    M = int(input())
    print(48 - M)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4072
N, M = map(int,input().split())
a_list = list(map(int,input().split()))

a_list = [(-a,a) for a in a_list]

import heapq

heapq.heapify(a_list)
for i in range(M):
#     print(a_list)
    max_a = heapq.heappop(a_list)[1]
    tpl = (-(max_a//2),max_a//2)
    heapq.heappush(a_list, tpl)

print(sum([a for _,a in a_list]))

Measured memory_bytes: 86252
#include <stdio.h>
#include <ctype.h>

int main(int argc, const char * argv[]) {
    char s[1200];
    gets(s);
    int i;
    for(i=0;i<1200;i++){
        if(s[i] == '\0'){
            printf("\n");
            break;
        }
        else if(isupper(s[i])){
            printf("%c",tolower(s[i]));
        }
        else if(islower(s[i])){
            printf("%c", toupper(s[i]));
        }
        else{
            printf("%c",s[i]);
        }
    }
    
    return 0;
}

Measured memory_bytes: 524
let rec countFactors (n : int) =
    let d = n / 2
    let m = n % 2
    if m = 0 then 1 + countFactors d
    else 0


let maxOperations (xs : seq<int>) =
    Seq.map countFactors xs |> Seq.sum


[<EntryPoint>]
let main argv = 
    let _ = stdin.ReadLine()
    let xs = stdin.ReadLine().Split(' ') |> Array.map int
    maxOperations xs |> printfn "%d"
    0


Measured memory_bytes: 15068
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a,int b){
    if(b==0) return a;
    return saidaikouyakusuu(b,a%b);
}
int saisyoukoubaisuu(int a,int b){
    return a*b/saidaikouyakusuu(a,b);
}
int n,m,cnt=0,aa[220000],ans=0,x,y,ab[220000];
pair<int,int> pp[220000];
string s,ss[220000];
char c;
queue<int> que;
signed main(){
    cin>>n>>m>>x>>y;
    rep(i,n){
        cin>>aa[i];
        x=max(x,aa[i]);
    }
    rep(i,m){
        cin>>ab[i];
        y=min(y,ab[i]);
    }
    if(y<=x){
        cout<<"War"<<endl;
    }else{
        cout<<"No War"<<endl;
    }
}

Measured memory_bytes: 10528
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

constexpr int INF = 100000000;

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

void bfs(vector<vector<int>> &I, pair<int, int> s, vector<string> &C, int H, int W) {
    queue<pair<int, int>> Q;
    Q.push(s);
    I[s.first][s.second] = 0;
    while (!Q.empty()) {
        auto p = Q.front();
        Q.pop();
        int y = p.first;
        int x = p.second;
        for (int i = 0; i < 4; i++) {
            int toY = y + dy[i];
            int toX = x + dx[i];
            int cost = I[y][x] + 1;
            if (toY < 0 || toY >= H || toX < 0 || toX >= W) continue;
            if (I[toY][toX] != INF) continue;
            if(C[toY][toX] == 'x') continue;
            I[toY][toX] = cost;
            Q.push(make_pair(toY, toX));
        }
    }
}

int main() {

    while (true) {

        int W, H;
        cin >> W >> H;

        if (!(W | H)) break;

        vector<string> C(H);
        for (int i = 0; i < H; i++) cin >> C[i];

        pair<int, int> s;
        for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (C[i][j] == 'o') s = make_pair(i, j);

        vector<pair<int, int>> dirty;
        for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (C[i][j] == '*') dirty.push_back(make_pair(i, j));

        vector<vector<int>> s_I(H, vector<int>(W, INF));
        vector<vector<vector<int>>> D_I(dirty.size(), vector<vector<int>>(H, vector<int>(W, INF)));

        bfs(s_I, s, C, H, W);
        for (int i = 0; i < D_I.size(); i++) bfs(D_I[i], dirty[i], C, H, W);

        vector<int> order(dirty.size());
        for (int i = 0; i < order.size(); i++) order[i] = i;

        int ans = INF;
        do {
            int sum = s_I[dirty[order[0]].first][dirty[order[0]].second];
            for(int i = 0;i<order.size() - 1;i++) sum += D_I[order[i]][dirty[order[i+1]].first][dirty[order[i+1]].second];
            ans = min(ans, sum);
        } while (next_permutation(order.begin(), order.end()));


        if(ans >= INF) cout << -1 << endl;
        else cout << ans << endl;

    }

    return 0;
}


Measured memory_bytes: 3084
H,W,K = map(int,input().split())
S = [list(input()) for _ in range(H)]

ANS = [[-1] * W for _ in range(H)]
n = 0

def paint(l,r,t,b):
    global H,W,K,S,ANS,n
    n += 1
    for x in range(l,r):
        for y in range(t,b):
            ANS[y][x] = n

def horizontalCut(l, r):
    global H,W,K,S,ANS
    e = []
    for x in range(l,r):
        for y in range(H):
            if S[y][x] == '#':
                e.append(y)
    e.sort()
    for i in range(len(e)):
        t = 0 if i == 0 else e[i]
        b = H if i == len(e)-1 else e[i+1]
        paint(l,r,t,b)

e = []
for x in range(W):
    for y in range(H):
        if S[y][x] == '#':
            e.append(x)
            break
for i in range(len(e)):
    l = 0 if i == 0 else e[i]
    r = W if i == len(e)-1 else e[i+1]
    horizontalCut(l,r)

for ans in ANS:
    print(*ans)


Measured memory_bytes: 50908
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
ll N;
ll A[200010];

int d[25];  //ここまで立っているビットは何個あったか？（偶奇をチェック）
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>N;
    REP(i,0,N) {
        cin >> A[i];
    }

    ll ans = 0LL;

    int l=0, r=0;
    while(true) {
        //cout<<"l: "<<l<<", r: "<<r<<endl;
        while(r < N){
            bool f = false;
            REP(i,0,20){
                if(d[i] && (1<<i)&A[r]){
                    f = true;
                }
            }
            if(f) break;
            REP(i,0,20){
                if((1<<i)&A[r])d[i]++;
            }
            r++;
        }
        ans += r - l;

        if(l==N-1 && r==N) break;

        while(true){
            bool t = false;
            REP(i,0,20){
                if((1<<i)&A[l])d[i]--;
            }
            REP(i,0,20){
                if(d[i] > 1){
                    t = true;
                }
            }

            l++;
            if(!t) break;
        }
    }

    cout<<ans<<endl;

    return 0;
}




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

using namespace std;

#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
    FAST();
    int n;
    string s;
    map<string,int>mp;
    cin >> n;
    while(n--)
    {
        cin >> s;
        ++mp[s];
    }
    cout << "AC x " << mp["AC"] << '\n';
    cout << "WA x " << mp["WA"] << '\n';
    cout << "TLE x " << mp["TLE"] << '\n';
    cout << "RE x " << mp["RE"] << '\n';
    return 0;
}


Measured memory_bytes: 3652
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	k = 0
	for i in 1:n
		if a[i]%2==1
			k += 1
		end
	end
	println(k%2==0?"YES":"NO")
end
main()


Measured memory_bytes: 174516
import java.util.*;

class Main{
    final static long mod = 1000000007;
    //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long[] cap = new long[5];
        for(int i = 0; i < 5; i++) cap[i] = sc.nextLong();
        long max = 0;
        for(int i = 0; i < 5; i++){
            max = Math.max((n + cap[i] - 1) / cap[i], max);
        }
        System.out.println(max + 4);
    }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  sort(a.begin(), a.end());
  int ans = 0;
  int last = 0;
  int exist = 0;
  rep(i, n) {
    if (a[i] == last) exist = 1 - exist;
    else {
      ans += exist;
      last = a[i];
      exist = 1;
    }
  }
  ans += exist;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007


void solve(void)
{ 
  int N,x;
  cin>>N>>x;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
  }
  int ANS = 0;

  for (int i = 0; i < N; i++)
  {
    if(vec[i] > x)
    {
      ANS += vec[i] -x;
      vec[i] = x;
    }
  }

  for (int i = 0; i < N-1; i++)
  {
    int SUM = vec[i] + vec[i+1];
    if(SUM > x)
    {
      ANS += SUM -x;
      vec[i+1] -= SUM -x;
    }
  }

  cout<<ANS<<endl;
  
  
  

  
}



int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // std::cout << std::fixed;
  // std::cout << std::setprecision(8);

  solve();

 
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
using namespace std;
ll h, w; char a[114][114], b[114][114];
signed main() {
	cin >> h >> w;
	rep(i, h) { rep(j, w)cin >> a[i][j]; }
	for (int i = 0; i < h + 2; i++) {
		for (int j = 0; j < w + 2; j++) {
			if (i == 0 || i == h + 1 || j == 0 || j == w + 1)b[i][j] = '#';
			else b[i][j] = a[i - 1][j - 1];
		}
	}
	for (int i = 0; i < h + 2; i++) {
		for (int j = 0; j < w + 2; j++) {
			cout << b[i][j];
		}
		cout << endl;
	}
	cout << endl;
	getchar(); getchar(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    int A,B;
    cin>>A>>B;
    int now=1;
    int cnt=0;
    while(1){
        if(now>=B){
            break;
        }
        now+=A;
        now--;
        cnt++;
    }
    cout<<cnt<<endl;
}


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

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
		cout << fixed << setprecision( 10 );
	}

	void solve() {
		int N, K;
		cin >> N >> K;

		vector<int> x( N );
		for( auto& v: x ) { cin >> v; }

		int ans = INT_MAX;
		for( int i = 0; i < N-K+1; ++i ) {
			int a = x[i+K-1] - x[i];
			ans = min( { ans, abs( x[i] )+a, abs( x[i+K-1] )+a } );
		}

		cout << ans << endl;
	}
};

int main() {
	Solver().solve();
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int NPrime=3000000;
bool prime[NPrime+1];
vi EnumeratePrime(){
	fill(prime+2,prime+NPrime+1,true);
	vi a;
	for(int i=2;i<=NPrime;i++) if(prime[i]){
		a.emplace_back(i);
		for(int j=2*i;j<=NPrime;j+=i) prime[j]=0;
	}
	return a;
}

int n,m,k;

int main(){
	while(1){
	cin>>n>>m>>k;
	if(n==0) break;
	k--;
	vip a(m);
	for(int i=0;i<m;i++){
		int h,p,q;
		cin>>h>>p>>q;
		a[i]={-h,{p-1,q-1}};
	}
	sort(a.begin(),a.end());
	for(int i=0;i<m;i++){
		int x=a[i].second.first,y=a[i].second.second;
		if(x==k){
			k=y;
		}
		else if(k==y) k=x;
	}
	cout<<k+1<<endl;
	
	}
}


Measured memory_bytes: 3044
#include <iostream>
    using namespace std;
    int main() {
      int a,b,c;
      cin>>a>>b>>c;
      if(a==b){
          cout<<c;
      }
      else if(a==c){
          cout<<b;
      }
      else if(b==c){
          cout<<a;
      }
    }

Measured memory_bytes: 256
def solve(n, a_list):

    # judge_if_possible
    b_list = [0] * (n + 1)  # nodes with child

    for d in range(n + 1):
        if d == 0:
            n_nodes = 1
        else:
            n_nodes = b_list[d - 1] * 2
        if a_list[d] > n_nodes:
            return -1
        b_list[d] = n_nodes - a_list[d]
    # print(a_list, b_list)
    # backward
    b_list[n] = 0
    for i in range(n - 1, -1, -1):
        b_list[i] = min(b_list[i], a_list[i + 1] + b_list[i + 1])
    res = sum(a_list) + sum(b_list)
    # print(a_list, b_list, res)
    return res


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    res = solve(n, a_list)
    print(res)


def test():
    assert solve(3, [0, 1, 1, 2]) == 7
    assert solve(4, [0, 0, 1, 0, 2]) == 10
    assert solve(2, [0, 3, 1]) == -1
    assert solve(10, [0, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34]) == 264


if __name__ == "__main__":
    test()
    main()


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

template <int32_t MOD>
struct mint {
    int32_t data;
    mint() = default;  // data is not initialized
    mint(int32_t value) : data(value) {}  // assume value is in proper range
    inline mint<MOD> operator + (mint<MOD> other) const { int32_t c = this->data + other.data; return mint<MOD>(c >= MOD ? c - MOD : c); }
    inline mint<MOD> & operator += (mint<MOD> other) { this->data += other.data; if (this->data >= MOD) this->data -= MOD; return *this; }
};

constexpr int MOD = 1e9 + 7;
mint<MOD> solve(ll n) {
    mint<MOD> dp[64][2][2][2] = {};
    dp[63][1][1][0] = 1;
    REP_R (k, 63) {
        REP (u_eq, 2) REP (v_eq, 2) REP (c_k, 2) {
            REP (a_k, 2) REP (b_k, 2) if (a_k <= b_k) {
                REP (u_eq1, 2) REP (v_eq1, 2) {
                    int n_k = bool(n & (1ll << k));
                    int u_k = a_k ^ b_k;
                    int v_k = (a_k + b_k + c_k) & 1;
                    int c_k1 = (a_k + b_k + c_k) >= 2;
                    if (u_eq  and not u_eq1) continue;
                    if (u_eq  and n_k != u_k) continue;
                    if (v_eq  and not v_eq1) continue;
                    if (v_eq  and n_k != v_k) continue;
                    if (u_eq1 and n_k == u_k and not u_eq) continue;
                    if (u_eq1 and n_k <  u_k) continue;
                    if (v_eq1 and n_k == v_k and not v_eq) continue;
                    if (v_eq1 and n_k <  v_k) continue;
                    dp[k][u_eq][v_eq][c_k] += dp[k + 1][u_eq1][v_eq1][c_k1];
                }
            }
        }
    }
    mint<MOD> answer = 0;
    REP (u_eq, 2) REP (v_eq, 2) answer += dp[0][u_eq][v_eq][0];
    return answer;
}

int main() {
    ll n; cin >> n;
    cout << solve(n).data << endl;
    return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

X = Base_10_to_n(N, K)
X_ = str(X)
print(len(X_))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define W '.'
#define B '#'
using namespace std;


int main() {
    int h, w;

    cin >> h >> w;

    char a[h][w];
    bool allWh[h];
    bool allWw[w];

    for (int i = 0; i < h; i++) {
        allWh[i] = true;
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
            if (a[i][j] != W) allWh[i] = false;
        }
    }

    for (int j = 0; j < w; j++) {
        allWw[j] = true;
        for (int i = 0; i < h; i++) {
            if (a[i][j] != W) allWw[j] = false;
        }
    }

    for (int i = 0; i < h; i++) {
        if (allWh[i]) continue;
        for (int j = 0; j < w; j++) {
            if (allWw[j]) continue;
            cout << a[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define N 200010
namespace seg{
  ll dat[2*N];
  void init(){
      for(int i=0;i<2*N;i++)dat[i]=0;
  }  
  void upd(ll i,ll val){
      i+=N; dat[i]+=val;
      for(;i;i>>=1){
	  dat[i/2]=dat[i]+dat[i^1];
      }
  }
  ll sum(ll l,ll r){
      l+=N,r+=N+1;
      ll res=0;
      for(ll a=l,b=r;a<b;a>>=1,b>>=1){
	  if(a&1)res+=dat[a++];
	  if(b&1)res+=dat[--b];
      }
      return res;
  }
};
struct str{
  ll id,score;
  bool operator<(const str&key)const{
      if(this->score==key.score){
	  return this->id>key.id;
      }
      return this->score<key.score;
  }  
};
str strs(ll id,ll score){
    str gen;gen.id=id,gen.score=score;
    return gen;
}
ll n,q;
ll type[N],a[N],b[N];
ll p[N],c[N];
vector<str> v;
int main(){
    cin>>n>>q;
    for(int i=1;i<=n;i++)v.push_back(strs(i,0));
    for(int i=0;i<q;i++){
	cin>>type[i];
	if(type[i]==0)cin>>a[i]>>b[i];
	else cin>>a[i];
    }
    for(int i=1;i<=n;i++)p[i]=0;
    for(int i=0;i<q;i++){
	if(type[i]==1)continue;
	p[a[i]]+=b[i];
	v.push_back(strs(a[i],p[a[i]]));
    }
    /*
    cout<<"---"<<endl;
    for(auto x:v){
	cout<<x.id<<" "<<x.score<<endl;
    }cout<<"---"<<endl;*/
    vector<pair<str,ll> >za;
    for(int i=0;i<v.size();i++){
	za.push_back(make_pair(v[i],i));
    }
    sort(za.begin(),za.end());
    for(int i=0;i<v.size();i++){
	c[za[i].second]=i;
    }
    //for(int i=0;i<v.size();i++)cout<<c[i]<<" ";cout<<endl;
    seg::init();
    for(int i=1;i<=n;i++){
	p[i]=n-i;
	seg::upd(p[i],+1);
    }
    ll t=n;
    for(int i=0;i<q;i++){
	if(type[i]==0){
	    seg::upd(p[a[i]],-1);
	    seg::upd(c[t],+1);
	    p[a[i]]=c[t]; t++;
	}
	if(type[i]==1){
	    ll l=-1,r=N-1,mid;
	    while(l<r-1){
		mid=(l+r)/2;
		if(seg::sum(mid,N-1)>=a[i])l=mid;
		else r=mid;
	    }
	    cout<<za[l].first.id<<" "<<za[l].first.score<<endl;
	}
    }
    return 0;
}



Measured memory_bytes: 21504
A=int(input())
def divisor_enu(N):
   S=1
   for i in range(2,int(N**0.5)+1):
      cnt=0
      if N%i==0:
         while N%i==0:
            cnt+=1
            N//=i
         S*=(cnt+1)
   if N != 1:
      S*=2
   return S
ans=0
for i in range(1,A+1):
   if divisor_enu(i)==8 and i%2==1:
      ans+=1
print(ans)

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

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

typedef long long ll;



int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    vector<char> str(ALL(s)); 
    REP(i,str.size()) {
        char av = N+str[i];
        if (av>'Z') av-=26;
        cout << av;
    }
    cout << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define piii pair<ll, pii>
#define MOD 1000000007
#define M 100005
#define inf 1000000005
using namespace std;
ll h[M];
ll dp[M];
ll n;

int main(){
    //ll t; cin>> t; while(t--){
        cin>> n;
        for(ll i =1;i<=n;i++){
            cin>> h[i];
            dp[i]  = inf;
        }
        dp[1] = 0;
        for(ll i =1;i<=n;i++){
            if(i+1<=n) dp[i+1]  = min(dp[i+1], dp[i]+ abs(h[i+1]- h[i]));
            if(i+2<=n) dp[i+2]  = min(dp[i+2], dp[i]+ abs(h[i+2]- h[i]));
        }
        cout << dp[n] << endl;

}


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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  int res = 0;
  for (int i = 0; i < s.size(); i++) {
    int cnt = 0;
    for (int j = 0; j < s.size() - i; j++) {
      if (s[i + j] == 'A' || s[i + j] == 'T'
          || s[i + j] == 'G' || s[i + j] == 'C') {
        cnt++;
      } else {
        break;
      }
    }
    res = max(res, cnt);
  }

  cout << res << endl;

  return 0;
}


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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    FOREACH(x, v) { cout << x << " "; }                                        \
    cout << "\n";

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N, M;
VL a, b;

struct UnionFind {
    vector<int> par;
    vector<int> sizes;

    UnionFind(int n) : par(n), sizes(n, 1) { REP(i, n) par[i] = i; }

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

    void unite(int x, int y) {
        x = find(x);
        y = find(y);

        if(x == y) return;

        if(sizes[x] < sizes[y]) swap(x, y);

        par[y] = x;
        sizes[x] += sizes[y];
        sizes[y] = 0;
    }

    bool same(int x, int y) { return find(x) == find(y); }

    int size(int x) { return sizes[find(x)]; }
};

int main() {
    cin >> N >> M;
    REP(i, M) {
        a.emplace_back(IN());
        b.emplace_back(IN());
    }
    ll ans = 0;
    REP(i, M) {
        auto uf = UnionFind(N + 1);
        REP(j, M) {
            if(j != i) uf.unite(a[j], b[j]);
        }
        if(uf.size(1) != N) ans++;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define EPS 0.01
using namespace std;

class Point{
public:
  double x, y, z;
};


double norm(Point a, Point b){
  return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z);
}
double abs(Point a, Point b){
  return sqrt(norm(a, b));
}
main(){
  Point in[30];
  double qr, rp, pq;
  int n;
  while(cin >> n){
    int np;
    for(int count=0;count<n;count++){
      cin >> qr >> rp >> pq;
      cin >> np;
      for(int i=0;i<np;i++){
	cin >> in[i].x >> in[i].y >> in[i].z;
      }
      bool end=false;
      for(int p=0;p<np;p++){
	for(int q=0;q<np;q++){
	  if(p==q) continue;
	  for(int r=0;r<np;r++){
	    if(p==r) continue;
	    if(q==r) continue;
	    double a, b, c;
	    a=abs(in[q], in[r]);
	    b=abs(in[r], in[p]);
	    c=abs(in[p], in[q]);
	    double tmp=a/qr;
	    if(b/rp>=tmp-EPS && b/rp<=tmp+EPS){
	      printf("%d %d %d\n", p+1, q+1, r+1);
	      end=true;
	      break;
	    }else if(c/pq>=tmp-EPS && c/pq<=tmp+EPS){
	      printf("%d %d %d\n", p+1, q+1, r+1);
	      end=true;
	      break;
	    }
	  }
	  if(end) break;
	}
	if(end) break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#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 = 1001001001;

int main(){
  int h,w,n;
  cin >> h >> w >> n;
  int mn = min(h,w);
  int mx = max(h,w);

  int cnt = 0;
  while(n>0){
    n -= mx;
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3620
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]


a = int(input())
s = str(input())
ans = 0

if(a>=3200):
    print(s)
else:
    print("red")

#print(ans)


Measured memory_bytes: 75004
n = int(input())
lst = [0] *4

for i in range(n):
  a = input()
  if a == 'AC':
    lst[0] += 1
  if a == 'WA':
    lst[1] += 1
  if a == 'TLE':
    lst[2] += 1
  if a == 'RE':
    lst[3] += 1
    
print('AC x',lst[0])
print('WA x',lst[1])
print('TLE x',lst[2])
print('RE x',lst[3])

Measured memory_bytes: 9208
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a=0;
    int b=0;
    int p[10];
    int c=0;
    for(int i=0;i<n;i++){
        cin >> p[i];
        if(a<p[i]) a=p[i];
    }
    for(int i=0;i<n;i++){
        if(a==p[i]&&c==0) c=1,b+=p[i]/2;
        else b+=p[i];
    }
    cout << b <<endl;
    
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import *

def judge(x):
    d = defaultdict(int)
    
    for i in range(N-x+1):
        k = hash(S[i:i+x])
        
        if k not in d:
            d[k] = i
        else:
            if i-d[k]>=x:
                return True
    
    return False

def binary_search():
    l, r = 0, N
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            l = m+1
        else:
            r = m-1
    
    return r

N = int(input())
S = input()[:-1]

print(binary_search())

Measured memory_bytes: 43356
#include <stdio.h>
  
int main(void){
    int a,b;
    scanf("%d",&a);
    scanf("%d",&b);
    if(a<b)
       puts("a < b");
    else if(a>b)
       puts("a > b");
    else
       puts("a == b");
      return 0;
  }

Measured memory_bytes: 1756
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;
const int di[]={-1,0,1,0};
const int dj[]={0,-1,0,1};

int main()
{
    int h,w;
    cin>>h>>w;
    vector<string> s(h);
    rep(i,h)
    {
        cin>>s[i];
    }
    vector<vector<int>> vl(h,vector<int>(w,0)),vr(h,vector<int>(w,0)),vu(h,vector<int>(w,0)),vd(h,vector<int>(w,0));
    int ans=0;
    rep(i,h)
    {
        int cl=0,cr=0;
        rep(j,w)
        {
            if(s[i][j]=='#')
            {
                cl=0;
            }
            else
            {
                cl++;
            }
            vl[i][j]=cl;

            if(s[i][w-j-1]=='#')
            {
                cr=0;
            }
            else
            {
                cr++;
            }
            vr[i][w-j-1]=cr;
        }
    }

    rep(i,w)
    {
        int cu=0,cd=0;
        rep(j,h)
        {
            if(s[j][i]=='#')
            {
                cu=0;
            }
            else
            {
                cu++;
            }
            vu[j][i]=cu;

            if(s[h-1-j][i]=='#')
            {
                cd=0;
            }
            else
            {
                cd++;
            }
            vd[h-1-j][i]=cd;
        }
    }
    rep(i,h)
    {
        rep(j,w)
        {
            ans=max(ans,vl[i][j]+vr[i][j]+vu[i][j]+vd[i][j]-3);
        }
    }
    cout<<ans;
}


Measured memory_bytes: 73692
N = int(input())
a = []
b = ''
flag = 0

for i in range(N):
    t, b = b, input()

    if i != 0:
        if t[-1] != b[0]:
            flag = 1
            break

    if b not in a:
        a.append(b)
    else:
        flag = 1
        break

if flag == 1:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 3060
N, A, B = map(int, input().strip().split())

a, b, c, d, e = 0, 0, 0, 0, 0
ans = 0

for i in range(1, N+1):
    e += 1
    if e == 10:
        d += 1
        e = 0

    if d == 10:
        c += 1
        d = 0

    if c == 10:
        b += 1
        c = 0

    if b == 10:
        a += 1
        b = 0

    sum = a + b + c + d + e
    if sum >= A and sum <= B:
        ans += i

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1)
	{
		cerr << name << " = " << arg1 << endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args)
	{
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
		__f(comma+1, args...);
	}
#else
#define debug(...)
#endif
 
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}
 
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}
 
#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"
 
// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;
 
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;
 
int main()
{
	FAST_IO;
 
 	ll n, cnt = 0, c = 0;
 	cin >> n;
 	string a;
 	cin >> a;
 	vector<ll>v;
 	for(int i=n-1;i>=0;i--) if(a[i] == 'R') v.pb(i);
 	for(int i=0;i<n;i++)
 	{
 		if(a[i] == 'R') continue;
 		if(c < sz(v) && v[c] > i)
 		{
 		    c += 1;
 			cnt += 1;
 			swap(a[i], a[v[c]]);
 		}
 	}
 	cout << cnt << endl;
    return 0;
}


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

void solve(long long A, long long B, long long K) {
    if (K >= A) {
        cout << 0 << " ";
        K -= A;
    } else {
        cout << A - K << " ";
        K = 0;
    }
    if (K >= B) {
        cout << 0 << endl;
    } else {
        cout << B - K << endl;
    }
}

int main() {
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long K;
    scanf("%lld", &K);
    solve(A, B, K);
    return 0;
}


Measured memory_bytes: 3664
from itertools import combinations
n, k = map(int, input().split())
if k>(n-1)*(n-2)//2:
    print(-1)
    exit(0)
edges = []
for i in range(2, n+1):
    edges.append((1, i))
k = (n-1)*(n-2)//2-k
for i, j in combinations(range(2, n+1), 2):
    if k==0:
        break
    edges.append((i, j))
    k -= 1
print(len(edges))
for i, j in edges:
    print(i, j)

Measured memory_bytes: 9424
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
signed main() {
	ll n, m;
	string s, t;
	cin >> n >> m >> s >> t;
	for (int i = 0; i < gcd(n, m); i++) {
		if (s[i * (n / gcd(n, m))] != t[i * (m / gcd(n, m))]) { puts("-1"); ggr }
	}
	cout << lcm(n, m) << endl;
	ggr
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
    int n,A,B,C,D;
    cin>>n;
    D=n%10;n/=10;
    C=n%10;n/=10;
    B=n%10;n/=10;
    A=n%10;n/=10;
    if(A+B+C+D==7){cout<<A<<'+'<<B<<'+'<<C<<'+'<<D<<"=7";return 0;}
    if(A+B+C-D==7){cout<<A<<'+'<<B<<'+'<<C<<'-'<<D<<"=7";return 0;}
    if(A+B-C+D==7){cout<<A<<'+'<<B<<'-'<<C<<'+'<<D<<"=7";return 0;}
    if(A-B+C+D==7){cout<<A<<'-'<<B<<'+'<<C<<'+'<<D<<"=7";return 0;}
    if(A+B-C-D==7){cout<<A<<'+'<<B<<'-'<<C<<'-'<<D<<"=7";return 0;}
    if(A-B-C+D==7){cout<<A<<'-'<<B<<'-'<<C<<'+'<<D<<"=7";return 0;}
    if(A-B+C-D==7){cout<<A<<'-'<<B<<'+'<<C<<'-'<<D<<"=7";return 0;}
    if(A-B-C-D==7){cout<<A<<'-'<<B<<'-'<<C<<'-'<<D<<"=7";return 0;}

}


Measured memory_bytes: 256
A = list(input())
B = list(input())
C = list(input())
tmp = A.pop(0)
while True:
    if tmp == "a":
        if len(A) == 0:
            print("A")
            break
        else:
            tmp = A.pop(0)
    if tmp == "b":
        if len(B) == 0:
            print("B")
            break
        else:
            tmp = B.pop(0)
    if tmp == "c":
        if len(C) == 0:
            print("C")
            break
        else:
            tmp = C.pop(0)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

string s[100'000];
uint64_t num[100'000][26];
uint64_t h[100'000];

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

    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
        for (int j = 0; j < 26; j++)
        {
            num[i][j] = 0;
        }
        for (int j = 0; j < s[i].size(); j++)
        {
            num[i][s[i][j] - 'a']++;
        }
    }

    for (int i = 0; i < n; i++)
    {
        h[i] = 0;
        for (int j = 0; j < 26; j++)
        {
            h[i] = h[i] * 11 + num[i][j];
        }
    }

    map<uint64_t, uint64_t> m;
    for (int i = 0; i < n; i++)
    {
        m[h[i]]++;
    }

    uint64_t result = 0;
    for (const auto &ha : m)
    {
        uint64_t z = ha.second;
        result += z * (z - 1) / 2;
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 34560
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    cin >> N;
    double p[N];
    for (int i = 0; i < N; i++) cin >> p[i];

    double dp[N+1][N+1];
    fill(dp[0], dp[N+1], 0);
    dp[0][0] = 1;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i + j >= N) continue;

            dp[i+1][j] += dp[i][j] * p[i+j];
            dp[i][j+1] += dp[i][j] * (1 - p[i+j]);
        }
    }

    double ret = 0;
    for (int j = 0; j <= N; j++) {
        for (int i = j + 1; i <= N; i++) {
            if (i + j != N) continue;
            ret += dp[i][j];
        }
    }

    cout << setprecision(10) << ret << endl;

    return 0;
}

Measured memory_bytes: 70528