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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,k;
    cin >> n >> k;
    int32 ans = 0;
    REP(i,n){
        int32 h;
        cin >> h;
        if(h >= k)ans++;
    }
    ANS(ans);
    return 0;
}

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

pair<int, int> INF = { -1000000000, -1 };

class SegmentTree {
private:
	vector<pair<int, int> > Node;
public:
	SegmentTree(vector<int>& V) : Node(V.size() * 2, INF) {
		for (int i = 0; i < V.size(); i++) {
			Node[i + V.size()] = { V[i], i };
		}
		for (int i = V.size() - 1; i >= 1; i--) {
			Node[i] = max(Node[i * 2], Node[i * 2 + 1]);
		}
	}
	void Update(int K, int X) {
		K += Node.size() / 2;
		Node[K].first = X;
		while (K >= 2) {
			K >>= 1;
			Node[K] = max(Node[K * 2], Node[K * 2 + 1]);
		}
	}
	pair<int, int> Query(int L, int R) {
		L += Node.size() / 2, R += Node.size() / 2;
		pair<int, int> ANS = INF;
		while (L < R) {
			if (L & 1) {
				ANS = max(ANS, Node[L]);
				L++;
			}
			if (R & 1) {
				ANS = max(ANS, Node[R - 1]);
				R--;
			}
			L >>= 1, R >>= 1;
		}
		return ANS;
	}
};

int main() {
	int N;
	cin >> N;
	vector<int> A(N), C(N, 0);
	for (int i = 0; i < N; i++) cin >> A[i], A[i]--, C[A[i]]++;
	if (N == 2) {
		cout << -1 << endl;
		return 0;
	}
	SegmentTree Seg(C);
	vector<bool> B(N, true);
	vector<int> ANS;
	stack<int> ST;
	for (int i = N - 1; i >= 0; i--) ST.push(i);
	for (int i = 0; i < N - 3; i++) {
		pair<int, int> P = Seg.Query(0, N);
		if (P.first == N - i - 1) {
			ANS.push_back(P.second);
			B[P.second] = false;
			Seg.Update(P.second, -1);
			C[A[P.second]]--;
			Seg.Update(A[P.second], C[A[P.second]]);
		}
		else {
			while (1) {
				if (B[ST.top()]) break;
				else ST.pop();
			}
			if (i == 0 || A[ANS[i - 1]] != ST.top()) {
				ANS.push_back(ST.top());
				B[ST.top()] = false;
				Seg.Update(ST.top(), -1);
				C[A[ST.top()]]--;
				Seg.Update(A[ST.top()], C[A[ST.top()]]);
				ST.pop();
			}
			else {
				int X = ST.top();
				ST.pop();
				while (1) {
					if (B[ST.top()]) break;
					else ST.pop();
				}
				ANS.push_back(ST.top());
				B[ST.top()] = false;
				Seg.Update(ST.top(), -1);
				C[A[ST.top()]]--;
				Seg.Update(A[ST.top()], C[A[ST.top()]]);
				ST.pop();
				ST.push(X);
			}
		}
	}
	vector<int> X;
	while (!ST.empty()) {
		if (B[ST.top()]) X.push_back(ST.top());
		ST.pop();
	}
	do {
		bool check = true;
		if (N > 3 && A[ANS[N - 4]] == X[0]) check = false;
		if (A[X[0]] == X[1]) check = false;
		if (A[X[1]] == X[2]) check = false;
		if (check) {
			ANS.push_back(X[0]), ANS.push_back(X[1]), ANS.push_back(X[2]);
			break;
		}
	} while (next_permutation(X.begin(), X.end()));
	for (int i = 0; i < N; i++) cout << ANS[i] + 1 << (i == N - 1 ? '\n' : ' ');
}

Measured memory_bytes: 4020
#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 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	int a[n];
	ll cnt[100010] = {};
	int zero = 0;
	REP(i, n){
		cin >> a[i];
		cnt[a[i]-1]++;
		cnt[a[i]]++;
		cnt[a[i]+1]++;
	}

	ll ans = 0;

	for (auto x : cnt) ans = max(ans, x);

	cout << ans << endl;

}


Measured memory_bytes: 1408
main(){
    int i=0;
    int j=0;
    
    int t[9<<14]={};
    int m=0;
    int s=0;
    
    for(;~scanf("%d",&t[i]);i++){
        i*(t[i]>m)?m=t[i]:0;
    }
    for(;++j<t[0]+2;){
        if(abs(t[j]-m/2)<abs(s-m/2))s=t[j];
    }
    printf("%d %d",m,s);
}

Measured memory_bytes: 2300
import java.util.*;


public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int [] data = new int[n];
			for(int i = 0; i < n; i++){
				data[i] = sc.nextInt();
			}
			int [] calc = new int[n+1];
			int prev = 0, sum = 0;
			for(int i = 0; i < n+1; i++){
				int num = 0;
				if(i < n){
					num = data[i];
				}
				
				calc[i] = Math.abs(num - prev);
				prev = num;
				sum += calc[i];
			}
			int [] calc2 = new int[n];
			prev = 0;
			for(int i = 0; i < n; i++){
				int num = 0;
				if(i+1 < n){
					num = data[i+1];
				}
				
				calc2[i] = Math.abs(num - prev);
				prev = data[i];
			}
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < n; i++){
				sb.append(sum - calc[i] - calc[i+1] + calc2[i] + "\n");
			}
			System.out.print(sb.toString());

		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 66220
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
	int a,b; cin>>a>>b;
	VI l(a); rep(i,a) cin>>l[i]; sort(RALL(l));
	int ans = 0;
	rep(i,b) ans+=l[i];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	a += (a == 1 ? 13 : 0);
	b += (b == 1 ? 13 : 0);
	
	printf("%s\n",a == b ? "Draw" : a > b ? "Alice" : "Bob");
	
	return 0;
}


