akhauriyash/Code-Regression huggingface dataset:
s=list(input())
q=int(input())
start=[]
owari=[]
r=1
for i in range(q):
    data=input().split()
    if(len(data)==1):
        r*=-1
    elif(data[1]=="1"):
        if(r==1):
            start.append(data[2])
        else:
            owari.append(data[2])
    else:
        if(r==1):
            owari.append(data[2])
        else:
            start.append(data[2])

if(r==1):
    start.reverse()
    print(''.join(start),end='')
    print(''.join(s),end='')
    print(''.join(owari),end='')
else:
    owari.reverse()
    s.reverse()
    print(''.join(owari),end='')
    print(''.join(s),end='')
    print(''.join(start),end='')


Measured memory_bytes: 6048
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32
from bisect import bisect_left, bisect_right

def solve(N: int, a: "List[int]"):
    # x = [[i+1, a[i]] for i in range(N)]

    # x = sorted(x, key=lambda x:x[1])
    # x1 = [i for i,j in x]
    # x2 = [j for i,j in x]

    # ans = 0
    # for i in range(N):
    #     p = bisect_left(x2, x1[i])
    #     if not (0 <= p < N):
    #         continue
    #     if x1[i] == x2[p] and x2[i] == x1[p]:
    #         ans += 1

    # print(ans//2)

    ans = 0
    for i in range(N):
        if a[a[i]-1] == i+1:
            ans += 1

    print(ans//2)


    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


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

int main()
{
    long long n, m;
    cin >> n >> m;
    if(m >= 2 * n)
        cout << n + (m - 2 * n) / 4 << endl;
    else
        cout << m / 2 << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  string s,t; cin>>s; t=s; reverse(all(s));
  if(s==t) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}













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

typedef long long ll;

using namespace std;

inline int read() {
	int x = 0, f = 1; char c = getchar();
	while (!isdigit(c)) {
		if (c == '-') f = -1;
		c = getchar();
	}
	while (isdigit(c)) {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}

signed main() {
	int k =read();
	string s;cin>>s;
	if(s.length()<=k)cout<<s<<endl;
	else {
	for(int i=0;i<k;i++)cout<<s[i];
	cout<<"..."<<endl;
}
	return 0;
}


Measured memory_bytes: 3632
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws Exception{
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        in.nextToken();
        int N = (int) in.nval;
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            in.nextToken();
            a[i] = (int) in.nval;
        }
        int j = 0;
        double ans = 0;
        for(int i = 1; i < N; i++){
            if(a[i] < a[j]){
                ans += (a[j] - a[i]);
            }else{
                j = i;
            }
        }
        System.out.format("%.0f",ans);
        System.out.println();
    }
}


