akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

bool expectS(int index1, int index2, bool s) {
    return (abs(index1 - index2) % 2 == 0) ? s : !s;
}


int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    string s;

    cout << 0 << endl << flush;
    cin >> s;

    if (s == "Vacant")
        return 0;
    
    bool firstS = (s == "Male");
    int first = 0;
    int last = n - 1;
    bool lastS = !firstS;
    int count = 0;

    while (count < 20) {
        int index = first + (last - first + 1) / 2;

        cout << index << endl << flush;
        cin >> s;
        if (s == "Vacant")
            return 0;
    
        bool indexS = (s == "Male");

        if (indexS == expectS(index, first, firstS)) {
            first = index;
            firstS = indexS;
        } else {
            last = index;
            lastS = indexS;
        }
        count++;
    }
    
    return 0;
}


Measured memory_bytes: 852
N = int(input())

def gen(n):
  if n < 10:
    yield n
  else:
    for m in gen(n/10):
      yield m
    yield n%10

num = [int(i) for i in gen(N)]

SN = 0
for i in num:
    SN += i

if N % SN == 0:
    print("Yes")
else:
    print("No")

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

using namespace std;

int main(void)
{
    int A,B,N;
    scanf("%d%d%d",&N,&A,&B);
    if(N==1)
    {
        if(A==B)
            printf("1\n");
        else
            printf("0\n");
    }
    else 
    {
        if(A>B)
            printf("0\n");
        else
            printf("%lld\n",(long long )(B-A)*(N-2)+1);
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	puts(abs(b - a) <= d && abs(c - b) <= d || abs(c - a) <= d ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 128
N = int(input())
A = [int(i) for i in input().split()]
cnt = 0
for a in A:
    if a<0:
        cnt += 1
A = [abs(a) for a in A]
if cnt % 2 == 1:
    print(sum(A)-2*min(A))
else:
    print(sum(A))


Measured memory_bytes: 14224
#include <stdio.h>

char s[100010];
int main(){
	int n,a,b;
	scanf("%d%d%d%s",&n,&a,&b,s);
	int cnt=0;
	int bcnt=0;
	for(int i=0;i<n;i++){
		if(s[i]=='a')puts(cnt<a+b?cnt++,"Yes":"No");
		else if(s[i]=='b')puts(cnt<a+b&&++bcnt<=b?cnt++,"Yes":"No");
		else puts("No");
	}
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=(s);i<(t);++i)
#define repb(i,s,t) for(int i=(s);i<=(t);++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define mst(a,b) memset(a,b,sizeof(a))
#define dd(x) cout<<#x<<'='<<x<<' '
#define de(x) cout<<#x<<'='<<x<<'\n'

typedef long long ll;
typedef pair<int,int> pii;

const int inf = 0x3f3f3f3f;

int main()
{
	int n,k,x,ans=inf;vector<int> v;
	cin>>n>>k;
	rep(i,0,n){cin>>x;v.pb(x);}
	rep(i,0,n-k+1)ans=min(ans,min(abs(v[i]),abs(v[i+k-1]))+v[i+k-1]-v[i]);
	cout<<ans<<endl;
	
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  double hh=30.0;
  double mm=6.0;
  double a,b,h,m;
  cin>>a>>b>>h>>m;
  double e=m/60.0*30.0;
  hh=hh*h+e;
  mm=mm*m;
  hh=360.0-hh;
  mm=360.0-mm;
  double r;
  double pi = 3.141592653589793238;
  r=max(hh,mm)-min(hh,mm);
  double Cos=cos(r/180.0*pi);
  double resu;
  resu=a*a+b*b-2.0*a*b*Cos;
  resu=sqrt(resu);
  cout<<fixed<<setprecision(15)<<resu<<endl;
}

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

char board[8][8];

bool out(int x,int y){
    if(x<0 || x>7 || y<0 || y>7) return false;
    else return true;
}

bool judge(int x, int y){
    
    for(int vy=-1; vy<=1;vy++){
        for(int vx=-1;vx<=1;vx++){
            if(vy==0 && vx==0) continue;
            
            int px=x, py=y;
            while(1){
                px+=vx;
                py+=vy;
                if(!out(px,py)) break;
                if(board[py][px]=='Q') return false;
            }
        }
    }
    
    return true;
}

bool dfs(int num, int pos){
    if(num == 0) return true;
    
    if(pos==64) return false;
    
    int y = pos/8;
    int x = pos%8;
    
    if(board[y][x]=='Q'){
        if(dfs(num-1, pos+1)) return true;
    }
    else{
        if(judge(x,y)){
            board[y][x]='Q';
            if(dfs(num-1, pos+1)) return true;
            board[y][x]='.';
        }
        
        if(dfs(num, pos+1)) return true;
    }
    
    return false;
}

int main(void){
    // Your code here!
    
    int n;
    cin>>n;
    int qs[n][2];
    
    for(int i=0;i<8;i++){
        for(int j=0;j<8;j++){
            board[i][j] = '.';
        }
    }
    
    for(int i=0;i<n;i++){
        cin>>qs[i][0]>>qs[i][1];
        board[qs[i][0]][qs[i][1]]='Q';
    }
    
    bool ok = dfs(8,0);
    
    if(ok){
        for(int i=0;i<8;i++){
            for(int j=0;j<8;j++){
                cout<<board[i][j];
            }
            cout<<endl;
        }
    }
    else{
        cout<<"NG"<<endl;
    }
    
}



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

using namespace std;
typedef long long ll;
const int INF=INT_MAX;

struct lst
{
private:
    int n;
    vector<ll> node;
    vector<ll> lazy;
    vector<bool> lflg;

    void lazy2node(int k, int l, int r)
    {
        if(lflg[k])
        {
            node[k]+=lazy[k];
            prop(lazy[k], k, l, r);
            lazy[k]=0;
            lflg[k]=false;
        }
    }

    void prop(ll v, int k, int l, int r)
    {
        if(r-l>0)
        {
            lazy[2*k+1]+=v;
            lazy[2*k+2]+=v;
            lflg[2*k+1]=lflg[2*k+2]=true;
        }
    }
public:
    lst(int sz)
    {
        n=1; while(n<sz) n*=2;
        node.resize(2*n-1, 0);
        lazy.resize(2*n-1, 0);
        lflg.resize(2*n-1, false);
    }
    void update(int qa, int qb, ll v, int k=0, int l=0, int r=-1)
    {
        if(r<0) r=n-1;
        lazy2node(k, l, r);
        if(qb<l || r<qa) return;
        if(qa<=l && r<=qb) 
        {
            node[k]+=v;
            prop(v, k, l, r);
        }
        else
        {
            int m=(l+r)/2;
            update(qa, qb, v, 2*k+1, l, m);
            update(qa, qb, v, 2*k+2, m+1, r);
            node[k]=min(node[2*k+1], node[2*k+2]);
        }
    }

    ll get(int qa, int qb, int k=0, int l=0, int r=-1)
    {
        if(r<0) r=n-1;
        lazy2node(k, l, r);
        if(qb<l || qa>r) return INF;
        if(qa<=l && r<=qb) return node[k];
        else
        {
            int m=(l+r)/2;
            ll lm = get(qa, qb, 2*k+1, l, m);
            ll rm = get(qa, qb, 2*k+2, m+1, r);
            return min(lm, rm);
        }
    }
};

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    lst tree=lst(n);
    for(int i=0; i<q; i++)
    {
        int c;
        scanf("%d", &c);
        if(c)
        {
            int s, t;
            scanf("%d %d", &s, &t);
            printf("%lld\n", tree.get(s,t));
        }
        else
        {
            int s, t, v;
            scanf("%d %d %d", &s, &t, &v);
            tree.update(s, t, (ll)v);
        }
    }
}


Measured memory_bytes: 7060
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  cin >> n;
  int p[n];
  for(int i= 0; i<n ;++i){
    cin >> p[i];
  }
  int c1 = 0;
  int c2 = 0;
  bool enable = true;
  for(int i = 0; i< n; ++i){
    if(p[i] != i+1 && c1 == 0 && c2 == 0){
      c1 = i+1;
      //printf("check c1 %d\n", i);
    }else if(p[i] != i+1 && c1 != 0 && c2 == 0){
      c2 = i+1;
      //printf("check c2 %d\n", i);
    }else if(p[i] != i+1 && c1 != 0 && c2 != 0){
      enable = false;
      break;
    }
  }
  if(enable && ((c1 != 0 && c2 != 0)||(c1 == 0 && c2 == 0))){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N, M;
    cin >> N >> M;
    int A[M], B[M];
    vector<int> adj[N];
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        adj[A[i]].push_back(B[i]);
        adj[B[i]].push_back(A[i]);
    }
    deque<int> q;
    q.push_back(0);
    int ans[N]{};
    bool vis[N]{};
    vis[0] = true;
    while (!q.empty()) {
        int v = q.front();
        q.pop_front();
        for (int i : adj[v]) {
            if (vis[i]) continue;
            ans[i] = v;
            q.push_back(i);
            vis[i] = true;
        }
    }
    cout << "Yes\n";
    for (int i = 1; i < N; i++) {
        cout << ans[i] + 1<< "\n";
    }
    return 0;
}

Measured memory_bytes: 11988
n, a, b = map(int, input().split())
ans = -1
if (b-a) % 2 == 0:
    ans = (b-a) // 2
else:
    diff_left = a - 1
    diff_right = n - b
    if diff_left <= diff_right:
        ans = diff_left
        ans += 1
        ans += (b-a-1) // 2
    else:
        ans = diff_right
        ans += 1
        ans += (b-a-1) // 2


print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define mp make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define rep(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

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

    int n, T;
    vector<int> route;
    cin >> n >> T;
    for (int i = 0; i < n; i++) {
        int t, tt;
        cin >> t >> tt;
        if (tt <= T)route.pb(t);
    }
    sort(route.begin(), route.end());
    if (route.size() == 0)cout << "TLE" << endl;
    else cout << route[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <deque>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <complex>
#include <sstream>
#include <climits>
#include <cstring>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=200010;
long long a[N];

int main()
{
  int n;
  while(scanf("%d",&n)==1)
  {
    long long ret=0;
    for(int i=1; i<=n; i++)
      scanf("%d",&a[i]);
    int j=0;
    long long sum1=0,sum2=0;
    for(int i=1; i<=n; i++)
    {
      while(j+1<=n&&(sum1+a[j+1])==(sum2^a[j+1]))
      {
        sum1+=a[j+1];
        sum2=sum2^a[j+1];
        j++;
      }
      if(sum1==sum2)
        ret+=j-i+1;
      sum1-=a[i];
      sum2=sum2^a[i];
    }
    printf("%lld\n",ret);
  }
  return 0;
}


Measured memory_bytes: 1792
n = int(input())
d = [list(map(int, input().split())) for i in range(n)]
for x in range(101):
  for y in range(101):
    for i in d:
      if i[2] > 0:
        H = i[2] + abs(x-i[0]) + abs(y-i[1])
        break
    if all(l[2] == max(H - abs(x-l[0]) - abs(y-l[1]), 0) for l in d):
      print('{} {} {}'.format(x, y, H))
      exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define vecsort(x) sort(x.begin(), x.end())
#define vecrsort(x) sort(x.rbegin(), x.rend())
#define massort(x, n) sort(x, x + n)
#define FOR(i, n) for(int i = 0; i < n; i ++)
using namespace std;
int max(int32_t a, int b){
   return max((int)a, b);
}

const int INF = 1e9 + 7;
const int N = 1e5 + 2000;

int dp[N];
int  h[N];

int32_t main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int n, k;
   cin >> n >> k;
   FOR(i, n)
      cin >> h[i], dp[i] = INF;
   dp[0] = 0;
   for(int i = 0; i < n-1; i ++){
      for(int j = 1; j <= k; j ++){
         if(i + j >= n)
            break;
         dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
      }
   }
   cout << dp[n-1];
}



Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int h = s.nextInt();
        int w = s.nextInt();
        s.nextLine();
        List<String> list = new LinkedList<>();
        int a = h;
        for (int i = 0; i < h; i++) {
             String ss = s.nextLine();
             if(ss.contains("#")) {
                 list.add(ss);
             } else {
                 a--;
             }
        }



        for(int i=0;i<w;i++) {
            int j = 0;
            for(;j<a;j++) {
                if(list.get(j).charAt(i)=='#') {
                    break;
                }
            }
            if(j==a) {
                for(int k=0;k<a;k++) {
                    StringBuilder sb = new StringBuilder(list.get(k));
                    sb.deleteCharAt(i);
                    list.remove(k);
                    list.add(k,new String(sb));
                }
                w--;
                i = i-1;
            }
        }
        for(int i=0;i<a;i++) {
            System.out.println(list.get(i));
        }
    }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std; 
int n;
int a[200010];
long long ans;
bool cmp(int a,int b){
	return a>b;
}
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n,cmp);
	ans+=a[0];
	for(int i=1;i<n-1;i++){
		ans+=a[(i+1)/2];
	}
	cout<<ans<<endl;
    return 0; 
}/*
*/

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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
struct BIT{
    vector<T> elm;
    BIT(int n, T init = T()) : elm(n + 1, init){
    }

