akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n, ans = 0;  cin >> n;
    for(int i = 1; i <= n; i++){
        int x = i, c = 0;
        while(x > 0){
            x /= 10;
            c++;
        }
        ans += (c&1);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int N, A[3][3];
  
  for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){
      cin >> A[i][j] ;
    }
  }
  
  cin >> N;
  
  int B[N];
  
  for (int i = 0; i < N; i++){
    cin >> B[i];
  }
  
  int D[3][3];
  
  for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){
      D[i][j] = 0;
    }
  }

  for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){
      for (int k = 0; k < N; k++){
        if (A[i][j] == B[k]){
          D[i][j] = 1;
        }
      }
    }
  }
  
    
  string ans;
  ans = "No";
  for (int i = 0; i < 3; i++){
    if (D[0][i] * D[1][i] * D[2][i] == 1){
      ans = "Yes";
    }
  }
  for (int i = 0; i < 3; i++){
    if (D[i][0] * D[i][1] * D[i][2] == 1){
      ans = "Yes";
    }
    if (D[0][0] * D[1][1] * D[2][2] == 1){
      ans = "Yes";
    }
    if (D[2][0] * D[1][1] * D[0][2] == 1){
      ans = "Yes";
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  string line[3];
  while(cin>>line[0]>>line[1]>>line[2]){
    REP(i,3){
      int a=0,b=0;
      FOR(j,1,line[i].size()){
        if(line[i][j]=='A') a++;
        else b++;
      }
      if(a-b>0) a++;
      else b++;
      cout<<a<<" "<<b<<endl;
    }
  }
  return 0;
}


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

int main()
{
  int a, b;
  std::cin >> a >> b;
  if((a*b) % 2 == 0) {
    std::cout << "Even" << std::endl;
  } else {
    std::cout << "Odd" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.Vector;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int mod = 1_000_000_007;

		Integer a[] = new Integer[n];
		Vector<Integer> posZero = new Vector<Integer>();
		Vector<Integer> neg = new Vector<Integer>();

		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();

			if(a[i] < 0){
				neg.add(a[i]);
			}
			else{
				posZero.add(a[i]);
			}
		}

		if(n == k){
			long result = 1;

			for(int i = 0; i < n; i++){
				if(a[i] >= 0){
					result = result * a[i] % mod;
				}
				else {
					result = result * (a[i] + mod)%mod;
				}
			}

			System.out.println(result);
			return;
		}



		Collections.sort(posZero, new Comparator<Integer>() {

			@Override
			public int compare(Integer n1, Integer n2) {
				// TODO 自動生成されたメソッド・スタブ
				return Math.abs(n2) - Math.abs(n1);
			}
		});

		Collections.sort(neg, new Comparator<Integer>() {

			@Override
			public int compare(Integer n1, Integer n2) {
				// TODO 自動生成されたメソッド・スタブ
				return Math.abs(n2) - Math.abs(n1);
			}
		});

		if(neg.size() == n && k%2 == 1){
			long result = 1;
			for(int i = 0; i < k; i++){
				result = result * (neg.get(n - i - 1) + mod)%mod;
			}

			System.out.println(result);
			return;
		}

		long result = 1;
		int posIndex = 0;
		int negIndex = 0;
		for(int i = 0; i < k; i++){
			if(i == k - 1 || negIndex >= neg.size() - 1){
				result = result*posZero.get(posIndex)%mod;
				posIndex++;
			}
			else if(posIndex >= posZero.size() - 1){
				result = result*(neg.get(negIndex) + mod)%mod*(neg.get(negIndex + 1) + mod)%mod;
				negIndex += 2;
				i++;
			}
			else {
				long tmp1 = (long)posZero.get(posIndex)*posZero.get(posIndex + 1);
				long tmp2 = (long)neg.get(negIndex)*neg.get(negIndex + 1);

//				System.out.println(tmp1 + " " +tmp2);
				if(tmp1 > tmp2){
					result = result*posZero.get(posIndex)%mod;
					posIndex++;
				}
				else {
					result = result*(neg.get(negIndex) + mod)%mod*(neg.get(negIndex + 1) + mod)%mod;
					negIndex += 2;
					i++;
				}
			}

//			System.out.println("i = "+i+" pos "+posIndex+"  neg "+negIndex+" / "+neg.size());
//			System.out.println(result);
		}

		System.out.println(result);
	}

}


