akhauriyash/Code-Regression huggingface dataset:
N,M = map(int, input().split())
E = []
for _ in range(M):
  a,b = map(int, input().split())
  E.append((a-1,b-1))

## https://note.nkmk.me/python-union-find/
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
###
uf = UnionFind(N)

ans = [0] * (M+1)
ans[M] = N*(N-1) // 2
  
for i in range(M-1,-1,-1):
  a,b = E[i]
  if uf.same(a,b):
    ans[i] = ans[i+1]
  else:
    # union
    _t, _u = uf.size(a), uf.size(b)
    uf.union(a,b)
    #_v = uf.size(a)
    ans[i] = ans[i+1] - _t*_u
  
for i in range(1,M+1):
  print(ans[i])

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<P> p(n);
  
  rep(i,n){
    cin >> p[i].first >> p[i].second;
  }
  
  sort(p.begin(),p.end());
  
  ll ans = 0;
  int num = m;
  rep(i,n){
    if(num > p[i].second){
      num -= p[i].second;
      ans += (ll)p[i].first * (ll)p[i].second;
    }else{
      ans += (ll)p[i].first * (ll)num;
      break;
    }
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define M 1000000007
#define pie 3.141592653589793238
using namespace std;


signed main(){  
    int n; cin >> n;
    int a[n];
    for(int i=0; i<n; i++)
        cin >> a[i];
    int ans = 0;
    for(int i=1; i<n; i++){
        if(a[i-1] > a[i]){
            ans += (a[i-1] - a[i]);
            a[i] += (a[i-1] - a[i]);
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 5148
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 998244353 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 4010

ll dp[SIZE][SIZE];

int main(){
  char s[SIZE];
  int n;

  scanf("%s", s);
  n = strlen(s);

  int R = 0, B = 0;

  dp[0][0] = 1;

  for(int i=0;i<n*2;i++){
    if (i < n) {
      if (s[i] == '0') { R += 2; }
      if (s[i] == '1') { R += 1; B += 1; }
      if (s[i] == '2') { B += 2; }
    }

    for(int j=0;j<=R;j++){
      int r = j, b = i - j;

      if(r < R) (dp[i+1][r+1] += dp[i][r]) %= mod;
      if(b < B) (dp[i+1][r] += dp[i][r]) %= mod;
    }
  }

  cout << dp[n*2][R] << endl;


  return 0;
}


Measured memory_bytes: 123776
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  string S;
  cin>>S;
  int a=0,counter=0;
  rep(i,S.size()) {
    if(S.at(i)=='A'||S.at(i)=='T'||S.at(i)=='G'||S.at(i)=='C') {
      counter++;
    }
    else {
      counter=0;
    }
    a=max(a,counter);
  }
  cout<<a<<endl;
}

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

int main() {
  vector<string> s;
  while(1) {
    string t;
    getline(cin, t);
    if(cin.eof()) {
      break;
    }
    s.push_back(t);
  }

  vector<int> x(26);
  vector<char> a;
  for(char i = 'a'; i <= 'z'; i++) a.push_back(i);
  for(int i = 0; i < s.size(); i++) {
    for(int j = 0; j < s.at(i).size(); j++) {
      for(int k = 0; k < a.size(); k++) {
        if(tolower(s.at(i).at(j)) == a.at(k)) x.at(k) += 1;
      }
    }
  }
  for(int i = 0; i < x.size(); i++) cout << a.at(i) << " : " << x.at(i) << "\n";
}


Measured memory_bytes: 3164
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int A = c/b;
    int B = c % b;
    int C = a/d;
    int D = a % d;
    if ((B == 0 && D == 0) || (B != 0 && D != 0)){
        if(A <= C)
            cout << "Yes";
        else
            cout << "No";
    }else if(B == 0 && D != 0){
        if(A <= C + 1)
            cout << "Yes";
        else 
            cout << "No";
    }else{
        if(A < C)
            cout << "Yes";
        else
            cout << "No";
    }
    cout << endl;
}


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

int main() {
    int cnt = 0;
    string s;
    cin >> s;
    if (s[0] == '1') {
        cnt++;
    }
    if (s[1] == '1') {
        cnt++;
    }
    if (s[2] == '1') {
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

n = int(input())
AS = list(map(int,input().split()))

m = 1
j = 0

if 0 in AS:
    print(0)
    j = 1
    

if j == 0:
    for i in AS:
        m = m * i
        if m > 10**18 and j == 0:
            print(-1)
            j = 1
            break
        elif m == 0:
            break
        else:
            continue

if j == 0:
    print(m)

Measured memory_bytes: 21704
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
    int W,H,x,y,r;
    String s = buf.readLine();
    String[] strlAry =s.split(" ");
    for(int i=0;i<strlAry.length;i++){
    }
    W= Integer.parseInt(strlAry[0]);
    H= Integer.parseInt(strlAry[1]);
    x= Integer.parseInt(strlAry[2]);
    y= Integer.parseInt(strlAry[3]);
    r= Integer.parseInt(strlAry[4]);
 
    if(((x+r) <=W && 0<=(x-r)) && ((y+r) <=H) &&( 0<=(y-r)) ){
            System.out.println("Yes");
    }
    else{
            System.out.println("No");
    }
}
}

Measured memory_bytes: 24384
import java.util.Scanner;

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

		String S = n.next();

		String[] strArray = S.split("");

		if(strArray[2].equals(strArray[3]) && strArray[4].equals(strArray[5])) {
			System.out.println("Yes");

		}else {
			System.out.println("No");
		}
	}

}


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

