akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
  IOS();
  string s;
  cin>>s;
  int cnt = 0;
  REP(i,6)if( s[i]=='1' ) cnt++;
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN=3010;
string s,dp[2][MAXN];
char x;
int sl,tl;

int main(){
	cin>>s,sl=s.size(),s=" "+s; cin.get();
	while(x=getchar()){
		if(x=='\n') break;
		++tl;
		for(register int j=1;j<=sl;++j){
			if(s[j]==x) dp[tl&1][j]=dp[(tl-1)&1][j-1]+x;
			else dp[tl&1][j]=(dp[(tl-1)&1][j].size()>dp[tl&1][j-1].size()?dp[(tl-1)&1][j]:dp[tl&1][j-1]);
		}
	}
	cout<<dp[tl&1][sl]<<endl;
	return 0;
}

Measured memory_bytes: 16920
import java.util.Scanner;

public class Main {

    private static int[] banboo;
    private static int N;
    private static int A;
    private static int B;
    private static int C;

    private static int INF = 1000000;

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

        N = scanner.nextInt();
        A = scanner.nextInt();
        B = scanner.nextInt();
        C = scanner.nextInt();

        banboo = new int[N];

        for(int i=0; i<N; i++){
            banboo[i] = scanner.nextInt();
        }

        System.out.println(dfs(0, 0, 0, 0));

    }

    private static int dfs(int depth, int a, int b, int c){

        if(depth == N){
            if(a==0 || b==0 || c ==0){
                return INF;
            }else{
                return Math.abs(A - a) + Math.abs(B - b) + Math.abs(C - c) - 30;
            }
        }

        int ret0 = dfs(depth+1, a, b, c);
        int ret1 = dfs(depth+1, a + banboo[depth], b, c) + 10;
        int ret2 = dfs(depth+1, a , b+ banboo[depth], c) + 10;
        int ret3 = dfs(depth+1, a , b, c+ banboo[depth]) + 10;

        return Math.min(Math.min(ret0, ret1), Math.min(ret2, ret3));

    }


}


Measured memory_bytes: 22336
N = int(input())
S = input()

W = [0 for k in range(N)]
E = [0 for k in range(N)]

for k in range(1,N):
    if S[k-1] == "W":
        W[k] = W[k-1] + 1
    else:
        W[k] = W[k-1]

for k in range(1,N):
    if S[N-k] == "E":
        E[N-k-1] = E[N-k] + 1
    else:
        E[N-k-1] = E[N-k]

ans = 10**9
for k in range(N):
    ans = min(W[k]+E[k],ans)

print(ans)


Measured memory_bytes: 17872
#include<cstdio>
#include<algorithm>
#define maxn 100005
using namespace std;
int n,k,x[maxn],ans=2147483647;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&x[i]);
	int l=1,r=k;
	for(;r<=n&&x[r]<=0;l++,r++) ans=min(ans,-x[l]);
	for(;r<=n&&x[l]<0;l++,r++) ans=min(ans,-x[l]*2+x[r]);
	for(;r<=n;l++,r++) ans=min(ans,x[r]);
	l=n-k+1,r=n;
	for(;l&&x[l]>=0;l--,r--) ans=min(ans,x[r]);
	for(;l&&x[r]>0;l--,r--) ans=min(ans,x[r]*2-x[l]);
	for(;l;l--,r--) ans=min(ans,-x[l]);
	printf("%d\n",ans);
}

Measured memory_bytes: 512
N,M,C=map(int, input().split())
B = list(map(int,input().split()))

ans = 0
for i in range(N):
  A = list(map(int, input().split()))
  score = C
  for j in range(M):
    score += A[j] * B[j]
  if(score > 0):
    ans += 1
print(ans)


Measured memory_bytes: 3060
/******************************************
 *  Author : Atul Anand   
 *  Created On : Sat Feb 08 2020
 *******************************************/

import java.io.*;
import java.util.*;

public class Main{
    
    public static void main(String[] args) throws IOException {
        int N=in.nextInt();
        int K=in.nextInt();
        int h[]=new int[N];
        read(h, N);
        int cost[]=new int[N];
        Arrays.fill(cost, -1);
        cost[0]=0;
        println(minCost(h, cost, N-1, K));
        in.close();
        out.close();
    }