Measured memory_bytes: 38856
#include<cstdio>
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
int prime[1000001];
int main() {
	prime[1] = 1;
	for(int i = 2; i * i <= 1000000; i++) {
		if(prime[i] == 1) continue;
		for(int j = i * i; j <= 1000000; j+=i) {
			prime[j] = 1;
		}
	}
	while(1) {
		int a,d,n;
		cin >> a >> d >> n;
		if(a == 0 && d == 0 && n == 0) break;
		int cnt = 0;
		for(int j = a; ; j += d) {
			if(prime[j] == 0) cnt++;
			if(cnt == n) {
				cout << j << endl;
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;

long long a,b;

long long xorsum(long long a, long long b){
    
    long long xor1toa;
    long long xor1tob;
    
    a--;
    if (a%4==0) xor1toa=a; else
        if (a%4==1) xor1toa=1; else
            if (a%4==2) xor1toa=a+1;
                else xor1toa=0;
                
    if (b%4==0) xor1tob=b; else
        if (b%4==1) xor1tob=1; else
            if (b%4==2) xor1tob=b+1;
                else xor1tob=0;
    
    return xor1tob^xor1toa;
}

int main(){
    cin>>a>>b;
    cout<<xorsum(a,b);
}

Measured memory_bytes: 256
#include <iostream> 
#include <cstdio> 
#include <cstdlib> 
#include <cstring> 
#include <cmath> 
#include <algorithm> 
using namespace std; 
int gi() { 
    int data = 0, w = 1; 
    char ch = 0; 
    while (!isdigit(ch) && ch != '-') ch = getchar(); 
    if (ch == '-') w = -1, ch = getchar(); 
    while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar();
    return w * data; 
}
int ban[1000]; 
int main () { 
	int N = gi(), K = gi(); 
	while (K--) { 
		int d = gi(); 
		while (d--) {
			int x = gi(); ban[x] = 1; 
		} 
	}
	int ans = 0; 
	for (int i = 1; i <= N; i++) ans += !ban[i]; 
	printf("%d\n", ans); 
    return 0; 
} 

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

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    priority_queue<int> quea;
    for(int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        quea.push(tmp);
    }

    for(int i = 0; i < m; i++) {
        int tmp=quea.top()/2;
        quea.pop();
        quea.push(tmp);
    }

    ll count=0;
    for(int i = 0; i < n; i++) {
        count+=quea.top();
        quea.pop();
    }

    cout << count << "\n";
    return 0;
}

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

using namespace std;

#define int long long

inline int read()
{
  int res = 0;
  int fl = 1;
  char c = getchar();
  while (!isdigit(c))
  {
    c = getchar();
  }
  while (isdigit(c) || c == '.')
  {
    if (c != '.') res = res * 10 + c - '0';
    c = getchar();
  }
  return res;
}
signed main()
{
  int a, b;
  a = read(), b = read();
  printf("%lld\n", a * b / 100);
  return 0;
}



Measured memory_bytes: 3760
from math import ceil
N = int(input())
cnt = 1
print(0)
S = input()
if S == 'Vacant':
    exit()
d = {'Male': 1, 'Female': 0}
sex = [-1,-1]
sex[0] = d[S]
l = 0
r = N-1
print(r)
S = input()
if S == 'Vacant':
    exit()
sex[1] = d[S]
while True:
    mid = (l+r)//2
    if mid % 2 !=0 and r-l > 2:
        mid -= 1
    print(mid)
    S = input()
    if S == 'Vacant':
        exit()
    if d[S] == sex[0]:
        l = mid
    else:
        r = mid

Measured memory_bytes: 3660
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
//    cout << fixed << setprecision(10);
    int N, M;
    map<int, bool> visited;
    visited[1] = true;
    cin >> N >> M;
    vector<int> previousMark(N);
    vector< vector<int> > rooms(N + 1);
    for (int i = 1; i <= N; i++) {
        rooms[i] = vector<int>();
    }
    int A, B;
    for (int i = 0; i < M; i++) {
        cin >> A >> B;
        rooms[A].push_back(B);
        rooms[B].push_back(A);
    }
    
    vector<int> queue;
    queue.push_back(1);
    while (queue.size() > 0) {
        vector<int> nextQueue;
        for (int i = 0; i < queue.size(); i++) {
            int currentRoom = queue[i];
            vector<int> nextRooms = rooms[currentRoom];
            for (int j = 0; j < nextRooms.size(); j++) {
                if(visited[nextRooms[j]] == false) {
                    visited[nextRooms[j]] = true;
                    nextQueue.push_back(nextRooms[j]);
                    previousMark[nextRooms[j] - 2] = currentRoom;
                }
            }
        }
        queue = nextQueue;
    }
    
    cout << "Yes" << endl;
    for (int i = 0; i < N - 1; i++) {
        cout << previousMark[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 15120
def main():
    N, K = map(int, input().split())
    P = [p-1 for p in map(int, input().split())]
    *C, = map(int, input().split())

    used = [0]*N
    ans = -float('inf')
    for x in range(N):
        if used[x]:
            continue
        used[x] = 1
        Q = [C[x]]

        while not used[P[x]]:
            x = P[x]
            used[x] = 1
            Q.append(C[x])

        ret = check(Q, K)
        if ret > ans:
            ans = ret

    print(ans)


def check(Q, K):
    length = len(Q)
    tot = sum(Q)
    Q *= 2
    ret = -float('inf')
    for i in range(length):
        accum = 0
        for k in range(1, min(K, length)+1):
            accum += Q[i+k]
            if tot > 0:
                ret = max(ret, accum + tot * ((K-k)//length))
            else:
                ret = max(ret, accum)
    return ret


if __name__ == '__main__':
    main()


Measured memory_bytes: 69428
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
int n;

signed main(){
    cin >> n;
    if (n == 0) return puts("0") * 0;
    string s;
    while(n){
        if(n%2)s.push_back('1'),--n;
        else s.push_back('0');
        n/=-2;
    }
    reverse(all(s));
    cout << s << endl;
}





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

int main() {
	int row, col;
	cin>> row >> col;
	int N;
	cin >> N;
	vector<int>arr;
	int mat[row][col];
	int x;
	for (int i=0; i<N; i++){
		cin >> x;
		for(int j=0; j<x; j++){
			arr.push_back(i+1);
		}
	}
	
	//for (int i=0; i<arr.size(); i++){
	//	cout << arr[i];
	//}cout << '\n';
	
	for (int i=0; i<row; i++){
		if (i%2==0){
			for (int j=0; j<col; j++){
				mat[i][j]=arr[j+i*col];
			}	
		}
		else{
			for (int j=0; j<col; j++){
				mat[i][j]=arr[col-1-j+i*col];
			}
		}
	}
	for (int i=0; i<row; i++){
		for (int j=0; j<col; j++){
			cout << mat[i][j] << ' ';
		}
		cout <<'\n';
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define lli long long int
#define ulli unsigned long long int
#pragma GCC target ("sse4.2")
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define time cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define plli pair<lli,lli>
#define pslli pair<string,lli>
#define pclli pair<char,lli>
const lli N=4e5+5;


int main()
{


    fast;
    lli n,k;
    cin>>n>>k;
    vector<lli>v;
    lli t=0;
    for(lli i=0;i<n;i++)
    {
        lli x;
        cin>>x;
        v.push_back(x);

    }
    sort(v.begin(),v.end());
    if(n<=k)
    {
        cout<<0;
        return 0;
    }
    for(lli i=0;i<n-k;i++)
    {
        t+=v[i];
    }
    cout<<t;



    return 0;

}


Measured memory_bytes: 3444
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

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

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);

//番号ズレ注意！！
int main() {
    int N, M;
    string s[100], t[100];
    cin >> N;
    map<string, int> red;
    map<string, int> blue;
    REP(i, N) {
        cin >> s[i];
        if (blue.count(s[i])) { blue[s[i]] += 1; }
        else {
            blue[s[i]] = 1;
        }
    }
    cin >> M;
    REP(i, M) {
        cin >> t[i];
        if (red.count(t[i])) { red[t[i]] += 1; }
        else {
            red[t[i]] = 1;
        }
    }
    int ans = 0;
    for (auto x:blue) {
        int point = 0;
        if (!red.count(x.first)) { point = x.second; }
        else {
            if (red[x.first] > x.second) { continue; }
            point = x.second - red[x.first];
        }
        ans = max(ans, point);
    }
    print(ans);
}


Measured memory_bytes: 384
#include <stdio.h>
#include <memory.h>

typedef struct _element {
	int index;
	int val;
	char c;
} element;

int is_stable(element lst[], int n) {
	int i;
	element last;

	memcpy((char*)&last, (char*)&lst[0], sizeof(element));
	for(i=1;i<n;i++) {
		if(last.val == lst[i].val) {
			if(last.index > lst[i].index) {
				return 0;
			}
		}
		memcpy((char*)&last, (char*)&lst[i], sizeof(element));
	}
	
	return 1;
}

int bubble_sort(element lst[], int n) {
	int i, j;
	element tmp;
	for(i=0;i<n-1;i++) {
		for(j=n-1;j>i;j--) {
			if(lst[j-1].val > lst[j].val) {
				memcpy((char*)&tmp,(char*)&lst[j],sizeof(element));
				memcpy((char*)&lst[j],(char*)&lst[j-1],sizeof(element));
				memcpy((char*)&lst[j-1],(char*)&tmp,sizeof(element));
			}
		}
	}
	
	return is_stable(lst, n);
}

int selection_sort(element lst[], int n) {
	int i, j, index;
	element tmp;
	for(i=0;i<n-1;i++) {
		index = i;
		for(j=i+1;j<n;j++) {
			if(lst[j].val < lst[index].val) {
				index = j;
			}
		}
		
		if(index != i) {
			memcpy((char*)&tmp,(char*)&lst[i],sizeof(element));
			memcpy((char*)&lst[i],(char*)&lst[index],sizeof(element));
			memcpy((char*)&lst[index],(char*)&tmp,sizeof(element));
		}
	}
	
	return is_stable(lst, n);
}

int main(void) {
	int i, val, n;
	int stable;
	element lst[36];
	element b_lst[36];
	element s_lst[36];
	
	scanf("%d\n", &n);
	for(i=0;i<n;i++) {
		lst[i].index = i;
		scanf("%c%d ", &(lst[i].c), &(lst[i].val));
	}
	memcpy((char*)b_lst, (char*)lst, sizeof(lst));
	memcpy((char*)s_lst, (char*)lst, sizeof(lst));
	
	stable = bubble_sort(b_lst, n);
	for(i=0;i<n;i++) {
		printf("%c%d", b_lst[i].c, b_lst[i].val);
		if(i<n-1) {
			printf(" ");
		} else {
			printf("\n");
		}
	}
	if(stable == 1) {
		printf("Stable\n");
	} else {
		printf("Not stable\n");
	}
	
	stable = selection_sort(s_lst, n);
	for(i=0;i<n;i++) {
		printf("%c%d", s_lst[i].c, s_lst[i].val);
		if(i<n-1) {
			printf(" ");
		} else {
			printf("\n");
		}
	}
	if(stable == 1) {
		printf("Stable\n");
	} else {
		printf("Not stable\n");
	}
	
	return 0;
}

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

struct bp {
	int nb, pt;

	bool operator < (const bp & rhs) const {
		return pt > rhs.pt || (pt == rhs.pt && nb < rhs.nb);
	}
};

int main()
{	
	int n;

	cin >> n;

	while (n > 0) {
		vector<bp> a(n);

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

			vector<int> b;

			while (cin.get() != '\n') {
				int t;
				cin >> t;
				b.push_back(t);
			}

			a[i].pt = 0;
			int j = 0, fl = 1;
			while (j < b.size()) {
				if (fl == 10) {
					a[i].pt += b[j];
					j++;
				}
				else {
					fl++;
					a[i].pt += b[j] + b[j + 1];

					if (b[j] == 10 || b[j] + b[j + 1] == 10)
						a[i].pt += b[j + 2];

					if (b[j] == 10)
						j++;
					else
						j += 2;
				}
 			}
		}

		sort(a.begin(), a.end());

		for (int i = 0; i < n; i++)
			cout << a[i].nb << " " << a[i].pt << endl;

		cin >> n;
	}

	return 0;
}



Measured memory_bytes: 3136
package main

import (
	"fmt"
)

func main() {
	var k int
	fmt.Scanf("%d", &k)

	var a, b int
	fmt.Scanf("%d %d", &a, &b)

	var flag = false
	for i := a; i <= b; i++ {
		if i%k == 0 {
			flag = true
			break
		}
	}

	if flag {
		fmt.Println("OK")
	} else {
		fmt.Println("NG")
	}
}

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

int main(){
ll n; cin>>n;
ll a[n], b[n], c[n];
ll i;
for(i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
}
ll dp[3][n];
dp[0][0]=a[0];
dp[1][0]=b[0];
dp[2][0]=c[0];
for(i=1;i<n;i++){
    dp[0][i]=max(dp[1][i-1], dp[2][i-1])+a[i];
    dp[1][i]=max(dp[0][i-1], dp[2][i-1])+b[i];
    dp[2][i]=max(dp[1][i-1], dp[0][i-1])+c[i];
}
cout<<max(dp[0][n-1], max(dp[1][n-1], dp[2][n-1]))<<endl;

    return 0;
}

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

using namespace std;
typedef long long ll;

ll ans;
ll p10[19];

void gogo (int dhi, int dlo, ll K, ll nmult)
{
    if (dhi <= dlo)
    {
        if (dhi == dlo) nmult *= 10;
        if (!K)
            ans += nmult;
        return;
    }

    ll ndiff = p10[dhi] - p10[dlo];
    for (int i = -9; i <= 9; i++)
    {
        ll knew = K + i * ndiff;
        if (abs(knew) < p10[dhi])
        {
            int nways = 10 - abs (i);
            if (dlo == 0 && i <= 0) nways--;
            gogo (dhi - 1, dlo + 1, knew, nmult * nways);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    ans = 0;
    p10[0] = 1;
    for (int i = 1; i < 19; i++)
        p10[i] = p10[i-1] * 10;

    ll D;
    cin >> D;
    for (int ndig = 1; ndig <= 18; ndig++)
        gogo (ndig - 1, 0, D, 1);

    cout << ans << "\n";
}

Measured memory_bytes: 256
n,q = map(int,input().split())
s = list(input())
base = [0]*n
count = 0

for i in range(1,n):
  if (s[i-1] == "A") and (s[i] == "C"):
    count = count + 1
    base[i] = count
  else:
    base[i] = count

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

Measured memory_bytes: 54648
#include<iostream>
int main(){
	int Homu, Homuhomu, homu, homuhomu;
	std::cin >> Homu >> Homuhomu >> homu >> homuhomu;
	std::cout << (Homu - homu) * (Homuhomu - homuhomu) << std::endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
counter=0
for i in range(1,10):
    if N/i==1 or N/i==2 or N/i==3 or N/i==4 or N/i==5 or N/i==6 or N/i==7 or N/i==8 or N/i==9:
        print('Yes')
        break
    else:
        counter+=1
if counter==9:
    print('No')


Measured memory_bytes: 2940
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		a[0] = sc.nextInt();
		a[1] = sc.nextInt();
		a[2] = sc.nextInt();
		int k = sc.nextInt();
		sc.close();
		Arrays.sort (a);
		int max = a[2];
		for (int i = 0; i<k; i++) {
			max*=2;
		}
		int val = a[0] + a[1] + max;
		System.out.println(val);

	}
}


Measured memory_bytes: 35728
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

ll f(ll a) { 
    // if (a % 2 == 1) {
    //     if (((a+1)/2) % 2 == 0) return 0;
    //     else return 1;
    // } else {
    //     if ((a/2) % 2 == 0) return a;
    //     else return a^1;
    // }
    ll cnt1 = (a+1)/2;
    ll ans = cnt1 % 2;
    if (a % 2 == 0) ans ^= a;
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll a, b;
    cin >> a >> b;
    cout << (f(a-1) ^ f(b)) << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
    using namespace std;
    int a[200010], b[200010];
     
    int main(int argc, char const *argv[])
    {
    	int n;
    	scanf("%d", &n);
    	
    	long long P = 0, Q = 0;
    	long long X = 0, Y = 0;
    	int cnt = 0;
    	bool good = true;
    	for(int i = 1; i <= n; i++) {
    		scanf("%d %d", &a[i], &b[i]);
    		good &= (a[i] == b[i]);
    		if(a[i] <= b[i]) {
    			P += b[i] - a[i];
    			Q += a[i];
    		} else {
    			X += a[i] - b[i];
    			Y += b[i];
    			++cnt;
    		}
    	}
    	long long ans = 0;
    	if(good) {
    		printf("0\n");
    		exit(0);
    	}
    	ans += Q;
    	ans += P;
    	if(cnt == 1) printf("%lld\n", ans);
    	else {
    		ans += Y;
    		int opt = INT_MAX;
    		for(int i = 1; i <= n; i++) {
    			if(b[i] < a[i]) {
    				opt = min(opt, b[i]);
    			}
    		}
    		ans -= opt;
    		printf("%lld\n", ans);
    	}
    	return 0;
    }

Measured memory_bytes: 384
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int A = in.nextInt();
        int B = in.nextInt();
        String S = in.next();

        for(int i = 0; i < A; i++){
            if (!Character.isDigit(S.charAt(i))){
                System.out.println("No");
                return;
            }
        }
        if(S.charAt(A) != '-'){
                System.out.println("No");
                return;
        }
        for(int i = A+1; i < A+1+B; i++){
            if (!Character.isDigit(S.charAt(i))){
                System.out.println("No");
                return;
            }
        }

        System.out.println("Yes");
        in.close();
    }
}


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

import sys

def merge(A, left, mid, right):
    global count
    n1 = mid-left
    n2 = right-mid
    L = [0]*(n1+1)
    R = [0]*(n2+1)
    for i in range(n1):
        L[i] = A[left+i]
    for i in range(n2):
        R[i] = A[mid+i]
    L[n1] = R[n2] = sys.maxint
    i = j = 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left+right)/2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

n = int(raw_input())
S = map(int, raw_input().split())
count = 0
mergeSort(S, 0, n)
print " ".join(map(str, S))
print count

Measured memory_bytes: 70408
while True:
    H,W = map(int,raw_input().split())
    if (H,W) == (0,0):
        break
    for k in range(H):
        if k==0 or k==H-1:
            print "#"*W
        else:
            print "#" + "." * (W-2) + "#"
    print ""

Measured memory_bytes: 4196
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <stack>
#include <cmath>
#include <functional>
#include <set>
#include <string>
#include <stdlib.h>
#include <utility>
 
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i = a;i<=b;i++)
#define ll long long int
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define iii pair<ii,int >
#define ff first
#define ss second
#define vi vector<int>
 
using namespace std;

const int MAX_NV = 100001;
const ll INF = 10000000000000000;
int main(){
	int n , W;
	cin >> n >> W;
	ll w[n];
	ll v[n];
	FOR(i,n) cin >> w[i] >> v[i];
	ll dp[n][MAX_NV];
	FOR(i,n)FOR(j,MAX_NV)dp[i][j] = INF;
	FOR(i,n)dp[i][0] = 0;
	dp[0][v[0]] = w[0];
	FOR(i,n){
		if(i == 0)continue;
		FOR(j,MAX_NV){
			if(j >= v[i])dp[i][j] = min(dp[i-1][j],w[i] + dp[i-1][j-v[i]]);
			else dp[i][j] = dp[i-1][j];
		}
	}
	FOR(i,n){
		FOR(j,40){
			//if(dp[i][j] == INF)cout << "INF ";
			//else cout << dp[i][j] << " ";
		}	
		//cout << endl;
	}

	int mx = 0;
	FOR(i,n)FOR(j,MAX_NV)if(dp[i][j] <= W)mx = max(mx,j);
	cout << mx << endl;

	return 0;
}


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

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

	int can = A[0][0], max = 0;
	for (int i = 0;i<N;i++) can += A[1][i];
	max = can;

	for (int i = 0;i<N - 1;i++) {
		can = can - A[1][i] + A[0][i + 1];
		if (can>max) {
			max = can;
		}
	}
	cout << max;
}


Measured memory_bytes: 256
#include <stdio.h>
int p[1000100];
int 
main(){
	long int n;
	long int j,i;
	long int cnt = 0;
	scanf("%ld",&n);
	
	for(i=1;i<=n/2;i++){
		if(n-i !=i)
		p[n-i]=1;//printf("%ld ",n-i);
	}
	
	for(i=1;i<n;i++){
		cnt+=p[i];
	}
	printf("%ld\n",cnt);
		
	
 return 0;
}

Measured memory_bytes: 2176
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

const int N = 110;

int n;
int a[N];
int b[N];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
  for (int i = n; i; --i) {
    int pos = -1;
    for (int j = i; j; --j)
      if (b[j] == j) {
        pos = j;
        break;
      }
    if (pos == -1) {
      puts("-1");
      return 0;
    }
    a[i] = pos;
    for (int j = pos; j < i; ++j)
      b[j] = b[j + 1];
  }
  for (int i = 1; i <= n; ++i)
    printf("%d\n", a[i]);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

class Magatro
{

    static void Main()
    {
        int N;
        int x;
        string[] s = Console.ReadLine().Split(' ');
        N = int.Parse(s[0]);
        x = int.Parse(s[1]);
        int l = N * 2 - 1;
        if (x == 1 || x == l)
        {
            Console.WriteLine("No");
            return;
        }
        Console.WriteLine("Yes");
        int[] ans = new int[l];
   
        if (x==2)
        {
            ans[N - 1] = 2;
            ans[N - 2] = 1;
            for(int i = 0; i < l; i++)
            {
                if (i < N - 2)
                {
                    ans[i] = i + 3;
                }
                if (i > N - 1)
                {
                    ans[i] = i + 1;
                }
            }

        }
        else
        {
            ans[N - 1] = x;
            ans[N - 2] = x + 1;
            ans[N - 3] = x - 1;
            ans[N] = x - 2;
            for(int i = 0; i < l; i++)
            {
                if ((i < N - 3 && i < x - 3) || (i > N && i > x))
                {
                    ans[i] = i+1;
                }
                if (i < N - 3 && i >= x - 3)
                {
                    ans[i] = i + 5;
                }
                if (i > N && i <= x)
                {
                    ans[i] = i - 3;
                }
            }
            
        }
        StringBuilder ss = new StringBuilder();

   for(int i = 0; i < l; i++)
        {
            ss.Append(ans[i] + "\n");
        }
        Console.Write(ss.ToString());
    }


}

Measured memory_bytes: 13888
import fractions
a, b = map(int, input().split())
gc = fractions.gcd(a, b)

def prime_factorize(n):
    a = []
    if n % 2 == 0:
        a.append(2)
        while n % 2 == 0:
            n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            while n % f == 0:
                n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

print(len(prime_factorize(gc)) + 1)

Measured memory_bytes: 5048
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007

vector<ll> func(vector<ll> &arr) {
  vector<ll> res;
  for(auto val:arr) {
    reps(i, -1, 2) {
      int add = val%10 + i;
      if(add>=0 && add<=9) res.push_back(val*10+add);
    }
  }
  return res;
}

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

  // https://drken1215.hatenablog.com/entry/2020/04/05/150900
  // 解法1-2
  int K; cin>>K;
  vector<ll> cur, all;
  reps(i, 1, 10) cur.push_back(i), all.push_back(i);

  rep(i,9) {  // 2~10桁までの9回
    cur = func(cur);
    for(auto val:cur) all.push_back(val);
  }

  cout << all[K-1] << endl;

  return 0;
}


Measured memory_bytes: 3440
import math
N, A, B = map(int, input().split())
H = [0] * N
H = [int(input()) for i in range(N)]
maxH = max(H)
U = math.ceil(maxH / B)
L = 0
def binsearch(U, L):
  m = (U + L) // 2
  if m == L:
    print(U)
  else:
    if sum([math.ceil(max(h - B * m, 0) / (A - B)) for h in H]) <= m:
      binsearch(m, L)
    else:
      binsearch(U, m)
binsearch(U, L)

Measured memory_bytes: 10944
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  map<int, vector<int>> path;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    path[a].push_back(b);
    path[b].push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool flag = true;
    for (int j = 0; j < path[i].size(); j++) {
      if (h[path[i][j]] >= h[i]) flag = false;
    }
    if (flag == true) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 14296
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;

/* {{{ Variables */
int A, B;
/* }}} */

int main(int argc, char *argv[])
{
  /* {{{ Input */
  cin >> A >> B;
  /* }}} */

  /* {{{ Output */
  cout << max({A+B, A-B, A*B});
  /* }}} */

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// 素因数分解：nの素因数分解を{素数, 指数}の形で昇順に返す。
ll primeFactorize(long long n){
    ll sum = 1;
    vector<pair<long long, long long>> ret;
    for(long long i=2; i*i<=n; i++){
        if(n%i != 0) continue;
        long long ex = 0;
        while(n%i == 0){ ex++; n /= i; }
        sum *= (ex+1);
    }
    if(n != 1) sum *= 2;
    return sum;
}

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

    vector<bool> chkPrime(1000001, true);
    for(long long i=2; i<=1000001; i++){
        if(chkPrime[i]){
            for(long long j=2*i; j<=n; j+=i) chkPrime[j]=false;
        }
    }
    chkPrime[1] = false;
    vi isOK(n+1, 0);

    ll ans = 0;
    for(ll c=1; c<n; c++){
        ll tn = n-c, p = 1;
        if(chkPrime[tn]){
            ans += 2;
            continue;
        }
        ans += primeFactorize(tn);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11172
#include<iostream>
#include <climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int H, W;
	cin >> H >> W;
	vector<vector<char>> a(H, vector<char>(W)), b;
	REP(i, H)REP(j, W) cin >> a[i][j];
	vector<bool> h(H, false), w(W, false);
	REP(i, H)REP(j, W) {
		if (a[i][j] == '#') {
			h[i] = true;
			break;
		}
	}
	REP(j, W)REP(i, H) {
		if (a[i][j] == '#') {
			w[j] = true;
			break;
		}
	}
	REP(i, H){
		if (h[i]) {
			REP(j, W) {
				if (w[j]) {
					cout << a[i][j];
				}
			}
			cout << "\n";
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << (h2-h1)*60 + m2-m1 - k << endl;
    return 0;
}


Measured memory_bytes: 3612
import sys
read = sys.stdin.read
from itertools import chain
from collections import Counter
def main():
    def warshall_floyd(d):
        for k in range(n):
            for i in range(n):
                for j in range(n):
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j])
        return d

    h, w = map(int, input().split())
    n = 10
    d = [[10**9] * 10 for _ in range(10)]
    for i1 in range(10):
        row = tuple(map(int, input().split()))
        for i2 in range(10):
            d[i1][i2] = row[i2]
    res = warshall_floyd(d)
    hw = [list(map(int, input().split())) for _ in range(h)]
    hw1d = chain.from_iterable(hw)
    hw1dc = Counter(hw1d)
    r = 0
    for j1 in range(10):
        r += hw1dc[j1] * res[j1][1]
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 74248
#!/usr/bin/python3
# abc060_a
"""
Shiritori
"""

def main():
    A, B, C = map(str, input().split())
    if A[-1] == B[0] and B[-1] == C[0]:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
const lli mod = 1e9 + 7;
int main()
{
	lli a, b; cin >> a >> b;
	lli left = 0, right = 0, ans = 0;
	for(int i=0; i < b; i++)
	{
		left = (left + i) % mod;
		right = (right + a - i + mod) % mod;
	}
//	cout << left << ' ' << right << '\n';
	for(int i=b; i <= a + 1; i++)
	{
		ans = (ans + (right - left + 1 + mod)) % mod;
		left = (left + i) % mod;
		right = (right + a - i + mod) % mod;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3636
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static long mod = 998244353;
		static long[] fac, finv, inv;

		static void Main(string[] args)
		{
			var firstLine = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
			var n = firstLine[0];
			var m = firstLine[1];
			var k = firstLine[2];

			CombinationInitialize(n);

			long count = 0;
			for(long i = n - 1 - k; i <= n - 1; i++)
			{
				count += ModPow(m - 1, i, mod) * Combination(n - 1, n - 1 - i);
				count %= mod;
			}

			WriteLine(count * m % mod);
		}

		private static long ModPow(long a, long n, long mod)
		{
			long answer = 1;

			while(n > 0)
			{
				if((n & 1) == 1)
				{
					answer = answer * a % mod;
				}
				a = a * a % mod;
				n >>= 1;
			}

			return answer;
		}

		private static long Combination(long n, long k)
		{
			if(n < k)
			{
				return 0;
			}
			if(n < 0 || k < 0)
			{
				return 0;
			}

			return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
		}

		private static void CombinationInitialize(long n)
		{
			fac = new long[n + 1];
			finv = new long[n + 1];
			inv = new long[n + 1];

			fac[0] = fac[1] = 1;
			finv[0] = finv[1] = 1;
			inv[1] = 1;

			for(long i = 2; i <= n; 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;
			}
		}
	}
}


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

int main(){
	int n, A[1000];

	while(1){
		cin >> n;
		if( n == 0)break;

		for( int i = 0; i < n; i++)cin >> A[i];
		int sum = 0;
		for( int i = 0; i < n; i++)sum += A[i];
		double avg = 1.0*sum/n;
		double dist = 0.0;
		for( int i = 0; i < n; i++){
			dist += (avg-A[i])*(avg-A[i]);
		}
		printf("%lf\n", sqrt(dist/n));
	}
}

Measured memory_bytes: 3152
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n;
  cin >> n;
  str s;
  ll pw = 1;
  if(n==0){
    cout << 0 << endl;
    return 0;
  }
  ll power = 2;
  while(n!=0){
    if(n%power==0){
      s += '0';
    }else{
      s += '1';
      n -= (power/2)*((pw%2)?1:-1);
    }
    pw++;
    power *= 2;
    //cout << n << endl;
  }
  reverse(s.begin(),s.end());
  cout << s << endl;
  return 0;
}


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

int main()
{
    string s,t,a;
    cin>>s>>t;
    if(s.length()>t.length())
    cout<<"No"<<endl;
    else
    {
        a = t.substr(0, s.length());
        if(a==s)
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define inputv(arr,n) for(ll i=0;i<n;i++){ll value;cin>>value;arr.pb(value);}
#define sz(a) ((ll)(a).size())
#define len(a) ((ll)(a).length())
#define precise cout<<fixed<<setprecision(0); 
#define F first
#define S second
#define vi vector <int> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define YES cout<<"Yes\n"
#define NO cout<<"No\n"
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b)
{if(b==0) return a;a%=b;return gcd(b,a);}
#define nl cout<<"\n"
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
// hashing for pairs
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};
//sort in reverse order
bool compare(ll x, ll y){
    return x>y;
}
void solve()
{
  ll  x,k,d;
  cin>>x>>k>>d;
  if(x<0)
  {
    x = (-1)*x;
  }
  ll val = x/d;
  if(val>k)
  {
    cout<<x-k*d;nl;
    return;
  }
  else
  {
    x-=(val)*d;
    k-=val;
    if(k%2)
    {
      cout<<(d-x);nl;
    }
    else
    {
      cout<<x;nl;
    }
    
  }
  
  return;
}
int main()
{
    IOS;
    int T=1;
  //  cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define pf push_front
#define ll long long
using namespace std;
void TxtRead(){
    freopen("bphoto.in","r", stdin);
    freopen("bphoto.out","w", stdout);
}
void TheTime(){
    ios_base::sync_with_stdio(false);
	cin.tie();
}
const int N = 405;
const ll INF = 1e9+5;
const ll MOD = 1e9+7;
const double PI = 3.141592653589793116;

int n;
ll inf, sum[N], dp[N][N];

ll _rec(int l, int r)
{
	if(l==r) return 0;
	if(dp[l][r]!=inf) return dp[l][r];
	
	for(int i=l; i<r; i++){
		dp[l][r]=min(dp[l][r], _rec(l, i)+_rec(i+1, r)
				                    +(sum[r]-sum[l-1]));
	}
	return dp[l][r];
}

int main()
{
    //TxtRead();
    TheTime();
	
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		ll a;
		scanf("%lld", &a);
		sum[i]=sum[i-1]+a;
	}
	
	memset(dp, '?', sizeof(dp));
	inf=dp[0][0];
	printf("%lld", _rec(1, n));
}


Measured memory_bytes: 1536
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
//const ll MAX_V=114514LL;
//const ll MAX = 500010LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={0,0,1,-1};
vl dy={1,-1,0,0};




int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  ll x;cin>>x;
  cout<<360/__gcd(x,360LL)<<endl;
}

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

int main() {
  ll a, b;
  cin >> a >> b;
  rep(i,max(a,b)) {
      if(abs(a-i)==abs(b-i)) {
          cout << i << endl;
          return 0;
      }
  }  
  cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 384
/*
********************
Author : Sahil Kundu
********************
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mod 1000000007
#define pb(i) push_back(i)
#define f first
#define s second
#define mk(l,r) make_pair(l,r)
#define all(vc) vc.begin(),vc.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ms(i,j) memset(i,j,sizeof i)
#define w(t) while(t--)
#define len(s) s.length()
const ll MAX=1e5+5;
const ll INF=2e18+10;
const int inf=1e9+10;
void solve()
{
    int n;
    cin>>n;
    int a[n];
    for(auto &i:a)cin>>i;
    ll dp[n+1];
    ms(dp,0);
    ll sum=a[0];
    for(int i=2;i<=n;i++)
    {
        if(i&1)
        {
            dp[i]=max(dp[i-2]+a[i-1],dp[i-1]);
            sum+=a[i-1];
        }
        else dp[i]=max(dp[i-2]+a[i-1],sum);
    }
    cout<<dp[n]<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    w(t) solve();
    return 0;
}

Measured memory_bytes: 5968
# -*- coding: utf-8 -*-
s = input()
max_cnt = 0
cnt = 0
for v in s:
  if v in ['A', 'T', 'C', 'G']:
    cnt += 1
  else:
    max_cnt = cnt if max_cnt < cnt else max_cnt
    cnt = 0

max_cnt = cnt if max_cnt < cnt else max_cnt
print(max_cnt)

Measured memory_bytes: 3060
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    int a[n];
    int tot = 0;
    for(int i=0;i<n;i++)    cin>>a[i], tot+=a[i];
    //cout<<tot<<endl;
    if(tot%10!=0){
        cout<<tot<<endl;
        return 0;
    }
    //sort(a,a+n);
    int max_tot=INT_MIN;
    //tot=0;
    bool nonzero = false;
    for(int i=0;i<n;i++)
    {   
        if(a[i]%10!=0)
            nonzero=true, max_tot = max(max_tot, tot-a[i]); 
    }
    if(nonzero) cout<<max_tot<<endl;
    else        cout<<0<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int INF = 1e9+7;
int main(){
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    if(s.back()=='s'){
    	s += "es";
    }
    else{
    	s += 's';
    }
    cout<<s<<'\n';
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x, y, z;
    cin >> x >> y >> z;
    int c = 0;
    while (true) {
        if (z * (c + 1) + y * c < x) c++;
        else if (z * (c + 1) + y * c > x) {
            c--;
            break;
        }
        else break;
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll n; cin >> n; ll cnt = 0;
  
  if(n % 2 == 1) cout << 0 << endl;
  else{
    n /= 10;
    while(n != 0){
      cnt += n;
      n /= 5;
    }
    
    cout << cnt << endl;
  }
  
}

Measured memory_bytes: 256