akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

map<ll, int> factorize(ll n) {
    map<ll, int> factors;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++factors[i];
            n /= i;
        }
    }
    if (n != 1) { factors[n] = 1; }
    return factors;
}

vll get_divisors(const map<ll, int>& factors) {
    vll res = {1};
    for (pair<ll, int> elem : factors) {
        ll end = res.size();
        rep(i, 0, end) {
            ll pow = 1;
            rep(j, 1, elem.second + 1) {
                res.push_back(res[i] * elem.first * pow);
                pow *= elem.first;
            }
        }
    }
    return res;
}

ll calc(const ll n) {
    // O(sqrt(n)): Calculate the number of divisors of (n - 1) except for 1.
    map<ll, int> factors = factorize(n - 1);
    ll ans = 1;
    for (pair<ll, int> elem : factors) { ans *= (elem.second + 1); }
    --ans;

    // O(sqrt(n) + log(n)): Calculate divisors of n.
    vll divisors = get_divisors(factorize(n));

    // O(log(n))
    rep(i, 1, divisors.size()) {
        ll num = n, k = divisors[i];
        while (num % k == 0) { num /= k; }
        if (num % k == 1) { ++ans; }
    }

    return ans;
}

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

    ll n;
    cin >> n;
    cout << calc(n) << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    bool flg = true;
    int cnt = 0;
    while (flg) {
        flg = false;
        for (int i = 1; i < n; i++) {
            if (a[i] < a[i - 1]) {
                swap(a[i], a[i - 1]);
                cnt++;
                flg = true;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << a[i];
        if (i != n - 1) cout << " ";
    }
    cout << endl;
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3076
package main

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

type Tree [][]int

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	size := scanInt(sc)
	u := scanInt(sc)
	v := scanInt(sc)

	tree := make(Tree, size+1)
	for i := 0; i < size-1; i++ {
		a := scanInt(sc)
		b := scanInt(sc)
		tree[a] = append(tree[a], b)
		tree[b] = append(tree[b], a)
	}

	du := make([]int, size+1)
	calcDistances(tree, 0, u, du, 1)

	dv := make([]int, size+1)
	calcDistances(tree, 0, v, dv, 1)

	maxDv := 0
	for node, _ := range tree {
		if du[node] > dv[node] {
			continue
		}
		if maxDv < dv[node] {
			maxDv = dv[node]
		}
	}

	if maxDv > 0 {
		maxDv -= 1
	}
	fmt.Println(maxDv)
}

func calcDistances(tree Tree, parent, from int, ds []int, d int) {
	for _, child := range tree[from] {
		if child != parent {
			ds[child] = d
			calcDistances(tree, from, child, ds, d+1)
		}
	}
}


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

int main() {
    int n; cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            for (int k = j+1; k < n; k++) {
                int a = l[i], b = l[j], c = l[k];
                if (a == b or b == c or a == c) continue;
                if (a+b > c and a+c > b and b+c > a) ans++;
            }
        }
    }
    cout << ans << endl;
}


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

int a[1005];
int n;


void proc()
{
    for (int i =1; i <= n; i++)
    if (a[i] % 2 == 0)
    {
        if (a[i] % 3 == 0 || a[i] % 5 == 0) continue;
        cout << "DENIED";
        return;
    }
    cout << "APPROVED";
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    proc();
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
const int inf = 1000000000; //10^9
using ll = long long;
using P = pair<int,int>;
//加算代入演算子は+=！！！！！

// int main() {
//     double l;
//     cin >> l;
//     double x = l / 3; //縦、横、高さの長さは均等
//     double ans = pow(x, 3); //均等なので3乗で体積が求められる
//     printf("%.10f\n", ans); // %.桁数lf とすると小数点以下「桁数」だけ出力される
//     return 0;
// }

int main() {
    double l, ans;
    cin >> l;
    ans = (l / 3) * (l / 3) * (l / 3);
    cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 256
def get_substr(i, l, s):
    j = (i + l) % len(s)
    if j > i:
        return s[i:j]
    else:
        return s[i:] + s[:j]


s = input()
p = input()

for i in range(len(s)):
    if get_substr(i, len(p), s) == p:
        print('Yes')
        break
else:
    print('No')



Measured memory_bytes: 5564
#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() {
  double r, p = 6.28318530717958623200/2; cin >> r;
  cout << r * 2 * p << endl;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    auto tmp = lcm(x * (360 / x), 360);
    if(tmp == 360) cout << 360 / x << endl;
    else cout << tmp / x << endl;

    return 0;
}

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

using namespace std;

#define LIMIT 100
typedef pair<int64_t, int64_t> ii;
typedef int64_t ll;
int gcd(ll a, ll b) { return (b==0)?a:gcd(b, a%b); }
int lcm(ll a, ll b) { ll i=(a/gcd(a,b))*b; assert(i>0); return i; }

//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);

  string s; cin >> s;
  int x[4];

  for (int i = 0; i < 4; ++i) { x[i] = s[i]-'0'; }

  for(int i = 0; i < (1<<3); ++i){

    int o = x[0];
    string w = ""; w += s[0];

    for(int j = 0; j < 3; ++j){
      if( i&(1<<j) ){
        o += x[j+1];
        w += "+";
        w += (s[j+1]);
      }
      else{
        o -= x[j+1];
        w += "-";
        w += (s[j+1]);
      }
    }
    w+= "=7";

    if(o==7){
      std::cout << w << std::endl;
      return 0;
    }

  }

  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 K = sc.nextInt();
        int N = sc.nextInt();
        int[] A = new int[N];
        int maxDistance = 0;
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }

        for(int i=0;i<N;i++){
            if(i < N-1){
                maxDistance = Math.max(maxDistance,A[i+1] - A[i]);
            } else {
                maxDistance = Math.max(maxDistance,A[0] + K - A[i]);
            }
        }

        System.out.println(K - maxDistance);

    }

}









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