    // first memoization code
    public static int minCost(int h[], int cost[], int j, int K){
        if(cost[j]!=-1){
            return cost[j];
        }
        int totalCost=MAX;
        for(int i=1;i<=K;i++){
            if(j-i>=0){
                totalCost=Math.min(totalCost, minCost(h, cost, j-i, K)+Math.abs(h[j-i]-h[j]));
            }
        }
        cost[j]=totalCost;
        return totalCost; 
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);
    static void read(int arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=in.nextInt(); } }
    static void read(long arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=in.nextLong(); } }
    static void read(String arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=in.next(); } }
    static void print(Object O){ out.print(O); }
    static void println(Object O){ out.println(O); }
    static void print(int arr[]){ for(int i=0;i<arr.length;i++){ print(arr[i]+" "); } println(""); }
    static void print(int arr[][]){ for(int i=0;i<arr.length;i++){ print(arr[i]); } }
    static void debug(Object O){ System.out.println(O); }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { tokenizer=new StringTokenizer(reader.readLine()); }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { return Integer.parseInt(next()); }
    double nextDouble() throws IOException { return Double.parseDouble(next()); }
    long nextLong() throws IOException { return Long.parseLong(next()); }
    String nextLine() throws IOException { return reader.readLine(); }
    void close() throws IOException { reader.close(); }
}

Measured memory_bytes: 47264
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools
import heapq
#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
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

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    a,b,h,m=map(int,input().split())
    akakudo=h*5+m/12
    bkakudo=m
    kakudosa=abs(akakudo-bkakudo)
    if kakudosa>=30:
        kakudosa=60-kakudosa
    bx=b*math.cos(math.radians(kakudosa*6))
    by=b*math.sin(math.radians(kakudosa*6))
    ans=math.sqrt((a-bx)**2+by**2)
    print(ans)



if __name__ == "__main__":

    main()

Measured memory_bytes: 10104
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
//グローバル変数宣言
 ll p=0,q=0,r=0;


int main(){
   ll n,x;
   cin>>n>>x;
   vl a(n);
   rep(i,n)cin>>a[i];
   sortp(a);
   rep(i,n){p+=a[i];
            if(x<p){q=i;break;}
            if(i==n-1){if(p==x)q=n;else q=n-1;}}
   print(q);
}

Measured memory_bytes: 3608
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> result(N, 0);
	int ac = 0, wa = 0;
	for (int i = 0; i < M; ++i) {
		int p; string s;
		cin >> p >> s; --p;
		if (s == "WA") {
			if (result[p] != -1) {
				++result[p];
			}
		}
		if (s == "AC") {
			if (result[p] != -1) {
				wa += result[p];
				result[p] = -1;
				++ac;
			}
		}
	}
	cout << ac << ' ' << wa << endl;
	return 0;
}

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


int wari(int h){
 
 
  
   int ans = 0;
  
    while (h > 0) {
		
      
        if (h%2 == 0){
          
           h = h/2;
            
           ans++;
          
        }else{
          
          break;
          
        }
      
		
	}
  
  
  
  return ans;
}

int main() {
  
    int n;
   
 
   cin >> n;
  
  
   int ans = 0;
  
   int lastans = 1;
  
   for (int i = 1;i < n + 1; i++){
     
     int temp = wari(i);
     
     if (ans < temp){
       
       ans = temp;
       
       lastans = i;
       
     }
        
   }
  
 
   cout << lastans << endl;
  return 0;
}

Measured memory_bytes: 256
c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())

if not(c12-c11 == c22-c21 == c32-c31):
    print("No")
    quit()
if not(c13-c12 == c23-c22 == c33-c32):
    print("No")
    quit()
if not(c21-c11 == c22-c12 == c23-c13):
    print("No")
    quit()
if not(c31-c21 == c32-c22 == c33-c23):
    print("No")
    quit()

print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vl sa(n + 1, 0), sb(m + 1, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    sa[i + 1] = sa[i] + a;
  }
  rep(i, m) {
    ll b;
    cin >> b;
    sb[i + 1] = sb[i] + b;
  }
  ll ans = 0;
  rep(i, n + 1) {
    if(sa[i] > k) continue;
    ll in = upper_bound(all(sb), k - sa[i]) - sb.begin() - 1;
    ans = max(ans, in + i);
  }
  cout << ans << endl;
}

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

using namespace std;

