akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        string s = cin.next();

        int ans = 0;

        switch (s)
        {
            case "SUN":
                ans = 7;
                break;
            case "MON":
                ans = 6;
                break;
            case "TUE":
                ans = 5;
                break;
            case "WED":
                ans = 4;
                break;
            case "THU":
                ans = 3;
                break;
            case "FRI":
                ans = 2;
                break;
            case "SAT":
                ans = 1;
                break;
        }

        WriteLine(ans);
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

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

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

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

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

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

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

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


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


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
typedef long double ld;
const int N  = 5e5+10;
const ll mod = 1e9+7;
const ll inf = 1e18;
 
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define iceil(n,x)      ((n)+(x)-1)/(x)
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define sp              <<" "<<

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;    }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }
ll choose2(ll n)   { ll ans=(n*(n-1))/2; return ans;  }
ll dist2(ll x1,ll y1,ll x2,ll y2){ ll ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return ans;}

vector<pll>graph[N];
bool color[N];
bool vis[N];

void dfs(ll v)
{
     vis[v]=1;
     
     for(auto x:graph[v])
     {
        ll d=x.second;
        ll u=x.first;
        if(!vis[u])
        {
          if(d%2==0)color[u]=color[v];
          else      color[u]=!color[v];
          dfs(u); 
        }
     }
}


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

     ll u,v,w;
     forn(i,0,n-1)
     {
          cin>>u>>v>>w;
          graph[u].pb({v,w});
          graph[v].pb({u,w});
     }
     color[1]=1;
     dfs(1);
     forn(i,1,n+1)
     cout<<color[i]<<endl; 

     return 0;
} 

Measured memory_bytes: 18304
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include<cstdio>
#include <vector>
#include<queue>
#include<limits.h>
#include<string.h>
#include<functional>
using namespace std;

signed main() {
	int a;
	for (int i = 1; cin >> a, a; i++) {
		printf("Case %d: %d\n", i, a);
	}
}

Measured memory_bytes: 3108
N=int(input())
H=list(map(int,input().split()))

dp=[0 for i in range(N)]
dp[1]=abs(H[1]-H[0])

for i in range(2,N):
    dp[i]=min(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))
print(dp[N-1])