Measured memory_bytes: 128
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
s=0
temp=None
for i in range(n):
    s+=b[a[i]-1]
    if temp==a[i]-1:
        s+=c[temp-1]
    temp=a[i]
print(s)

Measured memory_bytes: 3064
X, N = list(map(int, input().split()))
P = list(map(int, input().split()))

d = {i : abs(X - i) * 1000 + i for i in range(-110, 110, 1)}

for p in P:
  if p in d:
    d[p] = 10000000

d = sorted(d.keys(), key=lambda x: d[x])

print(d[0])

Measured memory_bytes: 9204
#include <iostream>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) std::cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<std::endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}

const int NOT_FREE = 1;
const int FREE = 0;
const int N = 8;
int row[N], col[N];
int dpos[N + N];
int dneg[N + N];

int M;
int Fixed[N];

void printBoard(){
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(row[i] == j) std::cout<<"Q";
      else std::cout<<".";
    }
    std::cout<<std::endl;
  }
}

void putQueen(int i){
  if(i == N){
    printBoard();
    exit(0);
    return;
  }

  //printBoard();

  for(int j=0;j<N;j++){
    if (col[j] == NOT_FREE ||
	dpos[i + j] == NOT_FREE ||
	dneg[i - j + N - 1] == NOT_FREE ||
	(Fixed[i] != -1 && Fixed[i] != j)) continue;
    
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    
    putQueen(i + 1);
    
    col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}

signed main(){
  std::cin>>M;
  for(int i=0;i<N;i++) Fixed[i] = -1;
  
  for(int i=0;i<M;i++){
    int h, w;
    std::cin>>h>>w;
    Fixed[h] = w;
  }

  putQueen(0);
  return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#define ll long long
#define f(i, n) for (int i=1; i <= n; i++)
// sort(bb, bb+n);

using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    string s;
    int n = s.length();
    cin >>s;
    if(s[2]==s[3] && s[4]==s[5]){
        cout <<"Yes";
    } 
    else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;

using ull = unsigned long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vull = vector<ull>;
using vpii = vector<pii>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end());
#define rSORT(a) sort((a).rbegin(),(a).rend());
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;

//sankou
//vvi = vector<vector<int>>(20, vector<int>(10, 0));

int isP(int n) {
    if(n<=1) return 0;
    FOR(i,2,(int)sqrt(n)) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {
    
    int n,aa,bb,t1=0,t2=0;
    cin >>n;
    vi a(n);
    FOR(i,0,n-1) {
        cin >>a[i];
    }
    rSORT(a);
    aa=a[0];
    t1=n-1;
    FOR(i,2,n-1) {
        if(a[i]<(aa/2)+(n%2)) {
            t1=i-1;
            break;
        }
    }
    t2=1;
    rFOR(i,1,n-2) {
        if(a[i]>((aa/2))) {
            t2=i+1;
            break;
        }
    }
    if(a[t1]-((aa/2)+(n%2))>=(aa/2)-a[t2]) bb=a[t2];
    if(a[t1]-((aa/2)+(n%2))<(aa/2)-a[t2]) bb=a[t1];
    
    cout <<aa<<" "<<bb<<endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
    int n, i, j;

    scanf("%d", &n);

    int v[n];

    for (i = 0; i < n - 1; i++)
    {
        scanf("%d ", &v[i]); //0 ~ n - 1個目の数字を空白区切りで読み込む
    }

    scanf("%d", &v[n - 1]); //最後の数字のみ空白区切りなし

    for (j = n - 1; j >= 1; j--)
    {
        printf("%d ", v[j]);
    }

    printf("%d\n", v[0]);

    return 0;
}


Measured memory_bytes: 2704
#include<stdio.h>
int main()
{
    int n,m,x,i,a=0,b=0;
    int s[105];
    scanf("%d%d%d",&n,&m,&x);
    for(i=0;i<m;i++)
        {
            scanf("%d",&s[i]);
        }
    for(i=0;i<m;i++)
    {
        if(s[i]<=x)
            a++;
        if(s[i]>x)
            b++;
    }
    if(a>b)
        printf("%d",b);
    else
        printf("%d",a);
    return 0;
}

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

const int INF = 1 << 29;
using ll = long long int;
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; ++i)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)


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

	int res = 0;
	int t = 0;
	rep(i, s.size()) {
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
			++t;
		}
		else {
			res = max(res, t);
			t = 0;
		}
	}
	res = max(res, t);

	cout << res << endl;
}

Measured memory_bytes: 3136
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
 
ll n;
ll d[3 * 100005];
ll rd[3 * 100005];
ll sum[3 * 100005];
 
bool f(ll d[]);
 
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> d[i];
    }
     
    for (int i = n, k = 1; i > 0; i--, k++) {
        rd[k] = d[i];
    }
 
    bool l = f(d);
    bool r = f(rd);
 
    if (l && r) cout << "yes" << endl;
    else cout << "no" << endl;
 
    return 0;
}
 
bool f(ll d[]) {
    memset(sum, 0, sizeof(sum));
    sum[n] = 1;
 
    for (int i = n - 1; i > 0; i--) {
        ll r = min(n, i + d[i] / 10);
         
        //sum[i] += sum[i + 1];
        if (d[i] >= 10) {
            if (sum[i + 1] - sum[r + 1] > 0) {
                sum[i]++;
            }
        }
 
        sum[i] += sum[i + 1];
    }
 
    if (sum[1] > sum[2]) return true;
    else return false;
}