    // [0, x)
    T sum(int x){
        T val = 0;
        for(; x > 0; x -= x & -x)
            val += elm[x];
        return val;
    }

    // [l, r)
    T sum(int l, int r){
        return sum(r) - sum(l);
    }

    void add(int x, T val){
        for(++x; x < elm.size(); x += x & -x)
            elm[x] += val;
    }
};


i64 solve(vector<int> v){
    BIT<int> b(v.size());
    for(int i = 0; i < v.size(); ++i)
        if(v[i] == 0)
            b.add(i, 1);
    i64 ans = 0;
    for(int i = 0; i < v.size(); ++i)
        if(v[i] == 1)
            ans += b.sum(i);
    return ans;
}

signed main(){
    string s;
    cin >> s;
    i64 ans = 0;
    vector<int> v;
    for(int i = 0; i < s.size(); ++i){
        if(s.substr(i, 2) == "BC"){
            v.push_back(1);
            ++i;
        }else if(s[i] == 'A')
            v.push_back(0);
        else
            v.push_back(-1);
    }
    v.push_back(-1);
    vector<int> w;
    for(auto& x : v){
        if(x == -1){
            if(!w.empty())
                ans += solve(w);
            w.clear();
        }else
            w.push_back(x);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3704
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n; cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    REP(i,n) cin >> p[i];
    REP(i,n) cin >> q[i];
    vector<int> a;
    for(int i = 1; i <= n; ++i) a.push_back(i);

    int num = 0;
    int a2, b;
    
    do {
        num++;
        bool flag = true;
        REP(i,n) {
            if(a[i]!=q[i]) {
                flag = false;
            }
        }
        if(flag) a2 = num;
    
        flag = true;
        REP(i,n) {
            if(a[i]!=p[i]) {
                flag = false;
            }
        }
        if(flag) b = num;
    } while(next_permutation(a.begin(),a.end()));
    cout << abs(a2-b)  << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;

import java.util.*;

import java.math.BigDecimal;

import java.text.DecimalFormat;





class Main{

	private static ArrayList<Double> calc_equ(ArrayList<Double> a){

		ArrayList<Double> b = new ArrayList<Double>();

		

		int s = a.size()/6;

				

		for(int i = 0;i<s;i++){

			

			Double x,y,a1,b1,c1,d1,e1,f1;

			x = 0.0;

			y = 0.0;



			a1 = a.get(i*6);

			b1 = a.get(i*6+1);

			c1 = a.get(i*6+2);

			d1 = a.get(i*6+3);

			e1 = a.get(i*6+4);

			f1 = a.get(i*6+5);

						

			y = (a1*f1-c1*d1)/(e1*a1-b1*d1);

			x = (c1-b1*y)/a1;

			

			b.add(x);

			b.add(y);

			}

		return b;

	}

	private static void print_calc(ArrayList<Double> a){

		String format = "0.000";

		DecimalFormat decimalFormat = new DecimalFormat( format );

		

		String str1,str2;

		double x,y;

		

		for(int i = 0;i<a.size()/2;i++){	

			

			x = a.get(i*2);

			y = a.get(i*2+1);

			

			str1 = Double.toString(x);

			str2 = Double.toString(y);

			

			BigDecimal bigDecimal1 = new BigDecimal( str1 );

			BigDecimal bigDecimal2 = new BigDecimal( str2 );

			

			BigDecimal Result1 = bigDecimal1.setScale(4,BigDecimal.ROUND_HALF_UP);

			BigDecimal Result2 = bigDecimal2.setScale(4,BigDecimal.ROUND_HALF_UP);

			

			System.out.println( decimalFormat.format( Result1 ) + " " + decimalFormat.format( Result2 ) );

			

		}

	}

		public static void main(String args[]) throws IOException{

			ArrayList<Double> equ = new ArrayList<Double>();

			Scanner scan = new Scanner(System.in);

			Double n;

			

			while(scan.hasNext()){

					String str1 = scan.next();

					n = Double.parseDouble(str1);

					equ.add(n);



			}

						

			

			ArrayList<Double> res = new ArrayList<Double>();

			res = calc_equ(equ);

			print_calc(res);

	}

}

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

using namespace std;

const long long MOD = 1000000007;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    /*
     * REMOVE ME PLS
     */

    //freopen("input.txt", "r", stdin);

    int a, b;
    cin >> a >> b;

    if(a >= 13){
        cout << b;
    } else if(12 >= a && a >= 6){
        cout << b / 2;
    } else {
        cout << 0;
    }


    return 0;
}


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

int main(void) {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    int cnt = 0;
    long long sum = 0;
    int mn = 1e9;
    for (int i = 0; i < n; i++) {
        cnt += a[i] < 0;
        sum += abs(a[i]);
        mn = min(abs(a[i]), mn);
    }
    if (cnt % 2 == 1) {
        sum -= mn * 2;
    }
    printf("%lld\n", sum);
    return 0;
}

Measured memory_bytes: 640
n= int(input())
task = [list(map(int,input().split()))for i in range(n)]

task.sort(key= lambda x: x[1])
time = 0
for i in range(n):
    time += task[i][0]
    if time > task[i][1]:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 53724
//	Author : amnptl 
//	   Godbless
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define NeedForSpeed() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod (2019) // not 1e9+7

ll power(ll base, ll exponent, ll modx = mod) 
{
    ll ret = 1 % modx; base %= modx;
    while(exponent) 
    {
        if(exponent & 1) ret = (ret * base) % modx;
        base = (base * base) % modx; exponent >>= 1;
    }
    return ret;
}

int main()
{
	NeedForSpeed();
	string s; cin>>s; ll n = s.size(); ll a[n+1];
	for(ll i=0; i<n; i++) a[i+1] = (s[i] - '0');
	ll num[n+1]={0}; ll dp[2019]={0}; dp[0]++; ll ans = 0;
	for(ll i=1; i<=n; i++)
	{
		num[i] = (power(10,n-i+1)*a[i])%mod;
		num[i] += num[i-1]; num[i] %= mod;
		dp[num[i]]++;
	}
	for(ll i=0; i<2019; i++) ans += ((dp[i])*(dp[i]-1))/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6856
/* created   : 2019-08-11 23:15:12
 * accepted  : 2019-08-11 23:23:15
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> was(n);
  for (int i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) {
      int t = a[i];
      for (int j = i; j >= 0 && a[j] == t && !was[j]; j--) {
        was[j] = 1;
        a[j]--;
      }
    }
  }
  trace(a);
  for (int i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) {
      cout << "No" << "\n";
      return;
    }
  }
  cout << "Yes" << "\n";
}

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


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

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

    int a, b, c;
    cin >> a >> b >> c;
    int result = c - (a - b);
    if (result < 0) {
        cout << '0';
    } else {
        cout << result;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<vector<ll>> Graph;
typedef vector<pii> vpii;

ll f(ll A,ll N) {
  if(A*3==N) return INF;
  ll cnt=0;
  while(1) {
    if((N-A)%2) return cnt;
    A=(N-A)/2;
    cnt++;
  }
}

int main() {
  ll A,B,C,N; cin>>A>>B>>C; N=A+B+C;
  if(A%2&&B%2&&C%2) {cout<<0<<endl; return 0;}
  ll ans=INF;
  ans=min(ans,f(A,N));
  ans=min(ans,f(B,N));
  ans=min(ans,f(C,N));
  if(ans==INF) cout<<-1<<endl;
  else cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

// 二項係数計算
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int dight_min(int n) {
	int ans = 9;
	while (n >= 10) {
		ans = min(ans, n % 10);
		n /= 10;
	}
	ans = min(ans, n);
	return ans;
}
int dight_max(int n) {
	int ans = 0;
	while (n >= 10) {
		ans = max(ans, n % 10);
		n /= 10;
	}
	ans = max(ans, n);
	return ans;
}
int a;
double b;
signed main() {
	cin >> a >> b;
	cout << (int)(floor(a * b)) << endl;
	ggr
}


Measured memory_bytes: 3716
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int N;
vector<int>A, B, C;

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		int tmp; cin >> tmp;
		A.push_back(tmp);
	}
	for (int i = 0; i < N; ++i) {
		int tmp; cin >> tmp;
		B.push_back(tmp);
	}
	for (int i = 0; i < N - 1; ++i) {
		int tmp; cin >> tmp;
		C.push_back(tmp);
	}
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += B[A[i] - 1];
		if (i != N - 1 && A[i + 1] == A[i] + 1) {
			ans += C[A[i] - 1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;
using LD = long double;

LL N;
LL M;

template< class T >
struct BinaryIndexedTree
{
	vector< T > data;

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

	void init()
	{
		for (T& t : data)t = T();
	}

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

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


struct line
{
	LL A, B, C;
};


const LD EPS = 1e-9;
vector<line>plane;

LL getDrop(LD X, BinaryIndexedTree<LL>& bit)
{
	bit.init();
	vector<pair<LD, int>>cash;
	for (int i = 0; i < N; ++i)
	{
		const auto& lin = plane[i];
		LD Y = lin.C - lin.A * X;
		Y /= lin.B;
		cash.push_back({ Y,i });
	}
	sort(cash.rbegin(), cash.rend());
	LL ret = 0;
	for (int i = 0; i < N; ++i)
	{
		ret += bit.sum(cash[i].second);
		bit.add(cash[i].second, 1);
	}
	return ret;
}
LD getMedian()
{
	BinaryIndexedTree<LL>bit(N);
	LD lo = -1e10, hi = 1e10;
	while (hi - lo > EPS)
	{
		LD mid = (lo + hi) / 2;
		LL res = getDrop(mid, bit);
		if (res * 2 < M)
		{
			lo = mid;
		}
		else
		{
			hi = mid;
		}
	}
	return hi;
}

int main(void)
{
	cin >> N;
	M = (N - 1) * (N) / 2;
	for (int i = 0; i < N; ++i)
	{
		int a, b, c;
		cin >> a >> b >> c;
		plane.push_back({ a,b,c });
	}
	sort(plane.begin(), plane.end(), [](const line& l1, const line& l2)
	{
		return (LD)l1.A / l1.B < (LD)l2.A / l2.B;
	});
	LD xMedian = getMedian();
	for (int i = 0; i < N; ++i)
	{
		swap(plane[i].A, plane[i].B);
	}
	sort(plane.begin(), plane.end(), [](const line& l1, const line& l2)
	{
		return (LD)l1.A / l1.B < (LD)l2.A / l2.B;
	});
	LD yMedian = getMedian();
	cout.precision(15);
	cout << xMedian << " " << yMedian << endl;
	return 0;
}


Measured memory_bytes: 6796
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXIST2(s,e) (find(ALL(s),(e))!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

int dfs(vs &f, vvi &visited,int x,int y){
	int ret=1;
	visited[y][x]=1;
	REP(i,4){
		int xx=x+dx[i],yy=y+dy[i];
		if(xx>=0&&yy>=0&&xx<w&&yy<h){
			if(f[yy][xx]!='#'&&!visited[yy][xx]){
				ret+=dfs(f,visited,xx,yy);
			}
		}
	}
	return ret;
}

int main(){
	while(cin>>w>>h,w){
		vs f(h,string(w,' '));
		int sx,sy;
		REP(i,h){
			REP(j,w){
				cin>>f[i][j];
				if(f[i][j]=='@'){
					sx=j;sy=i;
				}
			}
		}
		vvi visited(h,vi(w));
		cout<<dfs(f,visited,sx,sy)<<endl;
	}
}

Measured memory_bytes: 1284
#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;

const ll mod=1000000007;

ll keta(ll a){
  if(a<=9)return 1;
  return keta(a/10)+1;
}

int main() {
 int n;
  bool flag1=true,flag2=false;
  cin >> n;
  ll a=1;
  r(i,n){
    ll b;
    cin >> b;
    if(b==0)flag2=true;
    if(a*b!=1000000000000000000&&keta(a)+keta(b)>=20)flag1=false;
    a*=b;
    if(a>1000000000000000000)flag1=false;
  }
  if(!flag1&&!flag2)cout<<-1<<endl;
  else if(!flag1&&flag2)cout<<0<<endl;
  else cout<<a<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    int n, k; cin >> n >> k; k--;
    string s; cin >> s;
    s[k] = s[k]-'A'+'a';
    print(s);
}


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

int main(){
  int n;
  cin >> n;
  ll ans = 0;
  rep(i, n){
    int a;
    cin >> a;
    int co = 0;
    if(a == 0 || a % 2 != 0) continue;
    while(1){
      if(a == 0 || a % 2 != 0) break;
      co++;
      a /= 2;
    }
    ans += co;
  }
  cout << ans << endl;
  return 0;
}

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


int main(void){
	int M,T,P,R;
	while(cin >> M >> T >> P >> R,M){
		vector<int> solved[11][3010];
		vector<int> ts(T,0);
		vector<int> tt(T,0);
		vector<vector<int>> pen(T,vector<int>(10,0));
		
		rep(i,R){
			int m,t,p,j;
			cin >> m >> t >> p >> j;
			t--,p--;
			if(ts[t]&(1<<p)) continue;

			if(j==0){
				ts[t]|=(1<<p);
				tt[t]+=m + 20*pen[t][p];
			}else{
				pen[t][p]++;
			}
		}

		for(int i = T-1; i >=0;--i){
			const int s = __builtin_popcount(ts[i]);
			const int t = tt[i];
			solved[s][t].push_back(i+1);
		}


		string ans="";
		bool first = true;
		for(int i=P;i>=0;--i){
			for(int j=0;j<=3000;++j){
				if(solved[i][j].empty()) continue;
				const int n = solved[i][j].size();
				
				if(first) 
					first = false;
				else
					ans +=",";
				rep(k,n) ans += (k?"=":"") + to_string(solved[i][j][k]);
			}
		}

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

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

/* macros */
#define inf 1e9
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define vt vector
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define tc int t;cin>>t;while (t--){solve();}
#define gtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": " << solve() << "\n";TC++;}
#define gvtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": "; vsolve(); TC++;}
#define notc solve();
#define newline cout << "\n";
#define mod 1000000007
#define ret return 0;
#define sz(x) (int)x.size();
#define rep(i,a,b) for(int i=a;i<b;i++)
#define srt(x) sort(x.begin(), x.end())
#define rsrt(x) sort(x.rbegin(), x.rend())

void solve() {
    int n;
    cin>>n;
    int a = 1;
    int ans = 0;
    while (true) {
        int c = n - (a * 1);
        int x = ceil((double)c / (double)a);
        ans += x;
        if (c == 1) {
            break;
        }
        a++;
    }
    cout << ans << "\n";
}

int32_t main(){
    fastio
    notc
    ret
}


Measured memory_bytes: 3756
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.rmi.server.ExportException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Main m = new Main();
        m.solve();
    }
    private void solve() throws Exception {
        FastScan scan = new FastScan(System.in);
        int N = scan.scanInt();
        List<Path>[] graph = new List[N];
        for (int i = 0; i < N; i++) {
            graph[i] = new ArrayList<>();
        }
        for (int i = 0; i < N - 1; i++) {
            int a = scan.scanInt()-1;
            int b = scan.scanInt()-1;
            long c = scan.scanLong();
            graph[a].add(new Path(b, c));
            graph[b].add(new Path(a, c));
        }
        int Q = scan.scanInt();
        int K = scan.scanInt()-1;
        Queue<Integer> queue = new ArrayDeque<>();
        long[] distances = new long[N];
        boolean[] visited = new boolean[N];
        Arrays.fill(distances, Long.MAX_VALUE);
        distances[K] = 0;
        queue.add(K);
        while(!queue.isEmpty()) {
            int current = queue.poll();
            visited[current] = true;
            for (Path p : graph[current]) {
                if (visited[p.to]) {
                    continue;
                }
                distances[p.to] = distances[current] + p.cost;
                queue.add(p.to);
            }
        }
        for (int i = 0; i < Q; i++) {
            int from = scan.scanInt() - 1;
            int to = scan.scanInt() - 1;
            System.out.println(distances[from] + distances[to]);
        }
    }

    class Path {
        int to;
        long cost;
        Path(int to, long cost) {
            this.to = to;
            this.cost = cost;
        }
    }
    class FastScan {
        BufferedReader br;
        StringTokenizer st;
        FastScan(InputStream is) {
            InputStreamReader isr = new InputStreamReader(is);
            this.br = new BufferedReader(isr);
        }
        String next() throws IOException {
            while (this.st == null || !this.st.hasMoreTokens()) {
                this.st = new StringTokenizer(br.readLine().trim());
            }
            return st.nextToken();
        }
        long scanLong() throws IOException {
            return Long.parseLong(this.next());
        }
        int scanInt() throws IOException {
            return Integer.parseInt(this.next());
        }
        double scanDouble() throws IOException {
            return Double.parseDouble(this.next());
        }
        char scanCharacter() throws IOException {
            return this.next().charAt(0);
        }
        String nextLine() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 83848
{-# LANGUAGE BangPatterns #-}
 
module Main
  ( main
  )
where
 
import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
 
parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine
 
main = do
  s <- getLine
  let n = length s
      start = 1 + length (takeWhile ('A' /= ) s)
      end = n - (length . takeWhile ('Z' /=) $ reverse s)
  print $ end - start + 1

Measured memory_bytes: 20988
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 2000000001; //check the limits, dummy

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

     int n,k,l,sum=0,res=0;
     cin>>n;
     string str;
    vector< pair<string,int>> vct;
     for (int i=0;i<n;i++)
     {  string s;
       ll p;
       cin>>s>>p;
       vct.pb(mp(s,p));
     }
     cin>>str;
    for (int i=n-1;i>=0; i--){
        sum+=vct[i].s;
        if (vct[i].f==str){
                sum-=vct[i].s;
                    break;
        }
    }
  cout<<sum;
	return 0;
}



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

int main() {
    ll N, K;
    string S;
    cin >> N >> K >> S;
    ll ans = 0;
    ll change_num = 0;
    for (ll i = 0; i < S.size(); i++) {
        if (i < S.size() - 1) {
            ans += (S[i] == 'R' && S[i + 1] == 'R');
        }
        if (i > 0) {
            ans += (S[i] == 'L' && S[i - 1] == 'L');
        }
        if (i < S.size() - 1) {
            change_num += (S[i] != S[i + 1]);
        }
    }

    cout << ans + min(change_num, K * 2) << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define mp make_pair
#define M 1000000007
#define F first
#define S second
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}

// #define ncr_nikalo
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
}
ll modinv(ll a,ll m)
{
    return power(a,m-2,m);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll int t=1;
    //cin>>t;
    #ifdef ncr_nikalo
        initialvalues();
    #endif
        
    for(ll int g=0;g<t;g++)
    {
    	ll int n,ans;
    	cin>>n;
    	ans=n*n;
    	ans*=n;
    	ans+=n*n;
    	ans+=n;
    	cout<<ans;



    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main() {
    int n, val;
    cin >> n;
    int a = 1, b = 1;
    for (int i = 0; i < n; i++) {
        scanf("%d", &val);
        a *= 3;
        if (val % 2 == 0) b *= 2;
    }
    cout << a-b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int a[800][800];

int main(){
	while(1){
		ll w,h,t,p; cin >> w >> h >> t >> p;
		if(w+h+t+p == 0) break;
		rep(i,h) rep(j,w) a[i][j] = 1;
		int l = 0, u = 0;
		rep(z,t){
			int d,c; cin >> d >> c;
			if(d == 2){
				for(int i=u; i<u+c; i++){
					REP(j,l,w+l){
						a[2*u+2*c-1-i][j] += a[i][j];
						a[i][j] = 0;
					}
				}
				u += c;
			}else{
				for(int j=l; j<l+c; j++){
					REP(i,u,h+u){
						a[i][2*l+2*c-1-j] += a[i][j];
						a[i][j] = 0;
					}
				}
				l += c;
			}
		}
		rep(i,p){
			int x,y; cin >> x >> y;
			cout << a[y+u][x+l] << "\n";
		}
		REP(i,u,u+h) REP(j,l,l+w) a[i][j] = 0;
	}
}


Measured memory_bytes: 4532
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in); //scanの宣言
        
        String str;  //文字列変数の宣言
        
        str = sc.next(); //input
        
        for(int i = 0; i < str.length(); i++){
			System.out.print((char)((str.charAt(i) - 'A' - 3 + 26) % 26 + 'A'));
		}
		
		System.out.println(); //print
        
    }
}



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

#undef int
int main()
{
#define int long long
    int n,m;
    cin >> n >> m;
    vector<pair<int,int> >vp;
    priority_queue<int>pq;
    int x,y,sum=0,next=0;
    for(int i=0;i<n;i++) {
        cin >> x >> y;
        vp.push_back({x,y});
    }
    sort(vp.begin(),vp.end());
    for(int i=1;i<=m;i++) {
        while(next<n && vp[next].first==i)
        {
            pq.push(vp[next].second);
            next++;
        }
        if(!pq.empty()) {
            sum+=pq.top();
            pq.pop();
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

void showIntArray(int a[], int n) {
  for (int i=0; i<n; i++) {
    cout << a[i] << ' ';
  } cout << endl;
}

int main() {
  int N, v[21], c[21], ans=0;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> v[i];
  }
  for (int i=0; i<N; i++) {
    cin >> c[i];
  }

  for (int i=0; i<N; i++) {
    if (v[i] - c[i] > 0) {
      ans += v[i] - c[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long com(long long N,long long R){
    if(R<0 ||R>N)return 0;
    if(R==1)return N;
    else if(R==2)return N*(N-1)/2;
    else return N*(N-1)*(N-2)/6;
}
long long pow(long long N,long long k){
    long long res=1;
    for(int i=0;i<k;i++)res*=N;
    return res;
}

string S;
int N,K;
long long solve(int i,int k,int smaller){
    if(i==N){
        if(k==0)return 1;
        else return 0;
    }
    if(k==0)return 1;
    if(smaller)return com(N-i,k)*pow(9,k);
    else{
        if(S[i]=='0')return solve(i+1,k,false);
        else{
            long long zero=solve(i+1,k,true);
            long long aida=solve(i+1,k-1,true)*(S[i]-'1');
            long long icchi=solve(i+1,k-1,false);
            return zero+aida+icchi;
        }
    }
}

int main(){
    cin>>S>>K;
    N=S.size();
    cout<<solve(0,K,false)<<endl;
}

Measured memory_bytes: 256
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re

N = int(input())

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

c = Counter(M)

print("AC x " + str(c['AC']))
print("WA x " + str(c['WA']))
print("TLE x " + str(c['TLE']))
print("RE x " + str(c['RE']))


Measured memory_bytes: 16988
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

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


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

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


	for (int i = 0; i < S.size(); ++i){
		if (S[i] == ','){
			cout << " ";
		}
		else{
			cout << S[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 764