akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n';

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n) { int a; cin >> a; p[i] = a - 1;}
	int count1 = 0;
	
	rep(i, n - 1) {
		if (p[i] == i) {
			int tmp = p[i];
			p[i] = p[i + 1];
			p[i + 1] = tmp;
			++count1;
		}
	}
	if (p[n - 1] == n - 1) ++count1;
	cout << count1;
}



Measured memory_bytes: 640
/*
[m-solutions2019] C - Best-of-(2n-1)
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 100000;
const ll MOD = 1e9 + 7;

int N, A, B, C;
ll pa[2 * MAX_N + 1], pb[2 * MAX_N + 1], ph[2 * MAX_N + 1];
ll fact[2 * MAX_N + 1], finv[2 * MAX_N + 1], inv[2 * MAX_N + 1];

ll solve() {
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i <= 2 * MAX_N; i++) {
        fact[i] = (fact[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;
    }

    pa[0] = 1;
    pb[0] = 1;
    ph[0] = 1;
    for (int i = 1; i <= 2 * N; i++) {
        pa[i] = (pa[i - 1] * A) % MOD;
        pb[i] = (pb[i - 1] * B) % MOD;
        ph[i] = (ph[i - 1] * inv[100 - C]) % MOD;
    }

    ll ans = 0;
    for (int i = N; i <= 2 * N - 1; i++) {
        ll tmp = (fact[i - 1] * (finv[N - 1] * finv[i - N] % MOD)) % MOD;
        (tmp *= (((pa[N] * pb[i - N] % MOD + pa[i - N] * pb[N] % MOD) % MOD) *
                 i * 100) %
                MOD) %= MOD;
        (tmp *= ph[i + 1] % MOD) %= MOD;
        (ans += tmp) %= MOD;
    }

    return ans;
}

int main() {
    cin >> N >> A >> B >> C;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 9600
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        string s = ReadLine();
        int k = int.Parse(ReadLine());

        var list = new List<String>();
        for (int i = 0; i < s.Length; i++)
        {
            int len = 0;
            if (s.Length - i < 5) {
                len = s.Length - i;
            } else {
                len = 5;
            }
            for (int j = 1; j <= len; j++) {
                list.Add(s.Substring(i, j));
            }
        }

        list = list.Distinct().OrderBy(b => b).ToList();
        WriteLine(list[k - 1]);
    }
}

Measured memory_bytes: 15840
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int main()
{
    while(true)
    {
        int n, y;
        
        std::cin >> n;
        if (n == 0) {
            break;
        }
        
        std::cin >> y;
        
        struct Bank {
            int b, r, t;
            float motori;
        };
        
        constexpr int TANRI = 1, HUKURI = 2;
        std::vector<Bank> banks(n);
        for (int i = 0; i < n; i++) {
            Bank& bank = banks[i]; 
            std::cin >> bank.b >> bank.r >> bank.t;
            if (bank.t == TANRI) {
               bank.motori = 1 + y * (bank.r / 100.0f);
            } else if (bank.t == HUKURI){
                bank.motori = std::pow((1 + bank.r / 100.0f), y);
            }
        }
        
        auto it = std::max_element(banks.begin(), banks.end(), [](const Bank& lhs, const Bank& rhs){
            return lhs.motori < rhs.motori;
        });
        
        std::cout << it->b << std::endl;
    }
    
    return 0;
}




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

using namespace std;
using llint = long long int;

int n, m;
vector<vector<int>> graph;

vector<bool> marked;
vector<int> nodes;
void mark(int node)
{
  marked[node] = true;
  nodes.push_back(node);
  for (int next : graph[node])
  {
    if (!marked[next])
    {
      mark(next);
    }
  }
}

int main()
{
  cin >> n >> m;
  vector<int> vec;
  vec.resize(n);
  graph.resize(n);
  marked.resize(n);
  for (int i = 0; i < n; i++)
  {
    int x;
    cin >> x;
    vec[i] = x - 1;
  }

  for (int i = 0; i < m; i++)
  {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }

  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    if (!marked[i])
    {
      nodes.clear();
      mark(i);
      set<int> connected(nodes.begin(), nodes.end());
      for (int from : connected)
      {
        if (connected.count(vec[from]))
        {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 14200
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> parse(string str) {
	vector<int> ret; int t = 0; str += ' ';
	for (int i = 0; i < str.size(); i++) {
		if (str[i] == ' ') ret.push_back(t), t = 0;
		else t = t * 10 + str[i] - 48;
	}
	return ret;
}
int bitcount(int x) {
	int ret = 0;
	for (int i = 0; i < 31; i++) {
		if (x & (1 << i)) ret++;
	}
	return ret;
}
string s; double dp[65536][16];
int main() {
	while (s = "", getline(cin, s)) {
		vector<int> u = parse(s);
		vector<int> v(u.begin() + 1, u.end());
		int n = v.size();
		for (int i = 0; i < (1 << n); i++) {
			for (int j = 0; j < n; j++) dp[i][j] = 999999999.9L;
		}
		for (int i = 0; i < n; i++) dp[1 << i][i] = v[i];
		for (int i = 1; i < (1 << n); i++) {
			if (bitcount(i) <= 1) continue;
			for (int j = 0; j < n; j++) {
				if (!(i & (1 << j))) continue;
				dp[i][j] = 999999999.9L;
				for (int k = 0; k < n; k++) {
					if ((i & (1 << k)) && (j != k)) {
						double d1 = v[j] + v[k], d2 = abs(v[j] - v[k]);
						dp[i][j] = min(dp[i][j], dp[i - (1 << j)][k] + sqrt(d1 * d1 - d2 * d2));
					}
				}
			}
		}
		double ret = 999999999.9L;
		for (int i = 0; i < n; i++) ret = min(ret, dp[(1 << n) - 1][i] + v[i]);
		cout << (ret <= u[0] + 1e-10 ? "OK" : "NA") << endl;
	}
}

Measured memory_bytes: 3656
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    string N;
    int K;
    cin >> N >> K;
    int L=N.length();
    lint dp[L+1][4][2]={};
    dp[0][0][0]=1;
    rep(i,L) rep(j,4) rep(k,2){
        int digit=N[i]-'0';
        rep(d,10){
            int i2=i+1,j2=j,k2=k;
            if(d!=0) j2++;
            if(j2>K) continue;
            if(k==0){
                if(d>digit) continue;
                if(d<digit) k2=1;
            }
            dp[i2][j2][k2]+=dp[i][j][k];
        }
    }
    cout << dp[L][K][0]+dp[L][K][1] << endl;
}

Measured memory_bytes: 256
N, M = (map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

C = 1
A.sort(reverse=True)
B.sort(reverse=True)

aloop = 0
bloop = 0

if len(set(A)) != len(A) or len(set(B)) != len(B):
    C = 0

else:
    for k in range(N * M, 0, -1):
        if aloop < N and bloop < M and k == A[aloop] and k == B[bloop]:
            aloop += 1
            bloop += 1
        elif aloop < N and k == A[aloop]:
            C *= bloop
            aloop += 1
        elif bloop < M and k == B[bloop]:
            C *= aloop
            bloop += 1
        else:
            C *= (aloop * bloop - (N * M - k))

        C = C % (10**9+7)
print(C)


Measured memory_bytes: 3188
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	s=input().rstrip().decode()

	n=len(s)

	for i in range(2,n,2):
		#print(s[:(n-i)//2])
		if s[:(n-i)//2]==s[(n-i)//2:n-i]:
			print(n-i)
			exit()













if __name__ == "__main__":
	main()


Measured memory_bytes: 62088
#include <cstdio>
#include <algorithm>
#include <cctype>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
struct Edge
{
    int next, to;
    Edge(int next = 0, int to = 0):next(next), to(to) {};
}edge[N<<1];
int tot = 1, head[N];
void _add(int x, int y) { edge[++tot] = Edge(head[x], y), head[x] = tot; }
void add(int x, int y) { _add(x, y), _add(y, x); }
int n, m, t, d[N], fa[N], dfn[N], top[N], son[N], s[N], out[N];
void dfs(int x)
{
    d[x] = d[fa[x]]+1, s[x] = 1;
    for(int i = head[x]; i; i = edge[i].next)
    {
        int y = edge[i].to; if(y == fa[x]) continue;
        if(d[y]) out[i>>1] = 1;
        else fa[y] = x, dfs(y), s[x] += s[y], son[x] = s[son[x]]>s[y]?son[x]:y;
    }
}
void dfs(int x, int topf)
{
    top[x] = topf, s[x] = 0, dfn[++t] = x; 
    if(son[x]) dfs(son[x], topf);
    for(int i = head[x]; i; i = edge[i].next)
    {
        int y = edge[i].to; 
        if(y == fa[x]||y == son[x]||out[i>>1]) continue;
        dfs(y, y);
    }
}
int lca(int x, int y)
{
    for( ; top[x] != top[y]; x = fa[top[x]])
        if(d[top[x]] < d[top[y]]) swap(x, y);
    return d[x]<d[y]?x:y;
}
int main()
{
    n = read(), m = read();
    for(int i = 1, x, y; i <= m; ++i) x = read(), y = read(), add(x, y);
    for(int i = 1; i <= n; ++i) if(!d[i]) dfs(i);
    for(int i = 1; i <= n; ++i) if(!top[i]) dfs(i, i);
    for(int i = 1, x, y; i <= m; ++i)
        if(out[i]) x = edge[i<<1].to, y = edge[i<<1|1].to, s[x] ^= 1, s[y] ^= 1;
    for(int i = n; i; --i) s[fa[dfn[i]]] ^= s[dfn[i]];
    for(int i = 1; i <= n; ++i)
        if((~s[i]&1)&&fa[i]) return puts("NO"), 0;
    puts("YES");
    return 0;
}

/*
10 9
1 2
1 2
3 4
3 4
5 6
5 6
7 8
7 8
9 10
*/