Measured memory_bytes: 10120
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  vector<int> ans(n);
  rep(i,n) ans.at(a.at(i)-1)=i+1;
  rep(i,n) cout << ans.at(i) << endl;
  return 0;
  }

Measured memory_bytes: 1664
n = int(input())
a = []
d = {}
for i in range(n):
  w = input()
  if w in d:
    print('No')
    exit()
  d[w] = 1
  a.append(w)
for i in range(n-1):
  if a[i][-1] != a[i+1][0]:
    print('No')
    break
else:
  print('Yes')


Measured memory_bytes: 3060
n = int(input())
t_won = 0
h_won = 0
#Pythonでは文字列の辞書順での大小関係を比較演算子を使って比較可能
#比較を行い、太郎と花子それぞれの勝ち数をカウント
for i in range(n):
    t_wd,h_wd = input().split()
    if   t_wd > h_wd:
        t_won += 1
    elif t_wd < h_wd:
        h_won += 1

#    print(t_won)
#    print(h_won)
#    print(n-t_won-h_won)
#    print()

print(t_won*3 + (n-t_won-h_won), h_won*3 + (n-t_won-h_won))
#勝ったら3pointなので*3
#n-t_won-h_wonで引き分け分を足す


Measured memory_bytes: 5596
#include <stdio.h>
#include <stdlib.h>
 
typedef struct node{
  int key;
  struct node *p;
  struct node *l;
  struct node *r;
} Node;
 
typedef Node *NodePointer;
NodePointer root = NULL;
 
NodePointer createNode(){
  NodePointer z = malloc(sizeof(Node));
  z->l = NULL;
  z->r = NULL;
  z->p = NULL;
  z->key = 0;
  return z;
}
 
void insert(int key){
   
  NodePointer z = createNode();
  NodePointer y = NULL;
  NodePointer x = root;
  z->key = key;
   
  while(x != NULL){
    y = x;
    if(z->key < x->key) x = x->l;
    else x = x->r;
  }
  z->p = y;
  if(y == NULL) root = z;
  else if(z->key < y->key) y->l = z;
  else y->r = z;
}
   
void inorder(NodePointer p){
     
  if(p != NULL){
    inorder(p->l);
    printf(" %d",p->key);
    inorder(p->r);
  }
}
 
void preorder(NodePointer p){
  if(p != NULL){
    printf(" %d",p->key);
    preorder(p->l);
    preorder(p->r);
  }
}

int find(NodePointer p, int key){

  if(p == NULL) return 0;
  else if(p->key == key) return 1;

  if(key < p->key)  return find(p->l,key);
  else  return find(p->r,key);

}
 
