akhauriyash/Code-Regression huggingface dataset:
/*input
10 4
40 10 20 70 80 10 20 70 80 60
*/
 
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define ld long double
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define se second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<long long int, long long int> mpi;
typedef set<long long int> seti;
typedef multiset<long long int> mseti;
typedef priority_queue<long long int> pq;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define PI 3.14159265
#define dbg(x) cerr << "\n" << (#x) << " = " << (x) << endl ;
//#define cerr if(false)cerr
  
struct node{
    ll val;
};
struct Interval {int start, end;};
bool compare(struct node n1, struct node n2) {
    return (n1.val < n2.val);
}
 
 
 ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 











int main() 
{
	ll n,k; cin>>n>>k;
	ll dp[100005];
	dp[1]=0;
	ll h[100005];
	rep(i,n){cin>>h[i];}

	dp[2] = abs(h[1]-h[0]);
	repA(i,3,n){
		ll mini = 1e16;
		repA(j,1,k){
			if(i-j>=1)
				mini = min(mini, dp[i-j] + abs( h[i-1] - h[i-j-1] ) ) ;
			else
				continue;
		}
		dp[i] = mini;
	}
	cout<<dp[n];
    return 0;  
}



















 

Measured memory_bytes: 5048
N = int(input())
A = list(map(int, input().split(' ')))
result = True
for i in range(N):
    if A[i]%2 == 0  and not(A[i]%3 == 0 or A[i]%5 == 0):
        result = False
if result:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3060
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

int main(){
    string s,front,back;
    cin>>s;
    int maxlength=-1;
    for(int i=s.size()-1;i>=0;i--){
        s=s.substr(0,i);
        if(s.size()%2!=0){continue;}
        front=s.substr(0,s.size()/2);
        back=s.substr(s.size()/2,s.size());
        debug(front);
        debug(back);
        if(front==back){
            maxlength=max(maxlength,(int)s.size());
        }

    }
    cout<<maxlength<<endl;





}


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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 100005
#define ALL(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;


int32_t main()
{
    IOS;

    int tt=1;
    //cin>>tt;
    while(tt--)
    {
		int n; cin>>n;
		vector<pair<int,int>> v(n);
		for (int i = 0; i < n; i++)
		{
			cin>>v[i].F;
			v[i].S = i + 1;
		}
		sort(ALL(v));
		for (int i = 0; i < n; i++)
		{
			cout<<v[i].S<<" ";
		}
		
		
		cout<<endl;
    }
    return 0;

}


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

int main(){
  int N, score=0, max=0;  
  string str;
  cin >> N;
  str.resize(N);
  cin >> str;

  for(int i=0; i<N; i++){
    if(str[i] == 'I'){
      score++;
      if(score > max) max = score;      
    }
    else score--;
  }

  cout << max << endl;
  
  return 0;
}


Measured memory_bytes: 888
N, L = map(int, input().split())
A = [] # リスト宣言(りんごの味)

for i in range(N):
    A.append(L + i) # A.append([追加するもの])

total = sum(A) # リストAの総和

# 持ってるりんごの味で一番絶対値が小さいものを選ぶ
b = 1000000
j = 0 # 絶対値が一番小さいりんごの番号
for i in range(N):
    if abs(A[i]) < b:
        j = i
        b = abs(A[i])

print(total - A[j])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 N;
  cin >> N;
  vector<i64> a(N), b(N);
  for (i64 i = 0; i < N; i++)
    cin >> a[i];
  for (i64 i = 0; i < N; i++)
    cin >> b[i];
  i64 ans = 0;
  for (i64 i = 0; i < N; i++)
    if (a[i] < b[i])
      ans += (b[i] - a[i]) / 2;
    else
      ans -= a[i] - b[i];
  if (ans < 0)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}


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

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

Node root;

Node treeMinimum(Node x){
}
Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key)return u;
  if(k<u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}
Node treeSuccessor(Node x){
}
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
}
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL) root=z;
  else if(z->key<y->key) y->left=z;
  else y->right=z;
}
void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='f'){
      scanf("%d",&x);
      Node t = treeSearch(root,x);
      if(t!=NIL)printf("yes\n");
      else printf("no\n");

    } else if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    } else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(com[0]=='d'){
      printf("in delete\n");
      scanf("%d",&x);
      //treeDelete(treeSearch(root,x));
    }
  } 
  return 0;
}