Measured memory_bytes: 6400
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


n = inp()
a = [0]

for i in range(n):
    a.append(inp())

i = 1
c = 1

while a[i] != 2:
    if a[i] == -1:
        c = -1
        break
    c += 1
    temp = i
    i = a[i]
    a[temp] = -1
print(c)


Measured memory_bytes: 7080
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    AB, BC, CA = map(int, input().split())
    print(AB * BC // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x ,ans = 20000000;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n,vector<int>(m));
  for (int i = 0; i < n; i++)
  {
    cin >> c[i];
    for (int j = 0; j < m; j++)
    {
      cin >> a[i][j];
    }
  }
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    int anss = 0;
    bitset<12> s(tmp);
    vector<int> d(m);
    for (int i = 0; i < n; i++)
    {
      if (s.test(i))
      {
        for (int j = 0; j < m; j++)
        {
          d[j] += a[i][j];
        }
        anss += c[i];
      }
    }
    bool test = true;
    for (int i = 0; i < m; i++)
    {
      if (d[i] < x)
      {
        test = false;
      }
    }
    if (test)
    {
      ans = min(ans, anss);
    }
  }
  if (ans == 20000000)
  {
    cout << -1 <<endl;
  }else
  {
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int a[100010],n;
int main(){
	int i,j=0,k=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i];
		k+=abs(a[i]-j);
		j=a[i];
	}
	a[0]=a[i]=0;k+=abs(j);
	for(i=1;i<=n;i++){
		if(a[i-1]<=a[i+1]){
			if(a[i]>=a[i-1]&&a[i]<=a[i+1])cout<<k<<endl;
			else if(a[i]<a[i-1]) cout<<k-2*abs(a[i]-a[i-1])<<endl;
			else cout<<k-2*abs(a[i]-a[i+1])<<endl;
		}
		else{
			if(a[i]>=a[i+1]&&a[i]<=a[i-1])cout<<k<<endl;
			else if(a[i]<a[i+1])cout<<k-2*abs(a[i]-a[i+1])<<endl;
			else cout<<k-2*abs(a[i]-a[i-1])<<endl;
		}
	}
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextInt();
  string s; cin >> s;
  int Q = nextInt();

  set<int> pos[26];
  REP(i, N) {
    pos[s[i] - 'a'].insert(i);
  }

  REP(qi, Q) {
    int t = nextInt();
    int a = nextInt();
    // cout << t << " " << a << " " << b << endl;
    if (t == 1) {
      a--;
      char b; cin >> b;
      pos[ s[a] - 'a' ].erase(a);
      pos[ b - 'a' ].insert(a);
      s[a] = b;
    }
    if (t == 2) {
      a--;
      int b = nextInt() - 1;
      int ans = 0;
      REP(i, 26) {
        auto i1 = pos[i].lower_bound(a);
        auto i2 = pos[i].upper_bound(b);
        if (i1 != i2) ans++;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

int main(){
int n;

cin>>n;
for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
        if(n==i*j){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
}
cout<<"No"<<endl;

}

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

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    A += B;
    string s;
    cin >> s;
    for (int i = 0; i < N; i++) {
        if (s[i] == 'c') {
            cout << "No" << endl;
        }
        if (s[i] == 'a') {
            if (A > 0) {
                cout << "Yes" << endl;
                A--;
            }
            else cout << "No" << endl;
        }
        if (s[i] == 'b') {
            if (A > 0 && B > 0) {
                cout << "Yes" << endl;
                A--;
                B--;
            }
            else cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string S;
  cin >> S;
  
  if(S[0] != S[1] && S[1] != S[2] && S[2] != S[3])
    cout << "Good" << endl;
  else
    cout << "Bad" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
int main() {
	// your code goes here
	
	long double d,t,s;
	cin>>d>>t>>s;
	

	if(d/s<=t)cout<<"Yes";
	else
	cout<<"No";
	return 0;
}


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

int main(){
  string s; cin >>s;
  int n = s.size();
  int cnt = 0;
  char cur = s[n-1];
  for(int i = n-1; 0<=i; i--){
    if(s[i]!=cur){
      cnt++;
      cur = s[i];
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[3][3];
	for(int i=0;i<3;i++)
	   for(int j=0;j<3;j++)
	       cin>>a[i][j];
	int x,y,p,q;
	x=a[0][1]-a[0][0];
	y=a[0][2]-a[0][1];
	p=a[1][0]-a[0][0];
	q=a[2][0]-a[1][0];
	if((a[1][1]-a[1][0]==x)&&(a[2][1]-a[2][0]==x)&&(a[1][2]-a[1][1]==y)&&(a[2][2]-a[2][1]==y))
	{
		if((a[1][1]-a[0][1]==p)&&(a[1][2]-a[0][2]==p)&&(a[2][1]-a[1][1]==q)&&(a[2][2]-a[1][2]==q))
		   cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
if s == "SUN":
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
else:
    print(1)

Measured memory_bytes: 38384
#include<stdio.h>
#include<stdlib.h>
void insertionSort(int *,int);
void print(int *,int);
int main(){
  int *A;
  int i,n;
  
  scanf("%d",&n);
  A=(int *)malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  print(A,n);
  insertionSort(A,n);

  return 0;
}
void insertionSort(int *A,int N){
  int i,j,k,key;
  for(i=1;i<N;i++){
    key=A[i];
    j=i-1;
    while(j>=0&&A[j]>key){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=key;
    print(A,N);
  }
}
void print(int *A,int N){
  int i;
  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}



Measured memory_bytes: 2072
#include <stdio.h>
#define MAX 2000000000
void maxHeapify(int);
int A[MAX+1];
int H;

int main(void)
{
	int i,j;

	scanf("%d",&H);
	
	for(i=1;i<H+1;i++){
	scanf("%d", &A[i]);
	}
	
	for(i=H/2;i>=1;i--){
	maxHeapify(i);
	//printf("max-heapifing...\n");
	}
	
	for(i=1;i<H+1;i++){
		printf(" %d",A[i]);
	}
	printf("\n");
	
}

void maxHeapify(int i){
	int tmp;
	int max;
	if(i*2<H+1 && A[i] < A[i*2]){
		max = i*2;
		//printf("left is largest\n");
	}
	
	else {
		max = i;
	//	printf("i is largest\n");
	}
	if(i*2+1 < H+1 && A[max] < A[i*2+1]){
		max = i*2+1;
	//	printf("right is largest\n");
	}
	
	if(max != i ){
		tmp  = A[max];
		A[max] = A[i];
		A[i] = tmp; 
		maxHeapify(max);
	}
}



Measured memory_bytes: 3728
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 2000;

long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll GetDigit(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

ll power(ll a, ll b){
  ll ans = 1;
  if(b%2==0){
    REP(i, b/2){
      ans *= a;
      if(ans>1000000000){
        return -1;
      }
    }
    return ans * ans;
  }else{
    b = b/2;
    REP(i, b){
      ans *= a;
      if(ans>1000000000){
        return -1;
      }
    }
    return ans * ans* a;
  }
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main(void){

  ll n;
  cin>>n;
  vector<ll> v(n);
  REP(i, n){
    ll x;
    cin>>x;
    v[i] = x;
  }

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

  ll ans = 0;

  for(int i=0;i<n-2;i++){
    for(int j=i+1; j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(v[i]!=v[j] && v[i]!=v[k] && v[j]!=v[k]){
          if(v[i]+v[j] > v[k]) ans++;
          else break;
        }
      }
    }
  }

  cout<<ans<<endl;
  return 0;

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

class UnionFind{
public:
    vector<ll> par;
    vector<ll> siz;

    UnionFind(ll k):par(k), siz(k,1LL){
        for(int i = 0; i < k; i++) par[i] = i;
    }

    ll root(ll k){
        if(par[k] == k) return k;
        else return par[k] = root(par[k]);
    }
    
    bool unite(ll x, ll y){
        x = root(x);
        y = root(y);
        if(x==y) return false;

        if(siz[x] < siz[y]) swap(x, y);
        par[y] = x;
        siz[x] += siz[y];
        return true;
    }

    bool same(ll x, ll y){
        return root(x) == root(y);
    }

    ll size(ll x){
        return siz[root(x)];
    }
};

struct edge{
    ll from, to, cost;
};

bool comp(const edge& a, const edge& b){
    return a.cost < b.cost;
}

vector<edge> ed;
ll V, E;

int main(){
    cin >> V >> E;
    ed.resize(E);
    rep(i,E){
        ll a, b, c;
        cin >> a >> b >> c;
        edge e = {a,b,c};
        ed[i] = e;
    }
    UnionFind uf(V);
    ll ans = 0;
    sort(ed.begin(), ed.end(), comp);
    for(int i = 0; i < E; i++){
        edge e = ed[i];
        if(!uf.same(e.from, e.to)){
            uf.unite(e.from, e.to);
            ans += e.cost;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5464
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int main(void) {
    int n;
    cin >> n;
    int ans[n][n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            ans[i][j] = 0;
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int tmp;
            cin >> tmp;
            ans[u-1][tmp-1] = 1;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j == n-1) cout << ans[i][j];
            else cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1196
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		
		int[] x = new int[N + 1];
		
		for(int i = 1; i <= N; i++) {
			x[i] = sc.nextInt();
		}
		
		int d = 0;
		
		for(int i = 1; i <= N; i++) {
			d += 2 * Math.min(Math.abs(x[i] - K), x[i]);
		}
		System.out.println(d);
	}
}


Measured memory_bytes: 21844
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto data = readln.split, N = data[0].to!int, X = data[1].to!int;
	auto x = readln.split.to!(int[]);
	x = x.map!(a => (a-X).abs).array;
	auto minx = x.reduce!"min(a,b)";
	
	label: foreach_reverse(i; 1 .. minx+1) {
		foreach (y; x) {
			if (y % i != 0) continue label;
		}
		writeln(i); return;
	}
}

Measured memory_bytes: 4276
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

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

/* see https://github.com/pllk/cphb/
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
    tree_order_statistics_node_update> indexed_set;
 **/

typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

//typedef __int128 lll;
typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int p;
    
    int ans=0;
    fori(n) {
        cin>>p;
        if(p!=i+1)
            ans++;
    }

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

}



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

int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<char>>data(h+2,vector<char>(w+2));
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      cin >> data.at(i+1).at(j+1);
    }
  }
  for(int i = 1;i < w+1;i++){
    data.at(0).at(i) = '#';
    data.at(h+1).at(i) = '#';
  }
  for(int i = 0;i < h+2;i++){
    data.at(i).at(0) = '#';
    data.at(i).at(w+1) = '#';
  }
 
  for(int i = 0;i < h+2;i++){
    for(int j = 0;j < w+2;j++){
      if(j != w+1){
        cout << data.at(i).at(j);
      }
      else{
        cout << data.at(i).at(j) << endl;
      }
    }
  }
}


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

int main()
{
  int K; string S;
  cin >> K >> S;
  int sizeS = S.size();
  if(sizeS <= K) cout << S << endl;
  else cout << S.substr(0,K) << "..." << endl;
}

Measured memory_bytes: 3596
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.array;

void main() {
  bool[] state = new bool[](3);
  state[0] = true; state[1] = false; state[2] = false;
  while(true) {
    string line = readln.chomp;
    if (stdin.eof) break;
    auto data = line.split(",").map!((x) => to!(uint)(x[0] - 'A')).array;
    swap(state[data[0]], state[data[1]]);
  }
  foreach(i, s; state) if(s) writeln(to!(char)(i + 'A'));
}

Measured memory_bytes: 1060
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <cmath>
#include <bitset>
#include <limits>
#include <time.h>
#include <chrono>
#include <algorithm>
#include <sstream>
#include <string>
#include <tuple>
#include <queue>
#include <vector>
#include <unordered_map>
#include <unordered_set>
// #include "dbg.h"
using namespace std;

// change to long if you run out of memory
typedef long long ll;
typedef string str;
typedef unordered_map<ll, ll> dict;
typedef vector<ll> list;
typedef unordered_set<ll> set;
typedef unordered_map<ll, list> adj;

// infinity, but not really
const ll inf = std::numeric_limits<ll>::max() - (1 << 15);

#define MAXN 100001
ll dp[MAXN];

int main(void) {
  // fast cin
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  ll N, K, i, k, v;
  cin >> N >> K;

  list h;
  for (i = 0; i < N; i++) {
    cin >> v;
    h.push_back(v);
  }

  for (i = 0; i < N; i++) {
    dp[i] = inf;
  }
  dp[0] = 0;

  for (i = 0; i < N; i++) {
    for (k = 1; k < min(K + 1, N - i); k++) {
      dp[i + k] = min(dp[i + k], abs(h[i] - h[i + k]) + dp[i]);
    }
  }

  cout << dp[N - 1] << '\n';
  return 0;
}


Measured memory_bytes: 1908
#include<iostream>

#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

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

    int res = stoi(a+b);
    int check = sqrt(res);
    Yes(res==check*check)
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int min = Integer.MAX_VALUE;
		int i;
		int temp;
		long ans = 0;
		for(i = 0; i < n; i++) {
			temp = scan.nextInt();
			if(temp < min) {
				min = temp;
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 66036
//
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

#define REP(i,e,s) for(register int i=e; i<=s; i++)
#define DREP(i,e,s) for(register int i=e; i>=s; i--)
#define ll long long
#define DE(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG(a) DE("DEBUG: %d\n",a)
int read() {
	int x=0,f=1,ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=100000+10;

int n,x[MAXN],f[MAXN][20];

int binary_search(int k) {
	int l=1,r=n;
	while(l<r) {
		int mid=(l+r+1)>>1;
		if(x[mid]<=k) l=mid;
		else r=mid-1;
	}

	return r;
}

int main() {
	n=read();
	REP(i,1,n) x[i]=read();
	
	int l=read(),q=read();
	
	REP(i,1,n) f[i][0]=binary_search(x[i]+l);
	
	//DE("\n");REP(i,1,n) DE("%d ",f[i][0]);DE("\n");
	REP(j,1,16) REP(i,1,n) f[i][j]=f[f[i][j-1]][j-1];

	while(q--) {
		int a=read(),b=read();
		if(a>b) swap(a,b);
		int ans=0;
		DREP(i,16,0) {
			if(f[a][i]<b) a=f[a][i],ans+=(1<<i); 
		}

		printf("%d\n",ans+1);
	}
}

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

int main(){
  
  int A,B,C;
  
  cin >> A >> B >> C;
  
  if(A == B && B == C && C == A){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
}

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

int main() {

	int s;
	cin >> s;

	int x[4];
	x[0] = s / 1000;
	x[1] = (s / 100) % 10;
	x[2] = ((s / 10) % 100) % 10; 
	x[3] = ((s % 1000) % 100 ) % 10;

	int flug = 0;
	for(int i = 1; i < 4; i++){
		if(x[i] == x[i - 1]){
			flug += 1;
		}
	}
	if(flug > 0){
		cout << "Bad" << endl;
	}else{		
		cout << "Good" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
N,Q = map(int,input().split())
S = ' '+input()+' '

Q = tuple(tuple(input().split()) for _ in range(Q))


def simulate(i):
    for t,d in Q:
        if S[i] == t:
            i += 1 if d == 'R' else -1
    return i

def find(ng, ok, judge):
    while abs(ng-ok) > 1:
        m = (ng+ok)//2
        if judge(m):
            ok = m
        else:
            ng = m
    return ok

i_l = find(0, N+1, lambda i: simulate(i) != 0)
i_r = find(N+1, 0, lambda i: simulate(i) != N+1)

print(i_r-i_l+1)

Measured memory_bytes: 18164
#include <iostream>
#include <algorithm>


bool inRange(int v, int low, int high)
{
  return low <= v && v <= high;
}

int main()
{
  int n;
  std::cin >> n;
  
  int count = 0;
  for(int i=1; i<=n; i++)
  {
    if(
      inRange(i, 1, 9) ||
      inRange(i, 100, 999) ||
      inRange(i, 10000, 99999))
    {
      count += 1;
    }
  }

  std::cout << count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pii pair<ll, ll> 
#define pb push_back
#define debug(x) cerr<< #x << " is " <<x<<endl;
#define debug2(x) cerr<<#x<< " is\n"; for (auto &i:x) {cout<<i<<' '; } cout<<endl;
#define f first
#define s second
using namespace std;

ll dp[3005][3005][2];
ll ps[3005];
ll sum[3005][3005];

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin>>n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin>>a[i];
    for (int i=0; i<n; i++){
    	ps[i+1]=ps[i]+a[i];
    }
    for (int i=0; i<n; i++) {
    	for (int j=i; j<n; j++){
    		sum[i][j]=ps[j+1]-ps[i];
    	}
    }
    for (int i=0; i<n; i++){
    	for (int j=0; i+j<n; j++){
    		int k = i+j;
    		if (i==0) {
    			dp[j][k][0]=dp[j][k][1]=a[j];
    		}
    		dp[j][k][0]=max(a[j]+sum[j+1][k]-dp[j+1][k][1],
    						a[k]+sum[j][k-1]-dp[j][k-1][1]);
    		dp[j][k][1]=max(a[j]+sum[j+1][k]-dp[j+1][k][0],
    						a[k]+sum[j][k-1]-dp[j][k-1][0]);
    	}
    }
    cout<<dp[0][n-1][0]*2-sum[0][n-1]<<endl;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  int hei = b - a;
  int ans=0;
  for(int i=0; i<hei; i++){
    ans+=(i+1);
  }
  ans=ans - hei - a;
  cout << ans << endl;
}

Measured memory_bytes: 256
// 解説後
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main() {
  size_t N;
  std::string S;
  std::cin >> N >> S;

  // 共通文字列の最大長を求める
  size_t result = 0;  // 一致する部分文字列の最大長
  std::vector<size_t> z;  // [0, z[i])と[i, i+z[i])が一致している
  for (size_t l1 = 0; l1 < N - 1; ++l1) {
    // バッファをクリアする
    z.clear();
    z.resize(N - l1, 0);

    // Z-Algorithm
    size_t beg = 0, end = 0;  // [l1, l1+(end-beg))と[beg, end)が一致している
    for (size_t i = 1; i < z.size(); ++i) {
      if (i + z[i - beg] < end) {
        // 一致を確認した範囲の中であれば、以前に計算した値を再利用できる
        z[i] = z[i - beg];
      } else {
        // 一致を確認した範囲を外れる場合、改めて一致する部分を探す
        const size_t l2 = l1 + i;
        size_t len = i < end ? (end - i) : 0;
        for (; l2 + len < N; ++len) {
          if (S[l1 + len] != S[l2 + len]) break;
        }
        z[i] = len;
        beg = i;
        end = i + len;
      }

      result = std::max(result, std::min(i, z[i]));
    }
  }

  std::cout << result;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

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;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string w;
	cin>>w;
	map<char,int> cnt;
	rep(i,w.size()){
		cnt[w[i]]++;
	}
	for(auto itr:cnt){
		if(itr.se%2==1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

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

using namespace std;
#define int long long
int MOD = 1000000007;

signed main(){
    signed int A,B,K;
    cin >> A >> B >> K;
    
    if(A+B<=K){
        cout << "0 0" << endl;
        return 0;
    }
    
    if(K>=A){
        B = B-(K-A);
        A = 0;
    }else{
        A = A-K;
    }
    
    cout << A << " " << B << endl;
    
    return 0;
}


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

int main() {
	string str;
	cin >> str;
	if (str.length() >= 4) {
		if ((char)str[0] == 'Y'&&(char)str[1] == 'A'&& (char)str[2] == 'K'&& (char)str[3] == 'I') {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	} else {
		cout << "No" << endl;
	}
	return 0;
}


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

int main(){
  string s,t;
  cin >> s;
  if ( s.length() == 2 ) {
    cout << s << endl;
  }
  else{
    for( int i = 0; i<3; i++){
      t += s.substr(2-i, 1);
    }
    cout << t << endl;
  }
  return 0;
}

Measured memory_bytes: 256
for _ in[0]*int(input()):
 e=input()
 for i in range(1,26,2):
  for j in range(26):
   a=''.join([c,chr(((ord(c)-97)*i+j)%26+97)][c.islower()]for c in e)
   if'that'in a or'this'in a:print(a);break


Measured memory_bytes: 5600
//              _      _                 
//             (_)    | |                
//    _ __ ___  _  ___| |__   __ _  ___  
//   | '_ ` _ \| |/ __| '_ \ / _` |/ _ \ 
//   | | | | | | | (__| | | | (_| | (_) |
//   |_| |_| |_|_|\___|_| |_|\__,_|\___/ 
//                                       
// 
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
map<string,int>cnt;
const string s[4]={"AC","WA","TLE","RE"};
int32_t main()
{
  BOOST;
  int n;
  cin>>n;
  for (int i=1;i<=n;i++)
  {
  	string st;
  	cin>>st;
  	cnt[st]++;
  }
  
  
  for (int i=0;i<4;i++)
  {
  	string a=s[i];
  	int ile=cnt[a];
    cout<<a<<" "<<"x "<<ile<<"\n";
  }
  
  return 0;
}


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

int main(){
  int a,b,c,count=3;
  cin >> a >> b >> c;
  if(a==b){
    count--;
  }
  if(b==c){
    count--;
  }
  if(c==a){
    count--;
  }
  if(a==b && b==c){
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
n = int(input())
S = input()
ct = 0

for i in range(10):
    if str(i) in S:
        p = S.index(str(i))
        Si = S[p+1 :]
        for j in range(10):
            if str(j) in Si:
                q = Si.index(str(j))
                Sj = Si[q+1 :]
                for k in range(10):
                    if str(k) in Sj:
                        ct += 1
print(ct)

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    string a, b;
    cin >> a >> b;
    a += b;

    int n = 0;
    rep(i, a.size()) n = 10 * n + a[i] - '0';

    for (int i = 4; i * i <= n; i++)
    {
        if (n == i * i)
        {
            cout << "Yes" << '\n';
            return 0;
        }
    }

    cout << "No" << '\n';
    return 0;
}


Measured memory_bytes: 3596
n=int(input())
s=input()
r=g=b=0
for i in s:
  if i=="R":r+=1
  elif i=="G":g+=1
  else:b+=1

ans=r*g*b
for i in range(n):
  for j in range(i+1,n):
    k_ = j+(j-i)
    if(k_ >=n):
      break
    ans -= int(s[i]!= s[j] and s[i] != s[k_] and s[j] != s[k_])

print(ans)


Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define forn(i,n) for (int i=0;i<n;i++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define trav(a,x) for (auto& a : x)

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define sz(x) ((int)(x).size())
#define mem(x,a) memset(x,a,sizeof(x))

typedef vector<int> vi;
typedef pair<int,int> pii;

const int MOD = 1e9+7;
const int INF = 1e18;
const int N = 4e3 + 5;
string s ;
int f(char a , char b){
 if((a=='R' && b == 'G') || (a=='G' && b=='R'))return 2;
 if((a=='R' && b == 'B') || (a=='B' && b=='R'))return 1;
 if((a=='B' && b == 'G') || (a=='G' && b=='B'))return 0;
}
int g(int i ,int u){
 if(u==0 && s[i] == 'R')return 1;
 if(u==1 && s[i] == 'G')return 1;
 if(u==2 && s[i] == 'B')return 1;
 return 0;
}
int c[3][N];

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

 forn(i,n){
  forn(j,3)c[j][i + 1] = c[j][i] ;
  int u = 0;
  if(s[i] == 'G')u = 1 ;
  else if (s[i] == 'B')u = 2; 
  c[u][i + 1] += 1 ;
 }

 int ans = 0;
 forn(i,n){
  rep(j , i + 1 , n){
   if(s[i] != s[j]){
    int u = f(s[i] , s[j]);
    int l = c[u][n] - c[u][j] ;

    ans += l - g(2*j - i , u);
   }
  }
 }

 cout << ans <<" ";


 return 0;
}        

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

using namespace std;

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

    if ( a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 ) {
        cout << "Possible\n";
    } else {
        cout << "Impossible\n";
    }

    return 0;
}



Measured memory_bytes: 256
// https://atcoder.jp/contests/abc172/tasks/abc172_d
#include<bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[]) {
	long long n;
	cin >> n;
	vector<long long> a (n+1);
	for (long long i = 1; i <= n; i++) {
		for (long long j = i; j <= n; j+=i) {
			++a[j];
		}
	}
	long long ans = 0;
	for (long long i = 1; i <= n; i++) {
		ans += i*a[i];
	}
	cout << ans << endl;
	return 0;
}

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

#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}


//約数をベクトル形式で返す
vector<int> vect_yakusuu(int n) {
	vector<int> ret;
	for (int i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			ret.push_back(i);
			if (i*i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return ret;
}

int main() {

	int N;
	int ans = 0;

	int A[1000010];
	int num[1000010] = {};

	vector<int> yakusuu;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		num[A[i]]++;
	}

	for (int i = 0; i < N; i++) {
		yakusuu = vect_yakusuu(A[i]);
		int is_undiv = 1;
		for (int j = 0; j < yakusuu.size()-1; j++) {
			if (num[yakusuu[j]] != 0) {
				is_undiv = 0;
			}
		}
		int j = yakusuu.size() - 1;
		if (num[yakusuu[j]] > 1) {
			is_undiv = 0;
		}
		if (is_undiv == 1) {
			ans++;
		}

	}

	cout << ans << endl;

	cin >> ans;

	return 0;


}

Measured memory_bytes: 8284
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int a, b;

int main() {
	cin >> a >> b;
	string S1; for (int i = 0; i < b; i++) S1 += to_string(a);
	string S2; for (int i = 0; i < a; i++) S2 += to_string(b);

	cout << min(S1, S2) << endl;
	return 0;
}

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

ll solve() {
  int N; cin >> N;
  vector<int> T(N), A(N);
  rep(i, 0, N) cin >> T[i];
  rep(i, 0, N) cin >> A[i];
  if(N == 1) return T[0] == A[0];
  if(T.back() != A.front()) return 0;
  rep(i, 1, N) if(T[i-1] != T[i] && T[i] > A[i]) return 0;
  rep(i, 0, N-1) if(A[i] != A[i+1] && A[i] > T[i]) return 0;
  ll ans = 1;
  rep(i, 0, N) {
    if(T[i-1] != T[i]) continue;
    if(A[i] != A[i+1]) continue;
    ans *= min(T[i], A[i]);
    ans %= MOD;
  }
  return ans;
}

int main() {
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public long MOD = 1000000007;
        public int[] H;
        public long[] DP;
        public void Run()
        {
            N = Input.ReadInt();
            H = Input.ReadIntArray();
            DP = new long[N];
            DP[0] = 0;
            DP[1] = Math.Abs(H[1] - H[0]); 
            for (int i = 2; i < N; i++)
            {
                DP[i] = Math.Min(DP[i - 2] + Math.Abs(H[i] - H[i-2]), 
                                 DP[i - 1] + Math.Abs(H[i] - H[i - 1]));
            }
            Console.WriteLine(DP[N - 1]);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 18528
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i=(int)s;i<(int)n;i++)
int main(){
  long long x,k,d,a; cin>>x>>k>>d;
  x=abs(x);
  if(x/d>k) a=x-k*d;
  else{
    k-=x/d;
    a=x-d*(x/d);
    if(k%2) a-=d;
  }
  cout<<abs(a);
}

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();

            if (n % 2 == 0) {
                System.out.println(n);
            } else {
                System.out.println(n * 2);
            }
        }
    }

}


Measured memory_bytes: 21972