Measured memory_bytes: 57160
#include<iostream>
#include<vector>
#include<map>
#include<stack>
#define FOR(i,a,b) for(int i=(a); i<int(b); ++i)
#define RFOR(i,a,b) for(int i=(b)-1; i>=int(a); --i)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,int(n)+1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(),d.end()
using namespace std;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(int n){
	vector<T> vec;
	rep(i,n){
		T input;
		cin >> input;
		vec.emplace_back(input);
	}
	return vec;
}
using AdjList = vector<vector<int>>;
using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

// Recieve edge(=(int,int)) as an adj list.
AdjList getadj(int N, int M){
	// Initialize all lists of the graph as a empty vector.
	vector<int> init;
	vector<vector<int>> graph(N,init);

	rep(i,M){
		int a, b;
		cin >> a >> b;
		graph[a-1].emplace_back(b-1);
		graph[b-1].emplace_back(a-1);
	}
// rep(i,N)
// 	putv(graph[i]);
	return graph;
}

#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
using namespace std;
long long Manhattan_dist(long long x1, long long y1, long long x2, long long y2){return abs(x1-x2) + abs(y1-y2);}

void Out(bool ans){
	if(ans == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}
void OUT(bool ans){
	if(ans == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}

 unsigned long long gcd(const unsigned long long a, const unsigned long long b){
 	return (b==0) ? a : gcd(b,a%b);
 }
int main(){
	int H,W;
	cin >> H>>W;
	rep(i,W+2)
		cout << '#';
	cout << endl;
	string a;
	rep(i,H){
		cin >> a;
		cout << '#' << a << '#' << endl;
	}
	rep(i,W+2)
		cout << '#';
	cout << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int a,b;
    cin >> a >> b;

    cout << (a+b)%24 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n, q, x;

main(){
	ios::sync_with_stdio(false);
	while(cin >> n >> q){
		vi d(300001);
		REP(i, n){
			cin >> x;
			d[x] = x;
		}
		REP(i, 300000) if(!d[i+1]) d[i+1] = d[i];
		REP(i, q){
			cin >> x;
			int ans = 0;
			for(int j=x-1;j<=300000;j+=x) ans = max(ans, d[j]%x);
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2324
x,y = gets.split(" ").map(&:to_i)
sum = 0
ans = true

if x == 1 && y == 1
    puts 1000000
    ans = false
else
    if x == 1
        sum += 300000
    elsif x == 2
        sum += 200000
    elsif x == 3
        sum += 100000
    end
    
    if y == 1
        sum += 300000
    elsif y == 2
        sum += 200000
    elsif y == 3
        sum += 100000
    end
end

if ans
    puts sum
end


Measured memory_bytes: 1788
from collections import deque

q = deque()

n = int(input().strip())

for _ in range(n):
    cmd = input()
    if cmd == "deleteFirst":
        q.popleft()
    elif cmd == "deleteLast":
        q.pop()
    elif cmd.startswith("insert "):
        v = cmd[7:]
        q.appendleft(v)
    elif cmd.startswith("delete "):
        v = cmd[7:]
        try:
            q.remove(v)
        except ValueError:
            pass
print(" ".join(q))

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

using namespace std;

const long long INF = 1e18L + 5;

int main(){

  int N, W;

  cin >> N >> W;
  
  vector <int> w(N);
  vector <int> v(N);
  
  for(int i=0;i<N;i++){
    cin >> w[i] >> v[i];
  }

  int sum = 0;

  for(int i=0;i<N;i++)
    sum += v[i];

  vector <vector <long long> > dp(N);

  for(int i=0;i<N;i++)
    dp[i].assign(sum+1,INF);

  for(int i=0;i<N;i++)
    dp[i][0] = 0;

  dp[0][v[0]] = w[0];

  for(int i=1;i<N;i++){
    for(int j=0;j<=sum;j++){
      if(j-v[i] >= 0){
        dp[i][j] = min(dp[i-1][j], w[i] + dp[i-1][j-v[i]]);
      }else{
        dp[i][j] = dp[i-1][j];
      }
    }
  }

  long long ans  = 0;

  for(long long i = 0;i<=sum;i++){
    if(dp[N-1][i] <= W)
      ans = max(ans,i);  
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  int N = 1000;
  int out = -1;
  for (int i = 1; i <= N; i ++) {
    if ((i * 8 / 100 == A) && (i / 10 == B)) {
      out = i;
      break;
    }
  }
 
  cout << out << endl;
}


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

struct StCoord
{
  StCoord() : m_nx(0), m_ny(0) { }

  int m_nx;
  int m_ny;
};

void fnInput(vector<StCoord>& rvoCoord)
{
  int nCrdSiz;
  cin >> nCrdSiz;
  rvoCoord.resize(nCrdSiz);

  for (StCoord& roCoord : rvoCoord)
    cin >> roCoord.m_nx >> roCoord.m_ny;
}

double fnAveDistGet(const vector<StCoord>& cnrvoCoord)
{
  vector<vector<double>> vvnDist(cnrvoCoord.size(), vector<double>(cnrvoCoord.size()));
  
  for (int i = 0; i < cnrvoCoord.size(); i++)
    for (int j = 0; j < cnrvoCoord.size(); j++)
      if (i != j)
        vvnDist[i][j] = vvnDist[j][i] =
          sqrt(pow(cnrvoCoord[i].m_nx - cnrvoCoord[j].m_nx, 2.0) +
               pow(cnrvoCoord[i].m_ny - cnrvoCoord[j].m_ny, 2.0)  );

  int nFact = 1;
  for (int n = 1; n < cnrvoCoord.size() + 1; n++)
    nFact *= n;

  double nTotalDist = 0.0;
  vector<int> vnCity(cnrvoCoord.size());
  iota(begin(vnCity), end(vnCity), 0);

  do {
    for (int i = 0; i < cnrvoCoord.size() - 1; i++)
      nTotalDist += vvnDist[ vnCity[i] ][ vnCity[i + 1] ];
  }
  while ( next_permutation(begin(vnCity), end(vnCity)) );

  return nTotalDist / nFact;
}

int main()
{
  vector<StCoord> voCoord;

  fnInput(voCoord);
  cout << fixed << setprecision(10) << fnAveDistGet(voCoord) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
#include<random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const int MOD=1e9+7;

int main(){

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



  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;

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

  vector<ll> r(n+1);

  r[0] = 2;
  r[1] = 1;
  REP2(i,2,n+1){
    r[i] = r[i-1]+r[i-2];
  }

  cout << r[n] << endl;

  return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=1e6+5;
const int mod=998244353;
map<string,int> mp;
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	int n;
	cin>>n;
	string s;
	long long ans=0;
	for(int i=0;i<n;i++){
		cin>>s;
		sort(s.begin(),s.end());
		ans+=mp[s];
		mp[s]++;
	}
	cout<<ans<<'\n';
	return 0;
}

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

int main(){
  string S;
  cin>>S;
  sort(S.begin(),S.end());
  if(S[0]==S[1]&&S[2]==S[3]&&S[0]!=S[2])
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Matrix_Vector_Multiplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] l1 = Console.ReadLine().Split(' ');

            int row = int.Parse(l1[0]);
            int col = int.Parse(l1[1]);

            List<int> nm = new List<int>();
            List<int> m1 = new List<int>();

            for (int i = 0; i < row; i++)
            {
                string[] temp = Console.ReadLine().Split(' ');
                for (int j = 0; j < temp.Length; j++)
                {
                    nm.Add(int.Parse(temp[j]));
                }
            }

            for (int i = 0; i < col; i++)
            {
                m1.Add(int.Parse(Console.ReadLine()));
            }

            List<int> results = new List<int>();

            for (int i = 0; i < row; i++)
            {
                int sum = 0;

                for (int j = 0; j < col; j++)
                {
                    sum += m1[j] * nm[j+col*i];
                }

                results.Add(sum);
            }

            foreach (int item in results)
            {
                Console.WriteLine(item);
            }
        }
    }
}



Measured memory_bytes: 17984
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const int INF = 2147483647;

//Segment tree min range query and single update
const int NIL = -1;

struct Node {
    int minv;
    int lchild = NIL;
    int rchild = NIL;
    Node(int minv = INF) : minv(minv) {}
};

struct SegmentTree {
    vector<Node> heap;
    int rootId, lRange, rRange;
 
    SegmentTree(int lRange, int rRange) : lRange(lRange), rRange(rRange) {
        rootId = 0;
        heap.assign(rootId + 1, Node());
    }
    
    void update(int q, int v) {
        update(rootId, lRange, rRange, q, v);
    }

    void ensureChidren(int nodeId){
        if (heap[nodeId].lchild == NIL) {
            int id = newNode();
            heap[nodeId].lchild = id;
        }
        if (heap[nodeId].rchild == NIL) {
            int id = newNode();
            heap[nodeId].rchild = id;
        }
    }
    
    void update(int nodeId, int l, int r, int q, int v) {
        if (q < l || q > r) {
            return;
        }
        if (l == r) {
            heap[nodeId].minv = v;
            return;
        }
        int m = l + (r - l)/2;
        
        ensureChidren(nodeId);
        
        update(heap[nodeId].lchild, l, m, q, v);
        update(heap[nodeId].rchild, m + 1, r, q, v);
             
        pullUp(nodeId); 
    }
    
    int query(int ql , int qr) {
        return query(rootId, lRange, rRange, ql, qr);
    }
    
    int query(int nodeId, int l, int r, int ql , int qr) {
        if (nodeId == NIL || ql > r || qr < l) {
            return INF;
        }
        //printf("%d %d %d\n", nodeId, l, r);
        Node node = heap[nodeId];
        
        if (ql <= l && r <= qr) {
            return node.minv;
        }
        int m = l + (r - l) / 2;
        return min(query(node.lchild, l, m, ql, qr), 
                query(node.rchild, m + 1, r, ql, qr));
    }
    
    void pullUp(int nodeId) {
        Node node = heap[nodeId];
        heap[nodeId].minv = min(heap[heap[nodeId].lchild].minv, heap[heap[nodeId].rchild].minv);
    }
    
    int newNode() {
        heap.push_back(Node());
        return heap.size() - 1;    
    }   
};


int main() {
    int n, q;
    cin >> n >> q;
    
    SegmentTree sg = SegmentTree(0, n - 1);
    
    for (int i = 0; i < q; i++) {
        int cmd;
        cin >> cmd;
        if (cmd == 0) {
            int pos, v;
            cin >> pos >> v;
            sg.update(pos, v);
        }
        else {
            int ql, qr;
            cin >> ql >> qr;
            cout << sg.query(ql, qr) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5988
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    vector<int> cnt(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        cnt[A[i] - 1]++;
    }
    priority_queue<int,vector<int>, greater<int>> q;
    for(int i = 0; i < N; i++){
        if(cnt[i] > 0) q.push(cnt[i]);
    }
    int ans = 0;
    while(q.size() > K){
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 5772
<?php
	$n = intval(fgets(STDIN)) - 1;
	$val = explode(" ",str_replace("\n","",fgets(STDIN)));
	
	$ans = array();
	$f = 0;
	$b = 0;
	for($i = $n;$i >= 0;$i--){
		if(($n - $i) % 2 == 0){
			$ans[$f++] = $val[$i];
		}else{
			$ans[$n - $b++] = $val[$i];
		}
	}
	
	for($i = 0;$i <= $n;$i++){
		if($i == 0) echo $ans[$i];
		else        echo ' '.$ans[$i];
	}
?>

Measured memory_bytes: 60628
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ans = s;
        
        if(ans.length()==3){
            ans = ""+s.charAt(2) + s.charAt(1) + s.charAt(0);
        }
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 39076
/*
Original problem: https://atcoder.jp/contests/dp/tasks/dp_a
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)


#define PII pair<int,int>
#define PLL pair<ll,ll>

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

namespace SOLVE {
    void main() {
        // dp[i] is min(dp[i-1] + c, dp[i-2] + c)
        int n;
        cin >> n;
        VI A(n);
        VI dp(n); // dp[i] is the cost to land on i

        REP(i, 0, n) {
            cin >> A[i];
        }

        dp[0] = 0;
        dp[1] = abs(A[1] - A[0]);

        REP(i, 2, n) {
            dp[i] = min(dp[i - 1] + abs(A[i - 1] - A[i]), dp[i - 2] + abs(A[i - 2] - A[i]));
        }

        cout << dp[n - 1] << endl;

    }
}


signed main() {
	int t;
	t = 1;
	// cin >> t;
	while (t--) {
		SOLVE::main();
	}

	return 0;
}

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

int main(){
  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r;
  if(x > 0 && y > 0){
   if(x+r<=W&&y+r<=H&&x>=r&&y>=r){
     cout << "Yes" << endl;
     return 0;
   }
  }
  cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 3112
#include<stdio.h>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int num[100005],a[100005];
void init(int x)
{
    if(x%2==0)
        for(int i=1;i<=x;i+=2) 
        {
            a[i]=i;
            a[i+1]=a[i];
        }
    else
        for(int i=2;i<=x;i+=2)
        {
            a[i]=i;
            a[i+1]=a[i];
        }

}
int main()
{
    int n,k=1;
    scanf("%d",&n);
    init(n);
    for(int i=1;i<=n;i++)
        scanf("%d",&num[i]);
    sort(num+1,num+1+n);
    for(int i=1;i<=n;i++)
        if(a[i]!=num[i])
        {
            printf("0");
            return 0; 
        }

    long long ans=1;
    n/=2;
    while(n--)
        ans=ans*2%mod;
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 896
import math
N = int(input())

div_num = []
for i in range(1,int(math.sqrt(N))+1):
    if N%i== 0:
        div_num.append((i,N//i))
if div_num == []:
    div_num = [(1,N)]
min_div_num = 10**12
for i in div_num:
    min_div_num = min(sum(i),min_div_num)
print(min_div_num-2)

Measured memory_bytes: 9196
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w;
    cin>>h>>w;
    if(h==1||w==1){
        cout<<1<<endl;
        return 0;
    }
    ll a=(w+1)/2;
    ll b=w/2;
    ll c=(h+1)/2;
    ll d=h/2;
    cout<<a*c+b*d<<endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,S;
int X[111111],P[111111];

signed main(){
    cin>>N>>S;
    rep(i,N)cin>>X[i]>>P[i];

    int l=0,r=N-1;
    vint latte;
    while(l<=r){
        if(X[l]>S){
            latte.pb(X[r]);
            break;
        }
        if(X[r]<S){
            latte.pb(X[l]);
            break;
        }
        if(P[l]>=P[r]){
            latte.pb(X[r]);
            P[l]+=P[r];
            r--;
        }
        else{
            latte.pb(X[l]);
            P[r]+=P[l];
            l++;
        }
    }
    latte.pb(S);
    int ans=0;
    rep(i,latte.size()-1)ans+=abs(latte[i]-latte[i+1]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2936
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int dm = 1 << 21;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	char S[100001];
	scanf("%s", S);
	int N = strlen(S);
	int saigo = N;
	int kaisuu = (N - 2) / 2;
	int base = 1;
	if (S[0] == '0' || S[N - 1] == '1' || S[N - 2] == '0') {
		printf("-1");
	}
	else {
		rep1(i, kaisuu) {
			char c = S[i];
			if (c != S[N - i - 2]) {
				printf("-1");
				return 0;
			}
			base += (S[i] == '1');
		}

		putint(base);
		putint(base + 1);
		int k = base + 2;
		rep1(i, kaisuu) {
			if (S[i] == '0') {
				putint(base);
				putint(k++);
			}
			else {
				putint(base--);
				putint(base);
			}
		}
		for (int i = kaisuu + 3; i <= N; i++) {
			*di++ = '1';
			*di++ = '\n';
			putint(i);
		}
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 2176
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
using namespace std;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <bitset>

int main() {
	int N;
	cin >> N;

	vector<int> a(N);
	rep(i, N) {
		cin >> a.at(i);	
	}

	sort(a.rbegin(), a.rend());

	int A = 0, B = 0;
	rep(i, N) {
		if (i % 2 == 0) {
			A += a.at(i);
		}
		else {
			B += a.at(i);
		}
	}

	cout << A - B << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define REP(n) for(int i = 0; i < n; i++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
template<class X=int>inline X min(X a,X b,X c){return min(min(a,b),c);}
template<class X=int>inline X min(X a,X b,X c,X d){return min(min(a,b,c),d);}
template<class X=int> inline X max(X a,X b,X c){return max(max(a,b),c);}
template<class X=int> inline X max(X a,X b,X c,X d){return max(max(a,b,c),d);}
template<class X=int> inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int> inline X len(X s,X e){return (e-s+1);}
const int MOD = 1e9 + 7;
const int INF = 987654321;
const bool TESTCASES = 0;
const bool CODEJAM = 0;

void solve() {
	int n, m;
	cin >> n >> m;
	vector<string> grid(n);
	vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
	REP(n) cin >> grid[i];
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(i == 1 and j == 1)
				dp[i][j] = 1;
			else if(grid[i - 1][j - 1] == '#')
				dp[i][j] = 0;
			else
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1])%MOD;
		}
	}
	cout << dp[n][m] << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int T = 1;
	if(TESTCASES) cin >> T;
	for(int t = 1; t <= T; t++) {
		if(CODEJAM) cout << "Case #" << t << ": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 12484
S = input()
OK = False
if S=='KIHBR':
    OK = True
elif S=='KIHBRA':
    OK = True
elif S=='KIHBAR':
    OK = True
elif S=='KIHBARA':
    OK = True
elif S=='KIHABR':
    OK = True
elif S=='KIHABRA':
    OK = True
elif S=='KIHABAR':
    OK = True
elif S=='KIHABARA':
    OK = True
elif S=='AKIHBR':
    OK = True
elif S=='AKIHBRA':
    OK = True
elif S=='AKIHBAR':
    OK = True
elif S=='AKIHBARA':
    OK = True
elif S=='AKIHABR':
    OK = True
elif S=='AKIHABRA':
    OK = True
elif S=='AKIHABAR':
    OK = True
elif S=='AKIHABARA':
    OK = True
print('YES' if OK else 'NO')


Measured memory_bytes: 38384
/***** TheAnshul *****/

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  100005
ll dp[N][3];
ll a[N][3],n;
ll fun(ll i,ll j)
{
	if(i==n+1)
		return 0;
	if(dp[i][j]!=-1)
	{
		return dp[i][j];
	}
	ll vl=0;
	rep(k,0,3)
	{
		if(k==j)
		{
			continue;
		}
		vl=max(fun(i+1,k)+a[i][k],vl);
	}
	// what_is(i);
	// what_is(j);
	// what_is(vl);
	// what_is(n);
	dp[i][j]=vl;
	return vl;
}
void solve()
{
	// ll n;
	cin>>n;
	rep(i,1,n+1)
	{
		rep(j,0,3)
		{
			dp[i][j]=-1;
		}
	}
	rep(i,1,n+1)
	{
		rep(j,0,3)
		cin>>a[i][j];
		// cin>>a[i]>>b[i]>>c[i];
	}
	cout<<max(fun(2,0)+a[1][0],max(fun(2,1)+a[1][1],fun(2,2)+a[1][2]));
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	time
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int a;

int main()
{
    cin >> a;
    cout << 3 * a * a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep2(i,n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
template <class T>
using Grid = vector<vector<T>>;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    int cnt = 0;
    for (int i = 1; i < n-1; i++) 
    {
        if (max({v[i - 1], v[i], v[i + 1]}) != v[i] &&
            min({v[i - 1], v[i], v[i + 1]}) != v[i])
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3536
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	char c;
	cin>>c;
	if(c>='a')cout<<'a';
	else cout<<'A';
	return 0;
}



Measured memory_bytes: 3604
import sys

alpha = 'abcdefghijklmnopqrstuvwxyz'
dic = {c: 0 for c in alpha}
s = ''.join(sys.stdin.readlines()).lower()

for c in s:
    if c in alpha:
        dic[c] += 1

for c in alpha:
    print(f'{c} : {dic[c]}')



Measured memory_bytes: 5584
from functools import reduce
from fractions import gcd
import sys
input = sys.stdin.readline


def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))

    B = [abs(A[i]-X) for i in range(N)]
    print(reduce(gcd, B))


if __name__ == '__main__':
    main()

Measured memory_bytes: 16248
# 入力　宿泊日数、割引前日数、宿泊費、割引宿泊費
days = int(input())
k = int(input())
fee1 = int(input())
fee2 = int(input())

# 総宿泊費の計算
if days <= k :
    all_fee = days * fee1
else :
    all_fee = k * fee1 + (days - k) * fee2

# 出力
print(all_fee)


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main() {
    int n;
    int p[4+1][3+1][10+1] = {0};
    int b, f, r, v;
    
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> b >> f >> r >> v;
        p[b][f][r] += v;
    }
    
    for (int i = 1; i <= 4; i++) {
        if (i != 1) cout << "####################" << endl;
        for (int j = 1; j <= 3; j++) {
            for (int k = 1; k <= 10; k++) {
                cout << " " << p[i][j][k];
            }
            cout << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3088
fun main(args: Array<String>) {
    val k = readLine()!!.toInt()

    var answer = 0L

    for (h in 1..k) {
        for (i in 1..k) {
            val gcdhi = gcd(h,i)
            for (j in 1..k) {
                answer += gcd(gcdhi, j)
            }
        }
    }
    println(answer)
}

fun gcd(a: Int, b: Int): Int {
    if (a==1 || b== 1) return 1
    if (a < b) return gcd(b, a)
    if (b == 0) return a
    return gcd(b, a % b)
}

Measured memory_bytes: 34792
h,w = map(int,input().split())
a = [input() for i in range(h)]
removeh = []
removew = []
for i in range(h):
    if not "#" in a[i]:
        removeh.append(i)
for i in range(w):
    flag = 0
    for j in range(h):
        if a[j][i] == "#":
            flag = 1
            break
    if flag == 0:
        removew.append(i)

for i in range(h):
    if removeh.count(i) == 0:
        buf = ""
        for j in list(set(range(w)) - set(removew)):
            buf += a[i][j]
        print(buf)

Measured memory_bytes: 3064
def diff(a,b):
    output = 0
    for i in range(N):
        if a[i] != b[i]:
            output += 1
    return output

S = input()
N = len(S)

S1,S2 = "",""
for i in range(N):
    if i % 2 == 0:
        S1 += "0"
        S2 += "1"
    else:
        S1 += "1"
        S2 += "0"

ans = min(diff(S,S1),diff(S,S2))
print(ans)


Measured memory_bytes: 3316
# A - Two Abbreviations
from fractions import gcd

N,M = map(int,input().split())
S = input()
T = input()

GCD = gcd(len(S),len(T))
LCM = len(S) * len(T) // GCD
ans = LCM

for i in range(GCD):
    if S[i*len(S)//GCD]!=T[i*len(T)//GCD]:
        ans = -1
        break

print(ans)

Measured memory_bytes: 5348
#include<bits/stdc++.h>
#define SIZE 10005
using namespace std;

char str[SIZE];

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  int a = 0, b = 0, ba = 0;
  for (int i = 0; i < n; i++) {
    cin >> str;
    int L = strlen(str);
	for (int j = 0; j + 1 < L; j++) {
	  if (str[j] == 'A' && str[j + 1] == 'B') cnt++;
	}
	if (str[0] == 'B') b++;
	if (str[L - 1] == 'A') a++;
	if (str[0] == 'B' && str[L - 1] == 'A') ba++;
  }
  cnt += min(a,b);
  if (a == ba && b == ba && b > 0) cnt--;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
a=gets.chomp.split.map(&:to_i)
b=gets.chomp.split.map(&:to_i)
c=gets.chomp.split.map(&:to_i)
d=[]
k=0
f=b.sort
g=c.sort
d.push(f[0]+g[0])
a[2].times do 
    n=gets.chomp.split.map(&:to_i)
    d.push(b[n[0]-1]+c[n[1]-1]-n[2])
end
d=d.sort
puts d[0]

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(){
  int a, b, c, x, y; cin >> a >> b >> c >> x >> y;
  int ans = a*x + b*y;
  if(a+b > c*2){
    ans = min(x,y)*c*2;
    if(x-y>0 && a<=c*2) ans += (x-y)*a;
    else if(x-y>0 && a>c*2) ans += (x-y)*c*2;
    else if(x-y<0 && b<=c*2) ans += (y-x)*b;
    else if(x-y<0 && b>c*2) ans += (y-x)*c*2;
  }
  cout << ans;
  
  return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

struct P {
   int y, x;
};

int H, W, N;
int sy, sx;
char B[1111][1111];
int dist[1111][1111];
P c[11];
const int INF = 1e8;

void print() {
   rep (i, H) {
      rep (j, W) {
         if (dist[i][j] == INF) {
            printf("%3c", 'I');
         } else {
            printf("%3d", dist[i][j]);
         }
      }
      puts("");
   }
}

int bfs(int y, int x, int ty, int tx) {
   rep (i, H) { rep (j, W) { dist[i][j] = INF; } }
   queue<P> que;
   que.push(P{y, x});
   dist[y][x] = 0;
   while (que.size()) {
      P p = que.front(); que.pop();
      if (p.y == ty && p.x == tx) break;
      rep (i, 4) {
         int ny = p.y + dy[i], nx = p.x + dx[i];
         if (ny < 0 || ny >= H || nx < 0 || nx >= W || B[ny][nx] == 'X' || dist[ny][nx] != INF) continue;
         que.push(P{ny, nx});
         dist[ny][nx] = dist[p.y][p.x] + 1;
      }
   }
   return dist[ty][tx];
}

int main() {
   cin >> H >> W >> N;
   rep (i, H) {
      rep (j, W) {
         cin >> B[i][j];
         if (isdigit(B[i][j])) {
            c[B[i][j]-'0'] = P{i, j};
         }
         if (B[i][j] == 'S') {
            sy = i, sx = j;
         }
      }
   }
   c[0] = P{sy, sx};

   ll sum = 0;
   for (int i = 1; i <= N; i++) {
      // printf("(%d, %d) - (%d, %d)\n", c[i].y, c[i].x, c[i-1].y, c[i-1].x);
      // sum += abs(dist[c[i].y][c[i].x] - dist[c[i-1].y][c[i-1].x]);
      int y = c[i-1].y, x = c[i-1].x;
      int ny = c[i].y, nx = c[i].x;
      sum += bfs(y, x, ny, nx);
   }
   cout << sum << endl;

   return 0;
}



Measured memory_bytes: 8520
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    vector<P> v(n+1, P(0, 0));
    for(int i=0; i<n; i++){
        int a; cin>>a;
        v[i] = P(a, i);
    }

    sort(v.begin(), v.end(), greater<P>());

    int idmin = inf;
    vector<ll> ans(n, 0);
    for(int i=0; i<n; i++){
        int ca, cid; tie(ca, cid) = v[i];
        int na, nid; tie(na, nid) = v[i+1];

        chmin(idmin, cid);

        if(ca != na){
            ans[idmin] += (ll)(i + 1) * (ca - na);
        }
    }

    for(int i=0; i<n; i++){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int as[80][80];
int bs[80][80];
int ds[81][81];
bool ss[81][81][6401] = {};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int h, w; cin >> h >> w;
	FOR_LT(i, 0, h) {
		FOR_LT(j, 0, w) {
			int a; cin >> a;
			as[i][j] = a;
		}
	};
	FOR_LT(i, 0, h) {
		FOR_LT(j, 0, w) {
			int b; cin >> b;
			bs[i][j] = b;
		}
	}

	FOR_LT(i, 0, h) {
		FOR_LT(j, 0, w) {
			ds[i + 1][j + 1] = abs(as[i][j] - bs[i][j]);
		}
	}

	FOR_LE(i, 1, h) {
		FOR_LE(k, 0, 6400) {
			ss[i][0][k] = false;
		}
	}
	FOR_LE(i, 1, w) {
		FOR_LE(k, 0, 6400) {
			ss[0][i][k] = false;
		}
	}
	ss[1][0][0] = true;
	ss[0][1][0] = true;

	FOR_LE(i, 1, h) {
		FOR_LE(j, 1, w) {
			FOR_LE(k, 0, 6400) {
				if (ss[i][j - 1][k] || ss[i - 1][j][k]) {
					int d = ds[i][j];
					if (k + d <= 6400) ss[i][j][k + d] = true;
					ss[i][j][abs(k - d)] = true;
				}
			}
		}
	}

	FOR_LE(k, 0, 80) {
		if (ss[h][w][k]) {
			cout << k << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 41216
#[allow(unused_imports)]
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let abcd = read_vec::<u64>();
    let a = abcd[0];
    let b = abcd[1];
    let c = abcd[2];
    let d = abcd[3];
    


    let answer = solve(a, b, c, d);
    println!("{}", answer);
}

fn solve(a: u64, b:u64, c:u64, d:u64) -> u64 {
    let total = b - a + 1;
    let cc = b / c  - (a - 1) / c;
    let dd = b / d - (a - 1) / d;
    
    let l = lcm(c, d);
    let ll = b / l - (a - 1) / l;

    //println!("{}, {}, {}, {}", total, cc, dd, ll);
    
    return total - cc - dd + ll;
}

fn lcm(a: u64, b: u64) -> u64 {
    return a * b / gcd(a, b)
}

fn gcd(a: u64, b: u64) -> u64 {
    let mut m : u64 = a;
    let mut n : u64 = b;
    if m < n {
        m = b;
        n = a;
    }

    loop {
        let r = m % n;
        if r == 0 {
            return n;
        }
        m = n;
        n = r;    
    }
}

Measured memory_bytes: 2096
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
typedef long long int ll;
int main(){
    int N;
    cin>>N;
    vector<int>A(N);
    rep(i,N){
        cin>>A.at(i);
    }
    map<int,int>ma;
    for(auto x:A){
        ma[x]++;
    }
    set<int>s;
    int count=0;
    for(auto x:ma){
        if(x.second%2!=0){
            count++;
        }
    }
    cout<<count<<endl;




    return 0;
}

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

int main(){
  int N, K,sum;
  cin >> N >>K;
  sum = 1;
  for (int i=0;i <N;i++){
    if (sum <= K){
      sum *= 2;
    }
    else{
      sum += K;
    }
  }
  cout << sum <<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){
   
    int n;
	cin >> n;

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

	vll s;
	s.pb(0);
	s.pb(0);
	s.pb(0);

	int ans = 1;

	rep(i,n){
		int cnt = 0;
		rep(j,3)if(s[j] == a[i])cnt++;
		ans *= cnt;
		ans %=MOD;
		rep(j,3){
			if(s[j] == a[i]){
				s[j]++;
				break;
			}
		}
	}
	cout << ans << endl;
	
	
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://sumitrust2019.contest.atcoder.jp/tasks/sumitb2019_b

Measured memory_bytes: 1024