using namespace std;

#define MAX 100000

int n,A[MAX + 1],L[MAX];

/**
 最長増加部分列の長さを返す
*/
int lis(){
    L[0] = A[0];
    int length = 1;
    
    for(int i = 1;i < n;++i){
        if(L[length - 1] < A[i]){
            L[length++] = A[i];
        }else{
            *lower_bound(L,L + length,A[i]) = A[i];
        }
    }
    
    return length;
}

int main(){
    cin >> n;
    for(int i = 0;i < n;++i){
        cin >> A[i];
    }
    
    cout << lis() << endl;
    return 0;
}



Measured memory_bytes: 3876
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#define ll long long
#define INF 10000000000000000
#define MOD 998244353
using namespace std;


int main(){
    string s;
    cin >> s;
    int l=s.length();
    s+=s;
    
    string p;
    cin >> p;
    for(int i=0; i<l; i++){
        int ok=1;
        for(int j=0; j<p.length(); j++){
            if(s[i+j]!=p[j]){
                ok=0;
            }
        }
        if(ok==1){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    
    return 0;
}



Measured memory_bytes: 3224
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: i64,
    k: i64,
  }

  puts!("{}\n", cmp::min(n % k, k - n % k));
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
#define MAX_B 1001001
#define NIL -1
const int MOD = 1e9+7;
const int INF = 1 << 29;
const ll INFTY=1000000000000000000LL;
bool is_prime(int n){
   for(int i=2;i*i<=n;i++){
       if(n%i==0)return 0;
   }
   return 1;
}
int main(){
    int n;
    cin>>n;
    map<ll,ll>m;
    for(int i=2;i<=n;i++){
        int x=i;
       for(int j=2;j<=i;j++){
       while(x%j==0){
           x/=j;
           m[j]++;
       }
       }
    }
    ll ans=1;
    for(auto p:m){
        ans=ans*(p.second+1)%MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//region Template
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../debug_prettyprint.hpp"
#else
#define debug(...) 42
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#endif
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout<<fixed<<setprecision(12);
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
#define EXIT(answer) { cerr<<"EXIT #"<<__LINE__<<endl; cout<<answer<<endl; exit(0); }
#define sz(v) int(v.size())
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> istream& operator>>(istream& in, pair<T,U> &p) { in>>p.first>>p.second; return in; }
template<typename T> inline vector<T> READ(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
//endregion

int main() {
    FASTIO

    ll a; cin>>a;
    cout<<a+a*a+a*a*a<<endl;

}

Measured memory_bytes: 3640
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        
        Deque<Integer> list = new ArrayDeque<>();
        for(int i = 0; i < n; i++) {
            String cmd = sc.next();
            switch(cmd) {
                case "insert":
                list.addFirst(sc.nextInt());
                break;
                case "delete":
                list.remove((Integer)sc.nextInt());
                break;
                case "deleteFirst":
                list.removeFirst();
                break;
                case "deleteLast":
                list.removeLast();
            }
        }

        StringBuilder sb = new StringBuilder();
        while(true) {
            sb.append(list.removeFirst());
            if(!list.isEmpty()) {
                sb.append(" ");
            }else {
                break;
            }
        }
        System.out.println(sb);
        
        sc.close();
    }
}


Measured memory_bytes: 494324
// A - Ferris Wheel

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

int main() {
	int A, B;
	cin >> A >> B;

	int ans;

	if (A <= 5) {
		ans = 0;
	} else if (A <= 12) {
		ans = B / 2;
	} else {
		ans = B;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>


int main()
{
   int N;
   char S[10002];

   scanf("%d %s", &N, S);
   int s_len = strlen(S);


   for(int i=0; i<s_len; i++){
     printf("%c",(S[i] - 'A' + N)%26 + 'A');
   }
   /*char[int]は最初は空白すらない何かが格納されている
     char配列の各要素は「'A'」のように格納される
     'A'はprintfしたら%dでアスキー表で対応する整数、％cでAを出力
     Aは$c,%dもエラ-が起こる*/
    // printf("%d %d %c %c",A,S[0],'A',S[0]);



    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cmpfunc (const void * a, const void * b)
{
    if( *(long long int*)a - *(long long int*)b < 0 )
        return 1;
    if( *(long long int*)a - *(long long int*)b > 0 )
        return -1;
    return 0;
} // large from small

int main(){
  long long int n,m,i;
  scanf("%lld",&n);
  scanf("%lld",&m);
  long long int x[m];
  for(i=0;i<m;i++) {
    scanf("%lld",&x[i]);
  }
  if(n >= m) {
    printf("0\n");
  } else {
    qsort(x,m,sizeof(long long int),cmpfunc);
    long long int diff[m-1];
    for(i=0;i<m-1;i++) {
      diff[i] = x[i]-x[i+1];
    }
    qsort(diff,m-1,sizeof(long long int),cmpfunc);
    long long int ans = x[0]-x[m-1];
    for(i=0;i<=n-2;i++) {
      ans -= diff[i];
    }
    printf("%lld\n",ans);
  }
  return 0;
}


Measured memory_bytes: 2412
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p;

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

int main()
{
  ll N,K;
  cin >> N >> K;

  vector<ll> vec(N);
  for (ll i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  ll sum = 0;

  if(N<=K){
    cout << 0 << endl;
  }
  else{
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());

    for (ll i = 0; i < K; i++)
    {
      vec.at(i) = 0;
    }

    for (ll i = 0; i < N; i++)
    {
      sum += vec.at(i);
    }

    cout << sum << endl;
  }

}

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

int main(){
  string S;
  cin >> S;
  for(int i = 0; i < S.size(); i++){
    if(S[i] == '1') S[i] = '9';
    else if(S[i] == '9') S[i] = '1';
  }
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,ans=1,tp=0;
	cin>>n;
	int a[101010]={};
	cin>>a[0];
	FOR(i,1,n){
		cin>>a[i];
		if(tp==0){
			if(a[i]>a[i-1]){
				tp=1;
			}else if(a[i]<a[i-1]){
				tp=2;
			}
		}else if(tp==1){
			if(a[i]>a[i-1]){

			}else if(a[i]<a[i-1]){
				ans++;
				tp=0;
			}
		}else{
			if(a[i]>a[i-1]){
				ans++;
				tp=0;
			}else if(a[i]<a[i-1]){

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


Measured memory_bytes: 640
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

S = list(str(input()))
O = ['R', 'U', 'D']
E = ['L', 'U', 'D']

for i in range(len(S)):
    if (i + 1) % 2 != 0:
        if O.count(S[i]) == 0:
            print('No')
            break
    else:
        if E.count(S[i]) == 0:
            print('No')
            break
else:
    print('Yes')


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define N 300005
#define ll long long
#define db double
#define dbg(x) cout<<#x<<"="<<x<<"\n"
int n,a,b,cnt,tmp,ans[N],len;
int main()
{
//	freopen("1.in","w",stdout);
	scanf("%d%d%d",&n,&a,&b);
	if(a+b>n+1) return !puts("-1");
	if(1ll*a*b<n) return !puts("-1");
	for(int i=b;i;i--) ans[++len]=i;
	tmp=b,cnt=n-b-a+1;
	for(int i=2;i<=a;i++)
	{
		ans[++len]=tmp+min(cnt,b-1)+1,tmp=ans[len];
		for(int j=1;j<=min(cnt,b-1);j++) ans[++len]=tmp-j;
//		cout<<min(cnt,b)<<"\n";
		cnt-=min(cnt,b-1);
	}
//	cout<<n<<" "<<a<<" "<<b<<"\n";
	for(int i=1;i<n;i++) printf("%d ",ans[i]);
	printf("%d\n",ans[n]);
	return 0;
}

Measured memory_bytes: 3328
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		ArrayList<Data> list = new ArrayList<Data>();
		while(true){
			String str=sc.next();
			String[] d=str.split(",");
			int ids=Integer.parseInt(d[0]);
			int anss=Integer.parseInt(d[1]);
			if(ids+anss==0)break;
			list.add(new Data(ids, anss));
		}
		Collections.sort(list);
		while(sc.hasNext()){
			int num=sc.nextInt();
			int cnt=1;
			for(int k=1;k<list.size();k++){
				if(list.get(k).ans!=list.get(k-1).ans){
					cnt++;
				}
				if(list.get(k).id==num)break;
			}		
			if(list.get(0).id==num)cnt=1;
			System.out.println(cnt);
		}
	}
}
class Data implements Comparable<Data>{
	int id;
	int ans;
	public Data(int id, int ans) {
		this.id=id;
		this.ans=ans;
	}
	public int compareTo(Data o) {
		if(this.ans>o.ans)return -1;
		else if(this.ans<o.ans)return 1;
		return 0;
	}
}

Measured memory_bytes: 17212
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
 
int main() {
    string sd, t;
    cin >> sd >> t;

    if(sd.size() < t.size()){
        cout << "UNRESTORABLE";
        return 0;
    }

    bool didSet = false;

    for(int i=sd.size()-t.size(); i>=0; i--){
        bool canSet = true;
        for(int j = 0; j < t.size(); j++){
            if(sd[i+j] != t[j] && sd[i+j] != '?'){
                canSet = false;
                break;
            }
        }
        if(canSet){
            for(int j = 0; j < t.size(); j++){
                sd[i+j] = t[j];        
            }            
            for(int i = 0; i < sd.size(); i++){
                if(sd[i] == '?') sd[i] = 'a';
            }
            didSet = true;
            break;
        }   
    }


    if(didSet){
        cout << sd;
    }else{
        cout << "UNRESTORABLE";
    }
};

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

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

	vector<int> C(N);
	map<int, vector<int>> posi;
	for (int i = 0; i < N; i++) {
		cin >> C[i];
		posi[C[i]].push_back(i);
	}

	vector<ll> dp(N + 1);
	dp[0] = 1;
	for (int i = 1; i <= N; i++) {
		dp[i] = dp[i - 1];
		int id = lower_bound(posi[C[i-1]].begin(), posi[C[i-1]].end(), i)- posi[C[i-1]].begin()-1;
		//cout << "id=" << id << endl;
		if (id != 0) {
			if (posi[C[i - 1]][id - 1] + 1 != i-1) {
				//cout << posi[C[i - 1]][id - 1] << " " << i-1 << endl;
				dp[i] += dp[posi[C[i - 1]][id - 1]+1];
			}
		}
		dp[i] %= DIV;
	}
	/*
	for (int i = 1; i <= N; i++) {
		printf("dp[%d]=", i);
		cout << dp[i] << endl;
	}
	*/
	cout << dp[N] << endl;
}


Measured memory_bytes: 24448
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int h,w,n;
    cin >> h >> w >> n;
    int a[n],c[h][w];
    vector<int> b;
    rep(i,n) cin >> a[i];
    rep(i,n){
        rep(j,a[i]) b.push_back(i+1);
    }
    rep(i,h){
        rep(j,w) c[i][j] = b[w*i+j]; 
    }
    rep(i,h){
        if(i%2){
            for(int j=w-1;0<=j;j--) cout << c[i][j] << ' ';
            cout << endl; 
        }
        else{
           rep(j,w) cout << c[i][j] << ' ';
            cout << endl;
        }
    }
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int n,ans;
	cin >> n;
	int a, b, c;
	a = n / 100;
	b = (n - a * 100) / 10;
	c = (n - a * 100 - b * 10);
	int zoro,n_zoro;
	zoro = a * 100 + a * 10 + a;
	n_zoro = (a + 1) * 100 + (a + 1) * 10 + (a + 1);
	if (a == b && b == c) {
		cout << n << endl;
		return 0;
	}
	else {
		if (n < zoro) {
			cout << zoro << endl;
			return 0;
		}
		else {
			cout << n_zoro << endl;
			return 0;
		}
	}
	return 0;
}

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

int main(void) {
    int64_t n, sum; cin >> n >> sum;
    for(int x = 0; x <= n; ++x) {
        for(int y = 0; y<= n; ++y) {
            int z = n - x - y;
            if(z < 0 || n < z) continue;
            if(x * 10000 + y * 5000 + z * 1000 == sum) {
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}


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

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

ll fraction (ll n) {
    ll res = 1;
    for (ll i = n; i >= 1; i--) {
        res *= i;
    }
    return res;
}

const int MOD = 1000000007;

int main() {
    string a, b, c; cin >> a >> b >> c;
    char status = 'a';
    while (true) {
        cerr << a << endl;
        cerr << b << endl;
        cerr << c << endl;
        cerr << "-----------------" << endl;
        if (status == 'a') {
            if (a.empty()) break;
            status = a[0];
            a.erase(a.begin());
        }
        else if (status == 'b') {
            if (b.empty()) break;
            status = b[0];
            b.erase(b.begin());
        }
        else if (status == 'c') {
            if (c.empty()) break;
            status = c[0];
            c.erase(c.begin());
        }
    }
    status = toupper(status);
    cout << status << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k,ans;
int main()
{
     cin>>n>>k;
	 ans=1;
     for(int i=0;i<n;i++)
    {
        if(ans>k)
        {
            ans+=k;
        }
        else 
        ans*=2;

    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    int a[n-1];
    a[0]=0;
    for(int i=1;i<n;i++){
        if(s[i-1]=='A' && s[i]=='C'){
            a[i]=a[i-1]+1;
        }else{
            a[i]=a[i-1];
        }
    }
    int l[q],r[q];
    for(int i=0;i<q;i++){
        cin >> l[i] >> r[i];
        l[i]--;
        r[i]--;
        cout << a[r[i]]-a[l[i]] << endl;
    }
}


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

using namespace std;

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

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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()
#define fst first
#define sec	second
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef pair<long,long> P;

const int mod = 1e9 + 7;


int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	int a[6];
	int m=0, n=200;
	rep(i, 6){
		cin >> a[i];
		m = max(m, a[i]);
		n = min(n, a[i]);
	}

	if(m - n <= a[5]){
		cout << "Yay!" << endl;
	}else{
		cout << ":(" << endl;
	}




    return 0;
}



Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    switch(n){
        case 22:
            cout << "Christmas Eve Eve Eve";
            break;
        case 23:
            cout << "Christmas Eve Eve";
            break;
        case 24:
            cout << "Christmas Eve";
            break;
        case 25:
            cout << "Christmas";
            break;
    }
}

Measured memory_bytes: 256
from math import gcd
from functools import reduce
n = int(input())
a = list(map(int, input().split()))

# sieve[n]は、その数を最初にふるいに落とした数を格納
def prime_factor_table(n):
    # sieveとはふるいの意味
    sieve = [i for i in range(n+1)]
    # n以下の整数を最初にふるい落とす数(√n以下に必ず存在)を求める.
    for i in range(2, int(n**0.5)+1):
        if sieve[i] == i:
            for j in range(2*i, n+1, i):
                if sieve[j] == j:
                    sieve[j] = i
    return sieve

sieve = prime_factor_table(10**6+1)

def prime_factor(n):
    # 素数は英語でprime number
    prime = set()
    while n > 1:
        prime.add(sieve[n])
        n //= sieve[n]
    return prime

for i, v in enumerate(a):
    if i == 0:
        tmp = prime_factor(v)
    else:
        prime = prime_factor(v)
        for j in prime:
            if j in tmp:
                if reduce(gcd, a) == 1:
                    print("setwise coprime")
                    exit()
                else:
                    print("not coprime")
                    exit()
            tmp.add(j)
print("pairwise coprime")

Measured memory_bytes: 220400
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int cal(string s);
int  A, B;
string N;
int ANS=0;
int c;
int main(void){
	cin >> N >> A >> B;
	for (int i = 0; i < stoi(N); i++) {
		c = cal(to_string(i + 1));
		if (A <= c && c <= B) {
			ANS += i+1;
		}
	}
	cout << ANS << endl;
	system("pause");
	return 0;
}

int cal(string s) {
	int sum=0;
	int a;
	for (int i = 0; i < s.size(); i++) {
		a=s[i] - 48;
		sum += a ;
		
	}
	return sum;
}

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

int main()
{
    long long int a=2,b=1,c=0,n;
    scanf("%lld",&n);
    if(n == 0)
        printf("%lld\n",a);
    else if(n == 1)
        printf("%lld\n",b);
    else{
        for(int i = 1;i < n;i++){
            c = a + b;
            a = b;
            b = c;
        }
        printf("%lld\n",c);
    }

    return 0;
}


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

#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
int N;
vector<int> x,y;

bool check(vector<LL> v){
    FOR(i,1,N)if(v[i-1]>v[i])return false;
    return true;
}
void ins(int a,int b){
    x.pb(a);
    y.pb(b);
}
int main(){
    cin>>N;
    vector<LL> a(N);
    cin>>a;
    if(check(a)){
        cout<<0<<endl;return 0;
    }
    int id =0;
    FOR(i,1,N)if(abs(a[id])<abs(a[i]))id=i;
    REP(i,N){
        a[i]+=a[id];
        ins(id+1,i+1);
    }
    if(a[id]>0){
        FOR(i,1,N){
            a[i]+=a[i-1];
            ins(i,i+1);
        }
    }
    else{
        FOR(i,1,N){
            a[N-i-1]+=a[N-i];
            ins(N-i+1,N-i);
        }
    }
    assert(check(a));
    cout<<x.size()<<endl;
    REP(i,x.size()){
        cout<<x[i]<<" "<<y[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}


// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
};

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}



// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll a,b,k;
    cin >> a >> b >> k;
    ll a2 = max(0LL, a - k);
    k = max(k - a, 0LL);
    ll b2 = max(0LL, b - k);
    cout << a2 << " " << b2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int lcd(int a,int b){
	return a*b /(__gcd(a,b));
}
int main()
{	
    int ans=1,n; cin >>n;
    while(n--){
    	int k; cin >> k;
    	ans = lcd(ans,k);
    }

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



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //y1 j0 j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;



void Main(){

    ll N,K; cin>>N>>K;

    vector<pair<ll,ll>> ve;

    rep(i,N){
        ll t,d;
        cin>>t>>d;
        ve.emplace_back(d,t);
    }

    bool nonFirstNeta[N+1]={};

    sort(ALL(ve),greater<pair<ll,ll>>());

    ll netakind=0;

    // 種類の異なるもの
    // 上からKことって、種類を増やしていく
    bool check[N]={};
    rep(i,N){
        if(!nonFirstNeta[ve[i].second]){
            nonFirstNeta[ve[i].second]=true;
            check[i]=true;
            netakind++;
            //ve[i].first+=(netakind*netakind)-(netakind-1)*(netakind-1);
        }
    }

    ll ans=0;
    ll nowneta=0;

    rep(i,K){
        if(check[i]){
            ans+=nowneta*2+1;
            nowneta++;
        }
        ans+=ve[i].first;
    }

    ll left=K;
    ll right=K-1;

    ll tmp=ans;

    while(--left>=0 and nowneta<netakind){
        if(check[left]) continue;
        tmp-=ve[left].first;
        while(true){
            ++right;
            if(check[right]) break;
        }
        tmp+=ve[right].first;
        tmp+=nowneta*2+1;
        //cout<< tmp <<" "<< nowneta<<"\n";
        maxi(ans,tmp);
        nowneta++;
    }

    cout<< ans<<"\n";
}

//-----------------------------------
int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------


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

T[] readNumbers(T)() {
	return readln.chomp.split(" ").map!(to!T).array;
}

void readPair(T)(out T a, out T b) {
	auto xs = readNumbers!T;
	a = xs[0];
	b = xs[1];
}

int findMinMatch(int first, int last, const(int)[] ss, const(char)[] cs) {
	foreach (i;first..last) {
		auto s = i.to!string;
		auto matched = true;

		foreach (j;0..ss.length) {
			if (ss[j] >= s.length || s[ss[j]] != cs[j]) {
				matched = false;
			}
		}
		if (matched) return i;
	}
	return -1;
}

void main() {
	int n, m;
	int[] ss;
	char[] cs;
	
	readPair(n, m);

	foreach (i;0..m) {
		int s, c;
		readPair(s, c);
		ss ~= s - 1;
		cs ~= cast(char)c + '0';
	}

	switch (n) {
	case 3:
		findMinMatch(100, 1000, ss, cs).writeln;
		break;
	case 2:
		findMinMatch(10, 100, ss, cs).writeln;
		break;
	case 1:
		findMinMatch(0, 10, ss, cs).writeln;
		break;
	default:
		assert(false);
	}
}


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

int main(){
  int n, m;
  cin >> n;
  map<string, int> blue, red;
  vector<string> s;
  for (int i = 0; i < n; i++){
    string x;
    cin >> x;
    blue[x]++;
    s.push_back(x);
  }

  cin >> m;
  for (int i = 0; i < m; i++){
    string x;
    cin >> x;
    red[x]++;
  }

  int ans = -1e9;
  for (int i = 0 ; i < s.size(); i++){
    ans = max(ans, blue[s[i]] - red[s[i]]);
  }
  if (ans < 0) ans = 0;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)

using namespace std;
#define INF 1001001001

int main(){
	int N, K;
	cin >> N >> K;
	int h[N];
	REP(i,N) cin >> h[i];
	int dp[N + K];
	REP(i,N+K) dp[i] = INF;
	dp[0] = 0;
	REP(i,N){
        REP1(j,K+1){
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i] - h[i+j]));
        }
	}
	cout << dp[N - 1] << endl;
	return 0; 
}




Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <numeric>

using namespace std;

int main(){
	int n;
	while(cin >> n){
		if(n == 0) break;
		int m[n];
		for(int i = 0;i < n;i++) cin >> m[i];
		sort(m,m+n);
		cout << accumulate(m+1,m+n-1,0) / (n - 2) << endl;
	}
}

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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int a, b;
    cin >> a >> b;
    if(a > 9 || b > 9) cout << -1;
    else cout << a*b;
    return 0;
}


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

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

int main() {
  string S, T;
  ll N, M, g;
  cin >> N >> M;
  cin >> S >> T;

  g = gcd(N, M);
  for (ll i = 0; i < g; i++) {
    if (S[i * N / g] != T[i * M / g]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << N * M / g << endl;
  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
	int n;
	scanf("%d", &n);
	char str[5];
	int cwa=0, ctle=0, cre=0, cac=0;
	for(int i=0; i<n; i++){
		scanf("%s", str);
		if(str[0] == 'A'){
			cac++;
		}
		if(str[0] == 'W'){
			cwa++;
		}
		if(str[0] == 'T'){
			ctle++;
		}
		if(str[0] == 'R'){
			cre++;
		}
	}
	printf("AC x %d\n", cac);
	printf("WA x %d\n", cwa);
	printf("TLE x %d\n", ctle);
	printf("RE x %d\n", cre);
	
	return 0;
}

Measured memory_bytes: 1708
import java.util.Scanner
import java.util.ArrayList

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    var arraylist = ArrayList<Int>()
    var counter = 0
    for(i in 0 until N){
       arraylist.add(sc.nextInt())
    }
    for(i in 1 until N - 1){
       if(arraylist.elementAt(i-1) < arraylist.elementAt(i)){
          if(arraylist.elementAt(i) <= arraylist.elementAt(i+1)){
              counter++
          }
       }else if(arraylist.elementAt(i) > arraylist.elementAt(i+1)){
           counter++
       }
    }
    println(counter)
}

Measured memory_bytes: 29352
#include<iostream>
using namespace std;
int main(){
    char b;
    cin >> b;
    if(b=='A')
        cout << 'T' << endl;
    else if(b=='C')
        cout << 'G' << endl;
    else if(b=='G')
        cout << 'C' << endl;
    else if(b=='T')
        cout << 'A' << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
int main(){
    while (1){
        string a;
        cin >> a;
        if (a == "0") break;
        int ans =0;
        while (!a.empty()){
            int q=stoi(a.substr(a.size()-1));
            ans += q;
            a.pop_back();
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3156
N,x=map(int,input().split())


if x==1 or x==2*N-1:
    print("No")
elif N==2:
    print("Yes")
    for i in range(1,4):
        print(i)
else:
    lst=[0 for i in range(2*N-1)]
    nlst=set([i for i in range(1,2*N)])
    if x>=N:
        lst[N-1]=x
        lst[N]=x+1
        lst[N+1]=x-1
        lst[N-2]=x-2
        nlst.remove(x)
        nlst.remove(x+1)
        nlst.remove(x-1)
        nlst.remove(x-2)
    else:
        lst[N-1]=x
        lst[N]=x-1
        lst[N+1]=x+1
        lst[N-2]=x+2
        nlst.remove(x)
        nlst.remove(x-1)
        nlst.remove(x+1)
        nlst.remove(x+2)

    idxlst=set([i for i in range(2*N-1)])
    idxlst.remove(N-2)
    idxlst.remove(N-1)
    idxlst.remove(N)
    idxlst.remove(N+1)

    nlst=list(nlst)
    idxlst=list(idxlst)
    for n,i in zip(nlst,idxlst):
        lst[i]=n
    print("Yes")
    for i in lst:
        print(i)


Measured memory_bytes: 41988
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long s = sc.nextLong();
    long ans = (long)Math.pow(10, 12);
    if(n == s) {
      ans = n + 1;
    }  else {
    for(long b = 2; (b * b) <= n; b++) {
      long t = n;
      long c = 0;
      while(t > 0) {
        c += (t % b);
        t /= b;
      }
      if(c == s) {
        ans = Math.min(ans, b);
        break;
      }
    }
    for(long p = 1; (p * p) <= n; p++) {
      long q = s - p;
      if((q >= 0) && (n > q) && (((n - q) % p) == 0)) {
        long b = (n - q) / p;
        if((b > p) && (b > q)) {
          long t = n;
          long c = 0;
          while(t > 0) {
            c += (t % b);
            t /= b;
          }
          if(c == s) ans = Math.min(ans, b);
        }
      }
    }
    if(s == 1) ans = Math.min(ans, n);
    if(ans == (long)Math.pow(10, 12)) ans = -1;
    }
    System.out.println(ans);
  }
} 

Measured memory_bytes: 23764
import java.util.Arrays;
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);
    final int n = scanner.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = scanner.nextInt();
    }
    int[] b = Arrays.copyOf(a, a.length);
    Arrays.sort(b);
    int mid = b[n / 2 - 1];
    int mid1 = b[n / 2];
    for (int i = 0; i < n; i++) {
      if (a[i] <= mid) System.out.println(mid1);
      else System.out.println(mid);
    }
  }
}


Measured memory_bytes: 91480
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  ll mod = 998244353;
  ll N;
  cin >> N;
  v(ll) D(N);
  rep(i,N) {
    cin >> D[i];
  }
  if(D[0] != 0) {
    cout << 0 << endl;
    return 0;
  }
  v(ll) d(N,0);
  rep(i,N) {
    d[D[i]]++;
  }
  ll ans = 1;
  ll cnt = 1;
  ll i = 1;
  while(cnt < N){
    cnt += d[i];
    rep(j,d[i]) {
      ans *= d[i-1];
      ans %= mod;
    }
    i++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <functional>
#include <set>
using namespace std;

int main() {
  int h, w;
  while(cin >> w >> h, w || h) {
    vector<vector<bool> > qfield(h, vector<bool>(w)); // black: true, red: true
    int starty, startx;
    for(int y = 0; y < h; ++y) for(int x = 0; x < w; ++x) {
      char c;
      cin >> c;
      qfield[y][x] = (c == '#' ? false : true);
      if(c == '@') {
        starty = y;
        startx = x;
      }
    }
    set<pair<int, int> > countedPoses;
    function<int(int, int)> tileCount = [&](int y, int x) {
      int rtn = 0;
      if(y >= 0 && y < h && x >= 0 && x < w && qfield[y][x] && countedPoses.count(make_pair(y, x)) == 0) {
        countedPoses.insert(make_pair(y, x));
        int dy[] = {0, 1, 0, -1};
        int dx[] = {1, 0, -1, 0};
        for(int i = 0; i < 4; ++i) rtn += tileCount(y + dy[i], x + dx[i]);
        ++rtn;
      }
      return rtn;
    };
    cout << tileCount(starty, startx) << endl;
  }
  return 0;
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  N--;
  i64 first = 1;
  vector<i64> vec;
  vector<i64> sum;
  vec.push_back(1);
  sum.push_back(0);
  while(sum.back() <= N) {
    i64 v = vec.back();
    vec.push_back(v * 26);
    i64 s = sum.back();
    sum.push_back(s + v * 26);
  }
  string s = "";
  for(int i = vec.size() - 1; i --> 0;) {
    i64 ss = (N - sum[i]) / vec[i];
    s.push_back('a' + (N - sum[i]) / vec[i]);
    N -= (ss + 1) * vec[i];
  }
  cout << s << endl;
}



Measured memory_bytes: 3628
#include <stdio.h>
#include <stdbool.h>

int main(){
    int i, j, n;
    char mark;
    char marks[4]={'S', 'H', 'C', 'D'};
    int num;
    bool cards[4][13]={false};

    scanf("%d ", &n);
    for(i=0;i<n;i++){
        scanf("%c %d ", &mark, &num);
        for(j=0;j<4;j++){
            if(mark==marks[j]){
                cards[j][num-1]=true;
                break;
            }
        }
    }
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(!cards[i][j]){
                printf("%c %d\n", marks[i], j+1);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2072