akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
int main(void)
{
    char s[100005];
    int n=0, ans=0;
    scanf("%s", s);
    while(strncmp(&s[n], "\0", 1)!=0) n++;
    for(int i=0; i<n; i++)
    {
        
        if(strncmp(&s[i], &s[i+1], 1)!=0)
        {
            if(strncmp(&s[i+1], "\0", 1)!=0) ans++;
        }
    }
    printf("%d",ans);
    return 0;
}

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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec g(nmax);

int n,m,q;
vec A(100),B(100),C(100),D(100);
int ans=0;

void check(vec &a){
    int memo=0;
    rep(i,q){
        if(a[B[i]]-a[A[i]]==C[i]) memo+=D[i];
    }
    chmax(ans,memo);
}

void dfs(vec a){
    if(a.size()==n){
        check(a);
        return;
    }
    int n=a.size();
    for(int i=a[n-1];i<=m;i++){
        a.pb(i);
        dfs(a);
        a.pop_back();
    }
}

void solve4ts()
{
    
    
    cin>>n>>m>>q;
    rep(i,q){
        cin>>A[i]>>B[i]>>C[i]>>D[i];
        A[i]--;
        B[i]--;
    }
    rep(i,m){
        vec a;
        a.pb(i+1);
        dfs(a);
    }
    cout<<ans<<endl;
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

Measured memory_bytes: 7792
//Moh_K_Imar .......
//26/08/2020  ... 3,15.
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll a,b;
    cin>>a>>b;
    if(b*2>a)cout<<0<<endl;
    else cout<<a-(b*2)<<endl;

    return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    ll d; cin >> d;
    int res=0;
    for(int i=0;i<n;i++){
        ll x,y; cin >> x >> y;
        if(x*x+y*y<=d*d){
            res++;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
unordered_map<string,int> mp;
int main(){
  int n; cin>>n; string s;
  while(n--){ cin>>s; mp[s]++; }
  cout<<"AC x "<<mp["AC"]<<endl;
  cout<<"WA x "<<mp["WA"]<<endl;
  cout<<"TLE x "<<mp["TLE"]<<endl;
  cout<<"RE x "<<mp["RE"]<<endl;
}

Measured memory_bytes: 3620
while True:
    h, w = map(int, input().split())
    if h==0 and w==0:
        break
    for i in range(w):
        print("#", end="")
    print()
    for i in range(h-2):
        print("#", end="")
        for j in range(w-2):
            print(".", end="")
        print("#")
    for i in range(w):
        print("#", end="")
    print()
    print()




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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
  int x, a, b;
  cin >> x >> a >> b;
  cout << (abs(x - a) > abs(x - b) ? "B" : "A") << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	
	vector<int> a(n);
	int dx = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int ans = (n - 1) / (k - 1);
	if((n - 1) % (k - 1) != 0)
	{
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
import bisect
N,M = map(int,input().split())
A = list(map(int,input().split()))
D = []
for _ in range(M):
  D.append(list(map(int,input().split())))
D.sort(key=lambda x:x[1], reverse=True)
cnt = 0
ans = []
for d in D:
  b,c = d[0],d[1]
  ans += [c for _ in range(b)]
  cnt += b
  if cnt>=N:
    break
ans = ans[:min(cnt,N)] + A
ans.sort(reverse=True)
print(sum(ans[:N]))

Measured memory_bytes: 35668
#include<bits/stdc++.h>
#define maxn 100005
#define inf 1e18L + 5
#define ll long long
#define MOD 1000000007
using namespace std;

ll arr[21][21];
ll dp[21][1<<21]; // for ith man considered , j gives the mask
ll n;

ll solve(ll pos, ll mask){
    if(pos == n && mask == ((1<<n) -1)) return 1;
    if(pos>=n) return 0;
    if(dp[pos][mask]!=-1) return dp[pos][mask];
    ll res = 0;
    for(ll i = 0; i < n; i++){
        ll k = arr[pos][i];
        if(k && !(mask&(1<<i))){
            res += solve(pos+1,mask|(1<<i));
            res %= MOD;
        }
    }
    //cout << pos << " " << res <<  endl ;
    return dp[pos][mask] = res;
}
int main(){
    cin>>n;
    memset(arr, 0, sizeof(arr));
    for(ll i =0;i<n;i++){
        for(ll j =0;j<n;j++){
            cin>> arr[i][j];
        }
    }
    memset(dp,-1, sizeof(dp));
    cout << solve(0, 0) << endl;
}


Measured memory_bytes: 344320
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    for(int i=1;i<=n-1;++i) {
        for(int j=i+1;j<=n;++j) {
            for(int k=0;k<30;++k) {
                if((i & (1 << k)) ^ (j & (1 << k))) {
                    cout << k+1 << " ";
                    break;
                }
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 512
#![allow(dead_code)]
use std::io;

fn main() {
    solve_a();
}

fn solve_d() {
    let mut x = String::new();

    io::stdin().read_line(&mut x).unwrap();

    let v: Vec<u32> = x.trim()
        .split(' ')
        .map(|s| s.parse::<u32>().unwrap())
        .collect();

    let a = v[0];
    let b = v[1];
    let c = v[2];
    let mut count = 0;
    for i in a..(b + 1) {
        if (c % i) == 0 {
            count += 1;
        }
    }
    println!("{}", count);
}

fn solve_c() {
    loop {
        let mut x = String::new();
        io::stdin().read_line(&mut x).unwrap();

        let mut v: Vec<u32> = x.trim()
            .split(' ')
            .map(|s| s.parse::<u32>().unwrap())
            .collect();

        v.sort();
        if v[0] == 0 && v[1] == 0 {
            break;
        } else {
            println!("{} {}", v[0], v[1]);
        }
    }
}

fn solve_b() {
    let mut i = 1;
    loop {
        let mut x = String::new();
        io::stdin().read_line(&mut x).unwrap();
        let n = x.trim().parse::<u64>().unwrap();

        if n == 0 {
            break;
        } else {
            println!("Case {}: {}", i, n);
            i += 1;
        }
    }
}

fn solve_a() {
    let mut x = String::new();
    io::stdin().read_line(&mut x).unwrap();

    let v: Vec<u64> = x.trim()
        .split(' ')
        .map(|s| s.parse::<u64>().unwrap())
        .collect();

    let a = v[0];
    let b = v[1];

    println!("{} {} {:.5}", a / b, a % b, a as f64 / b as f64);
}



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

int main(){
  int n;
  cin >> n;
  int F[50];
  F[0] = F[1] = 1;
  for(int i=2;i<=n;i++)
  {
    F[i]=F[i-1]+F[i-2];
  }
  cout << F[n] << endl;
  return 0;
}



Measured memory_bytes: 3136
#!/usr/bin/env python3
#ABC146 A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
lst = ["SUN","MON","TUE","WED","THU","FRI","SAT","SUN"]
print(7 - lst.index(s))

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





int main(){
	int N;
	
	cin>>N;
	int ans;
	vector<int>t(N+1);

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

	int S1=0,S2=0;


	for(int i =0;i<N-1;i++){
		for(int j=0;j<i+1;j++){
			S1 =S1+t[j];
		}
		for(int k=i+1;k<N;k++){
			S2 =S2+t[k];
		}

		if(i==0){
			ans =abs(S1-S2);
		}else{
			if(abs(S1-S2)<ans){
				ans=abs(S1-S2);
			}
		}
		S1=0;
		S2=0;
	}

	cout<<ans;

	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	while(true){
		bool ok=true;
		for(int i=2;i*i<=n;i++){
			if(n%i==0){
				ok=false;
				break;
			}
		}
		if(ok){
			cout<<n;
			return 0;
		}
		++n;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
while 1:
	n = int(raw_input())
	if n == 0:
		break
	land = [map(int,raw_input().split(" ")) for i in range(n)]
	land.sort(key = lambda x:(x[1],x[0]))
	gold = 0
	for i in range(n):
		gold += land[i][0]
		if gold > land[i][1]:
			print "No"
			break
	else:
		print "Yes"

Measured memory_bytes: 4220
#include <stdio.h>

int main(void)
{
	int a, b, i, j;
	while (1)
	{
		scanf("%d%d", &a, &b);
		if (a == 0 && b == 0){
			break;
		}

		for (i = 1; i <= a; i++)
		{
			for (j = 1; j <= b; j++)
			{
				if (i > 1 && i < a&&j < b&&j>1){
					printf(".");
				}
				else printf("#");
			}
			printf("\n");
		}
		printf("\n");

	}
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = INF;
    rep(i,n){
            int x,y;
            if(i==0){
                x = a[n-1]-a[0];
                y = k - (a[1]-a[0]);
            }
            else if(i==n-1){
                x = a[n-1]-a[0];
                y = k - (a[n-1]-a[n-2]);
            }
            else{
                x = k-(a[i+1]-a[i]);
                y = k-(a[i]-a[i-1]);
            }
            int z = min(x,y);
            chmin(ans,z);
        
    }
    cout << ans << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<int64_t> L(N + 1);
    L.at(0) = 2; L.at(1) = 1;

    for (int i = 2; i <= N; i ++){
        L.at(i) = L.at(i - 1) + L.at(i - 2);
    }
    cout << L.at(N) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;cin >> a >> b >> c;
	if(a + b == c || a + c == b || b + c == a) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int max,n,m;
    while(scanf("%d%d",&n,&m)==2)
    {
        max=n-m;
        max=n*m>max?n*m:max;
        max=(n+m)>max?(n+m):max;
        printf("%d\n",max);
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000
#define NIL -1

typedef struct{
  int parent,left,right;
}family;

//int getDepth(int);
void setDepth(int,int);
void printchildren(int);

int D[MAX];
family t[MAX];

int main(){
  int n,i,j,id,k,child,pre,root = 0;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    t[i].parent = NIL;
    t[i].left = NIL;
    t[i].right = NIL;
  }
  for(i = 0;i < n;i++){
    scanf("%d",&id);
    scanf("%d",&k);
    //  printf("(1) %d %d",id,k);
    for(j = 0;j < k;j++){
      scanf("%d",&child);
      //    printf("child %d",child);
      if(j == 0) t[id].left = child;
      else t[pre].right = child;
      // if(j == k - 1) t[child].right = NIL;
      t[child].parent = id;

      pre = child;
    }
    
  }
  //  printchildren(child);
  //  printf("scan ok\n");
  for(i = 0;i < n;i++){
    if(t[i].parent == NIL) root = i;
  }
  // printf("nannka ok\n");
  setDepth(root,0);
  //printf("setdepth ok\n");
  
  //ここから自作
  for(i = 0;i < n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,t[i].parent,D[i]);
    if(t[i].parent == NIL) printf("root, ");
    else if(t[i].left == NIL) printf("leaf, ");
    else printf("internal node, ");
    printchildren(i);
    //上は自作なため、不確定。
  }


  //depth どうするか

  return 0;
}

/*int getDepth(int u){
  int d = 0;
  while(t[u].parent != NIL){
    u = t[u].parent;
    d++;
  }
  return d;
  }*/

void setDepth(int u,int p){
  D[u] = p;
  if(t[u].right != NIL) setDepth(t[u].right,p);
  if(t[u].left != NIL) setDepth(t[u].left,p + 1);
}

void printchildren(int u){
  int c = t[u].left;
  printf("[");
  while(c != NIL){
    printf("%d",c);
    if(t[c].right != NIL) printf(", ");
    c = t[c].right;
  }
  printf("]\n");
}



Measured memory_bytes: 6540
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <cstdio>
#include <cstdint>
#include <cmath>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr ll BIGP  = 1000000007L;
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ld INF_F = std::numeric_limits<float>::infinity();
constexpr ld PI    = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll iA, iB, iH, iM;
    cin >> iA >> iB >> iH >> iM;
    ld A = ld(iA);
    ld B = ld(iB);
    ld H = ld(iH);
    ld M = ld(iM);
    ld dt = (H / 12.0L + M / (60.0L * 12.0L) - M / 60.0L) * 2.0L * PI;
    ld R2 = A * A + B * B - 2.0L * A * B * cosl(dt);
    ld R = sqrtl(R2);
    printf("%16.16Lf", R);
    return 0;
}

Measured memory_bytes: 3540
N = int(input())
X = list(map(int,input().split()))
q = int(input())
for i in range(q):
    a = input().split()
    j = int(a[0])
    t = int(a[1])
    s = int(a[2])
    count= 0
    for p in X[j:t]:
        if p == s:
            count += 1
    print(count)



Measured memory_bytes: 5640
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())
N, Y = map(int, input().split())

for x in range(N+1) :
  for y in range(N-x+1) :
    z = N-x-y
    sum = 10000*x + 5000*y + 1000*z
    if sum == Y :
      print (str(x) + " " + str(y) + " " + str(z))
      exit()
print ("-1 -1 -1")
      


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

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int ans = 0;
    if (A + B < C * 2) {
        ans += A * X + B * Y;
    } else {
        if (X < Y) {
            ans += C * 2 * X;
            Y -= X;
            if (B < C * 2) {
                ans += B * Y;
            } else {
                ans += C * 2 * Y;
            }
        } else {
            ans += C * 2 * Y;
            X -= Y;
            if (A < C * 2) {
                ans += A * X;
            } else {
                ans += C * 2 * X;
            }
        }
    }

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


Measured memory_bytes: 256
N,M = map(int,input().split())
a =[0]*M
b =[0]*M

ans = [0]*N

for i in range(M):
  a[i],b[i] = map(int,input().split())

for _ in range(M):
  ans[a[_]-1]+=1
  ans[b[_]-1]+=1

for j in range(N):
  print(ans[j])

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int coin[10];
int change[1<<10];
int dp[100010];

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M;
  while(cin >> N >> M, N || M) {
    rep(i, N) cin >> coin[i];
    rep(i, 1<<N) {
      int c = 0;
      rep(j, N) if((i>>j)&1) c += coin[j];
      change[i] = c;
    }
    fill(dp, dp + 100010, inf);
    dp[0] = 0;
    rep(i, 1<<N) {
      for(int j = 0; j+change[i] <= M; j++) {
	chmin(dp[j+change[i]], dp[j] + 1);
      }
    }
    cout << dp[M] << endl;
  }

  return 0;
}

Measured memory_bytes: 3808
#include <iostream>

using namespace std;

int main(void) {
	int X;
	cin >> X;
	int now = 0;
	int res = 0;
	while (now+res < X) {
		now += res+1;
		++res;
	}
	int rest = X-now;
	while (rest > 0) {
		rest -= res;
		++res;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
from itertools import permutations
from math import sqrt, pow, factorial
def calc(a, b):
    x1, y1 = a
    x2, y2 = b
    return sqrt(pow(x1  - x2, 2) + pow(y1 - y2, 2))
n = int(input())
x_y = [list(map(int, input().split())) for i in range(n)]

ans = 0
for oder in permutations(range(n)):
    tmp = 0
    for i in range(n - 1):
        tmp += calc(x_y[oder[i] - 1], x_y[oder[i + 1] - 1])
    ans += tmp
ans = ans / factorial(n)
print(ans)

Measured memory_bytes: 43244
#include <iostream>
//#include <algorithm>
//#include <string>
//#include <functional>
using namespace std;
int main() {
  
    /*string x;
    cin>>x;
    char part1[20];
    char part2[20];
 
    x.copy(part1,4,0);
    x.copy(part2,8,4);
    
    cout<<part1<<" "<<part2<< endl;*/
    int count;
    cin>>count;
    
    int list[count+1]; // array of known length
    //cout << "enter the sequence of " << count << " numbers space separated: ";
    // user inputs values space separated in one line.  Inputs more than the count are discarded.
    for (int i=1; i<count+1; i++) {
        cin >> list[i];
    }
    //cout<<list[4]<<endl;
    int final;
    int result[count+1];
    for(int z=0;z<count+1;z++) {
        result[z]=0;
    }
    for (int y=1;y<count+1;y++) {
        int temp= list[y];
        if(temp==y){result[y]=1;}
        if(list[temp])
        {
            int temp2=list[temp];
            if(result[temp]==0){
                if(temp2==y){
                    result[temp]=1;
                    final++;
                }
            }
                    }
        else
        {result[y]=1;}
    }
    cout<<final/2<<endl;
    
   
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
int main(){
  char b;
  cin >> b;
  if(b=='A')cout << "T"<< endl;
  if(b=='T')cout << "A"<<endl;
  if(b=='C')cout << "G"<< endl;
  if(b=='G') cout << "C" << endl;
}

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

using namespace std;

typedef long long ll;

signed main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto& x : a)
        cin >> x;
    vector<int> dp(n, 1e9);
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        if(i + 1 < n)
            dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i] - a[i + 1]));
        if(i + 2 < n)
            dp[i + 2] = min(dp[i + 2], dp[i] + abs(a[i] - a[i + 2]));
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
N = int(input())
d = dict()
for a in map(int,input().split()):
   if a-1 in d:
      d[a-1] += 1
   else:
      d[a-1] = 1
   if a in d:
      d[a] += 1
   else:
      d[a] = 1
   if a+1 in d:
      d[a+1] += 1
   else:
      d[a+1] = 1
print(max(d.values()))


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

int h , w , ans ;
char map[101][101] = {} ;
int dx[] = { -1,0,1,0 } ;
int dy[] = { 0,-1,0,1 } ;

void count( int y , int x , char f ){
	map[y][x] = '0' ;
	
	for( int k=0 ; k<4 ; k++ ){
		if( 0 <= y+dy[k] && y+dy[k] < h &&
			0 <= x+dx[k] && x+dx[k] < w &&
			map[y+dy[k]][x+dx[k]] == f )
				count( y+dy[k] , x+dx[k] , f ) ;
	}
}

int main(){
	
	while(1){
		cin >> h >> w ;
		if( h==0 && w==0 ) break ;
		
		for( int i=0 ; i<h ; i++ )
			for( int j=0 ; j<w ; j++ )
				cin >> map[i][j] ;
		
		ans = 0 ;
		for( int i=0 ; i<h ; i++ ){
			for( int j=0 ; j<w ; j++ ){
				if( map[i][j] != '0' ){
					count( i , j , map[i][j] ) ;
					ans++ ;
				}
			}
		}
		
		cout << ans << endl ;
	}
	
return 0;
}

Measured memory_bytes: 1636
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define MAXN 50004


signed main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
    //     freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    // #endif
    int n; cin>>n;
    string s;
    cin>>s;
    int r=0, b=0;
    For(i, 0, s.length()){
    	if(s[i]=='R')
    		r++;
    	else
    		b++;
    }
    if(r>b)
    	cout<<"Yes";
    else
    	cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll N, ll X, vector<ll> L) {
  int ans{1};
  int pos{};
  for (int i = 0; i != N; ++i) {
    pos += L[i];
    if (pos > X) break;
    ++ans;
  }
  cout << ans << endl;
}

int main() {
  ll N;
  cin >> N;
  ll X;
  cin >> X;
  vector<ll> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }
  solve(N, X, move(L));
  return 0;
}


Measured memory_bytes: 256
open System

let N = stdin.ReadLine() |> int

let aList = [ for _ in 1..N -> stdin.ReadLine() |> int ]

let SolveF list =
    let rec subSolveF accum list2 =

        match list2 with
        | hd::tl when (List.tryFind ((=) hd) accum) = None -> subSolveF (hd::accum) tl
        | hd::tl -> subSolveF accum tl
        | [] -> accum
    
    subSolveF [] list

SolveF aList |> List.length |> printfn "%i"

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

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

    map<int, int> stu;
    int n; cin >> n;
    for (int i = 1; i <= n; ++i) {
        int a; cin >> a;
        stu.insert(make_pair(a, i));
    }

    for (auto& s : stu){
        cout << s.second << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
int power(int x,int y){
	if(x==1 || y==0){
		return 1;
	}
	int ans = 1;
	while(y){
		if(y&1){
			ans =(ans*x)%mod;
		}
		y/=2;
		x=(x*x)%mod;
	}
	return ans;
}
int32_t main(){
	int n;
	cin>>n;
	int ans = power(10,n)%mod+power(8,n)%mod;
	ans = ans %mod - (power(9,n)%mod * 2)%mod;
	while(ans<0){
		ans += mod;
	}
	cout<<ans%mod<<endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	char s[4];
	for (int i = 0; i < 4; i++) {
		cin >> s[i];
	}
	if ((s[0] == s[1] && s[0] == s[2]) || (s[1] == s[2] && s[1] == s[3]))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();
        var t = Console.ReadLine();
        for (int i = 0; ; i++)
        {
            var res = s.Substring(0, i) + t;
            if (res.Substring(0, n) == s)
            {
                Console.WriteLine(res.Length);
                return;
            }
        }
    }
}


Measured memory_bytes: 11092
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var (
		a, b   string
		ai, bi int
	)
	fmt.Scan(&a, &b)
	ai, _ = strconv.Atoi(a)
	bi, _ = strconv.Atoi(b)
	a = strings.Repeat(a, bi)
	b = strings.Repeat(b, ai)

	if a < b {
		fmt.Println(a)
	} else {
		fmt.Println(b)
	}
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    vector<int>v(5);
    rep(i,0,5){
        cin>>v.at(i);

    }
    rep(i,0,5){
        if(v.at(i)==0){
            cout<<i+1<<endl;
            return 0;
        }
    }
return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <inttypes.h>

int compare_int(const void *a, const void *b){//qsort 整数比較<
	return *(int*)a - *(int*)b;
}
int compare_int2(const void *a, const void *b){//qsort 整数比較>
	return *(int*)b - *(int*)a;
}

int main(void){
	char s[200010]={'\0'};
	char t[200010]={'\0'};
	int i;
	int ans=0;

	scanf("%s",s);
	scanf("%s",t);

	for(i=0;s[i]!='\0';i++){
		if(s[i]!=t[i]){
			ans++;
		}
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int X, Y, Z;
	int A, B, C;
	cin >> X >> Y >> Z;
	A = Z;
	B = X;
	C = Y;
	cout << A <<" "<<B<<" "<<C << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>
#include <cmath>
#include <limits>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) {
        cin >> a[i];
        b[i] = a[i];
    }

    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    int m1 = b[0];
    int m2 = b[1];

    for(int i = 0; i < n; i++) {
        if(a[i] == m1) cout << m2 << endl;
        else cout << m1 << endl;
    }
}


Measured memory_bytes: 3200
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws Exception {       
        Scanner sc = new Scanner(System.in);
        for(int i=0;i<5;i++) {
            int k = sc.nextInt();
            if (k==0) {
                System.out.println(i+1);
            }
        }
    }
}


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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 998244353;

int v[18][2];
int dp[18][1<<18][18] = {};
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    
    ms1(dp);
    f(n){
        cin >> v[i][0];
    }
    f(n){
        cin >> v[i][1];
    }
    for(int i = 0 ; i < n ; i ++){
        dp[0][1<<i][i] = i;
    }
    for(int i = 1 ; i < n ; i++){
        for(int j = 1 ; j < (1 << n) ; j++){
            if(__builtin_popcount(j) != i + 1){
                continue;
            }
            int pre[n+5] = {};
            pre[0] = (j & 1);
            for(int k = 1 ; k < n ; k++){
                if(j & (1<<k)){
                    pre[k] = pre[k - 1] + 1;
                }
                else{
                    pre[k] = pre[k - 1];
                }
            }
            for(int k = 0 ; k < n ; k ++){
                if(!((1<<k)&j))continue;
                int mask = j ^ (1<<k);
                for(int l = 0; l < n ; l ++){
                    if(!(mask&(1<<l))){
                        continue;
                    }
                    if(dp[i-1][mask][l]== -1)continue;
                    if(v[k][(k&1)^(i&1)] >= v[l][((i+1)&1)^(l&1)]){
                       // cout << "here\n";
                        if(dp[i][j][k] == -1)
                            dp[i][j][k] = dp[i-1][mask][l] + k + 1 - pre[k];
                        else
                            dp[i][j][k] = min(dp[i][j][k], dp[i-1][mask][l] + k + 1 - pre[k]);
                    }
                }
               // cout << i <<' '<<j<<' '<<k<<' '<<dp[i][j][k] << '\n';
            }
        }
    }
    int ans = 1e9;
    for(int i = 0 ; i < n ; i++){
        if(~dp[n-1][(1<<n)-1][i]){
            ans = min(ans,dp[n-1][(1<<n)-1][i]);
        }
    }
    if(ans == 1e9)ans = -1;
    cout << ans << '\n';
}

Measured memory_bytes: 332032
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		if(S == "AAA" || S == "BBB"){
			Console.WriteLine("No");
		} else {
			Console.WriteLine("Yes");
		}
		
	}
	String S;
	public Sol(){
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
ll n,l[100010],r[100010];
bool ch[100010];
vector <ll>a[100010];
map<pair<ll,ll>,ll>b;
ll ans;
void dep(ll now,ll col){
	ch[now]=true;
	ll nexc=1;
	for(ll i=0;i<a[now].size();i++){
		ll nex=a[now][i];
		if(ch[nex]){
			continue;
		}
		if(nexc==col){
			nexc++;
		}
		b[make_pair(now,nex)]=nexc;
		b[make_pair(nex,now)]=nexc;
		ans=max(ans,nexc);
		dep(nex,nexc);
		nexc++;
	}
}
int main() {
	cin>>n;
	for(ll i=0;i<n-1;i++){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		l[i]=x;
		r[i]=y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	dep(0,0);
	cout <<ans<<endl;
	for(ll i=0;i<n-1;i++){
		ll x=l[i];
		ll y=r[i];
		pair <ll,ll>z=make_pair(x,y);
		cout << b[z]<<endl;
	}
	// your code goes here
	return 0;
}

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

int N, C;
int s[100100], t[100100], c[100100];
int imos[100100];
int su[100100];

signed main() {
    cin >> N >> C;
    rep(i, N) cin >> s[i] >> t[i] >> c[i];
    for (int i=1; i<=C; i++) {
        rep(j, 100100) imos[j] = 0;
        rep(j, N) {
            if (c[j]==i) {
                imos[s[j]-1]++;
                imos[t[j]]--;
            }
        }
        for (int j=1; j<100100; j++) imos[j] += imos[j-1];
        rep(j, 100100) if (imos[j]>0) su[j]++;
    }
    int ans = 0;
    rep(i, 100100) ans = max(ans, su[i]);
    cout << ans << endl;
}

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

using namespace std;

int main(){

    int N, L, sum;

    cin >> N >> L;


    vector<int> taste,taste_a;

    for (int i=0;i<N;i++) {
        taste.push_back(L + i);
    }

    vector<size_t> indices(taste.size());
    iota(indices.begin(), indices.end(), 0);

    for (auto j:taste) {
        taste_a.push_back(abs(j));
    }

    sort(indices.begin(), indices.end(), [&taste_a](size_t i1, size_t i2) {
        return taste_a[i1] < taste_a[i2];
    });


    sum = accumulate(taste.begin(), taste.end(), 0);
    cout << (sum - taste[indices[0]]) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5+10;
int n,m;
int w[N];
bool st[N];
int main()
{
	memset(st,1,sizeof st);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>w[i];
	for(int i=1;i<=m;i++)
	{
		int a,b;
		cin>>a>>b;
		int a1=w[a],b1=w[b];
		if(a1<=b1)
			st[a]=0;
		if(b1<=a1)
			st[b]=0;
	}
	int sum=0;
	for(int i=1;i<=n;i++)
		if(st[i])
			sum++;
	cout<<sum<<endl;
}


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

int check(char *str_a, char *str_b, char *str_c, int a, int b, int c, int turn){
  int ret;
  if (turn == 1){
    if (str_a[a] == 'a'){
      ret = check(str_a, str_b, str_c, a+1, b, c, 1);
    }
    else if(str_a[a] == 'b'){
      ret = check(str_a, str_b, str_c, a+1, b, c, 2);
    }
    else if(str_a[a] == 'c'){
      ret = check(str_a, str_b, str_c, a+1, b, c, 3);
    }
    else if(str_a[a] == '\0'){
      return 1;
    }
  }
  else if (turn == 2){
    if (str_b[b] == 'a'){
      ret = check(str_a, str_b, str_c, a, b+1, c, 1);
    }
    else if(str_b[b] == 'b'){
      ret = check(str_a, str_b, str_c, a, b+1, c, 2);
    }
    else if(str_b[b] == 'c'){
      ret = check(str_a, str_b, str_c, a, b+1, c, 3);
    }
    else{
      return 2;
    }
  }
  else if (turn == 3){
    if (str_c[c] == 'a'){
      ret = check(str_a, str_b, str_c, a, b, c+1, 1);
    }
    else if(str_c[c] == 'b'){
      ret = check(str_a, str_b, str_c, a, b, c+1, 2);
    }
    else if(str_c[c] == 'c'){
      ret = check(str_a, str_b, str_c, a, b, c+1, 3);
    }
    else{
      return 3;
    }
  }
  return ret;
}

int main(){
  char s_a[100];
  char s_b[100];
  char s_c[100];
  int a=0;
  int b=0;
  int c=0;
  int r;

  scanf("%s", &s_a[0]);
  scanf("%s", &s_b[0]);
  scanf("%s", &s_c[0]);

  r = check(s_a, s_b, s_c, a,b,c, 1);
  if(r==1){
    printf("A\n");
  }
  if(r==2){
    printf("B\n");
  }
  if(r==3){
    printf("C\n");
  }

  return 0;
}


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

int main(){
    string s;
    cin >> s;

    for(int i=0; i<s.length(); i++){
        if(s[i] != ',') cout << s[i];
        if(s[i] == ',') cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#バブルソート
n=int(input())
a=[int(i) for i in input().split()]

f=1 #隣接した要素が昇順になっていないものが存在する
j=0
while f:
    f=0
    for i in range(n-1):
        if a[n-i-1]<a[n-i-2]:
            a[n-i-1],a[n-i-2]=a[n-i-2],a[n-i-1]
            f=1
            j+=1
print(" ".join(list(map(str,a))))
print(j)



Measured memory_bytes: 5608
def resolve():

    # 辞書順最小のものを選びたいので、文字列は反転して判定を行っている
    # マッチする箇所が複数あった場合は、なるべく後ろのマッチ点でマッチさせて、前のマッチ点はすべて?をaに変更する
    ss = input()[::-1]
    t = input()[::-1]

    ans = 'UNRESTORABLE'
    for i in range(len(ss) - len(t) + 1):
        flg = True
        for j in range(len(t)):
            if ss[i + j] != t[j] and ss[i + j] != '?':
                flg = False
                break

        if flg:
            ans = ss[:i] + t + ss[i + len(t):]
            ans = ans.replace('?', 'a')[::-1]
            break

    print(ans)
    
resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAX_N = 2e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;
const double EPS = 1e-9;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)



void solve() {
    char x; cin >> x;
    cout << (isupper(x) ? "A" : "a");
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // LOCAL

    int tc; tc = 1;
    for (int t = 1; t <= tc; t++) {
        //cout << "Case #" << t  << ": ";
        solve();
    }
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<tuple>
using namespace std;

enum {STEP, FIELD};
typedef tuple<int, vector<vector<char>>> Node;

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

void flood_fill(vector<vector<char>>& field, int y, int x, char color) {
    char from = field[y][x];
    field[y][x] = color;
    for(int i = 0; i < 4; ++i) {
        int ny = y + dy[i];
        int nx = x + dx[i];
        if(ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
        if(field[ny][nx] != from) continue;
        flood_fill(field, ny, nx, color);
    }
}

bool clear(const vector<vector<char>>& field) {
    for(int i = 0; i < h; ++i) for(int j = 0; j < w; ++j) if(field[i][j] != field[0][0]) return false;
    return true;
}

int bfs(const vector<vector<char>>& init_field) {
    set<vector<vector<char>>> visited;
    queue<Node> q;
    q.push(Node(0, init_field));
    while(!q.empty()) {
        int step = get<STEP>(q.front());
        auto field = get<FIELD>(q.front());
        q.pop();
        if(clear(field)) return step;
        if(visited.count(field)) continue;
        visited.insert(field);
        for(char color: {'R', 'G', 'B'}) {
            if(color == field[0][0]) continue;
            auto next_field = field;
            flood_fill(next_field, 0, 0, color);
            q.push(Node(step + 1, next_field));
        }
    }
    return -1;
}

int main() {
    while(cin >> w >> h, w | h) {
        vector<vector<char>> field(h, vector<char>(w));
        for(int i = 0; i < h; ++i) for(int j = 0; j < w; ++j) cin >> field[i][j];
        cout << bfs(field) << endl;
    }
}

Measured memory_bytes: 5832
#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 1e6+2 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;
int a[N] ;

void solve(){
	int n ;
	cin >> n ;
	for(int i = 0 ; i < n ; i++){
		int x ;
		cin >> x ;
		a[x]++ ;
	}
	for(int i = 1 ; i < N ; i++){
		if(a[i] == 0) continue ;
		for(int j = 2*i ; j < N ; j += i){
			if(a[j]) a[j] = 0 ;
		}
		if(a[i]>=2) a[i] = 0 ;
	}
	int ans = 0 ;
	for(int i = 0 ; i < N ; i++){
		if(a[i]) ans++ ;
	}
	cout << ans << endl ;
}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
}


Measured memory_bytes: 11476
#include <stdio.h>
int main(void){
    // Your code here!
    int a, b, c, k;
    
    scanf("%d%d%d%d",&a,&b,&c,&k);
    
    
    if(k<=a) printf("%d\n",k);
    
    else{
        if(k<=a+b)  printf("%d\n",a);
        else printf("%d\n",a+(k-(a+b))*(-1));
    }
    
    return 0;
}

Measured memory_bytes: 1732
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>
# include <thread>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ui32 = unsigned int;
constexpr ll INFLL = 1e18;

#define CHECK_IMPL1(cond)              \
if (!(cond)) {                         \
    DEBUG("expected cond: " << #cond); \
    assert(cond);                      \
}

#define CHECK_IMPL2(cond, message)                                            \
if (!(cond)) {                                                                \
    DEBUG("expected cond: " << #cond << " failed with message: " << message); \
    assert(cond);                                                             \
}
#define CHECK_IMPL(_1, _2, NAME, ...) NAME
#define CHECK(...) CHECK_IMPL(__VA_ARGS__, CHECK_IMPL2, CHECK_IMPL1, CHECK_IMPL0)(__VA_ARGS__)

#ifdef __APPLE__
#define DEBUG(message) std::cerr << message << std::endl;
#else
#define DEBUG(message)
#endif

struct Node {
  ll x, y, r;
};

void solve() {
  int xs, ys, xt, yt;
  cin >> xs >> ys >> xt >> yt;

  int n;
  cin >> n;

  vector<Node> nodes;
  nodes.push_back({ xs, ys, 0 });
  for (int i = 0; i < n; i++) {
    int x, y, r;
    cin >> x >> y >> r;
    nodes.push_back({x, y, r});
  }
  nodes.push_back({ xt, yt, 0 });

  vector<double> dist(nodes.size(), 1e18);
  vector<bool> used(nodes.size(), false);
  dist[0] = 0.0;

  auto calc_dist = [&](size_t v, size_t u) {
    double d = (nodes[v].x - nodes[u].x) * (nodes[v].x - nodes[u].x) + (nodes[v].y - nodes[u].y) * (nodes[v].y - nodes[u].y);
    return max(0.0, sqrt(d) - nodes[v].r - nodes[u].r);
  };

  for (size_t it = 0; it < nodes.size(); it++) {
    size_t v = -1;
    double d = 1e18;
    for (size_t i = 0; i < nodes.size(); i++) {
      if (used[i]) {
        continue;
      }
      if (dist[i] < d) {
        d = dist[i];
        v = i;
      }
    }
    if (v == -1) {
      break;
    }
    used[v] = true;
    for (size_t u = 0; u < nodes.size(); u++) {
      auto new_dist = d + calc_dist(v, u);
      if (dist[u] > new_dist) {
        dist[u] = new_dist;
      }
    }
  }
  cout << fixed << setprecision(10) << dist[nodes.size() - 1] << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef __APPLE__
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  int t = 1;
//  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 256