int main()
{
    int n;
    int a[200];
    memset(a,0,sizeof(a));
    cin >> n;
    int cnt=0;
    while(n--)
    {
        int num;
        cin >> num;
        if(a[num]==0)
        {
            cnt++;
            a[num]=1;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

int main()
{
    int a ,b ,c ,x;
    cin >> a >> b >> c;
    x = fmax(abs(a - b),abs(b - c));
    cout << fmax(x,abs(a - c)) ;

    return 0;
}


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

int main() {
	string S;
	cin >> S;
	string words[4] = { "dream", "dreamer", "erase", "eraser" };

	reverse(S.begin(), S.end());
	for (int i = 0; i < 4; i++) {
		reverse(words[i].begin(), words[i].end());
	}

	for (int i = 0; i < S.size();) {
		bool flag = false;
		for (int j = 0; j < 4; j++) {
			string w = words[j];
			if (S.substr(i, w.size()) == w) {
				flag = true;
				i += w.size();
			}
		}
		if (flag == false) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;
 
int main(){
  ll k,n;
  cin >> k >> n;
  vector<ll> A(n), B;
  rep(i,n) cin >> A[i];

  ll ans = INF;
  rep(i,n){
    if(i==(n-1)) B.push_back(k-A[i]+A[0]);
    B.push_back(A[i+1]-A[i]);
  }
  rep(i,n) ans = min(ans,k-B[i]);
  cout << ans << endl;
}


Measured memory_bytes: 3956
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s) {
		stack<char> st;
		ll N = s.size();
		REP(i, s.size()) {
			if(s[i]=='T') {
				if(st.size() && st.top()=='S') {
					st.pop();
					N-=2;
				}
			} else {
				st.push('S');
			}
		}
		cout<<N<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 720
#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, m;
  cin >> n >> m;

  vector<P> con(m);
  rep(i, m) cin >> con[i].first >> con[i].second;

  rep(i, pow(10, n)) {
    int keta = 1;
    int nx = i / 10;
    vector<int> digit(1, i % 10);
    while (nx) {
      keta++;
      digit.push_back(nx % 10);
      nx /= 10;
    }
    if (keta != n) continue;
    reverse(digit.begin(), digit.end());

    bool flag = true;
    rep(j, m) if (digit[con[j].first - 1] != con[j].second) flag = false;

    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
def resolve():
    n,k = map(int,input().split())
    s = input().strip()
    s = list(s)
    if s[k-1]=='A':
        s[k-1]='a'
    elif s[k-1]=='B':
        s[k-1]='b'
    else:
        s[k-1]='c'
    s = ''.join(s)
    print(s)

if __name__ == "__main__":
    resolve()

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

const int INF = 1e9 + 5;
const int N = 1e5;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	string s, t;
	cin >> s >> t;

	vector<vector<int>> dp(s.size()+1, vector<int> (t.size()+1));
	for (int i = 1; i <= s.size(); i++)
	{
		for (int j = 1; j <= t.size(); j++)
		{
			if (s[i - 1] == t[j - 1])
				dp[i][j] = 1 + dp[i - 1][j - 1];
			dp[i][j] = max(dp[i][j], max(dp[i - 1][j], dp[i][j - 1]));
		}
	}

	stack<char> ans;
	int ans_size = dp[s.size()][t.size()];
	pair<int, int> curr = { s.size(), t.size() };
	while (ans_size > 0)
	{
		int curr_val = dp[curr.first][curr.second];
		int prev_val = dp[curr.first - 1][curr.second - 1];

		if (prev_val + 1 == curr_val && s[curr.first-1] == t[curr.second-1])
		{
			ans.push(s[curr.first - 1]);
			ans_size--;
			curr = { curr.first - 1, curr.second - 1 };
			continue;
		}

		prev_val = dp[curr.first - 1][curr.second];
		if (prev_val == curr_val)
			curr = { curr.first - 1, curr.second };
		else
			curr = { curr.first, curr.second - 1 };
	}
	while (!ans.empty())
	{
		cout << ans.top();
		ans.pop();
	}
	cout << "\n";
}

Measured memory_bytes: 35584
// template version 1.14
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;
const int MOD=1e9+7;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int gcd(int a, int b){
  if (b>a) swap(a,b);
  if (b==0) return a;
  return gcd(b, a%b);
}

int lcm(int a, int b){
  return (a/gcd(a,b))*b;  // overflowしにくいように最初に割り算をする。
}

signed main() {
  int a,b;cin>>a>>b;
  cout << lcm(a,b) << endl;
  return 0;
}


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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    int64_t ans = 0;
    int tmp = 0;
    int r = 0;
    for(int l=0; l<N; l++) {
        while((r < N) && (tmp & A[r]) == 0) {
            tmp |= A[r];
            ++r;
        }
        ans += r-l;
        tmp ^= A[l];
    }

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


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
const long long INF = 1000000007ll;
int k[4];
void ku(int a) {
  for (int i = 3; i >= 0; i --) {
    k[i] = a % 4;
    a /= 4;
  }
}
bool ok(int a) {
  for (int i = 0; i < 4; i ++) {
    ku(a);
    if (i >= 1) swap(k[i - 1], k[i]);
    if (k[0] == 0 && k[1] == 1 && k[2] == 2) return false;
    if (k[1] == 0 && k[2] == 1 && k[3] == 2) return false;
  }
  return true;
}
int N;
vector<vector<long long>>memo(101, vector<long long>(64, -1));
long long dfs(int cur, int last3) {
  if (memo[cur][last3] != -1) return memo[cur][last3];
  if (cur == N) return 1;
  long long ret = 0;
  for (int i = 0; i < 4; i ++) {
    if (ok(last3 * 4 + i)) {
      int jun = last3 % 16;
      jun *= 4;
      jun += i;
      ret = (ret + dfs(cur + 1, jun)) % INF;
    }
  }
  memo[cur][last3] = ret;
  return ret;
}
int main () {
  cin >> N;
  cout << dfs(0, 63) << endl;
}
  


Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

if sum(A) <= K:
  print(0)
  exit()

A.sort()
F.sort(reverse=True)

def check(x):
  k = 0
  for a,f in zip(A, F):
    k += max(0, a-(x//f))

  return k <= K

# AをX以下にできるか？?
ng,ok = 0, 10**18+1
while ok-ng > 1:
  x = (ok+ng)//2
  if check(x):
    ok = x
  else:
    ng = x

print(ok)


Measured memory_bytes: 114148
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

s = input()

for i in range(19):
    if (i==5 or i==13):
        print(" ", end="")
    else:
        print(s[i], end="")




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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    int ans=0;
    rep(i,n){
        if(a[i]>b[i]) ans+=a[i]-b[i];
    }
    cout << ans << endl;
    return 0;
}











Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

ll gcd(ll a, ll b){if (b == 0) return a;return gcd(b, a % b);}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main(){
    int A, B, C, ans = -1;
    cin >> A >> B >> C;
    int i = 0;
    while (i <= 1E8){
        if(A % 2 != 0 || B % 2 != 0 || C % 2 != 0){
            ans = i;
            break;
        }
        int ta = A;
        int tb = B;
        int tc = C;
        A = tb / 2 + tc / 2;
        B = ta / 2 + tc / 2;
        C = tb / 2 + ta / 2;
        i++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    double w,h,x,y; 
    cin >> w >> h >> x >> y;

    double ans = w/2.0*h;
    int temp = (w/2==x && h/2 == y) ? 1 : 0;
    
    printf("%.6f %d\n",ans,temp);
    return 0;

}

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

#define mp make_pair
#define pb push_back

using namespace std;

int n;
char s[111111], an[111111];

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d%s",&n,&s);
	for(int p = 0; p < 2; ++p){
		for(int q = 0; q < 2; ++q){
			if (p == 0) an[0] = 'W'; else an[0] = 'S';
			if (q == 0) an[1] = 'W'; else an[1] = 'S';
			for(int i = 2; i < n; ++i){
				if (an[i - 1] == 'S' && s[i - 1] == 'o') an[i] = an[i - 2];
				if (an[i - 1] == 'S' && s[i - 1] == 'x'){
					if (an[i - 2] == 'W') an[i] = 'S';
					else an[i] = 'W';
				}
				if (an[i - 1] == 'W' && s[i - 1] == 'x') an[i] = an[i - 2];
				if (an[i - 1] == 'W' && s[i - 1] == 'o'){
					if (an[i - 2] == 'W') an[i] = 'S';
					else an[i] = 'W';					
				}
			}
			if (an[0] == 'S' && s[0] == 'o' && an[n - 1] != an[1]) continue;
			if (an[0] == 'S' && s[0] == 'x' && an[n - 1] == an[1]) continue;
			if (an[0] == 'W' && s[0] == 'o' && an[n - 1] == an[1]) continue;
			if (an[0] == 'W' && s[0] == 'x' && an[n - 1] != an[1]) continue;
			if (an[n - 1] == 'S' && s[n - 1] == 'o' && an[n - 2] != an[0]) continue;
			if (an[n - 1] == 'S' && s[n - 1] == 'x' && an[n - 2] == an[0]) continue;
			if (an[n - 1] == 'W' && s[n - 1] == 'o' && an[n - 2] == an[0]) continue;
			if (an[n - 1] == 'W' && s[n - 1] == 'x' && an[n - 2] != an[0]) continue;			
			printf("%s",an);
			return 0;
		}
	}
	printf("-1");
	return 0;
}

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

const int limit = 50;
int n, m;
int a[limit], b[limit];

bool graph[limit][limit];
bool visited[limit];

void dfs(int v){
    visited[v] = true;
    for(int v2=0; v2<n; v2++){
        if(graph[v][v2]==false) continue;
        if(visited[v2]==true) continue;
        dfs(v2);
    }
}

int main(){
    cin >> n >> m;
    
    for(int i=0; i<m; i++){
        scanf("%d %d", &a[i], &b[i]);
        a[i]--, b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    int ans = 0;

    for(int i=0; i<m; i++){
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

        for(int j=0; j<n; j++) visited[j] = false;

        dfs(0);

        bool bridge = false;
        for(int j=0; j<n; j++) if(visited[j]==false) bridge = true;
        if(bridge) ans += 1;

        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

// ei1333's BIT
struct BinaryIndexedTree {
  VI data;

  BinaryIndexedTree(ll sz) {
    data.assign(++sz, 0);
  }

  ll sum(ll k) {
    ll ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  // iからjまでの和
  ll range_sum(ll i, ll j){
    return sum(j) - sum(i-1);
  }

  void add(ll k, ll x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

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

    // input
    ll N, K;
    cin >> N >> K;

    VI A(N);
    rep(i, N) cin >> A.at(i);

    ll all = N-K+1;

    ll already_sorted = 0;
    // 大小関係
    auto BIT = BinaryIndexedTree(N);
    rep(i, N-1){
      if(A[i]<A[i+1]){
        BIT.add(i, 1);
      }
    }
    ll equ = 0;

    if(N==K){
      p(1);
      return 0;
    }
    // 以降、K<N
    
    set<ll> se;
    rep(i, K+1){
      se.insert(A[i]);
    }

    rep(i, N-K+1){
      if(BIT.range_sum(i, i+K-2)==K-1){
        already_sorted++;
      }else{
        // ソートされていない時
        if(i==0){
          // 初回分
          if(A[0]==*se.begin() && A[K]==*se.rbegin()){
            equ++;
          }
        }
        // i, i+1がequivalentか
        else{
          if(i+K>=N) continue;
          if(A[i]==*se.begin() && A[i+K]==*se.rbegin()){
            equ++;
          }
        }
      }
      // se
      se.erase(A[i]);
      se.insert(A[i+K+1]);
    }
    
    if(already_sorted){
      all -= already_sorted-1;
    }
    if(equ){
      all -= equ;  
    }
    p(all);    
    return 0;
}

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


int main() {
  int a,b;
  cin >> a >> b;
  int d = a/b;
  int r = a%b;
  double x,y;
  x = a;
  y = b;
  double f = x/y;

  cout << d << " " << r << " ";
  cout << fixed << setprecision(8) << f << endl;

}


Measured memory_bytes: 3292
import sys
input = sys.stdin.readline

import collections
import random

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def dist(x1,y1,x2,y2):
	return abs(x1-x2)+abs(y1-y2)

def main():
	N = int(input())
	vS = [input().rstrip() for _ in [0,]*N]
	oA = ord("a")
	vD = [chr(i+oA) for i in range(26)]
	#vD += [".","#"]

	#res = 0
	vR = [1001001001,]*26
	for s in vS:
		for i,d in enumerate(vD):
			vR[i] = min(vR[i], s.count(d))
	
	res = ""
	for r,d in zip(vR,vD):
		res += d*r
	print(res)
	#sT = "No Yes".split()
	#print(sT[res])
	

if __name__ == "__main__":
	main()


Measured memory_bytes: 9660
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x; cin >> x;
  for(int i=1; i<=360; i++){
    if(x*i%360==0){
      cout << i << endl;
      break;
    }
  }
  return 0;
}


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

int main() {
    int n; cin >> n;
    int F[50];
    F[0] = F[1] = 1;
    for (int i = 2; i <= n; i++) {
        F[i] = F[i - 1] + F[i - 2];
    }
    
    cout << F[n] << endl;
    
    return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define sort(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;

using namespace std;

int main() {
	int n;
	cin >> n;
	double sum = 0;
	ff(i, 0, n) {
		double a;
		cin >> a;
		a = 1 / a;
		sum += a;
	}
	sum = 1 / sum;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()

void solve (int n)
{
    string s, t;
    cin >> s >> t;
    assert(sz(s) == n && sz(t) == n);

    for (int l = n; l <= 2 * n; l++)
    {
        string x = s + t.substr(n - (l - n));
        bool ok = true;
        for (int j = 1; j <= n; j++)
            ok &= (x[sz(x) - j] == t[sz(t) - j]);

        if (ok)
        {
            cout << l << endl;
            return;
        }
    }

    assert(false);
}

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

    int n;
    while (cin >> n)
        solve(n);
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int sum;
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  sum /= 2;
  for (int i = 0; i < N / 2 + 1; i++) {
    sum -= a.at(2 * i);
  }
  vector<int> x(N);
  x.at(0) = 0 - sum;
  cout << 2 * x.at(0) << " " ;
  for (int i = 1; i < N - 1; i++) {
    x.at(i) = a.at(i - 1) - x.at(i - 1);
    cout << 2 * x.at(i) << " " ;
  }
  cout << 2 * (a.at(N - 2) - x.at(N - 2)) <<endl;
}

Measured memory_bytes: 2048
N,M = map(int,input().split())

if N % 2 == 1:
    for i in range(M):
        print(i+1,N-i)
else: #こっちに問題あり
    for i in range(M):
        if i<N//4:
            print(i+1,N-i)
        else:
            print(i+1,N-i-1)

Measured memory_bytes: 9208
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, a[200009];
string s;

int fun(int x, int y)
{
	long long tmp = 1;
	int cnt = 0;
	for (int i = x; i < x + y; i++) {
		cnt += a[i];
		if (a[i] == 0) {
			tmp *= cnt;
			tmp %= MOD;
			cnt--;
		}
	}
	return (int)tmp;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> s;
	if (s[0] == 'W') {
		cout << 0 << E;
		return 0;
	}
	a[0] = 1;
	for (int i = 1; i < n + n; i++) {
		if (s[i] == s[i - 1]) {
			a[i] = 1 ^ a[i - 1];
		}
		else {
			a[i] = a[i - 1];
		}
	}
	int cur = 0;
	bool flag = false;
	for (int i = 0; i < n + n; i++) {
		if (a[i]) cur++;
		else cur--;
		if (cur < 0) {
			flag = true;
			break;
		}
	}
	if (cur != 0 || flag) {
		cout << 0 << E;
	}
	else {
		long long ans = 0;
		int cnt = 0;
		ans = fun(0, n + n);
		for (int i = 1; i <= n; i++) {
			ans *= i;
			ans %= MOD;
		}
		cout << ans << E;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 1360
#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>

int main()
{
	int length,breadth;
	int area, line;
	length = 0 , breadth = 0;
	area = 0, line = 0;

	scanf("%d %d", &length, &breadth);
	if (length >= 1 && breadth <= 100) {
		area = length * breadth;
		line = (length * 2) + (breadth * 2);

		printf("%d %d\n", area, line);
	}

	return 0;
}


Measured memory_bytes: 2032
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
    int s;
    cin >> s;
    vector<int> v(s+1, 0);
    // O(S logS)
    for(int i = 1; i <= s; i++){
        if(s%i) continue;
        for(int j = 1; j*(j+1)/2 <= i; j++){
            if((i-j*(j+1)/2)%j == 0)    v[i]++;
        }
    }
    ll ans = 0;
    for(int i = 1; i <= s; i++){
        ans += v[i]*v[s/i];
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

int main() {
    /*string S; long long K;
    cin >> S >> K;
    int N = S.size();
    vector<int> perm(N);
    for(int i = 0; i < N; ++i) {
        perm[i] = i;
    }
    sort(perm.begin(), perm.end(), [&](int i, int j) {
        if(S[i] != S[j]) return S[i] < S[j];
        return i < j;
    });
    vector<int> bit(N + 1);
    function<void(int, int)> add = [&](int pos, int x) {
        for(int i = pos + 1; i <= N; i += i & (-i)) {
            bit[i] += x;
        }
    };
    function<int(int)> sum = [&](int r) {
        int ans = 0;
        for(int i = r; i >= 1; i -= i & (-i)) {
            ans += bit[i];
        }
        return ans;
    };
    for(int i = 0; i < N; ++i) {
        add(i, 1);
    }
    string str;
    for(int i : perm) {
        int u = sum(i);
        if(K >= u) {
            K -= u;
            add(i, -1);
            str += S[i];
        }
    }
    for(int i = 0; i < N; ++i) {
        if(sum(i) != sum(i + 1)) {
            str += S[i];
        }
    }
    for(int i = 1; i < N; ++i) {
        int ptr = i;
        while(ptr != 0 && K > 0 && str[ptr - 1] > str[ptr]) {
            swap(str[ptr - 1], str[ptr]);
            --ptr;
            --K;
        }
    }
    cout << str << endl;*/

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

    int nowmax = 0;
    bool ret = true;
    for (int i = 0; i < n; i++) {
        if (nowmax < i) {
            ret = false;
            break;
        }
        nowmax = max(nowmax, i + d[i] / 10);
    }
    int nowmin = n - 1;
    for (int i = n - 1; i >= 0; i--) {
        if (nowmin > i) {
            ret = false;
            break;
        }
        nowmin = min(nowmin, i - d[i] / 10);
    }

    cout << (ret ? "yes" : "no") << endl;
    return 0;
}


Measured memory_bytes: 3808
import sys
import math

f_i = sys.stdin

n, q = map(int, f_i.readline().split())

# make a balanced binary tree.
n = 2 ** math.ceil(math.log(n, 2))

A = [0 for i in range(2 * n - 1)]

# operating function
def add(i, x):
    # note; argument i is 1-based.
    i += n - 2
    A[i] += x

    while i > 0:
        i = (i - 1) // 2
        A[i] += x

def getSum(s, t, k, l, r):
    if r < s or t < l:
        return 0
    elif s <= l and r <= t:
        return A[k]
    else:
        mid = (l + r) // 2
        lsum = getSum(s, t, k * 2 + 1, l, mid)
        rsum = getSum(s, t, k * 2 + 2, mid + 1, r)
        return lsum + rsum

for s_i in f_i:
    com, x, y = map(int, s_i.split())
    if com == 0:
        add(x, y)
    else:
        ans = getSum(x, y, 0, 1, n)
        print(ans)

Measured memory_bytes: 13172
N=int(input())
X=list(map(int,input().split()))
l=len(X)
s=10**10
for i in range(min(X),max(X)+1):
    x=[]
    for j in range(l):
        x.append((X[j]-i)**2)
    if s>sum(x):
        s=sum(x)
print(s)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;

int main() {
	int a, b;
	int ans = -1;
	cin >> a >> b;
	if (a <= 9 && b <= 9)ans = a * b;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

string getOp(int i) {
    return i > 0 ? "+" : "-";
}

int main() {
    int A, B, C, D;
    string temp;
    cin >> temp;
    A = temp[0] - '0';
    B = temp[1] - '0';
    C = temp[2] - '0';
    D = temp[3] - '0';
    for (int op1 = -1; op1 <= 1; op1 += 2) {
        for (int op2 = -1; op2 <= 1; op2 += 2) {
            for (int op3 = -1; op3 <= 1; op3 += 2) {
                if (A + op1 * B + op2 * C + op3 * D == 7) {
                    cout << A << getOp(op1) << B << getOp(op2) << C << getOp(op3) << D << "=7" << endl;
                    return 0;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
n,q=list(map(int,input().split()))
s=input()
li=[0]
c=0
for i in range(1,n):
  if s[i-1]=="A" and s[i]=="C":
    c+=1
  li.append(c)

for i in range(q):
  l,r=list(map(int,input().split()))
  l-=1
  r-=1
  print(li[r]-li[l])

Measured memory_bytes: 6116
#include<bits/stdc++.h>
#define ll long long

using namespace std;
int main(){
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	std::vector<ll> a;
	for(int i=0;i<n;++i){
		ll val;
		cin>>val;
		a.push_back(val);
	}
	ll ans=0;
	sort(a.rbegin(),a.rend());
	for(int i=k;i<n;++i){
		ans += a[i];
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 2420
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

A, B, C, K = read_ints()

if A >= K:
    print(K)
elif A + B >= K:
    print(A)
else:
    print(A - (K - (A + B)))


Measured memory_bytes: 65248
N,M = map(int, input().split())

balls_in_box = [0] + [1 for _ in range(1,N+1)]
red_ball_containable_box = set()
red_ball_containable_box.add(1)

for i in range(M):
    x,y = map(int, input().split())
    if x in red_ball_containable_box:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1
        red_ball_containable_box.add(y)
        if balls_in_box[x] == 0: #赤玉が入っている可能性が100％の箱を全部空にすれば確実に移る
            red_ball_containable_box.remove(x)
    else:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1

print(len(red_ball_containable_box))

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

int main(){
	string S;
	cin >> S;
	
	if(S[0] == 'M'){
		cout << 6 << endl;
	} else if(S[0] == 'T'){
		if(S[1] == 'U'){
			cout << 5 << endl;
		} else {
			cout << 3 << endl;
		}
	} else if(S[0] == 'W'){
		cout << 4 << endl;
	} else if(S[0] == 'F'){
		cout << 2 << endl;
	} else if(S[0] == 'S'){
		if(S[1] == 'A'){
			cout << 1 << endl;
		} else {
			cout << 7 << endl;
		}
	}
	
	return 0;
}


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

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

int main(){
  int K=0;
  cin>>K;

  int i,j,k;
  int gcd1;
  long int sum=0;

  for(i=0;i<K;i++){
    for(j=0;j<K;j++){
      for(k=0;k<K;k++){
        gcd1=gcd(i+1,j+1);
        sum+=gcd(gcd1,k+1);
      }
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3592
#include <cstdio>

int n, G[100][100], d[100], f[100], checked[100], time;

void dfs_visit(int u) {
    int i;
    checked[u] = 1;
    d[u] = ++time;
    for (i = 0; i < n; i++) {
        if (G[u][i] == 0) continue;
        if (checked[i] == 0) dfs_visit(i);
    }
    f[u] = ++time;
}

void dfs() {
    int i;
    for (i = 0; i < n; i++) checked[i] = 0;
    time = 0;

    for (i = 0; i < n; i++) {
        if (checked[i] == 0) dfs_visit(i);
    }
}

int main(void) {
    int u, k, v, i, j;
    scanf("%d", &n);
    
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++) G[i][j] = 0;
    
    for (i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        u--;
        for (j = 0; j < k; j++) {
            scanf("%d", &v);
            v--;
            G[u][v] = 1;
        }
    }

    dfs();

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

    return 0;
}

Measured memory_bytes: 1064
import numpy as np

N = int(input())

a = []
for i in range(N):
    a.append(int(input()))

if(N==1):
    print(a[0])
else:
    a_max = 0
    n_a_max = 0
    all_max = max(a)
    max_arg = np.argmax(a)

    if(max_arg!=0):
        a_max = max(a[:max_arg])
    if(max_arg!=N-1):
        n_a_max = max(a[max_arg+1:])

    if(a_max>=n_a_max):
        next_max = a_max
    else:
        next_max = n_a_max

    for i in range(N):
        if a[i]==all_max:
            print(next_max)
        else:
            print(all_max)
        

Measured memory_bytes: 24108
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "blist"

using namespace std;

const int maxn = 1e6 + 69;
const ll mod = 1e9 + 7;

ll mul[maxn], invmul[maxn];
ll dp[maxn];

ll Pow(ll x, ll k)
{
    if(k == 0) return 1;
    if(k == 1) return x % mod;
    ll t = Pow(x, k/2) % mod;
    if(k % 2 == 1) return ((t%mod*t%mod)%mod*x)%mod;
    return (t%mod*t%mod)%mod;
}

ll C(int k, int n)
{
    return ((invmul[k] * mul[n])%mod * invmul[n - k]%mod)%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if(fopen(task".in", "r")){
        freopen(task".in", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    //cout << Pow(2, 10);
    int n;
    cin >> n;
    for(int i = 3; i <= n; i ++){
        dp[i] = 1;

        for(int j = 3; j <= i; j ++){
            if(i - j >= 3){
                dp[i] = (dp[i] + dp[j]) % mod;
            }
        }
    }
    cout << dp[n];
}
/*
10 3
11 4
12 5
*/


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

int main(){
  double a,k;
  cin >> a >> k;
  double ans = 0;
  for(int i=1;i<=a;i++){
    if(i > k){
      ans += 1 ;
      //cout << '!';
    }else{
      double n = k/i;
      int nn = 1;
      while(n > 1){
        n /= 2;
        nn *= 2;
      }
      //cout << nn << "#";
      ans += 1.0 / nn;
    }
  }
  double s = ans / a;
  cout << setprecision(10);
  cout << s << endl;
  return 0;
}

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

int main()
{
  long long n, sum = 0;
  cin >> n;
  vector<int> a(n);
  for (long long i = 0; i < n; i++)
  {
    cin >> a.at(i);
    sum += a.at(i);
  }

  long long x = a.at(0);
  long long y = sum - a.at(0);
  long long ans = abs(x - y);
  for (long long i = 1; i < n - 1; i++)
  {
    x += a.at(i);
    y -= a.at(i);
    ans = min(ans, abs(x - y));
  }

  cout << ans << endl;
}


Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,x,t;
  cin>>n>>x>>t;
  int num=0;
  if(n%x==0){
    num=n/x;
  }else{
    num=n/x+1;
  }
  cout<<num*t<<endl;
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int K,Y;cin>>K>>Y;
	if(K*500>=Y)	Yes();
	else No();

    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
using ll = long long;
int main() {
    int K;
    cin >> K;
    queue<ll> q;
    rep(i, 1, 10)q.push(i);
    rep(i, 1, K){
        ll p = q.front();
        q.pop(); 
        ll ad = p%10;
        if(ad != 0) q.push(p*10 + ad -1);
        q.push(p*10 + ad);
        if(ad != 9) q.push(p*10 + ad + 1);
    }
    cout << q.front() << endl;
}
    

Measured memory_bytes: 1792