akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)

struct UnionFind{
	vector<int> par;

	UnionFind(int N) : par(N){
		for(int i=0; i<N; i++) par[i] = i;
	}

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

	void unite(int x, int y){
		int rx = root(x);
		int ry = root(y);
		if(rx==ry) return;
		par[rx] = ry;
	}

	bool same(int x, int y){
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main(){
	int N,M;
	cin >> N >> M;
	vector<int> a(M);
	vector<int> b(M);
	rep(i,M){ cin >> a[i] >> b[i]; }
	int ans = 0;
	rep(i,M){
		UnionFind uf(N+1);
		for(int j=0; j<M; j++){
			if(i==j)continue;
			uf.unite(a[j],b[j]);
		}
		if(!uf.same(a[i],b[i])) ans++;
		
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
X = [[int(_) for _ in input().split()] for i in range(n)]

A = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
for b, f, r, v in X:
    A[b-1][f-1][r-1] += v

for i, B in enumerate(A):
    for F in B:
        for r in F:
            print(" {}".format(r), end = "")
        print()
    if i < 3:
        print("#" * 20)



Measured memory_bytes: 5624
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    plglg p[N];
    REP(i, 0, N) {
        ll x, y;
        cin >> x >> y;
        p[i] = plglg(x, y);
    }
    vector<plglg> vec;
    REP(i, 0, N) {
        REP(j, i + 1, N) {
            ll x = p[i].first - p[j].first;
            ll y = p[i].second - p[j].second;
            if (x > 0) {
                vec.push_back(plglg(x, y));
            } else if (x < 0) {
                vec.push_back(plglg(-x, -y));
            } else {
                if (y >= 0) {
                    vec.push_back(plglg(x, y));
                } else {
                    vec.push_back(plglg(-x, -y));
                }
            }
        }
    }
    sort(vec.begin(), vec.end());
    ll len = vec.size();
    ll val = 0;
    ll tmp = 0;
    ll xx = inf;
    ll yy = inf;
    REP(i, 0, len) {
        if (vec[i].first != xx || vec[i].second != yy) {
            xx = vec[i].first;
            yy = vec[i].second;
            // cout << xx << " " << yy << " " << tmp << endl;
            val = max(val, tmp);
            tmp = 1;
        } else {
            tmp++;
        }
    }
    val = max(val, tmp);
    cout << N - val << endl;
}


Measured memory_bytes: 384
None, Wall, Visited = (0...3).to_a
Y, X = 0, 1
Even, Odd = 0, 1
NextPoint = [
  [[0,-1], [0,1], [-1,-1], [-1,0], [1,-1], [1,0]],
  [[0,-1], [0,1], [-1,0], [-1,1], [1,0], [1,1]],
]

def bfs!(map, y, x)
  q = Array.new.push([y,x])
  count = 0
  until q.empty? do
    y, x = q.pop
    next if map[y][x] == Visited
    map[y][x] = Visited
    parity = (y&1 == 0) ? Even : Odd
    NextPoint[parity].each do |d|
      nextY, nextX = y+d[Y], x+d[X]
      next if nextY < 0 || map.size <= nextY
      next if nextX < 0 || map[nextY].size <= nextX
      case map[nextY][nextX]
        when Wall
          count += 1
        when None
          q.push([nextY, nextX])
      end
    end
  end
  count
end

w, h = gets.split.map(&:to_i)
map = Array.new
map.push((0...w+2).collect{None})
map.push(*(0...h).collect{[None, *gets.split.map(&:to_i), None]})
map.push((0...w+2).collect{None})
p bfs!(map, 0, 0)

Measured memory_bytes: 6904
a = input()
b = 0
if a[0] != "A":
    print("WA")
    exit()
for i in range(2,len(a)-1):
    if b == 0 and a[i] == "C":
        b = i
    elif b != 0 and [i] == "C":
        print("WA")
        exit()
if b == 0:
    print("WA")
    exit()
for i in range(len(a)):
    if i != 0 and i != b and a[i].isupper():
        print("WA")
        exit()
print("AC")


Measured memory_bytes: 3064
fn main() {
    proconio::input! {
        n: usize,
        uv: [(usize,usize);n-1],
    }
    let mut s=n*(n+1)*(n+2)/6;
    for (u,v) in uv {
        let a=if u<v {u} else {v};
        let b=if u<v {v} else {u};
        s-=a*(n-b+1);
    }
    println!("{}",s);
}

Measured memory_bytes: 7720
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
      	int a = scn.nextInt();
      	int b = scn.nextInt();
      	int c = scn.nextInt();
      	int d = scn.nextInt();
      	String s = scn.next();
      	String s1 = s.substring(a-1, c);
        String s2 = s.substring(b-1, d);
        if(s1.contains("##") || s2.contains("##")){
            System.out.println("No");
        }else{
            if(d<n){
                s2 = s.substring(b-2, d+1);
            }else{
                s2 = s.substring(b-2, d);
            }
            if(d<c && !(s2.contains("..."))) {
                System.out.println("No");
            }else{
                System.out.println("Yes");
            }
        }
	}
}

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

int n, k, now = 1, bf = 0, ans = 0;
bool d[10] = {0};

int main() {
  cin >> n >> k;
  for(int i = 0; i < k; ++i) {
    int x;
    cin >> x;
    d[x] = 1;
  }
  ans = n;
  while(1) {
    now = ans;
    while(now > 0) {
      if(d[now % 10]) break;
      now /= 10;
    }
    if(now == 0) break;
    ++ans;
  }
  cout << ans << endl;
  return 0;
}

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

bool erats[1000001];

int main(){
	memset( erats, 0, sizeof(erats) );
	erats[0] = erats[1] = true;
	for( int i=2; i<500000; i++ ){
		for( int j=i+i; j<=1000000; j+=i ){
			erats[j] = true;
		}
	}
	int n;
	while( cin >> n, n>0 ){
		int ret=0, cnt=0;
		for( int i=2; cnt<n; i++ ){
			if( !erats[i] ){
				ret += i;
				cnt++;
			}
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 1732
#include<stdio.h>
#include<math.h>
#define SIZE 100
int main(void)
{
    int i, n, p, x[SIZE], y[SIZE];
    double d, max;
    
    scanf("%d", &n);
    for ( i=0; i<n; ++i)
        scanf("%d", &x[i]);
    for ( i=0; i<n; ++i)
        scanf("%d", &y[i]);
    
    for ( p=1; p<=3; ++p) {
        d = 0;
        for ( i=0; i<n; ++i)
            d += pow( abs(x[i]-y[i]), p);
        d = pow( d, 1.0/p);
        printf("%lf\n", d);
    }
    
    max = 0;
    for ( i=0; i<n; ++i)
        if ( (p=abs(x[i]-y[i])) > max)
            max = p;
    printf("%lf\n", max);
    
    return 0;
}


Measured memory_bytes: 2096
#include <iostream>
 
using namespace std;
typedef long long ll;
 
ll a, b;
 
void solve() {
  if ((a & 1) == (b & 1)) {
    cout << (a + b) / 2 << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}
 
int main() {
  cin >> a >> b;
  solve();
}

Measured memory_bytes: 256
import java.io.*;


public class Main {
    public static void main(String[] args) throws IOException {
        Reader reader=new Reader();
        PrintWriter pw=new PrintWriter(System.out);
        int t=reader.nextInt();
        int a=reader.nextInt();
        int b=reader.nextInt();
        for (int i = a; i <=b; i++) {
            if (i%t==0) {
                System.out.println("OK");
                return;
            }
            
        }
        System.out.println("NG");

        pw.close();
    }
}

 class Reader {
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader() {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException {
        byte[] buf = new byte[64];
        int cnt = 0, c;
        while ((c = read()) != -1) {
            if (c == '\n') break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException {
        int ret = 0;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (neg) return -ret;
        return ret;
    }

    public long nextLong() throws IOException {
        long ret = 0;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (neg) return -ret;
        return ret;
    }

    public double nextDouble() throws IOException {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
        if (neg) return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1) buffer[0] = -1;
    }

    private byte read() throws IOException {
        if (bufferPointer == bytesRead) fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException {
        if (din == null) return;
        din.close();
    }
}



Measured memory_bytes: 32596
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 100000000000
#define MOD 1000000007LL
#define MAX 100100
#define MAX_N 100100
#define MAX_LOG_N 25
#define NIL -1
#define WHITE 0
#define BLACK 1
using namespace std;
typedef long long ll;
typedef map<ll, ll> Map;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> P;

int main(void) {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    bool flag=false;
    
    for(ll i=0; i<=n; i++) {
        if(c*(n-1-i)-d*i<=b-a && b-a<=-c*i+(n-1-i)*d)
            flag=true;
    }
    
    if(flag) pYE;
    else pNO;
}

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

int main(){
  int N,i=0,memo[55]={};
  long ans;
  string S,T;
  cin>>N>>S>>T;
  if(S[0]==S[1]){
    ans = 6;
    i = 2;
    memo[0]=2;
    memo[1]=2;
  }else{
    ans = 3;
    i = 1;
    memo[0]=1;
  }
  while(i<N){
    if(memo[i-1]==1){
      if(S[i]==S[i+1]){
        ans *=2;
        memo[i]=2;
        memo[i+1]=2;
        i+=2;
      }else{
        ans *= 2;
        memo[i]=1;
        i += 1;
      }
    }else if(memo[i-1]==2){
      if(S[i]==S[i+1]){
        ans*=3;
        memo[i]=2;
        memo[i+1]=2;
        i +=2;
      }else{
        memo[i]=1;
        i+=1;
      }
    }
  }
  cout<<ans%1000000007<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int team1;
		int team2;
		int point1;
		int point2;
		int[] win=new int[100];
		int[] total=new int[100];
		int N=n*(n-1)/2;
		for(int i=0;i<N;i++){
			team1=sc.nextInt();
			team2=sc.nextInt();
			point1=sc.nextInt();
			point2=sc.nextInt();
			if(point1>point2){
				win[team1-1]=win[team1-1]+3;
			}
			else if(point1<point2){
				win[team2-1]=win[team2-1]+3;
			}
			else{
				win[team1-1]=win[team1-1]+1;
				win[team2-1]=win[team2-1]+1;
			}
		}
		for(int a=0;a<n;a++){
			int r = 1;
			for(int j=0;j<n;j++){
				if(win[a]<win[j]){
					r = r + 1;
				}
				
			}
			total[a] = total[a] + r;
			
		}
		for(int b = 0; b < n; b++){
			System.out.println(total[b]);
			
		}
	}
}

Measured memory_bytes: 42292
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        string s = cin.next();
        if (s.IndexOf("9") == -1) Console.WriteLine("No");
        else Console.WriteLine("Yes");
    }
    


}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

int main()
{
    std::string s;
    std::cin >> s;
    for(std::size_t i = 0; i != s.length() - 2; i++)
    {
        if(s[i] == s[i + 1] || s[i] == s[i + 2] || s[i + 1] == s[i + 2])
        {
            std::cout << i + 1 << ' ' << i + 3 << std::endl;
            return 0;
        }
    }
    if(s.length() == 2 && s[0] == s[1])
    {
        std::cout << "1 2" << std::endl;
        return 0;
    }
    std::cout << "-1 -1" << std::endl;
    return 0;
}


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

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

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  A -= 1;
  ll X = (B - B / C - B / D + B / (C * D / gcd(C, D)));
  ll Y = (A - A / C - A / D + A / (C * D / gcd(C, D)));
  cout << X - Y << endl;
}

Measured memory_bytes: 256
#include<iostream>
#define ll long long int
#define ld long double
#define pi acos(-1)
#define pb push_back
using namespace std;

int main()
{
    ll i,j,a,k,b,c,n,t,m,p,q,d,e,f,y,g,z,h,r,l,x;
    ld aa,bb,ee,dd,ff,kk,gg;
//    vector<ll > v,s,vv;
//    map<ll, ll > ta,pa,sa,ma;
//    map<ll,vector<ll>  > me;
//    priority_queue<ll > aq,tq,pq,nq,mq,xq;
//    string st,et,ft,pt,ct;
//    deque<ll> de,ne;
//    set<ll> li;
    ios_base::sync_with_stdio(false);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    cin>>n>>x>>t;
    b = n/x;
    if(n%x!=0)b++;
    cout<<b*t<<endl;
}


Measured memory_bytes: 3660
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n;
	cin >> n;
	vector<int>name(5);
	string march = "MARCH";
	rep(i, n) {
		string s;
		cin >> s;
		rep(i, 5) {
			if (s[0] == march[i]) name[i]++;
		}
	}
	int ans = 0;
	for (int bit = 0; bit < (1 << 5); ++bit) {
		vector<int> a;
		for (int i = 0; i < 5; ++i) {
			if (bit & (1 << i)) {
				a.push_back(i);
			}
		}
		if (a.size() != 3)continue;
		ans += name[a[0]] * name[a[1]] * name[a[2]];
	}
    cout<<ans<<endl;
}


Measured memory_bytes: 3604
#include <cstdio>
#include <vector>

using namespace std;

int main()
{
    const int limit = 1e5;
    vector <int> frequency(limit + 1, 0);

    int no_of_elements;
    scanf("%d", &no_of_elements);

    for(int i = 1; i <= no_of_elements; i++)
    {
        int element_i;
        scanf("%d", &element_i);

        frequency[element_i]++;
    }

    int maximum_equal_elements = 0;
    for(int equal_element = 1; equal_element < limit; equal_element++)
    {
        int no_of_equal_elements = frequency[equal_element - 1] + frequency[equal_element] + frequency[equal_element + 1];
        maximum_equal_elements = max(maximum_equal_elements, no_of_equal_elements);
    }

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

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

int main(){
	int a, b, c;
	int count7 = 0, count5 = 0;
	cin>>a>>b>>c;
	if(a != 5 && a != 7)
		cout<<"NO1";
	if(b != 5 && b != 7)
		cout<<"NO2";
	if(c != 5 && c != 7)
		cout<<"NO3";
	if(a == 5)
		count5++;
	if(a == 7)
		count7++;
	if(b == 5)
		count5++;
	if(b == 7)
		count7++;
	if(c == 5)
		count5++;
	if(c == 7)
		count7++;
	if(count5 == 2)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto N = RD;
	auto A = RDA;
	auto Q = RD;
	auto B = new long[](Q);
	auto C = new long[](Q);
	foreach (i; 0..Q)
	{
		B[i] = RD;
		C[i] = RD;
	}

	long ans;
	long[long] cnt;
	foreach (i; 0..N)
	{
		++cnt[A[i]];
		ans += A[i];
	}

	foreach (i; 0..Q)
	{
		auto x = cnt.get(B[i], 0);
		auto y = cnt.get(C[i], 0);
		y += x;
		ans -= x * B[i];
		ans += x * C[i];
		cnt[C[i]] = y;
		cnt[B[i]] = 0;
		writeln(ans);
	}

	stdout.flush;
	debug readln;
}

Measured memory_bytes: 10304
import java.util.ArrayList;
import java.util.Scanner;

public class Main
{
	static int n, m;

	static int[] mask = new int[12];
	static long[] dp = new long[4096];
	static int fullmask = 0;
	static ArrayList<Integer> reachablestates = new ArrayList<Integer>();
	static long INF = 1000000000000l;
	
	public static void main(String[] args) 
	{
		for(int i = 0; i < 4096; i++)
			dp[i] = INF;
		int curm = 1;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		for(int i = 0; i < 12; i++)
		{
			if(i<n)fullmask += curm;
			mask[i] = curm;
			curm *= 2;
		}
//		dp[fullmask] = 0;
		
		reachablestates.add(0);
		dp[0] = 0;
		
		for(int i = 0; i < m; i++)
		{
			long price = sc.nextLong();
			int opens = sc.nextInt();
			int masker = 0;
			for(int j = 0; j < opens; j++)
			{
				int ch = sc.nextInt()-1;
				masker = masker | mask[ch];
			}
			
			ArrayList<Integer> toadd = new ArrayList<>();
			for(Integer s : reachablestates)
			{
				int after = masker | s;
				if(after != s)
				{
					//update cost
					if(dp[after] == INF)
					{
						toadd.add(after);
					}
					dp[after] = Math.min(dp[after], dp[s] + price);
				}
			}
			for(Integer s : toadd)
				reachablestates.add(s);
			

		}
		if(dp[fullmask]==INF)System.out.println(-1);
		else System.out.println(dp[fullmask]);
		

	}

}


Measured memory_bytes: 32192
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        //入力
        Scanner scn=new Scanner(System.in);
        int n=scn.nextInt();
        double[] digits =new double[n];
        String[] kind=new String[n];
        for(int i=0;i<n;i++){
            digits[i]=scn.nextDouble();
            kind[i]=scn.next();
        }
        //処理
        double total=0;
        for(int i=0;i<n;i++){
            if(kind[i].equals("BTC")){
                total+=380000*digits[i];
            }else{
                total+=digits[i];
            }
        }
        //入力
        System.out.println(total);
    }
}


Measured memory_bytes: 25172
#include<bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
using namespace std;
#define mod 1000000007
const int maxn=1000000;
int dp[3005][3005];
int lcs(string &a,string &b,int n,int m) {
    if (n == 0 or m == 0) return 0;
    if (dp[n][m] != -1) return dp[n][m];
    if (a[n - 1] == b[m - 1]) {
        return dp[n][m] = 1 + lcs(a, b, n - 1, m - 1);
    }
    int x = lcs(a, b, n - 1, m);
    int y = lcs(a, b, n, m - 1);
    return dp[n][m] = max(x, y);
}
void solve() {
    string a, b;
    cin >> a >> b;
    int n = a.size(), m = b.size();
    memset(dp, -1, sizeof(dp));
    int len = lcs(a, b, n, m);
    string ans;
    int i = n, j = m;
    while (i > 0 and j > 0) {
        if (a[i - 1] == b[j - 1]) {
            ans += a[i - 1];
            i--;
            j--;
            len--;
        } else if (dp[i - 1][j] > dp[i][j - 1]) {
            i--;
        } else j--;
    }
    reverse(all(ans));
    cout<<ans;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 74476
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int n;
  cin>>n;
  int cnt=0;
  for(int i:irange(1,n/2+1)) {
    if (n-i != i) ++cnt;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 20 16:39:29 2018

@author: Yuya
"""


N = int(input())

C=[0]*(N-1)
S=[0]*(N-1)
F=[0]*(N-1)

for i in range(N-1):
    c, s, f = map(int,input().split())
    C[i] = c
    S[i] = s
    F[i] = f

for i in range(N-1):
    time = 0
    for j in range(i, N-1):
        if time < S[j]:
            time = S[j]
        elif time % F[j] == 0:
            time = time
        else:
            time = time+F[j]-(time%F[j])
        time = time + C[j]
    print(time)

time = 0
print(time)

Measured memory_bytes: 3188
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<numeric>
#include<stdio.h>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

#define INF 999999999
#define MOD 1000000007

#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

struct w{
	int Beg;
	int End;
	int siz;
};

string s;
vector<int> c;
w ipt;
vector<w> cc;
vector<int> answer;
w maxim = {0, 0, 0};
int A;


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

	cin >> s;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '\\'){
			c.push_back(i);
		}else if(s[i] == '/'){
			if(!c.empty()){
				ipt.Beg = c.back();c.pop_back();
				ipt.End = i;
				ipt.siz = ipt.End - ipt.Beg;
				dbug(ipt.Beg)dbug(ipt.End)dbug(ipt.siz)dbugln;
				cc.push_back(ipt);
			}
		}
	}
	sort(cc.begin(), cc.end(), [](w a, w b){return (a.Beg < b.Beg);});
	for(auto i = cc.begin();i != cc.end(); ++i){
		dbug(i->Beg)dbug(i->End)dbug(i->siz)dbugln;
		dbug(maxim.Beg)dbug(maxim.End)dbug(maxim.siz)dbugln;
		if(maxim.End <= i->Beg){
			if(maxim.siz != 0){
				A+=maxim.siz;
				answer.push_back(maxim.siz);
			}
			maxim = *i;
		}else if(maxim.End >= i->End){
			maxim.siz += i->siz;
		}
	}
	if(maxim.siz != 0){
		A+=maxim.siz;
		answer.push_back(maxim.siz);
	}
	cout << A << "\n";
	cout << answer.size();if(answer.size() != 0)cout << " ";
	for(int i = 0; i  < answer.size(); ++i){
		cout << answer[i];
		if(i != answer.size()-1) cout << " ";
	}
	cout << "\n";
	return 0;
}



Measured memory_bytes: 3400
#include<iostream>
#include<cmath>
using namespace std;
long i,n,a,p;
int main()
{
	string s;
	cin>>s;
	n=s.size();
	for(i=p=n-1;~i;i--)if(s[i]=='B')a+=p-i,p--;
	cout<<a<<endl;
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))
count = 0
c = 0

for i in range(N-1):
  if (int(A[i]) + count) > int(A[i+1]):
    count = (int(A[i]) + count) - int(A[i+1])
    c += count
    
  else:
    count = 0
print(c)

Measured memory_bytes: 93888
def solve():
    n, y = list(map(int, input().split()))
    for man in range(n + 1):
        for gosen in range(n - man + 1):
            sen = n - man - gosen
            total = 10000 * man + 5000 * gosen + 1000 * sen
            if total == y:
                return ' '.join([str(man), str(gosen), str(sen)])
    return ' '.join(["-1", "-1", "-1"])


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 3060
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<int> N;
  multimap<int, int> adj;
  
  REP(i, N-1) {
    int a, b;
    cin >> a >> b;
    adj.emplace(a, b);
    adj.emplace(b, a);
  }
  
  vector<int> assign[2], r(N);
  vector<bool> visited(N + 1, false);
  REC(dfs, int node, int color) -> void {
    if (!visited[node]) {
      visited[node] = true;
      assign[color].push_back(node-1);
      for (auto it = adj.lower_bound(node); it != adj.upper_bound(node); ++it)
        dfs(dfs, it->second, !color);
    }
  };
  dfs(dfs, 1, 0);
  
  if (assign[0].size() < assign[1].size())
    swap(assign[0], assign[1]);
  auto it0 = assign[0].begin(), it1 = assign[1].begin();
  int value = 1;
  while (value <= N) {
    if (it0 == assign[0].end()) {
      cout << -1 << endl;
      return;
    }
    r[*it0++] = value;
    value += 3;
  }
  if (assign[0].end() - it0 > assign[1].size()) {
    swap(assign[0], assign[1]);
    swap(it0, it1);
  }
  value = 2;
  while (value <= N) {
    if (it1 == assign[1].end()) {
      cout << -1 << endl;
      return;
    }
    r[*it1++] = value;
    value += 3;
  }
  value = 3;
  while (it0 != assign[0].end()) {
    r[*it0++] = value;
    value += 3;
  } 
  while (it1 != assign[1].end()) {
    r[*it1++] = value;
    value += 3;
  } 


  for (const auto& i : r)
    cout << i << endl;
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 22820
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll ans=0LL;
	cin >>n;
	V a(n);
	cin >> a;
	rep(i, n) { a[i] -= i + 1; }
	sort(all(a));
	int b = a[n / 2];
	rep(i, n) { ans += abs(b - a[i]); }
	cout<<ans<<endl;
}

Measured memory_bytes: 4848
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <map>
#include <string>
#include <cstring>
typedef long long int ll;
using namespace std;

int main() {
	ll N; cin >> N;
	ll ans = (N * (N - 1)) / 2;
	cout << ans << endl;	
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <string>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>myvector;
    int x;
    int i;
    for(i = 0; i < n; i++){
            cin >> x;
            myvector.push_back(x);
    }
    int a = myvector[0];
    int H = 1;
    for(i = 1; i < n; i++){
        if(myvector[i] >= a){
            a = myvector[i];    
            H += 1;
        }
    }
    cout << H;
}

Measured memory_bytes: 256
/******************************************************************************
 
                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
 
*******************************************************************************/
 
#include <stdio.h>

int allzero(unsigned long long a[], int n){
    int i;
    for(i=0; i<n; i++)if(a[i] != 0)return 0;
    return 1;
}

int main()
{
   unsigned long long a[200];
   int n ,cnt=0;
   int i;
   
   scanf("%d",&n);
   for(i=0; i<n; i++){
       scanf("%lld",&a[i]);
   }
   
   while(!allzero(a,n)){
    for(i=0; i<n; i++){
        if(a[i]%2 == 1 || a[i]==0){
            goto END;
        }
        else{
            a[i] /= 2;
        }
    }
    
 
    cnt++;

   }
    
    
    END:
    printf("%d\n",cnt);
    return 0;
}
 
 

Measured memory_bytes: 128
//
// Created by kapildd on 10/5/17.
//
#include <bits/stdc++.h>
#define MAX_X 5010
#define MAX_VAL (1000000009LL)
using namespace std;

long long dfs(int v, vector< vector<int> >& adj, vector<int>& X) {
    vector<long long> dp(MAX_X, MAX_VAL);
    vector<long long> extra(MAX_X, MAX_VAL);
    dp[0] = 0;
    for(int i=0; i<adj[v].size(); i++) {
        int u = adj[v][i];
        long long white = dfs(u, adj, X);
        //if(white==MAX_VAL) continue;
        fill(extra.begin(), extra.end(), MAX_VAL);
        for(int j=0; j<MAX_X-white; j++) {
            extra[j+white] = min(extra[j+white], dp[j]+X[u]);
        }
        for(int j=0; j< MAX_X-X[u]; j++) {
            extra[j+X[u]] = min(extra[j+X[u]], dp[j]+white);
        }
        swap(extra, dp);
    }
    long long min_w = MAX_VAL;
    for(int i=0; i<=X[v]; i++) {
        min_w = min(min_w, dp[i]);
    }
    return min_w;
}

int main() {
    int n;
    cin>>n;
    vector<int> parent(n+1, 0), X(n+1);
    vector< vector<int> > adj(n+1);
    for(int i=2; i<=n; i++) {
        cin>>parent[i];
        adj[parent[i]].push_back(i);
    }
    for(int i=1; i<=n; i++) {
        cin>>X[i];
    }
    string ans = "IMPOSSIBLE";
    long long cval = dfs(1, adj, X);
    if(cval<MAX_VAL)
        ans = "POSSIBLE";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 34028
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

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

int main(void) {
    long long int n;
    long long int mini=LINF;
    long long int total=0;
    long long int now=0;

    cin>>n;
    vector<long long int> a(n+1);
    LFOR(i,1,n){
        cin>>a[i];
        total+=a[i];
    }
    LFOR(i,1,n-1){
       now+=a[i];
       mini=min(mini,abs((total-now)-now));
    }
    cout<<mini<<endl;
}


Measured memory_bytes: 1792
package main

import (
        "fmt"
        //"sort"
)

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

        check := func() {
                for a := 0; a <= N; a++ {
                        for b := 0; b <= (N - a); b++ {
                                c := N - a - b
                                if (a*10000 + b*5000 + c*1000) == Y {
                                        fmt.Println(a, b, c)
                                        return
                                }
                        }
                }
                fmt.Println("-1 -1 -1")
        }
        check()
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
ll N, H;
pair<ll, ll> v[100000 + 10];
ll a[100000 + 10];
ll b[100000 + 10];
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> H;
  ll maxa = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a[i] >> b[i];
    maxa = max(maxa, a[i]);
  }
  sort(b, b + N);
  reverse(b, b + N);
  ll ret = INT_MAX;
  ll psum = 0;
  for (ll i = 1; i <= N ; ++i) {
    H -= b[i - 1];
    if (H <= 0) {
      ret = min(ret, i);
      break;
    }
    ll ct = (H - 1) / maxa + 1;
    ret = min(ret, i + ct);
  }

  cout << ret;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
	
	int i=0,j=0,a,b;
	
	while(1){
	
		scanf("%d %d",&a,&b);
		
		if(a == 0 && b == 0){break;}
		
		while(j != a){
		
			while(i != b){
				printf("#");
				++i;
			}
			printf("\n");
			++j;
			i = 0;
		}
		j = 0;
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
w=input()
abc=["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"]
flag=True
for i in abc:
        if w.count(i)%2==1:
            flag=False
if flag:
    print("Yes")
else:
    print("No")


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

int next_number(char c){
    if (c == 'a'){
        return 0;
    }else if (c == 'b'){
        return 1;
    }else{
        return 2;
    }
}

int main() {
    string Sa, Sb, Sc;
    cin >> Sa >> Sb >> Sc;
    int next = 0; 
    // 0-a 1-b 2-c
    while (true)
    {
        if(next == 0){
            if (Sa.length() == 0){
                cout << 'A' << endl;
                break;
            } 
            next = next_number(Sa[0]);
            Sa.erase(Sa.begin());
        }else if (next == 1){
            if (Sb.length() == 0){
                cout << 'B' << endl;
                break;
            }
            next = next_number(Sb[0]);
            Sb.erase(Sb.begin());
        }else {
            if (Sc.length() == 0){
                cout << 'C' << endl;
                break;
            }
            next = next_number(Sc[0]);
            Sc.erase(Sc.begin());
        }
        // cout << Sa << endl;
        // cout << Sb << endl;
        // cout << Sc << endl;
        // cout << endl;
    }

    return 0;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-15;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;


const int nmax=100000;
double dp[nmax+1];

int main(void){
	dp[0]=0.0;
	dp[1]=1.0;
	for(int i=2;i<=nmax;++i){
		double p=1.0,win=0.5;
		for(int k=1;k<i&&eps<p;++k){
			double cur=p*(1.0-win);
			dp[i]+=cur*(k+dp[max(0,i-1-k)]);
			p*=win,win/=2.0;
		}
		dp[i]+=i*p;
	}

	int n;
	cout.precision(3);
	while(cin >> n){
		if(n==0) break;
 		cout << fixed << dp[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 2012
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;cin>>a>>b;
  int ans=0;
  for(int i=a;i<=b;i++){
    int j=i;
    int c[5];
    for(int k=0;k<5;k++){
      c[k]=j%10;
      j/=10;
    }
    if(c[0]==c[4]&&c[1]==c[3])ans++;
  }
  cout<<ans<<endl;
}

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

int main()
{
    int x, y;
    cin >> x >> y;

    if (y > x) swap(x, y);

    for (; y > 0;) {
        int r = x % y;
        x = y;
        y = r;
    }

    cout << x << endl;

    return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int INF=1e9;
int n;
vector<int> v;

int main(void){
    cin>>n;
    int ans=n;
    for(int i=0;i<=n;i++){
        int t=i;
        int cnt=0;
        while(t>0){
            cnt+=t%6;
            t/=6;
        }
        t=n-i;
        while (t>0){
            cnt+=t%9;
            t/=9;
        }
        ans=min(ans, cnt);
    }
    cout<<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
/*************************************************\
           In the name of almighty ALLAH
                 MD.Faysal Hasan
                Comilla Univesity
\*************************************************/

#include<bits/stdc++.h>
using namespace std;

#define     ikarus_101  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef     long long             ll;
typedef     long double           ld;
typedef     unsigned long long    ull;
typedef     vector<ll>            vll;
typedef     pair<ll,ll>           pll;
typedef     vector<pll>           vpl;
typedef     map<ll,ll>            mll;
typedef     multiset<ll>          msl;
typedef     multimap<ll,ll>       Mll;
using pqboro=priority_queue<ll,vll,less<ll>>;
using pqchoto=priority_queue<ll,vll,greater<ll>>;

#define    all(str)       str.begin(),str.end()
#define    sajo(str)      sort(str.begin(),str.end())
#define    rev(str)       reverse(str.begin(),str.end())
#define    usajo(str)     sort(str.rbegin(),str.rend())
#define    vin(a)         for(auto &it : a) cin>>it
#define    vout(a)        for(auto it:a) cout<<it<<' ';cout<<nn
#define    pb             push_back
#define    eb             emplace_back
#define    mkp(x,y)       make_pair(x,y)
#define    F              first
#define    S              second
#define    yes            cout<<"YES"<<nn
#define    no             cout<<"NO"<<nn
#define    nn             "\n" ///endl
#define    rep(i,n)       for (i=0;i<n;++i )
#define    rep1(i,n)      for (i=1;i<=n;++i )

#define    min3(a,b,c)    min(a,min(b,c))
#define    max3(a,b,c)    max(a,max(b,c))
#define    sqr(x)         ((x)*(x))
#define    pi             2*acos(0.0)
#define    gcd(a,b)       __gcd(a,b)
#define    lcm(a,b)       (a/gcd(a,b))*b
#define    mem(a,b)       memset(a,b,sizeof (a))
#define    dec(x)         cout<<fixed<<setprecision(x)
#define    none(n)         __builtin_popcountll(n)

template < typename T > string toString ( T Number ) { stringstream ss ; ss << Number ; return ss.str() ; }
template < typename T > ll toll ( T str ) { stringstream ss ; ss << str ; ll num ; ss >> num ; return num ; }
ll power(ll n , ll k) { if(k == 0) return 1 ; if(k&1) return n*sqr(power(n,k/2)) ; else return sqr(power(n,k/2)); }

const   int  N   =   2e5+7;
const   int  M   =   1e9+7;
const   ll  inf  =   0x7f7f7f7f7f7f7f7f;
const   int dx[] =   {+1,+2,+2,+1,-1,-2,-2,-1};
const   int dy[] =   {-2,-1,+1,+2,+2,+1,-1,-2};

int main() {//ikarus_101

    ll n,m,i,j,k,x;

    ll d;
    cin>>x>>k>>d;
    x = abs(x);
    ll ct = x/d;
    if(ct >= k)
    {
        cout << x - k * d << endl;
    }
    else
    {
        ll ans;
        if((k-ct)%2)
        {
            ans = (ct+1)*d-x ;
        }
        else {
            ans = x - (d*ct);
        }
        cout << abs(ans) << endl;
    }
















    return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL) root=z;
  else if(z->key < y->key) y->left=z;
  else y->right=z;
}


void inorder(Node u){
  if(u==NIL) return ;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL) return ;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
     if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }

  return 0;
}

Measured memory_bytes: 24040
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
  	cin>>a>>b>>c;
    if(a == 7)
    {
      if(b == 5 && c ==5)
      {  cout<<"YES";
          return 0;
      }
    }
    if(a == 5)
    {
      if((b == 7 && c == 5) || (b == 5 && c == 7))
      {
       	cout<<"YES";
        return 0;
      }
    }
    cout<<"NO";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() 
{

    long int num;
    long int joshi;
    long int buka[200001] = {0};

    scanf("%ld", &num);

    for (int i = 0; i < num-1; ++i){
        scanf("%ld", &joshi);
        buka[joshi-1]++;
    }

    for (int i = 0; i < num; ++i){
        printf("%ld\n", buka[i]);
    }

    return 0;

}



Measured memory_bytes: 3296
#include <stdio.h>

int main ( void )
{
    int delta, sum, i;
    while ( scanf( "%d", &delta ) != EOF )
    {
        sum = 0;
        for ( i = 0; i < 600; i = i + delta )
        {
            sum += i * i * delta;
        }
        printf( "%d\n", sum );
    }
    return 0;
}

Measured memory_bytes: 596