int main(void){
 
  int i,key,n,x;
  char str[20];
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%s",str);
 
    if(str[0] == 'i'){
      scanf("%d",&key);
      insert(key);
    }
    else if(str[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else{
      scanf("%d",&key);
	x = find(root,key);
	if(x == 1) printf("yes\n");
	else printf("no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 19364
#ABC048 C - Boxes and Candies
N,x = map(int,input().split())
A = list(map(int,input().split()))
A_ = A[:]
ans = 0

if A[0] >x:
    ans = A[0]-x
    A[0] = x
for i in range(N-1):
    y = A[i]+A[i+1]-x
    if y > 0:
        A[i+1] -= y
        ans += y

print(ans)

Measured memory_bytes: 14592
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
using namespace std;

using ll=long long int;

int main() {
	
	int n, k;
	cin >> n >> k;

	string s;
	cin >> s;

	s[k - 1] += 32;

	cout << s << endl;

	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
     
#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()
     
using namespace std;
using ll = long long;
using P = pair<int, int>;
     
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; }
     
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int G[20][20];
int dp[1 << 15][20];

int rec( int S, int v, int n ){
  if( dp[S][v] >= 0 ){
    return dp[S][v];
  }

  if( S == ( 1 << n ) - 1 && v == 0 ){
    return dp[S][v] = 0;
  }

  int res = INF;
  REP( i, n ){
    if( !( S >> i & 1 ) ){
      chmin( res, rec( S | 1 << i, i, n ) + G[v][i] );
    }
  }
  
  return dp[S][v] = res;
}

int main(){
  int v, e; cin >> v >> e;

  fill( G[0], G[v], INF );
  
  REP( i, e ){
    int f, t, d; cin >> f >> t >> d;
    G[f][t] = d;
  }

  fill( dp[0], dp[1 << 15], -1 );

  int ans = rec( 0, 0, v );
  if( ans != INF ){
    cout << ans << endl;
  }else{
    cout << -1 << endl;
  }
}



Measured memory_bytes: 5644
#include <cstdio>
#include <cstring>
#define ll long long

ll n,m;
char s[100010],t[100010];
ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}

int main()
{
	scanf("%lld %lld",&n,&m);
	scanf("%s %s",s+1,t+1);
	ll lcm=n/gcd(n,m)*m;
	ll a=lcm/n,b=lcm/m;
	ll Gcd=a/gcd(a,b)*b;
	ll c=Gcd/a,d=Gcd/b;
	ll x=1,y=1;
	while(x<=n&&y<=m)
	{
		if(s[x]!=t[y])
		{
			printf("-1");
			return 0;
		}
		x+=c;
		y+=d;
	}
	printf("%lld",lcm);
}

Measured memory_bytes: 384
// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
void solve();
int main() { solve(); return 0; }

vector<string> Z { "NO", "YES" };

#include <set>
void solve() {
  string s;
  cin >> s; 
  int n = s.size();
  int cnt = 0;
  int l=0, r=n-1;
  while (l<r) {
    cnt += s[l++]!=s[r--];
  }
  cout << cnt << endl;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

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

    sort(a.rbegin(), a.rend());

    ll ans = 0;
//    ans += a[0];
    for (ll i = 1; i < n; ++i) {
        ans += a[i / 2];
    }

    cout << ans << endl;
}

Measured memory_bytes: 4808
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline
INF = float("inf")


@nb.njit
def solve(N, K, h):
    dp = [0] * N
    for i in range(1, N):
        min_cost = INF
        for k in range(1, min(K + 1, i + 1)):
            cost = dp[i - k] + abs(h[i] - h[i - k])
            if cost < min_cost:
                min_cost = cost
        dp[i] = min_cost
    return dp[-1]


def main():
    N, K = map(int, input().split())
    h = np.array(input().split(), dtype=np.int64)

    ans = solve(N, K, h)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 111652
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int n = s.size();
    vi cnt(3);
    cnt[0] = count(s.cbegin(), s.cend(), 'a');
    cnt[1] = count(s.cbegin(), s.cend(), 'b');
    cnt[2] = count(s.cbegin(), s.cend(), 'c');
    
    if (cnt[0] > (n+2)/3 || cnt[1] > (n+2)/3 || cnt[2] > (n+2)/3) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 512
from collections import deque

que = deque()

K = int(input())

que.append((1, 1))
visited = {}

while len(que) != 0:
    num, step = que.popleft()
    if num in visited:
        continue
    visited[num] = step
    que.appendleft((num * 10 % K, step))
    que.append(((num + 1) % K, step + 1))

print(visited[0])

Measured memory_bytes: 24300
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

template< typename T > T mod_pow(T x, T n, const T& p) {
	T ret = 1;
	while (n > 0) {
		if (n & 1) (ret *= x) %= p;
		(x *= x) %= p;
		n >>= 1;
	}
	return ret;
}

string s;
int dp[100001][2][13];
int inv = mod_pow(10, 11, 13);
int rec(int k, bool zero, int rem, int digit) {
	if (k > s.size() - 1) {
		return rem == 5;
	}
	int x = (s[k] == '?' ? 9 : s[k] - '0');

	int& res = dp[k][zero][rem];
	if (~res)return res;
	res = 0;

	bool is = (k == 0 ? true : false);
	if (s[k] == '?') {
		rep(i, 0, x + 1) {
			res += rec(k + 1, (is ? i == 0 : zero), (rem + i * digit) % 13, (digit * inv) % 13);
			res %= mod;
		}
	}
	else {
		res += rec(k + 1, zero, (rem + x * digit) % 13, (digit * inv) % 13);
		res %= mod;

	}
	return res;
}

int main() {
	init();

	cin >> s;
	memset(dp, -1, sizeof(dp));
	int digit = mod_pow(10, (int)s.size() - 1, 13);

	cout << rec(0,true,0,digit) << "\n";

	return 0;
}

Measured memory_bytes: 20048
import heapq
n,m=map(int,input().split())
edge=[[] for _ in range(n)]
for i in range(n-1):
  edge[i+1].append([0,i])
for _ in range(m):
  l,r,c=map(int,input().split())
  l-=1
  r-=1
  edge[l].append([c,r])
  edge[r].append([c,l])
def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    infi=10**18
    d = [infi] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    if d[n-1]!=infi:
      return d[n-1]
    else:
      return -1
print(dijkstra_heap(0))

Measured memory_bytes: 70948
/*
問題A：イチョウの数
https://onlinejudge.u-aizu.ac.jp/problems/1325

問題A：イチョウの数
銀杏数の定義と銀杏数への乗算を説明します。

銀杏数とは、<m, n>の組で、mとnは整数である。例えば、<1, 1>, <2, 1>, <3,-1>はイチョウ数です。

イチョウ数に対する乗算は、<m, n> - <x, y> = <mx - ny, my + nx>で定義される。例えば、<1,1> - <2,1> = <3,-1>となります。

イチョウ数 <m, n> は、<m, n> - <x, y> = <p, q> となるようなイチョウ数 <x, y> が存在する場合、イチョウ数 <p, q> の除数と呼ばれる。

任意のイチョウ数<m, n>について、イチョウ数<1, 0>, <0, 1>, <1, 0>, <0,-1>, <m, n>, <n,m>, <m,-n>, <n,-m>は<m, n>の除数である。ｍ２＋ｎ２＞１であれば、これらのイチョウ数は明瞭である。言い換えれば、m2 + n2 > 1のような任意のイチョウ数は、少なくとも8つの除数を持つ。

イチョウ数<m, n>は、m2+n2 > 1で、8つの除数を持つ場合、素数と呼ばれます。あなたの使命は，与えられたイチョウ数が素数かどうかを調べることです．

あるイチョウ数が他のイチョウ数の割り算であるかどうかを調べるには、次の2つの事実が役に立つかもしれません。

m2 + n2 > 0 とすると、整数 m2 + n2 が mp + nq と mq - np の共通除数である場合に限り、<m, n> は <p, q> の除数である。
<m, n> - <x, y> = <p, q>ならば、(m2 + n2)(x2 + y2) = p2 + q2となる。
入力
入力の最初の行には、データセットの数である1つの整数が含まれています。

入力の残りの部分は，データセットの列である．各データセットは，スペースで区切られた2つの整数mとnを含む1行である．これらはイチョウの数 <m, n> を指定します．1 < m2 + n2 < 20000 と考えることができる．

出力
各データセットについて，イチョウ数が素数の場合は行に文字 'P' を出力してください．それ以外の場合は行に文字 'C' を出力する．

*/

#include <iostream>
#include <vector>
using namespace std;

const int MAX = 1000100;
const int INF = 1<<29;

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

    for(int i=0; i< n; i++){
        int p, q;
        cin >> p >> q;

        int mul1 = p*p + q*q;

        int x = 1;
        int y = 1;
        bool flag = false;
        int ans;

        while(1){
            while(1){
                int mul2 = x*x + y*y;
                if(mul2 < mul1){

                    if (mul1 % mul2 == 0){
                        flag = true;
                        break;
                    }

                }
                else{
                    break;
                }
                ++y;
            }
            if(flag){
                break;
            }
            if(x*x >= 20000 || x*x > mul1) break;

            ++x;
            y = 0;
        }

        if(flag){
            cout << "C" << endl;
        }
        else{
            cout << "P" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3056
import java.io.*;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=1;//sc.nextInt();
		while(t-->0) {
			int n=sc.nextInt();
			long ans=0;
			int max=Integer.MIN_VALUE;
			for(int i=0;i<n;i++) {
				int val=sc.nextInt();
				max=Math.max(val, max);
				ans+=max-val;
			}
			System.out.println(ans);
		}

	}

}
/*class Reader{
	BufferedReader reader;
	Reader(){
		reader=new BufferedReader(new InputStreamReader(System.in));
	}
	int nextInt() throws IOException{
		String in=reader.readLine().trim();
		return Integer.parseInt(in);
	}
	long nextLong() throws IOException{
		String in=reader.readLine().trim();
		return Long.parseLong(in);
	}
	String next() throws IOException{
		return reader.readLine().trim();
	}
	String[] stringArray() throws IOException{
		return reader.readLine().trim().split("\\s+");
	}
	int[] intArray() throws IOException{
		String[] inp=this.stringArray();
		int[] arr=new int[inp.length];
		int i=0;
		for(String s:inp) {
			arr[i++]=Integer.parseInt(s);
		}
		return arr;
	}
}*/




Measured memory_bytes: 58300
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stdio.h>
#include<map>
#include<queue>
#include<vector>
using namespace std;
const int maxn=1e6;

typedef long long ll;

ll a[maxn],b[maxn];

int main(){
	int n;cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		cin>>b[i];
	reverse(b,b+n);
	
	//找到相等区间 
	int t=0,l=n,r=-1;
	for(int i=0;i<n;i++){
		if(t==0&&a[i]==b[i]){
			t=a[i];l=r=i;
		}
		else if(t!=0&&a[i]==b[i]){
			r=i;
		}
	}

	//交换后左移 
	for(int i=0;i<n;i++){
		if(a[i]!=t&&b[i]!=t&&l<=r){
			swap(b[i],b[l]);
			l++;
		}
	}
	
	if(l>r){
		cout<<"Yes"<<endl;
        for(int i=0;i<n;i++)
            cout<<b[i]<<" ";
	}
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 6732
#include<bits/stdc++.h>
using namespace std;
void solve(int k)
{
	int i,count = 0;
	queue<string> q;
	string b;
	char a;
	for(i=1;i<=9;++i)
	{
		b = "";
		a = '0'+i;
		b += a;
		q.push(b);
		count++;
		if(k==count)
		{
			printf("%d",i);
			return;
		}
	}
	while(1)
	{
		b = q.front();q.pop();
		if(b[b.size()-1]!='0')
		{
			a = b[b.size()-1]-1;
			++count;
			if(count==k)
			{
				cout << b + a;
				return; 	
			}	
			q.push(b+a);
		}
		a = b[b.size()-1];
		++count;
		if(count==k)
		{
			cout << b + a;
			return; 	
		}	
		q.push(b+a);
		if(b[b.size()-1]!='9')
		{
			a = b[b.size()-1]+1;
			++count;
			if(count==k)
			{
				cout << b + a;
				return; 	
			}	
			q.push(b+a);
		}	
	}
}
int main()
{
	int k;
	scanf("%d",&k);
	solve(k);
}


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


int main(){
    
    
    
    int a,b;
    int ans=0;
    while(cin>>a>>b){
        int x=a+b;
        ans=0;
        while(x>0){
            x=x/10;
            ans++;
        }
        cout<<ans<<endl;
    }
    
    
    return 0;
}



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

#define inf 0x3f3f3f3f
#define pi acos(-1)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
template<class T> bool mmin(T &a,T b){return (a>b ?(a=b,true):false);};
template<class T> bool mmax(T &a,T b){return (a<b ?(a=b,true):false);};

vector<int> pref;
inline int query(int l,int r){
	return pref[r]-pref[l];
}
int32_t main(){
	
	int n, m;
	cin >> n >> m;
	string str;
	cin >> str;
	int ans=0,cont=0,sz = (int)str.size();
	pref = vector<int>(sz,0);
	for(int i=1;i<sz;i++){
		char c = str[i];
		if(c=='C' and str[i-1]=='A')
			pref[i]++;
		pref[i]+=pref[i-1];
	}
	//for(int i=0;i<sz;i++)
		//cout << pref[i] << " ";
	//cout << '\n';
	while(m--){
		int u,v;
		scanf("%d%d",&u,&v);
		v--,u--;
		printf("%d\n",query(u,v)); 
	}
#ifdef LOCAL_DEFINE
	cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}




















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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll h, w;
    cin >> h >> w;

    ll ch, cw;
    cin >> ch >> cw;
    ch--;
    cw--;
    ll dh, dw;
    cin >> dh >> dw;
    dh--;
    dw--;

    string s[h];
    rep(i, h) { cin >> s[i]; }

    bool field[h][w];
    rep(i, h) {
        rep(j, w) { field[i][j] = s[i][j] == '#'; }
    }

    deque<pair<ll, ll>> q;
    q.push_front(make_pair(ch, cw));

    ll cost[h][w];
    rep(i, h) {
        rep(j, w) { cost[i][j] = mod; }
    }
    cost[ch][cw] = 0;

    ll mh[] = {-1, 0, 0, 1};
    ll mw[] = {0, -1, 1, 0};

    bool visited[h][w] = {};

    ll ans = -1;
    while (!q.empty()) {
        auto now = q.front();
        q.pop_front();
        ll nx = now.first, ny = now.second;
        if (visited[nx][ny]) {
            continue;
        }
        visited[nx][ny] = true;

        if (nx == dh && ny == dw) {
            ans = cost[nx][ny];
            break;
        }

        rep(i, 4) {
            ll next_x = nx + mh[i], next_y = ny + mw[i];
            if (next_x < 0 || h <= next_x)
                continue;
            if (next_y < 0 || w <= next_y)
                continue;

            if (!visited[next_x][next_y] && !field[next_x][next_y]) {
                q.push_front(make_pair(next_x, next_y));
                cost[next_x][next_y] = min(cost[next_x][next_y], cost[nx][ny]);
            }
        }
        for (ll i = -2; i <= 2; i++) {
            for (ll j = -2; j <= 2; j++) {
                ll next_x = nx + i, next_y = ny + j;
                if (next_x < 0 || h <= next_x)
                    continue;
                if (next_y < 0 || w <= next_y)
                    continue;
                if (!visited[next_x][next_y] && !field[next_x][next_y]) {
                    q.push_back(make_pair(next_x, next_y));
                    cost[next_x][next_y] =
                        min(cost[next_x][next_y], cost[nx][ny] + 1);
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

using ll = int_fast64_t;
constexpr ll llmax = INT_FAST64_MAX; // std::numeric_limits<int_fast64_t>::max()
constexpr ll llmin = INT_FAST64_MIN; // std::numeric_limits<int_fast64_t>::min()
using ull = uint_fast64_t;
constexpr ull ullmax = UINT_FAST64_MAX; // std::numeric_limits<uint_fast64_t>::max()

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(a);
    scanInt(b);
    scanInt(c);
    scanInt(d);
    scanInt(e);
    scanInt(k);
    if (e - a <= k){
        puts("Yay!");
    }else{
        puts(":(");
    }
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int f[100001][2];
int head[100001],to[200001],nxt[200001];
int tot;
int n;
void addedge(int u,int v)
{
	tot++;
	nxt[tot]=head[u];
	to[tot]=v;
	head[u]=tot; 
}
void dfs(int index,int p)
{
	f[index][0]=f[index][1]=1;
	for(int i=head[index];i;i=nxt[i])
	{
		int v=to[i];
		if(p==v)
			continue;
		dfs(v,index);
		f[index][0]=f[index][0]*((long long)f[v][0]+f[v][1])%1000000007;
		f[index][1]=f[index][1]*(long long)f[v][0]%1000000007;
	}
	return;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	dfs(1,0);
	printf("%lld",((long long)f[1][0]+f[1][1])%1000000007);
}

Measured memory_bytes: 8576
#include<stdio.h>

int main(){
  int o,n,k,i,j;
  int key;
  int A[110];
  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d",&A[i]);

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


Measured memory_bytes: 2056
function Main(input) {
    var N = parseInt(input[0].split(/\s/)[0], 10);
    var M = parseInt(input[0].split(/\s/)[1], 10);
    var s = input.slice(1).map(sc => sc.split(/\s/)[0]);
    var c = input.slice(1).map(sc => sc.split(/\s/)[1]);
    
    var list = new Array(N);
    list.fill(-1);

    for (var i = 0; i < M; i++) {
        if (list[s[i] - 1] !== -1 && list[s[i] - 1] !== c[i]) {
            return console.log(-1);
        } else {
            list[s[i] - 1] = c[i];
        }
    }

    var result = '';

    for (var j = 0; j < N; j++) {
        if (j === 0 && N !== 1) {
            if (list[j] === -1) {
                result += '1';
            } else if (list[j] === '0') {
                return console.log(-1);
            } else {
                result += `${list[j]}`;
            }
        } else if (list[j] === -1) {
            result += '0';
        } else {
            result += `${list[j]}`;
        }
    }

    console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/));


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

int main(){
  int N;
  std::cin >> N;
  std::vector<int> T(N);
  int sum = 0;
  for(int i = 0; i < N; i++){
    std::cin >> T.at(i);
    sum += T.at(i);
  }
//  std::cout << "sum = " << sum << std::endl;
  int M;
  std::cin >> M;
  std::vector<std::vector<int>> PX(M, std::vector<int>(2));
  for(int i = 0; i < M; i++){
    std::cin >> PX.at(i).at(0) >> PX.at(i).at(1);
//    std::cout << "Pi = " << PX.at(i).at(0) << " | Xi = " << PX.at(i).at(1) << std::endl;
    std::cout << sum - T.at(PX.at(i).at(0) - 1) + PX.at(i).at(1) << std::endl; 
  }
}

Measured memory_bytes: 256
n,c,k=gets.split.map &:to_i
a=$<.map(&:to_i).sort
b=[a[0]]
t=1
1.upto(n-1) do |i|
  if b.length<c && b[0]+k>=a[i]
    b<< a[i]
  else
    t+=1
    b=[a[i]]
  end
end
p t

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

int main() {
  int N;
  cin >> N;
  vector<uint64_t> Lucas(N+1);
  Lucas.at(0) = 2;
  Lucas.at(1) = 1;
  
  if(N==0){
    cout << Lucas.at(0) << endl;
  }
  else if(N==1){
    cout << Lucas.at(1) << endl;
  }
  else {
    rep2(i, 2, N+1){
      Lucas.at(i) = Lucas.at(i-1) + Lucas.at(i-2);
    }
    cout << Lucas.at(N) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  int n = s.size();
  string rs(s);
  reverse(ALL(s));
  int a = 0, b = 0;
  FOR(i, 1, n){
    if(s[i-1] == s[i]){
      a++;
      s[i] = (s[i-1] == '0') ? '1' : '0';
    }
    if(rs[i-1] == rs[i]){
      b++;
      rs[i] = (rs[i-1] == '0') ? '1' : '0';
    }
  }
  cout << min(a, b) << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <array>
#include <stack>
#include <queue>

using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
//#define TEST //*******************************************************************************************************************************************

//?????????????????¨??§?????\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
#ifdef TEST
    #define dout cout
#else
    stringstream dummy; //???????????°??????dout?????????????????????????????????
    #define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummy?????????????????????????????????????????¨?????¢?????¢???????????????
    //???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§???????????????????????????????????? http://d.hatena.ne.jp/linden/20060427/p1
#endif


#define Name first
#define Time second

int main(void) {
    
    queue<pair<string, int>> q;

    int N, quantam;
    string processName;
    int processTime;
    
    cin >> N >> quantam;
    
    for(int i=0; i<N; i++) {
        cin >> processName >> processTime;
        
        pair<string, int> process = {processName, processTime};
        
        q.push(process);
    }
    
    
//    //display q[]
//    while( !q.empty() ) {
//        pair<string, int> process;
//        process = q.front();
//        
//        dout << process.Name << " " << process.Time << endl;
//        
//        q.pop();
//    }
    
    //execute q[]
    int time = 0;
    while( !q.empty() ) {
        pair<string, int> process;
        process = q.front();
        
        dout << setw(4) << time << " : " << process.Name << " " << process.Time << endl;
        
        if(process.Time <= quantam) { //process?????????????????´???
            time += process.Time;
            
            cout << process.Name << " " << time << endl;
        }
        else { //?????????????????´?????????????°??????????
            time += quantam;
            process.Time -= quantam;
            
            dout << setw(4) << time << " : " << process.Name << " remains " << process.Time << endl;

            q.push(process);
        }

        //????????????????????????????´??????????
        q.pop();
    }

    return 0;
}

Measured memory_bytes: 5948
#include <iostream>
using namespace std;
int main(void){
  int x;
  cin >> x;
  int flg = 0;
  for(int i = x; ; i++){
    flg = 0;
    for(int j = 2; j < i; j++){
      if(i % j == 0){
        flg = 1;
        continue;
      }
    }
    if(flg == 0){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
a = na()

cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]
c = Counter()
for x in cum:
    c[x%m] += 1

ans = 0
for v in c.values():
    ans += v*(v-1)//2
print(ans)


Measured memory_bytes: 17648
#include <stdio.h>

int main(void){
	int i;
	int end;
	char board[3][3];
	while(
			scanf(
				"%c%c%c%c%c%c%c%c%c",
				&board[0][0],&board[0][1],&board[0][2],
				&board[1][0],&board[1][1],&board[1][2],
				&board[2][0],&board[2][1],&board[2][2]
			     ) != EOF
	     ){
		end = 0;
		for(i = 0; i < 3; i++){
			if(
					board[i][0] != 's' &&
					board[i][0] == board[i][1] &&
				       	board[i][1] == board[i][2]
			){
				printf("%c\n",board[i][0]);
				end = 1;
				break;
			}
		}
		if(end){getchar();continue;}
		for(i = 0; i < 3; i++){
			if(
					board[0][i] != 's' &&
					board[0][i] == board[1][i] &&
				       	board[1][i] == board[2][i]
			){
				printf("%c\n",board[0][i]);
				end = 1;
				break;
			}
		}
		if(end){getchar();continue;}
		if(
				board[0][0] != 's' &&
				board[0][0] == board[1][1] &&
				board[1][1] == board[2][2]
		  ){
				printf("%c\n",board[0][0]);
				getchar();continue;
		}
		if(
				board[0][2] != 's' &&
				board[0][2] == board[1][1] &&
				board[1][1] == board[2][0]
		  ){
				printf("%c\n",board[0][2]);
				getchar();continue;
		}
		puts("d");
		getchar();
	}

	return 0;
}

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

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int N;  cin >> N;
   	V A(N);
    REP(i, N-1){  int kp;  cin >> kp;  A[kp-1]++;  }

    REP(i, N)
      cout << A[i] << endl;
	return 0;
}


Measured memory_bytes: 3948
n,c,k = map(int,input().split())
t = [int(input()) for _ in range(n)]
t.sort()
cnt = 0
ans = 0
end = -1
for i,t in enumerate(t):
  if end < t:
    cnt = 1
    ans +=1
    end = t+k
  else:
    cnt +=1
  if cnt > c:
    cnt = 1
    ans +=1
    end = t+k
#  print("i",i,"t",t,"cnt",cnt,"ans",ans,"end",end)
print(ans)

Measured memory_bytes: 13268
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;



int main(){
    ll N,L; cin>>N>>L;
    ll left = L;
    ll right = L + N - 1;
    ll sum = (left + right) * N /2;
    if(left <= 0 and right >= 0) cout<<sum<<endl;
    else if (right <= 0) cout<<sum- (right)<<endl;
    else if (left >= 0) cout<<sum - abs(left)<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define rep(i, a, b) for (int i = a; i < b; i++)
#define print(a) cout << (a) << endl; 

int dp[101][4][2];

int main() {
    string s; 
    int k;
    cin >> s;
    cin >> k;
    int n = s.size();
    int ret = 0;
    int i0 = s[0] - '0';
    dp[0][1][1] = 1;
    dp[0][1][0] = i0 - 1;
    dp[0][0][1] = 0;
    dp[0][0][0] = 1;

    rep(i, 1, n) {
        int is = s[i] - '0';
        dp[i][0][1] = 0;
        dp[i][0][0] = 1; 
        if (is > 0) {
            rep(k, 1, 4) {
                dp[i][k][0] = dp[i-1][k-1][0] * 9 
                    + dp[i-1][k][0] + dp[i-1][k-1][1] * (is-1) + dp[i-1][k][1]; 
                dp[i][k][1] = dp[i-1][k-1][1]; 
            }
        } else {
            rep(k, 1, 4) {
                dp[i][k][0] = dp[i-1][k][0] + dp[i-1][k-1][0]*9; 
                dp[i][k][1] = dp[i-1][k][1]; 
            } 
        }
    }
    cout << dp[n-1][k][0] + dp[n-1][k][1] << endl;

    return 0;
}

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  
  	if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0]) {
      cout << "YES" << endl;
    }
  	else {
      cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
S=list(input())

ans=len(S)
for s in set(S):
  T=S
  tmp=0
  for i in range(len(S)):
    if len(set(T))==1:
      ans=min(ans,tmp)
      break
    tmp+=1
    T=[s if a==s else b for a,b in zip(T[0:],T[1:])]
print(ans)

Measured memory_bytes: 3060
import Foundation
let main: () = {
    let (N, _) = *listOfInt()
    let A = listOfInt()
    let ans = max(N - A.sum(), -1)
    print(ans)
}()
@inlinable func next() -> String { readLine()! }
@inlinable func nextInt() -> Int { Int(next())! }
@inlinable func nextDouble() -> Double { Double(next())! }
@inlinable func listOfString() -> [String] { next().split(separator: " ").map(String.init) }
@inlinable func listOfInt() -> [Int] { listOfString().map { Int($0)! } }
prefix operator *
prefix func * <T> (a: [T]) -> (T, T) { (a[0], a[1]) }
extension Array where Element == Int {
    @inlinable func sum() -> Element { self.reduce(0, +) }
}


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

int N, x[109], y[109], ax, ay, bx, by; bool used[209][209];

void init() {
	N = 0; ax = 0; ay = 0; bx = 0; by = 0;
	for (int i = 0; i < 109; i++) { x[i] = 0; y[i] = 0; }
	for (int i = 0; i < 209 * 209; i++) used[i / 209][i % 209] = false;
}

int solve() {
	vector<int>X, Y;
	for (int i = 0; i < N; i++) { X.push_back(x[i]); Y.push_back(y[i]); }
	sort(X.begin(), X.end()); X.erase(unique(X.begin(), X.end()), X.end());
	sort(Y.begin(), Y.end()); Y.erase(unique(Y.begin(), Y.end()), Y.end());

	for (int i = 0; i < Y.size(); i++) {
		vector<int>P;
		for (int j = 0; j < N; j++) {
			int v1 = y[j], v2 = y[(j + 1) % N]; if (v1 > v2) swap(v1, v2);
			if (x[j] == x[(j + 1) % N] && v1 <= Y[i] && Y[i] < v2) P.push_back(x[j]);
		}
		sort(P.begin(), P.end());

		int cnt = 0;
		for (int j = 0; j < X.size(); j++) {
			while (cnt < P.size() && P[cnt] == X[j]) cnt++;
			if (cnt % 2 == 1) used[j][i] = true; // (x 座標, y 座標) の順
		}
	}
	long long ret = 0;
	for (int i = 0; i < X.size() - 1; i++) {
		for (int j = 0; j < Y.size() - 1; j++) {
			if (used[i][j] == false) continue;
			int px = X[i], py = Y[j], qx = X[i + 1], qy = Y[j + 1];
			px = max(px, ax); py = max(py, ay);
			qx = min(qx, bx); qy = min(qy, by);

			if (px >= qx || py >= qy) ret += 0;
			else ret += (qx - px) * (qy - py);
		}
	}
	long long ret2 = 0;
	for (int i = 0; i < N; i++) ret2 += (x[i] - x[(i + 1) % N]) * (y[i] + y[(i + 1) % N]);
	ret2 = abs(ret2); ret2 /= 2;

	return ret2 - ret;
}

int main() {
	while (true) {
		init();
		cin >> N; if (N == 0) break;
		for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
		int v1, v2, v3, v4, v5, v6, v7, v8;
		cin >> v1 >> v2 >> v3 >> v4 >> v5 >> v6 >> v7 >> v8;
		ax = min({ v1, v3, v5, v7 });
		ay = min({ v2, v4, v6, v8 });
		bx = max({ v1, v3, v5, v7 });
		by = max({ v2, v4, v6, v8 });
		cout << solve() << endl;
	}
	return 0;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> s(m);
  rep(i,m) {
    int k;
    cin >> k;
    rep(j,k) {
      int a;
      cin >> a;
      a--;
      s[i].push_back(a);
    }
  }
  int p[m];
  rep(i,m) cin >> p[i];
  int ans = 0;
  rep(i,1<<n) {
    int c = 0;
    rep(j,m) {
      int d = 0;
      for(auto q : s[j]) {
        if(i & (1<<q)) d++;
      }
      if(d % 2 == p[j]) c++;
    }
    if(c == m) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256