Measured memory_bytes: 13980
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, p, ans = 0;
  scanf("%lld%lld", &n, &p);
  char s[n + 10];
  scanf("%s", s);
  ll mod[n], cnt[p], mul[n];
  for(i = 0; i < p; ++i) cnt[i] = 0;
  mul[0] = 1;
  for(i = 1; i < n; ++i) mul[i] = (mul[i - 1] * 10) % p;
  if(p == 2) {
    for(i = 0; i < n; ++i) if(!((s[i] - '0') & 1)) ans += i + 1;
  } else if(p == 5) {
    for(i = 0; i < n; ++i) if(!((s[i] - '0') % 5)) ans += i + 1;
  } else {
    mod[0] = (s[n - 1] - '0') % p;
    for(i = 1; i < n; ++i) mod[i] = (mod[i - 1] + (s[n - 1 - i] -'0') * mul[i]) % p;
    for(i = 0; i < n; ++i) {
      if(!mod[i]) ans++;
      ans += cnt[mod[i]]++;
    }
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 3584
N = int(input())
li = list(map(int, input().split()))

try:
  position1 = li.index(1)        
except:
  print(-1)
  exit()  
  
kowasu = position1
target = 2
position = position1 + 1
while True:
  flag = False
  for i in range(position, len(li)):
    if li[i] == target:
      flag = True
      kowasu += i - position
#      print(kowasu)
#      print(i)
      tekito = i
      break
  if flag:
    target += 1
    if tekito == len(li) - 1:
      break
    position = tekito + 1
  else:
    kowasu += len(li) - position
    break
print(kowasu)
  
    
  
  


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

int main(){
  int n;cin >> n;
  int d[n][2];
  rep(i,n){
    cin >> d[i][0] >> d[i][1];
  }
  for(int i=0;i<n-2;++i){
    if(d[i][0] == d[i][1]){
      if(d[i+1][0] == d[i+1][1]){
        if(d[i+2][0] == d[i+2][1]){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

/**
 * @author: pashka
 */

var cost = IntArray(3)
var letters = "spr"

fun calc(s: String) : Int {
    var d = IntArray(3)
    var n = s.length
    for (i in 0 until n) {
        var d2 = IntArray(3)
        for (x in 0..2) {
            for (y in 0..2) {
                if (x == y) continue
                var dd = d[y]
                if (s[i] == letters[x]) {
                    dd += cost[x]
                }
                d2[x] = Math.max(d2[x], dd)
            }
        }
        d = d2
    }
    var res = 0
    for (x in d) {
        res = Math.max(res, x)
    }
    return res
}

private fun solve() {
    var n = nextInt()
    var k = nextInt()
    cost[0] = nextInt()
    cost[1] = nextInt()
    cost[2] = nextInt()
    var t = next()
    var res = 0
    for (i in 0 until k) {
        var sb = StringBuilder()
        for (j in i until n step k) {
            sb.append(t[j])
        }
        res += calc(sb.toString())
    }
    println(res)
}

fun main(args: Array<String>) {
    solve()
    out.close()
}

private var br = BufferedReader(InputStreamReader(System.`in`))
private var st: StringTokenizer? = null
private var out = PrintWriter(System.out)

@Throws(IOException::class)
private fun next(): String {
    while (st == null || !st!!.hasMoreTokens()) {
        st = StringTokenizer(br.readLine())
    }
    return st!!.nextToken()
}

@Throws(IOException::class)
private fun nextInt(): Int {
    return next().toInt()
}

@Throws(IOException::class)
private fun nextLong(): Long {
    return next().toLong()
}


Measured memory_bytes: 41276
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<long double> x(n);
  vector<string> u(n);
  for(int i=0;i<n;i++)cin>>x.at(i)>>u.at(i);
  long double ans=0;
  for(int i=0;i<n;i++){
    if(u.at(i)=="BTC"){
      x.at(i)*=380000;
      ans+=x.at(i);
    }else{
      ans+=x.at(i);
    }
  }
  cout<<fixed<<setprecision(10)<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      solve(sc);
    }
  }

  static void solve(Scanner sc) {
    int n = sc.nextInt();
    int[] S = new int[n];
    for (int i = 0; i < n; i++) {
      S[i] = sc.nextInt();
    }

    int q = sc.nextInt();
    int sum = 0;
    for (int i = 0; i < q; i++) {
      if (binarySearch(S, sc.nextInt()) != -1)
        sum++;
    }

    System.out.println(sum);
  }

  static int binarySearch(int[] arr, int target) {
    // 探索範囲
    int begin = 0;
    int end = arr.length;

    while (begin < end) {
      int center = (begin + end) / 2;
      if (arr[center] == target) {
        return center;
      } else {
        if (arr[center] > target) {
          end = center;// 前を探す
        } else {
          begin = center + 1;// 後ろを探す
        }
      }
    }
    return -1;
  }
}



Measured memory_bytes: 66904
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

struct itm{
	string str;
	int w;
	int s;
	bool f;
};

int main()
{
	int n, w, p;
	itm it[11];
	string st[11];
	bool f;
	
	while(cin >> n && n){
		w = p = 0;
		for(int i = 0; i < n; i++){
			cin >> it[i].str >> it[i].w >> it[i].s;
			w += it[i].w;
			it[i].f = true;
		}
		
		for(int i = 0; i < n; i++){
			f = false;
			for(int j = 0; j < n; j++){
				if(it[j].f && it[j].s >= (w-it[j].w)){
					f = true;
					p = j;
					for(int k = j+1; k < n; k++){
						if(it[k].w > it[p].w && it[k].f && it[k].s >= (w-it[k].w)){
							p = k;
						}
					}
				}
				if(f){
					break;
				}
			}
			if(f){
				st[i] = it[p].str;
				w -= it[p].w;
				it[p].f = false;
				cout << it[p].str << endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n;
	cin >> n;
	vector<string> s(n);
	unordered_set<string> ss;
	REP(i, n) {
		cin >> s[i];
		ss.insert(s[i]);
	}
	cout << ss.size() << endl;
	return 0;
}


Measured memory_bytes: 23904
def calcCost(ave_num, num):
    cost = (num - ave_num) ** 2
    return cost

N = int(input())
numbers = [int(i) for i in input().split()]

if len(set(numbers)) == 1:
    print(0)
else :
    
    ave_num = round(sum(numbers) / N)

    total_cost = 0
    for num in numbers:
        total_cost += calcCost(num, ave_num)
    
    print(total_cost)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

int main()
{ 
    int n;
    cin>>n;
    int min=n+1;
    int ans=0;
    for(int i=0;i<n;i++){
        int p=0;
        cin>>p;
        if(min>=p){min=p;ans++;}
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){

  int a,b,c,i,j,k,l,N,cnt=0;
  scanf("%d",&N);
  int A[N];
  for(k=0;k<N;k++){
    scanf("%d",&A[k]);
  }
  for(i=0;i<N;i++){
    for(j=N-1;j>i;j--){
      if(A[j-1]>A[j]){
	c=A[j];
	A[j]=A[j-1];
	A[j-1]=c;
	cnt++;
	  }
     
    }
    if(i==N-1){
      printf("%d\n",A[i]);
    }else printf("%d ",A[i]);
  }
 
  printf("%d\n",cnt);

  return 0;
}



Measured memory_bytes: 2124
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long ll;
const int MOD=924844033;
const int MAXN=2005;

int n,m,ncnt;
int ed[MAXN*2];
ll f[MAXN],d[MAXN*2][MAXN][2],fac[MAXN];
bool vis[MAXN][2];

void Init(){
    fac[0]=1;
    for(int i=1;i<MAXN;i++)
        fac[i]=fac[i-1]*i%MOD;
}

int main(){

    Init();
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=0;j<=1;j++){
            if(vis[i][j]) continue;
            for(int x=i,y=j;x<=n;x+=m,y^=1)
                vis[x][y]=1,ncnt++;
            ed[ncnt]=1;
        }
    ed[0]=1;
    d[0][0][0]=1;
    for(int i=0;i<2*n;i++)
        for(int j=0;j<=n;j++){
            d[i+1][j][0]=(d[i][j][0]+d[i][j][1])%MOD;
            if(!ed[i]) d[i+1][j+1][1]=d[i][j][0];
        }
    for(int i=0;i<=n;i++) f[i]=(d[2*n][i][0]+d[2*n][i][1])%MOD;
    ll ans=0;
    for(int i=0,k=1;i<=n;i++,k*=-1)
        ans=(ans+1ll*k*fac[n-i]*f[i]%MOD)%MOD;
    printf("%lld\n",(ans+MOD)%MOD);

    fclose(stdin);
    fclose(stdout);
}


Measured memory_bytes: 125568
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323

//int calc1(float a,float b,float c,float d,float e,float f,float *x,float *y);
//void quick(int *,long long,long long);
//int comp(char *a,char *b);

int main(){
	
	int i,j,n,l[11],v1,v2,s;
	float t,a1;
	int a2;

	while(scanf("%d,",l+1)!=EOF){
		s=l[1];
		for(i=2;i<=10;i++){
			scanf("%d,",l+i);
			s+=l[i];
		}
		scanf("%d,%d",&v1,&v2);
		t=(float)s/(v1+v2);
		a1=t*v1;
		a2=(int)(a1*1000+0.5);
		i=0;
		while(a2>0){
			i++;
			a2-=l[i]*1000;
		}
		printf("%d\n",i);
	}	
	return 0;
}

Measured memory_bytes: 596
n = int(input())
h = list(map(int, input().split()))
h += [0]
ans = 0

if n<=2:
    print(max(h))
else:
    while True:
        count = 0
        for i in range(n):
            if h[i]!=0 and h[i+1]==0:
                count += 1
        for i in range(n):
            if h[i]!=0:
                h[i] -= 1
        ans += count
        if all([i==0 for i in h]):
            print(ans)
            exit()


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> rot = {
  {4, 2, 0, 3, 1, 5},
  {2, 4, 1, 3, 0, 5},
  {5, 3, 2, 0, 4, 1},
  {3, 5, 2, 1, 4, 0},
};
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
set<vector<int>> g[101][101];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> in(h);
  for (int i = 0; i < h; i++) cin >> in[i];
  g[0][0].insert({6, 1, 2, 3, 5, 4});
  vector<pair<int, int>> que;
  vector<vector<bool>> vis(h, vector<bool>(w));
  vis[0][0] = true;
  que.emplace_back(0, 0);
  for (int u = 0; u < (int) que.size(); u++) {
    for (int i = 0; i < 4; i++) {
      int x = que[u].first + dx[i];
      int y = que[u].second + dy[i];
      if (x < 0 || x >= h || y < 0 || y >= w || in[x][y] == '#') continue;
      for (auto& v : g[que[u].first][que[u].second]) {
        vector<int> nxt(6);
        for (int j = 0; j < 6; j++) {
          nxt[rot[i][j]] = v[j];
        }
        if (nxt[0] != (in[x][y] - '0')) continue;
        g[x][y].insert(nxt);
        if (!vis[x][y]) {
          vis[x][y] = true;
          que.emplace_back(x, y);
        } else {
        }
      }
    }
  }
  // for (int i = 0; i < h; i++) {
  //   for (int j = 0; j < w; j++) cerr << vis[i][j] << " ";
  //   cerr << endl;
  // }
  cout << (vis[h - 1][w - 1] ? "YES\n" : "NO\n");
  return 0;
}


Measured memory_bytes: 4460
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

int a[100];
int main(){
  int n;cin>>n;
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  reverse(a,a+n);
  int ans=0;
  rep(i,n)ans+=a[i]*(i%2==0?1:-1);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
s =[input() for i in range(N)]
M = int(input())
t =[input() for i in range(M)]
ansmx= -100
ans=0

strset =set(s+t)
strlist = list(strset)

for i in range(len(strlist)):
    str1=strlist[i]
    ans = s.count(str1)-t.count(str1)
    if ans>ansmx:
        ansmx = ans
if ansmx <0:
    print(0)
else:
    print(ansmx)

Measured memory_bytes: 3064
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A[2];
	int K;
	cin >> A[0] >> A[1] >> K;

	rep(i, 0, K)
	{
		if (A[i % 2] % 2 == 1)
		{
			A[i % 2]--;
		}
		A[(i + 1) % 2] += A[i % 2] / 2;
		A[i % 2] /= 2;
	}

	cout << A[0] <<" "<< A[1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define M (L+R)/2
#define N 500009
#define inf 99999999999
#define ll long long
#define mod 1000000007
using namespace std;
ll n,k,s,a[N];
int main(){

	ios::sync_with_stdio(0);
	
	cin>>n>>k>>s;
	
	for(int i=1;i<=k;i++){
		a[i]=s;
	}
	if(s>n-k){
		for(int i=k+1;i<=n;i++){
			a[i]=1;
		}
	} else {
		for(int i=k+1;i<=n;i++){
			a[i]=999999999;
		}
	}
	
	for(int i=1;i<=n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;

	return 0;
}



Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (unsigned long long i = 0; i < (n); i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  string s, t;
  cin >> s >> t;
  ll END = -1;
  REP(i, s.size() - t.size() + 1) {
    bool f = 1;
    REP(j, t.size()) {
      if (s[i + j] != '?' && s[i + j] != t[j])
        f = 0;
    }
    if (f)
      END = i;
  }
  if (END < 0)
    return !printf("UNRESTORABLE\n");
  REP(i, s.size()) {
    if (i < END || i >= END + t.size())
      cout << (s[i] == '?' ? 'a' : s[i]);
    else
      cout << t[i - END];
  }
  printf("\n");
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            long N = long.Parse(Console.ReadLine());
            long ans = 0;
            for (long i = 1; i <= N-1; i++)
            {
                ans += i;
            }
            
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

    ll temp = N;
    ll sum = 0;
    while (temp > 0) {
        sum += temp % 10;
        temp /= 10;
    }

    cout << (N % sum == 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//#pragma warning( disable : 4996 )
#define ll long long
#define pb push_back
#define endl '\n'
#define fastIO cin.tie( 0 );ios_base::sync_with_stdio( false )
#define pii pair<int, int>
#define eps 1e-13
#define N 14

using namespace std;

inline void init()
{
    int a, b, c;
    cin >> a >> b >> c;
    if ( a < b )
        swap( a, b );
    if ( c <= a && c >= b )
        cout << "Yes";
    else
        cout << "No";
}

inline void solve()
{
    cout << endl;
}

int main()
{
    fastIO;
    init();
    solve();

    return 0;
}


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

int dp[100009]; vector<int>vec;

int main() {
	int u1 = 1; for (int i = 0; i < 10; i++) { vec.push_back(u1); u1 *= 6; }
	int u2 = 1; for (int i = 0; i < 8; i++) { vec.push_back(u2); u2 *= 9; }

	for (int i = 0; i <= 100000; i++) dp[i] = 10000;
	dp[0] = 0;
	for (int i = 0; i <= 100000; i++) {
		for (int j : vec) {
			if (i + j <= 100000) dp[i + j] = min(dp[i + j], dp[i] + 1);
		}
	}
	int n; cin >> n;
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N;
  cin>>N;
  string ans="ABC";
  if(N>=1000)
    ans="ABD";
  cout<<ans;
  }


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        Dice dice = new Dice(str);
        int n = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();
        String str2[];
        int i,j=0;
        while(n-->0){
            str2 = br.readLine().split(" ");
            for(i=0;i<6;i++){
                if(dice.getStr(i).equals(str2[0])) break;
            }
            switch(i){
                case 0:
                    break;
                case 1:
                    dice.moveN();
                    break;
                case 2:
                    dice.moveW();
                    break;
                case 3:
                    dice.moveE();
                    break;
                case 4:
                    dice.moveS();
                    break;
                case 5:
                    dice.moveN();
                    dice.moveN();
                    break;
            }
            for(i=1;i<5;i++){
                if(dice.getStr(i).equals(str2[1])) break;
            }
            switch(i){
                case 1:
                    j = 2;
                    break;
                case 2:
                    j = 4;
                    break;
                case 3:
                    j = 1;
                    break;
                case 4:
                    j = 3;
                    break;
                default:
                    break;
            }    
            sb.append(dice.getStr(j)).append("\n");
        }
        System.out.print(sb);
    }
}

class Dice{
    private String str[];//0=???,1=???,2=???,3=???,4=??????,5=???
    private String tmp;
    
    Dice(String str) {
        this.str = new String[6];
        this.str = str.split(" ");
    }
    
    public String getStr(int n){
        return this.str[n];
    }
    
    void moveW(){
        tmp = this.str[0];
        this.str[0] = this.str[2];
        this.str[2] = this.str[5];
        this.str[5] = this.str[3];
        this.str[3] = tmp;
    }
    
    void moveE(){
        tmp = this.str[0];
        this.str[0] = this.str[3];
        this.str[3] = this.str[5];
        this.str[5] = this.str[2];
        this.str[2] = tmp;
    }
    
    void moveS(){
        tmp = this.str[0];
        this.str[0] = this.str[4];
        this.str[4] = this.str[5];
        this.str[5] = this.str[1];
        this.str[1] = tmp;
    }
    
    void moveN(){
        tmp = this.str[0];
        this.str[0] = this.str[1];
        this.str[1] = this.str[5];
        this.str[5] = this.str[4];
        this.str[4] = tmp;
    }
}

Measured memory_bytes: 24096
n = int(input())
s = str(input())
ok = "Yes"
if n == 1:
    ok = "No"
if n % 2 == 1:
    ok = "No"
for i in range (0, n//2):
    if s[i] != s[i + n // 2] :
        ok = "No" 
print(ok)

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

void con(char a[101],int *b){
    int i;
    for(i=0;i<strlen(a);i++){
        if(a[i]=='I'){
            *b=1;
        }
        else if(a[i]=='V'){
            *b=5;
        }
        else if(a[i]=='X'){
            *b=10;
        }
        else if(a[i]=='L'){
            *b=50;
        }
        else if(a[i]=='C'){
            *b=100;
        }
        else if(a[i]=='D'){
            *b=500;
        }
        else if(a[i]=='M'){
            *b=1000;
        }
        b++;
    }
    
}

int main(int argc, const char * argv[]) {
    char roman[101]={};
    int i,sum=0,num[101]={};
    
    while(scanf("%s",roman)!=EOF){
        con(roman,num);
        for(i=0;i<strlen(roman);i++){
            //printf("roman[%d]:%c num[%d]:%d\n",i,roman[i],i,num[i]);
            if(num[i]>=num[i+1]){
                sum+=num[i];
            }
            else{
                sum-=num[i];
            }
        }
        printf("%d\n",abs(sum));
        sum=0;
        for(i=0;i<101;i++){
            roman[i]=0;
            num[i]=0;
        }
    }
    return 0;
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
#define F(i, x, y) for (int i = (x); i <= (y); ++i)
#define Fr(i, x, y) for (int i = (x); i < (y); ++i)
using namespace std;
typedef long long ll;

const int N = 200005;
int n, t, a[N];
int main() {
	ios::sync_with_stdio(0);
	cin >> n >> t;
	F(i, 1, n) cin >> a[i];
	int lst = 0, ans = 0;
	F(i, 1, n) {
		if (a[i] <= lst) ans += t - (lst - a[i]), lst = (a[i] + t);
		else ans += t, lst = a[i] + t;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 4360
#include<bits/stdc++.h>
using namespace std;
int n ;
int main(){
    cin >> n;
    n = n % 10;
    if(n == 3)
        cout << "bon";
    else if(n == 0 || n == 1 || n == 6 || n == 8)
        cout << "pon" ;
    else cout << "hon";
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

#define MAX 256

int main(void){
	int n, m;

	scanf("%d%d", &n, &m);

	int a[n][m] = { 0 };
	int b[m] = { 0 };
	int c[n] = { 0 };

	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			scanf("%d", &a[i][j]);
		}
	}

	for (int i = 0; i < m; i++){
		scanf("%d", &b[i]);
	}

	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			c[i] += a[i][j] * b[j];
		}
	}

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

	return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  ll a, b , n;
  cin >> a >> b >> n;

  ll x;
  if (b <= n) {
    x = b - 1;
  } else {
    x = n;
  }

  cout << a * (x % b) / b << endl;
  return 0;
}


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

int main() {
	int a;
	cin >> a;
	cout << a / 100 + ((a - a / 100 * 100) / 10) + ((a - a / 100 * 100) - (a - a / 100 * 100) / 10 * 10) << endl;
}

Measured memory_bytes: 256
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
cnt=0
for i in range(n):
  A = bisect.bisect_left(a, b[i])
  C = n-bisect.bisect_right(c, b[i])
  cnt+=A*C
print(cnt)

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod = 1e9+7;

int d;
vector<int> c;
vector<vector<int>> s;
vector<int> last(26, 0);

ll calculate(int date, int choice) {
    ll ans = 0;
    ans += s[date][choice];
    last[choice] = -1;
    rep (i, 26) {
        last[i]++;
        ans -= last[i] * c[i];

    }
    return ans;
}

vector<int> argsort(vector<int> v) {
    vector<int> indices(v.size());
    iota(indices.begin(), indices.end(), 0);
    // ソートする。
    sort(indices.begin(), indices.end(), [&v](int i1, int i2) {
        return v[i1] < v[i2];
    });
    return indices;
}

int greedy(int date) {
    vector<int> score(26, 0);
    rep (i, 26) {
        score[i] = s[date][i] + last[i] * c[i];
    }
    vector<int> indices = argsort(score);
    last[indices[25]] = 0;
    return indices[25];
}

int main() {
    cin >> d;
    c.resize(26);
    rep (i, c.size()) {
        scanf("%d", &c[i]);
    }
    s.resize(d, vector<int>(26));
    rep (i, d) {
        rep (j, c.size()) {
            cin >> s[i][j];
        }
    }
    ll default_score = 0;
    vector<int> default_res(d);
    rep (i, d) {
        default_res[i] = greedy(i);
        default_score += calculate(i, default_res[i]);
    }
    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<> rand26(0, 25), rand365(0, 364);

    rep (i, 100000) {
        int p = rand26(mt);
        int q = rand365(mt);
        auto changed_res = default_res;
        changed_res[q] = p;
        ll changed_score = 0;
        rep (j, 26) {
            last[j] = 0;
        }
        rep (j, d) {
            changed_score += calculate(j, changed_res[j]);
        }
        if (changed_score > default_score) {
            default_res = changed_res;
            default_score = changed_score;
        }
    }

    rep (i, d) {
        cout << default_res[i] + 1 << endl;
    }
}




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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	string n;
	cin>>n;
	int len = n.size();
	int sum = 0;
	for(int i=0;i<len;i++){
		sum += (n[i] - '0');
	}
	if(sum % 9 == 0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
};

Measured memory_bytes: 3696
MOD = 1000000007

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

digits = [0] * 60
for i in A:
    for j in range(60):
        if i>>j&1 == 1:
            digits[j] += 1

ans = 0
for i in range(60):
    ans += digits[i] * (N - digits[i]) * (1<<i)
    ans %= MOD

print(ans)

Measured memory_bytes: 122936
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int[] s = new int[n];
			for(int i = 0; i < n; i++){
				s[i] = sc.nextInt();
			}
			Arrays.sort(s);
			int sum = 0;
			for(int i = 1; i < n-1; i++){
				sum += s[i];
			}
			int ans = (int)sum/(n-2);
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 28880
#include <iostream>
#include <bitset>
#include <cmath>

using namespace std;

typedef long long ll;

ll D,G;
ll p[10];
ll c[10];
ll score[10];

int main(){
    ll ans = 0;
    cin >> D >> G;
    for(int i=0;i<D;i++){
        cin >> p[i] >> c[i];
        score[i] = 100 * (i+1) * p[i] + c[i];
        ans += p[i];
    }
    for(int i=0;i<(1<<D);i++){
        bitset<10> bs(i);
        ll s = 0;
        ll a = 0;
        for(int j=0;j<D;j++){
            if(bs[j]){
                s += score[j];
                a += p[j];
            }
        }
        if(s > G) continue;
        for(int j=0;j<D;j++){
            if(bs[j]) continue;
            if(s + score[j] < G) continue;
            ll q = (G-s) / (100 * (j+1));
            if((G-s) % (100*(j+1)) != 0) q++;
            ans = min(a + min(p[j], q), ans);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int direction = 90;
		double x = 0;
		double y = 0;
		while(true) {
			String s = sc.next();
			String[] sp = s.split(",");
			int step = Integer.valueOf(sp[0]);
			int rotation = -Integer.valueOf(sp[1]);
			if (step == 0) {
				break;
			}
			x += Math.cos(Math.toRadians(direction)) * step;
			y += Math.sin(Math.toRadians(direction)) * step;
			direction += rotation;
		}
		System.out.println((int) x);
		System.out.println((int) y);
	}

}

Measured memory_bytes: 17216
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int H, W;

		while (true) {
			H = scanner.nextInt();
			W = scanner.nextInt();

			if (H == 0 && W == 0)
				break;

			for (int i = 0; i < H; i++) {
				for (int i2 = 0; i2 < W; i2++) {
					System.out.print("#");
				}

				System.out.println();
			}

			System.out.println();
		}
	}
}

Measured memory_bytes: 34744
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   int n;
           cin>>n;
           int f=55555;
// エラトステネスのふるい
   bitset<1000010> is_prime(0);
           rep(i,2,f+1)is_prime.set(i);
           rep(i,2,f+1){
             if(is_prime[i]){
               for(int j=2*i;j<=f;j+=i){
                 is_prime.reset(j);
               }
             }
           }
           int cnt=0;
     rep(i,2,f){
       if(is_prime[i]&&i%5==1){
         cout<<i<<" ";
         cnt++;
         if(cnt==n){
           //cout<<cnt<<endl;
           break;
         }
       }
       
     }
           
           
           
          }

Measured memory_bytes: 3728
class NormalInput {
  input: string[];
  pointer: number;
  constructor(raw: string) {
    this.input = raw.split(/ |\n/);
    this.pointer = 0;
  }
  int = (): number => {
    const ret = parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  };
  str = (): string => {
    const ret = this.input[this.pointer];
    this.pointer++;
    return ret;
  };
  strs = (length: number): string[] => {
    let ret: string[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.str());
    }
    return ret;
  };
  ints = (length: number): number[] => {
    let ret: number[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.int());
    }
    return ret;
  };
}
function rep(n: number) {
  let a = [];
  for (let i = 0; i < n; i++) a.push(i);
  return a;
}
function Main({ int, str, strs, ints }: NormalInput) {
  const L = int();
  console.log(L*L*L/27);
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 7372
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

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

using namespace std;

typedef pair<int,int> s;
typedef long long int ll;

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}
int x,a,b;

int main(int argc, char const *argv[])
{
  scanf("%d %d %d",&x, &a, &b);
  if(abs(x-a)>abs(x-b)){
    printf("B\n");
  }else{
    printf("A\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>


int main(void)
{
	int W, H, x, y, r, w, h;
	scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
	w = W - r;
	h = H - r;
	    if (r <= x && x <= w && r <= y && y <= h) printf("Yes\n");

		if (!(r <= x) || !(x <= w) || !(r <= y) || !(y <= h)) printf("No\n");
		

	return 0;
}

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

int main() {
    string w;
    cin >> w;
    for (int i = 0; i < w.size(); i++) {
        w[i] = tolower(w[i]);
    }
    string t;
    cin >> t;
    int c = 0;
    while (1) {
        if (t == "END_OF_TEXT") break;
        for (int i = 0; i < t.size(); i++) {
            t[i] = tolower(t[i]);
        }
        if (t == w) c += 1;
        cin >> t;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3144
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    f = {}
    p = {}
    l = [-1] * N
    for i, v in enumerate(A):
        if v not in f:
            f[v] = i
            p[v] = i
        else:
            l[p[v]] = i
            p[v] = i
    t = 0
    r = 0
    while r < K - 1:
        if l[t] == -1:
            r += 1
            t = f[A[t]] + 1
        else:
            t = l[t] + 1
        if t == N:
            r += 1
            r = K - (K % r)
            t = 0
    a = []
    while t < N:
        if l[t] == -1:
            a.append(A[t])
            t += 1
        else:
            t = l[t] + 1
    print(' '.join(str(i) for i in a))
main()


Measured memory_bytes: 128448
#include<stdio.h>

struct Card{
  char suit;
  char value;
};


void BubbleSort(struct Card *A, int length) {

  int i, j;
  char tmp;
  char tmp1;

  for(i = 0; i < length; i++) {
    for(j = length-1; j > i; j--) {
      if(A[j].value < A[j-1].value) {

	tmp = A[j].value;
	tmp1 = A[j].suit;

	A[j].value = A[j-1].value;
	A[j].suit = A[j-1].suit;

	A[j-1].value = tmp;
	A[j-1].suit = tmp1;

      }
    }
  }
}

void SelectionSort(struct Card *A,int length) {

  int i, j, mini;
  char tmp;
  char tmp1;

  for(i = 0; i < length; i++) {
    mini = i;
    for(j = i; j < length; j++) {
      if(A[j].value < A[mini].value) {
	mini = j;
      }
    }
    if(i != mini) {
    tmp = A[i].value;
    tmp1 = A[i].suit;

    A[i].value = A[mini].value;
    A[i].suit = A[mini].suit;

    A[mini].value = tmp;
    A[mini].suit = tmp1;

    }
  }
}



int main(){
  struct Card C1[101], C2[101];
  char table[9][4]={};
  int c[9]={};

  int n, i,j,f=0;
  char ch;

  scanf("%d%c", &n, &ch);
  for ( i = 0; i < n; i++ ){
    scanf("%c%c%c", &C1[i].suit, &C1[i].value, &ch);
    table[C1[i].value-'1'][c[C1[i].value-'1']]=C1[i].suit;
    c[C1[i].value-'1']++;
  }
  for(i = 0; i < n; i++) {

    C2[i].suit = C1[i].suit;
    C2[i].value = C1[i].value;
  }

  BubbleSort(C1, n);
  SelectionSort(C2, n);


  for(i=0;i<9;i++)c[i]=0;

  if(table[C1[0].value-'1'][c[C1[0].value-'1']++]!=C1[0].suit)
    {
      f=1;
    }
  printf("%c%c", C1[0].suit, C1[0].value);
  for(i = 1; i < n; i++) {
  if(table[C1[i].value-'1'][c[C1[i].value-'1']++]!=C1[i].suit)
    {
      f=1;
    }
  printf(" %c%c", C1[i].suit, C1[i].value);
  }

  if(f==0)
    printf("\nStable\n");
  else
    printf("\nNot stable\n");

  for(i=0;i<9;i++)c[i]=0;
  f=0;

  if(table[C2[0].value-'1'][c[C2[0].value-'1']++]!=C2[0].suit)
    {
      f=1;
    }


 printf("%c%c", C2[0].suit, C2[0].value);
  for(i = 1; i < n; i++) {
  if(table[C1[i].value-'1'][c[C1[i].value-'1']++]!=C2[i].suit)
    {
      f=1;
    }
  printf(" %c%c", C2[i].suit, C2[i].value);
  }

  if(f==0)
    printf("\nStable\n");
  else
    printf("\nNot stable\n");

  return 0;
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main() {
    cin>>N;
    ll N3 = N * 3;
    vec a(N3);
    rep(i, N3) cin>>a[i];
    multiset<ll> l, r, n;
    ll sl{0}, sr{0};
    vec temp(N * 2);
    reps(i, N, N3) temp[i - N] = a[i];
    sort(ALL(temp));
    rep(i,N) {
        l.insert(a[i]);
        r.insert(temp[i]);
        n.insert(temp[i+N]);
        sl += a[i];
        sr += temp[i];
    }
    ll ans = sl - sr;
    reps(i, N, N*2){
        if(n.find(a[i]) != n.end()){
            n.erase(n.find(a[i]));
        }else{
            r.erase(r.find(a[i]));
            r.insert(*n.begin());
            sr += *n.begin() - a[i];
            n.erase(n.begin());
        }
        l.insert(a[i]);
        sl += a[i] - *l.begin();
        l.erase(l.begin());
        ans = max(ans, sl - sr);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 18176
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=1e6+10;
int S[N],mp[3],buc[3];
int n;
void change(int a,int b) {
	swap(mp[a],mp[b]);
	for(int i=1;i<=n;++i) {
		if(S[i]==a) S[i]=b;
		else if(S[i]==b) S[i]=a;
	}
}
int L[N],R[N];
void del(int x) {
	buc[S[x]]--;
	R[L[x]]=R[x];
	L[R[x]]=L[x];
}


int main() {
	mp[1]=1,mp[2]=2;
	
	{
		static char str[N];
		scanf("%s",str+1);
		int m=strlen(str+1);
		for(int i=1;i<=m;++i)
			if(i==1||str[i]!=str[i-1]) S[++n]=str[i]-'A';
	}
	
	S[0]=-1,S[n+1]=-2;
	for(int i=1;i<=n;++i) L[i]=i-1,R[i]=i+1; R[0]=1,L[n+1]=n;
	
	buc[0]=buc[1]=buc[2]=0;
	for(int i=1;i<=n;++i) buc[S[i]]++;
	
	{
		int ch=0;
		if(buc[1]<=min(buc[2],buc[0])) ch=1;
		if(buc[2]<=min(buc[1],buc[0])) ch=2;
		if(ch) change(0,ch),swap(buc[0],buc[ch]);
		if(buc[1]<buc[2]) change(1,2),swap(buc[1],buc[2]);
	}
	
	{
		int t=buc[1]-buc[2];
		for(int i=R[0];i<=n&&t;i=R[i])
			if(S[i]==1&&S[L[i]]!=S[R[i]]) del(i),t--;

		for(int i=R[0];i<=n&&t;i=R[i]) 
			if(S[i]==1&&S[L[i]]==0&&S[R[i]]==0) del(R[i]),del(i),t--;

	}
	{
		int t=buc[2]-buc[0];
		for(int i=R[0];R[i]<=n&&t;i=R[i])
			if(S[i]!=0&&S[R[i]]!=0&&S[L[i]]!=S[R[R[i]]])
				del(R[i]),del(i),t--;
	}
	for(int i=R[0];i<=n;i=R[i]) putchar('A'+mp[S[i]]);
	return 0;
}

Measured memory_bytes: 13952
import java.util.*;

public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] num = new int[n];
        int max = 0, index = 0, hindex = 0, diff = 1000000000;
        double half;
        
        for(int i=0; i<n; i++){
        	num[i] = Integer.parseInt(sc.next());
        	if(max < num[i]){
        		max = num[i];
        		index = i;
        	}
        }
        
        half = max/2.0;
        
        for(int i=0; i<n; i++){
        	if(Math.abs(half - num[i]) < diff && index != i){
        		diff = (int)Math.abs(half - num[i]);
        		hindex = i;
        	}
        }
        
        System.out.println(max + " " + num[hindex]);
        sc.close();
    }
}
	
	

Measured memory_bytes: 48108
#include<bits/stdc++.h>
#define pb push_back
#define int long long
//#define M 998244353
#define M 1000000007
using namespace std;
const int inf=4e18;
const int MX=100;
const int MN=-100;
const double pi=3.14159265358979;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int a,b;cin>>a>>b;
	cout<<6-a-b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll bai4,even,odd;
int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		ll z;
		cin>>z;
		if(z%4==0){
			bai4++;
			continue;
		}
		if(z%2==0){
			even++;
		}
		else{
			odd++;
		}
	}
	if(even>0){
		cout << ( bai4>=odd ? "Yes": "No");
		return 0;
	}
	else{
		cout << (bai4>=odd-1 ?"Yes":"No");
	}
	return 0;
}

Measured memory_bytes: 256