int main() {
  int i,j,n,k,tmp,add=0;
  int l[100];
  cin>>n>>k;
  for(i=0;i<n;i++){
    cin>>l[i];
  }
  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      if(l[i]<l[j]){
        tmp=l[i];
        l[i]=l[j];
        l[j]=tmp;
      }
    }
  }
  for(i=0;i<k;i++){
    add+=l[i];
  }
  
  cout<<add<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, T;
  cin >> N >> A >> T;
  int plan1 = N * A;
  if(plan1 > T){
    cout << T << endl;
  }
  else if(plan1 < T){
    cout << plan1 << endl;
  }else{
   cout << plan1 << endl; 
  }
}

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

int main(){
  int a, b, c, n;
 
 cin>>n;
 while(n--){
  cin>>a>>b>>c;
 if(a*a==b*b+c*c || b*b==a*a+c*c || c*c==a*a+b*b){
  cout<<"YES"<<endl;
 }else
  cout<<"NO"<<endl;
 }
}

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

int main() {
	int N, X;
	cin >> N >> X;
	vector<int> L(N);
	vector<int> D(N+1);
	D[0] = 0;
	int count = 0;
	for (int i = 0; i < N; i++) {
		cin >> L[i];
	}
	for (int i = 0; i <= N; i++) {
		D[i + 1] = D[i] + L[i];
		if (D[i] <= X) {
			count+=1;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
#define mk make_pair
#define pb push_back
#define pf push_front
typedef pair<int, int> pii;
int mod = 1000000007;
int INF = 1000000009;
ll INFL = 1000000000000000018ll;

int N, K, Q, a[2020], b[2020];

signed main()
{
    cin >> N >> K >> Q;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    int ans = INFL;
    sort(b, b + N);
    for(int i = 0; i < N; i++){
        priority_queue<int, vector<int>, greater<int> > que, suzuki;
        for(int j = 0; j < N; j++){
            if(b[i] <= a[j]){
                que.push(a[j]);
            }
            else {
                while(que.size() >= K){
                    suzuki.push(que.top());
                    que.pop();
                }
                while(que.size() > 0){
                    que.pop();
                }
            }
        }
        while(que.size() >= K){
            suzuki.push(que.top());
            que.pop();
        }
        if(suzuki.size() < Q){
            continue;
        }
        int mn = suzuki.top();
        for(int j = 0; j < Q - 1; j++){
            suzuki.pop();
        }
        int mx = suzuki.top();
        if(mx < mn)return 1;
        ans = min(ans, mx - mn);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, ans;
    cin >> n;
    ans = n*(n-1)/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n, a;
    cin >> n >> a;
    int x[n];
    int X = a;
    REP(i, n)
    {
        cin >> x[i];
        X = max(X, x[i]);
    }

    long long dp[n + 1][n + 1][n * X + 1];

    REP(j, n + 1)
    {
        REP(k, n + 1)
        {
            REP(s, n * X + 1)
            {
                if (j == 0 and k == 0 and s == 0)
                    dp[j][k][s] = 1;
                else if (j >= 1 and s < x[j - 1])
                {
                    dp[j][k][s] = dp[j - 1][k][s];
                }
                else if (j >= 1 and k >= 1 and s >= x[j - 1])
                {
                    dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]];
                }
                else
                {
                    dp[j][k][s] = 0;
                }
            }
        }
    }
    long long ans = 0;
    rep(k, 1, n + 1)
    {
        ans += dp[n][k][k * a];
    }
    cout << ans << endl;
}

Measured memory_bytes: 51072
from collections import deque


queue = deque()

num, q = map(int, input().split())
for _ in range(num):
    job, time = input().split()
    queue.append([job, int(time)])

res = []
timer = 0
while queue:
    curr_job, job_time = queue.popleft()
    if job_time <= q:
        timer += job_time
        res.append([curr_job, timer])
        continue
    else:
        job_time -= q
        timer += q
        queue.append([curr_job, int(job_time)])

for job in res:
    print(*job)


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

// A,Bの範囲を考える．この時，Xが正の整数であるから，単調増加する数列のうち，最も増分が低いものを考える．
// y = (x+1)^5 - x^5の数列を考える．
//この時，およそx ~ 200 でyはXの範囲を超えてくるのでこれをA,Bの範囲とする．
int main (void){
    ll X;
    cin >> X;
    int A,B;
    FOR(i,-200,200){
        FOR(j,-200,200){
            if(pow(i,5) - pow(j,5) == X){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

int main() {
	int n, i, p[100], t;
	int max, min, maxi, mini;
	cin >> n;
	
	while (n != 0){
		max = 0; min = 1000; t = 0;

		for (i = 0; i < n; i++) {
			cin >> p[i];
		}

		for (i = 0; i < n; i++) {
			t += p[i];

			if (p[i] > max) {
				maxi = i;
				max = p[i];
			}

			if (p[i] < min) {
				mini = i;
				min = p[i];
			}
		}

		cout << (t - p[maxi] - p[mini]) / (n - 2) << endl;

		cin >> n;
	}
}

Measured memory_bytes: 1160
#include<iostream>
#define ll long long
#define MAXN 55
#define mod 998244353
#define INF 0x3f3f3f3f
#define ld long double
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
    #define int ll
    string s;
    cin>>s;
    for(int i=0;i<3;i++){
        if(s[i]=='7'){
            cout<<"Yes"<<endl;return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <algorithm>

using namespace std;

typedef pair<int,int> pii;
typedef pair<int,pii> pipii;

pipii pt[50];
bool solved[50][10];
int penalty[50][10];

int main() {
  while (true) {
    int T, P, R;
    scanf("%d %d %d", &T, &P, &R);
    if (T == 0 && P == 0 && R == 0) break;
    for (int i=0;i<T;i++) {
      pt[i] = pipii(0, pii(0, i+1));
      for (int j=0;j<P;j++) {
        solved[i][j] = false;
        penalty[i][j] = 0;
      }
    }
    for (int i=0;i<R;i++) {
      int tID, pID, time;
      char msg[8];
      scanf("%d %d %d %s", &tID, &pID, &time, msg);
      tID--, pID--;
      if (solved[tID][pID]) continue;
      if (msg[0] == 'C') {
        solved[tID][pID] = true;
        pt[tID].first--;
        pt[tID].second.first += penalty[tID][pID]*1200+time;
      } else {
        penalty[tID][pID]++;
      }
    }
    sort(pt, pt+T);
    for (int i=0;i<T;i++) {
      printf("%d %d %d\n", pt[i].second.second, -pt[i].first, pt[i].second.first);
    }
  }
  return 0;
}

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

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

void hawawa()
{
	int n;
	cin >> n;
	cout << 2 * n / gcd(2, n) << "\n";
}

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


Measured memory_bytes: 256
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1024)

func readLine() string {
	buf := make([]byte, 0, 1024)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func atoi(s string) int {
	i, e := strconv.Atoi(s)
	if e != nil {
		panic(e)
	}
	return i
}

func readStringArray() []string {
	return strings.Split(strings.TrimSpace(readLine()), " ")
}

func readInt() int {
	return atoi(readLine())
}

func readIntArray() []int {
	var a []int
	sa := readStringArray()
	for _, s := range sa {
		a = append(a, atoi(s))
	}
	return a
}

func main() {
	ab := readIntArray()
	var ans int
	if ab[0] < 10 && ab[1] < 10 {
		ans = ab[0] * ab[1]
	} else {
		ans = -1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

int main() {
	int n,m;
	cin >> n >> m;
	vector<int> x(m),d;
	for(int i=0;i<m;i++){
		cin >> x[i];
	}
	sort(x.begin(),x.end());
	
	if(n>=m){
		cout << "0" << endl;
		return 0;
	}
	
	for(int i=1;i<m;i++){
		d.push_back(abs(x[i]-x[i-1]));
	}
	sort(d.begin(),d.end());
	
	long long sum=0;
	for(int i=0;i<d.size()-n+1;i++){
		sum+=d[i];
	}
	cout << sum << endl;
	return 0;
}



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

int GetDigitSum(int tmp) {
  int sum = 0;
  while (tmp) {
    sum += tmp % 10;
    tmp /= 10;
  }
  return sum;
}

int main() {
  
  int N, A, B; cin >> N >> A >> B; int ans = 0;
  
  for (int i = 1; i <= N; i++) {
    
    int tmp = GetDigitSum(i);
    
    if (A <= tmp && tmp <= B) ans += i;
    
  }
  
  cout << ans << endl;
  
}

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

int main() {
	int n,x,ans=0;cin>>n;
  	vector<int> a(100000);
  	for(int i=0;i<n;i++){
    	cin>>x;
      	a[x]++;
    }
  	for(int i=2;i<=100000;i++){
     	 ans=max(ans,a[i-2]+a[i-1]+a[i]);
    }
  	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <sstream>
using namespace std;

#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//STANDARD DATA TYPES
#define ll long long
#define llu unsigned long long
#define ld long double
//ADV DATA TYPES
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ss second
//C 9/++ DS
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define iter :: iterator
#define all(x) x.begin(),x.end()
 
//priority_queue < pii, vector < pii >, greater < pii > > pq;
//lower_bound(v.begin(),v.end(),20);//for any sorted container
//CONSTANTS
#define MOD 998244353
#define INF 0x3f3f3f3f
#define MAXN (int)(2e4+20)

#define fori(i,n) for(int i=0; i<n; i++)
#define forl(i,n) for(ll i=0; i<n; i++)
//MOD OPERATIONS
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll addmod(ll a, ll val, ll p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline ll submod(ll a, ll val, ll p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline ll mult(ll a, ll b, ll p = MOD) {return (ll) a * b % p;}
const  llu int_max = pow(2,32) - 1 ;

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.ff < j.ff;
}

int main(int argc, char const *argv[])
{
	int n,cnt=0;
	ll ans = 0;
	cin>>n;
	int a[n+1];
	for (int i = 0; i < n+1; ++i)
	{
		cin>>a[i];
	}
	int b[n];
	for (int i = 0; i < n; ++i)
	{
		/* code */cin>>b[i];
	}
	for (int i = n-1; i >= 0; i--)
	{
		if(b[i]>=a[i+1]){
			b[i] -= a[i+1] ;
			ans += a[i+1];
		}
		else{
			ans += b[i];
			b[i] = 0;
		}
		if(b[i]>=a[i]){
			ans += a[i];
			a[i] = 0 ;
		}
		else{
			ans += b[i];
			a[i] -= b[i];
		}

	}

	cout<<ans;


	return 0;
}

Measured memory_bytes: 1024
x, k, d = map(int, input().split())

if abs(x) > k*d:
  	print(abs(x)-k*d)
else:
    k -= abs(x)//d
    if k%2 == 1:
      print(abs(d-abs(x)%d))
    else:
      print(abs(x)%d)

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

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define boost ios::sync_with_stdio(0); cin.tie(0)
#define fi first
#define se second
#define  pb push_back
#define  pob pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define sz(x) (int)x.size()
#define endl '\n'
#define mod 1000000007
#define MAX 100005

typedef long long ll;
//typedef int ll;
typedef double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

/********************************************************/

signed main()
{
    boost;
    #ifndef ONLINE_JUDGE
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    #endif // ONLINE_JUDGE
    
    ll h,w,k;
    cin >> h >> w >> k;

    char c[h][w];
    rep(i,0,h){
      rep(j,0,w){
        cin >> c[i][j];
      }
    }
    
    ll posx = (1LL<<h);
    ll x[(1LL<<h)][h];
    rep(i,0,(1LL<<h)){
      ll o = i;
      rep(j,0,h){
        x[i][j] = o%2;
        o/=2; 
      }
    }
    
    ll posy = (1LL<<w);
    ll y[(1LL<<w)][w];
    rep(i,0,(1LL<<w)){
      ll o = i;
      rep(j,0,w){
        y[i][j] = o%2;
        o/=2; 
      }
    }
    ll ans = 0;

    rep(i,0,posx){
      rep(j,0,posy){
         ll bl = 0;
         rep(k,0,h){
          rep(d,0,w){
            if(x[i][k] == 1 or y[j][d]==1)continue;
            if(c[k][d]=='#')bl++;
          }
         }
         if(bl == k)ans++;
      }
    }
    cout << ans << endl;
    return 0;

}



Measured memory_bytes: 3656
#include <stdio.h>

int main(){
  int n, a[200];
  int i, ans, flag;

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

  ans = 0;
  flag = 1;
  while (flag) {
    for (i = 0; i < n; i++) {
      if (a[i] % 2 == 0) {
        a[i] = a[i] / 2;
      }
      else {
        flag = 0;
        break;
      }
    }
    if (flag) {
      ans++;
    }
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 128
def prime_factorize(num):
    """
    This function performs prime factorization on the input natural number.
    The result is returned in the form of a dictionary with the prime number as the key
    and its number as the value.
    :param num:
    :return prime_factor: Dictionary with the prime number as the key and its number as the value.
    """
    prime_factor = {}
    i = 2
    while i ** 2 <= num:
        while num % i == 0:
            num //= i
            if i in prime_factor.keys():
                prime_factor[i] += 1
            else:
                prime_factor[i] = 1
        i += 1
    if num > 1:
        prime_factor[num] = 1
    return prime_factor


from math import factorial


def comb(n, r, R):
    if n not in R:
        a = factorial(n)
        R[n] = a
    else:
        a = R[n]

    if n - r not in R:
        b = factorial(n - r)
        R[n - r] = b
    else:
        b = R[n - r]

    if r not in R:
        c = factorial(r)
        R[r] = c
    else:
        c = R[r]
    return a // (b * c)


n, m = map(int, input().split())
r = 1

R = dict()
prime_fac = prime_factorize(m)
for v in prime_fac.values():
    r *= comb(v + n - 1, v, R)
mod = 1000000000 + 7
print(r % mod)


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



int main() {
    ll n;
    cin >> n;
    vector<ll> g;

    for (ll i = 1; i*i <= n; i++) {
        if (n%i == 0) {
            if (i != 1) g.push_back(i);
            if (n/i != i) g.push_back(n/i);
        }
    } 
    for (ll i = 1; i*i <= n-1; i++) {
        if ((n-1)%i == 0) {
            if (i != 1) g.push_back(i);
            if ((n-1)/i != i) g.push_back((n-1)/i);
        }
    } 

    int ans = 0;
    for (ll x : g) {
        ll dn = n;
        while (dn >= x) {
            if (dn%x == 0) dn /= x;
            else dn %= x;
        }
        if (dn == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
)

func getStdin() []string {
	stdin := bufio.NewScanner(os.Stdin)
	buf := make([]byte, initialBufSize)
	stdin.Buffer(buf, maxBufSize)
	lines := []string{}
	for stdin.Scan() {
		if err := stdin.Err(); err != nil {
			fmt.Fprintln(os.Stderr, err)
		}
		lines = append(lines, stdin.Text())
	}
	return lines
}

func reverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}

func main() {
	lines := getStdin()
	str := lines[0]

	q, _ := strconv.Atoi(lines[1])
	rev := 0
	var first bytes.Buffer
	var last bytes.Buffer
	for i := 0; i < q; i++ {
		line := lines[i+2]
		items := strings.Split(line, " ")
		t := items[0]
		if t == "1" {
			rev++
		} else if t == "2" {
			f := items[1]
			c := items[2]
			if (f == "1" && rev%2 == 0) || (f == "2" && rev%2 == 1) {
				first.WriteString(c)
			} else if (f == "2" && rev%2 == 0) || (f == "1" && rev%2 == 1) {
				last.WriteString(c)
			}
		}
	}

	var ans string
	if rev%2 == 1 {
		ans = reverse(last.String()) + reverse(str) + first.String()
	} else {
		ans = reverse(first.String()) + str + last.String()
	}
	fmt.Println(ans)
}


Measured memory_bytes: 15360
n = gets.to_i
map = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
ans = Array.new(26,0)
s = []
n.times do |i|
  s[i] = gets.chomp
end
s[0].length.times do |i|
  ans[map.index(s[0][i])] += 1
end
1.upto(n-1) do |i|
  tmp = Array.new(26,0)
  s[i].length.times do |j|
    tmp[map.index(s[i][j])] += 1
  end
  26.times do |k|
    ans[k] = tmp[k] if ans[k] > tmp[k]
  end
end
string = ""
26.times do |i|
  ans[i].times do
    string = string + map[i]
  end
end
puts string

Measured memory_bytes: 14204
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 998244353
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	string s;

	int w;

	cin>>s>>w;

	for(int i=0; i<s.size(); i+=w){
		cout<<s[i];
	}
	cout<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
main(){
  int x,y,a,flag = 0;
  cin>>x>>y;
  for(int i=0;i<=x;i++){
    if(2*i+4*(x-i) == y){
      flag = 1;
      break;
    }
  }
  if(flag == 1) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3624
package main

import (
	"fmt"
)

func main() {
	var N, K int
	fmt.Scan(&N, &K)

	for i := 1; i < 100000; i++ {
		max := 1
		for j := 0; j < i; j++ {
			max *= K
		}
		max--
		// fmt.Printf("max %d\n", max)
		if N <= max {
			fmt.Printf("%d\n", i)
			break
		}
	}
}


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

using namespace std;

int ans = 0;

bool check(vector<vector<int> >& vec){
    int n = (int)vec.size();
    bool ok = false;
    rep(i,n){
        int s=0, t=0;
        int cri = 0;
        if(vec[i][0] == vec[i][1] && vec[i][1] == vec[i][2] && vec[i][2] > 0){
            s = 0, t = 3;
            cri = vec[i][0];
            if(vec[i][3] == cri){
                t++;
                if(vec[i][4] == cri){
                    t++;
                }
            }
        }else if(vec[i][1] == vec[i][2] && vec[i][2] == vec[i][3] && vec[i][2] > 0){
            s = 1, t = 4;
            cri = vec[i][1];
            if(vec[i][4] == cri){
                t++;
            }
        }else if(vec[i][2] == vec[i][3] && vec[i][3] == vec[i][4] && vec[i][2] > 0){
            s = 2, t = 5;
            cri = vec[i][2];
        }
        for(int j = s; j < t; j++){
            ok |= true;
            vec[i][j] = -1;
        }
        ans += cri*(t-s);
    }
    return ok;
}

void down(vector<vector<int> >& vec)
{
    int n = (int)vec.size();
    for(int i = n-1;i >= 1;i--){
        rep(j,5){
            if(vec[i][j] == -1){
                for(int k = i-1; k >= 0; k--){
                    if(vec[k][j] > 0){
                        vec[i][j] = vec[k][j];
                        vec[k][j] = -1;
                        break;
                    }
                }
            }
        }
    }
}

int main()
{
    while(1){
        int h;
        cin >> h;
        if(h == 0){
            break;
        }
        ans = 0;
        vector<vector<int> > vec(h,vector<int>(5));
        rep(i,h){
            rep(j,5){
                cin >> vec[i][j];
            }
        }
        while(1){
            if(check(vec)){
                // rep(i,h){
                //     rep(j,5){
                //         cout << vec[i][j] << " ";
                //     }
                //     cout << "\n";
                // }
                down(vec);
                // rep(i,h){
                //     rep(j,5){
                //         cout << vec[i][j] << " ";
                //     }
                //     cout << "\n";
                // }
            }else{
                break;
            }
        }
        cout << ans << "\n";
    }
}



Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位


int main(void){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a+1==c && d==1)
        cout << 1 << endl;
    else
        cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int s,ss,sss;
	while(1){
		scanf("%d",&s);
		if(s==0) break;
		ss=1000-s;
		sss=ss/500;

		ss=ss%500;
		sss+=ss/100;

		ss=ss%100;
		sss+=ss/50;

		ss=ss%50;
		sss+=ss/10;

		ss=ss%10;
		sss+=ss/5;

		ss=ss%5;
		sss+=ss/1;

	printf("%d\n",sss);
	}
	return 0;
}

Measured memory_bytes: 1028
import sys
# Xは動物の総数,Yは動物の足の総数
X,Y = map(int, input().split())

# まずは鶴が1匹の時だけを判定,奇数は有えないので排除
for i in range(100):
  for j in range(100):
    if i + j == X and 4*i + 2*j == Y:
      print("Yes")
      sys.exit()

print("No")

Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
#define Long long long
#define fastIO ios::sync_with_stdio(0) , cin.tie(0)

#define all(v) v.begin() ,v.end()
#define rall(v) v.rbegin(),v.rend()
#define forn(i,n) for(__typeof(n) i=0 ;i<n ;++i)
#define pb push_back
#define debug(x) cout << "[ " << #x << " = " << x << " ]\n"

#define PI acos(-1.0)
#define EPS 1e-6
#define MOD 1e9+7

const int MXS = 2e5 + 5 ;
const Long MX = 1e18 + 5 ;


int main(){
    fastIO;
    int n,k;
    int cnt = 0;
    cin >>n >> k;
    vector<int> v(n+1,0);
    forn(i,k){
        int x;
        cin >> x;
        forn(j,x){
            int s;
            cin >> s;
            if(v[s]==0) cnt++;
            v[s]++;
        }
    }
    cout << n - cnt;

    return 0;
}

Measured memory_bytes: 3636
def gcd(a,b):
    if b==0: return a
    return gcd(b,a%b)

def ela(g):
    s={1}
    i=2
    while i*i<=g:
        while g%i==0:
            g//=i
            s.add(i)
        i+=1
    if g!=1: s.add(g)
    return s

a,b=map(int,input().split())
G=gcd(max(a,b),min(a,b))
print(len(ela(G)))

Measured memory_bytes: 9208
N, A, B = gets.chomp.split(" ").map(&:to_i)
x = gets.chomp.split(" ").map(&:to_i)
walk_fatigue = []
(1...N).each do |i|
    walk_fatigue << (x[i] - x[i-1]) * A
end
ans = 0
walk_fatigue.each do |e|
    ans += e > B ? B : e
end
puts ans

Measured memory_bytes: 10372
import sys

def main(lines):
  a, b = map(int, lines[0].split())
  if a % 2 != 0 and b % 2 != 0:
    print("Yes")
    return
  print("No")


if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)

Measured memory_bytes: 3060
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var b = Array.ConvertAll(line, int.Parse);
        var a = new int[n + 2];
        long t = Math.Abs(b[0]) + Math.Abs(b[n - 1]);
        for (int i = 1; i <n; i++)
        {
            t += Math.Abs(b[i] - b[i - 1]);
            a[i + 1] = b[i];
        }
        a[n + 1] = a[0];  a[1] = b[0];
        for (int i = 1; i <= n; i++)
        {
            if ((a[i - 1] <= a[i] && a[i] <= a[i + 1]) | (a[i - 1] >= a[i] && a[i] >= a[i + 1])) Console.WriteLine(t);
            else
            {
                var ret = t - Math.Abs(a[i - 1] - a[i]) - Math.Abs(a[i] - a[i + 1]) + Math.Abs(a[i - 1] - a[i + 1]);
                Console.WriteLine(ret);
            }
        }
    }
}

Measured memory_bytes: 26332
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    int A[N];
    ll s[N+1];
    rep(i, N) {
        cin >> A[i];
    }
    s[0] = 0;
    rep(i, N) {
        s[i+1] = s[i] + A[i];
    }
    sort(s, s+N+1); 

    ll t = s[0];
    int k = 0;
    int c[N+1];
    rep(i, N+1) {
        c[i] = 0;
    }   

    rep(i, N+1) {
        if(t < s[i]) {
            t = s[i];
            k++;
            c[k]++;
        } 
        else {
            c[k]++;
        }
    }

    ll ans = 0;

    rep(i, N+1) {
        if(c[i] == 0) {
            break;
        }
        ans += (ll)c[i]*(c[i]-1)/2;
    }

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

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

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))

using namespace std;

using ll = long long;
const ll MAX = LLONG_MAX;
const ll MIN = LLONG_MIN;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;
typedef vector<int> IntVector;
typedef list<int> IntList;

typedef struct S{
  int a;
  int b;
} Object;

int main(){
  char C;
  cin >> C;
 
  C++;
  
  cout << C << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b = sc.nextInt();

		int c = (a * b) % 2;

		if(c == 1){
			System.out.println("Odd");
		}
		else{
			System.out.println("Even");
		}
	}

}

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

using ull = unsigned long long;
using vals = std::pair<ull, ull>; //number & count
using vecv = std::vector<vals>;

void p(const vecv&v_) {
	for (const auto& v : v_) {

		std::cout << v.first<<","<<v.second << "\n";
	}
}
void p(const vals&v_) {

	std::cout << v_.first << "," << v_.second << "\n";
}
int main() {
	ull N,t;
	std::cin >> N;
	vecv vec;
	for (size_t i{ 0 }; i < N; i++) {
		std::cin >> t;
		vec.emplace_back(t, 0);
	}
	


	bool b = true, sec = { false };
	ull ind = 1;
	while (b) {

		auto& x = vec[static_cast<unsigned int>(ind - 1)];
//		p(x);
		if (x.second == 0) {
			x.second += 1;
		}else {
			b = !b;
		}


		
		ind = x.first;
		if (ind == 2) { sec = !sec; b = !b; }
//		std::cout << sec << ", " << b << "\n";
	}

	auto res = std::count_if(std::begin(vec), std::end(vec),
		[](auto v) {
		return v.second == 1;
	});
//	p(vec);
	std::cout << (sec ? res: -1) << "\n";
	return 0;
}


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

int cnt = 0;
int MOD = 1000000007;

int N,total=0;
int A[200010];
signed main(){
    cin >> N;
    
    for(int i=0;i<N;i++){
        cin >> A[i];
        total += A[i];
    }
    
    int tmp = total,sum = 0;
    for(int i=0;i<N;i++){
        sum += A[i];
        tmp = min(tmp,abs(sum-(total-sum)));
    }
    
    cout << tmp << endl;
    return 0;
}


Measured memory_bytes: 1792
n = int(input())

min_digits = 100
for i in range(int(n ** 0.5) + 1):
    a = i + 1
    if n % a != 0:
        continue
    b = n // a
    x = max([a, b])
    digits = len(str(x))
    if digits < min_digits:
        min_digits = digits

print(min_digits)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>

using namespace std;
int main() {
	string A, B, C;
	cin >> A >> B >> C;

	bool ans = true;

	if (A.at(A.size() - 1) != B.at(0)) ans = false;
	if (B.at(B.size() - 1) != C.at(0)) ans = false;

	if (ans) cout << "YES" << endl;
	else cout << "NO" << endl;

}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define LL unsigned long long 
const int N=1e5+9;
using namespace std;
LL a[N],n,l,r;
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;++i) 
	  scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	LL ans;
	LL pos;
	for(LL  i=n;i>=1;i=pos-1)
	{
		pos=i;
		LL num=0;
		while(a[pos]==a[pos-1])
		 {
		 	num++;
		 	pos--;
		 }
		num++; 
	    if(num>=2)
	    {
		   	if(r>0) { ans=(LL)a[pos]*r;break;}
		    else
			{
			 if(num>=4) {ans=(LL) a[pos]*a[pos];break;}
			 else r=a[pos];
	        }
		}
	}
	cout<<ans<<endl;
}
/*
6
9 5 1 1 1 1
*/

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr auto INF = INT_MAX / 2;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n, z, w;
	cin >> n >> z >> w;

	vi a(n);
	rep(i, n)cin >> a[i];

	if (n == 1)cout << abs(a[0] - w) << endl;
	else cout << max(abs(a[n - 1] - w), abs(a[n - 1] - a[n - 2]));

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String X = sc.next();
        String Y = sc.next();
        String Z = sc.next();
        
        String temp = X;
      	X = Y;
      	Y = temp;
      
      	temp = X;
      	X = Z;
      	Z = temp;
      
      	System.out.println(X + " " + Y + " " + Z);
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>
#include <math.h>
 int main(void){
    
    int a,p,c=0;
   scanf("%d %d",&a,&p);
    
   while(a>0){
     a-=1;
      c++;
   }
   printf("%d",(p+c*3)/2);
  
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>

using namespace std;

using ll = long long;

int main(){
    int a,b;
    cin >> a >> b;
    int ans = 0;
    for(int i=a; i<=b; i++){
        string k = to_string(i);
        bool flag = true;
        for(int j=0; j<3; j++){
            if(k[j]==k[4-j]){
                continue;
            }
            else{
                flag = false;
                break;
            }
        }
        if(flag){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
#define ll  long long 
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  string a;cin>>a;
  ll b=0,c=0;
  rep(i,a.size()){
    if(a[i]=='?')a[i]='D';
  }
    cout<<a;
}

Measured memory_bytes: 27156
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

S = np.array(list(readline().rstrip()),np.int64)
T = np.array(list(readline().rstrip()),np.int64)

LS = len(S); LT = len(T)
LSext = LS + LT
LSext += (-LSext) % LS
Sext = np.tile(S,LSext//LS)

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

U = 2*10**6
MOD = 10 ** 9 + 993
base = 123450
x = np.full(U,base,dtype=np.int64); x[0] = 1
power = cumprod(x,MOD)
x = np.full(U,pow(base,MOD-2,MOD),dtype=np.int64); x[0] = 1
power_inv = cumprod(x,MOD)

def RollingHash(S):
    return (S * power[:len(S)] % MOD).cumsum() % MOD

Sext_hash = RollingHash(Sext)
T_hash = RollingHash(T)[-1]

# ある地点を開始位置として、長さLTの文字列のhash値
x = Sext_hash[LT-1:LS+LT-1].copy()
x[1:] -= Sext_hash[:LS-1]
x *= power_inv[:LS]; x %= MOD

# ある場所から始めたとして、Tを繰り返せる回数
INF = LS+100
cnt = [INF] * LS
stack = np.where(x!=T_hash)[0].tolist()
for x in stack:
    cnt[x] = 0
while stack:
    x = stack.pop()
    y = (x-LT)%LS
    if cnt[y] == INF:
        cnt[y] = cnt[x] + 1
        stack.append(y)

answer = max(cnt)
if answer == INF:
    answer = -1
print(answer)

Measured memory_bytes: 142740
#include <vector>
#include <iostream>
#define MOD 1000000007
using namespace std;
long long fast_pow(long long Base, long long n, long long M){
	if (n == 0)	return 1;
	if (n == 1)	return Base;
	long long  halfn = fast_pow(Base, n / 2, M);
	long long ans;
	if (n % 2 == 0)	{ ans =(halfn * halfn) % M; }
	else { ans =(((halfn * halfn) % M)*Base) % M; }
	return ans;
}
long long findMMI(int n){
	return fast_pow(n, MOD - 2, MOD);
}
long long  nCr(long long n, long long r, const vector<long long>& modFact){
	long long ans;
	long long numerator = modFact[n];
	long long denominator = (modFact[r] * modFact[n - r]) % MOD;
	long long denMMI = findMMI(denominator);
	ans = (numerator * denMMI) % MOD;
	return ans;
}
int main()
{
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	vector<long long> modFact = { 1 };
	for (int i = 1; i <= w + h; ++i){
		modFact.push_back ((modFact.back()*i)%MOD);
	}
	long long ans = 0;
	for (int t = 1; t <= h - a; ++t){
		ans +=(nCr(b + t - 2, b - 1, modFact)*nCr(w - b + h - t - 1, w - b - 1, modFact));
		ans %= MOD;
	}
	cout << ans << endl;
	//cin >> a;
	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
 
//Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	deque< char > dq;
	for (int i = 0 ; i < s.length() ; i++)
		dq.push_back(s[i]);
	int q;
	cin >> q;
	int curState = 0;
	while (q--)
	{
		int ask;
		cin >> ask;
		if (ask == 1)
			curState ^= 1;
		else
		{
			int x;
			cin >> x;
			--x;
			x ^= curState;
			char ta;
			cin >> ta;
			if (x == 0)
				dq.push_front(ta);
			else
				dq.push_back(ta);
		}
	}
	if (curState)
		reverse(dq.begin(),dq.end());
	for (auto i : dq)
		cout << i;
	cout << endl;
	return 0;
}

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

int main()
{
  const int MOD = 2019;
  int L, R; cin >> L >> R; R++;
  int maxij, minij;
  minij = L % MOD;
  if (R - L >= MOD) maxij = minij + MOD;
  else {
    maxij = R % 2019;
    if (minij >= maxij) maxij += MOD;
  }

  int ans = MOD;
  for (int i = minij; i < maxij; i++)
  {
    for (int j = i + 1; j < maxij; j++)
    {
      ans = min(ans, i * j % MOD);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int a;
    cin>>a;
    int ans=a;
    for(int i=0;i<=a;i++)
    {
        int cont=0;
        int t=i;
        while(t>0)
        {
            cont+=t%6;
            t/=6;
        }
        t=a-i;
        while(t>0)
        {
            cont+=t%9;
            t/=9;
        }
        ans=min(ans,cont);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def binarySearch(a, key)
	left = 0
	right = a.size
	while left < right
		mid = (left + right) / 2
		if a[mid] == key
			return true
		elsif key < a[mid]
			right = mid
		else
			left = mid + 1
		end
	end
	return false
end

n = gets.to_i
s = gets.split.map &:to_i
q = gets.to_i
t = gets.split.map &:to_i

s.sort!
sum = 0
t.each do |val|
	sum += 1 if binarySearch(s, val)
end

puts sum

Measured memory_bytes: 18048