Measured memory_bytes: 19364
#include<bits/stdc++.h>
using namespace std;
int main() {
	string S; cin >> S;
	string P[4] = { "dream","dreamer","erase","eraser" };
	reverse(S.begin(), S.end());
	for (int i = 0; i < 4; i++)
		reverse(P[i].begin(), P[i].end());
	for (int i = 0; i < S.size();) {
		for (int j = 0; j < 4; j++) {
			if (S.compare(i, P[j].size(), P[j]) == 0) {
				i += P[j].size();
				break;
			}
			if (j == 3) {
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 512
def main():
  N=int(input())
  A=list(map(int,input().split()))
  B=list(map(int,input().split()))
  ans=[]
  for i in range(29):
    T=2**i
    B_=list(B)
    A_=list(A)
    t=0
    for j in range(N):
      B_[j]%=2*T
      A_[j]%=2*T
    A_.sort()
    B_.sort()
    p=q=r=0
    for a in A_[::-1]:
      while p<N and a+B_[p]<T:
        p+=1
      while q<N and a+B_[q]<2*T:
        q+=1
      while r<N and a+B_[r]<3*T:
        r+=1
      t+=(q-p)+(N-r)
    ans.append(t%2)
  a=0
  for i in range(29):
    a+=2**i*ans[i]
  print(a)
if __name__=='__main__':
  main()


Measured memory_bytes: 138384
package main

import "fmt"

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

	for i := -200; i <= 200; i++ {
		for j := -200; j <= 200; j++ {
			if gojo(i)-gojo(j) == X {
				fmt.Printf("%d %d\n", i, j)
				return
			}
		}
	}
}

func gojo(x int) int {
	return x * x * x * x * x
}


Measured memory_bytes: 1836
#include <cstdio>
#include <string>
#include <cmath>
#include <map>
#include <cmath>
#include <queue>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 5;
const int mod = 100003;
int main()
{
    int n,a=0,b=0,c=0;
    scanf("%d",&n);
    a=n/3600;
    n%=3600;
    b=n/60;
    n%=60;
    c=n;
    printf("%d:%d:%d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
   
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        int a[5];
        rep(i,5)cin>>a[i];
        rep(i,5){
            if(a[i]==0){
                cout<<i+1;return 0;
            }
        }
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 3648
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
 
L.sort()
 
ans = 0

for b in range(N):
  for a in range(b):
    ab = L[a] + L[b]
    r = bisect_left(L, ab)
    l = b + 1
    
    ans += r-l

print(ans)

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

int main()
{
    int N, K ; 
    cin >> N >> K ;
    
    vector<int> a(N) ;
    for(int &x : a) cin >> x ;

    vector<int> dp(N, INT_MAX) ;
    dp[0] = 0 ;

    for(int i = 0 ; i < N ; ++i)
    {
        for(int j = 1 ; j <= K && i-j >= 0 ; ++j)
        {
            dp[i] = min(dp[i], dp[i-j] + abs(a[i] - a[i-j])) ;
        }
    }
    cout << dp[N-1] << endl ;
    return 0 ;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		int A = Integer.parseInt(tokens[0]);
		int B = Integer.parseInt(tokens[1]);
		in.close();
		if (B % A == 0) {
			System.out.println((A + B));
		} else {
			System.out.println((B - A));
		}
	}

}


Measured memory_bytes: 21844
import java.util.ArrayDeque
import java.math.*

fun main(args: Array<String>) {
    var (N, u, v) = readInputLine().split(" ").map { it.toInt() }
    u--
    v--
    val edges = Array(N) { mutableListOf<Int>() }

    if (u == v) {
        println(0)
        return
    }

    for (i in 1 until N) {
        val (A, B) = readInputLine().split(" ").map { it.toInt() - 1 }
        edges[A].add(B)
        edges[B].add(A)
    }

    // (node, parent)
    val queue = ArrayDeque<Pair<Int, Int>>()
    val uDist = IntArray(N) { -1 }
    val vDist = IntArray(N)

    for (e in edges[v]) {
        queue.add(Pair(e, v))
    }

    while (queue.isNotEmpty()) {
        val (n, p) = queue.poll()!!
        vDist[n] = vDist[p] + 1

        for (e in edges[n]) {
            if (e == p) {
                continue
            }
            queue.add(Pair(e, n))
        }
    }

    uDist[u] = 0

    for (e in edges[u]) {
        queue.add(Pair(e, u))
    }

    while (queue.isNotEmpty()) {
        val (n, p) = queue.poll()!!
        val tmp = uDist[p] + 1
        if (tmp >= vDist[n]) {
            continue
        }
        uDist[n] = tmp

        for (e in edges[n]) {
            if (e == p) {
                continue
            }
            queue.add(Pair(e, n))
        }
    }

    var leaf = u

    for (i in 0 until N) {
        if (uDist[i] == -1) {
            continue
        }
        if (vDist[i] > vDist[leaf]) {
            leaf = i
        }
    }

    /*
    println(uDist.joinToString(" "))
    println(vDist.joinToString(" "))

    println(leaf)

     */

    println(vDist[leaf] - 1)
}

fun readInputLine(): String {
    return readLine()!!
}


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

int main(){
  long long int x,k,d;
  cin >> x >> k >> d;
  long long int ans;
  
  long long int count; //【ミス】ここをふつうのintにしてた...
  count = abs(x)/d; //count回移動させると次に符号が変わる
  if(x>=0){
    if(count >= k){ //符号変わらない場合
      ans = x - k*d;
    }else{ //符号が途中で切り替わる(+ to -)
      if((k - count)%2==0){
        ans = x -count*d;
      }else{
        ans = abs(x - count*d -d);
      }
    }
  }else if(x < 0){
    if(count >= k){
      ans = abs(x + k*d);
    }else{
      if((k - count)%2==0){
        ans = abs(x +count*d);
      }else{
        ans = x + count*d + d;
      }
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 3612
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

// Use g++ compiler for this include to work.
#include <bits/stdc++.h>

using namespace std;

// Constants 
#define INF 1e18
#define EPS 1e-9
#define MOD 1000000007
 
// // for using in pairs
#define F first
#define S second
 
// Macros
#define all(x) begin(x), end(x)
 
// aliases
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;

// Temporary macro.
#define int long long

// Operator overloads.
/**
 * The type of element in the vector should have overload for << operator with ostream. 
 */
template<typename T>
ostream& operator<<(ostream &stream, vector<T>& v)
{
	for (const auto &it : v)
		stream << it << " ";
	return stream;
}

/**
 * Both types in the pair should have overload for << operator with ostream. 
 */
template<typename T1, typename T2>
ostream& operator<<(ostream &ostream, pair<T1, T2>& p)
{
	ostream << p.first << " " << p.second;
	return ostream;
}

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

template<typename T>
istream& operator>>(istream &istream, vector<T>& a)
{
	for (auto &it : a)
		istream >> it;
	return istream;
}

// Utility functions.

int GCD(int a, int b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}

int LCM(int a, int b)
{
	return (a * b) / GCD(a, b);
}

int modpow(int x, int n, int m = MOD)
{
	if (n == 0) return 1 % m;
	long long u = modpow(x, n / 2, m);
	u = (u * u) % m;
	if (n % 2 == 1)
		u = (u * x) % m;
	return u;	
}

//////////////////// START CODE HERE ///////////////////////////

void solve(int tc)
{
	int n;
	cin >> n;
	int ans = 0;
	for (int a = 1; a < n; a++)
	{
		int b = (n - 1) / a;
		ans += b;
	}
	cout << ans;
}	

int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t = 1;
	// cin >> t;		
	for (int i = 1; i <= t; i++)
	{
		solve(i);
	}

	return 0;
}


Measured memory_bytes: 3648
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cstring>

#include<vector>

#include<queue>



using namespace std;

typedef long long ll;
int n,t,s;
int a[3001],b[3001];
int dp[3002][3002];
int main(void){
	scanf("%d%d%d",&n,&t,&s);
	for(int i=0;i<n;i++)scanf("%d%d",&a[i],&b[i]);
	int res=0;
	for(int i=0;i<=t;i++){
		int M=0;
		for(int j=0;j<=n;j++){
			M=max(M,dp[i][j]);
			dp[i+1][j]=max(M,dp[i+1][j]);
			res=max(dp[i+1][j],res);
			if(j==n)continue;
			if((s<=i || i+b[j]<=s) && i+b[j]<=t){
				dp[i+b[j]][j+1]=max(dp[i+b[j]][j+1],M+a[j]);
				res=max(res,dp[i+b[j]][j+1]);
			}
		}
	}
	printf("%d\n",res);

	return 0;

}

Measured memory_bytes: 36404
#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in,in> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (in)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(in i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

int main(){
    IOS;
    string s;
    cin >> s;
    if(s[2]==s[3] and s[4]==s[5]) cout << "Yes\n";
    else cout << "No\n";
}

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

int lucas(int n, int k){
    return (n&k) == k;
}

void Main(){
    int N; cin >> N;
    string a; cin >> a;

    bool flag = false;
    int guki = 0;
    REP(i,N){
        if(a[i]=='2'){
            guki ^= lucas(N-1,i);
            flag = true;
        }
    }

    if(guki){
        cout << 1 << en;
        return;
    }

    if(flag){
        cout << 0 << en;
        return;
    }

    REP(i,N) if(a[i]=='3') a[i] = '1'; else a[i] = '0';
    guki = 0;
    REP(i,N){
        if(a[i]=='1'){
            guki ^= lucas(N-1,i);
        }
    }

    cout << (guki ? 2 : 0) << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 1948
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
using namespace std;
int n,k;
int main()
{
	scanf("%d %d",&n,&k);
	if(k==1)
	{
		printf("0");
		return 0;
	}
	printf("%d\n",n-k);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

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

map<long, long> prime_factors(long n) {
    map<long, long> res;
    if(n == 1) { // n=1 の素因数分解は n^1
        res[n] = 1;
        return res;
    }
    for(long i = 2, _n = n; i*i <= _n; ++i) {
        while(n % i == 0) {
            ++res[i]; // 素数i^{res[i]}
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

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

  long a, b;

  cin >> a >> b;

  long gv = gcd(a, b);
  map<long, long> res = prime_factors(gv);

  if (gv == 1) {
    cout << 1 << endl;
  } else {
    cout << res.size()+1 << endl;
  }
}


Measured memory_bytes: 888
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin>>s;
  int count1=0,count0=0;
  for(int i=0;i<s.length();i++){
    if(s[i]=='0')
      count0++;
    if(s[i]=='1')
      count1++;
  }
  int ans=count1<count0? count1:count0;
  cout<<ans*2<<endl;
  return 0;
}

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

int n, a[200001], sum[200001], maxi[200001], q, dis, c, b, itr = 1, reach[200001][18];

int main()
{
	memset(reach, -1, sizeof reach);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    cin >> dis;
    for(int i = 1; i < n; i++){
        int l = i + 1, r = n;
        while(l != r){
            int mid = (l + r) / 2;
            if(a[mid] - a[i] < dis) l = mid + 1;
            else r = mid;
        }
        if(a[l] - a[i] > dis) l--;
        maxi[i] = l;
    }
    maxi[n] = n;
    for (int j = 0; j < 17; j++){
		for (int i = 1; i <= n; i++){
			if (j == 0){
				reach[i][j] = maxi[i];
			}
			else{
				reach[i][j] = reach[reach[i][j - 1]][j - 1];
			}
		}
	}
    cin >> q;
    for(int i = 0; i < q; i++){
    	int ans = 0;
        cin >> c >> b;
    	if(c > b) swap(b, c);
    	if(c == b){
    		cout << 0 << endl;
    		continue;
		}
    	for(int i = 17; i >= 0; i--){
    		if(reach[c][i] < b && reach[c][i] != -1){
    			c = reach[c][i];
    			ans += 1 << i;
			}
		}
		cout << ans + 1 << endl;
    }
}

Measured memory_bytes: 17152
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var h = Math.floor(N / 100);
  var a = N % 100;
  if(N < 100){
    myout(0);
    return;
  }
  if(a != 0){
    var req = Math.ceil(a / 5);
    if(h >= req){
      myout(1);
    }else{
      myout(0);
    }
  }else{
    myout(1);
  }
}


Measured memory_bytes: 29720
#include<bits/stdc++.h>
using namespace std;
int main()
{   ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n,m;
    cin>>n>>m;
    long long arr[m];
    for(int i=0;i<m;i++)
        cin>>arr[i];
    for(int x:arr)
        n-=x;
    if(n>=0)
    cout<<n;
    else
        cout<<"-1";
}

Measured memory_bytes: 3732
#https://note.nkmk.me/python-gcd-lcm/
def f(myList):
    if len(myList) == 0:
        return 0
    else:
        #print(myList)
        tmp = min(myList)
        ans = tmp
        for i in range(len(myList)):
            myList[i] -= tmp
        newList = []
        for i in range(len(myList)):
            pop_a = myList.pop()
            if pop_a != 0:
                newList.append(pop_a)
            else:
                ans += f(newList)
                newList = []
        ans += f(newList)
        return ans 

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

print(f(a))


Measured memory_bytes: 9196
def gli
  gets.split.map(&:to_i)
end
n, a = gli
x = gli
for i in 0..x.size-1
  x[i] -= a
end

dp = {}
dp[0] = 1
n.times { |i|
  tmp = dp.dup
  dp.each { |k, v|
    if tmp.has_key? (x[i] + k)
      tmp[x[i] + k] += v
    else
      tmp[x[i] + k] = v
    end
  }
  dp = tmp.dup
}

puts dp[0] - 1


Measured memory_bytes: 5116
s = list(input())
k = int(input())

l = len(s)

ss = s + s
ll = len(ss)

single = 0
cnt = 0

for i in range(1, l):
    if s[i - 1] == s[i]:
        if cnt == 0:
            single += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                single += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

double = 0
cnt = 0

for i in range(1, ll):
    if ss[i - 1] == ss[i]:
        if cnt == 0:
            double += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                double += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

if len(set(s)) == 1:
    ans = double * (k // 2) + single * (k % 2)
elif single * 2 == double:
    ans = single * k
else:
    ans = single + (single + 1) * (k - 1)

# print(single, double)
print(ans)


Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 300005
using namespace std;
inline int in(){
    int x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
int a[MN],q[MN],tp,hd,tl,n;
int main()
{
	n=in();hd=tp=1;
	for (int i=1;i<=n;++i) a[i]=in();
	for (int i=1;i<=n;++i){
		tp=min(tp,i); 
		if((a[i]-tp)&1){if(a[i]!=i){printf("No");return 0;}}
		else if (hd>tl||q[tl]<a[i]) q[++tl]=a[i];
		else if (a[i]==tp) tp+=2;
		else {printf("No");return 0;}
		while (hd<=tl&&q[hd]==tp) tp+=2,++hd;
	}printf("Yes");return 0;
}

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

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

  int c[N]; 
  rep(i,N){
    c[i]=0;
  }
  int M = sqrt(N);
  rep(i,M) {
    int x = i + 1;
    int xx = x*x;
    if (xx > N) break;
    rep(j,M){
      int y = j + 1;
      int yy = y*y;
      int xy = x*y;
      if (xx + yy + xy > N) break; 
      rep(k,M){
        int z = k + 1;
        int n = xx + yy + z*z + xy + y*z + z*x;
        if (n > n) break;
        rep(l,N){
          if (l+1==n) c[l]++;
        }
      }
    }
  }
  rep(i,N){
    cout << c[i] << endl;
  }
}


Measured memory_bytes: 3552
N, W = map(int, input().split())
w = []
v = []
for _ in range(N):
  wi, vi = map(int, input().split())
  w.append(wi)
  v.append(vi)
dp = [[float('inf')]*(max(v)*N+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(N):
  for sum_v in range(max(v)*N+1):
    if v[i] - sum_v > 0:
      dp[i+1][sum_v] = dp[i][sum_v]
    else:
      dp[i+1][sum_v] = min(dp[i][sum_v], dp[i][sum_v - v[i]] + w[i])

ans = 0
for sum_v in range(max(v)*N+1):
  if dp[N][sum_v] <= W:
    ans = sum_v
print(ans)

Measured memory_bytes: 248316
#include <bits/stdc++.h>
using namespace std;
typedef long double db;

const int MAXN = 3000 + 10;

int n;
db p[MAXN], f[MAXN][MAXN], np[MAXN], ans;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%llf", &p[i]), np[i] = (1.0 - p[i]);
    f[0][0] = 1.0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= i; ++j) {
            f[i][j] += f[i - 1][j] * np[i];
            if (j > 0) f[i][j] += f[i - 1][j - 1] * p[i];
        }
    }
    for (int i = 0; i <= n; ++i) {
        ans += (f[n][i]) * ((n - i) < i);
    }
    printf("%.10llf\n", ans); 
    return 0;
}

Measured memory_bytes: 139904
#include <iostream>
#include <stdio.h>

bool check(int x)
{
    if(x % 2 == 0){
        if (x % 3 == 0)
        {
            return true;
        }
        else if (x % 5 == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return true;
    }
    
}

int main()
{
    int N, A[100];
    bool chk = true;
    bool rel = false;
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
        scanf("%d", &A[i]);
    int i = 0;
    while (i < N && chk)
    {
        if (!check(A[i]))
        {
            rel = true;
        }
        i++;
    }
    if (rel)
    {
        printf("DENIED");
        return 0;
    }
    else
    {
        printf("APPROVED");
        return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, b, c, d;std::cin >> a >> b >> c >> d;
  std::cout << max(a*b, c*d) << '\n';
  return 0;
}


Measured memory_bytes: 888
// AOJ ALDS1_14_D Multiple String Matching
// 2018.5.13 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define MAX_L 1000005

char text[MAX_L]; int len;
char pattern[10005]; int plen;
int  sa[MAX_L], rank[MAX_L<<1];

// rank[i]～[i+k] と rank[j]～[j+k] を比較
int k; // comstruct_sa()内で設定
int compare_sa(int i, int j)
{
	if (rank[i] != rank[j]) return rank[i] < rank[j];
	return rank[i+k] < rank[j+k];
}

// for qsort()
int cmp(int *a, int *b)
{
	int i = *a, j = *b;
	
	if (rank[i] != rank[j]) return rank[i] - rank[j];
	return rank[i+k] - rank[j+k];
}

// 文字列Sの接尾辞配列saを構築。   len:　strlen(s)
int tmp[MAX_L];
void construct_sa(char *s, int *sa)
{
	int i;
	
	memset(rank, -1, sizeof(rank));
	for(i = 0; i <= len; i++) {
		sa[i] = i;
		if (i < len) rank[i] = s[i];
	}
	
	for(k = 1; k <= len; k *= 2) {
		qsort(sa, len+1, sizeof(int), cmp);
		
		tmp[sa[0]] = 0;
		for(i = 1; i <= len; i++) {
			tmp[sa[i]] = tmp[sa[i-1]]+(compare_sa(sa[i-1], sa[i])? 1: 0);
		}
		for(i = 0; i <= len; i++) rank[i] = tmp[i];
	}
}

// 接尾辞配列を用いた文字列検索　len = strlen(s), plen = strlen(t)
int contain(char *s, char *t)
{
	int l, r, m;

	l = 0, r = len;
	while (l+1 < r) {
		m = (l+r)>>1;
		if (memcmp(s+sa[m], t, plen) < 0) l = m; else r = m;
	}
	return !memcmp(s+sa[r], t, plen);
}

int main()
{
	int Q;
	char c, *p;

	p = text;
	while ((c = gc()) > ' ') *p++ = c;
	*p = 0;
	len = p-text;

	construct_sa(text, sa);

//for (int i = 0; i <= len; i++) printf("[%d] sa %d\n", i, sa[i]);

	Q = in();
	while (Q--) {
		p = pattern;
		while ((c = gc()) > ' ') *p++ = c;
		*p = 0;
		plen = p-pattern;

		pc('0' + contain(text, pattern));
		pc('\n');
	}
	return 0;
}


Measured memory_bytes: 21384
x,y = gets.strip.split(" ").map(&:to_i)
count = "-1 -1 -1"
(0..x).each do |n|
    (0..(x-n)).each do |m|
        l = x - n - m
        count = "#{n} #{m} #{l}" if 10000 * n + 5000 * m + 1000 * l == y
    end
end
print count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,sum=0;
int arr[1000000];
ll dp[1000000];
ll finds(int next=0)
{
    if(next>=n)
        return  100000;
    if(next==(n-1))
        return 0;
    if(dp[next]!=-1)
        return dp[next];

    ll ans1=finds(next+1)+abs(arr[next+1]-arr[next]);
    ll ans2=finds(next+2)+abs(arr[next+2]-arr[next]);
    return dp[next]= min(ans1,ans2);

}
int main()
{
    ll i,j,k,l,m;
    cin>>n;
    memset(dp,-1,sizeof dp);
    for(i=0;i<n;i++)
        cin>>arr[i];
    cout<<finds(0);

}


Measured memory_bytes: 13568
def minus(a:str):
    return int(a)*-1

N,M = map(int,input().split())
A = list(map(minus,input().split()))

import heapq as hq

def main():
    hq.heapify(A)
    for _ in range(M):
        target = hq.heappop(A)
        target = -1*((-1*target) // 2)
        hq.heappush(A,target)
    print(sum(A)*-1)
    return 

if __name__ == "__main__":
    main()

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

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


ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}


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

    ll x = rep_jijo(10,n);
    ll y = rep_jijo(9,n);
    ll z = rep_jijo(8,n);

    ll ans = x+z;
    ans %= mod;

    ll Y = 2*y;
    Y %= mod;

    ans -= Y;
    if (ans <0){
        ans += mod;
    }
    ans %= mod;

    cout << ans <<endl;

    return 0;
}


Measured memory_bytes: 3612
from math import sqrt
from collections import defaultdict as dd
class dijkstra:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def path(self, s, t):
    d = [float("inf")] * (self.n + 1)
    vis = set()
    d[s] = 0
    while not t in vis:
      v = -1
      for i in range(self.n):
        if (not i in vis) and (v == -1):
          v = i
        elif (not i in vis) and d[i] < d[v]:
          v = i
      if v == -1:
        break
      vis.add(v)
      for p in self.e[v]:
        d[p[0]] = min(d[p[0]], d[v] + p[1])
    return d[t]
def distance(u1, v1, r1, u2, v2, r2):
  dis = sqrt(((u1 - u2) ** 2) + ((v1 - v2) ** 2))
  return max(dis - r1 - r2, 0)
sx, sy, tx, ty = map(int, input().split())
N = int(input())
c = [list(map(int, input().split())) for _ in range(N)]
c.append([sx, sy, 0])
c.append([tx, ty, 0])
e = dd(list)
for i in range(N + 1):
  for j in range(N + 2):
    if i == j: continue
    if j == N: continue
    e[i + 1].append([j + 1, distance(c[i][0], c[i][1], c[i][2], c[j][0], c[j][1], c[j][2])])
d = dijkstra(N + 2, e)
print(d.path(N + 1, N + 2))

Measured memory_bytes: 161884
class WeightedUnionFind
  def initialize(n)
    @parent = (0...n).to_a # 親の番号
    @rank = Array.new(n, 0) # 木の深さ
    @diff_weight = Array.new(n, 0) # 親との重みの差
  end

  def root(x)
    return x if @parent[x] == x
    r = root(@parent[x])
    @diff_weight[x] += @diff_weight[@parent[x]]
    @parent[x] = r
    return r
  end

  def weight(x)
    root(x)
    return @diff_weight[x]
  end

  def same?(x, y)
    root(x) == root(y)
  end

  def diff(x, y)
    # x と y とが同じグループにいるとき、weight(y) - weight(x) を返す
    # 同じグループでないならnil
    return nil if !same?(x, y)
    return weight(y) - weight(x)
  end

  def merge(x, y, w)
    # weight(y) - weight(x) = wとなるように結合
    w -= weight(x)
    w -= weight(y)
    x, y = root(x), root(y)
    return false if x == y
    if @rank[x] < @rank[y]
      x, y = y, x
      w = -w
    end
    @rank[x] += 1 if @rank[x] == @rank[y]
    @parent[y] = x
    @diff_weight[y] = w
    return true
  end
end

N,M=gets.split.map(&:to_i)
uf=WeightedUnionFind.new(N)

M.times do
  x,y,z = gets.split.map(&:to_i)
  uf.merge(x-1, y-1, 1)
end

cnt = {}
N.times do |i|
  cnt[uf.root(i)]=1
end

p cnt.size

Measured memory_bytes: 10620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string T;
  cin >> T;
  
  for (int i = 0; i < T.size(); i++) {
    if ( T.at(i) == '?') {
      T.at(i) = 'D';
    }
  } 
  
  cout << T << endl;
  
}

Measured memory_bytes: 3752
n = int(input())
a = list(map(int, input().split()))

ct = [0]*(n+1)
for i in a:
    ct[i] += 1

x, y = [0]*(n+1), [0]*(n+1)
for i in range(n+1):
    x[i] = ct[i]*(ct[i]-1)//2
    y[i] = (ct[i]-1)*(ct[i]-2)//2
s = sum(x)

for i in a:
    print(s-x[i]+y[i])


Measured memory_bytes: 26268
#include <iostream>
#include <cstdio>

using namespace std;

int GetGroup(int value)
{
    switch (value)
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            return 0;
            
        case 4:
        case 6:
        case 9:
        case 11:
            return 1;
            
        default:
            return 2;
    }
}

int main()
{
    int x, y;
    
    cin >> x >> y;
    
    if (GetGroup(x) == GetGroup(y))
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int main(){
  int H,W;
  string S;
  cin >> H >> W;
  FOR(i,1,H+1)for(char c = 'A';c < 'A'+W;c++){
    cin >> S;
    if(S == "snuke"){
      cout << c << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
from collections import deque


s = list(input())
q = int(input())
queries = [input().split() for _ in range(q)]
for i in range(q):
    queries[i][0] = int(queries[i][0])
    if queries[i][0] == 2:
        queries[i][1] = int(queries[i][1])

revised_queries = []
reverse_num = 0

for query in reversed(queries):
    q_type = query[0]
    if q_type == 1:
        reverse_num += 1
        continue
    f_b = query[1]
    c = query[2]
    if reverse_num % 2 == 1:
        f_b = 2 if f_b == 1 else 1
    revised_queries.append([f_b, c])

if reverse_num % 2 == 1:
    s = reversed(s)

s = deque(s)
for _ in range(len(revised_queries)):
    query = revised_queries.pop()
    f_b = query[0]
    c = query[1]
    if f_b == 1:
        s.appendleft(c)
    else:
        s.append(c)
print("".join(list(s)))







Measured memory_bytes: 61548
#include<iostream>
using namespace std;
int main(){
	int n,t=0;
	cin>>n;
	int a[n];
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]!=i)
		t++;
	}
	if(t==2 || t==0)cout<<"YES";
	else cout<<"NO";
	return 0;
	
	}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    
    int m = 0, sum = 0;
    for(int i = 0; i < N; i++){
      int n = Integer.parseInt(sc.next());
      sum += n;
      m = m < n ? n : m;
    }
    
    sum -= m;
    System.out.println(sum > m ? "Yes" : "No");
  }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M;
vector<pii> G[100010];
int use[100010], dis[100010];

int dfs(int cur, int d) {
  use[cur] = 1;
  dis[cur] = d;
  int res = 0;
  for (pii &e : G[cur]) {
    if (!use[e.first]) {
      res += dfs(e.first, dis[cur] + e.second);
    } else {
      res += (dis[e.first] != dis[cur] + e.second);
    }
  }
  return res != 0;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int L, R, D;
    cin >> L >> R >> D;
    L--; R--;
    G[L].emplace_back(R, D);
    G[R].emplace_back(L, -D);
  }
  int no = 0;
  for (int i = 0; i < N; i++) {
    if (use[i]) continue;
    no += dfs(i, 0);
  }
  cout << (no ? "No" : "Yes") << endl;

  return 0;
}

Measured memory_bytes: 12416
n = gets.to_i
a = gets.split.map(&:to_i)

tally = Hash.new { 0 }
a.each do |num|
  tally[num] += 1
end

not_banned = tally.values.inject(0) { |r, v| r + (v * (v - 1) / 2) }

puts a.map { |num| not_banned - (tally[num] - 1) }


Measured memory_bytes: 31236
object Main extends App {

  val Array(n, a, b) = io.StdIn.readLine.split(" ").map(_.toInt)

  val ans = (1 to n).par.foldLeft(0)( (acc,i) => {
    val sum = (1 to 5).foldLeft((i,0))( (acc,_) => {
      (acc._1 / 10, acc._2 + (acc._1 % 10))
    })._2
    if(a <= sum && sum <= b ) acc + i else acc
  })

  println(ans)
}

Measured memory_bytes: 32596
// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define in(x) 		scanf("%d", &x)
#define echo(x)		printf("%d", x)
#define inf 		(int)(1e18)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;

#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}

// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };


// Code from Here -------------------------------------------------------------------------------


signed main() {
	tezz



	int n;
	cin >> n;
	vi arr(n);
	map<int,int> mp;
	int ans = 0;
	for(int i=0; i<n; i++){
		cin >> arr[i];
		mp[arr[i]]++;
		ans+=arr[i];
	}
	int q,l,r;
	cin >> q;
	while(q--){
		cin >> l >> r;
		ans -= l*mp[l];
		ans += r*(mp[l]);
		mp[r]+=mp[l];
		mp[l]=0;
		cout << ans << endl;
	}


	return 0;
}  


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

int N, K;
vector<int> A;

int main () {
  cin >> N >> K;
  A.resize(N);
  rep(i,N) cin >> A[i];

  int ans = 1e9;
  for(int i = 0; i < K-1; i++){
    ans = min(ans, (N + i - 1 + K - 2)/(K-1));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640